@@ -47,8 +47,8 @@ import {
47
47
log ,
48
48
isString ,
49
49
isStringLiteral ,
50
- bufToString ,
51
50
getLast ,
51
+ getLines ,
52
52
noop ,
53
53
once ,
54
54
parseBool ,
@@ -601,26 +601,19 @@ export class ProcessPromise extends Promise<ProcessOutput> {
601
601
602
602
// Async iterator API
603
603
async * [ Symbol . asyncIterator ] ( ) : AsyncIterator < string> {
604
- let last : string | undefined
605
- const getLines = ( chunk : Buffer | string ) => {
606
- const lines = ( ( last || '' ) + bufToString ( chunk ) ) . split ( '\n' )
607
- last = lines . pop ( )
608
- return lines
609
- }
604
+ const memo : ( string | undefined ) [ ] = [ ]
610
605
611
606
for ( const chunk of this . _zurk ! . store . stdout ) {
612
- const lines = getLines ( chunk )
613
- for ( const line of lines ) yield line
607
+ yield * getLines ( chunk , memo )
614
608
}
615
609
616
610
for await ( const chunk of this . stdout [ Symbol . asyncIterator ]
617
611
? this . stdout
618
612
: VoidStream . from ( this . stdout ) ) {
619
- const lines = getLines ( chunk )
620
- for ( const line of lines ) yield line
613
+ yield * getLines ( chunk , memo )
621
614
}
622
615
623
- if ( last ) yield last
616
+ if ( memo [ 0 ] ) yield memo [ 0 ]
624
617
625
618
if ( ( await this . exitCode ) !== 0 ) throw this . _output
626
619
}
@@ -766,16 +759,13 @@ export class ProcessOutput extends Error {
766
759
}
767
760
768
761
* [ Symbol . iterator ] ( ) : Iterator < string > {
769
- let buffer = ''
762
+ const memo : ( string | undefined ) [ ] = [ ]
770
763
771
764
for ( const chunk of this . _dto . store . stdall ) {
772
- buffer += chunk . toString ( )
773
- const lines = buffer . split ( / \r ? \n / )
774
- buffer = lines . pop ( ) ?? ''
775
- yield * lines
765
+ yield * getLines ( chunk , memo )
776
766
}
777
767
778
- if ( buffer ) yield buffer
768
+ if ( memo [ 0 ] ) yield memo [ 0 ]
779
769
}
780
770
781
771
static getExitMessage = formatExitMessage
0 commit comments