Skip to content

Commit

Permalink
feat: let detached opt be configurable (#782)
Browse files Browse the repository at this point in the history
* feat: let detached opt be configurable

closes #781

* fix: set `datached` opt to false by default
  • Loading branch information
antongolub committed Apr 18, 2024
1 parent d397293 commit b52bcd9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -256,7 +257,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
spawnSync: $.spawnSync,
stdio: self._stdio ?? $.stdio,
sync: $[syncExec],
detached: !isWin,
detached: $.detached,
run: (cb) => cb(),
on: {
start: () => {
Expand Down
10 changes: 5 additions & 5 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b52bcd9

Please sign in to comment.