mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-03 23:14:03 +00:00
* refactor: persist plugin install index in sqlite * fix: merge legacy plugin index records into sqlite * test: update plugin index sqlite fixtures * fix: migrate custom plugin install indexes * test: update plugin index sentinel * fix: exclude migrated plugin index archives * fix: read post-upgrade plugin index from sqlite * fix: migrate legacy plugin index before agent runs * fix: respect disabled persisted plugin registry reads * test: type plugin install record fixtures * fix: simplify plugin index record reader type * test: fix sqlite plugin index CI fallout * test: mock provider normalization in agent command tests # Conflicts: # src/commands/agent-command.test-mocks.ts * build: remove unused ui three dependency
57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { readJson } from "./fixtures/common.mjs";
|
|
import { readPluginInstallRecords } from "./plugin-index-sqlite.mjs";
|
|
|
|
export { readJson };
|
|
|
|
export function stateDir() {
|
|
return process.env.OPENCLAW_STATE_DIR || path.join(process.env.HOME, ".openclaw");
|
|
}
|
|
|
|
export function configPath() {
|
|
return process.env.OPENCLAW_CONFIG_PATH || path.join(stateDir(), "openclaw.json");
|
|
}
|
|
|
|
export function managedNpmRoot() {
|
|
return path.join(stateDir(), "npm");
|
|
}
|
|
|
|
export function realPathMaybe(filePath) {
|
|
try {
|
|
return fs.realpathSync(filePath);
|
|
} catch {
|
|
return path.resolve(filePath);
|
|
}
|
|
}
|
|
|
|
export function assertPathInside(parentPath, childPath, label) {
|
|
const parent = realPathMaybe(parentPath);
|
|
const child = realPathMaybe(childPath);
|
|
const relative = path.relative(parent, child);
|
|
if (relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
throw new Error(`${label} resolved outside ${parentPath}: ${child}`);
|
|
}
|
|
}
|
|
|
|
export function readInstallRecords(fallbackRecords = {}) {
|
|
return readPluginInstallRecords({ fallbackRecords });
|
|
}
|
|
|
|
export function npmProjectRootForInstalledPackage(installPath, packageName) {
|
|
const packageRoot = packageName
|
|
.split("/")
|
|
.reduce((current) => path.dirname(current), installPath);
|
|
return path.basename(packageRoot) === "node_modules"
|
|
? path.dirname(packageRoot)
|
|
: managedNpmRoot();
|
|
}
|
|
|
|
export function findPackageJson(packageName, roots) {
|
|
const packagePath = packageName.startsWith("@")
|
|
? path.join(...packageName.split("/"), "package.json")
|
|
: path.join(packageName, "package.json");
|
|
const candidates = roots.map((root) => path.join(root, "node_modules", packagePath));
|
|
return candidates.find((candidate) => fs.existsSync(candidate));
|
|
}
|