@@ -24,12 +24,13 @@ function ForkTsCheckerWebpackPlugin (options) {
24
24
this . ignoreLints = options . ignoreLints || [ ] ;
25
25
this . logger = options . logger || console ;
26
26
this . silent = ! ! options . silent ;
27
- this . workers = options . workers || ForkTsCheckerWebpackPlugin . ONE_CPU ;
27
+ this . workersNumber = options . workers || ForkTsCheckerWebpackPlugin . ONE_CPU ;
28
28
this . memoryLimit = options . memoryLimit || ForkTsCheckerWebpackPlugin . DEFAULT_MEMORY_LIMIT ;
29
29
30
30
this . tsconfigPath = undefined ;
31
31
this . tslintPath = undefined ;
32
32
this . watchPaths = [ ] ;
33
+ this . isWatching = false ;
33
34
this . compiler = undefined ;
34
35
this . colors = new chalk . constructor ( {
35
36
enabled : options . colors === undefined ? true : ! ! options . colors
@@ -75,6 +76,8 @@ ForkTsCheckerWebpackPlugin.prototype.apply = function (compiler) {
75
76
}
76
77
77
78
if ( tsconfigOk && tslintOk ) {
79
+ this . pluginStart ( ) ;
80
+ this . pluginStop ( ) ;
78
81
this . pluginCompile ( ) ;
79
82
80
83
if ( this . blockEmit ) {
@@ -113,11 +116,38 @@ ForkTsCheckerWebpackPlugin.prototype.computeContextPath = function (filePath) {
113
116
? filePath : path . resolve ( this . compiler . options . context , filePath ) ;
114
117
} ;
115
118
119
+ ForkTsCheckerWebpackPlugin . prototype . pluginStart = function ( ) {
120
+ this . compiler . plugin ( 'run' , function ( compiler , callback ) {
121
+ this . isWatching = false ;
122
+ callback ( ) ;
123
+ } . bind ( this ) ) ;
124
+
125
+ this . compiler . plugin ( 'watch-run' , function ( watching , callback ) {
126
+ this . isWatching = true ;
127
+ callback ( ) ;
128
+ } . bind ( this ) ) ;
129
+ } ;
130
+
131
+ ForkTsCheckerWebpackPlugin . prototype . pluginStop = function ( ) {
132
+ this . compiler . plugin ( 'done' , function ( ) {
133
+ if ( ! this . isWatching && this . service ) {
134
+ try {
135
+ this . service . kill ( ) ;
136
+ } catch ( e ) {
137
+ if ( this . logger && ! this . silent ) {
138
+ this . logger . error ( e ) ;
139
+ }
140
+ }
141
+ }
142
+ } . bind ( this ) ) ;
143
+ } ;
144
+
116
145
ForkTsCheckerWebpackPlugin . prototype . pluginCompile = function ( ) {
117
146
this . compiler . plugin ( 'compile' , function ( ) {
118
147
if ( this . cancellationToken ) {
119
148
// request cancellation if there is not finished job
120
149
this . cancellationToken . requestCancellation ( ) ;
150
+ this . compiler . applyPlugins ( 'fork-ts-checker-cancel' , this . cancellationToken ) ;
121
151
}
122
152
this . checkDone = false ;
123
153
this . compilationDone = false ;
@@ -171,27 +201,33 @@ ForkTsCheckerWebpackPlugin.prototype.pluginDone = function () {
171
201
172
202
ForkTsCheckerWebpackPlugin . prototype . spawnService = function ( ) {
173
203
this . service = childProcess . fork (
174
- path . resolve ( __dirname , this . workers > 1 ? './cluster.js' : './service.js' ) ,
204
+ path . resolve ( __dirname , this . workersNumber > 1 ? './cluster.js' : './service.js' ) ,
175
205
[ ] ,
176
206
{
177
- execArgv : this . workers > 1 ? [ ] : [ '--max-old-space-size=' + this . memoryLimit ] ,
207
+ execArgv : this . workersNumber > 1 ? [ ] : [ '--max-old-space-size=' + this . memoryLimit ] ,
178
208
env : {
179
209
TSCONFIG : this . tsconfigPath ,
180
210
TSLINT : this . tslintPath || '' ,
181
211
WATCH : this . watchPaths . join ( '|' ) ,
182
- WORK_DIVISION : Math . max ( 1 , this . workers ) ,
212
+ WORK_DIVISION : Math . max ( 1 , this . workersNumber ) ,
183
213
MEMORY_LIMIT : this . memoryLimit
184
214
} ,
185
215
stdio : [ 'inherit' , 'inherit' , 'inherit' , 'ipc' ]
186
216
}
187
217
) ;
188
-
189
- this . compiler . applyPlugins ( 'fork-ts-checker-service-start' ) ;
218
+ this . compiler . applyPlugins (
219
+ 'fork-ts-checker-service-start' ,
220
+ this . tsconfigPath ,
221
+ this . tslintPath ,
222
+ this . watchPaths ,
223
+ this . workersNumber ,
224
+ this . memoryLimit
225
+ ) ;
190
226
191
227
if ( ! this . silent && this . logger ) {
192
228
var message = 'Starting type checking' + ( this . tslint ? ' and linting' : '' ) + ' service...' ;
193
229
var performance = (
194
- 'Using ' + this . colors . bold ( this . workers === 1 ? '1 worker' : this . workers + ' workers' ) +
230
+ 'Using ' + this . colors . bold ( this . workersNumber === 1 ? '1 worker' : this . workersNumber + ' workers' ) +
195
231
' with ' + this . colors . bold ( this . memoryLimit + 'MB' ) + ' memory limit'
196
232
) ;
197
233
var lines = [ message , performance , this . colors . grey ( this . tsconfigPath ) ] ;
@@ -200,7 +236,7 @@ ForkTsCheckerWebpackPlugin.prototype.spawnService = function () {
200
236
}
201
237
202
238
this . logger . info ( lines . join ( '\n' ) ) ;
203
- if ( this . watchPaths . length ) {
239
+ if ( this . watchPaths . length && this . isWatching ) {
204
240
this . logger . info (
205
241
'Watching:' +
206
242
( this . watchPaths . length > 1 ? '\n' : ' ' ) +
@@ -239,6 +275,8 @@ ForkTsCheckerWebpackPlugin.prototype.handleServiceMessage = function (message) {
239
275
} . bind ( this ) ) ;
240
276
}
241
277
278
+ this . compiler . applyPlugins ( 'fork-ts-checker-receive' , this . diagnostics , this . lints ) ;
279
+
242
280
if ( this . compilationDone ) {
243
281
this . blockEmit ? this . emitCallback ( ) : this . doneCallback ( ) ;
244
282
}
@@ -263,6 +301,15 @@ ForkTsCheckerWebpackPlugin.prototype.handleServiceExit = function (code, signal)
263
301
264
302
ForkTsCheckerWebpackPlugin . prototype . createEmitCallback = function ( compilation , callback ) {
265
303
return function emitCallback ( ) {
304
+ var elapsed = Math . round ( this . elapsed [ 0 ] * 1E9 + this . elapsed [ 1 ] ) ;
305
+
306
+ this . compiler . applyPlugins (
307
+ 'fork-ts-checker-emit' ,
308
+ this . diagnostics ,
309
+ this . lints ,
310
+ elapsed
311
+ ) ;
312
+
266
313
this . diagnostics . concat ( this . lints ) . forEach ( function ( message ) {
267
314
// webpack message format
268
315
var formatted = {
0 commit comments