@@ -29,7 +29,7 @@ fn remove_iast(package: &packages::Package, source_file: &Path) {
2929 ) ) ;
3030}
3131
32- fn remove_mjs_file ( source_file : & Path , suffix : & String ) {
32+ fn remove_mjs_file ( source_file : & Path , suffix : & str ) {
3333 let _ = std:: fs:: remove_file ( source_file. with_extension (
3434 // suffix.to_string includes the ., so we need to remove it
3535 & suffix. to_string ( ) [ 1 ..] ,
@@ -59,36 +59,51 @@ pub fn remove_compile_assets(package: &packages::Package, source_file: &Path) {
5959 }
6060}
6161
62- fn clean_source_files ( build_state : & BuildState , root_package : & packages:: Package ) {
62+ fn clean_source_files (
63+ build_state : & BuildState ,
64+ // If the root_package is part of a workspace, we only want to clean that package,
65+ // not the entire build_state modules.
66+ workspace_has_root_config : bool ,
67+ root_package : & Package ,
68+ suffix : & str ,
69+ ) {
6370 // get all rescript file locations
6471 let rescript_file_locations = build_state
6572 . modules
6673 . values ( )
6774 . filter_map ( |module| match & module. source_type {
6875 SourceType :: SourceFile ( source_file) => {
69- let package = build_state. packages . get ( & module. package_name ) . unwrap ( ) ;
70- Some (
71- root_package
72- . config
73- . get_package_specs ( )
74- . iter ( )
75- . filter_map ( |spec| {
76- if spec. in_source {
77- Some ( (
78- package. path . join ( & source_file. implementation . path ) ,
79- root_package. config . get_suffix ( spec) ,
80- ) )
81- } else {
82- None
83- }
84- } )
85- . collect :: < Vec < ( PathBuf , String ) > > ( ) ,
86- )
76+ if !workspace_has_root_config || module. package_name == root_package. name
77+ {
78+ let package = build_state. packages . get ( & module. package_name ) . unwrap ( ) ;
79+ Some (
80+ root_package
81+ . config
82+ . get_package_specs ( )
83+ . iter ( )
84+ . filter_map ( |spec| {
85+ if spec. in_source {
86+ Some ( (
87+ package. path . join ( & source_file. implementation . path ) ,
88+ match & root_package. config . suffix {
89+ None => suffix,
90+ Some ( sfx) => sfx,
91+ } ,
92+ ) )
93+ } else {
94+ None
95+ }
96+ } )
97+ . collect :: < Vec < ( PathBuf , & str ) > > ( ) ,
98+ )
99+ } else {
100+ None
101+ }
87102 }
88103 _ => None ,
89104 } )
90105 . flatten ( )
91- . collect :: < Vec < ( PathBuf , String ) > > ( ) ;
106+ . collect :: < Vec < ( PathBuf , & str ) > > ( ) ;
92107
93108 rescript_file_locations
94109 . par_iter ( )
@@ -352,15 +367,20 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool, build_dev_
352367 ) ;
353368 let _ = std:: io:: stdout ( ) . flush ( ) ;
354369 } ;
355- match & workspace_root {
356- Some ( _) => {
357- // There is a workspace detected, so will only clean the current package
370+
371+ let mut workspace_has_root_config = false ;
372+ match & workspace_config_name {
373+ Some ( workspace_config_name) if packages. contains_key ( workspace_config_name) => {
374+ // The workspace package was found in the packages.
375+ // This means that the root_config and workspace_config have a parent/child relationship.
376+ // So we only want to clean the root package in this case.
358377 let package = packages
359378 . get ( & root_config_name)
360379 . expect ( "Could not find package during clean" ) ;
361380 clean_package ( show_progress, snapshot_output, package) ;
381+ workspace_has_root_config = true ;
362382 }
363- None => {
383+ _ => {
364384 packages. iter ( ) . for_each ( |( _, package) | {
365385 clean_package ( show_progress, snapshot_output, package) ;
366386 } ) ;
@@ -421,7 +441,7 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool, build_dev_
421441 let _ = std:: io:: stdout ( ) . flush ( ) ;
422442 }
423443
424- clean_source_files ( & build_state, root_package) ;
444+ clean_source_files ( & build_state, workspace_has_root_config , root_package, suffix ) ;
425445 let timing_clean_mjs_elapsed = timing_clean_mjs. elapsed ( ) ;
426446
427447 if !snapshot_output && show_progress {
0 commit comments