Skip to content

Commit 437ed3a

Browse files
committed
Fix finding the standard library for pnpm
1 parent 00cb4d0 commit 437ed3a

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
- Rewatch: fix non-unicode stderr. https://github.com/rescript-lang/rescript/pull/7613
5252
- Fix rewatch considering warning configs of non-local dependencies. https://github.com/rescript-lang/rescript/pull/7614
5353
- Rewatch: fix panic if package.json name different from module name. https://github.com/rescript-lang/rescript/pull/7616
54+
- Fix finding the standard library for pnpm. https://github.com/rescript-lang/rescript/pull/7615
5455

5556
#### :nail_care: Polish
5657

compiler/ext/config.ml

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
let version = "4.06.1+BS"
22

3-
(* FIXME: Unreliable resolution *)
3+
(* This resolves the location of the standard library starting from the location of bsc.exe,
4+
handling different supported package layouts. *)
45
let standard_library =
5-
let ( // ) = Filename.concat in
6-
let exe_path = Sys.executable_name in
7-
if Ext_string.contain_substring exe_path ("node_modules" // "@rescript") then
8-
(* node_modules/@rescript/{platform}/bin *)
9-
Filename.dirname exe_path // Filename.parent_dir_name
10-
// Filename.parent_dir_name // Filename.parent_dir_name // "rescript"
11-
// "lib" // "ocaml"
12-
else if Ext_string.contain_substring exe_path ("node_modules" // "rescript")
13-
then
14-
(* node_modules/rescript/{platform} *)
15-
Filename.dirname exe_path // Filename.parent_dir_name // "lib" // "ocaml"
16-
else
17-
(* git repo: rescript/packages/@rescript/{platform}/bin *)
18-
Filename.dirname exe_path // Filename.parent_dir_name
19-
// Filename.parent_dir_name // Filename.parent_dir_name
20-
// Filename.parent_dir_name // "lib" // "ocaml"
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+
- stdlib: node_modules/rescript/lib/ocaml (symlink)
17+
*)
18+
| "bin" :: _platform :: "@rescript" :: "node_modules" :: _package :: ".pnpm"
19+
:: "node_modules" :: rest ->
20+
build_path rest ["node_modules"; "rescript"; "lib"; "ocaml"]
21+
(* 2. Packages installed via npm
22+
- bin: node_modules/@rescript/{platform}/bin
23+
- stdlib: node_modules/rescript/lib/ocaml
24+
*)
25+
| "bin" :: _platform :: "@rescript" :: "node_modules" :: rest ->
26+
build_path rest ["node_modules"; "rescript"; "lib"; "ocaml"]
27+
(* 3. Several other cases that can occur in local development, e.g.
28+
- bin: <repo>/packages/@rescript/{platform}/bin, <repo>/_build/install/default/bin
29+
- stdlib: <repo>/lib/ocaml
30+
*)
31+
| _ :: _ :: _ :: _ :: rest -> build_path rest ["lib"; "ocaml"]
32+
| _ -> ""
2133

2234
let standard_library_default = standard_library
2335

0 commit comments

Comments
 (0)