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
@@ -115,10 +115,6 @@
115
115
  "TypeScriptOptions": {
116
116
  "type": "object",
117
117
  "properties": {
118
- "memoryLimit": {
119
- "type": "number",
120
- "description": "Memory limit for TypeScript reporter process."
121
- },
122
118
  "configFile": {
123
119
  "type": "string",
124
120
  "description": "Path to tsconfig.json. By default plugin uses context or process.cwd() to localize tsconfig.json file."
@@ -133,8 +129,8 @@
133
129
  },
134
130
  "mode": {
135
131
  "type": "string",
136
- "enum": ["readonly", "write-tsbuildinfo", "write-dts", "write-references"],
137
- "description": "`readonly` keeps all emitted files in memory, `write-tsbuildinfo` which writes only .tsbuildinfo files, `write-dts` writes .tsbuildinfo and type definition files, and `write-references` which writes both .tsbuildinfo and referenced projects output"
132
+ "enum": ["in-memory", "write"],
133
+ "description": "`in-memory` writes nothing to the disk, `write` writes type definition files, or with `build` all outputs of the build, like `tsc --build`"
138
134
  },
139
135
  "compilerOptions": {
140
136
  "type": "object",
@@ -161,11 +157,11 @@
161
157
  },
162
158
  "profile": {
163
159
  "type": "boolean",
164
- "description": "Measures and prints timings related to the TypeScript performance."
160
+ "description": "Measures and prints timings of the requests made to TypeScript's native compiler."
165
161
  },
166
162
  "typescriptPath": {
167
163
  "type": "string",
168
- "description": "If supplied this is a custom path where TypeScript can be found."
164
+ "description": "If supplied this is a custom path where TypeScript (7.1 or newer) can be found."
169
165
  }
170
166
  }
171
167
  },
@@ -1,4 +1,3 @@
1
- import type { AbortController } from 'node-abort-controller';
2
1
  import type { FullTap } from 'tapable';
3
2
  import type { FilesChange } from './files-change';
4
3
  import type { FilesMatch } from './files-match';
package/lib/plugin.js CHANGED
@@ -39,7 +39,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.ForkTsCheckerWebpackPlugin = void 0;
40
40
  const path = __importStar(require("path"));
41
41
  const cosmiconfig_1 = require("cosmiconfig");
42
- const deepmerge_1 = __importDefault(require("deepmerge"));
43
42
  const schema_utils_1 = require("schema-utils");
44
43
  const tap_after_compile_to_add_dependencies_1 = require("./hooks/tap-after-compile-to-add-dependencies");
45
44
  const tap_after_environment_to_patch_watching_1 = require("./hooks/tap-after-environment-to-patch-watching");
@@ -53,19 +52,33 @@ const plugin_pools_1 = require("./plugin-pools");
53
52
  const plugin_state_1 = require("./plugin-state");
54
53
  const rpc_1 = require("./rpc");
55
54
  const type_script_support_1 = require("./typescript/type-script-support");
55
+ const deep_merge_1 = require("./utils/deep-merge");
56
56
  class ForkTsCheckerWebpackPlugin {
57
+ /**
58
+ * Current version of the plugin
59
+ */
60
+ static version = '10.0.0-alpha.1'; // will be replaced by the @semantic-release/exec
61
+ /**
62
+ * Default pools for the plugin concurrency limit
63
+ */
64
+ static issuesPool = plugin_pools_1.issuesPool;
65
+ static dependenciesPool = plugin_pools_1.dependenciesPool;
66
+ /**
67
+ * @deprecated Use ForkTsCheckerWebpackPlugin.issuesPool instead
68
+ */
69
+ static pool = plugin_pools_1.issuesPool;
70
+ options;
57
71
  constructor(options = {}) {
58
- const explorerSync = (0, cosmiconfig_1.cosmiconfigSync)('fork-ts-checker', {
59
- // keep searching parent directories up to the home directory, as cosmiconfig did before v9
60
- // TODO: in the next major release, drop this option to use the cosmiconfig default (no search in
61
- // parent directories) - it's a breaking change
62
- searchStrategy: 'global',
63
- });
64
- const { config: externalOptions } = explorerSync.search() || {};
72
+ const explorerSync = (0, cosmiconfig_1.cosmiconfigSync)('fork-ts-checker');
73
+ const { config: loadedOptions } = explorerSync.search() || {};
74
+ // a config file that is an ES module (`export default`) is loaded as its namespace
75
+ const externalOptions = loadedOptions?.__esModule && 'default' in loadedOptions
76
+ ? loadedOptions.default
77
+ : loadedOptions;
65
78
  // first validate options directly passed to the constructor
66
79
  const config = { name: 'ForkTsCheckerWebpackPlugin' };
67
80
  (0, schema_utils_1.validate)(plugin_options_json_1.default, options, config);
68
- this.options = (0, deepmerge_1.default)(externalOptions || {}, options || {});
81
+ this.options = (0, deep_merge_1.deepMerge)(externalOptions || {}, options || {});
69
82
  // then validate merged options
70
83
  (0, schema_utils_1.validate)(plugin_options_json_1.default, this.options, config);
71
84
  }
@@ -76,7 +89,7 @@ class ForkTsCheckerWebpackPlugin {
76
89
  const config = (0, plugin_config_1.createPluginConfig)(compiler, this.options);
77
90
  const state = (0, plugin_state_1.createPluginState)();
78
91
  (0, type_script_support_1.assertTypeScriptSupport)(config.typescript);
79
- const getIssuesWorker = (0, rpc_1.createRpcWorker)(path.resolve(__dirname, './typescript/worker/get-issues-worker.js'), config.typescript, config.typescript.memoryLimit);
92
+ const getIssuesWorker = (0, rpc_1.createRpcWorker)(path.resolve(__dirname, './typescript/worker/get-issues-worker.js'), config.typescript);
80
93
  const getDependenciesWorker = (0, rpc_1.createRpcWorker)(path.resolve(__dirname, './typescript/worker/get-dependencies-worker.js'), config.typescript);
81
94
  (0, tap_after_environment_to_patch_watching_1.tapAfterEnvironmentToPatchWatching)(compiler, state);
82
95
  (0, tap_start_to_run_workers_1.tapStartToRunWorkers)(compiler, getIssuesWorker, getDependenciesWorker, config, state);
@@ -86,16 +99,3 @@ class ForkTsCheckerWebpackPlugin {
86
99
  }
87
100
  }
88
101
  exports.ForkTsCheckerWebpackPlugin = ForkTsCheckerWebpackPlugin;
89
- /**
90
- * Current version of the plugin
91
- */
92
- ForkTsCheckerWebpackPlugin.version = '9.2.0'; // will be replaced by the @semantic-release/exec
93
- /**
94
- * Default pools for the plugin concurrency limit
95
- */
96
- ForkTsCheckerWebpackPlugin.issuesPool = plugin_pools_1.issuesPool;
97
- ForkTsCheckerWebpackPlugin.dependenciesPool = plugin_pools_1.dependenciesPool;
98
- /**
99
- * @deprecated Use ForkTsCheckerWebpackPlugin.issuesPool instead
100
- */
101
- ForkTsCheckerWebpackPlugin.pool = plugin_pools_1.issuesPool;
@@ -1,13 +1,4 @@
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
  };
@@ -34,7 +25,7 @@ function exposeRpc(fn) {
34
25
  });
35
26
  }
36
27
  });
37
- const handleMessage = (message) => __awaiter(this, void 0, void 0, function* () {
28
+ const handleMessage = async (message) => {
38
29
  if (message.type === 'call') {
39
30
  if (!process_1.default.send) {
40
31
  // process disconnected - skip
@@ -43,21 +34,21 @@ function exposeRpc(fn) {
43
34
  let value;
44
35
  let error;
45
36
  try {
46
- value = yield fn(...message.args);
37
+ value = await fn(...message.args);
47
38
  }
48
39
  catch (fnError) {
49
40
  error = fnError;
50
41
  }
51
42
  try {
52
43
  if (error) {
53
- yield sendMessage({
44
+ await sendMessage({
54
45
  type: 'reject',
55
46
  id: message.id,
56
47
  error,
57
48
  });
58
49
  }
59
50
  else {
60
- yield sendMessage({
51
+ await sendMessage({
61
52
  type: 'resolve',
62
53
  id: message.id,
63
54
  value,
@@ -72,6 +63,6 @@ function exposeRpc(fn) {
72
63
  console.error(sendError);
73
64
  }
74
65
  }
75
- });
66
+ };
76
67
  process_1.default.on('message', handleMessage);
77
68
  }
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RpcExitError = void 0;
4
4
  class RpcExitError extends Error {
5
+ code;
6
+ signal;
5
7
  constructor(message, code, signal) {
6
8
  super(message);
7
9
  this.code = code;
@@ -7,6 +7,6 @@ interface RpcWorkerBase {
7
7
  readonly process: ChildProcess | undefined;
8
8
  }
9
9
  type RpcWorker<T extends RpcMethod = RpcMethod> = RpcWorkerBase & RpcRemoteMethod<T>;
10
- declare function createRpcWorker<T extends RpcMethod>(modulePath: string, data: unknown, memoryLimit?: number): RpcWorker<T>;
10
+ declare function createRpcWorker<T extends RpcMethod>(modulePath: string, data: unknown): RpcWorker<T>;
11
11
  declare function getRpcWorkerData(): unknown;
12
12
  export { createRpcWorker, getRpcWorkerData, RpcWorker };
@@ -39,15 +39,15 @@ const child_process = __importStar(require("child_process"));
39
39
  const process = __importStar(require("process"));
40
40
  const wrap_rpc_1 = require("./wrap-rpc");
41
41
  const WORKER_DATA_ENV_KEY = 'WORKER_DATA';
42
- function createRpcWorker(modulePath, data, memoryLimit) {
42
+ function createRpcWorker(modulePath, data) {
43
43
  const options = {
44
- env: Object.assign(Object.assign({}, process.env), { [WORKER_DATA_ENV_KEY]: JSON.stringify(data || {}) }),
44
+ env: {
45
+ ...process.env,
46
+ [WORKER_DATA_ENV_KEY]: JSON.stringify(data || {}),
47
+ },
45
48
  stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
46
49
  serialization: 'advanced',
47
50
  };
48
- if (memoryLimit) {
49
- options.execArgv = [`--max-old-space-size=${memoryLimit}`];
50
- }
51
51
  let childProcess;
52
52
  let remoteMethod;
53
53
  const worker = {
@@ -57,7 +57,7 @@ function createRpcWorker(modulePath, data, memoryLimit) {
57
57
  childProcess = undefined;
58
58
  remoteMethod = undefined;
59
59
  }
60
- if (!(childProcess === null || childProcess === void 0 ? void 0 : childProcess.connected)) {
60
+ if (!childProcess?.connected) {
61
61
  childProcess = child_process.fork(modulePath, options);
62
62
  remoteMethod = (0, wrap_rpc_1.wrapRpc)(childProcess);
63
63
  }
@@ -70,7 +70,7 @@ function createRpcWorker(modulePath, data, memoryLimit) {
70
70
  }
71
71
  },
72
72
  get connected() {
73
- return Boolean(childProcess === null || childProcess === void 0 ? void 0 : childProcess.connected);
73
+ return Boolean(childProcess?.connected);
74
74
  },
75
75
  get process() {
76
76
  return childProcess;
@@ -1,20 +1,11 @@
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.wrapRpc = wrapRpc;
13
4
  const controlled_promise_1 = require("../utils/async/controlled-promise");
14
5
  const rpc_error_1 = require("./rpc-error");
15
6
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
7
  function wrapRpc(childProcess) {
17
- return ((...args) => __awaiter(this, void 0, void 0, function* () {
8
+ return (async (...args) => {
18
9
  if (!childProcess.send) {
19
10
  throw new Error(`Process ${childProcess.pid} doesn't have IPC channels`);
20
11
  }
@@ -26,7 +17,7 @@ function wrapRpc(childProcess) {
26
17
  const { promise: resultPromise, resolve: resolveResult, reject: rejectResult, } = (0, controlled_promise_1.createControlledPromise)();
27
18
  const { promise: sendPromise, resolve: resolveSend, reject: rejectSend, } = (0, controlled_promise_1.createControlledPromise)();
28
19
  const handleMessage = (message) => {
29
- if ((message === null || message === void 0 ? void 0 : message.id) === id) {
20
+ if (message?.id === id) {
30
21
  if (message.type === 'resolve') {
31
22
  // assume the contract is respected
32
23
  resolveResult(message.value);
@@ -68,7 +59,7 @@ function wrapRpc(childProcess) {
68
59
  }
69
60
  });
70
61
  return sendPromise.then(() => resultPromise);
71
- }));
62
+ });
72
63
  }
73
64
  function uuid() {
74
65
  return new Array(4)
@@ -0,0 +1,4 @@
1
+ export declare function findTypeScriptPackageDirectory(typescriptPath: string): string;
2
+ export declare function readTypeScriptPackageJson(packageDirectory: string): any;
3
+ /** The version of the TypeScript package that `typescriptPath` points into, if any. */
4
+ export declare function getTypeScriptVersion(typescriptPath: string): string | undefined;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.findTypeScriptPackageDirectory = findTypeScriptPackageDirectory;
37
+ exports.readTypeScriptPackageJson = readTypeScriptPackageJson;
38
+ exports.getTypeScriptVersion = getTypeScriptVersion;
39
+ const fs = __importStar(require("fs"));
40
+ const path = __importStar(require("path"));
41
+ /**
42
+ * `typescriptPath` points somewhere inside the TypeScript package (by default
43
+ * `require.resolve('typescript')`, i.e. `lib/version.cjs`), or at the package
44
+ * directory itself. TypeScript 7 has no `main`, and its entry points are only
45
+ * reachable through the `exports` map, so locate the package.json ourselves.
46
+ */
47
+ /**
48
+ * Skips unrelated package.json files on the way up, such as the user's project
49
+ * when `typescriptPath` is wrong. A package exposing `./sync` also counts, so a
50
+ * TypeScript build published under another name still works.
51
+ */
52
+ function isTypeScriptPackage(directory) {
53
+ try {
54
+ const packageJson = readTypeScriptPackageJson(directory);
55
+ return packageJson.name === 'typescript' || packageJson.exports?.['./sync'] !== undefined;
56
+ }
57
+ catch (error) {
58
+ return false;
59
+ }
60
+ }
61
+ function findTypeScriptPackageDirectory(typescriptPath) {
62
+ let directory = fs.existsSync(typescriptPath) && fs.statSync(typescriptPath).isDirectory()
63
+ ? typescriptPath
64
+ : path.dirname(typescriptPath);
65
+ while (true) {
66
+ if (isTypeScriptPackage(directory)) {
67
+ return directory;
68
+ }
69
+ const parent = path.dirname(directory);
70
+ if (parent === directory) {
71
+ throw new Error(`Cannot find the TypeScript package.json for "${typescriptPath}".`);
72
+ }
73
+ directory = parent;
74
+ }
75
+ }
76
+ function readTypeScriptPackageJson(packageDirectory) {
77
+ return JSON.parse(fs.readFileSync(path.join(packageDirectory, 'package.json'), 'utf8'));
78
+ }
79
+ /** The version of the TypeScript package that `typescriptPath` points into, if any. */
80
+ function getTypeScriptVersion(typescriptPath) {
81
+ try {
82
+ const packageJson = readTypeScriptPackageJson(findTypeScriptPackageDirectory(typescriptPath));
83
+ return typeof packageJson.version === 'string' ? packageJson.version : undefined;
84
+ }
85
+ catch (error) {
86
+ return undefined;
87
+ }
88
+ }
@@ -37,34 +37,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.assertTypeScriptSupport = assertTypeScriptSupport;
40
+ const fs_1 = __importDefault(require("fs"));
40
41
  const os_1 = __importDefault(require("os"));
41
- const fs_extra_1 = __importDefault(require("fs-extra"));
42
42
  const semver = __importStar(require("semver"));
43
+ const type_script_package_1 = require("./type-script-package");
44
+ const MINIMUM_TYPESCRIPT_VERSION = '7.1.0-beta';
43
45
  function assertTypeScriptSupport(config) {
44
- let typescriptVersion;
45
- try {
46
- // eslint-disable-next-line @typescript-eslint/no-require-imports
47
- typescriptVersion = require(config.typescriptPath).version;
48
- }
49
- catch (error) {
50
- // silent catch
51
- }
46
+ const typescriptVersion = (0, type_script_package_1.getTypeScriptVersion)(config.typescriptPath);
52
47
  if (!typescriptVersion) {
53
48
  throw new Error('When you use ForkTsCheckerWebpackPlugin with typescript reporter enabled, you must install `typescript` package.');
54
49
  }
55
- if (semver.lt(typescriptVersion, '3.6.0')) {
50
+ if (semver.lt(typescriptVersion, MINIMUM_TYPESCRIPT_VERSION)) {
56
51
  throw new Error([
57
52
  `ForkTsCheckerWebpackPlugin cannot use the current typescript version of ${typescriptVersion}.`,
58
- 'The minimum required version is 3.6.0.',
59
- ].join(os_1.default.EOL));
60
- }
61
- if (config.build && semver.lt(typescriptVersion, '3.8.0')) {
62
- throw new Error([
63
- `ForkTsCheckerWebpackPlugin doesn't support build option for the current typescript version of ${typescriptVersion}.`,
64
- 'The minimum required version is 3.8.0.',
53
+ `The minimum required version is ${MINIMUM_TYPESCRIPT_VERSION}.`,
54
+ 'Use fork-ts-checker-webpack-plugin@9 for older TypeScript versions.',
65
55
  ].join(os_1.default.EOL));
66
56
  }
67
- if (!fs_extra_1.default.existsSync(config.configFile)) {
57
+ if (!fs_1.default.existsSync(config.configFile)) {
68
58
  throw new Error([
69
59
  `Cannot find the "${config.configFile}" file.`,
70
60
  `Please check webpack and ForkTsCheckerWebpackPlugin configuration.`,
@@ -1,14 +1,13 @@
1
1
  import type * as webpack from 'webpack';
2
2
  import type { TypeScriptConfigOverwrite } from './type-script-config-overwrite';
3
3
  import type { TypeScriptDiagnosticsOptions } from './type-script-diagnostics-options';
4
- import type { TypeScriptWorkerOptions } from './type-script-worker-options';
4
+ import type { TypeScriptWorkerMode, TypeScriptWorkerOptions } from './type-script-worker-options';
5
5
  interface TypeScriptWorkerConfig {
6
- memoryLimit: number;
7
6
  configFile: string;
8
7
  configOverwrite: TypeScriptConfigOverwrite;
9
8
  build: boolean;
10
9
  context: string;
11
- mode: 'readonly' | 'write-dts' | 'write-tsbuildinfo' | 'write-references';
10
+ mode: TypeScriptWorkerMode;
12
11
  diagnosticOptions: TypeScriptDiagnosticsOptions;
13
12
  profile: boolean;
14
13
  typescriptPath: string;
@@ -6,12 +6,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createTypeScriptWorkerConfig = createTypeScriptWorkerConfig;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  function createTypeScriptWorkerConfig(compiler, options) {
9
- let configFile = (options === null || options === void 0 ? void 0 : options.configFile) || 'tsconfig.json';
9
+ let configFile = options?.configFile || 'tsconfig.json';
10
10
  // ensure that `configFile` is an absolute normalized path
11
11
  configFile = path_1.default.normalize(path_1.default.isAbsolute(configFile)
12
12
  ? configFile
13
13
  : path_1.default.resolve(compiler.options.context || process.cwd(), configFile));
14
14
  const optionsAsObject = typeof options === 'object' ? options : {};
15
15
  const typescriptPath = optionsAsObject.typescriptPath || require.resolve('typescript');
16
- return Object.assign(Object.assign({ memoryLimit: 2048, build: false, mode: optionsAsObject.build ? 'write-tsbuildinfo' : 'readonly', profile: false }, optionsAsObject), { configFile: configFile, configOverwrite: optionsAsObject.configOverwrite || {}, context: optionsAsObject.context || path_1.default.dirname(configFile), diagnosticOptions: Object.assign({ syntactic: false, semantic: true, declaration: false, global: false }, (optionsAsObject.diagnosticOptions || {})), typescriptPath: typescriptPath });
16
+ const build = Boolean(optionsAsObject.build);
17
+ const mode = optionsAsObject.mode || 'in-memory';
18
+ return {
19
+ profile: false,
20
+ ...optionsAsObject,
21
+ build,
22
+ mode,
23
+ configFile: configFile,
24
+ configOverwrite: optionsAsObject.configOverwrite || {},
25
+ // ensure that `context` is an absolute normalized path, like `configFile`
26
+ context: optionsAsObject.context
27
+ ? path_1.default.resolve(optionsAsObject.context)
28
+ : path_1.default.dirname(configFile),
29
+ diagnosticOptions: {
30
+ syntactic: false, // by default they are reported by the loader
31
+ semantic: true,
32
+ declaration: false,
33
+ global: false,
34
+ ...(optionsAsObject.diagnosticOptions || {}),
35
+ },
36
+ typescriptPath: typescriptPath,
37
+ };
17
38
  }
@@ -1,14 +1,15 @@
1
1
  import type { TypeScriptConfigOverwrite } from './type-script-config-overwrite';
2
2
  import type { TypeScriptDiagnosticsOptions } from './type-script-diagnostics-options';
3
+ declare const TYPESCRIPT_WORKER_MODES: readonly ['in-memory', 'write'];
4
+ type TypeScriptWorkerMode = (typeof TYPESCRIPT_WORKER_MODES)[number];
3
5
  type TypeScriptWorkerOptions = {
4
- memoryLimit?: number;
5
6
  configFile?: string;
6
7
  configOverwrite?: TypeScriptConfigOverwrite;
7
8
  context?: string;
8
9
  build?: boolean;
9
- mode?: 'readonly' | 'write-tsbuildinfo' | 'write-dts' | 'write-references';
10
+ mode?: TypeScriptWorkerMode;
10
11
  diagnosticOptions?: Partial<TypeScriptDiagnosticsOptions>;
11
12
  profile?: boolean;
12
13
  typescriptPath?: string;
13
14
  };
14
- export { TypeScriptWorkerOptions };
15
+ export { TYPESCRIPT_WORKER_MODES, TypeScriptWorkerMode, TypeScriptWorkerOptions };
@@ -1,2 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TYPESCRIPT_WORKER_MODES = void 0;
4
+ // keep in sync with the `mode` enum in plugin-options.json - a unit test checks it
5
+ const TYPESCRIPT_WORKER_MODES = ['in-memory', 'write'];
6
+ exports.TYPESCRIPT_WORKER_MODES = TYPESCRIPT_WORKER_MODES;
@@ -1,15 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const rpc_1 = require("../../rpc");
4
+ const api_1 = require("./lib/api");
4
5
  const config_1 = require("./lib/config");
5
6
  const dependencies_1 = require("./lib/dependencies");
6
- const system_1 = require("./lib/system");
7
+ // the native compiler process must not outlive the worker (see get-issues-worker.ts)
8
+ process.on('exit', api_1.closeApi);
7
9
  const getDependenciesWorker = (change) => {
8
- system_1.system.invalidateCache();
9
- if ((0, config_1.didConfigFileChanged)(change) || (0, config_1.didDependenciesProbablyChanged)((0, dependencies_1.getDependencies)(), change)) {
10
+ try {
11
+ if ((0, config_1.didConfigFileChanged)((0, dependencies_1.getConfigFiles)(), change) ||
12
+ (0, config_1.didDependenciesProbablyChanged)((0, dependencies_1.getDependencies)(), change)) {
13
+ (0, config_1.invalidateConfig)();
14
+ (0, dependencies_1.invalidateDependencies)();
15
+ }
16
+ return (0, dependencies_1.getDependencies)();
17
+ }
18
+ catch (error) {
19
+ // the compiler process may have died - start from scratch on the next call
20
+ (0, api_1.closeApi)();
10
21
  (0, config_1.invalidateConfig)();
11
22
  (0, dependencies_1.invalidateDependencies)();
23
+ throw error;
12
24
  }
13
- return (0, dependencies_1.getDependencies)();
14
25
  };
15
26
  (0, rpc_1.exposeRpc)(getDependenciesWorker);
@@ -1,5 +1,5 @@
1
1
  import type { FilesChange } from '../../files-change';
2
2
  import type { Issue } from '../../issue';
3
- declare const getIssuesWorker: (change: FilesChange, watching: boolean) => Promise<Issue[]>;
3
+ declare const getIssuesWorker: (change: FilesChange) => Promise<Issue[]>;
4
4
  export type GetIssuesWorker = typeof getIssuesWorker;
5
5
  export {};