Skip to content

Support .mjs and .bs.mjs for Node.js ES-module-support, and lower "suffix" option into "package-specs" #1

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

Draft
wants to merge 25 commits into
base: prep/per-package-spec-suffix
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
01b4c78
(- noop re) Rename Js_packages_info to Js_package_info
ELLIOTTCABLE Mar 9, 2020
056adf9
(- noop re) Clarify naming of some package-info interfaces
ELLIOTTCABLE Mar 9, 2020
0a33ff1
(- re) Clarify name of Js_packages_state to Js_current_package_info
ELLIOTTCABLE Mar 26, 2020
c25b317
(- re) Rename npm_package_path to package_info, matching correspondin…
ELLIOTTCABLE Apr 6, 2020
10f7d44
(NF new) Add an "extension" compoment to -bs-package-output
ELLIOTTCABLE Mar 9, 2020
c8bbb6c
(!! NF re config) Moving top-level "suffix" config down into "package…
ELLIOTTCABLE Jan 26, 2020
c79d9ef
(- fix doc) Update json-schema to match new "suffix" location
ELLIOTTCABLE Feb 4, 2020
a9dc25c
(- NF fix) Remove all .bs.m?js-suffixed build-products, not just .bs.js
ELLIOTTCABLE Feb 4, 2020
da606d1
(- re) change_ext_ns_suffix: Label ambiguous string-args, clarify name
ELLIOTTCABLE Feb 4, 2020
9f4ab20
(fix) Remove remaining references to bs_suffix in bsb
ELLIOTTCABLE Apr 6, 2020
4b65444
(- meta) Update lib/. Plz explain why this is checked into source-con…
ELLIOTTCABLE Apr 6, 2020
73d2e09
(- new) Add extension to the -bs-package-output generated by bsb
ELLIOTTCABLE Apr 6, 2020
aec8be5
(- fix) Include non-.bs-prefixed .mjs in supported extensions
ELLIOTTCABLE Apr 6, 2020
adb93d3
(- doc fix) Remove a couple old, commented out references to dead code
ELLIOTTCABLE Apr 8, 2020
4086b61
(!! new) Deprecate -bs-suffix; add extensions to -bs-package-output
ELLIOTTCABLE Apr 10, 2020
0908593
(new) Support multiple in-source builds with differing file-extensions
ELLIOTTCABLE Apr 10, 2020
6059c12
(- revert bsb) Restore backwards-compat for deprecated toplevel 'suff…
ELLIOTTCABLE Apr 13, 2020
f99498c
(new style) Add a .prettierrc for auto-formatting JavaScript and JSON…
ELLIOTTCABLE Apr 13, 2020
c9f1820
(- doc re) Improve formatting of suffix-deprecation message
ELLIOTTCABLE Apr 13, 2020
09f89a2
(- fix) Only deprecation-warn if config present
ELLIOTTCABLE Apr 13, 2020
da51ab3
(- fix test) Update in_source test's error-message
ELLIOTTCABLE Apr 13, 2020
7cc9fc9
(test fix) Update bsconfig.json in each build-test
ELLIOTTCABLE Apr 13, 2020
20d87f1
(- test fix) Include module-type in namespacing build-test bsconfig
ELLIOTTCABLE Apr 13, 2020
2fa8b0b
(fix) Repair resolution of mis-matched extensions
ELLIOTTCABLE Apr 14, 2020
ce8e5c9
(new test bsb) Test deprecation of top-level suffix field
ELLIOTTCABLE Apr 14, 2020
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
11 changes: 9 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ root = true
[*]
charset = utf-8

[*.{ml,mli,mll,mly}]
max_line_length = 80
[*.{ml,mli,mll,mly}, *.{js,jsx,ts,tsx,vue,json}]
max_line_length = 92
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2

[*.{js,jsx,ts,tsx,vue,json}]
max_line_length = 92
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
Expand Down
4 changes: 3 additions & 1 deletion .ocamlformat-ignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Files containing cppo directives that ocamlformat cannot parse
jscomp/core/js_name_of_module_id.ml
#jscomp/core/js_name_of_module_id.ml
#jscomp/core/js_cmj_load.ml
#jscomp/core/lam_compile_main.ml
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Explicitly set to override .editorconfig with a lower value; see:
# <https://prettier.io/docs/en/options.html#print-width>
printWidth: 80

# Attempting to match existing style in the codebase
semi: false
singleQuote: true
16 changes: 9 additions & 7 deletions docs/docson/build-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
"in-source": {
"type": "boolean",
"description": "Default: false."
},
"suffix" : {
"enum" : [
".js",
".mjs",
".bs.js",
".bs.mjs"
],
"description": "suffix of generated JavaScript files, default varies by 'module' and 'in-source'"
}
},
"required": [
Expand Down Expand Up @@ -482,13 +491,6 @@
"type": "string"
},
"description": "(Not needed usually) arguments to pass to `refmt` above. Default: `[\"--print\", \"binary\"]`."
},
"suffix" : {
"enum" : [
".js",
".bs.js"
],
"description": "suffix of generated js files, default to [.js] "
}
},
"additionalProperties": false,
Expand Down
3 changes: 2 additions & 1 deletion jscomp/bsb/bsb_build_schemas.ml
Original file line number Diff line number Diff line change
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"
51 changes: 28 additions & 23 deletions jscomp/bsb/bsb_config_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,32 @@ let extract_main_entries (map : json_map) =
#end


let deprecated_extract_bs_suffix_exn (map : json_map) =
match Map_string.find_opt map Bsb_build_schemas.suffix with
| None -> None
| Some (Str { str } as config) ->
if str = Literals.suffix_js then Some false
else if str = Literals.suffix_bs_js then Some true
else
Bsb_exception.config_error config
"DEPRECATED: This form of 'suffix' only supports either `.js` or \
`.bs.js`. Use 'suffix' under 'package-specs' instead."
| Some config ->
Bsb_exception.config_error config
"DEPRECATED: This form of 'suffix' only supports a string"


let package_specs_from_obj_map (map : json_map) =
let deprecated_bs_suffix = deprecated_extract_bs_suffix_exn map in
match Map_string.find_opt map Bsb_build_schemas.package_specs with
| Some x -> Bsb_package_specs.from_json ?deprecated_bs_suffix x
| None -> Bsb_package_specs.default_package_specs ?deprecated_bs_suffix ()


let package_specs_from_bsconfig () =
let json = Ext_json_parse.parse_json_from_file Literals.bsconfig_json in
match json with
| Obj { map } -> (
match Map_string.find_opt map Bsb_build_schemas.package_specs with
| Some x -> Bsb_package_specs.from_json x
| None -> Bsb_package_specs.default_package_specs )
| Obj { map } -> package_specs_from_obj_map map
| _ -> assert false


Expand Down Expand Up @@ -159,17 +178,6 @@ let check_stdlib (map : json_map) cwd (*built_in_package*) =
| _ -> assert false )


let extract_bs_suffix_exn (map : json_map) =
match Map_string.find_opt map Bsb_build_schemas.suffix with
| None -> false
| Some (Str { str } as config) ->
if str = Literals.suffix_js then false
else if str = Literals.suffix_bs_js then true
else Bsb_exception.config_error config "expect .bs.js or .js string here"
| Some config ->
Bsb_exception.config_error config "expect .bs.js or .js string here"


let extract_gentype_config (map : json_map) cwd :
Bsb_config_types.gentype_config option =
match Map_string.find_opt map Bsb_build_schemas.gentypeconfig with
Expand Down Expand Up @@ -375,13 +383,11 @@ let interpret_json ~toplevel_package_specs ~(per_proj_dir : string) :
let package_name, namespace = extract_package_name_and_namespace map in
let refmt = extract_refmt map per_proj_dir in
let gentype_config = extract_gentype_config map per_proj_dir in
let bs_suffix = extract_bs_suffix_exn map in
(* The default situation is empty *)
let built_in_package = check_stdlib map per_proj_dir in
let package_specs =
match Map_string.find_opt map Bsb_build_schemas.package_specs with
| Some x -> Bsb_package_specs.from_json x
| None -> Bsb_package_specs.default_package_specs
let package_specs = package_specs_from_obj_map map in
let bs_suffixes =
Bsb_package_specs.extract_in_source_bs_suffixes package_specs
in
let pp_flags : string option =
extract_string map Bsb_build_schemas.pp_flags (fun p ->
Expand Down Expand Up @@ -411,12 +417,11 @@ let interpret_json ~toplevel_package_specs ~(per_proj_dir : string) :
in
let groups, number_of_dev_groups =
Bsb_parse_sources.scan ~ignored_dirs:(extract_ignored_dirs map)
~toplevel ~root:per_proj_dir ~cut_generators ~bs_suffix ~namespace
sources
~toplevel ~root:per_proj_dir ~cut_generators ~bs_suffixes
~namespace sources
in
{
gentype_config;
bs_suffix;
package_name;
namespace;
warning = extract_warning map;
Expand Down
1 change: 0 additions & 1 deletion jscomp/bsb/bsb_config_types.ml
Original file line number Diff line number Diff line change
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
}
14 changes: 7 additions & 7 deletions jscomp/bsb/bsb_ninja_file_groups.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let make_common_shadows package_specs dirname dir_index :
key = Bsb_ninja_global_vars.g_pkg_flg;
op =
Append
(Bsb_package_specs.package_flag_of_package_specs package_specs dirname);
(Bsb_package_specs.flags_of_package_specs package_specs dirname);
}
::
( if Bsb_dir_index.is_lib_dir dir_index then []
Expand All @@ -60,7 +60,7 @@ let make_common_shadows package_specs dirname dir_index :

let emit_module_build (rules : Bsb_ninja_rule.builtin)
(package_specs : Bsb_package_specs.t) (group_dir_index : Bsb_dir_index.t) oc
~bs_suffix js_post_build_cmd namespace (module_info : Bsb_db.module_info) =
js_post_build_cmd namespace (module_info : Bsb_db.module_info) =
let has_intf_file = module_info.info = Ml_mli in
let is_re = module_info.is_re in
let filename_sans_extension = module_info.name_sans_extension in
Expand Down Expand Up @@ -90,7 +90,7 @@ let emit_module_build (rules : Bsb_ninja_rule.builtin)
let output_cmi = output_filename_sans_extension ^ Literals.suffix_cmi in
let output_cmj = output_filename_sans_extension ^ Literals.suffix_cmj in
let output_js =
Bsb_package_specs.get_list_of_output_js package_specs bs_suffix
Bsb_package_specs.get_list_of_output_js package_specs
output_filename_sans_extension
in
let common_shadows =
Expand Down Expand Up @@ -155,8 +155,8 @@ let emit_module_build (rules : Bsb_ninja_rule.builtin)
~order_only_deps:[ output_d ] ~rule


let handle_files_per_dir oc ~bs_suffix ~(rules : Bsb_ninja_rule.builtin)
~package_specs ~js_post_build_cmd ~(files_to_install : Hash_set_string.t)
let handle_files_per_dir oc ~(rules : Bsb_ninja_rule.builtin) ~package_specs
~js_post_build_cmd ~(files_to_install : Hash_set_string.t)
~(namespace : string option) (group : Bsb_file_groups.file_group) : unit =
handle_generators oc group rules.customs;
let installable =
Expand All @@ -168,7 +168,7 @@ let handle_files_per_dir oc ~bs_suffix ~(rules : Bsb_ninja_rule.builtin)
Map_string.iter group.sources (fun module_name module_info ->
if installable module_name then
Hash_set_string.add files_to_install module_info.name_sans_extension;
emit_module_build rules package_specs group.dir_index oc ~bs_suffix
js_post_build_cmd namespace module_info)
emit_module_build rules package_specs group.dir_index oc js_post_build_cmd
namespace module_info)

(* pseuduo targets per directory *)
1 change: 0 additions & 1 deletion jscomp/bsb/bsb_ninja_file_groups.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

val handle_files_per_dir :
out_channel ->
bs_suffix:bool ->
rules:Bsb_ninja_rule.builtin ->
package_specs:Bsb_package_specs.t ->
js_post_build_cmd:string option ->
Expand Down
8 changes: 3 additions & 5 deletions jscomp/bsb/bsb_ninja_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ let output_static_resources (static_resources : string list) copy_rule oc =

let output_ninja_and_namespace_map ~per_proj_dir ~toplevel
({
bs_suffix;
package_name;
external_includes;
bsc_flags;
Expand Down Expand Up @@ -195,17 +194,16 @@ let output_ninja_and_namespace_map ~per_proj_dir ~toplevel
~has_postbuild:(js_post_build_cmd <> None)
~has_ppx:(ppx_files <> []) ~has_pp:(pp_file <> None)
~has_builtin:(built_in_dependency <> None)
~reason_react_jsx ~bs_suffix ~digest generators
~reason_react_jsx ~digest generators
in

emit_bsc_lib_includes bs_dependencies bsc_lib_dirs external_includes namespace
oc;
output_static_resources static_resources rules.copy_resources oc;
(* Generate build statement for each file *)
Ext_list.iter bs_file_groups (fun files_per_dir ->
Bsb_ninja_file_groups.handle_files_per_dir oc ~bs_suffix ~rules
~js_post_build_cmd ~package_specs ~files_to_install ~namespace
files_per_dir);
Bsb_ninja_file_groups.handle_files_per_dir oc ~rules ~js_post_build_cmd
~package_specs ~files_to_install ~namespace files_per_dir);

Ext_option.iter namespace (fun ns ->
let namespace_dir = per_proj_dir // Bsb_config.lib_bs in
Expand Down
3 changes: 1 addition & 2 deletions jscomp/bsb/bsb_ninja_rule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type builtin = {
}

let make_custom_rules ~(has_gentype : bool) ~(has_postbuild : bool)
~(has_ppx : bool) ~(has_pp : bool) ~(has_builtin : bool) ~(bs_suffix : bool)
~(has_ppx : bool) ~(has_pp : bool) ~(has_builtin : bool)
~(reason_react_jsx : Bsb_config_types.reason_react_jsx option)
~(digest : string) ~(refmt : string option)
(* set refmt path when needed *)
Expand All @@ -100,7 +100,6 @@ let make_custom_rules ~(has_gentype : bool) ~(has_postbuild : bool)
let mk_ml_cmj_cmd ~read_cmi ~is_dev ~postbuild : string =
Buffer.clear buf;
Buffer.add_string buf "$bsc -nostdlib $g_pkg_flg -color always";
if bs_suffix then Buffer.add_string buf " -bs-suffix";
if read_cmi then Buffer.add_string buf " -bs-read-cmi";
if is_dev then Buffer.add_string buf " $g_dev_incls";
Buffer.add_string buf " $g_lib_incls";
Expand Down
1 change: 0 additions & 1 deletion jscomp/bsb/bsb_ninja_rule.mli
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ val make_custom_rules :
has_ppx:bool ->
has_pp:bool ->
has_builtin:bool ->
bs_suffix:bool ->
reason_react_jsx:Bsb_config_types.reason_react_jsx option ->
digest:string ->
refmt:string option ->
Expand Down
Loading