@@ -31,7 +31,11 @@ let (//) = Ext_path.combine
3131type format =
3232 | NodeJS | Es6 | Es6_global
3333
34- type spec = { format : format ; in_source : bool }
34+ type spec = {
35+ format : format ;
36+ in_source : bool ;
37+ suffix : string
38+ }
3539
3640module Spec_set = Set. Make ( struct type t = spec
3741 let compare = Pervasives. compare
@@ -66,6 +70,29 @@ let prefix_of_format (x : format) =
6670 | Es6_global -> Bsb_config. lib_es6_global )
6771
6872
73+ let bad_suffix_message_warn suffix =
74+ Bsb_log. warn
75+ " @{<warning>UNSUPPORTED@}: package-specs: extension `%s` is unsupported@;\
76+ ; consider one of: %s, %s, %s, or %s@." suffix Literals. suffix_js
77+ Literals. suffix_mjs Literals. suffix_bs_js Literals. suffix_bs_mjs
78+
79+
80+ let supported_suffix (x : string ) =
81+ if not (List. mem x Literals. [ suffix_js; suffix_bs_js; suffix_bs_mjs ]) then
82+ bad_suffix_message_warn x;
83+ x
84+
85+
86+ let default_suffix format in_source =
87+ (* In the absence of direction to the contrary, the suffix depends on
88+ * [format] and [in_source]. *)
89+ match (format, in_source) with
90+ | NodeJS , false -> Literals. suffix_js
91+ | NodeJS , true -> Literals. suffix_bs_js
92+ | _ , false -> Literals. suffix_mjs
93+ | _ , true -> Literals. suffix_bs_mjs
94+
95+
6996let rec from_array (arr : Ext_json_types.t array ) : Spec_set.t =
7097 let spec = ref Spec_set. empty in
7198 let has_in_source = ref false in
@@ -85,16 +112,27 @@ let rec from_array (arr : Ext_json_types.t array) : Spec_set.t =
85112and from_json_single (x : Ext_json_types.t ) : spec =
86113 match x with
87114 | Str { str = format ; loc } ->
88- { format = supported_format format loc; in_source = false }
115+ let format = supported_format format loc in
116+ { format; in_source = false ; suffix = default_suffix format false }
89117 | Obj { map; loc } -> (
90- match Map_string. find_exn map " module " with
118+ match Map_string. find_exn map Bsb_build_schemas. _module with
91119 | Str { str = format } ->
120+ let format = supported_format format loc in
92121 let in_source =
93122 match Map_string. find_opt map Bsb_build_schemas. in_source with
94123 | Some (True _ ) -> true
95124 | Some _ | None -> false
96125 in
97- { format = supported_format format loc; in_source }
126+ let suffix =
127+ match Map_string. find_opt map Bsb_build_schemas. suffix with
128+ | Some (Str { str = suffix ; loc } ) -> supported_suffix suffix
129+ | Some _ ->
130+ Bsb_exception. errorf ~loc
131+ " package-specs: the `suffix` field of the configuration \
132+ object must be absent, or a string."
133+ | None -> default_suffix format in_source
134+ in
135+ { format; in_source; suffix }
98136 | Arr _ ->
99137 Bsb_exception. errorf ~loc
100138 " package-specs: when the configuration is an object, `module` \
@@ -139,7 +177,8 @@ let package_flag_of_package_specs (package_specs : t) (dirname : string) :
139177
140178
141179let default_package_specs =
142- Spec_set. singleton { format = NodeJS ; in_source = false }
180+ Spec_set. singleton
181+ { format = NodeJS ; in_source = false ; suffix = default_suffix NodeJS false }
143182
144183
145184(* *
0 commit comments