Skip to content

Commit f642c90

Browse files
committed
Add jsx config "exclude-dependencies"
Example: ``` "jsx": { "version": 4, "exclude-dependencies": ["rescript-react-navigation"] } ```
1 parent eddd2e2 commit f642c90

File tree

5 files changed

+76
-122
lines changed

5 files changed

+76
-122
lines changed

docs/docson/build-schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@
345345
"type": "string",
346346
"enum": ["classic", "automatic"],
347347
"description": "JSX transformation mode"
348+
},
349+
"exclude-dependencies": {
350+
"$ref": "#/definitions/dependencies",
351+
"description": "Don't propagate the jsx configuration to these dependencies."
348352
}
349353
}
350354
},

jscomp/bsb/bsb_build_schemas.ml

+1-52
Original file line numberDiff line numberDiff line change
@@ -24,110 +24,59 @@
2424

2525
(* let files = "files" *)
2626
let version = "version"
27-
2827
let name = "name"
2928

3029
(* let ocaml_config = "ocaml-config" *)
3130
let bsdep = "bsdep"
32-
3331
let ppx_flags = "ppx-flags"
34-
3532
let pp_flags = "pp-flags"
36-
3733
let bsc = "bsc"
38-
3934
let bs_external_includes = "bs-external-includes"
40-
4135
let bs_lib_dir = "bs-lib-dir"
42-
4336
let bs_dependencies = "bs-dependencies"
44-
4537
let pinned_dependencies = "pinned-dependencies"
46-
4738
let bs_dev_dependencies = "bs-dev-dependencies"
48-
4939
let sources = "sources"
50-
5140
let dir = "dir"
52-
5341
let files = "files"
54-
5542
let subdirs = "subdirs"
56-
5743
let bsc_flags = "bsc-flags"
58-
5944
let excludes = "excludes"
60-
6145
let slow_re = "slow-re"
62-
6346
let resources = "resources"
64-
6547
let public = "public"
66-
6748
let js_post_build = "js-post-build"
68-
6949
let cmd = "cmd"
70-
7150
let ninja = "ninja"
72-
7351
let package_specs = "package-specs"
74-
7552
let generate_merlin = "generate-merlin"
76-
7753
let type_ = "type"
78-
7954
let dev = "dev"
80-
8155
let export_all = "all"
82-
8356
let export_none = "none"
84-
8557
let use_stdlib = "use-stdlib"
86-
8758
let external_stdlib = "external-stdlib"
88-
8959
let reason = "reason"
90-
9160
let react_jsx = "react-jsx"
92-
9361
let jsx = "jsx"
94-
9562
let jsx_version = "version"
96-
9763
let jsx_module = "module"
98-
9964
let jsx_mode = "mode"
100-
65+
let jsx_exclude_dependencies = "exclude-dependencies"
10166
let entries = "entries"
102-
10367
let backend = "backend"
104-
10568
let main_module = "main-module"
106-
10769
let cut_generators = "cut-generators"
108-
10970
let generators = "generators"
110-
11171
let command = "command"
112-
11372
let edge = "edge"
114-
11573
let namespace = "namespace"
116-
11774
let in_source = "in-source"
118-
11975
let warnings = "warnings"
120-
12176
let number = "number"
122-
12377
let error = "error"
124-
12578
let suffix = "suffix"
126-
12779
let gentypeconfig = "gentypeconfig"
128-
12980
let language = "language"
130-
13181
let path = "path"
132-
13382
let ignored_dirs = "ignored-dirs"

jscomp/bsb/bsb_config_parse.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,10 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string)
334334
reason_react_jsx;
335335
jsx =
336336
(match package_kind with
337-
| Toplevel -> Bsb_jsx.from_map map
338-
| Pinned_dependency x | Dependency x -> x.jsx);
337+
| (Pinned_dependency x | Dependency x)
338+
when not (List.mem package_name x.jsx.exclude_dependencies) ->
339+
x.jsx
340+
| _ -> Bsb_jsx.from_map map);
339341
generators = extract_generators map;
340342
cut_generators;
341343
}

jscomp/bsb/bsb_jsx.ml

+31-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
type version = Jsx_v3 | Jsx_v4
22
type module_ = React
33
type mode = Classic | Automatic
4+
type dependencies = string list
45

56
type t = {
67
version : version option;
78
module_ : module_ option;
89
mode : mode option;
10+
exclude_dependencies : dependencies;
911
}
1012

1113
let encode_no_nl jsx =
@@ -23,10 +25,17 @@ let encode_no_nl jsx =
2325
let ( .?() ) = Map_string.find_opt
2426
let ( |? ) m (key, cb) = m |> Ext_json.test key cb
2527

28+
let get_list_string_acc (s : Ext_json_types.t array) acc =
29+
Ext_array.to_list_map_acc s acc (fun x ->
30+
match x with Str x -> Some x.str | _ -> None)
31+
32+
let get_list_string s = get_list_string_acc s []
33+
2634
let from_map map =
2735
let version : version option ref = ref None in
2836
let module_ : module_ option ref = ref None in
2937
let mode : mode option ref = ref None in
38+
let exclude_dependencies : dependencies ref = ref [] in
3039
map
3140
|? ( Bsb_build_schemas.jsx,
3241
`Obj
@@ -36,11 +45,11 @@ let from_map map =
3645
match flo with
3746
| "3" -> version := Some Jsx_v3
3847
| "4" -> version := Some Jsx_v4
39-
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-version %s" flo
48+
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx version %s" flo
4049
)
4150
| Some x ->
4251
Bsb_exception.config_error x
43-
"Unexpected input (expect a version number) for jsx-version"
52+
"Unexpected input (expect a version number) for jsx version"
4453
| None -> ()) )
4554
|? ( Bsb_build_schemas.jsx,
4655
`Obj
@@ -49,10 +58,10 @@ let from_map map =
4958
| Some (Str { loc; str }) -> (
5059
match str with
5160
| "react" -> module_ := Some React
52-
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-module %s" str)
61+
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx module %s" str)
5362
| Some x ->
5463
Bsb_exception.config_error x
55-
"Unexpected input (jsx module name) for jsx-mode"
64+
"Unexpected input (jsx module name) for jsx module"
5665
| None -> ()) )
5766
|? ( Bsb_build_schemas.jsx,
5867
`Obj
@@ -62,10 +71,25 @@ let from_map map =
6271
match str with
6372
| "classic" -> mode := Some Classic
6473
| "automatic" -> mode := Some Automatic
65-
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-mode %s" str)
74+
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx mode %s" str)
75+
| Some x ->
76+
Bsb_exception.config_error x
77+
"Unexpected input (expect classic or automatic) for jsx mode"
78+
| None -> ()) )
79+
|? ( Bsb_build_schemas.jsx,
80+
`Obj
81+
(fun m ->
82+
match m.?(Bsb_build_schemas.jsx_exclude_dependencies) with
83+
| Some (Arr { content }) ->
84+
exclude_dependencies := get_list_string content
6685
| Some x ->
6786
Bsb_exception.config_error x
68-
"Unexpected input (expect classic or automatic) for jsx-mode"
87+
"Unexpected input for jsx exclude_dependencies"
6988
| None -> ()) )
7089
|> ignore;
71-
{ version = !version; module_ = !module_; mode = !mode }
90+
{
91+
version = !version;
92+
module_ = !module_;
93+
mode = !mode;
94+
exclude_dependencies = !exclude_dependencies;
95+
}

0 commit comments

Comments
 (0)