Skip to content
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

prepare #4687, allow user to customize js suffix per package specs #4689

Merged
merged 2 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 6 additions & 4 deletions jscomp/bsb/bsb_config_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ let check_stdlib (map : json_map) cwd (*built_in_package*) =
| _ -> assert false

end
let extract_bs_suffix_exn (map : json_map) =


let extract_bs_suffix_exn (map : json_map) : Ext_js_suffix.t =
match Map_string.find_opt map Bsb_build_schemas.suffix with
| None -> false
| None -> Js
| Some (Str {str} as config ) ->
if str = Literals.suffix_js then false
else if str = Literals.suffix_bs_js then true
if str = Literals.suffix_js then Js
else if str = Literals.suffix_bs_js then Bs_js
else Bsb_exception.config_error config
"expect .bs.js or .js string here"
| Some config ->
Expand Down
2 changes: 1 addition & 1 deletion jscomp/bsb/bsb_config_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ type t =
reason_react_jsx : reason_react_jsx option; (* whether apply PPX transform or not*)
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 *)
bs_suffix : Ext_js_suffix.t ;
gentype_config : gentype_config option;
}
4 changes: 2 additions & 2 deletions jscomp/bsb/bsb_ninja_file_groups.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ let emit_module_build
(package_specs : Bsb_package_specs.t)
(is_dev : bool)
oc
~bs_suffix
~(bs_suffix : Ext_js_suffix.t)
js_post_build_cmd
namespace
(module_info : Bsb_db.module_info)
Expand Down Expand Up @@ -187,7 +187,7 @@ let emit_module_build

let handle_files_per_dir
oc
~bs_suffix
~(bs_suffix : Ext_js_suffix.t)
~(rules : Bsb_ninja_rule.builtin)
~package_specs
~js_post_build_cmd
Expand Down
2 changes: 1 addition & 1 deletion jscomp/bsb/bsb_ninja_file_groups.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

val handle_files_per_dir :
out_channel ->
bs_suffix:bool ->
bs_suffix:Ext_js_suffix.t ->
rules:Bsb_ninja_rule.builtin ->
package_specs:Bsb_package_specs.t ->
js_post_build_cmd:string option ->
Expand Down
5 changes: 2 additions & 3 deletions jscomp/bsb/bsb_ninja_rule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ let make_custom_rules
~(has_ppx : bool)
~(has_pp : bool)
~(has_builtin : bool)
~(bs_suffix : bool)
~(bs_suffix : Ext_js_suffix.t)
~(reason_react_jsx : Bsb_config_types.reason_react_jsx option)
~(digest : string)
~(refmt : string option) (* set refmt path when needed *)
Expand All @@ -131,8 +131,7 @@ let make_custom_rules
Ext_buffer.clear buf;
Ext_buffer.add_string buf "$bsc";
Ext_buffer.add_ninja_prefix_var buf Bsb_ninja_global_vars.g_pkg_flg;
if bs_suffix then
Ext_buffer.add_string buf " -bs-suffix";
Ext_js_suffix.to_bsc_flag bs_suffix buf;
if read_cmi then
Ext_buffer.add_string buf " -bs-read-cmi";
if is_dev then
Expand Down
2 changes: 1 addition & 1 deletion jscomp/bsb/bsb_ninja_rule.mli
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ val make_custom_rules :
has_ppx:bool ->
has_pp:bool ->
has_builtin:bool ->
bs_suffix:bool ->
bs_suffix:Ext_js_suffix.t ->
reason_react_jsx : Bsb_config_types.reason_react_jsx option ->
digest:string ->
refmt:string option ->
Expand Down
8 changes: 4 additions & 4 deletions jscomp/bsb/bsb_package_specs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,17 @@ let default_package_specs =
*)
let get_list_of_output_js
(package_specs : Spec_set.t)
(bs_suffix : bool)
(bs_suffix : Ext_js_suffix.t)
(output_file_sans_extension : string)
=
Spec_set.fold
(fun (spec : spec) acc ->
let basename = Ext_namespace.change_ext_ns_suffix
output_file_sans_extension
(if bs_suffix then Literals.suffix_bs_js else Literals.suffix_js)
(Ext_js_suffix.to_string bs_suffix)
in
(Bsb_config.proj_rel @@ (if spec.in_source then basename
else prefix_of_format spec.format // basename))
(Bsb_config.proj_rel (if spec.in_source then basename
else prefix_of_format spec.format // basename))
:: acc
) package_specs []

Expand Down
5 changes: 4 additions & 1 deletion jscomp/bsb/bsb_package_specs.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ val from_json:
Ext_json_types.t -> t

val get_list_of_output_js :
t -> bool -> string -> string list
t ->
Ext_js_suffix.t ->
string ->
string list

(**
Sample output: {[ -bs-package-output commonjs:lib/js/jscomp/test]}
Expand Down
4 changes: 1 addition & 3 deletions jscomp/bsb/bsb_parse_sources.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type cxt = {
cut_generators : bool;
traverse : bool;
namespace : string option;
bs_suffix: bool;
ignored_dirs : Set_string.t
}

Expand Down Expand Up @@ -392,7 +391,7 @@ let scan
~root
~cut_generators
~namespace
~bs_suffix
~(bs_suffix : Ext_js_suffix.t)
~ignored_dirs
x : t =
parse_sources {
Expand All @@ -403,7 +402,6 @@ let scan
root ;
cut_generators;
namespace;
bs_suffix;
traverse = false
} x

Expand Down
2 changes: 1 addition & 1 deletion jscomp/bsb/bsb_parse_sources.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ val scan :
root: string ->
cut_generators: bool ->
namespace : string option ->
bs_suffix:bool ->
bs_suffix:Ext_js_suffix.t ->
ignored_dirs:Set_string.t ->
Ext_json_types.t ->
Bsb_file_groups.t
Expand Down
2 changes: 1 addition & 1 deletion jscomp/common/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ let syntax_only = ref false
let binary_ast = ref false


let bs_suffix = ref false
let bs_suffix : Ext_js_suffix.t ref = ref Ext_js_suffix.Js

let debug = ref false

Expand Down
2 changes: 1 addition & 1 deletion jscomp/common/js_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ val binary_ast : bool ref



val bs_suffix : bool ref
val bs_suffix : Ext_js_suffix.t ref
val debug : bool ref

val cmi_only : bool ref
Expand Down
12 changes: 6 additions & 6 deletions jscomp/core/lam_compile_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ let get_cmj_case output_prefix : Ext_js_file_kind.t =
Ext_char.is_lower_case (Filename.basename output_prefix).[0]
in
match little, !Js_config.bs_suffix with
| true, true -> Little_bs
| true, false -> Little_js
| false, true -> Upper_bs
| false, false -> Upper_js
| true, Bs_js -> Little_bs
| true, Js -> Little_js
| false, Bs_js -> Upper_bs
| false, Js -> Upper_js


let compile_group (meta : Lam_stats.t)
Expand Down Expand Up @@ -278,7 +278,7 @@ let compile
meta
effect
coerced_input.export_map
(get_cmj_case output_prefix)
~js_file_kind:(get_cmj_case output_prefix)
in
(if not !Clflags.dont_write_files then
Js_cmj_format.to_file
Expand All @@ -298,7 +298,7 @@ let lambda_as_module
Ext_namespace.change_ext_ns_suffix
(Filename.basename
output_prefix)
(if !Js_config.bs_suffix then Literals.suffix_bs_js else Literals.suffix_js)
(Ext_js_suffix.to_string !Js_config.bs_suffix)
in
let package_info = Js_packages_state.get_packages_info () in
if Js_packages_info.is_empty package_info && !Js_config.js_stdout then begin
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_stats_export.ml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ let export_to_cmj
(meta : Lam_stats.t )
effect
export_map
js_file_kind
~js_file_kind
: Js_cmj_format.t =
let values = values_of_export meta export_map in

Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_stats_export.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ val export_to_cmj :
Lam_stats.t ->
Js_cmj_format.effect ->
Lam.t Map_ident.t ->
Ext_js_file_kind.t ->
js_file_kind:Ext_js_file_kind.t ->
Js_cmj_format.t

14 changes: 14 additions & 0 deletions jscomp/ext/ext_js_suffix.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type t =
| Js
| Bs_js


let to_string (x : t) =
match x with
| Js -> Literals.suffix_js
| Bs_js -> Literals.suffix_bs_js

let to_bsc_flag (x : t) (buf : Ext_buffer.t) =
match x with
| Js -> ()
| Bs_js -> Ext_buffer.add_string buf " -bs-suffix"
2 changes: 1 addition & 1 deletion jscomp/main/js_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
"-bs-g", unit_call (fun _ -> Js_config.debug := true; Lexer.replace_directive_bool "DEBUG" true),
"Debug mode";

"-bs-suffix", set Js_config.bs_suffix,
"-bs-suffix", unit_call (fun _ -> Js_config.bs_suffix := Bs_js),
"*internal* set suffix to .bs.js";

"-bs-package-name", string_call Js_packages_state.set_package_name,
Expand Down
Loading