fix(pnp): align exports resolution with enhanced-resolve#196
Open
ha1fstack wants to merge 2 commits intorstackjs:mainfrom
Open
fix(pnp): align exports resolution with enhanced-resolve#196ha1fstack wants to merge 2 commits intorstackjs:mainfrom
ha1fstack wants to merge 2 commits intorstackjs:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adjusts Yarn PnP resolution so exports are resolved from the PnP-derived subpath (matching enhanced-resolve) rather than relying on package.json.name matching for the PnP branch, which could incorrectly bypass exports in alias/name-mismatch scenarios.
Changes:
- Update PnP resolution flow to resolve
exportsusing the request-derived (PnP-provided) subpath viaload_package_exports. - Normalize PnP subpaths before constructing
exportsand inner fallback requests. - Add fixtures + tests covering PnP exports resolution for bare, subpath, and name-mismatch cases.
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib.rs | Changes PnP branch to resolve exports from the PnP subpath directly, avoiding package-name matching in load_package_self. |
| src/tests/pnp.rs | Adds regression tests for PnP exports handling (bare + subpath) with a name-mismatch fixture. |
| fixtures/pnp/package.json | Adds a linked dependency @user/m1 pointing to the name-mismatch fixture. |
| fixtures/pnp/yarn.lock | Updates lockfile entries for the new linked dependency. |
| fixtures/pnp/shared-name-mismatch/package.json | Adds a fixture package whose name intentionally differs from the requested specifier while providing exports. |
| fixtures/pnp/shared-name-mismatch/dist/a.js | Adds the exported target file used by the new tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
rspack-resolver’s PnP path previously calledload_package_self(&cached_path, specifier, ...)before resolving exports.That flow depends on
package_json.namematching the request package prefix, which is valid for Node self-reference, but can be wrong for PnP edge cases (aliases, virtualized layouts, or name-mismatch paths).enhanced-resolvedoes not rely on that check in its PnP path. It derives the subpath from the request and resolves exports from that subpath directly.Original fallback behavior (and why it was problematic)
In the old
load_pnpflow:load_package_self(&cached_path, specifier, ...).None, fall back toinner_requestand call the inner resolver from the PnP-resolved package path.resolve(path, "."), which can proceed via directory/main/index resolution.Problem in mismatch cases:
package.json.namediffers from the requested specifier,load_package_selffails early due to name check."."/ filesystem-style main/index pathing) is not equivalent to exports-field resolution and can produce incorrect results orNotFoundfor requests that should be resolved byexports.What changed
load_package_selfpackage-name matching in the PnP-specific flow.Why
This aligns
rspack-resolverwithenhanced-resolvebehavior in PnP mode and ensures deterministic exports resolution based on the PnP-resolved package/subpath, not onpackage.json.namestring matching.Tests
Added/updated tests (modeled after enhanced-resolve scenarios) covering:
Result