Skip to content

Commit 2fa8b0b

Browse files
committed
(fix) Repair resolution of mis-matched extensions
1 parent 20d87f1 commit 2fa8b0b

File tree

6 files changed

+135
-59
lines changed

6 files changed

+135
-59
lines changed

jscomp/core/js_name_of_module_id.ml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,37 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t)
102102
let current_loc = query current_package_info module_system in
103103
match Lam_compile_env.get_package_path_from_cmj dep_module_id with
104104
| cmj_path, dep_package_info, case -> (
105-
let js_file =
106-
Ext_namespace.js_filename_of_modulename
107-
~name:dep_module_id.id.name ~ext case
108-
in
109105
let dep_loc = query dep_package_info module_system in
110106
match (dep_loc, current_loc) with
111107
| Package_not_found, _ ->
112108
Bs_exception.error (Missing_ml_dependency dep_module_id.id.name)
113109
| Package_script, Package_found _ ->
110+
let js_file =
111+
Ext_namespace.js_filename_of_modulename
112+
(* FIXME: Unsure how to infer a useful file-extension here. *)
113+
~name:dep_module_id.id.name ~ext:"" case
114+
in
114115
Bs_exception.error
115116
(Dependency_script_module_dependent_not js_file)
116117
| (Package_script | Package_found _), Package_not_found ->
117118
assert false
118-
| Package_found pkg, Package_script ->
119+
| Package_found dep_pkg, Package_script ->
120+
let js_file =
121+
Ext_namespace.js_filename_of_modulename
122+
~name:dep_module_id.id.name ~ext:dep_pkg.extension case
123+
in
119124
#if BS_NATIVE then
120-
if Filename.is_relative pkg.rel_path then
121-
pkg.pkg_rel_path // js_file
122-
else pkg.rel_path // js_file
125+
if Filename.is_relative dep_pkg.rel_path then
126+
dep_pkg.pkg_rel_path // js_file
127+
else dep_pkg.rel_path // js_file
123128
#else
124-
pkg.pkg_rel_path // js_file
129+
dep_pkg.pkg_rel_path // js_file
125130
#end
126131
| Package_found dep_pkg, Package_found cur_pkg -> (
132+
let js_file =
133+
Ext_namespace.js_filename_of_modulename
134+
~name:dep_module_id.id.name ~ext:dep_pkg.extension case
135+
in
127136
if
128137
Js_package_info.same_package_by_name current_package_info
129138
dep_package_info
@@ -158,6 +167,10 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t)
158167
(Filename.dirname (Filename.dirname cmj_path))
159168
// dep_pkg.rel_path // js_file ) )
160169
| Package_script, Package_script -> (
170+
let js_file =
171+
Ext_namespace.js_filename_of_modulename
172+
~name:dep_module_id.id.name ~ext case
173+
in
161174
match Config_util.find_opt js_file with
162175
| Some file ->
163176
let basename = Filename.basename file in

jscomp/core/js_package_info.ml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ let dump_package_info (fmt : Format.formatter) ({ name; locations } : t) =
123123
locations
124124

125125

126-
type package_paths = { rel_path : string; pkg_rel_path : string }
126+
type package_paths = {
127+
rel_path : string;
128+
pkg_rel_path : string;
129+
extension : string;
130+
}
127131
type query_result =
128132
| Package_script
129133
| Package_not_found
@@ -140,20 +144,18 @@ let query_package_location_by_module_system ({ name; locations } : t)
140144
Ext_list.find_first locations (fun k ->
141145
compatible k.module_system module_system)
142146
with
143-
| Some k ->
144-
let rel_path = k.path in
147+
| Some { path = rel_path; extension; module_system = _ms } ->
145148
let pkg_rel_path = name // rel_path in
146-
Package_found { rel_path; pkg_rel_path }
149+
Package_found { rel_path; pkg_rel_path; extension }
147150
| None -> Package_not_found )
148151
| Pkg_runtime -> (
149152
match
150153
Ext_list.find_first locations (fun k ->
151154
compatible k.module_system module_system)
152155
with
153-
| Some k ->
154-
let rel_path = k.path in
156+
| Some { path = rel_path; extension; module_system = _ms } ->
155157
let pkg_rel_path = runtime_package_name // rel_path in
156-
Package_found { rel_path; pkg_rel_path }
158+
Package_found { rel_path; pkg_rel_path; extension }
157159
| None -> Package_not_found )
158160

159161

jscomp/core/js_package_info.mli

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ val deprecated_set_bs_extension : unit -> unit
5353
val append_location_descriptor_of_string : t -> string -> t
5454
(** used by command line option e.g [-bs-package-output commonjs:xx/path:ext] *)
5555

56-
type package_paths = { rel_path : string; pkg_rel_path : string }
56+
type package_paths = {
57+
rel_path : string;
58+
pkg_rel_path : string;
59+
extension : string;
60+
}
5761

5862
type query_result =
5963
| Package_script

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90427,7 +90427,11 @@ val deprecated_set_bs_extension : unit -> unit
9042790427
val append_location_descriptor_of_string : t -> string -> t
9042890428
(** used by command line option e.g [-bs-package-output commonjs:xx/path:ext] *)
9042990429

90430-
type package_paths = { rel_path : string; pkg_rel_path : string }
90430+
type package_paths = {
90431+
rel_path : string;
90432+
pkg_rel_path : string;
90433+
extension : string;
90434+
}
9043190435

9043290436
type query_result =
9043390437
| Package_script
@@ -90567,7 +90571,11 @@ let dump_package_info (fmt : Format.formatter) ({ name; locations } : t) =
9056790571
locations
9056890572

9056990573

90570-
type package_paths = { rel_path : string; pkg_rel_path : string }
90574+
type package_paths = {
90575+
rel_path : string;
90576+
pkg_rel_path : string;
90577+
extension : string;
90578+
}
9057190579
type query_result =
9057290580
| Package_script
9057390581
| Package_not_found
@@ -90584,20 +90592,18 @@ let query_package_location_by_module_system ({ name; locations } : t)
9058490592
Ext_list.find_first locations (fun k ->
9058590593
compatible k.module_system module_system)
9058690594
with
90587-
| Some k ->
90588-
let rel_path = k.path in
90595+
| Some { path = rel_path; extension; module_system = _ms } ->
9058990596
let pkg_rel_path = name // rel_path in
90590-
Package_found { rel_path; pkg_rel_path }
90597+
Package_found { rel_path; pkg_rel_path; extension }
9059190598
| None -> Package_not_found )
9059290599
| Pkg_runtime -> (
9059390600
match
9059490601
Ext_list.find_first locations (fun k ->
9059590602
compatible k.module_system module_system)
9059690603
with
90597-
| Some k ->
90598-
let rel_path = k.path in
90604+
| Some { path = rel_path; extension; module_system = _ms } ->
9059990605
let pkg_rel_path = runtime_package_name // rel_path in
90600-
Package_found { rel_path; pkg_rel_path }
90606+
Package_found { rel_path; pkg_rel_path; extension }
9060190607
| None -> Package_not_found )
9060290608

9060390609

@@ -109568,24 +109574,33 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t)
109568109574
let current_loc = query current_package_info module_system in
109569109575
match Lam_compile_env.get_package_path_from_cmj dep_module_id with
109570109576
| cmj_path, dep_package_info, case -> (
109571-
let js_file =
109572-
Ext_namespace.js_filename_of_modulename
109573-
~name:dep_module_id.id.name ~ext case
109574-
in
109575109577
let dep_loc = query dep_package_info module_system in
109576109578
match (dep_loc, current_loc) with
109577109579
| Package_not_found, _ ->
109578109580
Bs_exception.error (Missing_ml_dependency dep_module_id.id.name)
109579109581
| Package_script, Package_found _ ->
109582+
let js_file =
109583+
Ext_namespace.js_filename_of_modulename
109584+
(* FIXME: Unsure how to infer a useful file-extension here. *)
109585+
~name:dep_module_id.id.name ~ext:"" case
109586+
in
109580109587
Bs_exception.error
109581109588
(Dependency_script_module_dependent_not js_file)
109582109589
| (Package_script | Package_found _), Package_not_found ->
109583109590
assert false
109584-
| Package_found pkg, Package_script ->
109591+
| Package_found dep_pkg, Package_script ->
109592+
let js_file =
109593+
Ext_namespace.js_filename_of_modulename
109594+
~name:dep_module_id.id.name ~ext:dep_pkg.extension case
109595+
in
109585109596

109586-
pkg.pkg_rel_path // js_file
109597+
dep_pkg.pkg_rel_path // js_file
109587109598

109588109599
| Package_found dep_pkg, Package_found cur_pkg -> (
109600+
let js_file =
109601+
Ext_namespace.js_filename_of_modulename
109602+
~name:dep_module_id.id.name ~ext:dep_pkg.extension case
109603+
in
109589109604
if
109590109605
Js_package_info.same_package_by_name current_package_info
109591109606
dep_package_info
@@ -109616,6 +109631,10 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t)
109616109631
(Filename.dirname (Filename.dirname cmj_path))
109617109632
// dep_pkg.rel_path // js_file ) )
109618109633
| Package_script, Package_script -> (
109634+
let js_file =
109635+
Ext_namespace.js_filename_of_modulename
109636+
~name:dep_module_id.id.name ~ext case
109637+
in
109619109638
match Config_util.find_opt js_file with
109620109639
| Some file ->
109621109640
let basename = Filename.basename file in

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90427,7 +90427,11 @@ val deprecated_set_bs_extension : unit -> unit
9042790427
val append_location_descriptor_of_string : t -> string -> t
9042890428
(** used by command line option e.g [-bs-package-output commonjs:xx/path:ext] *)
9042990429

90430-
type package_paths = { rel_path : string; pkg_rel_path : string }
90430+
type package_paths = {
90431+
rel_path : string;
90432+
pkg_rel_path : string;
90433+
extension : string;
90434+
}
9043190435

9043290436
type query_result =
9043390437
| Package_script
@@ -90567,7 +90571,11 @@ let dump_package_info (fmt : Format.formatter) ({ name; locations } : t) =
9056790571
locations
9056890572

9056990573

90570-
type package_paths = { rel_path : string; pkg_rel_path : string }
90574+
type package_paths = {
90575+
rel_path : string;
90576+
pkg_rel_path : string;
90577+
extension : string;
90578+
}
9057190579
type query_result =
9057290580
| Package_script
9057390581
| Package_not_found
@@ -90584,20 +90592,18 @@ let query_package_location_by_module_system ({ name; locations } : t)
9058490592
Ext_list.find_first locations (fun k ->
9058590593
compatible k.module_system module_system)
9058690594
with
90587-
| Some k ->
90588-
let rel_path = k.path in
90595+
| Some { path = rel_path; extension; module_system = _ms } ->
9058990596
let pkg_rel_path = name // rel_path in
90590-
Package_found { rel_path; pkg_rel_path }
90597+
Package_found { rel_path; pkg_rel_path; extension }
9059190598
| None -> Package_not_found )
9059290599
| Pkg_runtime -> (
9059390600
match
9059490601
Ext_list.find_first locations (fun k ->
9059590602
compatible k.module_system module_system)
9059690603
with
90597-
| Some k ->
90598-
let rel_path = k.path in
90604+
| Some { path = rel_path; extension; module_system = _ms } ->
9059990605
let pkg_rel_path = runtime_package_name // rel_path in
90600-
Package_found { rel_path; pkg_rel_path }
90606+
Package_found { rel_path; pkg_rel_path; extension }
9060190607
| None -> Package_not_found )
9060290608

9060390609

@@ -109568,24 +109574,33 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t)
109568109574
let current_loc = query current_package_info module_system in
109569109575
match Lam_compile_env.get_package_path_from_cmj dep_module_id with
109570109576
| cmj_path, dep_package_info, case -> (
109571-
let js_file =
109572-
Ext_namespace.js_filename_of_modulename
109573-
~name:dep_module_id.id.name ~ext case
109574-
in
109575109577
let dep_loc = query dep_package_info module_system in
109576109578
match (dep_loc, current_loc) with
109577109579
| Package_not_found, _ ->
109578109580
Bs_exception.error (Missing_ml_dependency dep_module_id.id.name)
109579109581
| Package_script, Package_found _ ->
109582+
let js_file =
109583+
Ext_namespace.js_filename_of_modulename
109584+
(* FIXME: Unsure how to infer a useful file-extension here. *)
109585+
~name:dep_module_id.id.name ~ext:"" case
109586+
in
109580109587
Bs_exception.error
109581109588
(Dependency_script_module_dependent_not js_file)
109582109589
| (Package_script | Package_found _), Package_not_found ->
109583109590
assert false
109584-
| Package_found pkg, Package_script ->
109591+
| Package_found dep_pkg, Package_script ->
109592+
let js_file =
109593+
Ext_namespace.js_filename_of_modulename
109594+
~name:dep_module_id.id.name ~ext:dep_pkg.extension case
109595+
in
109585109596

109586-
pkg.pkg_rel_path // js_file
109597+
dep_pkg.pkg_rel_path // js_file
109587109598

109588109599
| Package_found dep_pkg, Package_found cur_pkg -> (
109600+
let js_file =
109601+
Ext_namespace.js_filename_of_modulename
109602+
~name:dep_module_id.id.name ~ext:dep_pkg.extension case
109603+
in
109589109604
if
109590109605
Js_package_info.same_package_by_name current_package_info
109591109606
dep_package_info
@@ -109616,6 +109631,10 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t)
109616109631
(Filename.dirname (Filename.dirname cmj_path))
109617109632
// dep_pkg.rel_path // js_file ) )
109618109633
| Package_script, Package_script -> (
109634+
let js_file =
109635+
Ext_namespace.js_filename_of_modulename
109636+
~name:dep_module_id.id.name ~ext case
109637+
in
109619109638
match Config_util.find_opt js_file with
109620109639
| Some file ->
109621109640
let basename = Filename.basename file in

0 commit comments

Comments
 (0)