mirror of
https://github.com/pnpm/action-setup.git
synced 2026-03-30 23:02:36 +00:00
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:
parent
62bce64275
commit
747414e7da
BIN
dist/index.js
vendored
BIN
dist/index.js
vendored
Binary file not shown.
@ -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
|
||||
}
|
||||
|
||||
@ -118,6 +122,19 @@ 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, {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user