mirror of
https://github.com/pnpm/action-setup
synced 2026-04-03 19:41:13 +08:00
fix: Windows standalone mode — bypass broken npm shims (#217)
* 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. * fix: copy pnpm.exe to .bin/ on Windows for standalone mode The .cmd wrapper approach didn't work because CMD doesn't properly wait for extensionless PE binaries. Instead, copy the actual .exe (and .cmd for pnpx) from @pnpm/exe into .bin/ so PATHEXT finds pnpm.exe directly, bypassing npm's broken node-wrapping shim. * fix: add @pnpm/exe dir to PATH on Windows instead of .bin shims On Windows, npm's .bin shims can't properly execute the extensionless native binaries from @pnpm/exe. Instead of trying to fix the shims, add the @pnpm/exe directory directly to PATH where pnpm.exe lives. * test: validate pnpm --version output in CI All version checks now capture output and assert it matches a semver pattern. Previously, a silently failing pnpm (exit 0, no output) would pass the tests. * debug: log pnpm --version output during setup * fix: remove duplicate addPath in setOutputs that shadowed pnpm.exe setOutputs called addPath(node_modules/.bin) AFTER installPnpm had already added the correct path (@pnpm/exe on Windows). Since GITHUB_PATH entries are prepended, .bin ended up first in PATH, causing PowerShell to find npm's broken shims instead of pnpm.exe. * fix: add PNPM_HOME/bin to PATH on all platforms * fix: address review feedback — PATH ordering and regex anchoring - Swap addPath order so pnpmHome (with pnpm.exe) is prepended last and has highest precedence over pnpmHome/bin. - Anchor version regex with $ and allow prerelease suffixes.
This commit is contained in:
parent
994d756a33
commit
6b87c4621a
36
.github/workflows/test.yaml
vendored
36
.github/workflows/test.yaml
vendored
@ -33,7 +33,14 @@ jobs:
|
|||||||
run: which pnpm; which pnpx
|
run: which pnpm; which pnpx
|
||||||
|
|
||||||
- name: 'Test: version'
|
- name: 'Test: version'
|
||||||
run: pnpm --version
|
run: |
|
||||||
|
actual="$(pnpm --version)"
|
||||||
|
echo "pnpm version: ${actual}"
|
||||||
|
if [[ ! "${actual}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
|
||||||
|
echo "ERROR: pnpm --version did not produce valid output"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|
||||||
- name: 'Test: install in a fresh project'
|
- name: 'Test: install in a fresh project'
|
||||||
run: |
|
run: |
|
||||||
@ -71,7 +78,14 @@ jobs:
|
|||||||
run: which pnpm && which pnpx
|
run: which pnpm && which pnpx
|
||||||
|
|
||||||
- name: 'Test: version'
|
- name: 'Test: version'
|
||||||
run: pnpm --version
|
run: |
|
||||||
|
actual="$(pnpm --version)"
|
||||||
|
echo "pnpm version: ${actual}"
|
||||||
|
if [[ ! "${actual}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
|
||||||
|
echo "ERROR: pnpm --version did not produce valid output"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|
||||||
test_standalone:
|
test_standalone:
|
||||||
name: Test with standalone
|
name: Test with standalone
|
||||||
@ -98,7 +112,14 @@ jobs:
|
|||||||
run: which pnpm
|
run: which pnpm
|
||||||
|
|
||||||
- name: 'Test: version'
|
- name: 'Test: version'
|
||||||
run: pnpm --version
|
run: |
|
||||||
|
actual="$(pnpm --version)"
|
||||||
|
echo "pnpm version: ${actual}"
|
||||||
|
if [[ ! "${actual}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
|
||||||
|
echo "ERROR: pnpm --version did not produce valid output"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|
||||||
- name: 'Test: install in a fresh project'
|
- name: 'Test: install in a fresh project'
|
||||||
run: |
|
run: |
|
||||||
@ -196,4 +217,11 @@ jobs:
|
|||||||
run: which pnpm; which pnpx
|
run: which pnpm; which pnpx
|
||||||
|
|
||||||
- name: 'Test: version'
|
- name: 'Test: version'
|
||||||
run: pnpm --version
|
run: |
|
||||||
|
actual="$(pnpm --version)"
|
||||||
|
echo "pnpm version: ${actual}"
|
||||||
|
if [[ ! "${actual}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
|
||||||
|
echo "ERROR: pnpm --version did not produce valid output"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|||||||
222
dist/index.js
vendored
222
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@ -34,23 +34,33 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
|||||||
return npmExitCode
|
return npmExitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
const pnpmHome = path.join(dest, 'node_modules', '.bin')
|
// On Windows with standalone mode, npm's .bin shims can't properly
|
||||||
addPath(pnpmHome)
|
// execute the extensionless @pnpm/exe native binaries. Add the
|
||||||
|
// @pnpm/exe directory directly to PATH so pnpm.exe is found natively.
|
||||||
|
const pnpmHome = standalone && process.platform === 'win32'
|
||||||
|
? path.join(dest, 'node_modules', '@pnpm', 'exe')
|
||||||
|
: path.join(dest, 'node_modules', '.bin')
|
||||||
|
// pnpm expects PNPM_HOME/bin in PATH for global binaries (e.g. node
|
||||||
|
// installed via `pnpm runtime`). Add it first so the next addPath
|
||||||
|
// (pnpmHome itself, which contains pnpm.exe) has higher precedence.
|
||||||
addPath(path.join(pnpmHome, 'bin'))
|
addPath(path.join(pnpmHome, 'bin'))
|
||||||
|
addPath(pnpmHome)
|
||||||
exportVariable('PNPM_HOME', pnpmHome)
|
exportVariable('PNPM_HOME', pnpmHome)
|
||||||
|
|
||||||
// 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')
|
if (process.platform !== 'win32') {
|
||||||
if (!existsSync(pnpmBinLink)) {
|
const pnpmBinLink = path.join(dest, 'node_modules', '.bin', 'pnpm')
|
||||||
await mkdir(pnpmHome, { recursive: true })
|
if (!existsSync(pnpmBinLink)) {
|
||||||
const target = standalone
|
await mkdir(path.join(dest, 'node_modules', '.bin'), { recursive: true })
|
||||||
? path.join('..', '@pnpm', 'exe', 'pnpm')
|
const target = standalone
|
||||||
: path.join('..', 'pnpm', 'bin', 'pnpm.mjs')
|
? path.join('..', '@pnpm', 'exe', 'pnpm')
|
||||||
await symlink(target, pnpmBinLink)
|
: path.join('..', 'pnpm', 'bin', 'pnpm.mjs')
|
||||||
|
await symlink(target, pnpmBinLink)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const bootstrapPnpm = standalone
|
const bootstrapPnpm = standalone
|
||||||
? path.join(dest, 'node_modules', '@pnpm', 'exe', 'pnpm')
|
? path.join(dest, 'node_modules', '@pnpm', 'exe', process.platform === 'win32' ? 'pnpm.exe' : 'pnpm')
|
||||||
: path.join(dest, 'node_modules', 'pnpm', 'bin', 'pnpm.mjs')
|
: path.join(dest, 'node_modules', 'pnpm', 'bin', 'pnpm.mjs')
|
||||||
|
|
||||||
// Determine the target version
|
// Determine the target version
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
import { setOutput, addPath } from '@actions/core'
|
import { setOutput } from '@actions/core'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
import { getBinDest } from '../utils'
|
import { getBinDest } from '../utils'
|
||||||
|
|
||||||
export function setOutputs(inputs: Inputs) {
|
export function setOutputs(inputs: Inputs) {
|
||||||
const binDest = getBinDest(inputs)
|
const binDest = getBinDest(inputs)
|
||||||
addPath(binDest)
|
// NOTE: addPath is already called in installPnpm — do not call it again
|
||||||
|
// here, as a second addPath would shadow the correct entry on Windows.
|
||||||
setOutput('dest', inputs.dest)
|
setOutput('dest', inputs.dest)
|
||||||
setOutput('bin_dest', binDest)
|
setOutput('bin_dest', binDest)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user