Skip to content

Commit 7fb5efe

Browse files
committed
Merge branch 'master' into belt-rename-exn-to-or-throw
2 parents 914560a + 2ed1742 commit 7fb5efe

39 files changed

+688
-195
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/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rewatch/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rewatch"
3-
version = "1.2.0"
3+
version = "12.0.0-alpha.15"
44
edition = "2021"
55

66
[dependencies]

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 {

rewatch/src/build/compile.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ pub fn compiler_args(
394394
};
395395

396396
let uncurried_args = root_config.get_uncurried_args(version);
397+
let jsx_args = root_config.get_jsx_args();
398+
let jsx_module_args = root_config.get_jsx_module_args();
399+
let jsx_mode_args = root_config.get_jsx_mode_args();
400+
let jsx_preserve_args = root_config.get_jsx_preserve_args();
397401
let gentype_arg = config.get_gentype_arg();
398402

399403
let warning_args: Vec<String> = match config.warnings.to_owned() {
@@ -476,6 +480,10 @@ pub fn compiler_args(
476480
Path::new("..").join("ocaml").to_string_lossy().to_string(),
477481
],
478482
dependency_paths.concat(),
483+
jsx_args,
484+
jsx_module_args,
485+
jsx_mode_args,
486+
jsx_preserve_args,
479487
uncurried_args,
480488
bsc_flags.to_owned(),
481489
warning_args,

rewatch/src/build/packages.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,10 @@ impl Package {
839839
self.config.get_jsx_module_args()
840840
}
841841

842+
pub fn get_jsx_preserve_args(&self) -> Vec<String> {
843+
self.config.get_jsx_preserve_args()
844+
}
845+
842846
pub fn get_uncurried_args(&self, version: &str, root_package: &packages::Package) -> Vec<String> {
843847
root_package.config.get_uncurried_args(version)
844848
}

rewatch/src/build/parse.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ pub fn parser_args(
272272
let jsx_args = root_config.get_jsx_args();
273273
let jsx_module_args = root_config.get_jsx_module_args();
274274
let jsx_mode_args = root_config.get_jsx_mode_args();
275+
let jsx_preserve_args = root_config.get_jsx_preserve_args();
275276
let uncurried_args = root_config.get_uncurried_args(version);
276277
let bsc_flags = config::flatten_flags(&config.bsc_flags);
277278

@@ -285,6 +286,7 @@ pub fn parser_args(
285286
jsx_args,
286287
jsx_module_args,
287288
jsx_mode_args,
289+
jsx_preserve_args,
288290
uncurried_args,
289291
bsc_flags,
290292
vec![

0 commit comments

Comments
 (0)