mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-18 19:31:43 +00:00
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
// Resolves filesystem paths for installed plugin index storage.
|
|
import path from "node:path";
|
|
import { resolveStateDir } from "../config/paths.js";
|
|
import type { OpenClawStateDatabaseOptions } from "../state/openclaw-state-db.js";
|
|
import { resolveOpenClawStateSqlitePath } from "../state/openclaw-state-db.paths.js";
|
|
|
|
const LEGACY_INSTALLED_PLUGIN_INDEX_STORE_PATH = path.join("plugins", "installs.json");
|
|
|
|
/** Options for resolving installed plugin index storage paths. */
|
|
export type InstalledPluginIndexStoreOptions = {
|
|
env?: NodeJS.ProcessEnv;
|
|
stateDir?: string;
|
|
filePath?: string;
|
|
};
|
|
|
|
function resolveStoreEnv(options: InstalledPluginIndexStoreOptions): NodeJS.ProcessEnv {
|
|
return options.stateDir
|
|
? { ...(options.env ?? process.env), OPENCLAW_STATE_DIR: options.stateDir }
|
|
: (options.env ?? process.env);
|
|
}
|
|
|
|
/** Resolves the canonical SQLite-backed installed plugin index path. */
|
|
export function resolveInstalledPluginIndexStorePath(
|
|
options: InstalledPluginIndexStoreOptions = {},
|
|
): string {
|
|
if (options.filePath) {
|
|
return options.filePath;
|
|
}
|
|
return resolveOpenClawStateSqlitePath(resolveStoreEnv(options));
|
|
}
|
|
|
|
/** Resolves state database options for the installed plugin index store. */
|
|
export function resolveInstalledPluginIndexStateDatabaseOptions(
|
|
options: InstalledPluginIndexStoreOptions = {},
|
|
): OpenClawStateDatabaseOptions {
|
|
if (options.filePath) {
|
|
return {
|
|
...(options.env ? { env: options.env } : {}),
|
|
path: options.filePath,
|
|
};
|
|
}
|
|
if (options.stateDir) {
|
|
return {
|
|
env: resolveStoreEnv(options),
|
|
};
|
|
}
|
|
return options.env ? { env: options.env } : {};
|
|
}
|
|
|
|
/** Resolves the legacy JSON installed plugin index path for migration/doctor use. */
|
|
export function resolveLegacyInstalledPluginIndexStorePath(
|
|
options: InstalledPluginIndexStoreOptions = {},
|
|
): string {
|
|
if (options.filePath) {
|
|
return options.filePath;
|
|
}
|
|
const env = options.env ?? process.env;
|
|
const stateDir = options.stateDir ?? resolveStateDir(env);
|
|
return path.join(stateDir, LEGACY_INSTALLED_PLUGIN_INDEX_STORE_PATH);
|
|
}
|