Skip to content

Commit

Permalink
[services] Fix trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
goodmind committed Aug 13, 2019
1 parent 9d8b4b5 commit f7bd065
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/services/inference/module/module_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/services/inference/module/node_paths_part.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f7bd065

Please sign in to comment.