Skip to content

Commit a69073e

Browse files
committed
fix(@ngtools/webpack): add exclude override to tsconfig
Fix #3973
1 parent e4fc294 commit a69073e

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

packages/@ngtools/webpack/src/plugin.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -122,35 +122,31 @@ export class AotPlugin implements Tapable {
122122
);
123123
}
124124

125+
// Default exclude to **/*.spec.ts files.
126+
if (!options.hasOwnProperty('exclude')) {
127+
options['exclude'] = ['**/*.spec.ts'];
128+
}
129+
130+
// Add custom excludes to default TypeScript excludes.
131+
if (options.hasOwnProperty('exclude')) {
132+
// If the tsconfig doesn't contain any excludes, we must add the default ones before adding
133+
// any extra ones (otherwise we'd include all of these which can cause unexpected errors).
134+
// This is the same logic as present in TypeScript.
135+
if (!tsConfigJson.exclude) {
136+
tsConfigJson['exclude'] = ['node_modules', 'bower_components', 'jspm_packages'];
137+
if (tsConfigJson.compilerOptions && tsConfigJson.compilerOptions.outDir) {
138+
tsConfigJson.exclude.push(tsConfigJson.compilerOptions.outDir);
139+
}
140+
}
141+
142+
// Join our custom excludes with the existing ones.
143+
tsConfigJson.exclude = tsConfigJson.exclude.concat(options.exclude);
144+
}
145+
125146
const tsConfig = ts.parseJsonConfigFileContent(
126147
tsConfigJson, ts.sys, basePath, null, this._tsConfigPath);
127148

128149
let fileNames = tsConfig.fileNames;
129-
if (options.hasOwnProperty('exclude')) {
130-
let exclude: string[] = typeof options.exclude == 'string'
131-
? [options.exclude as string] : (options.exclude as string[]);
132-
133-
exclude.forEach((pattern: string) => {
134-
const basePathPattern = '(' + basePath.replace(/\\/g, '/')
135-
.replace(/[\-\[\]\/{}()+?.\\^$|*]/g, '\\$&') + ')?';
136-
pattern = pattern
137-
// Replace windows path separators with forward slashes.
138-
.replace(/\\/g, '/')
139-
// Escape characters that are used normally in regexes, except stars.
140-
.replace(/[\-\[\]{}()+?.\\^$|]/g, '\\$&')
141-
// Two stars replacement.
142-
.replace(/\*\*/g, '(?:.*)')
143-
// One star replacement.
144-
.replace(/\*/g, '(?:[^/]*)')
145-
// Escape characters from the basePath and make sure it's forward slashes.
146-
.replace(/^/, basePathPattern);
147-
148-
const re = new RegExp('^' + pattern + '$');
149-
fileNames = fileNames.filter(x => !x.replace(/\\/g, '/').match(re));
150-
});
151-
} else {
152-
fileNames = fileNames.filter(fileName => !/\.spec\.ts$/.test(fileName));
153-
}
154150
this._rootFilePath = fileNames;
155151

156152
// Check the genDir. We generate a default gendir that's under basepath; it will generate

0 commit comments

Comments
 (0)