refactor(cli): share npm install metadata helpers

This commit is contained in:
Peter Steinberger
2026-02-21 21:56:05 +00:00
parent d6ad647f56
commit 2d4e4e2288
6 changed files with 316 additions and 79 deletions

View File

@@ -21,6 +21,12 @@ import { formatDocsLink } from "../terminal/links.js";
import { renderTable } from "../terminal/table.js";
import { theme } from "../terminal/theme.js";
import { resolveUserPath, shortenHomeInString, shortenHomePath } from "../utils.js";
import {
buildNpmInstallRecordFields,
logPinnedNpmSpecMessages,
resolvePinnedNpmSpec,
} from "./npm-resolution.js";
import { setPluginEnabledInConfig } from "./plugins-config.js";
import { promptYesNo } from "./prompt.js";
export type PluginsListOptions = {
@@ -360,19 +366,7 @@ export function registerPluginsCli(program: Command) {
.argument("<id>", "Plugin id")
.action(async (id: string) => {
const cfg = loadConfig();
const next = {
...cfg,
plugins: {
...cfg.plugins,
entries: {
...cfg.plugins?.entries,
[id]: {
...(cfg.plugins?.entries as Record<string, { enabled?: boolean }> | undefined)?.[id],
enabled: false,
},
},
},
};
const next = setPluginEnabledInConfig(cfg, id, false);
await writeConfigFile(next);
defaultRuntime.log(`Disabled plugin "${id}". Restart the gateway to apply.`);
});
@@ -631,28 +625,24 @@ export function registerPluginsCli(program: Command) {
clearPluginManifestRegistryCache();
let next = enablePluginInConfig(cfg, result.pluginId).config;
const resolvedSpec = result.npmResolution?.resolvedSpec;
const recordSpec = opts.pin && resolvedSpec ? resolvedSpec : raw;
if (opts.pin && !resolvedSpec) {
defaultRuntime.log(
theme.warn("Could not resolve exact npm version for --pin; storing original npm spec."),
);
}
if (opts.pin && resolvedSpec) {
defaultRuntime.log(`Pinned npm install record to ${resolvedSpec}.`);
}
const pinInfo = resolvePinnedNpmSpec({
rawSpec: raw,
pin: Boolean(opts.pin),
resolvedSpec: result.npmResolution?.resolvedSpec,
});
logPinnedNpmSpecMessages(
pinInfo,
(message) => defaultRuntime.log(message),
(message) => defaultRuntime.log(theme.warn(message)),
);
next = recordPluginInstall(next, {
pluginId: result.pluginId,
source: "npm",
spec: recordSpec,
installPath: result.targetDir,
version: result.version,
resolvedName: result.npmResolution?.name,
resolvedVersion: result.npmResolution?.version,
resolvedSpec: result.npmResolution?.resolvedSpec,
integrity: result.npmResolution?.integrity,
shasum: result.npmResolution?.shasum,
resolvedAt: result.npmResolution?.resolvedAt,
...buildNpmInstallRecordFields({
spec: pinInfo.recordSpec,
installPath: result.targetDir,
version: result.version,
resolution: result.npmResolution,
}),
});
const slotResult = applySlotSelectionForPlugin(next, result.pluginId);
next = slotResult.config;