fork-ts-checker-webpack-plugin 0.4.14 → 0.5.2
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 +23 -0
- package/README.md +3 -0
- package/lib/{types/CancellationToken.d.ts → CancellationToken.d.ts} +4 -4
- package/lib/CancellationToken.js +28 -27
- package/lib/{types/FilesRegister.d.ts → FilesRegister.d.ts} +9 -14
- package/lib/FilesRegister.js +24 -24
- package/lib/{types/FilesWatcher.d.ts → FilesWatcher.d.ts} +4 -7
- package/lib/FilesWatcher.js +27 -29
- package/lib/FsHelper.d.ts +5 -0
- package/lib/FsHelper.js +20 -0
- package/lib/IncrementalChecker.d.ts +34 -0
- package/lib/IncrementalChecker.js +97 -109
- package/lib/{types/Message.d.ts → Message.d.ts} +0 -0
- package/lib/{types/NormalizedMessage.d.ts → NormalizedMessage.d.ts} +16 -23
- package/lib/NormalizedMessage.js +76 -86
- package/lib/{types/VueProgram.d.ts → VueProgram.d.ts} +0 -0
- package/lib/VueProgram.js +62 -77
- package/lib/{types/WorkResult.d.ts → WorkResult.d.ts} +6 -6
- package/lib/WorkResult.js +22 -25
- package/lib/{types/WorkSet.d.ts → WorkSet.d.ts} +6 -6
- package/lib/WorkSet.js +6 -7
- package/lib/{types/cluster.d.ts → cluster.d.ts} +0 -0
- package/lib/cluster.js +19 -19
- package/lib/{types/formatter → formatter}/codeframeFormatter.d.ts +0 -0
- package/lib/formatter/codeframeFormatter.js +17 -16
- package/lib/{types/formatter → formatter}/defaultFormatter.d.ts +0 -0
- package/lib/formatter/defaultFormatter.js +9 -9
- package/lib/index.d.ts +98 -0
- package/lib/index.js +183 -192
- package/lib/{types/service.d.ts → service.d.ts} +0 -0
- package/lib/service.js +11 -11
- package/package.json +14 -18
- package/lib/types/IncrementalChecker.d.ts +0 -43
- package/lib/types/index.d.ts +0 -101
package/lib/index.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var checkerPluginName = 'fork-ts-checker-webpack-plugin';
|
|
17
|
-
var customHooks = {
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const process = require("process");
|
|
4
|
+
const childProcess = require("child_process");
|
|
5
|
+
const chalk_1 = require("chalk");
|
|
6
|
+
const micromatch = require("micromatch");
|
|
7
|
+
const os = require("os");
|
|
8
|
+
const CancellationToken_1 = require("./CancellationToken");
|
|
9
|
+
const NormalizedMessage_1 = require("./NormalizedMessage");
|
|
10
|
+
const defaultFormatter_1 = require("./formatter/defaultFormatter");
|
|
11
|
+
const codeframeFormatter_1 = require("./formatter/codeframeFormatter");
|
|
12
|
+
const FsHelper_1 = require("./FsHelper");
|
|
13
|
+
const tapable_1 = require("tapable");
|
|
14
|
+
const checkerPluginName = 'fork-ts-checker-webpack-plugin';
|
|
15
|
+
const customHooks = {
|
|
18
16
|
forkTsCheckerServiceBeforeStart: 'fork-ts-checker-service-before-start',
|
|
19
17
|
forkTsCheckerCancel: 'fork-ts-checker-cancel',
|
|
20
18
|
forkTsCheckerServiceStartError: 'fork-ts-checker-service-start-error',
|
|
@@ -32,8 +30,8 @@ var customHooks = {
|
|
|
32
30
|
*
|
|
33
31
|
* Options description in README.md
|
|
34
32
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
class ForkTsCheckerWebpackPlugin {
|
|
34
|
+
constructor(options) {
|
|
37
35
|
options = options || {};
|
|
38
36
|
this.options = Object.assign({}, options);
|
|
39
37
|
this.tsconfig = options.tsconfig || './tsconfig.json';
|
|
@@ -46,9 +44,9 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
46
44
|
? './tslint.json'
|
|
47
45
|
: options.tslint
|
|
48
46
|
: undefined;
|
|
49
|
-
this.
|
|
50
|
-
|
|
51
|
-
: options.watch || [];
|
|
47
|
+
this.tslintAutoFix = options.tslintAutoFix || false;
|
|
48
|
+
this.watch =
|
|
49
|
+
typeof options.watch === 'string' ? [options.watch] : options.watch || [];
|
|
52
50
|
this.ignoreDiagnostics = options.ignoreDiagnostics || [];
|
|
53
51
|
this.ignoreLints = options.ignoreLints || [];
|
|
54
52
|
this.reportFiles = options.reportFiles || [];
|
|
@@ -62,7 +60,7 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
62
60
|
this.useColors = options.colors !== false; // default true
|
|
63
61
|
this.colors = new chalk_1.default.constructor({ enabled: this.useColors });
|
|
64
62
|
this.formatter =
|
|
65
|
-
options.formatter &&
|
|
63
|
+
options.formatter && typeof options.formatter === 'function'
|
|
66
64
|
? options.formatter
|
|
67
65
|
: ForkTsCheckerWebpackPlugin.createFormatter(options.formatter || 'default', options.formatterOptions || {});
|
|
68
66
|
this.tsconfigPath = undefined;
|
|
@@ -85,7 +83,7 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
85
83
|
: undefined;
|
|
86
84
|
this.vue = options.vue === true; // default false
|
|
87
85
|
}
|
|
88
|
-
|
|
86
|
+
static createFormatter(type, options) {
|
|
89
87
|
switch (type) {
|
|
90
88
|
case 'default':
|
|
91
89
|
return defaultFormatter_1.createDefaultFormatter();
|
|
@@ -94,17 +92,17 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
94
92
|
default:
|
|
95
93
|
throw new Error('Unknown "' + type + '" formatter. Available are: default, codeframe.');
|
|
96
94
|
}
|
|
97
|
-
}
|
|
98
|
-
|
|
95
|
+
}
|
|
96
|
+
apply(compiler) {
|
|
99
97
|
this.compiler = compiler;
|
|
100
98
|
this.tsconfigPath = this.computeContextPath(this.tsconfig);
|
|
101
99
|
this.tslintPath = this.tslint
|
|
102
100
|
? this.computeContextPath(this.tslint)
|
|
103
|
-
:
|
|
101
|
+
: undefined;
|
|
104
102
|
this.watchPaths = this.watch.map(this.computeContextPath.bind(this));
|
|
105
103
|
// validate config
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
const tsconfigOk = FsHelper_1.FsHelper.existsSync(this.tsconfigPath);
|
|
105
|
+
const tslintOk = !this.tslintPath || FsHelper_1.FsHelper.existsSync(this.tslintPath);
|
|
108
106
|
// validate logger
|
|
109
107
|
if (this.logger) {
|
|
110
108
|
if (!this.logger.error || !this.logger.warn || !this.logger.info) {
|
|
@@ -145,20 +143,19 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
145
143
|
' (if you want to disable tslint support)');
|
|
146
144
|
}
|
|
147
145
|
}
|
|
148
|
-
}
|
|
149
|
-
|
|
146
|
+
}
|
|
147
|
+
computeContextPath(filePath) {
|
|
150
148
|
return path.isAbsolute(filePath)
|
|
151
149
|
? filePath
|
|
152
150
|
: path.resolve(this.compiler.options.context, filePath);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
_this.isWatching = false;
|
|
151
|
+
}
|
|
152
|
+
pluginStart() {
|
|
153
|
+
const run = (_compiler, callback) => {
|
|
154
|
+
this.isWatching = false;
|
|
158
155
|
callback();
|
|
159
156
|
};
|
|
160
|
-
|
|
161
|
-
|
|
157
|
+
const watchRun = (_compiler, callback) => {
|
|
158
|
+
this.isWatching = true;
|
|
162
159
|
callback();
|
|
163
160
|
};
|
|
164
161
|
if ('hooks' in this.compiler) {
|
|
@@ -171,15 +168,14 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
171
168
|
this.compiler.plugin('run', run);
|
|
172
169
|
this.compiler.plugin('watch-run', watchRun);
|
|
173
170
|
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
_this.killService();
|
|
171
|
+
}
|
|
172
|
+
pluginStop() {
|
|
173
|
+
const watchClose = () => {
|
|
174
|
+
this.killService();
|
|
179
175
|
};
|
|
180
|
-
|
|
181
|
-
if (!
|
|
182
|
-
|
|
176
|
+
const done = (_stats) => {
|
|
177
|
+
if (!this.isWatching) {
|
|
178
|
+
this.killService();
|
|
183
179
|
}
|
|
184
180
|
};
|
|
185
181
|
if ('hooks' in this.compiler) {
|
|
@@ -192,11 +188,11 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
192
188
|
this.compiler.plugin('watch-close', watchClose);
|
|
193
189
|
this.compiler.plugin('done', done);
|
|
194
190
|
}
|
|
195
|
-
process.on('exit',
|
|
196
|
-
|
|
191
|
+
process.on('exit', () => {
|
|
192
|
+
this.killService();
|
|
197
193
|
});
|
|
198
|
-
}
|
|
199
|
-
|
|
194
|
+
}
|
|
195
|
+
registerCustomHooks() {
|
|
200
196
|
if (this.compiler.hooks.forkTsCheckerServiceBeforeStart ||
|
|
201
197
|
this.compiler.hooks.forkTsCheckerCancel ||
|
|
202
198
|
this.compiler.hooks.forkTsCheckerServiceStartError ||
|
|
@@ -239,7 +235,7 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
239
235
|
'elapsed'
|
|
240
236
|
]);
|
|
241
237
|
// for backwards compatibility
|
|
242
|
-
this.compiler._pluginCompat.tap(checkerPluginName,
|
|
238
|
+
this.compiler._pluginCompat.tap(checkerPluginName, (options) => {
|
|
243
239
|
switch (options.name) {
|
|
244
240
|
case customHooks.forkTsCheckerServiceBeforeStart:
|
|
245
241
|
options.async = true;
|
|
@@ -256,82 +252,80 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
256
252
|
}
|
|
257
253
|
return undefined;
|
|
258
254
|
});
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
var _this = this;
|
|
255
|
+
}
|
|
256
|
+
pluginCompile() {
|
|
262
257
|
if ('hooks' in this.compiler) {
|
|
263
258
|
// webpack 4
|
|
264
|
-
this.compiler.hooks.compile.tap(checkerPluginName,
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (
|
|
259
|
+
this.compiler.hooks.compile.tap(checkerPluginName, () => {
|
|
260
|
+
this.compilationDone = false;
|
|
261
|
+
this.compiler.hooks.forkTsCheckerServiceBeforeStart.callAsync(() => {
|
|
262
|
+
if (this.cancellationToken) {
|
|
268
263
|
// request cancellation if there is not finished job
|
|
269
|
-
|
|
270
|
-
|
|
264
|
+
this.cancellationToken.requestCancellation();
|
|
265
|
+
this.compiler.hooks.forkTsCheckerCancel.call(this.cancellationToken);
|
|
271
266
|
}
|
|
272
|
-
|
|
273
|
-
|
|
267
|
+
this.checkDone = false;
|
|
268
|
+
this.started = process.hrtime();
|
|
274
269
|
// create new token for current job
|
|
275
|
-
|
|
276
|
-
if (!
|
|
277
|
-
|
|
270
|
+
this.cancellationToken = new CancellationToken_1.CancellationToken();
|
|
271
|
+
if (!this.service || !this.service.connected) {
|
|
272
|
+
this.spawnService();
|
|
278
273
|
}
|
|
279
274
|
try {
|
|
280
|
-
|
|
275
|
+
this.service.send(this.cancellationToken);
|
|
281
276
|
}
|
|
282
277
|
catch (error) {
|
|
283
|
-
if (!
|
|
284
|
-
|
|
278
|
+
if (!this.silent && this.logger) {
|
|
279
|
+
this.logger.error(this.colors.red('Cannot start checker service: ' +
|
|
285
280
|
(error ? error.toString() : 'Unknown error')));
|
|
286
281
|
}
|
|
287
|
-
|
|
282
|
+
this.compiler.hooks.forkTsCheckerServiceStartError.call(error);
|
|
288
283
|
}
|
|
289
284
|
});
|
|
290
285
|
});
|
|
291
286
|
}
|
|
292
287
|
else {
|
|
293
288
|
// webpack 2 / 3
|
|
294
|
-
this.compiler.plugin('compile',
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if (
|
|
289
|
+
this.compiler.plugin('compile', () => {
|
|
290
|
+
this.compilationDone = false;
|
|
291
|
+
this.compiler.applyPluginsAsync('fork-ts-checker-service-before-start', () => {
|
|
292
|
+
if (this.cancellationToken) {
|
|
298
293
|
// request cancellation if there is not finished job
|
|
299
|
-
|
|
300
|
-
|
|
294
|
+
this.cancellationToken.requestCancellation();
|
|
295
|
+
this.compiler.applyPlugins('fork-ts-checker-cancel', this.cancellationToken);
|
|
301
296
|
}
|
|
302
|
-
|
|
303
|
-
|
|
297
|
+
this.checkDone = false;
|
|
298
|
+
this.started = process.hrtime();
|
|
304
299
|
// create new token for current job
|
|
305
|
-
|
|
306
|
-
if (!
|
|
307
|
-
|
|
300
|
+
this.cancellationToken = new CancellationToken_1.CancellationToken(undefined, undefined);
|
|
301
|
+
if (!this.service || !this.service.connected) {
|
|
302
|
+
this.spawnService();
|
|
308
303
|
}
|
|
309
304
|
try {
|
|
310
|
-
|
|
305
|
+
this.service.send(this.cancellationToken);
|
|
311
306
|
}
|
|
312
307
|
catch (error) {
|
|
313
|
-
if (!
|
|
314
|
-
|
|
308
|
+
if (!this.silent && this.logger) {
|
|
309
|
+
this.logger.error(this.colors.red('Cannot start checker service: ' +
|
|
315
310
|
(error ? error.toString() : 'Unknown error')));
|
|
316
311
|
}
|
|
317
|
-
|
|
312
|
+
this.compiler.applyPlugins('fork-ts-checker-service-start-error', error);
|
|
318
313
|
}
|
|
319
314
|
});
|
|
320
315
|
});
|
|
321
316
|
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
if (_this.isWatching && _this.async) {
|
|
317
|
+
}
|
|
318
|
+
pluginEmit() {
|
|
319
|
+
const emit = (compilation, callback) => {
|
|
320
|
+
if (this.isWatching && this.async) {
|
|
327
321
|
callback();
|
|
328
322
|
return;
|
|
329
323
|
}
|
|
330
|
-
|
|
331
|
-
if (
|
|
332
|
-
|
|
324
|
+
this.emitCallback = this.createEmitCallback(compilation, callback);
|
|
325
|
+
if (this.checkDone) {
|
|
326
|
+
this.emitCallback();
|
|
333
327
|
}
|
|
334
|
-
|
|
328
|
+
this.compilationDone = true;
|
|
335
329
|
};
|
|
336
330
|
if ('hooks' in this.compiler) {
|
|
337
331
|
// webpack 4
|
|
@@ -341,56 +335,54 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
341
335
|
// webpack 2 / 3
|
|
342
336
|
this.compiler.plugin('emit', emit);
|
|
343
337
|
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
var _this = this;
|
|
338
|
+
}
|
|
339
|
+
pluginDone() {
|
|
347
340
|
if ('hooks' in this.compiler) {
|
|
348
341
|
// webpack 4
|
|
349
|
-
this.compiler.hooks.done.tap(checkerPluginName,
|
|
350
|
-
if (!
|
|
342
|
+
this.compiler.hooks.done.tap(checkerPluginName, (_stats) => {
|
|
343
|
+
if (!this.isWatching || !this.async) {
|
|
351
344
|
return;
|
|
352
345
|
}
|
|
353
|
-
if (
|
|
354
|
-
|
|
346
|
+
if (this.checkDone) {
|
|
347
|
+
this.doneCallback();
|
|
355
348
|
}
|
|
356
349
|
else {
|
|
357
|
-
if (
|
|
358
|
-
|
|
350
|
+
if (this.compiler) {
|
|
351
|
+
this.compiler.hooks.forkTsCheckerWaiting.call(this.tslint !== false);
|
|
359
352
|
}
|
|
360
|
-
if (!
|
|
361
|
-
|
|
353
|
+
if (!this.silent && this.logger) {
|
|
354
|
+
this.logger.info(this.tslint
|
|
362
355
|
? 'Type checking and linting in progress...'
|
|
363
356
|
: 'Type checking in progress...');
|
|
364
357
|
}
|
|
365
358
|
}
|
|
366
|
-
|
|
359
|
+
this.compilationDone = true;
|
|
367
360
|
});
|
|
368
361
|
}
|
|
369
362
|
else {
|
|
370
363
|
// webpack 2 / 3
|
|
371
|
-
this.compiler.plugin('done',
|
|
372
|
-
if (!
|
|
364
|
+
this.compiler.plugin('done', () => {
|
|
365
|
+
if (!this.isWatching || !this.async) {
|
|
373
366
|
return;
|
|
374
367
|
}
|
|
375
|
-
if (
|
|
376
|
-
|
|
368
|
+
if (this.checkDone) {
|
|
369
|
+
this.doneCallback();
|
|
377
370
|
}
|
|
378
371
|
else {
|
|
379
|
-
if (
|
|
380
|
-
|
|
372
|
+
if (this.compiler) {
|
|
373
|
+
this.compiler.applyPlugins('fork-ts-checker-waiting', this.tslint !== false);
|
|
381
374
|
}
|
|
382
|
-
if (!
|
|
383
|
-
|
|
375
|
+
if (!this.silent && this.logger) {
|
|
376
|
+
this.logger.info(this.tslint
|
|
384
377
|
? 'Type checking and linting in progress...'
|
|
385
378
|
: 'Type checking in progress...');
|
|
386
379
|
}
|
|
387
380
|
}
|
|
388
|
-
|
|
381
|
+
this.compilationDone = true;
|
|
389
382
|
});
|
|
390
383
|
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
var _this = this;
|
|
384
|
+
}
|
|
385
|
+
spawnService() {
|
|
394
386
|
this.service = childProcess.fork(path.resolve(__dirname, this.workersNumber > 1 ? './cluster.js' : './service.js'), [], {
|
|
395
387
|
execArgv: this.workersNumber > 1
|
|
396
388
|
? []
|
|
@@ -399,6 +391,7 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
399
391
|
TSCONFIG: this.tsconfigPath,
|
|
400
392
|
COMPILER_OPTIONS: JSON.stringify(this.compilerOptions),
|
|
401
393
|
TSLINT: this.tslintPath || '',
|
|
394
|
+
TSLINTAUTOFIX: this.tslintAutoFix,
|
|
402
395
|
WATCH: this.isWatching ? this.watchPaths.join('|') : '',
|
|
403
396
|
WORK_DIVISION: Math.max(1, this.workersNumber),
|
|
404
397
|
MEMORY_LIMIT: this.memoryLimit,
|
|
@@ -429,34 +422,30 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
429
422
|
if (this.watchPaths.length && this.isWatching) {
|
|
430
423
|
this.logger.info('Watching:' +
|
|
431
424
|
(this.watchPaths.length > 1 ? '\n' : ' ') +
|
|
432
|
-
this.watchPaths.map(
|
|
425
|
+
this.watchPaths.map(wpath => this.colors.grey(wpath)).join('\n'));
|
|
433
426
|
}
|
|
434
427
|
}
|
|
435
|
-
this.service.on('message',
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
if (this.cancellationToken) {
|
|
446
|
-
this.cancellationToken.cleanupCancellation();
|
|
447
|
-
}
|
|
448
|
-
this.service.kill();
|
|
449
|
-
this.service = undefined;
|
|
428
|
+
this.service.on('message', (message) => this.handleServiceMessage(message));
|
|
429
|
+
this.service.on('exit', (code, signal) => this.handleServiceExit(code, signal));
|
|
430
|
+
}
|
|
431
|
+
killService() {
|
|
432
|
+
if (!this.service) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
try {
|
|
436
|
+
if (this.cancellationToken) {
|
|
437
|
+
this.cancellationToken.cleanupCancellation();
|
|
450
438
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
439
|
+
this.service.kill();
|
|
440
|
+
this.service = undefined;
|
|
441
|
+
}
|
|
442
|
+
catch (e) {
|
|
443
|
+
if (this.logger && !this.silent) {
|
|
444
|
+
this.logger.error(e);
|
|
455
445
|
}
|
|
456
446
|
}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
var _this = this;
|
|
447
|
+
}
|
|
448
|
+
handleServiceMessage(message) {
|
|
460
449
|
if (this.cancellationToken) {
|
|
461
450
|
this.cancellationToken.cleanupCancellation();
|
|
462
451
|
// job is done - nothing to cancel
|
|
@@ -467,18 +456,16 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
467
456
|
this.diagnostics = message.diagnostics.map(NormalizedMessage_1.NormalizedMessage.createFromJSON);
|
|
468
457
|
this.lints = message.lints.map(NormalizedMessage_1.NormalizedMessage.createFromJSON);
|
|
469
458
|
if (this.ignoreDiagnostics.length) {
|
|
470
|
-
this.diagnostics = this.diagnostics.filter(
|
|
471
|
-
return _this.ignoreDiagnostics.indexOf(parseInt(diagnostic.getCode(), 10)) === -1;
|
|
472
|
-
});
|
|
459
|
+
this.diagnostics = this.diagnostics.filter(diagnostic => !this.ignoreDiagnostics.includes(parseInt(diagnostic.code, 10)));
|
|
473
460
|
}
|
|
474
461
|
if (this.ignoreLints.length) {
|
|
475
|
-
this.lints = this.lints.filter(
|
|
462
|
+
this.lints = this.lints.filter(lint => !this.ignoreLints.includes(lint.code));
|
|
476
463
|
}
|
|
477
464
|
if (this.reportFiles.length) {
|
|
478
|
-
|
|
465
|
+
const reportFilesPredicate = (diagnostic) => {
|
|
479
466
|
if (diagnostic.file) {
|
|
480
|
-
|
|
481
|
-
|
|
467
|
+
const relativeFileName = path.relative(this.compiler.options.context, diagnostic.file);
|
|
468
|
+
const matchResult = micromatch([relativeFileName], this.reportFiles);
|
|
482
469
|
if (matchResult.length === 0) {
|
|
483
470
|
return false;
|
|
484
471
|
}
|
|
@@ -499,30 +486,33 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
499
486
|
if (this.compilationDone) {
|
|
500
487
|
this.isWatching && this.async ? this.doneCallback() : this.emitCallback();
|
|
501
488
|
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
if (signal
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
// webpack 2 / 3
|
|
513
|
-
this.compiler.applyPlugins('fork-ts-checker-service-out-of-memory');
|
|
514
|
-
}
|
|
489
|
+
}
|
|
490
|
+
handleServiceExit(_code, signal) {
|
|
491
|
+
if (signal !== 'SIGABRT') {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
// probably out of memory :/
|
|
495
|
+
if (this.compiler) {
|
|
496
|
+
if ('hooks' in this.compiler) {
|
|
497
|
+
// webpack 4
|
|
498
|
+
this.compiler.hooks.forkTsCheckerServiceOutOfMemory.call();
|
|
515
499
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
500
|
+
else {
|
|
501
|
+
// webpack 2 / 3
|
|
502
|
+
this.compiler.applyPlugins('fork-ts-checker-service-out-of-memory');
|
|
519
503
|
}
|
|
520
504
|
}
|
|
521
|
-
|
|
522
|
-
|
|
505
|
+
if (!this.silent && this.logger) {
|
|
506
|
+
this.logger.error(this.colors.red('Type checking and linting aborted - probably out of memory. ' +
|
|
507
|
+
'Check `memoryLimit` option in ForkTsCheckerWebpackPlugin configuration.'));
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
createEmitCallback(compilation, callback) {
|
|
523
511
|
return function emitCallback() {
|
|
524
|
-
|
|
525
|
-
|
|
512
|
+
if (!this.elapsed) {
|
|
513
|
+
throw new Error('Execution order error');
|
|
514
|
+
}
|
|
515
|
+
const elapsed = Math.round(this.elapsed[0] * 1e9 + this.elapsed[1]);
|
|
526
516
|
if ('hooks' in this.compiler) {
|
|
527
517
|
// webpack 4
|
|
528
518
|
this.compiler.hooks.forkTsCheckerEmit.call(this.diagnostics, this.lints, elapsed);
|
|
@@ -531,20 +521,20 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
531
521
|
// webpack 2 / 3
|
|
532
522
|
this.compiler.applyPlugins('fork-ts-checker-emit', this.diagnostics, this.lints, elapsed);
|
|
533
523
|
}
|
|
534
|
-
this.diagnostics.concat(this.lints).forEach(
|
|
524
|
+
this.diagnostics.concat(this.lints).forEach(message => {
|
|
535
525
|
// webpack message format
|
|
536
|
-
|
|
537
|
-
rawMessage: message.
|
|
526
|
+
const formatted = {
|
|
527
|
+
rawMessage: message.severity.toUpperCase() +
|
|
538
528
|
' ' +
|
|
539
529
|
message.getFormattedCode() +
|
|
540
530
|
': ' +
|
|
541
|
-
message.
|
|
542
|
-
message:
|
|
531
|
+
message.content,
|
|
532
|
+
message: this.formatter(message, this.useColors),
|
|
543
533
|
location: {
|
|
544
|
-
line: message.
|
|
545
|
-
character: message.
|
|
534
|
+
line: message.line,
|
|
535
|
+
character: message.character
|
|
546
536
|
},
|
|
547
|
-
file: message.
|
|
537
|
+
file: message.file
|
|
548
538
|
};
|
|
549
539
|
if (message.isWarningSeverity()) {
|
|
550
540
|
compilation.warnings.push(formatted);
|
|
@@ -555,15 +545,17 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
555
545
|
});
|
|
556
546
|
callback();
|
|
557
547
|
};
|
|
558
|
-
}
|
|
559
|
-
|
|
548
|
+
}
|
|
549
|
+
createNoopEmitCallback() {
|
|
560
550
|
// tslint:disable-next-line:no-empty
|
|
561
551
|
return function noopEmitCallback() { };
|
|
562
|
-
}
|
|
563
|
-
|
|
552
|
+
}
|
|
553
|
+
createDoneCallback() {
|
|
564
554
|
return function doneCallback() {
|
|
565
|
-
|
|
566
|
-
|
|
555
|
+
if (!this.elapsed) {
|
|
556
|
+
throw new Error('Execution order error');
|
|
557
|
+
}
|
|
558
|
+
const elapsed = Math.round(this.elapsed[0] * 1e9 + this.elapsed[1]);
|
|
567
559
|
if (this.compiler) {
|
|
568
560
|
if ('hooks' in this.compiler) {
|
|
569
561
|
// webpack 4
|
|
@@ -576,11 +568,11 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
576
568
|
}
|
|
577
569
|
if (!this.silent && this.logger) {
|
|
578
570
|
if (this.diagnostics.length || this.lints.length) {
|
|
579
|
-
(this.lints || []).concat(this.diagnostics).forEach(
|
|
580
|
-
|
|
571
|
+
(this.lints || []).concat(this.diagnostics).forEach(message => {
|
|
572
|
+
const formattedMessage = this.formatter(message, this.useColors);
|
|
581
573
|
message.isWarningSeverity()
|
|
582
|
-
?
|
|
583
|
-
:
|
|
574
|
+
? this.logger.warn(formattedMessage)
|
|
575
|
+
: this.logger.error(formattedMessage);
|
|
584
576
|
});
|
|
585
577
|
}
|
|
586
578
|
if (!this.diagnostics.length) {
|
|
@@ -599,12 +591,11 @@ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
|
|
|
599
591
|
'ms');
|
|
600
592
|
}
|
|
601
593
|
};
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
}());
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT = 2048;
|
|
597
|
+
ForkTsCheckerWebpackPlugin.ONE_CPU = 1;
|
|
598
|
+
ForkTsCheckerWebpackPlugin.ALL_CPUS = os.cpus && os.cpus() ? os.cpus().length : 1;
|
|
599
|
+
ForkTsCheckerWebpackPlugin.ONE_CPU_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 1);
|
|
600
|
+
ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 2);
|
|
610
601
|
module.exports = ForkTsCheckerWebpackPlugin;
|
|
File without changes
|
package/lib/service.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const process = require("process");
|
|
4
|
+
const ts = require("typescript");
|
|
5
|
+
const IncrementalChecker_1 = require("./IncrementalChecker");
|
|
6
|
+
const CancellationToken_1 = require("./CancellationToken");
|
|
7
|
+
const checker = new IncrementalChecker_1.IncrementalChecker(process.env.TSCONFIG, JSON.parse(process.env.COMPILER_OPTIONS), process.env.TSLINT === '' ? false : process.env.TSLINT, process.env.TSLINTAUTOFIX === 'true', process.env.WATCH === '' ? [] : process.env.WATCH.split('|'), parseInt(process.env.WORK_NUMBER, 10) || 0, parseInt(process.env.WORK_DIVISION, 10) || 1, process.env.CHECK_SYNTACTIC_ERRORS === 'true', process.env.VUE === 'true');
|
|
8
8
|
function run(cancellationToken) {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
let diagnostics = [];
|
|
10
|
+
let lints = [];
|
|
11
11
|
checker.nextIteration();
|
|
12
12
|
try {
|
|
13
13
|
diagnostics = checker.getDiagnostics(cancellationToken);
|
|
@@ -24,8 +24,8 @@ function run(cancellationToken) {
|
|
|
24
24
|
if (!cancellationToken.isCancellationRequested()) {
|
|
25
25
|
try {
|
|
26
26
|
process.send({
|
|
27
|
-
diagnostics
|
|
28
|
-
lints
|
|
27
|
+
diagnostics,
|
|
28
|
+
lints
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
catch (e) {
|
|
@@ -34,9 +34,9 @@ function run(cancellationToken) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
process.on('message',
|
|
37
|
+
process.on('message', message => {
|
|
38
38
|
run(CancellationToken_1.CancellationToken.createFromJSON(message));
|
|
39
39
|
});
|
|
40
|
-
process.on('SIGINT',
|
|
40
|
+
process.on('SIGINT', () => {
|
|
41
41
|
process.exit();
|
|
42
42
|
});
|