@@ -6,6 +6,12 @@ var fs = require('fs');
6
6
var path = require ( 'path' ) ;
7
7
var semver = require ( 'semver' ) ;
8
8
var tsc = null ;
9
+ var TscCompilationCompleteMessage = "watching for file changes" ;
10
+ var TscWatcherInfoMessages = [
11
+ "file change detected" ,
12
+ "starting incremental compilation" ,
13
+ TscCompilationCompleteMessage
14
+ ] ;
9
15
10
16
function getTypeScriptVersion ( typeScriptPath ) {
11
17
try {
@@ -30,7 +36,7 @@ function runTypeScriptCompiler(logger, projectDir, options) {
30
36
var peerTypescriptPath = path . join ( __dirname , '../../typescript' ) ;
31
37
var tscPath = path . join ( peerTypescriptPath , 'lib/tsc.js' ) ;
32
38
var typeScriptVersion = getTypeScriptVersion ( peerTypescriptPath ) ;
33
-
39
+
34
40
if ( fs . existsSync ( tscPath ) ) {
35
41
logger . info ( `Found peer TypeScript ${ typeScriptVersion } ` ) ;
36
42
} else {
@@ -56,6 +62,12 @@ function runTypeScriptCompiler(logger, projectDir, options) {
56
62
nodeArgs . push ( '--preserveWatchOutput' ) ;
57
63
}
58
64
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
+
59
71
logger . trace ( process . execPath , nodeArgs . join ( ' ' ) ) ;
60
72
tsc = spawn ( process . execPath , nodeArgs ) ;
61
73
@@ -71,24 +83,28 @@ function runTypeScriptCompiler(logger, projectDir, options) {
71
83
. join ( "\n" ) ;
72
84
73
85
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
+ }
76
97
77
98
if ( isTraceLogLevel ) {
78
- nodeArgs . push ( "--listEmittedFiles" ) ;
79
99
logger . trace ( filteredData ) ;
80
100
}
81
-
101
+
82
102
// https://github.com/Microsoft/TypeScript/blob/e53e56cf8212e45d0ebdd6affe462d161c7e0dc5/src/compiler/watch.ts#L160
83
103
if ( ! isTraceLogLevel && filteredData . indexOf ( "error" ) !== - 1 ) {
84
104
logger . info ( filteredData ) ;
85
105
}
86
106
}
87
107
88
- if ( options . watch && stringData . toLowerCase ( ) . indexOf ( "watching for file changes." ) !== - 1 && ! isResolved ) {
89
- isResolved = true ;
90
- resolve ( ) ;
91
- }
92
108
} ) ;
93
109
94
110
tsc . stderr . on ( 'data' , function ( data ) {
0 commit comments