Skip to content

Commit 3f164e0

Browse files
authored
fix: handle endless streams piping (#936)
closes #935
1 parent 6eb540f commit 3f164e0

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/core.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
358358
from.pipe(dest.stdin)
359359
return dest
360360
}
361-
362-
from.pipe(dest)
361+
from.once('end', () => dest.emit('end-piped-from')).pipe(dest)
363362
return promisifyStream(dest)
364363
}
365364

src/util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ export const promisifyStream = <S extends Writable>(
462462
target
463463
.once('error', (e) => _rej(rej(e)))
464464
.once('finish', () => _res(res(target)))
465+
.once('end-piped-from', () => _res(res(target)))
465466
)
466467
}
467468
const value = Reflect.get(target, key)

test/core.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,11 @@ describe('core', () => {
427427
assert.equal((await fs.readFile(file)).toString(), 'HELLO\n')
428428
await fs.rm(file)
429429
})
430+
431+
test('$ > stdout', async () => {
432+
const p = $`echo 1`.pipe(process.stdout)
433+
assert.equal(await p, process.stdout)
434+
})
430435
})
431436

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

0 commit comments

Comments
 (0)