From f7bd065f92e06ab90eaf4b2f2421e0004913280b Mon Sep 17 00:00:00 2001 From: andretshurotshka Date: Wed, 14 Aug 2019 03:29:46 +0500 Subject: [PATCH] [services] Fix trailing slash --- src/services/inference/module/module_js.ml | 9 ++++++--- src/services/inference/module/node_paths_part.ml | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/services/inference/module/module_js.ml b/src/services/inference/module/module_js.ml index f48ad8ece4f..576184c44e7 100644 --- a/src/services/inference/module/module_js.ml +++ b/src/services/inference/module/module_js.ml @@ -102,7 +102,7 @@ let types_versions_package_candidates reader = version_path ) -let types_versions_candidates dir reader rel_path dirname = +let types_versions_candidates ~reader dir rel_path dirname = let open Node_paths_part in let parts = get_node_module_path_parts rel_path dirname in match parts with @@ -124,9 +124,12 @@ let types_versions_candidates dir reader rel_path dirname = in let rel_path = match version_path with | Some (_, version_path) -> - Files.normalize_path package_root (Filename.concat version_path filename) + (* Chop trailing "/" *) + let tail = if filename = "" then version_path else Filename.concat version_path filename in + Files.normalize_path package_root tail | None -> rel_path in + (* If file points outside of root, resolve current package root *) let rel_path = if String_utils.string_starts_with rel_path package_root then rel_path else @@ -458,7 +461,7 @@ module Node = struct if SSet.mem dir node_modules_containers then lazy_seq (Files.node_resolver_dirnames file_options |> Core_list.map ~f:(fun dirname -> let rel_path = spf "%s%s%s" dirname Filename.dir_sep r in - let rel_path_opt = types_versions_candidates dir reader rel_path dirname in + let rel_path_opt = types_versions_candidates ~reader dir rel_path dirname in match rel_path_opt with | Some rel_path -> lazy (resolve_relative diff --git a/src/services/inference/module/node_paths_part.ml b/src/services/inference/module/node_paths_part.ml index d5bea3d68c5..69de9cb8a12 100644 --- a/src/services/inference/module/node_paths_part.ml +++ b/src/services/inference/module/node_paths_part.ml @@ -26,6 +26,8 @@ let states = { package_content = 3; } +(* Example of expected pattern: /base/path/node_modules/[@scope/otherpackage/@otherscope/node_modules/]package/[subdirectory/]file.js *) +(* Returns indices: ^ ^ ^ ^ *) let get_node_module_path_parts (full_path: string) (node_modules_path_part: string): node_module_path_parts option = let top_level_node_modules_index = ref 0 in let top_level_package_name_index = ref 0 in