From d2384b8c9f0b33f74dd7e2408557dc9a0ef4911d Mon Sep 17 00:00:00 2001 From: Benjamin Staneck Date: Thu, 21 May 2026 18:07:28 +0200 Subject: [PATCH] feat: add pnpm alias shims Signed-off-by: Benjamin Staneck --- config.json | 13 +++++++++++++ package.json | 8 ++++++++ tests/Enable.test.ts | 26 ++++++++++++++++++++++++++ tests/main.test.ts | 18 ++++++++++++++++++ 4 files changed, 65 insertions(+) diff --git a/config.json b/config.json index 18dfd74cd..c7fd4f13f 100644 --- a/config.json +++ b/config.json @@ -49,12 +49,23 @@ "pnpm", "init" ], + [ + "pn", + "init" + ], [ "pnpx" ], + [ + "pnx" + ], [ "pnpm", "dlx" + ], + [ + "pn", + "dlx" ] ] }, @@ -96,7 +107,9 @@ ">=11.0.0": { "url": "https://registry.npmjs.org/pnpm/-/pnpm-{}.tgz", "bin": { + "pn": "./bin/pnpm.mjs", "pnpm": "./bin/pnpm.mjs", + "pnx": "./bin/pnpx.mjs", "pnpx": "./bin/pnpx.mjs" }, "registry": { diff --git a/package.json b/package.json index 3ec1db1d0..b29812336 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,9 @@ "publishConfig": { "bin": { "corepack": "./dist/corepack.js", + "pn": "./dist/pn.js", "pnpm": "./dist/pnpm.js", + "pnx": "./dist/pnx.js", "pnpx": "./dist/pnpx.js", "yarn": "./dist/yarn.js", "yarnpkg": "./dist/yarnpkg.js" @@ -72,7 +74,9 @@ "executableFiles": [ "./dist/npm.js", "./dist/npx.js", + "./dist/pn.js", "./dist/pnpm.js", + "./dist/pnx.js", "./dist/pnpx.js", "./dist/yarn.js", "./dist/yarnpkg.js", @@ -81,8 +85,12 @@ "./shims/npm.ps1", "./shims/npx", "./shims/npx.ps1", + "./shims/pn", + "./shims/pn.ps1", "./shims/pnpm", "./shims/pnpm.ps1", + "./shims/pnx", + "./shims/pnx.ps1", "./shims/pnpx", "./shims/pnpx.ps1", "./shims/yarn", diff --git a/tests/Enable.test.ts b/tests/Enable.test.ts index c85f91f45..37998fbf7 100644 --- a/tests/Enable.test.ts +++ b/tests/Enable.test.ts @@ -88,6 +88,32 @@ describe(`EnableCommand`, () => { }); }); + it(`should add pnpm alias binaries`, async () => { + await xfs.mktempPromise(async cwd => { + const corepackBin = await makeBin(cwd, `corepack` as Filename); + + await expect(runCli(cwd, [`enable`, `--install-directory=${npath.fromPortablePath(cwd)}`, `pnpm`])).resolves.toMatchObject({ + stdout: ``, + stderr: ``, + exitCode: 0, + }); + + const sortedEntries = xfs.readdirPromise(cwd).then(entries => { + return entries.sort(); + }); + + const expectedEntries: Array = [ + ppath.basename(corepackBin), + ...getBinaryNames(`pn`), + ...getBinaryNames(`pnpm`), + ...getBinaryNames(`pnpx`), + ...getBinaryNames(`pnx`), + ]; + + await expect(sortedEntries).resolves.toEqual(expectedEntries.sort()); + }); + }); + test.skipIf(process.platform === `win32`)(`should overwrite existing files`, async () => { await xfs.mktempPromise(async cwd => { await xfs.writeFilePromise(ppath.join(cwd, `yarn`), `hello`); diff --git a/tests/main.test.ts b/tests/main.test.ts index 507db2e43..ade0199a9 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -621,6 +621,24 @@ it(`should allow using transparent commands on npm-configured projects`, async ( }); }); +it(`should allow using pnpm alias transparent commands on npm-configured projects`, async () => { + await xfs.mktempPromise(async cwd => { + await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), { + packageManager: `npm@6.14.2`, + }); + + await expect(runCli(cwd, [`pn`, `dlx`, `--help`])).resolves.toMatchObject({ + exitCode: 0, + stderr: ``, + }); + + await expect(runCli(cwd, [`pnx`, `--help`])).resolves.toMatchObject({ + exitCode: 0, + stderr: ``, + }); + }); +}); + it(`should transparently use the preconfigured version when there is no local project`, async () => { await xfs.mktempPromise(async cwd => { await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({