diff --git a/CHANGELOG.md b/CHANGELOG.md index 343a2affd2..b24b5783f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,7 @@ #### :bug: Bug fix - Fix `typeof` parens on functions. https://github.com/rescript-lang/rescript/pull/7643 - +- Add --dev flag to clean command. https://github.com/rescript-lang/rescript/pull/7622 # 12.0.0-beta.1 diff --git a/rewatch/src/build/clean.rs b/rewatch/src/build/clean.rs index da1543b2f9..4cd52a4759 100644 --- a/rewatch/src/build/clean.rs +++ b/rewatch/src/build/clean.rs @@ -331,7 +331,7 @@ pub fn cleanup_after_build(build_state: &BuildState) { }); } -pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool) -> Result<()> { +pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool, build_dev_deps: bool) -> Result<()> { let project_root = helpers::get_abs_path(path); let workspace_root = helpers::get_workspace_root(&project_root); let packages = packages::make( @@ -339,9 +339,7 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool) -> Result< &project_root, &workspace_root, show_progress, - // Build the package tree with dev dependencies. - // They should always be cleaned if they are there. - true, + build_dev_deps, )?; let root_config_name = packages::read_package_name(&project_root)?; let bsc_path = helpers::get_bsc(); diff --git a/rewatch/src/cli.rs b/rewatch/src/cli.rs index 6053d8cca2..5f593009df 100644 --- a/rewatch/src/cli.rs +++ b/rewatch/src/cli.rs @@ -143,6 +143,9 @@ pub enum Command { #[command(flatten)] snapshot_output: SnapshotOutputArg, + + #[command(flatten)] + dev: DevArg, }, /// Alias to `legacy format`. #[command(disable_help_flag = true)] diff --git a/rewatch/src/main.rs b/rewatch/src/main.rs index fb3f6c3516..a81c3e1bb6 100644 --- a/rewatch/src/main.rs +++ b/rewatch/src/main.rs @@ -79,10 +79,16 @@ fn main() -> Result<()> { cli::Command::Clean { folder, snapshot_output, + dev, } => { let _lock = get_lock(&folder); - build::clean::clean(Path::new(&folder as &str), show_progress, *snapshot_output) + build::clean::clean( + Path::new(&folder as &str), + show_progress, + *snapshot_output, + dev.dev, + ) } cli::Command::Legacy { legacy_args } => { let code = build::pass_through_legacy(legacy_args); diff --git a/rewatch/testrepo/bsconfig.json b/rewatch/testrepo/bsconfig.json index dfa69cf830..f55b950dcd 100644 --- a/rewatch/testrepo/bsconfig.json +++ b/rewatch/testrepo/bsconfig.json @@ -21,7 +21,8 @@ "@testrepo/new-namespace", "@testrepo/namespace-casing", "@testrepo/with-dev-deps", - "@testrepo/compiled-by-legacy" + "@testrepo/compiled-by-legacy", + "@testrepo/nonexisting-dev-files" ], "bs-dependencies": [ "@testrepo/main", @@ -30,6 +31,7 @@ "@testrepo/new-namespace", "@testrepo/namespace-casing", "@testrepo/with-dev-deps", - "@testrepo/compiled-by-legacy" + "@testrepo/compiled-by-legacy", + "@testrepo/nonexisting-dev-files" ] } diff --git a/rewatch/testrepo/package.json b/rewatch/testrepo/package.json index 638c31f638..a170d39c59 100644 --- a/rewatch/testrepo/package.json +++ b/rewatch/testrepo/package.json @@ -9,7 +9,8 @@ "packages/new-namespace", "packages/namespace-casing", "packages/with-dev-deps", - "packages/compiled-by-legacy" + "packages/compiled-by-legacy", + "packages/nonexisting-dev-files" ] }, "dependencies": { diff --git a/rewatch/testrepo/packages/nonexisting-dev-files/package.json b/rewatch/testrepo/packages/nonexisting-dev-files/package.json new file mode 100644 index 0000000000..7af67a1eea --- /dev/null +++ b/rewatch/testrepo/packages/nonexisting-dev-files/package.json @@ -0,0 +1,9 @@ +{ + "name": "@testrepo/nonexisting-dev-files", + "version": "0.0.1", + "keywords": [ + "rescript" + ], + "author": "", + "license": "MIT" +} diff --git a/rewatch/testrepo/packages/nonexisting-dev-files/rescript.json b/rewatch/testrepo/packages/nonexisting-dev-files/rescript.json new file mode 100644 index 0000000000..7eb6700ad8 --- /dev/null +++ b/rewatch/testrepo/packages/nonexisting-dev-files/rescript.json @@ -0,0 +1,8 @@ +{ + "name": "@testrepo/nonexisting-dev-files", + "sources": { + "dir": "dev", + "subdirs": true, + "type": "dev" + } +} diff --git a/rewatch/testrepo/yarn.lock b/rewatch/testrepo/yarn.lock index 5c323e6f29..fa0f31c40a 100644 --- a/rewatch/testrepo/yarn.lock +++ b/rewatch/testrepo/yarn.lock @@ -81,6 +81,12 @@ __metadata: languageName: unknown linkType: soft +"@testrepo/nonexisting-dev-files@workspace:packages/nonexisting-dev-files": + version: 0.0.0-use.local + resolution: "@testrepo/nonexisting-dev-files@workspace:packages/nonexisting-dev-files" + languageName: unknown + linkType: soft + "@testrepo/with-dev-deps@workspace:packages/with-dev-deps": version: 0.0.0-use.local resolution: "@testrepo/with-dev-deps@workspace:packages/with-dev-deps" diff --git a/rewatch/tests/compile.sh b/rewatch/tests/compile.sh index 334993cfc5..15f1bf09c3 100755 --- a/rewatch/tests/compile.sh +++ b/rewatch/tests/compile.sh @@ -82,7 +82,7 @@ rewatch build --snapshot-output &> ../tests/snapshots/dependency-cycle.txt git checkout -- packages/new-namespace/src/NS_alias.res # it should compile dev dependencies with the --dev flag -rewatch clean &> /dev/null +rewatch clean --dev &> /dev/null rewatch build --dev &> /dev/null; if [ $? -ne 0 ]; then @@ -100,7 +100,7 @@ else exit 1 fi -error_output=$(rewatch clean 2>&1 >/dev/null) +error_output=$(rewatch clean --dev 2>&1 >/dev/null) file_count=$(find ./packages/with-dev-deps -name *.mjs | wc -l) if [ "$file_count" -eq 0 ]; then