From 837fc9908e08bbebfddf27b8ec67bf5a53d92622 Mon Sep 17 00:00:00 2001 From: Braden Napier Date: Fri, 16 Nov 2018 03:52:08 -0800 Subject: [PATCH 01/14] commit resolve_alias feature add tests for resolve_alias --- src/commands/commandUtils.ml | 1 + src/commands/config/flowConfig.ml | 14 +++- src/commands/config/flowConfig.mli | 2 + src/common/files.ml | 25 ++++++- src/common/files.mli | 6 +- src/services/inference/module/module_js.ml | 70 ++++++++++--------- .../.flowconfig | 3 + ...fig_module_system_node_resolve_dirname.exp | 53 ++++++++++++++ .../custom_resolve_dir/testproj/index.js | 3 + .../custom_resolve_dir/testproj2/index.js | 3 + .../node_modules/testproj/index.js | 3 + .../node_modules/testproj2/index.js | 3 + .../custom_resolve_dir/testproj2/index.js | 3 + .../subdir/sublevel.js | 7 ++ .../toplevel.js | 6 ++ 15 files changed, 163 insertions(+), 39 deletions(-) create mode 100644 tests/config_module_system_node_resolve_alias/.flowconfig create mode 100644 tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_dirname.exp create mode 100644 tests/config_module_system_node_resolve_alias/custom_resolve_dir/testproj/index.js create mode 100644 tests/config_module_system_node_resolve_alias/custom_resolve_dir/testproj2/index.js create mode 100644 tests/config_module_system_node_resolve_alias/node_modules/testproj/index.js create mode 100644 tests/config_module_system_node_resolve_alias/node_modules/testproj2/index.js create mode 100644 tests/config_module_system_node_resolve_alias/subdir/custom_resolve_dir/testproj2/index.js create mode 100644 tests/config_module_system_node_resolve_alias/subdir/sublevel.js create mode 100644 tests/config_module_system_node_resolve_alias/toplevel.js diff --git a/src/commands/commandUtils.ml b/src/commands/commandUtils.ml index ba5b5b5a728..64c81d12eef 100644 --- a/src/commands/commandUtils.ml +++ b/src/commands/commandUtils.ml @@ -659,6 +659,7 @@ let file_options = module_file_exts = FlowConfig.module_file_exts flowconfig; module_resource_exts = FlowConfig.module_resource_exts flowconfig; node_resolver_dirnames = FlowConfig.node_resolver_dirnames flowconfig; + node_resolver_aliases = FlowConfig.node_resolver_aliases flowconfig } let ignore_flag prev = diff --git a/src/commands/config/flowConfig.ml b/src/commands/config/flowConfig.ml index 66079d8d8e1..3d99bf0a480 100644 --- a/src/commands/config/flowConfig.ml +++ b/src/commands/config/flowConfig.ml @@ -90,6 +90,7 @@ module Opts = struct munge_underscores: bool; no_flowlib: bool; node_resolver_dirnames: string list; + node_resolver_aliases: string list; recursion_limit: int; root_name: string option; saved_state_fetcher: Options.saved_state_fetcher; @@ -139,6 +140,7 @@ module Opts = struct |> SSet.add ".mp4" |> SSet.add ".webm" +<<<<<<< HEAD let default_options = { abstract_locations = false; @@ -185,6 +187,7 @@ module Opts = struct munge_underscores = false; no_flowlib = false; node_resolver_dirnames = ["node_modules"]; + node_resolver_aliases = []; recursion_limit = 10000; root_name = None; saved_state_fetcher = Options.Dummy_fetcher; @@ -457,6 +460,13 @@ module Opts = struct (fun opts v -> let node_resolver_dirnames = v :: opts.node_resolver_dirnames in Ok { opts with node_resolver_dirnames }) ); + ( "module.system.node.resolve_alias", + string + ~init: (fun opts -> { opts with node_resolver_aliases = [] }) + ~multiple: true + (fun opts v -> + let node_resolver_aliases = v :: opts.node_resolver_aliases in + Ok {opts with node_resolver_aliases;}) ); ("module.use_strict", boolean (fun opts v -> Ok { opts with modules_are_use_strict = v })); ("munge_underscores", boolean (fun opts v -> Ok { opts with munge_underscores = v })); ( "name", @@ -979,7 +989,7 @@ let is_not_comment = (* Line starts with ; *) Str.regexp_string "\240\159\146\169"; (* Line starts with poop emoji *) - + ] in fun (_, line) -> @@ -1165,6 +1175,8 @@ let no_flowlib c = c.options.Opts.no_flowlib let node_resolver_dirnames c = c.options.Opts.node_resolver_dirnames +let node_resolver_aliases c = c.options.Opts.node_resolver_aliases + let recursion_limit c = c.options.Opts.recursion_limit let root_name c = c.options.Opts.root_name diff --git a/src/commands/config/flowConfig.mli b/src/commands/config/flowConfig.mli index 97fa9c6068c..7d5bbb52cbf 100644 --- a/src/commands/config/flowConfig.mli +++ b/src/commands/config/flowConfig.mli @@ -136,6 +136,8 @@ val no_flowlib : config -> bool val node_resolver_dirnames : config -> string list +val node_resolver_aliases: config -> string list + val required_version : config -> string option val recursion_limit : config -> int diff --git a/src/common/files.ml b/src/common/files.ml index ef5816bd7f2..151471d4461 100644 --- a/src/common/files.ml +++ b/src/common/files.ml @@ -17,6 +17,7 @@ type options = { module_file_exts: SSet.t; module_resource_exts: SSet.t; node_resolver_dirnames: string list; + node_resolver_aliases: string list; } let default_lib_dir options = options.default_lib_dir @@ -36,6 +37,7 @@ let module_file_exts options = options.module_file_exts let module_resource_exts options = options.module_resource_exts let node_resolver_dirnames options = options.node_resolver_dirnames +let node_resolver_aliases options = options.node_resolver_aliases let node_modules_containers = ref SSet.empty @@ -106,6 +108,9 @@ let is_valid_path = let is_node_module options path = List.mem (Filename.basename path) options.node_resolver_dirnames +let is_module_alias options path = + List.mem (Filename.basename path) options.node_resolver_aliases + let is_flow_file ~options = let is_valid_path = is_valid_path ~options in (fun path -> is_valid_path path && not (is_directory path)) @@ -185,7 +190,7 @@ let max_files = 1000 If kind_of_path fails, then we only emit a warning if error_filter passes *) let make_next_files_and_symlinks - ~node_module_filter ~path_filter ~realpath_filter ~error_filter paths = + ~node_module_filter ~module_alias_filter ~path_filter ~realpath_filter ~error_filter paths = let prefix_checkers = Core_list.map ~f:is_prefix paths in let rec process sz (acc, symlinks) files dir stack = if sz >= max_files then @@ -207,7 +212,7 @@ let make_next_files_and_symlinks else process sz (acc, symlinks) files dir stack | Dir (path, is_symlink) -> - if node_module_filter file then + if node_module_filter file || module_alias_filter file then node_modules_containers := SSet.add (Filename.dirname file) !node_modules_containers; let dirfiles = Array.to_list @@ try_readdir path in let symlinks = @@ -243,12 +248,13 @@ let make_next_files_and_symlinks and including any directories that are symlinked to even if they are outside of `paths`. *) let make_next_files_following_symlinks - ~node_module_filter ~path_filter ~realpath_filter ~error_filter paths = + ~node_module_filter ~module_alias_filter ~path_filter ~realpath_filter ~error_filter paths = let paths = Core_list.map ~f:Path.to_string paths in let cb = ref (make_next_files_and_symlinks ~node_module_filter + ~module_alias_filter ~path_filter ~realpath_filter ~error_filter @@ -281,6 +287,7 @@ let make_next_files_following_symlinks cb := make_next_files_and_symlinks ~node_module_filter + ~module_alias_filter ~path_filter:realpath_filter ~realpath_filter ~error_filter @@ -302,6 +309,7 @@ let get_all = let init ?(flowlibs_only = false) (options : options) = let node_module_filter = is_node_module options in + let module_alias_filter = is_module_alias options in let libs = if flowlibs_only then [] @@ -328,6 +336,7 @@ let init ?(flowlibs_only = false) (options : options) = let filter' path = (path = lib_str || filter path) && not (is_json_file path) in make_next_files_following_symlinks ~node_module_filter + ~module_alias_filter ~path_filter:filter' ~realpath_filter:filter' ~error_filter:(fun _ -> true) @@ -403,6 +412,7 @@ let watched_paths options = Path_matcher.stems options.includes *) let make_next_files ~root ~all ~subdir ~options ~libs = let node_module_filter = is_node_module options in + let module_alias_filter = is_module_alias options in let filter = if all then fun _ -> @@ -441,6 +451,7 @@ let make_next_files ~root ~all ~subdir ~options ~libs = in make_next_files_following_symlinks ~node_module_filter + ~module_alias_filter ~path_filter ~realpath_filter ~error_filter:filter @@ -572,6 +583,14 @@ let is_within_node_modules ~root ~options path = let node_resolver_dirnames = node_resolver_dirnames options |> SSet.of_list in not (SSet.inter directories node_resolver_dirnames |> SSet.is_empty) +(* Given a path, we want to know if it's a resolve alias. *) +let is_within_alias_directory ~root ~options path = + (* We use paths that are relative to the root, so that we ignore ancestor directories *) + let path = relative_path (Path.to_string root) path in + let directories = Str.split dir_sep path |> SSet.of_list in + let node_resolver_aliases = node_resolver_aliases options |> SSet.of_list in + not (SSet.inter directories node_resolver_aliases |> SSet.is_empty) + (* realpath doesn't work for non-existent paths. So let's find the longest existent prefix, run * realpath on that, and then append the rest to it *) diff --git a/src/common/files.mli b/src/common/files.mli index b38ac8ee0fa..2ec8726be00 100644 --- a/src/common/files.mli +++ b/src/common/files.mli @@ -17,9 +17,9 @@ type options = { module_file_exts: SSet.t; module_resource_exts: SSet.t; node_resolver_dirnames: string list; + node_resolver_aliases: string list; } -val default_lib_dir : options -> Path.t option val ignores : options -> (string * Str.regexp) list @@ -37,6 +37,8 @@ val module_resource_exts : options -> SSet.t val node_resolver_dirnames : options -> string list +val node_resolver_aliases: options -> string list + val node_modules_containers : SSet.t ref val global_file_name : string @@ -124,6 +126,8 @@ val mkdirp : string -> Unix.file_perm -> unit val is_within_node_modules : root:Path.t -> options:options -> string -> bool +val is_within_alias_directory: root:Path.t -> options: options -> string -> bool + val imaginary_realpath : string -> string val canonicalize_filenames : diff --git a/src/services/inference/module/module_js.ml b/src/services/inference/module/module_js.ml index 538461d59f4..b9b13b9938e 100644 --- a/src/services/inference/module/module_js.ml +++ b/src/services/inference/module/module_js.ml @@ -408,40 +408,42 @@ module Node = struct let rec node_module ~options ~reader node_modules_containers file loc resolution_acc dir r = let file_options = Options.file_options options in - lazy_seq - [ - lazy - ( if SSet.mem dir node_modules_containers then - lazy_seq - ( Files.node_resolver_dirnames file_options - |> Core_list.map ~f:(fun dirname -> - lazy - (resolve_relative - ~options - ~reader - loc - ?resolution_acc - dir - (spf "%s%s%s" dirname Filename.dir_sep r))) ) - else - None ); - lazy - (let parent_dir = Filename.dirname dir in - if dir = parent_dir then - None - else - node_module - ~options - ~reader - node_modules_containers - file - loc - resolution_acc - (Filename.dirname dir) - r); - ] - - let absolute r = Str.string_match Files.absolute_path_regexp r 0 + lazy_seq [ + lazy ( + if SSet.mem dir node_modules_containers then + lazy_seq([ + lazy ( + lazy_seq (Files.node_resolver_aliases file_options |> Core_list.map ~f:(fun dirname -> + lazy (resolve_relative + ~options + loc ?resolution_acc dir (spf "%s%s%s" dirname Filename.dir_sep r) + ) + )) + ); + lazy ( + lazy_seq (Files.node_resolver_dirnames file_options |> Core_list.map ~f:(fun dirname -> + lazy (resolve_relative + ~options ~reader + loc ?resolution_acc dir (spf "%s%s%s" dirname Filename.dir_sep r) + ) + )) + ); + ]) + else None + ); + + lazy ( + let parent_dir = Filename.dirname dir in + if dir = parent_dir then None + else + node_module + ~options ~reader node_modules_containers + file loc resolution_acc (Filename.dirname dir) r + ); + ] + + let absolute r = + Str.string_match Files.absolute_path_regexp r 0 let explicitly_relative r = Str.string_match Files.current_dir_name r 0 || Str.string_match Files.parent_dir_name r 0 diff --git a/tests/config_module_system_node_resolve_alias/.flowconfig b/tests/config_module_system_node_resolve_alias/.flowconfig new file mode 100644 index 00000000000..20da9977f24 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/.flowconfig @@ -0,0 +1,3 @@ +[options] +module.system.node.resolve_dirname=node_modules +module.system.node.resolve_alias=custom_resolve_dir diff --git a/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_dirname.exp b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_dirname.exp new file mode 100644 index 00000000000..3b04ff95125 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_dirname.exp @@ -0,0 +1,53 @@ +Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ subdir/sublevel.js:6:2 + +Cannot cast name to string literal custom_resolve_dir/testproj2 because string +literal subdir/custom_resolve_dir/testproj2 [1] is incompatible with string literal +custom_resolve_dir/testproj2 [2]. + + subdir/sublevel.js + 3│ import {name} from "testproj2"; + 4│ + 5│ (name: "subdir/custom_resolve_dir/testproj2"); + [2] 6│ (name: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + 7│ (name: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + 8│ + + subdir/custom_resolve_dir/testproj2/index.js + [1] 3│ export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; + + +Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ subdir/sublevel.js:7:2 + +Cannot cast name to string literal node_modules/testproj2 because string literal +subdir/custom_resolve_dir/testproj2 [1] is incompatible with string literal +node_modules/testproj2 [2]. + + subdir/sublevel.js + 4│ + 5│ (name: "subdir/custom_resolve_dir/testproj2"); + 6│ (name: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + [2] 7│ (name: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + 8│ + + subdir/custom_resolve_dir/testproj2/index.js + [1] 3│ export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; + + +Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ toplevel.js:6:2 + +Cannot cast name to string literal node_modules/testproj because string literal +custom_resolve_dir/testproj [1] is incompatible with string literal +node_modules/testproj [2]. + + toplevel.js + 3│ import {name} from "testproj"; + 4│ + 5│ (name: "custom_resolve_dir/testproj"); + [2] 6│ (name: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + + custom_resolve_dir/testproj/index.js + [1] 3│ export var name: "custom_resolve_dir/testproj" = "custom_resolve_dir/testproj"; + + + +Found 3 errors \ No newline at end of file diff --git a/tests/config_module_system_node_resolve_alias/custom_resolve_dir/testproj/index.js b/tests/config_module_system_node_resolve_alias/custom_resolve_dir/testproj/index.js new file mode 100644 index 00000000000..124474deaaf --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/custom_resolve_dir/testproj/index.js @@ -0,0 +1,3 @@ +// @flow + +export var name: "custom_resolve_dir/testproj" = "custom_resolve_dir/testproj"; diff --git a/tests/config_module_system_node_resolve_alias/custom_resolve_dir/testproj2/index.js b/tests/config_module_system_node_resolve_alias/custom_resolve_dir/testproj2/index.js new file mode 100644 index 00000000000..620347ab2f1 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/custom_resolve_dir/testproj2/index.js @@ -0,0 +1,3 @@ +// @flow + +export var name: "custom_resolve_dir/testproj2" = "custom_resolve_dir/testproj2"; diff --git a/tests/config_module_system_node_resolve_alias/node_modules/testproj/index.js b/tests/config_module_system_node_resolve_alias/node_modules/testproj/index.js new file mode 100644 index 00000000000..04064ab9e18 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/node_modules/testproj/index.js @@ -0,0 +1,3 @@ +// @flow + +export var name: "node_modules/testproj" = "node_modules/testproj"; diff --git a/tests/config_module_system_node_resolve_alias/node_modules/testproj2/index.js b/tests/config_module_system_node_resolve_alias/node_modules/testproj2/index.js new file mode 100644 index 00000000000..592604c3880 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/node_modules/testproj2/index.js @@ -0,0 +1,3 @@ +// @flow + +export var name: "node_modules/testproj2" = "node_modules/testproj2"; diff --git a/tests/config_module_system_node_resolve_alias/subdir/custom_resolve_dir/testproj2/index.js b/tests/config_module_system_node_resolve_alias/subdir/custom_resolve_dir/testproj2/index.js new file mode 100644 index 00000000000..af4294a36c2 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/subdir/custom_resolve_dir/testproj2/index.js @@ -0,0 +1,3 @@ +// @flow + +export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; diff --git a/tests/config_module_system_node_resolve_alias/subdir/sublevel.js b/tests/config_module_system_node_resolve_alias/subdir/sublevel.js new file mode 100644 index 00000000000..19bc2d993c7 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/subdir/sublevel.js @@ -0,0 +1,7 @@ +// @flow + +import {name} from "testproj2"; + +(name: "subdir/custom_resolve_dir/testproj2"); +(name: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! +(name: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! diff --git a/tests/config_module_system_node_resolve_alias/toplevel.js b/tests/config_module_system_node_resolve_alias/toplevel.js new file mode 100644 index 00000000000..03ee0aae2fa --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/toplevel.js @@ -0,0 +1,6 @@ +// @flow + +import {name} from "testproj"; + +(name: "custom_resolve_dir/testproj"); +(name: "node_modules/testproj"); // Error: Resolve from resolve_alias first! \ No newline at end of file From eeb8b06e0ddf7f99df1d03b1498bef388d94d16d Mon Sep 17 00:00:00 2001 From: Braden Napier Date: Mon, 4 Feb 2019 22:13:44 -0800 Subject: [PATCH 02/14] provide ~reader to alias lazy_seq --- src/services/inference/module/module_js.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/inference/module/module_js.ml b/src/services/inference/module/module_js.ml index b9b13b9938e..cf82398b01c 100644 --- a/src/services/inference/module/module_js.ml +++ b/src/services/inference/module/module_js.ml @@ -415,7 +415,7 @@ module Node = struct lazy ( lazy_seq (Files.node_resolver_aliases file_options |> Core_list.map ~f:(fun dirname -> lazy (resolve_relative - ~options + ~options ~reader loc ?resolution_acc dir (spf "%s%s%s" dirname Filename.dir_sep r) ) )) From 21cf50de85f5a1ddf1fb33a978e668a4c38edbce Mon Sep 17 00:00:00 2001 From: Braden Napier Date: Mon, 4 Feb 2019 22:34:07 -0800 Subject: [PATCH 03/14] update tests to new styling of messages --- ...onfig_module_system_node_resolve_alias.exp | 56 +++++++++++++++++++ ...fig_module_system_node_resolve_dirname.exp | 53 ------------------ 2 files changed, 56 insertions(+), 53 deletions(-) create mode 100644 tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp delete mode 100644 tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_dirname.exp diff --git a/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp new file mode 100644 index 00000000000..73b65ea9c04 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp @@ -0,0 +1,56 @@ +Error ------------------------------------------------------------------------------------------- subdir/sublevel.js:6:2 + +Cannot cast `name` to string literal `custom_resolve_dir/testproj2` because string literal +`subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `custom_resolve_dir/testproj2` [2]. + + subdir/sublevel.js:6:2 + 6| (name: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + ^^^^ + +References: + subdir/custom_resolve_dir/testproj2/index.js:3:18 + 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] + subdir/sublevel.js:6:8 + 6| (name: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2] + + +Error ------------------------------------------------------------------------------------------- subdir/sublevel.js:7:2 + +Cannot cast `name` to string literal `node_modules/testproj2` because string literal +`subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `node_modules/testproj2` [2]. + + subdir/sublevel.js:7:2 + 7| (name: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + ^^^^ + +References: + subdir/custom_resolve_dir/testproj2/index.js:3:18 + 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] + subdir/sublevel.js:7:8 + 7| (name: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + ^^^^^^^^^^^^^^^^^^^^^^^^ [2] + + +Error -------------------------------------------------------------------------------------------------- toplevel.js:6:2 + +Cannot cast `name` to string literal `node_modules/testproj` because string literal `custom_resolve_dir/testproj` [1] is +incompatible with string literal `node_modules/testproj` [2]. + + toplevel.js:6:2 + 6| (name: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + ^^^^ + +References: + custom_resolve_dir/testproj/index.js:3:18 + 3| export var name: "custom_resolve_dir/testproj" = "custom_resolve_dir/testproj"; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] + toplevel.js:6:8 + 6| (name: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + ^^^^^^^^^^^^^^^^^^^^^^^ [2] + + + +Found 3 errors diff --git a/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_dirname.exp b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_dirname.exp deleted file mode 100644 index 3b04ff95125..00000000000 --- a/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_dirname.exp +++ /dev/null @@ -1,53 +0,0 @@ -Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ subdir/sublevel.js:6:2 - -Cannot cast name to string literal custom_resolve_dir/testproj2 because string -literal subdir/custom_resolve_dir/testproj2 [1] is incompatible with string literal -custom_resolve_dir/testproj2 [2]. - - subdir/sublevel.js - 3│ import {name} from "testproj2"; - 4│ - 5│ (name: "subdir/custom_resolve_dir/testproj2"); - [2] 6│ (name: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! - 7│ (name: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! - 8│ - - subdir/custom_resolve_dir/testproj2/index.js - [1] 3│ export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; - - -Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ subdir/sublevel.js:7:2 - -Cannot cast name to string literal node_modules/testproj2 because string literal -subdir/custom_resolve_dir/testproj2 [1] is incompatible with string literal -node_modules/testproj2 [2]. - - subdir/sublevel.js - 4│ - 5│ (name: "subdir/custom_resolve_dir/testproj2"); - 6│ (name: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! - [2] 7│ (name: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! - 8│ - - subdir/custom_resolve_dir/testproj2/index.js - [1] 3│ export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; - - -Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ toplevel.js:6:2 - -Cannot cast name to string literal node_modules/testproj because string literal -custom_resolve_dir/testproj [1] is incompatible with string literal -node_modules/testproj [2]. - - toplevel.js - 3│ import {name} from "testproj"; - 4│ - 5│ (name: "custom_resolve_dir/testproj"); - [2] 6│ (name: "node_modules/testproj"); // Error: Resolve from resolve_alias first! - - custom_resolve_dir/testproj/index.js - [1] 3│ export var name: "custom_resolve_dir/testproj" = "custom_resolve_dir/testproj"; - - - -Found 3 errors \ No newline at end of file From 022aa1c86c0273378f7c92d30f9fc5dcee34efc1 Mon Sep 17 00:00:00 2001 From: Braden Napier Date: Mon, 4 Feb 2019 22:43:44 -0800 Subject: [PATCH 04/14] resolve_alias extra tests to handle more cases --- .../.flowconfig | 1 + ...onfig_module_system_node_resolve_alias.exp | 52 +++++++++---------- .../custom_node_modules/testproj4/index.js | 4 ++ .../node_modules/testproj3/index.js | 3 ++ .../subdir/sublevel.js | 18 +++++-- .../toplevel.js | 12 +++-- 6 files changed, 57 insertions(+), 33 deletions(-) create mode 100644 tests/config_module_system_node_resolve_alias/custom_node_modules/testproj4/index.js create mode 100644 tests/config_module_system_node_resolve_alias/node_modules/testproj3/index.js diff --git a/tests/config_module_system_node_resolve_alias/.flowconfig b/tests/config_module_system_node_resolve_alias/.flowconfig index 20da9977f24..def20c40880 100644 --- a/tests/config_module_system_node_resolve_alias/.flowconfig +++ b/tests/config_module_system_node_resolve_alias/.flowconfig @@ -1,3 +1,4 @@ [options] module.system.node.resolve_dirname=node_modules +module.system.node.resolve_dirname=custom_node_modules module.system.node.resolve_alias=custom_resolve_dir diff --git a/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp index 73b65ea9c04..16ee4887fd2 100644 --- a/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp +++ b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp @@ -1,55 +1,55 @@ -Error ------------------------------------------------------------------------------------------- subdir/sublevel.js:6:2 +Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:10:2 -Cannot cast `name` to string literal `custom_resolve_dir/testproj2` because string literal +Cannot cast `two` to string literal `custom_resolve_dir/testproj2` because string literal `subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `custom_resolve_dir/testproj2` [2]. - subdir/sublevel.js:6:2 - 6| (name: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! - ^^^^ + subdir/sublevel.js:10:2 + 10| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + ^^^ References: subdir/custom_resolve_dir/testproj2/index.js:3:18 - 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - subdir/sublevel.js:6:8 - 6| (name: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] + subdir/sublevel.js:10:7 + 10| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2] -Error ------------------------------------------------------------------------------------------- subdir/sublevel.js:7:2 +Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:11:2 -Cannot cast `name` to string literal `node_modules/testproj2` because string literal +Cannot cast `two` to string literal `node_modules/testproj2` because string literal `subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `node_modules/testproj2` [2]. - subdir/sublevel.js:7:2 - 7| (name: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! - ^^^^ + subdir/sublevel.js:11:2 + 11| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + ^^^ References: subdir/custom_resolve_dir/testproj2/index.js:3:18 - 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - subdir/sublevel.js:7:8 - 7| (name: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] + subdir/sublevel.js:11:7 + 11| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^^^^^^^^^^^^^^^^^^^^^^ [2] -Error -------------------------------------------------------------------------------------------------- toplevel.js:6:2 +Error -------------------------------------------------------------------------------------------------- toplevel.js:7:2 -Cannot cast `name` to string literal `node_modules/testproj` because string literal `custom_resolve_dir/testproj` [1] is +Cannot cast `one` to string literal `node_modules/testproj` because string literal `custom_resolve_dir/testproj` [1] is incompatible with string literal `node_modules/testproj` [2]. - toplevel.js:6:2 - 6| (name: "node_modules/testproj"); // Error: Resolve from resolve_alias first! - ^^^^ + toplevel.js:7:2 + 7| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + ^^^ References: custom_resolve_dir/testproj/index.js:3:18 3| export var name: "custom_resolve_dir/testproj" = "custom_resolve_dir/testproj"; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - toplevel.js:6:8 - 6| (name: "node_modules/testproj"); // Error: Resolve from resolve_alias first! - ^^^^^^^^^^^^^^^^^^^^^^^ [2] + toplevel.js:7:7 + 7| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + ^^^^^^^^^^^^^^^^^^^^^^^ [2] diff --git a/tests/config_module_system_node_resolve_alias/custom_node_modules/testproj4/index.js b/tests/config_module_system_node_resolve_alias/custom_node_modules/testproj4/index.js new file mode 100644 index 00000000000..bc4d5706e49 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/custom_node_modules/testproj4/index.js @@ -0,0 +1,4 @@ +// @flow + +export var name: "custom_node_modules/testproj4" = + "custom_node_modules/testproj4"; diff --git a/tests/config_module_system_node_resolve_alias/node_modules/testproj3/index.js b/tests/config_module_system_node_resolve_alias/node_modules/testproj3/index.js new file mode 100644 index 00000000000..5c439a350d5 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/node_modules/testproj3/index.js @@ -0,0 +1,3 @@ +// @flow + +export var name: "node_modules/testproj3" = "node_modules/testproj3"; diff --git a/tests/config_module_system_node_resolve_alias/subdir/sublevel.js b/tests/config_module_system_node_resolve_alias/subdir/sublevel.js index 19bc2d993c7..ec08d74a359 100644 --- a/tests/config_module_system_node_resolve_alias/subdir/sublevel.js +++ b/tests/config_module_system_node_resolve_alias/subdir/sublevel.js @@ -1,7 +1,17 @@ // @flow +import { name as one } from "testproj"; +import { name as two } from "testproj2"; +import { name as three } from "testproj3"; +import { name as four } from "testproj4"; -import {name} from "testproj2"; +(one: "custom_resolve_dir/testproj"); -(name: "subdir/custom_resolve_dir/testproj2"); -(name: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! -(name: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! +(two: "subdir/custom_resolve_dir/testproj2"); +(two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! +(two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + +// should still resolve node_modules +(three: "node_modules/testproj3"); + +// should still resolve custom_node_modules +(four: "custom_node_modules/testproj4"); diff --git a/tests/config_module_system_node_resolve_alias/toplevel.js b/tests/config_module_system_node_resolve_alias/toplevel.js index 03ee0aae2fa..668b94a560f 100644 --- a/tests/config_module_system_node_resolve_alias/toplevel.js +++ b/tests/config_module_system_node_resolve_alias/toplevel.js @@ -1,6 +1,12 @@ // @flow -import {name} from "testproj"; +import { name as one } from "testproj"; +import { name as two } from "testproj2"; -(name: "custom_resolve_dir/testproj"); -(name: "node_modules/testproj"); // Error: Resolve from resolve_alias first! \ No newline at end of file +(one: "custom_resolve_dir/testproj"); +(one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + +// at base level we resolve local testproj2 +// as opposed to the local custom_resolve_dir +// in the subdir test +(two: "custom_resolve_dir/testproj2"); From bb0b58cfa285d047d97232ca4dee4a3b140ab930 Mon Sep 17 00:00:00 2001 From: Braden Napier Date: Mon, 4 Feb 2019 22:54:29 -0800 Subject: [PATCH 05/14] resolve_alias another example edge case for resolution tree merging behavior --- ...onfig_module_system_node_resolve_alias.exp | 20 ++++++++-------- .../node_modules/testproj2/subfile.js | 3 +++ .../subdir/sublevel.js | 24 +++++++++++++++---- 3 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 tests/config_module_system_node_resolve_alias/node_modules/testproj2/subfile.js diff --git a/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp index 16ee4887fd2..c306d601960 100644 --- a/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp +++ b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp @@ -1,36 +1,36 @@ -Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:10:2 +Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:12:2 Cannot cast `two` to string literal `custom_resolve_dir/testproj2` because string literal `subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `custom_resolve_dir/testproj2` [2]. - subdir/sublevel.js:10:2 - 10| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + subdir/sublevel.js:12:2 + 12| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^ References: subdir/custom_resolve_dir/testproj2/index.js:3:18 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - subdir/sublevel.js:10:7 - 10| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + subdir/sublevel.js:12:7 + 12| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2] -Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:11:2 +Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:13:2 Cannot cast `two` to string literal `node_modules/testproj2` because string literal `subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `node_modules/testproj2` [2]. - subdir/sublevel.js:11:2 - 11| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + subdir/sublevel.js:13:2 + 13| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^ References: subdir/custom_resolve_dir/testproj2/index.js:3:18 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - subdir/sublevel.js:11:7 - 11| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + subdir/sublevel.js:13:7 + 13| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^^^^^^^^^^^^^^^^^^^^^^ [2] diff --git a/tests/config_module_system_node_resolve_alias/node_modules/testproj2/subfile.js b/tests/config_module_system_node_resolve_alias/node_modules/testproj2/subfile.js new file mode 100644 index 00000000000..86e2965c7ac --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/node_modules/testproj2/subfile.js @@ -0,0 +1,3 @@ +// @flow +export var name: "node_modules/testproj2/subfile" = + "node_modules/testproj2/subfile"; diff --git a/tests/config_module_system_node_resolve_alias/subdir/sublevel.js b/tests/config_module_system_node_resolve_alias/subdir/sublevel.js index ec08d74a359..b5bc787cac5 100644 --- a/tests/config_module_system_node_resolve_alias/subdir/sublevel.js +++ b/tests/config_module_system_node_resolve_alias/subdir/sublevel.js @@ -1,8 +1,10 @@ // @flow import { name as one } from "testproj"; import { name as two } from "testproj2"; -import { name as three } from "testproj3"; -import { name as four } from "testproj4"; +import { name as three } from "testproj2/subfile"; + +import { name as four } from "testproj3"; +import { name as five } from "testproj4"; (one: "custom_resolve_dir/testproj"); @@ -10,8 +12,22 @@ import { name as four } from "testproj4"; (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! +// if we fail to resolve in custom_resolve_dir +// then we should still resolve node_modules if +// possible. +// +// this tends to bring up the possibility of +// confusing bugs but it is consistent with +// the behavior of the webpack/babel features +// they are based upon. +// +// personally can see a flow lint warning +// as an option here if a conflict of folders +// is detected between aliases and/or node_modules +(three: "node_modules/testproj2/subfile"); + // should still resolve node_modules -(three: "node_modules/testproj3"); +(four: "node_modules/testproj3"); // should still resolve custom_node_modules -(four: "custom_node_modules/testproj4"); +(five: "custom_node_modules/testproj4"); From 88d1b56bd90d26b0c47506009da05c0835c68dd4 Mon Sep 17 00:00:00 2001 From: Braden Napier Date: Tue, 5 Feb 2019 00:07:37 -0800 Subject: [PATCH 06/14] highlight fail case --- tests/config_module_system_node_resolve_alias/.flowconfig | 3 +++ .../config_module_system_node_resolve_alias/jsconfig.json | 8 ++++++++ .../root_resolve_dir/testproj6/index.js | 3 +++ .../subdir/custom_resolve_dir/testproj5/index.js | 4 ++++ .../subdir/root_resolve_dir/testproj6/index.js | 4 ++++ .../subdir/sublevel.js | 6 ++++++ 6 files changed, 28 insertions(+) create mode 100644 tests/config_module_system_node_resolve_alias/jsconfig.json create mode 100644 tests/config_module_system_node_resolve_alias/root_resolve_dir/testproj6/index.js create mode 100644 tests/config_module_system_node_resolve_alias/subdir/custom_resolve_dir/testproj5/index.js create mode 100644 tests/config_module_system_node_resolve_alias/subdir/root_resolve_dir/testproj6/index.js diff --git a/tests/config_module_system_node_resolve_alias/.flowconfig b/tests/config_module_system_node_resolve_alias/.flowconfig index def20c40880..bb04c96a24e 100644 --- a/tests/config_module_system_node_resolve_alias/.flowconfig +++ b/tests/config_module_system_node_resolve_alias/.flowconfig @@ -2,3 +2,6 @@ module.system.node.resolve_dirname=node_modules module.system.node.resolve_dirname=custom_node_modules module.system.node.resolve_alias=custom_resolve_dir +; should also be able to specify as +; /root_resolve_dir +module.system.node.resolve_alias=./root_resolve_dir diff --git a/tests/config_module_system_node_resolve_alias/jsconfig.json b/tests/config_module_system_node_resolve_alias/jsconfig.json new file mode 100644 index 00000000000..c3729654cc3 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/jsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "*": ["./src/*"] + } + } +} diff --git a/tests/config_module_system_node_resolve_alias/root_resolve_dir/testproj6/index.js b/tests/config_module_system_node_resolve_alias/root_resolve_dir/testproj6/index.js new file mode 100644 index 00000000000..7499d5fcf0a --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/root_resolve_dir/testproj6/index.js @@ -0,0 +1,3 @@ +// @flow + +export var name: "root_resolve_dir/testproj6" = "root_resolve_dir/testproj6"; diff --git a/tests/config_module_system_node_resolve_alias/subdir/custom_resolve_dir/testproj5/index.js b/tests/config_module_system_node_resolve_alias/subdir/custom_resolve_dir/testproj5/index.js new file mode 100644 index 00000000000..40e5d9afa37 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/subdir/custom_resolve_dir/testproj5/index.js @@ -0,0 +1,4 @@ +// @flow + +export var name: "subdir/custom_resolve_dir/testproj5" = + "subdir/custom_resolve_dir/testproj5"; diff --git a/tests/config_module_system_node_resolve_alias/subdir/root_resolve_dir/testproj6/index.js b/tests/config_module_system_node_resolve_alias/subdir/root_resolve_dir/testproj6/index.js new file mode 100644 index 00000000000..e666bbcd3e8 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/subdir/root_resolve_dir/testproj6/index.js @@ -0,0 +1,4 @@ +// @flow + +export var name: "subdir/root_resolve_dir/testproj6" = + "subdir/root_resolve_dir/testproj6"; diff --git a/tests/config_module_system_node_resolve_alias/subdir/sublevel.js b/tests/config_module_system_node_resolve_alias/subdir/sublevel.js index b5bc787cac5..41daab004d4 100644 --- a/tests/config_module_system_node_resolve_alias/subdir/sublevel.js +++ b/tests/config_module_system_node_resolve_alias/subdir/sublevel.js @@ -6,6 +6,10 @@ import { name as three } from "testproj2/subfile"; import { name as four } from "testproj3"; import { name as five } from "testproj4"; +import { name as six } from "testproj5"; + +import { name as seven } from "testproj6"; + (one: "custom_resolve_dir/testproj"); (two: "subdir/custom_resolve_dir/testproj2"); @@ -31,3 +35,5 @@ import { name as five } from "testproj4"; // should still resolve custom_node_modules (five: "custom_node_modules/testproj4"); + +(seven: "root_resolve_dir/testproj6/"); From ffb0f727948662eae5b5617b3a1c230f38ad564c Mon Sep 17 00:00:00 2001 From: davidroeca Date: Fri, 20 Sep 2019 15:08:32 -0400 Subject: [PATCH 07/14] style consistency + cleanup --- src/commands/config/flowConfig.ml | 1 - src/common/files.ml | 14 +++- src/common/files.mli | 1 + src/services/inference/module/module_js.ml | 87 +++++++++++++--------- 4 files changed, 64 insertions(+), 39 deletions(-) diff --git a/src/commands/config/flowConfig.ml b/src/commands/config/flowConfig.ml index 3d99bf0a480..087c9744813 100644 --- a/src/commands/config/flowConfig.ml +++ b/src/commands/config/flowConfig.ml @@ -140,7 +140,6 @@ module Opts = struct |> SSet.add ".mp4" |> SSet.add ".webm" -<<<<<<< HEAD let default_options = { abstract_locations = false; diff --git a/src/common/files.ml b/src/common/files.ml index 151471d4461..db68d2dfbae 100644 --- a/src/common/files.ml +++ b/src/common/files.ml @@ -190,7 +190,12 @@ let max_files = 1000 If kind_of_path fails, then we only emit a warning if error_filter passes *) let make_next_files_and_symlinks - ~node_module_filter ~module_alias_filter ~path_filter ~realpath_filter ~error_filter paths = + ~node_module_filter + ~module_alias_filter + ~path_filter + ~realpath_filter + ~error_filter + paths = let prefix_checkers = Core_list.map ~f:is_prefix paths in let rec process sz (acc, symlinks) files dir stack = if sz >= max_files then @@ -248,7 +253,12 @@ let make_next_files_and_symlinks and including any directories that are symlinked to even if they are outside of `paths`. *) let make_next_files_following_symlinks - ~node_module_filter ~module_alias_filter ~path_filter ~realpath_filter ~error_filter paths = + ~node_module_filter + ~module_alias_filter + ~path_filter + ~realpath_filter + ~error_filter + paths = let paths = Core_list.map ~f:Path.to_string paths in let cb = ref diff --git a/src/common/files.mli b/src/common/files.mli index 2ec8726be00..d322a8b5906 100644 --- a/src/common/files.mli +++ b/src/common/files.mli @@ -20,6 +20,7 @@ type options = { node_resolver_aliases: string list; } +val default_lib_dir : options -> Path.t option val ignores : options -> (string * Str.regexp) list diff --git a/src/services/inference/module/module_js.ml b/src/services/inference/module/module_js.ml index cf82398b01c..f400385b6b3 100644 --- a/src/services/inference/module/module_js.ml +++ b/src/services/inference/module/module_js.ml @@ -408,42 +408,57 @@ module Node = struct let rec node_module ~options ~reader node_modules_containers file loc resolution_acc dir r = let file_options = Options.file_options options in - lazy_seq [ - lazy ( - if SSet.mem dir node_modules_containers then - lazy_seq([ - lazy ( - lazy_seq (Files.node_resolver_aliases file_options |> Core_list.map ~f:(fun dirname -> - lazy (resolve_relative - ~options ~reader - loc ?resolution_acc dir (spf "%s%s%s" dirname Filename.dir_sep r) - ) - )) - ); - lazy ( - lazy_seq (Files.node_resolver_dirnames file_options |> Core_list.map ~f:(fun dirname -> - lazy (resolve_relative - ~options ~reader - loc ?resolution_acc dir (spf "%s%s%s" dirname Filename.dir_sep r) - ) - )) - ); - ]) - else None - ); - - lazy ( - let parent_dir = Filename.dirname dir in - if dir = parent_dir then None - else - node_module - ~options ~reader node_modules_containers - file loc resolution_acc (Filename.dirname dir) r - ); - ] - - let absolute r = - Str.string_match Files.absolute_path_regexp r 0 + lazy_seq + [ + lazy + ( if SSet.mem dir node_modules_containers then + lazy_seq([ + lazy ( + lazy_seq + ( Files.node_resolver_aliases file_options + |> Core_list.map ~f:(fun dirname -> + lazy + (resolve_relative + ~options + ~reader + loc + ?resolution_acc + dir + (spf "%s%s%s" dirname Filename.dir_sep r))) ) + ); + lazy ( + lazy_seq + ( Files.node_resolver_dirnames file_options + |> Core_list.map ~f:(fun dirname -> + lazy + (resolve_relative + ~options + ~reader + loc + ?resolution_acc + dir (spf "%s%s%s" dirname Filename.dir_sep r))) ) + ); + ]) + else None + ); + + lazy + (let parent_dir = Filename.dirname dir in + if dir = parent_dir then + None + else + node_module + ~options + ~reader + node_modules_containers + file + loc + resolution_acc + (Filename.dirname dir) + r); + ] + + let absolute r = Str.string_match Files.absolute_path_regexp r 0 let explicitly_relative r = Str.string_match Files.current_dir_name r 0 || Str.string_match Files.parent_dir_name r 0 From 845b1c0581c221f192b4df265f5a87ddfd9d7f05 Mon Sep 17 00:00:00 2001 From: davidroeca Date: Fri, 20 Sep 2019 15:45:45 -0400 Subject: [PATCH 08/14] fix test line numbers --- ...onfig_module_system_node_resolve_alias.exp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp index c306d601960..cad3ea1c15f 100644 --- a/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp +++ b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp @@ -1,36 +1,36 @@ -Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:12:2 +Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:16:2 Cannot cast `two` to string literal `custom_resolve_dir/testproj2` because string literal `subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `custom_resolve_dir/testproj2` [2]. - subdir/sublevel.js:12:2 - 12| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + subdir/sublevel.js:16:2 + 16| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^ References: subdir/custom_resolve_dir/testproj2/index.js:3:18 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - subdir/sublevel.js:12:7 - 12| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + subdir/sublevel.js:16:7 + 16| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2] -Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:13:2 +Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:17:2 Cannot cast `two` to string literal `node_modules/testproj2` because string literal `subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `node_modules/testproj2` [2]. - subdir/sublevel.js:13:2 - 13| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + subdir/sublevel.js:17:2 + 17| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^ References: subdir/custom_resolve_dir/testproj2/index.js:3:18 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - subdir/sublevel.js:13:7 - 13| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + subdir/sublevel.js:17:7 + 17| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^^^^^^^^^^^^^^^^^^^^^^ [2] From 41498d561348ffa8b85e0e6bc248c5aa9941ec63 Mon Sep 17 00:00:00 2001 From: davidroeca Date: Fri, 20 Sep 2019 18:08:20 -0400 Subject: [PATCH 09/14] Working for resolve aliases --- src/services/inference/module/module_js.ml | 14 +++++++++++--- .../.flowconfig | 5 ++--- .../subdir/sublevel.js | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/services/inference/module/module_js.ml b/src/services/inference/module/module_js.ml index f400385b6b3..dd884e9d3df 100644 --- a/src/services/inference/module/module_js.ml +++ b/src/services/inference/module/module_js.ml @@ -62,6 +62,9 @@ let choose_provider_and_warn_about_duplicates = in (defn, errmap) +let get_root ~options = + Options.root options |> Path.to_string |> Sys_utils.normalize_filename_dir_sep + (** * A set of module.name_mapper config entry allows users to specify regexp * matcher strings each with a template string in order to map the names of a @@ -75,7 +78,7 @@ let choose_provider_and_warn_about_duplicates = let module_name_candidates ~options = Module_hashtables.memoize_with_module_name_candidates_cache ~f:(fun name -> let mappers = Options.module_name_mappers options in - let root = Options.root options |> Path.to_string |> Sys_utils.normalize_filename_dir_sep in + let root = get_root options in let map_name mapped_names (regexp, template) = let new_name = name @@ -408,6 +411,7 @@ module Node = struct let rec node_module ~options ~reader node_modules_containers file loc resolution_acc dir r = let file_options = Options.file_options options in + let root = get_root options in lazy_seq [ lazy @@ -417,14 +421,18 @@ module Node = struct lazy_seq ( Files.node_resolver_aliases file_options |> Core_list.map ~f:(fun dirname -> + let modified_dirname = + dirname + |> Str.split_delim Files.project_root_token + |> String.concat root + in lazy (resolve_relative ~options ~reader loc ?resolution_acc - dir - (spf "%s%s%s" dirname Filename.dir_sep r))) ) + dir (spf "%s%s%s" modified_dirname Filename.dir_sep r))) ) ); lazy ( lazy_seq diff --git a/tests/config_module_system_node_resolve_alias/.flowconfig b/tests/config_module_system_node_resolve_alias/.flowconfig index bb04c96a24e..e170bd2d057 100644 --- a/tests/config_module_system_node_resolve_alias/.flowconfig +++ b/tests/config_module_system_node_resolve_alias/.flowconfig @@ -2,6 +2,5 @@ module.system.node.resolve_dirname=node_modules module.system.node.resolve_dirname=custom_node_modules module.system.node.resolve_alias=custom_resolve_dir -; should also be able to specify as -; /root_resolve_dir -module.system.node.resolve_alias=./root_resolve_dir +module.system.node.resolve_alias=/root_resolve_dir +; module.system.node.resolve_alias=./root_resolve_dir diff --git a/tests/config_module_system_node_resolve_alias/subdir/sublevel.js b/tests/config_module_system_node_resolve_alias/subdir/sublevel.js index 41daab004d4..77eff9cfda7 100644 --- a/tests/config_module_system_node_resolve_alias/subdir/sublevel.js +++ b/tests/config_module_system_node_resolve_alias/subdir/sublevel.js @@ -36,4 +36,4 @@ import { name as seven } from "testproj6"; // should still resolve custom_node_modules (five: "custom_node_modules/testproj4"); -(seven: "root_resolve_dir/testproj6/"); +(seven: "root_resolve_dir/testproj6"); From 2b31bedf9fe539574e05ce0ef54cb90ff60b0754 Mon Sep 17 00:00:00 2001 From: davidroeca Date: Fri, 20 Sep 2019 19:34:41 -0400 Subject: [PATCH 10/14] remove relative alias --- tests/config_module_system_node_resolve_alias/.flowconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/config_module_system_node_resolve_alias/.flowconfig b/tests/config_module_system_node_resolve_alias/.flowconfig index e170bd2d057..1beb8c31031 100644 --- a/tests/config_module_system_node_resolve_alias/.flowconfig +++ b/tests/config_module_system_node_resolve_alias/.flowconfig @@ -3,4 +3,3 @@ module.system.node.resolve_dirname=node_modules module.system.node.resolve_dirname=custom_node_modules module.system.node.resolve_alias=custom_resolve_dir module.system.node.resolve_alias=/root_resolve_dir -; module.system.node.resolve_alias=./root_resolve_dir From a2e05daa6c632ff6714a616c0e6fb92af772c4f2 Mon Sep 17 00:00:00 2001 From: davidroeca Date: Mon, 23 Sep 2019 00:50:45 -0400 Subject: [PATCH 11/14] failing recheck tests --- .../.testconfig | 1 + ...onfig_module_system_node_resolve_alias.exp | 67 +++++++++++++++++++ .../jsconfig.json | 8 --- .../test.sh | 17 +++++ 4 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 tests/config_module_system_node_resolve_alias/.testconfig delete mode 100644 tests/config_module_system_node_resolve_alias/jsconfig.json create mode 100755 tests/config_module_system_node_resolve_alias/test.sh diff --git a/tests/config_module_system_node_resolve_alias/.testconfig b/tests/config_module_system_node_resolve_alias/.testconfig new file mode 100644 index 00000000000..70d0dd9761a --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/.testconfig @@ -0,0 +1 @@ +shell: test.sh \ No newline at end of file diff --git a/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp index cad3ea1c15f..55aed5441e3 100644 --- a/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp +++ b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp @@ -1,3 +1,5 @@ + +Should have all 3 expected errors Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:16:2 Cannot cast `two` to string literal `custom_resolve_dir/testproj2` because string literal @@ -54,3 +56,68 @@ References: Found 3 errors + +Should fix the first error +Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:17:2 + +Cannot cast `two` to string literal `node_modules/testproj2` because string literal +`subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `node_modules/testproj2` [2]. + + subdir/sublevel.js:17:2 + 17| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + ^^^ + +References: + subdir/custom_resolve_dir/testproj2/index.js:3:18 + 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] + subdir/sublevel.js:17:7 + 17| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + ^^^^^^^^^^^^^^^^^^^^^^^^ [2] + + +Error -------------------------------------------------------------------------------------------------- toplevel.js:7:2 + +Cannot cast `one` to string literal `node_modules/testproj` because string literal `custom_resolve_dir/testproj` [1] is +incompatible with string literal `node_modules/testproj` [2]. + + toplevel.js:7:2 + 7| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + ^^^ + +References: + custom_resolve_dir/testproj/index.js:3:18 + 3| export var name: "custom_resolve_dir/testproj" = "custom_resolve_dir/testproj"; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] + toplevel.js:7:7 + 7| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + ^^^^^^^^^^^^^^^^^^^^^^^ [2] + + + +Found 2 errors + +Should fix the second error +Error -------------------------------------------------------------------------------------------------- toplevel.js:7:2 + +Cannot cast `one` to string literal `node_modules/testproj` because string literal `custom_resolve_dir/testproj` [1] is +incompatible with string literal `node_modules/testproj` [2]. + + toplevel.js:7:2 + 7| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + ^^^ + +References: + custom_resolve_dir/testproj/index.js:3:18 + 3| export var name: "custom_resolve_dir/testproj" = "custom_resolve_dir/testproj"; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] + toplevel.js:7:7 + 7| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + ^^^^^^^^^^^^^^^^^^^^^^^ [2] + + + +Found 1 error + +Should fix the third error +No errors! diff --git a/tests/config_module_system_node_resolve_alias/jsconfig.json b/tests/config_module_system_node_resolve_alias/jsconfig.json deleted file mode 100644 index c3729654cc3..00000000000 --- a/tests/config_module_system_node_resolve_alias/jsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "compilerOptions": { - "baseUrl": ".", - "paths": { - "*": ["./src/*"] - } - } -} diff --git a/tests/config_module_system_node_resolve_alias/test.sh b/tests/config_module_system_node_resolve_alias/test.sh new file mode 100755 index 00000000000..5948ff58b75 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/test.sh @@ -0,0 +1,17 @@ +#!/bin/bash +. ../fs.sh +mkdir -p tmp/subdir/custom_resolve_dir tmp/custom_resolve_dir +printf "\nShould have all 3 expected errors\n" +assert_errors "$FLOW" status . +printf "\nShould fix the first error\n" +move subdir/custom_resolve_dir/testproj2 tmp/subdir/custom_resolve_dir/testproj2 +assert_errors "$FLOW" status . +printf "\nShould fix the second error\n" +move custom_resolve_dir/testproj2 tmp/custom_resolve_dir/testproj2 +assert_errors "$FLOW" status . +printf "\nShould fix the third error\n" +move custom_resolve_dir/testproj tmp/custom_resolve_dir/testproj +mv tmp/custom_resolve_dir/testproj custom_resolve_dir/testproj +mv tmp/custom_resolve_dir/testproj2 custom_resolve_dir/testproj2 +mv tmp/subdir/custom_resolve_dir subdir/custom_resolve_dir +rm -rf tmp From 10696724de987af411bc3f39a4e84cf37215a4a0 Mon Sep 17 00:00:00 2001 From: davidroeca Date: Mon, 23 Sep 2019 22:51:40 -0400 Subject: [PATCH 12/14] some test improvements --- ...onfig_module_system_node_resolve_alias.exp | 186 ++++++++++++++---- .../custom_node_modules/incremental/index.js | 3 + .../incrementalNodeModules/index.js | 3 + .../incrementalNodeModules/index.js | 3 + .../root_resolve_dir/incrementalRoot/index.js | 3 + .../incrementalRoot/index.js | 3 + .../subdir/sublevel.js | 6 + .../test.sh | 17 +- .../toplevel.js | 3 + 9 files changed, 176 insertions(+), 51 deletions(-) create mode 100644 tests/config_module_system_node_resolve_alias/custom_node_modules/incremental/index.js create mode 100644 tests/config_module_system_node_resolve_alias/custom_resolve_dir/incrementalNodeModules/index.js create mode 100644 tests/config_module_system_node_resolve_alias/node_modules/incrementalNodeModules/index.js create mode 100644 tests/config_module_system_node_resolve_alias/root_resolve_dir/incrementalRoot/index.js create mode 100644 tests/config_module_system_node_resolve_alias/subdir/custom_resolve_dir/incrementalRoot/index.js diff --git a/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp index 55aed5441e3..048605368c5 100644 --- a/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp +++ b/tests/config_module_system_node_resolve_alias/config_module_system_node_resolve_alias.exp @@ -1,123 +1,231 @@ -Should have all 3 expected errors -Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:16:2 +Should have all expected errors +Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:18:2 Cannot cast `two` to string literal `custom_resolve_dir/testproj2` because string literal `subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `custom_resolve_dir/testproj2` [2]. - subdir/sublevel.js:16:2 - 16| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + subdir/sublevel.js:18:2 + 18| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^ References: subdir/custom_resolve_dir/testproj2/index.js:3:18 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - subdir/sublevel.js:16:7 - 16| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + subdir/sublevel.js:18:7 + 18| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2] -Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:17:2 +Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:19:2 Cannot cast `two` to string literal `node_modules/testproj2` because string literal `subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `node_modules/testproj2` [2]. - subdir/sublevel.js:17:2 - 17| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + subdir/sublevel.js:19:2 + 19| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^ References: subdir/custom_resolve_dir/testproj2/index.js:3:18 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - subdir/sublevel.js:17:7 - 17| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + subdir/sublevel.js:19:7 + 19| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^^^^^^^^^^^^^^^^^^^^^^ [2] -Error -------------------------------------------------------------------------------------------------- toplevel.js:7:2 +Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:45:2 + +Cannot cast `incrementalRoot` to string literal `root_resolve_dir/incrementalRoot` because string literal +`subdir/custom_resolve_dir/incrementalRoot` [1] is incompatible with string literal +`root_resolve_dir/incrementalRoot` [2]. + + subdir/sublevel.js:45:2 + 45| (incrementalRoot: "root_resolve_dir/incrementalRoot"); + ^^^^^^^^^^^^^^^ + +References: + subdir/custom_resolve_dir/incrementalRoot/index.js:3:18 + 3| export var name: "subdir/custom_resolve_dir/incrementalRoot" = "subdir/custom_resolve_dir/incrementalRoot"; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] + subdir/sublevel.js:45:19 + 45| (incrementalRoot: "root_resolve_dir/incrementalRoot"); + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2] + + +Error -------------------------------------------------------------------------------------------------- toplevel.js:8:2 Cannot cast `one` to string literal `node_modules/testproj` because string literal `custom_resolve_dir/testproj` [1] is incompatible with string literal `node_modules/testproj` [2]. - toplevel.js:7:2 - 7| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + toplevel.js:8:2 + 8| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! ^^^ References: custom_resolve_dir/testproj/index.js:3:18 3| export var name: "custom_resolve_dir/testproj" = "custom_resolve_dir/testproj"; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - toplevel.js:7:7 - 7| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + toplevel.js:8:7 + 8| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! ^^^^^^^^^^^^^^^^^^^^^^^ [2] +Error ------------------------------------------------------------------------------------------------- toplevel.js:15:2 -Found 3 errors +Cannot cast `incrementalNodeModules` to string literal `node_modules/incrementalNodeModules` because string literal +`custom_resolve_dir/incrementalNodeModules` [1] is incompatible with string literal +`node_modules/incrementalNodeModules` [2]. + + toplevel.js:15:2 + 15| (incrementalNodeModules: "node_modules/incrementalNodeModules"); + ^^^^^^^^^^^^^^^^^^^^^^ + +References: + custom_resolve_dir/incrementalNodeModules/index.js:3:18 + 3| export var name: "custom_resolve_dir/incrementalNodeModules" = "custom_resolve_dir/incrementalNodeModules"; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] + toplevel.js:15:26 + 15| (incrementalNodeModules: "node_modules/incrementalNodeModules"); + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2] + + + +Found 5 errors + +Should fix incrementalRoot +Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:18:2 + +Cannot cast `two` to string literal `custom_resolve_dir/testproj2` because string literal +`subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `custom_resolve_dir/testproj2` [2]. -Should fix the first error -Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:17:2 + subdir/sublevel.js:18:2 + 18| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + ^^^ + +References: + subdir/custom_resolve_dir/testproj2/index.js:3:18 + 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] + subdir/sublevel.js:18:7 + 18| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2] + + +Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:19:2 Cannot cast `two` to string literal `node_modules/testproj2` because string literal `subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `node_modules/testproj2` [2]. - subdir/sublevel.js:17:2 - 17| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + subdir/sublevel.js:19:2 + 19| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^ References: subdir/custom_resolve_dir/testproj2/index.js:3:18 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - subdir/sublevel.js:17:7 - 17| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + subdir/sublevel.js:19:7 + 19| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! ^^^^^^^^^^^^^^^^^^^^^^^^ [2] -Error -------------------------------------------------------------------------------------------------- toplevel.js:7:2 +Error -------------------------------------------------------------------------------------------------- toplevel.js:8:2 Cannot cast `one` to string literal `node_modules/testproj` because string literal `custom_resolve_dir/testproj` [1] is incompatible with string literal `node_modules/testproj` [2]. - toplevel.js:7:2 - 7| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + toplevel.js:8:2 + 8| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! ^^^ References: custom_resolve_dir/testproj/index.js:3:18 3| export var name: "custom_resolve_dir/testproj" = "custom_resolve_dir/testproj"; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - toplevel.js:7:7 - 7| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + toplevel.js:8:7 + 8| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! ^^^^^^^^^^^^^^^^^^^^^^^ [2] +Error ------------------------------------------------------------------------------------------------- toplevel.js:15:2 + +Cannot cast `incrementalNodeModules` to string literal `node_modules/incrementalNodeModules` because string literal +`custom_resolve_dir/incrementalNodeModules` [1] is incompatible with string literal +`node_modules/incrementalNodeModules` [2]. + + toplevel.js:15:2 + 15| (incrementalNodeModules: "node_modules/incrementalNodeModules"); + ^^^^^^^^^^^^^^^^^^^^^^ + +References: + custom_resolve_dir/incrementalNodeModules/index.js:3:18 + 3| export var name: "custom_resolve_dir/incrementalNodeModules" = "custom_resolve_dir/incrementalNodeModules"; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] + toplevel.js:15:26 + 15| (incrementalNodeModules: "node_modules/incrementalNodeModules"); + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2] + + + +Found 4 errors + +Should fix incrementalNodeModules +Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:18:2 + +Cannot cast `two` to string literal `custom_resolve_dir/testproj2` because string literal +`subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `custom_resolve_dir/testproj2` [2]. + + subdir/sublevel.js:18:2 + 18| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + ^^^ + +References: + subdir/custom_resolve_dir/testproj2/index.js:3:18 + 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] + subdir/sublevel.js:18:7 + 18| (two: "custom_resolve_dir/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2] + + +Error ------------------------------------------------------------------------------------------ subdir/sublevel.js:19:2 -Found 2 errors +Cannot cast `two` to string literal `node_modules/testproj2` because string literal +`subdir/custom_resolve_dir/testproj2` [1] is incompatible with string literal `node_modules/testproj2` [2]. -Should fix the second error -Error -------------------------------------------------------------------------------------------------- toplevel.js:7:2 + subdir/sublevel.js:19:2 + 19| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + ^^^ + +References: + subdir/custom_resolve_dir/testproj2/index.js:3:18 + 3| export var name: "subdir/custom_resolve_dir/testproj2" = "subdir/custom_resolve_dir/testproj2"; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] + subdir/sublevel.js:19:7 + 19| (two: "node_modules/testproj2"); // Error: Resolve from sibling 'custom_resolve_dir' first! + ^^^^^^^^^^^^^^^^^^^^^^^^ [2] + + +Error -------------------------------------------------------------------------------------------------- toplevel.js:8:2 Cannot cast `one` to string literal `node_modules/testproj` because string literal `custom_resolve_dir/testproj` [1] is incompatible with string literal `node_modules/testproj` [2]. - toplevel.js:7:2 - 7| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + toplevel.js:8:2 + 8| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! ^^^ References: custom_resolve_dir/testproj/index.js:3:18 3| export var name: "custom_resolve_dir/testproj" = "custom_resolve_dir/testproj"; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] - toplevel.js:7:7 - 7| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! + toplevel.js:8:7 + 8| (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! ^^^^^^^^^^^^^^^^^^^^^^^ [2] -Found 1 error - -Should fix the third error -No errors! +Found 3 errors diff --git a/tests/config_module_system_node_resolve_alias/custom_node_modules/incremental/index.js b/tests/config_module_system_node_resolve_alias/custom_node_modules/incremental/index.js new file mode 100644 index 00000000000..1c9bf0a126a --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/custom_node_modules/incremental/index.js @@ -0,0 +1,3 @@ +// @flow + +export var name: "custom_node_modules/incremental" = "custom_node_modules/incremental"; diff --git a/tests/config_module_system_node_resolve_alias/custom_resolve_dir/incrementalNodeModules/index.js b/tests/config_module_system_node_resolve_alias/custom_resolve_dir/incrementalNodeModules/index.js new file mode 100644 index 00000000000..398a6397e57 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/custom_resolve_dir/incrementalNodeModules/index.js @@ -0,0 +1,3 @@ +// @flow + +export var name: "custom_resolve_dir/incrementalNodeModules" = "custom_resolve_dir/incrementalNodeModules"; diff --git a/tests/config_module_system_node_resolve_alias/node_modules/incrementalNodeModules/index.js b/tests/config_module_system_node_resolve_alias/node_modules/incrementalNodeModules/index.js new file mode 100644 index 00000000000..a06529ae6fa --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/node_modules/incrementalNodeModules/index.js @@ -0,0 +1,3 @@ +// @flow + +export var name: "node_modules/incrementalNodeModules" = "node_modules/incrementalNodeModules"; diff --git a/tests/config_module_system_node_resolve_alias/root_resolve_dir/incrementalRoot/index.js b/tests/config_module_system_node_resolve_alias/root_resolve_dir/incrementalRoot/index.js new file mode 100644 index 00000000000..3e8e4357bec --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/root_resolve_dir/incrementalRoot/index.js @@ -0,0 +1,3 @@ +// @flow + +export var name: "root_resolve_dir/incrementalRoot" = "root_resolve_dir/incrementalRoot"; diff --git a/tests/config_module_system_node_resolve_alias/subdir/custom_resolve_dir/incrementalRoot/index.js b/tests/config_module_system_node_resolve_alias/subdir/custom_resolve_dir/incrementalRoot/index.js new file mode 100644 index 00000000000..354ae0a1982 --- /dev/null +++ b/tests/config_module_system_node_resolve_alias/subdir/custom_resolve_dir/incrementalRoot/index.js @@ -0,0 +1,3 @@ +// @flow + +export var name: "subdir/custom_resolve_dir/incrementalRoot" = "subdir/custom_resolve_dir/incrementalRoot"; diff --git a/tests/config_module_system_node_resolve_alias/subdir/sublevel.js b/tests/config_module_system_node_resolve_alias/subdir/sublevel.js index 77eff9cfda7..ce3bba44c70 100644 --- a/tests/config_module_system_node_resolve_alias/subdir/sublevel.js +++ b/tests/config_module_system_node_resolve_alias/subdir/sublevel.js @@ -10,6 +10,8 @@ import { name as six } from "testproj5"; import { name as seven } from "testproj6"; +import { name as incrementalRoot } from "incrementalRoot"; + (one: "custom_resolve_dir/testproj"); (two: "subdir/custom_resolve_dir/testproj2"); @@ -36,4 +38,8 @@ import { name as seven } from "testproj6"; // should still resolve custom_node_modules (five: "custom_node_modules/testproj4"); +// Should not resolve to the subdir (seven: "root_resolve_dir/testproj6"); + +// should resolve to the subdirectory, and then get fixed +(incrementalRoot: "root_resolve_dir/incrementalRoot"); diff --git a/tests/config_module_system_node_resolve_alias/test.sh b/tests/config_module_system_node_resolve_alias/test.sh index 5948ff58b75..7d0018c358d 100755 --- a/tests/config_module_system_node_resolve_alias/test.sh +++ b/tests/config_module_system_node_resolve_alias/test.sh @@ -1,17 +1,10 @@ #!/bin/bash . ../fs.sh -mkdir -p tmp/subdir/custom_resolve_dir tmp/custom_resolve_dir -printf "\nShould have all 3 expected errors\n" +printf "\nShould have all expected errors\n" assert_errors "$FLOW" status . -printf "\nShould fix the first error\n" -move subdir/custom_resolve_dir/testproj2 tmp/subdir/custom_resolve_dir/testproj2 +printf "\nShould fix incrementalRoot\n" +remove subdir/custom_resolve_dir/incrementalRoot/index.js assert_errors "$FLOW" status . -printf "\nShould fix the second error\n" -move custom_resolve_dir/testproj2 tmp/custom_resolve_dir/testproj2 +printf "\nShould fix incrementalNodeModules\n" +remove custom_resolve_dir/incrementalNodeModules/index.js assert_errors "$FLOW" status . -printf "\nShould fix the third error\n" -move custom_resolve_dir/testproj tmp/custom_resolve_dir/testproj -mv tmp/custom_resolve_dir/testproj custom_resolve_dir/testproj -mv tmp/custom_resolve_dir/testproj2 custom_resolve_dir/testproj2 -mv tmp/subdir/custom_resolve_dir subdir/custom_resolve_dir -rm -rf tmp diff --git a/tests/config_module_system_node_resolve_alias/toplevel.js b/tests/config_module_system_node_resolve_alias/toplevel.js index 668b94a560f..524389e49d1 100644 --- a/tests/config_module_system_node_resolve_alias/toplevel.js +++ b/tests/config_module_system_node_resolve_alias/toplevel.js @@ -2,6 +2,7 @@ import { name as one } from "testproj"; import { name as two } from "testproj2"; +import { name as incrementalNodeModules } from "incrementalNodeModules"; (one: "custom_resolve_dir/testproj"); (one: "node_modules/testproj"); // Error: Resolve from resolve_alias first! @@ -10,3 +11,5 @@ import { name as two } from "testproj2"; // as opposed to the local custom_resolve_dir // in the subdir test (two: "custom_resolve_dir/testproj2"); + +(incrementalNodeModules: "node_modules/incrementalNodeModules"); From fb3874cde4cd7b0c39711d14b4f1e87e92b401b5 Mon Sep 17 00:00:00 2001 From: davidroeca Date: Tue, 24 Sep 2019 02:25:28 -0400 Subject: [PATCH 13/14] ocamlformat the files --- src/commands/commandUtils.ml | 2 +- src/commands/config/flowConfig.ml | 6 +- src/common/files.ml | 18 ++---- src/common/files.mli | 4 +- src/services/inference/module/module_js.ml | 68 +++++++++++----------- 5 files changed, 44 insertions(+), 54 deletions(-) diff --git a/src/commands/commandUtils.ml b/src/commands/commandUtils.ml index 64c81d12eef..f2fc53740bc 100644 --- a/src/commands/commandUtils.ml +++ b/src/commands/commandUtils.ml @@ -659,7 +659,7 @@ let file_options = module_file_exts = FlowConfig.module_file_exts flowconfig; module_resource_exts = FlowConfig.module_resource_exts flowconfig; node_resolver_dirnames = FlowConfig.node_resolver_dirnames flowconfig; - node_resolver_aliases = FlowConfig.node_resolver_aliases flowconfig + node_resolver_aliases = FlowConfig.node_resolver_aliases flowconfig; } let ignore_flag prev = diff --git a/src/commands/config/flowConfig.ml b/src/commands/config/flowConfig.ml index 087c9744813..a76edaf05f9 100644 --- a/src/commands/config/flowConfig.ml +++ b/src/commands/config/flowConfig.ml @@ -461,11 +461,11 @@ module Opts = struct Ok { opts with node_resolver_dirnames }) ); ( "module.system.node.resolve_alias", string - ~init: (fun opts -> { opts with node_resolver_aliases = [] }) - ~multiple: true + ~init:(fun opts -> { opts with node_resolver_aliases = [] }) + ~multiple:true (fun opts v -> let node_resolver_aliases = v :: opts.node_resolver_aliases in - Ok {opts with node_resolver_aliases;}) ); + Ok { opts with node_resolver_aliases }) ); ("module.use_strict", boolean (fun opts v -> Ok { opts with modules_are_use_strict = v })); ("munge_underscores", boolean (fun opts v -> Ok { opts with munge_underscores = v })); ( "name", diff --git a/src/common/files.ml b/src/common/files.ml index db68d2dfbae..819e63167dd 100644 --- a/src/common/files.ml +++ b/src/common/files.ml @@ -37,6 +37,7 @@ let module_file_exts options = options.module_file_exts let module_resource_exts options = options.module_resource_exts let node_resolver_dirnames options = options.node_resolver_dirnames + let node_resolver_aliases options = options.node_resolver_aliases let node_modules_containers = ref SSet.empty @@ -108,8 +109,7 @@ let is_valid_path = let is_node_module options path = List.mem (Filename.basename path) options.node_resolver_dirnames -let is_module_alias options path = - List.mem (Filename.basename path) options.node_resolver_aliases +let is_module_alias options path = List.mem (Filename.basename path) options.node_resolver_aliases let is_flow_file ~options = let is_valid_path = is_valid_path ~options in @@ -190,12 +190,7 @@ let max_files = 1000 If kind_of_path fails, then we only emit a warning if error_filter passes *) let make_next_files_and_symlinks - ~node_module_filter - ~module_alias_filter - ~path_filter - ~realpath_filter - ~error_filter - paths = + ~node_module_filter ~module_alias_filter ~path_filter ~realpath_filter ~error_filter paths = let prefix_checkers = Core_list.map ~f:is_prefix paths in let rec process sz (acc, symlinks) files dir stack = if sz >= max_files then @@ -253,12 +248,7 @@ let make_next_files_and_symlinks and including any directories that are symlinked to even if they are outside of `paths`. *) let make_next_files_following_symlinks - ~node_module_filter - ~module_alias_filter - ~path_filter - ~realpath_filter - ~error_filter - paths = + ~node_module_filter ~module_alias_filter ~path_filter ~realpath_filter ~error_filter paths = let paths = Core_list.map ~f:Path.to_string paths in let cb = ref diff --git a/src/common/files.mli b/src/common/files.mli index d322a8b5906..363862d208d 100644 --- a/src/common/files.mli +++ b/src/common/files.mli @@ -38,7 +38,7 @@ val module_resource_exts : options -> SSet.t val node_resolver_dirnames : options -> string list -val node_resolver_aliases: options -> string list +val node_resolver_aliases : options -> string list val node_modules_containers : SSet.t ref @@ -127,7 +127,7 @@ val mkdirp : string -> Unix.file_perm -> unit val is_within_node_modules : root:Path.t -> options:options -> string -> bool -val is_within_alias_directory: root:Path.t -> options: options -> string -> bool +val is_within_alias_directory : root:Path.t -> options:options -> string -> bool val imaginary_realpath : string -> string diff --git a/src/services/inference/module/module_js.ml b/src/services/inference/module/module_js.ml index dd884e9d3df..fea426ed92a 100644 --- a/src/services/inference/module/module_js.ml +++ b/src/services/inference/module/module_js.ml @@ -416,40 +416,40 @@ module Node = struct [ lazy ( if SSet.mem dir node_modules_containers then - lazy_seq([ - lazy ( - lazy_seq - ( Files.node_resolver_aliases file_options - |> Core_list.map ~f:(fun dirname -> - let modified_dirname = - dirname - |> Str.split_delim Files.project_root_token - |> String.concat root - in - lazy - (resolve_relative - ~options - ~reader - loc - ?resolution_acc - dir (spf "%s%s%s" modified_dirname Filename.dir_sep r))) ) - ); - lazy ( - lazy_seq - ( Files.node_resolver_dirnames file_options - |> Core_list.map ~f:(fun dirname -> - lazy - (resolve_relative - ~options - ~reader - loc - ?resolution_acc - dir (spf "%s%s%s" dirname Filename.dir_sep r))) ) - ); - ]) - else None - ); - + lazy_seq + [ + lazy + (lazy_seq + ( Files.node_resolver_aliases file_options + |> Core_list.map ~f:(fun dirname -> + let modified_dirname = + dirname + |> Str.split_delim Files.project_root_token + |> String.concat root + in + lazy + (resolve_relative + ~options + ~reader + loc + ?resolution_acc + dir + (spf "%s%s%s" modified_dirname Filename.dir_sep r))) )); + lazy + (lazy_seq + ( Files.node_resolver_dirnames file_options + |> Core_list.map ~f:(fun dirname -> + lazy + (resolve_relative + ~options + ~reader + loc + ?resolution_acc + dir + (spf "%s%s%s" dirname Filename.dir_sep r))) )); + ] + else + None ); lazy (let parent_dir = Filename.dirname dir in if dir = parent_dir then From cae670dd7da32cdb63b7e0b0f4ca4d9f84307833 Mon Sep 17 00:00:00 2001 From: davidroeca Date: Fri, 1 Nov 2019 13:46:01 -0400 Subject: [PATCH 14/14] switch from Core_list to Base.List --- src/services/inference/module/module_js.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/inference/module/module_js.ml b/src/services/inference/module/module_js.ml index db2aed90e3c..4428f1d77bf 100644 --- a/src/services/inference/module/module_js.ml +++ b/src/services/inference/module/module_js.ml @@ -332,7 +332,7 @@ module Node = struct lazy (lazy_seq ( Files.node_resolver_aliases file_options - |> Core_list.map ~f:(fun dirname -> + |> Base.List.map ~f:(fun dirname -> let modified_dirname = dirname |> Str.split_delim Files.project_root_token