Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

- `rescript format` now has a `--dev` flag that works similar to `rescript clean`. https://github.com/rescript-lang/rescript/pull/7752
- `rescript clean` now will clean an individual project (see [#7707](https://github.com/rescript-lang/rescript/issues/7707)). https://github.com/rescript-lang/rescript/pull/7752
- `rescript clean` will log multiple `in-source` extensions if present. https://github.com/rescript-lang/rescript/pull/7769

#### :house: Internal

Expand Down
33 changes: 27 additions & 6 deletions rewatch/src/build/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn remove_compile_assets(package: &packages::Package, source_file: &Path) {
}
}

fn clean_source_files(build_state: &BuildState, root_config: &Config, suffix: &str) {
fn clean_source_files(build_state: &BuildState, root_config: &Config) {
// get all rescript file locations
let rescript_file_locations = build_state
.modules
Expand All @@ -77,7 +77,7 @@ fn clean_source_files(build_state: &BuildState, root_config: &Config, suffix: &s
Some((
package.path.join(&source_file.implementation.path),
match spec.suffix {
None => suffix.to_owned(),
None => root_config.get_suffix(&spec),
Some(suffix) => suffix,
},
))
Expand Down Expand Up @@ -367,19 +367,40 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool, clean_dev_
let mut build_state = BuildState::new(project_context, packages, bsc_path);
packages::parse_packages(&mut build_state);
let root_config = build_state.get_root_config();
let suffix = build_state.project_context.get_suffix();
let suffix_for_print = if snapshot_output || !show_progress {
String::new()
} else {
match root_config.package_specs {
None => match &root_config.suffix {
None => String::from(".js"),
Some(suffix) => suffix.clone(),
},
Some(_) => root_config
.get_package_specs()
.into_iter()
.filter_map(|spec| {
if spec.in_source {
spec.suffix.or_else(|| root_config.suffix.clone())
} else {
None
}
})
.collect::<Vec<String>>()
.join(", "),
}
};

if !snapshot_output && show_progress {
println!(
"{} {}Cleaning {} files...",
style("[2/2]").bold().dim(),
SWEEP,
suffix
suffix_for_print
);
let _ = std::io::stdout().flush();
}

clean_source_files(&build_state, root_config, &suffix);
clean_source_files(&build_state, root_config);
let timing_clean_mjs_elapsed = timing_clean_mjs.elapsed();

if !snapshot_output && show_progress {
Expand All @@ -388,7 +409,7 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool, clean_dev_
LINE_CLEAR,
style("[2/2]").bold().dim(),
SWEEP,
suffix,
suffix_for_print,
timing_clean_mjs_elapsed.as_secs_f64()
);
let _ = std::io::stdout().flush();
Expand Down
7 changes: 0 additions & 7 deletions rewatch/src/project_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,6 @@ impl ProjectContext {
self.get_root_config().path.parent().unwrap()
}

pub fn get_suffix(&self) -> String {
self.get_root_config()
.suffix
.clone()
.unwrap_or(String::from(".res.mjs"))
}

/// Returns the local packages relevant for the current context.
/// Either a single project, all projects from a monorepo or a single package inside a monorepo.
pub fn get_scoped_local_packages(&self, include_dev_deps: bool) -> AHashSet<String> {
Expand Down
Loading