Skip to content

Commit e753b53

Browse files
authored
Add --dev flag to clean command (#7622)
* Don't panic when dev files are not found during clean. * Add test project * Clean up * Test clean of nonexisting dev files * Revert usage of rescript json name * type dev * Add changelog entry * Don't read folder is dev source does not exists during clean. * Clean up changelog * Revert changes * Revert cli changes * Update changelog * Add --dev in tests
1 parent 4e70537 commit e753b53

File tree

10 files changed

+44
-11
lines changed

10 files changed

+44
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#### :bug: Bug fix
3333

3434
- Fix `typeof` parens on functions. https://github.com/rescript-lang/rescript/pull/7643
35-
35+
- Add --dev flag to clean command. https://github.com/rescript-lang/rescript/pull/7622
3636

3737
# 12.0.0-beta.1
3838

rewatch/src/build/clean.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,15 @@ pub fn cleanup_after_build(build_state: &BuildState) {
331331
});
332332
}
333333

334-
pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool) -> Result<()> {
334+
pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool, build_dev_deps: bool) -> Result<()> {
335335
let project_root = helpers::get_abs_path(path);
336336
let workspace_root = helpers::get_workspace_root(&project_root);
337337
let packages = packages::make(
338338
&None,
339339
&project_root,
340340
&workspace_root,
341341
show_progress,
342-
// Build the package tree with dev dependencies.
343-
// They should always be cleaned if they are there.
344-
true,
342+
build_dev_deps,
345343
)?;
346344
let root_config_name = packages::read_package_name(&project_root)?;
347345
let bsc_path = helpers::get_bsc();

rewatch/src/cli.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ pub enum Command {
143143

144144
#[command(flatten)]
145145
snapshot_output: SnapshotOutputArg,
146+
147+
#[command(flatten)]
148+
dev: DevArg,
146149
},
147150
/// Alias to `legacy format`.
148151
#[command(disable_help_flag = true)]

rewatch/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,16 @@ fn main() -> Result<()> {
7979
cli::Command::Clean {
8080
folder,
8181
snapshot_output,
82+
dev,
8283
} => {
8384
let _lock = get_lock(&folder);
8485

85-
build::clean::clean(Path::new(&folder as &str), show_progress, *snapshot_output)
86+
build::clean::clean(
87+
Path::new(&folder as &str),
88+
show_progress,
89+
*snapshot_output,
90+
dev.dev,
91+
)
8692
}
8793
cli::Command::Legacy { legacy_args } => {
8894
let code = build::pass_through_legacy(legacy_args);

rewatch/testrepo/bsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"@testrepo/new-namespace",
2222
"@testrepo/namespace-casing",
2323
"@testrepo/with-dev-deps",
24-
"@testrepo/compiled-by-legacy"
24+
"@testrepo/compiled-by-legacy",
25+
"@testrepo/nonexisting-dev-files"
2526
],
2627
"bs-dependencies": [
2728
"@testrepo/main",
@@ -30,6 +31,7 @@
3031
"@testrepo/new-namespace",
3132
"@testrepo/namespace-casing",
3233
"@testrepo/with-dev-deps",
33-
"@testrepo/compiled-by-legacy"
34+
"@testrepo/compiled-by-legacy",
35+
"@testrepo/nonexisting-dev-files"
3436
]
3537
}

rewatch/testrepo/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"packages/new-namespace",
1010
"packages/namespace-casing",
1111
"packages/with-dev-deps",
12-
"packages/compiled-by-legacy"
12+
"packages/compiled-by-legacy",
13+
"packages/nonexisting-dev-files"
1314
]
1415
},
1516
"dependencies": {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "@testrepo/nonexisting-dev-files",
3+
"version": "0.0.1",
4+
"keywords": [
5+
"rescript"
6+
],
7+
"author": "",
8+
"license": "MIT"
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@testrepo/nonexisting-dev-files",
3+
"sources": {
4+
"dir": "dev",
5+
"subdirs": true,
6+
"type": "dev"
7+
}
8+
}

rewatch/testrepo/yarn.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ __metadata:
8181
languageName: unknown
8282
linkType: soft
8383

84+
"@testrepo/nonexisting-dev-files@workspace:packages/nonexisting-dev-files":
85+
version: 0.0.0-use.local
86+
resolution: "@testrepo/nonexisting-dev-files@workspace:packages/nonexisting-dev-files"
87+
languageName: unknown
88+
linkType: soft
89+
8490
"@testrepo/with-dev-deps@workspace:packages/with-dev-deps":
8591
version: 0.0.0-use.local
8692
resolution: "@testrepo/with-dev-deps@workspace:packages/with-dev-deps"

rewatch/tests/compile.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ rewatch build --snapshot-output &> ../tests/snapshots/dependency-cycle.txt
8282
git checkout -- packages/new-namespace/src/NS_alias.res
8383

8484
# it should compile dev dependencies with the --dev flag
85-
rewatch clean &> /dev/null
85+
rewatch clean --dev &> /dev/null
8686
rewatch build --dev &> /dev/null;
8787
if [ $? -ne 0 ];
8888
then
@@ -100,7 +100,7 @@ else
100100
exit 1
101101
fi
102102

103-
error_output=$(rewatch clean 2>&1 >/dev/null)
103+
error_output=$(rewatch clean --dev 2>&1 >/dev/null)
104104
file_count=$(find ./packages/with-dev-deps -name *.mjs | wc -l)
105105
if [ "$file_count" -eq 0 ];
106106
then

0 commit comments

Comments
 (0)