Skip to content

[esy] Read dependencies in esy from installation.json #3860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions jscomp/bsb/bsb_pkg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ let pkg_name_as_variable package =
|> fun s -> Ext_string.split s '-'
|> String.concat "_"

let rec find_dep_path ic package_name =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing you could do that might make this function simpler is make this function do the try/catch and return an option of string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

let line = input_line ic |> Ext_string.trim in
if Ext_string.starts_with line ("\"" ^ package_name ^ "@") then
input_line ic
|> Ext_string.trim
|> Ext_string.split_by (fun c -> c ='"')
|> List.hd
else
find_dep_path ic package_name

let get_dep_path_from_file ~cwd package =
(* We should find the correct file if we move 3 steps up because we're in _esy/<sandbox>/store/b/<build> *)
try
let ic = open_in_bin Ext_path.(cwd // ".." // ".." // ".." // "installation.json") in
let package_name = Bsb_pkg_types.to_string package in
Some(find_dep_path ic package_name)
with _ -> None

(** TODO: collect all warnings and print later *)
let resolve_bs_package ~cwd (package : t) =
if Lazy.force custom_resolution then
Expand All @@ -117,15 +135,18 @@ let resolve_bs_package ~cwd (package : t) =
| exception Not_found ->
begin
Bsb_log.error
"@{<error>Custom resolution of package %s does not exist in var %s @}@."
"@{<error>Custom resolution@} of package @{<info>%s@} does not exist in var @{<info>%s@}, checking installation.json @."
(Bsb_pkg_types.to_string package)
custom_pkg_loc;
Bsb_exception.package_not_found ~pkg:package ~json:None

match get_dep_path_from_file ~cwd package with
| Some dep_path -> dep_path
| None -> Bsb_exception.package_not_found ~pkg:package ~json:None
end
| path when not (Sys.file_exists path) ->
begin
Bsb_log.error
"@{<error>Custom resolution of package %s does not exist on disk: %s=%s @}@."
"@{<error>Custom resolution@} of package @{<info>%s@} does not exist on disk: %s=%s @."
(Bsb_pkg_types.to_string package)
custom_pkg_loc
path;
Expand All @@ -134,7 +155,7 @@ let resolve_bs_package ~cwd (package : t) =
| path ->
begin
Bsb_log.info
"@{<info>Custom Resolution of package %s in var %s found at %s@}@."
"@{<info>Custom Resolution@} of package %s in var %s found at %s@."
(Bsb_pkg_types.to_string package)
custom_pkg_loc
path;
Expand Down