mirror of
https://github.com/pnpm/action-setup.git
synced 2026-05-14 22:33:32 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b635341b3e | ||
|
|
025de3876f | ||
|
|
5c388c2b3b | ||
|
|
84fa52c3d7 | ||
|
|
07ad39cba4 | ||
|
|
052c4ffb7d |
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
@@ -1 +0,0 @@
|
||||
* @zkochan
|
||||
48
.github/workflows/test.yaml
vendored
48
.github/workflows/test.yaml
vendored
@@ -194,54 +194,6 @@ jobs:
|
||||
pnpm add is-odd
|
||||
shell: bash
|
||||
|
||||
cache_store_path:
|
||||
# Regression guard for #233. When package.json pins a pnpm major that
|
||||
# differs from the bootstrap pnpm's major, the bootstrap reports its
|
||||
# own STORE_VERSION from `pnpm store path` (the `store` command skips
|
||||
# pnpm's auto-switch). The user's actual `pnpm install` runs under the
|
||||
# pinned version and writes to a different STORE_VERSION, so the post
|
||||
# step's saveCache then fails with "Path Validation Error". The fix is
|
||||
# to self-update the bootstrap to the pinned version up front.
|
||||
name: 'Cache store path matches install (#233): ${{ matrix.label }}'
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- label: 'packageManager pnpm@10.33.0'
|
||||
manifest: '{"packageManager":"pnpm@10.33.0","dependencies":{"is-odd":"3.0.1"}}'
|
||||
- label: 'devEngines exact pnpm@10.33.0'
|
||||
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:
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||
|
||||
- name: Set up package.json
|
||||
run: echo '${{ matrix.manifest }}' > package.json
|
||||
shell: bash
|
||||
|
||||
- id: pnpm
|
||||
uses: ./
|
||||
with:
|
||||
cache: true
|
||||
run_install: |
|
||||
- args: [--no-frozen-lockfile]
|
||||
|
||||
- name: 'Test: store path computed by the action exists on disk'
|
||||
run: |
|
||||
set -e
|
||||
actual="$(pnpm store path --silent)"
|
||||
echo "pnpm store path: ${actual}"
|
||||
if [ ! -d "${actual}" ]; then
|
||||
echo "Expected store path to exist on disk; cache save would fail"
|
||||
exit 1
|
||||
fi
|
||||
shell: bash
|
||||
|
||||
run_install:
|
||||
name: 'run_install (${{ matrix.run_install.name }})'
|
||||
|
||||
|
||||
234
dist/index.js
vendored
234
dist/index.js
vendored
File diff suppressed because one or more lines are too long
13
src/index.ts
13
src/index.ts
@@ -8,16 +8,16 @@ import pnpmInstall from './pnpm-install'
|
||||
import pruneStore from './pnpm-store-prune'
|
||||
|
||||
async function main() {
|
||||
const inputs = getInputs()
|
||||
|
||||
if (getState('is_post') === 'true') {
|
||||
await runPost()
|
||||
await runPost(inputs)
|
||||
} else {
|
||||
await runMain()
|
||||
await runMain(inputs)
|
||||
}
|
||||
}
|
||||
|
||||
async function runMain() {
|
||||
const inputs = getInputs()
|
||||
saveState('inputs', inputs)
|
||||
async function runMain(inputs: Inputs) {
|
||||
saveState('is_post', 'true')
|
||||
|
||||
const binDest = await installPnpm(inputs)
|
||||
@@ -30,8 +30,7 @@ async function runMain() {
|
||||
pnpmInstall(inputs)
|
||||
}
|
||||
|
||||
async function runPost() {
|
||||
const inputs = JSON.parse(getState('inputs')) as Inputs
|
||||
async function runPost(inputs: Inputs) {
|
||||
pruneStore(inputs)
|
||||
await saveCache(inputs)
|
||||
}
|
||||
|
||||
@@ -84,31 +84,37 @@ 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', 'bin', 'pnpm.mjs')
|
||||
|
||||
// Self-update the bootstrap to the requested pnpm version. readTargetVersion
|
||||
// either returns a value or throws, so this always runs.
|
||||
// Determine the target version
|
||||
const targetVersion = readTargetVersion({ version, packageJsonFile })
|
||||
const cmd = standalone ? bootstrapPnpm : process.execPath
|
||||
const args = standalone ? ['self-update', targetVersion] : [bootstrapPnpm, 'self-update', targetVersion]
|
||||
const exitCode = await runCommand(cmd, args, { cwd: dest })
|
||||
if (exitCode !== 0) {
|
||||
return { exitCode, binDest: pnpmHome }
|
||||
|
||||
if (targetVersion) {
|
||||
const cmd = standalone ? bootstrapPnpm : process.execPath
|
||||
const args = standalone ? ['self-update', targetVersion] : [bootstrapPnpm, 'self-update', targetVersion]
|
||||
const exitCode = await runCommand(cmd, args, { cwd: dest })
|
||||
if (exitCode !== 0) {
|
||||
return { exitCode, binDest: pnpmHome }
|
||||
}
|
||||
// self-update writes the target pnpm/pnpx into PNPM_HOME/bin, leaving
|
||||
// the bootstrap symlinks in pnpmHome pointing at the old version. Use
|
||||
// PNPM_HOME/bin so consumers of the bin_dest output (e.g.
|
||||
// `${steps.pnpm.outputs.bin_dest}/pnpm`) invoke the requested version.
|
||||
return { exitCode: 0, binDest: path.join(pnpmHome, 'bin') }
|
||||
}
|
||||
// self-update writes the target pnpm/pnpx into PNPM_HOME/bin, leaving
|
||||
// the bootstrap symlinks in pnpmHome pointing at the old version. Use
|
||||
// PNPM_HOME/bin so consumers of the bin_dest output (e.g.
|
||||
// `${steps.pnpm.outputs.bin_dest}/pnpm`) invoke the requested version.
|
||||
//
|
||||
// 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,
|
||||
// whose symlinks already point at the right version.
|
||||
const updatedBinDir = path.join(pnpmHome, 'bin')
|
||||
return { exitCode: 0, binDest: existsSync(updatedBinDir) ? updatedBinDir : pnpmHome }
|
||||
|
||||
// No explicit target version: rely on the bootstrap pnpm to switch to
|
||||
// the version declared in packageManager/devEngines 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: {
|
||||
readonly version?: string | undefined
|
||||
readonly packageJsonFile: string
|
||||
}): string {
|
||||
}): string | undefined {
|
||||
const { version, packageJsonFile } = opts
|
||||
const { GITHUB_WORKSPACE } = process.env
|
||||
|
||||
@@ -129,15 +135,12 @@ function readTargetVersion(opts: {
|
||||
}
|
||||
}
|
||||
|
||||
// packageManager is always exact `pnpm@<version>[+<integrity>]` per spec.
|
||||
// Strip the integrity hash for self-update.
|
||||
const packageManagerVersion =
|
||||
typeof packageManager === 'string' && packageManager.startsWith('pnpm@')
|
||||
? packageManager.slice('pnpm@'.length).split('+')[0]
|
||||
: undefined
|
||||
|
||||
if (version) {
|
||||
if (packageManagerVersion && packageManagerVersion !== version) {
|
||||
if (
|
||||
typeof packageManager === 'string' &&
|
||||
packageManager.startsWith('pnpm@') &&
|
||||
packageManager.replace('pnpm@', '') !== version
|
||||
) {
|
||||
throw new Error(`Multiple versions of pnpm specified:
|
||||
- version ${version} in the GitHub Action config with the key "version"
|
||||
- version ${packageManager} in the package.json with the key "packageManager"
|
||||
@@ -147,22 +150,13 @@ Remove one of these versions to avoid version mismatch errors like ERR_PNPM_BAD_
|
||||
return version
|
||||
}
|
||||
|
||||
// Self-update the bootstrap pnpm to the version pinned in package.json so
|
||||
// PATH-resolved `pnpm` (and the bin_dest output) reflect the target
|
||||
// version. Without this, `pnpm store path` runs as the bootstrap and
|
||||
// reports a different STORE_VERSION than the one the user's actual
|
||||
// install writes to — breaking cache: true and actions/setup-node's
|
||||
// `cache: pnpm` on cold caches (issue #233).
|
||||
//
|
||||
// devEngines.packageManager takes priority over packageManager, matching
|
||||
// pnpm's getWantedPackageManager logic. `pnpm self-update` accepts both
|
||||
// exact versions and semver ranges, so we pass either through directly.
|
||||
if (devEngines?.packageManager?.name === 'pnpm' && devEngines.packageManager.version) {
|
||||
return devEngines.packageManager.version
|
||||
// pnpm will automatically download and switch to the right version
|
||||
if (typeof packageManager === 'string' && packageManager.startsWith('pnpm@')) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
if (packageManagerVersion) {
|
||||
return packageManagerVersion
|
||||
if (devEngines?.packageManager?.name === 'pnpm' && devEngines.packageManager.version) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
if (!GITHUB_WORKSPACE) {
|
||||
|
||||
Reference in New Issue
Block a user