Skip to content

Commit 98cdcc2

Browse files
committed
Add test to ensure we clean dev-dependency with --dev.
1 parent c87fa26 commit 98cdcc2

File tree

2 files changed

+46
-30
lines changed

2 files changed

+46
-30
lines changed

rewatch/src/build/clean.rs

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ pub fn remove_compile_assets(package: &packages::Package, source_file: &Path) {
6060
}
6161
}
6262

63-
fn clean_source_files(build_state: &BuildState, root_package: &Package, suffix: &str, clean_dev_deps: bool) {
64-
let packages_to_clean = build_state
65-
.project_context
66-
.get_scoped_local_packages(clean_dev_deps);
67-
63+
fn clean_source_files(
64+
build_state: &BuildState,
65+
root_package: &Package,
66+
suffix: &str,
67+
packages_to_clean: &AHashSet<String>,
68+
) {
6869
// get all rescript file locations
6970
let rescript_file_locations = build_state
7071
.modules
@@ -369,30 +370,10 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool, clean_dev_
369370
let _ = std::io::stdout().flush();
370371
};
371372

372-
match &project_context {
373-
ProjectContext::SingleProject { config, .. } => {
374-
find_and_clean_package(&packages, &config.name, show_progress, snapshot_output)?;
375-
}
376-
ProjectContext::MonorepoRoot {
377-
config,
378-
local_dependencies,
379-
..
380-
} => {
381-
find_and_clean_package(&packages, &config.name, show_progress, snapshot_output)?;
382-
// TODO: this does the local dependencies and dev-dependencies.
383-
// I guess the dev deps should be cleaned if flag is set?
384-
for dep in local_dependencies {
385-
find_and_clean_package(&packages, dep, show_progress, snapshot_output)?;
386-
}
387-
}
388-
ProjectContext::MonorepoPackage { config, .. } => {
389-
// We know we are in a monorepo, but we only clean the package that is being targeted.
390-
let package = packages
391-
.get(&config.name)
392-
.expect("Could not find package during clean");
393-
clean_package(show_progress, snapshot_output, package);
394-
}
395-
};
373+
let packages_to_clean = project_context.get_scoped_local_packages(clean_dev_deps);
374+
for package in &packages_to_clean {
375+
find_and_clean_package(&packages, package, show_progress, snapshot_output)?;
376+
}
396377

397378
let timing_clean_compiler_assets_elapsed = timing_clean_compiler_assets.elapsed();
398379

@@ -423,7 +404,7 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool, clean_dev_
423404
let _ = std::io::stdout().flush();
424405
}
425406

426-
clean_source_files(&build_state, root_package, &suffix, clean_dev_deps);
407+
clean_source_files(&build_state, root_package, &suffix, &packages_to_clean);
427408
let timing_clean_mjs_elapsed = timing_clean_mjs.elapsed();
428409

429410
if !snapshot_output && show_progress {

rewatch/tests/clean.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,39 @@ then
4646
else
4747
error "Expected files from new-namespace not to be cleaned"
4848
exit 1
49+
fi
50+
51+
bold "--dev should clean dev-dependencies of monorepo"
52+
53+
# First we build the entire monorepo (including --dev)
54+
error_output=$(rewatch build --dev 2>&1)
55+
if [ $? -eq 0 ];
56+
then
57+
success "Built monorepo"
58+
else
59+
error "Error building monorepo"
60+
printf "%s\n" "$error_output" >&2
61+
exit 1
62+
fi
63+
64+
# Clean entire monorepo (including --dev)
65+
error_output=$(rewatch clean --dev 2>&1)
66+
clean_status=$?
67+
if [ $clean_status -ne 0 ];
68+
then
69+
error "Error cleaning current project file-casing"
70+
printf "%s\n" "$error_output" >&2
71+
exit 1
72+
fi
73+
74+
# Count compiled files in dev-dependency project "pure-dev"
75+
project_compiled_files=$(find packages/pure-dev -type f -name '*.mjs' | wc -l | tr -d '[:space:]')
76+
if [ "$project_compiled_files" -eq 0 ];
77+
then
78+
success "pure-dev cleaned"
79+
git restore .
80+
else
81+
error "Expected 0 .mjs files in pure-dev after clean, got $project_compiled_files"
82+
printf "%s\n" "$error_output"
83+
exit 1
4984
fi

0 commit comments

Comments
 (0)