Skip to content

Commit 20c3f1e

Browse files
committed
watching can be disabled
1 parent 96857ca commit 20c3f1e

File tree

13 files changed

+118
-34
lines changed

13 files changed

+118
-34
lines changed

crates/bsnext_input/src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,26 @@ impl FromStr for Input {
122122

123123
#[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)]
124124
pub struct InputConfig {
125-
pub infer_watchers: InferWatchers,
125+
pub watchers: WatchGlobalConfig,
126126
pub global_fs_ignore: Option<PathPattern>,
127127
pub global_fs_only: Option<PathPattern>,
128128
pub global_fs_debounce: Option<DebounceDuration>,
129129
}
130130

131+
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
132+
pub enum WatchGlobalConfig {
133+
Enabled { infer: InferWatchers },
134+
Disabled,
135+
}
136+
137+
impl Default for WatchGlobalConfig {
138+
fn default() -> Self {
139+
Self::Enabled {
140+
infer: InferWatchers::default(),
141+
}
142+
}
143+
}
144+
131145
#[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)]
132146
pub enum InferWatchers {
133147
None,

crates/bsnext_system/examples/without_stdout.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub async fn main() -> Result<(), anyhow::Error> {
2424
logging: Default::default(),
2525
format: Default::default(),
2626
watch_sub_opts: Default::default(),
27+
no_watch: false,
2728
};
2829

2930
let (events_sender, mut events_receiver) = mpsc::channel::<AnyEvent>(1);

crates/bsnext_system/src/args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ pub struct Args {
3333
#[clap(flatten)]
3434
pub watch_opts: WatchSubOpts,
3535

36+
#[clap(long)]
37+
pub no_watch: bool,
38+
3639
/// Paths to serve + possibly watch, incompatible with `-i` option
3740
pub trailing: Vec<String>,
3841
}

crates/bsnext_system/src/cli.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::args::{Args, SubCommands};
2-
32
use crate::export::export_cmd;
43
use crate::start;
54
use crate::start::start_command::StartCommand;
@@ -81,6 +80,7 @@ where
8180
watch_sub_opts: args.watch_opts,
8281
logging,
8382
format,
83+
no_watch: args.no_watch,
8484
})
8585
});
8686

@@ -110,6 +110,7 @@ async fn async_init(
110110
watch_sub_opts: Default::default(),
111111
logging,
112112
format,
113+
no_watch: true,
113114
};
114115
let cwd = PathBuf::from(current_dir().unwrap().to_string_lossy().to_string());
115116
let result = export_cmd(&cwd, &args.fs_opts, &args.input_opts, &cmd, &start_cmd).await;

crates/bsnext_system/src/start/start_command.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ pub struct StartCommand {
2626
/// Paths to serve + possibly watch, incompatible with `-i` option
2727
pub trailing: Vec<String>,
2828

29+
/// disable all auto-watching
30+
#[clap(long)]
31+
pub no_watch: bool,
32+
2933
/// additional watchers
3034
#[clap(flatten)]
3135
pub watch_sub_opts: WatchSubOpts,

crates/bsnext_system/src/start/start_kind.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl StartKind {
5151
cors: cmd.cors.then_some(CorsOpts::Cors(true)),
5252
..Default::default()
5353
},
54+
no_watch: cmd.no_watch,
5455
});
5556
}
5657

crates/bsnext_system/src/start/start_kind/snapshots/bsnext_system__start__start_kind__start_from_paths__test__test-2.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ servers:
2323
watchers: []
2424
run: {}
2525
config:
26-
infer_watchers: RoutesAndServers
26+
watchers:
27+
Enabled:
28+
infer: RoutesAndServers
2729
global_fs_ignore: ~
2830
global_fs_only: ~
2931
global_fs_debounce: ~

crates/bsnext_system/src/start/start_kind/snapshots/bsnext_system__start__start_kind__start_from_paths__test__test.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ Input {
4747
watchers: [],
4848
run: {},
4949
config: InputConfig {
50-
infer_watchers: RoutesAndServers,
50+
watchers: Enabled {
51+
infer: RoutesAndServers,
52+
},
5153
global_fs_ignore: None,
5254
global_fs_only: None,
5355
global_fs_debounce: None,

crates/bsnext_system/src/start/start_kind/start_from_paths.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use bsnext_input::path_def::PathDef;
33
use bsnext_input::route::{DirRoute, MultiWatch, Opts, Route, RouteKind};
44
use bsnext_input::server_config::{ServerConfig, ServerIdentity};
55
use bsnext_input::startup::{Lazy, StartupContext, SystemStart, SystemStartArgs};
6-
use bsnext_input::{InferWatchers, Input, InputError, PathDefinition, PathDefs, PathError};
6+
use bsnext_input::{
7+
InferWatchers, Input, InputError, PathDefinition, PathDefs, PathError, WatchGlobalConfig,
8+
};
79
use std::path::{Path, PathBuf};
810

911
#[derive(Debug)]
@@ -14,6 +16,7 @@ pub struct StartFromPaths {
1416
pub force: bool,
1517
pub route_opts: Opts,
1618
pub watch_sub_opts: WatchSubOpts,
19+
pub no_watch: bool,
1720
}
1821

1922
impl SystemStart for StartFromPaths {
@@ -40,13 +43,18 @@ impl SystemStart for StartFromPaths {
4043
Ok(input)
4144
};
4245

43-
let explicit_watch_count =
44-
self.watch_sub_opts.paths.len() + self.watch_sub_opts.before.len();
45-
46-
let input = if explicit_watch_count > 0 {
47-
with_explicit_paths(&self.watch_sub_opts)
46+
let input = if self.no_watch {
47+
let mut input = Input::default();
48+
input.config.watchers = WatchGlobalConfig::Disabled;
49+
input
4850
} else {
49-
with_inferred_watchers(&self.watch_sub_opts)
51+
let explicit_watch_count =
52+
self.watch_sub_opts.paths.len() + self.watch_sub_opts.before.len();
53+
if explicit_watch_count > 0 {
54+
with_explicit_paths(&self.watch_sub_opts)
55+
} else {
56+
with_inferred_watchers(&self.watch_sub_opts)
57+
}
5058
};
5159

5260
Ok(SystemStartArgs::InputOnlyDeferred {
@@ -70,7 +78,9 @@ fn with_explicit_paths(opts: &WatchSubOpts) -> Input {
7078
tracing::debug!("{} sh_commands to run", opts.run.len());
7179
let multi = MultiWatch::from(opts.clone());
7280
input.watchers = vec![multi];
73-
input.config.infer_watchers = InferWatchers::None;
81+
input.config.watchers = WatchGlobalConfig::Enabled {
82+
infer: InferWatchers::None,
83+
};
7484
input
7585
}
7686

@@ -171,6 +181,7 @@ mod test {
171181
force: false,
172182
route_opts: Default::default(),
173183
watch_sub_opts: Default::default(),
184+
no_watch: false,
174185
};
175186
let ctx = StartupContext {
176187
cwd: tmp_dir.path().to_path_buf(),

crates/bsnext_system/src/watch/watch_sub_opts.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ pub struct WatchSubOpts {
2525
pub initial: bool,
2626
}
2727

28+
impl WatchSubOpts {
29+
pub fn empty() -> Self {
30+
Self::default()
31+
}
32+
}
33+
2834
impl From<WatchSubOpts> for MultiWatch {
2935
fn from(value: WatchSubOpts) -> Self {
3036
let span = tracing::debug_span!("creating MultiWatch");

0 commit comments

Comments
 (0)