@@ -18,7 +18,7 @@ pub struct StartFromPaths {
1818
1919impl SystemStart for StartFromPaths {
2020 fn resolve_input ( & self , ctx : & StartupContext ) -> Result < SystemStartArgs , Box < InputError > > {
21- let span = tracing:: debug_span!( "StartFromTrailingArgs ::resolve_input" ) ;
21+ let span = tracing:: debug_span!( "StartFromPaths ::resolve_input" ) ;
2222 let _g = span. entered ( ) ;
2323
2424 let port = self . port ;
@@ -40,32 +40,59 @@ impl SystemStart for StartFromPaths {
4040 Ok ( input)
4141 } ;
4242
43- let mut input_stub = Input :: default ( ) ;
43+ let explicit_watch_count =
44+ self . watch_sub_opts . paths . len ( ) + self . watch_sub_opts . before . len ( ) ;
4445
45- ' watch_overrides: {
46- // if there is some explicit --watch.paths given, we want to ONLY support that
47- let total = self . watch_sub_opts . paths . len ( ) + self . watch_sub_opts . before . len ( ) ;
48- if total == 0 {
49- tracing:: debug!( "not appending watchers since paths + before tasks were empty" ) ;
50- break ' watch_overrides;
51- }
52-
53- let span = tracing:: debug_span!( parent: None , "StartFromTrailingArgs watch_sub_opts" ) ;
54- let _g = span. entered ( ) ;
55- tracing:: debug!( "{} paths to watch" , self . watch_sub_opts. paths. len( ) ) ;
56- tracing:: debug!( "{} sh_commands to run" , self . watch_sub_opts. run. len( ) ) ;
57- let multi = MultiWatch :: from ( self . watch_sub_opts . clone ( ) ) ;
58- input_stub. watchers = vec ! [ multi] ;
59- input_stub. config . infer_watchers = InferWatchers :: None ;
60- }
46+ let input = if explicit_watch_count > 0 {
47+ with_explicit_paths ( & self . watch_sub_opts )
48+ } else {
49+ with_inferred_watchers ( & self . watch_sub_opts )
50+ } ;
6151
6252 Ok ( SystemStartArgs :: InputOnlyDeferred {
63- input : input_stub ,
53+ input,
6454 create : Lazy :: new ( Box :: new ( lazy) ) ,
6555 } )
6656 }
6757}
6858
59+ /// when we have given explicit paths on the command line, we are opting out of inferred watchers,
60+ /// for example, the following command would normally create a watcher for the path 'public'
61+ /// `bslive public`
62+ /// however, if we want to watch something else, we need a way to opt-out of the inferred ones, like:
63+ /// `bslive public --watch.paths src`
64+ /// ^ in this case, we only want to watch 'src' and prevent inferred things later.
65+ fn with_explicit_paths ( opts : & WatchSubOpts ) -> Input {
66+ let mut input = Input :: default ( ) ;
67+ let span = tracing:: debug_span!( parent: None , "StartFromPaths watch_overrides" ) ;
68+ let _g = span. entered ( ) ;
69+ tracing:: debug!( "{} paths to watch" , opts. paths. len( ) ) ;
70+ tracing:: debug!( "{} sh_commands to run" , opts. run. len( ) ) ;
71+ let multi = MultiWatch :: from ( opts. clone ( ) ) ;
72+ input. watchers = vec ! [ multi] ;
73+ input. config . infer_watchers = InferWatchers :: None ;
74+ input
75+ }
76+
77+ /// in this second scenario, we're probably starting a server without explicit watch paths given as CLI args.
78+ /// eg: `bslive .`
79+ /// this means we'll watch the directory, but it might accidentally end up watching a noisy build folder or similar
80+ /// in that case, we still want to forward --ignore and --only args, but nothing else to allow the user to opt-out
81+ /// eg: `bslive . --only dist/*.html`
82+ fn with_inferred_watchers ( opts : & WatchSubOpts ) -> Input {
83+ let mut input = Input :: default ( ) ;
84+ let span = tracing:: debug_span!( parent: None , "StartFromPaths global_overrides" ) ;
85+ let _g = span. entered ( ) ;
86+ tracing:: debug!( "{} ignore add" , opts. ignore. len( ) ) ;
87+ let multi = MultiWatch :: from ( opts. clone ( ) ) ;
88+ if let Some ( spec_from_cli) = multi. spec {
89+ input. config . global_fs_ignore = spec_from_cli. ignore ;
90+ input. config . global_fs_only = spec_from_cli. only ;
91+ input. config . global_fs_debounce = spec_from_cli. debounce ;
92+ }
93+ input
94+ }
95+
6996fn from_dir_paths < T : AsRef < str > > (
7097 cwd : & Path ,
7198 paths : & [ T ] ,
0 commit comments