Skip to content

Commit 51b1bc4

Browse files
committed
push suffix into per package
1 parent 5b59850 commit 51b1bc4

13 files changed

+52
-40
lines changed

jscomp/core/js_cmj_format.ml

+2-4
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,15 @@ type t = {
5151
values : keyed_cmj_values ;
5252
pure : bool;
5353
package_spec : Js_packages_info.t ;
54-
case : Ext_js_file_kind.case;
55-
suffix : Ext_js_suffix.t;
54+
case : Ext_js_file_kind.case;
5655
}
5756

5857
let make
5958
~(values:cmj_value Map_string.t)
6059
~effect
6160
~package_spec
6261
~case
63-
~suffix : t =
62+
: t =
6463
{
6564
values = Map_string.to_sorted_array_with_f values (fun k v -> {
6665
name = k ;
@@ -69,7 +68,6 @@ let make
6968
});
7069
pure = effect = None ;
7170
package_spec;
72-
suffix;
7371
case
7472
}
7573

jscomp/core/js_cmj_format.mli

-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ type t = {
7575
pure : bool;
7676
package_spec : Js_packages_info.t ;
7777
case : Ext_js_file_kind.case;
78-
suffix : Ext_js_suffix.t;
7978
}
8079

8180

@@ -84,7 +83,6 @@ val make:
8483
effect: effect ->
8584
package_spec: Js_packages_info.t ->
8685
case:Ext_js_file_kind.case ->
87-
suffix:Ext_js_suffix.t ->
8886
t
8987

9088

jscomp/core/js_cmj_load_builtin_unit.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let load_builin_unit (unit_name : string) : Js_cmj_format.cmj_load_info =
3636
{values; pure;
3737
package_spec = Js_packages_info.runtime_package_specs;
3838
case = Little;
39-
suffix = Js} (* FIXME when we change it *)
39+
} (* FIXME when we change it *)
4040
in
4141
if Js_config.get_diagnose () then
4242
Format.fprintf Format.err_formatter "<Cmj: %s@." unit_name;

jscomp/core/js_name_of_module_id.ml

+13-5
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,29 @@ let string_of_module_id
109109
module_system
110110
in
111111
match Lam_compile_env.get_package_path_from_cmj dep_module_id with
112-
| (package_path, dep_package_info, case, suffix) ->
113-
let js_file = Ext_namespace.js_name_of_modulename dep_module_id.id.name case suffix in
112+
| (package_path, dep_package_info, case) ->
113+
114+
114115
let dep_info_query =
115116
Js_packages_info.query_package_infos dep_package_info module_system
116117
in
117118
match dep_info_query, current_info_query with
118119
| Package_not_found , _ ->
119120
Bs_exception.error (Missing_ml_dependency dep_module_id.id.name)
120121
| Package_script , Package_found _ ->
121-
Bs_exception.error (Dependency_script_module_dependent_not js_file)
122+
Bs_exception.error (Dependency_script_module_dependent_not dep_module_id.id.name)
122123
| (Package_script | Package_found _ ), Package_not_found -> assert false
123124

124-
| Package_found pkg, Package_script
125+
| Package_found ({suffix} as pkg), Package_script
125126
->
127+
let js_file =
128+
Ext_namespace.js_name_of_modulename dep_module_id.id.name case suffix in
126129
pkg.pkg_rel_path // js_file
127-
| Package_found dep_pkg,
130+
| Package_found ({suffix } as dep_pkg),
128131
Package_found cur_pkg ->
132+
let js_file =
133+
Ext_namespace.js_name_of_modulename dep_module_id.id.name case suffix in
134+
129135
if Js_packages_info.same_package_by_name current_package_info dep_package_info then
130136
Ext_path.node_rebase_file
131137
~from:cur_pkg.rel_path
@@ -154,6 +160,8 @@ let string_of_module_id
154160
end
155161
| Package_script, Package_script
156162
->
163+
let js_file =
164+
Ext_namespace.js_name_of_modulename dep_module_id.id.name case Js in
157165
match Config_util.find_opt js_file with
158166
| Some file ->
159167
let basename = Filename.basename file in

jscomp/core/js_packages_info.ml

+21-10
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ let compatible (dep : module_system)
4343
(* As a dependency Leaf Node, it is the same either [global] or [not] *)
4444

4545

46-
type package_info =
47-
{ module_system : module_system ; path : string }
46+
type package_info = {
47+
module_system : module_system ;
48+
path : string;
49+
suffix : Ext_js_suffix.t
50+
}
4851

4952
type package_name =
5053
| Pkg_empty
@@ -79,8 +82,8 @@ type t =
7982
let runtime_package_specs : t = {
8083
name = Pkg_runtime;
8184
module_systems =[
82-
{module_system = Es6; path = "lib/es6"};
83-
{module_system = NodeJS; path = "lib/js"};
85+
{module_system = Es6; path = "lib/es6"; suffix = Js};
86+
{module_system = NodeJS; path = "lib/js"; suffix = Js};
8487
]
8588
}
8689
let same_package_by_name (x : t) (y : t) = x.name = y.name
@@ -140,13 +143,14 @@ let module_system_of_string package_name : module_system option =
140143

141144
let dump_package_info
142145
(fmt : Format.formatter)
143-
({module_system = ms; path = name} : package_info)
146+
({module_system = ms; path = name; suffix} : package_info)
144147
=
145148
Format.fprintf
146149
fmt
147-
"@[%s:@ %s@]"
150+
"@[%s@ %s@ %s@]"
148151
(string_of_module_system ms)
149152
name
153+
(Ext_js_suffix.to_string suffix)
150154

151155
let dump_package_name fmt (x : package_name) =
152156
match x with
@@ -169,7 +173,8 @@ type package_found_info =
169173
{
170174

171175
rel_path : string ;
172-
pkg_rel_path : string
176+
pkg_rel_path : string;
177+
suffix : Ext_js_suffix.t
173178
}
174179
type info_query =
175180
| Package_script
@@ -193,10 +198,12 @@ let query_package_infos
193198
Package_found
194199
{
195200
rel_path ;
196-
pkg_rel_path
201+
pkg_rel_path ;
202+
suffix = k.suffix
197203
}
198204
| None -> Package_not_found)
199205
| Pkg_runtime ->
206+
(*FIXME: [compatible] seems not correct *)
200207
match Ext_list.find_first module_systems (fun k ->
201208
compatible k.module_system module_system) with
202209
| Some k ->
@@ -205,7 +212,8 @@ let query_package_infos
205212
Package_found
206213
{
207214
rel_path ;
208-
pkg_rel_path
215+
pkg_rel_path ;
216+
suffix = k.suffix
209217
}
210218
| None -> Package_not_found
211219

@@ -253,7 +261,10 @@ let add_npm_package_path (packages_info : t) (s : string) : t =
253261
| _ ->
254262
Bsc_args.bad_arg @@ "invalid npm package path: " ^ s
255263
in
256-
{ packages_info with module_systems = {module_system; path}::packages_info.module_systems}
264+
{ packages_info with
265+
module_systems =
266+
{module_system; path; suffix = !Js_config.bs_suffix}::packages_info.module_systems
267+
}
257268

258269
(* support es6 modules instead
259270
TODO: enrich ast to support import export

jscomp/core/js_packages_info.mli

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ val runtime_package_path:
4040

4141
type package_info = {
4242
module_system : module_system ;
43-
path : string
43+
path : string ;
44+
suffix : Ext_js_suffix.t
4445
}
4546

4647
type t
@@ -82,7 +83,8 @@ type package_found_info =
8283
{
8384

8485
rel_path : string ;
85-
pkg_rel_path : string
86+
pkg_rel_path : string;
87+
suffix : Ext_js_suffix.t
8688
}
8789

8890
type info_query =

jscomp/core/lam_compile_env.ml

+2-3
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ let query_external_id_info (module_id : Ident.t) (name : string) : ident_info =
133133

134134
let get_package_path_from_cmj
135135
( id : Lam_module_ident.t) :
136-
string * Js_packages_info.t * Ext_js_file_kind.case * Ext_js_suffix.t
136+
string * Js_packages_info.t * Ext_js_file_kind.case
137137
=
138138
let cmj_load_info =
139139
match Lam_module_ident.Hash.find_opt cached_tbl id with
@@ -157,8 +157,7 @@ let get_package_path_from_cmj
157157
let cmj_table = cmj_load_info.cmj_table in
158158
(cmj_load_info.package_path,
159159
cmj_table.package_spec,
160-
cmj_table.case,
161-
cmj_table.suffix
160+
cmj_table.case
162161
)
163162

164163
let add = Lam_module_ident.Hash_set.add

jscomp/core/lam_compile_env.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ val is_pure_module : Lam_module_ident.t -> bool
8888

8989
val get_package_path_from_cmj :
9090
Lam_module_ident.t ->
91-
string * Js_packages_info.t * Ext_js_file_kind.case * Ext_js_suffix.t
91+
string * Js_packages_info.t * Ext_js_file_kind.case
9292

9393

9494

jscomp/core/lam_compile_main.ml

-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ let compile
268268
meta
269269
effect
270270
coerced_input.export_map
271-
!Js_config.bs_suffix
272271
(if Ext_char.is_lower_case (Filename.basename output_prefix).[0] then Little else Upper)
273272
in
274273
(if not !Clflags.dont_write_files then

jscomp/core/lam_stats_export.ml

-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ let export_to_cmj
148148
(meta : Lam_stats.t )
149149
effect
150150
export_map
151-
suffix
152151
case
153152
: Js_cmj_format.t =
154153
let values = values_of_export meta export_map in
@@ -157,7 +156,6 @@ let export_to_cmj
157156
~values
158157
~effect
159158
~package_spec: (Js_packages_state.get_packages_info ())
160-
~suffix
161159
~case
162160
(* FIXME: make sure [-o] would not change its case
163161
add test for ns/non-ns

jscomp/core/lam_stats_export.mli

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ val export_to_cmj :
3434
Lam_stats.t ->
3535
Js_cmj_format.effect ->
3636
Lam.t Map_ident.t ->
37-
Ext_js_suffix.t ->
3837
Ext_js_file_kind.case ->
3938
Js_cmj_format.t
4039

jscomp/main/cmij_main.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ let from_cmj ~mode (files : string list) (output_file : string) : unit =
6363
let () = match mode with
6464
| Native ->
6565
begin match content with
66-
| {case = Little; suffix = Js; package_spec}
66+
| {case = Little; package_spec}
6767
when package_spec = Js_packages_info.runtime_package_specs
6868
-> ()
69+
(*TODO: assert its suffixes*)
6970
| _ -> assert false
7071
end
7172
| Playground _ -> ()

jscomp/main/cmjdump_main.ml

+6-7
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,20 @@
2626

2727
let f fmt = Printf.fprintf stdout fmt
2828

29-
let pp_cmj_case (case : Ext_js_file_kind.case) suffix : unit =
30-
f "%s"
29+
let pp_cmj_case (case : Ext_js_file_kind.case) : unit =
30+
f "%s\n"
3131
("case : " ^
3232
(match case with
3333
| Little -> "little"
34-
| Upper -> "upper") ^
35-
"," ^
36-
Ext_js_suffix.to_string suffix ^ "\n")
34+
| Upper -> "upper")
35+
)
3736

3837
let pp_cmj
39-
({ values ; pure; package_spec = npm_package_path ; case ; suffix } : Js_cmj_format.t) =
38+
({ values ; pure; package_spec = npm_package_path ; case } : Js_cmj_format.t) =
4039
f "package info: %s\n"
4140
(Format.asprintf "%a" Js_packages_info.dump_packages_info npm_package_path)
4241
;
43-
pp_cmj_case case suffix;
42+
pp_cmj_case case ;
4443

4544
f "effect: %s\n"
4645
(if pure then "pure" else "not pure");

0 commit comments

Comments
 (0)