@@ -201,12 +201,31 @@ async function initialize(
201201 i18n : I18nOptions ;
202202} > {
203203 const originalOutputPath = options . outputPath ;
204+
205+ // Assets are processed directly by the builder except when watching
206+ const adjustedOptions = options . watch ? options : { ...options , assets : [ ] } ;
207+
204208 const {
205209 config,
206210 projectRoot,
207211 projectSourceRoot,
208212 i18n,
209- } = await buildBrowserWebpackConfigFromContext ( options , context , host , true ) ;
213+ } = await buildBrowserWebpackConfigFromContext ( adjustedOptions , context , host , true ) ;
214+
215+ // Validate asset option values if processed directly
216+ if ( options . assets ?. length && ! adjustedOptions . assets ?. length ) {
217+ normalizeAssetPatterns (
218+ options . assets ,
219+ new virtualFs . SyncDelegateHost ( host ) ,
220+ normalize ( context . workspaceRoot ) ,
221+ normalize ( projectRoot ) ,
222+ projectSourceRoot === undefined ? undefined : normalize ( projectSourceRoot ) ,
223+ ) . forEach ( ( { output } ) => {
224+ if ( output . startsWith ( '..' ) ) {
225+ throw new Error ( 'An asset cannot be written to a location outside of the output path.' ) ;
226+ }
227+ } ) ;
228+ }
210229
211230 let transformedConfig ;
212231 if ( webpackConfigurationTransform ) {
@@ -573,27 +592,6 @@ export function buildWebpackBrowser(
573592 executor . stop ( ) ;
574593 }
575594
576- // Copy assets
577- if ( options . assets ) {
578- try {
579- await copyAssets (
580- normalizeAssetPatterns (
581- options . assets ,
582- new virtualFs . SyncDelegateHost ( host ) ,
583- root ,
584- normalize ( projectRoot ) ,
585- projectSourceRoot === undefined ? undefined : normalize ( projectSourceRoot ) ,
586- ) ,
587- Array . from ( outputPaths . values ( ) ) ,
588- context . workspaceRoot ,
589- ) ;
590- } catch ( err ) {
591- context . logger . error ( 'Unable to copy assets: ' + err . message ) ;
592-
593- return { success : false } ;
594- }
595- }
596-
597595 type ArrayElement < A > = A extends ReadonlyArray < infer T > ? T : never ;
598596 function generateBundleInfoStats (
599597 id : string | number ,
@@ -698,6 +696,27 @@ export function buildWebpackBrowser(
698696 }
699697 }
700698
699+ // Copy assets
700+ if ( ! options . watch && options . assets ) {
701+ try {
702+ await copyAssets (
703+ normalizeAssetPatterns (
704+ options . assets ,
705+ new virtualFs . SyncDelegateHost ( host ) ,
706+ root ,
707+ normalize ( projectRoot ) ,
708+ projectSourceRoot === undefined ? undefined : normalize ( projectSourceRoot ) ,
709+ ) ,
710+ Array . from ( outputPaths . values ( ) ) ,
711+ context . workspaceRoot ,
712+ ) ;
713+ } catch ( err ) {
714+ context . logger . error ( 'Unable to copy assets: ' + err . message ) ;
715+
716+ return { success : false } ;
717+ }
718+ }
719+
701720 if ( options . index ) {
702721 for ( const [ locale , outputPath ] of outputPaths . entries ( ) ) {
703722 let localeBaseHref ;
0 commit comments