Skip to content

Commit ce6e8ed

Browse files
authored
Fix finding the standard library for pnpm (#7615)
* Fix finding the standard library for pnpm * Add pnpm installation test and parallelize installation tests
1 parent 00cb4d0 commit ce6e8ed

File tree

3 files changed

+114
-19
lines changed

3 files changed

+114
-19
lines changed

.github/workflows/ci.yml

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ jobs:
522522
git commit -m "Update API docs for ${{ github.ref_name }}"
523523
git push
524524
525-
test-integration:
525+
test-installation-npm:
526526
needs:
527527
- pkg-pr-new
528528
strategy:
@@ -573,6 +573,86 @@ jobs:
573573
shell: bash
574574
working-directory: ${{ steps.tmp-dir.outputs.path }}
575575

576+
test-installation-pnpm:
577+
needs:
578+
- pkg-pr-new
579+
strategy:
580+
fail-fast: false
581+
matrix:
582+
include:
583+
- os: macos-13
584+
- os: macos-14
585+
- os: ubuntu-24.04
586+
- os: ubuntu-24.04-arm
587+
- os: windows-latest
588+
runs-on: ${{ matrix.os }}
589+
env:
590+
RUST_BACKTRACE: "1"
591+
steps:
592+
- name: Install pnpm
593+
uses: pnpm/action-setup@v4
594+
with:
595+
version: 10
596+
597+
- name: Use Node.js
598+
uses: actions/setup-node@v4
599+
with:
600+
# Run integration tests with the oldest supported node version.
601+
node-version: 20
602+
603+
- name: Checkout
604+
uses: actions/checkout@v4
605+
606+
- name: Make test directory
607+
id: tmp-dir
608+
shell: bash
609+
run: |
610+
if [[ "$RUNNER_OS" == "Windows" ]]; then
611+
dir=$(powershell -Command "[System.IO.Path]::GetTempPath() + [System.Guid]::NewGuid().ToString()" | tr -d '\r')
612+
mkdir -p "$dir"
613+
else
614+
dir=$(mktemp -d)
615+
fi
616+
echo "path=$dir" >> "$GITHUB_OUTPUT"
617+
cp -r tests/package_tests/installation_test/* "$dir"
618+
619+
- name: Install ReScript package
620+
run: |
621+
COMMIT_SHA="${{ github.event.pull_request.head.sha || github.sha }}"
622+
pnpm i "https://pkg.pr.new/rescript-lang/rescript@${COMMIT_SHA::7}"
623+
shell: bash
624+
working-directory: ${{ steps.tmp-dir.outputs.path }}
625+
626+
- name: Test installation
627+
run: pnpm rescript -h && pnpm rescript legacy build && cat src/Test.res.js
628+
shell: bash
629+
working-directory: ${{ steps.tmp-dir.outputs.path }}
630+
631+
test-integration-rewatch:
632+
needs:
633+
- pkg-pr-new
634+
strategy:
635+
fail-fast: false
636+
matrix:
637+
include:
638+
- os: macos-13
639+
- os: macos-14
640+
- os: ubuntu-24.04
641+
- os: ubuntu-24.04-arm
642+
- os: windows-latest
643+
runs-on: ${{ matrix.os }}
644+
env:
645+
RUST_BACKTRACE: "1"
646+
steps:
647+
- name: Checkout
648+
uses: actions/checkout@v4
649+
650+
- name: Use Node.js
651+
uses: actions/setup-node@v4
652+
with:
653+
# Run integration tests with the oldest supported node version.
654+
node-version: 20
655+
576656
- name: Install ReScript package in rewatch/testrepo
577657
run: |
578658
COMMIT_SHA="${{ github.event.pull_request.head.sha || github.sha }}"
@@ -586,7 +666,9 @@ jobs:
586666

587667
publish:
588668
needs:
589-
- test-integration
669+
- test-installation-npm
670+
- test-installation-pnpm
671+
- test-integration-rewatch
590672
if: startsWith(github.ref, 'refs/tags/v')
591673
runs-on: ubuntu-24.04-arm
592674
steps:

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)