fork-ts-checker-webpack-plugin 6.0.7 → 6.2.0

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/README.md CHANGED
@@ -137,13 +137,13 @@ you can place your configuration in the:
137
137
 
138
138
  Options passed to the plugin constructor will overwrite options from the cosmiconfig (using [deepmerge](https://github.com/TehShrike/deepmerge)).
139
139
 
140
- | Name | Type | Default value | Description |
141
- | ----------------- | --------------------- | ------------------------------------------------------------------ | ----------- |
142
- | `async` | `boolean` | `compiler.options.mode === 'development'` | If `true`, reports issues **after** webpack's compilation is done. Thanks to that it doesn't block the compilation. Used only in the `watch` mode. |
143
- | `typescript` | `object` or `boolean` | `true` | If a `boolean`, it enables/disables TypeScript checker. If an `object`, see [TypeScript options](#typescript-options). |
144
- | `eslint` | `object` | `undefined` | If `undefined`, it disables ESLint linter. If an `object`, see [ESLint options](#eslint-options). |
145
- | `issue` | `object` | `{}` | See [Issues options](#issues-options). |
146
- | `formatter` | `string` or `object` | `codeframe` | Available formatters are `basic` and `codeframe`. To [configure](https://babeljs.io/docs/en/babel-code-frame#options) `codeframe` formatter, pass object: `{ type: 'codeframe', options: { <coderame options> } }`. |
140
+ | Name | Type | Default value | Description |
141
+ | ----------------- | ---------------------------------- | ------------------------------------------------------------------ | ----------- |
142
+ | `async` | `boolean` | `compiler.options.mode === 'development'` | If `true`, reports issues **after** webpack's compilation is done. Thanks to that it doesn't block the compilation. Used only in the `watch` mode. |
143
+ | `typescript` | `object` or `boolean` | `true` | If a `boolean`, it enables/disables TypeScript checker. If an `object`, see [TypeScript options](#typescript-options). |
144
+ | `eslint` | `object` | `undefined` | If `undefined`, it disables ESLint linter. If an `object`, see [ESLint options](#eslint-options). |
145
+ | `issue` | `object` | `{}` | See [Issues options](#issues-options). |
146
+ | `formatter` | `string` or `object` or `function` | `codeframe` | Available formatters are `basic`, `codeframe` and a custom `function`. To [configure](https://babeljs.io/docs/en/babel-code-frame#options) `codeframe` formatter, pass object: `{ type: 'codeframe', options: { <coderame options> } }`. |
147
147
  | `logger` | `object` | `{ infrastructure: 'silent', issues: 'console', devServer: true }` | Available loggers are `silent`, `console`, and `webpack-infrastructure`. Infrastructure logger prints additional information, issue logger prints `issues` in the `async` mode. If `devServer` is set to `false`, errors will not be reported to Webpack Dev Server. |
148
148
 
149
149
  ### TypeScript options
@@ -187,13 +187,51 @@ Options for the ESLint linter (`eslint` option object).
187
187
 
188
188
  ### Issues options
189
189
 
190
- Options for the issues filtering (`issues` option object).
190
+ Options for the issues filtering (`issue` option object).
191
+ I could write some plain text explanation of these options but I think code will explain it better:
191
192
 
192
- | Name | Type | Default value | Description |
193
- | --------- | --------------------------------- | ------------- | ----------- |
194
- | `include` | `object` or `function` or `array` | `undefined` | If `object`, defines issue properties that should be [matched](./src/issue/IssueMatch.ts). If `function`, acts as a predicate where `issue` is an argument. |
195
- | `exclude` | `object` or `function` or `array` | `undefined` | Same as `include` but issues that match this predicate will be excluded. |
196
- | `scope` | `'all'` or `'webpack'` | `'webpack'` | Defines issues scope to be reported. If `'webpack'`, reports errors only related to the webpack compilation. Reports all errors otherwise (like `tsc` and `eslint` command). |
193
+ ```typescript
194
+ interface Issue {
195
+ origin: 'typescript' | 'eslint';
196
+ severity: 'error' | 'warning';
197
+ code: string;
198
+ file?: string;
199
+ }
200
+
201
+ type IssueMatch = Partial<Issue>; // file field supports glob matching
202
+ type IssuePredicate = (issue: Issue) => boolean;
203
+ type IssueFilter = IssueMatch | IssuePredicate | (IssueMatch | IssuePredicate)[];
204
+ ```
205
+
206
+ | Name | Type | Default value | Description |
207
+ | --------- | ------------- | ------------- | ----------- |
208
+ | `include` | `IssueFilter` | `undefined` | If `object`, defines issue properties that should be [matched](./src/issue/IssueMatch.ts). If `function`, acts as a predicate where `issue` is an argument. |
209
+ | `exclude` | `IssueFilter` | `undefined` | Same as `include` but issues that match this predicate will be excluded. |
210
+
211
+ <details>
212
+ <summary>Expand example</summary>
213
+
214
+ Include issues from the `src` directory, exclude eslint issues from `.spec.ts` files:
215
+
216
+ ```js
217
+ module.exports = {
218
+ // ...the webpack configuration
219
+ plugins: [
220
+ new ForkTsCheckerWebpackPlugin({
221
+ issue: {
222
+ include: [
223
+ { file: '**/src/**/*' }
224
+ ],
225
+ exclude: [
226
+ { origin: 'eslint', file: '**/*.spec.ts' }
227
+ ]
228
+ }
229
+ })
230
+ ]
231
+ };
232
+ ```
233
+
234
+ </details>
197
235
 
198
236
  ## Vue.js
199
237
 
@@ -1,7 +1,15 @@
1
1
  import webpack from 'webpack';
2
2
  import { ForkTsCheckerWebpackPluginOptions } from './ForkTsCheckerWebpackPluginOptions';
3
+ import { Pool } from './utils/async/pool';
3
4
  declare class ForkTsCheckerWebpackPlugin implements webpack.Plugin {
5
+ /**
6
+ * Current version of the plugin
7
+ */
4
8
  static readonly version: string;
9
+ /**
10
+ * Default pool for the plugin concurrency limit
11
+ */
12
+ static readonly pool: Pool;
5
13
  private readonly options;
6
14
  constructor(options?: ForkTsCheckerWebpackPluginOptions);
7
15
  static getCompilerHooks(compiler: webpack.Compiler): {
@@ -20,6 +20,8 @@ const tapAfterCompileToAddDependencies_1 = require("./hooks/tapAfterCompileToAdd
20
20
  const tapErrorToLogMessage_1 = require("./hooks/tapErrorToLogMessage");
21
21
  const pluginHooks_1 = require("./hooks/pluginHooks");
22
22
  const tapAfterEnvironmentToPatchWatching_1 = require("./hooks/tapAfterEnvironmentToPatchWatching");
23
+ const pool_1 = require("./utils/async/pool");
24
+ const os_1 = __importDefault(require("os"));
23
25
  class ForkTsCheckerWebpackPlugin {
24
26
  constructor(options = {}) {
25
27
  const explorerSync = cosmiconfig_1.cosmiconfigSync('fork-ts-checker');
@@ -60,4 +62,11 @@ class ForkTsCheckerWebpackPlugin {
60
62
  }
61
63
  }
62
64
  exports.ForkTsCheckerWebpackPlugin = ForkTsCheckerWebpackPlugin;
63
- ForkTsCheckerWebpackPlugin.version = '6.0.7'; // will be replaced by the @semantic-release/exec
65
+ /**
66
+ * Current version of the plugin
67
+ */
68
+ ForkTsCheckerWebpackPlugin.version = '6.2.0'; // will be replaced by the @semantic-release/exec
69
+ /**
70
+ * Default pool for the plugin concurrency limit
71
+ */
72
+ ForkTsCheckerWebpackPlugin.pool = pool_1.createPool(Math.max(1, os_1.default.cpus().length));
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const FormatterFactory_1 = require("./FormatterFactory");
4
4
  function createFormatterConfiguration(options) {
5
- return FormatterFactory_1.createFormatter(options ? (typeof options === 'string' ? options : options.type || 'codeframe') : 'codeframe', options && typeof options === 'object' ? options.options || {} : {});
5
+ return FormatterFactory_1.createFormatter(options ? (typeof options === 'object' ? options.type || 'codeframe' : options) : 'codeframe', options && typeof options === 'object' ? options.options || {} : {});
6
6
  }
7
7
  exports.createFormatterConfiguration = createFormatterConfiguration;
@@ -1,6 +1,6 @@
1
1
  import { Formatter } from './Formatter';
2
2
  import { BabelCodeFrameOptions } from './CodeFrameFormatter';
3
- declare type NotConfigurableFormatterType = undefined | 'basic';
3
+ declare type NotConfigurableFormatterType = undefined | 'basic' | Formatter;
4
4
  declare type ConfigurableFormatterType = 'codeframe';
5
5
  declare type FormatterType = NotConfigurableFormatterType | ConfigurableFormatterType;
6
6
  declare type ConfigurableFormatterOptions = {
@@ -4,14 +4,15 @@ const CodeFrameFormatter_1 = require("./CodeFrameFormatter");
4
4
  const BasicFormatter_1 = require("./BasicFormatter");
5
5
  // declare function implementation
6
6
  function createFormatter(type, options) {
7
- switch (type) {
8
- case 'basic':
9
- case undefined:
10
- return BasicFormatter_1.createBasicFormatter();
11
- case 'codeframe':
12
- return CodeFrameFormatter_1.createCodeFrameFormatter(options);
13
- default:
14
- throw new Error(`Unknown "${type}" formatter. Available types are: basic, codeframe.`);
7
+ if (typeof type === 'function') {
8
+ return type;
15
9
  }
10
+ if (typeof type === 'undefined' || type === 'basic') {
11
+ return BasicFormatter_1.createBasicFormatter();
12
+ }
13
+ if (type === 'codeframe') {
14
+ return CodeFrameFormatter_1.createCodeFrameFormatter(options);
15
+ }
16
+ throw new Error(`Unknown "${type}" formatter. Available types are: "basic", "codeframe" or a custom function.`);
16
17
  }
17
18
  exports.createFormatter = createFormatter;
@@ -31,7 +31,7 @@ function tapDoneToAsyncGetIssues(compiler, configuration, state) {
31
31
  try {
32
32
  if (yield isPending_1.default(issuesPromise)) {
33
33
  hooks.waiting.call(stats.compilation);
34
- configuration.logger.issues.log(chalk_1.default.blue('Issues checking in progress...'));
34
+ configuration.logger.issues.log(chalk_1.default.cyan('Issues checking in progress...'));
35
35
  }
36
36
  else {
37
37
  // wait 10ms to log issues after webpack stats
@@ -15,6 +15,7 @@ const OperationCanceledError_1 = require("../error/OperationCanceledError");
15
15
  const tapDoneToAsyncGetIssues_1 = require("./tapDoneToAsyncGetIssues");
16
16
  const tapAfterCompileToGetIssues_1 = require("./tapAfterCompileToGetIssues");
17
17
  const interceptDoneToGetWebpackDevServerTap_1 = require("./interceptDoneToGetWebpackDevServerTap");
18
+ const ForkTsCheckerWebpackPlugin_1 = require("../ForkTsCheckerWebpackPlugin");
18
19
  function tapStartToConnectAndRunReporter(compiler, reporter, configuration, state) {
19
20
  const hooks = pluginHooks_1.getForkTsCheckerWebpackPluginHooks(compiler);
20
21
  compiler.hooks.run.tap('ForkTsCheckerWebpackPlugin', () => {
@@ -67,7 +68,7 @@ function tapStartToConnectAndRunReporter(compiler, reporter, configuration, stat
67
68
  rejectIssues = reject;
68
69
  });
69
70
  const previousReportPromise = state.reportPromise;
70
- state.reportPromise = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
71
+ state.reportPromise = ForkTsCheckerWebpackPlugin_1.ForkTsCheckerWebpackPlugin.pool.submit((done) => new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
71
72
  change = yield hooks.start.promise(change, compilation);
72
73
  try {
73
74
  yield reporter.connect();
@@ -83,7 +84,7 @@ function tapStartToConnectAndRunReporter(compiler, reporter, configuration, stat
83
84
  .catch(rejectedDependencies)
84
85
  .finally(() => {
85
86
  // get issues after dependencies are resolved as it can be blocking
86
- report.getIssues().then(resolveIssues).catch(rejectIssues);
87
+ report.getIssues().then(resolveIssues).catch(rejectIssues).finally(done);
87
88
  });
88
89
  }
89
90
  catch (error) {
@@ -96,8 +97,9 @@ function tapStartToConnectAndRunReporter(compiler, reporter, configuration, stat
96
97
  resolve(undefined);
97
98
  resolveDependencies(undefined);
98
99
  resolveIssues(undefined);
100
+ done();
99
101
  }
100
- }));
102
+ })));
101
103
  }));
102
104
  }
103
105
  exports.tapStartToConnectAndRunReporter = tapStartToConnectAndRunReporter;
@@ -0,0 +1,8 @@
1
+ declare type Task<T> = (done: () => void) => Promise<T>;
2
+ interface Pool {
3
+ submit<T>(task: Task<T>): Promise<T>;
4
+ size: number;
5
+ readonly pending: number;
6
+ }
7
+ declare function createPool(size: number): Pool;
8
+ export { Pool, createPool };
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ function createPool(size) {
13
+ let pendingPromises = [];
14
+ const pool = {
15
+ submit(task) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ while (pendingPromises.length >= pool.size) {
18
+ yield Promise.race(pendingPromises).catch(() => undefined);
19
+ }
20
+ let resolve;
21
+ let reject;
22
+ const taskPromise = new Promise((taskResolve, taskReject) => {
23
+ resolve = taskResolve;
24
+ reject = taskReject;
25
+ });
26
+ const donePromise = new Promise((doneResolve) => {
27
+ task(() => {
28
+ doneResolve(undefined);
29
+ pendingPromises = pendingPromises.filter((pendingPromise) => pendingPromise !== donePromise);
30
+ })
31
+ .then(resolve)
32
+ .catch(reject);
33
+ });
34
+ pendingPromises.push(donePromise);
35
+ return taskPromise;
36
+ });
37
+ },
38
+ size,
39
+ get pending() {
40
+ return pendingPromises.length;
41
+ },
42
+ };
43
+ return pool;
44
+ }
45
+ exports.createPool = createPool;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fork-ts-checker-webpack-plugin",
3
- "version": "6.0.7",
3
+ "version": "6.2.0",
4
4
  "description": "Runs typescript type checker and linter on separate process.",
5
5
  "keywords": [
6
6
  "fast",