Skip to content

Commit 81029b3

Browse files
committed
change bulid schema for bsconfig.json
1 parent dec3057 commit 81029b3

18 files changed

+234
-133
lines changed

docs/docson/build-schema.json

+14-7
Original file line numberDiff line numberDiff line change
@@ -350,16 +350,23 @@
350350
}
351351
}
352352
},
353-
"react-specs": {
353+
"jsx-specs": {
354354
"type": "object",
355355
"properties": {
356-
"jsx": {
357-
"$ref": "#/definitions/jsx-version",
358-
"description": "Whether to apply the [RescriptReact](https://github.com/rescript-lang/rescript-react)-specific JSX PPX transformation."
356+
"version": {
357+
"type": "number",
358+
"enum": [3, 4],
359+
"description": "Whether to apply the specific version of JSX PPX transformation"
359360
},
360-
"runtime": {
361-
"$ref": "#/definitions/react-runtime",
362-
"description": "Whether to apply the [RescriptReact](https://github.com/rescript-lang/rescript-react)-specific JSX PPX transformation."
361+
"module": {
362+
"type": "string",
363+
"enum": ["react"],
364+
"description": "JSX module, currently only support the React."
365+
},
366+
"mode": {
367+
"type": "string",
368+
"enum": ["classic", "automatic"],
369+
"description": "JSX transformation mode"
363370
}
364371
}
365372
},

jscomp/bsb/bsb_build_schemas.ml

+5-3
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@ let reason = "reason"
9090

9191
let react_jsx = "react-jsx"
9292

93-
let react = "react"
93+
let jsx = "jsx"
9494

95-
let jsx_version = "jsx"
95+
let jsx_version = "version"
9696

97-
let react_runtime = "runtime"
97+
let jsx_module = "module"
98+
99+
let jsx_mode = "mode"
98100

99101
let entries = "entries"
100102

jscomp/bsb/bsb_config_parse.ml

+36-17
Original file line numberDiff line numberDiff line change
@@ -145,42 +145,59 @@ let extract_reason_react_jsx (map : json_map) =
145145
|> ignore;
146146
!default
147147

148-
let extract_react_jsx (map : json_map) =
149-
let default : Bsb_config_types.react_jsx option ref = ref None in
148+
let extract_jsx_version (map : json_map) =
149+
let default : Bsb_config_types.jsx_version option ref = ref None in
150150
map
151-
|? ( Bsb_build_schemas.react,
151+
|? ( Bsb_build_schemas.jsx,
152152
`Obj
153153
(fun m ->
154154
match m.?(Bsb_build_schemas.jsx_version) with
155155
| Some (Flo { loc; flo }) -> (
156156
match flo with
157157
| "3" -> default := Some Jsx_v3
158158
| "4" -> default := Some Jsx_v4
159-
| _ -> Bsb_exception.errorf ~loc "Unsupported react-jsx %s" flo)
159+
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-version %s" flo
160+
)
161+
| Some x ->
162+
Bsb_exception.config_error x
163+
"Unexpected input (expect a version number) for jsx-version"
164+
| None -> ()) )
165+
|> ignore;
166+
!default
167+
168+
let extract_jsx_module (map : json_map) =
169+
let default : Bsb_config_types.jsx_module option ref = ref None in
170+
map
171+
|? ( Bsb_build_schemas.jsx,
172+
`Obj
173+
(fun m ->
174+
match m.?(Bsb_build_schemas.jsx_module) with
175+
| Some (Str { loc; str }) -> (
176+
match str with
177+
| "react" -> default := Some React
178+
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-module %s" str)
160179
| Some x ->
161180
Bsb_exception.config_error x
162-
"Unexpected input (expect a version number) for jsx"
181+
"Unexpected input (jsx module name) for jsx-mode"
163182
| None -> ()) )
164183
|> ignore;
165184
!default
166185

167-
let extract_react_runtime (map : json_map) =
168-
let default : Bsb_config_types.react_runtime option ref = ref None in
186+
let extract_jsx_mode (map : json_map) =
187+
let default : Bsb_config_types.jsx_mode option ref = ref None in
169188
map
170-
|? ( Bsb_build_schemas.react,
189+
|? ( Bsb_build_schemas.jsx,
171190
`Obj
172191
(fun m ->
173-
match m.?(Bsb_build_schemas.react_runtime) with
192+
match m.?(Bsb_build_schemas.jsx_mode) with
174193
| Some (Str { loc; str }) -> (
175194
match str with
176195
| "classic" -> default := Some Classic
177196
| "automatic" -> default := Some Automatic
178-
| _ ->
179-
Bsb_exception.errorf ~loc "Unsupported react-runtime %s" str)
197+
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-mode %s" str)
180198
| Some x ->
181199
Bsb_exception.config_error x
182-
"Unexpected input (expect classic or automatic) for \
183-
react-runtime"
200+
"Unexpected input (expect classic or automatic) for jsx-mode"
184201
| None -> ()) )
185202
|> ignore;
186203
!default
@@ -332,8 +349,9 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string)
332349
.path)
333350
in
334351
let reason_react_jsx = extract_reason_react_jsx map in
335-
let react_jsx = extract_react_jsx map in
336-
let react_runtime = extract_react_runtime map in
352+
let jsx_version = extract_jsx_version map in
353+
let jsx_module = extract_jsx_module map in
354+
let jsx_mode = extract_jsx_mode map in
337355
let bs_dependencies =
338356
extract_dependencies map per_proj_dir Bsb_build_schemas.bs_dependencies
339357
in
@@ -390,8 +408,9 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string)
390408
generate_merlin =
391409
extract_boolean map Bsb_build_schemas.generate_merlin false;
392410
reason_react_jsx;
393-
react_jsx;
394-
react_runtime;
411+
jsx_version;
412+
jsx_module;
413+
jsx_mode;
395414
generators = extract_generators map;
396415
cut_generators;
397416
}

jscomp/bsb/bsb_config_types.ml

+6-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ type dependencies = dependency list
3131
type reason_react_jsx = Jsx_v3
3232
(* string option *)
3333

34-
type react_jsx = Jsx_v3 | Jsx_v4
35-
type react_runtime = Classic | Automatic
34+
type jsx_version = Jsx_v3 | Jsx_v4
35+
type jsx_module = React
36+
type jsx_mode = Classic | Automatic
3637
type gentype_config = { path : string (* resolved *) }
3738
type command = string
3839
type ppx = { name : string; args : string list }
@@ -61,8 +62,9 @@ type t = {
6162
files_to_install : Bsb_db.module_info Queue.t;
6263
generate_merlin : bool;
6364
reason_react_jsx : reason_react_jsx option;
64-
react_jsx : react_jsx option;
65-
react_runtime : react_runtime option;
65+
jsx_version : jsx_version option;
66+
jsx_module : jsx_module option;
67+
jsx_mode : jsx_mode option;
6668
(* whether apply PPX transform or not*)
6769
generators : command Map_string.t;
6870
cut_generators : bool;

jscomp/bsb/bsb_merlin_gen.ml

+15-6
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ let merlin_file_gen ~(per_proj_dir : string)
119119
built_in_dependency;
120120
external_includes;
121121
reason_react_jsx;
122-
react_jsx;
123-
react_runtime;
122+
jsx_version;
123+
jsx_module;
124+
jsx_mode;
124125
namespace;
125126
package_name = _;
126127
warning;
@@ -142,7 +143,7 @@ let merlin_file_gen ~(per_proj_dir : string)
142143
Buffer.add_string buffer (merlin_flg_pp ^ x));
143144
Buffer.add_string buffer
144145
(merlin_flg_ppx
145-
^ (match (reason_react_jsx, react_jsx) with
146+
^ (match (reason_react_jsx, jsx_version) with
146147
| None, None ->
147148
let fmt : _ format =
148149
if Ext_sys.is_windows_or_cygwin then "\"%s -as-ppx \""
@@ -163,13 +164,21 @@ let merlin_file_gen ~(per_proj_dir : string)
163164
in
164165
Printf.sprintf fmt Bsb_global_paths.vendor_bsc
165166
(match opt with Jsx_v3 -> 3 | Jsx_v4 -> 4))
167+
^ (match jsx_module with
168+
| None -> ""
169+
| Some opt ->
170+
let fmt : _ format =
171+
if Ext_sys.is_windows_or_cygwin then "\"-bs-jsx-module %s\""
172+
else "'-bs-jsx-module %s'"
173+
in
174+
Printf.sprintf fmt (match opt with React -> "react"))
166175
^
167-
match react_runtime with
176+
match jsx_mode with
168177
| None -> ""
169178
| Some opt ->
170179
let fmt : _ format =
171-
if Ext_sys.is_windows_or_cygwin then "\"-bs-react-runtime %s\""
172-
else "'-bs-react-runtime %s'"
180+
if Ext_sys.is_windows_or_cygwin then "\"-bs-jsx-mode %s\""
181+
else "'-bs-jsx-mode %s'"
173182
in
174183
Printf.sprintf fmt
175184
(match opt with Classic -> "classic" | Automatic -> "automatic"));

jscomp/bsb/bsb_ninja_gen.ml

+5-4
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ let output_ninja_and_namespace_map ~per_proj_dir ~package_kind
160160
files_to_install;
161161
built_in_dependency;
162162
reason_react_jsx;
163-
react_jsx;
164-
react_runtime;
163+
jsx_version;
164+
jsx_module;
165+
jsx_mode;
165166
generators;
166167
namespace;
167168
warning;
@@ -208,8 +209,8 @@ let output_ninja_and_namespace_map ~per_proj_dir ~package_kind
208209
let rules : Bsb_ninja_rule.builtin =
209210
Bsb_ninja_rule.make_custom_rules ~gentype_config
210211
~has_postbuild:js_post_build_cmd ~pp_file ~has_builtin:built_in_dependency
211-
~reason_react_jsx ~react_jsx ~react_runtime ~package_specs ~namespace
212-
~digest ~package_name ~warnings ~ppx_files ~bsc_flags
212+
~reason_react_jsx ~jsx_version ~jsx_module ~jsx_mode ~package_specs
213+
~namespace ~digest ~package_name ~warnings ~ppx_files ~bsc_flags
213214
~dpkg_incls (* dev dependencies *)
214215
~lib_incls (* its own libs *)
215216
~dev_incls (* its own devs *)

jscomp/bsb/bsb_ninja_rule.ml

+13-11
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config option)
9191
~(has_postbuild : string option) ~(pp_file : string option)
9292
~(has_builtin : bool)
9393
~(reason_react_jsx : Bsb_config_types.reason_react_jsx option)
94-
~(react_jsx : Bsb_config_types.react_jsx option)
95-
~(react_runtime : Bsb_config_types.react_runtime option) ~(digest : string)
94+
~(jsx_version : Bsb_config_types.jsx_version option)
95+
~(jsx_module : Bsb_config_types.jsx_module option)
96+
~(jsx_mode : Bsb_config_types.jsx_mode option) ~(digest : string)
9697
~(package_specs : Bsb_package_specs.t) ~(namespace : string option)
9798
~package_name ~warnings ~(ppx_files : Bsb_config_types.ppx list) ~bsc_flags
9899
~(dpkg_incls : string) ~(lib_incls : string) ~(dev_incls : string)
@@ -163,17 +164,18 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config option)
163164
| None -> ()
164165
| Some flag ->
165166
Ext_buffer.add_char_string buf ' ' (Bsb_build_util.pp_flag flag));
166-
(match (has_reason_react_jsx, reason_react_jsx) with
167-
| false, _ | _, None -> ()
168-
| _, Some Jsx_v3 -> Ext_buffer.add_string buf " -bs-jsx 3");
169-
(match react_jsx with
167+
(match (has_reason_react_jsx, reason_react_jsx, jsx_version) with
168+
| _, _, Some Jsx_v3 -> Ext_buffer.add_string buf " -bs-jsx 3"
169+
| _, _, Some Jsx_v4 -> Ext_buffer.add_string buf " -bs-jsx 4"
170+
| _, Some Jsx_v3, None -> Ext_buffer.add_string buf " -bs-jsx 3"
171+
| _ -> ());
172+
(match jsx_module with
170173
| None -> ()
171-
| Some Jsx_v3 -> Ext_buffer.add_string buf " -bs-jsx 3"
172-
| Some Jsx_v4 -> Ext_buffer.add_string buf " -bs-jsx 4");
173-
(match react_runtime with
174+
| Some React -> Ext_buffer.add_string buf " -bs-jsx-module react");
175+
(match jsx_mode with
174176
| None -> ()
175-
| Some Classic -> Ext_buffer.add_string buf " -bs-react-runtime classic"
176-
| Some Automatic -> Ext_buffer.add_string buf " -bs-react-runtime automatic");
177+
| Some Classic -> Ext_buffer.add_string buf " -bs-jsx-mode classic"
178+
| Some Automatic -> Ext_buffer.add_string buf " -bs-jsx-mode automatic");
177179

178180
Ext_buffer.add_char_string buf ' ' bsc_flags;
179181
Ext_buffer.add_string buf " -absname -bs-ast -o $out $i";

jscomp/bsb/bsb_ninja_rule.mli

+3-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ val make_custom_rules :
7171
pp_file:string option ->
7272
has_builtin:bool ->
7373
reason_react_jsx:Bsb_config_types.reason_react_jsx option ->
74-
react_jsx:Bsb_config_types.react_jsx option ->
75-
react_runtime:Bsb_config_types.react_runtime option ->
74+
jsx_version:Bsb_config_types.jsx_version option ->
75+
jsx_module:Bsb_config_types.jsx_module option ->
76+
jsx_mode:Bsb_config_types.jsx_mode option ->
7677
digest:string ->
7778
package_specs:Bsb_package_specs.t ->
7879
namespace:string option ->

jscomp/common/js_config.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ let cmj_only = ref false
5252
let force_cmi = ref false
5353
let force_cmj = ref false
5454
let jsx_version = ref (-1)
55-
let react_runtime = ref "classic"
55+
let jsx_module = ref "react"
56+
let jsx_mode = ref "classic"
5657
let js_stdout = ref true
5758
let all_module_aliases = ref false
5859
let no_stdlib = ref false

jscomp/common/js_config.mli

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ val force_cmj : bool ref
7575

7676
val jsx_version : int ref
7777

78-
val react_runtime: string ref
78+
val jsx_module: string ref
79+
80+
val jsx_mode: string ref
7981

8082
val js_stdout : bool ref
8183

jscomp/common/js_config.pp.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ let cmj_only = ref false
5050
let force_cmi = ref false
5151
let force_cmj = ref false
5252
let jsx_version = ref (-1)
53-
let react_runtime = ref "classic"
53+
let jsx_module = ref "react"
54+
let jsx_mode = ref "classic"
5455
let js_stdout = ref true
5556
let all_module_aliases = ref false
5657
let no_stdlib = ref false

jscomp/frontend/ppx_driver.ml

+6-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ let main impl intf =
3535
( "-bs-jsx",
3636
Arg.Int (fun i -> Js_config.jsx_version := i),
3737
" Set jsx version" );
38-
( "-bs-react-runtime",
39-
Arg.String (fun i -> Js_config.react_runtime := i),
40-
" Set react runtime" );
38+
( "-bs-jsx-module",
39+
Arg.String (fun i -> Js_config.jsx_module := i),
40+
" Set jsx module" );
41+
( "-bs-jsx-mode",
42+
Arg.String (fun i -> Js_config.jsx_mode := i),
43+
" Set jsx mode" );
4144
]
4245
ignore usage;
4346
Ppx_apply.apply_lazy ~source:a.(n - 2) ~target:a.(n - 1) impl intf)

jscomp/frontend/ppx_entry.ml

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature =
3030
let ast =
3131
match !Js_config.jsx_version with
3232
| 3 -> Reactjs_jsx_ppx_v3.rewrite_signature ast
33-
| 4 -> Reactjs_jsx_ppx_v4.rewrite_signature !Js_config.react_runtime ast
33+
| 4 -> Reactjs_jsx_ppx_v4.rewrite_signature !Js_config.jsx_mode ast
3434
| _ -> ast
3535
(* react-jsx ppx relies on built-in ones like `##` *)
3636
in
@@ -47,8 +47,7 @@ let rewrite_implementation (ast : Parsetree.structure) : Parsetree.structure =
4747
let ast =
4848
match !Js_config.jsx_version with
4949
| 3 -> Reactjs_jsx_ppx_v3.rewrite_implementation ast
50-
| 4 ->
51-
Reactjs_jsx_ppx_v4.rewrite_implementation !Js_config.react_runtime ast
50+
| 4 -> Reactjs_jsx_ppx_v4.rewrite_implementation !Js_config.jsx_mode ast
5251
| _ -> ast
5352
in
5453
if !Js_config.no_builtin_ppx then ast

jscomp/main/rescript_compiler_main.ml

+9-4
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,15 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
279279
Js_config.jsx_version := int_of_string i),
280280
"*internal* Set jsx version";
281281

282-
"-bs-react-runtime", string_call (fun i ->
283-
(if i <> "classic" && i <> "automatic" then Bsc_args.bad_arg (" Not supported react-runtime : " ^ i));
284-
Js_config.react_runtime := i),
285-
"*internal* Set react runtime";
282+
"-bs-jsx-module", string_call (fun i ->
283+
(if i <> "react" then Bsc_args.bad_arg (" Not supported jsx-module : " ^ i));
284+
Js_config.jsx_mode := i),
285+
"*internal* Set jsx module";
286+
287+
"-bs-jsx-mode", string_call (fun i ->
288+
(if i <> "classic" && i <> "automatic" then Bsc_args.bad_arg (" Not supported jsx-mode : " ^ i));
289+
Js_config.jsx_mode := i),
290+
"*internal* Set jsx mode";
286291

287292
"-bs-package-output", string_call Js_packages_state.update_npm_package_path,
288293
"*internal* Set npm-output-path: [opt_module]:path, for example: 'lib/cjs', 'amdjs:lib/amdjs', 'es6:lib/es6' ";

0 commit comments

Comments
 (0)