Skip to content

Commit 9bc9000

Browse files
filipesilvahansl
authored andcommitted
fix(@angular/cli): add polyfills manually in for ng5 unit tests
1 parent 5f979d7 commit 9bc9000

File tree

5 files changed

+21
-34
lines changed

5 files changed

+21
-34
lines changed

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,15 @@ export function getNonAotTestConfig(wco: WebpackConfigOptions) {
162162

163163
let pluginOptions: any = { tsConfigPath, skipCodeGeneration: true };
164164

165-
// The options below only apply to AoTPlugin.
166-
if (!AngularCompilerPlugin.isSupported()) {
165+
if (AngularCompilerPlugin.isSupported()) {
166+
if (appConfig.polyfills) {
167+
// TODO: remove singleFileIncludes for 2.0, this is just to support old projects that did not
168+
// include 'polyfills.ts' in `tsconfig.spec.json'.
169+
const polyfillsPath = path.resolve(projectRoot, appConfig.root, appConfig.polyfills);
170+
pluginOptions.singleFileIncludes = [polyfillsPath];
171+
}
172+
} else {
173+
// The options below only apply to AoTPlugin.
167174
// Force include main and polyfills.
168175
// This is needed for AngularCompilerPlugin compatibility with existing projects,
169176
// since TS compilation there is stricter and tsconfig.spec.ts doesn't include them.

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export interface AngularCompilerPluginOptions {
6060
mainPath?: string;
6161
skipCodeGeneration?: boolean;
6262
hostReplacementPaths?: { [path: string]: string };
63+
// TODO: remove singleFileIncludes for 2.0, this is just to support old projects that did not
64+
// include 'polyfills.ts' in `tsconfig.spec.json'.
65+
singleFileIncludes?: string[];
6366
i18nInFile?: string;
6467
i18nInFormat?: string;
6568
i18nOutFile?: string;
@@ -83,6 +86,7 @@ export class AngularCompilerPlugin implements Tapable {
8386
// TS compilation.
8487
private _compilerOptions: CompilerOptions;
8588
private _rootNames: string[];
89+
private _singleFileIncludes: string[] = [];
8690
private _program: (ts.Program | Program);
8791
private _compilerHost: WebpackCompilerHost & CompilerHost;
8892
private _moduleResolutionCache: ts.ModuleResolutionCache;
@@ -157,17 +161,19 @@ export class AngularCompilerPlugin implements Tapable {
157161
basePath = path.resolve(process.cwd(), options.basePath);
158162
}
159163

160-
// TODO: check if we can get this from readConfiguration
161-
this._basePath = basePath;
164+
if (options.singleFileIncludes !== undefined) {
165+
this._singleFileIncludes.push(...options.singleFileIncludes);
166+
}
162167

163168
// Parse the tsconfig contents.
164169
const config = readConfiguration(this._tsConfigPath);
165170
if (config.errors && config.errors.length) {
166171
throw new Error(formatDiagnostics(config.errors));
167172
}
168173

169-
this._rootNames = config.rootNames;
174+
this._rootNames = config.rootNames.concat(...this._singleFileIncludes);
170175
this._compilerOptions = config.options;
176+
this._basePath = config.options.basePath;
171177

172178
// Overwrite outDir so we can find generated files next to their .ts origin in compilerHost.
173179
this._compilerOptions.outDir = '';
@@ -295,7 +301,8 @@ export class AngularCompilerPlugin implements Tapable {
295301
// Get the root files from the ts config.
296302
// When a new root name (like a lazy route) is added, it won't be available from
297303
// following imports on the existing files, so we need to get the new list of root files.
298-
this._rootNames = readConfiguration(this._tsConfigPath).rootNames;
304+
const config = readConfiguration(this._tsConfigPath);
305+
this._rootNames = config.rootNames.concat(...this._singleFileIncludes);
299306

300307
// Update the forked type checker with all changed compilation files.
301308
// This includes templates, that also need to be reloaded on the type checker.

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

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const MagicString = require('magic-string');
1616
* @param max The maximum number of items to return.
1717
* @return all nodes of kind, or [] if none is found
1818
*/
19+
// TODO: replace this with collectDeepNodes and add limits to collectDeepNodes
1920
export function findAstNodes<T extends ts.Node>(
2021
node: ts.Node | null,
2122
sourceFile: ts.SourceFile,

tests/e2e/setup/500-create-project.ts

-14
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,6 @@ export default function() {
5252
.then(() => updateTsConfig(json => {
5353
json['compilerOptions']['sourceRoot'] = '/';
5454
}))
55-
.then(() => {
56-
if (argv.nightly) {
57-
// *************************************************************************************
58-
// REMOVE THIS WITH UPDATED NG5 SCHEMATICS
59-
// In ng5 we have to tell users users to update their tsconfig.json.
60-
// `src/tsconfig.spec.json` needs to be updated with "polyfills.ts" on `include`.
61-
// *************************************************************************************
62-
return updateJsonFile('src/tsconfig.spec.json', json => {
63-
json['include'] = json['include'].concat('polyfills.ts');
64-
})
65-
// Ignore error if file doesn't exist.
66-
.catch(() => { return; });
67-
}
68-
})
6955
.then(() => git('config', 'user.email', '[email protected]'))
7056
.then(() => git('config', 'user.name', 'Angular CLI E2e'))
7157
.then(() => git('config', 'commit.gpgSign', 'false'))

tests/e2e/utils/project.ts

-14
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,6 @@ export function createProject(name: string, ...args: string[]) {
4343
.then(() => useCIDefaults())
4444
.then(() => argv['ng2'] ? useNg2() : Promise.resolve())
4545
.then(() => argv.nightly || argv['ng-sha'] ? useSha() : Promise.resolve())
46-
.then(() => {
47-
if (argv.nightly) {
48-
// *************************************************************************************
49-
// REMOVE THIS WITH UPDATED NG5 SCHEMATICS
50-
// In ng5 we have to tell users users to update their tsconfig.json.
51-
// `src/tsconfig.spec.json` needs to be updated with "polyfills.ts" on `include`.
52-
// *************************************************************************************
53-
return updateJsonFile('src/tsconfig.spec.json', json => {
54-
json['include'] = json['include'].concat('polyfills.ts');
55-
})
56-
// Ignore error if file doesn't exist.
57-
.catch(() => { return; });
58-
}
59-
})
6046
.then(() => console.log(`Project ${name} created... Installing npm.`))
6147
.then(() => silentNpm('install'));
6248
}

0 commit comments

Comments
 (0)