Skip to content

Commit 8d8125c

Browse files
authored
fix: use "exclude" from tsconfig.json in webpack watch (#624)
1 parent 0e682bb commit 8d8125c

File tree

7 files changed

+35
-12
lines changed

7 files changed

+35
-12
lines changed

src/eslint-reporter/reporter/EsLintReporter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ function createEsLintReporter(configuration: EsLintReporterConfiguration): Repor
8383
return {
8484
files: (await getFiles()).map((file) => normalize(file)),
8585
dirs: getDirs().map((dir) => normalize(dir)),
86+
excluded: [],
8687
extensions: getExtensions(),
8788
};
8889
},

src/reporter/FilesMatch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
interface FilesMatch {
22
files: string[];
33
dirs: string[];
4+
excluded: string[];
45
extensions: string[];
56
}
67

src/reporter/reporter-rpc/ReporterRpcClient.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ function composeReporterRpcClients(clients: ReporterRpcClient[]): ReporterRpcCli
7575
new Set([...mergedDependencies.files, ...singleDependencies.files])
7676
),
7777
dirs: Array.from(new Set([...mergedDependencies.dirs, ...singleDependencies.dirs])),
78+
excluded: Array.from(
79+
new Set([...mergedDependencies.excluded, ...singleDependencies.excluded])
80+
),
7881
extensions: Array.from(
7982
new Set([...mergedDependencies.extensions, ...singleDependencies.extensions])
8083
),
8184
}),
82-
{ files: [], dirs: [], extensions: [] }
85+
{ files: [], dirs: [], excluded: [], extensions: [] }
8386
)
8487
),
8588
getIssues: () =>

src/typescript-reporter/reporter/ControlledTypeScriptSystem.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function createControlledTypeScriptSystem(
4848
let artifacts: FilesMatch = {
4949
files: [],
5050
dirs: [],
51+
excluded: [],
5152
extensions: [],
5253
};
5354
let isInitialRun = true;

src/typescript-reporter/reporter/TypeScriptConfigurationParser.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,40 @@ function parseTypeScriptConfiguration(
4343
function getDependenciesFromTypeScriptConfiguration(
4444
typescript: typeof ts,
4545
parsedConfiguration: ts.ParsedCommandLine,
46+
configFileContext: string,
4647
parseConfigFileHost: ts.ParseConfigFileHost,
4748
processedConfigFiles: string[] = []
4849
): FilesMatch {
4950
const files = new Set<string>(parsedConfiguration.fileNames);
50-
if (typeof parsedConfiguration.options.configFilePath === 'string') {
51-
files.add(parsedConfiguration.options.configFilePath);
51+
const configFilePath = parsedConfiguration.options.configFilePath;
52+
if (typeof configFilePath === 'string') {
53+
files.add(configFilePath);
5254
}
5355
const dirs = new Set(Object.keys(parsedConfiguration.wildcardDirectories || {}));
56+
const excluded = new Set<string>(
57+
(parsedConfiguration.raw?.exclude || []).map((path: string) => resolve(configFileContext, path))
58+
);
5459

5560
for (const projectReference of parsedConfiguration.projectReferences || []) {
56-
const configFile = typescript.resolveProjectReferencePath(projectReference);
57-
if (processedConfigFiles.includes(configFile)) {
61+
const childConfigFilePath = typescript.resolveProjectReferencePath(projectReference);
62+
const childConfigContext = dirname(childConfigFilePath);
63+
if (processedConfigFiles.includes(childConfigFilePath)) {
5864
// handle circular dependencies
5965
continue;
6066
}
61-
const parsedConfiguration = parseTypeScriptConfiguration(
67+
const childParsedConfiguration = parseTypeScriptConfiguration(
6268
typescript,
63-
configFile,
64-
dirname(configFile),
69+
childConfigFilePath,
70+
childConfigContext,
6571
{},
6672
parseConfigFileHost
6773
);
6874
const childDependencies = getDependenciesFromTypeScriptConfiguration(
6975
typescript,
70-
parsedConfiguration,
76+
childParsedConfiguration,
77+
childConfigContext,
7178
parseConfigFileHost,
72-
[...processedConfigFiles, configFile]
79+
[...processedConfigFiles, childConfigFilePath]
7380
);
7481
childDependencies.files.forEach((file) => {
7582
files.add(file);
@@ -90,6 +97,7 @@ function getDependenciesFromTypeScriptConfiguration(
9097
return {
9198
files: Array.from(files).map((file) => normalize(file)),
9299
dirs: Array.from(dirs).map((dir) => normalize(dir)),
100+
excluded: Array.from(excluded).map((path) => normalize(path)),
93101
extensions: extensions,
94102
};
95103
}
@@ -198,6 +206,7 @@ function getArtifactsFromTypeScriptConfiguration(
198206
return {
199207
files: Array.from(files).map((file) => normalize(file)),
200208
dirs: Array.from(dirs).map((dir) => normalize(dir)),
209+
excluded: [],
201210
extensions,
202211
};
203212
}

src/typescript-reporter/reporter/TypeScriptReporter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ function createTypeScriptReporter(configuration: TypeScriptReporterConfiguration
167167
let dependencies = getDependenciesFromTypeScriptConfiguration(
168168
typescript,
169169
parsedConfiguration,
170+
configuration.context,
170171
parseConfigFileHost
171172
);
172173

src/watch/InclusiveNodeWatchFileSystem.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import minimatch from 'minimatch';
99
const BUILTIN_IGNORED_DIRS = ['node_modules', '.git', '.yarn', '.pnp'];
1010

1111
function createIsIgnored(
12-
ignored: WatchFileSystemOptions['ignored'] | undefined
12+
ignored: WatchFileSystemOptions['ignored'] | undefined,
13+
excluded: string[]
1314
): (path: string) => boolean {
1415
const ignoredPatterns = ignored ? (Array.isArray(ignored) ? ignored : [ignored]) : [];
1516
const ignoredFunctions = ignoredPatterns.map((pattern) => {
@@ -25,6 +26,9 @@ function createIsIgnored(
2526
return () => false;
2627
}
2728
});
29+
ignoredFunctions.push((path: string) =>
30+
excluded.some((excludedPath) => path.startsWith(excludedPath))
31+
);
2832
ignoredFunctions.push((path: string) =>
2933
BUILTIN_IGNORED_DIRS.some((ignoredDir) => path.includes(`/${ignoredDir}/`))
3034
);
@@ -60,7 +64,10 @@ class InclusiveNodeWatchFileSystem implements WatchFileSystem {
6064
callbackUndelayed?: Function
6165
): Watcher {
6266
clearFilesChange(this.compiler);
63-
const isIgnored = createIsIgnored(options?.ignored);
67+
const isIgnored = createIsIgnored(
68+
options?.ignored,
69+
this.pluginState.lastDependencies?.excluded || []
70+
);
6471

6572
// use standard watch file system for files and missing
6673
const standardWatcher = this.watchFileSystem.watch(

0 commit comments

Comments
 (0)