@@ -6,6 +6,12 @@ var fs = require('fs');
66var path = require ( 'path' ) ;
77var semver = require ( 'semver' ) ;
88var tsc = null ;
9+ var TscCompilationCompleteMessage = "watching for file changes" ;
10+ var TscWatcherInfoMessages = [
11+ "file change detected" ,
12+ "starting incremental compilation" ,
13+ TscCompilationCompleteMessage
14+ ] ;
915
1016function getTypeScriptVersion ( typeScriptPath ) {
1117 try {
@@ -30,7 +36,7 @@ function runTypeScriptCompiler(logger, projectDir, options) {
3036 var peerTypescriptPath = path . join ( __dirname , '../../typescript' ) ;
3137 var tscPath = path . join ( peerTypescriptPath , 'lib/tsc.js' ) ;
3238 var typeScriptVersion = getTypeScriptVersion ( peerTypescriptPath ) ;
33-
39+
3440 if ( fs . existsSync ( tscPath ) ) {
3541 logger . info ( `Found peer TypeScript ${ typeScriptVersion } ` ) ;
3642 } else {
@@ -56,6 +62,12 @@ function runTypeScriptCompiler(logger, projectDir, options) {
5662 nodeArgs . push ( '--preserveWatchOutput' ) ;
5763 }
5864
65+ const logLevel = logger . getLevel ( ) ;
66+ const isTraceLogLevel = logLevel && / t r a c e / i. test ( logLevel ) ;
67+ if ( isTraceLogLevel ) {
68+ nodeArgs . push ( "--listEmittedFiles" ) ;
69+ }
70+
5971 logger . trace ( process . execPath , nodeArgs . join ( ' ' ) ) ;
6072 tsc = spawn ( process . execPath , nodeArgs ) ;
6173
@@ -71,24 +83,28 @@ function runTypeScriptCompiler(logger, projectDir, options) {
7183 . join ( "\n" ) ;
7284
7385 if ( filteredData ) {
74- const logLevel = logger . getLevel ( ) ;
75- const isTraceLogLevel = logLevel && / t r a c e / i. test ( logLevel ) ;
86+ var infoMessage = TscWatcherInfoMessages . find ( ( info ) => filteredData . toLowerCase ( ) . indexOf ( info ) !== - 1 ) ;
87+ if ( infoMessage ) {
88+ if ( options . watch && ! isResolved && infoMessage === TscCompilationCompleteMessage ) {
89+ isResolved = true ;
90+ resolve ( ) ;
91+ }
92+
93+ // ignore these info messages as they are spamming the CLI output
94+ // on each file generated in the platforms folder during prepare
95+ return ;
96+ }
7697
7798 if ( isTraceLogLevel ) {
78- nodeArgs . push ( "--listEmittedFiles" ) ;
7999 logger . trace ( filteredData ) ;
80100 }
81-
101+
82102 // https://github.com/Microsoft/TypeScript/blob/e53e56cf8212e45d0ebdd6affe462d161c7e0dc5/src/compiler/watch.ts#L160
83103 if ( ! isTraceLogLevel && filteredData . indexOf ( "error" ) !== - 1 ) {
84104 logger . info ( filteredData ) ;
85105 }
86106 }
87107
88- if ( options . watch && stringData . toLowerCase ( ) . indexOf ( "watching for file changes." ) !== - 1 && ! isResolved ) {
89- isResolved = true ;
90- resolve ( ) ;
91- }
92108 } ) ;
93109
94110 tsc . stderr . on ( 'data' , function ( data ) {
0 commit comments