Skip to content

Commit

Permalink
fix(@angular/cli): add polyfills manually in for ng5 unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and hansl committed Oct 30, 2017
1 parent 5f979d7 commit 9bc9000
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 34 deletions.
11 changes: 9 additions & 2 deletions packages/@angular/cli/models/webpack-configs/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,15 @@ export function getNonAotTestConfig(wco: WebpackConfigOptions) {

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

// The options below only apply to AoTPlugin.
if (!AngularCompilerPlugin.isSupported()) {
if (AngularCompilerPlugin.isSupported()) {
if (appConfig.polyfills) {
// TODO: remove singleFileIncludes for 2.0, this is just to support old projects that did not
// include 'polyfills.ts' in `tsconfig.spec.json'.
const polyfillsPath = path.resolve(projectRoot, appConfig.root, appConfig.polyfills);
pluginOptions.singleFileIncludes = [polyfillsPath];
}
} else {
// The options below only apply to AoTPlugin.
// Force include main and polyfills.
// This is needed for AngularCompilerPlugin compatibility with existing projects,
// since TS compilation there is stricter and tsconfig.spec.ts doesn't include them.
Expand Down
15 changes: 11 additions & 4 deletions packages/@ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export interface AngularCompilerPluginOptions {
mainPath?: string;
skipCodeGeneration?: boolean;
hostReplacementPaths?: { [path: string]: string };
// TODO: remove singleFileIncludes for 2.0, this is just to support old projects that did not
// include 'polyfills.ts' in `tsconfig.spec.json'.
singleFileIncludes?: string[];
i18nInFile?: string;
i18nInFormat?: string;
i18nOutFile?: string;
Expand All @@ -83,6 +86,7 @@ export class AngularCompilerPlugin implements Tapable {
// TS compilation.
private _compilerOptions: CompilerOptions;
private _rootNames: string[];
private _singleFileIncludes: string[] = [];
private _program: (ts.Program | Program);
private _compilerHost: WebpackCompilerHost & CompilerHost;
private _moduleResolutionCache: ts.ModuleResolutionCache;
Expand Down Expand Up @@ -157,17 +161,19 @@ export class AngularCompilerPlugin implements Tapable {
basePath = path.resolve(process.cwd(), options.basePath);
}

// TODO: check if we can get this from readConfiguration
this._basePath = basePath;
if (options.singleFileIncludes !== undefined) {
this._singleFileIncludes.push(...options.singleFileIncludes);
}

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

this._rootNames = config.rootNames;
this._rootNames = config.rootNames.concat(...this._singleFileIncludes);
this._compilerOptions = config.options;
this._basePath = config.options.basePath;

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

// Update the forked type checker with all changed compilation files.
// This includes templates, that also need to be reloaded on the type checker.
Expand Down
1 change: 1 addition & 0 deletions packages/@ngtools/webpack/src/refactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const MagicString = require('magic-string');
* @param max The maximum number of items to return.
* @return all nodes of kind, or [] if none is found
*/
// TODO: replace this with collectDeepNodes and add limits to collectDeepNodes
export function findAstNodes<T extends ts.Node>(
node: ts.Node | null,
sourceFile: ts.SourceFile,
Expand Down
14 changes: 0 additions & 14 deletions tests/e2e/setup/500-create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,6 @@ export default function() {
.then(() => updateTsConfig(json => {
json['compilerOptions']['sourceRoot'] = '/';
}))
.then(() => {
if (argv.nightly) {
// *************************************************************************************
// REMOVE THIS WITH UPDATED NG5 SCHEMATICS
// In ng5 we have to tell users users to update their tsconfig.json.
// `src/tsconfig.spec.json` needs to be updated with "polyfills.ts" on `include`.
// *************************************************************************************
return updateJsonFile('src/tsconfig.spec.json', json => {
json['include'] = json['include'].concat('polyfills.ts');
})
// Ignore error if file doesn't exist.
.catch(() => { return; });
}
})
.then(() => git('config', 'user.email', 'angular-core+e2e@google.com'))
.then(() => git('config', 'user.name', 'Angular CLI E2e'))
.then(() => git('config', 'commit.gpgSign', 'false'))
Expand Down
14 changes: 0 additions & 14 deletions tests/e2e/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,6 @@ export function createProject(name: string, ...args: string[]) {
.then(() => useCIDefaults())
.then(() => argv['ng2'] ? useNg2() : Promise.resolve())
.then(() => argv.nightly || argv['ng-sha'] ? useSha() : Promise.resolve())
.then(() => {
if (argv.nightly) {
// *************************************************************************************
// REMOVE THIS WITH UPDATED NG5 SCHEMATICS
// In ng5 we have to tell users users to update their tsconfig.json.
// `src/tsconfig.spec.json` needs to be updated with "polyfills.ts" on `include`.
// *************************************************************************************
return updateJsonFile('src/tsconfig.spec.json', json => {
json['include'] = json['include'].concat('polyfills.ts');
})
// Ignore error if file doesn't exist.
.catch(() => { return; });
}
})
.then(() => console.log(`Project ${name} created... Installing npm.`))
.then(() => silentNpm('install'));
}
Expand Down

0 comments on commit 9bc9000

Please sign in to comment.