mirror of
https://gh.hjkl01.cn/https://github.com/pnpm/action-setup
synced 2026-05-30 12:35:22 +08:00
`patchPnpmEnv` prepended `dest/node_modules/.bin` to PATH before
spawning `pnpm install` / `pnpm store prune`. On Windows in standalone
mode, `.bin/pnpm.cmd` is an npm-created shim that always points at the
BOOTSTRAP pnpm (currently 11.0.4) — the binary npm linked when it
installed `@pnpm/exe` into `node_modules`. The self-updated pnpm
written by `pnpm self-update` lives at `$PNPM_HOME/bin`, which is
separately added to PATH via `addPath()` in install-pnpm.
When the user requested a pnpm version different from the bootstrap
under `standalone: true` on Windows, patchPnpmEnv's `.bin` entry
shadowed the self-updated `$PNPM_HOME/bin` and the action's internal
`pnpm install` ran on the bootstrap. On a pnpm 11.0.x bootstrap this
broke any 11.1+ install flag (e.g. `--no-runtime`), reporting:
ERROR Unknown option: 'runtime'
POSIX standalone got lucky because `.bin` and `$PNPM_HOME` resolve to
the same directory there. Non-standalone never tripped on this since
the `.bin/pnpm` symlink for a regular `pnpm` package keeps working
across self-updates.
Removed `patchPnpmEnv` and the now-empty `src/utils/` module.
`spawnSync` now inherits `process.env`, whose PATH is already
correctly fronted by `$PNPM_HOME/bin` and `$PNPM_HOME` via the
`addPath` calls in install-pnpm.
Added `standalone_windows_self_update` to test.yaml as a regression
guard: standalone on Windows + target 11.1.0 + `run_install` with
`--no-runtime`. With the previous code, the install would have run
under the bootstrap (11.0.4) and errored on the unknown flag.
Originally found while building pnpm/setup (the new combined
pnpm + runtime action).
32 lines
773 B
TypeScript
32 lines
773 B
TypeScript
import { warning, startGroup, endGroup } from '@actions/core'
|
|
import { spawnSync } from 'child_process'
|
|
import { Inputs } from '../inputs'
|
|
|
|
export function pruneStore(inputs: Inputs) {
|
|
if (inputs.runInstall.length === 0) {
|
|
console.log('Pruning is unnecessary.')
|
|
return
|
|
}
|
|
|
|
startGroup('Running pnpm store prune...')
|
|
// spawnSync inherits process.env (which has the right PATH from addPath
|
|
// in install-pnpm). See pnpm-install/index.ts for the rationale.
|
|
const { error, status } = spawnSync('pnpm', ['store', 'prune'], {
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
})
|
|
endGroup()
|
|
|
|
if (error) {
|
|
warning(error)
|
|
return
|
|
}
|
|
|
|
if (status) {
|
|
warning(`command pnpm store prune exits with code ${status}`)
|
|
return
|
|
}
|
|
}
|
|
|
|
export default pruneStore
|