Skip to content

Commit aab2fd6

Browse files
committed
[common] Add FLOWLIB_ROOT variable
1 parent f6e4773 commit aab2fd6

File tree

3 files changed

+55
-42
lines changed

3 files changed

+55
-42
lines changed

src/commands/commandUtils.ml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ let file_options =
568568
let msg = "Could not locate flowlib files" in
569569
FlowExitStatus.(exit ~msg Could_not_find_flowconfig)
570570
in
571-
let ignores_of_arg root patterns extras =
571+
let ignores_of_arg root default_lib_dir patterns extras =
572572
let patterns = Core_list.rev_append extras patterns in
573573
Core_list.map
574574
~f:(fun s ->
@@ -578,6 +578,8 @@ let file_options =
578578
|> remove_exclusion
579579
|> Str.split_delim Files.project_root_token
580580
|> String.concat root
581+
|> Str.split_delim Files.flowlib_root_token
582+
|> String.concat default_lib_dir
581583
|> Str.regexp
582584
in
583585
(s, reg))
@@ -638,17 +640,30 @@ let file_options =
638640
fun ~root ~no_flowlib ~temp_dir ~includes ~ignores ~libs ~untyped ~declarations flowconfig ->
639641
let default_lib_dir =
640642
let no_flowlib = no_flowlib || FlowConfig.no_flowlib flowconfig in
641-
Some (default_lib_dir ~no_flowlib temp_dir)
643+
default_lib_dir ~no_flowlib temp_dir
642644
in
643-
let ignores = ignores_of_arg root (FlowConfig.ignores flowconfig) ignores in
644-
let untyped = ignores_of_arg root (FlowConfig.untyped flowconfig) untyped in
645-
let declarations = ignores_of_arg root (FlowConfig.declarations flowconfig) declarations in
645+
let ignores = ignores_of_arg
646+
root
647+
(Path.to_string default_lib_dir)
648+
(FlowConfig.ignores flowconfig)
649+
ignores in
650+
let untyped = ignores_of_arg
651+
root
652+
(Path.to_string default_lib_dir)
653+
(FlowConfig.untyped flowconfig)
654+
untyped in
655+
let declarations = ignores_of_arg
656+
root
657+
(Path.to_string default_lib_dir)
658+
(FlowConfig.declarations flowconfig)
659+
declarations in
646660
let lib_paths = lib_paths ~root flowconfig libs in
647661
let includes =
648662
includes
649663
|> Core_list.rev_append (FlowConfig.includes flowconfig)
650664
|> includes_of_arg ~root ~lib_paths
651665
in
666+
let default_lib_dir = Some (default_lib_dir) in
652667
{
653668
Files.default_lib_dir;
654669
ignores;

src/common/files.ml

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -300,43 +300,6 @@ let get_all =
300300
in
301301
(fun next -> get_all_rec next SSet.empty)
302302

303-
let init ?(flowlibs_only = false) (options : options) =
304-
let node_module_filter = is_node_module options in
305-
let libs =
306-
if flowlibs_only then
307-
[]
308-
else
309-
options.lib_paths
310-
in
311-
let (libs, filter) =
312-
match options.default_lib_dir with
313-
| None -> (libs, is_valid_path ~options)
314-
| Some root ->
315-
let is_in_flowlib = is_prefix (Path.to_string root) in
316-
let is_valid_path = is_valid_path ~options in
317-
let filter path = is_in_flowlib path || is_valid_path path in
318-
(root :: libs, filter)
319-
in
320-
(* preserve enumeration order *)
321-
let libs =
322-
if libs = [] then
323-
[]
324-
else
325-
let get_next lib =
326-
let lib_str = Path.to_string lib in
327-
(* TODO: better to parse json files, not ignore them *)
328-
let filter' path = (path = lib_str || filter path) && not (is_json_file path) in
329-
make_next_files_following_symlinks
330-
~node_module_filter
331-
~path_filter:filter'
332-
~realpath_filter:filter'
333-
~error_filter:(fun _ -> true)
334-
[lib]
335-
in
336-
libs |> Core_list.map ~f:(fun lib -> SSet.elements (get_all (get_next lib))) |> List.flatten
337-
in
338-
(libs, SSet.of_list libs)
339-
340303
(* Local reference to the module exported by a file. Like other local references
341304
to modules imported by the file, it is a member of Context.module_map. *)
342305
let module_ref file = File_key.to_string file
@@ -353,6 +316,8 @@ let absolute_path_regexp = Str.regexp "^\\(/\\|[A-Za-z]:[/\\\\]\\)"
353316

354317
let project_root_token = Str.regexp_string "<PROJECT_ROOT>"
355318

319+
let flowlib_root_token = Str.regexp_string "<FLOWLIB_ROOT>"
320+
356321
let is_matching path pattern_list =
357322
List.fold_left
358323
(fun current (pattern, rx) ->
@@ -393,6 +358,37 @@ let wanted ~options lib_fileset =
393358

394359
let watched_paths options = Path_matcher.stems options.includes
395360

361+
let init ?(flowlibs_only=false) (options: options) =
362+
let node_module_filter = is_node_module options in
363+
let libs = if flowlibs_only then [] else options.lib_paths in
364+
let libs, filter = match options.default_lib_dir with
365+
| None -> libs, is_valid_path ~options
366+
| Some root ->
367+
let is_in_flowlib = is_prefix (Path.to_string root) in
368+
let is_valid_path = is_valid_path ~options in
369+
let filter path = (is_in_flowlib path || is_valid_path path) && (not (is_ignored options path)) in
370+
root::libs, filter
371+
in
372+
(* preserve enumeration order *)
373+
let libs = if libs = []
374+
then []
375+
else
376+
let get_next lib =
377+
let lib_str = Path.to_string lib in
378+
let filter' path = path = lib_str || filter path in
379+
make_next_files_following_symlinks
380+
~node_module_filter
381+
~path_filter:filter'
382+
~realpath_filter:filter'
383+
~error_filter:(fun _ -> true)
384+
[lib]
385+
in
386+
libs
387+
|> Core_list.map ~f:(fun lib -> SSet.elements (get_all (get_next lib)))
388+
|> List.flatten
389+
in
390+
(libs, SSet.of_list libs)
391+
396392
(**
397393
* Creates a "next" function (see also: `get_all`) for finding the files in a
398394
* given FlowConfig root. This means all the files under the root and all the

src/common/files.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ val absolute_path_regexp : Str.regexp
8484

8585
val project_root_token : Str.regexp
8686

87+
val flowlib_root_token : Str.regexp
88+
8789
val watched_paths : options -> Path.t list
8890

8991
(* given a root, make a filter for file names *)

0 commit comments

Comments
 (0)