@@ -12,7 +12,12 @@ use relay_compiler::{
12
12
config:: { Config , SingleProjectConfigFile , TypegenLanguage } ,
13
13
FileSourceKind , RemotePersister ,
14
14
} ;
15
- use std:: { env:: current_dir, path:: PathBuf , sync:: Arc } ;
15
+ use std:: {
16
+ env:: { self , current_dir} ,
17
+ path:: PathBuf ,
18
+ process:: Command ,
19
+ sync:: Arc ,
20
+ } ;
16
21
use structopt:: StructOpt ;
17
22
18
23
#[ derive( StructOpt ) ]
@@ -86,14 +91,23 @@ async fn main() {
86
91
std:: process:: exit ( 1 ) ;
87
92
} ) ;
88
93
config. operation_persister = Some ( Box :: new ( RemotePersister ) ) ;
89
- // TODO: Check if watchman is available
90
- config. file_source_config = FileSourceKind :: Glob ;
94
+ config. file_source_config = if should_use_watchman ( ) {
95
+ FileSourceKind :: Watchman
96
+ } else {
97
+ FileSourceKind :: Glob
98
+ } ;
99
+
100
+ if opt. watch && !matches ! ( & config. file_source_config, FileSourceKind :: Watchman ) {
101
+ panic ! (
102
+ "Cannot run relay in watch mode if `watchman` is not available (or explicitly disabled)."
103
+ ) ;
104
+ }
91
105
92
106
let compiler = Compiler :: new ( Arc :: new ( config) , Arc :: new ( common:: NoopPerfLogger ) ) ;
93
107
94
108
if opt. watch {
95
109
if let Err ( err) = compiler. watch ( ) . await {
96
- error ! ( "{}" , err) ;
110
+ error ! ( "Watchman error: {}" , err) ;
97
111
std:: process:: exit ( 1 ) ;
98
112
}
99
113
} else {
@@ -108,3 +122,15 @@ async fn main() {
108
122
}
109
123
}
110
124
}
125
+
126
+ /// Check if `watchman` is available.
127
+ /// Additionally, this method is checking for an existence of `FORCE_NO_WATCHMAN`
128
+ /// environment variable. If this `FORCE_NO_WATCHMAN` is set, this method will return `false`
129
+ /// and compiler will use non-watchman file finder.
130
+ fn should_use_watchman ( ) -> bool {
131
+ let check_watchman = Command :: new ( "watchman" )
132
+ . args ( [ "list-capabilities" ] )
133
+ . output ( ) ;
134
+
135
+ check_watchman. is_ok ( ) && env:: var ( "FORCE_NO_WATCHMAN" ) . is_err ( )
136
+ }
0 commit comments