Skip to content

Commit b52bcd9

Browse files
authored
feat: let detached opt be configurable (google#782)
* feat: let detached opt be configurable closes google#781 * fix: set `datached` opt to false by default
1 parent d397293 commit b52bcd9

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/core.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export interface Options {
6969
postfix: string
7070
quote: typeof quote
7171
quiet: boolean
72+
detached: boolean
7273
spawn: typeof spawn
7374
spawnSync: typeof spawnSync
7475
log: typeof log
@@ -102,12 +103,12 @@ export const defaults: Options = {
102103
prefix: '',
103104
postfix: '',
104105
quote: noquote,
106+
detached: false,
105107
spawn,
106108
spawnSync,
107109
log,
108110
kill,
109111
}
110-
const isWin = process.platform == 'win32'
111112

112113
export function usePowerShell() {
113114
$.shell = which.sync('powershell.exe')
@@ -256,7 +257,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
256257
spawnSync: $.spawnSync,
257258
stdio: self._stdio ?? $.stdio,
258259
sync: $[syncExec],
259-
detached: !isWin,
260+
detached: $.detached,
260261
run: (cb) => cb(),
261262
on: {
262263
start: () => {

test/core.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ describe('core', () => {
318318
})
319319

320320
test('abort() method works', async () => {
321-
const p = $`sleep 9999`
321+
const p = $({ detached: true })`sleep 999`
322322
setTimeout(() => p.abort(), 100)
323323

324324
try {
@@ -331,7 +331,7 @@ describe('core', () => {
331331

332332
test('accepts optional AbortController', async () => {
333333
const ac = new AbortController()
334-
const p = $({ ac })`sleep 9999`
334+
const p = $({ ac, detached: true })`sleep 999`
335335
setTimeout(() => ac.abort(), 100)
336336

337337
try {
@@ -345,7 +345,7 @@ describe('core', () => {
345345
test('accepts AbortController `signal` separately', async () => {
346346
const ac = new AbortController()
347347
const signal = ac.signal
348-
const p = $({ signal })`sleep 9999`
348+
const p = $({ signal, detached: true })`sleep 999`
349349
setTimeout(() => ac.abort(), 100)
350350

351351
try {
@@ -357,7 +357,7 @@ describe('core', () => {
357357
})
358358

359359
test('kill() method works', async () => {
360-
let p = $`sleep 9999`.nothrow()
360+
let p = $`sleep 999`.nothrow()
361361
setTimeout(() => {
362362
p.kill()
363363
}, 100)
@@ -471,7 +471,7 @@ describe('core', () => {
471471
test('timeout() works', async () => {
472472
let exitCode, signal
473473
try {
474-
await $`sleep 9999`.timeout(10, 'SIGKILL')
474+
await $`sleep 999`.timeout(10, 'SIGKILL')
475475
} catch (p) {
476476
exitCode = p.exitCode
477477
signal = p.signal

0 commit comments

Comments
 (0)