( source: InstallSource, version: string, platform: NodeJS.Platform, )
| 482 | } |
| 483 | |
| 484 | export async function installUpdate( |
| 485 | source: InstallSource, |
| 486 | version: string, |
| 487 | platform: NodeJS.Platform, |
| 488 | ): Promise<void> { |
| 489 | const { cmd, args } = spawnForSource(source, version, platform); |
| 490 | await new Promise<void>((resolve, reject) => { |
| 491 | // Windows package managers (npm/pnpm/yarn) are .cmd shims. Since the |
| 492 | // CVE-2024-27980 fix, Node throws EINVAL when spawning a .cmd/.bat without |
| 493 | // a shell, so run through the shell on win32. The version is a validated |
| 494 | // semver and the package name is a constant, so args are shell-safe. |
| 495 | const child = spawn(cmd, [...args], { |
| 496 | stdio: 'inherit', |
| 497 | shell: platform === 'win32' ? true : undefined, |
| 498 | }); |
| 499 | child.once('error', reject); |
| 500 | child.once('exit', (code, signal) => { |
| 501 | if (code === 0) { |
| 502 | resolve(); |
| 503 | return; |
| 504 | } |
| 505 | const detail = signal !== null ? `signal ${signal}` : `code ${String(code)}`; |
| 506 | reject(new Error(`${cmd} exited with ${detail}`)); |
| 507 | }); |
| 508 | }); |
| 509 | } |
| 510 | |
| 511 | async function startBackgroundInstall( |
| 512 | state: UpdateInstallState, |
no test coverage detected