From b52bcd9c52750d34be0fd0e1924d1a2756466c3d Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Thu, 18 Apr 2024 16:55:59 +0300 Subject: [PATCH] feat: let `detached` opt be configurable (#782) * feat: let detached opt be configurable closes #781 * fix: set `datached` opt to false by default --- src/core.ts | 5 +++-- test/core.test.js | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core.ts b/src/core.ts index 28e838496d..907f511cc2 100644 --- a/src/core.ts +++ b/src/core.ts @@ -69,6 +69,7 @@ export interface Options { postfix: string quote: typeof quote quiet: boolean + detached: boolean spawn: typeof spawn spawnSync: typeof spawnSync log: typeof log @@ -102,12 +103,12 @@ export const defaults: Options = { prefix: '', postfix: '', quote: noquote, + detached: false, spawn, spawnSync, log, kill, } -const isWin = process.platform == 'win32' export function usePowerShell() { $.shell = which.sync('powershell.exe') @@ -256,7 +257,7 @@ export class ProcessPromise extends Promise { spawnSync: $.spawnSync, stdio: self._stdio ?? $.stdio, sync: $[syncExec], - detached: !isWin, + detached: $.detached, run: (cb) => cb(), on: { start: () => { diff --git a/test/core.test.js b/test/core.test.js index edadae7bb2..d850617d47 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -318,7 +318,7 @@ describe('core', () => { }) test('abort() method works', async () => { - const p = $`sleep 9999` + const p = $({ detached: true })`sleep 999` setTimeout(() => p.abort(), 100) try { @@ -331,7 +331,7 @@ describe('core', () => { test('accepts optional AbortController', async () => { const ac = new AbortController() - const p = $({ ac })`sleep 9999` + const p = $({ ac, detached: true })`sleep 999` setTimeout(() => ac.abort(), 100) try { @@ -345,7 +345,7 @@ describe('core', () => { test('accepts AbortController `signal` separately', async () => { const ac = new AbortController() const signal = ac.signal - const p = $({ signal })`sleep 9999` + const p = $({ signal, detached: true })`sleep 999` setTimeout(() => ac.abort(), 100) try { @@ -357,7 +357,7 @@ describe('core', () => { }) test('kill() method works', async () => { - let p = $`sleep 9999`.nothrow() + let p = $`sleep 999`.nothrow() setTimeout(() => { p.kill() }, 100) @@ -471,7 +471,7 @@ describe('core', () => { test('timeout() works', async () => { let exitCode, signal try { - await $`sleep 9999`.timeout(10, 'SIGKILL') + await $`sleep 999`.timeout(10, 'SIGKILL') } catch (p) { exitCode = p.exitCode signal = p.signal