Repository navigation
Resolver: Resolve package target arrays in order - #2089
Open
maximilliangrand wants to merge 1 commit into
Open
maximilliangrand wants to merge 1 commit into
maximilliangrand wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Summary
Follow-up to the array handling discussion on #2074 and the conditional-array example on #1238.
For an export such as
[{"browser": "./web.js"}, "./native.js"], Metro currently keeps only the first array item. Whenbrowseris not asserted, it misses the valid fallback and falls back to legacy file resolution instead. Nested arrays in conditions andimportsare also treated as unresolved.Keep arrays until condition resolution and evaluate their targets in order. Unmatched conditions, null entries and invalid targets allow the next array item; a valid path is selected even if the file is missing. Preserve the distinction between an unmatched condition and an explicit null when returning to an enclosing condition object. Select the requested exact key or pattern before evaluating its target, so an unrelated invalid mapping does not prevent resolution. Existing export path validation runs for each candidate before it can be selected.
Changelog: [Fix] Resolve conditional and nested array fallbacks in package
exportsandimports.Test plan
Using Node 24.22.1 and Yarn 1.22.22:
104590ad; 68 pass with the fix. Covers root exports, subpath exports, imports, nested arrays, null/error ordering, unmatched parent conditions, invalid export paths, unrelated mappings and valid-but-missing files.yarn test --maxWorkers=2: Flow, lint, formatting and build pass; 161 suites, 3,083 tests and 495 snapshots pass, with 14 tests skipped.yarn typecheck-tsandyarn test-smoke: pass.This changes array fallback semantics for Metro's supported local targets. It does not add external
importstargets or change the existing numeric condition-key and imports path-validation behavior.Codex assisted with implementation, testing and review.