From 16f96eeabf77964092b4b6a830e29f2761ffaeec Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 5 Sep 2022 09:52:20 +0000 Subject: [PATCH] refactor(compiler-cli): remove `enableIvy` options (#47346) This option has no longer any effect as Ivy is the only rendering engine. BREAKING CHANGE: Angular compiler option `enableIvy` has been removed as Ivy is the only rendering engine. PR Close #47346 --- devtools/tsconfig.json | 5 +- .../compiler-cli/compiler_options.md | 1 - integration/ivy-i18n/tsconfig.legacy-xmb.json | 1 - integration/ivy-i18n/tsconfig.legacy.json | 1 - integration/ngcc/tsconfig-app.json | 7 +-- packages/bazel/src/ngc-wrapped/index.ts | 23 +++----- .../flat_module/tsconfig-build.json | 3 +- .../ngtools_src/tsconfig-build.json | 3 +- .../third_party_src/tsconfig-build.json | 3 +- .../integrationtest/tsconfig-build.json | 3 +- .../integrationtest/tsconfig-xi18n.json | 3 +- packages/compiler-cli/src/main.ts | 5 +- .../src/ngtsc/core/api/src/public_options.ts | 15 +---- packages/compiler-cli/src/perform_compile.ts | 3 - .../compiler-cli/src/transformers/util.ts | 3 +- .../compliance/test_helpers/compile_test.ts | 1 - packages/compiler-cli/test/ngtsc/env.ts | 5 +- .../compiler-cli/test/ngtsc/ngtsc_spec.ts | 1 - .../compiler-cli/test/perform_compile_spec.ts | 58 +++++++++---------- .../test/legacy/language_service_spec.ts | 3 - 20 files changed, 51 insertions(+), 96 deletions(-) diff --git a/devtools/tsconfig.json b/devtools/tsconfig.json index 8d3b337ee52a0..021da6a0c17c0 100644 --- a/devtools/tsconfig.json +++ b/devtools/tsconfig.json @@ -52,7 +52,6 @@ }, "angularCompilerOptions": { "fullTemplateTypeCheck": true, - "strictInjectionParameters": true, - "enableIvy": true + "strictInjectionParameters": true } -} \ No newline at end of file +} diff --git a/goldens/public-api/compiler-cli/compiler_options.md b/goldens/public-api/compiler-cli/compiler_options.md index 9433d6f9efc7e..b67885ba91c16 100644 --- a/goldens/public-api/compiler-cli/compiler_options.md +++ b/goldens/public-api/compiler-cli/compiler_options.md @@ -58,7 +58,6 @@ export interface MiscOptions { // @public export interface NgcCompatibilityOptions { - enableIvy?: boolean | 'ngtsc'; generateNgFactoryShims?: boolean; generateNgSummaryShims?: boolean; } diff --git a/integration/ivy-i18n/tsconfig.legacy-xmb.json b/integration/ivy-i18n/tsconfig.legacy-xmb.json index 58e0a5e393068..564b79ad6309c 100644 --- a/integration/ivy-i18n/tsconfig.legacy-xmb.json +++ b/integration/ivy-i18n/tsconfig.legacy-xmb.json @@ -1,7 +1,6 @@ { "extends": "./tsconfig.app.json", "angularCompilerOptions": { - "enableIvy": true, "i18nInFormat": "xmb" } } diff --git a/integration/ivy-i18n/tsconfig.legacy.json b/integration/ivy-i18n/tsconfig.legacy.json index 3bf6947e21a4a..c6b2943809e02 100644 --- a/integration/ivy-i18n/tsconfig.legacy.json +++ b/integration/ivy-i18n/tsconfig.legacy.json @@ -1,7 +1,6 @@ { "extends": "./tsconfig.app.json", "angularCompilerOptions": { - "enableIvy": true, "i18nInFormat": "xlf" } } diff --git a/integration/ngcc/tsconfig-app.json b/integration/ngcc/tsconfig-app.json index 2468de186e67a..2bb4b94a4909d 100644 --- a/integration/ngcc/tsconfig-app.json +++ b/integration/ngcc/tsconfig-app.json @@ -13,8 +13,5 @@ }, "files": [ "src/main.ts" - ], - "angularCompilerOptions": { - "enableIvy": "ngtsc" - } -} \ No newline at end of file + ] +} diff --git a/packages/bazel/src/ngc-wrapped/index.ts b/packages/bazel/src/ngc-wrapped/index.ts index e69a0a32916db..018c0266ecac5 100644 --- a/packages/bazel/src/ngc-wrapped/index.ts +++ b/packages/bazel/src/ngc-wrapped/index.ts @@ -232,7 +232,6 @@ export function compile({ } // Detect from compilerOpts whether the entrypoint is being invoked in Ivy mode. - const isInIvyMode = !!compilerOpts.enableIvy; if (!compilerOpts.rootDirs) { throw new Error('rootDirs is not set!'); } @@ -259,16 +258,14 @@ export function compile({ bazelHost = new CompilerHost(files, compilerOpts, bazelOpts, tsHost, fileLoader); } - if (isInIvyMode) { - const delegate = bazelHost.shouldSkipTsickleProcessing.bind(bazelHost); - bazelHost.shouldSkipTsickleProcessing = (fileName: string) => { - // The base implementation of shouldSkipTsickleProcessing checks whether `fileName` is part of - // the original `srcs[]`. For Angular (Ivy) compilations, ngfactory/ngsummary files that are - // shims for original .ts files in the program should be treated identically. Thus, strip the - // '.ngfactory' or '.ngsummary' part of the filename away before calling the delegate. - return delegate(fileName.replace(/\.(ngfactory|ngsummary)\.ts$/, '.ts')); - }; - } + const delegate = bazelHost.shouldSkipTsickleProcessing.bind(bazelHost); + bazelHost.shouldSkipTsickleProcessing = (fileName: string) => { + // The base implementation of shouldSkipTsickleProcessing checks whether `fileName` is part of + // the original `srcs[]`. For Angular (Ivy) compilations, ngfactory/ngsummary files that are + // shims for original .ts files in the program should be treated identically. Thus, strip the + // '.ngfactory' or '.ngsummary' part of the filename away before calling the delegate. + return delegate(fileName.replace(/\.(ngfactory|ngsummary)\.ts$/, '.ts')); + }; // By default, disable tsickle decorator transforming in the tsickle compiler host. // The Angular compilers have their own logic for decorator processing and we wouldn't @@ -286,9 +283,7 @@ export function compile({ // decorator transformation is still needed. This might be because of custom decorators // with the `@Annotation` JSDoc that will be processed by the tsickle decorator transform. // TODO: Figure out why this is needed in g3 and how we can improve this. FW-2225 - if (isInIvyMode) { - bazelHost.transformDecorators = true; - } + bazelHost.transformDecorators = true; } else { compilerOpts.annotateForClosureCompiler = false; } diff --git a/packages/compiler-cli/integrationtest/flat_module/tsconfig-build.json b/packages/compiler-cli/integrationtest/flat_module/tsconfig-build.json index fa47ca08690e8..d78312a696ccd 100644 --- a/packages/compiler-cli/integrationtest/flat_module/tsconfig-build.json +++ b/packages/compiler-cli/integrationtest/flat_module/tsconfig-build.json @@ -2,8 +2,7 @@ "angularCompilerOptions": { "flatModuleId": "flat_module", "flatModuleOutFile": "index.js", - "skipTemplateCodegen": true, - "enableIvy": false + "skipTemplateCodegen": true }, "compilerOptions": { diff --git a/packages/compiler-cli/integrationtest/ngtools_src/tsconfig-build.json b/packages/compiler-cli/integrationtest/ngtools_src/tsconfig-build.json index 7899fe775a39e..b40087b188eeb 100644 --- a/packages/compiler-cli/integrationtest/ngtools_src/tsconfig-build.json +++ b/packages/compiler-cli/integrationtest/ngtools_src/tsconfig-build.json @@ -1,7 +1,6 @@ { "angularCompilerOptions": { - "debug": true, - "enableIvy": false + "debug": true }, "compilerOptions": { diff --git a/packages/compiler-cli/integrationtest/third_party_src/tsconfig-build.json b/packages/compiler-cli/integrationtest/third_party_src/tsconfig-build.json index 42a20413b307a..e5f508af71222 100644 --- a/packages/compiler-cli/integrationtest/third_party_src/tsconfig-build.json +++ b/packages/compiler-cli/integrationtest/third_party_src/tsconfig-build.json @@ -1,7 +1,6 @@ { "angularCompilerOptions": { - "skipTemplateCodegen": true, - "enableIvy": false + "skipTemplateCodegen": true }, "compilerOptions": { diff --git a/packages/compiler-cli/integrationtest/tsconfig-build.json b/packages/compiler-cli/integrationtest/tsconfig-build.json index b5a73bd4c62c4..d5f9c24c4805b 100644 --- a/packages/compiler-cli/integrationtest/tsconfig-build.json +++ b/packages/compiler-cli/integrationtest/tsconfig-build.json @@ -4,8 +4,7 @@ "annotationsAs": "static fields", "debug": true, "enableSummariesForJit": true, - "i18nFormat": "xlf", - "enableIvy": false + "i18nFormat": "xlf" }, "compilerOptions": { diff --git a/packages/compiler-cli/integrationtest/tsconfig-xi18n.json b/packages/compiler-cli/integrationtest/tsconfig-xi18n.json index 3e08ef46dbe87..5c94014051a0c 100644 --- a/packages/compiler-cli/integrationtest/tsconfig-xi18n.json +++ b/packages/compiler-cli/integrationtest/tsconfig-xi18n.json @@ -1,8 +1,7 @@ { "angularCompilerOptions": { "debug": true, - "enableSummariesForJit": true, - "enableIvy": false + "enableSummariesForJit": true }, "compilerOptions": { diff --git a/packages/compiler-cli/src/main.ts b/packages/compiler-cli/src/main.ts index 65580605f9b22..e1b08acd64b70 100644 --- a/packages/compiler-cli/src/main.ts +++ b/packages/compiler-cli/src/main.ts @@ -12,7 +12,6 @@ import yargs from 'yargs'; import {exitCodeFromResult, formatDiagnostics, ParsedConfiguration, performCompilation, readConfiguration} from './perform_compile'; import {createPerformWatchHost, performWatchCompilation} from './perform_watch'; import * as api from './transformers/api'; -import {GENERATED_FILES} from './transformers/util'; type TsickleModule = typeof import('tsickle'); @@ -106,9 +105,7 @@ function createEmitCallback( 'fileNameToModuleId'|'googmodule'|'untyped'|'convertIndexImportShorthand'| 'transformDecorators'|'transformTypesToClosure'|'generateExtraSuppressions'| 'rootDirsRelative'> = { - shouldSkipTsickleProcessing: (fileName) => /\.d\.ts$/.test(fileName) || - // View Engine's generated files were never intended to be processed with tsickle. - (!options.enableIvy && GENERATED_FILES.test(fileName)), + shouldSkipTsickleProcessing: (fileName) => fileName.endsWith('.d.ts'), pathToModuleName: (context, importPath) => '', shouldIgnoreWarningsForPath: (filePath) => false, fileNameToModuleId: (fileName) => fileName, diff --git a/packages/compiler-cli/src/ngtsc/core/api/src/public_options.ts b/packages/compiler-cli/src/ngtsc/core/api/src/public_options.ts index ce329c835ae3b..48a52eba7c651 100644 --- a/packages/compiler-cli/src/ngtsc/core/api/src/public_options.ts +++ b/packages/compiler-cli/src/ngtsc/core/api/src/public_options.ts @@ -110,18 +110,6 @@ export interface NgcCompatibilityOptions { * `TestBed`, which is a no-op in Ivy. */ generateNgSummaryShims?: boolean; - - /** - * Tells the compiler to generate definitions using the Render3 style code generation. - * This option defaults to `true`. - * - * Acceptable values are as follows: - * - * `false` - run ngc normally - * `true` - run the ngtsc compiler instead of the normal ngc compiler - * `ngtsc` - alias for `true` - */ - enableIvy?: boolean|'ngtsc'; } /** @@ -385,7 +373,6 @@ export interface I18nOptions { /** * Render `$localize` messages with legacy format ids. * - * This is only active if we are building with `enableIvy: true`. * The default value for now is `true`. * * Use this option when use are using the `$localize` based localization messages but @@ -437,7 +424,7 @@ export interface TargetOptions { export interface MiscOptions { /** * Whether the compiler should avoid generating code for classes that haven't been exported. - * This is only active when building with `enableIvy: true`. Defaults to `true`. + * Defaults to `true`. */ compileNonExportedClasses?: boolean; diff --git a/packages/compiler-cli/src/perform_compile.ts b/packages/compiler-cli/src/perform_compile.ts index b7734359da8ef..866085c08c35c 100644 --- a/packages/compiler-cli/src/perform_compile.ts +++ b/packages/compiler-cli/src/perform_compile.ts @@ -119,9 +119,6 @@ export function readConfiguration( ts.parseJsonConfigFileContent( config, parseConfigHost, basePath, existingCompilerOptions, configFileName); - // Coerce to boolean as `enableIvy` can be `ngtsc|true|false|undefined` here. - options.enableIvy = !!(options.enableIvy ?? true); - let emitFlags = api.EmitFlags.Default; if (!(options.skipMetadataEmit || options.flatModuleOutFile)) { emitFlags |= api.EmitFlags.Metadata; diff --git a/packages/compiler-cli/src/transformers/util.ts b/packages/compiler-cli/src/transformers/util.ts index 1a471695c61fa..f6a2078873fff 100644 --- a/packages/compiler-cli/src/transformers/util.ts +++ b/packages/compiler-cli/src/transformers/util.ts @@ -8,9 +8,8 @@ import ts from 'typescript'; -import {CompilerOptions, DEFAULT_ERROR_CODE, SOURCE} from './api'; +import {DEFAULT_ERROR_CODE, SOURCE} from './api'; -export const GENERATED_FILES = /(.*?)\.(ngfactory|shim\.ngstyle|ngstyle|ngsummary)\.(js|d\.ts|ts)$/; export function error(msg: string): never { throw new Error(`Internal error: ${msg}`); diff --git a/packages/compiler-cli/test/compliance/test_helpers/compile_test.ts b/packages/compiler-cli/test/compliance/test_helpers/compile_test.ts index 177f1cb9b79af..f3682eb206878 100644 --- a/packages/compiler-cli/test/compliance/test_helpers/compile_test.ts +++ b/packages/compiler-cli/test/compliance/test_helpers/compile_test.ts @@ -117,7 +117,6 @@ function getOptions( moduleResolution: ts.ModuleResolutionKind.NodeJs, typeRoots: ['node_modules/@types'], ...convertedCompilerOptions.options, - enableIvy: true, enableI18nLegacyMessageIdFormat: false, ...angularCompilerOptions, }; diff --git a/packages/compiler-cli/test/ngtsc/env.ts b/packages/compiler-cli/test/ngtsc/env.ts index 6516bcfbd962d..08742ccb5b481 100644 --- a/packages/compiler-cli/test/ngtsc/env.ts +++ b/packages/compiler-cli/test/ngtsc/env.ts @@ -78,9 +78,6 @@ export class NgtscTestEnvironment { "lib": ["es2015", "dom"], "typeRoots": ["node_modules/@types"] }, - "angularCompilerOptions": { - "enableIvy": true, - }, "exclude": [ "built" ] @@ -195,7 +192,7 @@ export class NgtscTestEnvironment { tsconfig(extraOpts: TsConfigOptions = {}, extraRootDirs?: string[], files?: string[]): void { const tsconfig: {[key: string]: any} = { extends: './tsconfig-base.json', - angularCompilerOptions: {...extraOpts, enableIvy: true}, + angularCompilerOptions: extraOpts, }; if (files !== undefined) { tsconfig['files'] = files; diff --git a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts index e06d32e131c83..f1e313d16cfa3 100644 --- a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts +++ b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts @@ -1905,7 +1905,6 @@ function allTests(os: string) { it('should be able to use abstract directive in other compilation units', () => { env.write('tsconfig.json', JSON.stringify({ extends: './tsconfig-base.json', - angularCompilerOptions: {enableIvy: true}, compilerOptions: {rootDir: '.', outDir: '../node_modules/lib1_built'}, })); env.write('index.ts', ` diff --git a/packages/compiler-cli/test/perform_compile_spec.ts b/packages/compiler-cli/test/perform_compile_spec.ts index 9b6a405b64196..0d58c9ad79c30 100644 --- a/packages/compiler-cli/test/perform_compile_spec.ts +++ b/packages/compiler-cli/test/perform_compile_spec.ts @@ -51,33 +51,31 @@ describe('perform_compile', () => { it('should merge tsconfig "angularCompilerOptions"', () => { writeSomeConfigs(); const {options} = readConfiguration(path.resolve(basePath, 'tsconfig-level-1.json')); - expect(options.annotateForClosureCompiler).toBe(true); + expect(options.annotateForClosureCompiler).toBeTrue(); expect(options.annotationsAs).toBe('decorators'); - expect(options.skipMetadataEmit).toBe(true); + expect(options.skipMetadataEmit).toBeTrue(); }); - it(`should return 'enableIvy: true' when enableIvy is not defined in "angularCompilerOptions"`, - () => { - writeSomeConfigs(); - const {options} = readConfiguration(path.resolve(basePath, 'tsconfig-level-1.json')); - expect(options.enableIvy).toBe(true); - }); + it(`should return undefined when debug is not defined in "angularCompilerOptions"`, () => { + writeSomeConfigs(); + const {options} = readConfiguration(path.resolve(basePath, 'tsconfig-level-1.json')); + expect(options.debug).toBeUndefined(); + }); - it(`should return 'enableIvy: false' when enableIvy is disabled in "angularCompilerOptions"`, - () => { - writeSomeConfigs(); - support.writeFiles({ - 'tsconfig-level-3.json': `{ + it(`should return 'debug: false' when debug is disabled in "angularCompilerOptions"`, () => { + writeSomeConfigs(); + support.writeFiles({ + 'tsconfig-level-3.json': `{ "angularCompilerOptions": { - "enableIvy": false + "debug": false } } `, - }); + }); - const {options} = readConfiguration(path.resolve(basePath, 'tsconfig-level-1.json')); - expect(options.enableIvy).toBe(false); - }); + const {options} = readConfiguration(path.resolve(basePath, 'tsconfig-level-1.json')); + expect(options.debug).toBeFalse(); + }); it('should override options defined in tsconfig with those defined in `existingOptions`', () => { support.writeFiles({ @@ -89,15 +87,17 @@ describe('perform_compile', () => { "annotateForClosureCompiler": true } } - ` + `, }); - const {options} = readConfiguration( - path.resolve(basePath, 'tsconfig-level-1.json'), - {annotateForClosureCompiler: false, target: ts.ScriptTarget.ES2015, enableIvy: false}); + const {options} = readConfiguration(path.resolve(basePath, 'tsconfig-level-1.json'), { + annotateForClosureCompiler: false, + target: ts.ScriptTarget.ES2015, + debug: false, + }); expect(options).toEqual(jasmine.objectContaining({ - enableIvy: false, + debug: false, target: ts.ScriptTarget.ES2015, annotateForClosureCompiler: false, })); @@ -108,7 +108,7 @@ describe('perform_compile', () => { 'tsconfig-level-1.json': `{ "extends": "@angular-ru/tsconfig", "angularCompilerOptions": { - "enableIvy": false + "debug": false } } `, @@ -133,7 +133,7 @@ describe('perform_compile', () => { expect(options).toEqual(jasmine.objectContaining({ strict: true, skipMetadataEmit: true, - enableIvy: false, + debug: false, })); }); @@ -143,7 +143,7 @@ describe('perform_compile', () => { 'tsconfig-level-1.json': `{ "extends": "@1stg/tsconfig/angular", "angularCompilerOptions": { - "enableIvy": false + "debug": false } }`, 'node_modules/@1stg/tsconfig/angular.json': `{ @@ -164,7 +164,7 @@ describe('perform_compile', () => { expect(options).toEqual(jasmine.objectContaining({ strict: true, skipMetadataEmit: true, - enableIvy: false, + debug: false, })); }); @@ -174,7 +174,7 @@ describe('perform_compile', () => { 'tsconfig-level-1.json': `{ "extends": "./tsconfig.app", "angularCompilerOptions": { - "enableIvy": false + "debug": false } }`, 'tsconfig.app.json': `{ @@ -191,7 +191,7 @@ describe('perform_compile', () => { expect(options).toEqual(jasmine.objectContaining({ strict: true, skipMetadataEmit: true, - enableIvy: false, + debug: false, })); }); }); diff --git a/packages/language-service/test/legacy/language_service_spec.ts b/packages/language-service/test/legacy/language_service_spec.ts index af4bbf4ad3f2e..4ffc7b70d97ed 100644 --- a/packages/language-service/test/legacy/language_service_spec.ts +++ b/packages/language-service/test/legacy/language_service_spec.ts @@ -34,7 +34,6 @@ describe('language service adapter', () => { describe('parse compiler options', () => { it('should initialize with angularCompilerOptions from tsconfig.json', () => { expect(ngLS.getCompilerOptions()).toEqual(jasmine.objectContaining({ - enableIvy: true, // default for ivy is true strictTemplates: true, strictInjectionParameters: true, })); @@ -42,7 +41,6 @@ describe('language service adapter', () => { it('should reparse angularCompilerOptions on tsconfig.json change', () => { expect(ngLS.getCompilerOptions()).toEqual(jasmine.objectContaining({ - enableIvy: true, // default for ivy is true strictTemplates: true, strictInjectionParameters: true, })); @@ -66,7 +64,6 @@ describe('language service adapter', () => { // First make sure the default for strictTemplates is true expect(ngLS.getCompilerOptions()).toEqual(jasmine.objectContaining({ - enableIvy: true, // default for ivy is true strictTemplates: true, strictInjectionParameters: true, }));