Skip to content

Commit 65dda8b

Browse files
committed
Read dependencies in esy from installation.json
1 parent a1b896f commit 65dda8b

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

jscomp/bsb/bsb_pkg.ml

+22-4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ let pkg_name_as_variable package =
106106
|> fun s -> Ext_string.split s '-'
107107
|> String.concat "_"
108108

109+
let rec find_dep_path ic package_name =
110+
let line = input_line ic |> Ext_string.trim in
111+
if Ext_string.starts_with line ("\"" ^ package_name ^ "@") then
112+
input_line ic
113+
|> Ext_string.trim
114+
|> Ext_string.split_by (fun c -> c ='"')
115+
|> List.hd
116+
else
117+
find_dep_path ic package_name
118+
119+
let get_dep_path_from_file ~cwd package =
120+
(* We should find the correct file if we move 3 steps up because we're in _esy/<sandbox>/store/b/<build> *)
121+
let ic = open_in_bin Ext_path.(cwd // ".." // ".." // ".." // "installation.json") in
122+
let package_name = Bsb_pkg_types.to_string package in
123+
find_dep_path ic package_name
124+
109125
(** TODO: collect all warnings and print later *)
110126
let resolve_bs_package ~cwd (package : t) =
111127
if Lazy.force custom_resolution then
@@ -117,15 +133,17 @@ let resolve_bs_package ~cwd (package : t) =
117133
| exception Not_found ->
118134
begin
119135
Bsb_log.error
120-
"@{<error>Custom resolution of package %s does not exist in var %s @}@."
136+
"@{<error>Custom resolution@} of package @{<info>%s@} does not exist in var @{<info>%s@}, checking installation.json @."
121137
(Bsb_pkg_types.to_string package)
122138
custom_pkg_loc;
123-
Bsb_exception.package_not_found ~pkg:package ~json:None
139+
140+
try get_dep_path_from_file ~cwd package
141+
with _ -> Bsb_exception.package_not_found ~pkg:package ~json:None
124142
end
125143
| path when not (Sys.file_exists path) ->
126144
begin
127145
Bsb_log.error
128-
"@{<error>Custom resolution of package %s does not exist on disk: %s=%s @}@."
146+
"@{<error>Custom resolution@} of package @{<info>%s@} does not exist on disk: %s=%s @."
129147
(Bsb_pkg_types.to_string package)
130148
custom_pkg_loc
131149
path;
@@ -134,7 +152,7 @@ let resolve_bs_package ~cwd (package : t) =
134152
| path ->
135153
begin
136154
Bsb_log.info
137-
"@{<info>Custom Resolution of package %s in var %s found at %s@}@."
155+
"@{<info>Custom Resolution@} of package %s in var %s found at %s@."
138156
(Bsb_pkg_types.to_string package)
139157
custom_pkg_loc
140158
path;

0 commit comments

Comments
 (0)