feat(plugins): move install records to managed ledger

This commit is contained in:
Vincent Koc
2026-04-25 11:36:42 -07:00
parent e473577eaa
commit 888448facc
31 changed files with 721 additions and 74 deletions

View File

@@ -1,5 +1,12 @@
import { loadConfig, readConfigFileSnapshot, replaceConfigFile } from "../config/config.js";
import { updateNpmInstalledHookPacks } from "../hooks/update.js";
import {
loadPluginInstallRecords,
PLUGIN_INSTALLS_CONFIG_PATH,
withoutPluginInstallRecords,
writePersistedPluginInstallLedger,
withPluginInstallRecords,
} from "../plugins/install-ledger-store.js";
import { updateNpmInstalledPlugins } from "../plugins/update.js";
import { defaultRuntime } from "../runtime.js";
import { theme } from "../terminal/theme.js";
@@ -16,12 +23,14 @@ export async function runPluginUpdateCommand(params: {
}) {
const sourceSnapshotPromise = readConfigFileSnapshot().catch(() => null);
const cfg = loadConfig();
const pluginInstallRecords = await loadPluginInstallRecords({ config: cfg });
const cfgWithPluginInstallRecords = withPluginInstallRecords(cfg, pluginInstallRecords);
const logger = {
info: (msg: string) => defaultRuntime.log(msg),
warn: (msg: string) => defaultRuntime.log(theme.warn(msg)),
};
const pluginSelection = resolvePluginUpdateSelection({
installs: cfg.plugins?.installs ?? {},
installs: pluginInstallRecords,
rawId: params.id,
all: params.opts.all,
});
@@ -41,7 +50,7 @@ export async function runPluginUpdateCommand(params: {
}
const pluginResult = await updateNpmInstalledPlugins({
config: cfg,
config: cfgWithPluginInstallRecords,
pluginIds: pluginSelection.pluginIds,
specOverrides: pluginSelection.specOverrides,
dryRun: params.opts.dryRun,
@@ -109,13 +118,25 @@ export async function runPluginUpdateCommand(params: {
}
if (!params.opts.dryRun && (pluginResult.changed || hookResult.changed)) {
const nextPluginInstallRecords = pluginResult.config.plugins?.installs ?? {};
const shouldPersistPluginInstallLedger =
pluginResult.changed || Object.keys(pluginInstallRecords).length > 0;
if (shouldPersistPluginInstallLedger) {
await writePersistedPluginInstallLedger(nextPluginInstallRecords);
}
const nextConfig = shouldPersistPluginInstallLedger
? withoutPluginInstallRecords(hookResult.config)
: hookResult.config;
await replaceConfigFile({
nextConfig: hookResult.config,
nextConfig,
baseHash: (await sourceSnapshotPromise)?.hash,
...(shouldPersistPluginInstallLedger
? { writeOptions: { unsetPaths: [Array.from(PLUGIN_INSTALLS_CONFIG_PATH)] } }
: {}),
});
if (pluginResult.changed) {
await refreshPluginRegistryAfterConfigMutation({
config: hookResult.config,
config: nextConfig,
reason: "source-changed",
logger,
});