refactor(compiler-cli): Add experimental local compilation mode. (#49846)

In this mode the compiler generates code based on each individual source file without using its dependencies. This mode is suitable only for fast edit/refresh during development.

PR Close #49846
This commit is contained in:
Payam Valadkhan
2023-04-23 18:19:35 -07:00
committed by Dylan Hunn
parent 27093a7167
commit 345dd6d81a
4 changed files with 25 additions and 5 deletions
@@ -73,7 +73,7 @@ export interface StrictTemplateOptions {
// @public // @public
export interface TargetOptions { export interface TargetOptions {
compilationMode?: 'full' | 'partial'; compilationMode?: 'full' | 'partial' | 'experimental-local';
} }
// (No @packageDocumentation comment for this package) // (No @packageDocumentation comment for this package)
@@ -383,10 +383,13 @@ export interface TargetOptions {
* Specifies the compilation mode to use. The following modes are available: * Specifies the compilation mode to use. The following modes are available:
* - 'full': generates fully AOT compiled code using Ivy instructions. * - 'full': generates fully AOT compiled code using Ivy instructions.
* - 'partial': generates code in a stable, but intermediate form suitable for publication to NPM. * - 'partial': generates code in a stable, but intermediate form suitable for publication to NPM.
* - 'experimental-local': generates code based on each individual source file without using its
* dependencies. This mode is suitable only for fast edit/refresh during development. It will be
* eventually replaced by the value `local` once the feature is ready to be public.
* *
* The default value is 'full'. * The default value is 'full'.
*/ */
compilationMode?: 'full'|'partial'; compilationMode?: 'full'|'partial'|'experimental-local';
} }
/** /**
@@ -1006,9 +1006,20 @@ export class NgCompiler {
// Note: If this compilation builds `@angular/core`, we always build in full compilation // Note: If this compilation builds `@angular/core`, we always build in full compilation
// mode. Code inside the core package is always compatible with itself, so it does not // mode. Code inside the core package is always compatible with itself, so it does not
// make sense to go through the indirection of partial compilation // make sense to go through the indirection of partial compilation
const compilationMode = this.options.compilationMode === 'partial' && !isCore ? let compilationMode: CompilationMode = CompilationMode.FULL;
CompilationMode.PARTIAL : if (!isCore) {
CompilationMode.FULL; switch (this.options.compilationMode) {
case 'full':
compilationMode = CompilationMode.FULL;
break;
case 'partial':
compilationMode = CompilationMode.PARTIAL;
break;
case 'experimental-local':
compilationMode = CompilationMode.LOCAL;
break;
}
}
// Cycles are handled in full compilation mode by "remote scoping". // Cycles are handled in full compilation mode by "remote scoping".
// "Remote scoping" does not work well with tree shaking for libraries. // "Remote scoping" does not work well with tree shaking for libraries.
@@ -31,6 +31,12 @@ export enum CompilationMode {
* Generates code using a stable, but intermediate format suitable to be published to NPM. * Generates code using a stable, but intermediate format suitable to be published to NPM.
*/ */
PARTIAL, PARTIAL,
/**
* Generates code based on each individual source file without using its
* dependencies (suitable for local dev edit/refresh workflow).
*/
LOCAL,
} }
export enum HandlerPrecedence { export enum HandlerPrecedence {