@@ -27,20 +27,10 @@ let (//) = Ext_path.combine
27
27
28
28
29
29
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
+
39
31
40
32
(* 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
44
34
45
35
type t = {
46
36
modules : Spec_set .t ;
@@ -59,13 +49,13 @@ let bad_module_format_message_exn ~loc format =
59
49
Literals. es6
60
50
Literals. es6_global
61
51
62
- let supported_format (x : string ) loc =
52
+ let supported_format (x : string ) loc : Ext_module_system.t =
63
53
if x = Literals. commonjs then NodeJS
64
54
else if x = Literals. es6 then Es6
65
55
else if x = Literals. es6_global then Es6_global
66
56
else bad_module_format_message_exn ~loc x
67
57
68
- let string_of_format (x : format ) =
58
+ let string_of_format (x : Ext_module_system.t ) =
69
59
match x with
70
60
| NodeJS -> Literals. commonjs
71
61
| Es6 -> Literals. es6
@@ -91,7 +81,7 @@ let rec from_array suffix (arr : Ext_json_types.t array) : Spec_set.t =
91
81
! spec
92
82
93
83
(* 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 =
95
85
match x with
96
86
| Str {str = format ; loc } ->
97
87
{format = supported_format format loc ; in_source = false ; suffix }
@@ -136,7 +126,7 @@ let bs_package_output = "-bs-package-output"
136
126
coordinate with command line flag
137
127
{[ -bs-package-output commonjs:lib/js/jscomp/test:.js ]}
138
128
*)
139
- let package_flag ({format; in_source; suffix } : spec ) dir =
129
+ let package_flag ({format; in_source; suffix } : Bsb_spec_set. spec ) dir =
140
130
Ext_string. inter2
141
131
bs_package_output
142
132
(Ext_string. concat5
@@ -151,13 +141,30 @@ let package_flag ({format; in_source; suffix } : spec) dir =
151
141
(* FIXME: we should adapt it *)
152
142
let package_flag_of_package_specs (package_specs : t )
153
143
~(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
157
163
match package_specs.runtime with
158
164
| None -> res
159
165
| Some x ->
160
- res ^ " -runtime " ^ x
166
+ Ext_string. inter3 res " -runtime" x
167
+
161
168
let default_package_specs suffix =
162
169
Spec_set. singleton
163
170
{ format = NodeJS ; in_source = false ; suffix }
@@ -173,7 +180,7 @@ let get_list_of_output_js
173
180
(output_file_sans_extension : string )
174
181
=
175
182
Spec_set. fold
176
- (fun (spec : spec ) acc ->
183
+ (fun (spec : Bsb_spec_set. spec ) acc ->
177
184
let basename =
178
185
Ext_namespace. change_ext_ns_suffix
179
186
output_file_sans_extension
@@ -189,7 +196,7 @@ let list_dirs_by
189
196
(package_specs : t )
190
197
(f : string -> unit )
191
198
=
192
- Spec_set. iter (fun (spec : spec ) ->
199
+ Spec_set. iter (fun (spec : Bsb_spec_set. spec ) ->
193
200
if not spec.in_source then
194
201
f (Bsb_config. top_prefix_of_format spec.format)
195
202
) package_specs.modules
0 commit comments