refactor(core): undecorated-classes-with-di migration should never use ngtsc (#32318)

ec4381dd40 enabled Ivy by default. This is
problematic as migrations like `undecorated-classes-with-di` depend on the
`AngularCompilerProgram` (NGC) in order to perform the migration from
version 8 to version 9. 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.

PR Close #32318
This commit is contained in:
Paul Gschwendtner 2019-08-26 16:11:37 +02:00 committed by Miško Hevery
parent b094936d72
commit e5636a322c
2 changed files with 8 additions and 7 deletions

View File

@ -12,12 +12,14 @@ import * as ts from 'typescript';
/** Creates an NGC program that can be used to read and parse metadata for files. */
export function createNgcProgram(
createHost: (options: ts.CompilerOptions) => ts.CompilerHost, tsconfigPath: string | null,
parseConfig: () => {
rootNames: readonly string[],
options: ts.CompilerOptions
} = () => readConfiguration(tsconfigPath !)) {
const {rootNames, options} = parseConfig();
createHost: (options: ts.CompilerOptions) => ts.CompilerHost, tsconfigPath: string) {
const {rootNames, options} = readConfiguration(tsconfigPath);
// 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 host = createHost(options);
const ngcProgram = createProgram({rootNames, options, host});
const program = ngcProgram.getTsProgram();

View File

@ -32,7 +32,6 @@ describe('Undecorated classes with DI migration', () => {
compilerOptions: {
lib: ['es2015'],
},
angularCompilerOptions: {enableIvy: false}
}));
writeFile('/angular.json', JSON.stringify({
projects: {t: {architect: {build: {options: {tsConfig: './tsconfig.json'}}}}}