mirror of
https://github.com/pnpm/action-setup.git
synced 2026-05-14 14:23:32 +08:00
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.
This commit is contained in:
2
.github/workflows/test.yaml
vendored
2
.github/workflows/test.yaml
vendored
@@ -214,6 +214,8 @@ jobs:
|
|||||||
manifest: '{"packageManager":"pnpm@10.33.0","dependencies":{"is-odd":"3.0.1"}}'
|
manifest: '{"packageManager":"pnpm@10.33.0","dependencies":{"is-odd":"3.0.1"}}'
|
||||||
- label: 'devEngines exact pnpm@10.33.0'
|
- label: 'devEngines exact pnpm@10.33.0'
|
||||||
manifest: '{"devEngines":{"packageManager":{"name":"pnpm","version":"10.33.0"}},"dependencies":{"is-odd":"3.0.1"}}'
|
manifest: '{"devEngines":{"packageManager":{"name":"pnpm","version":"10.33.0"}},"dependencies":{"is-odd":"3.0.1"}}'
|
||||||
|
- label: 'devEngines range >=10 <11'
|
||||||
|
manifest: '{"devEngines":{"packageManager":{"name":"pnpm","version":">=10 <11"}},"dependencies":{"is-odd":"3.0.1"}}'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||||
|
|||||||
142
dist/index.js
vendored
142
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -84,10 +84,9 @@ export async function runSelfInstaller(inputs: Inputs): Promise<SelfInstallerRes
|
|||||||
? path.join(dest, 'node_modules', '@pnpm', 'exe', process.platform === 'win32' ? 'pnpm.exe' : 'pnpm')
|
? path.join(dest, 'node_modules', '@pnpm', 'exe', process.platform === 'win32' ? 'pnpm.exe' : 'pnpm')
|
||||||
: path.join(dest, 'node_modules', 'pnpm', 'bin', 'pnpm.mjs')
|
: path.join(dest, 'node_modules', 'pnpm', 'bin', 'pnpm.mjs')
|
||||||
|
|
||||||
// Determine the target version
|
// Self-update the bootstrap to the requested pnpm version. readTargetVersion
|
||||||
|
// either returns a value or throws, so this always runs.
|
||||||
const targetVersion = readTargetVersion({ version, packageJsonFile })
|
const targetVersion = readTargetVersion({ version, packageJsonFile })
|
||||||
|
|
||||||
if (targetVersion) {
|
|
||||||
const cmd = standalone ? bootstrapPnpm : process.execPath
|
const cmd = standalone ? bootstrapPnpm : process.execPath
|
||||||
const args = standalone ? ['self-update', targetVersion] : [bootstrapPnpm, 'self-update', targetVersion]
|
const args = standalone ? ['self-update', targetVersion] : [bootstrapPnpm, 'self-update', targetVersion]
|
||||||
const exitCode = await runCommand(cmd, args, { cwd: dest })
|
const exitCode = await runCommand(cmd, args, { cwd: dest })
|
||||||
@@ -99,28 +98,17 @@ export async function runSelfInstaller(inputs: Inputs): Promise<SelfInstallerRes
|
|||||||
// PNPM_HOME/bin so consumers of the bin_dest output (e.g.
|
// PNPM_HOME/bin so consumers of the bin_dest output (e.g.
|
||||||
// `${steps.pnpm.outputs.bin_dest}/pnpm`) invoke the requested version.
|
// `${steps.pnpm.outputs.bin_dest}/pnpm`) invoke the requested version.
|
||||||
//
|
//
|
||||||
// When the requested version equals the bootstrap version, self-update
|
// When the requested version resolves to the bootstrap version, self-update
|
||||||
// is a no-op and PNPM_HOME/bin is not created — fall back to pnpmHome,
|
// is a no-op and PNPM_HOME/bin is not created — fall back to pnpmHome,
|
||||||
// whose symlinks already point at the right version.
|
// whose symlinks already point at the right version.
|
||||||
const updatedBinDir = path.join(pnpmHome, 'bin')
|
const updatedBinDir = path.join(pnpmHome, 'bin')
|
||||||
return { exitCode: 0, binDest: existsSync(updatedBinDir) ? updatedBinDir : pnpmHome }
|
return { exitCode: 0, binDest: existsSync(updatedBinDir) ? updatedBinDir : pnpmHome }
|
||||||
}
|
|
||||||
|
|
||||||
// No exact target version we can self-update to (devEngines pins a
|
|
||||||
// semver range, or nothing is pinned at all). Rely on the bootstrap
|
|
||||||
// pnpm to switch versions at runtime. Force `pmOnFail=download` so a
|
|
||||||
// project that pins `devEngines.packageManager.onFail = "error"` doesn't
|
|
||||||
// trip BAD_PM_VERSION before the switch can happen (issue #252). Scoped
|
|
||||||
// to this branch so users who pass an explicit `version:` input keep
|
|
||||||
// strict onFail behavior.
|
|
||||||
exportVariable('pnpm_config_pm_on_fail', 'download')
|
|
||||||
return { exitCode: 0, binDest: pnpmHome }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function readTargetVersion(opts: {
|
function readTargetVersion(opts: {
|
||||||
readonly version?: string | undefined
|
readonly version?: string | undefined
|
||||||
readonly packageJsonFile: string
|
readonly packageJsonFile: string
|
||||||
}): string | undefined {
|
}): string {
|
||||||
const { version, packageJsonFile } = opts
|
const { version, packageJsonFile } = opts
|
||||||
const { GITHUB_WORKSPACE } = process.env
|
const { GITHUB_WORKSPACE } = process.env
|
||||||
|
|
||||||
@@ -167,15 +155,10 @@ Remove one of these versions to avoid version mismatch errors like ERR_PNPM_BAD_
|
|||||||
// `cache: pnpm` on cold caches (issue #233).
|
// `cache: pnpm` on cold caches (issue #233).
|
||||||
//
|
//
|
||||||
// devEngines.packageManager takes priority over packageManager, matching
|
// devEngines.packageManager takes priority over packageManager, matching
|
||||||
// pnpm's getWantedPackageManager logic. devEngines.packageManager.version
|
// pnpm's getWantedPackageManager logic. `pnpm self-update` accepts both
|
||||||
// can be a semver range; `pnpm self-update` needs a specific version, so
|
// exact versions and semver ranges, so we pass either through directly.
|
||||||
// for ranges we fall through to the bootstrap auto-switch path.
|
if (devEngines?.packageManager?.name === 'pnpm' && devEngines.packageManager.version) {
|
||||||
if (devEngines?.packageManager?.name === 'pnpm') {
|
return devEngines.packageManager.version
|
||||||
const v = devEngines.packageManager.version
|
|
||||||
if (v != null && isExactSemver(v)) {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
return undefined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packageManagerVersion) {
|
if (packageManagerVersion) {
|
||||||
@@ -196,10 +179,6 @@ Please specify it by one of the following ways:
|
|||||||
- in the package.json with the key "devEngines.packageManager"`)
|
- in the package.json with the key "devEngines.packageManager"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isExactSemver(v: string): boolean {
|
|
||||||
return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.test(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSystemNodeVersion(): Promise<{ major: number; minor: number }> {
|
function getSystemNodeVersion(): Promise<{ major: number; minor: number }> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const cp = spawn('node', ['--version'], { stdio: ['pipe', 'pipe', 'pipe'], shell: process.platform === 'win32' })
|
const cp = spawn('node', ['--version'], { stdio: ['pipe', 'pipe', 'pipe'], shell: process.platform === 'win32' })
|
||||||
|
|||||||
Reference in New Issue
Block a user