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.
Files changed (34) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +3 -0
  3. package/lib/{types/CancellationToken.d.ts → CancellationToken.d.ts} +4 -4
  4. package/lib/CancellationToken.js +28 -27
  5. package/lib/{types/FilesRegister.d.ts → FilesRegister.d.ts} +9 -14
  6. package/lib/FilesRegister.js +24 -24
  7. package/lib/{types/FilesWatcher.d.ts → FilesWatcher.d.ts} +4 -7
  8. package/lib/FilesWatcher.js +27 -29
  9. package/lib/FsHelper.d.ts +5 -0
  10. package/lib/FsHelper.js +20 -0
  11. package/lib/IncrementalChecker.d.ts +34 -0
  12. package/lib/IncrementalChecker.js +97 -109
  13. package/lib/{types/Message.d.ts → Message.d.ts} +0 -0
  14. package/lib/{types/NormalizedMessage.d.ts → NormalizedMessage.d.ts} +16 -23
  15. package/lib/NormalizedMessage.js +76 -86
  16. package/lib/{types/VueProgram.d.ts → VueProgram.d.ts} +0 -0
  17. package/lib/VueProgram.js +62 -77
  18. package/lib/{types/WorkResult.d.ts → WorkResult.d.ts} +6 -6
  19. package/lib/WorkResult.js +22 -25
  20. package/lib/{types/WorkSet.d.ts → WorkSet.d.ts} +6 -6
  21. package/lib/WorkSet.js +6 -7
  22. package/lib/{types/cluster.d.ts → cluster.d.ts} +0 -0
  23. package/lib/cluster.js +19 -19
  24. package/lib/{types/formatter → formatter}/codeframeFormatter.d.ts +0 -0
  25. package/lib/formatter/codeframeFormatter.js +17 -16
  26. package/lib/{types/formatter → formatter}/defaultFormatter.d.ts +0 -0
  27. package/lib/formatter/defaultFormatter.js +9 -9
  28. package/lib/index.d.ts +98 -0
  29. package/lib/index.js +183 -192
  30. package/lib/{types/service.d.ts → service.d.ts} +0 -0
  31. package/lib/service.js +11 -11
  32. package/package.json +14 -18
  33. package/lib/types/IncrementalChecker.d.ts +0 -43
  34. package/lib/types/index.d.ts +0 -101
package/lib/index.js CHANGED
@@ -1,20 +1,18 @@
1
1
  "use strict";
2
- var path = require("path");
3
- var process = require("process");
4
- var childProcess = require("child_process");
5
- var chalk_1 = require("chalk");
6
- var fs = require("fs");
7
- var micromatch = require("micromatch");
8
- var os = require("os");
9
- var isString = require("lodash/isString");
10
- var isFunction = require("lodash/isFunction");
11
- var CancellationToken_1 = require("./CancellationToken");
12
- var NormalizedMessage_1 = require("./NormalizedMessage");
13
- var defaultFormatter_1 = require("./formatter/defaultFormatter");
14
- var codeframeFormatter_1 = require("./formatter/codeframeFormatter");
15
- var tapable_1 = require("tapable");
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
- var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
36
- function ForkTsCheckerWebpackPlugin(options) {
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.watch = isString(options.watch)
50
- ? [options.watch]
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 && isFunction(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
- ForkTsCheckerWebpackPlugin.createFormatter = function (type, options) {
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
- ForkTsCheckerWebpackPlugin.prototype.apply = function (compiler) {
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
- : null;
101
+ : undefined;
104
102
  this.watchPaths = this.watch.map(this.computeContextPath.bind(this));
105
103
  // validate config
106
- var tsconfigOk = fs.existsSync(this.tsconfigPath);
107
- var tslintOk = !this.tslintPath || fs.existsSync(this.tslintPath);
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
- ForkTsCheckerWebpackPlugin.prototype.computeContextPath = function (filePath) {
146
+ }
147
+ computeContextPath(filePath) {
150
148
  return path.isAbsolute(filePath)
151
149
  ? filePath
152
150
  : path.resolve(this.compiler.options.context, filePath);
153
- };
154
- ForkTsCheckerWebpackPlugin.prototype.pluginStart = function () {
155
- var _this = this;
156
- var run = function (_compiler, callback) {
157
- _this.isWatching = false;
151
+ }
152
+ pluginStart() {
153
+ const run = (_compiler, callback) => {
154
+ this.isWatching = false;
158
155
  callback();
159
156
  };
160
- var watchRun = function (_compiler, callback) {
161
- _this.isWatching = true;
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
- ForkTsCheckerWebpackPlugin.prototype.pluginStop = function () {
176
- var _this = this;
177
- var watchClose = function () {
178
- _this.killService();
171
+ }
172
+ pluginStop() {
173
+ const watchClose = () => {
174
+ this.killService();
179
175
  };
180
- var done = function (_stats) {
181
- if (!_this.isWatching) {
182
- _this.killService();
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', function () {
196
- _this.killService();
191
+ process.on('exit', () => {
192
+ this.killService();
197
193
  });
198
- };
199
- ForkTsCheckerWebpackPlugin.prototype.registerCustomHooks = function () {
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, function (options) {
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
- ForkTsCheckerWebpackPlugin.prototype.pluginCompile = function () {
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, function () {
265
- _this.compilationDone = false;
266
- _this.compiler.hooks.forkTsCheckerServiceBeforeStart.callAsync(function () {
267
- if (_this.cancellationToken) {
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
- _this.cancellationToken.requestCancellation();
270
- _this.compiler.hooks.forkTsCheckerCancel.call(_this.cancellationToken);
264
+ this.cancellationToken.requestCancellation();
265
+ this.compiler.hooks.forkTsCheckerCancel.call(this.cancellationToken);
271
266
  }
272
- _this.checkDone = false;
273
- _this.started = process.hrtime();
267
+ this.checkDone = false;
268
+ this.started = process.hrtime();
274
269
  // create new token for current job
275
- _this.cancellationToken = new CancellationToken_1.CancellationToken(undefined, undefined);
276
- if (!_this.service || !_this.service.connected) {
277
- _this.spawnService();
270
+ this.cancellationToken = new CancellationToken_1.CancellationToken();
271
+ if (!this.service || !this.service.connected) {
272
+ this.spawnService();
278
273
  }
279
274
  try {
280
- _this.service.send(_this.cancellationToken);
275
+ this.service.send(this.cancellationToken);
281
276
  }
282
277
  catch (error) {
283
- if (!_this.silent && _this.logger) {
284
- _this.logger.error(_this.colors.red('Cannot start checker service: ' +
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
- _this.compiler.hooks.forkTsCheckerServiceStartError.call(error);
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', function () {
295
- _this.compilationDone = false;
296
- _this.compiler.applyPluginsAsync('fork-ts-checker-service-before-start', function () {
297
- if (_this.cancellationToken) {
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
- _this.cancellationToken.requestCancellation();
300
- _this.compiler.applyPlugins('fork-ts-checker-cancel', _this.cancellationToken);
294
+ this.cancellationToken.requestCancellation();
295
+ this.compiler.applyPlugins('fork-ts-checker-cancel', this.cancellationToken);
301
296
  }
302
- _this.checkDone = false;
303
- _this.started = process.hrtime();
297
+ this.checkDone = false;
298
+ this.started = process.hrtime();
304
299
  // create new token for current job
305
- _this.cancellationToken = new CancellationToken_1.CancellationToken(undefined, undefined);
306
- if (!_this.service || !_this.service.connected) {
307
- _this.spawnService();
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
- _this.service.send(_this.cancellationToken);
305
+ this.service.send(this.cancellationToken);
311
306
  }
312
307
  catch (error) {
313
- if (!_this.silent && _this.logger) {
314
- _this.logger.error(_this.colors.red('Cannot start checker service: ' +
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
- _this.compiler.applyPlugins('fork-ts-checker-service-start-error', error);
312
+ this.compiler.applyPlugins('fork-ts-checker-service-start-error', error);
318
313
  }
319
314
  });
320
315
  });
321
316
  }
322
- };
323
- ForkTsCheckerWebpackPlugin.prototype.pluginEmit = function () {
324
- var _this = this;
325
- var emit = function (compilation, callback) {
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
- _this.emitCallback = _this.createEmitCallback(compilation, callback);
331
- if (_this.checkDone) {
332
- _this.emitCallback();
324
+ this.emitCallback = this.createEmitCallback(compilation, callback);
325
+ if (this.checkDone) {
326
+ this.emitCallback();
333
327
  }
334
- _this.compilationDone = true;
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
- ForkTsCheckerWebpackPlugin.prototype.pluginDone = function () {
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, function (_stats) {
350
- if (!_this.isWatching || !_this.async) {
342
+ this.compiler.hooks.done.tap(checkerPluginName, (_stats) => {
343
+ if (!this.isWatching || !this.async) {
351
344
  return;
352
345
  }
353
- if (_this.checkDone) {
354
- _this.doneCallback();
346
+ if (this.checkDone) {
347
+ this.doneCallback();
355
348
  }
356
349
  else {
357
- if (_this.compiler) {
358
- _this.compiler.hooks.forkTsCheckerWaiting.call(_this.tslint !== false);
350
+ if (this.compiler) {
351
+ this.compiler.hooks.forkTsCheckerWaiting.call(this.tslint !== false);
359
352
  }
360
- if (!_this.silent && _this.logger) {
361
- _this.logger.info(_this.tslint
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
- _this.compilationDone = true;
359
+ this.compilationDone = true;
367
360
  });
368
361
  }
369
362
  else {
370
363
  // webpack 2 / 3
371
- this.compiler.plugin('done', function () {
372
- if (!_this.isWatching || !_this.async) {
364
+ this.compiler.plugin('done', () => {
365
+ if (!this.isWatching || !this.async) {
373
366
  return;
374
367
  }
375
- if (_this.checkDone) {
376
- _this.doneCallback();
368
+ if (this.checkDone) {
369
+ this.doneCallback();
377
370
  }
378
371
  else {
379
- if (_this.compiler) {
380
- _this.compiler.applyPlugins('fork-ts-checker-waiting', _this.tslint !== false);
372
+ if (this.compiler) {
373
+ this.compiler.applyPlugins('fork-ts-checker-waiting', this.tslint !== false);
381
374
  }
382
- if (!_this.silent && _this.logger) {
383
- _this.logger.info(_this.tslint
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
- _this.compilationDone = true;
381
+ this.compilationDone = true;
389
382
  });
390
383
  }
391
- };
392
- ForkTsCheckerWebpackPlugin.prototype.spawnService = function () {
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(function (wpath) { return _this.colors.grey(wpath); }).join('\n'));
425
+ this.watchPaths.map(wpath => this.colors.grey(wpath)).join('\n'));
433
426
  }
434
427
  }
435
- this.service.on('message', function (message) {
436
- return _this.handleServiceMessage(message);
437
- });
438
- this.service.on('exit', function (code, signal) {
439
- return _this.handleServiceExit(code, signal);
440
- });
441
- };
442
- ForkTsCheckerWebpackPlugin.prototype.killService = function () {
443
- if (this.service) {
444
- try {
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
- catch (e) {
452
- if (this.logger && !this.silent) {
453
- this.logger.error(e);
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
- ForkTsCheckerWebpackPlugin.prototype.handleServiceMessage = function (message) {
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(function (diagnostic) {
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(function (lint) { return _this.ignoreLints.indexOf(lint.getCode()) === -1; });
462
+ this.lints = this.lints.filter(lint => !this.ignoreLints.includes(lint.code));
476
463
  }
477
464
  if (this.reportFiles.length) {
478
- var reportFilesPredicate = function (diagnostic) {
465
+ const reportFilesPredicate = (diagnostic) => {
479
466
  if (diagnostic.file) {
480
- var relativeFileName = path.relative(_this.compiler.options.context, diagnostic.file);
481
- var matchResult = micromatch([relativeFileName], _this.reportFiles);
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
- ForkTsCheckerWebpackPlugin.prototype.handleServiceExit = function (_code, signal) {
504
- if (signal === 'SIGABRT') {
505
- // probably out of memory :/
506
- if (this.compiler) {
507
- if ('hooks' in this.compiler) {
508
- // webpack 4
509
- this.compiler.hooks.forkTsCheckerServiceOutOfMemory.call();
510
- }
511
- else {
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
- if (!this.silent && this.logger) {
517
- this.logger.error(this.colors.red('Type checking and linting aborted - probably out of memory. ' +
518
- 'Check `memoryLimit` option in ForkTsCheckerWebpackPlugin configuration.'));
500
+ else {
501
+ // webpack 2 / 3
502
+ this.compiler.applyPlugins('fork-ts-checker-service-out-of-memory');
519
503
  }
520
504
  }
521
- };
522
- ForkTsCheckerWebpackPlugin.prototype.createEmitCallback = function (compilation, callback) {
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
- var _this = this;
525
- var elapsed = Math.round(this.elapsed[0] * 1e9 + this.elapsed[1]);
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(function (message) {
524
+ this.diagnostics.concat(this.lints).forEach(message => {
535
525
  // webpack message format
536
- var formatted = {
537
- rawMessage: message.getSeverity().toUpperCase() +
526
+ const formatted = {
527
+ rawMessage: message.severity.toUpperCase() +
538
528
  ' ' +
539
529
  message.getFormattedCode() +
540
530
  ': ' +
541
- message.getContent(),
542
- message: _this.formatter(message, _this.useColors),
531
+ message.content,
532
+ message: this.formatter(message, this.useColors),
543
533
  location: {
544
- line: message.getLine(),
545
- character: message.getCharacter()
534
+ line: message.line,
535
+ character: message.character
546
536
  },
547
- file: message.getFile()
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
- ForkTsCheckerWebpackPlugin.prototype.createNoopEmitCallback = function () {
548
+ }
549
+ createNoopEmitCallback() {
560
550
  // tslint:disable-next-line:no-empty
561
551
  return function noopEmitCallback() { };
562
- };
563
- ForkTsCheckerWebpackPlugin.prototype.createDoneCallback = function () {
552
+ }
553
+ createDoneCallback() {
564
554
  return function doneCallback() {
565
- var _this = this;
566
- var elapsed = Math.round(this.elapsed[0] * 1e9 + this.elapsed[1]);
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(function (message) {
580
- var formattedMessage = _this.formatter(message, _this.useColors);
571
+ (this.lints || []).concat(this.diagnostics).forEach(message => {
572
+ const formattedMessage = this.formatter(message, this.useColors);
581
573
  message.isWarningSeverity()
582
- ? _this.logger.warn(formattedMessage)
583
- : _this.logger.error(formattedMessage);
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
- ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT = 2048;
604
- ForkTsCheckerWebpackPlugin.ONE_CPU = 1;
605
- ForkTsCheckerWebpackPlugin.ALL_CPUS = os.cpus && os.cpus() ? os.cpus().length : 1;
606
- ForkTsCheckerWebpackPlugin.ONE_CPU_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 1);
607
- ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 2);
608
- return ForkTsCheckerWebpackPlugin;
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
- var process = require("process");
4
- var ts = require("typescript");
5
- var IncrementalChecker_1 = require("./IncrementalChecker");
6
- var CancellationToken_1 = require("./CancellationToken");
7
- var checker = new IncrementalChecker_1.IncrementalChecker(process.env.TSCONFIG, JSON.parse(process.env.COMPILER_OPTIONS), process.env.TSLINT === '' ? false : process.env.TSLINT, process.env.WATCH === '' ? [] : process.env.WATCH.split('|'), parseInt(process.env.WORK_NUMBER, 10), parseInt(process.env.WORK_DIVISION, 10), process.env.CHECK_SYNTACTIC_ERRORS === 'true', process.env.VUE === 'true');
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
- var diagnostics = [];
10
- var lints = [];
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: diagnostics,
28
- lints: 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', function (message) {
37
+ process.on('message', message => {
38
38
  run(CancellationToken_1.CancellationToken.createFromJSON(message));
39
39
  });
40
- process.on('SIGINT', function () {
40
+ process.on('SIGINT', () => {
41
41
  process.exit();
42
42
  });