Skip to content

Commit 739bfe4

Browse files
authored
fix: self-update bootstrap to packageManager-pinned version (#233) (#256)
* fix: self-update bootstrap to packageManager-pinned version (#233) When package.json pins pnpm via `packageManager` or an exact `devEngines.packageManager.version`, self-update the bootstrap up front. The bootstrap's `pnpm store path` skips pnpm's auto-switch (the `store` command sets `skipPackageManagerCheck = true`), so it reports the bootstrap's `STORE_VERSION` while the user's actual install runs under the pinned version and writes to a different STORE_VERSION — breaking `cache: true` and `setup-node`'s `cache: pnpm` on cold caches. * fix: check bin/ dir instead of pnpm.exe for self-update detection On Windows pnpm self-update writes `.bin/bin/pnpm` (a JS launcher), not `.bin/bin/pnpm.exe`, so the previous existsSync probe always fell back to pnpmHome and the bin_dest output pointed at the bootstrap pnpm. Check whether the `bin` directory itself exists. * fix: self-update accepts ranges; drop exact-semver gate `pnpm self-update` resolves semver ranges to a specific version, so `devEngines.packageManager.version: ">=10 <11"` can also go through the self-update path. That makes readTargetVersion total — it always returns a string or throws — so the runtime auto-switch fallback (and the `pnpm_config_pm_on_fail=download` export from #252) is no longer reachable and gets removed. Adds a range case to the cache_store_path matrix.
1 parent f61705d commit 739bfe4

3 files changed

Lines changed: 191 additions & 137 deletions

File tree

.github/workflows/test.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,54 @@ jobs:
194194
pnpm add is-odd
195195
shell: bash
196196

197+
cache_store_path:
198+
# Regression guard for #233. When package.json pins a pnpm major that
199+
# differs from the bootstrap pnpm's major, the bootstrap reports its
200+
# own STORE_VERSION from `pnpm store path` (the `store` command skips
201+
# pnpm's auto-switch). The user's actual `pnpm install` runs under the
202+
# pinned version and writes to a different STORE_VERSION, so the post
203+
# step's saveCache then fails with "Path Validation Error". The fix is
204+
# to self-update the bootstrap to the pinned version up front.
205+
name: 'Cache store path matches install (#233): ${{ matrix.label }}'
206+
207+
runs-on: ubuntu-latest
208+
209+
strategy:
210+
fail-fast: false
211+
matrix:
212+
include:
213+
- label: 'packageManager pnpm@10.33.0'
214+
manifest: '{"packageManager":"pnpm@10.33.0","dependencies":{"is-odd":"3.0.1"}}'
215+
- label: 'devEngines exact pnpm@10.33.0'
216+
manifest: '{"devEngines":{"packageManager":{"name":"pnpm","version":"10.33.0"}},"dependencies":{"is-odd":"3.0.1"}}'
217+
- label: 'devEngines range >=10 <11'
218+
manifest: '{"devEngines":{"packageManager":{"name":"pnpm","version":">=10 <11"}},"dependencies":{"is-odd":"3.0.1"}}'
219+
220+
steps:
221+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
222+
223+
- name: Set up package.json
224+
run: echo '${{ matrix.manifest }}' > package.json
225+
shell: bash
226+
227+
- id: pnpm
228+
uses: ./
229+
with:
230+
cache: true
231+
run_install: |
232+
- args: [--no-frozen-lockfile]
233+
234+
- name: 'Test: store path computed by the action exists on disk'
235+
run: |
236+
set -e
237+
actual="$(pnpm store path --silent)"
238+
echo "pnpm store path: ${actual}"
239+
if [ ! -d "${actual}" ]; then
240+
echo "Expected store path to exist on disk; cache save would fail"
241+
exit 1
242+
fi
243+
shell: bash
244+
197245
run_install:
198246
name: 'run_install (${{ matrix.run_install.name }})'
199247

0 commit comments

Comments
 (0)