Skip to content

Commit 9068abb

Browse files
committed
Merge branch 'master' into rewatch-bs-dev-dependencies
2 parents 0e433fc + fd68109 commit 9068abb

File tree

5 files changed

+61
-31
lines changed

5 files changed

+61
-31
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- Clean up `config.ml`. https://github.com/rescript-lang/rescript/pull/7636
2626
- Rewatch: simplify getting bsc path. https://github.com/rescript-lang/rescript/pull/7634
2727
- Rewatch: only get `"type": "dev"` source files for local packages. https://github.com/rescript-lang/rescript/pull/7646
28+
- Rewatch: add support for `rescript -w` for compatibility. https://github.com/rescript-lang/rescript/pull/7649
2829

2930
#### :rocket: New Feature
3031

@@ -33,7 +34,8 @@
3334
#### :bug: Bug fix
3435

3536
- Fix `typeof` parens on functions. https://github.com/rescript-lang/rescript/pull/7643
36-
- Add --dev flag to clean command. https://github.com/rescript-lang/rescript/pull/7622
37+
- Rewatch: Add --dev flag to clean command. https://github.com/rescript-lang/rescript/pull/7622
38+
- Rewatch: Use root package suffix in clean log messages. https://github.com/rescript-lang/rescript/pull/7648
3739

3840
# 12.0.0-beta.1
3941

rewatch/src/build/clean.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,14 @@ pub fn remove_compile_assets(package: &packages::Package, source_file: &Path) {
5858
}
5959
}
6060

61-
pub fn clean_mjs_files(build_state: &BuildState) {
61+
fn clean_source_files(build_state: &BuildState, root_package: &packages::Package) {
6262
// get all rescript file locations
6363
let rescript_file_locations = build_state
6464
.modules
6565
.values()
6666
.filter_map(|module| match &module.source_type {
6767
SourceType::SourceFile(source_file) => {
6868
let package = build_state.packages.get(&module.package_name).unwrap();
69-
let root_package = build_state
70-
.packages
71-
.get(&build_state.root_config_name)
72-
.expect("Could not find root package");
73-
7469
Some(
7570
root_package
7671
.config
@@ -391,10 +386,6 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool, build_dev_
391386
}
392387

393388
let timing_clean_mjs = Instant::now();
394-
if !snapshot_output && show_progress {
395-
println!("{} {}Cleaning mjs files...", style("[2/2]").bold().dim(), SWEEP);
396-
let _ = std::io::stdout().flush();
397-
}
398389
let mut build_state = BuildState::new(
399390
project_root.to_owned(),
400391
root_config_name,
@@ -403,15 +394,33 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool, build_dev_
403394
bsc_path,
404395
);
405396
packages::parse_packages(&mut build_state);
406-
clean_mjs_files(&build_state);
397+
let root_package = build_state
398+
.packages
399+
.get(&build_state.root_config_name)
400+
.expect("Could not find root package");
401+
402+
let suffix = root_package.config.suffix.as_deref().unwrap_or(".res.mjs");
403+
404+
if !snapshot_output && show_progress {
405+
println!(
406+
"{} {}Cleaning {} files...",
407+
style("[2/2]").bold().dim(),
408+
SWEEP,
409+
suffix
410+
);
411+
let _ = std::io::stdout().flush();
412+
}
413+
414+
clean_source_files(&build_state, root_package);
407415
let timing_clean_mjs_elapsed = timing_clean_mjs.elapsed();
408416

409417
if !snapshot_output && show_progress {
410418
println!(
411-
"{}{} {}Cleaned mjs files in {:.2}s",
419+
"{}{} {}Cleaned {} files in {:.2}s",
412420
LINE_CLEAR,
413421
style("[2/2]").bold().dim(),
414422
SWEEP,
423+
suffix,
415424
timing_clean_mjs_elapsed.as_secs_f64()
416425
);
417426
let _ = std::io::stdout().flush();

rewatch/src/cli.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ use std::{ffi::OsString, ops::Deref};
22

33
use clap::{Args, Parser, Subcommand};
44
use clap_verbosity_flag::InfoLevel;
5+
use regex::Regex;
6+
7+
fn parse_regex(s: &str) -> Result<Regex, regex::Error> {
8+
Regex::new(s)
9+
}
510

611
/// ReScript - Fast, Simple, Fully Typed JavaScript from the Future
712
#[derive(Parser, Debug)]
@@ -39,8 +44,8 @@ pub struct FilterArg {
3944
///
4045
/// Filter allows for a regex to be supplied which will filter the files to be compiled. For
4146
/// instance, to filter out test files for compilation while doing feature work.
42-
#[arg(short, long)]
43-
pub filter: Option<String>,
47+
#[arg(short, long, value_parser = parse_regex)]
48+
pub filter: Option<Regex>,
4449
}
4550

4651
#[derive(Args, Debug, Clone)]
@@ -107,6 +112,10 @@ pub struct BuildArgs {
107112

108113
#[command(flatten)]
109114
pub snapshot_output: SnapshotOutputArg,
115+
116+
/// Watch mode (deprecated, use `rescript watch` instead)
117+
#[arg(short, default_value_t = false, num_args = 0..=1)]
118+
pub watch: bool,
110119
}
111120

112121
#[derive(Args, Clone, Debug)]
@@ -130,6 +139,19 @@ pub struct WatchArgs {
130139
pub snapshot_output: SnapshotOutputArg,
131140
}
132141

142+
impl From<BuildArgs> for WatchArgs {
143+
fn from(build_args: BuildArgs) -> Self {
144+
Self {
145+
folder: build_args.folder,
146+
filter: build_args.filter,
147+
after_build: build_args.after_build,
148+
create_sourcedirs: build_args.create_sourcedirs,
149+
dev: build_args.dev,
150+
snapshot_output: build_args.snapshot_output,
151+
}
152+
}
153+
}
154+
133155
#[derive(Subcommand, Clone, Debug)]
134156
pub enum Command {
135157
/// Build the project
@@ -187,7 +209,7 @@ impl Deref for FolderArg {
187209
}
188210

189211
impl Deref for FilterArg {
190-
type Target = Option<String>;
212+
type Target = Option<Regex>;
191213

192214
fn deref(&self) -> &Self::Target {
193215
&self.filter

rewatch/src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub fn get_bsc() -> PathBuf {
196196

197197
bsc_path
198198
.canonicalize()
199-
.expect("Could not get bsc path")
199+
.expect("Could not get bsc path, did you set environment variable RESCRIPT_BSC_EXE ?")
200200
.to_stripped_verbatim_path()
201201
}
202202

rewatch/src/main.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use anyhow::Result;
22
use clap::Parser;
33
use log::LevelFilter;
4-
use regex::Regex;
54
use std::{io::Write, path::Path};
65

76
use rewatch::{build, cli, cmd, lock, watcher};
@@ -17,27 +16,29 @@ fn main() -> Result<()> {
1716
.target(env_logger::fmt::Target::Stdout)
1817
.init();
1918

20-
let command = args.command.unwrap_or(cli::Command::Build(args.build_args));
19+
let mut command = args.command.unwrap_or(cli::Command::Build(args.build_args));
20+
21+
if let cli::Command::Build(build_args) = &command {
22+
if build_args.watch {
23+
log::warn!("`rescript build -w` is deprecated. Please use `rescript watch` instead.");
24+
command = cli::Command::Watch(build_args.clone().into());
25+
}
26+
}
2127

2228
// The 'normal run' mode will show the 'pretty' formatted progress. But if we turn off the log
2329
// level, we should never show that.
2430
let show_progress = log_level_filter == LevelFilter::Info;
2531

26-
match command.clone() {
32+
match command {
2733
cli::Command::CompilerArgs { path, dev } => {
2834
println!("{}", build::get_compiler_args(Path::new(&path), *dev)?);
2935
std::process::exit(0);
3036
}
3137
cli::Command::Build(build_args) => {
3238
let _lock = get_lock(&build_args.folder);
3339

34-
let filter = build_args
35-
.filter
36-
.as_ref()
37-
.map(|filter| Regex::new(&filter).expect("Could not parse regex"));
38-
3940
match build::build(
40-
&filter,
41+
&build_args.filter,
4142
Path::new(&build_args.folder as &str),
4243
show_progress,
4344
build_args.no_timing,
@@ -60,12 +61,8 @@ fn main() -> Result<()> {
6061
cli::Command::Watch(watch_args) => {
6162
let _lock = get_lock(&watch_args.folder);
6263

63-
let filter = watch_args
64-
.filter
65-
.as_ref()
66-
.map(|filter| Regex::new(&filter).expect("Could not parse regex"));
6764
watcher::start(
68-
&filter,
65+
&watch_args.filter,
6966
show_progress,
7067
&watch_args.folder,
7168
(*watch_args.after_build).clone(),

0 commit comments

Comments
 (0)