feat: support pnpm v12, which is distributed as a native executable - #887
feat: support pnpm v12, which is distributed as a native executable#887zkochan wants to merge 3 commits into
Conversation
|
First I wanted to add support for yarn 6 as well but then I have found out they don't recommend corepack for yarn anymore. |
|
Hi @zkochan Thanks for the PR! I tested it locally and it looks good to me. 🚀 Hopefully a maintainer will be able to review soon! $ corepack use pnpm@next-12
Installing pnpm@12.0.0-rc.1 in the project...
Already up to date
Done in 4.6s using pnpm v12.0.0-rc.1
Yarn 6 (currently in beta status) is moving to Yarn Switch. |
|
FWIW Yarn v6 ships the following script to keep backward compat with Corepack: https://repo.yarnpkg.com/6.0.0/packages/yarnpkg-cli/bin/yarn.js |
This comment was marked as outdated.
This comment was marked as outdated.
|
Probably best to deprecate corepack altogether as it has lost relevance. |
I don't think that's accurate, there are many users of the CJS-based package managers (including pnpm) that rely on Corepack |
| // builds leave it unset. `process.report` may be unavailable, in which case | ||
| // we default to glibc. | ||
| try { | ||
| const report = process.report?.getReport() as any; |
There was a problem hiding this comment.
as any looks wrong here. We should have the types or at least cast the expected types
| // we default to glibc. | ||
| try { | ||
| const report = process.report?.getReport() as any; | ||
| if (report == null) |
There was a problem hiding this comment.
Lets also disable network to speed this up. See this:
As far as pnpm is concerned, since you have alternatives, it is understandable for you to de-prioritize Corepack. I see that you removed it from the https://pnpm.io/installation page. If you are able to continue with this PR, then your pnpm users who would like to migrate to pnpm 12 and (continue to) use Corepack would benefit. Otherwise I'm not sure if anybody else would pick up your PR material and bring it to completion. In that case the Corepack documentation should probably list the incompatibility with pnpm 12. It looks like you put significant effort into this PR, so I do hope you will be able to continue - meaning rebasing, resolving conflicts and responding to review comments. |
@MikeMcC399 Corepack doesn't work with pnpm anymore, so maybe this is moot: It looks like there's a fundamental mismatch between:
So probably it's best to not use Corepack with pnpm anymore. |
It does though, not everyone is using |
Hmm... I would call "Corepack supports pnpm" into question if big features and workflows are not supported. Maybe better would be "Corepack sometimes may work with pnpm". Anyway, too tenuous for me and my students - I'll also be removing Corepack from everything. |
Starting with v12, the `pnpm` package on npm only ships placeholders for its binaries: the actual platform-specific executable lives in a companion `@pnpm/exe.<platform>` package (pinned in the `optionalDependencies` of the main package), and a `preinstall` script copies it over the placeholders. Since Corepack never runs lifecycle scripts, it now replicates their effect for package manager versions whose config defines `nativePackages`: it downloads the companion package for the current platform, verifies its signature and integrity, and hardlinks its executable over each placeholder. The executable adapts its behavior to the name it was invoked under, which keeps the `pnpx` alias working. Native executables cannot be loaded into the current Node.js process like the JavaScript-based package managers, so they are spawned as a child process instead. Installs of pnpm >=12 performed by previous Corepack releases recorded binary paths that don't exist; such installs are detected and redone. Fixes: nodejs#873 Refs: nodejs#775 Refs: pnpm/pnpm#13018 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
I will finish this PR but overall I would ask the corepack team to remove pnpm from corepack altogether. |
Replace the `as any` cast with an explicit shape for the bits of the diagnostic report we read, and exclude the network interfaces from the report since gathering them is by far the slowest part of generating it and we only care about the header. Ref: lovell/detect-libc#21 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
0f599b8 to
b44b7cd
Compare
Keep only the comments explaining something the code doesn't already say, and hoist the single `COREPACK_ROOT` assignment out of the native branch so it isn't duplicated. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Fixes: #873
Refs: #775
Refs: pnpm/pnpm#13018
Problem
Starting with v12, pnpm is a native executable (a Rust port). The
pnpmpackage on npm only ships shebang-less placeholders for its binaries; the actual platform-specific executable lives in a companion@pnpm/exe.<platform>package (pinned in theoptionalDependenciesof the main package), and apreinstalllifecycle script copies it over the placeholders. Corepack neither runs lifecycle scripts nor installsoptionalDependencies, socorepack use pnpm@next-12currently fails withMODULE_NOT_FOUND(#873). pnpm won't be adding a backward-compatible JS shim, as it would defeat the point of the native port (see pnpm/pnpm#13018 (comment)).Solution
This PR replicates the effect of pnpm's install script inside Corepack, driven by a new optional
nativePackagesfield inconfig.jsonrange definitions (mapping${platform}-${arch}[-musl]keys to{package, bin}):package.json'soptionalDependencies, downloads the companion package for the current platform (with the same signature + integrity verification as the main tarball), and hardlinks its executable over each placeholder bin. The pnpm executable adapts its behavior to the name it was invoked under, which is what keepspnpx(=pnpm dlx) working.Module.runMain, so it is spawned as a child process, with signal forwarding and exit-code propagation../bin/pnpm.mjs). Such installs are detected on reuse and silently redone, so users don't need to clearCOREPACK_HOMEby hand.The libc detection (glibc vs musl via
process.report) and the platform table mirror the logic of pnpm's owninstall.js.Testing
pnpxalias, signature verification of the companion package, and cache reuse (skipped on Windows, where the fake native executable — a shell script — cannot be spawned).pnpm@12.0.0-rc.1:corepack pnpm --version,corepack pnpm install, andcorepack pnpx --help(correctly maps topnpm dlx) all work;pnpm/pnpxbins are hardlinks of the same 38 MB native executable;🤖 Generated with Claude Code