Skip to content

Commit 0983d7c

Browse files
authored
feat(cli): add --no-watch argument to the dev command, closes #4617 (#4793)
1 parent 0246205 commit 0983d7c

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

.changes/no-watch.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"cli.rs": minor
3+
"cli.js": minor
4+
---
5+
6+
Added `--no-watch` argument to the `dev` command to disable the file watcher.

tooling/cli/src/dev.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ pub struct Options {
5858
pub release_mode: bool,
5959
/// Command line arguments passed to the runner
6060
pub args: Vec<String>,
61+
/// Disable the file watcher
62+
#[clap(long)]
63+
pub no_watch: bool,
6164
}
6265

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

236239
let exit_on_panic = options.exit_on_panic;
240+
let no_watch = options.no_watch;
237241
interface.dev(options.into(), move |status, reason| {
238-
on_dev_exit(status, reason, exit_on_panic)
242+
on_dev_exit(status, reason, exit_on_panic, no_watch)
239243
})
240244
}
241245

242-
fn on_dev_exit(status: ExitStatus, reason: ExitReason, exit_on_panic: bool) {
243-
if !matches!(reason, ExitReason::TriggeredKill)
244-
&& (exit_on_panic || matches!(reason, ExitReason::NormalExit))
246+
fn on_dev_exit(status: ExitStatus, reason: ExitReason, exit_on_panic: bool, no_watch: bool) {
247+
if no_watch
248+
|| (!matches!(reason, ExitReason::TriggeredKill)
249+
&& (exit_on_panic || matches!(reason, ExitReason::NormalExit)))
245250
{
246251
kill_before_dev_process();
247252
#[cfg(not(debug_assertions))]

tooling/cli/src/interface/rust.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
str::FromStr,
1212
sync::{
1313
atomic::{AtomicBool, Ordering},
14-
mpsc::channel,
14+
mpsc::{channel, sync_channel},
1515
Arc, Mutex,
1616
},
1717
time::{Duration, Instant},
@@ -50,6 +50,7 @@ pub struct Options {
5050
pub features: Option<Vec<String>>,
5151
pub args: Vec<String>,
5252
pub config: Option<String>,
53+
pub no_watch: bool,
5354
}
5455

5556
impl From<crate::build::Options> for Options {
@@ -61,6 +62,7 @@ impl From<crate::build::Options> for Options {
6162
features: options.features,
6263
args: options.args,
6364
config: options.config,
65+
no_watch: true,
6466
}
6567
}
6668
}
@@ -74,6 +76,7 @@ impl From<crate::dev::Options> for Options {
7476
features: options.features,
7577
args: options.args,
7678
config: options.config,
79+
no_watch: options.no_watch,
7780
}
7881
}
7982
}
@@ -215,11 +218,23 @@ impl Interface for Rust {
215218
let on_exit = Arc::new(on_exit);
216219

217220
let on_exit_ = on_exit.clone();
218-
let child = self.run_dev(options.clone(), move |status, reason| {
219-
on_exit_(status, reason)
220-
})?;
221221

222-
self.run_dev_watcher(child, options, on_exit)
222+
if options.no_watch {
223+
let (tx, rx) = sync_channel(1);
224+
self.run_dev(options, move |status, reason| {
225+
tx.send(()).unwrap();
226+
on_exit_(status, reason)
227+
})?;
228+
229+
rx.recv().unwrap();
230+
Ok(())
231+
} else {
232+
let child = self.run_dev(options.clone(), move |status, reason| {
233+
on_exit_(status, reason)
234+
})?;
235+
236+
self.run_dev_watcher(child, options, on_exit)
237+
}
223238
}
224239
}
225240

0 commit comments

Comments
 (0)