refactor(cli): share update global command runner adapter

This commit is contained in:
Peter Steinberger
2026-02-21 20:19:39 +00:00
parent 944913fc98
commit a04cdc0390
3 changed files with 63 additions and 8 deletions

View File

@@ -11,6 +11,7 @@ import { fetchNpmTagVersion } from "../../infra/update-check.js";
import {
detectGlobalInstallManagerByPresence,
detectGlobalInstallManagerForRoot,
type CommandRunner,
type GlobalInstallManager,
} from "../../infra/update-global.js";
import type { UpdateStepProgress, UpdateStepResult } from "../../infra/update-runner.js";
@@ -236,10 +237,7 @@ export async function resolveGlobalManager(params: {
installKind: "git" | "package" | "unknown";
timeoutMs: number;
}): Promise<GlobalInstallManager> {
const runCommand = async (argv: string[], options: { timeoutMs: number }) => {
const res = await runCommandWithTimeout(argv, options);
return { stdout: res.stdout, stderr: res.stderr, code: res.code };
};
const runCommand = createGlobalCommandRunner();
if (params.installKind === "package") {
const detected = await detectGlobalInstallManagerForRoot(
@@ -281,3 +279,10 @@ export async function tryWriteCompletionCache(root: string, jsonMode: boolean):
defaultRuntime.log(theme.warn(`Completion cache update failed${detail}.`));
}
}
export function createGlobalCommandRunner(): CommandRunner {
return async (argv, options) => {
const res = await runCommandWithTimeout(argv, options);
return { stdout: res.stdout, stderr: res.stderr, code: res.code };
};
}