fork-ts-checker-webpack-plugin 9.2.0 → 10.0.0-alpha.1

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/README.md +23 -13
  2. package/lib/formatter/basic-formatter.js +2 -2
  3. package/lib/formatter/code-frame-formatter.d.ts +3 -2
  4. package/lib/formatter/code-frame-formatter.js +13 -3
  5. package/lib/formatter/formatter-config.js +2 -1
  6. package/lib/formatter/formatter-options.d.ts +1 -1
  7. package/lib/formatter/stats-formatter.js +3 -3
  8. package/lib/formatter/webpack-formatter.js +5 -9
  9. package/lib/hooks/report-issues.d.ts +8 -0
  10. package/lib/hooks/report-issues.js +22 -0
  11. package/lib/hooks/tap-after-compile-to-add-dependencies.js +3 -12
  12. package/lib/hooks/tap-after-compile-to-get-issues.js +6 -27
  13. package/lib/hooks/tap-done-to-async-get-issues.js +12 -32
  14. package/lib/hooks/tap-error-to-log-message.js +5 -7
  15. package/lib/hooks/tap-start-to-run-workers.js +12 -22
  16. package/lib/issue/issue-webpack-error.js +4 -11
  17. package/lib/plugin-options.json +4 -8
  18. package/lib/plugin-state.d.ts +0 -1
  19. package/lib/plugin.js +23 -23
  20. package/lib/rpc/expose-rpc.js +5 -14
  21. package/lib/rpc/rpc-error.js +2 -0
  22. package/lib/rpc/rpc-worker.d.ts +1 -1
  23. package/lib/rpc/rpc-worker.js +7 -7
  24. package/lib/rpc/wrap-rpc.js +3 -12
  25. package/lib/typescript/type-script-package.d.ts +4 -0
  26. package/lib/typescript/type-script-package.js +88 -0
  27. package/lib/typescript/type-script-support.js +8 -18
  28. package/lib/typescript/type-script-worker-config.d.ts +2 -3
  29. package/lib/typescript/type-script-worker-config.js +23 -2
  30. package/lib/typescript/type-script-worker-options.d.ts +4 -3
  31. package/lib/typescript/type-script-worker-options.js +4 -0
  32. package/lib/typescript/worker/get-dependencies-worker.js +15 -4
  33. package/lib/typescript/worker/get-issues-worker.d.ts +1 -1
  34. package/lib/typescript/worker/get-issues-worker.js +52 -64
  35. package/lib/typescript/worker/lib/api.d.ts +13 -0
  36. package/lib/typescript/worker/lib/api.js +62 -0
  37. package/lib/typescript/worker/lib/config.d.ts +13 -9
  38. package/lib/typescript/worker/lib/config.js +63 -63
  39. package/lib/typescript/worker/lib/dependencies.d.ts +6 -1
  40. package/lib/typescript/worker/lib/dependencies.js +168 -43
  41. package/lib/typescript/worker/lib/diagnostics.d.ts +5 -4
  42. package/lib/typescript/worker/lib/diagnostics.js +44 -50
  43. package/lib/typescript/worker/lib/in-memory-file-system.d.ts +14 -0
  44. package/lib/typescript/worker/lib/in-memory-file-system.js +140 -0
  45. package/lib/typescript/worker/lib/performance.d.ts +1 -2
  46. package/lib/typescript/worker/lib/performance.js +12 -19
  47. package/lib/typescript/worker/lib/program/program.d.ts +6 -2
  48. package/lib/typescript/worker/lib/program/program.js +135 -24
  49. package/lib/typescript/worker/lib/program/solution-builder.d.ts +3 -1
  50. package/lib/typescript/worker/lib/program/solution-builder.js +41 -24
  51. package/lib/typescript/worker/lib/typescript.d.ts +4 -2
  52. package/lib/typescript/worker/lib/typescript.js +69 -3
  53. package/lib/utils/async/abort-error.d.ts +0 -1
  54. package/lib/utils/async/abort-error.js +1 -1
  55. package/lib/utils/async/pool.d.ts +0 -1
  56. package/lib/utils/async/pool.js +12 -23
  57. package/lib/utils/deep-merge.d.ts +5 -0
  58. package/lib/utils/deep-merge.js +56 -0
  59. package/lib/utils/path/format-file-path.d.ts +3 -0
  60. package/lib/utils/path/format-file-path.js +15 -0
  61. package/lib/watch/inclusive-node-watch-file-system.d.ts +3 -0
  62. package/lib/watch/inclusive-node-watch-file-system.js +119 -111
  63. package/package.json +30 -38
  64. package/lib/formatter/types/babel__code-frame.d.ts +0 -21
  65. package/lib/formatter/types/babel__code-frame.js +0 -7
  66. package/lib/typescript/worker/lib/artifacts.d.ts +0 -4
  67. package/lib/typescript/worker/lib/artifacts.js +0 -103
  68. package/lib/typescript/worker/lib/emit.d.ts +0 -2
  69. package/lib/typescript/worker/lib/emit.js +0 -12
  70. package/lib/typescript/worker/lib/file-system/file-system.d.ts +0 -17
  71. package/lib/typescript/worker/lib/file-system/file-system.js +0 -2
  72. package/lib/typescript/worker/lib/file-system/mem-file-system.d.ts +0 -5
  73. package/lib/typescript/worker/lib/file-system/mem-file-system.js +0 -79
  74. package/lib/typescript/worker/lib/file-system/passive-file-system.d.ts +0 -5
  75. package/lib/typescript/worker/lib/file-system/passive-file-system.js +0 -65
  76. package/lib/typescript/worker/lib/file-system/real-file-system.d.ts +0 -5
  77. package/lib/typescript/worker/lib/file-system/real-file-system.js +0 -201
  78. package/lib/typescript/worker/lib/host/compiler-host.d.ts +0 -2
  79. package/lib/typescript/worker/lib/host/compiler-host.js +0 -9
  80. package/lib/typescript/worker/lib/host/watch-compiler-host.d.ts +0 -2
  81. package/lib/typescript/worker/lib/host/watch-compiler-host.js +0 -19
  82. package/lib/typescript/worker/lib/host/watch-solution-builder-host.d.ts +0 -2
  83. package/lib/typescript/worker/lib/host/watch-solution-builder-host.js +0 -46
  84. package/lib/typescript/worker/lib/program/watch-program.d.ts +0 -3
  85. package/lib/typescript/worker/lib/program/watch-program.js +0 -50
  86. package/lib/typescript/worker/lib/system.d.ts +0 -19
  87. package/lib/typescript/worker/lib/system.js +0 -232
  88. package/lib/typescript/worker/lib/tracing.d.ts +0 -4
  89. package/lib/typescript/worker/lib/tracing.js +0 -28
  90. package/lib/typescript/worker/lib/tsbuildinfo.d.ts +0 -4
  91. package/lib/typescript/worker/lib/tsbuildinfo.js +0 -105
package/README.md CHANGED
@@ -23,8 +23,12 @@
23
23
 
24
24
  ## Installation
25
25
 
26
- This plugin requires **Node.js >=14.0.0+**, **Webpack ^5.11.0**, **TypeScript ^3.6.0**
26
+ This plugin requires **Node.js ^22.22.0 || >=24.11.0**, **Webpack ^5.11.0**, **TypeScript >=7.1.0** (until TypeScript 7.1 has a stable release, that means `typescript@beta`)
27
27
 
28
+ It type checks with TypeScript's native API (`typescript/sync`), so it pairs with [ts-loader v10](https://github.com/TypeStrong/ts-loader), which is built on the same API.
29
+ TypeScript's native compiler resolves modules from the file system itself, so [Yarn Plug'n'Play](https://yarnpkg.com/features/pnp) isn't supported - use `nodeLinker: node-modules`.
30
+
31
+ * If you depend on **TypeScript 3.6 - 6.x**, please use [version 9](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/tree/v9.1.0) of the plugin.
28
32
  * If you depend on **TypeScript 2.1 - 2.6.2**, please use [version 4](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/tree/v4.1.4) of the plugin.
29
33
  * If you depend on **Webpack 4**, **TypeScript 2.7 - 3.5.3** or **ESLint** feature, please use [version 6](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/tree/v6.2.6) of the plugin.
30
34
  * If you depend on **Node.js 12**, please use [version 8](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/tree/v8.0.0) of the plugin.
@@ -94,8 +98,14 @@ you can place your configuration in the:
94
98
  * `"fork-ts-checker"` field in the `package.json`
95
99
  * `.fork-ts-checkerrc` file in JSON or YAML format
96
100
  * `fork-ts-checker.config.js` file exporting a JS object
101
+ * `fork-ts-checker.config.ts` file exporting a JS object
102
+
103
+ A `fork-ts-checker.config.ts` file is loaded with Node.js's built-in type stripping, not with the `typescript` package.
104
+ Type annotations, interfaces and `import type` work, but syntax that needs transforming, such as `enum` and `namespace`, does not.
97
105
 
98
- Options passed to the plugin constructor will overwrite options from the cosmiconfig (using [deepmerge](https://github.com/TehShrike/deepmerge)).
106
+ The configuration file is only looked for in the current working directory. Parent directories are not searched.
107
+
108
+ Options passed to the plugin constructor will overwrite options from the cosmiconfig (objects are merged deeply and arrays are concatenated).
99
109
 
100
110
  | Name | Type | Default value | Description |
101
111
  |--------------|--------------------------------------|-------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -112,15 +122,14 @@ Options for the TypeScript checker (`typescript` option object).
112
122
 
113
123
  | Name | Type | Default value | Description |
114
124
  |---------------------|--------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
115
- | `memoryLimit` | `number` | `2048` | Memory limit for the checker process in MB. If the process exits with the allocation failed error, try to increase this number. |
116
125
  | `configFile` | `string` | `'tsconfig.json'` | Path to the `tsconfig.json` file (path relative to the `compiler.options.context` or absolute path) |
117
- | `configOverwrite` | `object` | `{ compilerOptions: { skipLibCheck: true, sourceMap: false, inlineSourceMap: false, declarationMap: false } }` | This configuration will overwrite configuration from the `tsconfig.json` file. Supported fields are: `extends`, `compilerOptions`, `include`, `exclude`, `files`, and `references`. |
126
+ | `configOverwrite` | `object` | `{ compilerOptions: { skipLibCheck: true, sourceMap: false, inlineSourceMap: false, declarationMap: false } }` | This configuration will overwrite configuration from the `tsconfig.json` file. Supported fields are: `extends`, `compilerOptions`, `include`, `exclude`, `files`, and `references`. In `build` mode, TypeScript reads each project's `tsconfig.json` itself, so only these `compilerOptions` apply: `incremental`, `declaration`, `declarationMap`, `emitDeclarationOnly`, `sourceMap`, `inlineSourceMap`, `traceResolution`, and `assumeChangesOnlyAffectDirectDependencies`. |
118
127
  | `context` | `string` | `dirname(configuration.configFile)` | The base path for finding files specified in the `tsconfig.json`. Same as the `context` option from the [ts-loader](https://github.com/TypeStrong/ts-loader#context). Useful if you want to keep your `tsconfig.json` in an external package. Keep in mind that **not** having a `tsconfig.json` in your project root can cause different behaviour between `fork-ts-checker-webpack-plugin` and `tsc`. When using editors like `VS Code` it is advised to add a `tsconfig.json` file to the root of the project and extend the config file referenced in option `configFile`. |
119
- | `build` | `boolean` | `false` | The equivalent of the `--build` flag for the `tsc` command. |
120
- | `mode` | `'readonly'` or `'write-dts'` or `'write-tsbuildinfo'` or `'write-references'` | `build === true ? 'write-tsbuildinfo' ? 'readonly'` | Use `readonly` if you don't want to write anything on the disk, `write-dts` to write only `.d.ts` files, `write-tsbuildinfo` to write only `.tsbuildinfo` files, `write-references` to write both `.js` and `.d.ts` files of project references (last 2 modes requires `build: true`). |
121
- | `diagnosticOptions` | `object` | `{ syntactic: false, semantic: true, declaration: false, global: false }` | Settings to select which diagnostics do we want to perform. |
122
- | `profile` | `boolean` | `false` | Measures and prints timings related to the TypeScript performance. |
123
- | `typescriptPath` | `string` | `require.resolve('typescript')` | If supplied this is a custom path where TypeScript can be found. |
128
+ | `build` | `boolean` | `false` | The equivalent of the `--build` flag for the `tsc` command. Like `tsc --build`, it reports every diagnostic of each project, so `diagnosticOptions` doesn't apply, and it doesn't apply the implicit `skipLibCheck: true` - set `skipLibCheck` in your `tsconfig.json` if you need it. |
129
+ | `mode` | `'in-memory'` or `'write'` | `'in-memory'` | Use `in-memory` if you don't want to write anything on the disk. Use `write` to write the `.d.ts` files, or with `build: true` all the outputs of the build (`.js`, `.d.ts` and `.tsbuildinfo` files), like `tsc --build`. With `build: true` in the `in-memory` mode, `.tsbuildinfo` files from a previous run are ignored, so the first check after a restart is a full one. |
130
+ | `diagnosticOptions` | `object` | `{ syntactic: false, semantic: true, declaration: false, global: false }` | Settings to select which diagnostics do we want to perform. Ignored in `build` mode. |
131
+ | `profile` | `boolean` | `false` | Measures and prints timings of the requests made to TypeScript's native compiler. |
132
+ | `typescriptPath` | `string` | `require.resolve('typescript')` | If supplied this is a custom path where TypeScript can be found (the package directory or any file inside it). It must be TypeScript 7.1 or newer, exposing the `typescript/sync` API. |
124
133
 
125
134
  ### Issues options
126
135
 
@@ -221,10 +230,9 @@ module.exports = {
221
230
 
222
231
  ## Profiling types resolution
223
232
 
224
- When using TypeScript 4.3.0 or newer you can profile long type checks by
225
- setting "generateTrace" compiler option. This is an instruction from [microsoft/TypeScript#40063](https://github.com/microsoft/TypeScript/pull/40063):
233
+ To profile long type checks, run `tsc` with the `--generateTrace` option. This is an instruction from [microsoft/TypeScript#40063](https://github.com/microsoft/TypeScript/pull/40063):
226
234
 
227
- 1. Set "generateTrace": "{folderName}" in your `tsconfig.json` (under `compilerOptions`)
235
+ 1. Run `tsc --noEmit --generateTrace {folderName}` (or `tsc --build --generateTrace {folderName}` for project references)
228
236
  2. Look in the resulting folder. If you used build mode, there will be a `legend.json` telling you what went where.
229
237
  Otherwise, there will be `trace.json` file and `types.json` files.
230
238
  3. Navigate to [edge://tracing](edge://tracing) or [chrome://tracing](chrome://tracing) and load `trace.json`
@@ -235,7 +243,9 @@ setting "generateTrace" compiler option. This is an instruction from [microsoft/
235
243
 
236
244
  ## Enabling incremental mode
237
245
 
238
- You must both set "incremental": true in your `tsconfig.json` (under `compilerOptions`) and also specify mode: 'write-references' in `ForkTsCheckerWebpackPlugin` settings.
246
+ Set `"incremental": true` in your `tsconfig.json` (under `compilerOptions`) and `build: true` in the plugin's `typescript` options. With the default `in-memory` mode the outputs, including the `.tsbuildinfo` files, are kept in memory. It makes the checks after the first one incremental while the plugin is running, but the first check after a restart is a full one.
247
+
248
+ To reuse the `.tsbuildinfo` files after a restart, use the `write` mode, which also writes the `.js` and `.d.ts` files, like `tsc --build`.
239
249
 
240
250
 
241
251
  ## Related projects
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createBasicFormatter = createBasicFormatter;
7
- const chalk_1 = __importDefault(require("chalk"));
7
+ const picocolors_1 = __importDefault(require("picocolors"));
8
8
  function createBasicFormatter() {
9
9
  return function basicFormatter(issue) {
10
- return chalk_1.default.grey(issue.code + ': ') + issue.message;
10
+ return picocolors_1.default.gray(issue.code + ': ') + issue.message;
11
11
  };
12
12
  }
@@ -1,4 +1,5 @@
1
+ import type { Options as BabelCodeFrameOptions } from '@babel/code-frame';
1
2
  import type { Formatter } from './formatter';
2
- import { BabelCodeFrameOptions } from './types/babel__code-frame';
3
3
  declare function createCodeFrameFormatter(options?: BabelCodeFrameOptions): Formatter;
4
- export { createCodeFrameFormatter, BabelCodeFrameOptions };
4
+ export { createCodeFrameFormatter };
5
+ export type { BabelCodeFrameOptions };
@@ -4,17 +4,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createCodeFrameFormatter = createCodeFrameFormatter;
7
+ const fs_1 = __importDefault(require("fs"));
7
8
  const os_1 = __importDefault(require("os"));
8
9
  const code_frame_1 = require("@babel/code-frame");
9
- const fs_extra_1 = __importDefault(require("fs-extra"));
10
10
  const basic_formatter_1 = require("./basic-formatter");
11
11
  function createCodeFrameFormatter(options) {
12
12
  const basicFormatter = (0, basic_formatter_1.createBasicFormatter)();
13
13
  return function codeFrameFormatter(issue) {
14
- const source = issue.file && fs_extra_1.default.existsSync(issue.file) && fs_extra_1.default.readFileSync(issue.file, 'utf-8');
14
+ const source = issue.file && fs_1.default.existsSync(issue.file) && fs_1.default.readFileSync(issue.file, 'utf-8');
15
15
  let frame = '';
16
16
  if (source && issue.location) {
17
- frame = (0, code_frame_1.codeFrameColumns)(source, issue.location, Object.assign({ highlightCode: true }, (options || {})))
17
+ // issue columns are 1-based, @babel/code-frame 8 expects 0-based columns
18
+ const { start, end } = issue.location;
19
+ const location = {
20
+ start: { line: start.line, column: start.column - 1 },
21
+ // custom issues may come without an end position
22
+ end: end && { line: end.line, column: end.column - 1 },
23
+ };
24
+ frame = (0, code_frame_1.codeFrameColumns)(source, location, {
25
+ highlightCode: true,
26
+ ...(options || {}),
27
+ })
18
28
  .split('\n')
19
29
  .map((line) => ' ' + line)
20
30
  .join(os_1.default.EOL);
@@ -31,5 +31,6 @@ function createFormatterConfig(options) {
31
31
  pathType,
32
32
  };
33
33
  }
34
- throw new Error(`Unknown "${type}" formatter. Available types are: "basic", "codeframe" or a custom function.`);
34
+ const typeName = String(type);
35
+ throw new Error(`Unknown "${typeName}" formatter. Available types are: "basic", "codeframe" or a custom function.`);
35
36
  }
@@ -1,5 +1,5 @@
1
+ import type { Options as BabelCodeFrameOptions } from '@babel/code-frame';
1
2
  import type { Formatter, FormatterPathType } from './formatter';
2
- import type { BabelCodeFrameOptions } from './types/babel__code-frame';
3
3
  type FormatterType = 'basic' | 'codeframe';
4
4
  type BasicFormatterOptions = {
5
5
  type: 'basic';
@@ -4,16 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.statsFormatter = statsFormatter;
7
- const chalk_1 = __importDefault(require("chalk"));
7
+ const picocolors_1 = __importDefault(require("picocolors"));
8
8
  // mimics webpack's stats summary formatter
9
9
  function statsFormatter(issues, stats) {
10
10
  const errorsNumber = issues.filter((issue) => issue.severity === 'error').length;
11
11
  const warningsNumber = issues.filter((issue) => issue.severity === 'warning').length;
12
12
  const errorsFormatted = errorsNumber
13
- ? chalk_1.default.red.bold(`${errorsNumber} ${errorsNumber === 1 ? 'error' : 'errors'}`)
13
+ ? picocolors_1.default.bold(picocolors_1.default.red(`${errorsNumber} ${errorsNumber === 1 ? 'error' : 'errors'}`))
14
14
  : '';
15
15
  const warningsFormatted = warningsNumber
16
- ? chalk_1.default.yellow.bold(`${warningsNumber} ${warningsNumber === 1 ? 'warning' : 'warnings'}`)
16
+ ? picocolors_1.default.bold(picocolors_1.default.yellow(`${warningsNumber} ${warningsNumber === 1 ? 'warning' : 'warnings'}`))
17
17
  : '';
18
18
  const timeFormatted = Math.round(Date.now() - stats.startTime);
19
19
  return [
@@ -5,22 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createWebpackFormatter = createWebpackFormatter;
7
7
  const os_1 = __importDefault(require("os"));
8
- const path_1 = __importDefault(require("path"));
9
- const chalk_1 = __importDefault(require("chalk"));
8
+ const picocolors_1 = __importDefault(require("picocolors"));
10
9
  const issue_1 = require("../issue");
11
- const forward_slash_1 = require("../utils/path/forward-slash");
12
- const relative_to_context_1 = require("../utils/path/relative-to-context");
10
+ const format_file_path_1 = require("../utils/path/format-file-path");
13
11
  function createWebpackFormatter(formatter, pathType) {
14
12
  // mimics webpack error formatter
15
13
  return function webpackFormatter(issue) {
16
- const color = issue.severity === 'warning' ? chalk_1.default.yellow.bold : chalk_1.default.red.bold;
14
+ const color = (text) => picocolors_1.default.bold(issue.severity === 'warning' ? picocolors_1.default.yellow(text) : picocolors_1.default.red(text));
17
15
  const severity = issue.severity.toUpperCase();
18
16
  if (issue.file) {
19
- let location = chalk_1.default.bold(pathType === 'absolute'
20
- ? (0, forward_slash_1.forwardSlash)(path_1.default.resolve(issue.file))
21
- : (0, relative_to_context_1.relativeToContext)(issue.file, process.cwd()));
17
+ let location = picocolors_1.default.bold((0, format_file_path_1.formatFilePath)(issue.file, pathType));
22
18
  if (issue.location) {
23
- location += `:${chalk_1.default.green.bold((0, issue_1.formatIssueLocation)(issue.location))}`;
19
+ location += `:${picocolors_1.default.bold(picocolors_1.default.green((0, issue_1.formatIssueLocation)(issue.location)))}`;
24
20
  }
25
21
  return [`${color(severity)} in ${location}`, formatter(issue), ''].join(os_1.default.EOL);
26
22
  }
@@ -0,0 +1,8 @@
1
+ import type * as webpack from 'webpack';
2
+ import type { Issue } from '../issue';
3
+ import type { ForkTsCheckerWebpackPluginConfig } from '../plugin-config';
4
+ /** Applies the `issue` option's predicate, then lets the plugin hooks modify the list. */
5
+ declare function getIssuesToReport(issues: Issue[], compilation: webpack.Compilation, config: ForkTsCheckerWebpackPluginConfig): Issue[];
6
+ /** Adds the issues to the compilation as webpack errors and warnings. */
7
+ declare function addIssuesToCompilation(issues: Issue[], compilation: webpack.Compilation, config: ForkTsCheckerWebpackPluginConfig): void;
8
+ export { getIssuesToReport, addIssuesToCompilation };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIssuesToReport = getIssuesToReport;
4
+ exports.addIssuesToCompilation = addIssuesToCompilation;
5
+ const issue_webpack_error_1 = require("../issue/issue-webpack-error");
6
+ const plugin_hooks_1 = require("../plugin-hooks");
7
+ /** Applies the `issue` option's predicate, then lets the plugin hooks modify the list. */
8
+ function getIssuesToReport(issues, compilation, config) {
9
+ return (0, plugin_hooks_1.getPluginHooks)(compilation.compiler).issues.call(issues.filter(config.issue.predicate), compilation);
10
+ }
11
+ /** Adds the issues to the compilation as webpack errors and warnings. */
12
+ function addIssuesToCompilation(issues, compilation, config) {
13
+ for (const issue of issues) {
14
+ const error = new issue_webpack_error_1.IssueWebpackError(config.formatter.format(issue), config.formatter.pathType, issue);
15
+ if (issue.severity === 'warning') {
16
+ compilation.warnings.push(error);
17
+ }
18
+ else {
19
+ compilation.errors.push(error);
20
+ }
21
+ }
22
+ }
@@ -1,24 +1,15 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.tapAfterCompileToAddDependencies = tapAfterCompileToAddDependencies;
13
4
  const infrastructure_logger_1 = require("../infrastructure-logger");
14
5
  function tapAfterCompileToAddDependencies(compiler, config, state) {
15
6
  const { debug } = (0, infrastructure_logger_1.getInfrastructureLogger)(compiler);
16
- compiler.hooks.afterCompile.tapPromise('ForkTsCheckerWebpackPlugin', (compilation) => __awaiter(this, void 0, void 0, function* () {
7
+ compiler.hooks.afterCompile.tapPromise('ForkTsCheckerWebpackPlugin', async (compilation) => {
17
8
  if (compilation.compiler !== compiler) {
18
9
  // run only for the compiler that the plugin was registered for
19
10
  return;
20
11
  }
21
- const dependencies = yield state.dependenciesPromise;
12
+ const dependencies = await state.dependenciesPromise;
22
13
  debug(`Got dependencies from the getDependenciesWorker.`, dependencies);
23
14
  if (dependencies) {
24
15
  state.lastDependencies = dependencies;
@@ -26,5 +17,5 @@ function tapAfterCompileToAddDependencies(compiler, config, state) {
26
17
  compilation.fileDependencies.add(file);
27
18
  });
28
19
  }
29
- }));
20
+ });
30
21
  }
@@ -1,51 +1,30 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.tapAfterCompileToGetIssues = tapAfterCompileToGetIssues;
13
4
  const infrastructure_logger_1 = require("../infrastructure-logger");
14
- const issue_webpack_error_1 = require("../issue/issue-webpack-error");
15
5
  const plugin_hooks_1 = require("../plugin-hooks");
6
+ const report_issues_1 = require("./report-issues");
16
7
  function tapAfterCompileToGetIssues(compiler, config, state) {
17
8
  const hooks = (0, plugin_hooks_1.getPluginHooks)(compiler);
18
9
  const { debug } = (0, infrastructure_logger_1.getInfrastructureLogger)(compiler);
19
- compiler.hooks.afterCompile.tapPromise('ForkTsCheckerWebpackPlugin', (compilation) => __awaiter(this, void 0, void 0, function* () {
10
+ compiler.hooks.afterCompile.tapPromise('ForkTsCheckerWebpackPlugin', async (compilation) => {
20
11
  if (compilation.compiler !== compiler) {
21
12
  // run only for the compiler that the plugin was registered for
22
13
  return;
23
14
  }
24
15
  let issues = [];
25
16
  try {
26
- issues = yield state.issuesPromise;
17
+ issues = await state.issuesPromise;
27
18
  }
28
19
  catch (error) {
29
20
  hooks.error.call(error, compilation);
30
21
  return;
31
22
  }
32
- debug('Got issues from getIssuesWorker.', issues === null || issues === void 0 ? void 0 : issues.length);
23
+ debug('Got issues from getIssuesWorker.', issues?.length);
33
24
  if (!issues) {
34
25
  // some error has been thrown or it was canceled
35
26
  return;
36
27
  }
37
- // filter list of issues by provided issue predicate
38
- issues = issues.filter(config.issue.predicate);
39
- // modify list of issues in the plugin hooks
40
- issues = hooks.issues.call(issues, compilation);
41
- issues.forEach((issue) => {
42
- const error = new issue_webpack_error_1.IssueWebpackError(config.formatter.format(issue), config.formatter.pathType, issue);
43
- if (issue.severity === 'warning') {
44
- compilation.warnings.push(error);
45
- }
46
- else {
47
- compilation.errors.push(error);
48
- }
49
- });
50
- }));
28
+ (0, report_issues_1.addIssuesToCompilation)((0, report_issues_1.getIssuesToReport)(issues, compilation, config), compilation, config);
29
+ });
51
30
  }
@@ -1,30 +1,21 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.tapDoneToAsyncGetIssues = tapDoneToAsyncGetIssues;
16
- const chalk_1 = __importDefault(require("chalk"));
7
+ const picocolors_1 = __importDefault(require("picocolors"));
17
8
  const stats_formatter_1 = require("../formatter/stats-formatter");
18
9
  const webpack_formatter_1 = require("../formatter/webpack-formatter");
19
10
  const infrastructure_logger_1 = require("../infrastructure-logger");
20
- const issue_webpack_error_1 = require("../issue/issue-webpack-error");
21
11
  const plugin_hooks_1 = require("../plugin-hooks");
22
12
  const is_pending_1 = require("../utils/async/is-pending");
23
13
  const wait_1 = require("../utils/async/wait");
14
+ const report_issues_1 = require("./report-issues");
24
15
  function tapDoneToAsyncGetIssues(compiler, config, state) {
25
16
  const hooks = (0, plugin_hooks_1.getPluginHooks)(compiler);
26
17
  const { debug } = (0, infrastructure_logger_1.getInfrastructureLogger)(compiler);
27
- compiler.hooks.done.tap('ForkTsCheckerWebpackPlugin', (stats) => __awaiter(this, void 0, void 0, function* () {
18
+ compiler.hooks.done.tap('ForkTsCheckerWebpackPlugin', async (stats) => {
28
19
  if (stats.compilation.compiler !== compiler) {
29
20
  // run only for the compiler that the plugin was registered for
30
21
  return;
@@ -32,15 +23,15 @@ function tapDoneToAsyncGetIssues(compiler, config, state) {
32
23
  const issuesPromise = state.issuesPromise;
33
24
  let issues;
34
25
  try {
35
- if (yield (0, is_pending_1.isPending)(issuesPromise)) {
26
+ if (await (0, is_pending_1.isPending)(issuesPromise)) {
36
27
  hooks.waiting.call(stats.compilation);
37
- config.logger.log(chalk_1.default.cyan('Type-checking in progress...'));
28
+ config.logger.log(picocolors_1.default.cyan('Type-checking in progress...'));
38
29
  }
39
30
  else {
40
31
  // wait 10ms to log issues after webpack stats
41
- yield (0, wait_1.wait)(10);
32
+ await (0, wait_1.wait)(10);
42
33
  }
43
- issues = yield issuesPromise;
34
+ issues = await issuesPromise;
44
35
  }
45
36
  catch (error) {
46
37
  hooks.error.call(error, stats.compilation);
@@ -51,11 +42,8 @@ function tapDoneToAsyncGetIssues(compiler, config, state) {
51
42
  ) {
52
43
  return;
53
44
  }
54
- debug(`Got ${(issues === null || issues === void 0 ? void 0 : issues.length) || 0} issues from getIssuesWorker.`);
55
- // filter list of issues by provided issue predicate
56
- issues = issues.filter(config.issue.predicate);
57
- // modify list of issues in the plugin hooks
58
- issues = hooks.issues.call(issues, stats.compilation);
45
+ debug(`Got ${issues?.length || 0} issues from getIssuesWorker.`);
46
+ issues = (0, report_issues_1.getIssuesToReport)(issues, stats.compilation, config);
59
47
  const formatter = (0, webpack_formatter_1.createWebpackFormatter)(config.formatter.format, config.formatter.pathType);
60
48
  if (issues.length) {
61
49
  // follow webpack's approach - one process.write to stderr with all errors and warnings
@@ -64,22 +52,14 @@ function tapDoneToAsyncGetIssues(compiler, config, state) {
64
52
  config.logger.log((0, stats_formatter_1.statsFormatter)(issues, stats));
65
53
  }
66
54
  else {
67
- config.logger.log(chalk_1.default.green('No typescript errors found.'));
55
+ config.logger.log(picocolors_1.default.green('No typescript errors found.'));
68
56
  }
69
57
  // report issues to webpack-dev-server, if it's listening
70
58
  // skip reporting if there are no issues, to avoid an extra hot reload
71
59
  if (issues.length && state.webpackDevServerDoneTap) {
72
- issues.forEach((issue) => {
73
- const error = new issue_webpack_error_1.IssueWebpackError(config.formatter.format(issue), config.formatter.pathType, issue);
74
- if (issue.severity === 'warning') {
75
- stats.compilation.warnings.push(error);
76
- }
77
- else {
78
- stats.compilation.errors.push(error);
79
- }
80
- });
60
+ (0, report_issues_1.addIssuesToCompilation)(issues, stats.compilation, config);
81
61
  debug('Sending issues to the webpack-dev-server.');
82
62
  state.webpackDevServerDoneTap.fn(stats);
83
63
  }
84
- }));
64
+ });
85
65
  }
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.tapErrorToLogMessage = tapErrorToLogMessage;
7
- const chalk_1 = __importDefault(require("chalk"));
7
+ const picocolors_1 = __importDefault(require("picocolors"));
8
8
  const plugin_hooks_1 = require("../plugin-hooks");
9
9
  const rpc_1 = require("../rpc");
10
10
  const abort_error_1 = require("../utils/async/abort-error");
@@ -17,14 +17,12 @@ function tapErrorToLogMessage(compiler, config) {
17
17
  config.logger.error(String(error));
18
18
  if (error instanceof rpc_1.RpcExitError) {
19
19
  if (error.signal === 'SIGINT') {
20
- config.logger.error(chalk_1.default.red('Issues checking service interrupted - If running in a docker container, this may be caused ' +
21
- "by the container running out of memory. If so, try increasing the container's memory limit " +
22
- 'or lowering the `memoryLimit` value in the ForkTsCheckerWebpackPlugin configuration.'));
20
+ config.logger.error(picocolors_1.default.red('Issues checking service interrupted - If running in a docker container, this may be caused ' +
21
+ "by the container running out of memory. If so, try increasing the container's memory limit."));
23
22
  }
24
23
  else {
25
- config.logger.error(chalk_1.default.red('Issues checking service aborted - probably out of memory. ' +
26
- 'Check the `memoryLimit` option in the ForkTsCheckerWebpackPlugin configuration.\n' +
27
- "If increasing the memory doesn't solve the issue, it's most probably a bug in the TypeScript."));
24
+ config.logger.error(picocolors_1.default.red('Issues checking service aborted - probably out of memory. ' +
25
+ "If increasing the available memory doesn't solve the issue, it's most probably a bug in the TypeScript."));
28
26
  }
29
27
  }
30
28
  });
@@ -1,16 +1,6 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.tapStartToRunWorkers = tapStartToRunWorkers;
13
- const node_abort_controller_1 = require("node-abort-controller");
14
4
  const files_change_1 = require("../files-change");
15
5
  const infrastructure_logger_1 = require("../infrastructure-logger");
16
6
  const plugin_hooks_1 = require("../plugin-hooks");
@@ -29,7 +19,7 @@ function tapStartToRunWorkers(compiler, getIssuesWorker, getDependenciesWorker,
29
19
  (0, tap_after_compile_to_get_issues_1.tapAfterCompileToGetIssues)(compiler, config, state);
30
20
  }
31
21
  });
32
- compiler.hooks.watchRun.tap('ForkTsCheckerWebpackPlugin', () => __awaiter(this, void 0, void 0, function* () {
22
+ compiler.hooks.watchRun.tap('ForkTsCheckerWebpackPlugin', async () => {
33
23
  if (!state.initialized) {
34
24
  state.initialized = true;
35
25
  state.watching = true;
@@ -43,8 +33,8 @@ function tapStartToRunWorkers(compiler, getIssuesWorker, getDependenciesWorker,
43
33
  (0, tap_after_compile_to_get_issues_1.tapAfterCompileToGetIssues)(compiler, config, state);
44
34
  }
45
35
  }
46
- }));
47
- compiler.hooks.compilation.tap('ForkTsCheckerWebpackPlugin', (compilation) => __awaiter(this, void 0, void 0, function* () {
36
+ });
37
+ compiler.hooks.compilation.tap('ForkTsCheckerWebpackPlugin', async (compilation) => {
48
38
  if (compilation.compiler !== compiler) {
49
39
  // run only for the compiler that the plugin was registered for
50
40
  return;
@@ -57,7 +47,7 @@ function tapStartToRunWorkers(compiler, getIssuesWorker, getDependenciesWorker,
57
47
  state.abortController.abort();
58
48
  }
59
49
  // create new abort controller for the new iteration
60
- const abortController = new node_abort_controller_1.AbortController();
50
+ const abortController = new AbortController();
61
51
  state.abortController = abortController;
62
52
  let filesChange = {};
63
53
  if (state.watching) {
@@ -71,7 +61,7 @@ function tapStartToRunWorkers(compiler, getIssuesWorker, getDependenciesWorker,
71
61
  else {
72
62
  log('Calling reporter service for single check.');
73
63
  }
74
- filesChange = yield hooks.start.promise(filesChange, compilation);
64
+ filesChange = await hooks.start.promise(filesChange, compilation);
75
65
  let aggregatedFilesChange = filesChange;
76
66
  if (state.aggregatedFilesChange) {
77
67
  aggregatedFilesChange = (0, files_change_1.aggregateFilesChanges)([aggregatedFilesChange, filesChange]);
@@ -92,10 +82,10 @@ function tapStartToRunWorkers(compiler, getIssuesWorker, getDependenciesWorker,
92
82
  return undefined;
93
83
  }
94
84
  debug(`Submitting the getIssuesWorker to the pool, iteration ${iteration}.`);
95
- return plugin_pools_1.issuesPool.submit(() => __awaiter(this, void 0, void 0, function* () {
85
+ return plugin_pools_1.issuesPool.submit(async () => {
96
86
  try {
97
87
  debug(`Running the getIssuesWorker, iteration ${iteration}.`);
98
- const issues = yield getIssuesWorker(aggregatedFilesChange, state.watching);
88
+ const issues = await getIssuesWorker(aggregatedFilesChange);
99
89
  if (state.aggregatedFilesChange === aggregatedFilesChange) {
100
90
  state.aggregatedFilesChange = undefined;
101
91
  }
@@ -111,13 +101,13 @@ function tapStartToRunWorkers(compiler, getIssuesWorker, getDependenciesWorker,
111
101
  finally {
112
102
  debug(`The getIssuesWorker finished its job, iteration ${iteration}.`);
113
103
  }
114
- }), abortController.signal);
104
+ }, abortController.signal);
115
105
  });
116
106
  debug(`Submitting the getDependenciesWorker to the pool, iteration ${iteration}.`);
117
- state.dependenciesPromise = plugin_pools_1.dependenciesPool.submit(() => __awaiter(this, void 0, void 0, function* () {
107
+ state.dependenciesPromise = plugin_pools_1.dependenciesPool.submit(async () => {
118
108
  try {
119
109
  debug(`Running the getDependenciesWorker, iteration ${iteration}.`);
120
- return yield getDependenciesWorker(filesChange);
110
+ return await getDependenciesWorker(filesChange);
121
111
  }
122
112
  catch (error) {
123
113
  hooks.error.call(error, compilation);
@@ -126,6 +116,6 @@ function tapStartToRunWorkers(compiler, getIssuesWorker, getDependenciesWorker,
126
116
  finally {
127
117
  debug(`The getDependenciesWorker finished its job, iteration ${iteration}.`);
128
118
  }
129
- })); // don't pass abortController.signal because getDependencies() is blocking
130
- }));
119
+ }); // don't pass abortController.signal because getDependencies() is blocking
120
+ });
131
121
  }
@@ -32,29 +32,22 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
35
  Object.defineProperty(exports, "__esModule", { value: true });
39
36
  exports.IssueWebpackError = void 0;
40
- const path_1 = __importDefault(require("path"));
41
37
  const webpack = __importStar(require("webpack"));
42
- const forward_slash_1 = require("../utils/path/forward-slash");
43
- const relative_to_context_1 = require("../utils/path/relative-to-context");
38
+ const format_file_path_1 = require("../utils/path/format-file-path");
44
39
  const issue_location_1 = require("./issue-location");
45
40
  class IssueWebpackError extends webpack.WebpackError {
41
+ issue;
42
+ hideStack = true;
46
43
  constructor(message, pathType, issue) {
47
44
  super(message);
48
45
  this.issue = issue;
49
- this.hideStack = true;
50
46
  // to display issue location using `loc` property, webpack requires `error.module` which
51
47
  // should be a NormalModule instance.
52
48
  // to avoid such a dependency, we do a workaround - error.file will contain formatted location instead
53
49
  if (issue.file) {
54
- this.file =
55
- pathType === 'absolute'
56
- ? (0, forward_slash_1.forwardSlash)(path_1.default.resolve(issue.file))
57
- : (0, relative_to_context_1.relativeToContext)(issue.file, process.cwd());
50
+ this.file = (0, format_file_path_1.formatFilePath)(issue.file, pathType);
58
51
  if (issue.location) {
59
52
  this.file += `:${(0, issue_location_1.formatIssueLocation)(issue.location)}`;
60
53
  }