Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(compiler-cli): remove enableIvy option #47346

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions devtools/tsconfig.json
Expand Up @@ -52,7 +52,6 @@
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableIvy": true
"strictInjectionParameters": true
}
}
}
1 change: 0 additions & 1 deletion goldens/public-api/compiler-cli/compiler_options.md
Expand Up @@ -58,7 +58,6 @@ export interface MiscOptions {

// @public
export interface NgcCompatibilityOptions {
enableIvy?: boolean | 'ngtsc';
generateNgFactoryShims?: boolean;
generateNgSummaryShims?: boolean;
}
Expand Down
1 change: 0 additions & 1 deletion integration/ivy-i18n/tsconfig.legacy-xmb.json
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.app.json",
"angularCompilerOptions": {
"enableIvy": true,
"i18nInFormat": "xmb"
}
}
1 change: 0 additions & 1 deletion integration/ivy-i18n/tsconfig.legacy.json
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.app.json",
"angularCompilerOptions": {
"enableIvy": true,
"i18nInFormat": "xlf"
}
}
7 changes: 2 additions & 5 deletions integration/ngcc/tsconfig-app.json
Expand Up @@ -13,8 +13,5 @@
},
"files": [
"src/main.ts"
],
"angularCompilerOptions": {
"enableIvy": "ngtsc"
}
}
]
}
23 changes: 9 additions & 14 deletions packages/bazel/src/ngc-wrapped/index.ts
Expand Up @@ -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!');
}
Expand All @@ -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) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed?

// 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
Expand All @@ -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;
}
Expand Down
Expand Up @@ -2,8 +2,7 @@
"angularCompilerOptions": {
"flatModuleId": "flat_module",
"flatModuleOutFile": "index.js",
"skipTemplateCodegen": true,
"enableIvy": false
"skipTemplateCodegen": true
},

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

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

"compilerOptions": {
Expand Down
3 changes: 1 addition & 2 deletions packages/compiler-cli/integrationtest/tsconfig-build.json
Expand Up @@ -4,8 +4,7 @@
"annotationsAs": "static fields",
"debug": true,
"enableSummariesForJit": true,
"i18nFormat": "xlf",
"enableIvy": false
"i18nFormat": "xlf"
},

"compilerOptions": {
Expand Down
3 changes: 1 addition & 2 deletions packages/compiler-cli/integrationtest/tsconfig-xi18n.json
@@ -1,8 +1,7 @@
{
"angularCompilerOptions": {
"debug": true,
"enableSummariesForJit": true,
"enableIvy": false
"enableSummariesForJit": true
},

"compilerOptions": {
Expand Down
5 changes: 1 addition & 4 deletions packages/compiler-cli/src/main.ts
Expand Up @@ -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');

Expand Down Expand Up @@ -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,
Expand Down
15 changes: 1 addition & 14 deletions packages/compiler-cli/src/ngtsc/core/api/src/public_options.ts
Expand Up @@ -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';
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 0 additions & 3 deletions packages/compiler-cli/src/perform_compile.ts
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions packages/compiler-cli/src/transformers/util.ts
Expand Up @@ -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}`);
Expand Down
Expand Up @@ -117,7 +117,6 @@ function getOptions(
moduleResolution: ts.ModuleResolutionKind.NodeJs,
typeRoots: ['node_modules/@types'],
...convertedCompilerOptions.options,
enableIvy: true,
enableI18nLegacyMessageIdFormat: false,
...angularCompilerOptions,
};
Expand Down
5 changes: 1 addition & 4 deletions packages/compiler-cli/test/ngtsc/env.ts
Expand Up @@ -78,9 +78,6 @@ export class NgtscTestEnvironment {
"lib": ["es2015", "dom"],
"typeRoots": ["node_modules/@types"]
},
"angularCompilerOptions": {
"enableIvy": true,
},
"exclude": [
"built"
]
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/compiler-cli/test/ngtsc/ngtsc_spec.ts
Expand Up @@ -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', `
Expand Down
58 changes: 29 additions & 29 deletions packages/compiler-cli/test/perform_compile_spec.ts
Expand Up @@ -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({
Expand All @@ -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,
}));
Expand All @@ -108,7 +108,7 @@ describe('perform_compile', () => {
'tsconfig-level-1.json': `{
"extends": "@angular-ru/tsconfig",
"angularCompilerOptions": {
"enableIvy": false
"debug": false
}
}
`,
Expand All @@ -133,7 +133,7 @@ describe('perform_compile', () => {
expect(options).toEqual(jasmine.objectContaining({
strict: true,
skipMetadataEmit: true,
enableIvy: false,
debug: false,
}));
});

Expand All @@ -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': `{
Expand All @@ -164,7 +164,7 @@ describe('perform_compile', () => {
expect(options).toEqual(jasmine.objectContaining({
strict: true,
skipMetadataEmit: true,
enableIvy: false,
debug: false,
}));
});

Expand All @@ -174,7 +174,7 @@ describe('perform_compile', () => {
'tsconfig-level-1.json': `{
"extends": "./tsconfig.app",
"angularCompilerOptions": {
"enableIvy": false
"debug": false
}
}`,
'tsconfig.app.json': `{
Expand All @@ -191,7 +191,7 @@ describe('perform_compile', () => {
expect(options).toEqual(jasmine.objectContaining({
strict: true,
skipMetadataEmit: true,
enableIvy: false,
debug: false,
}));
});
});