fix(npm-resolver): request full metadata for optional dependencies#10455
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where pnpm was incorrectly downloading both glibc and musl versions of optional dependencies on glibc systems due to missing libc field information in abbreviated metadata.
Changes:
- Added support for requesting full metadata for optional dependencies to obtain the
libcfield needed for proper platform filtering - Modified cache key generation to include
metaDirto prevent collisions between abbreviated and full metadata - Propagated the
optionalflag from package requester through to the npm resolver
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| resolving/resolver-base/src/index.ts | Added optional field to ResolveOptions interface |
| resolving/npm-resolver/test/resolveFromNpm.test.ts | Added comprehensive integration tests for full metadata usage with optional dependencies |
| resolving/npm-resolver/test/pickPackage.test.ts | Added unit tests for cache key separation and fullMetadata flag propagation |
| resolving/npm-resolver/src/pickPackage.ts | Modified cache key to include metaDir and updated fetch call to pass fullMetadata flag |
| resolving/npm-resolver/src/index.ts | Added logic to use FULL_META_DIR for optional dependencies and pass optional flag through context |
| resolving/npm-resolver/src/fetch.ts | Added fullMetadata parameter to fetch function signature |
| pkg-manager/package-requester/test/index.ts | Added test to verify optional flag is passed to resolve function |
| pkg-manager/package-requester/src/packageRequester.ts | Modified to pass optional flag from WantedDependency to resolve options |
| network/fetching-types/src/index.ts | Added fullMetadata field to FetchFromRegistry options |
| network/fetch/src/fetchFromRegistry.ts | Modified to use per-request fullMetadata option with fallback to default |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
581c3fb to
0bc4181
Compare
|
TBH, I hate this solution but I don't have better ideas at the moment. |
| const resolveResult = await ctx.requestsQueue.add<ResolveResult>(async () => ctx.resolve(wantedDependency, { | ||
| ...options, | ||
| optional: wantedDependency.optional, |
There was a problem hiding this comment.
why are you adding optional to options if it is already passed in via wantedDependency in the first argument?
| metaDir: opts.fullMetadata ? (opts.filterMetadata ? FULL_FILTERED_META_DIR : FULL_META_DIR) : ABBREVIATED_META_DIR, | ||
| metaDir: defaultMetaDir, |
There was a problem hiding this comment.
it looks like it will be better to have two fields. metaDir and metaDirForOptionalPackages. The code will be simpler.
6574b3c to
a7add93
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a7add93 to
75028dc
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Congrats on merging your first pull request! 🎉🎉🎉 |
close #9950
Biome correctly declares the
os,cpu, andlibcfields in each platform specific package1.For context, the npm registry provides two types of metadata responses. Full metadata (
application/json) includes thelibcfield, while Abbreviated metadata (application/vnd.npm.install-v1+json) does not.Since pnpm uses abbreviated metadata by default, the
libcfield may beundefined. As a result, the check forlibcincheckPlatform()can be skipped, making it impossible to distinguish between musl and glibc. To address this, adding a flag to request fullMetadata for each registry request allows pnpm to consistently obtain complete platform information and resolveoptionalDependenciescorrectly. This change will prevent unsupported versions, such as@biomejs/cli-linux-x64-musl, from being erroneously downloaded on glibc systems.You can verify the behavior by clearing pnpm's cache and running
pnpm installin the directory containing the followingpackage.json. The examples below were tested on Ubuntu 24.04.{ "name": "sandbox-pnpm", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "packageManager": "pnpm@11.0.0-alpha.2", "type": "module", "devDependencies": { "@biomejs/biome": "2.3.11" } }Before:
After:
Footnotes
https://github.com/biomejs/biome/issues/7442#issuecomment-3265414662 ↩