Skip to content

Commit

Permalink
fix: handle endless streams piping (#936)
Browse files Browse the repository at this point in the history
closes #935
  • Loading branch information
antongolub authored Nov 8, 2024
1 parent 6eb540f commit 3f164e0
Show file tree
Hide file tree
Showing 3 changed files with 7 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
1 change: 1 addition & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,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 3f164e0

Please sign in to comment.