ts-checker-rspack-plugin 1.3.2 → 1.5.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 +66 -11
- package/lib/hooks/tap-start-to-run-type-script-go.d.ts +5 -0
- package/lib/index.js +513 -26
- package/lib/typescript/type-script-go-constants.d.ts +6 -0
- package/lib/typescript/type-script-go-package.d.ts +15 -0
- package/lib/typescript/type-script-go-runner.d.ts +24 -0
- package/lib/typescript/type-script-support.d.ts +2 -1
- package/lib/typescript/type-script-worker-config.d.ts +4 -1
- package/lib/typescript/type-script-worker-options.d.ts +1 -0
- package/package.json +15 -9
package/README.md
CHANGED
|
@@ -104,17 +104,72 @@ Rspack's modules resolution**. It means that you have to setup `tsconfig.json` c
|
|
|
104
104
|
|
|
105
105
|
Options for the TypeScript checker (`typescript` option object).
|
|
106
106
|
|
|
107
|
-
| Name | Type | Default value
|
|
108
|
-
| ------------------- | ------------------------------------------------------------------------------ |
|
|
109
|
-
| `memoryLimit` | `number` | `8192`
|
|
110
|
-
| `configFile` | `string` | `'tsconfig.json'`
|
|
111
|
-
| `configOverwrite` | `object` | `{ compilerOptions: { skipLibCheck: true, sourceMap: false, inlineSourceMap: false, declarationMap: false } }`
|
|
112
|
-
| `context` | `string` | `dirname(configuration.configFile)`
|
|
113
|
-
| `build` | `boolean` | `false`
|
|
114
|
-
| `mode` | `'readonly'` or `'write-dts'` or `'write-tsbuildinfo'` or `'write-references'` | `build === true ? 'write-tsbuildinfo' ? 'readonly'`
|
|
115
|
-
| `diagnosticOptions` | `object` | `{ syntactic: false, semantic: true, declaration: false, global: false }`
|
|
116
|
-
| `profile` | `boolean` | `false`
|
|
117
|
-
| `typescriptPath` | `string` | `require.resolve('typescript')`
|
|
107
|
+
| Name | Type | Default value | Description |
|
|
108
|
+
| ------------------- | ------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
109
|
+
| `memoryLimit` | `number` | `8192` | Memory limit for the checker process in MB. If the process exits with the allocation failed error, try to increase this number. |
|
|
110
|
+
| `configFile` | `string` | `'tsconfig.json'` | Path to the `tsconfig.json` file (path relative to the `compiler.options.context` or absolute path) |
|
|
111
|
+
| `configOverwrite` | `object` | `{ compilerOptions: { skipLibCheck: true, sourceMap: false, inlineSourceMap: false, declarationMap: false } }` | This configuration will overwrite configuration from the `tsconfig.json` file. Supported fields are: `extends`, `compilerOptions`, `include`, `exclude`, `files`, and `references`. |
|
|
112
|
+
| `context` | `string` | `dirname(configuration.configFile)` | The base path for finding files specified in the `tsconfig.json`. Same as the `context` option from the [ts-loader](https://github.com/TypeStrong/ts-loader#context). Useful if you want to keep your `tsconfig.json` in an external package. Keep in mind that **not** having a `tsconfig.json` in your project root can cause different behaviour between `ts-checker-rspack-plugin` and `tsc`. When using editors like `VS Code` it is advised to add a `tsconfig.json` file to the root of the project and extend the config file referenced in option `configFile`. |
|
|
113
|
+
| `build` | `boolean` | `false` | The equivalent of the `--build` flag for the `tsc` command. |
|
|
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
|
+
| `diagnosticOptions` | `object` | `{ syntactic: false, semantic: true, declaration: false, global: false }` | Settings to select which diagnostics do we want to perform. |
|
|
116
|
+
| `profile` | `boolean` | `false` | Measures and prints timings related to the TypeScript performance. |
|
|
117
|
+
| `typescriptPath` | `string` | `require.resolve('typescript/package.json')` for TypeScript 7+, `require.resolve('@typescript/native-preview/package.json')` when `tsgo` falls back to preview, otherwise `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/package.json` from TypeScript 7+ or `@typescript/native-preview/package.json`. |
|
|
118
|
+
| `tsgo` | `boolean` | `true` when TypeScript 7+ is detected, otherwise `false` | Enables experimental TypeScript Go support. The plugin runs the TypeScript Go checker binary in a child process. |
|
|
119
|
+
|
|
120
|
+
### TypeScript Go support
|
|
121
|
+
|
|
122
|
+
`typescript.tsgo` can reduce type-checking time by about 5-10x, especially on large projects, by using the Go implementation of TypeScript. It enables experimental [typescript-go](https://github.com/microsoft/typescript-go) support through TypeScript 7+ or [`@typescript/native-preview`](https://www.npmjs.com/package/@typescript/native-preview).
|
|
123
|
+
|
|
124
|
+
When the configured or default installed `typescript` package is major version 7 or higher, the plugin enables `typescript.tsgo` automatically and runs the TypeScript Go executable from that package. When `typescript.tsgo: true` is set without a custom `typescriptPath` and TypeScript 7+ is not installed, the plugin falls back to `@typescript/native-preview`.
|
|
125
|
+
|
|
126
|
+
In this mode, the plugin runs the TypeScript Go binary in a child process, parses its diagnostics, and reports them through the existing issue formatter when possible. If the output cannot be parsed safely, the raw output is printed and the build fails when it exits with errors.
|
|
127
|
+
|
|
128
|
+
Supported options include `typescript.configFile`, `typescript.context`, `typescript.build`, `typescript.typescriptPath`, `async`, and `logger`. It also supports `tsconfig.json` compiler options used by `tsgo`, including `incremental` and `composite`.
|
|
129
|
+
|
|
130
|
+
Install TypeScript 7.0 RC to enable `tsgo` automatically:
|
|
131
|
+
|
|
132
|
+
```sh
|
|
133
|
+
# with npm
|
|
134
|
+
npm install -D typescript@rc
|
|
135
|
+
|
|
136
|
+
# with yarn
|
|
137
|
+
yarn add -D typescript@rc
|
|
138
|
+
|
|
139
|
+
# with pnpm
|
|
140
|
+
pnpm add -D typescript@rc
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Or install `@typescript/native-preview` and enable `tsgo` explicitly:
|
|
144
|
+
|
|
145
|
+
```sh
|
|
146
|
+
# with npm
|
|
147
|
+
npm install -D @typescript/native-preview
|
|
148
|
+
|
|
149
|
+
# with yarn
|
|
150
|
+
yarn add -D @typescript/native-preview
|
|
151
|
+
|
|
152
|
+
# with pnpm
|
|
153
|
+
pnpm add -D @typescript/native-preview
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
new TsCheckerRspackPlugin({
|
|
158
|
+
typescript: {
|
|
159
|
+
tsgo: true,
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
> The `@typescript/native-preview` usage is deprecated and kept only for compatibility. We recommend installing `typescript@rc` to use `tsgo`.
|
|
165
|
+
|
|
166
|
+
Limitations:
|
|
167
|
+
|
|
168
|
+
- `issue.include`, `issue.exclude`, and `issue.defaultSeverity` only apply to diagnostics whose `tsgo` output can be matched by `file`, `line`, `column`, `code`, and `message`.
|
|
169
|
+
- `typescript.configOverwrite`, `typescript.diagnosticOptions`, and `typescript.profile` are not supported.
|
|
170
|
+
- TypeScript API-based formatting or filesystem output rewrites are not supported.
|
|
171
|
+
- Plugin-controlled declaration or reference emit modes such as `write-dts` and `write-references` are not supported; `tsgo` always runs with `--noEmit`.
|
|
172
|
+
- This integration may change when TypeScript provides a stable JavaScript API for `tsgo`.
|
|
118
173
|
|
|
119
174
|
### Issues options
|
|
120
175
|
|
|
@@ -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,229 @@ var __webpack_exports__ = {};
|
|
|
3717
3717
|
Error.captureStackTrace(this, this.constructor);
|
|
3718
3718
|
}
|
|
3719
3719
|
}
|
|
3720
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
3721
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
3722
|
+
const external_node_url_namespaceObject = require("node:url");
|
|
3723
|
+
const TYPESCRIPT_PACKAGE = "typescript";
|
|
3724
|
+
const TYPESCRIPT_PACKAGE_JSON = `${TYPESCRIPT_PACKAGE}/package.json`;
|
|
3725
|
+
const TYPESCRIPT_PREVIEW_PACKAGE = "@typescript/native-preview";
|
|
3726
|
+
const TYPESCRIPT_PREVIEW_PACKAGE_JSON = `${TYPESCRIPT_PREVIEW_PACKAGE}/package.json`;
|
|
3727
|
+
function resolveTypeScriptGoPackageJsonPath(config) {
|
|
3728
|
+
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 a package.json file when tsgo is enabled.");
|
|
3729
|
+
if (!config.tsgoPackage) throw new Error(`The typescriptPath option must point to "${TYPESCRIPT_PREVIEW_PACKAGE_JSON}" or "${TYPESCRIPT_PACKAGE}@rc".`);
|
|
3730
|
+
return config.typescriptPath;
|
|
3731
|
+
}
|
|
3732
|
+
async function resolveTypeScriptGoNativeExecutablePath(packageJsonPath, packageName) {
|
|
3733
|
+
const getExePathPath = external_node_path_default().resolve(external_node_path_default().dirname(packageJsonPath), './lib/getExePath.js');
|
|
3734
|
+
const getExePathUrl = (0, external_node_url_namespaceObject.pathToFileURL)(getExePathPath).href;
|
|
3735
|
+
const getExePathModule = await import(getExePathUrl);
|
|
3736
|
+
const getExePath = getExePathModule.default || getExePathModule.getExePath;
|
|
3737
|
+
if ('function' != typeof getExePath) throw new Error(`Cannot resolve the typescript-go executable from "${packageName}".`);
|
|
3738
|
+
const executablePath = getExePath();
|
|
3739
|
+
if ('string' != typeof executablePath || !external_node_fs_default().existsSync(executablePath)) throw new Error('Executable not found');
|
|
3740
|
+
return executablePath;
|
|
3741
|
+
}
|
|
3742
|
+
async function resolveTypeScriptGoBinPath(config) {
|
|
3743
|
+
const packageJsonPath = resolveTypeScriptGoPackageJsonPath(config);
|
|
3744
|
+
if ("typescript" === config.tsgoPackage) return resolveTypeScriptGoNativeExecutablePath(packageJsonPath, TYPESCRIPT_PACKAGE);
|
|
3745
|
+
return resolveTypeScriptGoNativeExecutablePath(packageJsonPath, TYPESCRIPT_PREVIEW_PACKAGE);
|
|
3746
|
+
}
|
|
3747
|
+
async function resolveTypeScriptGoExecutable(config) {
|
|
3748
|
+
const binPath = await resolveTypeScriptGoBinPath(config);
|
|
3749
|
+
return {
|
|
3750
|
+
command: binPath,
|
|
3751
|
+
args: []
|
|
3752
|
+
};
|
|
3753
|
+
}
|
|
3754
|
+
function createTypeScriptGoArgs(config) {
|
|
3755
|
+
const args = config.build ? [
|
|
3756
|
+
'--build',
|
|
3757
|
+
config.configFile
|
|
3758
|
+
] : [
|
|
3759
|
+
'--project',
|
|
3760
|
+
config.configFile
|
|
3761
|
+
];
|
|
3762
|
+
args.push('--noEmit', '--pretty');
|
|
3763
|
+
return args;
|
|
3764
|
+
}
|
|
3765
|
+
function logOutput(logger, output) {
|
|
3766
|
+
if (!output.trim()) return;
|
|
3767
|
+
logger.error(output.trimEnd());
|
|
3768
|
+
}
|
|
3769
|
+
function stripAnsi(output) {
|
|
3770
|
+
return output.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, '');
|
|
3771
|
+
}
|
|
3772
|
+
function getTypeScriptGoErrorCount(output) {
|
|
3773
|
+
const plainOutput = stripAnsi(output);
|
|
3774
|
+
const matches = Array.from(plainOutput.matchAll(/\bFound\s+(\d+)\s+errors?\b/g));
|
|
3775
|
+
const lastMatch = matches[matches.length - 1];
|
|
3776
|
+
if (!lastMatch) return;
|
|
3777
|
+
return Number(lastMatch[1]);
|
|
3778
|
+
}
|
|
3779
|
+
function getTypeScriptGoIssueSeverity(severity, defaultSeverity) {
|
|
3780
|
+
return 'auto' === defaultSeverity ? severity : defaultSeverity;
|
|
3781
|
+
}
|
|
3782
|
+
function createTypeScriptGoIssue(message) {
|
|
3783
|
+
return {
|
|
3784
|
+
severity: 'error',
|
|
3785
|
+
code: "TSGO",
|
|
3786
|
+
message
|
|
3787
|
+
};
|
|
3788
|
+
}
|
|
3789
|
+
const diagnosticPattern = /^(.*?):(\d+):(\d+)\s+-\s+(error|warning)\s+TS(\d+):\s+(.+)$/;
|
|
3790
|
+
const globalDiagnosticPattern = /^(error|warning)\s+TS(\d+):\s+(.+)$/;
|
|
3791
|
+
function getTypeScriptGoMarkerLength(output, startIndex) {
|
|
3792
|
+
const lines = output.slice(startIndex).split(/\r?\n/);
|
|
3793
|
+
for (const line of lines){
|
|
3794
|
+
if (diagnosticPattern.test(line) || globalDiagnosticPattern.test(line) || /^Found\s+\d+\s+errors?\b/.test(line)) break;
|
|
3795
|
+
const marker = line.match(/^\s*([~^]+)\s*$/);
|
|
3796
|
+
if (marker) return marker[1].length;
|
|
3797
|
+
}
|
|
3798
|
+
}
|
|
3799
|
+
function parseTypeScriptGoIssues(output, config, defaultSeverity = 'auto') {
|
|
3800
|
+
const issues = [];
|
|
3801
|
+
const plainOutput = stripAnsi(output);
|
|
3802
|
+
const diagnosticPatternWithGlobal = new RegExp(diagnosticPattern, 'gm');
|
|
3803
|
+
const globalDiagnosticPatternWithGlobal = new RegExp(globalDiagnosticPattern, 'gm');
|
|
3804
|
+
for (const match of plainOutput.matchAll(diagnosticPatternWithGlobal)){
|
|
3805
|
+
const [, file, line, column, severity, code, message] = match;
|
|
3806
|
+
const startColumn = Number(column);
|
|
3807
|
+
const markerLength = getTypeScriptGoMarkerLength(plainOutput, (match.index || 0) + match[0].length);
|
|
3808
|
+
const position = {
|
|
3809
|
+
line: Number(line),
|
|
3810
|
+
column: startColumn
|
|
3811
|
+
};
|
|
3812
|
+
issues.push({
|
|
3813
|
+
severity: getTypeScriptGoIssueSeverity(severity, defaultSeverity),
|
|
3814
|
+
code: `TS${code}`,
|
|
3815
|
+
message,
|
|
3816
|
+
file: external_node_path_default().isAbsolute(file) ? file : external_node_path_default().resolve(config.context, file),
|
|
3817
|
+
location: {
|
|
3818
|
+
start: position,
|
|
3819
|
+
end: {
|
|
3820
|
+
line: position.line,
|
|
3821
|
+
column: markerLength ? startColumn + markerLength : startColumn
|
|
3822
|
+
}
|
|
3823
|
+
}
|
|
3824
|
+
});
|
|
3825
|
+
}
|
|
3826
|
+
for (const match of plainOutput.matchAll(globalDiagnosticPatternWithGlobal)){
|
|
3827
|
+
const [, severity, code, message] = match;
|
|
3828
|
+
issues.push({
|
|
3829
|
+
severity: getTypeScriptGoIssueSeverity(severity, defaultSeverity),
|
|
3830
|
+
code: `TS${code}`,
|
|
3831
|
+
message
|
|
3832
|
+
});
|
|
3833
|
+
}
|
|
3834
|
+
return issues;
|
|
3835
|
+
}
|
|
3836
|
+
function createTypeScriptGoExitIssues(output, signal, config, defaultSeverity = 'auto') {
|
|
3837
|
+
const parsedIssues = parseTypeScriptGoIssues(output, config, defaultSeverity);
|
|
3838
|
+
const errorCount = getTypeScriptGoErrorCount(output);
|
|
3839
|
+
if (parsedIssues.length && (void 0 === errorCount || parsedIssues.length >= errorCount)) return parsedIssues;
|
|
3840
|
+
if (void 0 !== errorCount) return Array.from({
|
|
3841
|
+
length: Math.max(errorCount, 1)
|
|
3842
|
+
}, ()=>createTypeScriptGoIssue('tsgo check failed. See the output above for diagnostics.'));
|
|
3843
|
+
if (null !== signal) return [
|
|
3844
|
+
createTypeScriptGoIssue(`tsgo check interrupted by ${signal}. See the output above for diagnostics.`)
|
|
3845
|
+
];
|
|
3846
|
+
return [
|
|
3847
|
+
createTypeScriptGoIssue('tsgo check failed. See the output above for diagnostics.')
|
|
3848
|
+
];
|
|
3849
|
+
}
|
|
3850
|
+
function isTypeScriptGoIssue(issue) {
|
|
3851
|
+
return "TSGO" === issue.code;
|
|
3852
|
+
}
|
|
3853
|
+
function isTypeScriptGoStatsError(error) {
|
|
3854
|
+
const issue = error?.issue;
|
|
3855
|
+
if (issue && isTypeScriptGoIssue(issue)) return true;
|
|
3856
|
+
const message = error?.message;
|
|
3857
|
+
return 'string' == typeof message && message.includes("TSGO:");
|
|
3858
|
+
}
|
|
3859
|
+
async function runTypeScriptGo(config, logger, defaultSeverity = 'auto', signal) {
|
|
3860
|
+
AbortError.throwIfAborted(signal);
|
|
3861
|
+
const executable = await resolveTypeScriptGoExecutable(config);
|
|
3862
|
+
const args = createTypeScriptGoArgs(config);
|
|
3863
|
+
return new Promise((resolve, reject)=>{
|
|
3864
|
+
let settled = false;
|
|
3865
|
+
let output = '';
|
|
3866
|
+
const childProcess = (0, external_node_child_process_namespaceObject.spawn)(executable.command, [
|
|
3867
|
+
...executable.args,
|
|
3868
|
+
...args
|
|
3869
|
+
], {
|
|
3870
|
+
cwd: config.context,
|
|
3871
|
+
stdio: [
|
|
3872
|
+
'inherit',
|
|
3873
|
+
'pipe',
|
|
3874
|
+
'pipe'
|
|
3875
|
+
]
|
|
3876
|
+
});
|
|
3877
|
+
const cleanup = ()=>{
|
|
3878
|
+
signal?.removeEventListener('abort', abort);
|
|
3879
|
+
childProcess.stdout?.removeAllListeners();
|
|
3880
|
+
childProcess.stderr?.removeAllListeners();
|
|
3881
|
+
childProcess.removeAllListeners();
|
|
3882
|
+
};
|
|
3883
|
+
const finish = (callback)=>{
|
|
3884
|
+
if (settled) return;
|
|
3885
|
+
settled = true;
|
|
3886
|
+
cleanup();
|
|
3887
|
+
callback();
|
|
3888
|
+
};
|
|
3889
|
+
const abort = ()=>{
|
|
3890
|
+
childProcess.kill('SIGTERM');
|
|
3891
|
+
finish(()=>reject(new AbortError()));
|
|
3892
|
+
};
|
|
3893
|
+
signal?.addEventListener('abort', abort, {
|
|
3894
|
+
once: true
|
|
3895
|
+
});
|
|
3896
|
+
childProcess.stdout?.on('data', (data)=>{
|
|
3897
|
+
output += data.toString();
|
|
3898
|
+
});
|
|
3899
|
+
childProcess.stderr?.on('data', (data)=>{
|
|
3900
|
+
output += data.toString();
|
|
3901
|
+
});
|
|
3902
|
+
childProcess.on('error', (error)=>{
|
|
3903
|
+
finish(()=>reject(error));
|
|
3904
|
+
});
|
|
3905
|
+
childProcess.on('close', (exitCode, exitSignal)=>{
|
|
3906
|
+
finish(()=>{
|
|
3907
|
+
if (0 === exitCode && null === exitSignal) {
|
|
3908
|
+
logOutput(logger, output);
|
|
3909
|
+
resolve([]);
|
|
3910
|
+
return;
|
|
3911
|
+
}
|
|
3912
|
+
const issues = createTypeScriptGoExitIssues(output, exitSignal, config, defaultSeverity);
|
|
3913
|
+
if (issues.some(isTypeScriptGoIssue)) logOutput(logger, output);
|
|
3914
|
+
resolve(issues);
|
|
3915
|
+
});
|
|
3916
|
+
});
|
|
3917
|
+
});
|
|
3918
|
+
}
|
|
3919
|
+
function getTypeScriptGoDependencies(config) {
|
|
3920
|
+
return {
|
|
3921
|
+
files: [
|
|
3922
|
+
config.configFile
|
|
3923
|
+
],
|
|
3924
|
+
dirs: [
|
|
3925
|
+
config.context
|
|
3926
|
+
],
|
|
3927
|
+
excluded: [
|
|
3928
|
+
external_node_path_default().join(config.context, 'node_modules')
|
|
3929
|
+
],
|
|
3930
|
+
extensions: [
|
|
3931
|
+
'.ts',
|
|
3932
|
+
'.tsx',
|
|
3933
|
+
'.mts',
|
|
3934
|
+
'.cts',
|
|
3935
|
+
'.js',
|
|
3936
|
+
'.jsx',
|
|
3937
|
+
'.mjs',
|
|
3938
|
+
'.cjs',
|
|
3939
|
+
'.json'
|
|
3940
|
+
]
|
|
3941
|
+
};
|
|
3942
|
+
}
|
|
3720
3943
|
function tapAfterCompileToGetIssues(compiler, config, state) {
|
|
3721
3944
|
const hooks = getPluginHooks(compiler);
|
|
3722
3945
|
const { debug } = getInfrastructureLogger(compiler);
|
|
@@ -3731,8 +3954,16 @@ var __webpack_exports__ = {};
|
|
|
3731
3954
|
}
|
|
3732
3955
|
debug('Got issues from getIssuesWorker.', issues?.length);
|
|
3733
3956
|
if (!issues) return;
|
|
3734
|
-
|
|
3735
|
-
|
|
3957
|
+
if (config.typescript.tsgo) {
|
|
3958
|
+
const internalIssues = issues.filter(isTypeScriptGoIssue);
|
|
3959
|
+
let visibleIssues = issues.filter((issue)=>!isTypeScriptGoIssue(issue));
|
|
3960
|
+
visibleIssues = visibleIssues.filter(config.issue.predicate);
|
|
3961
|
+
visibleIssues = hooks.issues.call(visibleIssues, compilation);
|
|
3962
|
+
issues = internalIssues.concat(visibleIssues);
|
|
3963
|
+
} else {
|
|
3964
|
+
issues = issues.filter(config.issue.predicate);
|
|
3965
|
+
issues = hooks.issues.call(issues, compilation);
|
|
3966
|
+
}
|
|
3736
3967
|
issues.forEach((issue)=>{
|
|
3737
3968
|
const error = new IssueRspackError(config.formatter.format(issue), config.formatter.pathType, issue);
|
|
3738
3969
|
if ('warning' === issue.severity) compilation.warnings.push(error);
|
|
@@ -3802,13 +4033,23 @@ var __webpack_exports__ = {};
|
|
|
3802
4033
|
}
|
|
3803
4034
|
if (!issues || state.issuesPromise !== issuesPromise) return;
|
|
3804
4035
|
debug(`Got ${issues?.length || 0} issues from getIssuesWorker.`);
|
|
3805
|
-
|
|
3806
|
-
|
|
4036
|
+
let visibleIssues;
|
|
4037
|
+
if (config.typescript.tsgo) {
|
|
4038
|
+
const internalIssues = issues.filter(isTypeScriptGoIssue);
|
|
4039
|
+
visibleIssues = issues.filter((issue)=>!isTypeScriptGoIssue(issue));
|
|
4040
|
+
visibleIssues = visibleIssues.filter(config.issue.predicate);
|
|
4041
|
+
visibleIssues = hooks.issues.call(visibleIssues, stats.compilation);
|
|
4042
|
+
issues = internalIssues.concat(visibleIssues);
|
|
4043
|
+
} else {
|
|
4044
|
+
visibleIssues = issues.filter(config.issue.predicate);
|
|
4045
|
+
visibleIssues = hooks.issues.call(visibleIssues, stats.compilation);
|
|
4046
|
+
issues = visibleIssues;
|
|
4047
|
+
}
|
|
3807
4048
|
const formatter = createRspackFormatter(config.formatter.format, config.formatter.pathType);
|
|
3808
|
-
if (
|
|
4049
|
+
if (visibleIssues.length) config.logger.error(visibleIssues.map((issue)=>formatter(issue)).join('\n'));
|
|
3809
4050
|
config.logger.log(statsFormatter(issues, stats));
|
|
3810
|
-
if (
|
|
3811
|
-
|
|
4051
|
+
if (visibleIssues.length && state.DevServerDoneTap) {
|
|
4052
|
+
visibleIssues.forEach((issue)=>{
|
|
3812
4053
|
const error = new IssueRspackError(config.formatter.format(issue), config.formatter.pathType, issue);
|
|
3813
4054
|
if ('warning' === issue.severity) stats.compilation.warnings.push(error);
|
|
3814
4055
|
else stats.compilation.errors.push(error);
|
|
@@ -3907,6 +4148,214 @@ var __webpack_exports__ = {};
|
|
|
3907
4148
|
});
|
|
3908
4149
|
});
|
|
3909
4150
|
}
|
|
4151
|
+
function readTsgoPackageJson(packageJsonPath) {
|
|
4152
|
+
return require(packageJsonPath);
|
|
4153
|
+
}
|
|
4154
|
+
function getTsgoPackage(packageJson) {
|
|
4155
|
+
if (packageJson.name === TYPESCRIPT_PACKAGE) {
|
|
4156
|
+
const versionMatch = packageJson.version?.match(/^(\d+)\.(\d+)(?:\.|$|-)/);
|
|
4157
|
+
if (versionMatch && Number(versionMatch[1]) >= 7) return "typescript";
|
|
4158
|
+
}
|
|
4159
|
+
if (packageJson.name === TYPESCRIPT_PREVIEW_PACKAGE) return 'preview';
|
|
4160
|
+
}
|
|
4161
|
+
function resolveTypeScriptGoPackage(packageJsonPath) {
|
|
4162
|
+
if (!external_node_path_default().isAbsolute(packageJsonPath) || 'package.json' !== external_node_path_default().basename(packageJsonPath)) return;
|
|
4163
|
+
try {
|
|
4164
|
+
const tsgoPackage = getTsgoPackage(readTsgoPackageJson(packageJsonPath));
|
|
4165
|
+
return tsgoPackage ? {
|
|
4166
|
+
packageJsonPath,
|
|
4167
|
+
tsgoPackage
|
|
4168
|
+
} : void 0;
|
|
4169
|
+
} catch {
|
|
4170
|
+
return;
|
|
4171
|
+
}
|
|
4172
|
+
}
|
|
4173
|
+
function isDefaultTypeScriptGoPath(typescriptPath) {
|
|
4174
|
+
if (typescriptPath === TYPESCRIPT_PREVIEW_PACKAGE_JSON) return true;
|
|
4175
|
+
try {
|
|
4176
|
+
if (typescriptPath === require.resolve(TYPESCRIPT_PREVIEW_PACKAGE_JSON)) return true;
|
|
4177
|
+
} catch {}
|
|
4178
|
+
if (!external_node_path_default().isAbsolute(typescriptPath) || 'package.json' !== external_node_path_default().basename(typescriptPath)) return false;
|
|
4179
|
+
try {
|
|
4180
|
+
return Boolean(getTsgoPackage(readTsgoPackageJson(typescriptPath)));
|
|
4181
|
+
} catch {
|
|
4182
|
+
return false;
|
|
4183
|
+
}
|
|
4184
|
+
}
|
|
4185
|
+
function createTypeScriptGoSupportError(config, error) {
|
|
4186
|
+
const message = [
|
|
4187
|
+
`When you enable TsCheckerRspackPlugin with \`typescript.tsgo\`, you must install \`${TYPESCRIPT_PACKAGE}@rc\` or \`${TYPESCRIPT_PREVIEW_PACKAGE}\` package.`
|
|
4188
|
+
];
|
|
4189
|
+
if (!isDefaultTypeScriptGoPath(config.typescriptPath)) message.push(`If you set \`typescript.typescriptPath\`, it must be an absolute path to \`${TYPESCRIPT_PACKAGE_JSON}\` from \`${TYPESCRIPT_PACKAGE}@rc\` or \`${TYPESCRIPT_PREVIEW_PACKAGE_JSON}\`.`);
|
|
4190
|
+
if (error instanceof Error && error.message) message.push(`Failed to resolve the tsgo executable: ${error.message}`);
|
|
4191
|
+
message.push(`You can install it with \`npm add ${TYPESCRIPT_PACKAGE}@rc -D\` or \`npm add ${TYPESCRIPT_PREVIEW_PACKAGE} -D\`.`);
|
|
4192
|
+
return new Error(message.join(external_node_os_default().EOL));
|
|
4193
|
+
}
|
|
4194
|
+
function assertTypeScriptGoSupport(config) {
|
|
4195
|
+
try {
|
|
4196
|
+
const tsgoPackageJsonPath = resolveTypeScriptGoPackageJsonPath(config);
|
|
4197
|
+
const getExePathPath = external_node_path_default().resolve(external_node_path_default().dirname(tsgoPackageJsonPath), './lib/getExePath.js');
|
|
4198
|
+
if (!external_node_fs_default().existsSync(getExePathPath)) throw new Error();
|
|
4199
|
+
} catch (error) {
|
|
4200
|
+
throw createTypeScriptGoSupportError(config, error);
|
|
4201
|
+
}
|
|
4202
|
+
}
|
|
4203
|
+
async function assertTypeScriptGoExecutable(config) {
|
|
4204
|
+
try {
|
|
4205
|
+
await resolveTypeScriptGoBinPath(config);
|
|
4206
|
+
} catch (error) {
|
|
4207
|
+
throw createTypeScriptGoSupportError(config, error);
|
|
4208
|
+
}
|
|
4209
|
+
}
|
|
4210
|
+
function assertTypeScriptSupport(config) {
|
|
4211
|
+
if (config.tsgo) assertTypeScriptGoSupport(config);
|
|
4212
|
+
else {
|
|
4213
|
+
if ('package.json' === external_node_path_default().basename(config.typescriptPath)) throw new Error("When you use TsCheckerRspackPlugin without `typescript.tsgo`, `typescript.typescriptPath` should point to a path like `require.resolve('typescript')`.");
|
|
4214
|
+
let typescriptVersion;
|
|
4215
|
+
try {
|
|
4216
|
+
typescriptVersion = require(config.typescriptPath).version;
|
|
4217
|
+
} catch {}
|
|
4218
|
+
if (!typescriptVersion) throw new Error("When you use TsCheckerRspackPlugin with typescript reporter enabled, you must install `typescript` package.");
|
|
4219
|
+
}
|
|
4220
|
+
if (!external_node_fs_default().existsSync(config.configFile)) throw new Error([
|
|
4221
|
+
`Cannot find the "${config.configFile}" file.`,
|
|
4222
|
+
"Please check Rspack and TsCheckerRspackPlugin configuration.",
|
|
4223
|
+
"Possible errors:",
|
|
4224
|
+
' - wrong `context` directory in Rspack configuration (if `configFile` is not set or is a relative path in the fork plugin configuration)',
|
|
4225
|
+
" - wrong `typescript.configFile` path in the plugin configuration (should be a relative or absolute path)"
|
|
4226
|
+
].join(external_node_os_default().EOL));
|
|
4227
|
+
}
|
|
4228
|
+
const hiddenTypeScriptGoErrors = Symbol('hiddenTypeScriptGoErrors');
|
|
4229
|
+
function getStatsFilterHook(hook) {
|
|
4230
|
+
return hook;
|
|
4231
|
+
}
|
|
4232
|
+
function getStatsPrintHook(hook) {
|
|
4233
|
+
return hook;
|
|
4234
|
+
}
|
|
4235
|
+
function tapStartToRunTypeScriptGo(compiler, config, state) {
|
|
4236
|
+
const hooks = getPluginHooks(compiler);
|
|
4237
|
+
const { log, debug } = getInfrastructureLogger(compiler);
|
|
4238
|
+
let assertTypeScriptGoExecutablePromise;
|
|
4239
|
+
const assertTypeScriptGoExecutableOnce = async ()=>{
|
|
4240
|
+
try {
|
|
4241
|
+
if (!assertTypeScriptGoExecutablePromise) assertTypeScriptGoExecutablePromise = assertTypeScriptGoExecutable(config.typescript);
|
|
4242
|
+
await assertTypeScriptGoExecutablePromise;
|
|
4243
|
+
} catch (error) {
|
|
4244
|
+
assertTypeScriptGoExecutablePromise = void 0;
|
|
4245
|
+
throw error;
|
|
4246
|
+
}
|
|
4247
|
+
};
|
|
4248
|
+
compiler.hooks.run.tapPromise('TsCheckerRspackPlugin', async ()=>{
|
|
4249
|
+
if (!state.initialized) {
|
|
4250
|
+
await assertTypeScriptGoExecutableOnce();
|
|
4251
|
+
debug('Initializing tsgo for single run (not async).');
|
|
4252
|
+
state.initialized = true;
|
|
4253
|
+
state.watching = false;
|
|
4254
|
+
tapAfterCompileToGetIssues(compiler, config, state);
|
|
4255
|
+
}
|
|
4256
|
+
});
|
|
4257
|
+
compiler.hooks.watchRun.tapPromise('TsCheckerRspackPlugin', async ()=>{
|
|
4258
|
+
if (!state.initialized) {
|
|
4259
|
+
await assertTypeScriptGoExecutableOnce();
|
|
4260
|
+
state.initialized = true;
|
|
4261
|
+
state.watching = true;
|
|
4262
|
+
if (config.async) {
|
|
4263
|
+
debug('Initializing tsgo for watch run (async).');
|
|
4264
|
+
tapDoneToAsyncGetIssues(compiler, config, state);
|
|
4265
|
+
interceptDoneToGetDevServerTap(compiler, config, state);
|
|
4266
|
+
} else {
|
|
4267
|
+
debug('Initializing tsgo for watch run (not async).');
|
|
4268
|
+
tapAfterCompileToGetIssues(compiler, config, state);
|
|
4269
|
+
}
|
|
4270
|
+
}
|
|
4271
|
+
});
|
|
4272
|
+
compiler.hooks.compilation.tap('TsCheckerRspackPlugin', async (compilation)=>{
|
|
4273
|
+
if (compilation.compiler !== compiler) return;
|
|
4274
|
+
compilation.hooks.statsFactory.tap('TsCheckerRspackPlugin', (stats)=>{
|
|
4275
|
+
const errorsFilter = getStatsFilterHook(stats.hooks.filter.for('compilation.errors'));
|
|
4276
|
+
errorsFilter.tap('TsCheckerRspackPlugin', (error)=>isTypeScriptGoStatsError(error) ? false : void 0);
|
|
4277
|
+
stats.hooks.result.for('compilation').tap('TsCheckerRspackPlugin', (statsCompilation, context)=>{
|
|
4278
|
+
const hiddenErrorsCount = context.cachedGetErrors?.(context.compilation).filter(isTypeScriptGoStatsError).length || 0;
|
|
4279
|
+
if (hiddenErrorsCount) Object.defineProperty(statsCompilation, hiddenTypeScriptGoErrors, {
|
|
4280
|
+
value: hiddenErrorsCount
|
|
4281
|
+
});
|
|
4282
|
+
return statsCompilation;
|
|
4283
|
+
});
|
|
4284
|
+
});
|
|
4285
|
+
compilation.hooks.statsPrinter.tap('TsCheckerRspackPlugin', (stats)=>{
|
|
4286
|
+
const errorsInChildrenPrinter = getStatsPrintHook(stats.hooks.print.for('compilation.errorsInChildren!'));
|
|
4287
|
+
errorsInChildrenPrinter.tap('TsCheckerRspackPlugin', (_, { compilation, red })=>{
|
|
4288
|
+
const hiddenErrorsCount = compilation[hiddenTypeScriptGoErrors] || 0;
|
|
4289
|
+
if (!hiddenErrorsCount || compilation.children || !compilation.errorsCount || !compilation.errors) return;
|
|
4290
|
+
const childErrorsCount = compilation.errorsCount - compilation.errors.length - hiddenErrorsCount;
|
|
4291
|
+
if (childErrorsCount <= 0) return '';
|
|
4292
|
+
const childErrorsLabel = 1 === childErrorsCount ? 'ERROR' : 'ERRORS';
|
|
4293
|
+
const childErrorsMessage = `${childErrorsCount} ${childErrorsLabel} in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details)`;
|
|
4294
|
+
return red(childErrorsMessage);
|
|
4295
|
+
});
|
|
4296
|
+
});
|
|
4297
|
+
const iteration = ++state.iteration;
|
|
4298
|
+
if (state.abortController) {
|
|
4299
|
+
debug(`Aborting tsgo iteration ${iteration - 1}.`);
|
|
4300
|
+
state.abortController.abort();
|
|
4301
|
+
}
|
|
4302
|
+
const abortController = new AbortController();
|
|
4303
|
+
state.abortController = abortController;
|
|
4304
|
+
let filesChange = {};
|
|
4305
|
+
if (state.watching) {
|
|
4306
|
+
filesChange = consumeFilesChange(compiler);
|
|
4307
|
+
log([
|
|
4308
|
+
'Calling tsgo for incremental check.',
|
|
4309
|
+
` Changed files: ${JSON.stringify(filesChange.changedFiles)}`,
|
|
4310
|
+
` Deleted files: ${JSON.stringify(filesChange.deletedFiles)}`
|
|
4311
|
+
].join('\n'));
|
|
4312
|
+
} else log('Calling tsgo for single check.');
|
|
4313
|
+
state.dependenciesPromise = Promise.resolve(getTypeScriptGoDependencies(config.typescript));
|
|
4314
|
+
filesChange = await hooks.start.promise(filesChange, compilation);
|
|
4315
|
+
let aggregatedFilesChange = filesChange;
|
|
4316
|
+
if (state.aggregatedFilesChange) {
|
|
4317
|
+
aggregatedFilesChange = aggregateFilesChanges([
|
|
4318
|
+
aggregatedFilesChange,
|
|
4319
|
+
filesChange
|
|
4320
|
+
]);
|
|
4321
|
+
debug([
|
|
4322
|
+
`Aggregating with previous files change, iteration ${iteration}.`,
|
|
4323
|
+
` Changed files: ${JSON.stringify(aggregatedFilesChange.changedFiles)}`,
|
|
4324
|
+
` Deleted files: ${JSON.stringify(aggregatedFilesChange.deletedFiles)}`
|
|
4325
|
+
].join('\n'));
|
|
4326
|
+
}
|
|
4327
|
+
state.aggregatedFilesChange = aggregatedFilesChange;
|
|
4328
|
+
state.issuesPromise = (state.issuesPromise || Promise.resolve()).catch(()=>void 0).then(()=>{
|
|
4329
|
+
if (abortController.signal.aborted) return;
|
|
4330
|
+
debug(`Submitting tsgo to the pool, iteration ${iteration}.`);
|
|
4331
|
+
return issuesPool.submit(async (signal)=>{
|
|
4332
|
+
try {
|
|
4333
|
+
debug(`Running tsgo, iteration ${iteration}.`);
|
|
4334
|
+
const issues = await runTypeScriptGo(config.typescript, config.logger, config.issue.defaultSeverity, signal);
|
|
4335
|
+
if (state.aggregatedFilesChange === aggregatedFilesChange) state.aggregatedFilesChange = void 0;
|
|
4336
|
+
if (state.abortController === abortController) state.abortController = void 0;
|
|
4337
|
+
return issues;
|
|
4338
|
+
} catch (error) {
|
|
4339
|
+
hooks.error.call(error, compilation);
|
|
4340
|
+
return;
|
|
4341
|
+
} finally{
|
|
4342
|
+
debug(`tsgo finished its job, iteration ${iteration}.`);
|
|
4343
|
+
}
|
|
4344
|
+
}, abortController.signal);
|
|
4345
|
+
});
|
|
4346
|
+
});
|
|
4347
|
+
const abortTypeScriptGo = ()=>{
|
|
4348
|
+
if (state.abortController) {
|
|
4349
|
+
debug('Compiler is going to close - terminating tsgo...');
|
|
4350
|
+
state.abortController.abort();
|
|
4351
|
+
state.abortController = void 0;
|
|
4352
|
+
}
|
|
4353
|
+
};
|
|
4354
|
+
compiler.hooks.watchClose.tap('TsCheckerRspackPlugin', abortTypeScriptGo);
|
|
4355
|
+
compiler.hooks.failed.tap('TsCheckerRspackPlugin', ()=>{
|
|
4356
|
+
if (!state.watching) abortTypeScriptGo();
|
|
4357
|
+
});
|
|
4358
|
+
}
|
|
3910
4359
|
function tapStopToTerminateWorkers(compiler, getIssuesWorker, getDependenciesWorker, state) {
|
|
3911
4360
|
const { debug } = getInfrastructureLogger(compiler);
|
|
3912
4361
|
const terminateWorkers = ()=>{
|
|
@@ -3930,8 +4379,6 @@ var __webpack_exports__ = {};
|
|
|
3930
4379
|
};
|
|
3931
4380
|
}
|
|
3932
4381
|
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
4382
|
function createCodeFrameFormatter(options) {
|
|
3936
4383
|
const basicFormatter = createBasicFormatter();
|
|
3937
4384
|
return function(issue) {
|
|
@@ -3997,11 +4444,58 @@ var __webpack_exports__ = {};
|
|
|
3997
4444
|
defaultSeverity
|
|
3998
4445
|
};
|
|
3999
4446
|
}
|
|
4447
|
+
function resolveInstalledTypeScriptPackageForTsgo() {
|
|
4448
|
+
try {
|
|
4449
|
+
const packageJsonPath = require.resolve(TYPESCRIPT_PACKAGE_JSON);
|
|
4450
|
+
const tsgoPackage = resolveTypeScriptGoPackage(packageJsonPath);
|
|
4451
|
+
if (tsgoPackage?.tsgoPackage === "typescript") return tsgoPackage;
|
|
4452
|
+
} catch {}
|
|
4453
|
+
}
|
|
4454
|
+
function resolveDefaultPreviewPackageJsonPath() {
|
|
4455
|
+
try {
|
|
4456
|
+
return require.resolve(TYPESCRIPT_PREVIEW_PACKAGE_JSON);
|
|
4457
|
+
} catch {
|
|
4458
|
+
return TYPESCRIPT_PREVIEW_PACKAGE_JSON;
|
|
4459
|
+
}
|
|
4460
|
+
}
|
|
4461
|
+
function resolveTypeScriptRuntimeConfig(options) {
|
|
4462
|
+
if (options.typescriptPath) {
|
|
4463
|
+
const tsgoPackage = resolveTypeScriptGoPackage(options.typescriptPath);
|
|
4464
|
+
const tsgo = void 0 === options.tsgo && tsgoPackage?.tsgoPackage === "typescript" ? true : options.tsgo;
|
|
4465
|
+
return {
|
|
4466
|
+
typescriptPath: options.typescriptPath,
|
|
4467
|
+
...void 0 === tsgo ? {} : {
|
|
4468
|
+
tsgo
|
|
4469
|
+
},
|
|
4470
|
+
...true === tsgo && tsgoPackage ? {
|
|
4471
|
+
tsgoPackage: tsgoPackage.tsgoPackage
|
|
4472
|
+
} : {}
|
|
4473
|
+
};
|
|
4474
|
+
}
|
|
4475
|
+
if (false === options.tsgo) return {
|
|
4476
|
+
typescriptPath: require.resolve("typescript"),
|
|
4477
|
+
tsgo: false
|
|
4478
|
+
};
|
|
4479
|
+
const installedTypeScriptTsgoPackage = resolveInstalledTypeScriptPackageForTsgo();
|
|
4480
|
+
if (installedTypeScriptTsgoPackage) return {
|
|
4481
|
+
typescriptPath: installedTypeScriptTsgoPackage.packageJsonPath,
|
|
4482
|
+
tsgo: true,
|
|
4483
|
+
tsgoPackage: "typescript"
|
|
4484
|
+
};
|
|
4485
|
+
if (true === options.tsgo) return {
|
|
4486
|
+
typescriptPath: resolveDefaultPreviewPackageJsonPath(),
|
|
4487
|
+
tsgo: true,
|
|
4488
|
+
tsgoPackage: 'preview'
|
|
4489
|
+
};
|
|
4490
|
+
return {
|
|
4491
|
+
typescriptPath: require.resolve("typescript")
|
|
4492
|
+
};
|
|
4493
|
+
}
|
|
4000
4494
|
function createTypeScriptWorkerConfig(compiler, options) {
|
|
4001
4495
|
let configFile = 'object' == typeof options ? options.configFile || 'tsconfig.json' : 'tsconfig.json';
|
|
4002
4496
|
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
4497
|
const optionsAsObject = 'object' == typeof options ? options : {};
|
|
4004
|
-
const
|
|
4498
|
+
const typescriptRuntimeConfig = resolveTypeScriptRuntimeConfig(optionsAsObject);
|
|
4005
4499
|
return {
|
|
4006
4500
|
enabled: Boolean(options) || void 0 === options,
|
|
4007
4501
|
memoryLimit: 8192,
|
|
@@ -4009,6 +4503,7 @@ var __webpack_exports__ = {};
|
|
|
4009
4503
|
mode: optionsAsObject.build ? 'write-tsbuildinfo' : 'readonly',
|
|
4010
4504
|
profile: false,
|
|
4011
4505
|
...optionsAsObject,
|
|
4506
|
+
...typescriptRuntimeConfig,
|
|
4012
4507
|
configFile: configFile,
|
|
4013
4508
|
configOverwrite: optionsAsObject.configOverwrite || {},
|
|
4014
4509
|
context: optionsAsObject.context || external_node_path_default().dirname(configFile),
|
|
@@ -4018,8 +4513,7 @@ var __webpack_exports__ = {};
|
|
|
4018
4513
|
declaration: false,
|
|
4019
4514
|
global: false,
|
|
4020
4515
|
...optionsAsObject.diagnosticOptions || {}
|
|
4021
|
-
}
|
|
4022
|
-
typescriptPath: typescriptPath
|
|
4516
|
+
}
|
|
4023
4517
|
};
|
|
4024
4518
|
}
|
|
4025
4519
|
function createPluginConfig(compiler, options = {}) {
|
|
@@ -4051,20 +4545,6 @@ var __webpack_exports__ = {};
|
|
|
4051
4545
|
DevServerDoneTap: void 0
|
|
4052
4546
|
};
|
|
4053
4547
|
}
|
|
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
4548
|
function plugin_define_property(obj, key, value) {
|
|
4069
4549
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
4070
4550
|
value: value,
|
|
@@ -4084,6 +4564,13 @@ var __webpack_exports__ = {};
|
|
|
4084
4564
|
const config = createPluginConfig(compiler, this.options);
|
|
4085
4565
|
const state = createPluginState();
|
|
4086
4566
|
assertTypeScriptSupport(config.typescript);
|
|
4567
|
+
if (config.typescript.tsgo) {
|
|
4568
|
+
tapAfterEnvironmentToPatchWatching(compiler, state);
|
|
4569
|
+
tapStartToRunTypeScriptGo(compiler, config, state);
|
|
4570
|
+
tapAfterCompileToAddDependencies(compiler, config, state);
|
|
4571
|
+
tapErrorToLogMessage(compiler, config);
|
|
4572
|
+
return;
|
|
4573
|
+
}
|
|
4087
4574
|
const getIssuesWorker = createRpcWorker(external_node_path_namespaceObject.resolve(__dirname, './getIssuesWorker.js'), config.typescript, config.typescript.memoryLimit);
|
|
4088
4575
|
const getDependenciesWorker = createRpcWorker(external_node_path_namespaceObject.resolve(__dirname, './getDependenciesWorker.js'), config.typescript);
|
|
4089
4576
|
tapAfterEnvironmentToPatchWatching(compiler, state);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const TYPESCRIPT_PACKAGE = "typescript";
|
|
2
|
+
declare const TYPESCRIPT_PACKAGE_JSON = "typescript/package.json";
|
|
3
|
+
declare const TYPESCRIPT_PREVIEW_PACKAGE = "@typescript/native-preview";
|
|
4
|
+
declare const TYPESCRIPT_PREVIEW_PACKAGE_JSON = "@typescript/native-preview/package.json";
|
|
5
|
+
declare const TYPESCRIPT_GO_ISSUE_CODE = "TSGO";
|
|
6
|
+
export { TYPESCRIPT_GO_ISSUE_CODE, TYPESCRIPT_PACKAGE, TYPESCRIPT_PACKAGE_JSON, TYPESCRIPT_PREVIEW_PACKAGE, TYPESCRIPT_PREVIEW_PACKAGE_JSON, };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type TypeScriptGoPackage = 'typescript' | 'preview';
|
|
2
|
+
type TypeScriptGoPackageJson = {
|
|
3
|
+
name?: string;
|
|
4
|
+
version?: string;
|
|
5
|
+
bin?: string | Record<string, string>;
|
|
6
|
+
};
|
|
7
|
+
type ResolvedTypeScriptGoPackage = {
|
|
8
|
+
packageJsonPath: string;
|
|
9
|
+
tsgoPackage: TypeScriptGoPackage;
|
|
10
|
+
};
|
|
11
|
+
declare function readTsgoPackageJson(packageJsonPath: string): TypeScriptGoPackageJson;
|
|
12
|
+
declare function getTsgoPackage(packageJson: TypeScriptGoPackageJson): TypeScriptGoPackage | undefined;
|
|
13
|
+
declare function resolveTypeScriptGoPackage(packageJsonPath: string): ResolvedTypeScriptGoPackage | undefined;
|
|
14
|
+
export { getTsgoPackage, readTsgoPackageJson, resolveTypeScriptGoPackage, };
|
|
15
|
+
export type { ResolvedTypeScriptGoPackage, TypeScriptGoPackage, TypeScriptGoPackageJson, };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Issue, IssueDefaultSeverity } from '../issue';
|
|
2
|
+
import type { Logger } from '../logger';
|
|
3
|
+
import type { TypeScriptWorkerConfig } from './type-script-worker-config';
|
|
4
|
+
type TypeScriptGoExecutable = {
|
|
5
|
+
command: string;
|
|
6
|
+
args: string[];
|
|
7
|
+
};
|
|
8
|
+
declare function resolveTypeScriptGoPackageJsonPath(config: TypeScriptWorkerConfig): string;
|
|
9
|
+
declare function resolveTypeScriptGoBinPath(config: TypeScriptWorkerConfig): Promise<string>;
|
|
10
|
+
declare function resolveTypeScriptGoExecutable(config: TypeScriptWorkerConfig): Promise<TypeScriptGoExecutable>;
|
|
11
|
+
declare function createTypeScriptGoArgs(config: TypeScriptWorkerConfig): string[];
|
|
12
|
+
declare function getTypeScriptGoErrorCount(output: string): number | undefined;
|
|
13
|
+
declare function parseTypeScriptGoIssues(output: string, config: TypeScriptWorkerConfig, defaultSeverity?: IssueDefaultSeverity): Issue[];
|
|
14
|
+
declare function createTypeScriptGoExitIssues(output: string, signal: NodeJS.Signals | null, config: TypeScriptWorkerConfig, defaultSeverity?: IssueDefaultSeverity): Issue[];
|
|
15
|
+
declare function isTypeScriptGoIssue(issue: Issue): boolean;
|
|
16
|
+
declare function isTypeScriptGoStatsError(error: unknown): boolean;
|
|
17
|
+
declare function runTypeScriptGo(config: TypeScriptWorkerConfig, logger: Pick<Logger, 'error'>, defaultSeverity?: IssueDefaultSeverity, signal?: AbortSignal): Promise<Issue[]>;
|
|
18
|
+
declare function getTypeScriptGoDependencies(config: TypeScriptWorkerConfig): {
|
|
19
|
+
files: string[];
|
|
20
|
+
dirs: string[];
|
|
21
|
+
excluded: string[];
|
|
22
|
+
extensions: string[];
|
|
23
|
+
};
|
|
24
|
+
export { createTypeScriptGoArgs, createTypeScriptGoExitIssues, getTypeScriptGoDependencies, getTypeScriptGoErrorCount, isTypeScriptGoIssue, isTypeScriptGoStatsError, parseTypeScriptGoIssues, resolveTypeScriptGoExecutable, 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 };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type * as rspack from '@rspack/core';
|
|
2
2
|
import type { TypeScriptConfigOverwrite } from './type-script-config-overwrite';
|
|
3
3
|
import type { TypeScriptDiagnosticsOptions } from './type-script-diagnostics-options';
|
|
4
|
+
import { type TypeScriptGoPackage } from './type-script-go-package';
|
|
4
5
|
import type { TypeScriptWorkerOptions } from './type-script-worker-options';
|
|
5
6
|
interface TypeScriptWorkerConfig {
|
|
6
7
|
enabled: boolean;
|
|
@@ -13,7 +14,9 @@ interface TypeScriptWorkerConfig {
|
|
|
13
14
|
diagnosticOptions: TypeScriptDiagnosticsOptions;
|
|
14
15
|
profile: boolean;
|
|
15
16
|
typescriptPath: string;
|
|
17
|
+
tsgo?: boolean;
|
|
18
|
+
tsgoPackage?: TypeScriptGoPackage;
|
|
16
19
|
}
|
|
17
20
|
declare function createTypeScriptWorkerConfig(compiler: rspack.Compiler, options: TypeScriptWorkerOptions | undefined): TypeScriptWorkerConfig;
|
|
18
|
-
export { createTypeScriptWorkerConfig };
|
|
21
|
+
export { createTypeScriptWorkerConfig, };
|
|
19
22
|
export type { TypeScriptWorkerConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-checker-rspack-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Runs typescript type checker and linter on separate process.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rspack",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"type": "git",
|
|
16
16
|
"url": "https://github.com/rstackjs/ts-checker-rspack-plugin.git"
|
|
17
17
|
},
|
|
18
|
+
"homepage": "https://github.com/rstackjs/ts-checker-rspack-plugin#readme",
|
|
18
19
|
"license": "MIT",
|
|
19
20
|
"main": "lib/index.js",
|
|
20
21
|
"types": "lib/index.d.ts",
|
|
@@ -22,37 +23,42 @@
|
|
|
22
23
|
"lib"
|
|
23
24
|
],
|
|
24
25
|
"dependencies": {
|
|
25
|
-
"@rspack/lite-tapable": "^1.1.
|
|
26
|
+
"@rspack/lite-tapable": "^1.1.2",
|
|
26
27
|
"chokidar": "^3.6.0",
|
|
27
|
-
"memfs": "^4.57.
|
|
28
|
+
"memfs": "^4.57.7",
|
|
28
29
|
"picocolors": "^1.1.1"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@babel/code-frame": "^7.29.7",
|
|
32
|
-
"@rslib/core": "^0.22.
|
|
33
|
-
"@rslint/core": "^0.
|
|
34
|
-
"@rspack/core": "^2.0.
|
|
35
|
-
"@rstest/core": "^0.10.
|
|
33
|
+
"@rslib/core": "^0.22.1",
|
|
34
|
+
"@rslint/core": "^0.6.1",
|
|
35
|
+
"@rspack/core": "^2.0.8",
|
|
36
|
+
"@rstest/core": "^0.10.4",
|
|
36
37
|
"@types/babel__code-frame": "^7.27.0",
|
|
37
38
|
"@types/is-glob": "^4.0.4",
|
|
38
39
|
"@types/mock-fs": "^4.13.4",
|
|
39
|
-
"@types/node": "^24.
|
|
40
|
+
"@types/node": "^24.13.2",
|
|
41
|
+
"@typescript/native-preview": "7.0.0-dev.20260613.1",
|
|
40
42
|
"cross-env": "^10.1.0",
|
|
41
43
|
"husky": "^9.1.7",
|
|
42
44
|
"is-glob": "^4.0.3",
|
|
43
45
|
"minimatch": "^10.2.5",
|
|
44
46
|
"mock-fs": "^5.5.0",
|
|
45
|
-
"prettier": "^3.8.
|
|
47
|
+
"prettier": "^3.8.4",
|
|
46
48
|
"strip-ansi": "^7.2.0",
|
|
47
49
|
"typescript": "^6.0.3"
|
|
48
50
|
},
|
|
49
51
|
"peerDependencies": {
|
|
50
52
|
"@rspack/core": "^1.0.0 || ^2.0.0",
|
|
53
|
+
"@typescript/native-preview": "^7.0.0-0",
|
|
51
54
|
"typescript": ">=3.8.0"
|
|
52
55
|
},
|
|
53
56
|
"peerDependenciesMeta": {
|
|
54
57
|
"@rspack/core": {
|
|
55
58
|
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"@typescript/native-preview": {
|
|
61
|
+
"optional": true
|
|
56
62
|
}
|
|
57
63
|
},
|
|
58
64
|
"publishConfig": {
|