mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 21:01:43 +03:00
fix: support file: npm specs in plugin install
This commit is contained in:
+35
-1
@@ -43,6 +43,34 @@ export type PluginUninstallOptions = {
|
|||||||
dryRun?: boolean;
|
dryRun?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function resolveFileNpmSpecToLocalPath(
|
||||||
|
raw: string,
|
||||||
|
): { ok: true; path: string } | { ok: false; error: string } | null {
|
||||||
|
const trimmed = raw.trim();
|
||||||
|
if (!trimmed.toLowerCase().startsWith("file:")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const rest = trimmed.slice("file:".length);
|
||||||
|
if (!rest) {
|
||||||
|
return { ok: false, error: "unsupported file: spec: missing path" };
|
||||||
|
}
|
||||||
|
if (rest.startsWith("///")) {
|
||||||
|
// file:///abs/path -> /abs/path
|
||||||
|
return { ok: true, path: rest.slice(2) };
|
||||||
|
}
|
||||||
|
if (rest.startsWith("//localhost/")) {
|
||||||
|
// file://localhost/abs/path -> /abs/path
|
||||||
|
return { ok: true, path: rest.slice("//localhost".length) };
|
||||||
|
}
|
||||||
|
if (rest.startsWith("//")) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: 'unsupported file: URL host (expected "file:<path>" or "file:///abs/path")',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { ok: true, path: rest };
|
||||||
|
}
|
||||||
|
|
||||||
function formatPluginLine(plugin: PluginRecord, verbose = false): string {
|
function formatPluginLine(plugin: PluginRecord, verbose = false): string {
|
||||||
const status =
|
const status =
|
||||||
plugin.status === "loaded"
|
plugin.status === "loaded"
|
||||||
@@ -484,7 +512,13 @@ export function registerPluginsCli(program: Command) {
|
|||||||
.argument("<path-or-spec>", "Path (.ts/.js/.zip/.tgz/.tar.gz) or an npm package spec")
|
.argument("<path-or-spec>", "Path (.ts/.js/.zip/.tgz/.tar.gz) or an npm package spec")
|
||||||
.option("-l, --link", "Link a local path instead of copying", false)
|
.option("-l, --link", "Link a local path instead of copying", false)
|
||||||
.action(async (raw: string, opts: { link?: boolean }) => {
|
.action(async (raw: string, opts: { link?: boolean }) => {
|
||||||
const resolved = resolveUserPath(raw);
|
const fileSpec = resolveFileNpmSpecToLocalPath(raw);
|
||||||
|
if (fileSpec && !fileSpec.ok) {
|
||||||
|
defaultRuntime.error(fileSpec.error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
const normalized = fileSpec && fileSpec.ok ? fileSpec.path : raw;
|
||||||
|
const resolved = resolveUserPath(normalized);
|
||||||
const cfg = loadConfig();
|
const cfg = loadConfig();
|
||||||
|
|
||||||
if (fs.existsSync(resolved)) {
|
if (fs.existsSync(resolved)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user