Skip to content

Commit

Permalink
fix: provide stdio customization
Browse files Browse the repository at this point in the history
closes #5
  • Loading branch information
antongolub committed Apr 7, 2024
1 parent 6a8b008 commit cbfc232
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/ts/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ export type TChild = ReturnType<typeof cp.spawn>

export type TInput = string | Buffer | Stream

export type IO = 'pipe' | 'ignore' | 'inherit'

export interface TSpawnCtxNormalized {
id: string,
cwd: string
cmd: string
sync: boolean
args: ReadonlyArray<string>
input: TInput | null
stdio: ['pipe', 'pipe', 'pipe']
stdio: [IO, IO, IO]
detached: boolean
env: Record<string, string | undefined>
ee: EventEmitter
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/test/ts/x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
Expand Down

0 comments on commit cbfc232

Please sign in to comment.