@@ -15,7 +15,8 @@ use tracing::instrument;
1515pub use self :: rebuild:: CompilationRecords ;
1616use crate :: {
1717 BoxPlugin , CleanOptions , Compilation , CompilationAsset , CompilerOptions , ContextModuleFactory ,
18- KeepPattern , Logger , NormalModuleFactory , PluginDriver , ResolverFactory , SharedPluginDriver ,
18+ Filename , KeepPattern , Logger , NormalModuleFactory , PluginDriver , ResolverFactory ,
19+ SharedPluginDriver ,
1920 cache:: { Cache , new_cache} ,
2021 compilation:: make:: ModuleExecutor ,
2122 fast_set, include_hash,
@@ -349,7 +350,15 @@ impl Compiler {
349350
350351 #[ instrument( "emit_assets" , skip_all) ]
351352 pub async fn emit_assets ( & mut self ) -> Result < ( ) > {
352- self . run_clean_options ( ) . await ?;
353+ let output_path_str = self
354+ . compilation
355+ . get_path (
356+ & Filename :: from ( & self . options . output . path ) ,
357+ Default :: default ( ) ,
358+ )
359+ . await ?;
360+ let output_path = Utf8Path :: new ( & output_path_str) ;
361+ self . run_clean_options ( output_path) . await ?;
353362
354363 self
355364 . plugin_driver
@@ -383,10 +392,10 @@ impl Compiler {
383392 }
384393
385394 // SAFETY: await immediately and trust caller to poll future entirely
386- let s = unsafe { token. used ( ( & self , filename, asset) ) } ;
395+ let s = unsafe { token. used ( ( & self , filename, asset, output_path ) ) } ;
387396
388- s. spawn ( |( this, filename, asset) | {
389- this. emit_asset ( & this . options . output . path , filename, asset)
397+ s. spawn ( |( this, filename, asset, output_path ) | {
398+ this. emit_asset ( output_path , filename, asset)
390399 } ) ;
391400 } )
392401 } )
@@ -480,7 +489,7 @@ impl Compiler {
480489 Ok ( ( ) )
481490 }
482491
483- async fn run_clean_options ( & mut self ) -> Result < ( ) > {
492+ async fn run_clean_options ( & mut self , output_path : & Utf8Path ) -> Result < ( ) > {
484493 let clean_options = & self . options . output . clean ;
485494
486495 // keep all
@@ -491,37 +500,24 @@ impl Compiler {
491500 if self . emitted_asset_versions . is_empty ( ) {
492501 match clean_options {
493502 CleanOptions :: CleanAll ( true ) => {
494- self
495- . output_filesystem
496- . remove_dir_all ( & self . options . output . path )
497- . await ?;
503+ self . output_filesystem . remove_dir_all ( output_path) . await ?;
498504 }
499505 CleanOptions :: KeepPath ( p) => {
500- let path = self . options . output . path . join ( p) ;
506+ let path = output_path . join ( p) ;
501507 trim_dir (
502508 & * self . output_filesystem ,
503- & self . options . output . path ,
509+ output_path ,
504510 KeepPattern :: Path ( & path) ,
505511 )
506512 . await ?;
507513 }
508514 CleanOptions :: KeepRegex ( r) => {
509515 let keep_pattern = KeepPattern :: Regex ( r) ;
510- trim_dir (
511- & * self . output_filesystem ,
512- & self . options . output . path ,
513- keep_pattern,
514- )
515- . await ?;
516+ trim_dir ( & * self . output_filesystem , output_path, keep_pattern) . await ?;
516517 }
517518 CleanOptions :: KeepFunc ( f) => {
518519 let keep_pattern = KeepPattern :: Func ( f) ;
519- trim_dir (
520- & * self . output_filesystem ,
521- & self . options . output . path ,
522- keep_pattern,
523- )
524- . await ?;
520+ trim_dir ( & * self . output_filesystem , output_path, keep_pattern) . await ?;
525521 }
526522 _ => { }
527523 }
@@ -539,7 +535,7 @@ impl Compiler {
539535 let filename = filename. to_owned ( ) ;
540536 Some ( async {
541537 if !clean_options. keep ( & filename) . await {
542- let filename = Utf8Path :: new ( & self . options . output . path ) . join ( filename) ;
538+ let filename = output_path . join ( filename) ;
543539 let _ = self . output_filesystem . remove_file ( & filename) . await ;
544540 }
545541 } )
0 commit comments