fix: ensure PNPM_HOME/bin is in PATH during pnpm setup

When upgrading from old pnpm (global bin = PNPM_HOME) to new pnpm
(global bin = PNPM_HOME/bin), `pnpm setup` would fail because the
spawned `pnpm add -g` checks that the global bin dir is in PATH.
Prepend PNPM_HOME/bin to PATH in the spawned process env so the
check passes during the transition.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Zoltan Kochan
2026-03-21 13:26:37 +01:00
parent 0ba71da576
commit bb9226cd98
3 changed files with 7 additions and 0 deletions

View File

@@ -50,6 +50,7 @@
"@pnpm/store.controller": "workspace:*",
"@pnpm/types": "workspace:*",
"@pnpm/workspace.project-manifest-reader": "workspace:*",
"path-name": "catalog:",
"ramda": "catalog:",
"render-help": "catalog:",
"semver": "catalog:",

View File

@@ -10,6 +10,7 @@ import {
type ConfigReport,
type PathExtenderReport,
} from '@pnpm/os.env.path-extender'
import PATH from 'path-name'
import { renderHelp } from 'render-help'
export const rcOptionsTypes = (): Record<string, unknown> => ({})
@@ -80,11 +81,13 @@ function installCliGlobally (execPath: string, pnpmHomeDir: string): void {
})
try {
const binDir = path.join(pnpmHomeDir, 'bin')
const { status, error } = spawnSync(execPath, ['add', '-g', `file:${execDir}`], {
stdio: 'inherit',
env: {
...process.env,
PNPM_HOME: pnpmHomeDir,
[PATH]: `${binDir}${path.delimiter}${process.env[PATH] ?? ''}`,
},
})

3
pnpm-lock.yaml generated
View File

@@ -3524,6 +3524,9 @@ importers:
'@pnpm/workspace.project-manifest-reader':
specifier: workspace:*
version: link:../../../workspace/project-manifest-reader
path-name:
specifier: 'catalog:'
version: 1.0.0
ramda:
specifier: 'catalog:'
version: '@pnpm/ramda@0.28.1'