fix: honor devEngines.packageManager.onFail=error (#252)

Export pnpm_config_pm_on_fail=download so the bootstrap pnpm switches to
the version pinned in devEngines.packageManager instead of throwing
BAD_PM_VERSION on the user's first invocation.
This commit is contained in:
Zoltan Kochan
2026-05-10 23:30:57 +02:00
parent 91ab88e261
commit 052c4ffb7d
3 changed files with 123 additions and 67 deletions

View File

@@ -298,6 +298,57 @@ jobs:
fi
shell: bash
test_dev_engines_on_fail_error:
name: 'Test devEngines.packageManager with onFail=error (${{ matrix.version }}, ${{ matrix.os }})'
# Regression test for #252: with devEngines.packageManager.onFail="error" and no
# `version:` input, the user's first `pnpm` call hit BAD_PM_VERSION because the
# bootstrap version didn't match. The action now exports
# pnpm_config_pm_on_fail=download so pnpm switches versions instead of erroring.
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
version:
- '9.15.5'
- '>=9.15.0'
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Set up package.json with devEngines.packageManager onFail=error
run: echo '{"devEngines":{"packageManager":{"name":"pnpm","version":"${{ matrix.version }}","onFail":"error"}}}' > package.json
shell: bash
- name: Run the action
uses: ./
- name: 'Test: version'
run: |
set -e
required='${{ matrix.version }}'
actual="$(pnpm --version)"
echo "pnpm version: ${actual}"
if [ "${required}" = ">=9.15.0" ]; then
min="9.15.0"
if [ "$(printf '%s\n' "${min}" "${actual}" | sort -V | head -n1)" != "${min}" ]; then
echo "Expected pnpm version >= ${min}, but got ${actual}"
exit 1
fi
else
if [ "${actual}" != "${required}" ]; then
echo "Expected pnpm version ${required}, but got ${actual}"
exit 1
fi
fi
shell: bash
test_run_install:
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'

134
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -67,6 +67,11 @@ export async function runSelfInstaller(inputs: Inputs): Promise<SelfInstallerRes
addPath(pnpmHome)
addPath(path.join(pnpmHome, 'bin'))
exportVariable('PNPM_HOME', pnpmHome)
// Force pnpm to honor manage-package-manager-versions even when the project
// pins `devEngines.packageManager.onFail = "error"`. Without this override
// the bootstrap pnpm errors with BAD_PM_VERSION instead of switching to the
// requested version on the user's first invocation (issue #252).
exportVariable('pnpm_config_pm_on_fail', 'download')
// Ensure pnpm bin link exists — npm ci sometimes doesn't create it
if (process.platform !== 'win32') {