@@ -3,7 +3,7 @@ import { Client } from "fb-watchman";
33const client = new Client ( ) ;
44const clientB = new Client ( { } ) ;
55
6- client . capabilityCheck ( { optional : [ ] , required : [ "relative_root" ] } , e => {
6+ client . capabilityCheck ( { optional : [ ] , required : [ "relative_root" ] } , ( e ) => {
77 if ( e ) {
88 client . end ( ) ;
99 return ;
@@ -12,3 +12,202 @@ client.capabilityCheck({ optional: [], required: ["relative_root"] }, e => {
1212client . connect ( ) ;
1313
1414client . command ( [ "watch-project" , "/tmp" ] , ( ) => { } ) ;
15+
16+ client . command ( [ "watch-project" , "/tmp" ] , ( error , resp ) => {
17+ if ( error ) {
18+ client . end ( ) ;
19+ return ;
20+ }
21+
22+ // Verify that resp.watch is not any:
23+ // @ts -expect-error
24+ const not_any : number = resp . watch ;
25+ const watch : string = resp . watch ;
26+ } ) ;
27+
28+ // @ts -expect-error
29+ client . command ( [ "watch-project" , "/tmp" , "INVALID ARG" ] , ( ) => { } ) ;
30+
31+ client . command (
32+ [
33+ "subscribe" ,
34+ "/" ,
35+ "test" ,
36+ {
37+ expression : [ "allof" , [ "type" , "f" ] , [ "name" , "*.js" ] ] ,
38+ fields : [ "name" , "size" , "mtime_ms" ] ,
39+ } ,
40+ ] ,
41+ ( ) => { } ,
42+ ) ;
43+
44+ client . command (
45+ [
46+ "subscribe" ,
47+ "/" ,
48+ "test" ,
49+ {
50+ expression : [
51+ "allof" ,
52+ [ "dirname" , "src/components" ] ,
53+ [ "anyof" , [ "suffix" , [ "js" , "tsx" , "ts" ] ] , [ "match" , "package.json" , "basename" ] ] ,
54+ ] ,
55+ fields : [ "name" , "type" ] ,
56+ } ,
57+ ] ,
58+ ( ) => { } ,
59+ ) ;
60+
61+ client . command (
62+ [
63+ "subscribe" ,
64+ "/" ,
65+ "test" ,
66+ {
67+ expression : [
68+ "allof" ,
69+ [ "since" , 1234567890 , "mtime" ] ,
70+ [ "size" , "gt" , 1024 ] ,
71+ [ "not" , [ "name" , [ "node_modules" , ".git" ] , "wholename" ] ] ,
72+ ] ,
73+ } ,
74+ ] ,
75+ ( ) => { } ,
76+ ) ;
77+
78+ client . command (
79+ [
80+ "subscribe" ,
81+ "/" ,
82+ "test" ,
83+ {
84+ expression : [ "anyof" , [ "iname" , "*.test.js" ] , [ "dirname" , "tests" , [ "depth" , "le" , 2 ] ] ] ,
85+ fields : [ "name" , "exists" ] ,
86+ } ,
87+ ] ,
88+ ( ) => { } ,
89+ ) ;
90+
91+ client . command (
92+ [
93+ "subscribe" ,
94+ "/" ,
95+ "test" ,
96+ {
97+ expression : [
98+ "allof" ,
99+ [ "true" ] ,
100+ [ "not" , [ "anyof" , [ "dirname" , "dist" ] , [ "dirname" , "build" ] , [ "name" , [ "*.min.js" , "*.map" ] ] ] ] ,
101+ [ "exists" ] ,
102+ ] ,
103+ fields : [ "name" , "type" , "size" ] ,
104+ } ,
105+ ] ,
106+ ( ) => { } ,
107+ ) ;
108+
109+ client . command (
110+ [
111+ "subscribe" ,
112+ "/" ,
113+ "test" ,
114+ {
115+ expression : [
116+ "anyof" ,
117+ [ "allof" , [ "type" , "f" ] , [ "suffix" , [ "md" , "txt" ] ] ] ,
118+ [ "allof" , [ "type" , "d" ] , [ "match" , "test-*" ] ] ,
119+ ] ,
120+ } ,
121+ ] ,
122+ ( ) => { } ,
123+ ) ;
124+
125+ client . command (
126+ [
127+ "subscribe" ,
128+ "/" ,
129+ "test" ,
130+ {
131+ expression : [
132+ "allof" ,
133+ [ "anyof" , [ "dirname" , "src/api" ] , [ "dirname" , "src/utils" ] ] ,
134+ [ "since" , "c:1234567890" ] ,
135+ [ "not" , [ "empty" ] ] ,
136+ ] ,
137+ relative_root : "src" ,
138+ } ,
139+ ] ,
140+ ( ) => { } ,
141+ ) ;
142+
143+ client . command (
144+ [
145+ "subscribe" ,
146+ "/" ,
147+ "test" ,
148+ {
149+ expression : [
150+ "anyof" ,
151+ [ "allof" , [ "type" , "f" ] , [ "size" , "lt" , 10240 ] , [ "suffix" , "json" ] ] ,
152+ [ "allof" , [ "type" , "l" ] , [ "name" , "*.config" ] ] ,
153+ ] ,
154+ fields : [ "name" , "size" , "type" ] ,
155+ } ,
156+ ] ,
157+ ( ) => { } ,
158+ ) ;
159+
160+ // Invalid expression
161+ client . command (
162+ [
163+ // @ts -expect-error
164+ "subscribe" ,
165+ "/" ,
166+ "test" ,
167+ {
168+ expression : [ "INVALID" , [ "type" , "f" ] , [ "name" , "*.js" ] ] ,
169+ fields : [ "name" , "size" , "mtime_ms" ] ,
170+ } ,
171+ ] ,
172+ ( ) => { } ,
173+ ) ;
174+
175+ client . on ( "subscription" , ( resp ) => {
176+ // @ts -expect-error
177+ const not_any : number = resp . root ;
178+
179+ console . log ( "Subscription update received:" ) ;
180+ console . log ( "- Watch root:" , resp . root ) ;
181+ console . log ( "- Subscription name:" , resp . subscription ) ;
182+
183+ resp . files . forEach ( ( file ) => {
184+ // @ts -expect-error
185+ const not_any : number = file . name ;
186+ const name : string = file . name ;
187+
188+ console . log ( "Changed file:" , {
189+ name,
190+ size : file . size ,
191+ mtime : file . mtime_ms ,
192+ exists : file . exists ,
193+ type : file . type ,
194+ } ) ;
195+
196+ // Handle different file types
197+ switch ( file . type ) {
198+ case undefined :
199+ break ;
200+ case "f" :
201+ console . log ( "Regular file changed:" , file . name ) ;
202+ break ;
203+ case "d" :
204+ console . log ( "Directory changed:" , file . name ) ;
205+ break ;
206+ case "l" :
207+ console . log ( "Symlink changed:" , file . name ) ;
208+ break ;
209+ // @ts -expect-error
210+ case "INVALID" :
211+ }
212+ } ) ;
213+ } ) ;
0 commit comments