Skip to content

Add --dev flag to clean command #7622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jul 15, 2025
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions rewatch/src/build/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,15 @@ 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(
&None,
&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();
Expand Down
3 changes: 3 additions & 0 deletions rewatch/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 7 additions & 1 deletion rewatch/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions rewatch/testrepo/bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
]
}
3 changes: 2 additions & 1 deletion rewatch/testrepo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 9 additions & 0 deletions rewatch/testrepo/packages/nonexisting-dev-files/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@testrepo/nonexisting-dev-files",
"version": "0.0.1",
"keywords": [
"rescript"
],
"author": "",
"license": "MIT"
}
8 changes: 8 additions & 0 deletions rewatch/testrepo/packages/nonexisting-dev-files/rescript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@testrepo/nonexisting-dev-files",
"sources": {
"dir": "dev",
"subdirs": true,
"type": "dev"
}
}
6 changes: 6 additions & 0 deletions rewatch/testrepo/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions rewatch/tests/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down