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
@@ -0,0 +1,31 @@
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.tapAfterCompileToAddDependencies = void 0;
13
+ const infrastructure_logger_1 = require("../infrastructure-logger");
14
+ function tapAfterCompileToAddDependencies(compiler, config, state) {
15
+ const { debug } = (0, infrastructure_logger_1.getInfrastructureLogger)(compiler);
16
+ compiler.hooks.afterCompile.tapPromise('TsCheckerRspackPlugin', (compilation) => __awaiter(this, void 0, void 0, function* () {
17
+ if (compilation.compiler !== compiler) {
18
+ // run only for the compiler that the plugin was registered for
19
+ return;
20
+ }
21
+ const dependencies = yield state.dependenciesPromise;
22
+ debug(`Got dependencies from the getDependenciesWorker.`, dependencies);
23
+ if (dependencies) {
24
+ state.lastDependencies = dependencies;
25
+ dependencies.files.forEach((file) => {
26
+ compilation.fileDependencies.add(file);
27
+ });
28
+ }
29
+ }));
30
+ }
31
+ exports.tapAfterCompileToAddDependencies = tapAfterCompileToAddDependencies;
@@ -0,0 +1,5 @@
1
+ import type * as rspack from '@rspack/core';
2
+ import type { TsCheckerRspackPluginConfig } from '../plugin-config';
3
+ import type { TsCheckerRspackPluginState } from '../plugin-state';
4
+ declare function tapAfterCompileToGetIssues(compiler: rspack.Compiler, config: TsCheckerRspackPluginConfig, state: TsCheckerRspackPluginState): void;
5
+ export { tapAfterCompileToGetIssues };
@@ -0,0 +1,52 @@
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.tapAfterCompileToGetIssues = void 0;
13
+ const infrastructure_logger_1 = require("../infrastructure-logger");
14
+ const issue_webpack_error_1 = require("../issue/issue-webpack-error");
15
+ const plugin_hooks_1 = require("../plugin-hooks");
16
+ function tapAfterCompileToGetIssues(compiler, config, state) {
17
+ const hooks = (0, plugin_hooks_1.getPluginHooks)(compiler);
18
+ const { debug } = (0, infrastructure_logger_1.getInfrastructureLogger)(compiler);
19
+ compiler.hooks.afterCompile.tapPromise('TsCheckerRspackPlugin', (compilation) => __awaiter(this, void 0, void 0, function* () {
20
+ if (compilation.compiler !== compiler) {
21
+ // run only for the compiler that the plugin was registered for
22
+ return;
23
+ }
24
+ let issues = [];
25
+ try {
26
+ issues = yield state.issuesPromise;
27
+ }
28
+ catch (error) {
29
+ hooks.error.call(error, compilation);
30
+ return;
31
+ }
32
+ debug('Got issues from getIssuesWorker.', issues === null || issues === void 0 ? void 0 : issues.length);
33
+ if (!issues) {
34
+ // some error has been thrown or it was canceled
35
+ return;
36
+ }
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
+ }));
51
+ }
52
+ exports.tapAfterCompileToGetIssues = tapAfterCompileToGetIssues;
@@ -0,0 +1,4 @@
1
+ import type * as rspack from '@rspack/core';
2
+ import type { TsCheckerRspackPluginState } from '../plugin-state';
3
+ declare function tapAfterEnvironmentToPatchWatching(compiler: rspack.Compiler, state: TsCheckerRspackPluginState): void;
4
+ export { tapAfterEnvironmentToPatchWatching };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tapAfterEnvironmentToPatchWatching = void 0;
4
+ const infrastructure_logger_1 = require("../infrastructure-logger");
5
+ const inclusive_node_watch_file_system_1 = require("../watch/inclusive-node-watch-file-system");
6
+ function tapAfterEnvironmentToPatchWatching(compiler, state) {
7
+ const { debug } = (0, infrastructure_logger_1.getInfrastructureLogger)(compiler);
8
+ compiler.hooks.afterEnvironment.tap('TsCheckerRspackPlugin', () => {
9
+ const watchFileSystem = compiler.watchFileSystem;
10
+ if (watchFileSystem) {
11
+ debug("Overwriting webpack's watch file system.");
12
+ // wrap original watch file system
13
+ compiler.watchFileSystem = new inclusive_node_watch_file_system_1.InclusiveNodeWatchFileSystem(
14
+ // we use some internals here
15
+ watchFileSystem, compiler, state);
16
+ }
17
+ else {
18
+ debug('No watch file system found - plugin may not work correctly.');
19
+ }
20
+ });
21
+ }
22
+ exports.tapAfterEnvironmentToPatchWatching = tapAfterEnvironmentToPatchWatching;
@@ -0,0 +1,5 @@
1
+ import type * as rspack from '@rspack/core';
2
+ import type { TsCheckerRspackPluginConfig } from '../plugin-config';
3
+ import type { TsCheckerRspackPluginState } from '../plugin-state';
4
+ declare function tapDoneToAsyncGetIssues(compiler: rspack.Compiler, config: TsCheckerRspackPluginConfig, state: TsCheckerRspackPluginState): void;
5
+ export { tapDoneToAsyncGetIssues };
@@ -0,0 +1,86 @@
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.tapDoneToAsyncGetIssues = void 0;
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ const stats_formatter_1 = require("../formatter/stats-formatter");
18
+ const webpack_formatter_1 = require("../formatter/webpack-formatter");
19
+ const infrastructure_logger_1 = require("../infrastructure-logger");
20
+ const issue_webpack_error_1 = require("../issue/issue-webpack-error");
21
+ const plugin_hooks_1 = require("../plugin-hooks");
22
+ const is_pending_1 = require("../utils/async/is-pending");
23
+ const wait_1 = require("../utils/async/wait");
24
+ function tapDoneToAsyncGetIssues(compiler, config, state) {
25
+ const hooks = (0, plugin_hooks_1.getPluginHooks)(compiler);
26
+ const { debug } = (0, infrastructure_logger_1.getInfrastructureLogger)(compiler);
27
+ compiler.hooks.done.tap('TsCheckerRspackPlugin', (stats) => __awaiter(this, void 0, void 0, function* () {
28
+ if (stats.compilation.compiler !== compiler) {
29
+ // run only for the compiler that the plugin was registered for
30
+ return;
31
+ }
32
+ const issuesPromise = state.issuesPromise;
33
+ let issues;
34
+ try {
35
+ if (yield (0, is_pending_1.isPending)(issuesPromise)) {
36
+ hooks.waiting.call(stats.compilation);
37
+ config.logger.log(chalk_1.default.cyan('Type-checking in progress...'));
38
+ }
39
+ else {
40
+ // wait 10ms to log issues after webpack stats
41
+ yield (0, wait_1.wait)(10);
42
+ }
43
+ issues = yield issuesPromise;
44
+ }
45
+ catch (error) {
46
+ hooks.error.call(error, stats.compilation);
47
+ return;
48
+ }
49
+ if (!issues || // some error has been thrown
50
+ state.issuesPromise !== issuesPromise // we have a new request - don't show results for the old one
51
+ ) {
52
+ return;
53
+ }
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);
59
+ const formatter = (0, webpack_formatter_1.createWebpackFormatter)(config.formatter.format, config.formatter.pathType);
60
+ if (issues.length) {
61
+ // follow webpack's approach - one process.write to stderr with all errors and warnings
62
+ config.logger.error(issues.map((issue) => formatter(issue)).join('\n'));
63
+ // print stats of the compilation
64
+ config.logger.log((0, stats_formatter_1.statsFormatter)(issues, stats));
65
+ }
66
+ else {
67
+ config.logger.log(chalk_1.default.green('No errors found.'));
68
+ }
69
+ // report issues to webpack-dev-server, if it's listening
70
+ // skip reporting if there are no issues, to avoid an extra hot reload
71
+ 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
+ });
81
+ debug('Sending issues to the webpack-dev-server.');
82
+ state.webpackDevServerDoneTap.fn(stats);
83
+ }
84
+ }));
85
+ }
86
+ exports.tapDoneToAsyncGetIssues = tapDoneToAsyncGetIssues;
@@ -0,0 +1,4 @@
1
+ import type * as rspack from '@rspack/core';
2
+ import type { TsCheckerRspackPluginConfig } from '../plugin-config';
3
+ declare function tapErrorToLogMessage(compiler: rspack.Compiler, config: TsCheckerRspackPluginConfig): void;
4
+ export { tapErrorToLogMessage };
@@ -0,0 +1,32 @@
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.tapErrorToLogMessage = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const plugin_hooks_1 = require("../plugin-hooks");
9
+ const rpc_1 = require("../rpc");
10
+ const abort_error_1 = require("../utils/async/abort-error");
11
+ function tapErrorToLogMessage(compiler, config) {
12
+ const hooks = (0, plugin_hooks_1.getPluginHooks)(compiler);
13
+ hooks.error.tap('TsCheckerRspackPlugin', (error) => {
14
+ if (error instanceof abort_error_1.AbortError) {
15
+ return;
16
+ }
17
+ config.logger.error(String(error));
18
+ if (error instanceof rpc_1.RpcExitError) {
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 TsCheckerRspackPlugin configuration.'));
23
+ }
24
+ else {
25
+ config.logger.error(chalk_1.default.red('Issues checking service aborted - probably out of memory. ' +
26
+ 'Check the `memoryLimit` option in the TsCheckerRspackPlugin configuration.\n' +
27
+ "If increasing the memory doesn't solve the issue, it's most probably a bug in the TypeScript."));
28
+ }
29
+ }
30
+ });
31
+ }
32
+ exports.tapErrorToLogMessage = tapErrorToLogMessage;
@@ -0,0 +1,8 @@
1
+ import type * as rspack from '@rspack/core';
2
+ import type { TsCheckerRspackPluginConfig } from '../plugin-config';
3
+ import type { TsCheckerRspackPluginState } from '../plugin-state';
4
+ import type { RpcWorker } from '../rpc';
5
+ import type { GetDependenciesWorker } from '../typescript/worker/get-dependencies-worker';
6
+ import type { GetIssuesWorker } from '../typescript/worker/get-issues-worker';
7
+ declare function tapStartToRunWorkers(compiler: rspack.Compiler, getIssuesWorker: RpcWorker<GetIssuesWorker>, getDependenciesWorker: RpcWorker<GetDependenciesWorker>, config: TsCheckerRspackPluginConfig, state: TsCheckerRspackPluginState): void;
8
+ export { tapStartToRunWorkers };
@@ -0,0 +1,132 @@
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.tapStartToRunWorkers = void 0;
13
+ const node_abort_controller_1 = require("node-abort-controller");
14
+ const files_change_1 = require("../files-change");
15
+ const infrastructure_logger_1 = require("../infrastructure-logger");
16
+ const plugin_hooks_1 = require("../plugin-hooks");
17
+ const plugin_pools_1 = require("../plugin-pools");
18
+ const intercept_done_to_get_dev_server_tap_1 = require("./intercept-done-to-get-dev-server-tap");
19
+ const tap_after_compile_to_get_issues_1 = require("./tap-after-compile-to-get-issues");
20
+ const tap_done_to_async_get_issues_1 = require("./tap-done-to-async-get-issues");
21
+ function tapStartToRunWorkers(compiler, getIssuesWorker, getDependenciesWorker, config, state) {
22
+ const hooks = (0, plugin_hooks_1.getPluginHooks)(compiler);
23
+ const { log, debug } = (0, infrastructure_logger_1.getInfrastructureLogger)(compiler);
24
+ compiler.hooks.run.tap('TsCheckerRspackPlugin', () => {
25
+ if (!state.initialized) {
26
+ debug('Initializing plugin for single run (not async).');
27
+ state.initialized = true;
28
+ state.watching = false;
29
+ (0, tap_after_compile_to_get_issues_1.tapAfterCompileToGetIssues)(compiler, config, state);
30
+ }
31
+ });
32
+ compiler.hooks.watchRun.tap('TsCheckerRspackPlugin', () => __awaiter(this, void 0, void 0, function* () {
33
+ if (!state.initialized) {
34
+ state.initialized = true;
35
+ state.watching = true;
36
+ if (config.async) {
37
+ debug('Initializing plugin for watch run (async).');
38
+ (0, tap_done_to_async_get_issues_1.tapDoneToAsyncGetIssues)(compiler, config, state);
39
+ (0, intercept_done_to_get_dev_server_tap_1.interceptDoneToGetDevServerTap)(compiler, config, state);
40
+ }
41
+ else {
42
+ debug('Initializing plugin for watch run (not async).');
43
+ (0, tap_after_compile_to_get_issues_1.tapAfterCompileToGetIssues)(compiler, config, state);
44
+ }
45
+ }
46
+ }));
47
+ compiler.hooks.compilation.tap('TsCheckerRspackPlugin', (compilation) => __awaiter(this, void 0, void 0, function* () {
48
+ if (compilation.compiler !== compiler) {
49
+ // run only for the compiler that the plugin was registered for
50
+ return;
51
+ }
52
+ // get current iteration number
53
+ const iteration = ++state.iteration;
54
+ // abort previous iteration
55
+ if (state.abortController) {
56
+ debug(`Aborting iteration ${iteration - 1}.`);
57
+ state.abortController.abort();
58
+ }
59
+ // create new abort controller for the new iteration
60
+ const abortController = new node_abort_controller_1.AbortController();
61
+ state.abortController = abortController;
62
+ let filesChange = {};
63
+ if (state.watching) {
64
+ filesChange = (0, files_change_1.consumeFilesChange)(compiler);
65
+ log([
66
+ 'Calling reporter service for incremental check.',
67
+ ` Changed files: ${JSON.stringify(filesChange.changedFiles)}`,
68
+ ` Deleted files: ${JSON.stringify(filesChange.deletedFiles)}`,
69
+ ].join('\n'));
70
+ }
71
+ else {
72
+ log('Calling reporter service for single check.');
73
+ }
74
+ filesChange = yield hooks.start.promise(filesChange, compilation);
75
+ let aggregatedFilesChange = filesChange;
76
+ if (state.aggregatedFilesChange) {
77
+ aggregatedFilesChange = (0, files_change_1.aggregateFilesChanges)([aggregatedFilesChange, filesChange]);
78
+ debug([
79
+ `Aggregating with previous files change, iteration ${iteration}.`,
80
+ ` Changed files: ${JSON.stringify(aggregatedFilesChange.changedFiles)}`,
81
+ ` Deleted files: ${JSON.stringify(aggregatedFilesChange.deletedFiles)}`,
82
+ ].join('\n'));
83
+ }
84
+ state.aggregatedFilesChange = aggregatedFilesChange;
85
+ // submit one at a time for a single compiler
86
+ state.issuesPromise = (state.issuesPromise || Promise.resolve())
87
+ // resolve to undefined on error
88
+ .catch(() => undefined)
89
+ .then(() => {
90
+ // early return
91
+ if (abortController.signal.aborted) {
92
+ return undefined;
93
+ }
94
+ debug(`Submitting the getIssuesWorker to the pool, iteration ${iteration}.`);
95
+ return plugin_pools_1.issuesPool.submit(() => __awaiter(this, void 0, void 0, function* () {
96
+ try {
97
+ debug(`Running the getIssuesWorker, iteration ${iteration}.`);
98
+ const issues = yield getIssuesWorker(aggregatedFilesChange, state.watching);
99
+ if (state.aggregatedFilesChange === aggregatedFilesChange) {
100
+ state.aggregatedFilesChange = undefined;
101
+ }
102
+ if (state.abortController === abortController) {
103
+ state.abortController = undefined;
104
+ }
105
+ return issues;
106
+ }
107
+ catch (error) {
108
+ hooks.error.call(error, compilation);
109
+ return undefined;
110
+ }
111
+ finally {
112
+ debug(`The getIssuesWorker finished its job, iteration ${iteration}.`);
113
+ }
114
+ }), abortController.signal);
115
+ });
116
+ debug(`Submitting the getDependenciesWorker to the pool, iteration ${iteration}.`);
117
+ state.dependenciesPromise = plugin_pools_1.dependenciesPool.submit(() => __awaiter(this, void 0, void 0, function* () {
118
+ try {
119
+ debug(`Running the getDependenciesWorker, iteration ${iteration}.`);
120
+ return yield getDependenciesWorker(filesChange);
121
+ }
122
+ catch (error) {
123
+ hooks.error.call(error, compilation);
124
+ return undefined;
125
+ }
126
+ finally {
127
+ debug(`The getDependenciesWorker finished its job, iteration ${iteration}.`);
128
+ }
129
+ })); // don't pass abortController.signal because getDependencies() is blocking
130
+ }));
131
+ }
132
+ exports.tapStartToRunWorkers = tapStartToRunWorkers;
@@ -0,0 +1,5 @@
1
+ import type * as rspack from '@rspack/core';
2
+ import type { TsCheckerRspackPluginState } from '../plugin-state';
3
+ import type { RpcWorker } from '../rpc';
4
+ declare function tapStopToTerminateWorkers(compiler: rspack.Compiler, getIssuesWorker: RpcWorker, getDependenciesWorker: RpcWorker, state: TsCheckerRspackPluginState): void;
5
+ export { tapStopToTerminateWorkers };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tapStopToTerminateWorkers = void 0;
4
+ const infrastructure_logger_1 = require("../infrastructure-logger");
5
+ function tapStopToTerminateWorkers(compiler, getIssuesWorker, getDependenciesWorker, state) {
6
+ const { debug } = (0, infrastructure_logger_1.getInfrastructureLogger)(compiler);
7
+ const terminateWorkers = () => {
8
+ debug('Compiler is going to close - terminating workers...');
9
+ getIssuesWorker.terminate();
10
+ getDependenciesWorker.terminate();
11
+ };
12
+ compiler.hooks.watchClose.tap('TsCheckerRspackPlugin', () => {
13
+ terminateWorkers();
14
+ });
15
+ compiler.hooks.done.tap('TsCheckerRspackPlugin', () => {
16
+ if (!state.watching) {
17
+ terminateWorkers();
18
+ }
19
+ });
20
+ compiler.hooks.failed.tap('TsCheckerRspackPlugin', () => {
21
+ if (!state.watching) {
22
+ terminateWorkers();
23
+ }
24
+ });
25
+ }
26
+ exports.tapStopToTerminateWorkers = tapStopToTerminateWorkers;
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { TsCheckerRspackPlugin } from './plugin';
2
+ export { TsCheckerRspackPlugin };
package/lib/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TsCheckerRspackPlugin = void 0;
4
+ const plugin_1 = require("./plugin");
5
+ Object.defineProperty(exports, "TsCheckerRspackPlugin", { enumerable: true, get: function () { return plugin_1.TsCheckerRspackPlugin; } });
@@ -0,0 +1,9 @@
1
+ import type * as rspack from '@rspack/core';
2
+ export interface InfrastructureLogger {
3
+ log(...args: unknown[]): void;
4
+ debug(...args: unknown[]): void;
5
+ error(...args: unknown[]): void;
6
+ warn(...args: unknown[]): void;
7
+ info(...args: unknown[]): void;
8
+ }
9
+ export declare function getInfrastructureLogger(compiler: rspack.Compiler): InfrastructureLogger;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInfrastructureLogger = void 0;
4
+ function getInfrastructureLogger(compiler) {
5
+ const logger = compiler.getInfrastructureLogger('TsCheckerRspackPlugin');
6
+ return {
7
+ log: logger.log.bind(logger),
8
+ debug: logger.debug.bind(logger),
9
+ error: logger.error.bind(logger),
10
+ warn: logger.warn.bind(logger),
11
+ info: logger.info.bind(logger),
12
+ };
13
+ }
14
+ exports.getInfrastructureLogger = getInfrastructureLogger;
@@ -0,0 +1,3 @@
1
+ export * from './issue';
2
+ export * from './issue-severity';
3
+ export * from './issue-location';
@@ -0,0 +1,15 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./issue"), exports);
14
+ __exportStar(require("./issue-severity"), exports);
15
+ __exportStar(require("./issue-location"), exports);
@@ -0,0 +1,8 @@
1
+ import type * as rspack from '@rspack/core';
2
+ import type { IssueOptions } from './issue-options';
3
+ import type { IssuePredicate } from './issue-predicate';
4
+ interface IssueConfig {
5
+ predicate: IssuePredicate;
6
+ }
7
+ declare function createIssueConfig(compiler: rspack.Compiler, options: IssueOptions | undefined): IssueConfig;
8
+ export { IssueConfig, createIssueConfig };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createIssueConfig = void 0;
4
+ const issue_match_1 = require("./issue-match");
5
+ const issue_predicate_1 = require("./issue-predicate");
6
+ function createIssuePredicateFromOption(context, option) {
7
+ if (Array.isArray(option)) {
8
+ return (0, issue_predicate_1.composeIssuePredicates)(option.map((option) => typeof option === 'function' ? option : (0, issue_match_1.createIssuePredicateFromIssueMatch)(context, option)));
9
+ }
10
+ return typeof option === 'function'
11
+ ? option
12
+ : (0, issue_match_1.createIssuePredicateFromIssueMatch)(context, option);
13
+ }
14
+ function createIssueConfig(compiler, options) {
15
+ const context = compiler.options.context || process.cwd();
16
+ if (!options) {
17
+ options = {};
18
+ }
19
+ const include = options.include
20
+ ? createIssuePredicateFromOption(context, options.include)
21
+ : (0, issue_predicate_1.createTrivialIssuePredicate)(true);
22
+ const exclude = options.exclude
23
+ ? createIssuePredicateFromOption(context, options.exclude)
24
+ : (0, issue_predicate_1.createTrivialIssuePredicate)(false);
25
+ return {
26
+ predicate: (issue) => include(issue) && !exclude(issue),
27
+ };
28
+ }
29
+ exports.createIssueConfig = createIssueConfig;
@@ -0,0 +1,8 @@
1
+ import type { IssuePosition } from './issue-position';
2
+ interface IssueLocation {
3
+ start: IssuePosition;
4
+ end: IssuePosition;
5
+ }
6
+ declare function compareIssueLocations(locationA?: IssueLocation, locationB?: IssueLocation): number;
7
+ declare function formatIssueLocation(location: IssueLocation): string;
8
+ export { IssueLocation, compareIssueLocations, formatIssueLocation };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatIssueLocation = exports.compareIssueLocations = void 0;
4
+ const issue_position_1 = require("./issue-position");
5
+ function compareIssueLocations(locationA, locationB) {
6
+ if (locationA === locationB) {
7
+ return 0;
8
+ }
9
+ if (!locationA) {
10
+ return -1;
11
+ }
12
+ if (!locationB) {
13
+ return 1;
14
+ }
15
+ return ((0, issue_position_1.compareIssuePositions)(locationA.start, locationB.start) ||
16
+ (0, issue_position_1.compareIssuePositions)(locationA.end, locationB.end));
17
+ }
18
+ exports.compareIssueLocations = compareIssueLocations;
19
+ function formatIssueLocation(location) {
20
+ return `${location.start.line}:${location.start.column}`;
21
+ }
22
+ exports.formatIssueLocation = formatIssueLocation;
@@ -0,0 +1,5 @@
1
+ import type { IssuePredicate } from './issue-predicate';
2
+ import type { Issue } from './index';
3
+ declare type IssueMatch = Partial<Pick<Issue, 'severity' | 'code' | 'file'>>;
4
+ declare function createIssuePredicateFromIssueMatch(context: string, match: IssueMatch): IssuePredicate;
5
+ export { IssueMatch, createIssuePredicateFromIssueMatch };
@@ -0,0 +1,20 @@
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.createIssuePredicateFromIssueMatch = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const minimatch_1 = __importDefault(require("minimatch"));
9
+ const forward_slash_1 = require("../utils/path/forward-slash");
10
+ function createIssuePredicateFromIssueMatch(context, match) {
11
+ return (issue) => {
12
+ const matchesSeverity = !match.severity || match.severity === issue.severity;
13
+ const matchesCode = !match.code || match.code === issue.code;
14
+ const matchesFile = !issue.file ||
15
+ (!!issue.file &&
16
+ (!match.file || (0, minimatch_1.default)((0, forward_slash_1.forwardSlash)(path_1.default.relative(context, issue.file)), match.file)));
17
+ return matchesSeverity && matchesCode && matchesFile;
18
+ };
19
+ }
20
+ exports.createIssuePredicateFromIssueMatch = createIssuePredicateFromIssueMatch;
@@ -0,0 +1,8 @@
1
+ import type { IssueMatch } from './issue-match';
2
+ import type { IssuePredicate } from './issue-predicate';
3
+ declare type IssuePredicateOption = IssuePredicate | IssueMatch | (IssuePredicate | IssueMatch)[];
4
+ interface IssueOptions {
5
+ include?: IssuePredicateOption;
6
+ exclude?: IssuePredicateOption;
7
+ }
8
+ export { IssueOptions, IssuePredicateOption };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ interface IssuePosition {
2
+ line: number;
3
+ column: number;
4
+ }
5
+ declare function compareIssuePositions(positionA?: IssuePosition, positionB?: IssuePosition): number;
6
+ export { IssuePosition, compareIssuePositions };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compareIssuePositions = void 0;
4
+ function compareIssuePositions(positionA, positionB) {
5
+ if (positionA === positionB) {
6
+ return 0;
7
+ }
8
+ if (!positionA) {
9
+ return -1;
10
+ }
11
+ if (!positionB) {
12
+ return 1;
13
+ }
14
+ return (Math.sign(positionA.line - positionB.line) || Math.sign(positionA.column - positionB.column));
15
+ }
16
+ exports.compareIssuePositions = compareIssuePositions;
@@ -0,0 +1,5 @@
1
+ import type { Issue } from './index';
2
+ declare type IssuePredicate = (issue: Issue) => boolean;
3
+ declare function createTrivialIssuePredicate(result: boolean): IssuePredicate;
4
+ declare function composeIssuePredicates(predicates: IssuePredicate[]): IssuePredicate;
5
+ export { IssuePredicate, createTrivialIssuePredicate, composeIssuePredicates };