fix: handle Windows with .cmd/.ps1 shims and add tests

- Extract ensureAliasLinks to its own module for testability
- On Windows, create .cmd and .ps1 shims instead of symlinks
- On Unix, create symlinks (as before)
- Skip alias creation when targets don't exist (pnpm v10)
- Add vitest and 8 tests covering unix/windows/skip/no-overwrite
This commit is contained in:
Zoltan Kochan
2026-03-26 18:41:05 +01:00
parent 747414e7da
commit 11687bb3d2
6 changed files with 1088 additions and 160 deletions

View File

@@ -8,6 +8,7 @@ import { Inputs } from '../inputs'
import { parse as parseYaml } from 'yaml'
import pnpmLock from './bootstrap/pnpm-lock.json'
import exeLock from './bootstrap/exe-lock.json'
import { ensureAliasLinks } from './ensureAliasLinks'
const BOOTSTRAP_PNPM_PACKAGE_JSON = JSON.stringify({ private: true, dependencies: { pnpm: pnpmLock.packages['node_modules/pnpm'].version } })
const BOOTSTRAP_EXE_PACKAGE_JSON = JSON.stringify({ private: true, dependencies: { '@pnpm/exe': exeLock.packages['node_modules/@pnpm/exe'].version } })
@@ -122,19 +123,6 @@ Please specify it by one of the following ways:
- in the package.json with the key "packageManager"`)
}
async function ensureAliasLinks(pnpmHome: string, standalone: boolean): Promise<void> {
const aliases = standalone
? { pn: path.join('..', '@pnpm', 'exe', 'pn'), pnpx: path.join('..', '@pnpm', 'exe', 'pnpx'), pnx: path.join('..', '@pnpm', 'exe', 'pnx') }
: { pn: path.join('..', 'pnpm', 'bin', 'pnpm.cjs'), pnpx: path.join('..', 'pnpm', 'bin', 'pnpx.cjs'), pnx: path.join('..', 'pnpm', 'bin', 'pnpx.cjs') }
for (const [name, target] of Object.entries(aliases)) {
const link = path.join(pnpmHome, name)
const resolvedTarget = path.resolve(pnpmHome, target)
if (!existsSync(link) && existsSync(resolvedTarget)) {
await symlink(target, link)
}
}
}
function runCommand(cmd: string, args: string[], opts: { cwd: string }): Promise<number> {
return new Promise<number>((resolve, reject) => {
const cp = spawn(cmd, args, {