diff --git a/src/commands/commandUtils.ml b/src/commands/commandUtils.ml index ba5b5b5a728..a8667491776 100644 --- a/src/commands/commandUtils.ml +++ b/src/commands/commandUtils.ml @@ -568,7 +568,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 -> @@ -578,6 +578,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)) @@ -638,17 +640,30 @@ 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 (FlowConfig.ignores flowconfig) ignores in - let untyped = ignores_of_arg root (FlowConfig.untyped flowconfig) untyped in - let declarations = ignores_of_arg root (FlowConfig.declarations flowconfig) declarations 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; diff --git a/src/common/files.ml b/src/common/files.ml index ef5816bd7f2..06c6f86493c 100644 --- a/src/common/files.ml +++ b/src/common/files.ml @@ -300,43 +300,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 - (* TODO: better to parse json files, not ignore them *) - let filter' path = (path = lib_str || filter path) && not (is_json_file 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 = File_key.to_string file @@ -353,6 +316,8 @@ let absolute_path_regexp = Str.regexp "^\\(/\\|[A-Za-z]:[/\\\\]\\)" let project_root_token = Str.regexp_string "" +let flowlib_root_token = Str.regexp_string "" + let is_matching path pattern_list = List.fold_left (fun current (pattern, rx) -> @@ -393,6 +358,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 diff --git a/src/common/files.mli b/src/common/files.mli index b38ac8ee0fa..b7f48e5283a 100644 --- a/src/common/files.mli +++ b/src/common/files.mli @@ -84,6 +84,8 @@ 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 (* given a root, make a filter for file names *)