6
6
* found in the LICENSE file at https://angular.dev/license
7
7
*/
8
8
9
- import type { ApplicationBuilderOptions } from '@angular/build' ;
10
- import {
11
- Result ,
12
- ResultKind ,
13
- buildApplicationInternal ,
14
- deleteOutputDir ,
15
- emitFilesToDisk ,
16
- } from '@angular/build/private' ;
17
- import { BuilderContext , createBuilder } from '@angular-devkit/architect' ;
9
+ import { type ApplicationBuilderOptions , buildApplication } from '@angular/build' ;
10
+ import { BuilderContext , BuilderOutput , createBuilder } from '@angular-devkit/architect' ;
18
11
import type { Plugin } from 'esbuild' ;
19
- import fs from 'node:fs/promises' ;
20
- import path from 'node:path' ;
21
12
import { logBuilderStatusWarnings } from './builder-status-warnings' ;
22
13
import type { Schema as BrowserBuilderOptions } from './schema' ;
23
14
15
+ export type { BrowserBuilderOptions } ;
16
+
24
17
type OutputPathClass = Exclude < ApplicationBuilderOptions [ 'outputPath' ] , string | undefined > ;
25
18
26
19
/**
@@ -37,57 +30,15 @@ export async function* buildEsbuildBrowser(
37
30
write ?: boolean ;
38
31
} ,
39
32
plugins ?: Plugin [ ] ,
40
- ) : AsyncIterable < Result > {
33
+ ) : AsyncIterable < BuilderOutput > {
41
34
// Inform user of status of builder and options
42
35
logBuilderStatusWarnings ( userOptions , context ) ;
43
- const normalizedOptions = normalizeOptions ( userOptions ) ;
44
- const { deleteOutputPath, outputPath } = normalizedOptions ;
45
- const fullOutputPath = path . join ( context . workspaceRoot , outputPath . base ) ;
46
-
47
- if ( deleteOutputPath && infrastructureSettings ?. write !== false ) {
48
- await deleteOutputDir ( context . workspaceRoot , outputPath . base ) ;
49
- }
50
-
51
- for await ( const result of buildApplicationInternal (
52
- normalizedOptions ,
53
- context ,
54
- plugins && { codePlugins : plugins } ,
55
- ) ) {
56
- // Write the file directly from this builder to maintain webpack output compatibility
57
- // and not output browser files into '/browser'.
58
- if (
59
- infrastructureSettings ?. write !== false &&
60
- ( result . kind === ResultKind . Full || result . kind === ResultKind . Incremental )
61
- ) {
62
- const directoryExists = new Set < string > ( ) ;
63
- // Writes the output file to disk and ensures the containing directories are present
64
- await emitFilesToDisk ( Object . entries ( result . files ) , async ( [ filePath , file ] ) => {
65
- // Ensure output subdirectories exist
66
- const basePath = path . dirname ( filePath ) ;
67
- if ( basePath && ! directoryExists . has ( basePath ) ) {
68
- await fs . mkdir ( path . join ( fullOutputPath , basePath ) , { recursive : true } ) ;
69
- directoryExists . add ( basePath ) ;
70
- }
71
-
72
- if ( file . origin === 'memory' ) {
73
- // Write file contents
74
- await fs . writeFile ( path . join ( fullOutputPath , filePath ) , file . contents ) ;
75
- } else {
76
- // Copy file contents
77
- await fs . copyFile (
78
- file . inputPath ,
79
- path . join ( fullOutputPath , filePath ) ,
80
- fs . constants . COPYFILE_FICLONE ,
81
- ) ;
82
- }
83
- } ) ;
84
- }
85
36
86
- yield result ;
87
- }
37
+ const normalizedOptions = convertBrowserOptions ( userOptions ) ;
38
+ yield * buildApplication ( normalizedOptions , context , { codePlugins : plugins } ) ;
88
39
}
89
40
90
- function normalizeOptions (
41
+ export function convertBrowserOptions (
91
42
options : BrowserBuilderOptions ,
92
43
) : Omit < ApplicationBuilderOptions , 'outputPath' > & { outputPath : OutputPathClass } {
93
44
const {
@@ -96,6 +47,7 @@ function normalizeOptions(
96
47
ngswConfigPath,
97
48
serviceWorker,
98
49
polyfills,
50
+ resourcesOutputPath,
99
51
...otherOptions
100
52
} = options ;
101
53
@@ -106,18 +58,11 @@ function normalizeOptions(
106
58
outputPath : {
107
59
base : outputPath ,
108
60
browser : '' ,
61
+ server : '' ,
62
+ media : resourcesOutputPath ?? 'media' ,
109
63
} ,
110
64
...otherOptions ,
111
65
} ;
112
66
}
113
67
114
- export async function * buildEsbuildBrowserArchitect (
115
- options : BrowserBuilderOptions ,
116
- context : BuilderContext ,
117
- ) {
118
- for await ( const result of buildEsbuildBrowser ( options , context ) ) {
119
- yield { success : result . kind !== ResultKind . Failure } ;
120
- }
121
- }
122
-
123
- export default createBuilder < BrowserBuilderOptions > ( buildEsbuildBrowserArchitect ) ;
68
+ export default createBuilder < BrowserBuilderOptions > ( buildEsbuildBrowser ) ;
0 commit comments