| 150 | |
| 151 | /** Run `npm install -g <pkg>@latest` and return the exit code (0 = success). */ |
| 152 | export function runNpmUpdate(pkg: string): Promise<number> { |
| 153 | return new Promise((resolve) => { |
| 154 | // On Windows, npm is a .cmd shim; spawning it directly fails without shell:true. |
| 155 | const isWin = process.platform === "win32"; |
| 156 | const child = spawn("npm", ["install", "-g", `${pkg}@latest`], { |
| 157 | stdio: "inherit", |
| 158 | shell: isWin, |
| 159 | }); |
| 160 | child.on("error", () => resolve(1)); |
| 161 | child.on("close", (code) => resolve(typeof code === "number" ? code : 1)); |
| 162 | }); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Detect whether the running CLI is inside a global npm install, so the |