Skip to content

Commit

Permalink
feat(cli): add --no-watch argument to the dev command, closes #4617 (
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Jul 29, 2022
1 parent 0246205 commit 0983d7c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changes/no-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"cli.rs": minor
"cli.js": minor
---

Added `--no-watch` argument to the `dev` command to disable the file watcher.
13 changes: 9 additions & 4 deletions tooling/cli/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub struct Options {
pub release_mode: bool,
/// Command line arguments passed to the runner
pub args: Vec<String>,
/// Disable the file watcher
#[clap(long)]
pub no_watch: bool,
}

pub fn command(options: Options) -> Result<()> {
Expand Down Expand Up @@ -234,14 +237,16 @@ fn command_internal(mut options: Options) -> Result<()> {
let mut interface = AppInterface::new(config.lock().unwrap().as_ref().unwrap())?;

let exit_on_panic = options.exit_on_panic;
let no_watch = options.no_watch;
interface.dev(options.into(), move |status, reason| {
on_dev_exit(status, reason, exit_on_panic)
on_dev_exit(status, reason, exit_on_panic, no_watch)
})
}

fn on_dev_exit(status: ExitStatus, reason: ExitReason, exit_on_panic: bool) {
if !matches!(reason, ExitReason::TriggeredKill)
&& (exit_on_panic || matches!(reason, ExitReason::NormalExit))
fn on_dev_exit(status: ExitStatus, reason: ExitReason, exit_on_panic: bool, no_watch: bool) {
if no_watch
|| (!matches!(reason, ExitReason::TriggeredKill)
&& (exit_on_panic || matches!(reason, ExitReason::NormalExit)))
{
kill_before_dev_process();
#[cfg(not(debug_assertions))]
Expand Down
25 changes: 20 additions & 5 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
str::FromStr,
sync::{
atomic::{AtomicBool, Ordering},
mpsc::channel,
mpsc::{channel, sync_channel},
Arc, Mutex,
},
time::{Duration, Instant},
Expand Down Expand Up @@ -50,6 +50,7 @@ pub struct Options {
pub features: Option<Vec<String>>,
pub args: Vec<String>,
pub config: Option<String>,
pub no_watch: bool,
}

impl From<crate::build::Options> for Options {
Expand All @@ -61,6 +62,7 @@ impl From<crate::build::Options> for Options {
features: options.features,
args: options.args,
config: options.config,
no_watch: true,
}
}
}
Expand All @@ -74,6 +76,7 @@ impl From<crate::dev::Options> for Options {
features: options.features,
args: options.args,
config: options.config,
no_watch: options.no_watch,
}
}
}
Expand Down Expand Up @@ -215,11 +218,23 @@ impl Interface for Rust {
let on_exit = Arc::new(on_exit);

let on_exit_ = on_exit.clone();
let child = self.run_dev(options.clone(), move |status, reason| {
on_exit_(status, reason)
})?;

self.run_dev_watcher(child, options, on_exit)
if options.no_watch {
let (tx, rx) = sync_channel(1);
self.run_dev(options, move |status, reason| {
tx.send(()).unwrap();
on_exit_(status, reason)
})?;

rx.recv().unwrap();
Ok(())
} else {
let child = self.run_dev(options.clone(), move |status, reason| {
on_exit_(status, reason)
})?;

self.run_dev_watcher(child, options, on_exit)
}
}
}

Expand Down

0 comments on commit 0983d7c

Please sign in to comment.