From 7503e3540dce998da6cb4695938045b2d7190b94 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Wed, 2 Oct 2019 11:44:44 +0200 Subject: [PATCH] refactor(core): static-queries migration should never use ngtsc (#32954) ec4381d enabled Ivy by default. This is problematic as migrations like `static-queries` depend on the `AngularCompilerProgram` (NGC) in order to perform the migration from version 7 to version 8. In order to ensure that the migration always runs with NGC (and doesn't get the `NgtscProgram`), we need to explicitly disable ivy when creating the `@angular/compiler-cli` program for the migration. This code is still relevant even though the update from version 7 to version 8 landed. Developers can run `ng update` from version 7 and immediately get to version 9 where Ivy is enabled by default (and in that case we need to ensure that ngtsc is not accidentally used). Similar to https://github.com/angular/angular/commit/e5636a322ccaa87faac9b2126c45f97cf76bc114. PR Close #32954 --- .../strategies/template_strategy/template_strategy.ts | 8 +++++++- .../test/static_queries_migration_template_spec.ts | 2 -- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/core/schematics/migrations/static-queries/strategies/template_strategy/template_strategy.ts b/packages/core/schematics/migrations/static-queries/strategies/template_strategy/template_strategy.ts index 4028d01866..ba354de43a 100644 --- a/packages/core/schematics/migrations/static-queries/strategies/template_strategy/template_strategy.ts +++ b/packages/core/schematics/migrations/static-queries/strategies/template_strategy/template_strategy.ts @@ -11,7 +11,6 @@ import {Diagnostic, createProgram, readConfiguration} from '@angular/compiler-cl import {resolve} from 'path'; import * as ts from 'typescript'; -import {hasPropertyNameText} from '../../../../utils/typescript/property_name'; import {ClassMetadataMap} from '../../angular/ng_query_visitor'; import {NgQueryDefinition, QueryTiming, QueryType} from '../../angular/query-definition'; import {TimingResult, TimingStrategy} from '../timing-strategy'; @@ -34,6 +33,13 @@ export class QueryTemplateStrategy implements TimingStrategy { */ setup() { const {rootNames, options} = readConfiguration(this.projectPath); + + // https://github.com/angular/angular/commit/ec4381dd401f03bded652665b047b6b90f2b425f made Ivy + // the default. This breaks the assumption that "createProgram" from compiler-cli returns the + // NGC program. In order to ensure that the migration runs properly, we set "enableIvy" to + // false. + options.enableIvy = false; + const aotProgram = createProgram({rootNames, options, host: this.host}); // The "AngularCompilerProgram" does not expose the "AotCompiler" instance, nor does it diff --git a/packages/core/schematics/test/static_queries_migration_template_spec.ts b/packages/core/schematics/test/static_queries_migration_template_spec.ts index 638b15186a..cce1b34bee 100644 --- a/packages/core/schematics/test/static_queries_migration_template_spec.ts +++ b/packages/core/schematics/test/static_queries_migration_template_spec.ts @@ -31,7 +31,6 @@ describe('static-queries migration with template strategy', () => { experimentalDecorators: true, lib: ['es2015'], }, - angularCompilerOptions: {enableIvy: false} })); writeFile('/angular.json', JSON.stringify({ projects: {t: {architect: {build: {options: {tsConfig: './tsconfig.json'}}}}} @@ -682,7 +681,6 @@ describe('static-queries migration with template strategy', () => { angularCompilerOptions: { flatModuleId: 'flat-module', flatModuleOutFile: 'flat-module-bundle.js', - enableIvy: false, }, files: ['index.ts'] }));