Skip to content

Commit

Permalink
feat: make the Ivy compiler the default for ngc (angular#32219)
Browse files Browse the repository at this point in the history
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 angular#32219
  • Loading branch information
alxhub authored and AndrewKushnir committed Aug 20, 2019
1 parent 2b64031 commit ec4381d
Show file tree
Hide file tree
Showing 43 changed files with 146 additions and 48 deletions.
12 changes: 9 additions & 3 deletions aio/content/examples/upgrade-phonecat-1-typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"lib": [
"es2015",
"dom"
],
"noImplicitAny": true,
"skipLibCheck": true,
"suppressImplicitAnyIndexErrors": true
Expand All @@ -16,5 +19,8 @@
"node_modules/*",
"**/*-aot.ts",
"aot/**/*"
]
}
],
"angularCompilerOptions": {
"enableIvy": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
],

"angularCompilerOptions": {
"skipMetadataEmit" : true
"skipMetadataEmit" : true,
"enableIvy": false,
}
}
12 changes: 9 additions & 3 deletions aio/content/examples/upgrade-phonecat-2-hybrid/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"lib": [
"es2015",
"dom"
],
"noImplicitAny": true,
"skipLibCheck": true,
"suppressImplicitAnyIndexErrors": true
Expand All @@ -15,5 +18,8 @@
"exclude": [
"node_modules/*",
"**/*-aot.ts"
]
}
],
"angularCompilerOptions": {
"enableIvy": false
}
}
12 changes: 9 additions & 3 deletions aio/content/examples/upgrade-phonecat-3-final/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"lib": [
"es2015",
"dom"
],
"noImplicitAny": true,
"skipLibCheck": true,
"suppressImplicitAnyIndexErrors": true
Expand All @@ -15,5 +18,8 @@
"exclude": [
"node_modules/*",
"**/*-aot.ts"
]
}
],
"angularCompilerOptions": {
"enableIvy": false
}
}
7 changes: 5 additions & 2 deletions aio/content/examples/visual-studio-2015/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"node_modules/@types"
]
},
"compileOnSave": true
}
"compileOnSave": true,
"angularCompilerOptions": {
"enableIvy": false
}
}
5 changes: 4 additions & 1 deletion aio/tools/examples/shared/boilerplate/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
"es2018",
"dom"
]
}
},
"angularCompilerOptions": {
"enableIvy": false,
},
}
5 changes: 4 additions & 1 deletion aio/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
"out-tsc",
"scripts",
"tools"
]
],
"angularCompilerOptions": {
"enableIvy": false,
},
}
17 changes: 17 additions & 0 deletions integration/bazel-schematics/disable-ivy.js
Original file line number Diff line number Diff line change
@@ -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));
2 changes: 2 additions & 0 deletions integration/bazel-schematics/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ function installLocalPackages() {
yarn add "${local_packages[@]}"
}


function testBazel() {
# Set up
bazel version
ng version
rm -rf demo
# Create project
ng new demo --collection=@angular/bazel --routing --skip-git --skip-install --style=scss
node ./disable-ivy.js
cd demo
installLocalPackages
ng generate component widget --style=css
Expand Down
3 changes: 2 additions & 1 deletion integration/bazel/angular-metadata.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"moduleResolution": "node"
},
"angularCompilerOptions": {
"enableSummariesForJit": true
"enableSummariesForJit": true,
"enableIvy": false
},
"include": [
"node_modules/@angular/**/*"
Expand Down
5 changes: 4 additions & 1 deletion integration/cli-hello-world/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"es2017",
"dom"
]
}
},
"angularCompilerOptions": {
"enableIvy": false,
},
}
3 changes: 3 additions & 0 deletions integration/dynamic-compiler/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"types": [
]
},
"angularCompilerOptions": {
"enableIvy": false,
},
"files": [
"src/main.ts",
"src/lazy.module.ts"
Expand Down
3 changes: 2 additions & 1 deletion integration/hello_world__closure/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"angularCompilerOptions": {
"annotationsAs": "static fields",
"annotateForClosureCompiler": true,
"alwaysCompileGeneratedCode": true
"alwaysCompileGeneratedCode": true,
"enableIvy": false,
},

"compilerOptions": {
Expand Down
5 changes: 4 additions & 1 deletion integration/hello_world__systemjs_umd/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
},
"angularCompilerOptions": {
"enableIvy": false,
},
}
3 changes: 2 additions & 1 deletion integration/i18n/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"angularCompilerOptions": {
"annotationsAs": "static fields",
"annotateForClosureCompiler": true,
"alwaysCompileGeneratedCode": true
"alwaysCompileGeneratedCode": true,
"enableIvy": false,
},

"compilerOptions": {
Expand Down
3 changes: 3 additions & 0 deletions integration/injectable-def/tsconfig-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"types": ["node"],
"rootDir": "."
},
"angularCompilerOptions": {
"enableIvy": false,
},
"files": [
"src/app.ts",
"src/main.ts"
Expand Down
3 changes: 2 additions & 1 deletion integration/injectable-def/tsconfig-lib1.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"flatModuleOutFile": "index.js",
"flatModuleId": "lib1_built"
"flatModuleId": "lib1_built",
"enableIvy": false,
}
}
3 changes: 2 additions & 1 deletion integration/injectable-def/tsconfig-lib2.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"flatModuleId": "lib2_built",
"flatModuleOutFile": "index.js"
"flatModuleOutFile": "index.js",
"enableIvy": false,
}
}
3 changes: 2 additions & 1 deletion integration/ng_elements/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"angularCompilerOptions": {
"annotationsAs": "static fields",
"annotateForClosureCompiler": true,
"alwaysCompileGeneratedCode": true
"alwaysCompileGeneratedCode": true,
"enableIvy": false,
},

"compilerOptions": {
Expand Down
3 changes: 2 additions & 1 deletion integration/platform-server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"angularCompilerOptions": {
"annotationsAs": "static fields",
"annotateForClosureCompiler": true
"annotateForClosureCompiler": true,
"enableIvy": false,
},

"compilerOptions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"module": "amd",
"moduleResolution": "node"
},
"angularCompilerOptions": {
"enableIvy": false
},
"include": [
"node_modules/@angular/**/*"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"angularCompilerOptions": {
"flatModuleId": "flat_module",
"flatModuleOutFile": "index.js",
"skipTemplateCodegen": true
"skipTemplateCodegen": true,
"enableIvy": false
},

"compilerOptions": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"angularCompilerOptions": {
"debug": true
"debug": true,
"enableIvy": false
},

"compilerOptions": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"angularCompilerOptions": {
"skipTemplateCodegen": true
"skipTemplateCodegen": true,
"enableIvy": false
},

"compilerOptions": {
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler-cli/integrationtest/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"annotationsAs": "static fields",
"debug": true,
"enableSummariesForJit": true,
"i18nFormat": "xlf"
"i18nFormat": "xlf",
"enableIvy": false
},

"compilerOptions": {
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler-cli/integrationtest/tsconfig-xi18n.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"angularCompilerOptions": {
"debug": true,
"enableSummariesForJit": true
"enableSummariesForJit": true,
"enableIvy": false
},

"compilerOptions": {
Expand Down
5 changes: 3 additions & 2 deletions packages/compiler-cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export function mainDiagnosticsForTest(
}

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;
if (!transformDecorators && !transformTypesToClosure) {
return undefined;
Expand Down Expand Up @@ -205,7 +206,7 @@ function reportErrorsAndExit(
const errorsAndWarnings = filterErrorsAndWarnings(allDiagnostics);
if (errorsAndWarnings.length) {
const formatHost = getFormatDiagnosticsHost(options);
if (options && options.enableIvy === true) {
if (options && options.enableIvy !== false) {
const ngDiagnostics = errorsAndWarnings.filter(api.isNgDiagnostic);
const tsDiagnostics = errorsAndWarnings.filter(api.isTsDiagnostic);
consoleError(replaceTsWithNgInErrors(
Expand Down
5 changes: 1 addition & 4 deletions packages/compiler-cli/src/transformers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,7 @@ export interface CompilerOptions extends ts.CompilerOptions {

/**
* Tells the compiler to generate definitions using the Render3 style code generation.
* This option defaults to `false`.
*
* Not all features are supported with this option enabled. It is only supported
* for experimentation and testing of Render3 style code generation.
* This option defaults to `true`.
*
* Acceptable values are as follows:
*
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler-cli/src/transformers/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class AngularCompilerProgram implements Program {
}

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

Expand Down Expand Up @@ -262,7 +262,7 @@ class AngularCompilerProgram implements Program {
emitCallback?: TsEmitCallback,
mergeEmitResultsCallback?: TsMergeEmitResultsCallback,
} = {}): ts.EmitResult {
if (this.options.enableIvy) {
if (this.options.enableIvy !== false) {
throw new Error('Cannot run legacy compiler in ngtsc mode');
}
return this._emitRender2(parameters);
Expand Down Expand Up @@ -897,7 +897,7 @@ export function createProgram({rootNames, options, host, oldProgram}: {
options: CompilerOptions,
host: CompilerHost, oldProgram?: Program
}): Program {
if (options.enableIvy === true) {
if (options.enableIvy !== false) {
return new NgtscProgram(rootNames, options, host, oldProgram as NgtscProgram);
} else {
return new AngularCompilerProgram(rootNames, options, host, oldProgram);
Expand Down
3 changes: 3 additions & 0 deletions packages/compiler-cli/test/extract_i18n_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ describe('extract_i18n command line', () => {
"moduleResolution": "node",
"lib": ["es6", "dom"],
"typeRoots": ["node_modules/@types"]
},
"angularCompilerOptions": {
"enableIvy": false
}
}`);
});
Expand Down
3 changes: 3 additions & 0 deletions packages/compiler-cli/test/ngc_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ describe('ngc transformer command-line', () => {
"moduleResolution": "node",
"lib": ["es6", "dom"],
"typeRoots": ["node_modules/@types"]
},
"angularCompilerOptions": {
"enableIvy": false
}
}`);
});
Expand Down

0 comments on commit ec4381d

Please sign in to comment.