Add support for resolving custom platform variant #41659
Closed
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:
For out-of-tree platforms that share most of the code with some base platform (like visionOS is based on iOS) the current
Platformabstraction doesn't fit nicely. Making "visionos" a distinct platform would mean we couldn't leverage from all the community code hidden behindPlatform.OS === "ios"checks.Building on top of existing Metro infrastructure (namely
customResolverOptions), we'd like to propose a concept of a "Platform variant". Variant serves two purposes:This PR: allows OOT platforms to properly resolve calls to
react-nativemodule, while not making them a de-facto platform. Would apply toreact-native-visionosproxyingreact-native->react-native-visionos.It would also help the
react-native-tvosplatform as well to avoid remapping in package.json:"react-native": "npm:react-native-tvos@latest",.Future proposal: allows extending custom out-of-tree platform resolver to resolve:
File.{platform}.{variant}.js->File.{platform}.js->File.jsThis change originates from visionOS fork: callstack#32
Changelog:
[GENERAL] [ADDED] - Add support for resolving custom platform variant
Test Plan:
Added a unit test for
metroPlatformResolverto illustrate the change