diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 97e4d43f55..19914ee946 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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 }}" @@ -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: diff --git a/CHANGELOG.md b/CHANGELOG.md index 8768980bdd..90cbb57457 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/compiler/ext/config.ml b/compiler/ext/config.ml index 61edbcfde7..0df8d7c50b 100644 --- a/compiler/ext/config.ml +++ b/compiler/ext/config.ml @@ -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" + :: "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: /packages/@rescript/{platform}/bin, /_build/install/default/bin + - stdlib: /lib/ocaml + *) + | _ :: _ :: _ :: _ :: rest -> build_path rest ["lib"; "ocaml"] + | _ -> "" let standard_library_default = standard_library