File tree 4 files changed +13
-10
lines changed
4 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -319,12 +319,12 @@ export class ProcessPromise extends Promise<ProcessOutput> {
319
319
320
320
// Essentials
321
321
pipe ( dest : TemplateStringsArray , ...args : any [ ] ) : ProcessPromise
322
- pipe < D extends Writable > ( dest : D ) : D & PromiseLike < void >
322
+ pipe < D extends Writable > ( dest : D ) : D & PromiseLike < D >
323
323
pipe < D extends ProcessPromise > ( dest : D ) : D
324
324
pipe (
325
325
dest : Writable | ProcessPromise | TemplateStringsArray ,
326
326
...args : any [ ]
327
- ) : ( Writable & PromiseLike < void > ) | ProcessPromise {
327
+ ) : ( Writable & PromiseLike < Writable > ) | ProcessPromise {
328
328
if ( isStringLiteral ( dest , ...args ) )
329
329
return this . pipe ( $ ( dest as TemplateStringsArray , ...args ) )
330
330
if ( isString ( dest ) )
Original file line number Diff line number Diff line change @@ -453,21 +453,21 @@ export const once = <T extends (...args: any[]) => any>(fn: T) => {
453
453
454
454
export const promisifyStream = < S extends Writable > (
455
455
stream : S
456
- ) : S & PromiseLike < void > =>
457
- new Proxy ( stream as S & PromiseLike < void > , {
456
+ ) : S & PromiseLike < S > =>
457
+ new Proxy ( stream as S & PromiseLike < S > , {
458
458
get ( target , key ) {
459
459
if ( key === 'then' ) {
460
460
return ( res : any = noop , rej : any = noop ) =>
461
461
new Promise ( ( _res , _rej ) =>
462
462
target
463
- . once ( 'error' , ( ) => _rej ( rej ( ) ) )
464
- . once ( 'finish' , ( ) => _res ( res ( ) ) )
463
+ . once ( 'error' , ( e ) => _rej ( rej ( e ) ) )
464
+ . once ( 'finish' , ( ) => _res ( res ( target ) ) )
465
465
)
466
466
}
467
467
const value = Reflect . get ( target , key )
468
468
if ( key === 'pipe' && typeof value === 'function' ) {
469
469
return function ( ...args : any ) {
470
- return promisifyStream ( value . apply ( target , args ) as S )
470
+ return promisifyStream ( value . apply ( target , args ) )
471
471
}
472
472
}
473
473
return value
Original file line number Diff line number Diff line change @@ -27,7 +27,9 @@ expectType<ProcessPromise>(p.nothrow())
27
27
expectType < ProcessPromise > ( p . quiet ( ) )
28
28
expectType < ProcessPromise > ( p . pipe ( $ `cmd` ) )
29
29
expectType < ProcessPromise > ( p . pipe `cmd` )
30
- expectType < typeof process . stdout & PromiseLike < void > > ( p . pipe ( process . stdout ) )
30
+ expectType < typeof process . stdout & PromiseLike < typeof process . stdout > > (
31
+ p . pipe ( process . stdout )
32
+ )
31
33
expectType < ProcessPromise > ( p . stdio ( 'pipe' ) )
32
34
expectType < ProcessPromise > ( p . timeout ( '1s' ) )
33
35
expectType < Promise < void > > ( p . kill ( ) )
Original file line number Diff line number Diff line change @@ -411,6 +411,7 @@ describe('core', () => {
411
411
412
412
test ( '$ > stream' , async ( ) => {
413
413
const file = tempfile ( )
414
+ const fileStream = fs . createWriteStream ( file )
414
415
const p = $ `echo "hello"`
415
416
. pipe (
416
417
new Transform ( {
@@ -419,10 +420,10 @@ describe('core', () => {
419
420
} ,
420
421
} )
421
422
)
422
- . pipe ( fs . createWriteStream ( file ) )
423
+ . pipe ( fileStream )
423
424
424
425
assert . ok ( p instanceof WriteStream )
425
- assert . equal ( await p , undefined )
426
+ assert . equal ( await p , fileStream )
426
427
assert . equal ( ( await fs . readFile ( file ) ) . toString ( ) , 'HELLO\n' )
427
428
await fs . rm ( file )
428
429
} )
You can’t perform that action at this time.
0 commit comments