diff --git a/jscomp/bsb/bsb_pkg.ml b/jscomp/bsb/bsb_pkg.ml index b57d42a2a2..d5e7ae9c94 100644 --- a/jscomp/bsb/bsb_pkg.ml +++ b/jscomp/bsb/bsb_pkg.ml @@ -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 = + 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//store/b/ *) + 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 @@ -117,15 +135,18 @@ let resolve_bs_package ~cwd (package : t) = | exception Not_found -> begin Bsb_log.error - "@{Custom resolution of package %s does not exist in var %s @}@." + "@{Custom resolution@} of package @{%s@} does not exist in var @{%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 - "@{Custom resolution of package %s does not exist on disk: %s=%s @}@." + "@{Custom resolution@} of package @{%s@} does not exist on disk: %s=%s @." (Bsb_pkg_types.to_string package) custom_pkg_loc path; @@ -134,7 +155,7 @@ let resolve_bs_package ~cwd (package : t) = | path -> begin Bsb_log.info - "@{Custom Resolution of package %s in var %s found at %s@}@." + "@{Custom Resolution@} of package %s in var %s found at %s@." (Bsb_pkg_types.to_string package) custom_pkg_loc path;