From 008b9c80093f8e80b41ca04a983e94dd01e217bb Mon Sep 17 00:00:00 2001 From: puneetdixit200 <236133619+puneetdixit200@users.noreply.github.com> Date: Fri, 22 May 2026 13:30:24 +0530 Subject: [PATCH 1/2] Detach non-wait PowerShell launches --- index.js | 1 + test.js | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/index.js b/index.js index ada71e5..20f6944 100644 --- a/index.js +++ b/index.js @@ -207,6 +207,7 @@ const baseOpen = async options => { if (!options.wait) { // PowerShell will keep the parent process alive unless stdio is ignored. childProcessOptions.stdio = 'ignore'; + childProcessOptions.detached = true; } } else { if (app) { diff --git a/test.js b/test.js index 500b301..e8cd867 100644 --- a/test.js +++ b/test.js @@ -139,6 +139,47 @@ test('subprocess is spawned before promise resolves', async t => { t.true(childProcess.pid !== undefined && childProcess.pid !== null); }); +test.serial('detaches PowerShell launches when not waiting on Windows', async t => { + const originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform'); + const originalSpawn = childProcess.spawn; + + t.teardown(() => { + Object.defineProperty(process, 'platform', originalPlatform); + childProcess.spawn = originalSpawn; + }); + + Object.defineProperty(process, 'platform', {value: 'win32'}); + + let childProcessOptions; + let unrefCalled = false; + + childProcess.spawn = (...arguments_) => { + childProcessOptions = arguments_[2]; + + // eslint-disable-next-line unicorn/prefer-event-target + const fakeChild = new EventEmitter(); + fakeChild.unref = () => { + unrefCalled = true; + }; + + setImmediate(() => { + fakeChild.emit('spawn'); + }); + + return fakeChild; + }; + + const {default: windowsOpen} = await import(`./index.js?windows-detach=${Date.now()}`); + await windowsOpen('C:/coverage/index.html'); + + t.like(childProcessOptions, { + windowsVerbatimArguments: true, + stdio: 'ignore', + detached: true, + }); + t.true(unrefCalled); +}); + test.serial('app launches resolve before close without fallback', async t => { const originalSpawn = childProcess.spawn; t.teardown(() => { From 6b71ed215b074a0f1381bddaed750ed3d84cea74 Mon Sep 17 00:00:00 2001 From: Puneet Dixit <236133619+puneetdixit200@users.noreply.github.com> Date: Sat, 23 May 2026 01:38:51 +0530 Subject: [PATCH 2/2] Fix hidden detached PowerShell windows Set windowsHide when detaching non-wait PowerShell launches on Windows, and assert the spawn option in the Windows regression test. --- index.js | 1 + test.js | 1 + 2 files changed, 2 insertions(+) diff --git a/index.js b/index.js index 20f6944..bde547f 100644 --- a/index.js +++ b/index.js @@ -208,6 +208,7 @@ const baseOpen = async options => { // PowerShell will keep the parent process alive unless stdio is ignored. childProcessOptions.stdio = 'ignore'; childProcessOptions.detached = true; + childProcessOptions.windowsHide = true; } } else { if (app) { diff --git a/test.js b/test.js index e8cd867..384cfd2 100644 --- a/test.js +++ b/test.js @@ -176,6 +176,7 @@ test.serial('detaches PowerShell launches when not waiting on Windows', async t windowsVerbatimArguments: true, stdio: 'ignore', detached: true, + windowsHide: true, }); t.true(unrefCalled); });