mirror of
https://github.com/pnpm/action-setup.git
synced 2026-04-04 03:10:11 +08: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:
222
dist/index.js
vendored
222
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -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, {
|
||||||
|
|||||||
Reference in New Issue
Block a user