6
6
* Use of this source code is governed by an MIT-style license that can be
7
7
* found in the LICENSE file at https://angular.dev/license
8
8
*/
9
- var __importDefault = ( this && this . __importDefault ) || function ( mod ) {
10
- return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
11
- } ;
12
9
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
13
10
exports . buildEsbuildBrowser = buildEsbuildBrowser ;
14
- exports . buildEsbuildBrowserArchitect = buildEsbuildBrowserArchitect ;
15
- const private_1 = require ( "@angular/build/private " ) ;
11
+ exports . convertBrowserOptions = convertBrowserOptions ;
12
+ const build_1 = require ( "@angular/build" ) ;
16
13
const architect_1 = require ( "@angular-devkit/architect" ) ;
17
- const promises_1 = __importDefault ( require ( "node:fs/promises" ) ) ;
18
- const node_path_1 = __importDefault ( require ( "node:path" ) ) ;
19
14
const builder_status_warnings_1 = require ( "./builder-status-warnings" ) ;
20
15
/**
21
16
* Main execution function for the esbuild-based application builder.
@@ -27,55 +22,22 @@ const builder_status_warnings_1 = require("./builder-status-warnings");
27
22
async function * buildEsbuildBrowser ( userOptions , context , infrastructureSettings , plugins ) {
28
23
// Inform user of status of builder and options
29
24
( 0 , builder_status_warnings_1 . logBuilderStatusWarnings ) ( userOptions , context ) ;
30
- const normalizedOptions = normalizeOptions ( userOptions ) ;
31
- const { deleteOutputPath, outputPath } = normalizedOptions ;
32
- const fullOutputPath = node_path_1 . default . join ( context . workspaceRoot , outputPath . base ) ;
33
- if ( deleteOutputPath && infrastructureSettings ?. write !== false ) {
34
- await ( 0 , private_1 . deleteOutputDir ) ( context . workspaceRoot , outputPath . base ) ;
35
- }
36
- for await ( const result of ( 0 , private_1 . buildApplicationInternal ) ( normalizedOptions , context , plugins && { codePlugins : plugins } ) ) {
37
- // Write the file directly from this builder to maintain webpack output compatibility
38
- // and not output browser files into '/browser'.
39
- if ( infrastructureSettings ?. write !== false &&
40
- ( result . kind === private_1 . ResultKind . Full || result . kind === private_1 . ResultKind . Incremental ) ) {
41
- const directoryExists = new Set ( ) ;
42
- // Writes the output file to disk and ensures the containing directories are present
43
- await ( 0 , private_1 . emitFilesToDisk ) ( Object . entries ( result . files ) , async ( [ filePath , file ] ) => {
44
- // Ensure output subdirectories exist
45
- const basePath = node_path_1 . default . dirname ( filePath ) ;
46
- if ( basePath && ! directoryExists . has ( basePath ) ) {
47
- await promises_1 . default . mkdir ( node_path_1 . default . join ( fullOutputPath , basePath ) , { recursive : true } ) ;
48
- directoryExists . add ( basePath ) ;
49
- }
50
- if ( file . origin === 'memory' ) {
51
- // Write file contents
52
- await promises_1 . default . writeFile ( node_path_1 . default . join ( fullOutputPath , filePath ) , file . contents ) ;
53
- }
54
- else {
55
- // Copy file contents
56
- await promises_1 . default . copyFile ( file . inputPath , node_path_1 . default . join ( fullOutputPath , filePath ) , promises_1 . default . constants . COPYFILE_FICLONE ) ;
57
- }
58
- } ) ;
59
- }
60
- yield result ;
61
- }
25
+ const normalizedOptions = convertBrowserOptions ( userOptions ) ;
26
+ yield * ( 0 , build_1 . buildApplication ) ( normalizedOptions , context , { codePlugins : plugins } ) ;
62
27
}
63
- function normalizeOptions ( options ) {
64
- const { main : browser , outputPath, ngswConfigPath, serviceWorker, polyfills, ...otherOptions } = options ;
28
+ function convertBrowserOptions ( options ) {
29
+ const { main : browser , outputPath, ngswConfigPath, serviceWorker, polyfills, resourcesOutputPath , ...otherOptions } = options ;
65
30
return {
66
31
browser,
67
32
serviceWorker : serviceWorker ? ngswConfigPath : false ,
68
33
polyfills : typeof polyfills === 'string' ? [ polyfills ] : polyfills ,
69
34
outputPath : {
70
35
base : outputPath ,
71
36
browser : '' ,
37
+ server : '' ,
38
+ media : resourcesOutputPath ?? 'media' ,
72
39
} ,
73
40
...otherOptions ,
74
41
} ;
75
42
}
76
- async function * buildEsbuildBrowserArchitect ( options , context ) {
77
- for await ( const result of buildEsbuildBrowser ( options , context ) ) {
78
- yield { success : result . kind !== private_1 . ResultKind . Failure } ;
79
- }
80
- }
81
- exports . default = ( 0 , architect_1 . createBuilder ) ( buildEsbuildBrowserArchitect ) ;
43
+ exports . default = ( 0 , architect_1 . createBuilder ) ( buildEsbuildBrowser ) ;
0 commit comments