Skip to content

Commit 76f9db5

Browse files
committed
[common] Add FLOWLIB_ROOT variable
1 parent 1efab19 commit 76f9db5

File tree

3 files changed

+42
-33
lines changed

3 files changed

+42
-33
lines changed

src/commands/commandUtils.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ let file_options =
502502
let msg = "Could not locate flowlib files" in
503503
FlowExitStatus.(exit ~msg Could_not_find_flowconfig)
504504
in
505-
let ignores_of_arg root patterns extras =
505+
let ignores_of_arg root default_lib_dir patterns extras =
506506
let patterns = Core_list.rev_append extras patterns in
507507
Core_list.map ~f:(fun s ->
508508
let root = Path.to_string root
@@ -511,6 +511,8 @@ let file_options =
511511
|> remove_exclusion
512512
|> Str.split_delim Files.project_root_token
513513
|> String.concat root
514+
|> Str.split_delim Files.flowlib_root_token
515+
|> String.concat default_lib_dir
514516
|> Str.regexp in
515517
(s, reg)
516518
) patterns
@@ -560,25 +562,29 @@ let file_options =
560562
fun ~root ~no_flowlib ~temp_dir ~includes ~ignores ~libs ~untyped ~declarations flowconfig ->
561563
let default_lib_dir =
562564
let no_flowlib = no_flowlib || FlowConfig.no_flowlib flowconfig in
563-
Some (default_lib_dir ~no_flowlib temp_dir)
565+
default_lib_dir ~no_flowlib temp_dir
564566
in
565567
let ignores = ignores_of_arg
566568
root
569+
(Path.to_string default_lib_dir)
567570
(FlowConfig.ignores flowconfig)
568571
ignores in
569572
let untyped = ignores_of_arg
570573
root
574+
(Path.to_string default_lib_dir)
571575
(FlowConfig.untyped flowconfig)
572576
untyped in
573577
let declarations = ignores_of_arg
574578
root
579+
(Path.to_string default_lib_dir)
575580
(FlowConfig.declarations flowconfig)
576581
declarations in
577582
let lib_paths = lib_paths ~root flowconfig libs in
578583
let includes =
579584
includes
580585
|> Core_list.rev_append (FlowConfig.includes flowconfig)
581586
|> includes_of_arg ~root ~lib_paths in
587+
let default_lib_dir = Some (default_lib_dir) in
582588
{ Files.
583589
default_lib_dir;
584590
ignores;

src/common/files.ml

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -271,37 +271,6 @@ let get_all =
271271
in
272272
fun next -> get_all_rec next SSet.empty
273273

274-
let init ?(flowlibs_only=false) (options: options) =
275-
let node_module_filter = is_node_module options in
276-
let libs = if flowlibs_only then [] else options.lib_paths in
277-
let libs, filter = match options.default_lib_dir with
278-
| None -> libs, is_valid_path ~options
279-
| Some root ->
280-
let is_in_flowlib = is_prefix (Path.to_string root) in
281-
let is_valid_path = is_valid_path ~options in
282-
let filter path = is_in_flowlib path || is_valid_path path in
283-
root::libs, filter
284-
in
285-
(* preserve enumeration order *)
286-
let libs = if libs = []
287-
then []
288-
else
289-
let get_next lib =
290-
let lib_str = Path.to_string lib in
291-
let filter' path = path = lib_str || filter path in
292-
make_next_files_following_symlinks
293-
~node_module_filter
294-
~path_filter:filter'
295-
~realpath_filter:filter'
296-
~error_filter:(fun _ -> true)
297-
[lib]
298-
in
299-
libs
300-
|> Core_list.map ~f:(fun lib -> SSet.elements (get_all (get_next lib)))
301-
|> List.flatten
302-
in
303-
(libs, SSet.of_list libs)
304-
305274
(* Local reference to the module exported by a file. Like other local references
306275
to modules imported by the file, it is a member of Context.module_map. *)
307276
let module_ref file =
@@ -316,6 +285,8 @@ let absolute_path_regexp = Str.regexp "^\\(/\\|[A-Za-z]:[/\\\\]\\)"
316285

317286
let project_root_token = Str.regexp_string "<PROJECT_ROOT>"
318287

288+
let flowlib_root_token = Str.regexp_string "<FLOWLIB_ROOT>"
289+
319290
let is_matching path pattern_list =
320291
List.fold_left (
321292
fun current (pattern, rx) ->
@@ -361,6 +332,37 @@ let wanted ~options lib_fileset =
361332
let watched_paths options =
362333
Path_matcher.stems options.includes
363334

335+
let init ?(flowlibs_only=false) (options: options) =
336+
let node_module_filter = is_node_module options in
337+
let libs = if flowlibs_only then [] else options.lib_paths in
338+
let libs, filter = match options.default_lib_dir with
339+
| None -> libs, is_valid_path ~options
340+
| Some root ->
341+
let is_in_flowlib = is_prefix (Path.to_string root) in
342+
let is_valid_path = is_valid_path ~options in
343+
let filter path = (is_in_flowlib path || is_valid_path path) && (not (is_ignored options path)) in
344+
root::libs, filter
345+
in
346+
(* preserve enumeration order *)
347+
let libs = if libs = []
348+
then []
349+
else
350+
let get_next lib =
351+
let lib_str = Path.to_string lib in
352+
let filter' path = path = lib_str || filter path in
353+
make_next_files_following_symlinks
354+
~node_module_filter
355+
~path_filter:filter'
356+
~realpath_filter:filter'
357+
~error_filter:(fun _ -> true)
358+
[lib]
359+
in
360+
libs
361+
|> Core_list.map ~f:(fun lib -> SSet.elements (get_all (get_next lib)))
362+
|> List.flatten
363+
in
364+
(libs, SSet.of_list libs)
365+
364366
(**
365367
* Creates a "next" function (see also: `get_all`) for finding the files in a
366368
* given FlowConfig root. This means all the files under the root and all the

src/common/files.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ val parent_dir_name: Str.regexp
6565
val absolute_path_regexp: Str.regexp
6666

6767
val project_root_token: Str.regexp
68+
val flowlib_root_token: Str.regexp
6869

6970
val watched_paths: options -> Path.t list
7071

0 commit comments

Comments
 (0)