Skip to content

Commit

Permalink
fix(@ngtools/webpack): add exclude override to tsconfig
Browse files Browse the repository at this point in the history
Fix #3973
  • Loading branch information
filipesilva committed Feb 22, 2017
1 parent 98c7999 commit 1e30159
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions packages/@ngtools/webpack/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,35 +122,31 @@ export class AotPlugin implements Tapable {
);
}

// Default exclude to **/*.spec.ts files.
if (!options.hasOwnProperty('exclude')) {
options['exclude'] = ['**/*.spec.ts'];
}

// Add custom excludes to default TypeScript excludes.
if (options.hasOwnProperty('exclude')) {
// If the tsconfig doesn't contain any excludes, we must add the default ones before adding
// any extra ones (otherwise we'd include all of these which can cause unexpected errors).
// This is the same logic as present in TypeScript.
if (!tsConfigJson.exclude) {
tsConfigJson['exclude'] = ['node_modules', 'bower_components', 'jspm_packages'];
if (tsConfigJson.compilerOptions && tsConfigJson.compilerOptions.outDir) {
tsConfigJson.exclude.push(tsConfigJson.compilerOptions.outDir);
}
}

// Join our custom excludes with the existing ones.
tsConfigJson.exclude = tsConfigJson.exclude.concat(options.exclude);
}

const tsConfig = ts.parseJsonConfigFileContent(
tsConfigJson, ts.sys, basePath, null, this._tsConfigPath);

let fileNames = tsConfig.fileNames;
if (options.hasOwnProperty('exclude')) {
let exclude: string[] = typeof options.exclude == 'string'
? [options.exclude as string] : (options.exclude as string[]);

exclude.forEach((pattern: string) => {
const basePathPattern = '(' + basePath.replace(/\\/g, '/')
.replace(/[\-\[\]\/{}()+?.\\^$|*]/g, '\\$&') + ')?';
pattern = pattern
// Replace windows path separators with forward slashes.
.replace(/\\/g, '/')
// Escape characters that are used normally in regexes, except stars.
.replace(/[\-\[\]{}()+?.\\^$|]/g, '\\$&')
// Two stars replacement.
.replace(/\*\*/g, '(?:.*)')
// One star replacement.
.replace(/\*/g, '(?:[^/]*)')
// Escape characters from the basePath and make sure it's forward slashes.
.replace(/^/, basePathPattern);

const re = new RegExp('^' + pattern + '$');
fileNames = fileNames.filter(x => !x.replace(/\\/g, '/').match(re));
});
} else {
fileNames = fileNames.filter(fileName => !/\.spec\.ts$/.test(fileName));
}
this._rootFilePath = fileNames;

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

0 comments on commit 1e30159

Please sign in to comment.