fix(windows): use cross-spawn for shim-backed commands (#18010)

This commit is contained in:
Luke Parker
2026-03-19 08:49:16 +10:00
committed by GitHub
parent 8ee939c741
commit 54ed87d53c
11 changed files with 126 additions and 38 deletions

View File

@@ -1,4 +1,5 @@
import { spawn as launch, type ChildProcess } from "child_process"
import { type ChildProcess } from "child_process"
import launch from "cross-spawn"
import { buffer } from "node:stream/consumers"
export namespace Process {
@@ -113,6 +114,7 @@ export namespace Process {
cwd: opts.cwd,
env: opts.env,
stdin: opts.stdin,
shell: opts.shell,
abort: opts.abort,
kill: opts.kill,
timeout: opts.timeout,
@@ -140,6 +142,20 @@ export namespace Process {
throw new RunFailedError(cmd, out.code, out.stdout, out.stderr)
}
export async function stop(proc: ChildProcess) {
if (process.platform !== "win32" || !proc.pid) {
proc.kill()
return
}
const out = await run(["taskkill", "/pid", String(proc.pid), "/T", "/F"], {
nothrow: true,
})
if (out.code === 0) return
proc.kill()
}
export async function text(cmd: string[], opts: RunOptions = {}): Promise<TextResult> {
const out = await run(cmd, opts)
return {