Skip to content

Commit 2172708

Browse files
committed
Test: propagate jsx config to dependencies.
1 parent 417cb07 commit 2172708

7 files changed

+78
-34
lines changed

jscomp/bsb/bsb_clean.ml

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ let clean_bs_garbage proj_dir =
5151
Bsb_log.warn "@{<warning>Failed@} to clean due to %s" (Printexc.to_string e)
5252

5353
let clean_bs_deps proj_dir =
54-
let _, pinned_dependencies =
55-
Bsb_config_parse.package_specs_from_bsconfig ()
56-
in
54+
let _, _, pinned_dependencies = Bsb_config_parse.deps_from_bsconfig () in
5755
let queue = Bsb_build_util.walk_all_deps proj_dir ~pinned_dependencies in
5856
Queue.iter
5957
(fun (pkg_cxt : Bsb_build_util.package_context) ->

jscomp/bsb/bsb_config_parse.ml

+7-3
Original file line numberDiff line numberDiff line change
@@ -325,25 +325,29 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string)
325325
package_specs =
326326
(match package_kind with
327327
| Toplevel -> Bsb_package_specs.from_map ~cwd:per_proj_dir map
328-
| Pinned_dependency x | Dependency x -> x);
328+
| Pinned_dependency x | Dependency x -> x.package_specs);
329329
file_groups = groups;
330330
files_to_install = Queue.create ();
331331
built_in_dependency = built_in_package;
332332
generate_merlin =
333333
extract_boolean map Bsb_build_schemas.generate_merlin false;
334334
reason_react_jsx;
335-
jsx = Bsb_jsx.from_map map;
335+
jsx =
336+
(match package_kind with
337+
| Toplevel -> Bsb_jsx.from_map map
338+
| Pinned_dependency x | Dependency x -> x.jsx);
336339
generators = extract_generators map;
337340
cut_generators;
338341
}
339342
| None ->
340343
Bsb_exception.invalid_spec "no sources specified in bsconfig.json")
341344
| _ -> Bsb_exception.invalid_spec "bsconfig.json expect a json object {}"
342345

343-
let package_specs_from_bsconfig () =
346+
let deps_from_bsconfig () =
344347
let json = Ext_json_parse.parse_json_from_file Literals.bsconfig_json in
345348
match json with
346349
| Obj { map } ->
347350
( Bsb_package_specs.from_map ~cwd:Bsb_global_paths.cwd map,
351+
Bsb_jsx.from_map map,
348352
extract_pinned_dependencies map )
349353
| _ -> assert false

jscomp/bsb/bsb_config_parse.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
val package_specs_from_bsconfig : unit -> Bsb_package_specs.t * Set_string.t
25+
val deps_from_bsconfig : unit -> Bsb_package_specs.t * Bsb_jsx.t * Set_string.t
2626

2727
val interpret_json :
2828
package_kind:Bsb_package_kind.t -> per_proj_dir:string -> Bsb_config_types.t

jscomp/bsb/bsb_jsx.ml

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ type t = {
88
mode : mode option;
99
}
1010

11+
let encode_no_nl jsx =
12+
(match jsx.version with
13+
| None -> ""
14+
| Some Jsx_v3 -> "3"
15+
| Some Jsx_v4 -> "4")
16+
^ (match jsx.module_ with None -> "" | Some React -> "React")
17+
^
18+
match jsx.mode with
19+
| None -> ""
20+
| Some Classic -> "Classic"
21+
| Some Automatic -> "Automatic"
22+
1123
let ( .?() ) = Map_string.find_opt
1224
let ( |? ) m (key, cb) = m |> Ext_json.test key cb
1325

jscomp/bsb/bsb_package_kind.ml

+12-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25+
type dep_payload = { package_specs : Bsb_package_specs.t; jsx : Bsb_jsx.t }
26+
2527
type t =
2628
| Toplevel
27-
| Dependency of Bsb_package_specs.t
28-
| Pinned_dependency of Bsb_package_specs.t
29+
| Dependency of dep_payload
30+
| Pinned_dependency of dep_payload
2931
(* This package specs comes from the toplevel to
3032
override the current settings
3133
*)
@@ -34,6 +36,12 @@ let encode_no_nl (x : t) =
3436
match x with
3537
| Toplevel -> "0"
3638
| Dependency x ->
37-
"1" ^ Bsb_package_specs.package_flag_of_package_specs x ~dirname:"."
39+
"1"
40+
^ Bsb_package_specs.package_flag_of_package_specs x.package_specs
41+
~dirname:"."
42+
^ Bsb_jsx.encode_no_nl x.jsx
3843
| Pinned_dependency x ->
39-
"2" ^ Bsb_package_specs.package_flag_of_package_specs x ~dirname:"."
44+
"2"
45+
^ Bsb_package_specs.package_flag_of_package_specs x.package_specs
46+
~dirname:"."
47+
^ Bsb_jsx.encode_no_nl x.jsx

jscomp/bsb/bsb_world.ml

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525
let ( // ) = Ext_path.combine
26-
2726
let vendor_ninja = Bsb_global_paths.vendor_ninja
2827

2928
let make_world_deps cwd (config : Bsb_config_types.t option)
3029
(ninja_args : string array) =
31-
let deps, pinned_dependencies =
30+
let package_specs, jsx, pinned_dependencies =
3231
match config with
3332
| None ->
3433
(* When this running bsb does not read bsconfig.json,
3534
we will read such json file to know which [package-specs]
3635
it wants
3736
*)
38-
Bsb_config_parse.package_specs_from_bsconfig ()
39-
| Some config -> (config.package_specs, config.pinned_dependencies)
37+
Bsb_config_parse.deps_from_bsconfig ()
38+
| Some config ->
39+
(config.package_specs, config.jsx, config.pinned_dependencies)
4040
in
4141
let args =
4242
if Ext_array.is_empty ninja_args then [| vendor_ninja |]
@@ -68,8 +68,8 @@ let make_world_deps cwd (config : Bsb_config_types.t option)
6868
let _config : _ option =
6969
Bsb_ninja_regen.regenerate_ninja
7070
~package_kind:
71-
(if is_pinned then Pinned_dependency deps
72-
else Dependency deps)
71+
(if is_pinned then Pinned_dependency { package_specs; jsx }
72+
else Dependency { package_specs; jsx })
7373
~per_proj_dir:proj_dir ~forced:false
7474
in
7575
let command =

lib/4.06.1/rescript.ml

+39-17
Original file line numberDiff line numberDiff line change
@@ -5180,6 +5180,18 @@ type t = {
51805180
mode : mode option;
51815181
}
51825182

5183+
let encode_no_nl jsx =
5184+
(match jsx.version with
5185+
| None -> ""
5186+
| Some Jsx_v3 -> "3"
5187+
| Some Jsx_v4 -> "4")
5188+
^ (match jsx.module_ with None -> "" | Some React -> "React")
5189+
^
5190+
match jsx.mode with
5191+
| None -> ""
5192+
| Some Classic -> "Classic"
5193+
| Some Automatic -> "Automatic"
5194+
51835195
let ( .?() ) = Map_string.find_opt
51845196
let ( |? ) m (key, cb) = m |> Ext_json.test key cb
51855197

@@ -7920,10 +7932,12 @@ module Bsb_package_kind
79207932
* along with this program; if not, write to the Free Software
79217933
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
79227934

7935+
type dep_payload = { package_specs : Bsb_package_specs.t; jsx : Bsb_jsx.t }
7936+
79237937
type t =
79247938
| Toplevel
7925-
| Dependency of Bsb_package_specs.t
7926-
| Pinned_dependency of Bsb_package_specs.t
7939+
| Dependency of dep_payload
7940+
| Pinned_dependency of dep_payload
79277941
(* This package specs comes from the toplevel to
79287942
override the current settings
79297943
*)
@@ -7932,9 +7946,15 @@ let encode_no_nl (x : t) =
79327946
match x with
79337947
| Toplevel -> "0"
79347948
| Dependency x ->
7935-
"1" ^ Bsb_package_specs.package_flag_of_package_specs x ~dirname:"."
7949+
"1"
7950+
^ Bsb_package_specs.package_flag_of_package_specs x.package_specs
7951+
~dirname:"."
7952+
^ Bsb_jsx.encode_no_nl x.jsx
79367953
| Pinned_dependency x ->
7937-
"2" ^ Bsb_package_specs.package_flag_of_package_specs x ~dirname:"."
7954+
"2"
7955+
^ Bsb_package_specs.package_flag_of_package_specs x.package_specs
7956+
~dirname:"."
7957+
^ Bsb_jsx.encode_no_nl x.jsx
79387958

79397959
end
79407960
module Bsc_warnings
@@ -10293,7 +10313,7 @@ module Bsb_config_parse : sig
1029310313
* along with this program; if not, write to the Free Software
1029410314
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
1029510315

10296-
val package_specs_from_bsconfig : unit -> Bsb_package_specs.t * Set_string.t
10316+
val deps_from_bsconfig : unit -> Bsb_package_specs.t * Bsb_jsx.t * Set_string.t
1029710317

1029810318
val interpret_json :
1029910319
package_kind:Bsb_package_kind.t -> per_proj_dir:string -> Bsb_config_types.t
@@ -10627,26 +10647,30 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string)
1062710647
package_specs =
1062810648
(match package_kind with
1062910649
| Toplevel -> Bsb_package_specs.from_map ~cwd:per_proj_dir map
10630-
| Pinned_dependency x | Dependency x -> x);
10650+
| Pinned_dependency x | Dependency x -> x.package_specs);
1063110651
file_groups = groups;
1063210652
files_to_install = Queue.create ();
1063310653
built_in_dependency = built_in_package;
1063410654
generate_merlin =
1063510655
extract_boolean map Bsb_build_schemas.generate_merlin false;
1063610656
reason_react_jsx;
10637-
jsx = Bsb_jsx.from_map map;
10657+
jsx =
10658+
(match package_kind with
10659+
| Toplevel -> Bsb_jsx.from_map map
10660+
| Pinned_dependency x | Dependency x -> x.jsx);
1063810661
generators = extract_generators map;
1063910662
cut_generators;
1064010663
}
1064110664
| None ->
1064210665
Bsb_exception.invalid_spec "no sources specified in bsconfig.json")
1064310666
| _ -> Bsb_exception.invalid_spec "bsconfig.json expect a json object {}"
1064410667

10645-
let package_specs_from_bsconfig () =
10668+
let deps_from_bsconfig () =
1064610669
let json = Ext_json_parse.parse_json_from_file Literals.bsconfig_json in
1064710670
match json with
1064810671
| Obj { map } ->
1064910672
( Bsb_package_specs.from_map ~cwd:Bsb_global_paths.cwd map,
10673+
Bsb_jsx.from_map map,
1065010674
extract_pinned_dependencies map )
1065110675
| _ -> assert false
1065210676

@@ -10862,9 +10886,7 @@ let clean_bs_garbage proj_dir =
1086210886
Bsb_log.warn "@{<warning>Failed@} to clean due to %s" (Printexc.to_string e)
1086310887

1086410888
let clean_bs_deps proj_dir =
10865-
let _, pinned_dependencies =
10866-
Bsb_config_parse.package_specs_from_bsconfig ()
10867-
in
10889+
let _, _, pinned_dependencies = Bsb_config_parse.deps_from_bsconfig () in
1086810890
let queue = Bsb_build_util.walk_all_deps proj_dir ~pinned_dependencies in
1086910891
Queue.iter
1087010892
(fun (pkg_cxt : Bsb_build_util.package_context) ->
@@ -15085,20 +15107,20 @@ end = struct
1508515107
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
1508615108

1508715109
let ( // ) = Ext_path.combine
15088-
1508915110
let vendor_ninja = Bsb_global_paths.vendor_ninja
1509015111

1509115112
let make_world_deps cwd (config : Bsb_config_types.t option)
1509215113
(ninja_args : string array) =
15093-
let deps, pinned_dependencies =
15114+
let package_specs, jsx, pinned_dependencies =
1509415115
match config with
1509515116
| None ->
1509615117
(* When this running bsb does not read bsconfig.json,
1509715118
we will read such json file to know which [package-specs]
1509815119
it wants
1509915120
*)
15100-
Bsb_config_parse.package_specs_from_bsconfig ()
15101-
| Some config -> (config.package_specs, config.pinned_dependencies)
15121+
Bsb_config_parse.deps_from_bsconfig ()
15122+
| Some config ->
15123+
(config.package_specs, config.jsx, config.pinned_dependencies)
1510215124
in
1510315125
let args =
1510415126
if Ext_array.is_empty ninja_args then [| vendor_ninja |]
@@ -15130,8 +15152,8 @@ let make_world_deps cwd (config : Bsb_config_types.t option)
1513015152
let _config : _ option =
1513115153
Bsb_ninja_regen.regenerate_ninja
1513215154
~package_kind:
15133-
(if is_pinned then Pinned_dependency deps
15134-
else Dependency deps)
15155+
(if is_pinned then Pinned_dependency { package_specs; jsx }
15156+
else Dependency { package_specs; jsx })
1513515157
~per_proj_dir:proj_dir ~forced:false
1513615158
in
1513715159
let command =

0 commit comments

Comments
 (0)