Skip to content

Commit

Permalink
(!! NF re config) Moving top-level "suffix" config down into "package…
Browse files Browse the repository at this point in the history
…-specs"
  • Loading branch information
ELLIOTTCABLE committed Apr 13, 2020
1 parent 10f7d44 commit c8bbb6c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
3 changes: 2 additions & 1 deletion jscomp/bsb/bsb_build_schemas.ml
Expand Up @@ -75,11 +75,12 @@ let generators = "generators"
let command = "command"
let edge = "edge"
let namespace = "namespace"
let _module = "module"
let in_source = "in-source"
let suffix = "suffix"
let warnings = "warnings"
let number = "number"
let error = "error"
let suffix = "suffix"
let gentypeconfig = "gentypeconfig"
let path = "path"
let ignored_dirs = "ignored-dirs"
1 change: 0 additions & 1 deletion jscomp/bsb/bsb_config_types.ml
Expand Up @@ -79,7 +79,6 @@ type t =
entries : entries_t list ;
generators : command Map_string.t ;
cut_generators : bool; (* note when used as a dev mode, we will always ignore it *)
bs_suffix : bool ; (* true means [.bs.js] we should pass [-bs-suffix] flag *)
gentype_config : gentype_config option;
number_of_dev_groups : int
}
49 changes: 44 additions & 5 deletions jscomp/bsb/bsb_package_specs.ml
Expand Up @@ -27,7 +27,11 @@ let ( // ) = Ext_path.combine
(* TODO: sync up with {!Js_package_info.module_system} *)
type format = NodeJS | Es6 | Es6_global

type spec = { format : format; in_source : bool }
type spec = {
format : format;
in_source : bool;
suffix : string
}

module Spec_set = Set.Make (struct
type t = spec
Expand Down Expand Up @@ -64,6 +68,29 @@ let prefix_of_format (x : format) =
| Es6_global -> Bsb_config.lib_es6_global


let bad_suffix_message_warn suffix =
Bsb_log.warn
"@{<warning>UNSUPPORTED@}: package-specs: extension `%s` is unsupported@;\
; consider one of: %s, %s, %s, or %s@." suffix Literals.suffix_js
Literals.suffix_mjs Literals.suffix_bs_js Literals.suffix_bs_mjs


let supported_suffix (x : string) =
if not (List.mem x Literals.[ suffix_js; suffix_bs_js; suffix_bs_mjs ]) then
bad_suffix_message_warn x;
x


let default_suffix format in_source =
(* In the absence of direction to the contrary, the suffix depends on
* [format] and [in_source]. *)
match (format, in_source) with
| NodeJS, false -> Literals.suffix_js
| NodeJS, true -> Literals.suffix_bs_js
| _, false -> Literals.suffix_mjs
| _, true -> Literals.suffix_bs_mjs


let rec from_array (arr : Ext_json_types.t array) : Spec_set.t =
let spec = ref Spec_set.empty in
let has_in_source = ref false in
Expand All @@ -83,16 +110,27 @@ let rec from_array (arr : Ext_json_types.t array) : Spec_set.t =
and from_json_single (x : Ext_json_types.t) : spec =
match x with
| Str { str = format; loc } ->
{ format = supported_format format loc; in_source = false }
let format = supported_format format loc in
{ format; in_source = false; suffix = default_suffix format false }
| Obj { map; loc } -> (
match Map_string.find_exn map "module" with
match Map_string.find_exn map Bsb_build_schemas._module with
| Str { str = format } ->
let format = supported_format format loc in
let in_source =
match Map_string.find_opt map Bsb_build_schemas.in_source with
| Some (True _) -> true
| Some _ | None -> false
in
{ format = supported_format format loc; in_source }
let suffix =
match Map_string.find_opt map Bsb_build_schemas.suffix with
| Some (Str { str = suffix; loc }) -> supported_suffix suffix
| Some _ ->
Bsb_exception.errorf ~loc
"package-specs: the `suffix` field of the configuration \
object must be absent, or a string."
| None -> default_suffix format in_source
in
{ format; in_source; suffix }
| Arr _ ->
Bsb_exception.errorf ~loc
"package-specs: when the configuration is an object, `module` \
Expand Down Expand Up @@ -137,7 +175,8 @@ let package_flag_of_package_specs (package_specs : t) (dirname : string) :


let default_package_specs =
Spec_set.singleton { format = NodeJS; in_source = false }
Spec_set.singleton
{ format = NodeJS; in_source = false; suffix = default_suffix NodeJS false }


(** [get_list_of_output_js specs true "src/hi/hello"] *)
Expand Down
2 changes: 2 additions & 0 deletions jscomp/ext/literals.ml
Expand Up @@ -100,7 +100,9 @@ let suffix_reiast = ".reiast"
let suffix_mliast_simple = ".mliast_simple"
let suffix_d = ".d"
let suffix_js = ".js"
let suffix_mjs = ".mjs"
let suffix_bs_js = ".bs.js"
let suffix_bs_mjs = ".bs.mjs"
(* let suffix_re_js = ".re.js" *)
let suffix_gen_js = ".gen.js"
let suffix_gen_tsx = ".gen.tsx"
Expand Down
2 changes: 2 additions & 0 deletions jscomp/ext/literals.mli
Expand Up @@ -99,7 +99,9 @@ val suffix_rei : string

val suffix_d : string
val suffix_js : string
val suffix_mjs : string
val suffix_bs_js : string
val suffix_bs_mjs : string
(* val suffix_re_js : string *)
val suffix_gen_js : string
val suffix_gen_tsx: string
Expand Down

0 comments on commit c8bbb6c

Please sign in to comment.