@@ -131,17 +131,15 @@ let extract_generators (map : json_map) =
131
131
! generators
132
132
133
133
let extract_package_specs (map : json_map ) ~suffix =
134
- let bad_module_format_message_exn ~loc format =
135
- Bsb_exception. errorf ~loc
136
- " package-specs: `%s` isn't a valid output module format. It has to be one \
137
- of: %s, %s or %s"
138
- format Literals. commonjs Literals. es6 Literals. es6_global
139
- in
140
134
let supported_format (x : string ) loc : Ext_module_system.t =
141
135
if x = Literals. commonjs then NodeJS
142
136
else if x = Literals. es6 then Es6
143
137
else if x = Literals. es6_global then Es6_global
144
- else bad_module_format_message_exn ~loc x
138
+ else
139
+ Bsb_exception. errorf ~loc
140
+ " package-specs: `%s` isn't a valid output module format. It has to be one \
141
+ of: %s, %s or %s"
142
+ x Literals. commonjs Literals. es6 Literals. es6_global
145
143
in
146
144
let from_json_single suffix (x : Ext_json_types.t ) : Bsb_manifest_types.package_spec =
147
145
match x with
@@ -182,7 +180,7 @@ let extract_package_specs (map : json_map) ~suffix =
182
180
Bsb_exception. errorf ~loc: (Ext_json. loc_of x)
183
181
" package-specs: we expect either a string or an object."
184
182
in
185
- let from_json suffix arr =
183
+ let from_json_array suffix arr =
186
184
let spec = ref Bsb_spec_set. empty in
187
185
let has_in_source = ref false in
188
186
Ext_array. iter arr (fun x ->
@@ -198,7 +196,7 @@ let extract_package_specs (map : json_map) ~suffix =
198
196
(* TODO: FIXME: better API without mutating *)
199
197
in
200
198
match map.?(Bsb_build_schemas. package_specs) with
201
- | Some (Arr { content } ) -> from_json suffix content
199
+ | Some (Arr { content } ) -> from_json_array suffix content
202
200
| Some _ | None -> Bsb_spec_set. singleton ({ format = NodeJS ; in_source = false ; suffix })
203
201
204
202
let extract_ppx_specs (map : json_map ) =
@@ -308,3 +306,53 @@ let extract_jsx (map : json_map) =
308
306
mode = ! mode;
309
307
v3_dependencies = ! v3_dependencies;
310
308
}
309
+
310
+ let extract_gentype (map : json_map ) ~package_specs =
311
+ let open Bsb_manifest_types.Gentype in
312
+ match map.?(Bsb_build_schemas. gentype) with
313
+ | None -> None
314
+ | Some (Obj { map } ) -> (
315
+ let { Bsb_manifest_types. format } = List. hd package_specs in
316
+ let module_ =
317
+ match (extract_string map Bsb_build_schemas. gentype_module, format) with
318
+ | Some "commonjs" , _ -> CommonJS
319
+ | Some "es6" , _ -> ES6
320
+ | None , NodeJS -> CommonJS
321
+ | None , (Es6 | Es6_global ) -> ES6
322
+ | _ -> ES6
323
+ in
324
+ let moduleResolution =
325
+ match extract_string map Bsb_build_schemas. gentype_module_resolution with
326
+ | Some "node" -> Node
327
+ | Some "node16" -> Node16
328
+ | Some "bundler" -> Bundler
329
+ | _ -> Node
330
+ in
331
+ let shims =
332
+ match map.?(Bsb_build_schemas. gentype_shims) with
333
+ | None -> Map_string. empty
334
+ | Some (Obj { map } ) ->
335
+ Map_string. map map
336
+ (fun x ->
337
+ match x with
338
+ | Str { str } -> str
339
+ | x -> Bsb_exception. manifest_error x " shims expects a record"
340
+ )
341
+ | Some manifest ->
342
+ Bsb_exception. manifest_error manifest " shims expects a record"
343
+ in
344
+ let debug =
345
+ match map.?(Bsb_build_schemas. gentype_debug) with
346
+ | Some (Obj { map } ) -> Some map
347
+ | _ -> None
348
+ in
349
+ Some {
350
+ module_;
351
+ moduleResolution;
352
+ shims;
353
+ debug;
354
+ exportInterfaces = extract_boolean map Bsb_build_schemas. gentype_export_interfaces false ;
355
+ generatedFileExtension = extract_string map Bsb_build_schemas. gentype_generated_file_extension;
356
+ }
357
+ )
358
+ | Some manifest -> Bsb_exception. manifest_error manifest " expect an object"
0 commit comments