Skip to content

Commit

Permalink
fix: use "exclude" from tsconfig.json in webpack watch (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-oles committed Jun 19, 2021
1 parent 0e682bb commit 8d8125c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/eslint-reporter/reporter/EsLintReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function createEsLintReporter(configuration: EsLintReporterConfiguration): Repor
return {
files: (await getFiles()).map((file) => normalize(file)),
dirs: getDirs().map((dir) => normalize(dir)),
excluded: [],
extensions: getExtensions(),
};
},
Expand Down
1 change: 1 addition & 0 deletions src/reporter/FilesMatch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
interface FilesMatch {
files: string[];
dirs: string[];
excluded: string[];
extensions: string[];
}

Expand Down
5 changes: 4 additions & 1 deletion src/reporter/reporter-rpc/ReporterRpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ function composeReporterRpcClients(clients: ReporterRpcClient[]): ReporterRpcCli
new Set([...mergedDependencies.files, ...singleDependencies.files])
),
dirs: Array.from(new Set([...mergedDependencies.dirs, ...singleDependencies.dirs])),
excluded: Array.from(
new Set([...mergedDependencies.excluded, ...singleDependencies.excluded])
),
extensions: Array.from(
new Set([...mergedDependencies.extensions, ...singleDependencies.extensions])
),
}),
{ files: [], dirs: [], extensions: [] }
{ files: [], dirs: [], excluded: [], extensions: [] }
)
),
getIssues: () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function createControlledTypeScriptSystem(
let artifacts: FilesMatch = {
files: [],
dirs: [],
excluded: [],
extensions: [],
};
let isInitialRun = true;
Expand Down
27 changes: 18 additions & 9 deletions src/typescript-reporter/reporter/TypeScriptConfigurationParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,40 @@ function parseTypeScriptConfiguration(
function getDependenciesFromTypeScriptConfiguration(
typescript: typeof ts,
parsedConfiguration: ts.ParsedCommandLine,
configFileContext: string,
parseConfigFileHost: ts.ParseConfigFileHost,
processedConfigFiles: string[] = []
): FilesMatch {
const files = new Set<string>(parsedConfiguration.fileNames);
if (typeof parsedConfiguration.options.configFilePath === 'string') {
files.add(parsedConfiguration.options.configFilePath);
const configFilePath = parsedConfiguration.options.configFilePath;
if (typeof configFilePath === 'string') {
files.add(configFilePath);
}
const dirs = new Set(Object.keys(parsedConfiguration.wildcardDirectories || {}));
const excluded = new Set<string>(
(parsedConfiguration.raw?.exclude || []).map((path: string) => resolve(configFileContext, path))
);

for (const projectReference of parsedConfiguration.projectReferences || []) {
const configFile = typescript.resolveProjectReferencePath(projectReference);
if (processedConfigFiles.includes(configFile)) {
const childConfigFilePath = typescript.resolveProjectReferencePath(projectReference);
const childConfigContext = dirname(childConfigFilePath);
if (processedConfigFiles.includes(childConfigFilePath)) {
// handle circular dependencies
continue;
}
const parsedConfiguration = parseTypeScriptConfiguration(
const childParsedConfiguration = parseTypeScriptConfiguration(
typescript,
configFile,
dirname(configFile),
childConfigFilePath,
childConfigContext,
{},
parseConfigFileHost
);
const childDependencies = getDependenciesFromTypeScriptConfiguration(
typescript,
parsedConfiguration,
childParsedConfiguration,
childConfigContext,
parseConfigFileHost,
[...processedConfigFiles, configFile]
[...processedConfigFiles, childConfigFilePath]
);
childDependencies.files.forEach((file) => {
files.add(file);
Expand All @@ -90,6 +97,7 @@ function getDependenciesFromTypeScriptConfiguration(
return {
files: Array.from(files).map((file) => normalize(file)),
dirs: Array.from(dirs).map((dir) => normalize(dir)),
excluded: Array.from(excluded).map((path) => normalize(path)),
extensions: extensions,
};
}
Expand Down Expand Up @@ -198,6 +206,7 @@ function getArtifactsFromTypeScriptConfiguration(
return {
files: Array.from(files).map((file) => normalize(file)),
dirs: Array.from(dirs).map((dir) => normalize(dir)),
excluded: [],
extensions,
};
}
Expand Down
1 change: 1 addition & 0 deletions src/typescript-reporter/reporter/TypeScriptReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ function createTypeScriptReporter(configuration: TypeScriptReporterConfiguration
let dependencies = getDependenciesFromTypeScriptConfiguration(
typescript,
parsedConfiguration,
configuration.context,
parseConfigFileHost
);

Expand Down
11 changes: 9 additions & 2 deletions src/watch/InclusiveNodeWatchFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import minimatch from 'minimatch';
const BUILTIN_IGNORED_DIRS = ['node_modules', '.git', '.yarn', '.pnp'];

function createIsIgnored(
ignored: WatchFileSystemOptions['ignored'] | undefined
ignored: WatchFileSystemOptions['ignored'] | undefined,
excluded: string[]
): (path: string) => boolean {
const ignoredPatterns = ignored ? (Array.isArray(ignored) ? ignored : [ignored]) : [];
const ignoredFunctions = ignoredPatterns.map((pattern) => {
Expand All @@ -25,6 +26,9 @@ function createIsIgnored(
return () => false;
}
});
ignoredFunctions.push((path: string) =>
excluded.some((excludedPath) => path.startsWith(excludedPath))
);
ignoredFunctions.push((path: string) =>
BUILTIN_IGNORED_DIRS.some((ignoredDir) => path.includes(`/${ignoredDir}/`))
);
Expand Down Expand Up @@ -60,7 +64,10 @@ class InclusiveNodeWatchFileSystem implements WatchFileSystem {
callbackUndelayed?: Function
): Watcher {
clearFilesChange(this.compiler);
const isIgnored = createIsIgnored(options?.ignored);
const isIgnored = createIsIgnored(
options?.ignored,
this.pluginState.lastDependencies?.excluded || []
);

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

0 comments on commit 8d8125c

Please sign in to comment.