Skip to content

Commit 6deee63

Browse files
authored
Rewatch cli refactor (#7551)
* chore: force LF on windows * feat: upstream changes of rescript-lang/rewatch#162 * test: update cli arg ordering * fix: look for rescript.exe not rescript-legacy * test: add legacy test repo * test: add legacy build system compile tests * test: print stderr output on failure * refactor: extract fn to get binary dir * fix: windows binary path * fix: pass bsc-path arg only to specific subcommands * test: add package to testrepo deps * test: update snapshots * test: improve test output * fix: args passing in cli wrapper * fix: pass `--bsc-path` to implicit build command * fix: wrong path to `rescript` executable refactor `cli.rs` to remove duplication of docstrings * fix: legacy tests inconsistency * test: is error output printed correctly * debug: print whole output of rewatch legacy * fix: node script invocation on windows * Update CHANGELOG.md * Update CHANGELOG.md
1 parent 9516742 commit 6deee63

31 files changed

+604
-192
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* text=auto eol=lf
2+
13
*.ml linguist-language=OCaml
24
*.mli linguist-language=OCaml
35
*.res linguist-language=ReScript

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
# 12.0.0-alpha.15 (Unreleased)
1414

15+
#### :boom: Breaking Change
16+
17+
- The legacy rescript cli can be called through rewatch via `rewatch legacy`. Arguments to rewatch need to be passed after the subcommand. Argument `--compiler-args` is now a subcommand `compiler-args`. https://github.com/rescript-lang/rescript/pull/7551
18+
1519
#### :bug: Bug fix
1620

1721
- Ignore inferred arity in functions inside `%raw` functions, leaving to `%ffi` the responsibility to check the arity since it gives an error in case of mismatch. https://github.com/rescript-lang/rescript/pull/7542

cli/rewatch.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,37 @@ import { rewatch_exe, bsc_exe } from "./common/bins.js";
77

88
const args = process.argv.slice(2);
99

10+
const firstPositionalArgIndex = args.findIndex((arg) => !arg.startsWith("-"));
11+
1012
try {
11-
child_process.execFileSync(rewatch_exe, [...args, "--bsc-path", bsc_exe], {
12-
stdio: "inherit",
13-
});
13+
if (firstPositionalArgIndex !== -1) {
14+
const subcommand = args[firstPositionalArgIndex];
15+
const subcommandWithArgs = args.slice(firstPositionalArgIndex);
16+
17+
if (
18+
subcommand === "build" ||
19+
subcommand === "watch" ||
20+
subcommand === "clean" ||
21+
subcommand === "compiler-args"
22+
) {
23+
child_process.execFileSync(
24+
rewatch_exe,
25+
[...subcommandWithArgs, "--bsc-path", bsc_exe],
26+
{
27+
stdio: "inherit",
28+
}
29+
);
30+
} else {
31+
child_process.execFileSync(rewatch_exe, [...args], {
32+
stdio: "inherit",
33+
});
34+
}
35+
} else {
36+
// no subcommand means build subcommand
37+
child_process.execFileSync(rewatch_exe, [...args, "--bsc-path", bsc_exe], {
38+
stdio: "inherit",
39+
});
40+
}
1441
} catch (err) {
1542
if (err.status !== undefined) {
1643
process.exit(err.status); // Pass through the exit code

rewatch/src/build.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ use console::style;
1818
use indicatif::{ProgressBar, ProgressStyle};
1919
use log::log_enabled;
2020
use serde::Serialize;
21+
use std::ffi::OsString;
2122
use std::fmt;
2223
use std::fs::File;
2324
use std::io::{stdout, Write};
2425
use std::path::{Path, PathBuf};
26+
use std::process::Stdio;
2527
use std::time::{Duration, Instant};
2628

2729
use self::compile::compiler_args;
@@ -57,7 +59,7 @@ pub struct CompilerArgs {
5759
pub fn get_compiler_args(
5860
path: &Path,
5961
rescript_version: Option<String>,
60-
bsc_path: &Option<PathBuf>,
62+
bsc_path: Option<PathBuf>,
6163
build_dev_deps: bool,
6264
) -> Result<String> {
6365
let filename = &helpers::get_abs_path(path);
@@ -499,7 +501,7 @@ pub fn build(
499501
show_progress: bool,
500502
no_timing: bool,
501503
create_sourcedirs: bool,
502-
bsc_path: &Option<PathBuf>,
504+
bsc_path: Option<PathBuf>,
503505
build_dev_deps: bool,
504506
snapshot_output: bool,
505507
) -> Result<BuildState> {
@@ -514,7 +516,7 @@ pub fn build(
514516
filter,
515517
show_progress,
516518
path,
517-
bsc_path,
519+
&bsc_path,
518520
build_dev_deps,
519521
snapshot_output,
520522
)
@@ -551,3 +553,25 @@ pub fn build(
551553
}
552554
}
553555
}
556+
557+
pub fn pass_through_legacy(mut args: Vec<OsString>) -> i32 {
558+
let project_root = helpers::get_abs_path(Path::new("."));
559+
let workspace_root = helpers::get_workspace_root(&project_root);
560+
561+
let rescript_legacy_path = helpers::get_rescript_legacy(&project_root, workspace_root);
562+
563+
args.insert(0, rescript_legacy_path.into());
564+
let status = std::process::Command::new("node")
565+
.args(args)
566+
.stdout(Stdio::inherit())
567+
.stderr(Stdio::inherit())
568+
.status();
569+
570+
match status {
571+
Ok(s) => s.code().unwrap_or(0),
572+
Err(err) => {
573+
eprintln!("Error running the legacy build system: {err}");
574+
1
575+
}
576+
}
577+
}

rewatch/src/build/clean.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ pub fn cleanup_after_build(build_state: &BuildState) {
334334
pub fn clean(
335335
path: &Path,
336336
show_progress: bool,
337-
bsc_path: &Option<PathBuf>,
338-
build_dev_deps: bool,
337+
bsc_path: Option<PathBuf>,
339338
snapshot_output: bool,
340339
) -> Result<()> {
341340
let project_root = helpers::get_abs_path(path);
@@ -345,8 +344,9 @@ pub fn clean(
345344
&project_root,
346345
&workspace_root,
347346
show_progress,
348-
// Always clean dev dependencies
349-
build_dev_deps,
347+
// Build the package tree with dev dependencies.
348+
// They should always be cleaned if they are there.
349+
true,
350350
)?;
351351
let root_config_name = packages::read_package_name(&project_root)?;
352352
let bsc_path = match bsc_path {

0 commit comments

Comments
 (0)