Skip to content

Commit aa7f1ee

Browse files
committed
Allow any suffix for generated .js file
1 parent 124f1ad commit aa7f1ee

14 files changed

+29
-85
lines changed

docs/docson/build-schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"description": "es6-global generate relative `require` paths instead of relying on NodeJS' module resolution. Default: commonjs."
77
},
88
"suffix-spec": {
9-
"enum": [".js", ".mjs", ".cjs", ".bs.js", ".bs.mjs", ".bs.cjs"],
10-
"description": "suffix of generated js files, default to [.js] "
9+
"type": "string",
10+
"description": "suffix of generated js files, defaults to [.js]"
1111
},
1212
"module-format-object": {
1313
"type": "object",

jscomp/bsb/bsb_package_specs.ml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ and from_json_single suffix (x : Ext_json_types.t) : Bsb_spec_set.spec =
8484
in
8585
let suffix =
8686
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
87+
| Some (Str { str = suffix }) -> suffix
9288
| Some _ ->
9389
Bsb_exception.errorf ~loc:(Ext_json.loc_of x)
9490
"expected a string field"
@@ -128,7 +124,7 @@ let package_flag ({ format; in_source; suffix } : Bsb_spec_set.spec) dir =
128124
(if in_source then dir
129125
else Bsb_config.top_prefix_of_format format // dir)
130126
Ext_string.single_colon
131-
(Ext_js_suffix.to_string suffix))
127+
suffix)
132128

133129
(* FIXME: we should adapt it *)
134130
let package_flag_of_package_specs (package_specs : t) ~(dirname : string) :
@@ -166,8 +162,7 @@ let get_list_of_output_js (package_specs : t)
166162
Spec_set.fold
167163
(fun (spec : Bsb_spec_set.spec) acc ->
168164
let basename =
169-
Ext_namespace.change_ext_ns_suffix output_file_sans_extension
170-
(Ext_js_suffix.to_string spec.suffix)
165+
Ext_namespace.change_ext_ns_suffix output_file_sans_extension spec.suffix
171166
in
172167
(if spec.in_source then Bsb_config.rev_lib_bs_prefix basename
173168
else Bsb_config.lib_bs_prefix_of_format spec.format // basename)
@@ -182,15 +177,10 @@ let list_dirs_by (package_specs : t) (f : string -> unit) =
182177

183178
type json_map = Ext_json_types.t Map_string.t
184179

185-
let extract_bs_suffix_exn (map : json_map) : Ext_js_suffix.t =
180+
let extract_bs_suffix_exn (map : json_map) : string =
186181
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
182+
| None -> Literals.suffix_js
183+
| Some (Str { str; _ }) -> str
194184
| Some config ->
195185
Bsb_exception.config_error config
196186
"expected a string extension like \".js\""

jscomp/bsb/bsb_spec_set.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
(* TODO: sync up with {!Js_packages_info.module_system} *)
2828
type format = Ext_module_system.t = NodeJS | Es6 | Es6_global
2929

30-
type spec = { format : format; in_source : bool; suffix : Ext_js_suffix.t }
30+
type spec = { format : format; in_source : bool; suffix : string }
3131

3232
type t = spec list
3333

jscomp/bsb/bsb_spec_set.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424
type format = Ext_module_system.t
2525

26-
type spec = { format : format; in_source : bool; suffix : Ext_js_suffix.t }
26+
type spec = { format : format; in_source : bool; suffix : string }
2727

2828
type t = private spec list
2929

jscomp/core/js_name_of_module_id.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ let get_runtime_module_path
5959
module_system in
6060
let js_file =
6161
Ext_namespace.js_name_of_modulename dep_module_id.id.name
62-
Little Js in
62+
Little Literals.suffix_js in
6363
match current_info_query with
6464
| Package_not_found -> assert false
6565
| Package_script ->
@@ -183,7 +183,7 @@ let string_of_module_id
183183
| Package_script, Package_script
184184
->
185185
let js_file =
186-
Ext_namespace.js_name_of_modulename dep_module_id.id.name case Js in
186+
Ext_namespace.js_name_of_modulename dep_module_id.id.name case Literals.suffix_js in
187187
match Config_util.find_opt js_file with
188188
| Some file ->
189189
let basename = Filename.basename file in

jscomp/core/js_packages_info.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ let compatible (dep : module_system) (query : module_system) =
3838
type package_info = {
3939
module_system : module_system;
4040
path : string;
41-
suffix : Ext_js_suffix.t;
41+
suffix : string;
4242
}
4343

4444
type package_name = Pkg_empty | Pkg_runtime | Pkg_normal of string
@@ -61,8 +61,8 @@ let runtime_package_specs : t =
6161
name = Pkg_runtime;
6262
module_systems =
6363
[
64-
{ module_system = Es6; path = "lib/es6"; suffix = Js };
65-
{ module_system = NodeJS; path = "lib/js"; suffix = Js };
64+
{ module_system = Es6; path = "lib/es6"; suffix = Literals.suffix_js };
65+
{ module_system = NodeJS; path = "lib/js"; suffix = Literals.suffix_js };
6666
];
6767
}
6868

@@ -121,7 +121,7 @@ let dump_package_info (fmt : Format.formatter)
121121
Format.fprintf fmt "@[%s@ %s@ %s@]"
122122
(string_of_module_system ms)
123123
name
124-
(Ext_js_suffix.to_string suffix)
124+
suffix
125125

126126
let dump_package_name fmt (x : package_name) =
127127
match x with
@@ -140,7 +140,7 @@ let dump_packages_info (fmt : Format.formatter)
140140
type package_found_info = {
141141
rel_path : string;
142142
pkg_rel_path : string;
143-
suffix : Ext_js_suffix.t;
143+
suffix : string;
144144
}
145145

146146
type info_query =
@@ -201,18 +201,18 @@ let add_npm_package_path (packages_info : t) (s : string) : t =
201201
in
202202
let m =
203203
match Ext_string.split ~keep_empty:true s ':' with
204-
| [ path ] -> { module_system = NodeJS; path; suffix = Js }
204+
| [ path ] -> { module_system = NodeJS; path; suffix = Literals.suffix_js }
205205
| [ module_system; path ] ->
206206
{
207207
module_system = handle_module_system module_system;
208208
path;
209-
suffix = Js;
209+
suffix = Literals.suffix_js;
210210
}
211211
| [ module_system; path; suffix ] ->
212212
{
213213
module_system = handle_module_system module_system;
214214
path;
215-
suffix = Ext_js_suffix.of_string suffix;
215+
suffix;
216216
}
217217
| _ -> Bsc_args.bad_arg ("invalid npm package path: " ^ s)
218218
in

jscomp/core/js_packages_info.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ val runtime_package_path : module_system -> string -> string
3131
type package_info = {
3232
module_system : module_system;
3333
path : string;
34-
suffix : Ext_js_suffix.t;
34+
suffix : string;
3535
}
3636

3737
type t
@@ -64,7 +64,7 @@ val add_npm_package_path : t -> string -> t
6464
type package_found_info = {
6565
rel_path : string;
6666
pkg_rel_path : string;
67-
suffix : Ext_js_suffix.t;
67+
suffix : string;
6868
}
6969

7070
type info_query =

jscomp/core/lam_compile_main.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,7 @@ let lambda_as_module
301301
(lambda_output)
302302
chan in
303303
let basename =
304-
Ext_namespace.change_ext_ns_suffix
305-
(Filename.basename
306-
output_prefix)
307-
(Ext_js_suffix.to_string suffix)
304+
Ext_namespace.change_ext_ns_suffix (Filename.basename output_prefix) suffix
308305
in
309306
let target_file =
310307
(Lazy.force Ext_path.package_dir //

jscomp/ext/ext_js_file_kind.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,4 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424
type case = Upper | Little
2525

26-
type [@warning "-69"] t = { case : case; suffix : Ext_js_suffix.t }
27-
28-
let any_runtime_kind = { case = Little; suffix = Ext_js_suffix.Js }
26+
type [@warning "-69"] t = { case : case; suffix : string }

jscomp/ext/ext_js_suffix.ml

Lines changed: 0 additions & 28 deletions
This file was deleted.

jscomp/ext/ext_namespace.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let js_name_of_modulename s (case : Ext_js_file_kind.case) suffix : string =
4545
let s =
4646
match case with Little -> Ext_string.uncapitalize_ascii s | Upper -> s
4747
in
48-
change_ext_ns_suffix s (Ext_js_suffix.to_string suffix)
48+
change_ext_ns_suffix s suffix
4949

5050
(* https://docs.npmjs.com/files/package.json
5151
Some rules:

jscomp/ext/ext_namespace.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ val try_split_module_name : string -> (string * string) option
3434
val change_ext_ns_suffix : string -> string -> string
3535

3636
val js_name_of_modulename :
37-
string -> Ext_js_file_kind.case -> Ext_js_suffix.t -> string
37+
string -> Ext_js_file_kind.case -> string -> string
3838
(** [js_name_of_modulename ~little A-Ns]
3939
*)
4040

jscomp/ext/literals.ml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,6 @@ let suffix_d = ".d"
121121

122122
let suffix_js = ".js"
123123

124-
let suffix_bs_js = ".bs.js"
125-
126-
let suffix_mjs = ".mjs"
127-
128-
let suffix_bs_mjs = ".bs.mjs"
129-
130-
let suffix_cjs = ".cjs"
131-
132-
let suffix_bs_cjs = ".bs.cjs"
133-
134124
let suffix_gen_js = ".gen.js"
135125

136126
let suffix_gen_tsx = ".gen.tsx"

jscomp/ounit_tests/ounit_string_tests.ml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,11 @@ let suites =
386386
=~ "a-.js";
387387
Ext_namespace.change_ext_ns_suffix "AA-b" Literals.suffix_js
388388
=~ "AA.js";
389-
Ext_namespace.js_name_of_modulename
390-
"AA-b" Little Js
389+
Ext_namespace.js_name_of_modulename "AA-b" Little Literals.suffix_js
391390
=~ "aA.js";
392-
Ext_namespace.js_name_of_modulename
393-
"AA-b" Upper Js
391+
Ext_namespace.js_name_of_modulename "AA-b" Upper Literals.suffix_js
394392
=~ "AA.js";
395-
Ext_namespace.js_name_of_modulename
396-
"AA-b" Upper Bs_js
393+
Ext_namespace.js_name_of_modulename "AA-b" Upper ".bs.js"
397394
=~ "AA.bs.js";
398395
end;
399396
__LOC__ >:: begin fun _ ->

0 commit comments

Comments
 (0)