refactor(update): extract package manager bootstrap logic

This commit is contained in:
Peter Steinberger
2026-04-06 01:38:46 +01:00
parent 0793136c63
commit d37b97c2ff
8 changed files with 376 additions and 217 deletions

View File

@@ -26,19 +26,34 @@ function makeResult(
}
describe("inferUpdateFailureHints", () => {
it("returns a package-manager bootstrap hint for required manager failures", () => {
it("returns a package-manager bootstrap hint for pnpm npm-bootstrap failures", () => {
const result = {
status: "error",
mode: "git",
reason: "required-manager-unavailable",
reason: "pnpm-npm-bootstrap-failed",
steps: [],
durationMs: 1,
} satisfies UpdateRunResult;
const hints = inferUpdateFailureHints(result);
expect(hints.join("\n")).toContain("requires its declared package manager");
expect(hints.join("\n")).toContain("Install the missing package manager manually");
expect(hints.join("\n")).toContain("bootstrap pnpm from npm");
expect(hints.join("\n")).toContain("Install pnpm manually");
});
it("returns a corepack hint when corepack is missing", () => {
const result = {
status: "error",
mode: "git",
reason: "pnpm-corepack-missing",
steps: [],
durationMs: 1,
} satisfies UpdateRunResult;
const hints = inferUpdateFailureHints(result);
expect(hints.join("\n")).toContain("corepack is missing");
expect(hints.join("\n")).toContain("Install pnpm manually");
});
it("returns EACCES hint for global update permission failures", () => {

View File

@@ -40,9 +40,27 @@ export function inferUpdateFailureHints(result: UpdateRunResult): string[] {
if (result.status !== "error") {
return [];
}
if (result.reason === "required-manager-unavailable") {
if (result.reason === "pnpm-corepack-missing") {
return [
"This checkout requires its declared package manager and the updater could not bootstrap it automatically.",
"This pnpm checkout could not auto-enable pnpm because corepack is missing.",
"Install pnpm manually or install Node with corepack available, then rerun the update command.",
];
}
if (result.reason === "pnpm-corepack-enable-failed") {
return [
"This pnpm checkout could not auto-enable pnpm via corepack.",
"Run `corepack enable` manually or install pnpm manually, then rerun the update command.",
];
}
if (result.reason === "pnpm-npm-bootstrap-failed") {
return [
"This pnpm checkout could not bootstrap pnpm from npm automatically.",
"Install pnpm manually, then rerun the update command.",
];
}
if (result.reason === "preferred-manager-unavailable") {
return [
"This checkout requires its declared package manager and the updater could not find it.",
"Install the missing package manager manually, then rerun the update command.",
];
}