fix: preserve order in packageRegistryData using IndexMap#86
Merged
Boshen merged 1 commit intoyarnpkg:mainfrom Jan 14, 2026
Merged
Conversation
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.
Description
The
packageRegistryDatais structured as a nested array where order is guaranteed.However, during deserialization of the PnP manifest via
serde_json, it's being mapped toFxHashMap, which doesn't preserve the array's original order.While this works in most cases, it becomes problematic when SOFT-linked dependencies (e.g., virtual packages) are present. In such scenarios, the resolution must respect the order of
packageRegistryDatato correctly resolve HARD-linked actual dependencies.In my case, the following PnP manifest data existed (added as a test case):
Scenario: Trying to resolve
invariantfromreact-native@npm:0.72.6Ref: package.json dependencies of react-native (
"invariant": "^2.2.4"package listed correctly)The sample data below assumes
react-native->lib,invariant->inner-package.The lib package had
inner-packageas a dependency, but pnp-rn returned a SOFT-linked virtual locator, causing a failure to resolveinner-package. This issue occurred because the order of the PnP manifest data was not respected.To work correctly, entries must be inserted into the Trie following the
packageRegistryDataorder:lib@npm:1.0.0,lib@virtual:3dd9....FxHashMapdoesn't preserve this order, inserting entries arbitrarily based on hash values. This causes pnp-rs to return SOFT-linked locators instead of HARD-linked packages when SOFT entries are processed out of order, leading to incorrect resolution results.To address this issue,
FxHashMapis replaced withIndexMapto preserve the order of data in the PnP manifest, and test cases are added to verify this behavior.(Before)
The insertion order of Trie data differs from the actual PnP manifest data.
(After)

Test Results
cargo test --package pnp --lib -- lib_tests::tests::test_package_registry_data_order --exact