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 {resolve} from 'path';
import * as ts from 'typescript'; import * as ts from 'typescript';
import {hasPropertyNameText} from '../../../../utils/typescript/property_name';
import {ClassMetadataMap} from '../../angular/ng_query_visitor'; import {ClassMetadataMap} from '../../angular/ng_query_visitor';
import {NgQueryDefinition, QueryTiming, QueryType} from '../../angular/query-definition'; import {NgQueryDefinition, QueryTiming, QueryType} from '../../angular/query-definition';
import {TimingResult, TimingStrategy} from '../timing-strategy'; import {TimingResult, TimingStrategy} from '../timing-strategy';
@ -34,6 +33,13 @@ export class QueryTemplateStrategy implements TimingStrategy {
*/ */
setup() { setup() {
const {rootNames, options} = readConfiguration(this.projectPath); 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}); const aotProgram = createProgram({rootNames, options, host: this.host});
// The "AngularCompilerProgram" does not expose the "AotCompiler" instance, nor does it // 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, experimentalDecorators: true,
lib: ['es2015'], lib: ['es2015'],
}, },
angularCompilerOptions: {enableIvy: false}
})); }));
writeFile('/angular.json', JSON.stringify({ writeFile('/angular.json', JSON.stringify({
projects: {t: {architect: {build: {options: {tsConfig: './tsconfig.json'}}}}} projects: {t: {architect: {build: {options: {tsConfig: './tsconfig.json'}}}}}
@ -682,7 +681,6 @@ describe('static-queries migration with template strategy', () => {
angularCompilerOptions: { angularCompilerOptions: {
flatModuleId: 'flat-module', flatModuleId: 'flat-module',
flatModuleOutFile: 'flat-module-bundle.js', flatModuleOutFile: 'flat-module-bundle.js',
enableIvy: false,
}, },
files: ['index.ts'] files: ['index.ts']
})); }));