@@ -27,20 +27,10 @@ let (//) = Ext_path.combine
2727
2828
2929
30- (* TODO: sync up with {!Js_packages_info.module_system} *)
31- type format = Ext_module_system .t =
32- | NodeJS | Es6 | Es6_global
33-
34- type spec = {
35- format : format ;
36- in_source : bool ;
37- suffix : Ext_js_suffix .t
38- }
30+
3931
4032(* FIXME: use assoc list instead *)
41- module Spec_set = Set. Make ( struct type t = spec
42- let compare = Pervasives. compare
43- end )
33+ module Spec_set = Bsb_spec_set
4434
4535type t = {
4636 modules : Spec_set .t ;
@@ -59,13 +49,13 @@ let bad_module_format_message_exn ~loc format =
5949 Literals. es6
6050 Literals. es6_global
6151
62- let supported_format (x : string ) loc =
52+ let supported_format (x : string ) loc : Ext_module_system.t =
6353 if x = Literals. commonjs then NodeJS
6454 else if x = Literals. es6 then Es6
6555 else if x = Literals. es6_global then Es6_global
6656 else bad_module_format_message_exn ~loc x
6757
68- let string_of_format (x : format ) =
58+ let string_of_format (x : Ext_module_system.t ) =
6959 match x with
7060 | NodeJS -> Literals. commonjs
7161 | Es6 -> Literals. es6
@@ -91,7 +81,7 @@ let rec from_array suffix (arr : Ext_json_types.t array) : Spec_set.t =
9181 ! spec
9282
9383(* TODO: FIXME: better API without mutating *)
94- and from_json_single suffix (x : Ext_json_types.t ) : spec =
84+ and from_json_single suffix (x : Ext_json_types.t ) : Bsb_spec_set. spec =
9585 match x with
9686 | Str {str = format ; loc } ->
9787 {format = supported_format format loc ; in_source = false ; suffix }
@@ -136,7 +126,7 @@ let bs_package_output = "-bs-package-output"
136126 coordinate with command line flag
137127 {[ -bs-package-output commonjs:lib/js/jscomp/test:.js ]}
138128*)
139- let package_flag ({format; in_source; suffix } : spec ) dir =
129+ let package_flag ({format; in_source; suffix } : Bsb_spec_set. spec ) dir =
140130 Ext_string. inter2
141131 bs_package_output
142132 (Ext_string. concat5
@@ -151,13 +141,30 @@ let package_flag ({format; in_source; suffix } : spec) dir =
151141(* FIXME: we should adapt it *)
152142let package_flag_of_package_specs (package_specs : t )
153143 ~(dirname : string ) : string =
154- let res = Spec_set. fold (fun format acc ->
155- Ext_string. inter2 acc (package_flag format dirname )
156- ) package_specs.modules Ext_string. empty in
144+ let res =
145+ match (package_specs.modules :> Bsb_spec_set.spec list ) with
146+ | [] -> Ext_string. empty
147+ | [format] ->
148+ Ext_string. inter2 Ext_string. empty (package_flag format dirname)
149+ | [a;b] ->
150+ Ext_string. inter3 Ext_string. empty
151+ (package_flag a dirname)
152+ (package_flag b dirname)
153+ | [a;b;c] ->
154+ Ext_string. inter4
155+ Ext_string. empty
156+ (package_flag a dirname)
157+ (package_flag b dirname)
158+ (package_flag c dirname)
159+ | _ ->
160+ Spec_set. fold (fun format acc ->
161+ Ext_string. inter2 acc (package_flag format dirname )
162+ ) package_specs.modules Ext_string. empty in
157163 match package_specs.runtime with
158164 | None -> res
159165 | Some x ->
160- res ^ " -runtime " ^ x
166+ Ext_string. inter3 res " -runtime" x
167+
161168let default_package_specs suffix =
162169 Spec_set. singleton
163170 { format = NodeJS ; in_source = false ; suffix }
@@ -173,7 +180,7 @@ let get_list_of_output_js
173180 (output_file_sans_extension : string )
174181 =
175182 Spec_set. fold
176- (fun (spec : spec ) acc ->
183+ (fun (spec : Bsb_spec_set. spec ) acc ->
177184 let basename =
178185 Ext_namespace. change_ext_ns_suffix
179186 output_file_sans_extension
@@ -189,7 +196,7 @@ let list_dirs_by
189196 (package_specs : t )
190197 (f : string -> unit )
191198 =
192- Spec_set. iter (fun (spec : spec ) ->
199+ Spec_set. iter (fun (spec : Bsb_spec_set. spec ) ->
193200 if not spec.in_source then
194201 f (Bsb_config. top_prefix_of_format spec.format)
195202 ) package_specs.modules
0 commit comments