Skip to content

Resolver: Extract redirectPackageSubpath from redirectModulePath - #2044

Merged
robhogan merged 1 commit into
mainfrom
robhogan/redirect-package-subpath
Oct 14, 2026
Merged

robhogan merged 1 commit into
mainfrom
robhogan/redirect-package-subpath

Conversation

@robhogan

@robhogan robhogan commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

redirectModulePath asks context.getPackageForModule for the package containing a module path, then applies that package's mainFields redirections (the "browser" spec) to the module's package-relative path. This splits the second half out as redirectPackageSubpath, for callers that already know the containing package. redirectModulePath delegates to it for relative and absolute paths and behaves exactly as before; bare specifiers are unchanged.

#1945 uses it to look up the package of a directory's files once and apply it to every extension candidate, instead of calling redirectModulePath per candidate.

Changelog: Internal

Test plan

A pure refactor, covered by the existing resolver tests.

yarn jest packages/metro-resolver packages/metro/src/DeltaBundler/__tests__/resolver-test.js
yarn flow check

## Summary
`redirectModulePath` asks `context.getPackageForModule` for the package containing a module path, then applies that package's `mainFields` redirections (the "browser" spec) to the module's package-relative path. This splits the second half out as `redirectPackageSubpath`, for callers that already know the containing package. `redirectModulePath` delegates to it for relative and absolute paths and behaves exactly as before; bare specifiers are unchanged.

#1945 uses it to look up the package of a directory's files once and apply it to every extension candidate, instead of calling `redirectModulePath` per candidate.

## Test plan
```
yarn jest packages/metro-resolver packages/metro/src/DeltaBundler/__tests__/resolver-test.js
yarn flow check
```

Changelog: Internal
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 9, 2026
@robhogan
robhogan added this pull request to stack #2045 October 9, 2026 15:34
@robhogan
robhogan requested a balanced review from Copilot October 13, 2026 10:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃煝 Approval recommended

The extraction preserves existing behavior and introduces no unresolved issues.

0 open findings

What changed in this PR

Extracts package-subpath redirection logic for reuse while preserving existing resolver behavior.

Changes:

  • Adds redirectPackageSubpath.
  • Delegates relative and absolute path handling to the new helper.
File Description
packages/鈥媘etro-resolver/鈥媠rc/鈥婸ackageResolve.js Extracts reusable package-relative redirect logic.

馃 Review effort: Balanced


馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@robhogan
robhogan marked this pull request as ready for review October 13, 2026 10:35
@robhogan
robhogan requested review from huntie and vzaidman October 13, 2026 10:35
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 13, 2026
@robhogan
robhogan merged commit ac92386 into main Oct 14, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants