diff --git a/src/main/ts/spawn.ts b/src/main/ts/spawn.ts index 1188101..3fabaaa 100644 --- a/src/main/ts/spawn.ts +++ b/src/main/ts/spawn.ts @@ -49,6 +49,7 @@ export interface TSpawnCtxNormalized { ee: EventEmitter on: Partial ac: AbortController + signal: AbortController['signal'] shell: string | true | undefined spawn: typeof cp.spawn spawnSync: typeof cp.spawnSync @@ -73,6 +74,7 @@ export const normalizeCtx = (...ctxs: TSpawnCtx[]): TSpawnCtxNormalized => assig env: process.env, ee: new EventEmitter(), ac: new AbortController(), + get signal() { return this.ac.signal }, on: {}, detached: process.platform !== 'win32', shell: true, @@ -105,7 +107,7 @@ export class VoidWritable extends Transform { } } -export const buildSpawnOpts = ({spawnOpts, stdio, cwd, shell, input, env, detached, ac: {signal}}: TSpawnCtxNormalized) => ({ +export const buildSpawnOpts = ({spawnOpts, stdio, cwd, shell, input, env, detached, signal}: TSpawnCtxNormalized) => ({ ...spawnOpts, env, cwd, diff --git a/src/test/ts/spawn.test.ts b/src/test/ts/spawn.test.ts index 51f2772..f4679fc 100644 --- a/src/test/ts/spawn.test.ts +++ b/src/test/ts/spawn.test.ts @@ -51,9 +51,11 @@ describe('invoke()', () => { describe('normalizeCtx()', () => { it('normalizes ctx', () => { + const signal = new AbortController().signal const cwds = ['a', 'b', 'c'] const ctx = { cmd: 'foo', + signal, get cwd () { return cwds.shift() || process.cwd() }, @@ -62,6 +64,7 @@ describe('normalizeCtx()', () => { assert.equal(normalized.cwd, 'a') assert.equal(normalized.cwd, 'b') assert.equal(normalized.cwd, 'c') + assert.equal(normalized.signal, signal) assert.ok(normalized.ee instanceof EventEmitter) assert.ok(normalized.ac instanceof AbortController) })