@@ -97,8 +97,8 @@ function runScript(script, scriptArgs, inspectHost, inspectPort, childPrint) {
97
97
const child = spawn ( process . execPath , args ) ;
98
98
child . stdout . setEncoding ( 'utf8' ) ;
99
99
child . stderr . setEncoding ( 'utf8' ) ;
100
- child . stdout . on ( 'data' , childPrint ) ;
101
- child . stderr . on ( 'data' , childPrint ) ;
100
+ child . stdout . on ( 'data' , ( chunk ) => childPrint ( chunk , 'stdout' ) ) ;
101
+ child . stderr . on ( 'data' , ( chunk ) => childPrint ( chunk , 'stderr' ) ) ;
102
102
103
103
let output = '' ;
104
104
function waitForListenHint ( text ) {
@@ -231,7 +231,7 @@ class NodeInspector {
231
231
return this . client . connect ( port , host )
232
232
. then ( ( ) => {
233
233
debuglog ( 'connection established' ) ;
234
- this . stdout . write ( ' ok' ) ;
234
+ this . stdout . write ( ' ok\n ' ) ;
235
235
} , ( error ) => {
236
236
debuglog ( 'connect failed' , error ) ;
237
237
// If it's failed to connect 10 times then print failed message
@@ -245,7 +245,7 @@ class NodeInspector {
245
245
} ) ;
246
246
} ;
247
247
248
- this . print ( `connecting to ${ host } :${ port } ..` , true ) ;
248
+ this . print ( `connecting to ${ host } :${ port } ..` , false ) ;
249
249
return attemptConnect ( ) ;
250
250
} ) ;
251
251
}
@@ -259,23 +259,32 @@ class NodeInspector {
259
259
}
260
260
}
261
261
262
- print ( text , oneline = false ) {
262
+ print ( text , appendNewline = false ) {
263
263
this . clearLine ( ) ;
264
- this . stdout . write ( oneline ? text : `${ text } \n` ) ;
264
+ this . stdout . write ( appendNewline ? `${ text } \n` : text ) ;
265
265
}
266
266
267
- childPrint ( text ) {
268
- this . print (
269
- text . toString ( )
270
- . split ( / \r \n | \r | \n / g)
271
- . filter ( ( chunk ) => ! ! chunk )
272
- . map ( ( chunk ) => `< ${ chunk } ` )
273
- . join ( '\n' )
274
- ) ;
275
- if ( ! this . paused ) {
276
- this . repl . displayPrompt ( true ) ;
267
+ #stdioBuffers = { stdout : '' , stderr : '' } ;
268
+ childPrint ( text , which ) {
269
+ const lines = ( this . #stdioBuffers[ which ] + text )
270
+ . split ( / \r \n | \r | \n / g) ;
271
+
272
+ this . #stdioBuffers[ which ] = '' ;
273
+
274
+ if ( lines [ lines . length - 1 ] !== '' ) {
275
+ this . #stdioBuffers[ which ] = lines . pop ( ) ;
276
+ }
277
+
278
+ const textToPrint = lines . map ( ( chunk ) => `< ${ chunk } ` ) . join ( '\n' ) ;
279
+
280
+ if ( lines . length ) {
281
+ this . print ( textToPrint , true ) ;
282
+ if ( ! this . paused ) {
283
+ this . repl . displayPrompt ( true ) ;
284
+ }
277
285
}
278
- if ( / W a i t i n g f o r t h e d e b u g g e r t o d i s c o n n e c t \. \. \. \n $ / . test ( text ) ) {
286
+
287
+ if ( textToPrint . endsWith ( 'Waiting for the debugger to disconnect...\n' ) ) {
279
288
this . killChild ( ) ;
280
289
}
281
290
}
0 commit comments