@@ -47,10 +47,10 @@ export function callTsProxy(tsCode, silent=false) {
4747 env : getEnvWithLocalBin ( currentDirectory ) ,
4848 } ) ;
4949 let stderr = "" ;
50- let stdoutLogs = [ ] ;
50+ let stdout = "" ;
5151
5252 child . stdout . on ( "data" , ( data ) => {
53- stdoutLogs . push ( data . toString ( ) ) ;
53+ stdout += data . toString ( ) ;
5454 } ) ;
5555
5656 child . stderr . on ( "data" , ( data ) => {
@@ -62,17 +62,18 @@ export function callTsProxy(tsCode, silent=false) {
6262 } ) ;
6363
6464 child . on ( "close" , ( code ) => {
65- const tsProxyResult = stdoutLogs . find ( log => log . includes ( '>>>>>>>' ) ) ;
66- if ( ! tsProxyResult ) {
67- reject ( new Error ( `Invalid JSON from tsproxy. stdout: ${ stdoutLogs . join ( "" ) } , stderr: ${ stderr } ` ) ) ;
65+ const resultStart = stdout . indexOf ( '>>>>>>>' ) ;
66+ const resultEnd = stdout . lastIndexOf ( '<<<<<<<' ) ;
67+ if ( resultStart === - 1 || resultEnd === - 1 || resultEnd < resultStart ) {
68+ reject ( new Error ( `Invalid JSON from tsproxy. stdout: ${ stdout } , stderr: ${ stderr } ` ) ) ;
6869 return ;
6970 }
70- const preparedStdout = tsProxyResult . slice ( tsProxyResult . indexOf ( '>>>>>>>' ) + 7 , tsProxyResult . lastIndexOf ( '<<<<<<<' ) ) ;
71- const preparedStdoutLogs = stdoutLogs . filter ( log => ! log . includes ( '>>>>>>>' ) ) ;
71+ const preparedStdout = stdout . slice ( resultStart + 7 , resultEnd ) ;
72+ const preparedStdoutLogs = stdout . slice ( 0 , resultStart ) ;
7273 if ( code === 0 ) {
7374 try {
74- for ( const log of preparedStdoutLogs ) {
75- console . log ( log ) ;
75+ if ( preparedStdoutLogs ) {
76+ process . stdout . write ( preparedStdoutLogs ) ;
7677 }
7778 const parsed = JSON . parse ( preparedStdout ) ;
7879 if ( ! silent ) {
0 commit comments