Skip to content

Commit

Permalink
[common] Add FLOWLIB_ROOT variable
Browse files Browse the repository at this point in the history
  • Loading branch information
goodmind committed May 16, 2019
1 parent 1efab19 commit 76f9db5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 33 deletions.
10 changes: 8 additions & 2 deletions src/commands/commandUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ let file_options =
let msg = "Could not locate flowlib files" in
FlowExitStatus.(exit ~msg Could_not_find_flowconfig)
in
let ignores_of_arg root patterns extras =
let ignores_of_arg root default_lib_dir patterns extras =
let patterns = Core_list.rev_append extras patterns in
Core_list.map ~f:(fun s ->
let root = Path.to_string root
Expand All @@ -511,6 +511,8 @@ let file_options =
|> remove_exclusion
|> Str.split_delim Files.project_root_token
|> String.concat root
|> Str.split_delim Files.flowlib_root_token
|> String.concat default_lib_dir
|> Str.regexp in
(s, reg)
) patterns
Expand Down Expand Up @@ -560,25 +562,29 @@ let file_options =
fun ~root ~no_flowlib ~temp_dir ~includes ~ignores ~libs ~untyped ~declarations flowconfig ->
let default_lib_dir =
let no_flowlib = no_flowlib || FlowConfig.no_flowlib flowconfig in
Some (default_lib_dir ~no_flowlib temp_dir)
default_lib_dir ~no_flowlib temp_dir
in
let ignores = ignores_of_arg
root
(Path.to_string default_lib_dir)
(FlowConfig.ignores flowconfig)
ignores in
let untyped = ignores_of_arg
root
(Path.to_string default_lib_dir)
(FlowConfig.untyped flowconfig)
untyped in
let declarations = ignores_of_arg
root
(Path.to_string default_lib_dir)
(FlowConfig.declarations flowconfig)
declarations in
let lib_paths = lib_paths ~root flowconfig libs in
let includes =
includes
|> Core_list.rev_append (FlowConfig.includes flowconfig)
|> includes_of_arg ~root ~lib_paths in
let default_lib_dir = Some (default_lib_dir) in
{ Files.
default_lib_dir;
ignores;
Expand Down
64 changes: 33 additions & 31 deletions src/common/files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -271,37 +271,6 @@ let get_all =
in
fun next -> get_all_rec next SSet.empty

let init ?(flowlibs_only=false) (options: options) =
let node_module_filter = is_node_module options in
let libs = if flowlibs_only then [] else options.lib_paths in
let libs, filter = match options.default_lib_dir with
| None -> libs, is_valid_path ~options
| Some root ->
let is_in_flowlib = is_prefix (Path.to_string root) in
let is_valid_path = is_valid_path ~options in
let filter path = is_in_flowlib path || is_valid_path path in
root::libs, filter
in
(* preserve enumeration order *)
let libs = if libs = []
then []
else
let get_next lib =
let lib_str = Path.to_string lib in
let filter' path = path = lib_str || filter path in
make_next_files_following_symlinks
~node_module_filter
~path_filter:filter'
~realpath_filter:filter'
~error_filter:(fun _ -> true)
[lib]
in
libs
|> Core_list.map ~f:(fun lib -> SSet.elements (get_all (get_next lib)))
|> List.flatten
in
(libs, SSet.of_list libs)

(* Local reference to the module exported by a file. Like other local references
to modules imported by the file, it is a member of Context.module_map. *)
let module_ref file =
Expand All @@ -316,6 +285,8 @@ let absolute_path_regexp = Str.regexp "^\\(/\\|[A-Za-z]:[/\\\\]\\)"

let project_root_token = Str.regexp_string "<PROJECT_ROOT>"

let flowlib_root_token = Str.regexp_string "<FLOWLIB_ROOT>"

let is_matching path pattern_list =
List.fold_left (
fun current (pattern, rx) ->
Expand Down Expand Up @@ -361,6 +332,37 @@ let wanted ~options lib_fileset =
let watched_paths options =
Path_matcher.stems options.includes

let init ?(flowlibs_only=false) (options: options) =
let node_module_filter = is_node_module options in
let libs = if flowlibs_only then [] else options.lib_paths in
let libs, filter = match options.default_lib_dir with
| None -> libs, is_valid_path ~options
| Some root ->
let is_in_flowlib = is_prefix (Path.to_string root) in
let is_valid_path = is_valid_path ~options in
let filter path = (is_in_flowlib path || is_valid_path path) && (not (is_ignored options path)) in
root::libs, filter
in
(* preserve enumeration order *)
let libs = if libs = []
then []
else
let get_next lib =
let lib_str = Path.to_string lib in
let filter' path = path = lib_str || filter path in
make_next_files_following_symlinks
~node_module_filter
~path_filter:filter'
~realpath_filter:filter'
~error_filter:(fun _ -> true)
[lib]
in
libs
|> Core_list.map ~f:(fun lib -> SSet.elements (get_all (get_next lib)))
|> List.flatten
in
(libs, SSet.of_list libs)

(**
* Creates a "next" function (see also: `get_all`) for finding the files in a
* given FlowConfig root. This means all the files under the root and all the
Expand Down
1 change: 1 addition & 0 deletions src/common/files.mli
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ val parent_dir_name: Str.regexp
val absolute_path_regexp: Str.regexp

val project_root_token: Str.regexp
val flowlib_root_token: Str.regexp

val watched_paths: options -> Path.t list

Expand Down

0 comments on commit 76f9db5

Please sign in to comment.