Skip to content

Commit a5728d1

Browse files
filipesilvaBrocco
authored andcommitted
fix(@angular/cli): support existing tsconfig.spec.json on Angular 5
1 parent 1ec8790 commit a5728d1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/@angular/cli/models/webpack-configs/typescript.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any) {
8686
hostReplacementPaths,
8787
sourceMap: buildOptions.sourcemaps,
8888
// If we don't explicitely list excludes, it will default to `['**/*.spec.ts']`.
89-
exclude: []
89+
exclude: [],
90+
include: options.include,
9091
}, options);
9192
return new AngularCompilerPlugin(pluginOptions);
9293
} else {
@@ -149,7 +150,12 @@ export function getNonAotTestConfig(wco: WebpackConfigOptions) {
149150
const tsConfigPath = path.resolve(projectRoot, appConfig.root, appConfig.testTsconfig);
150151
const appTsConfigPath = path.resolve(projectRoot, appConfig.root, appConfig.tsconfig);
151152

152-
let pluginOptions: any = { tsConfigPath, skipCodeGeneration: true };
153+
// Force include main and polyfills.
154+
// This is needed for AngularCompilerPlugin compatibility with existing projects,
155+
// since TS compilation there is stricter and tsconfig.spec.ts doesn't include them.
156+
const include = [appConfig.main, appConfig.polyfills];
157+
158+
let pluginOptions: any = { tsConfigPath, skipCodeGeneration: true, include };
153159

154160
// Fallback to correct module format on projects using a shared tsconfig.
155161
if (tsConfigPath === appTsConfigPath) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ export class AngularCompilerPlugin implements Tapable {
193193
tsConfigJson.exclude = tsConfigJson.exclude.concat(options.exclude);
194194
}
195195

196+
// Add extra includes.
197+
if (options.hasOwnProperty('include') && Array.isArray(options.include)) {
198+
tsConfigJson.include = tsConfigJson.include || [];
199+
tsConfigJson.include.push(...options.include);
200+
}
201+
196202
// Parse the tsconfig contents.
197203
const tsConfig = ts.parseJsonConfigFileContent(
198204
tsConfigJson, ts.sys, basePath, undefined, this._tsConfigPath);

0 commit comments

Comments
 (0)