@@ -12,6 +12,8 @@ import { constants as fsConstants } from 'node:fs';
12
12
import fs from 'node:fs/promises' ;
13
13
import path from 'node:path' ;
14
14
import { BuildOutputFile } from '../../tools/esbuild/bundler-context' ;
15
+ import { BuildOutputAsset } from '../../tools/esbuild/bundler-execution-result' ;
16
+ import { emitFilesToDisk } from '../../tools/esbuild/utils' ;
15
17
import { buildApplicationInternal } from '../application' ;
16
18
import { Schema as ApplicationBuilderOptions } from '../application/schema' ;
17
19
import { logBuilderStatusWarnings } from './builder-status-warnings' ;
@@ -74,36 +76,37 @@ function normalizeOptions(options: BrowserBuilderOptions): ApplicationBuilderOpt
74
76
// and not output browser files into '/browser'.
75
77
async function writeResultFiles (
76
78
outputFiles : BuildOutputFile [ ] ,
77
- assetFiles : { source : string ; destination : string } [ ] | undefined ,
79
+ assetFiles : BuildOutputAsset [ ] | undefined ,
78
80
outputPath : string ,
79
81
) {
80
82
const directoryExists = new Set < string > ( ) ;
81
- await Promise . all (
82
- outputFiles . map ( async ( file ) => {
83
- // Ensure output subdirectories exist
84
- const basePath = path . dirname ( file . path ) ;
85
- if ( basePath && ! directoryExists . has ( basePath ) ) {
86
- await fs . mkdir ( path . join ( outputPath , basePath ) , { recursive : true } ) ;
87
- directoryExists . add ( basePath ) ;
88
- }
89
- // Write file contents
90
- await fs . writeFile ( path . join ( outputPath , file . path ) , file . contents ) ;
91
- } ) ,
92
- ) ;
83
+ const ensureDirectoryExists = async ( basePath : string ) => {
84
+ if ( basePath && ! directoryExists . has ( basePath ) ) {
85
+ await fs . mkdir ( path . join ( outputPath , basePath ) , { recursive : true } ) ;
86
+ directoryExists . add ( basePath ) ;
87
+ }
88
+ } ;
89
+
90
+ // Writes the output file to disk and ensures the containing directories are present
91
+ await emitFilesToDisk ( outputFiles , async ( file : BuildOutputFile ) => {
92
+ // Ensure output subdirectories exist
93
+ const basePath = path . dirname ( file . path ) ;
94
+ await ensureDirectoryExists ( basePath ) ;
95
+
96
+ // Write file contents
97
+ await fs . writeFile ( path . join ( outputPath , file . path ) , file . contents ) ;
98
+ } ) ;
93
99
94
100
if ( assetFiles ?. length ) {
95
- await Promise . all (
96
- assetFiles . map ( async ( { source, destination } ) => {
97
- // Ensure output subdirectories exist
98
- const basePath = path . dirname ( destination ) ;
99
- if ( basePath && ! directoryExists . has ( basePath ) ) {
100
- await fs . mkdir ( path . join ( outputPath , basePath ) , { recursive : true } ) ;
101
- directoryExists . add ( basePath ) ;
102
- }
103
- // Copy file contents
104
- await fs . copyFile ( source , path . join ( outputPath ) , fsConstants . COPYFILE_FICLONE ) ;
105
- } ) ,
106
- ) ;
101
+ await emitFilesToDisk ( assetFiles , async ( { source, destination } ) => {
102
+ const basePath = path . dirname ( destination ) ;
103
+
104
+ // Ensure output subdirectories exist
105
+ await ensureDirectoryExists ( basePath ) ;
106
+
107
+ // Copy file contents
108
+ await fs . copyFile ( source , path . join ( outputPath , destination ) , fsConstants . COPYFILE_FICLONE ) ;
109
+ } ) ;
107
110
}
108
111
}
109
112
0 commit comments