Skip to content

Fix finding the standard library for pnpm #7615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 84 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ jobs:
git commit -m "Update API docs for ${{ github.ref_name }}"
git push

test-integration:
test-installation-npm:
needs:
- pkg-pr-new
strategy:
Expand Down Expand Up @@ -573,6 +573,86 @@ jobs:
shell: bash
working-directory: ${{ steps.tmp-dir.outputs.path }}

test-installation-pnpm:
needs:
- pkg-pr-new
strategy:
fail-fast: false
matrix:
include:
- os: macos-13
- os: macos-14
- os: ubuntu-24.04
- os: ubuntu-24.04-arm
- os: windows-latest
runs-on: ${{ matrix.os }}
env:
RUST_BACKTRACE: "1"
steps:
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10

- name: Use Node.js
uses: actions/setup-node@v4
with:
# Run integration tests with the oldest supported node version.
node-version: 20

- name: Checkout
uses: actions/checkout@v4

- name: Make test directory
id: tmp-dir
shell: bash
run: |
if [[ "$RUNNER_OS" == "Windows" ]]; then
dir=$(powershell -Command "[System.IO.Path]::GetTempPath() + [System.Guid]::NewGuid().ToString()" | tr -d '\r')
mkdir -p "$dir"
else
dir=$(mktemp -d)
fi
echo "path=$dir" >> "$GITHUB_OUTPUT"
cp -r tests/package_tests/installation_test/* "$dir"

- name: Install ReScript package
run: |
COMMIT_SHA="${{ github.event.pull_request.head.sha || github.sha }}"
pnpm i "https://pkg.pr.new/rescript-lang/rescript@${COMMIT_SHA::7}"
shell: bash
working-directory: ${{ steps.tmp-dir.outputs.path }}

- name: Test installation
run: pnpm rescript -h && pnpm rescript legacy build && cat src/Test.res.js
shell: bash
working-directory: ${{ steps.tmp-dir.outputs.path }}

test-integration-rewatch:
needs:
- pkg-pr-new
strategy:
fail-fast: false
matrix:
include:
- os: macos-13
- os: macos-14
- os: ubuntu-24.04
- os: ubuntu-24.04-arm
- os: windows-latest
runs-on: ${{ matrix.os }}
env:
RUST_BACKTRACE: "1"
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
# Run integration tests with the oldest supported node version.
node-version: 20

- name: Install ReScript package in rewatch/testrepo
run: |
COMMIT_SHA="${{ github.event.pull_request.head.sha || github.sha }}"
Expand All @@ -586,7 +666,9 @@ jobs:

publish:
needs:
- test-integration
- test-installation-npm
- test-installation-pnpm
- test-integration-rewatch
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-24.04-arm
steps:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
- Rewatch: fix non-unicode stderr. https://github.com/rescript-lang/rescript/pull/7613
- Fix rewatch considering warning configs of non-local dependencies. https://github.com/rescript-lang/rescript/pull/7614
- Rewatch: fix panic if package.json name different from module name. https://github.com/rescript-lang/rescript/pull/7616
- Fix finding the standard library for pnpm. https://github.com/rescript-lang/rescript/pull/7615

#### :nail_care: Polish

Expand Down
46 changes: 29 additions & 17 deletions compiler/ext/config.ml
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
let version = "4.06.1+BS"

(* FIXME: Unreliable resolution *)
(* This resolves the location of the standard library starting from the location of bsc.exe,
handling different supported package layouts. *)
let standard_library =
let ( // ) = Filename.concat in
let exe_path = Sys.executable_name in
if Ext_string.contain_substring exe_path ("node_modules" // "@rescript") then
(* node_modules/@rescript/{platform}/bin *)
Filename.dirname exe_path // Filename.parent_dir_name
// Filename.parent_dir_name // Filename.parent_dir_name // "rescript"
// "lib" // "ocaml"
else if Ext_string.contain_substring exe_path ("node_modules" // "rescript")
then
(* node_modules/rescript/{platform} *)
Filename.dirname exe_path // Filename.parent_dir_name // "lib" // "ocaml"
else
(* git repo: rescript/packages/@rescript/{platform}/bin *)
Filename.dirname exe_path // Filename.parent_dir_name
// Filename.parent_dir_name // Filename.parent_dir_name
// Filename.parent_dir_name // "lib" // "ocaml"
let build_path rest path =
String.concat Filename.dir_sep (List.rev_append rest path)
in
match
Sys.executable_name |> Filename.dirname
|> String.split_on_char Filename.dir_sep.[0]
|> List.rev
with
(* 1. Packages installed via pnpm
- bin: node_modules/.pnpm/@rescript+darwin-arm64@12.0.0-alpha.13/node_modules/@rescript/darwin-arm64/bin
- stdlib: node_modules/rescript/lib/ocaml (symlink)
*)
| "bin" :: _platform :: "@rescript" :: "node_modules" :: _package :: ".pnpm"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tricky

:: "node_modules" :: rest ->
build_path rest ["node_modules"; "rescript"; "lib"; "ocaml"]
(* 2. Packages installed via npm
- bin: node_modules/@rescript/{platform}/bin
- stdlib: node_modules/rescript/lib/ocaml
*)
| "bin" :: _platform :: "@rescript" :: "node_modules" :: rest ->
build_path rest ["node_modules"; "rescript"; "lib"; "ocaml"]
(* 3. Several other cases that can occur in local development, e.g.
- bin: <repo>/packages/@rescript/{platform}/bin, <repo>/_build/install/default/bin
- stdlib: <repo>/lib/ocaml
*)
| _ :: _ :: _ :: _ :: rest -> build_path rest ["lib"; "ocaml"]
| _ -> ""

let standard_library_default = standard_library

Expand Down