|
1 | 1 | use super::build_types::*; |
2 | 2 | use super::packages; |
3 | | -use crate::build; |
4 | 3 | use crate::build::packages::Package; |
5 | | -use crate::config::{Config, SourceMapCommand}; |
| 4 | +use crate::config::Config; |
6 | 5 | use crate::helpers; |
7 | 6 | use crate::helpers::emojis::*; |
8 | 7 | use crate::project_context::ProjectContext; |
9 | | -use ahash::AHashSet; |
| 8 | +use ahash::{AHashMap, AHashSet}; |
10 | 9 | use anyhow::Result; |
11 | 10 | use console::style; |
12 | 11 | use rayon::prelude::*; |
@@ -68,36 +67,32 @@ pub fn remove_compile_assets(package: &packages::Package, source_file: &Path) { |
68 | 67 | } |
69 | 68 | } |
70 | 69 |
|
71 | | -fn clean_source_files(build_state: &BuildState, root_config: &Config) { |
72 | | - // get all rescript file locations |
73 | | - let rescript_file_locations = build_state |
74 | | - .modules |
| 70 | +fn clean_source_files(packages: &AHashMap<String, Package>, root_config: &Config) { |
| 71 | + let rescript_file_locations = packages |
75 | 72 | .values() |
76 | | - .filter_map(|module| match &module.source_type { |
77 | | - SourceType::SourceFile(source_file) => { |
78 | | - build_state.packages.get(&module.package_name).map(|package| { |
| 73 | + .filter_map(|package| package.source_files.as_ref().map(|files| (package, files))) |
| 74 | + .flat_map(|(package, files)| { |
| 75 | + files |
| 76 | + .keys() |
| 77 | + .filter(|file| { |
| 78 | + file.extension() |
| 79 | + .and_then(|extension| extension.to_str()) |
| 80 | + .is_some_and(helpers::is_implementation_file) |
| 81 | + }) |
| 82 | + .flat_map(move |file| { |
79 | 83 | root_config |
80 | 84 | .get_package_specs() |
81 | 85 | .into_iter() |
82 | | - .filter_map(|spec| { |
83 | | - if spec.in_source { |
84 | | - Some(( |
85 | | - package.path.join(&source_file.implementation.path), |
86 | | - match spec.suffix { |
87 | | - None => root_config.get_suffix(&spec), |
88 | | - Some(suffix) => suffix, |
89 | | - }, |
90 | | - )) |
91 | | - } else { |
92 | | - None |
93 | | - } |
| 86 | + .filter(|spec| spec.in_source) |
| 87 | + .map(move |spec| { |
| 88 | + let suffix = match spec.suffix { |
| 89 | + None => root_config.get_suffix(&spec), |
| 90 | + Some(suffix) => suffix, |
| 91 | + }; |
| 92 | + (package.path.join(file), suffix) |
94 | 93 | }) |
95 | | - .collect::<Vec<(PathBuf, String)>>() |
96 | 94 | }) |
97 | | - } |
98 | | - _ => None, |
99 | 95 | }) |
100 | | - .flatten() |
101 | 96 | .collect::<Vec<(PathBuf, String)>>(); |
102 | 97 |
|
103 | 98 | rescript_file_locations |
@@ -342,7 +337,6 @@ pub fn cleanup_after_build(build_state: &BuildCommandState) { |
342 | 337 | #[instrument(name = "clean.clean", skip_all)] |
343 | 338 | pub fn clean(path: &Path, show_progress: bool, plain_output: bool, prod: bool) -> Result<()> { |
344 | 339 | let project_context = ProjectContext::new(path)?; |
345 | | - let compiler_info = build::get_compiler_info(&project_context)?; |
346 | 340 | // `clean` always acts on the full set of source directories regardless of which features are |
347 | 341 | // active. We explicitly pass `None` so every tagged source folder is included and its |
348 | 342 | // artifacts can be removed, even for features the user hasn't enabled for this build. |
@@ -376,9 +370,7 @@ pub fn clean(path: &Path, show_progress: bool, plain_output: bool, prod: bool) - |
376 | 370 | } |
377 | 371 |
|
378 | 372 | let timing_clean_mjs = Instant::now(); |
379 | | - let mut build_state = BuildState::new(project_context, packages, compiler_info, SourceMapCommand::Build); |
380 | | - packages::parse_packages(&mut build_state)?; |
381 | | - let root_config = build_state.get_root_config(); |
| 373 | + let root_config = project_context.get_root_config(); |
382 | 374 | let suffix_for_print = match root_config.package_specs { |
383 | 375 | None => match &root_config.suffix { |
384 | 376 | None => String::from(".js"), |
@@ -408,7 +400,7 @@ pub fn clean(path: &Path, show_progress: bool, plain_output: bool, prod: bool) - |
408 | 400 | let _ = std::io::stdout().flush(); |
409 | 401 | } |
410 | 402 |
|
411 | | - clean_source_files(&build_state, root_config); |
| 403 | + clean_source_files(&packages, root_config); |
412 | 404 | let timing_clean_mjs_elapsed = timing_clean_mjs.elapsed(); |
413 | 405 |
|
414 | 406 | if !plain_output && show_progress { |
|
0 commit comments