mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-29 15:43:34 +00:00
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
// Helpers for deriving package names from persisted plugin and hook-pack install records.
|
|
import type { HookInstallRecord } from "../config/types.hooks.js";
|
|
import type { PluginInstallRecord } from "../config/types.plugins.js";
|
|
import { parseRegistryNpmSpec } from "../infra/npm-registry-spec.js";
|
|
|
|
/** Return the installed npm package name for a plugin install record when available. */
|
|
export function extractInstalledNpmPackageName(install: PluginInstallRecord): string | undefined {
|
|
if (install.source !== "npm") {
|
|
return undefined;
|
|
}
|
|
const resolvedName = install.resolvedName?.trim();
|
|
if (resolvedName) {
|
|
return resolvedName;
|
|
}
|
|
return (
|
|
(install.spec ? parseRegistryNpmSpec(install.spec)?.name : undefined) ??
|
|
(install.resolvedSpec ? parseRegistryNpmSpec(install.resolvedSpec)?.name : undefined)
|
|
);
|
|
}
|
|
|
|
/** Return the installed npm package name for a hook-pack install record when available. */
|
|
export function extractInstalledNpmHookPackageName(install: HookInstallRecord): string | undefined {
|
|
const resolvedName = install.resolvedName?.trim();
|
|
if (resolvedName) {
|
|
return resolvedName;
|
|
}
|
|
return (
|
|
(install.spec ? parseRegistryNpmSpec(install.spec)?.name : undefined) ??
|
|
(install.resolvedSpec ? parseRegistryNpmSpec(install.resolvedSpec)?.name : undefined)
|
|
);
|
|
}
|