ts-checker-rspack-plugin 1.6.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js
CHANGED
|
@@ -3721,6 +3721,7 @@ var __webpack_exports__ = {};
|
|
|
3721
3721
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
3722
3722
|
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
3723
3723
|
const external_node_url_namespaceObject = require("node:url");
|
|
3724
|
+
const external_node_util_namespaceObject = require("node:util");
|
|
3724
3725
|
const TYPESCRIPT_PACKAGE = "typescript";
|
|
3725
3726
|
const TYPESCRIPT_PACKAGE_JSON = `${TYPESCRIPT_PACKAGE}/package.json`;
|
|
3726
3727
|
const TYPESCRIPT_PREVIEW_PACKAGE = "@typescript/native-preview";
|
|
@@ -3752,6 +3753,36 @@ var __webpack_exports__ = {};
|
|
|
3752
3753
|
args: []
|
|
3753
3754
|
};
|
|
3754
3755
|
}
|
|
3756
|
+
async function runTypeScriptGoShowConfig(executable, configFile) {
|
|
3757
|
+
const { stdout } = await (0, external_node_util_namespaceObject.promisify)(external_node_child_process_namespaceObject.execFile)(executable.command, [
|
|
3758
|
+
...executable.args,
|
|
3759
|
+
'--project',
|
|
3760
|
+
configFile,
|
|
3761
|
+
'--showConfig',
|
|
3762
|
+
'--pretty',
|
|
3763
|
+
'false'
|
|
3764
|
+
], {
|
|
3765
|
+
cwd: external_node_path_default().dirname(configFile),
|
|
3766
|
+
encoding: 'utf8',
|
|
3767
|
+
maxBuffer: 67108864
|
|
3768
|
+
});
|
|
3769
|
+
const parsedConfig = JSON.parse(stdout);
|
|
3770
|
+
if (!parsedConfig || 'object' != typeof parsedConfig || Array.isArray(parsedConfig)) throw new TypeError('Invalid tsgo --showConfig output.');
|
|
3771
|
+
return parsedConfig;
|
|
3772
|
+
}
|
|
3773
|
+
function toComparisonPath(file) {
|
|
3774
|
+
const normalizedPath = external_node_path_default().normalize(file);
|
|
3775
|
+
return 'win32' === process.platform ? normalizedPath.toLowerCase() : normalizedPath;
|
|
3776
|
+
}
|
|
3777
|
+
function shouldRefreshTypeScriptGoDependencies(dependencies, { changedFiles = [], deletedFiles = [] }) {
|
|
3778
|
+
if (!dependencies) return true;
|
|
3779
|
+
const dependencyKeys = dependencies.files.map(toComparisonPath);
|
|
3780
|
+
return changedFiles.some((file)=>{
|
|
3781
|
+
const key = toComparisonPath(file);
|
|
3782
|
+
const extension = external_node_path_default().extname(file).toLowerCase();
|
|
3783
|
+
return '.json' === extension || dependencies.extensions.includes(extension) && !dependencyKeys.includes(key);
|
|
3784
|
+
}) || deletedFiles.some((file)=>dependencyKeys.includes(toComparisonPath(file)));
|
|
3785
|
+
}
|
|
3755
3786
|
function createTypeScriptGoArgs(config) {
|
|
3756
3787
|
const args = config.build ? [
|
|
3757
3788
|
'--build',
|
|
@@ -3917,17 +3948,41 @@ var __webpack_exports__ = {};
|
|
|
3917
3948
|
});
|
|
3918
3949
|
});
|
|
3919
3950
|
}
|
|
3920
|
-
function getTypeScriptGoDependencies(config) {
|
|
3951
|
+
async function getTypeScriptGoDependencies(config) {
|
|
3952
|
+
const executable = await resolveTypeScriptGoExecutable(config);
|
|
3953
|
+
const files = new Set();
|
|
3954
|
+
const dirs = new Set();
|
|
3955
|
+
const excluded = new Set();
|
|
3956
|
+
const visitedConfigs = new Set();
|
|
3957
|
+
const collectConfigDependencies = async (configFile, fallbackRoot, collectExcluded)=>{
|
|
3958
|
+
const normalizedConfigFile = external_node_path_default().normalize(configFile);
|
|
3959
|
+
const configKey = toComparisonPath(normalizedConfigFile);
|
|
3960
|
+
if (visitedConfigs.has(configKey)) return;
|
|
3961
|
+
visitedConfigs.add(configKey);
|
|
3962
|
+
const configDir = external_node_path_default().dirname(normalizedConfigFile);
|
|
3963
|
+
const normalizedRoot = external_node_path_default().normalize(fallbackRoot);
|
|
3964
|
+
files.add(normalizedConfigFile);
|
|
3965
|
+
if (!Array.from(dirs).some((dir)=>'' === external_node_path_default().relative(dir, normalizedRoot) || isInsideAnotherPath(dir, normalizedRoot))) dirs.add(normalizedRoot);
|
|
3966
|
+
excluded.add(external_node_path_default().join(normalizedRoot, 'node_modules'));
|
|
3967
|
+
let parsedConfig;
|
|
3968
|
+
try {
|
|
3969
|
+
parsedConfig = await runTypeScriptGoShowConfig(executable, normalizedConfigFile);
|
|
3970
|
+
} catch {
|
|
3971
|
+
return;
|
|
3972
|
+
}
|
|
3973
|
+
for (const file of parsedConfig.files || [])files.add(external_node_path_default().normalize(external_node_path_default().resolve(configDir, file)));
|
|
3974
|
+
if (collectExcluded && !parsedConfig.references?.length) for (const exclude of parsedConfig.exclude || [])excluded.add(external_node_path_default().normalize(external_node_path_default().resolve(configDir, exclude)));
|
|
3975
|
+
for (const reference of parsedConfig.references || [])if (reference.path) {
|
|
3976
|
+
const resolvedReference = external_node_path_default().resolve(configDir, reference.path);
|
|
3977
|
+
const referenceConfig = '.json' === external_node_path_default().extname(resolvedReference).toLowerCase() ? resolvedReference : external_node_path_default().join(resolvedReference, 'tsconfig.json');
|
|
3978
|
+
await collectConfigDependencies(referenceConfig, external_node_path_default().dirname(referenceConfig), false);
|
|
3979
|
+
}
|
|
3980
|
+
};
|
|
3981
|
+
await collectConfigDependencies(config.configFile, config.context, true);
|
|
3921
3982
|
return {
|
|
3922
|
-
files:
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
dirs: [
|
|
3926
|
-
config.context
|
|
3927
|
-
],
|
|
3928
|
-
excluded: [
|
|
3929
|
-
external_node_path_default().join(config.context, 'node_modules')
|
|
3930
|
-
],
|
|
3983
|
+
files: Array.from(files),
|
|
3984
|
+
dirs: Array.from(dirs),
|
|
3985
|
+
excluded: Array.from(excluded),
|
|
3931
3986
|
extensions: [
|
|
3932
3987
|
'.ts',
|
|
3933
3988
|
'.tsx',
|
|
@@ -4243,6 +4298,8 @@ var __webpack_exports__ = {};
|
|
|
4243
4298
|
const hooks = getPluginHooks(compiler);
|
|
4244
4299
|
const { log, debug } = getInfrastructureLogger(compiler);
|
|
4245
4300
|
let assertTypeScriptGoExecutablePromise;
|
|
4301
|
+
let dependenciesPromise;
|
|
4302
|
+
let dependenciesCacheGeneration = 0;
|
|
4246
4303
|
const assertTypeScriptGoExecutableOnce = async ()=>{
|
|
4247
4304
|
try {
|
|
4248
4305
|
if (!assertTypeScriptGoExecutablePromise) assertTypeScriptGoExecutablePromise = assertTypeScriptGoExecutable(config.typescript);
|
|
@@ -4317,8 +4374,24 @@ var __webpack_exports__ = {};
|
|
|
4317
4374
|
` Deleted files: ${JSON.stringify(filesChange.deletedFiles)}`
|
|
4318
4375
|
].join('\n'));
|
|
4319
4376
|
} else log('Calling tsgo for single check.');
|
|
4320
|
-
|
|
4321
|
-
|
|
4377
|
+
const cacheGeneration = ++dependenciesCacheGeneration;
|
|
4378
|
+
const startPromise = hooks.start.promise(filesChange, compilation);
|
|
4379
|
+
state.dependenciesPromise = startPromise.then((nextFilesChange)=>{
|
|
4380
|
+
if (cacheGeneration !== dependenciesCacheGeneration) return;
|
|
4381
|
+
if (state.watching && dependenciesPromise && !shouldRefreshTypeScriptGoDependencies(state.lastDependencies, nextFilesChange)) {
|
|
4382
|
+
debug(`Reusing cached tsgo dependencies, iteration ${iteration}.`);
|
|
4383
|
+
return dependenciesPromise;
|
|
4384
|
+
}
|
|
4385
|
+
const nextDependenciesPromise = getTypeScriptGoDependencies(config.typescript);
|
|
4386
|
+
if (state.watching) {
|
|
4387
|
+
dependenciesPromise = nextDependenciesPromise;
|
|
4388
|
+
nextDependenciesPromise.catch(()=>{
|
|
4389
|
+
if (dependenciesPromise === nextDependenciesPromise) dependenciesPromise = void 0;
|
|
4390
|
+
});
|
|
4391
|
+
}
|
|
4392
|
+
return nextDependenciesPromise;
|
|
4393
|
+
});
|
|
4394
|
+
filesChange = await startPromise;
|
|
4322
4395
|
let aggregatedFilesChange = filesChange;
|
|
4323
4396
|
if (state.aggregatedFilesChange) {
|
|
4324
4397
|
aggregatedFilesChange = aggregateFilesChanges([
|
|
@@ -4358,8 +4431,14 @@ var __webpack_exports__ = {};
|
|
|
4358
4431
|
state.abortController = void 0;
|
|
4359
4432
|
}
|
|
4360
4433
|
};
|
|
4361
|
-
compiler.hooks.watchClose.tap('TsCheckerRspackPlugin',
|
|
4434
|
+
compiler.hooks.watchClose.tap('TsCheckerRspackPlugin', ()=>{
|
|
4435
|
+
dependenciesCacheGeneration++;
|
|
4436
|
+
dependenciesPromise = void 0;
|
|
4437
|
+
abortTypeScriptGo();
|
|
4438
|
+
});
|
|
4362
4439
|
compiler.hooks.failed.tap('TsCheckerRspackPlugin', ()=>{
|
|
4440
|
+
dependenciesCacheGeneration++;
|
|
4441
|
+
dependenciesPromise = void 0;
|
|
4363
4442
|
if (!state.watching) abortTypeScriptGo();
|
|
4364
4443
|
});
|
|
4365
4444
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { FilesChange } from '../files-change';
|
|
2
|
+
import type { FilesMatch } from '../files-match';
|
|
1
3
|
import type { Issue, IssueDefaultSeverity } from '../issue';
|
|
2
4
|
import type { Logger } from '../logger';
|
|
3
5
|
import type { TypeScriptWorkerConfig } from './type-script-worker-config';
|
|
@@ -8,6 +10,7 @@ type TypeScriptGoExecutable = {
|
|
|
8
10
|
declare function resolveTypeScriptGoPackageJsonPath(config: TypeScriptWorkerConfig): string;
|
|
9
11
|
declare function resolveTypeScriptGoBinPath(config: TypeScriptWorkerConfig): Promise<string>;
|
|
10
12
|
declare function resolveTypeScriptGoExecutable(config: TypeScriptWorkerConfig): Promise<TypeScriptGoExecutable>;
|
|
13
|
+
declare function shouldRefreshTypeScriptGoDependencies(dependencies: FilesMatch | undefined, { changedFiles, deletedFiles }: FilesChange): boolean;
|
|
11
14
|
declare function createTypeScriptGoArgs(config: TypeScriptWorkerConfig): string[];
|
|
12
15
|
declare function getTypeScriptGoErrorCount(output: string): number | undefined;
|
|
13
16
|
declare function parseTypeScriptGoIssues(output: string, config: TypeScriptWorkerConfig, defaultSeverity?: IssueDefaultSeverity): Issue[];
|
|
@@ -15,10 +18,5 @@ declare function createTypeScriptGoExitIssues(output: string, signal: NodeJS.Sig
|
|
|
15
18
|
declare function isTypeScriptGoIssue(issue: Issue): boolean;
|
|
16
19
|
declare function isTypeScriptGoStatsError(error: unknown): boolean;
|
|
17
20
|
declare function runTypeScriptGo(config: TypeScriptWorkerConfig, logger: Pick<Logger, 'error'>, defaultSeverity?: IssueDefaultSeverity, signal?: AbortSignal): Promise<Issue[]>;
|
|
18
|
-
declare function getTypeScriptGoDependencies(config: TypeScriptWorkerConfig):
|
|
19
|
-
|
|
20
|
-
dirs: string[];
|
|
21
|
-
excluded: string[];
|
|
22
|
-
extensions: string[];
|
|
23
|
-
};
|
|
24
|
-
export { createTypeScriptGoArgs, createTypeScriptGoExitIssues, getTypeScriptGoDependencies, getTypeScriptGoErrorCount, isTypeScriptGoIssue, isTypeScriptGoStatsError, parseTypeScriptGoIssues, resolveTypeScriptGoExecutable, resolveTypeScriptGoBinPath, resolveTypeScriptGoPackageJsonPath, runTypeScriptGo, };
|
|
21
|
+
declare function getTypeScriptGoDependencies(config: TypeScriptWorkerConfig): Promise<FilesMatch>;
|
|
22
|
+
export { createTypeScriptGoArgs, createTypeScriptGoExitIssues, getTypeScriptGoDependencies, getTypeScriptGoErrorCount, isTypeScriptGoIssue, isTypeScriptGoStatsError, parseTypeScriptGoIssues, resolveTypeScriptGoExecutable, resolveTypeScriptGoBinPath, resolveTypeScriptGoPackageJsonPath, runTypeScriptGo, shouldRefreshTypeScriptGoDependencies, };
|