@@ -7,26 +7,19 @@ import {handleMaxBuffer} from './max-buffer.js';
77import { getStripFinalNewline } from './strip-newline.js' ;
88
99// Retrieve `result.stdout|stderr|all|stdio[*]`
10- export const getStreamOutput = async ( { stream, onStreamEnd, fdNumber, encoding, buffer, maxBuffer, lines, allMixed, stripFinalNewline, verboseInfo, streamInfo : { fileDescriptors} } ) => {
11- if ( shouldLogOutput ( {
12- stdioItems : fileDescriptors [ fdNumber ] ?. stdioItems ,
10+ export const getStreamOutput = async ( { stream, onStreamEnd, fdNumber, encoding, buffer, maxBuffer, lines, allMixed, stripFinalNewline, verboseInfo, streamInfo} ) => {
11+ const logPromise = logOutputAsync ( {
12+ stream,
13+ onStreamEnd,
14+ fdNumber,
1315 encoding,
16+ allMixed,
1417 verboseInfo,
15- fdNumber,
16- } ) ) {
17- const linesIterable = iterateForResult ( {
18- stream,
19- onStreamEnd,
20- lines : true ,
21- encoding,
22- stripFinalNewline : true ,
23- allMixed,
24- } ) ;
25- logLines ( linesIterable , stream , verboseInfo ) ;
26- }
18+ streamInfo,
19+ } ) ;
2720
2821 if ( ! buffer ) {
29- await resumeStream ( stream ) ;
22+ await Promise . all ( [ resumeStream ( stream ) , logPromise ] ) ;
3023 return ;
3124 }
3225
@@ -39,14 +32,39 @@ export const getStreamOutput = async ({stream, onStreamEnd, fdNumber, encoding,
3932 stripFinalNewline : stripFinalNewlineValue ,
4033 allMixed,
4134 } ) ;
42- return getStreamContents ( {
43- stream,
44- iterable,
35+ const [ output ] = await Promise . all ( [
36+ getStreamContents ( {
37+ stream,
38+ iterable,
39+ fdNumber,
40+ encoding,
41+ maxBuffer,
42+ lines,
43+ } ) ,
44+ logPromise ,
45+ ] ) ;
46+ return output ;
47+ } ;
48+
49+ const logOutputAsync = async ( { stream, onStreamEnd, fdNumber, encoding, allMixed, verboseInfo, streamInfo : { fileDescriptors} } ) => {
50+ if ( ! shouldLogOutput ( {
51+ stdioItems : fileDescriptors [ fdNumber ] ?. stdioItems ,
52+ encoding,
53+ verboseInfo,
4554 fdNumber,
55+ } ) ) {
56+ return ;
57+ }
58+
59+ const linesIterable = iterateForResult ( {
60+ stream,
61+ onStreamEnd,
62+ lines : true ,
4663 encoding,
47- maxBuffer ,
48- lines ,
64+ stripFinalNewline : true ,
65+ allMixed ,
4966 } ) ;
67+ await logLines ( linesIterable , stream , verboseInfo ) ;
5068} ;
5169
5270// When using `buffer: false`, users need to read `subprocess.stdout|stderr|all` right away
0 commit comments