Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: let detached opt be configurable #782

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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