@@ -21,12 +21,7 @@ import { createHash } from 'node:crypto';
2121import * as path from 'node:path' ;
2222import { maxWorkers , useTypeChecking } from '../../../utils/environment-options' ;
2323import { AngularHostOptions } from '../../angular/angular-host' ;
24- import {
25- AngularCompilation ,
26- DiagnosticModes ,
27- NoopCompilation ,
28- createAngularCompilation ,
29- } from '../../angular/compilation' ;
24+ import { AngularCompilation , DiagnosticModes , NoopCompilation } from '../../angular/compilation' ;
3025import { JavaScriptTransformer } from '../javascript-transformer' ;
3126import { LoadResultCache , createCachedLoad } from '../load-result-cache' ;
3227import { logCumulativeDurations , profileAsync , resetCumulativeDurations } from '../profiling' ;
@@ -40,10 +35,7 @@ export interface CompilerPluginOptions {
4035 sourcemap : boolean | 'external' ;
4136 tsconfig : string ;
4237 jit ?: boolean ;
43- browserOnlyBuild ?: boolean ;
4438
45- /** Skip TypeScript compilation setup. This is useful to re-use the TypeScript compilation from another plugin. */
46- noopTypeScriptCompilation ?: boolean ;
4739 advancedOptimizations ?: boolean ;
4840 thirdPartySourcemaps ?: boolean ;
4941 fileReplacements ?: Record < string , string > ;
@@ -58,6 +50,7 @@ export interface CompilerPluginOptions {
5850// eslint-disable-next-line max-lines-per-function
5951export function createCompilerPlugin (
6052 pluginOptions : CompilerPluginOptions ,
53+ compilationOrFactory : AngularCompilation | ( ( ) => Promise < AngularCompilation > ) ,
6154 stylesheetBundler : ComponentStylesheetBundler ,
6255) : Plugin {
6356 return {
@@ -105,6 +98,13 @@ export function createCompilerPlugin(
10598 build . initialOptions . define ??= { } ;
10699 build . initialOptions . define [ 'ngI18nClosureMode' ] ??= 'false' ;
107100
101+ // The factory is only relevant for compatibility purposes with the private API.
102+ // TODO: Update private API in the next major to allow compilation function factory removal here.
103+ const compilation =
104+ typeof compilationOrFactory === 'function'
105+ ? await compilationOrFactory ( )
106+ : compilationOrFactory ;
107+
108108 // The in-memory cache of TypeScript file outputs will be used during the build in `onLoad` callbacks for TS files.
109109 // A string value indicates direct TS/NG output and a Uint8Array indicates fully transformed code.
110110 const typeScriptFileCache =
@@ -117,10 +117,6 @@ export function createCompilerPlugin(
117117 { outputFiles ?: OutputFile [ ] ; metafile ?: Metafile ; errors ?: PartialMessage [ ] }
118118 > ( ) ;
119119
120- // Create new reusable compilation for the appropriate mode based on the `jit` plugin option
121- const compilation : AngularCompilation = pluginOptions . noopTypeScriptCompilation
122- ? new NoopCompilation ( )
123- : await createAngularCompilation ( ! ! pluginOptions . jit , ! ! pluginOptions . browserOnlyBuild ) ;
124120 // Compilation is initially assumed to have errors until emitted
125121 let hasCompilationErrors = true ;
126122
@@ -153,8 +149,8 @@ export function createCompilerPlugin(
153149 // dependencies or web worker processing.
154150 let modifiedFiles ;
155151 if (
156- pluginOptions . sourceFileCache ?. modifiedFiles . size &&
157- ! pluginOptions . noopTypeScriptCompilation
152+ ! ( compilation instanceof NoopCompilation ) &&
153+ pluginOptions . sourceFileCache ?. modifiedFiles . size
158154 ) {
159155 // TODO: Differentiate between changed input files and stale output files
160156 modifiedFiles = referencedFileTracker . update ( pluginOptions . sourceFileCache . modifiedFiles ) ;
@@ -168,11 +164,7 @@ export function createCompilerPlugin(
168164 modifiedFiles . forEach ( ( file ) => additionalResults . delete ( file ) ) ;
169165 }
170166
171- if (
172- ! pluginOptions . noopTypeScriptCompilation &&
173- compilation . update &&
174- pluginOptions . sourceFileCache ?. modifiedFiles . size
175- ) {
167+ if ( compilation . update && pluginOptions . sourceFileCache ?. modifiedFiles . size ) {
176168 await compilation . update ( modifiedFiles ?? pluginOptions . sourceFileCache . modifiedFiles ) ;
177169 }
178170
0 commit comments