Skip to content

Commit

Permalink
fix: handle endless streams piping
Browse files Browse the repository at this point in the history
closes #935
  • Loading branch information
antongolub committed Nov 8, 2024
1 parent 6eb540f commit ccd69ca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
from.pipe(dest.stdin)
return dest
}

from.pipe(dest)
from.once('end', () => dest.emit('end-piped-from')).pipe(dest)
return promisifyStream(dest)
}

Expand Down
2 changes: 2 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import path from 'node:path'
import fs from 'node:fs'
import { chalk } from './vendor-core.js'
import type { Writable } from 'node:stream'
import { pipeline } from 'node:stream/promises'

export { isStringLiteral } from './vendor-core.js'

Expand Down Expand Up @@ -462,6 +463,7 @@ export const promisifyStream = <S extends Writable>(
target
.once('error', (e) => _rej(rej(e)))
.once('finish', () => _res(res(target)))
.once('end-piped-from', () => _res(res(target)))
)
}
const value = Reflect.get(target, key)
Expand Down
5 changes: 5 additions & 0 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,11 @@ describe('core', () => {
assert.equal((await fs.readFile(file)).toString(), 'HELLO\n')
await fs.rm(file)
})

test('$ > stdout', async () => {
const p = $`echo 1`.pipe(process.stdout)
assert.equal(await p, process.stdout)
})
})

it('supports delayed piping', async () => {
Expand Down

0 comments on commit ccd69ca

Please sign in to comment.