Skip to content

Commit e790729

Browse files
committed
change bulid schema for bsconfig.json
1 parent 07ee1e7 commit e790729

17 files changed

+204
-121
lines changed

docs/docson/build-schema.json

Lines changed: 14 additions & 7 deletions
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

Lines changed: 5 additions & 3 deletions
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

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,42 +130,59 @@ let extract_reason_react_jsx (map : json_map) =
130130
|> ignore;
131131
!default
132132

133-
let extract_react_jsx (map : json_map) =
134-
let default : Bsb_config_types.react_jsx option ref = ref None in
133+
let extract_jsx_version (map : json_map) =
134+
let default : Bsb_config_types.jsx_version option ref = ref None in
135135
map
136-
|? ( Bsb_build_schemas.react,
136+
|? ( Bsb_build_schemas.jsx,
137137
`Obj
138138
(fun m ->
139139
match m.?(Bsb_build_schemas.jsx_version) with
140140
| Some (Flo { loc; flo }) -> (
141141
match flo with
142142
| "3" -> default := Some Jsx_v3
143143
| "4" -> default := Some Jsx_v4
144-
| _ -> Bsb_exception.errorf ~loc "Unsupported react-jsx %s" flo)
144+
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-version %s" flo
145+
)
146+
| Some x ->
147+
Bsb_exception.config_error x
148+
"Unexpected input (expect a version number) for jsx-version"
149+
| None -> ()) )
150+
|> ignore;
151+
!default
152+
153+
let extract_jsx_module (map : json_map) =
154+
let default : Bsb_config_types.jsx_module option ref = ref None in
155+
map
156+
|? ( Bsb_build_schemas.jsx,
157+
`Obj
158+
(fun m ->
159+
match m.?(Bsb_build_schemas.jsx_module) with
160+
| Some (Str { loc; str }) -> (
161+
match str with
162+
| "react" -> default := Some React
163+
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-module %s" str)
145164
| Some x ->
146165
Bsb_exception.config_error x
147-
"Unexpected input (expect a version number) for jsx"
166+
"Unexpected input (jsx module name) for jsx-mode"
148167
| None -> ()) )
149168
|> ignore;
150169
!default
151170

152-
let extract_react_runtime (map : json_map) =
153-
let default : Bsb_config_types.react_runtime option ref = ref None in
171+
let extract_jsx_mode (map : json_map) =
172+
let default : Bsb_config_types.jsx_mode option ref = ref None in
154173
map
155-
|? ( Bsb_build_schemas.react,
174+
|? ( Bsb_build_schemas.jsx,
156175
`Obj
157176
(fun m ->
158-
match m.?(Bsb_build_schemas.react_runtime) with
177+
match m.?(Bsb_build_schemas.jsx_mode) with
159178
| Some (Str { loc; str }) -> (
160179
match str with
161180
| "classic" -> default := Some Classic
162181
| "automatic" -> default := Some Automatic
163-
| _ ->
164-
Bsb_exception.errorf ~loc "Unsupported react-runtime %s" str)
182+
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-mode %s" str)
165183
| Some x ->
166184
Bsb_exception.config_error x
167-
"Unexpected input (expect classic or automatic) for \
168-
react-runtime"
185+
"Unexpected input (expect classic or automatic) for jsx-mode"
169186
| None -> ()) )
170187
|> ignore;
171188
!default
@@ -317,8 +334,9 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string)
317334
.path)
318335
in
319336
let reason_react_jsx = extract_reason_react_jsx map in
320-
let react_jsx = extract_react_jsx map in
321-
let react_runtime = extract_react_runtime map in
337+
let jsx_version = extract_jsx_version map in
338+
let jsx_module = extract_jsx_module map in
339+
let jsx_mode = extract_jsx_mode map in
322340
let bs_dependencies =
323341
extract_dependencies map per_proj_dir Bsb_build_schemas.bs_dependencies
324342
in
@@ -375,8 +393,9 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string)
375393
generate_merlin =
376394
extract_boolean map Bsb_build_schemas.generate_merlin false;
377395
reason_react_jsx;
378-
react_jsx;
379-
react_runtime;
396+
jsx_version;
397+
jsx_module;
398+
jsx_mode;
380399
generators = extract_generators map;
381400
cut_generators;
382401
}

jscomp/bsb/bsb_config_types.ml

Lines changed: 6 additions & 4 deletions
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 = bool
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_ninja_gen.ml

Lines changed: 5 additions & 4 deletions
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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config)
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)
@@ -162,17 +163,18 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config)
162163
| None -> ()
163164
| Some flag ->
164165
Ext_buffer.add_char_string buf ' ' (Bsb_build_util.pp_flag flag));
165-
(match (has_reason_react_jsx, reason_react_jsx) with
166-
| false, _ | _, None -> ()
167-
| _, Some Jsx_v3 -> Ext_buffer.add_string buf " -bs-jsx 3");
168-
(match react_jsx with
166+
(match (has_reason_react_jsx, reason_react_jsx, jsx_version) with
167+
| _, _, Some Jsx_v3 -> Ext_buffer.add_string buf " -bs-jsx 3"
168+
| _, _, Some Jsx_v4 -> Ext_buffer.add_string buf " -bs-jsx 4"
169+
| _, Some Jsx_v3, None -> Ext_buffer.add_string buf " -bs-jsx 3"
170+
| _ -> ());
171+
(match jsx_module with
169172
| None -> ()
170-
| Some Jsx_v3 -> Ext_buffer.add_string buf " -bs-jsx 3"
171-
| Some Jsx_v4 -> Ext_buffer.add_string buf " -bs-jsx 4");
172-
(match react_runtime with
173+
| Some React -> Ext_buffer.add_string buf " -bs-jsx-module react");
174+
(match jsx_mode with
173175
| None -> ()
174-
| Some Classic -> Ext_buffer.add_string buf " -bs-react-runtime classic"
175-
| Some Automatic -> Ext_buffer.add_string buf " -bs-react-runtime automatic");
176+
| Some Classic -> Ext_buffer.add_string buf " -bs-jsx-mode classic"
177+
| Some Automatic -> Ext_buffer.add_string buf " -bs-jsx-mode automatic");
176178

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

jscomp/bsb/bsb_ninja_rule.mli

Lines changed: 3 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 6 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 9 additions & 4 deletions
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)