From ac449555f4607ea65895628164cb2835afdd0ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Wed, 28 Oct 2026 23:04:48 +0000 Subject: [PATCH] fix(cli): a Windows render no longer prints taskkill's already-exited message (#6698) * fix(cli): a Windows render no longer prints taskkill's already-exited message * fix(cli): fold the taskkill note into the hidden() doc comment --- packages/cli/src/utils/hideChildConsoles.test.ts | 9 +++++++++ packages/cli/src/utils/hideChildConsoles.ts | 9 ++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/utils/hideChildConsoles.test.ts b/packages/cli/src/utils/hideChildConsoles.test.ts index 30eefe3772..85a9e92d2b 100644 --- a/packages/cli/src/utils/hideChildConsoles.test.ts +++ b/packages/cli/src/utils/hideChildConsoles.test.ts @@ -65,6 +65,15 @@ describe("hideChildConsoles", () => { expect(calls[3]?.at(-1)).toBe(callback); }); + it("silences taskkill's stderr when its target is already gone", () => { + const calls = run("win32", (m) => { + m.execSync("taskkill /pid 1 /T /F"); + m.execSync("echo hi"); + }); + expect(calls[0]?.[2]).toEqual({ windowsHide: true, stdio: "ignore" }); + expect(calls[1]?.[2]).toEqual({ windowsHide: true }); + }); + it("leaves a caller that wants the window alone", () => { const calls = run("win32", (m) => m.spawn("browser", [], { windowsHide: false, detached: true }), diff --git a/packages/cli/src/utils/hideChildConsoles.ts b/packages/cli/src/utils/hideChildConsoles.ts index c94a76983d..5847d0d089 100644 --- a/packages/cli/src/utils/hideChildConsoles.ts +++ b/packages/cli/src/utils/hideChildConsoles.ts @@ -7,15 +7,18 @@ type ChildProcessModule = Record; const ENTRY_POINTS = ["spawn", "spawnSync", "exec", "execSync", "execFile", "execFileSync", "fork"]; -/** The call's arguments with `windowsHide: true` set unless the caller chose either way. */ +/** The call's arguments with `windowsHide: true` unless the caller chose; a taskkill's stderr is dropped too. */ function hidden(command: string, rest: unknown[]): unknown[] { + const defaults = /^taskkill\s/i.test(command) + ? { windowsHide: true, stdio: "ignore" } + : { windowsHide: true }; const args = [...rest]; const at = args.findIndex((arg) => arg && typeof arg === "object" && !Array.isArray(arg)); if (at >= 0) { - args[at] = { windowsHide: true, ...(args[at] as object) }; + args[at] = { ...defaults, ...(args[at] as object) }; } else { const callback = args.findIndex((arg) => typeof arg === "function"); - args.splice(callback < 0 ? args.length : callback, 0, { windowsHide: true }); + args.splice(callback < 0 ? args.length : callback, 0, defaults); } return [command, ...args]; }