fork-ts-checker-webpack-plugin 0.2.6 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +23 -3
- package/lib/CancellationToken.js +54 -64
- package/lib/FilesRegister.js +54 -64
- package/lib/FilesWatcher.js +58 -71
- package/lib/IncrementalChecker.js +172 -188
- package/lib/Message.js +2 -0
- package/lib/NormalizedMessage.js +162 -183
- package/lib/WorkResult.js +39 -44
- package/lib/WorkSet.js +21 -20
- package/lib/cluster.js +57 -78
- package/lib/formatter/codeframeFormatter.js +21 -37
- package/lib/formatter/defaultFormatter.js +15 -21
- package/lib/index.js +343 -414
- package/lib/service.js +34 -44
- package/package.json +17 -5
package/lib/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var path = require("path");
|
|
3
|
+
var process = require("process");
|
|
4
|
+
var childProcess = require("child_process");
|
|
5
|
+
var chalk = require("chalk");
|
|
6
|
+
var fs = require("fs");
|
|
7
|
+
var os = require("os");
|
|
8
|
+
var isString = require("lodash.isstring");
|
|
9
|
+
var isFunction = require("lodash.isfunction");
|
|
10
|
+
var CancellationToken = require("./CancellationToken");
|
|
11
|
+
var NormalizedMessage = require("./NormalizedMessage");
|
|
12
|
+
var createDefaultFormatter = require("./formatter/defaultFormatter");
|
|
13
|
+
var createCodeframeFormatter = require("./formatter/codeframeFormatter");
|
|
14
14
|
/**
|
|
15
15
|
* ForkTsCheckerWebpackPlugin
|
|
16
16
|
* Runs typescript type checker and linter (tslint) on separate process.
|
|
@@ -18,405 +18,334 @@ var createCodeframeFormatter = require('./formatter/codeframeFormatter');
|
|
|
18
18
|
*
|
|
19
19
|
* Options description in README.md
|
|
20
20
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.typescriptVersion = require('typescript').version;
|
|
60
|
-
this.tslintVersion = this.tslint ? require('tslint').Linter.VERSION : undefined;
|
|
61
|
-
}
|
|
62
|
-
module.exports = ForkTsCheckerWebpackPlugin;
|
|
63
|
-
|
|
64
|
-
ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT = 2048;
|
|
65
|
-
|
|
66
|
-
ForkTsCheckerWebpackPlugin.ONE_CPU = 1;
|
|
67
|
-
ForkTsCheckerWebpackPlugin.ALL_CPUS = os.cpus().length;
|
|
68
|
-
ForkTsCheckerWebpackPlugin.ONE_CPU_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 1);
|
|
69
|
-
ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 2);
|
|
70
|
-
|
|
71
|
-
ForkTsCheckerWebpackPlugin.createFormatter = function (type, options) {
|
|
72
|
-
switch (type) {
|
|
73
|
-
case 'default':
|
|
74
|
-
return createDefaultFormatter(options);
|
|
75
|
-
case 'codeframe':
|
|
76
|
-
return createCodeframeFormatter(options);
|
|
77
|
-
default:
|
|
78
|
-
throw new Error('Unknown "' + type + '" formatter. Available are: default, codeframe.');
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
ForkTsCheckerWebpackPlugin.prototype.apply = function (compiler) {
|
|
83
|
-
this.compiler = compiler;
|
|
84
|
-
|
|
85
|
-
this.tsconfigPath = this.computeContextPath(this.tsconfig);
|
|
86
|
-
this.tslintPath = this.tslint ? this.computeContextPath(this.tslint) : null;
|
|
87
|
-
this.watchPaths = this.watch.map(this.computeContextPath.bind(this));
|
|
88
|
-
|
|
89
|
-
// validate config
|
|
90
|
-
var tsconfigOk = fs.existsSync(this.tsconfigPath);
|
|
91
|
-
var tslintOk = !this.tslintPath || fs.existsSync(this.tslintPath);
|
|
92
|
-
|
|
93
|
-
// validate logger
|
|
94
|
-
if (this.logger) {
|
|
95
|
-
if (!this.logger.error || !this.logger.warn || !this.logger.info) {
|
|
96
|
-
throw new Error('Invalid logger object - doesn\'t provide `error`, `warn` or `info` method.');
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (tsconfigOk && tslintOk) {
|
|
101
|
-
this.pluginStart();
|
|
102
|
-
this.pluginStop();
|
|
103
|
-
this.pluginCompile();
|
|
104
|
-
this.pluginEmit();
|
|
105
|
-
this.pluginDone();
|
|
106
|
-
} else {
|
|
107
|
-
if (!tsconfigOk) {
|
|
108
|
-
throw new Error(
|
|
109
|
-
'Cannot find "' + this.tsconfigPath + '" file. Please check webpack and ForkTsCheckerWebpackPlugin configuration. \n' +
|
|
110
|
-
'Possible errors: \n' +
|
|
111
|
-
' - wrong `context` directory in webpack configuration' +
|
|
112
|
-
' (if `tsconfig` is not set or is a relative path in fork plugin configuration)\n' +
|
|
113
|
-
' - wrong `tsconfig` path in fork plugin configuration' +
|
|
114
|
-
' (should be a relative or absolute path)'
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
if (!tslintOk) {
|
|
118
|
-
throw new Error(
|
|
119
|
-
'Cannot find "' + this.tslintPath + '" file. Please check webpack and ForkTsCheckerWebpackPlugin configuration. \n' +
|
|
120
|
-
'Possible errors: \n' +
|
|
121
|
-
' - wrong `context` directory in webpack configuration' +
|
|
122
|
-
' (if `tslint` is not set or is a relative path in fork plugin configuration)\n' +
|
|
123
|
-
' - wrong `tslint` path in fork plugin configuration' +
|
|
124
|
-
' (should be a relative or absolute path)\n' +
|
|
125
|
-
' - `tslint` path is not set to false in fork plugin configuration' +
|
|
126
|
-
' (if you want to disable tslint support)'
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
ForkTsCheckerWebpackPlugin.prototype.computeContextPath = function (filePath) {
|
|
133
|
-
return path.isAbsolute(filePath) ? filePath : path.resolve(this.compiler.options.context, filePath);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
ForkTsCheckerWebpackPlugin.prototype.pluginStart = function () {
|
|
137
|
-
this.compiler.plugin('run', function (compiler, callback) {
|
|
138
|
-
this.isWatching = false;
|
|
139
|
-
callback();
|
|
140
|
-
}.bind(this));
|
|
141
|
-
|
|
142
|
-
this.compiler.plugin('watch-run', function (watching, callback) {
|
|
143
|
-
this.isWatching = true;
|
|
144
|
-
callback();
|
|
145
|
-
}.bind(this));
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
ForkTsCheckerWebpackPlugin.prototype.pluginStop = function () {
|
|
149
|
-
this.compiler.plugin('done', function () {
|
|
150
|
-
if (!this.isWatching) {
|
|
151
|
-
this.killService();
|
|
152
|
-
}
|
|
153
|
-
}.bind(this));
|
|
154
|
-
|
|
155
|
-
process.on('exit', function () {
|
|
156
|
-
this.killService();
|
|
157
|
-
}.bind(this));
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
ForkTsCheckerWebpackPlugin.prototype.pluginCompile = function () {
|
|
161
|
-
this.compiler.plugin('compile', function () {
|
|
162
|
-
if (this.cancellationToken) {
|
|
163
|
-
// request cancellation if there is not finished job
|
|
164
|
-
this.cancellationToken.requestCancellation();
|
|
165
|
-
this.compiler.applyPlugins('fork-ts-checker-cancel', this.cancellationToken);
|
|
166
|
-
}
|
|
167
|
-
this.checkDone = false;
|
|
168
|
-
this.compilationDone = false;
|
|
169
|
-
|
|
170
|
-
this.started = process.hrtime();
|
|
171
|
-
|
|
172
|
-
// create new token for current job
|
|
173
|
-
this.cancellationToken = new CancellationToken();
|
|
174
|
-
if (!this.service || !this.service.connected) {
|
|
175
|
-
this.spawnService();
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
try {
|
|
179
|
-
this.service.send(this.cancellationToken);
|
|
180
|
-
} catch (error) {
|
|
181
|
-
if (!this.silent && this.logger) {
|
|
182
|
-
this.logger.error(this.colors.red('Cannot start checker service: ' + (error ? error.toString() : 'Unknown error')));
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
this.compiler.applyPlugins('fork-ts-checker-service-start-error', error);
|
|
186
|
-
}
|
|
187
|
-
}.bind(this));
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
ForkTsCheckerWebpackPlugin.prototype.pluginEmit = function () {
|
|
191
|
-
this.compiler.plugin('emit', function (compilation, callback) {
|
|
192
|
-
if (this.isWatching && this.async) {
|
|
193
|
-
callback();
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
this.emitCallback = this.createEmitCallback(compilation, callback);
|
|
198
|
-
|
|
199
|
-
if (this.checkDone) {
|
|
200
|
-
this.emitCallback();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
this.compilationDone = true;
|
|
204
|
-
}.bind(this));
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
ForkTsCheckerWebpackPlugin.prototype.pluginDone = function () {
|
|
208
|
-
this.compiler.plugin('done', function () {
|
|
209
|
-
if (!this.isWatching || !this.async) {
|
|
210
|
-
return;
|
|
21
|
+
var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
22
|
+
function ForkTsCheckerWebpackPlugin(options) {
|
|
23
|
+
options = options || {};
|
|
24
|
+
this.options = Object.assign({}, options);
|
|
25
|
+
this.tsconfig = options.tsconfig || './tsconfig.json';
|
|
26
|
+
this.tslint = options.tslint ?
|
|
27
|
+
options.tslint === true ? './tslint.json' : options.tslint : undefined;
|
|
28
|
+
this.watch = isString(options.watch) ? [options.watch] : options.watch || [];
|
|
29
|
+
this.ignoreDiagnostics = options.ignoreDiagnostics || [];
|
|
30
|
+
this.ignoreLints = options.ignoreLints || [];
|
|
31
|
+
this.logger = options.logger || console;
|
|
32
|
+
this.silent = options.silent === true; // default false
|
|
33
|
+
this.async = options.async !== false; // default true
|
|
34
|
+
this.checkSyntacticErrors = options.checkSyntacticErrors === true; // default false
|
|
35
|
+
this.workersNumber = options.workers || ForkTsCheckerWebpackPlugin.ONE_CPU;
|
|
36
|
+
this.memoryLimit = options.memoryLimit || ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT;
|
|
37
|
+
this.useColors = options.colors !== false; // default true
|
|
38
|
+
this.colors = new chalk.constructor({ enabled: this.useColors });
|
|
39
|
+
this.formatter = (options.formatter && isFunction(options.formatter))
|
|
40
|
+
? options.formatter
|
|
41
|
+
: ForkTsCheckerWebpackPlugin.createFormatter(options.formatter || 'default', options.formatterOptions || {});
|
|
42
|
+
this.tsconfigPath = undefined;
|
|
43
|
+
this.tslintPath = undefined;
|
|
44
|
+
this.watchPaths = [];
|
|
45
|
+
this.compiler = undefined;
|
|
46
|
+
this.started = undefined;
|
|
47
|
+
this.elapsed = undefined;
|
|
48
|
+
this.cancellationToken = undefined;
|
|
49
|
+
this.isWatching = false;
|
|
50
|
+
this.checkDone = false;
|
|
51
|
+
this.compilationDone = false;
|
|
52
|
+
this.diagnostics = [];
|
|
53
|
+
this.lints = [];
|
|
54
|
+
this.emitCallback = this.createNoopEmitCallback();
|
|
55
|
+
this.doneCallback = this.createDoneCallback();
|
|
56
|
+
this.typescriptVersion = require('typescript').version;
|
|
57
|
+
this.tslintVersion = this.tslint ? require('tslint').Linter.VERSION : undefined;
|
|
211
58
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
this.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
this.
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
)
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
this.
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
this.
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
};
|
|
59
|
+
ForkTsCheckerWebpackPlugin.createFormatter = function (type, options) {
|
|
60
|
+
switch (type) {
|
|
61
|
+
case 'default':
|
|
62
|
+
return createDefaultFormatter();
|
|
63
|
+
case 'codeframe':
|
|
64
|
+
return createCodeframeFormatter(options);
|
|
65
|
+
default:
|
|
66
|
+
throw new Error('Unknown "' + type + '" formatter. Available are: default, codeframe.');
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
ForkTsCheckerWebpackPlugin.prototype.apply = function (compiler) {
|
|
70
|
+
this.compiler = compiler;
|
|
71
|
+
this.tsconfigPath = this.computeContextPath(this.tsconfig);
|
|
72
|
+
this.tslintPath = this.tslint ? this.computeContextPath(this.tslint) : null;
|
|
73
|
+
this.watchPaths = this.watch.map(this.computeContextPath.bind(this));
|
|
74
|
+
// validate config
|
|
75
|
+
var tsconfigOk = fs.existsSync(this.tsconfigPath);
|
|
76
|
+
var tslintOk = !this.tslintPath || fs.existsSync(this.tslintPath);
|
|
77
|
+
// validate logger
|
|
78
|
+
if (this.logger) {
|
|
79
|
+
if (!this.logger.error || !this.logger.warn || !this.logger.info) {
|
|
80
|
+
throw new Error('Invalid logger object - doesn\'t provide `error`, `warn` or `info` method.');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (tsconfigOk && tslintOk) {
|
|
84
|
+
this.pluginStart();
|
|
85
|
+
this.pluginStop();
|
|
86
|
+
this.pluginCompile();
|
|
87
|
+
this.pluginEmit();
|
|
88
|
+
this.pluginDone();
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
if (!tsconfigOk) {
|
|
92
|
+
throw new Error('Cannot find "' + this.tsconfigPath + '" file. Please check webpack and ForkTsCheckerWebpackPlugin configuration. \n' +
|
|
93
|
+
'Possible errors: \n' +
|
|
94
|
+
' - wrong `context` directory in webpack configuration' +
|
|
95
|
+
' (if `tsconfig` is not set or is a relative path in fork plugin configuration)\n' +
|
|
96
|
+
' - wrong `tsconfig` path in fork plugin configuration' +
|
|
97
|
+
' (should be a relative or absolute path)');
|
|
98
|
+
}
|
|
99
|
+
if (!tslintOk) {
|
|
100
|
+
throw new Error('Cannot find "' + this.tslintPath + '" file. Please check webpack and ForkTsCheckerWebpackPlugin configuration. \n' +
|
|
101
|
+
'Possible errors: \n' +
|
|
102
|
+
' - wrong `context` directory in webpack configuration' +
|
|
103
|
+
' (if `tslint` is not set or is a relative path in fork plugin configuration)\n' +
|
|
104
|
+
' - wrong `tslint` path in fork plugin configuration' +
|
|
105
|
+
' (should be a relative or absolute path)\n' +
|
|
106
|
+
' - `tslint` path is not set to false in fork plugin configuration' +
|
|
107
|
+
' (if you want to disable tslint support)');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
ForkTsCheckerWebpackPlugin.prototype.computeContextPath = function (filePath) {
|
|
112
|
+
return path.isAbsolute(filePath) ? filePath : path.resolve(this.compiler.options.context, filePath);
|
|
113
|
+
};
|
|
114
|
+
ForkTsCheckerWebpackPlugin.prototype.pluginStart = function () {
|
|
115
|
+
var _this = this;
|
|
116
|
+
this.compiler.plugin('run', function (_compiler, callback) {
|
|
117
|
+
_this.isWatching = false;
|
|
118
|
+
callback();
|
|
119
|
+
});
|
|
120
|
+
this.compiler.plugin('watch-run', function (_watching, callback) {
|
|
121
|
+
_this.isWatching = true;
|
|
122
|
+
callback();
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
ForkTsCheckerWebpackPlugin.prototype.pluginStop = function () {
|
|
126
|
+
var _this = this;
|
|
127
|
+
this.compiler.plugin('watch-close', function () {
|
|
128
|
+
_this.killService();
|
|
129
|
+
});
|
|
130
|
+
this.compiler.plugin('done', function () {
|
|
131
|
+
if (!_this.isWatching) {
|
|
132
|
+
_this.killService();
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
process.on('exit', function () {
|
|
136
|
+
_this.killService();
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
ForkTsCheckerWebpackPlugin.prototype.pluginCompile = function () {
|
|
140
|
+
var _this = this;
|
|
141
|
+
this.compiler.plugin('compile', function () {
|
|
142
|
+
_this.compiler.applyPluginsAsync('fork-ts-checker-service-before-start', function () {
|
|
143
|
+
if (_this.cancellationToken) {
|
|
144
|
+
// request cancellation if there is not finished job
|
|
145
|
+
_this.cancellationToken.requestCancellation();
|
|
146
|
+
_this.compiler.applyPlugins('fork-ts-checker-cancel', _this.cancellationToken);
|
|
147
|
+
}
|
|
148
|
+
_this.checkDone = false;
|
|
149
|
+
_this.compilationDone = false;
|
|
150
|
+
_this.started = process.hrtime();
|
|
151
|
+
// create new token for current job
|
|
152
|
+
_this.cancellationToken = new CancellationToken(undefined, undefined);
|
|
153
|
+
if (!_this.service || !_this.service.connected) {
|
|
154
|
+
_this.spawnService();
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
_this.service.send(_this.cancellationToken);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (!_this.silent && _this.logger) {
|
|
161
|
+
_this.logger.error(_this.colors.red('Cannot start checker service: ' + (error ? error.toString() : 'Unknown error')));
|
|
162
|
+
}
|
|
163
|
+
_this.compiler.applyPlugins('fork-ts-checker-service-start-error', error);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
ForkTsCheckerWebpackPlugin.prototype.pluginEmit = function () {
|
|
169
|
+
var _this = this;
|
|
170
|
+
this.compiler.plugin('emit', function (compilation, callback) {
|
|
171
|
+
if (_this.isWatching && _this.async) {
|
|
172
|
+
callback();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
_this.emitCallback = _this.createEmitCallback(compilation, callback);
|
|
176
|
+
if (_this.checkDone) {
|
|
177
|
+
_this.emitCallback();
|
|
178
|
+
}
|
|
179
|
+
_this.compilationDone = true;
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
ForkTsCheckerWebpackPlugin.prototype.pluginDone = function () {
|
|
183
|
+
var _this = this;
|
|
184
|
+
this.compiler.plugin('done', function () {
|
|
185
|
+
if (!_this.isWatching || !_this.async) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (_this.checkDone) {
|
|
189
|
+
_this.doneCallback();
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
if (_this.compiler) {
|
|
193
|
+
_this.compiler.applyPlugins('fork-ts-checker-waiting', _this.tslint !== false);
|
|
194
|
+
}
|
|
195
|
+
if (!_this.silent && _this.logger) {
|
|
196
|
+
_this.logger.info(_this.tslint
|
|
197
|
+
? 'Type checking and linting in progress...'
|
|
198
|
+
: 'Type checking in progress...');
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
_this.compilationDone = true;
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
ForkTsCheckerWebpackPlugin.prototype.spawnService = function () {
|
|
205
|
+
var _this = this;
|
|
206
|
+
this.service = childProcess.fork(path.resolve(__dirname, this.workersNumber > 1 ? './cluster.js' : './service.js'), [], {
|
|
207
|
+
execArgv: this.workersNumber > 1 ? [] : ['--max-old-space-size=' + this.memoryLimit],
|
|
208
|
+
env: Object.assign({}, process.env, {
|
|
209
|
+
TSCONFIG: this.tsconfigPath,
|
|
210
|
+
TSLINT: this.tslintPath || '',
|
|
211
|
+
WATCH: this.isWatching ? this.watchPaths.join('|') : '',
|
|
212
|
+
WORK_DIVISION: Math.max(1, this.workersNumber),
|
|
213
|
+
MEMORY_LIMIT: this.memoryLimit,
|
|
214
|
+
CHECK_SYNTACTIC_ERRORS: this.checkSyntacticErrors
|
|
215
|
+
}),
|
|
216
|
+
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
|
|
217
|
+
});
|
|
218
|
+
this.compiler.applyPlugins('fork-ts-checker-service-start', this.tsconfigPath, this.tslintPath, this.watchPaths, this.workersNumber, this.memoryLimit);
|
|
219
|
+
if (!this.silent && this.logger) {
|
|
220
|
+
this.logger.info('Starting type checking' + (this.tslint ? ' and linting' : '') + ' service...');
|
|
221
|
+
this.logger.info('Using ' + this.colors.bold(this.workersNumber === 1 ? '1 worker' : this.workersNumber + ' workers') +
|
|
222
|
+
' with ' + this.colors.bold(this.memoryLimit + 'MB') + ' memory limit');
|
|
223
|
+
if (this.watchPaths.length && this.isWatching) {
|
|
224
|
+
this.logger.info('Watching:' +
|
|
225
|
+
(this.watchPaths.length > 1 ? '\n' : ' ') +
|
|
226
|
+
this.watchPaths
|
|
227
|
+
.map(function (wpath) { return _this.colors.grey(wpath); })
|
|
228
|
+
.join('\n'));
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
this.service.on('message', function (message) { return _this.handleServiceMessage(message); });
|
|
232
|
+
this.service.on('exit', function (code, signal) { return _this.handleServiceExit(code, signal); });
|
|
233
|
+
};
|
|
234
|
+
ForkTsCheckerWebpackPlugin.prototype.killService = function () {
|
|
235
|
+
if (this.service) {
|
|
236
|
+
try {
|
|
237
|
+
if (this.cancellationToken) {
|
|
238
|
+
this.cancellationToken.cleanupCancellation();
|
|
239
|
+
}
|
|
240
|
+
this.service.kill();
|
|
241
|
+
this.service = undefined;
|
|
242
|
+
}
|
|
243
|
+
catch (e) {
|
|
244
|
+
if (this.logger && !this.silent) {
|
|
245
|
+
this.logger.error(e);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
ForkTsCheckerWebpackPlugin.prototype.handleServiceMessage = function (message) {
|
|
251
|
+
var _this = this;
|
|
252
|
+
if (this.cancellationToken) {
|
|
253
|
+
this.cancellationToken.cleanupCancellation();
|
|
254
|
+
// job is done - nothing to cancel
|
|
255
|
+
this.cancellationToken = undefined;
|
|
256
|
+
}
|
|
257
|
+
this.checkDone = true;
|
|
258
|
+
this.elapsed = process.hrtime(this.started);
|
|
259
|
+
this.diagnostics = message.diagnostics.map(NormalizedMessage.createFromJSON);
|
|
260
|
+
this.lints = message.lints.map(NormalizedMessage.createFromJSON);
|
|
261
|
+
if (this.ignoreDiagnostics.length) {
|
|
262
|
+
this.diagnostics = this.diagnostics.filter(function (diagnostic) {
|
|
263
|
+
return _this.ignoreDiagnostics.indexOf(parseInt(diagnostic.getCode(), 10)) === -1;
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
if (this.ignoreLints.length) {
|
|
267
|
+
this.lints = this.lints.filter(function (lint) {
|
|
268
|
+
return _this.ignoreLints.indexOf(lint.getCode()) === -1;
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
this.compiler.applyPlugins('fork-ts-checker-receive', this.diagnostics, this.lints);
|
|
272
|
+
if (this.compilationDone) {
|
|
273
|
+
(this.isWatching && this.async) ? this.doneCallback() : this.emitCallback();
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
ForkTsCheckerWebpackPlugin.prototype.handleServiceExit = function (_code, signal) {
|
|
277
|
+
if (signal === 'SIGABRT') {
|
|
278
|
+
// probably out of memory :/
|
|
279
|
+
if (this.compiler) {
|
|
280
|
+
this.compiler.applyPlugins('fork-ts-checker-service-out-of-memory');
|
|
281
|
+
}
|
|
282
|
+
if (!this.silent && this.logger) {
|
|
283
|
+
this.logger.error(this.colors.red('Type checking and linting aborted - probably out of memory. ' +
|
|
284
|
+
'Check `memoryLimit` option in ForkTsCheckerWebpackPlugin configuration.'));
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
ForkTsCheckerWebpackPlugin.prototype.createEmitCallback = function (compilation, callback) {
|
|
289
|
+
return function emitCallback() {
|
|
290
|
+
var elapsed = Math.round(this.elapsed[0] * 1E9 + this.elapsed[1]);
|
|
291
|
+
this.compiler.applyPlugins('fork-ts-checker-emit', this.diagnostics, this.lints, elapsed);
|
|
292
|
+
this.diagnostics.concat(this.lints).forEach(function (message) {
|
|
293
|
+
// webpack message format
|
|
294
|
+
var formatted = {
|
|
295
|
+
rawMessage: (message.getSeverity().toUpperCase() + ' ' + message.getFormattedCode() + ': ' +
|
|
296
|
+
message.getContent()),
|
|
297
|
+
message: '(' + message.getLine() + ',' + message.getCharacter() + '): ' + message.getContent(),
|
|
298
|
+
location: {
|
|
299
|
+
line: message.getLine(),
|
|
300
|
+
character: message.getCharacter()
|
|
301
|
+
},
|
|
302
|
+
file: message.getFile()
|
|
303
|
+
};
|
|
304
|
+
if (message.isWarningSeverity()) {
|
|
305
|
+
compilation.warnings.push(formatted);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
compilation.errors.push(formatted);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
callback();
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
ForkTsCheckerWebpackPlugin.prototype.createNoopEmitCallback = function () {
|
|
315
|
+
// tslint:disable-next-line:no-empty
|
|
316
|
+
return function noopEmitCallback() { };
|
|
317
|
+
};
|
|
318
|
+
ForkTsCheckerWebpackPlugin.prototype.createDoneCallback = function () {
|
|
319
|
+
return function doneCallback() {
|
|
320
|
+
var _this = this;
|
|
321
|
+
var elapsed = Math.round(this.elapsed[0] * 1E9 + this.elapsed[1]);
|
|
322
|
+
if (this.compiler) {
|
|
323
|
+
this.compiler.applyPlugins('fork-ts-checker-done', this.diagnostics, this.lints, elapsed);
|
|
324
|
+
}
|
|
325
|
+
if (!this.silent && this.logger) {
|
|
326
|
+
if (this.diagnostics.length || this.lints.length) {
|
|
327
|
+
(this.lints || []).concat(this.diagnostics).forEach(function (message) {
|
|
328
|
+
var formattedMessage = _this.formatter(message, _this.useColors);
|
|
329
|
+
message.isWarningSeverity() ? _this.logger.warn(formattedMessage) : _this.logger.error(formattedMessage);
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
if (!this.diagnostics.length) {
|
|
333
|
+
this.logger.info(this.colors.green('No type errors found'));
|
|
334
|
+
}
|
|
335
|
+
if (this.tslint && !this.lints.length) {
|
|
336
|
+
this.logger.info(this.colors.green('No lint errors found'));
|
|
337
|
+
}
|
|
338
|
+
this.logger.info('Version: typescript ' + this.colors.bold(this.typescriptVersion) +
|
|
339
|
+
(this.tslint ? ', tslint ' + this.colors.bold(this.tslintVersion) : ''));
|
|
340
|
+
this.logger.info('Time: ' + this.colors.bold(Math.round(elapsed / 1E6).toString()) + 'ms');
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT = 2048;
|
|
345
|
+
ForkTsCheckerWebpackPlugin.ONE_CPU = 1;
|
|
346
|
+
ForkTsCheckerWebpackPlugin.ALL_CPUS = os.cpus().length;
|
|
347
|
+
ForkTsCheckerWebpackPlugin.ONE_CPU_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 1);
|
|
348
|
+
ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 2);
|
|
349
|
+
return ForkTsCheckerWebpackPlugin;
|
|
350
|
+
}());
|
|
351
|
+
module.exports = ForkTsCheckerWebpackPlugin;
|