@@ -55,6 +55,10 @@ let string_of_format (x : Ext_module_system.t) =
55
55
| Es6 -> Literals. es6
56
56
| Es6_global -> Literals. es6_global
57
57
58
+ let js_suffix_regexp = Str. regexp " [A-Za-z0-9-_.]*\\ .[cm]?js"
59
+
60
+ let validate_js_suffix suffix = Str. string_match js_suffix_regexp suffix 0
61
+
58
62
let rec from_array suffix (arr : Ext_json_types.t array ) : Spec_set.t =
59
63
let spec = ref Spec_set. empty in
60
64
let has_in_source = ref false in
@@ -83,15 +87,14 @@ and from_json_single suffix (x : Ext_json_types.t) : Bsb_spec_set.spec =
83
87
| Some _ | None -> false
84
88
in
85
89
let suffix =
86
- match map.?(" suffix" ) with
87
- | Some (Str { str = suffix ; loc } ) ->
88
- let s = Ext_js_suffix. of_string suffix in
89
- if s = Unknown_extension then
90
- Bsb_exception. errorf ~loc " expected .js, .mjs, .cjs or .bs.js, .bs.mjs, .bs.cjs"
91
- else s
90
+ match map.?(Bsb_build_schemas. suffix) with
91
+ | Some (Str { str = suffix ; _ } ) when validate_js_suffix suffix -> suffix
92
+ | Some (Str {str; loc} ) ->
93
+ Bsb_exception. errorf ~loc
94
+ (" invalid suffix \" %s\" . The suffix and may contain letters, digits, \" -\" , \" _\" and \" .\" and must end with .js, .mjs or .cjs." ) str
92
95
| Some _ ->
93
- Bsb_exception. errorf ~loc: (Ext_json. loc_of x)
94
- " expected a string field "
96
+ Bsb_exception. errorf ~loc: (Ext_json. loc_of x)
97
+ " expected a string extension like \" .js \" "
95
98
| None -> suffix
96
99
in
97
100
{ format = supported_format format loc; in_source; suffix }
@@ -128,7 +131,7 @@ let package_flag ({ format; in_source; suffix } : Bsb_spec_set.spec) dir =
128
131
(if in_source then dir
129
132
else Bsb_config. top_prefix_of_format format // dir)
130
133
Ext_string. single_colon
131
- ( Ext_js_suffix. to_string suffix) )
134
+ suffix)
132
135
133
136
(* FIXME: we should adapt it *)
134
137
let package_flag_of_package_specs (package_specs : t ) ~(dirname : string ) :
@@ -166,8 +169,7 @@ let get_list_of_output_js (package_specs : t)
166
169
Spec_set. fold
167
170
(fun (spec : Bsb_spec_set.spec ) acc ->
168
171
let basename =
169
- Ext_namespace. change_ext_ns_suffix output_file_sans_extension
170
- (Ext_js_suffix. to_string spec.suffix)
172
+ Ext_namespace. change_ext_ns_suffix output_file_sans_extension spec.suffix
171
173
in
172
174
(if spec.in_source then Bsb_config. rev_lib_bs_prefix basename
173
175
else Bsb_config. lib_bs_prefix_of_format spec.format // basename)
@@ -182,21 +184,19 @@ let list_dirs_by (package_specs : t) (f : string -> unit) =
182
184
183
185
type json_map = Ext_json_types .t Map_string .t
184
186
185
- let extract_bs_suffix_exn (map : json_map ) : Ext_js_suffix.t =
187
+ let extract_js_suffix_exn (map : json_map ) : string =
186
188
match map.?(Bsb_build_schemas. suffix) with
187
- | None -> Js
188
- | Some (Str { str; loc } ) ->
189
- let s = Ext_js_suffix. of_string str in
190
- if s = Unknown_extension then
191
- Bsb_exception. errorf ~loc
192
- " expected .js, .mjs, .cjs or .bs.js, .bs.mjs, .bs.cjs"
193
- else s
189
+ | None -> Literals. suffix_js
190
+ | Some (Str { str = suffix ; _ } ) when validate_js_suffix suffix -> suffix
191
+ | Some ((Str {str; _} ) as config ) ->
192
+ Bsb_exception. config_error config
193
+ (" invalid suffix \" " ^ str ^ " \" . The suffix and may contain letters, digits, \" -\" , \" _\" and \" .\" and must end with .js, .mjs or .cjs." )
194
194
| Some config ->
195
- Bsb_exception. config_error config
196
- " expected a string extension like \" .js\" "
195
+ Bsb_exception. config_error config
196
+ " expected a string extension like \" .js\" "
197
197
198
198
let from_map ~(cwd : string ) map =
199
- let suffix = extract_bs_suffix_exn map in
199
+ let suffix = extract_js_suffix_exn map in
200
200
let modules =
201
201
match map.?(Bsb_build_schemas. package_specs) with
202
202
| Some x -> from_json suffix x
0 commit comments