feat: create pn and pnx alias symlinks for pnpm v11+

After self-update, create symlinks for pn, pnpx, and pnx in
node_modules/.bin if the target files exist in the installed package.
This enables the short aliases introduced in pnpm v11.
This commit is contained in:
Zoltan Kochan
2026-03-26 18:34:35 +01:00
parent 62bce64275
commit 747414e7da
2 changed files with 128 additions and 111 deletions

222
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -60,6 +60,10 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
} }
} }
// Create pn/pnx alias symlinks if the installed version supports them
// (pnpm v11+ adds pn and pnx as short aliases)
await ensureAliasLinks(pnpmHome, standalone)
return 0 return 0
} }
@@ -118,6 +122,19 @@ Please specify it by one of the following ways:
- in the package.json with the key "packageManager"`) - 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> { function runCommand(cmd: string, args: string[], opts: { cwd: string }): Promise<number> {
return new Promise<number>((resolve, reject) => { return new Promise<number>((resolve, reject) => {
const cp = spawn(cmd, args, { const cp = spawn(cmd, args, {