mirror of
https://github.com/pnpm/action-setup.git
synced 2026-04-04 19:42:36 +08:00
fix: overwrite npm .cmd wrappers for @pnpm/exe on Windows
npm creates .cmd wrappers that invoke bin entries through `node`, but @pnpm/exe bins are native executables, not JavaScript files. This causes pnpm commands to silently fail on Windows.
This commit is contained in:
131
dist/index.js
vendored
131
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -39,6 +39,18 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
|||||||
addPath(path.join(pnpmHome, 'bin'))
|
addPath(path.join(pnpmHome, 'bin'))
|
||||||
exportVariable('PNPM_HOME', pnpmHome)
|
exportVariable('PNPM_HOME', pnpmHome)
|
||||||
|
|
||||||
|
// On Windows, npm creates .cmd wrappers that invoke bin entries through
|
||||||
|
// `node`, but @pnpm/exe bins are native executables — not JavaScript.
|
||||||
|
// Overwrite the wrappers to invoke the binaries directly.
|
||||||
|
if (process.platform === 'win32' && standalone) {
|
||||||
|
for (const name of ['pnpm', 'pnpx']) {
|
||||||
|
await writeFile(
|
||||||
|
path.join(pnpmHome, `${name}.cmd`),
|
||||||
|
`@"%~dp0\\..\\@pnpm\\exe\\${name}" %*\r\n`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure pnpm bin link exists — npm ci sometimes doesn't create it
|
// Ensure pnpm bin link exists — npm ci sometimes doesn't create it
|
||||||
const pnpmBinLink = path.join(pnpmHome, 'pnpm')
|
const pnpmBinLink = path.join(pnpmHome, 'pnpm')
|
||||||
if (!existsSync(pnpmBinLink)) {
|
if (!existsSync(pnpmBinLink)) {
|
||||||
@@ -57,8 +69,21 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
|||||||
const targetVersion = readTargetVersion({ version, packageJsonFile })
|
const targetVersion = readTargetVersion({ version, packageJsonFile })
|
||||||
|
|
||||||
if (targetVersion) {
|
if (targetVersion) {
|
||||||
const cmd = standalone ? bootstrapPnpm : process.execPath
|
let cmd: string
|
||||||
const args = standalone ? ['self-update', targetVersion] : [bootstrapPnpm, 'self-update', targetVersion]
|
let args: string[]
|
||||||
|
if (standalone) {
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
// Use the corrected .cmd wrapper on Windows
|
||||||
|
cmd = path.join(pnpmHome, 'pnpm.cmd')
|
||||||
|
args = ['self-update', targetVersion]
|
||||||
|
} else {
|
||||||
|
cmd = bootstrapPnpm
|
||||||
|
args = ['self-update', targetVersion]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cmd = process.execPath
|
||||||
|
args = [bootstrapPnpm, 'self-update', targetVersion]
|
||||||
|
}
|
||||||
const exitCode = await runCommand(cmd, args, { cwd: dest })
|
const exitCode = await runCommand(cmd, args, { cwd: dest })
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
return exitCode
|
return exitCode
|
||||||
|
|||||||
Reference in New Issue
Block a user