feat: make the Ivy compiler the default for ngc (#32219)

This commit switches the default value of the enableIvy flag to true.
Applications that run ngc will now by default receive an Ivy build!

This does not affect the way Bazel builds in the Angular repo work, since
those are still switched based on the value of the --define=compile flag.
Additionally, projects using @angular/bazel still use View Engine builds
by default.

Since most of the Angular repo tests are still written against View Engine
(particularly because we still publish VE packages to NPM), this switch
also requires lots of `enableIvy: false` flags in tsconfigs throughout the
repo.

Congrats to the team for reaching this milestone!

PR Close #32219
This commit is contained in:
Alex Rickabaugh 2019-08-20 10:52:31 -07:00 committed by Andrew Kushnir
parent 2b64031ddc
commit ec4381dd40
43 changed files with 146 additions and 48 deletions

View File

@ -6,7 +6,10 @@
"sourceMap": true, "sourceMap": true,
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"lib": [ "es2015", "dom" ], "lib": [
"es2015",
"dom"
],
"noImplicitAny": true, "noImplicitAny": true,
"skipLibCheck": true, "skipLibCheck": true,
"suppressImplicitAnyIndexErrors": true "suppressImplicitAnyIndexErrors": true
@ -16,5 +19,8 @@
"node_modules/*", "node_modules/*",
"**/*-aot.ts", "**/*-aot.ts",
"aot/**/*" "aot/**/*"
] ],
"angularCompilerOptions": {
"enableIvy": false
}
} }

View File

@ -19,6 +19,7 @@
], ],
"angularCompilerOptions": { "angularCompilerOptions": {
"skipMetadataEmit" : true "skipMetadataEmit" : true,
"enableIvy": false,
} }
} }

View File

@ -6,7 +6,10 @@
"sourceMap": true, "sourceMap": true,
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"lib": [ "es2015", "dom" ], "lib": [
"es2015",
"dom"
],
"noImplicitAny": true, "noImplicitAny": true,
"skipLibCheck": true, "skipLibCheck": true,
"suppressImplicitAnyIndexErrors": true "suppressImplicitAnyIndexErrors": true
@ -15,5 +18,8 @@
"exclude": [ "exclude": [
"node_modules/*", "node_modules/*",
"**/*-aot.ts" "**/*-aot.ts"
] ],
"angularCompilerOptions": {
"enableIvy": false
}
} }

View File

@ -6,7 +6,10 @@
"sourceMap": true, "sourceMap": true,
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"lib": [ "es2015", "dom" ], "lib": [
"es2015",
"dom"
],
"noImplicitAny": true, "noImplicitAny": true,
"skipLibCheck": true, "skipLibCheck": true,
"suppressImplicitAnyIndexErrors": true "suppressImplicitAnyIndexErrors": true
@ -15,5 +18,8 @@
"exclude": [ "exclude": [
"node_modules/*", "node_modules/*",
"**/*-aot.ts" "**/*-aot.ts"
] ],
"angularCompilerOptions": {
"enableIvy": false
}
} }

View File

@ -13,5 +13,8 @@
"node_modules/@types" "node_modules/@types"
] ]
}, },
"compileOnSave": true "compileOnSave": true,
"angularCompilerOptions": {
"enableIvy": false
}
} }

View File

@ -18,5 +18,8 @@
"es2018", "es2018",
"dom" "dom"
] ]
} },
"angularCompilerOptions": {
"enableIvy": false,
},
} }

View File

@ -32,5 +32,8 @@
"out-tsc", "out-tsc",
"scripts", "scripts",
"tools" "tools"
] ],
"angularCompilerOptions": {
"enableIvy": false,
},
} }

View File

@ -0,0 +1,17 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
const fs = require('fs');
const configPath = 'demo/tsconfig.json';
const config = {
...JSON.parse(fs.readFileSync(configPath, 'utf8')),
"angularCompilerOptions": {
"enableIvy": false,
},
};
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));

View File

@ -18,6 +18,7 @@ function installLocalPackages() {
yarn add "${local_packages[@]}" yarn add "${local_packages[@]}"
} }
function testBazel() { function testBazel() {
# Set up # Set up
bazel version bazel version
@ -25,6 +26,7 @@ function testBazel() {
rm -rf demo rm -rf demo
# Create project # Create project
ng new demo --collection=@angular/bazel --routing --skip-git --skip-install --style=scss ng new demo --collection=@angular/bazel --routing --skip-git --skip-install --style=scss
node ./disable-ivy.js
cd demo cd demo
installLocalPackages installLocalPackages
ng generate component widget --style=css ng generate component widget --style=css

View File

@ -13,7 +13,8 @@
"moduleResolution": "node" "moduleResolution": "node"
}, },
"angularCompilerOptions": { "angularCompilerOptions": {
"enableSummariesForJit": true "enableSummariesForJit": true,
"enableIvy": false
}, },
"include": [ "include": [
"node_modules/@angular/**/*" "node_modules/@angular/**/*"

View File

@ -16,5 +16,8 @@
"es2017", "es2017",
"dom" "dom"
] ]
} },
"angularCompilerOptions": {
"enableIvy": false,
},
} }

View File

@ -21,6 +21,9 @@
"types": [ "types": [
] ]
}, },
"angularCompilerOptions": {
"enableIvy": false,
},
"files": [ "files": [
"src/main.ts", "src/main.ts",
"src/lazy.module.ts" "src/lazy.module.ts"

View File

@ -2,7 +2,8 @@
"angularCompilerOptions": { "angularCompilerOptions": {
"annotationsAs": "static fields", "annotationsAs": "static fields",
"annotateForClosureCompiler": true, "annotateForClosureCompiler": true,
"alwaysCompileGeneratedCode": true "alwaysCompileGeneratedCode": true,
"enableIvy": false,
}, },
"compilerOptions": { "compilerOptions": {

View File

@ -9,5 +9,8 @@
"lib": [ "es2015", "dom" ], "lib": [ "es2015", "dom" ],
"noImplicitAny": true, "noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true "suppressImplicitAnyIndexErrors": true
} },
"angularCompilerOptions": {
"enableIvy": false,
},
} }

View File

@ -2,7 +2,8 @@
"angularCompilerOptions": { "angularCompilerOptions": {
"annotationsAs": "static fields", "annotationsAs": "static fields",
"annotateForClosureCompiler": true, "annotateForClosureCompiler": true,
"alwaysCompileGeneratedCode": true "alwaysCompileGeneratedCode": true,
"enableIvy": false,
}, },
"compilerOptions": { "compilerOptions": {

View File

@ -10,6 +10,9 @@
"types": ["node"], "types": ["node"],
"rootDir": "." "rootDir": "."
}, },
"angularCompilerOptions": {
"enableIvy": false,
},
"files": [ "files": [
"src/app.ts", "src/app.ts",
"src/main.ts" "src/main.ts"

View File

@ -17,6 +17,7 @@
"angularCompilerOptions": { "angularCompilerOptions": {
"skipTemplateCodegen": true, "skipTemplateCodegen": true,
"flatModuleOutFile": "index.js", "flatModuleOutFile": "index.js",
"flatModuleId": "lib1_built" "flatModuleId": "lib1_built",
"enableIvy": false,
} }
} }

View File

@ -17,6 +17,7 @@
"angularCompilerOptions": { "angularCompilerOptions": {
"skipTemplateCodegen": true, "skipTemplateCodegen": true,
"flatModuleId": "lib2_built", "flatModuleId": "lib2_built",
"flatModuleOutFile": "index.js" "flatModuleOutFile": "index.js",
"enableIvy": false,
} }
} }

View File

@ -2,7 +2,8 @@
"angularCompilerOptions": { "angularCompilerOptions": {
"annotationsAs": "static fields", "annotationsAs": "static fields",
"annotateForClosureCompiler": true, "annotateForClosureCompiler": true,
"alwaysCompileGeneratedCode": true "alwaysCompileGeneratedCode": true,
"enableIvy": false,
}, },
"compilerOptions": { "compilerOptions": {

View File

@ -1,7 +1,8 @@
{ {
"angularCompilerOptions": { "angularCompilerOptions": {
"annotationsAs": "static fields", "annotationsAs": "static fields",
"annotateForClosureCompiler": true "annotateForClosureCompiler": true,
"enableIvy": false,
}, },
"compilerOptions": { "compilerOptions": {

View File

@ -12,6 +12,9 @@
"module": "amd", "module": "amd",
"moduleResolution": "node" "moduleResolution": "node"
}, },
"angularCompilerOptions": {
"enableIvy": false
},
"include": [ "include": [
"node_modules/@angular/**/*" "node_modules/@angular/**/*"
], ],

View File

@ -2,7 +2,8 @@
"angularCompilerOptions": { "angularCompilerOptions": {
"flatModuleId": "flat_module", "flatModuleId": "flat_module",
"flatModuleOutFile": "index.js", "flatModuleOutFile": "index.js",
"skipTemplateCodegen": true "skipTemplateCodegen": true,
"enableIvy": false
}, },
"compilerOptions": { "compilerOptions": {

View File

@ -1,6 +1,7 @@
{ {
"angularCompilerOptions": { "angularCompilerOptions": {
"debug": true "debug": true,
"enableIvy": false
}, },
"compilerOptions": { "compilerOptions": {

View File

@ -1,6 +1,7 @@
{ {
"angularCompilerOptions": { "angularCompilerOptions": {
"skipTemplateCodegen": true "skipTemplateCodegen": true,
"enableIvy": false
}, },
"compilerOptions": { "compilerOptions": {

View File

@ -4,7 +4,8 @@
"annotationsAs": "static fields", "annotationsAs": "static fields",
"debug": true, "debug": true,
"enableSummariesForJit": true, "enableSummariesForJit": true,
"i18nFormat": "xlf" "i18nFormat": "xlf",
"enableIvy": false
}, },
"compilerOptions": { "compilerOptions": {

View File

@ -1,7 +1,8 @@
{ {
"angularCompilerOptions": { "angularCompilerOptions": {
"debug": true, "debug": true,
"enableSummariesForJit": true "enableSummariesForJit": true,
"enableIvy": false
}, },
"compilerOptions": { "compilerOptions": {

View File

@ -68,7 +68,8 @@ export function mainDiagnosticsForTest(
} }
function createEmitCallback(options: api.CompilerOptions): api.TsEmitCallback|undefined { function createEmitCallback(options: api.CompilerOptions): api.TsEmitCallback|undefined {
const transformDecorators = !options.enableIvy && options.annotationsAs !== 'decorators'; const transformDecorators =
(options.enableIvy === false && options.annotationsAs !== 'decorators');
const transformTypesToClosure = options.annotateForClosureCompiler; const transformTypesToClosure = options.annotateForClosureCompiler;
if (!transformDecorators && !transformTypesToClosure) { if (!transformDecorators && !transformTypesToClosure) {
return undefined; return undefined;
@ -205,7 +206,7 @@ function reportErrorsAndExit(
const errorsAndWarnings = filterErrorsAndWarnings(allDiagnostics); const errorsAndWarnings = filterErrorsAndWarnings(allDiagnostics);
if (errorsAndWarnings.length) { if (errorsAndWarnings.length) {
const formatHost = getFormatDiagnosticsHost(options); const formatHost = getFormatDiagnosticsHost(options);
if (options && options.enableIvy === true) { if (options && options.enableIvy !== false) {
const ngDiagnostics = errorsAndWarnings.filter(api.isNgDiagnostic); const ngDiagnostics = errorsAndWarnings.filter(api.isNgDiagnostic);
const tsDiagnostics = errorsAndWarnings.filter(api.isTsDiagnostic); const tsDiagnostics = errorsAndWarnings.filter(api.isTsDiagnostic);
consoleError(replaceTsWithNgInErrors( consoleError(replaceTsWithNgInErrors(

View File

@ -186,10 +186,7 @@ export interface CompilerOptions extends ts.CompilerOptions {
/** /**
* Tells the compiler to generate definitions using the Render3 style code generation. * Tells the compiler to generate definitions using the Render3 style code generation.
* This option defaults to `false`. * This option defaults to `true`.
*
* Not all features are supported with this option enabled. It is only supported
* for experimentation and testing of Render3 style code generation.
* *
* Acceptable values are as follows: * Acceptable values are as follows:
* *

View File

@ -142,7 +142,7 @@ class AngularCompilerProgram implements Program {
} }
this.loweringMetadataTransform = this.loweringMetadataTransform =
new LowerMetadataTransform(options.enableIvy ? R3_LOWER_FIELDS : LOWER_FIELDS); new LowerMetadataTransform(options.enableIvy !== false ? R3_LOWER_FIELDS : LOWER_FIELDS);
this.metadataCache = this.createMetadataCache([this.loweringMetadataTransform]); this.metadataCache = this.createMetadataCache([this.loweringMetadataTransform]);
} }
@ -262,7 +262,7 @@ class AngularCompilerProgram implements Program {
emitCallback?: TsEmitCallback, emitCallback?: TsEmitCallback,
mergeEmitResultsCallback?: TsMergeEmitResultsCallback, mergeEmitResultsCallback?: TsMergeEmitResultsCallback,
} = {}): ts.EmitResult { } = {}): ts.EmitResult {
if (this.options.enableIvy) { if (this.options.enableIvy !== false) {
throw new Error('Cannot run legacy compiler in ngtsc mode'); throw new Error('Cannot run legacy compiler in ngtsc mode');
} }
return this._emitRender2(parameters); return this._emitRender2(parameters);
@ -897,7 +897,7 @@ export function createProgram({rootNames, options, host, oldProgram}: {
options: CompilerOptions, options: CompilerOptions,
host: CompilerHost, oldProgram?: Program host: CompilerHost, oldProgram?: Program
}): Program { }): Program {
if (options.enableIvy === true) { if (options.enableIvy !== false) {
return new NgtscProgram(rootNames, options, host, oldProgram as NgtscProgram); return new NgtscProgram(rootNames, options, host, oldProgram as NgtscProgram);
} else { } else {
return new AngularCompilerProgram(rootNames, options, host, oldProgram); return new AngularCompilerProgram(rootNames, options, host, oldProgram);

View File

@ -225,6 +225,9 @@ describe('extract_i18n command line', () => {
"moduleResolution": "node", "moduleResolution": "node",
"lib": ["es6", "dom"], "lib": ["es6", "dom"],
"typeRoots": ["node_modules/@types"] "typeRoots": ["node_modules/@types"]
},
"angularCompilerOptions": {
"enableIvy": false
} }
}`); }`);
}); });

View File

@ -59,6 +59,9 @@ describe('ngc transformer command-line', () => {
"moduleResolution": "node", "moduleResolution": "node",
"lib": ["es6", "dom"], "lib": ["es6", "dom"],
"typeRoots": ["node_modules/@types"] "typeRoots": ["node_modules/@types"]
},
"angularCompilerOptions": {
"enableIvy": false
} }
}`); }`);
}); });

View File

@ -57,6 +57,7 @@ function createTestSupportFor(basePath: string) {
'newLine': ts.NewLineKind.LineFeed, 'newLine': ts.NewLineKind.LineFeed,
'module': ts.ModuleKind.ES2015, 'module': ts.ModuleKind.ES2015,
'moduleResolution': ts.ModuleResolutionKind.NodeJs, 'moduleResolution': ts.ModuleResolutionKind.NodeJs,
'enableIvy': false,
'lib': Object.freeze([ 'lib': Object.freeze([
path.resolve(basePath, 'node_modules/typescript/lib/lib.es6.d.ts'), path.resolve(basePath, 'node_modules/typescript/lib/lib.es6.d.ts'),
]) as string[], ]) as string[],

View File

@ -26,7 +26,10 @@ describe('Google3 explicitQueryTiming TSLint rule', () => {
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test'); tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
shx.mkdir('-p', tmpDir); shx.mkdir('-p', tmpDir);
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}})); writeFile(
'tsconfig.json',
JSON.stringify(
{compilerOptions: {module: 'es2015'}, angularCompilerOptions: {enableIvy: false}}));
}); });
afterEach(() => shx.rm('-r', tmpDir)); afterEach(() => shx.rm('-r', tmpDir));

View File

@ -21,7 +21,10 @@ describe('Google3 missing injectable tslint rule', () => {
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test'); tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
shx.mkdir('-p', tmpDir); shx.mkdir('-p', tmpDir);
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}})); writeFile(
'tsconfig.json',
JSON.stringify(
{compilerOptions: {module: 'es2015'}, angularCompilerOptions: {enableIvy: false}}));
}); });
afterEach(() => shx.rm('-r', tmpDir)); afterEach(() => shx.rm('-r', tmpDir));

View File

@ -21,7 +21,10 @@ describe('Google3 noTemplateVariableAssignment TSLint rule', () => {
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test'); tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
shx.mkdir('-p', tmpDir); shx.mkdir('-p', tmpDir);
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}})); writeFile(
'tsconfig.json',
JSON.stringify(
{compilerOptions: {module: 'es2015'}, angularCompilerOptions: {enableIvy: false}}));
}); });
afterEach(() => shx.rm('-r', tmpDir)); afterEach(() => shx.rm('-r', tmpDir));

View File

@ -34,7 +34,8 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
paths: { paths: {
'@angular/core': ['angular.d.ts'], '@angular/core': ['angular.d.ts'],
} }
} },
angularCompilerOptions: {enableIvy: false}
})); }));
}); });

View File

@ -29,7 +29,8 @@ describe('Missing injectable migration', () => {
compilerOptions: { compilerOptions: {
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'}}}}}

View File

@ -27,7 +27,8 @@ describe('move-document migration', () => {
writeFile('/tsconfig.json', JSON.stringify({ writeFile('/tsconfig.json', JSON.stringify({
compilerOptions: { compilerOptions: {
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'}}}}}

View File

@ -28,7 +28,8 @@ describe('Renderer to Renderer2 migration', () => {
compilerOptions: { compilerOptions: {
lib: ['es2015'], lib: ['es2015'],
strictNullChecks: true, strictNullChecks: true,
} },
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'}}}}}

View File

@ -30,7 +30,8 @@ describe('static-queries migration with template strategy', () => {
compilerOptions: { compilerOptions: {
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'}}}}}
@ -681,6 +682,7 @@ 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']
})); }));

View File

@ -34,7 +34,8 @@ describe('static-queries migration with usage strategy', () => {
writeFile('/tsconfig.json', JSON.stringify({ writeFile('/tsconfig.json', JSON.stringify({
compilerOptions: { compilerOptions: {
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'}}}}}

View File

@ -28,7 +28,8 @@ describe('template variable assignment migration', () => {
writeFile('/tsconfig.json', JSON.stringify({ writeFile('/tsconfig.json', JSON.stringify({
compilerOptions: { compilerOptions: {
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'}}}}}

View File

@ -31,7 +31,8 @@ describe('Undecorated classes with DI migration', () => {
writeFile('/tsconfig.json', JSON.stringify({ writeFile('/tsconfig.json', JSON.stringify({
compilerOptions: { compilerOptions: {
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'}}}}}
@ -1259,6 +1260,7 @@ describe('Undecorated classes with DI migration', () => {
generateCodeForLibraries: false, generateCodeForLibraries: false,
allowEmptyCodegenFiles: true, allowEmptyCodegenFiles: true,
enableSummariesForJit: true, enableSummariesForJit: true,
enableIvy: false,
} }
})); }));