@@ -16,38 +16,30 @@ var NormalizedMessage = require('./NormalizedMessage');
16
16
* Options description in README.md
17
17
*/
18
18
function ForkTsCheckerWebpackPlugin ( options ) {
19
- var tslintInstalled ;
20
-
21
- try {
22
- require . resolve ( 'tslint' ) ;
23
- tslintInstalled = true ;
24
- } catch ( error ) {
25
- tslintInstalled = false ;
26
- }
27
-
19
+ options = options || { } ;
28
20
this . options = Object . assign ( { } , options ) ;
21
+
29
22
this . tsconfig = options . tsconfig || './tsconfig.json' ;
30
- this . tslint = options . tslint === false ? false : ( options . tslint || ( tslintInstalled ? './tslint.json' : false ) ) ;
23
+ this . tslint = options . tslint ? isString ( options . tslint ) ? options . tslint : './tslint.json' : undefined ;
31
24
this . watch = isString ( options . watch ) ? [ options . watch ] : options . watch || [ ] ;
32
- this . blockEmit = ! ! options . blockEmit ;
33
25
this . ignoreDiagnostics = options . ignoreDiagnostics || [ ] ;
34
26
this . ignoreLints = options . ignoreLints || [ ] ;
35
27
this . logger = options . logger || console ;
36
28
this . silent = ! ! options . silent ;
37
29
this . workersNumber = options . workers || ForkTsCheckerWebpackPlugin . ONE_CPU ;
38
30
this . memoryLimit = options . memoryLimit || ForkTsCheckerWebpackPlugin . DEFAULT_MEMORY_LIMIT ;
31
+ this . colors = new chalk . constructor ( { enabled : options . colors === undefined ? true : ! ! options . colors } ) ;
39
32
40
33
this . tsconfigPath = undefined ;
41
34
this . tslintPath = undefined ;
42
35
this . watchPaths = [ ] ;
43
- this . isWatching = false ;
44
36
this . compiler = undefined ;
45
- this . colors = new chalk . constructor ( {
46
- enabled : options . colors === undefined ? true : ! ! options . colors
47
- } ) ;
37
+
48
38
this . started = undefined ;
49
39
this . elapsed = undefined ;
50
40
this . cancellationToken = undefined ;
41
+
42
+ this . isWatching = false ;
51
43
this . checkDone = false ;
52
44
this . compilationDone = false ;
53
45
this . diagnostics = [ ] ;
@@ -90,12 +82,8 @@ ForkTsCheckerWebpackPlugin.prototype.apply = function (compiler) {
90
82
this . pluginStart ( ) ;
91
83
this . pluginStop ( ) ;
92
84
this . pluginCompile ( ) ;
93
-
94
- if ( this . blockEmit ) {
95
- this . pluginAfterEmit ( ) ;
96
- } else {
97
- this . pluginDone ( ) ;
98
- }
85
+ this . pluginEmit ( ) ;
86
+ this . pluginDone ( ) ;
99
87
} else {
100
88
if ( ! tsconfigOk ) {
101
89
throw new Error (
@@ -123,8 +111,7 @@ ForkTsCheckerWebpackPlugin.prototype.apply = function (compiler) {
123
111
} ;
124
112
125
113
ForkTsCheckerWebpackPlugin . prototype . computeContextPath = function ( filePath ) {
126
- return path . isAbsolute ( filePath )
127
- ? filePath : path . resolve ( this . compiler . options . context , filePath ) ;
114
+ return path . isAbsolute ( filePath ) ? filePath : path . resolve ( this . compiler . options . context , filePath ) ;
128
115
} ;
129
116
130
117
ForkTsCheckerWebpackPlugin . prototype . pluginStart = function ( ) {
@@ -141,11 +128,13 @@ ForkTsCheckerWebpackPlugin.prototype.pluginStart = function () {
141
128
142
129
ForkTsCheckerWebpackPlugin . prototype . pluginStop = function ( ) {
143
130
this . compiler . plugin ( 'done' , function ( ) {
144
- this . killService ( ) ;
131
+ if ( ! this . isWatching ) {
132
+ this . killService ( ) ;
133
+ }
145
134
} . bind ( this ) ) ;
146
135
147
136
process . on ( 'exit' , function ( ) {
148
- this . killService ( true ) ;
137
+ this . killService ( ) ;
149
138
} . bind ( this ) ) ;
150
139
} ;
151
140
@@ -170,7 +159,7 @@ ForkTsCheckerWebpackPlugin.prototype.pluginCompile = function () {
170
159
try {
171
160
this . service . send ( this . cancellationToken ) ;
172
161
} catch ( error ) {
173
- if ( ! this . options . silent && this . logger ) {
162
+ if ( ! this . silent && this . logger ) {
174
163
this . logger . error ( this . colors . red ( 'Cannot start checker service: ' + ( error ? error . toString ( ) : 'Unknown error' ) ) ) ;
175
164
}
176
165
@@ -179,8 +168,13 @@ ForkTsCheckerWebpackPlugin.prototype.pluginCompile = function () {
179
168
} . bind ( this ) ) ;
180
169
} ;
181
170
182
- ForkTsCheckerWebpackPlugin . prototype . pluginAfterEmit = function ( ) {
183
- this . compiler . plugin ( 'after-emit' , function ( compilation , callback ) {
171
+ ForkTsCheckerWebpackPlugin . prototype . pluginEmit = function ( ) {
172
+ this . compiler . plugin ( 'emit' , function ( compilation , callback ) {
173
+ if ( this . isWatching ) {
174
+ callback ( ) ;
175
+ return ;
176
+ }
177
+
184
178
this . emitCallback = this . createEmitCallback ( compilation , callback ) ;
185
179
186
180
if ( this . checkDone ) {
@@ -193,6 +187,10 @@ ForkTsCheckerWebpackPlugin.prototype.pluginAfterEmit = function () {
193
187
194
188
ForkTsCheckerWebpackPlugin . prototype . pluginDone = function ( ) {
195
189
this . compiler . plugin ( 'done' , function ( ) {
190
+ if ( ! this . isWatching ) {
191
+ return ;
192
+ }
193
+
196
194
if ( this . checkDone ) {
197
195
this . doneCallback ( ) ;
198
196
} else {
@@ -224,13 +222,14 @@ ForkTsCheckerWebpackPlugin.prototype.spawnService = function () {
224
222
env : {
225
223
TSCONFIG : this . tsconfigPath ,
226
224
TSLINT : this . tslintPath || '' ,
227
- WATCH : this . watchPaths . join ( '|' ) ,
225
+ WATCH : this . isWatching ? this . watchPaths . join ( '|' ) : '' ,
228
226
WORK_DIVISION : Math . max ( 1 , this . workersNumber ) ,
229
227
MEMORY_LIMIT : this . memoryLimit
230
228
} ,
231
229
stdio : [ 'inherit' , 'inherit' , 'inherit' , 'ipc' ]
232
230
}
233
231
) ;
232
+
234
233
this . compiler . applyPlugins (
235
234
'fork-ts-checker-service-start' ,
236
235
this . tsconfigPath ,
@@ -241,22 +240,12 @@ ForkTsCheckerWebpackPlugin.prototype.spawnService = function () {
241
240
) ;
242
241
243
242
if ( ! this . silent && this . logger ) {
244
- var message = 'Starting type checking' + ( this . tslint ? ' and linting' : '' ) + ' service...' ;
245
- var performance = (
243
+ this . logger . info ( 'Starting type checking' + ( this . tslint ? ' and linting' : '' ) + ' service...' ) ;
244
+ this . logger . info (
246
245
'Using ' + this . colors . bold ( this . workersNumber === 1 ? '1 worker' : this . workersNumber + ' workers' ) +
247
246
' with ' + this . colors . bold ( this . memoryLimit + 'MB' ) + ' memory limit'
248
247
) ;
249
- var lines = [ message , performance ] ;
250
- if ( ! this . options . tsconfig ) {
251
- // auto-detect tsconfig path - print to the user to be sure that it's proper file
252
- lines . push ( this . colors . grey ( this . tsconfigPath ) ) ;
253
- }
254
- if ( this . tslint && ! this . options . tslint ) {
255
- // auto-detect tslint path - print to the user to be sure that it's proper file
256
- lines . push ( this . colors . grey ( this . tslintPath ) ) ;
257
- }
258
248
259
- this . logger . info ( lines . join ( '\n' ) ) ;
260
249
if ( this . watchPaths . length && this . isWatching ) {
261
250
this . logger . info (
262
251
'Watching:' +
@@ -272,11 +261,11 @@ ForkTsCheckerWebpackPlugin.prototype.spawnService = function () {
272
261
this . service . on ( 'exit' , this . handleServiceExit . bind ( this ) ) ;
273
262
} ;
274
263
275
- ForkTsCheckerWebpackPlugin . prototype . killService = function ( force ) {
276
- if ( ( force || ! this . isWatching ) && this . service ) {
264
+ ForkTsCheckerWebpackPlugin . prototype . killService = function ( ) {
265
+ if ( this . service ) {
277
266
try {
278
267
if ( this . cancellationToken ) {
279
- this . cancellationToken . requestCancellation ( ) ;
268
+ this . cancellationToken . cleanupCancellation ( ) ;
280
269
}
281
270
282
271
this . service . kill ( ) ;
@@ -316,7 +305,7 @@ ForkTsCheckerWebpackPlugin.prototype.handleServiceMessage = function (message) {
316
305
this . compiler . applyPlugins ( 'fork-ts-checker-receive' , this . diagnostics , this . lints ) ;
317
306
318
307
if ( this . compilationDone ) {
319
- this . blockEmit ? this . emitCallback ( ) : this . doneCallback ( ) ;
308
+ this . isWatching ? this . doneCallback ( ) : this . emitCallback ( ) ;
320
309
}
321
310
} ;
322
311
0 commit comments