Skip to content
Open
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
2 changes: 1 addition & 1 deletion analysis/examples/larger-project/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
}
}
2 changes: 1 addition & 1 deletion analysis/examples/workspace-project/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"sources": [],
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"suffix": ".mjs",
Expand Down
16 changes: 6 additions & 10 deletions compiler/bsb/bsb_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ let ( // ) = Ext_path.combine

let lib_lit = "lib"

let lib_js = lib_lit // "js"

let lib_ocaml = lib_lit // "ocaml"

let lib_bs = lib_lit // "bs"

let lib_es6 = lib_lit // "es6"
let lib_commonjs = lib_lit // "js"

let lib_es6_global = lib_lit // "es6_global"
let lib_esmodule = lib_lit // "es6"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let lib_esmodule = lib_lit // "es6"
let lib_esmodule = lib_lit // "esmodule"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for the output path "lib/es6"

If we change this then it will be another breaking change which is huge

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. It does look wrong/confusing though. Maybe leave the name lib_es6 and/or add a comment why we do not change this for now.


let all_lib_artifacts = [lib_js; lib_ocaml; lib_bs; lib_es6; lib_es6_global]
let all_lib_artifacts = [lib_ocaml; lib_bs; lib_commonjs; lib_esmodule]

let rev_lib_bs = ".." // ".."

Expand All @@ -50,14 +48,12 @@ let lib_bs_prefix_of_format (x : Ext_module_system.t) =
match x with
| Commonjs -> "js"
| Esmodule -> "es6"
| Es6_global -> "es6_global"

(* lib/js, lib/es6, lib/es6_global *)
(* lib/js, lib/es6 *)
let top_prefix_of_format (x : Ext_module_system.t) =
match x with
| Commonjs -> lib_js
| Esmodule -> lib_es6
| Es6_global -> lib_es6_global
| Commonjs -> lib_commonjs
| Esmodule -> lib_esmodule

let rev_lib_bs_prefix p = rev_lib_bs // p

Expand Down
6 changes: 2 additions & 4 deletions compiler/bsb/bsb_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ val proj_rel : string -> string

val lib_lit : string

val lib_js : string

val lib_bs : string

val lib_es6 : string [@@ocaml.deprecated "will be removed in v12"]
val lib_commonjs : string

val lib_es6_global : string [@@ocaml.deprecated "will be removed in v12"]
val lib_esmodule : string

val lib_ocaml : string

Expand Down
19 changes: 4 additions & 15 deletions compiler/bsb/bsb_package_specs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,15 @@ let bad_module_format_message_exn ~loc format =
format Literals.esmodule Literals.commonjs

let supported_format (x : string) loc : Ext_module_system.t =
let _ =
if x = Literals.es6 || x = Literals.es6_global then
let loc_end =
{loc with Lexing.pos_cnum = loc.Lexing.pos_cnum + String.length x}
in
let loc = {Warnings.loc_start = loc; loc_end; loc_ghost = false} in
Location.deprecated ~can_be_automigrated:false loc
(Printf.sprintf "Option \"%s\" is deprecated. Use \"%s\" instead." x
Literals.esmodule)
in
if x = Literals.es6 || x = Literals.esmodule then Esmodule
else if x = Literals.commonjs then Commonjs
else if x = Literals.es6_global then Es6_global
else bad_module_format_message_exn ~loc x
match x with
| x when x = Literals.esmodule -> Esmodule
| x when x = Literals.commonjs -> Commonjs
| _ -> bad_module_format_message_exn ~loc x

let string_of_format (x : Ext_module_system.t) =
match x with
| Commonjs -> Literals.commonjs
| Esmodule -> Literals.esmodule
| Es6_global -> Literals.es6_global

let js_suffix_regexp = Str.regexp "[A-Za-z0-9-_.]*\\.[cm]?js"

Expand Down
4 changes: 2 additions & 2 deletions compiler/core/js_dump_import_export.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ let exports cxt f (idents : Ident.t list) =
(fun _ -> P.newline f);
outer_cxt

(** Print module in ES6 format, it is ES6, trailing comma is valid ES6 code *)
let es6_export cxt f (idents : Ident.t list) =
(** Print module in ESModule format, it is ESModule, trailing comma is valid ES code *)
let esmodule_export cxt f (idents : Ident.t list) =
P.at_least_two_lines f;
match idents with
| [] -> cxt
Expand Down
3 changes: 2 additions & 1 deletion compiler/core/js_dump_import_export.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ val default_export : string

val exports : Ext_pp_scope.t -> Ext_pp.t -> Ident.t list -> Ext_pp_scope.t

val es6_export : Ext_pp_scope.t -> Ext_pp.t -> Ident.t list -> Ext_pp_scope.t
val esmodule_export :
Ext_pp_scope.t -> Ext_pp.t -> Ident.t list -> Ext_pp_scope.t

val requires :
string ->
Expand Down
10 changes: 5 additions & 5 deletions compiler/core/js_dump_program.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let[@inline] is_default (x : Js_op.kind) =
| External {default} -> default
| _ -> false

let node_program ~output_dir f (x : J.deps_program) =
let commonjs_program ~output_dir f (x : J.deps_program) =
P.string f L.strict_directive;
P.newline f;
let cxt =
Expand All @@ -87,7 +87,7 @@ let node_program ~output_dir f (x : J.deps_program) =
in
program f cxt x.program

let es6_program ~output_dir fmt f (x : J.deps_program) =
let esmodule_program ~output_dir fmt f (x : J.deps_program) =
let cxt =
Js_dump_import_export.imports Ext_pp_scope.empty f
(* Not be emitted in import statements *)
Expand All @@ -105,7 +105,7 @@ let es6_program ~output_dir fmt f (x : J.deps_program) =
in
let () = P.at_least_two_lines f in
let cxt = Js_dump.statements true cxt f x.program.block in
Js_dump_import_export.es6_export cxt f x.program.exports
Js_dump_import_export.esmodule_export cxt f x.program.exports

let pp_deps_program ~(output_prefix : string)
(kind : Js_packages_info.module_system) (program : J.deps_program)
Expand All @@ -128,8 +128,8 @@ let pp_deps_program ~(output_prefix : string)
let output_dir = Filename.dirname output_prefix in
ignore
(match kind with
| Esmodule | Es6_global -> es6_program ~output_dir kind f program
| Commonjs -> node_program ~output_dir f program);
| Esmodule -> esmodule_program ~output_dir kind f program
| Commonjs -> commonjs_program ~output_dir f program);
P.newline f;
P.string f
(match program.side_effect with
Expand Down
40 changes: 2 additions & 38 deletions compiler/core/js_name_of_module_id.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,7 @@ let get_runtime_module_path
which is guaranteed by [-bs-package-output]
*)
else
match module_system with
| Commonjs | Esmodule ->
Js_packages_info.runtime_package_path module_system js_file
(* Note we did a post-processing when working on Windows *)
| Es6_global
->
(* lib/ocaml/xx.cmj --
HACKING: FIXME
maybe we can caching relative package path calculation or employ package map *)
(* assert false *)
Ext_path.rel_normalized_absolute_path
~from:(
Js_packages_info.get_output_dir
current_package_info
~package_dir:(Lazy.force Ext_path.package_dir)
module_system )
(*Invariant: the package path to rescript, it is used to
calculate relative js path
*)
(!Runtime_package.path // dep_path // js_file)
Js_packages_info.runtime_package_path module_system js_file

(* [output_dir] is decided by the command line argument *)
let string_of_module_id
Expand Down Expand Up @@ -157,24 +138,7 @@ let string_of_module_id
else
if Js_packages_info.is_runtime_package dep_package_info then
get_runtime_module_path dep_module_id current_package_info module_system
else
begin match module_system with
| Commonjs | Esmodule ->
dep_pkg.pkg_rel_path // js_file
(* Note we did a post-processing when working on Windows *)
| Es6_global
->
begin
Ext_path.rel_normalized_absolute_path
~from:(
Js_packages_info.get_output_dir
current_package_info
~package_dir:(Lazy.force Ext_path.package_dir)
module_system
)
(package_path // dep_pkg.rel_path // js_file)
end
end
else dep_pkg.pkg_rel_path // js_file
| Package_script, Package_script
->
let js_file =
Expand Down
8 changes: 2 additions & 6 deletions compiler/core/js_packages_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ let compatible (dep : module_system) (query : module_system) =
match query with
| Commonjs -> dep = Commonjs
| Esmodule -> dep = Esmodule
| Es6_global -> dep = Es6_global || dep = Esmodule
(* As a dependency Leaf Node, it is the same either [global] or [not] *)

type package_info = {module_system: module_system; path: string; suffix: string}
Expand All @@ -41,11 +40,10 @@ type package_name = Pkg_empty | Pkg_runtime | Pkg_normal of string

let ( // ) = Filename.concat

(* in runtime lib, [es6] and [es6] are treated the same wway *)
let runtime_dir_of_module_system (ms : module_system) =
match ms with
| Commonjs -> "js"
| Esmodule | Es6_global -> "es6"
| Esmodule -> "es6"

let runtime_package_path (ms : module_system) js_file =
Runtime_package.name // "lib" // runtime_dir_of_module_system ms // js_file
Expand Down Expand Up @@ -101,13 +99,11 @@ let string_of_module_system (ms : module_system) =
match ms with
| Commonjs -> "CommonJS"
| Esmodule -> "ESModule"
| Es6_global -> "Es6_global"

let module_system_of_string package_name : module_system option =
match package_name with
| "commonjs" -> Some Commonjs
| "esmodule" | "es6" -> Some Esmodule
| "es6-global" -> Some Es6_global
| "esmodule" -> Some Esmodule
| _ -> None

let dump_package_info (fmt : Format.formatter)
Expand Down
2 changes: 1 addition & 1 deletion compiler/ext/ext_module_system.ml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
type t = Commonjs | Esmodule | Es6_global
type t = Commonjs | Esmodule
6 changes: 0 additions & 6 deletions compiler/ext/literals.ml
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ let esmodule = "esmodule"

let commonjs = "commonjs"

let es6 = "es6"
(* [@@deprecated "Will be removed in v12"] *)

let es6_global = "es6-global"
(* [@@deprecated "Will be removed in v12"] *)

let unused_attribute = "Unused attribute "

(** Used when produce node compatible paths *)
Expand Down
4 changes: 2 additions & 2 deletions compiler/gentype/GenTypeConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ let read_config ~get_config_file ~namespace =
(* Give priority to gentypeconfig, followed by package-specs *)
match (module_string, package_specs_module_string) with
| Some "commonjs", _ -> CommonJS
| Some ("esmodule" | "es6"), _ -> ESModule
| Some "esmodule", _ -> ESModule
| None, Some "commonjs" -> CommonJS
| None, Some ("esmodule" | "es6" | "es6-global") -> ESModule
| None, Some "esmodule" -> ESModule
| _ -> default.module_
in
let module_resolution =
Expand Down
9 changes: 4 additions & 5 deletions compiler/jsoo/jsoo_playground_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ module BundleConfig = struct

let string_of_module_system m =
match m with
| Ext_module_system.Commonjs -> "nodejs"
| Esmodule -> "es6"
| Es6_global -> "es6_global"
| Ext_module_system.Commonjs -> "commonjs"
| Esmodule -> "esmodule"
end

type loc_err_info = {
Expand Down Expand Up @@ -604,10 +603,10 @@ module Export = struct
let config = BundleConfig.make () in
let set_module_system value =
match value with
| "esmodule" | "es6" ->
| "esmodule" ->
config.module_system <- Ext_module_system.Esmodule;
true
| "commonjs" | "nodejs" ->
| "commonjs" ->
config.module_system <- Commonjs;
true
| _ -> false
Expand Down
4 changes: 2 additions & 2 deletions docs/docson/build-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"module-format": {
"enum": ["esmodule", "commonjs", "es6", "es6-global"],
"description": "es6 and es6-global are deprecated. Default: commonjs."
"enum": ["esmodule", "commonjs"],
"description": "Output module format. Default: commonjs."
},
"suffix-spec": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion rewatch/CompilerConfigurationSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Currently supported features:

### Module-Format

enum: "commonjs" | "es6" | "es6-global"
enum: "commonjs" | "esmodule"

### Suffix

Expand Down
Loading
Loading