ts-checker-rspack-plugin 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -1
- package/lib/hooks/tap-start-to-run-type-script-go.d.ts +5 -0
- package/lib/index.js +427 -25
- package/lib/typescript/type-script-go-constants.d.ts +4 -0
- package/lib/typescript/type-script-go-runner.d.ts +19 -0
- package/lib/typescript/type-script-support.d.ts +2 -1
- package/lib/typescript/type-script-worker-config.d.ts +1 -0
- package/lib/typescript/type-script-worker-options.d.ts +1 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -114,7 +114,43 @@ Options for the TypeScript checker (`typescript` option object).
|
|
|
114
114
|
| `mode` | `'readonly'` or `'write-dts'` or `'write-tsbuildinfo'` or `'write-references'` | `build === true ? 'write-tsbuildinfo' ? 'readonly'` | Use `readonly` if you don't want to write anything on the disk, `write-dts` to write only `.d.ts` files, `write-tsbuildinfo` to write only `.tsbuildinfo` files, `write-references` to write both `.js` and `.d.ts` files of project references (last 2 modes requires `build: true`). |
|
|
115
115
|
| `diagnosticOptions` | `object` | `{ syntactic: false, semantic: true, declaration: false, global: false }` | Settings to select which diagnostics do we want to perform. |
|
|
116
116
|
| `profile` | `boolean` | `false` | Measures and prints timings related to the TypeScript performance. |
|
|
117
|
-
| `typescriptPath` | `string` | `require.resolve('typescript')`
|
|
117
|
+
| `typescriptPath` | `string` | `tsgo === true ? require.resolve('@typescript/native-preview/package.json') : require.resolve('typescript')` | If supplied this is a custom path where TypeScript can be found. In `tsgo` mode, it must be an absolute path to `@typescript/native-preview/package.json`. |
|
|
118
|
+
| `tsgo` | `boolean` | `false` | Enables experimental TypeScript Go (`@typescript/native-preview`) support. The plugin runs the tsgo binary in a child process. |
|
|
119
|
+
|
|
120
|
+
#### TypeScript Go support
|
|
121
|
+
|
|
122
|
+
`typescript.tsgo` is an experimental, CLI-based integration for [typescript-go](https://github.com/microsoft/typescript-go). Because typescript-go does not provide the JavaScript compiler API used by the default checker yet, this mode runs the tsgo binary and parses its output to report diagnostics. When diagnostics can be parsed safely, they are rendered by the existing formatter; otherwise, the plugin prints the raw tsgo output and fails the build when tsgo exits with errors. This integration may change when TypeScript 7.1 provides a JavaScript API for tsgo.
|
|
123
|
+
|
|
124
|
+
Supported in tsgo mode:
|
|
125
|
+
|
|
126
|
+
- `typescript.configFile`, `typescript.context`, `typescript.build`, and `typescript.typescriptPath`.
|
|
127
|
+
- `async`.
|
|
128
|
+
- `logger`.
|
|
129
|
+
- `tsconfig.json` compiler options used by tsgo, including `incremental` and `composite`.
|
|
130
|
+
|
|
131
|
+
Partially supported in tsgo mode:
|
|
132
|
+
|
|
133
|
+
- `issue.include` and `issue.exclude` work for diagnostics whose header can be matched from tsgo output, including `file`, `line`, `column`, `code`, and `message`.
|
|
134
|
+
- `issue.defaultSeverity` works for matched diagnostics.
|
|
135
|
+
- Raw tsgo stdout/stderr is printed when the plugin cannot safely parse the output.
|
|
136
|
+
|
|
137
|
+
Not supported in tsgo mode:
|
|
138
|
+
|
|
139
|
+
- `typescript.configOverwrite`.
|
|
140
|
+
- `typescript.diagnosticOptions`.
|
|
141
|
+
- `typescript.profile`.
|
|
142
|
+
- TypeScript API based formatting or filesystem output rewrites.
|
|
143
|
+
- Plugin-controlled declaration or reference emit modes such as `write-dts` and `write-references`; tsgo is always run with `--noEmit`.
|
|
144
|
+
|
|
145
|
+
To use it, install `@typescript/native-preview` and enable `tsgo`:
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
new TsCheckerRspackPlugin({
|
|
149
|
+
typescript: {
|
|
150
|
+
tsgo: true,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
```
|
|
118
154
|
|
|
119
155
|
### Issues options
|
|
120
156
|
|
|
@@ -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 tapStartToRunTypeScriptGo(compiler: rspack.Compiler, config: TsCheckerRspackPluginConfig, state: TsCheckerRspackPluginState): void;
|
|
5
|
+
export { tapStartToRunTypeScriptGo };
|
package/lib/index.js
CHANGED
|
@@ -3717,6 +3717,208 @@ var __webpack_exports__ = {};
|
|
|
3717
3717
|
Error.captureStackTrace(this, this.constructor);
|
|
3718
3718
|
}
|
|
3719
3719
|
}
|
|
3720
|
+
const external_node_url_namespaceObject = require("node:url");
|
|
3721
|
+
const TYPESCRIPT_GO_PACKAGE = "@typescript/native-preview";
|
|
3722
|
+
const TYPESCRIPT_GO_PACKAGE_JSON = `${TYPESCRIPT_GO_PACKAGE}/package.json`;
|
|
3723
|
+
function resolveTypeScriptGoPackageJsonPath(config) {
|
|
3724
|
+
if (!external_node_path_default().isAbsolute(config.typescriptPath) || 'package.json' !== external_node_path_default().basename(config.typescriptPath)) throw new Error(`The typescriptPath option must be an absolute path to "${TYPESCRIPT_GO_PACKAGE_JSON}" when tsgo is enabled.`);
|
|
3725
|
+
return config.typescriptPath;
|
|
3726
|
+
}
|
|
3727
|
+
async function resolveTypeScriptGoBinPath(config) {
|
|
3728
|
+
const tsgoPkgPath = resolveTypeScriptGoPackageJsonPath(config);
|
|
3729
|
+
const getExePathPath = external_node_path_default().resolve(external_node_path_default().dirname(tsgoPkgPath), './lib/getExePath.js');
|
|
3730
|
+
const getExePathUrl = (0, external_node_url_namespaceObject.pathToFileURL)(getExePathPath).href;
|
|
3731
|
+
const getExePathModule = await import(getExePathUrl);
|
|
3732
|
+
const getExePath = getExePathModule.default || getExePathModule.getExePath;
|
|
3733
|
+
if ('function' != typeof getExePath) throw new Error(`Cannot resolve the typescript-go executable from "${TYPESCRIPT_GO_PACKAGE}".`);
|
|
3734
|
+
return getExePath();
|
|
3735
|
+
}
|
|
3736
|
+
function createTypeScriptGoArgs(config) {
|
|
3737
|
+
const args = config.build ? [
|
|
3738
|
+
'--build',
|
|
3739
|
+
config.configFile
|
|
3740
|
+
] : [
|
|
3741
|
+
'--project',
|
|
3742
|
+
config.configFile
|
|
3743
|
+
];
|
|
3744
|
+
args.push('--noEmit', '--pretty');
|
|
3745
|
+
return args;
|
|
3746
|
+
}
|
|
3747
|
+
function logOutput(logger, output) {
|
|
3748
|
+
if (!output.trim()) return;
|
|
3749
|
+
logger.error(output.trimEnd());
|
|
3750
|
+
}
|
|
3751
|
+
function stripAnsi(output) {
|
|
3752
|
+
return output.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, '');
|
|
3753
|
+
}
|
|
3754
|
+
function getTypeScriptGoErrorCount(output) {
|
|
3755
|
+
const plainOutput = stripAnsi(output);
|
|
3756
|
+
const matches = Array.from(plainOutput.matchAll(/\bFound\s+(\d+)\s+errors?\b/g));
|
|
3757
|
+
const lastMatch = matches[matches.length - 1];
|
|
3758
|
+
if (!lastMatch) return;
|
|
3759
|
+
return Number(lastMatch[1]);
|
|
3760
|
+
}
|
|
3761
|
+
function getTypeScriptGoIssueSeverity(severity, defaultSeverity) {
|
|
3762
|
+
return 'auto' === defaultSeverity ? severity : defaultSeverity;
|
|
3763
|
+
}
|
|
3764
|
+
function createTypeScriptGoIssue(message) {
|
|
3765
|
+
return {
|
|
3766
|
+
severity: 'error',
|
|
3767
|
+
code: "TSGO",
|
|
3768
|
+
message
|
|
3769
|
+
};
|
|
3770
|
+
}
|
|
3771
|
+
const diagnosticPattern = /^(.*?):(\d+):(\d+)\s+-\s+(error|warning)\s+TS(\d+):\s+(.+)$/;
|
|
3772
|
+
const globalDiagnosticPattern = /^(error|warning)\s+TS(\d+):\s+(.+)$/;
|
|
3773
|
+
function getTypeScriptGoMarkerLength(output, startIndex) {
|
|
3774
|
+
const lines = output.slice(startIndex).split(/\r?\n/);
|
|
3775
|
+
for (const line of lines){
|
|
3776
|
+
if (diagnosticPattern.test(line) || globalDiagnosticPattern.test(line) || /^Found\s+\d+\s+errors?\b/.test(line)) break;
|
|
3777
|
+
const marker = line.match(/^\s*([~^]+)\s*$/);
|
|
3778
|
+
if (marker) return marker[1].length;
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
3781
|
+
function parseTypeScriptGoIssues(output, config, defaultSeverity = 'auto') {
|
|
3782
|
+
const issues = [];
|
|
3783
|
+
const plainOutput = stripAnsi(output);
|
|
3784
|
+
const diagnosticPatternWithGlobal = new RegExp(diagnosticPattern, 'gm');
|
|
3785
|
+
const globalDiagnosticPatternWithGlobal = new RegExp(globalDiagnosticPattern, 'gm');
|
|
3786
|
+
for (const match of plainOutput.matchAll(diagnosticPatternWithGlobal)){
|
|
3787
|
+
const [, file, line, column, severity, code, message] = match;
|
|
3788
|
+
const startColumn = Number(column);
|
|
3789
|
+
const markerLength = getTypeScriptGoMarkerLength(plainOutput, (match.index || 0) + match[0].length);
|
|
3790
|
+
const position = {
|
|
3791
|
+
line: Number(line),
|
|
3792
|
+
column: startColumn
|
|
3793
|
+
};
|
|
3794
|
+
issues.push({
|
|
3795
|
+
severity: getTypeScriptGoIssueSeverity(severity, defaultSeverity),
|
|
3796
|
+
code: `TS${code}`,
|
|
3797
|
+
message,
|
|
3798
|
+
file: external_node_path_default().isAbsolute(file) ? file : external_node_path_default().resolve(config.context, file),
|
|
3799
|
+
location: {
|
|
3800
|
+
start: position,
|
|
3801
|
+
end: {
|
|
3802
|
+
line: position.line,
|
|
3803
|
+
column: markerLength ? startColumn + markerLength : startColumn
|
|
3804
|
+
}
|
|
3805
|
+
}
|
|
3806
|
+
});
|
|
3807
|
+
}
|
|
3808
|
+
for (const match of plainOutput.matchAll(globalDiagnosticPatternWithGlobal)){
|
|
3809
|
+
const [, severity, code, message] = match;
|
|
3810
|
+
issues.push({
|
|
3811
|
+
severity: getTypeScriptGoIssueSeverity(severity, defaultSeverity),
|
|
3812
|
+
code: `TS${code}`,
|
|
3813
|
+
message
|
|
3814
|
+
});
|
|
3815
|
+
}
|
|
3816
|
+
return issues;
|
|
3817
|
+
}
|
|
3818
|
+
function createTypeScriptGoExitIssues(output, signal, config, defaultSeverity = 'auto') {
|
|
3819
|
+
const parsedIssues = parseTypeScriptGoIssues(output, config, defaultSeverity);
|
|
3820
|
+
const errorCount = getTypeScriptGoErrorCount(output);
|
|
3821
|
+
if (parsedIssues.length && (void 0 === errorCount || parsedIssues.length >= errorCount)) return parsedIssues;
|
|
3822
|
+
if (void 0 !== errorCount) return Array.from({
|
|
3823
|
+
length: Math.max(errorCount, 1)
|
|
3824
|
+
}, ()=>createTypeScriptGoIssue('tsgo check failed. See the output above for diagnostics.'));
|
|
3825
|
+
if (null !== signal) return [
|
|
3826
|
+
createTypeScriptGoIssue(`tsgo check interrupted by ${signal}. See the output above for diagnostics.`)
|
|
3827
|
+
];
|
|
3828
|
+
return [
|
|
3829
|
+
createTypeScriptGoIssue('tsgo check failed. See the output above for diagnostics.')
|
|
3830
|
+
];
|
|
3831
|
+
}
|
|
3832
|
+
function isTypeScriptGoIssue(issue) {
|
|
3833
|
+
return "TSGO" === issue.code;
|
|
3834
|
+
}
|
|
3835
|
+
function isTypeScriptGoStatsError(error) {
|
|
3836
|
+
const issue = error?.issue;
|
|
3837
|
+
if (issue && isTypeScriptGoIssue(issue)) return true;
|
|
3838
|
+
const message = error?.message;
|
|
3839
|
+
return 'string' == typeof message && message.includes("TSGO:");
|
|
3840
|
+
}
|
|
3841
|
+
async function runTypeScriptGo(config, logger, defaultSeverity = 'auto', signal) {
|
|
3842
|
+
AbortError.throwIfAborted(signal);
|
|
3843
|
+
const binPath = await resolveTypeScriptGoBinPath(config);
|
|
3844
|
+
const args = createTypeScriptGoArgs(config);
|
|
3845
|
+
return new Promise((resolve, reject)=>{
|
|
3846
|
+
let settled = false;
|
|
3847
|
+
let output = '';
|
|
3848
|
+
const childProcess = (0, external_node_child_process_namespaceObject.spawn)(binPath, args, {
|
|
3849
|
+
cwd: config.context,
|
|
3850
|
+
stdio: [
|
|
3851
|
+
'inherit',
|
|
3852
|
+
'pipe',
|
|
3853
|
+
'pipe'
|
|
3854
|
+
]
|
|
3855
|
+
});
|
|
3856
|
+
const cleanup = ()=>{
|
|
3857
|
+
signal?.removeEventListener('abort', abort);
|
|
3858
|
+
childProcess.stdout?.removeAllListeners();
|
|
3859
|
+
childProcess.stderr?.removeAllListeners();
|
|
3860
|
+
childProcess.removeAllListeners();
|
|
3861
|
+
};
|
|
3862
|
+
const finish = (callback)=>{
|
|
3863
|
+
if (settled) return;
|
|
3864
|
+
settled = true;
|
|
3865
|
+
cleanup();
|
|
3866
|
+
callback();
|
|
3867
|
+
};
|
|
3868
|
+
const abort = ()=>{
|
|
3869
|
+
childProcess.kill('SIGTERM');
|
|
3870
|
+
finish(()=>reject(new AbortError()));
|
|
3871
|
+
};
|
|
3872
|
+
signal?.addEventListener('abort', abort, {
|
|
3873
|
+
once: true
|
|
3874
|
+
});
|
|
3875
|
+
childProcess.stdout?.on('data', (data)=>{
|
|
3876
|
+
output += data.toString();
|
|
3877
|
+
});
|
|
3878
|
+
childProcess.stderr?.on('data', (data)=>{
|
|
3879
|
+
output += data.toString();
|
|
3880
|
+
});
|
|
3881
|
+
childProcess.on('error', (error)=>{
|
|
3882
|
+
finish(()=>reject(error));
|
|
3883
|
+
});
|
|
3884
|
+
childProcess.on('close', (exitCode, exitSignal)=>{
|
|
3885
|
+
finish(()=>{
|
|
3886
|
+
if (0 === exitCode && null === exitSignal) {
|
|
3887
|
+
logOutput(logger, output);
|
|
3888
|
+
resolve([]);
|
|
3889
|
+
return;
|
|
3890
|
+
}
|
|
3891
|
+
const issues = createTypeScriptGoExitIssues(output, exitSignal, config, defaultSeverity);
|
|
3892
|
+
if (issues.some(isTypeScriptGoIssue)) logOutput(logger, output);
|
|
3893
|
+
resolve(issues);
|
|
3894
|
+
});
|
|
3895
|
+
});
|
|
3896
|
+
});
|
|
3897
|
+
}
|
|
3898
|
+
function getTypeScriptGoDependencies(config) {
|
|
3899
|
+
return {
|
|
3900
|
+
files: [
|
|
3901
|
+
config.configFile
|
|
3902
|
+
],
|
|
3903
|
+
dirs: [
|
|
3904
|
+
config.context
|
|
3905
|
+
],
|
|
3906
|
+
excluded: [
|
|
3907
|
+
external_node_path_default().join(config.context, 'node_modules')
|
|
3908
|
+
],
|
|
3909
|
+
extensions: [
|
|
3910
|
+
'.ts',
|
|
3911
|
+
'.tsx',
|
|
3912
|
+
'.mts',
|
|
3913
|
+
'.cts',
|
|
3914
|
+
'.js',
|
|
3915
|
+
'.jsx',
|
|
3916
|
+
'.mjs',
|
|
3917
|
+
'.cjs',
|
|
3918
|
+
'.json'
|
|
3919
|
+
]
|
|
3920
|
+
};
|
|
3921
|
+
}
|
|
3720
3922
|
function tapAfterCompileToGetIssues(compiler, config, state) {
|
|
3721
3923
|
const hooks = getPluginHooks(compiler);
|
|
3722
3924
|
const { debug } = getInfrastructureLogger(compiler);
|
|
@@ -3731,8 +3933,16 @@ var __webpack_exports__ = {};
|
|
|
3731
3933
|
}
|
|
3732
3934
|
debug('Got issues from getIssuesWorker.', issues?.length);
|
|
3733
3935
|
if (!issues) return;
|
|
3734
|
-
|
|
3735
|
-
|
|
3936
|
+
if (config.typescript.tsgo) {
|
|
3937
|
+
const internalIssues = issues.filter(isTypeScriptGoIssue);
|
|
3938
|
+
let visibleIssues = issues.filter((issue)=>!isTypeScriptGoIssue(issue));
|
|
3939
|
+
visibleIssues = visibleIssues.filter(config.issue.predicate);
|
|
3940
|
+
visibleIssues = hooks.issues.call(visibleIssues, compilation);
|
|
3941
|
+
issues = internalIssues.concat(visibleIssues);
|
|
3942
|
+
} else {
|
|
3943
|
+
issues = issues.filter(config.issue.predicate);
|
|
3944
|
+
issues = hooks.issues.call(issues, compilation);
|
|
3945
|
+
}
|
|
3736
3946
|
issues.forEach((issue)=>{
|
|
3737
3947
|
const error = new IssueRspackError(config.formatter.format(issue), config.formatter.pathType, issue);
|
|
3738
3948
|
if ('warning' === issue.severity) compilation.warnings.push(error);
|
|
@@ -3802,13 +4012,23 @@ var __webpack_exports__ = {};
|
|
|
3802
4012
|
}
|
|
3803
4013
|
if (!issues || state.issuesPromise !== issuesPromise) return;
|
|
3804
4014
|
debug(`Got ${issues?.length || 0} issues from getIssuesWorker.`);
|
|
3805
|
-
|
|
3806
|
-
|
|
4015
|
+
let visibleIssues;
|
|
4016
|
+
if (config.typescript.tsgo) {
|
|
4017
|
+
const internalIssues = issues.filter(isTypeScriptGoIssue);
|
|
4018
|
+
visibleIssues = issues.filter((issue)=>!isTypeScriptGoIssue(issue));
|
|
4019
|
+
visibleIssues = visibleIssues.filter(config.issue.predicate);
|
|
4020
|
+
visibleIssues = hooks.issues.call(visibleIssues, stats.compilation);
|
|
4021
|
+
issues = internalIssues.concat(visibleIssues);
|
|
4022
|
+
} else {
|
|
4023
|
+
visibleIssues = issues.filter(config.issue.predicate);
|
|
4024
|
+
visibleIssues = hooks.issues.call(visibleIssues, stats.compilation);
|
|
4025
|
+
issues = visibleIssues;
|
|
4026
|
+
}
|
|
3807
4027
|
const formatter = createRspackFormatter(config.formatter.format, config.formatter.pathType);
|
|
3808
|
-
if (
|
|
4028
|
+
if (visibleIssues.length) config.logger.error(visibleIssues.map((issue)=>formatter(issue)).join('\n'));
|
|
3809
4029
|
config.logger.log(statsFormatter(issues, stats));
|
|
3810
|
-
if (
|
|
3811
|
-
|
|
4030
|
+
if (visibleIssues.length && state.DevServerDoneTap) {
|
|
4031
|
+
visibleIssues.forEach((issue)=>{
|
|
3812
4032
|
const error = new IssueRspackError(config.formatter.format(issue), config.formatter.pathType, issue);
|
|
3813
4033
|
if ('warning' === issue.severity) stats.compilation.warnings.push(error);
|
|
3814
4034
|
else stats.compilation.errors.push(error);
|
|
@@ -3907,6 +4127,189 @@ var __webpack_exports__ = {};
|
|
|
3907
4127
|
});
|
|
3908
4128
|
});
|
|
3909
4129
|
}
|
|
4130
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
4131
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
4132
|
+
function isDefaultTypeScriptGoPath(typescriptPath) {
|
|
4133
|
+
if (typescriptPath === TYPESCRIPT_GO_PACKAGE_JSON) return true;
|
|
4134
|
+
try {
|
|
4135
|
+
return typescriptPath === require.resolve(TYPESCRIPT_GO_PACKAGE_JSON);
|
|
4136
|
+
} catch {
|
|
4137
|
+
return false;
|
|
4138
|
+
}
|
|
4139
|
+
}
|
|
4140
|
+
function createTypeScriptGoSupportError(config, error) {
|
|
4141
|
+
const message = [
|
|
4142
|
+
`When you enable TsCheckerRspackPlugin with \`typescript.tsgo\`, you must install \`${TYPESCRIPT_GO_PACKAGE}\` package.`
|
|
4143
|
+
];
|
|
4144
|
+
if (!isDefaultTypeScriptGoPath(config.typescriptPath)) message.push(`If you set \`typescript.typescriptPath\`, it must be an absolute path to \`${TYPESCRIPT_GO_PACKAGE_JSON}\`.`);
|
|
4145
|
+
if (error instanceof Error && error.message) message.push(`Failed to resolve the tsgo executable: ${error.message}`);
|
|
4146
|
+
message.push(`You can install it with \`npm add ${TYPESCRIPT_GO_PACKAGE} -D\`.`);
|
|
4147
|
+
return new Error(message.join(external_node_os_default().EOL));
|
|
4148
|
+
}
|
|
4149
|
+
function assertTypeScriptGoSupport(config) {
|
|
4150
|
+
try {
|
|
4151
|
+
const tsgoPackageJsonPath = resolveTypeScriptGoPackageJsonPath(config);
|
|
4152
|
+
const getExePathPath = external_node_path_default().resolve(external_node_path_default().dirname(tsgoPackageJsonPath), './lib/getExePath.js');
|
|
4153
|
+
if (!external_node_fs_default().existsSync(getExePathPath)) throw new Error();
|
|
4154
|
+
} catch (error) {
|
|
4155
|
+
throw createTypeScriptGoSupportError(config, error);
|
|
4156
|
+
}
|
|
4157
|
+
}
|
|
4158
|
+
async function assertTypeScriptGoExecutable(config) {
|
|
4159
|
+
try {
|
|
4160
|
+
await resolveTypeScriptGoBinPath(config);
|
|
4161
|
+
} catch (error) {
|
|
4162
|
+
throw createTypeScriptGoSupportError(config, error);
|
|
4163
|
+
}
|
|
4164
|
+
}
|
|
4165
|
+
function assertTypeScriptSupport(config) {
|
|
4166
|
+
if (config.tsgo) assertTypeScriptGoSupport(config);
|
|
4167
|
+
else {
|
|
4168
|
+
let typescriptVersion;
|
|
4169
|
+
try {
|
|
4170
|
+
typescriptVersion = require(config.typescriptPath).version;
|
|
4171
|
+
} catch {}
|
|
4172
|
+
if (!typescriptVersion) throw new Error("When you use TsCheckerRspackPlugin with typescript reporter enabled, you must install `typescript` package.");
|
|
4173
|
+
}
|
|
4174
|
+
if (!external_node_fs_default().existsSync(config.configFile)) throw new Error([
|
|
4175
|
+
`Cannot find the "${config.configFile}" file.`,
|
|
4176
|
+
"Please check Rspack and TsCheckerRspackPlugin configuration.",
|
|
4177
|
+
"Possible errors:",
|
|
4178
|
+
' - wrong `context` directory in Rspack configuration (if `configFile` is not set or is a relative path in the fork plugin configuration)',
|
|
4179
|
+
" - wrong `typescript.configFile` path in the plugin configuration (should be a relative or absolute path)"
|
|
4180
|
+
].join(external_node_os_default().EOL));
|
|
4181
|
+
}
|
|
4182
|
+
const hiddenTypeScriptGoErrors = Symbol('hiddenTypeScriptGoErrors');
|
|
4183
|
+
function getStatsFilterHook(hook) {
|
|
4184
|
+
return hook;
|
|
4185
|
+
}
|
|
4186
|
+
function getStatsPrintHook(hook) {
|
|
4187
|
+
return hook;
|
|
4188
|
+
}
|
|
4189
|
+
function tapStartToRunTypeScriptGo(compiler, config, state) {
|
|
4190
|
+
const hooks = getPluginHooks(compiler);
|
|
4191
|
+
const { log, debug } = getInfrastructureLogger(compiler);
|
|
4192
|
+
let assertTypeScriptGoExecutablePromise;
|
|
4193
|
+
const assertTypeScriptGoExecutableOnce = async ()=>{
|
|
4194
|
+
try {
|
|
4195
|
+
if (!assertTypeScriptGoExecutablePromise) assertTypeScriptGoExecutablePromise = assertTypeScriptGoExecutable(config.typescript);
|
|
4196
|
+
await assertTypeScriptGoExecutablePromise;
|
|
4197
|
+
} catch (error) {
|
|
4198
|
+
assertTypeScriptGoExecutablePromise = void 0;
|
|
4199
|
+
throw error;
|
|
4200
|
+
}
|
|
4201
|
+
};
|
|
4202
|
+
compiler.hooks.run.tapPromise('TsCheckerRspackPlugin', async ()=>{
|
|
4203
|
+
if (!state.initialized) {
|
|
4204
|
+
await assertTypeScriptGoExecutableOnce();
|
|
4205
|
+
debug('Initializing tsgo for single run (not async).');
|
|
4206
|
+
state.initialized = true;
|
|
4207
|
+
state.watching = false;
|
|
4208
|
+
tapAfterCompileToGetIssues(compiler, config, state);
|
|
4209
|
+
}
|
|
4210
|
+
});
|
|
4211
|
+
compiler.hooks.watchRun.tapPromise('TsCheckerRspackPlugin', async ()=>{
|
|
4212
|
+
if (!state.initialized) {
|
|
4213
|
+
await assertTypeScriptGoExecutableOnce();
|
|
4214
|
+
state.initialized = true;
|
|
4215
|
+
state.watching = true;
|
|
4216
|
+
if (config.async) {
|
|
4217
|
+
debug('Initializing tsgo for watch run (async).');
|
|
4218
|
+
tapDoneToAsyncGetIssues(compiler, config, state);
|
|
4219
|
+
interceptDoneToGetDevServerTap(compiler, config, state);
|
|
4220
|
+
} else {
|
|
4221
|
+
debug('Initializing tsgo for watch run (not async).');
|
|
4222
|
+
tapAfterCompileToGetIssues(compiler, config, state);
|
|
4223
|
+
}
|
|
4224
|
+
}
|
|
4225
|
+
});
|
|
4226
|
+
compiler.hooks.compilation.tap('TsCheckerRspackPlugin', async (compilation)=>{
|
|
4227
|
+
if (compilation.compiler !== compiler) return;
|
|
4228
|
+
compilation.hooks.statsFactory.tap('TsCheckerRspackPlugin', (stats)=>{
|
|
4229
|
+
const errorsFilter = getStatsFilterHook(stats.hooks.filter.for('compilation.errors'));
|
|
4230
|
+
errorsFilter.tap('TsCheckerRspackPlugin', (error)=>isTypeScriptGoStatsError(error) ? false : void 0);
|
|
4231
|
+
stats.hooks.result.for('compilation').tap('TsCheckerRspackPlugin', (statsCompilation, context)=>{
|
|
4232
|
+
const hiddenErrorsCount = context.cachedGetErrors?.(context.compilation).filter(isTypeScriptGoStatsError).length || 0;
|
|
4233
|
+
if (hiddenErrorsCount) Object.defineProperty(statsCompilation, hiddenTypeScriptGoErrors, {
|
|
4234
|
+
value: hiddenErrorsCount
|
|
4235
|
+
});
|
|
4236
|
+
return statsCompilation;
|
|
4237
|
+
});
|
|
4238
|
+
});
|
|
4239
|
+
compilation.hooks.statsPrinter.tap('TsCheckerRspackPlugin', (stats)=>{
|
|
4240
|
+
const errorsInChildrenPrinter = getStatsPrintHook(stats.hooks.print.for('compilation.errorsInChildren!'));
|
|
4241
|
+
errorsInChildrenPrinter.tap('TsCheckerRspackPlugin', (_, { compilation, red })=>{
|
|
4242
|
+
const hiddenErrorsCount = compilation[hiddenTypeScriptGoErrors] || 0;
|
|
4243
|
+
if (!hiddenErrorsCount || compilation.children || !compilation.errorsCount || !compilation.errors) return;
|
|
4244
|
+
const childErrorsCount = compilation.errorsCount - compilation.errors.length - hiddenErrorsCount;
|
|
4245
|
+
if (childErrorsCount <= 0) return '';
|
|
4246
|
+
const childErrorsLabel = 1 === childErrorsCount ? 'ERROR' : 'ERRORS';
|
|
4247
|
+
const childErrorsMessage = `${childErrorsCount} ${childErrorsLabel} in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details)`;
|
|
4248
|
+
return red(childErrorsMessage);
|
|
4249
|
+
});
|
|
4250
|
+
});
|
|
4251
|
+
const iteration = ++state.iteration;
|
|
4252
|
+
if (state.abortController) {
|
|
4253
|
+
debug(`Aborting tsgo iteration ${iteration - 1}.`);
|
|
4254
|
+
state.abortController.abort();
|
|
4255
|
+
}
|
|
4256
|
+
const abortController = new AbortController();
|
|
4257
|
+
state.abortController = abortController;
|
|
4258
|
+
let filesChange = {};
|
|
4259
|
+
if (state.watching) {
|
|
4260
|
+
filesChange = consumeFilesChange(compiler);
|
|
4261
|
+
log([
|
|
4262
|
+
'Calling tsgo for incremental check.',
|
|
4263
|
+
` Changed files: ${JSON.stringify(filesChange.changedFiles)}`,
|
|
4264
|
+
` Deleted files: ${JSON.stringify(filesChange.deletedFiles)}`
|
|
4265
|
+
].join('\n'));
|
|
4266
|
+
} else log('Calling tsgo for single check.');
|
|
4267
|
+
state.dependenciesPromise = Promise.resolve(getTypeScriptGoDependencies(config.typescript));
|
|
4268
|
+
filesChange = await hooks.start.promise(filesChange, compilation);
|
|
4269
|
+
let aggregatedFilesChange = filesChange;
|
|
4270
|
+
if (state.aggregatedFilesChange) {
|
|
4271
|
+
aggregatedFilesChange = aggregateFilesChanges([
|
|
4272
|
+
aggregatedFilesChange,
|
|
4273
|
+
filesChange
|
|
4274
|
+
]);
|
|
4275
|
+
debug([
|
|
4276
|
+
`Aggregating with previous files change, iteration ${iteration}.`,
|
|
4277
|
+
` Changed files: ${JSON.stringify(aggregatedFilesChange.changedFiles)}`,
|
|
4278
|
+
` Deleted files: ${JSON.stringify(aggregatedFilesChange.deletedFiles)}`
|
|
4279
|
+
].join('\n'));
|
|
4280
|
+
}
|
|
4281
|
+
state.aggregatedFilesChange = aggregatedFilesChange;
|
|
4282
|
+
state.issuesPromise = (state.issuesPromise || Promise.resolve()).catch(()=>void 0).then(()=>{
|
|
4283
|
+
if (abortController.signal.aborted) return;
|
|
4284
|
+
debug(`Submitting tsgo to the pool, iteration ${iteration}.`);
|
|
4285
|
+
return issuesPool.submit(async (signal)=>{
|
|
4286
|
+
try {
|
|
4287
|
+
debug(`Running tsgo, iteration ${iteration}.`);
|
|
4288
|
+
const issues = await runTypeScriptGo(config.typescript, config.logger, config.issue.defaultSeverity, signal);
|
|
4289
|
+
if (state.aggregatedFilesChange === aggregatedFilesChange) state.aggregatedFilesChange = void 0;
|
|
4290
|
+
if (state.abortController === abortController) state.abortController = void 0;
|
|
4291
|
+
return issues;
|
|
4292
|
+
} catch (error) {
|
|
4293
|
+
hooks.error.call(error, compilation);
|
|
4294
|
+
return;
|
|
4295
|
+
} finally{
|
|
4296
|
+
debug(`tsgo finished its job, iteration ${iteration}.`);
|
|
4297
|
+
}
|
|
4298
|
+
}, abortController.signal);
|
|
4299
|
+
});
|
|
4300
|
+
});
|
|
4301
|
+
const abortTypeScriptGo = ()=>{
|
|
4302
|
+
if (state.abortController) {
|
|
4303
|
+
debug('Compiler is going to close - terminating tsgo...');
|
|
4304
|
+
state.abortController.abort();
|
|
4305
|
+
state.abortController = void 0;
|
|
4306
|
+
}
|
|
4307
|
+
};
|
|
4308
|
+
compiler.hooks.watchClose.tap('TsCheckerRspackPlugin', abortTypeScriptGo);
|
|
4309
|
+
compiler.hooks.failed.tap('TsCheckerRspackPlugin', ()=>{
|
|
4310
|
+
if (!state.watching) abortTypeScriptGo();
|
|
4311
|
+
});
|
|
4312
|
+
}
|
|
3910
4313
|
function tapStopToTerminateWorkers(compiler, getIssuesWorker, getDependenciesWorker, state) {
|
|
3911
4314
|
const { debug } = getInfrastructureLogger(compiler);
|
|
3912
4315
|
const terminateWorkers = ()=>{
|
|
@@ -3930,8 +4333,6 @@ var __webpack_exports__ = {};
|
|
|
3930
4333
|
};
|
|
3931
4334
|
}
|
|
3932
4335
|
var lib = __webpack_require__("./node_modules/.pnpm/@babel+code-frame@7.29.7/node_modules/@babel/code-frame/lib/index.js");
|
|
3933
|
-
const external_node_fs_namespaceObject = require("node:fs");
|
|
3934
|
-
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
3935
4336
|
function createCodeFrameFormatter(options) {
|
|
3936
4337
|
const basicFormatter = createBasicFormatter();
|
|
3937
4338
|
return function(issue) {
|
|
@@ -3997,11 +4398,19 @@ var __webpack_exports__ = {};
|
|
|
3997
4398
|
defaultSeverity
|
|
3998
4399
|
};
|
|
3999
4400
|
}
|
|
4401
|
+
function resolveDefaultTypeScriptPath(tsgo) {
|
|
4402
|
+
if (true === tsgo) try {
|
|
4403
|
+
return require.resolve(TYPESCRIPT_GO_PACKAGE_JSON);
|
|
4404
|
+
} catch {
|
|
4405
|
+
return TYPESCRIPT_GO_PACKAGE_JSON;
|
|
4406
|
+
}
|
|
4407
|
+
return require.resolve("typescript");
|
|
4408
|
+
}
|
|
4000
4409
|
function createTypeScriptWorkerConfig(compiler, options) {
|
|
4001
4410
|
let configFile = 'object' == typeof options ? options.configFile || 'tsconfig.json' : 'tsconfig.json';
|
|
4002
4411
|
configFile = external_node_path_default().normalize(external_node_path_default().isAbsolute(configFile) ? configFile : external_node_path_default().resolve(compiler.options.context || process.cwd(), configFile));
|
|
4003
4412
|
const optionsAsObject = 'object' == typeof options ? options : {};
|
|
4004
|
-
const typescriptPath = optionsAsObject.typescriptPath ||
|
|
4413
|
+
const typescriptPath = optionsAsObject.typescriptPath || resolveDefaultTypeScriptPath(optionsAsObject.tsgo);
|
|
4005
4414
|
return {
|
|
4006
4415
|
enabled: Boolean(options) || void 0 === options,
|
|
4007
4416
|
memoryLimit: 8192,
|
|
@@ -4019,7 +4428,7 @@ var __webpack_exports__ = {};
|
|
|
4019
4428
|
global: false,
|
|
4020
4429
|
...optionsAsObject.diagnosticOptions || {}
|
|
4021
4430
|
},
|
|
4022
|
-
typescriptPath
|
|
4431
|
+
typescriptPath
|
|
4023
4432
|
};
|
|
4024
4433
|
}
|
|
4025
4434
|
function createPluginConfig(compiler, options = {}) {
|
|
@@ -4051,20 +4460,6 @@ var __webpack_exports__ = {};
|
|
|
4051
4460
|
DevServerDoneTap: void 0
|
|
4052
4461
|
};
|
|
4053
4462
|
}
|
|
4054
|
-
function assertTypeScriptSupport(config) {
|
|
4055
|
-
let typescriptVersion;
|
|
4056
|
-
try {
|
|
4057
|
-
typescriptVersion = require(config.typescriptPath).version;
|
|
4058
|
-
} catch {}
|
|
4059
|
-
if (!typescriptVersion) throw new Error("When you use TsCheckerRspackPlugin with typescript reporter enabled, you must install `typescript` package.");
|
|
4060
|
-
if (!external_node_fs_default().existsSync(config.configFile)) throw new Error([
|
|
4061
|
-
`Cannot find the "${config.configFile}" file.`,
|
|
4062
|
-
"Please check Rspack and TsCheckerRspackPlugin configuration.",
|
|
4063
|
-
"Possible errors:",
|
|
4064
|
-
' - wrong `context` directory in Rspack configuration (if `configFile` is not set or is a relative path in the fork plugin configuration)',
|
|
4065
|
-
" - wrong `typescript.configFile` path in the plugin configuration (should be a relative or absolute path)"
|
|
4066
|
-
].join(external_node_os_default().EOL));
|
|
4067
|
-
}
|
|
4068
4463
|
function plugin_define_property(obj, key, value) {
|
|
4069
4464
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
4070
4465
|
value: value,
|
|
@@ -4084,6 +4479,13 @@ var __webpack_exports__ = {};
|
|
|
4084
4479
|
const config = createPluginConfig(compiler, this.options);
|
|
4085
4480
|
const state = createPluginState();
|
|
4086
4481
|
assertTypeScriptSupport(config.typescript);
|
|
4482
|
+
if (config.typescript.tsgo) {
|
|
4483
|
+
tapAfterEnvironmentToPatchWatching(compiler, state);
|
|
4484
|
+
tapStartToRunTypeScriptGo(compiler, config, state);
|
|
4485
|
+
tapAfterCompileToAddDependencies(compiler, config, state);
|
|
4486
|
+
tapErrorToLogMessage(compiler, config);
|
|
4487
|
+
return;
|
|
4488
|
+
}
|
|
4087
4489
|
const getIssuesWorker = createRpcWorker(external_node_path_namespaceObject.resolve(__dirname, './getIssuesWorker.js'), config.typescript, config.typescript.memoryLimit);
|
|
4088
4490
|
const getDependenciesWorker = createRpcWorker(external_node_path_namespaceObject.resolve(__dirname, './getDependenciesWorker.js'), config.typescript);
|
|
4089
4491
|
tapAfterEnvironmentToPatchWatching(compiler, state);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const TYPESCRIPT_GO_PACKAGE = "@typescript/native-preview";
|
|
2
|
+
declare const TYPESCRIPT_GO_PACKAGE_JSON = "@typescript/native-preview/package.json";
|
|
3
|
+
declare const TYPESCRIPT_GO_ISSUE_CODE = "TSGO";
|
|
4
|
+
export { TYPESCRIPT_GO_PACKAGE, TYPESCRIPT_GO_PACKAGE_JSON, TYPESCRIPT_GO_ISSUE_CODE };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Issue, IssueDefaultSeverity } from '../issue';
|
|
2
|
+
import type { Logger } from '../logger';
|
|
3
|
+
import type { TypeScriptWorkerConfig } from './type-script-worker-config';
|
|
4
|
+
declare function resolveTypeScriptGoPackageJsonPath(config: TypeScriptWorkerConfig): string;
|
|
5
|
+
declare function resolveTypeScriptGoBinPath(config: TypeScriptWorkerConfig): Promise<string>;
|
|
6
|
+
declare function createTypeScriptGoArgs(config: TypeScriptWorkerConfig): string[];
|
|
7
|
+
declare function getTypeScriptGoErrorCount(output: string): number | undefined;
|
|
8
|
+
declare function parseTypeScriptGoIssues(output: string, config: TypeScriptWorkerConfig, defaultSeverity?: IssueDefaultSeverity): Issue[];
|
|
9
|
+
declare function createTypeScriptGoExitIssues(output: string, signal: NodeJS.Signals | null, config: TypeScriptWorkerConfig, defaultSeverity?: IssueDefaultSeverity): Issue[];
|
|
10
|
+
declare function isTypeScriptGoIssue(issue: Issue): boolean;
|
|
11
|
+
declare function isTypeScriptGoStatsError(error: unknown): boolean;
|
|
12
|
+
declare function runTypeScriptGo(config: TypeScriptWorkerConfig, logger: Pick<Logger, 'error'>, defaultSeverity?: IssueDefaultSeverity, signal?: AbortSignal): Promise<Issue[]>;
|
|
13
|
+
declare function getTypeScriptGoDependencies(config: TypeScriptWorkerConfig): {
|
|
14
|
+
files: string[];
|
|
15
|
+
dirs: string[];
|
|
16
|
+
excluded: string[];
|
|
17
|
+
extensions: string[];
|
|
18
|
+
};
|
|
19
|
+
export { createTypeScriptGoArgs, createTypeScriptGoExitIssues, getTypeScriptGoDependencies, getTypeScriptGoErrorCount, isTypeScriptGoIssue, isTypeScriptGoStatsError, parseTypeScriptGoIssues, resolveTypeScriptGoBinPath, resolveTypeScriptGoPackageJsonPath, runTypeScriptGo, };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { TypeScriptWorkerConfig } from './type-script-worker-config';
|
|
2
|
+
declare function assertTypeScriptGoExecutable(config: TypeScriptWorkerConfig): Promise<void>;
|
|
2
3
|
declare function assertTypeScriptSupport(config: TypeScriptWorkerConfig): void;
|
|
3
|
-
export { assertTypeScriptSupport };
|
|
4
|
+
export { assertTypeScriptGoExecutable, assertTypeScriptSupport };
|
|
@@ -13,6 +13,7 @@ interface TypeScriptWorkerConfig {
|
|
|
13
13
|
diagnosticOptions: TypeScriptDiagnosticsOptions;
|
|
14
14
|
profile: boolean;
|
|
15
15
|
typescriptPath: string;
|
|
16
|
+
tsgo?: boolean;
|
|
16
17
|
}
|
|
17
18
|
declare function createTypeScriptWorkerConfig(compiler: rspack.Compiler, options: TypeScriptWorkerOptions | undefined): TypeScriptWorkerConfig;
|
|
18
19
|
export { createTypeScriptWorkerConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-checker-rspack-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Runs typescript type checker and linter on separate process.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rspack",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@types/is-glob": "^4.0.4",
|
|
38
38
|
"@types/mock-fs": "^4.13.4",
|
|
39
39
|
"@types/node": "^24.12.4",
|
|
40
|
+
"@typescript/native-preview": "7.0.0-dev.20260606.1",
|
|
40
41
|
"cross-env": "^10.1.0",
|
|
41
42
|
"husky": "^9.1.7",
|
|
42
43
|
"is-glob": "^4.0.3",
|
|
@@ -48,11 +49,15 @@
|
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
50
51
|
"@rspack/core": "^1.0.0 || ^2.0.0",
|
|
52
|
+
"@typescript/native-preview": "^7.0.0-0",
|
|
51
53
|
"typescript": ">=3.8.0"
|
|
52
54
|
},
|
|
53
55
|
"peerDependenciesMeta": {
|
|
54
56
|
"@rspack/core": {
|
|
55
57
|
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"@typescript/native-preview": {
|
|
60
|
+
"optional": true
|
|
56
61
|
}
|
|
57
62
|
},
|
|
58
63
|
"publishConfig": {
|