Skip to content

Rewatch cli refactor #7551

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 23 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* text=auto eol=lf

*.ml linguist-language=OCaml
*.mli linguist-language=OCaml
*.res linguist-language=ReScript
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

# 12.0.0-alpha.15 (Unreleased)

#### :boom: Breaking Change

- 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

#### :bug: Bug fix

- 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
Expand Down
33 changes: 30 additions & 3 deletions cli/rewatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,37 @@ import { rewatch_exe, bsc_exe } from "./common/bins.js";

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

const firstPositionalArgIndex = args.findIndex((arg) => !arg.startsWith("-"));

try {
child_process.execFileSync(rewatch_exe, [...args, "--bsc-path", bsc_exe], {
stdio: "inherit",
});
if (firstPositionalArgIndex !== -1) {
const subcommand = args[firstPositionalArgIndex];
const subcommandWithArgs = args.slice(firstPositionalArgIndex);

if (
subcommand === "build" ||
subcommand === "watch" ||
subcommand === "clean" ||
subcommand === "compiler-args"
) {
child_process.execFileSync(
rewatch_exe,
[...subcommandWithArgs, "--bsc-path", bsc_exe],
{
stdio: "inherit",
}
);
} else {
child_process.execFileSync(rewatch_exe, [...args], {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this branch? can we not just pass --bsc-path in both cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bsc-path is not a root level arg anymore

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be an option to use an env var BSC_PATH instead to avoid this problem?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea. Either that, or we promote --bsc-path to a root level argument again. If we decide for the env var would this be in addition to the arg?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that it would replace the arg. What's your opinion @jfrolich?

stdio: "inherit",
});
}
} else {
// no subcommand means build subcommand
child_process.execFileSync(rewatch_exe, [...args, "--bsc-path", bsc_exe], {
stdio: "inherit",
});
}
} catch (err) {
if (err.status !== undefined) {
process.exit(err.status); // Pass through the exit code
Expand Down
30 changes: 27 additions & 3 deletions rewatch/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ use console::style;
use indicatif::{ProgressBar, ProgressStyle};
use log::log_enabled;
use serde::Serialize;
use std::ffi::OsString;
use std::fmt;
use std::fs::File;
use std::io::{stdout, Write};
use std::path::{Path, PathBuf};
use std::process::Stdio;
use std::time::{Duration, Instant};

use self::compile::compiler_args;
Expand Down Expand Up @@ -57,7 +59,7 @@ pub struct CompilerArgs {
pub fn get_compiler_args(
path: &Path,
rescript_version: Option<String>,
bsc_path: &Option<PathBuf>,
bsc_path: Option<PathBuf>,
build_dev_deps: bool,
) -> Result<String> {
let filename = &helpers::get_abs_path(path);
Expand Down Expand Up @@ -499,7 +501,7 @@ pub fn build(
show_progress: bool,
no_timing: bool,
create_sourcedirs: bool,
bsc_path: &Option<PathBuf>,
bsc_path: Option<PathBuf>,
build_dev_deps: bool,
snapshot_output: bool,
) -> Result<BuildState> {
Expand All @@ -514,7 +516,7 @@ pub fn build(
filter,
show_progress,
path,
bsc_path,
&bsc_path,
build_dev_deps,
snapshot_output,
)
Expand Down Expand Up @@ -551,3 +553,25 @@ pub fn build(
}
}
}

pub fn pass_through_legacy(mut args: Vec<OsString>) -> i32 {
let project_root = helpers::get_abs_path(Path::new("."));
let workspace_root = helpers::get_workspace_root(&project_root);

let rescript_legacy_path = helpers::get_rescript_legacy(&project_root, workspace_root);

args.insert(0, rescript_legacy_path.into());
let status = std::process::Command::new("node")
.args(args)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status();

match status {
Ok(s) => s.code().unwrap_or(0),
Err(err) => {
eprintln!("Error running the legacy build system: {err}");
1
}
}
}
8 changes: 4 additions & 4 deletions rewatch/src/build/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ pub fn cleanup_after_build(build_state: &BuildState) {
pub fn clean(
path: &Path,
show_progress: bool,
bsc_path: &Option<PathBuf>,
build_dev_deps: bool,
bsc_path: Option<PathBuf>,
snapshot_output: bool,
) -> Result<()> {
let project_root = helpers::get_abs_path(path);
Expand All @@ -345,8 +344,9 @@ pub fn clean(
&project_root,
&workspace_root,
show_progress,
// Always clean dev dependencies
build_dev_deps,
// Build the package tree with dev dependencies.
// They should always be cleaned if they are there.
true,
)?;
let root_config_name = packages::read_package_name(&project_root)?;
let bsc_path = match bsc_path {
Expand Down
Loading