diff --git a/CHANGELOG.md b/CHANGELOG.md index 078b743760..cfc49f2fe0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Clean up `config.ml`. https://github.com/rescript-lang/rescript/pull/7636 - Rewatch: simplify getting bsc path. https://github.com/rescript-lang/rescript/pull/7634 - Rewatch: only get `"type": "dev"` source files for local packages. https://github.com/rescript-lang/rescript/pull/7646 +- Rewatch: add support for `rescript -w` for compatibility. https://github.com/rescript-lang/rescript/pull/7649 #### :rocket: New Feature diff --git a/rewatch/src/cli.rs b/rewatch/src/cli.rs index 5f593009df..0ee9e2e8e8 100644 --- a/rewatch/src/cli.rs +++ b/rewatch/src/cli.rs @@ -107,6 +107,10 @@ pub struct BuildArgs { #[command(flatten)] pub snapshot_output: SnapshotOutputArg, + + /// Watch mode (deprecated, use `rescript watch` instead) + #[arg(short, default_value_t = false, num_args = 0..=1)] + pub watch: bool, } #[derive(Args, Clone, Debug)] @@ -130,6 +134,19 @@ pub struct WatchArgs { pub snapshot_output: SnapshotOutputArg, } +impl From for WatchArgs { + fn from(build_args: BuildArgs) -> Self { + Self { + folder: build_args.folder, + filter: build_args.filter, + after_build: build_args.after_build, + create_sourcedirs: build_args.create_sourcedirs, + dev: build_args.dev, + snapshot_output: build_args.snapshot_output, + } + } +} + #[derive(Subcommand, Clone, Debug)] pub enum Command { /// Build the project diff --git a/rewatch/src/main.rs b/rewatch/src/main.rs index a81c3e1bb6..332f1f199f 100644 --- a/rewatch/src/main.rs +++ b/rewatch/src/main.rs @@ -17,13 +17,20 @@ fn main() -> Result<()> { .target(env_logger::fmt::Target::Stdout) .init(); - let command = args.command.unwrap_or(cli::Command::Build(args.build_args)); + let mut command = args.command.unwrap_or(cli::Command::Build(args.build_args)); + + if let cli::Command::Build(build_args) = &command { + if build_args.watch { + log::warn!("`rescript build -w` is deprecated. Please use `rescript watch` instead."); + command = cli::Command::Watch(build_args.clone().into()); + } + } // The 'normal run' mode will show the 'pretty' formatted progress. But if we turn off the log // level, we should never show that. let show_progress = log_level_filter == LevelFilter::Info; - match command.clone() { + match command { cli::Command::CompilerArgs { path, dev } => { println!("{}", build::get_compiler_args(Path::new(&path), *dev)?); std::process::exit(0);