| 7 | |
| 8 | export namespace Shell { |
| 9 | export async function killTree(proc: ChildProcess, opts?: { exited?: () => boolean }): Promise<void> { |
| 10 | const pid = proc.pid |
| 11 | if (!pid || opts?.exited?.()) return |
| 12 | |
| 13 | if (process.platform === "win32") { |
| 14 | await new Promise<void>((resolve) => { |
| 15 | const killer = spawn("taskkill", ["/pid", String(pid), "/f", "/t"], { stdio: "ignore" }) |
| 16 | killer.once("exit", () => resolve()) |
| 17 | killer.once("error", () => resolve()) |
| 18 | }) |
| 19 | return |
| 20 | } |
| 21 | |
| 22 | try { |
| 23 | process.kill(-pid, "SIGTERM") |
| 24 | await Bun.sleep(SIGKILL_TIMEOUT_MS) |
| 25 | if (!opts?.exited?.()) { |
| 26 | process.kill(-pid, "SIGKILL") |
| 27 | } |
| 28 | } catch (_e) { |
| 29 | proc.kill("SIGTERM") |
| 30 | await Bun.sleep(SIGKILL_TIMEOUT_MS) |
| 31 | if (!opts?.exited?.()) { |
| 32 | proc.kill("SIGKILL") |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | const BLACKLIST = new Set(["fish", "nu"]) |
| 37 | |
| 38 | function fallback() { |