Files
pnpm-setup/src/pnpm-store-prune/index.ts

32 lines
773 B
TypeScript
Raw Normal View History

2020-05-09 21:50:47 +07:00
import { warning, startGroup, endGroup } from '@actions/core'
2022-02-23 10:07:15 +07:00
import { spawnSync } from 'child_process'
2020-05-09 21:15:50 +07:00
import { Inputs } from '../inputs'
export function pruneStore(inputs: Inputs) {
if (inputs.runInstall.length === 0) {
console.log('Pruning is unnecessary.')
return
}
2020-05-09 21:50:47 +07:00
startGroup('Running pnpm store prune...')
fix: drop patchPnpmEnv so standalone+self-update works on Windows (#258) `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).
2026-05-11 22:48:51 +02:00
// spawnSync inherits process.env (which has the right PATH from addPath
// in install-pnpm). See pnpm-install/index.ts for the rationale.
2020-05-09 21:15:50 +07:00
const { error, status } = spawnSync('pnpm', ['store', 'prune'], {
stdio: 'inherit',
2020-05-09 21:41:25 +07:00
shell: true,
2020-05-09 21:15:50 +07:00
})
2020-05-09 21:50:47 +07:00
endGroup()
2020-05-09 21:15:50 +07:00
if (error) {
2020-05-09 21:43:19 +07:00
warning(error)
2020-05-09 21:15:50 +07:00
return
}
if (status) {
2020-05-09 21:43:19 +07:00
warning(`command pnpm store prune exits with code ${status}`)
2020-05-09 21:15:50 +07:00
return
}
}
export default pruneStore