Skip to content

Commit 6d78909

Browse files
committed
tweak package specs
1 parent 8953fd0 commit 6d78909

File tree

4 files changed

+54
-38
lines changed

4 files changed

+54
-38
lines changed

jscomp/bsb/bsb_ninja_rule.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ let make_custom_rules
172172
if read_cmi <> `is_cmi then begin
173173
Ext_buffer.add_string buf " -bs-package-name ";
174174
Ext_buffer.add_string buf package_name;
175-
Ext_buffer.add_string buf (Bsb_package_specs.package_flag_of_package_specs package_specs "$in_d")
175+
Ext_buffer.add_string buf
176+
(Bsb_package_specs.package_flag_of_package_specs package_specs ~dirname:"$in_d")
176177
end;
177178
begin match bs_dependencies, bs_dev_dependencies with
178179
| [], [] -> ()

jscomp/bsb/bsb_package_specs.ml

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ module Spec_set = Set.Make( struct type t = spec
4141
let compare = Pervasives.compare
4242
end)
4343

44-
type t = Spec_set.t
44+
type t = {
45+
modules : Spec_set.t;
46+
(* runtime: Bsb_pkg_types.t option; *)
47+
}
4548

4649
let (.?()) = Map_string.find_opt
4750

@@ -89,8 +92,8 @@ and from_json_single suffix (x : Ext_json_types.t) : spec =
8992
| Str {str = format; loc } ->
9093
{format = supported_format format loc ; in_source = false ; suffix }
9194
| Obj {map; loc} ->
92-
begin match Map_string.find_exn map "module" with
93-
| Str {str = format} ->
95+
begin match map .?("module") with
96+
| Some(Str {str = format}) ->
9497
let in_source =
9598
match map.?(Bsb_build_schemas.in_source) with
9699
| Some (True _) -> true
@@ -108,13 +111,10 @@ and from_json_single suffix (x : Ext_json_types.t) : spec =
108111
Bsb_exception.errorf ~loc:(Ext_json.loc_of x) "expect a string field"
109112
| None -> suffix in
110113
{format = supported_format format loc ; in_source ; suffix}
111-
| Arr _ ->
112-
Bsb_exception.errorf ~loc
113-
"package-specs: when the configuration is an object, `module` field should be a string, not an array. If you want to pass multiple module specs, try turning package-specs into an array of objects (or strings) instead."
114-
| _ ->
114+
| Some _ ->
115115
Bsb_exception.errorf ~loc
116-
"package-specs: the `module` field of the configuration object should be a string."
117-
| exception _ ->
116+
"package-specs: when the configuration is an object, `module` field should be a string, not an array. If you want to pass multiple module specs, try turning package-specs into an array of objects (or strings) instead."
117+
| None ->
118118
Bsb_exception.errorf ~loc
119119
"package-specs: when the configuration is an object, the `module` field is mandatory."
120120
end
@@ -144,11 +144,12 @@ let package_flag ({format; in_source; suffix } : spec) dir =
144144
(Ext_js_suffix.to_string suffix)
145145
)
146146

147+
(* FIXME: we should adapt it *)
147148
let package_flag_of_package_specs (package_specs : t)
148-
(dirname : string ) : string =
149+
~(dirname : string ) : string =
149150
Spec_set.fold (fun format acc ->
150151
Ext_string.inter2 acc (package_flag format dirname )
151-
) package_specs Ext_string.empty
152+
) package_specs.modules Ext_string.empty
152153

153154
let default_package_specs suffix =
154155
Spec_set.singleton
@@ -161,7 +162,7 @@ let default_package_specs suffix =
161162
162163
*)
163164
let get_list_of_output_js
164-
(package_specs : Spec_set.t)
165+
(package_specs : t)
165166
(output_file_sans_extension : string)
166167
=
167168
Spec_set.fold
@@ -174,17 +175,17 @@ let get_list_of_output_js
174175
(if spec.in_source then Bsb_config.rev_lib_bs_prefix basename
175176
else Bsb_config.lib_bs_prefix_of_format spec.format // basename)
176177
:: acc
177-
) package_specs []
178+
) package_specs.modules []
178179

179180

180181
let list_dirs_by
181-
(package_specs : Spec_set.t)
182+
(package_specs : t)
182183
(f : string -> unit)
183184
=
184185
Spec_set.iter (fun (spec : spec) ->
185186
if not spec.in_source then
186187
f (Bsb_config.top_prefix_of_format spec.format)
187-
) package_specs
188+
) package_specs.modules
188189

189190
type json_map = Ext_json_types.t Map_string.t
190191

@@ -203,8 +204,11 @@ let extract_bs_suffix_exn (map : json_map) : Ext_js_suffix.t =
203204

204205
let from_map map =
205206
let suffix = extract_bs_suffix_exn map in
206-
match map.?(Bsb_build_schemas.package_specs) with
207+
let modules = match map.?(Bsb_build_schemas.package_specs) with
207208
| Some x ->
208209
from_json suffix x
209-
| None -> default_package_specs suffix
210+
| None -> default_package_specs suffix in
211+
{
212+
modules
213+
}
210214

jscomp/bsb/bsb_package_specs.mli

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ val get_list_of_output_js :
3939
Sample output: {[ -bs-package-output commonjs:lib/js/jscomp/test]}
4040
*)
4141
val package_flag_of_package_specs :
42-
t -> string -> string
42+
t ->
43+
dirname:string ->
44+
string
4345

46+
(* used to ensure each dir does exist *)
4447
val list_dirs_by :
4548
t ->
4649
(string -> unit) ->

lib/4.06.1/bsb.ml

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7118,8 +7118,11 @@ val get_list_of_output_js :
71187118
Sample output: {[ -bs-package-output commonjs:lib/js/jscomp/test]}
71197119
*)
71207120
val package_flag_of_package_specs :
7121-
t -> string -> string
7121+
t ->
7122+
dirname:string ->
7123+
string
71227124

7125+
(* used to ensure each dir does exist *)
71237126
val list_dirs_by :
71247127
t ->
71257128
(string -> unit) ->
@@ -7169,7 +7172,10 @@ module Spec_set = Set.Make( struct type t = spec
71697172
let compare = Pervasives.compare
71707173
end)
71717174

7172-
type t = Spec_set.t
7175+
type t = {
7176+
modules : Spec_set.t;
7177+
(* runtime: Bsb_pkg_types.t option; *)
7178+
}
71737179

71747180
let (.?()) = Map_string.find_opt
71757181

@@ -7217,8 +7223,8 @@ and from_json_single suffix (x : Ext_json_types.t) : spec =
72177223
| Str {str = format; loc } ->
72187224
{format = supported_format format loc ; in_source = false ; suffix }
72197225
| Obj {map; loc} ->
7220-
begin match Map_string.find_exn map "module" with
7221-
| Str {str = format} ->
7226+
begin match map .?("module") with
7227+
| Some(Str {str = format}) ->
72227228
let in_source =
72237229
match map.?(Bsb_build_schemas.in_source) with
72247230
| Some (True _) -> true
@@ -7236,13 +7242,10 @@ and from_json_single suffix (x : Ext_json_types.t) : spec =
72367242
Bsb_exception.errorf ~loc:(Ext_json.loc_of x) "expect a string field"
72377243
| None -> suffix in
72387244
{format = supported_format format loc ; in_source ; suffix}
7239-
| Arr _ ->
7245+
| Some _ ->
72407246
Bsb_exception.errorf ~loc
7241-
"package-specs: when the configuration is an object, `module` field should be a string, not an array. If you want to pass multiple module specs, try turning package-specs into an array of objects (or strings) instead."
7242-
| _ ->
7243-
Bsb_exception.errorf ~loc
7244-
"package-specs: the `module` field of the configuration object should be a string."
7245-
| exception _ ->
7247+
"package-specs: when the configuration is an object, `module` field should be a string, not an array. If you want to pass multiple module specs, try turning package-specs into an array of objects (or strings) instead."
7248+
| None ->
72467249
Bsb_exception.errorf ~loc
72477250
"package-specs: when the configuration is an object, the `module` field is mandatory."
72487251
end
@@ -7272,11 +7275,12 @@ let package_flag ({format; in_source; suffix } : spec) dir =
72727275
(Ext_js_suffix.to_string suffix)
72737276
)
72747277

7278+
(* FIXME: we should adapt it *)
72757279
let package_flag_of_package_specs (package_specs : t)
7276-
(dirname : string ) : string =
7280+
~(dirname : string ) : string =
72777281
Spec_set.fold (fun format acc ->
72787282
Ext_string.inter2 acc (package_flag format dirname )
7279-
) package_specs Ext_string.empty
7283+
) package_specs.modules Ext_string.empty
72807284

72817285
let default_package_specs suffix =
72827286
Spec_set.singleton
@@ -7289,7 +7293,7 @@ let default_package_specs suffix =
72897293

72907294
*)
72917295
let get_list_of_output_js
7292-
(package_specs : Spec_set.t)
7296+
(package_specs : t)
72937297
(output_file_sans_extension : string)
72947298
=
72957299
Spec_set.fold
@@ -7302,17 +7306,17 @@ let get_list_of_output_js
73027306
(if spec.in_source then Bsb_config.rev_lib_bs_prefix basename
73037307
else Bsb_config.lib_bs_prefix_of_format spec.format // basename)
73047308
:: acc
7305-
) package_specs []
7309+
) package_specs.modules []
73067310

73077311

73087312
let list_dirs_by
7309-
(package_specs : Spec_set.t)
7313+
(package_specs : t)
73107314
(f : string -> unit)
73117315
=
73127316
Spec_set.iter (fun (spec : spec) ->
73137317
if not spec.in_source then
73147318
f (Bsb_config.top_prefix_of_format spec.format)
7315-
) package_specs
7319+
) package_specs.modules
73167320

73177321
type json_map = Ext_json_types.t Map_string.t
73187322

@@ -7331,10 +7335,13 @@ let extract_bs_suffix_exn (map : json_map) : Ext_js_suffix.t =
73317335

73327336
let from_map map =
73337337
let suffix = extract_bs_suffix_exn map in
7334-
match map.?(Bsb_build_schemas.package_specs) with
7338+
let modules = match map.?(Bsb_build_schemas.package_specs) with
73357339
| Some x ->
73367340
from_json suffix x
7337-
| None -> default_package_specs suffix
7341+
| None -> default_package_specs suffix in
7342+
{
7343+
modules
7344+
}
73387345

73397346

73407347
end
@@ -12920,7 +12927,8 @@ let make_custom_rules
1292012927
if read_cmi <> `is_cmi then begin
1292112928
Ext_buffer.add_string buf " -bs-package-name ";
1292212929
Ext_buffer.add_string buf package_name;
12923-
Ext_buffer.add_string buf (Bsb_package_specs.package_flag_of_package_specs package_specs "$in_d")
12930+
Ext_buffer.add_string buf
12931+
(Bsb_package_specs.package_flag_of_package_specs package_specs ~dirname:"$in_d")
1292412932
end;
1292512933
begin match bs_dependencies, bs_dev_dependencies with
1292612934
| [], [] -> ()

0 commit comments

Comments
 (0)