Skip to content

Commit 3f0b49a

Browse files
authored
Remove deprecated module systems es6 and es6-global (#8205)
* Remove module variants `es6` and `es6-global` * Remove unused stuff from Ext_path * CHANGELOG
1 parent 160e761 commit 3f0b49a

25 files changed

Lines changed: 112 additions & 457 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Remove the legacy build system. Going forward, only the modern build system is supported, and the `rescript-legacy` command is not available anymore. https://github.com/rescript-lang/rescript/pull/8186
1818
- Remove support for `bsconfig.json`. https://github.com/rescript-lang/rescript/pull/8187
1919
- `Int.fromString` and `Float.fromString` use stricter number parsing and no longer uses an explicit radix argument, but instead supports parsing hexadecimal, binary and exponential notation.
20+
- Remove the deprecated module system names `es6` and `es6-global` (superseded by `esmodule`). https://github.com/rescript-lang/rescript/pull/8205
2021
- Remove `external-stdlib` configuration option from `rescript.json`. This option was rarely used and is no longer supported.
2122
- `js-post-build` now passes the correct output file path based on `in-source` configuration: when `in-source: true`, the path next to the source file is passed; when `in-source: false`, the path in the `lib/<module>/` directory is passed. Additionally, stdout and stderr from the post-build command are now logged. https://github.com/rescript-lang/rescript/pull/8190
2223
- `js-post-build` command now runs in the directory containing the `rescript.json` where it is defined, instead of the unpredictable build invocation directory. This provides consistent behavior in monorepos. https://github.com/rescript-lang/rescript/pull/8195

analysis/examples/larger-project/rescript.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
],
1616
"package-specs": {
17-
"module": "es6",
17+
"module": "esmodule",
1818
"in-source": true
1919
}
2020
}

analysis/examples/workspace-project/rescript.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "workspace-project",
33
"sources": [],
44
"package-specs": {
5-
"module": "es6",
5+
"module": "esmodule",
66
"in-source": true
77
},
88
"suffix": ".mjs",

compiler/core/js_dump_import_export.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ let exports cxt f (idents : Ident.t list) =
6868
(fun _ -> P.newline f);
6969
outer_cxt
7070

71-
(** Print module in ES6 format, it is ES6, trailing comma is valid ES6 code *)
72-
let es6_export cxt f (idents : Ident.t list) =
71+
(** Print module in ESModule format, it is ESModule, trailing comma is valid ES code *)
72+
let esmodule_export cxt f (idents : Ident.t list) =
7373
P.at_least_two_lines f;
7474
match idents with
7575
| [] -> cxt

compiler/core/js_dump_import_export.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ val default_export : string
2626

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

29-
val es6_export : Ext_pp_scope.t -> Ext_pp.t -> Ident.t list -> Ext_pp_scope.t
29+
val esmodule_export :
30+
Ext_pp_scope.t -> Ext_pp.t -> Ident.t list -> Ext_pp_scope.t
3031

3132
val requires :
3233
string ->

compiler/core/js_dump_program.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ let[@inline] is_default (x : Js_op.kind) =
7070
| External {default} -> default
7171
| _ -> false
7272

73-
let node_program ~output_dir f (x : J.deps_program) =
73+
let commonjs_program ~output_dir f (x : J.deps_program) =
7474
P.string f L.strict_directive;
7575
P.newline f;
7676
let cxt =
@@ -87,7 +87,7 @@ let node_program ~output_dir f (x : J.deps_program) =
8787
in
8888
program f cxt x.program
8989

90-
let es6_program ~output_dir fmt f (x : J.deps_program) =
90+
let esmodule_program ~output_dir fmt f (x : J.deps_program) =
9191
let cxt =
9292
Js_dump_import_export.imports Ext_pp_scope.empty f
9393
(* Not be emitted in import statements *)
@@ -105,7 +105,7 @@ let es6_program ~output_dir fmt f (x : J.deps_program) =
105105
in
106106
let () = P.at_least_two_lines f in
107107
let cxt = Js_dump.statements true cxt f x.program.block in
108-
Js_dump_import_export.es6_export cxt f x.program.exports
108+
Js_dump_import_export.esmodule_export cxt f x.program.exports
109109

110110
let pp_deps_program ~(output_prefix : string)
111111
(kind : Js_packages_info.module_system) (program : J.deps_program)
@@ -128,8 +128,8 @@ let pp_deps_program ~(output_prefix : string)
128128
let output_dir = Filename.dirname output_prefix in
129129
ignore
130130
(match kind with
131-
| Esmodule | Es6_global -> es6_program ~output_dir kind f program
132-
| Commonjs -> node_program ~output_dir f program);
131+
| Esmodule -> esmodule_program ~output_dir kind f program
132+
| Commonjs -> commonjs_program ~output_dir f program);
133133
P.newline f;
134134
P.string f
135135
(match program.side_effect with

compiler/core/js_name_of_module_id.ml

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,7 @@ let get_runtime_module_path
7676
which is guaranteed by [-bs-package-output]
7777
*)
7878
else
79-
match module_system with
80-
| Commonjs | Esmodule ->
81-
Js_packages_info.runtime_package_path module_system js_file
82-
(* Note we did a post-processing when working on Windows *)
83-
| Es6_global
84-
->
85-
(* lib/ocaml/xx.cmj --
86-
HACKING: FIXME
87-
maybe we can caching relative package path calculation or employ package map *)
88-
(* assert false *)
89-
Ext_path.rel_normalized_absolute_path
90-
~from:(
91-
Js_packages_info.get_output_dir
92-
current_package_info
93-
~package_dir:(Lazy.force Ext_path.package_dir)
94-
module_system )
95-
(*Invariant: the package path to rescript, it is used to
96-
calculate relative js path
97-
*)
98-
(!Runtime_package.path // dep_path // js_file)
79+
Js_packages_info.runtime_package_path module_system js_file
9980

10081
(* [output_dir] is decided by the command line argument *)
10182
let string_of_module_id
@@ -157,24 +138,7 @@ let string_of_module_id
157138
else
158139
if Js_packages_info.is_runtime_package dep_package_info then
159140
get_runtime_module_path dep_module_id current_package_info module_system
160-
else
161-
begin match module_system with
162-
| Commonjs | Esmodule ->
163-
dep_pkg.pkg_rel_path // js_file
164-
(* Note we did a post-processing when working on Windows *)
165-
| Es6_global
166-
->
167-
begin
168-
Ext_path.rel_normalized_absolute_path
169-
~from:(
170-
Js_packages_info.get_output_dir
171-
current_package_info
172-
~package_dir:(Lazy.force Ext_path.package_dir)
173-
module_system
174-
)
175-
(package_path // dep_pkg.rel_path // js_file)
176-
end
177-
end
141+
else dep_pkg.pkg_rel_path // js_file
178142
| Package_script, Package_script
179143
->
180144
let js_file =

compiler/core/js_packages_info.ml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ let compatible (dep : module_system) (query : module_system) =
3232
match query with
3333
| Commonjs -> dep = Commonjs
3434
| Esmodule -> dep = Esmodule
35-
| Es6_global -> dep = Es6_global || dep = Esmodule
3635
(* As a dependency Leaf Node, it is the same either [global] or [not] *)
3736

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

4241
let ( // ) = Filename.concat
4342

44-
(* in runtime lib, [es6] and [es6] are treated the same wway *)
43+
(* We keep the dir names "js" and "es6" (instead of "commonjs" and "esmodule") for compatibility. *)
4544
let runtime_dir_of_module_system (ms : module_system) =
4645
match ms with
4746
| Commonjs -> "js"
48-
| Esmodule | Es6_global -> "es6"
47+
| Esmodule -> "es6"
4948

5049
let runtime_package_path (ms : module_system) js_file =
5150
Runtime_package.name // "lib" // runtime_dir_of_module_system ms // js_file
@@ -101,13 +100,11 @@ let string_of_module_system (ms : module_system) =
101100
match ms with
102101
| Commonjs -> "CommonJS"
103102
| Esmodule -> "ESModule"
104-
| Es6_global -> "Es6_global"
105103

106104
let module_system_of_string package_name : module_system option =
107105
match package_name with
108106
| "commonjs" -> Some Commonjs
109-
| "esmodule" | "es6" -> Some Esmodule
110-
| "es6-global" -> Some Es6_global
107+
| "esmodule" -> Some Esmodule
111108
| _ -> None
112109

113110
let dump_package_info (fmt : Format.formatter)

compiler/ext/ext_module_system.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
type t = Commonjs | Esmodule | Es6_global
1+
type t = Commonjs | Esmodule

compiler/ext/ext_path.ml

Lines changed: 0 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ type t =
2828
| Dir of string
2929
[@@unboxed]
3030

31-
let simple_convert_node_path_to_os_path =
32-
if Sys.unix then fun x -> x
33-
else if Sys.win32 || Sys.cygwin then Ext_string.replace_slash_backward
34-
else failwith ("Unknown OS : " ^ Sys.os_type)
35-
3631
let cwd = lazy (Sys.getcwd ())
3732

3833
let split_by_sep_per_os : string -> string list =
@@ -80,149 +75,18 @@ let node_rebase_file ~from ~to_ file =
8075
else node_relative_path ~from:(Dir from) (Dir to_))
8176
file
8277

83-
(***
84-
{[
85-
Filename.concat "." "";;
86-
"./"
87-
]}
88-
*)
89-
let combine path1 path2 =
90-
if Filename.is_relative path2 then
91-
if Ext_string.is_empty path2 then path1
92-
else if path1 = Filename.current_dir_name then path2
93-
else if path2 = Filename.current_dir_name then path1
94-
else Filename.concat path1 path2
95-
else path2
96-
9778
let ( // ) x y =
9879
if x = Filename.current_dir_name then y
9980
else if y = Filename.current_dir_name then x
10081
else Filename.concat x y
10182

102-
(**
103-
{[
104-
split_aux "//ghosg//ghsogh/";;
105-
- : string * string list = ("/", ["ghosg"; "ghsogh"])
106-
]}
107-
Note that
108-
{[
109-
Filename.dirname "/a/" = "/"
110-
Filename.dirname "/a/b/" = Filename.dirname "/a/b" = "/a"
111-
]}
112-
Special case:
113-
{[
114-
basename "//" = "/"
115-
basename "///" = "/"
116-
]}
117-
{[
118-
basename "" = "."
119-
basename "" = "."
120-
dirname "" = "."
121-
dirname "" = "."
122-
]}
123-
*)
124-
let split_aux p =
125-
let rec go p acc =
126-
let dir = Filename.dirname p in
127-
if dir = p then (dir, acc)
128-
else
129-
let new_path = Filename.basename p in
130-
if Ext_string.equal new_path Filename.dir_sep then go dir acc
131-
(* We could do more path simplification here
132-
leave to [rel_normalized_absolute_path]
133-
*)
134-
else go dir (new_path :: acc)
135-
in
136-
137-
go p []
138-
13983
(**
14084
TODO: optimization
14185
if [from] and [to] resolve to the same path, a zero-length string is returned
14286
14387
This function is useed in [es6-global] and
14488
[amdjs-global] format and tailored for `rollup`
14589
*)
146-
let rel_normalized_absolute_path ~from to_ =
147-
let root1, paths1 = split_aux from in
148-
let root2, paths2 = split_aux to_ in
149-
if root1 <> root2 then root2
150-
else
151-
let rec go xss yss =
152-
match (xss, yss) with
153-
| x :: xs, y :: ys ->
154-
if Ext_string.equal x y then go xs ys
155-
else if x = Filename.current_dir_name then go xs yss
156-
else if y = Filename.current_dir_name then go xss ys
157-
else
158-
let start =
159-
Ext_list.fold_left xs Ext_string.parent_dir_lit (fun acc _ ->
160-
acc // Ext_string.parent_dir_lit)
161-
in
162-
Ext_list.fold_left yss start (fun acc v -> acc // v)
163-
| [], [] -> Ext_string.empty
164-
| [], y :: ys -> Ext_list.fold_left ys y (fun acc x -> acc // x)
165-
| _ :: xs, [] ->
166-
Ext_list.fold_left xs Ext_string.parent_dir_lit (fun acc _ ->
167-
acc // Ext_string.parent_dir_lit)
168-
in
169-
let v = go paths1 paths2 in
170-
171-
if Ext_string.is_empty v then Literals.node_current
172-
else if
173-
v = "." || v = ".."
174-
|| Ext_string.starts_with v "./"
175-
|| Ext_string.starts_with v "../"
176-
then v
177-
else "./" ^ v
178-
179-
(*TODO: could be hgighly optimized later
180-
{[
181-
normalize_absolute_path "/gsho/./..";;
182-
183-
normalize_absolute_path "/a/b/../c../d/e/f";;
184-
185-
normalize_absolute_path "/gsho/./..";;
186-
187-
normalize_absolute_path "/gsho/./../..";;
188-
189-
normalize_absolute_path "/a/b/c/d";;
190-
191-
normalize_absolute_path "/a/b/c/d/";;
192-
193-
normalize_absolute_path "/a/";;
194-
195-
normalize_absolute_path "/a";;
196-
]}
197-
*)
198-
199-
(** See tests in {!Ounit_path_tests} *)
200-
let normalize_absolute_path x =
201-
let drop_if_exist xs =
202-
match xs with
203-
| [] -> []
204-
| _ :: xs -> xs
205-
in
206-
let rec normalize_list acc paths =
207-
match paths with
208-
| [] -> acc
209-
| x :: xs ->
210-
if Ext_string.equal x Ext_string.current_dir_lit then
211-
normalize_list acc xs
212-
else if Ext_string.equal x Ext_string.parent_dir_lit then
213-
normalize_list (drop_if_exist acc) xs
214-
else normalize_list (x :: acc) xs
215-
in
216-
let root, paths = split_aux x in
217-
let rev_paths = normalize_list [] paths in
218-
let rec go acc rev_paths =
219-
match rev_paths with
220-
| [] -> Filename.concat root acc
221-
| last :: rest -> go (Filename.concat last acc) rest
222-
in
223-
match rev_paths with
224-
| [] -> root
225-
| last :: rest -> go last rest
22690

22791
let absolute_path cwd s =
22892
let process s =
@@ -246,13 +110,6 @@ let absolute_cwd_path s = absolute_path cwd s
246110
| File x -> File (absolute_path cwd x )
247111
| Dir x -> Dir (absolute_path cwd x) *)
248112

249-
let concat dirname filename =
250-
if filename = Filename.current_dir_name then dirname
251-
else if dirname = Filename.current_dir_name then filename
252-
else Filename.concat dirname filename
253-
254-
let check_suffix_case = Ext_string.ends_with
255-
256113
(* Input must be absolute directory *)
257114
let rec find_root_filename ~cwd filenames =
258115
let file_exists =

0 commit comments

Comments
 (0)