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
e5636a322c.

PR Close #32954
This commit is contained in:
Paul Gschwendtner 2019-10-02 11:44:44 +02:00 committed by atscott
parent 32e315755b
commit 7503e3540d
2 changed files with 7 additions and 3 deletions

View File

@ -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

View File

@ -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']
}));