@@ -31,7 +31,11 @@ let (//) = Ext_path.combine
31
31
type format =
32
32
| NodeJS | Es6 | Es6_global
33
33
34
- type spec = { format : format ; in_source : bool }
34
+ type spec = {
35
+ format : format ;
36
+ in_source : bool ;
37
+ suffix : string
38
+ }
35
39
36
40
module Spec_set = Set. Make ( struct type t = spec
37
41
let compare = Pervasives. compare
@@ -66,6 +70,29 @@ let prefix_of_format (x : format) =
66
70
| Es6_global -> Bsb_config. lib_es6_global )
67
71
68
72
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
+
69
96
let rec from_array (arr : Ext_json_types.t array ) : Spec_set.t =
70
97
let spec = ref Spec_set. empty in
71
98
let has_in_source = ref false in
@@ -85,16 +112,27 @@ let rec from_array (arr : Ext_json_types.t array) : Spec_set.t =
85
112
and from_json_single (x : Ext_json_types.t ) : spec =
86
113
match x with
87
114
| 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 }
89
117
| Obj { map; loc } -> (
90
- match Map_string. find_exn map " module " with
118
+ match Map_string. find_exn map Bsb_build_schemas. _module with
91
119
| Str { str = format } ->
120
+ let format = supported_format format loc in
92
121
let in_source =
93
122
match Map_string. find_opt map Bsb_build_schemas. in_source with
94
123
| Some (True _ ) -> true
95
124
| Some _ | None -> false
96
125
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 }
98
136
| Arr _ ->
99
137
Bsb_exception. errorf ~loc
100
138
" package-specs: when the configuration is an object, `module` \
@@ -139,7 +177,8 @@ let package_flag_of_package_specs (package_specs : t) (dirname : string) :
139
177
140
178
141
179
let 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 }
143
182
144
183
145
184
(* *
0 commit comments