From 6ba67c6fff52d5da443f36fa1bfe1cc1f0919c51 Mon Sep 17 00:00:00 2001 From: JoostK Date: Thu, 8 Apr 2021 22:34:31 +0200 Subject: [PATCH] feat(compiler-cli): mark ability to use partial compilation mode as stable (#41518) This commit marks the `compilationMode` compiler option as stable, such that libraries can be compiled in partial compilation mode. In partial compilation mode, the compiler's output changes from fully compiled AOT definitions to an intermediate form using partial declarations. This form is suitable to be published to NPM, which now allows libraries to be compiled and published using the Ivy compiler. Please be aware that libraries that have been compiled using this mode can only be used in Angular 12 applications and up; they cannot be used when Ivy is disabled (i.e. when using View Engine) or in versions of Angular prior to 12. The `compilationMode` option has no effect if `enableIvy: false` is used. Closes #41496 PR Close #41518 --- aio/content/guide/angular-compiler-options.md | 9 +++++++++ .../compiler-cli/compiler_options.d.ts | 4 ++++ .../src/ngtsc/core/api/src/options.ts | 18 +----------------- .../src/ngtsc/core/api/src/public_options.ts | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/aio/content/guide/angular-compiler-options.md b/aio/content/guide/angular-compiler-options.md index e3fcdd53dd..76b79b939c 100644 --- a/aio/content/guide/angular-compiler-options.md +++ b/aio/content/guide/angular-compiler-options.md @@ -67,6 +67,15 @@ Modifies how Angular-specific annotations are emitted to improve tree-shaking. N When `true`, use [Tsickle](https://github.com/angular/tsickle) to annotate the emitted JavaScript with [JSDoc](https://jsdoc.app/) comments needed by the [Closure Compiler](https://github.com/google/closure-compiler). Default is `false`. +### `compilationMode` + +Specifies the compilation mode to use. The following modes are available: + +- `'full'`: generates fully AOT-compiled code according to the version of Angular that is currently being used. +- `'partial'`: generates code in a stable, but intermediate form suitable for a published library. + +The default value is `'full'`. + ### `disableExpressionLowering` When `true` (the default), transforms code that is or could be used in an annotation, to allow it to be imported from template factory modules. See [metadata rewriting](guide/aot-compiler#metadata-rewriting) for more information. diff --git a/goldens/public-api/compiler-cli/compiler_options.d.ts b/goldens/public-api/compiler-cli/compiler_options.d.ts index 2c462d513a..e972a3e99c 100644 --- a/goldens/public-api/compiler-cli/compiler_options.d.ts +++ b/goldens/public-api/compiler-cli/compiler_options.d.ts @@ -43,3 +43,7 @@ export interface StrictTemplateOptions { strictSafeNavigationTypes?: boolean; strictTemplates?: boolean; } + +export interface TargetOptions { + compilationMode?: 'full' | 'partial'; +} diff --git a/packages/compiler-cli/src/ngtsc/core/api/src/options.ts b/packages/compiler-cli/src/ngtsc/core/api/src/options.ts index 661221d87a..b9117d5459 100644 --- a/packages/compiler-cli/src/ngtsc/core/api/src/options.ts +++ b/packages/compiler-cli/src/ngtsc/core/api/src/options.ts @@ -8,7 +8,7 @@ import * as ts from 'typescript'; -import {BazelAndG3Options, I18nOptions, LegacyNgcOptions, MiscOptions, NgcCompatibilityOptions, StrictTemplateOptions} from './public_options'; +import {BazelAndG3Options, I18nOptions, LegacyNgcOptions, MiscOptions, NgcCompatibilityOptions, StrictTemplateOptions, TargetOptions} from './public_options'; /** @@ -36,22 +36,6 @@ export interface TestOnlyOptions { tracePerformance?: string; } -/** - * Options that specify compilation target. - */ -export interface TargetOptions { - /** - * Specifies the compilation mode to use. The following modes are available: - * - 'full': generates fully AOT compiled code using Ivy instructions. - * - 'partial': generates code in a stable, but intermediate form suitable to be published to NPM. - * - * To become public once the linker is ready. - * - * @internal - */ - compilationMode?: 'full'|'partial'; -} - /** * A merged interface of all of the various Angular compiler options, as well as the standard * `ts.CompilerOptions`. 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 115554b7d9..7af887196d 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 @@ -340,6 +340,22 @@ export interface I18nOptions { i18nNormalizeLineEndingsInICUs?: boolean; } +/** + * Options that specify compilation target. + * + * @publicApi + */ +export interface TargetOptions { + /** + * Specifies the compilation mode to use. The following modes are available: + * - 'full': generates fully AOT compiled code using Ivy instructions. + * - 'partial': generates code in a stable, but intermediate form suitable for publication to NPM. + * + * The default value is 'full'. + */ + compilationMode?: 'full'|'partial'; +} + /** * Miscellaneous options that don't fall into any other category *