Skip to content

Propagate jsx config to dependencies, and add config "preserve-dependencies". #5661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add jsx config "exclude-dependencies"
Example:
```
  "jsx": { "version": 4, "exclude-dependencies": ["rescript-react-navigation"] }
```
  • Loading branch information
cristianoc committed Sep 15, 2022
commit f6907a6b33509780dd9e861184fb04ae1e86a9b8
4 changes: 4 additions & 0 deletions docs/docson/build-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@
"type": "string",
"enum": ["classic", "automatic"],
"description": "JSX transformation mode"
},
"exclude-dependencies": {
"$ref": "#/definitions/dependencies",
"description": "Don't propagate the jsx configuration to these dependencies."
}
}
},
Expand Down
53 changes: 1 addition & 52 deletions jscomp/bsb/bsb_build_schemas.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,110 +24,59 @@

(* let files = "files" *)
let version = "version"

let name = "name"

(* let ocaml_config = "ocaml-config" *)
let bsdep = "bsdep"

let ppx_flags = "ppx-flags"

let pp_flags = "pp-flags"

let bsc = "bsc"

let bs_external_includes = "bs-external-includes"

let bs_lib_dir = "bs-lib-dir"

let bs_dependencies = "bs-dependencies"

let pinned_dependencies = "pinned-dependencies"

let bs_dev_dependencies = "bs-dev-dependencies"

let sources = "sources"

let dir = "dir"

let files = "files"

let subdirs = "subdirs"

let bsc_flags = "bsc-flags"

let excludes = "excludes"

let slow_re = "slow-re"

let resources = "resources"

let public = "public"

let js_post_build = "js-post-build"

let cmd = "cmd"

let ninja = "ninja"

let package_specs = "package-specs"

let generate_merlin = "generate-merlin"

let type_ = "type"

let dev = "dev"

let export_all = "all"

let export_none = "none"

let use_stdlib = "use-stdlib"

let external_stdlib = "external-stdlib"

let reason = "reason"

let react_jsx = "react-jsx"

let jsx = "jsx"

let jsx_version = "version"

let jsx_module = "module"

let jsx_mode = "mode"

let jsx_exclude_dependencies = "exclude-dependencies"
let entries = "entries"

let backend = "backend"

let main_module = "main-module"

let cut_generators = "cut-generators"

let generators = "generators"

let command = "command"

let edge = "edge"

let namespace = "namespace"

let in_source = "in-source"

let warnings = "warnings"

let number = "number"

let error = "error"

let suffix = "suffix"

let gentypeconfig = "gentypeconfig"

let language = "language"

let path = "path"

let ignored_dirs = "ignored-dirs"
6 changes: 4 additions & 2 deletions jscomp/bsb/bsb_config_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,10 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string)
reason_react_jsx;
jsx =
(match package_kind with
| Toplevel -> Bsb_jsx.from_map map
| Pinned_dependency x | Dependency x -> x.jsx);
| (Pinned_dependency x | Dependency x)
when not (List.mem package_name x.jsx.exclude_dependencies) ->
x.jsx
| _ -> Bsb_jsx.from_map map);
generators = extract_generators map;
cut_generators;
}
Expand Down
38 changes: 31 additions & 7 deletions jscomp/bsb/bsb_jsx.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
type version = Jsx_v3 | Jsx_v4
type module_ = React
type mode = Classic | Automatic
type dependencies = string list

type t = {
version : version option;
module_ : module_ option;
mode : mode option;
exclude_dependencies : dependencies;
}

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

let get_list_string_acc (s : Ext_json_types.t array) acc =
Ext_array.to_list_map_acc s acc (fun x ->
match x with Str x -> Some x.str | _ -> None)

let get_list_string s = get_list_string_acc s []

let from_map map =
let version : version option ref = ref None in
let module_ : module_ option ref = ref None in
let mode : mode option ref = ref None in
let exclude_dependencies : dependencies ref = ref [] in
map
|? ( Bsb_build_schemas.jsx,
`Obj
Expand All @@ -36,11 +45,11 @@ let from_map map =
match flo with
| "3" -> version := Some Jsx_v3
| "4" -> version := Some Jsx_v4
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-version %s" flo
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx version %s" flo
)
| Some x ->
Bsb_exception.config_error x
"Unexpected input (expect a version number) for jsx-version"
"Unexpected input (expect a version number) for jsx version"
| None -> ()) )
|? ( Bsb_build_schemas.jsx,
`Obj
Expand All @@ -49,10 +58,10 @@ let from_map map =
| Some (Str { loc; str }) -> (
match str with
| "react" -> module_ := Some React
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-module %s" str)
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx module %s" str)
| Some x ->
Bsb_exception.config_error x
"Unexpected input (jsx module name) for jsx-mode"
"Unexpected input (jsx module name) for jsx module"
| None -> ()) )
|? ( Bsb_build_schemas.jsx,
`Obj
Expand All @@ -62,10 +71,25 @@ let from_map map =
match str with
| "classic" -> mode := Some Classic
| "automatic" -> mode := Some Automatic
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-mode %s" str)
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx mode %s" str)
| Some x ->
Bsb_exception.config_error x
"Unexpected input (expect classic or automatic) for jsx mode"
| None -> ()) )
|? ( Bsb_build_schemas.jsx,
`Obj
(fun m ->
match m.?(Bsb_build_schemas.jsx_exclude_dependencies) with
| Some (Arr { content }) ->
exclude_dependencies := get_list_string content
| Some x ->
Bsb_exception.config_error x
"Unexpected input (expect classic or automatic) for jsx-mode"
"Unexpected input for jsx exclude_dependencies"
| None -> ()) )
|> ignore;
{ version = !version; module_ = !module_; mode = !mode }
{
version = !version;
module_ = !module_;
mode = !mode;
exclude_dependencies = !exclude_dependencies;
}
Loading