Skip to content

Commit 6fd1e73

Browse files
authored
Deprecated es6 and es6-global in favor of esmodule (rescript-lang#6709)
* deprecated es6 and es6-global in favor of esmodule * fix gentype * fix playground * migrate legecy options in tests * add changelog * maybe..?
1 parent 1df3b23 commit 6fd1e73

27 files changed

+100
-59
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
- Fix trailing undefined for optional parameters not omitted with `@send` and `@new`. https://github.com/rescript-lang/rescript-compiler/pull/6716
2424
- Fix JSX4 adding the incorrect type annotation for the prop `ref` in React.forwardRef component https://github.com/rescript-lang/rescript-compiler/pull/6718
2525

26+
#### :nail_care: Polish
27+
28+
- Module spec `es6` and `es6-global` is deprecated in favor of `esmodule`. https://github.com/rescript-lang/rescript-compiler/pull/6709
29+
2630
# 11.1.0-rc.7
2731

2832
#### :bug: Bug Fix

docs/docson/build-schema.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"$schema": "http://json-schema.org/draft-04/schema#",
33
"definitions": {
44
"module-format": {
5-
"enum": ["commonjs", "es6", "es6-global"],
6-
"description": "es6-global generate relative `require` paths instead of relying on NodeJS' module resolution. Default: commonjs."
5+
"enum": ["esmodule", "commonjs", "es6", "es6-global"],
6+
"description": "es6 and es6-global are deprecated. Default: commonjs."
77
},
88
"suffix-spec": {
99
"type": "string",

jscomp/bsb/bsb_config.ml

+5-3
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@ let rev_lib_bs = ".." // ".."
4141

4242
(* access the js directory from "lib/bs",
4343
it would be '../js'
44+
45+
TODO: should be renamed, js -> cjs, es6 -> mjs in v12
4446
*)
4547
let lib_bs_prefix_of_format (x : Ext_module_system.t) =
4648
".."
47-
// match x with NodeJS -> "js" | Es6 -> "es6" | Es6_global -> "es6_global"
49+
// match x with Commonjs -> "js" | Esmodule -> "es6" | Es6_global -> "es6_global"
4850

4951
(* lib/js, lib/es6, lib/es6_global *)
5052
let top_prefix_of_format (x : Ext_module_system.t) =
5153
match x with
52-
| NodeJS -> lib_js
53-
| Es6 -> lib_es6
54+
| Commonjs -> lib_js
55+
| Esmodule -> lib_es6
5456
| Es6_global -> lib_es6_global
5557

5658
let rev_lib_bs_prefix p = rev_lib_bs // p

jscomp/bsb/bsb_config.mli

+2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ val lib_js : string
3333
val lib_bs : string
3434

3535
val lib_es6 : string
36+
[@@ocaml.deprecated "will be removed in v12"]
3637

3738
val lib_es6_global : string
39+
[@@ocaml.deprecated "will be removed in v12"]
3840

3941
val lib_ocaml : string
4042

jscomp/bsb/bsb_package_specs.ml

+18-7
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,29 @@ let ( .?() ) = Map_string.find_opt
4040
let bad_module_format_message_exn ~loc format =
4141
Bsb_exception.errorf ~loc
4242
"package-specs: `%s` isn't a valid output module format. It has to be one \
43-
of: %s, %s or %s"
44-
format Literals.commonjs Literals.es6 Literals.es6_global
43+
of: %s or %s"
44+
format Literals.esmodule Literals.commonjs
4545

4646
let supported_format (x : string) loc : Ext_module_system.t =
47-
if x = Literals.commonjs then NodeJS
48-
else if x = Literals.es6 then Es6
47+
let _ =
48+
if x = Literals.es6 || x = Literals.es6_global then
49+
let loc_end =
50+
{loc with Lexing.pos_cnum = loc.Lexing.pos_cnum + String.length x}
51+
in
52+
let loc = {Warnings.loc_start = loc; loc_end; loc_ghost = false} in
53+
Location.deprecated loc
54+
(Printf.sprintf "Option \"%s\" is deprecated. Use \"%s\" instead." x
55+
Literals.esmodule)
56+
in
57+
if x = Literals.es6 || x = Literals.esmodule then Esmodule
58+
else if x = Literals.commonjs then Commonjs
4959
else if x = Literals.es6_global then Es6_global
5060
else bad_module_format_message_exn ~loc x
5161

5262
let string_of_format (x : Ext_module_system.t) =
5363
match x with
54-
| NodeJS -> Literals.commonjs
55-
| Es6 -> Literals.es6
64+
| Commonjs -> Literals.commonjs
65+
| Esmodule -> Literals.esmodule
5666
| Es6_global -> Literals.es6_global
5767

5868
let js_suffix_regexp = Str.regexp "[A-Za-z0-9-_.]*\\.[cm]?js"
@@ -158,7 +168,8 @@ let package_flag_of_package_specs (package_specs : t) ~(dirname : string) :
158168
| Some x -> Ext_string.inter3 res "-runtime" x
159169

160170
let default_package_specs suffix =
161-
Spec_set.singleton { format = NodeJS; in_source = false; suffix }
171+
(* TODO: swap default to Esmodule in v12 *)
172+
Spec_set.singleton { format = Commonjs; in_source = false; suffix }
162173

163174
(**
164175
[get_list_of_output_js specs "src/hi/hello"]

jscomp/bsb/bsb_spec_set.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
[@@@warning "+9"]
2626

2727
(* TODO: sync up with {!Js_packages_info.module_system} *)
28-
type format = Ext_module_system.t = NodeJS | Es6 | Es6_global
28+
type format = Ext_module_system.t
2929

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

jscomp/build_tests/cycle1/rescript.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"subdirs": true
88
},
99
"package-specs": {
10-
"module": "es6",
10+
"module": "esmodule",
1111
"in-source": true
1212
},
1313
"suffix": ".bs.js"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const child_process = require("child_process");
2+
const assert = require("assert");
3+
const rescript_exe = require("../../../scripts/bin_path").rescript_exe;
4+
5+
const out = child_process.spawnSync(rescript_exe, { encoding: "utf8" });
6+
assert.match(
7+
out.stderr,
8+
/deprecated: Option "es6-global" is deprecated\. Use "esmodule" instead\./
9+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "deprecated-package-specs",
3+
"version": "0.1.0",
4+
"sources": "src",
5+
"package-specs": {
6+
"module": "es6-global"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let () = Js.log("Hello, ReScript")

jscomp/build_tests/in_source/rescript.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"in-source": true
88
},
99
{
10-
"module": "es6",
10+
"module": "esmodule",
1111
"in-source": true
1212
}
1313
]

jscomp/core/dune

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
(run %{bin:cppo} %{env:CPPO_FLAGS=} %{input-file})))
77
(flags
88
(:standard -w +a-4-9-27-30-40-41-42-48-70))
9-
(libraries depends frontend gentype js_parser))
9+
(libraries depends ext frontend gentype js_parser))

jscomp/core/js_dump_program.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ let node_program ~output_dir f (x : J.deps_program) =
7979
| true -> None
8080
| false ->
8181
Some ( x.id,
82-
Js_name_of_module_id.string_of_module_id x ~output_dir NodeJS,
82+
Js_name_of_module_id.string_of_module_id x ~output_dir Commonjs,
8383
is_default x.kind )))
8484
in
8585
program f cxt x.program
@@ -129,8 +129,8 @@ let pp_deps_program ~(output_prefix : string)
129129
let output_dir = Filename.dirname output_prefix in
130130
ignore
131131
(match kind with
132-
| Es6 | Es6_global -> es6_program ~output_dir kind f program
133-
| NodeJS -> node_program ~output_dir f program);
132+
| Esmodule | Es6_global -> es6_program ~output_dir kind f program
133+
| Commonjs -> node_program ~output_dir f program);
134134
P.newline f;
135135
P.string f
136136
(match program.side_effect with

jscomp/core/js_name_of_module_id.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ let get_runtime_module_path
7777
*)
7878
else
7979
match module_system with
80-
| NodeJS | Es6 ->
80+
| Commonjs | Esmodule ->
8181
Js_packages_info.runtime_package_path module_system js_file
8282
(* Note we did a post-processing when working on Windows *)
8383
| Es6_global
@@ -164,7 +164,7 @@ let string_of_module_id
164164
get_runtime_module_path dep_module_id current_package_info module_system
165165
else
166166
begin match module_system with
167-
| NodeJS | Es6 ->
167+
| Commonjs | Esmodule ->
168168
dep_pkg.pkg_rel_path // js_file
169169
(* Note we did a post-processing when working on Windows *)
170170
| Es6_global
@@ -200,4 +200,4 @@ let string_of_module_id
200200
| None ->
201201
Bs_exception.error (Js_not_found js_file))
202202

203-
#endif
203+
#endif

jscomp/core/js_packages_info.ml

+11-11
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424

2525
[@@@warning "+9"]
2626

27-
type module_system = NodeJS | Es6 | Es6_global
27+
type module_system = Ext_module_system.t
2828
(* ignore node_modules, just calcluating relative path *)
2929

3030
(* ocamlopt could not optimize such simple case..*)
3131
let compatible (dep : module_system) (query : module_system) =
3232
match query with
33-
| NodeJS -> dep = NodeJS
34-
| Es6 -> dep = Es6
35-
| Es6_global -> dep = Es6_global || dep = Es6
33+
| Commonjs -> dep = Commonjs
34+
| Esmodule -> dep = Esmodule
35+
| Es6_global -> dep = Es6_global || dep = Esmodule
3636
(* As a dependency Leaf Node, it is the same either [global] or [not] *)
3737

3838
type package_info = {
@@ -47,7 +47,7 @@ let ( // ) = Filename.concat
4747

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

5252
let runtime_package_path (ms : module_system) js_file =
5353
!Bs_version.package_name // "lib"
@@ -61,8 +61,8 @@ let runtime_package_specs : t =
6161
name = Pkg_runtime;
6262
module_systems =
6363
[
64-
{ module_system = Es6; path = "lib/es6"; suffix = Literals.suffix_js };
65-
{ module_system = NodeJS; path = "lib/js"; suffix = Literals.suffix_js };
64+
{ module_system = Esmodule; path = "lib/es6"; suffix = Literals.suffix_js };
65+
{ module_system = Commonjs; path = "lib/js"; suffix = Literals.suffix_js };
6666
];
6767
}
6868

@@ -107,12 +107,12 @@ let from_name (name : string) : t =
107107
let is_empty (x : t) = x.name = Pkg_empty
108108

109109
let string_of_module_system (ms : module_system) =
110-
match ms with NodeJS -> "NodeJS" | Es6 -> "Es6" | Es6_global -> "Es6_global"
110+
match ms with Commonjs -> "CommonJS" | Esmodule -> "ESModule" | Es6_global -> "Es6_global"
111111

112112
let module_system_of_string package_name : module_system option =
113113
match package_name with
114-
| "commonjs" -> Some NodeJS
115-
| "es6" -> Some Es6
114+
| "commonjs" -> Some Commonjs
115+
| "esmodule" | "es6" -> Some Esmodule
116116
| "es6-global" -> Some Es6_global
117117
| _ -> None
118118

@@ -201,7 +201,7 @@ let add_npm_package_path (packages_info : t) (s : string) : t =
201201
in
202202
let m =
203203
match Ext_string.split ~keep_empty:true s ':' with
204-
| [ path ] -> { module_system = NodeJS; path; suffix = Literals.suffix_js }
204+
| [ path ] -> { module_system = Esmodule; path; suffix = Literals.suffix_js }
205205
| [ module_system; path ] ->
206206
{
207207
module_system = handle_module_system module_system;

jscomp/core/js_packages_info.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
type module_system = NodeJS | Es6 | Es6_global
25+
type module_system = Ext_module_system.t
2626

2727
val runtime_dir_of_module_system : module_system -> string
2828

jscomp/core/lam_compile_main.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ let lambda_as_module
292292
: unit =
293293
let package_info = Js_packages_state.get_packages_info () in
294294
if Js_packages_info.is_empty package_info && !Js_config.js_stdout then begin
295-
Js_dump_program.dump_deps_program ~output_prefix NodeJS (lambda_output) stdout
295+
Js_dump_program.dump_deps_program ~output_prefix Commonjs (lambda_output) stdout
296296
end else
297297
Js_packages_info.iter package_info (fun {module_system; path; suffix} ->
298298
let output_chan chan =

jscomp/core/lam_compile_primitive.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ let get_module_system () =
4444
let package_info = Js_packages_state.get_packages_info () in
4545
let module_system =
4646
if Js_packages_info.is_empty package_info && !Js_config.js_stdout then
47-
[Js_packages_info.NodeJS]
47+
[Ext_module_system.Commonjs]
4848
else Js_packages_info.map package_info (fun {module_system} -> module_system)
4949
in
5050
match module_system with
5151
| [module_system] -> module_system
52-
| _ -> NodeJS
52+
| _ -> Commonjs
5353

5454
let import_of_path path =
5555
E.call

jscomp/ext/ext_module_system.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
type t = NodeJS | Es6 | Es6_global
1+
type t = Commonjs | Esmodule | Es6_global

jscomp/ext/literals.ml

+4
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,15 @@ let suffix_gen_js = ".gen.js"
125125

126126
let suffix_gen_tsx = ".gen.tsx"
127127

128+
let esmodule = "esmodule"
129+
128130
let commonjs = "commonjs"
129131

130132
let es6 = "es6"
133+
[@@ocaml.deprecated "Will be removed in v12"]
131134

132135
let es6_global = "es6-global"
136+
[@@ocaml.deprecated "Will be removed in v12"]
133137

134138
let unused_attribute = "Unused attribute "
135139

jscomp/gentype/EmitType.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ let emitRequire ~importedValueOrComponent ~early ~emitters ~(config : Config.t)
382382
let importPathString = ImportPath.emit importPath in
383383
let output =
384384
match config.module_ with
385-
| ES6 when not importedValueOrComponent ->
385+
| ESModule when not importedValueOrComponent ->
386386
"import * as " ^ moduleNameString ^ " from '" ^ importPathString ^ "';"
387387
| _ ->
388388
"const " ^ moduleNameString ^ " = require('" ^ importPathString ^ "');"

jscomp/gentype/GenTypeConfig.ml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module ModuleNameMap = Map.Make (ModuleName)
22

3-
type module_ = CommonJS | ES6
3+
type module_ = CommonJS | ESModule
44

55
(** Compatibility for `compilerOptions.moduleResolution` in TypeScript projects. *)
66
type moduleResolution =
@@ -41,7 +41,7 @@ let default =
4141
everything = false;
4242
exportInterfaces = false;
4343
generatedFileExtension = None;
44-
module_ = ES6;
44+
module_ = ESModule;
4545
moduleResolution = Node;
4646
namespace = None;
4747
platformLib = "";
@@ -53,7 +53,7 @@ let default =
5353

5454
let bsPlatformLib ~config =
5555
match config.module_ with
56-
| ES6 -> config.platformLib ^ "/lib/es6"
56+
| ESModule -> config.platformLib ^ "/lib/es6"
5757
| CommonJS -> config.platformLib ^ "/lib/js"
5858

5959
let getBsCurryPath ~config = Filename.concat (bsPlatformLib ~config) "curry.js"
@@ -154,9 +154,9 @@ let readConfig ~getConfigFile ~namespace =
154154
(* Give priority to gentypeconfig, followed by package-specs *)
155155
match (moduleString, packageSpecsModuleString) with
156156
| Some "commonjs", _ -> CommonJS
157-
| Some "es6", _ -> ES6
157+
| Some ("esmodule" | "es6"), _ -> ESModule
158158
| None, Some "commonjs" -> CommonJS
159-
| None, Some ("es6" | "es6-global") -> ES6
159+
| None, Some ("esmodule" | "es6" | "es6-global") -> ESModule
160160
| _ -> default.module_
161161
in
162162
let moduleResolution =

jscomp/gentype_tests/typescript-react-example/rescript.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"gentypeconfig": {
33
"language": "typescript",
4-
"module": "es6",
4+
"module": "esmodule",
55
"importPath": "relative",
66
"shims": {
77
"Js": "Js",
@@ -26,7 +26,7 @@
2626
],
2727
"uncurried": false,
2828
"package-specs": {
29-
"module": "es6",
29+
"module": "esmodule",
3030
"in-source": true
3131
},
3232
"suffix": ".res.js"

0 commit comments

Comments
 (0)