fork-ts-checker-webpack-plugin 4.0.0-beta.3 → 4.0.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 (91) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +21 -73
  3. package/lib/ApiIncrementalChecker.d.ts +2 -15
  4. package/lib/ApiIncrementalChecker.js +79 -109
  5. package/lib/ApiIncrementalChecker.js.map +1 -1
  6. package/lib/CancellationToken.js +32 -24
  7. package/lib/CancellationToken.js.map +1 -1
  8. package/lib/CompilerHost.d.ts +7 -7
  9. package/lib/CompilerHost.js +225 -155
  10. package/lib/CompilerHost.js.map +1 -1
  11. package/lib/FilesRegister.d.ts +2 -4
  12. package/lib/FilesRegister.js +24 -23
  13. package/lib/FilesRegister.js.map +1 -1
  14. package/lib/FsHelper.js +9 -1
  15. package/lib/FsHelper.js.map +1 -1
  16. package/lib/IncrementalChecker.d.ts +2 -15
  17. package/lib/IncrementalChecker.js +146 -172
  18. package/lib/IncrementalChecker.js.map +1 -1
  19. package/lib/IncrementalCheckerInterface.d.ts +0 -4
  20. package/lib/IncrementalCheckerInterface.js.map +1 -1
  21. package/lib/LinkedList.js +38 -36
  22. package/lib/LinkedList.js.map +1 -1
  23. package/lib/Message.js.map +1 -1
  24. package/lib/RpcTypes.js.map +1 -1
  25. package/lib/VueProgram.d.ts +1 -1
  26. package/lib/VueProgram.js +92 -71
  27. package/lib/VueProgram.js.map +1 -1
  28. package/lib/createEslinter.d.ts +2 -2
  29. package/lib/createEslinter.js +13 -6
  30. package/lib/createEslinter.js.map +1 -1
  31. package/lib/formatter/CodeframeFormatter.js +41 -17
  32. package/lib/formatter/CodeframeFormatter.js.map +1 -1
  33. package/lib/formatter/DefaultFormatter.js +18 -8
  34. package/lib/formatter/DefaultFormatter.js.map +1 -1
  35. package/lib/formatter/Formatter.js.map +1 -1
  36. package/lib/formatter/FormatterFactory.js +2 -2
  37. package/lib/formatter/FormatterFactory.js.map +1 -1
  38. package/lib/formatter/InternalFormatter.js +17 -7
  39. package/lib/formatter/InternalFormatter.js.map +1 -1
  40. package/lib/formatter/RawFormatter.js +3 -3
  41. package/lib/formatter/RawFormatter.js.map +1 -1
  42. package/lib/formatter/index.js.map +1 -1
  43. package/lib/hooks.d.ts +0 -3
  44. package/lib/hooks.js +5 -16
  45. package/lib/hooks.js.map +1 -1
  46. package/lib/index.d.ts +2 -10
  47. package/lib/index.js +247 -377
  48. package/lib/index.js.map +1 -1
  49. package/lib/issue/Issue.js +6 -4
  50. package/lib/issue/Issue.js.map +1 -1
  51. package/lib/issue/IssueOrigin.d.ts +0 -1
  52. package/lib/issue/IssueOrigin.js +8 -9
  53. package/lib/issue/IssueOrigin.js.map +1 -1
  54. package/lib/issue/IssueSeverity.js +4 -2
  55. package/lib/issue/IssueSeverity.js.map +1 -1
  56. package/lib/issue/eslint/EsLintIssueFactory.d.ts +2 -2
  57. package/lib/issue/eslint/EsLintIssueFactory.js +17 -12
  58. package/lib/issue/eslint/EsLintIssueFactory.js.map +1 -1
  59. package/lib/issue/eslint/FileAwareEsLintMessage.d.ts +2 -2
  60. package/lib/issue/eslint/FileAwareEsLintMessage.js.map +1 -1
  61. package/lib/issue/eslint/index.js.map +1 -1
  62. package/lib/issue/index.d.ts +0 -1
  63. package/lib/issue/index.js +0 -1
  64. package/lib/issue/index.js.map +1 -1
  65. package/lib/issue/internal/InternalIssueFactory.d.ts +6 -1
  66. package/lib/issue/internal/InternalIssueFactory.js +5 -3
  67. package/lib/issue/internal/InternalIssueFactory.js.map +1 -1
  68. package/lib/issue/internal/index.js.map +1 -1
  69. package/lib/issue/typescript/TypeScriptIssueFactory.js +14 -14
  70. package/lib/issue/typescript/TypeScriptIssueFactory.js.map +1 -1
  71. package/lib/issue/typescript/index.js.map +1 -1
  72. package/lib/patchTypescript.js +27 -20
  73. package/lib/patchTypescript.js.map +1 -1
  74. package/lib/resolution.js +3 -11
  75. package/lib/resolution.js.map +1 -1
  76. package/lib/service.js +107 -63
  77. package/lib/service.js.map +1 -1
  78. package/lib/types/eslint.d.ts +33 -0
  79. package/lib/types/eslint.js +3 -0
  80. package/lib/types/eslint.js.map +1 -0
  81. package/lib/types/vue-options.js.map +1 -1
  82. package/package.json +11 -33
  83. package/lib/issue/tslint/TsLintIssueFactory.d.ts +0 -5
  84. package/lib/issue/tslint/TsLintIssueFactory.js +0 -25
  85. package/lib/issue/tslint/TsLintIssueFactory.js.map +0 -1
  86. package/lib/issue/tslint/index.d.ts +0 -1
  87. package/lib/issue/tslint/index.js +0 -7
  88. package/lib/issue/tslint/index.js.map +0 -1
  89. package/lib/linterConfigHelpers.d.ts +0 -10
  90. package/lib/linterConfigHelpers.js +0 -35
  91. package/lib/linterConfigHelpers.js.map +0 -1
package/lib/index.js CHANGED
@@ -1,33 +1,51 @@
1
1
  "use strict";
2
- const path = require("path");
3
- const process = require("process");
4
- const childProcess = require("child_process");
5
- const semver = require("semver");
6
- const micromatch = require("micromatch");
7
- const chalk_1 = require("chalk");
8
- const worker_rpc_1 = require("worker-rpc");
9
- const CancellationToken_1 = require("./CancellationToken");
10
- const formatter_1 = require("./formatter");
11
- const FsHelper_1 = require("./FsHelper");
12
- const hooks_1 = require("./hooks");
13
- const RpcTypes_1 = require("./RpcTypes");
14
- const issue_1 = require("./issue");
15
- const checkerPluginName = 'fork-ts-checker-webpack-plugin';
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importStar = (this && this.__importStar) || function (mod) {
14
+ if (mod && mod.__esModule) return mod;
15
+ var result = {};
16
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
17
+ result["default"] = mod;
18
+ return result;
19
+ };
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ var path = __importStar(require("path"));
24
+ var childProcess = __importStar(require("child_process"));
25
+ var semver = __importStar(require("semver"));
26
+ var micromatch_1 = __importDefault(require("micromatch"));
27
+ var chalk_1 = __importDefault(require("chalk"));
28
+ var worker_rpc_1 = require("worker-rpc");
29
+ var CancellationToken_1 = require("./CancellationToken");
30
+ var formatter_1 = require("./formatter");
31
+ var FsHelper_1 = require("./FsHelper");
32
+ var hooks_1 = require("./hooks");
33
+ var RpcTypes_1 = require("./RpcTypes");
34
+ var issue_1 = require("./issue");
35
+ var checkerPluginName = 'fork-ts-checker-webpack-plugin';
16
36
  /**
17
37
  * ForkTsCheckerWebpackPlugin
18
- * Runs typescript type checker and linter (tslint) on separate process.
38
+ * Runs typescript type checker and linter on separate process.
19
39
  * This speed-ups build a lot.
20
40
  *
21
41
  * Options description in README.md
22
42
  */
23
- class ForkTsCheckerWebpackPlugin {
24
- constructor(options) {
25
- this.tslint = false;
43
+ var ForkTsCheckerWebpackPlugin = /** @class */ (function () {
44
+ function ForkTsCheckerWebpackPlugin(options) {
26
45
  this.eslint = false;
27
46
  this.eslintOptions = {};
28
- this.tslintAutoFix = false;
29
47
  this.tsconfigPath = undefined;
30
- this.tslintPath = undefined;
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
49
  this.compiler = undefined;
32
50
  this.started = undefined;
33
51
  this.elapsed = undefined;
@@ -41,7 +59,7 @@ class ForkTsCheckerWebpackPlugin {
41
59
  this.startAt = 0;
42
60
  this.nodeArgs = [];
43
61
  options = options || {};
44
- this.options = Object.assign({}, options);
62
+ this.options = __assign({}, options);
45
63
  this.ignoreDiagnostics = options.ignoreDiagnostics || [];
46
64
  this.ignoreLints = options.ignoreLints || [];
47
65
  this.ignoreLintWarnings = options.ignoreLintWarnings === true;
@@ -59,24 +77,18 @@ class ForkTsCheckerWebpackPlugin {
59
77
  this.rawFormatter = formatter_1.createRawFormatter();
60
78
  this.emitCallback = this.createNoopEmitCallback();
61
79
  this.doneCallback = this.createDoneCallback();
62
- const { typescript, typescriptPath, typescriptVersion, tsconfig, compilerOptions } = this.validateTypeScript(options);
80
+ var _a = this.validateTypeScript(options), typescript = _a.typescript, typescriptPath = _a.typescriptPath, typescriptVersion = _a.typescriptVersion, tsconfig = _a.tsconfig, compilerOptions = _a.compilerOptions;
63
81
  this.typescript = typescript;
64
82
  this.typescriptPath = typescriptPath;
65
83
  this.typescriptVersion = typescriptVersion;
66
84
  this.tsconfig = tsconfig;
67
85
  this.compilerOptions = compilerOptions;
68
86
  if (options.eslint === true) {
69
- const { eslintVersion, eslintOptions } = this.validateEslint(options);
87
+ var _b = this.validateEslint(options), eslintVersion = _b.eslintVersion, eslintOptions = _b.eslintOptions;
70
88
  this.eslint = true;
71
89
  this.eslintVersion = eslintVersion;
72
90
  this.eslintOptions = eslintOptions;
73
91
  }
74
- else {
75
- const { tslint, tslintVersion, tslintAutoFix } = this.validateTslint(options);
76
- this.tslint = tslint;
77
- this.tslintVersion = tslintVersion;
78
- this.tslintAutoFix = tslintAutoFix;
79
- }
80
92
  this.vue = ForkTsCheckerWebpackPlugin.prepareVueOptions(options.vue);
81
93
  this.useTypescriptIncrementalApi =
82
94
  options.useTypescriptIncrementalApi === undefined
@@ -84,20 +96,26 @@ class ForkTsCheckerWebpackPlugin {
84
96
  : options.useTypescriptIncrementalApi;
85
97
  this.measureTime = options.measureCompilationTime === true;
86
98
  if (this.measureTime) {
99
+ if (semver.lt(process.version, '8.5.0')) {
100
+ throw new Error("To use 'measureCompilationTime' option, please update to Node.js >= v8.5.0 " +
101
+ ("(current version is " + process.version + ")"));
102
+ }
87
103
  // Node 8+ only
104
+ // eslint-disable-next-line node/no-unsupported-features/node-builtins
88
105
  this.performance = require('perf_hooks').performance;
89
106
  }
90
107
  }
91
- static getCompilerHooks(compiler) {
108
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
109
+ ForkTsCheckerWebpackPlugin.getCompilerHooks = function (compiler) {
92
110
  return hooks_1.getForkTsCheckerWebpackPluginHooks(compiler);
93
- }
94
- validateTypeScript(options) {
95
- const typescriptPath = options.typescript || require.resolve('typescript');
96
- const tsconfig = options.tsconfig || './tsconfig.json';
97
- const compilerOptions = typeof options.compilerOptions === 'object'
111
+ };
112
+ ForkTsCheckerWebpackPlugin.prototype.validateTypeScript = function (options) {
113
+ var typescriptPath = options.typescript || require.resolve('typescript');
114
+ var tsconfig = options.tsconfig || './tsconfig.json';
115
+ var compilerOptions = typeof options.compilerOptions === 'object'
98
116
  ? options.compilerOptions
99
117
  : {};
100
- let typescript, typescriptVersion;
118
+ var typescript, typescriptVersion;
101
119
  try {
102
120
  typescript = require(typescriptPath);
103
121
  typescriptVersion = typescript.version;
@@ -106,51 +124,33 @@ class ForkTsCheckerWebpackPlugin {
106
124
  throw new Error('When you use this plugin you must install `typescript`.');
107
125
  }
108
126
  if (semver.lt(typescriptVersion, '2.1.0')) {
109
- throw new Error(`Cannot use current typescript version of ${typescriptVersion}, the minimum required version is 2.1.0`);
127
+ throw new Error("Cannot use current typescript version of " + typescriptVersion + ", the minimum required version is 2.1.0");
110
128
  }
111
129
  return {
112
- typescriptPath,
113
- typescript,
114
- typescriptVersion,
115
- tsconfig,
116
- compilerOptions
130
+ typescriptPath: typescriptPath,
131
+ typescript: typescript,
132
+ typescriptVersion: typescriptVersion,
133
+ tsconfig: tsconfig,
134
+ compilerOptions: compilerOptions
117
135
  };
118
- }
119
- validateTslint(options) {
120
- const tslint = options.tslint
121
- ? options.tslint === true
122
- ? true
123
- : options.tslint
124
- : undefined;
125
- let tslintAutoFix, tslintVersion;
126
- try {
127
- tslintAutoFix = options.tslintAutoFix || false;
128
- tslintVersion = tslint
129
- ? // tslint:disable-next-line:no-implicit-dependencies
130
- require('tslint').Linter.VERSION
131
- : undefined;
136
+ };
137
+ ForkTsCheckerWebpackPlugin.prototype.validateEslint = function (options) {
138
+ var eslintVersion;
139
+ var eslintOptions = typeof options.eslintOptions === 'object' ? options.eslintOptions : {};
140
+ if (semver.lt(process.version, '8.10.0')) {
141
+ throw new Error("To use 'eslint' option, please update to Node.js >= v8.10.0 " +
142
+ ("(current version is " + process.version + ")"));
132
143
  }
133
- catch (_ignored) {
134
- throw new Error('When you use `tslint` option, make sure to install `tslint`.');
135
- }
136
- if (tslintVersion && semver.lt(tslintVersion, '4.0.0')) {
137
- throw new Error(`Cannot use current tslint version of ${tslintVersion}, the minimum required version is 4.0.0`);
138
- }
139
- return { tslint, tslintAutoFix, tslintVersion };
140
- }
141
- validateEslint(options) {
142
- let eslintVersion;
143
- const eslintOptions = typeof options.eslintOptions === 'object' ? options.eslintOptions : {};
144
144
  try {
145
145
  eslintVersion = require('eslint').Linter.version;
146
146
  }
147
- catch (_ignored) {
148
- throw new Error('When you use `eslint` option, make sure to install `eslint`.');
147
+ catch (error) {
148
+ throw new Error("When you use 'eslint' option, make sure to install 'eslint'.");
149
149
  }
150
- return { eslintVersion, eslintOptions };
151
- }
152
- static prepareVueOptions(vueOptions) {
153
- const defaultVueOptions = {
150
+ return { eslintVersion: eslintVersion, eslintOptions: eslintOptions };
151
+ };
152
+ ForkTsCheckerWebpackPlugin.prepareVueOptions = function (vueOptions) {
153
+ var defaultVueOptions = {
154
154
  compiler: 'vue-template-compiler',
155
155
  enabled: false
156
156
  };
@@ -163,247 +163,148 @@ class ForkTsCheckerWebpackPlugin {
163
163
  else {
164
164
  return defaultVueOptions;
165
165
  }
166
- }
167
- apply(compiler) {
166
+ };
167
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
+ ForkTsCheckerWebpackPlugin.prototype.apply = function (compiler) {
168
169
  this.compiler = compiler;
169
170
  this.tsconfigPath = this.computeContextPath(this.tsconfig);
170
- this.tslintPath =
171
- typeof this.tslint === 'string'
172
- ? this.computeContextPath(this.tslint)
173
- : undefined;
174
171
  // validate config
175
- const tsconfigOk = FsHelper_1.fileExistsSync(this.tsconfigPath);
176
- const tslintOk = !this.tslintPath || FsHelper_1.fileExistsSync(this.tslintPath);
172
+ var tsconfigOk = FsHelper_1.fileExistsSync(this.tsconfigPath);
177
173
  // validate logger
178
174
  if (this.logger) {
179
175
  if (!this.logger.error || !this.logger.warn || !this.logger.info) {
180
176
  throw new Error("Invalid logger object - doesn't provide `error`, `warn` or `info` method.");
181
177
  }
182
178
  }
183
- if (tsconfigOk && tslintOk) {
184
- this.pluginStart();
185
- this.pluginStop();
186
- this.pluginCompile();
187
- this.pluginEmit();
188
- this.pluginDone();
189
- }
190
- else {
191
- if (!tsconfigOk) {
192
- throw new Error('Cannot find "' +
193
- this.tsconfigPath +
194
- '" file. Please check webpack and ForkTsCheckerWebpackPlugin configuration. \n' +
195
- 'Possible errors: \n' +
196
- ' - wrong `context` directory in webpack configuration' +
197
- ' (if `tsconfig` is not set or is a relative path in fork plugin configuration)\n' +
198
- ' - wrong `tsconfig` path in fork plugin configuration' +
199
- ' (should be a relative or absolute path)');
200
- }
201
- if (!tslintOk) {
202
- throw new Error('Cannot find "' +
203
- this.tslintPath +
204
- '" file. Please check webpack and ForkTsCheckerWebpackPlugin configuration. \n' +
205
- 'Possible errors: \n' +
206
- ' - wrong `context` directory in webpack configuration' +
207
- ' (if `tslint` is not set or is a relative path in fork plugin configuration)\n' +
208
- ' - wrong `tslint` path in fork plugin configuration' +
209
- ' (should be a relative or absolute path)\n' +
210
- ' - `tslint` path is not set to false in fork plugin configuration' +
211
- ' (if you want to disable tslint support)');
212
- }
213
- }
214
- }
215
- computeContextPath(filePath) {
179
+ if (!tsconfigOk) {
180
+ throw new Error('Cannot find "' +
181
+ this.tsconfigPath +
182
+ '" file. Please check webpack and ForkTsCheckerWebpackPlugin configuration. \n' +
183
+ 'Possible errors: \n' +
184
+ ' - wrong `context` directory in webpack configuration' +
185
+ ' (if `tsconfig` is not set or is a relative path in fork plugin configuration)\n' +
186
+ ' - wrong `tsconfig` path in fork plugin configuration' +
187
+ ' (should be a relative or absolute path)');
188
+ }
189
+ this.pluginStart();
190
+ this.pluginStop();
191
+ this.pluginCompile();
192
+ this.pluginEmit();
193
+ this.pluginDone();
194
+ };
195
+ ForkTsCheckerWebpackPlugin.prototype.computeContextPath = function (filePath) {
216
196
  return path.isAbsolute(filePath)
217
197
  ? filePath
218
198
  : path.resolve(this.compiler.options.context, filePath);
219
- }
220
- pluginStart() {
221
- const run = (_compiler, callback) => {
222
- this.isWatching = false;
199
+ };
200
+ ForkTsCheckerWebpackPlugin.prototype.pluginStart = function () {
201
+ var _this = this;
202
+ var run = function (compilation, callback) {
203
+ _this.isWatching = false;
223
204
  callback();
224
205
  };
225
- const watchRun = (_compiler, callback) => {
226
- this.isWatching = true;
206
+ var watchRun = function (compiler, callback) {
207
+ _this.isWatching = true;
227
208
  callback();
228
209
  };
229
- if ('hooks' in this.compiler) {
230
- // webpack 4+
231
- this.compiler.hooks.run.tapAsync(checkerPluginName, run);
232
- this.compiler.hooks.watchRun.tapAsync(checkerPluginName, watchRun);
233
- }
234
- else {
235
- // webpack 2 / 3
236
- this.compiler.plugin('run', run);
237
- this.compiler.plugin('watch-run', watchRun);
238
- }
239
- }
240
- pluginStop() {
241
- const watchClose = () => {
242
- this.killService();
210
+ this.compiler.hooks.run.tapAsync(checkerPluginName, run);
211
+ this.compiler.hooks.watchRun.tapAsync(checkerPluginName, watchRun);
212
+ };
213
+ ForkTsCheckerWebpackPlugin.prototype.pluginStop = function () {
214
+ var _this = this;
215
+ var watchClose = function () {
216
+ _this.killService();
243
217
  };
244
- const done = (_stats) => {
245
- if (!this.isWatching) {
246
- this.killService();
218
+ var done = function () {
219
+ if (!_this.isWatching) {
220
+ _this.killService();
247
221
  }
248
222
  };
249
- if ('hooks' in this.compiler) {
250
- // webpack 4+
251
- this.compiler.hooks.watchClose.tap(checkerPluginName, watchClose);
252
- this.compiler.hooks.done.tap(checkerPluginName, done);
253
- }
254
- else {
255
- // webpack 2 / 3
256
- this.compiler.plugin('watch-close', watchClose);
257
- this.compiler.plugin('done', done);
258
- }
259
- process.on('exit', () => {
260
- this.killService();
223
+ this.compiler.hooks.watchClose.tap(checkerPluginName, watchClose);
224
+ this.compiler.hooks.done.tap(checkerPluginName, done);
225
+ process.on('exit', function () {
226
+ _this.killService();
261
227
  });
262
- }
263
- pluginCompile() {
264
- if ('hooks' in this.compiler) {
265
- // webpack 4+
266
- const forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
267
- this.compiler.hooks.compile.tap(checkerPluginName, () => {
268
- this.compilationDone = false;
269
- forkTsCheckerHooks.serviceBeforeStart.callAsync(() => {
270
- if (this.cancellationToken) {
271
- // request cancellation if there is not finished job
272
- this.cancellationToken.requestCancellation();
273
- forkTsCheckerHooks.cancel.call(this.cancellationToken);
274
- }
275
- this.checkDone = false;
276
- this.started = process.hrtime();
277
- // create new token for current job
278
- this.cancellationToken = new CancellationToken_1.CancellationToken(this.typescript);
279
- if (!this.service || !this.service.connected) {
280
- this.spawnService();
281
- }
282
- try {
283
- if (this.measureTime) {
284
- this.startAt = this.performance.now();
285
- }
286
- this.serviceRpc.rpc(RpcTypes_1.RUN, this.cancellationToken.toJSON()).then(result => {
287
- if (result) {
288
- this.handleServiceMessage(result);
289
- }
290
- });
291
- }
292
- catch (error) {
293
- if (!this.silent && this.logger) {
294
- this.logger.error(chalk_1.default.red('Cannot start checker service: ' +
295
- (error ? error.toString() : 'Unknown error')));
296
- }
297
- forkTsCheckerHooks.serviceStartError.call(error);
298
- }
299
- });
300
- });
301
- }
302
- else {
303
- // webpack 2 / 3
304
- this.compiler.plugin('compile', () => {
305
- this.compilationDone = false;
306
- this.compiler.applyPluginsAsync(hooks_1.legacyHookMap.serviceBeforeStart, () => {
307
- if (this.cancellationToken) {
308
- // request cancellation if there is not finished job
309
- this.cancellationToken.requestCancellation();
310
- this.compiler.applyPlugins(hooks_1.legacyHookMap.cancel, this.cancellationToken);
311
- }
312
- this.checkDone = false;
313
- this.started = process.hrtime();
314
- // create new token for current job
315
- this.cancellationToken = new CancellationToken_1.CancellationToken(this.typescript, undefined, undefined);
316
- if (!this.service || !this.service.connected) {
317
- this.spawnService();
318
- }
319
- try {
320
- this.serviceRpc.rpc(RpcTypes_1.RUN, this.cancellationToken.toJSON()).then(result => {
321
- if (result) {
322
- this.handleServiceMessage(result);
323
- }
324
- });
228
+ };
229
+ ForkTsCheckerWebpackPlugin.prototype.pluginCompile = function () {
230
+ var _this = this;
231
+ var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
232
+ this.compiler.hooks.compile.tap(checkerPluginName, function () {
233
+ _this.compilationDone = false;
234
+ forkTsCheckerHooks.serviceBeforeStart.callAsync(function () {
235
+ if (_this.cancellationToken) {
236
+ // request cancellation if there is not finished job
237
+ _this.cancellationToken.requestCancellation();
238
+ forkTsCheckerHooks.cancel.call(_this.cancellationToken);
239
+ }
240
+ _this.checkDone = false;
241
+ _this.started = process.hrtime();
242
+ // create new token for current job
243
+ _this.cancellationToken = new CancellationToken_1.CancellationToken(_this.typescript);
244
+ if (!_this.service || !_this.service.connected) {
245
+ _this.spawnService();
246
+ }
247
+ try {
248
+ if (_this.measureTime) {
249
+ _this.startAt = _this.performance.now();
325
250
  }
326
- catch (error) {
327
- if (!this.silent && this.logger) {
328
- this.logger.error(chalk_1.default.red('Cannot start checker service: ' +
329
- (error ? error.toString() : 'Unknown error')));
251
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
252
+ _this.serviceRpc.rpc(RpcTypes_1.RUN, _this.cancellationToken.toJSON()).then(function (result) {
253
+ if (result) {
254
+ _this.handleServiceMessage(result);
330
255
  }
331
- this.compiler.applyPlugins(hooks_1.legacyHookMap.serviceStartError, error);
256
+ });
257
+ }
258
+ catch (error) {
259
+ if (!_this.silent && _this.logger) {
260
+ _this.logger.error(chalk_1.default.red('Cannot start checker service: ' +
261
+ (error ? error.toString() : 'Unknown error')));
332
262
  }
333
- });
263
+ forkTsCheckerHooks.serviceStartError.call(error);
264
+ }
334
265
  });
335
- }
336
- }
337
- pluginEmit() {
338
- const emit = (compilation, callback) => {
339
- if (this.isWatching && this.async) {
266
+ });
267
+ };
268
+ ForkTsCheckerWebpackPlugin.prototype.pluginEmit = function () {
269
+ var _this = this;
270
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
271
+ var emit = function (compilation, callback) {
272
+ if (_this.isWatching && _this.async) {
340
273
  callback();
341
274
  return;
342
275
  }
343
- this.emitCallback = this.createEmitCallback(compilation, callback);
344
- if (this.checkDone) {
345
- this.emitCallback();
276
+ _this.emitCallback = _this.createEmitCallback(compilation, callback);
277
+ if (_this.checkDone) {
278
+ _this.emitCallback();
346
279
  }
347
- this.compilationDone = true;
280
+ _this.compilationDone = true;
348
281
  };
349
- if ('hooks' in this.compiler) {
350
- // webpack 4+
351
- this.compiler.hooks.emit.tapAsync(checkerPluginName, emit);
352
- }
353
- else {
354
- // webpack 2 / 3
355
- this.compiler.plugin('emit', emit);
356
- }
357
- }
358
- pluginDone() {
359
- if ('hooks' in this.compiler) {
360
- // webpack 4+
361
- const forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
362
- this.compiler.hooks.done.tap(checkerPluginName, (_stats) => {
363
- if (!this.isWatching || !this.async) {
364
- return;
365
- }
366
- if (this.checkDone) {
367
- this.doneCallback();
368
- }
369
- else {
370
- if (this.compiler) {
371
- forkTsCheckerHooks.waiting.call(this.tslint !== undefined);
372
- }
373
- if (!this.silent && this.logger) {
374
- this.logger.info(this.tslint
375
- ? 'Type checking and linting in progress...'
376
- : 'Type checking in progress...');
377
- }
378
- }
379
- this.compilationDone = true;
380
- });
381
- }
382
- else {
383
- // webpack 2 / 3
384
- this.compiler.plugin('done', () => {
385
- if (!this.isWatching || !this.async) {
386
- return;
387
- }
388
- if (this.checkDone) {
389
- this.doneCallback();
282
+ this.compiler.hooks.emit.tapAsync(checkerPluginName, emit);
283
+ };
284
+ ForkTsCheckerWebpackPlugin.prototype.pluginDone = function () {
285
+ var _this = this;
286
+ var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
287
+ this.compiler.hooks.done.tap(checkerPluginName, function () {
288
+ if (!_this.isWatching || !_this.async) {
289
+ return;
290
+ }
291
+ if (_this.checkDone) {
292
+ _this.doneCallback();
293
+ }
294
+ else {
295
+ if (_this.compiler) {
296
+ forkTsCheckerHooks.waiting.call();
390
297
  }
391
- else {
392
- if (this.compiler) {
393
- this.compiler.applyPlugins(hooks_1.legacyHookMap.waiting, this.tslint !== undefined);
394
- }
395
- if (!this.silent && this.logger) {
396
- this.logger.info(this.tslint
397
- ? 'Type checking and linting in progress...'
398
- : 'Type checking in progress...');
399
- }
298
+ if (!_this.silent && _this.logger) {
299
+ _this.logger.info('Type checking in progress...');
400
300
  }
401
- this.compilationDone = true;
402
- });
403
- }
404
- }
405
- spawnService() {
406
- const env = Object.assign({}, process.env, { TYPESCRIPT_PATH: this.typescriptPath, TSCONFIG: this.tsconfigPath, COMPILER_OPTIONS: JSON.stringify(this.compilerOptions), TSLINT: this.tslintPath || (this.tslint ? 'true' : ''), CONTEXT: this.compiler.options.context, TSLINTAUTOFIX: String(this.tslintAutoFix), ESLINT: String(this.eslint), ESLINT_OPTIONS: JSON.stringify(this.eslintOptions), MEMORY_LIMIT: String(this.memoryLimit), CHECK_SYNTACTIC_ERRORS: String(this.checkSyntacticErrors), USE_INCREMENTAL_API: String(this.useTypescriptIncrementalApi === true), VUE: JSON.stringify(this.vue) });
301
+ }
302
+ _this.compilationDone = true;
303
+ });
304
+ };
305
+ ForkTsCheckerWebpackPlugin.prototype.spawnService = function () {
306
+ var _this = this;
307
+ var env = __assign({}, process.env, { TYPESCRIPT_PATH: this.typescriptPath, TSCONFIG: this.tsconfigPath, COMPILER_OPTIONS: JSON.stringify(this.compilerOptions), CONTEXT: this.compiler.options.context, ESLINT: String(this.eslint), ESLINT_OPTIONS: JSON.stringify(this.eslintOptions), MEMORY_LIMIT: String(this.memoryLimit), CHECK_SYNTACTIC_ERRORS: String(this.checkSyntacticErrors), USE_INCREMENTAL_API: String(this.useTypescriptIncrementalApi === true), VUE: JSON.stringify(this.vue) });
407
308
  if (typeof this.resolveModuleNameModule !== 'undefined') {
408
309
  env.RESOLVE_MODULE_NAME = this.resolveModuleNameModule;
409
310
  }
@@ -417,29 +318,24 @@ class ForkTsCheckerWebpackPlugin {
417
318
  delete env.RESOLVE_TYPE_REFERENCE_DIRECTIVE;
418
319
  }
419
320
  this.service = childProcess.fork(path.resolve(__dirname, './service.js'), [], {
420
- env,
321
+ env: env,
421
322
  execArgv: ['--max-old-space-size=' + this.memoryLimit].concat(this.nodeArgs),
422
323
  stdio: ['inherit', 'inherit', 'inherit', 'ipc']
423
324
  });
424
- this.serviceRpc = new worker_rpc_1.RpcProvider(message => this.service.send(message));
425
- this.service.on('message', message => this.serviceRpc.dispatch(message));
426
- if ('hooks' in this.compiler) {
427
- // webpack 4+
428
- const forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
429
- forkTsCheckerHooks.serviceStart.call(this.tsconfigPath, this.tslintPath, this.memoryLimit);
430
- }
431
- else {
432
- // webpack 2 / 3
433
- this.compiler.applyPlugins(hooks_1.legacyHookMap.serviceStart, this.tsconfigPath, this.tslintPath, this.memoryLimit);
434
- }
325
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
326
+ this.serviceRpc = new worker_rpc_1.RpcProvider(function (message) { return _this.service.send(message); });
327
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
328
+ this.service.on('message', function (message) { return _this.serviceRpc.dispatch(message); });
329
+ var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
330
+ forkTsCheckerHooks.serviceStart.call(this.tsconfigPath, this.memoryLimit);
435
331
  if (!this.silent && this.logger) {
436
- this.logger.info('Starting type checking' +
437
- (this.tslint ? ' and linting' : '') +
438
- ' service...');
332
+ this.logger.info('Starting type checking service...');
439
333
  }
440
- this.service.on('exit', (code, signal) => this.handleServiceExit(code, signal));
441
- }
442
- killService() {
334
+ this.service.on('exit', function (code, signal) {
335
+ return _this.handleServiceExit(code, signal);
336
+ });
337
+ };
338
+ ForkTsCheckerWebpackPlugin.prototype.killService = function () {
443
339
  if (!this.service) {
444
340
  return;
445
341
  }
@@ -456,12 +352,13 @@ class ForkTsCheckerWebpackPlugin {
456
352
  this.logger.error(e);
457
353
  }
458
354
  }
459
- }
460
- handleServiceMessage(message) {
355
+ };
356
+ ForkTsCheckerWebpackPlugin.prototype.handleServiceMessage = function (message) {
357
+ var _this = this;
461
358
  if (this.measureTime) {
462
- const delta = this.performance.now() - this.startAt;
463
- const deltaRounded = Math.round(delta * 100) / 100;
464
- this.logger.info(`Compilation took: ${deltaRounded} ms.`);
359
+ var delta = this.performance.now() - this.startAt;
360
+ var deltaRounded = Math.round(delta * 100) / 100;
361
+ this.logger.info("Compilation took: " + deltaRounded + " ms.");
465
362
  }
466
363
  if (this.cancellationToken) {
467
364
  this.cancellationToken.cleanupCancellation();
@@ -473,16 +370,18 @@ class ForkTsCheckerWebpackPlugin {
473
370
  this.diagnostics = message.diagnostics;
474
371
  this.lints = message.lints;
475
372
  if (this.ignoreDiagnostics.length) {
476
- this.diagnostics = this.diagnostics.filter(diagnostic => !this.ignoreDiagnostics.includes(parseInt(diagnostic.code, 10)));
373
+ this.diagnostics = this.diagnostics.filter(function (diagnostic) {
374
+ return !_this.ignoreDiagnostics.includes(parseInt(diagnostic.code, 10));
375
+ });
477
376
  }
478
377
  if (this.ignoreLints.length) {
479
- this.lints = this.lints.filter(lint => !this.ignoreLints.includes(lint.code));
378
+ this.lints = this.lints.filter(function (lint) { return !_this.ignoreLints.includes(lint.code); });
480
379
  }
481
380
  if (this.reportFiles.length) {
482
- const reportFilesPredicate = (issue) => {
381
+ var reportFilesPredicate = function (issue) {
483
382
  if (issue.file) {
484
- const relativeFileName = path.relative(this.compiler.options.context, issue.file);
485
- const matchResult = micromatch([relativeFileName], this.reportFiles);
383
+ var relativeFileName = path.relative(_this.compiler.options.context, issue.file);
384
+ var matchResult = micromatch_1.default([relativeFileName], _this.reportFiles);
486
385
  if (matchResult.length === 0) {
487
386
  return false;
488
387
  }
@@ -492,60 +391,40 @@ class ForkTsCheckerWebpackPlugin {
492
391
  this.diagnostics = this.diagnostics.filter(reportFilesPredicate);
493
392
  this.lints = this.lints.filter(reportFilesPredicate);
494
393
  }
495
- if ('hooks' in this.compiler) {
496
- // webpack 4+
497
- const forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
498
- forkTsCheckerHooks.receive.call(this.diagnostics, this.lints);
499
- }
500
- else {
501
- // webpack 2 / 3
502
- this.compiler.applyPlugins(hooks_1.legacyHookMap.receive, this.diagnostics, this.lints);
503
- }
394
+ var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
395
+ forkTsCheckerHooks.receive.call(this.diagnostics, this.lints);
504
396
  if (this.compilationDone) {
505
397
  this.isWatching && this.async ? this.doneCallback() : this.emitCallback();
506
398
  }
507
- }
508
- handleServiceExit(_code, signal) {
399
+ };
400
+ ForkTsCheckerWebpackPlugin.prototype.handleServiceExit = function (_code, signal) {
509
401
  if (signal !== 'SIGABRT') {
510
402
  return;
511
403
  }
512
404
  // probably out of memory :/
513
405
  if (this.compiler) {
514
- if ('hooks' in this.compiler) {
515
- // webpack 4+
516
- const forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
517
- forkTsCheckerHooks.serviceOutOfMemory.call();
518
- }
519
- else {
520
- // webpack 2 / 3
521
- this.compiler.applyPlugins(hooks_1.legacyHookMap.serviceOutOfMemory);
522
- }
406
+ var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
407
+ forkTsCheckerHooks.serviceOutOfMemory.call();
523
408
  }
524
409
  if (!this.silent && this.logger) {
525
410
  this.logger.error(chalk_1.default.red('Type checking and linting aborted - probably out of memory. ' +
526
411
  'Check `memoryLimit` option in ForkTsCheckerWebpackPlugin configuration.'));
527
412
  }
528
- }
529
- createEmitCallback(compilation, callback) {
413
+ };
414
+ ForkTsCheckerWebpackPlugin.prototype.createEmitCallback = function (compilation, callback) {
530
415
  return function emitCallback() {
416
+ var _this = this;
531
417
  if (!this.elapsed) {
532
418
  throw new Error('Execution order error');
533
419
  }
534
- const elapsed = Math.round(this.elapsed[0] * 1e9 + this.elapsed[1]);
535
- if ('hooks' in this.compiler) {
536
- // webpack 4+
537
- const forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
538
- forkTsCheckerHooks.emit.call(this.diagnostics, this.lints, elapsed);
539
- }
540
- else {
541
- // webpack 2 / 3
542
- this.compiler.applyPlugins(hooks_1.legacyHookMap.emit, this.diagnostics, this.lints, elapsed);
543
- }
544
- this.diagnostics.concat(this.lints).forEach(issue => {
420
+ var elapsed = Math.round(this.elapsed[0] * 1e9 + this.elapsed[1]);
421
+ var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
422
+ forkTsCheckerHooks.emit.call(this.diagnostics, this.lints, elapsed);
423
+ this.diagnostics.concat(this.lints).forEach(function (issue) {
545
424
  // webpack message format
546
- const formatted = {
547
- rawMessage: this.rawFormatter(issue),
548
- message: this.formatter(issue),
425
+ var formatted = {
426
+ rawMessage: _this.rawFormatter(issue),
427
+ message: _this.formatter(issue),
549
428
  location: {
550
429
  line: issue.line,
551
430
  character: issue.character
@@ -553,7 +432,7 @@ class ForkTsCheckerWebpackPlugin {
553
432
  file: issue.file
554
433
  };
555
434
  if (issue.severity === issue_1.IssueSeverity.WARNING) {
556
- if (!this.ignoreLintWarnings) {
435
+ if (!_this.ignoreLintWarnings) {
557
436
  compilation.warnings.push(formatted);
558
437
  }
559
438
  }
@@ -563,12 +442,13 @@ class ForkTsCheckerWebpackPlugin {
563
442
  });
564
443
  callback();
565
444
  };
566
- }
567
- createNoopEmitCallback() {
568
- // tslint:disable-next-line:no-empty
445
+ };
446
+ ForkTsCheckerWebpackPlugin.prototype.createNoopEmitCallback = function () {
447
+ // this function is empty intentionally
448
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
569
449
  return function noopEmitCallback() { };
570
- }
571
- printLoggerMessage(issue, formattedIssue) {
450
+ };
451
+ ForkTsCheckerWebpackPlugin.prototype.printLoggerMessage = function (issue, formattedIssue) {
572
452
  if (issue.severity === issue_1.IssueSeverity.WARNING) {
573
453
  if (this.ignoreLintWarnings) {
574
454
  return;
@@ -578,49 +458,39 @@ class ForkTsCheckerWebpackPlugin {
578
458
  else {
579
459
  this.logger.error(formattedIssue);
580
460
  }
581
- }
582
- createDoneCallback() {
461
+ };
462
+ ForkTsCheckerWebpackPlugin.prototype.createDoneCallback = function () {
583
463
  return function doneCallback() {
464
+ var _this = this;
584
465
  if (!this.elapsed) {
585
466
  throw new Error('Execution order error');
586
467
  }
587
- const elapsed = Math.round(this.elapsed[0] * 1e9 + this.elapsed[1]);
468
+ var elapsed = Math.round(this.elapsed[0] * 1e9 + this.elapsed[1]);
588
469
  if (this.compiler) {
589
- if ('hooks' in this.compiler) {
590
- // webpack 4+
591
- const forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
592
- forkTsCheckerHooks.done.call(this.diagnostics, this.lints, elapsed);
593
- }
594
- else {
595
- // webpack 2 / 3
596
- this.compiler.applyPlugins(hooks_1.legacyHookMap.done, this.diagnostics, this.lints, elapsed);
597
- }
470
+ var forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(this.compiler);
471
+ forkTsCheckerHooks.done.call(this.diagnostics, this.lints, elapsed);
598
472
  }
599
473
  if (!this.silent && this.logger) {
600
474
  if (this.diagnostics.length || this.lints.length) {
601
- (this.lints || []).concat(this.diagnostics).forEach(diagnostic => {
602
- const formattedDiagnostic = this.formatter(diagnostic);
603
- this.printLoggerMessage(diagnostic, formattedDiagnostic);
475
+ (this.lints || []).concat(this.diagnostics).forEach(function (diagnostic) {
476
+ var formattedDiagnostic = _this.formatter(diagnostic);
477
+ _this.printLoggerMessage(diagnostic, formattedDiagnostic);
604
478
  });
605
479
  }
606
480
  if (!this.diagnostics.length) {
607
481
  this.logger.info(chalk_1.default.green('No type errors found'));
608
482
  }
609
- if (this.tslint && !this.lints.length) {
610
- this.logger.info(chalk_1.default.green('No lint errors found'));
611
- }
612
483
  this.logger.info('Version: typescript ' +
613
484
  chalk_1.default.bold(this.typescriptVersion) +
614
485
  (this.eslint
615
486
  ? ', eslint ' + chalk_1.default.bold(this.eslintVersion)
616
- : this.tslint
617
- ? ', tslint ' + chalk_1.default.bold(this.tslintVersion)
618
- : ''));
487
+ : ''));
619
488
  this.logger.info('Time: ' + chalk_1.default.bold(Math.round(elapsed / 1e6).toString()) + 'ms');
620
489
  }
621
490
  };
622
- }
623
- }
624
- ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT = 2048;
491
+ };
492
+ ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT = 2048;
493
+ return ForkTsCheckerWebpackPlugin;
494
+ }());
625
495
  module.exports = ForkTsCheckerWebpackPlugin;
626
496
  //# sourceMappingURL=index.js.map