ts-checker-rspack-plugin 1.0.0-beta.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.
Files changed (168) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +216 -0
  3. package/lib/files-change.d.ts +17 -0
  4. package/lib/files-change.js +57 -0
  5. package/lib/files-match.d.ts +7 -0
  6. package/lib/files-match.js +2 -0
  7. package/lib/formatter/basic-formatter.d.ts +3 -0
  8. package/lib/formatter/basic-formatter.js +13 -0
  9. package/lib/formatter/code-frame-formatter.d.ts +4 -0
  10. package/lib/formatter/code-frame-formatter.js +29 -0
  11. package/lib/formatter/formatter-config.d.ts +8 -0
  12. package/lib/formatter/formatter-config.js +36 -0
  13. package/lib/formatter/formatter-options.d.ts +14 -0
  14. package/lib/formatter/formatter-options.js +2 -0
  15. package/lib/formatter/formatter.d.ts +4 -0
  16. package/lib/formatter/formatter.js +2 -0
  17. package/lib/formatter/index.d.ts +6 -0
  18. package/lib/formatter/index.js +18 -0
  19. package/lib/formatter/stats-formatter.d.ts +3 -0
  20. package/lib/formatter/stats-formatter.js +28 -0
  21. package/lib/formatter/types/babel__code-frame.d.ts +21 -0
  22. package/lib/formatter/types/babel__code-frame.js +7 -0
  23. package/lib/formatter/webpack-formatter.d.ts +3 -0
  24. package/lib/formatter/webpack-formatter.js +32 -0
  25. package/lib/hooks/intercept-done-to-get-dev-server-tap.d.ts +5 -0
  26. package/lib/hooks/intercept-done-to-get-dev-server-tap.js +18 -0
  27. package/lib/hooks/tap-after-compile-to-add-dependencies.d.ts +5 -0
  28. package/lib/hooks/tap-after-compile-to-add-dependencies.js +31 -0
  29. package/lib/hooks/tap-after-compile-to-get-issues.d.ts +5 -0
  30. package/lib/hooks/tap-after-compile-to-get-issues.js +52 -0
  31. package/lib/hooks/tap-after-environment-to-patch-watching.d.ts +4 -0
  32. package/lib/hooks/tap-after-environment-to-patch-watching.js +22 -0
  33. package/lib/hooks/tap-done-to-async-get-issues.d.ts +5 -0
  34. package/lib/hooks/tap-done-to-async-get-issues.js +86 -0
  35. package/lib/hooks/tap-error-to-log-message.d.ts +4 -0
  36. package/lib/hooks/tap-error-to-log-message.js +32 -0
  37. package/lib/hooks/tap-start-to-run-workers.d.ts +8 -0
  38. package/lib/hooks/tap-start-to-run-workers.js +132 -0
  39. package/lib/hooks/tap-stop-to-terminate-workers.d.ts +5 -0
  40. package/lib/hooks/tap-stop-to-terminate-workers.js +26 -0
  41. package/lib/index.d.ts +2 -0
  42. package/lib/index.js +5 -0
  43. package/lib/infrastructure-logger.d.ts +9 -0
  44. package/lib/infrastructure-logger.js +14 -0
  45. package/lib/issue/index.d.ts +3 -0
  46. package/lib/issue/index.js +15 -0
  47. package/lib/issue/issue-config.d.ts +8 -0
  48. package/lib/issue/issue-config.js +29 -0
  49. package/lib/issue/issue-location.d.ts +8 -0
  50. package/lib/issue/issue-location.js +22 -0
  51. package/lib/issue/issue-match.d.ts +5 -0
  52. package/lib/issue/issue-match.js +20 -0
  53. package/lib/issue/issue-options.d.ts +8 -0
  54. package/lib/issue/issue-options.js +2 -0
  55. package/lib/issue/issue-position.d.ts +6 -0
  56. package/lib/issue/issue-position.js +16 -0
  57. package/lib/issue/issue-predicate.d.ts +5 -0
  58. package/lib/issue/issue-predicate.js +11 -0
  59. package/lib/issue/issue-severity.d.ts +4 -0
  60. package/lib/issue/issue-severity.js +12 -0
  61. package/lib/issue/issue-webpack-error.d.ts +10 -0
  62. package/lib/issue/issue-webpack-error.js +51 -0
  63. package/lib/issue/issue.d.ts +12 -0
  64. package/lib/issue/issue.js +41 -0
  65. package/lib/logger.d.ts +5 -0
  66. package/lib/logger.js +2 -0
  67. package/lib/plugin-config.d.ts +16 -0
  68. package/lib/plugin-config.js +26 -0
  69. package/lib/plugin-hooks.d.ts +20 -0
  70. package/lib/plugin-hooks.js +45 -0
  71. package/lib/plugin-options.d.ts +13 -0
  72. package/lib/plugin-options.js +2 -0
  73. package/lib/plugin-options.json +197 -0
  74. package/lib/plugin-pools.d.ts +4 -0
  75. package/lib/plugin-pools.js +28 -0
  76. package/lib/plugin-state.d.ts +18 -0
  77. package/lib/plugin-state.js +17 -0
  78. package/lib/plugin.d.ts +29 -0
  79. package/lib/plugin.js +79 -0
  80. package/lib/rpc/expose-rpc.d.ts +1 -0
  81. package/lib/rpc/expose-rpc.js +78 -0
  82. package/lib/rpc/index.d.ts +5 -0
  83. package/lib/rpc/index.js +12 -0
  84. package/lib/rpc/rpc-error.d.ts +6 -0
  85. package/lib/rpc/rpc-error.js +12 -0
  86. package/lib/rpc/rpc-worker.d.ts +13 -0
  87. package/lib/rpc/rpc-worker.js +79 -0
  88. package/lib/rpc/types.d.ts +19 -0
  89. package/lib/rpc/types.js +2 -0
  90. package/lib/rpc/wrap-rpc.d.ts +4 -0
  91. package/lib/rpc/wrap-rpc.js +79 -0
  92. package/lib/typescript/type-script-config-overwrite.d.ts +12 -0
  93. package/lib/typescript/type-script-config-overwrite.js +2 -0
  94. package/lib/typescript/type-script-diagnostics-options.d.ts +7 -0
  95. package/lib/typescript/type-script-diagnostics-options.js +2 -0
  96. package/lib/typescript/type-script-support.d.ts +3 -0
  97. package/lib/typescript/type-script-support.js +63 -0
  98. package/lib/typescript/type-script-worker-config.d.ts +18 -0
  99. package/lib/typescript/type-script-worker-config.js +18 -0
  100. package/lib/typescript/type-script-worker-options.d.ts +14 -0
  101. package/lib/typescript/type-script-worker-options.js +2 -0
  102. package/lib/typescript/worker/get-dependencies-worker.d.ts +5 -0
  103. package/lib/typescript/worker/get-dependencies-worker.js +15 -0
  104. package/lib/typescript/worker/get-issues-worker.d.ts +5 -0
  105. package/lib/typescript/worker/get-issues-worker.js +80 -0
  106. package/lib/typescript/worker/lib/artifacts.d.ts +4 -0
  107. package/lib/typescript/worker/lib/artifacts.js +90 -0
  108. package/lib/typescript/worker/lib/config.d.ts +15 -0
  109. package/lib/typescript/worker/lib/config.js +131 -0
  110. package/lib/typescript/worker/lib/dependencies.d.ts +3 -0
  111. package/lib/typescript/worker/lib/dependencies.js +81 -0
  112. package/lib/typescript/worker/lib/diagnostics.d.ts +7 -0
  113. package/lib/typescript/worker/lib/diagnostics.js +108 -0
  114. package/lib/typescript/worker/lib/emit.d.ts +2 -0
  115. package/lib/typescript/worker/lib/emit.js +13 -0
  116. package/lib/typescript/worker/lib/file-system/file-system.d.ts +18 -0
  117. package/lib/typescript/worker/lib/file-system/file-system.js +2 -0
  118. package/lib/typescript/worker/lib/file-system/mem-file-system.d.ts +5 -0
  119. package/lib/typescript/worker/lib/file-system/mem-file-system.js +78 -0
  120. package/lib/typescript/worker/lib/file-system/passive-file-system.d.ts +5 -0
  121. package/lib/typescript/worker/lib/file-system/passive-file-system.js +65 -0
  122. package/lib/typescript/worker/lib/file-system/real-file-system.d.ts +5 -0
  123. package/lib/typescript/worker/lib/file-system/real-file-system.js +187 -0
  124. package/lib/typescript/worker/lib/host/compiler-host.d.ts +2 -0
  125. package/lib/typescript/worker/lib/host/compiler-host.js +10 -0
  126. package/lib/typescript/worker/lib/host/watch-compiler-host.d.ts +2 -0
  127. package/lib/typescript/worker/lib/host/watch-compiler-host.js +20 -0
  128. package/lib/typescript/worker/lib/host/watch-solution-builder-host.d.ts +2 -0
  129. package/lib/typescript/worker/lib/host/watch-solution-builder-host.js +47 -0
  130. package/lib/typescript/worker/lib/performance.d.ts +3 -0
  131. package/lib/typescript/worker/lib/performance.js +32 -0
  132. package/lib/typescript/worker/lib/program/program.d.ts +2 -0
  133. package/lib/typescript/worker/lib/program/program.js +37 -0
  134. package/lib/typescript/worker/lib/program/solution-builder.d.ts +2 -0
  135. package/lib/typescript/worker/lib/program/solution-builder.js +39 -0
  136. package/lib/typescript/worker/lib/program/watch-program.d.ts +3 -0
  137. package/lib/typescript/worker/lib/program/watch-program.js +51 -0
  138. package/lib/typescript/worker/lib/system.d.ts +19 -0
  139. package/lib/typescript/worker/lib/system.js +232 -0
  140. package/lib/typescript/worker/lib/tracing.d.ts +4 -0
  141. package/lib/typescript/worker/lib/tracing.js +29 -0
  142. package/lib/typescript/worker/lib/tsbuildinfo.d.ts +4 -0
  143. package/lib/typescript/worker/lib/tsbuildinfo.js +92 -0
  144. package/lib/typescript/worker/lib/typescript.d.ts +2 -0
  145. package/lib/typescript/worker/lib/typescript.js +6 -0
  146. package/lib/typescript/worker/lib/worker-config.d.ts +2 -0
  147. package/lib/typescript/worker/lib/worker-config.js +5 -0
  148. package/lib/utils/async/abort-error.d.ts +6 -0
  149. package/lib/utils/async/abort-error.js +15 -0
  150. package/lib/utils/async/controlled-promise.d.ts +6 -0
  151. package/lib/utils/async/controlled-promise.js +17 -0
  152. package/lib/utils/async/is-pending.d.ts +2 -0
  153. package/lib/utils/async/is-pending.js +10 -0
  154. package/lib/utils/async/pool.d.ts +10 -0
  155. package/lib/utils/async/pool.js +47 -0
  156. package/lib/utils/async/wait.d.ts +2 -0
  157. package/lib/utils/async/wait.js +7 -0
  158. package/lib/utils/path/forward-slash.d.ts +6 -0
  159. package/lib/utils/path/forward-slash.js +15 -0
  160. package/lib/utils/path/is-inside-another-path.d.ts +2 -0
  161. package/lib/utils/path/is-inside-another-path.js +22 -0
  162. package/lib/utils/path/relative-to-context.d.ts +2 -0
  163. package/lib/utils/path/relative-to-context.js +16 -0
  164. package/lib/watch/inclusive-node-watch-file-system.d.ts +15 -0
  165. package/lib/watch/inclusive-node-watch-file-system.js +166 -0
  166. package/lib/watch/watch-file-system.d.ts +16 -0
  167. package/lib/watch/watch-file-system.js +2 -0
  168. package/package.json +88 -0
package/lib/plugin.js ADDED
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.TsCheckerRspackPlugin = void 0;
26
+ const path = __importStar(require("path"));
27
+ const schema_utils_1 = require("schema-utils");
28
+ const tap_after_compile_to_add_dependencies_1 = require("./hooks/tap-after-compile-to-add-dependencies");
29
+ const tap_after_environment_to_patch_watching_1 = require("./hooks/tap-after-environment-to-patch-watching");
30
+ const tap_error_to_log_message_1 = require("./hooks/tap-error-to-log-message");
31
+ const tap_start_to_run_workers_1 = require("./hooks/tap-start-to-run-workers");
32
+ const tap_stop_to_terminate_workers_1 = require("./hooks/tap-stop-to-terminate-workers");
33
+ const plugin_config_1 = require("./plugin-config");
34
+ const plugin_hooks_1 = require("./plugin-hooks");
35
+ const plugin_options_json_1 = __importDefault(require("./plugin-options.json"));
36
+ const plugin_pools_1 = require("./plugin-pools");
37
+ const plugin_state_1 = require("./plugin-state");
38
+ const rpc_1 = require("./rpc");
39
+ const type_script_support_1 = require("./typescript/type-script-support");
40
+ class TsCheckerRspackPlugin {
41
+ constructor(options = {}) {
42
+ // first validate options directly passed to the constructor
43
+ const config = { name: 'TsCheckerRspackPlugin' };
44
+ (0, schema_utils_1.validate)(plugin_options_json_1.default, options, config);
45
+ this.options = options;
46
+ // then validate merged options
47
+ (0, schema_utils_1.validate)(plugin_options_json_1.default, this.options, config);
48
+ }
49
+ static getCompilerHooks(compiler) {
50
+ return (0, plugin_hooks_1.getPluginHooks)(compiler);
51
+ }
52
+ apply(compiler) {
53
+ const config = (0, plugin_config_1.createPluginConfig)(compiler, this.options);
54
+ const state = (0, plugin_state_1.createPluginState)();
55
+ (0, type_script_support_1.assertTypeScriptSupport)(config.typescript);
56
+ const getIssuesWorker = (0, rpc_1.createRpcWorker)(path.resolve(__dirname, './typescript/worker/get-issues-worker.js'), config.typescript, config.typescript.memoryLimit);
57
+ const getDependenciesWorker = (0, rpc_1.createRpcWorker)(path.resolve(__dirname, './typescript/worker/get-dependencies-worker.js'), config.typescript);
58
+ (0, tap_after_environment_to_patch_watching_1.tapAfterEnvironmentToPatchWatching)(compiler, state);
59
+ (0, tap_start_to_run_workers_1.tapStartToRunWorkers)(compiler, getIssuesWorker, getDependenciesWorker, config, state);
60
+ (0, tap_after_compile_to_add_dependencies_1.tapAfterCompileToAddDependencies)(compiler, config, state);
61
+ (0, tap_stop_to_terminate_workers_1.tapStopToTerminateWorkers)(compiler, getIssuesWorker, getDependenciesWorker, state);
62
+ (0, tap_error_to_log_message_1.tapErrorToLogMessage)(compiler, config);
63
+ }
64
+ }
65
+ exports.TsCheckerRspackPlugin = TsCheckerRspackPlugin;
66
+ /**
67
+ * Current version of the plugin
68
+ * TODO: use `define` to replace it
69
+ */
70
+ TsCheckerRspackPlugin.version = '1.0.0-beta.0';
71
+ /**
72
+ * Default pools for the plugin concurrency limit
73
+ */
74
+ TsCheckerRspackPlugin.issuesPool = plugin_pools_1.issuesPool;
75
+ TsCheckerRspackPlugin.dependenciesPool = plugin_pools_1.dependenciesPool;
76
+ /**
77
+ * @deprecated Use TsCheckerRspackPlugin.issuesPool instead
78
+ */
79
+ TsCheckerRspackPlugin.pool = plugin_pools_1.issuesPool;
@@ -0,0 +1 @@
1
+ export declare function exposeRpc(fn: (...args: any[]) => any): void;
@@ -0,0 +1,78 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.exposeRpc = void 0;
16
+ const process_1 = __importDefault(require("process"));
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ function exposeRpc(fn) {
19
+ const sendMessage = (message) => new Promise((resolve, reject) => {
20
+ if (!process_1.default.send) {
21
+ reject(new Error(`Process ${process_1.default.pid} doesn't have IPC channels`));
22
+ }
23
+ else if (!process_1.default.connected) {
24
+ reject(new Error(`Process ${process_1.default.pid} doesn't have open IPC channels`));
25
+ }
26
+ else {
27
+ process_1.default.send(message, undefined, undefined, (error) => {
28
+ if (error) {
29
+ reject(error);
30
+ }
31
+ else {
32
+ resolve(undefined);
33
+ }
34
+ });
35
+ }
36
+ });
37
+ const handleMessage = (message) => __awaiter(this, void 0, void 0, function* () {
38
+ if (message.type === 'call') {
39
+ if (!process_1.default.send) {
40
+ // process disconnected - skip
41
+ return;
42
+ }
43
+ let value;
44
+ let error;
45
+ try {
46
+ value = yield fn(...message.args);
47
+ }
48
+ catch (fnError) {
49
+ error = fnError;
50
+ }
51
+ try {
52
+ if (error) {
53
+ yield sendMessage({
54
+ type: 'reject',
55
+ id: message.id,
56
+ error,
57
+ });
58
+ }
59
+ else {
60
+ yield sendMessage({
61
+ type: 'resolve',
62
+ id: message.id,
63
+ value,
64
+ });
65
+ }
66
+ }
67
+ catch (sendError) {
68
+ // we can't send things back to the parent process - let's use stdout to communicate error
69
+ if (error) {
70
+ console.error(error);
71
+ }
72
+ console.error(sendError);
73
+ }
74
+ }
75
+ });
76
+ process_1.default.on('message', handleMessage);
77
+ }
78
+ exports.exposeRpc = exposeRpc;
@@ -0,0 +1,5 @@
1
+ export { exposeRpc } from './expose-rpc';
2
+ export { wrapRpc } from './wrap-rpc';
3
+ export { createRpcWorker, getRpcWorkerData, RpcWorker } from './rpc-worker';
4
+ export { RpcExitError } from './rpc-error';
5
+ export { RpcRemoteMethod } from './types';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RpcExitError = exports.getRpcWorkerData = exports.createRpcWorker = exports.wrapRpc = exports.exposeRpc = void 0;
4
+ var expose_rpc_1 = require("./expose-rpc");
5
+ Object.defineProperty(exports, "exposeRpc", { enumerable: true, get: function () { return expose_rpc_1.exposeRpc; } });
6
+ var wrap_rpc_1 = require("./wrap-rpc");
7
+ Object.defineProperty(exports, "wrapRpc", { enumerable: true, get: function () { return wrap_rpc_1.wrapRpc; } });
8
+ var rpc_worker_1 = require("./rpc-worker");
9
+ Object.defineProperty(exports, "createRpcWorker", { enumerable: true, get: function () { return rpc_worker_1.createRpcWorker; } });
10
+ Object.defineProperty(exports, "getRpcWorkerData", { enumerable: true, get: function () { return rpc_worker_1.getRpcWorkerData; } });
11
+ var rpc_error_1 = require("./rpc-error");
12
+ Object.defineProperty(exports, "RpcExitError", { enumerable: true, get: function () { return rpc_error_1.RpcExitError; } });
@@ -0,0 +1,6 @@
1
+ declare class RpcExitError extends Error {
2
+ readonly code?: string | number | null | undefined;
3
+ readonly signal?: string | null | undefined;
4
+ constructor(message: string, code?: string | number | null | undefined, signal?: string | null | undefined);
5
+ }
6
+ export { RpcExitError };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RpcExitError = void 0;
4
+ class RpcExitError extends Error {
5
+ constructor(message, code, signal) {
6
+ super(message);
7
+ this.code = code;
8
+ this.signal = signal;
9
+ this.name = 'RpcExitError';
10
+ }
11
+ }
12
+ exports.RpcExitError = RpcExitError;
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import type { ChildProcess } from 'child_process';
3
+ import type { RpcMethod, RpcRemoteMethod } from './types';
4
+ interface RpcWorkerBase {
5
+ connect(): void;
6
+ terminate(): void;
7
+ readonly connected: boolean;
8
+ readonly process: ChildProcess | undefined;
9
+ }
10
+ declare type RpcWorker<T extends RpcMethod = RpcMethod> = RpcWorkerBase & RpcRemoteMethod<T>;
11
+ declare function createRpcWorker<T extends RpcMethod>(modulePath: string, data: unknown, memoryLimit?: number): RpcWorker<T>;
12
+ declare function getRpcWorkerData(): unknown;
13
+ export { createRpcWorker, getRpcWorkerData, RpcWorker };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.getRpcWorkerData = exports.createRpcWorker = void 0;
23
+ const child_process = __importStar(require("child_process"));
24
+ const process = __importStar(require("process"));
25
+ const wrap_rpc_1 = require("./wrap-rpc");
26
+ const WORKER_DATA_ENV_KEY = 'WORKER_DATA';
27
+ function createRpcWorker(modulePath, data, memoryLimit) {
28
+ const options = {
29
+ env: Object.assign(Object.assign({}, process.env), { [WORKER_DATA_ENV_KEY]: JSON.stringify(data || {}) }),
30
+ stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
31
+ serialization: 'advanced',
32
+ };
33
+ if (memoryLimit) {
34
+ options.execArgv = [`--max-old-space-size=${memoryLimit}`];
35
+ }
36
+ let childProcess;
37
+ let remoteMethod;
38
+ const worker = {
39
+ connect() {
40
+ if (childProcess && !childProcess.connected) {
41
+ childProcess.kill('SIGTERM');
42
+ childProcess = undefined;
43
+ remoteMethod = undefined;
44
+ }
45
+ if (!(childProcess === null || childProcess === void 0 ? void 0 : childProcess.connected)) {
46
+ childProcess = child_process.fork(modulePath, options);
47
+ remoteMethod = (0, wrap_rpc_1.wrapRpc)(childProcess);
48
+ }
49
+ },
50
+ terminate() {
51
+ if (childProcess) {
52
+ childProcess.kill('SIGTERM');
53
+ childProcess = undefined;
54
+ remoteMethod = undefined;
55
+ }
56
+ },
57
+ get connected() {
58
+ return Boolean(childProcess === null || childProcess === void 0 ? void 0 : childProcess.connected);
59
+ },
60
+ get process() {
61
+ return childProcess;
62
+ },
63
+ };
64
+ return Object.assign((...args) => {
65
+ if (!worker.connected) {
66
+ // try to auto-connect
67
+ worker.connect();
68
+ }
69
+ if (!remoteMethod) {
70
+ return Promise.reject('Worker is not connected - cannot perform RPC.');
71
+ }
72
+ return remoteMethod(...args);
73
+ }, worker);
74
+ }
75
+ exports.createRpcWorker = createRpcWorker;
76
+ function getRpcWorkerData() {
77
+ return JSON.parse(process.env[WORKER_DATA_ENV_KEY] || '{}');
78
+ }
79
+ exports.getRpcWorkerData = getRpcWorkerData;
@@ -0,0 +1,19 @@
1
+ interface RpcCallMessage {
2
+ type: 'call';
3
+ id: string;
4
+ args: unknown[];
5
+ }
6
+ interface RpcResolveMessage {
7
+ type: 'resolve';
8
+ id: string;
9
+ value: unknown;
10
+ }
11
+ interface RpcRejectMessage {
12
+ type: 'reject';
13
+ id: string;
14
+ error: unknown;
15
+ }
16
+ declare type RpcMessage = RpcCallMessage | RpcResolveMessage | RpcRejectMessage;
17
+ declare type RpcMethod = (...args: any[]) => any;
18
+ declare type RpcRemoteMethod<T extends RpcMethod> = T extends (...args: infer A) => infer R ? R extends Promise<any> ? (...args: A) => R : (...args: A) => Promise<R> : (...args: unknown[]) => Promise<unknown>;
19
+ export { RpcCallMessage, RpcResolveMessage, RpcRejectMessage, RpcMessage, RpcMethod, RpcRemoteMethod, };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import type { ChildProcess } from 'child_process';
3
+ import type { RpcRemoteMethod } from './types';
4
+ export declare function wrapRpc<T extends (...args: any[]) => any>(childProcess: ChildProcess): RpcRemoteMethod<T>;
@@ -0,0 +1,79 @@
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
+ exports.wrapRpc = void 0;
13
+ const controlled_promise_1 = require("../utils/async/controlled-promise");
14
+ const rpc_error_1 = require("./rpc-error");
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ function wrapRpc(childProcess) {
17
+ return ((...args) => __awaiter(this, void 0, void 0, function* () {
18
+ if (!childProcess.send) {
19
+ throw new Error(`Process ${childProcess.pid} doesn't have IPC channels`);
20
+ }
21
+ else if (!childProcess.connected) {
22
+ throw new Error(`Process ${childProcess.pid} doesn't have open IPC channels`);
23
+ }
24
+ const id = uuid();
25
+ // create promises
26
+ const { promise: resultPromise, resolve: resolveResult, reject: rejectResult, } = (0, controlled_promise_1.createControlledPromise)();
27
+ const { promise: sendPromise, resolve: resolveSend, reject: rejectSend, } = (0, controlled_promise_1.createControlledPromise)();
28
+ const handleMessage = (message) => {
29
+ if ((message === null || message === void 0 ? void 0 : message.id) === id) {
30
+ if (message.type === 'resolve') {
31
+ // assume the contract is respected
32
+ resolveResult(message.value);
33
+ removeHandlers();
34
+ }
35
+ else if (message.type === 'reject') {
36
+ rejectResult(message.error);
37
+ removeHandlers();
38
+ }
39
+ }
40
+ };
41
+ const handleClose = (code, signal) => {
42
+ rejectResult(new rpc_error_1.RpcExitError(code
43
+ ? `Process ${childProcess.pid} exited with code ${code}` +
44
+ (signal ? ` [${signal}]` : '')
45
+ : `Process ${childProcess.pid} exited` + (signal ? ` [${signal}]` : ''), code, signal));
46
+ removeHandlers();
47
+ };
48
+ // to prevent event handler leaks
49
+ const removeHandlers = () => {
50
+ childProcess.off('message', handleMessage);
51
+ childProcess.off('close', handleClose);
52
+ };
53
+ // add event listeners
54
+ childProcess.on('message', handleMessage);
55
+ childProcess.on('close', handleClose);
56
+ // send call message
57
+ childProcess.send({
58
+ type: 'call',
59
+ id,
60
+ args,
61
+ }, (error) => {
62
+ if (error) {
63
+ rejectSend(error);
64
+ removeHandlers();
65
+ }
66
+ else {
67
+ resolveSend(undefined);
68
+ }
69
+ });
70
+ return sendPromise.then(() => resultPromise);
71
+ }));
72
+ }
73
+ exports.wrapRpc = wrapRpc;
74
+ function uuid() {
75
+ return new Array(4)
76
+ .fill(0)
77
+ .map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))
78
+ .join('-');
79
+ }
@@ -0,0 +1,12 @@
1
+ interface TypeScriptConfigOverwrite {
2
+ extends?: string;
3
+ compilerOptions?: any;
4
+ include?: string[];
5
+ exclude?: string[];
6
+ files?: string[];
7
+ references?: {
8
+ path: string;
9
+ prepend?: boolean;
10
+ }[];
11
+ }
12
+ export { TypeScriptConfigOverwrite };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ interface TypeScriptDiagnosticsOptions {
2
+ syntactic: boolean;
3
+ semantic: boolean;
4
+ declaration: boolean;
5
+ global: boolean;
6
+ }
7
+ export { TypeScriptDiagnosticsOptions };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import type { TypeScriptWorkerConfig } from './type-script-worker-config';
2
+ declare function assertTypeScriptSupport(config: TypeScriptWorkerConfig): void;
3
+ export { assertTypeScriptSupport };
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.assertTypeScriptSupport = void 0;
26
+ const os_1 = __importDefault(require("os"));
27
+ const fs_extra_1 = __importDefault(require("fs-extra"));
28
+ const semver = __importStar(require("semver"));
29
+ function assertTypeScriptSupport(config) {
30
+ let typescriptVersion;
31
+ try {
32
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
33
+ typescriptVersion = require(config.typescriptPath).version;
34
+ }
35
+ catch (error) {
36
+ // silent catch
37
+ }
38
+ if (!typescriptVersion) {
39
+ throw new Error('When you use TsCheckerRspackPlugin with typescript reporter enabled, you must install `typescript` package.');
40
+ }
41
+ if (semver.lt(typescriptVersion, '3.6.0')) {
42
+ throw new Error([
43
+ `TsCheckerRspackPlugin cannot use the current typescript version of ${typescriptVersion}.`,
44
+ 'The minimum required version is 3.6.0.',
45
+ ].join(os_1.default.EOL));
46
+ }
47
+ if (config.build && semver.lt(typescriptVersion, '3.8.0')) {
48
+ throw new Error([
49
+ `TsCheckerRspackPlugin doesn't support build option for the current typescript version of ${typescriptVersion}.`,
50
+ 'The minimum required version is 3.8.0.',
51
+ ].join(os_1.default.EOL));
52
+ }
53
+ if (!fs_extra_1.default.existsSync(config.configFile)) {
54
+ throw new Error([
55
+ `Cannot find the "${config.configFile}" file.`,
56
+ `Please check webpack and TsCheckerRspackPlugin configuration.`,
57
+ `Possible errors:`,
58
+ ' - wrong `context` directory in webpack configuration (if `configFile` is not set or is a relative path in the fork plugin configuration)',
59
+ ' - wrong `typescript.configFile` path in the plugin configuration (should be a relative or absolute path)',
60
+ ].join(os_1.default.EOL));
61
+ }
62
+ }
63
+ exports.assertTypeScriptSupport = assertTypeScriptSupport;
@@ -0,0 +1,18 @@
1
+ import type * as rspack from '@rspack/core';
2
+ import type { TypeScriptConfigOverwrite } from './type-script-config-overwrite';
3
+ import type { TypeScriptDiagnosticsOptions } from './type-script-diagnostics-options';
4
+ import type { TypeScriptWorkerOptions } from './type-script-worker-options';
5
+ interface TypeScriptWorkerConfig {
6
+ enabled: boolean;
7
+ memoryLimit: number;
8
+ configFile: string;
9
+ configOverwrite: TypeScriptConfigOverwrite;
10
+ build: boolean;
11
+ context: string;
12
+ mode: 'readonly' | 'write-dts' | 'write-tsbuildinfo' | 'write-references';
13
+ diagnosticOptions: TypeScriptDiagnosticsOptions;
14
+ profile: boolean;
15
+ typescriptPath: string;
16
+ }
17
+ declare function createTypeScriptWorkerConfig(compiler: rspack.Compiler, options: TypeScriptWorkerOptions | undefined): TypeScriptWorkerConfig;
18
+ export { createTypeScriptWorkerConfig, TypeScriptWorkerConfig };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createTypeScriptWorkerConfig = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ function createTypeScriptWorkerConfig(compiler, options) {
9
+ let configFile = typeof options === 'object' ? options.configFile || 'tsconfig.json' : 'tsconfig.json';
10
+ // ensure that `configFile` is an absolute normalized path
11
+ configFile = path_1.default.normalize(path_1.default.isAbsolute(configFile)
12
+ ? configFile
13
+ : path_1.default.resolve(compiler.options.context || process.cwd(), configFile));
14
+ const optionsAsObject = typeof options === 'object' ? options : {};
15
+ const typescriptPath = optionsAsObject.typescriptPath || require.resolve('typescript');
16
+ return Object.assign(Object.assign({ enabled: options !== false, 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 });
17
+ }
18
+ exports.createTypeScriptWorkerConfig = createTypeScriptWorkerConfig;
@@ -0,0 +1,14 @@
1
+ import type { TypeScriptConfigOverwrite } from './type-script-config-overwrite';
2
+ import type { TypeScriptDiagnosticsOptions } from './type-script-diagnostics-options';
3
+ declare type TypeScriptWorkerOptions = {
4
+ memoryLimit?: number;
5
+ configFile?: string;
6
+ configOverwrite?: TypeScriptConfigOverwrite;
7
+ context?: string;
8
+ build?: boolean;
9
+ mode?: 'readonly' | 'write-tsbuildinfo' | 'write-dts' | 'write-references';
10
+ diagnosticOptions?: Partial<TypeScriptDiagnosticsOptions>;
11
+ profile?: boolean;
12
+ typescriptPath?: string;
13
+ };
14
+ export { TypeScriptWorkerOptions };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import type { FilesChange } from '../../files-change';
2
+ import type { FilesMatch } from '../../files-match';
3
+ declare const getDependenciesWorker: (change: FilesChange) => FilesMatch;
4
+ export declare type GetDependenciesWorker = typeof getDependenciesWorker;
5
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const rpc_1 = require("../../rpc");
4
+ const config_1 = require("./lib/config");
5
+ const dependencies_1 = require("./lib/dependencies");
6
+ const system_1 = require("./lib/system");
7
+ 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
+ (0, config_1.invalidateConfig)();
11
+ (0, dependencies_1.invalidateDependencies)();
12
+ }
13
+ return (0, dependencies_1.getDependencies)();
14
+ };
15
+ (0, rpc_1.exposeRpc)(getDependenciesWorker);
@@ -0,0 +1,5 @@
1
+ import type { FilesChange } from '../../files-change';
2
+ import type { Issue } from '../../issue';
3
+ declare const getIssuesWorker: (change: FilesChange, watching: boolean) => Promise<Issue[]>;
4
+ export declare type GetIssuesWorker = typeof getIssuesWorker;
5
+ export {};