fix(coding-agent): disable scripts during self-update

This commit is contained in:
Mario Zechner
2026-05-20 14:42:45 +02:00
parent 715c82ce04
commit a3ebcd2322
2 changed files with 47 additions and 32 deletions

View File

@@ -110,21 +110,21 @@ function getSelfUpdateCommandForMethod(
return undefined; return undefined;
case "pnpm": case "pnpm":
return makeSelfUpdateCommand( return makeSelfUpdateCommand(
makeSelfUpdateCommandStep("pnpm", ["install", "-g", updatePackageName]), makeSelfUpdateCommandStep("pnpm", ["install", "-g", "--ignore-scripts", updatePackageName]),
updatePackageName === installedPackageName updatePackageName === installedPackageName
? undefined ? undefined
: makeSelfUpdateCommandStep("pnpm", ["remove", "-g", installedPackageName]), : makeSelfUpdateCommandStep("pnpm", ["remove", "-g", installedPackageName]),
); );
case "yarn": case "yarn":
return makeSelfUpdateCommand( return makeSelfUpdateCommand(
makeSelfUpdateCommandStep("yarn", ["global", "add", updatePackageName]), makeSelfUpdateCommandStep("yarn", ["global", "add", "--ignore-scripts", updatePackageName]),
updatePackageName === installedPackageName updatePackageName === installedPackageName
? undefined ? undefined
: makeSelfUpdateCommandStep("yarn", ["global", "remove", installedPackageName]), : makeSelfUpdateCommandStep("yarn", ["global", "remove", installedPackageName]),
); );
case "bun": case "bun":
return makeSelfUpdateCommand( return makeSelfUpdateCommand(
makeSelfUpdateCommandStep("bun", ["install", "-g", updatePackageName]), makeSelfUpdateCommandStep("bun", ["install", "-g", "--ignore-scripts", updatePackageName]),
updatePackageName === installedPackageName updatePackageName === installedPackageName
? undefined ? undefined
: makeSelfUpdateCommandStep("bun", ["uninstall", "-g", installedPackageName]), : makeSelfUpdateCommandStep("bun", ["uninstall", "-g", installedPackageName]),
@@ -133,7 +133,13 @@ function getSelfUpdateCommandForMethod(
const [command = "npm", ...npmArgs] = npmCommand ?? []; const [command = "npm", ...npmArgs] = npmCommand ?? [];
const inferred = npmCommand?.length ? undefined : getInferredNpmInstall(); const inferred = npmCommand?.length ? undefined : getInferredNpmInstall();
const prefixArgs = [...npmArgs, ...(inferred ? ["--prefix", inferred.prefix] : [])]; const prefixArgs = [...npmArgs, ...(inferred ? ["--prefix", inferred.prefix] : [])];
const installStep = makeSelfUpdateCommandStep(command, [...prefixArgs, "install", "-g", updatePackageName]); const installStep = makeSelfUpdateCommandStep(command, [
...prefixArgs,
"install",
"-g",
"--ignore-scripts",
updatePackageName,
]);
const uninstallStep = const uninstallStep =
updatePackageName === installedPackageName updatePackageName === installedPackageName
? undefined ? undefined

View File

@@ -153,7 +153,7 @@ describe("detectInstallMethod", () => {
expect(detectInstallMethod()).toBe("pnpm"); expect(detectInstallMethod()).toBe("pnpm");
expect(getUpdateInstruction("@earendil-works/pi-coding-agent")).toBe( expect(getUpdateInstruction("@earendil-works/pi-coding-agent")).toBe(
"Run: pnpm install -g @earendil-works/pi-coding-agent", "Run: pnpm install -g --ignore-scripts @earendil-works/pi-coding-agent",
); );
}); });
@@ -175,8 +175,8 @@ describe("detectInstallMethod", () => {
expect(detectInstallMethod()).toBe("npm"); expect(detectInstallMethod()).toBe("npm");
expect(command).toEqual({ expect(command).toEqual({
command: "npm", command: "npm",
args: ["--prefix", prefix, "install", "-g", "@earendil-works/pi-coding-agent"], args: ["--prefix", prefix, "install", "-g", "--ignore-scripts", "@earendil-works/pi-coding-agent"],
display: `npm --prefix ${prefix} install -g @earendil-works/pi-coding-agent`, display: `npm --prefix ${prefix} install -g --ignore-scripts @earendil-works/pi-coding-agent`,
}); });
}); });
@@ -187,8 +187,8 @@ describe("detectInstallMethod", () => {
expect(command).toEqual({ expect(command).toEqual({
command: "npm", command: "npm",
args: ["--prefix", prefix, "install", "-g", "@new-scope/pi"], args: ["--prefix", prefix, "install", "-g", "--ignore-scripts", "@new-scope/pi"],
display: `npm --prefix ${prefix} uninstall -g @mariozechner/pi-coding-agent && npm --prefix ${prefix} install -g @new-scope/pi`, display: `npm --prefix ${prefix} uninstall -g @mariozechner/pi-coding-agent && npm --prefix ${prefix} install -g --ignore-scripts @new-scope/pi`,
steps: [ steps: [
{ {
command: "npm", command: "npm",
@@ -197,8 +197,8 @@ describe("detectInstallMethod", () => {
}, },
{ {
command: "npm", command: "npm",
args: ["--prefix", prefix, "install", "-g", "@new-scope/pi"], args: ["--prefix", prefix, "install", "-g", "--ignore-scripts", "@new-scope/pi"],
display: `npm --prefix ${prefix} install -g @new-scope/pi`, display: `npm --prefix ${prefix} install -g --ignore-scripts @new-scope/pi`,
}, },
], ],
}); });
@@ -211,8 +211,8 @@ describe("detectInstallMethod", () => {
expect(command).toEqual({ expect(command).toEqual({
command: "npm", command: "npm",
args: ["--prefix", prefix, "install", "-g", "@earendil-works/pi-coding-agent"], args: ["--prefix", prefix, "install", "-g", "--ignore-scripts", "@earendil-works/pi-coding-agent"],
display: `npm --prefix ${prefix} install -g @earendil-works/pi-coding-agent`, display: `npm --prefix ${prefix} install -g --ignore-scripts @earendil-works/pi-coding-agent`,
}); });
}); });
@@ -221,7 +221,14 @@ describe("detectInstallMethod", () => {
const command = getSelfUpdateCommand("@earendil-works/pi-coding-agent", []); const command = getSelfUpdateCommand("@earendil-works/pi-coding-agent", []);
expect(command?.args).toEqual(["--prefix", prefix, "install", "-g", "@earendil-works/pi-coding-agent"]); expect(command?.args).toEqual([
"--prefix",
prefix,
"install",
"-g",
"--ignore-scripts",
"@earendil-works/pi-coding-agent",
]);
}); });
test("quotes npm self-update display paths", () => { test("quotes npm self-update display paths", () => {
@@ -229,7 +236,9 @@ describe("detectInstallMethod", () => {
const command = getSelfUpdateCommand("@earendil-works/pi-coding-agent"); const command = getSelfUpdateCommand("@earendil-works/pi-coding-agent");
expect(command?.display).toBe(`npm --prefix "${prefix}" install -g @earendil-works/pi-coding-agent`); expect(command?.display).toBe(
`npm --prefix "${prefix}" install -g --ignore-scripts @earendil-works/pi-coding-agent`,
);
}); });
test("does not infer Windows npm custom prefixes from package paths", () => { test("does not infer Windows npm custom prefixes from package paths", () => {
@@ -239,7 +248,7 @@ describe("detectInstallMethod", () => {
expect(detectInstallMethod()).toBe("npm"); expect(detectInstallMethod()).toBe("npm");
expect(getUpdateInstruction("@earendil-works/pi-coding-agent")).toBe( expect(getUpdateInstruction("@earendil-works/pi-coding-agent")).toBe(
"Run: npm install -g @earendil-works/pi-coding-agent", "Run: npm install -g --ignore-scripts @earendil-works/pi-coding-agent",
); );
}); });
@@ -251,8 +260,8 @@ describe("detectInstallMethod", () => {
expect(detectInstallMethod()).toBe("bun"); expect(detectInstallMethod()).toBe("bun");
expect(command).toEqual({ expect(command).toEqual({
command: "bun", command: "bun",
args: ["install", "-g", "@earendil-works/pi-coding-agent"], args: ["install", "-g", "--ignore-scripts", "@earendil-works/pi-coding-agent"],
display: "bun install -g @earendil-works/pi-coding-agent", display: "bun install -g --ignore-scripts @earendil-works/pi-coding-agent",
}); });
}); });
@@ -264,8 +273,8 @@ describe("detectInstallMethod", () => {
expect(detectInstallMethod()).toBe("pnpm"); expect(detectInstallMethod()).toBe("pnpm");
expect(command).toEqual({ expect(command).toEqual({
command: "pnpm", command: "pnpm",
args: ["install", "-g", "@new-scope/pi"], args: ["install", "-g", "--ignore-scripts", "@new-scope/pi"],
display: "pnpm remove -g @mariozechner/pi-coding-agent && pnpm install -g @new-scope/pi", display: "pnpm remove -g @mariozechner/pi-coding-agent && pnpm install -g --ignore-scripts @new-scope/pi",
steps: [ steps: [
{ {
command: "pnpm", command: "pnpm",
@@ -274,8 +283,8 @@ describe("detectInstallMethod", () => {
}, },
{ {
command: "pnpm", command: "pnpm",
args: ["install", "-g", "@new-scope/pi"], args: ["install", "-g", "--ignore-scripts", "@new-scope/pi"],
display: "pnpm install -g @new-scope/pi", display: "pnpm install -g --ignore-scripts @new-scope/pi",
}, },
], ],
}); });
@@ -319,8 +328,8 @@ describe("detectInstallMethod", () => {
expect(detectInstallMethod()).toBe("pnpm"); expect(detectInstallMethod()).toBe("pnpm");
expect(command).toEqual({ expect(command).toEqual({
command: "pnpm", command: "pnpm",
args: ["install", "-g", packageName], args: ["install", "-g", "--ignore-scripts", packageName],
display: `pnpm install -g ${packageName}`, display: `pnpm install -g --ignore-scripts ${packageName}`,
}); });
}); });
@@ -332,8 +341,8 @@ describe("detectInstallMethod", () => {
expect(detectInstallMethod()).toBe("yarn"); expect(detectInstallMethod()).toBe("yarn");
expect(command).toEqual({ expect(command).toEqual({
command: "yarn", command: "yarn",
args: ["global", "add", "@new-scope/pi"], args: ["global", "add", "--ignore-scripts", "@new-scope/pi"],
display: "yarn global remove @mariozechner/pi-coding-agent && yarn global add @new-scope/pi", display: "yarn global remove @mariozechner/pi-coding-agent && yarn global add --ignore-scripts @new-scope/pi",
steps: [ steps: [
{ {
command: "yarn", command: "yarn",
@@ -342,8 +351,8 @@ describe("detectInstallMethod", () => {
}, },
{ {
command: "yarn", command: "yarn",
args: ["global", "add", "@new-scope/pi"], args: ["global", "add", "--ignore-scripts", "@new-scope/pi"],
display: "yarn global add @new-scope/pi", display: "yarn global add --ignore-scripts @new-scope/pi",
}, },
], ],
}); });
@@ -357,8 +366,8 @@ describe("detectInstallMethod", () => {
expect(detectInstallMethod()).toBe("bun"); expect(detectInstallMethod()).toBe("bun");
expect(command).toEqual({ expect(command).toEqual({
command: "bun", command: "bun",
args: ["install", "-g", "@new-scope/pi"], args: ["install", "-g", "--ignore-scripts", "@new-scope/pi"],
display: "bun uninstall -g @mariozechner/pi-coding-agent && bun install -g @new-scope/pi", display: "bun uninstall -g @mariozechner/pi-coding-agent && bun install -g --ignore-scripts @new-scope/pi",
steps: [ steps: [
{ {
command: "bun", command: "bun",
@@ -367,8 +376,8 @@ describe("detectInstallMethod", () => {
}, },
{ {
command: "bun", command: "bun",
args: ["install", "-g", "@new-scope/pi"], args: ["install", "-g", "--ignore-scripts", "@new-scope/pi"],
display: "bun install -g @new-scope/pi", display: "bun install -g --ignore-scripts @new-scope/pi",
}, },
], ],
}); });