From cbfc232011d79ae54e9bc99e6b41c59c0d6a47c0 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Sun, 7 Apr 2024 23:01:30 +0300 Subject: [PATCH] fix: provide stdio customization closes #5 --- src/main/ts/spawn.ts | 8 +++++--- src/test/ts/x.test.ts | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/ts/spawn.ts b/src/main/ts/spawn.ts index 3fabaaa..47a9636 100644 --- a/src/main/ts/spawn.ts +++ b/src/main/ts/spawn.ts @@ -36,6 +36,8 @@ export type TChild = ReturnType export type TInput = string | Buffer | Stream +export type IO = 'pipe' | 'ignore' | 'inherit' + export interface TSpawnCtxNormalized { id: string, cwd: string @@ -43,7 +45,7 @@ export interface TSpawnCtxNormalized { sync: boolean args: ReadonlyArray input: TInput | null - stdio: ['pipe', 'pipe', 'pipe'] + stdio: [IO, IO, IO] detached: boolean env: Record ee: EventEmitter @@ -182,12 +184,12 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => { }) processInput(child, c.input || c.stdin) - child.stdout.pipe(c.stdout).on('data', d => { + child.stdout?.pipe(c.stdout).on('data', d => { stdout.push(d) stdall.push(d) c.ee.emit('stdout', d, c) }) - child.stderr.pipe(c.stderr).on('data', d => { + child.stderr?.pipe(c.stderr).on('data', d => { stderr.push(d) stdall.push(d) c.ee.emit('stderr', d, c) diff --git a/src/test/ts/x.test.ts b/src/test/ts/x.test.ts index 61dbd5f..14f7ddb 100644 --- a/src/test/ts/x.test.ts +++ b/src/test/ts/x.test.ts @@ -55,6 +55,10 @@ describe('$()', () => { assert.equal((await sorted).toString(), '1\n2\n3\n4\n5') }) + it('handles custom stdio', async () => { + await $({stdio: ['inherit', 'inherit', 'inherit']})`ls` + }) + it('supports presets', () => { const $$ = $({sync: true, cmd: 'echo foo'}) const $$$ = $$({cmd: 'echo bar'})