Skip to content

Commit 122a3a6

Browse files
committed
New module Runtime_package
1 parent 22f68af commit 122a3a6

File tree

11 files changed

+50
-57
lines changed

11 files changed

+50
-57
lines changed

analysis/src/ModuleResolution.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let ( /+ ) = Filename.concat
33
let rec resolveNodeModulePath ~startPath name =
44
if name = "@rescript/runtime" then
55
(* Hack: we need a reliable way to resolve modules in monorepos. *)
6-
Some Config.runtime_module_path
6+
Some Runtime_package.path
77
else
88
let scope = Filename.dirname name in
99
let name = Filename.basename name in

compiler/bsb/bsb_exception.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ let print (fmt : Format.formatter) (x : error) =
4747
modname
4848
| Package_not_found name ->
4949
let name = Bsb_pkg_types.to_string name in
50-
if Ext_string.equal name Bs_version.package_name then
50+
if Ext_string.equal name Runtime_package.name then
5151
Format.fprintf fmt
5252
"File \"rescript.json\", line 1\n\
5353
@{<error>Error:@} package @{<error>%s@} is not found\n\

compiler/common/bs_version.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424
let version = "12.0.0-beta.10"
2525
let header = "// Generated by ReScript, PLEASE EDIT WITH CARE"
26-
let package_name = "@rescript/runtime"

compiler/common/bs_version.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,3 @@
2525
val version : string
2626

2727
val header : string
28-
29-
val package_name : string

compiler/core/js_name_of_module_id.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ let get_runtime_module_path
9595
(*Invariant: the package path to rescript, it is used to
9696
calculate relative js path
9797
*)
98-
(Config.runtime_module_path // dep_path // js_file)
98+
(Runtime_package.path // dep_path // js_file)
9999

100100
(* [output_dir] is decided by the command line argument *)
101101
let string_of_module_id

compiler/core/js_packages_info.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let runtime_dir_of_module_system (ms : module_system) =
4848
| Esmodule | Es6_global -> "es6"
4949

5050
let runtime_package_path (ms : module_system) js_file =
51-
Bs_version.package_name // "lib" // runtime_dir_of_module_system ms // js_file
51+
Runtime_package.name // "lib" // runtime_dir_of_module_system ms // js_file
5252

5353
type t = {name: package_name; module_systems: package_info list}
5454

@@ -85,8 +85,8 @@ let map (x : t) cb = Ext_list.map x.module_systems cb
8585

8686
(* we don't want force people to use package *)
8787

88-
(**
89-
TODO: not allowing user to provide such specific package name
88+
(**
89+
TODO: not allowing user to provide such specific package name
9090
For empty package, [-bs-package-output] does not make sense
9191
it is only allowed to generate commonjs file in the same directory
9292
*)
@@ -163,7 +163,7 @@ let query_package_infos ({name; module_systems} : t)
163163
with
164164
| Some k ->
165165
let rel_path = k.path in
166-
let pkg_rel_path = Bs_version.package_name // rel_path in
166+
let pkg_rel_path = Runtime_package.name // rel_path in
167167
Package_found {rel_path; pkg_rel_path; suffix = k.suffix}
168168
| None -> Package_not_found)
169169

compiler/core/res_compmisc.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525
let init_path () =
26-
let dirs = !Clflags.include_dirs in
27-
let exp_dirs =
28-
List.map (Misc.expand_directory Config.standard_library) dirs
26+
let stdlib_dir =
27+
let ( // ) = Filename.concat in
28+
Runtime_package.path // "lib" // "ocaml"
2929
in
30+
let dirs = !Clflags.include_dirs in
31+
let exp_dirs = List.map (Misc.expand_directory stdlib_dir) dirs in
3032
Config.load_path :=
3133
if !Js_config.no_stdlib then exp_dirs
32-
else List.rev_append exp_dirs [Config.standard_library];
34+
else List.rev_append exp_dirs [stdlib_dir];
3335
Env.reset_cache ()
3436

3537
(* Return the initial environment in which compilation proceeds. *)

compiler/ext/config.ml

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,3 @@
1-
(* This resolves the location of the standard library starting from the location of bsc.exe
2-
(@rescript/{platform}/bin/bsc.exe), handling different supported package layouts. *)
3-
let runtime_module_path =
4-
let build_path rest path =
5-
String.concat Filename.dir_sep (List.rev_append rest path)
6-
in
7-
match
8-
Sys.executable_name |> Filename.dirname
9-
|> String.split_on_char Filename.dir_sep.[0]
10-
|> List.rev
11-
with
12-
(* 1. Packages installed via pnpm
13-
- bin: node_modules/.pnpm/@[email protected]/node_modules/@rescript/darwin-arm64/bin
14-
- runtime: node_modules/.pnpm/node_modules/@rescript/runtime (symlink)
15-
*)
16-
| "bin" :: _platform :: "@rescript" :: "node_modules" :: _package :: ".pnpm"
17-
:: "node_modules" :: rest ->
18-
build_path rest
19-
["node_modules"; ".pnpm"; "node_modules"; "@rescript"; "runtime"]
20-
(* 2. Packages installed via npm
21-
- bin: node_modules/@rescript/{platform}/bin
22-
- runtime: node_modules/@rescript/runtime
23-
*)
24-
| "bin" :: _platform :: "@rescript" :: "node_modules" :: rest ->
25-
build_path rest ["node_modules"; "@rescript"; "runtime"]
26-
(* 3. Several other cases that can occur in local development, e.g.
27-
- bin: <repo>/packages/@rescript/{platform}/bin, <repo>/_build/install/default/bin
28-
- runtime: <repo>/packages/@rescript/runtime
29-
*)
30-
| _ :: _ :: _ :: _ :: rest ->
31-
build_path rest ["packages"; "@rescript"; "runtime"]
32-
| _ -> ""
33-
34-
let standard_library =
35-
let ( // ) = Filename.concat in
36-
runtime_module_path // "lib" // "ocaml"
37-
381
let cmi_magic_number = "Caml1999I022"
392

403
and ast_impl_magic_number = "Caml1999M022"

compiler/ext/config.mli

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515

1616
(* System configuration *)
1717

18-
(* The directory containing the runtime module (@rescript/runtime) *)
19-
val runtime_module_path : string
20-
21-
(* The directory containing the runtime artifacts (@rescript/runtime/lib/ocaml) *)
22-
val standard_library : string
23-
2418
(* Directories in the search path for .cmi and .cmo files *)
2519
val load_path : string list ref
2620

compiler/ext/runtime_package.ml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
let name = "@rescript/runtime"
2+
3+
(* This resolves the location of the standard library starting from the location of bsc.exe
4+
(@rescript/{platform}/bin/bsc.exe), handling different supported package layouts. *)
5+
let path =
6+
let build_path rest path =
7+
String.concat Filename.dir_sep (List.rev_append rest path)
8+
in
9+
match
10+
Sys.executable_name |> Filename.dirname
11+
|> String.split_on_char Filename.dir_sep.[0]
12+
|> List.rev
13+
with
14+
(* 1. Packages installed via pnpm
15+
- bin: node_modules/.pnpm/@[email protected]/node_modules/@rescript/darwin-arm64/bin
16+
- runtime: node_modules/.pnpm/node_modules/@rescript/runtime (symlink)
17+
*)
18+
| "bin" :: _platform :: "@rescript" :: "node_modules" :: _package :: ".pnpm"
19+
:: "node_modules" :: rest ->
20+
build_path rest
21+
["node_modules"; ".pnpm"; "node_modules"; "@rescript"; "runtime"]
22+
(* 2. Packages installed via npm
23+
- bin: node_modules/@rescript/{platform}/bin
24+
- runtime: node_modules/@rescript/runtime
25+
*)
26+
| "bin" :: _platform :: "@rescript" :: "node_modules" :: rest ->
27+
build_path rest ["node_modules"; "@rescript"; "runtime"]
28+
(* 3. Several other cases that can occur in local development, e.g.
29+
- bin: <repo>/packages/@rescript/{platform}/bin, <repo>/_build/install/default/bin
30+
- runtime: <repo>/packages/@rescript/runtime
31+
*)
32+
| _ :: _ :: _ :: _ :: rest ->
33+
build_path rest ["packages"; "@rescript"; "runtime"]
34+
| _ -> ""

0 commit comments

Comments
 (0)