66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- import type { FormatMessagesOptions , PartialMessage , TransformOptions , TransformResult } from 'esbuild' ;
9+ import type {
10+ BuildOptions ,
11+ BuildResult ,
12+ FormatMessagesOptions ,
13+ PartialMessage ,
14+ TransformOptions ,
15+ TransformResult ,
16+ } from 'esbuild' ;
1017
1118/**
1219 * Provides the ability to execute esbuild regardless of the current platform's support
@@ -17,6 +24,7 @@ import type { FormatMessagesOptions, PartialMessage, TransformOptions, Transform
1724 */
1825export class EsbuildExecutor implements Pick < typeof import ( 'esbuild' ) , 'transform' | 'formatMessages' > {
1926 private esbuildTransform : this[ 'transform' ] ;
27+ private esbuildBuild : this[ 'build' ] ;
2028 private esbuildFormatMessages : this[ 'formatMessages' ] ;
2129 private initialized = false ;
2230
@@ -27,9 +35,12 @@ export class EsbuildExecutor implements Pick<typeof import('esbuild'), 'transfor
2735 * performed; if false (default), the native variant will be preferred.
2836 */
2937 constructor ( private alwaysUseWasm = false ) {
30- this . esbuildTransform = this . esbuildFormatMessages = ( ) => {
31- throw new Error ( 'esbuild implementation missing' ) ;
32- } ;
38+ this . esbuildBuild =
39+ this . esbuildTransform =
40+ this . esbuildFormatMessages =
41+ ( ) => {
42+ throw new Error ( 'esbuild implementation missing' ) ;
43+ } ;
3344 }
3445
3546 /**
@@ -68,10 +79,11 @@ export class EsbuildExecutor implements Pick<typeof import('esbuild'), 'transfor
6879
6980 try {
7081 // Use the faster native variant if available.
71- const { transform, formatMessages } = await import ( 'esbuild' ) ;
82+ const { transform, build , formatMessages } = await import ( 'esbuild' ) ;
7283
7384 this . esbuildTransform = transform ;
7485 this . esbuildFormatMessages = formatMessages ;
86+ this . esbuildBuild = build ;
7587 } catch {
7688 // If the native variant is not installed then use the WASM-based variant
7789 await this . useWasm ( ) ;
@@ -84,9 +96,10 @@ export class EsbuildExecutor implements Pick<typeof import('esbuild'), 'transfor
8496 * Transitions an executor instance to use the WASM-variant of esbuild.
8597 */
8698 private async useWasm ( ) : Promise < void > {
87- const { transform, formatMessages } = await import ( 'esbuild-wasm' ) ;
99+ const { transform, build , formatMessages } = await import ( 'esbuild-wasm' ) ;
88100 this . esbuildTransform = transform ;
89101 this . esbuildFormatMessages = formatMessages ;
102+ this . esbuildBuild = build ;
90103
91104 // The ESBUILD_BINARY_PATH environment variable cannot exist when attempting to use the
92105 // WASM variant. If it is then the binary located at the specified path will be used instead
@@ -102,6 +115,12 @@ export class EsbuildExecutor implements Pick<typeof import('esbuild'), 'transfor
102115 return this . esbuildTransform ( input , options ) ;
103116 }
104117
118+ async build ( options : BuildOptions ) : Promise < BuildResult > {
119+ await this . ensureEsbuild ( ) ;
120+
121+ return this . esbuildBuild ( options ) ;
122+ }
123+
105124 async formatMessages ( messages : PartialMessage [ ] , options : FormatMessagesOptions ) : Promise < string [ ] > {
106125 await this . ensureEsbuild ( ) ;
107126
0 commit comments