Skip to content

Commit 56c9feb

Browse files
committed
(!! NF re config) Moving top-level "suffix" config down into "package-specs"
1 parent 9909eaa commit 56c9feb

File tree

5 files changed

+50
-7
lines changed

5 files changed

+50
-7
lines changed

jscomp/bsb/bsb_build_schemas.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ let generators = "generators"
7575
let command = "command"
7676
let edge = "edge"
7777
let namespace = "namespace"
78+
let _module = "module"
7879
let in_source = "in-source"
80+
let suffix = "suffix"
7981
let warnings = "warnings"
8082
let number = "number"
8183
let error = "error"
82-
let suffix = "suffix"
8384
let gentypeconfig = "gentypeconfig"
8485
let path = "path"
8586
let ignored_dirs = "ignored-dirs"

jscomp/bsb/bsb_config_types.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ type t =
7979
entries : entries_t list ;
8080
generators : command Map_string.t ;
8181
cut_generators : bool; (* note when used as a dev mode, we will always ignore it *)
82-
bs_suffix : bool ; (* true means [.bs.js] we should pass [-bs-suffix] flag *)
8382
gentype_config : gentype_config option;
8483
number_of_dev_groups : int
8584
}

jscomp/bsb/bsb_package_specs.ml

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ let (//) = Ext_path.combine
3131
type 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

3640
module 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+
6996
let 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 =
85112
and 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

141179
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 }
143182

144183

145184
(**

jscomp/ext/literals.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ let suffix_reiast = ".reiast"
100100
let suffix_mliast_simple = ".mliast_simple"
101101
let suffix_d = ".d"
102102
let suffix_js = ".js"
103+
let suffix_mjs = ".mjs"
103104
let suffix_bs_js = ".bs.js"
105+
let suffix_bs_mjs = ".bs.mjs"
104106
(* let suffix_re_js = ".re.js" *)
105107
let suffix_gen_js = ".gen.js"
106108
let suffix_gen_tsx = ".gen.tsx"

jscomp/ext/literals.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ val suffix_rei : string
9999

100100
val suffix_d : string
101101
val suffix_js : string
102+
val suffix_mjs : string
102103
val suffix_bs_js : string
104+
val suffix_bs_mjs : string
103105
(* val suffix_re_js : string *)
104106
val suffix_gen_js : string
105107
val suffix_gen_tsx: string

0 commit comments

Comments
 (0)