-
Notifications
You must be signed in to change notification settings - Fork 935
Allow out of tree platforms to work without custom metro configs #1115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a76e6ce
Allow out of tree platforms to work without custom metro configs
acoates-ms 744a769
Need to add the platofrm specifc InitializeCore to getModulesRunBefor…
acoates-ms 452b175
lock
acoates-ms c5481d1
Add npmPackageName to schema
acoates-ms 121ea01
Some documentation
acoates-ms 001874e
Use finally to restore resolveRequest
acoates-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /** | ||
| * This is an implementation of a metro resolveRequest option which will remap react-native imports | ||
| * to different npm packages based on the platform requested. This allows a single metro instance/config | ||
| * to produce bundles for multiple out of tree platforms at a time. | ||
| * | ||
| * @param platformImplementations | ||
| * A map of platform to npm package that implements that platform | ||
| * | ||
| * Ex: | ||
| * { | ||
| * windows: 'react-native-windows' | ||
| * macos: 'react-native-macos' | ||
| * } | ||
| */ | ||
| // @ts-ignore - no typed definition for the package | ||
| import {resolve} from 'metro-resolver'; | ||
acoates-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export function reactNativePlatformResolver(platformImplementations: { | ||
| [platform: string]: string; | ||
| }) { | ||
| return ( | ||
| context: any, | ||
| _realModuleName: string, | ||
| platform: string, | ||
| moduleName: string, | ||
| ) => { | ||
| let backupResolveRequest = context.resolveRequest; | ||
| delete context.resolveRequest; | ||
|
|
||
| try { | ||
| let modifiedModuleName = moduleName; | ||
| if (platformImplementations[platform]) { | ||
| if (moduleName === 'react-native') { | ||
| modifiedModuleName = platformImplementations[platform]; | ||
| } else if (moduleName.startsWith('react-native/')) { | ||
| modifiedModuleName = `${ | ||
| platformImplementations[platform] | ||
| }/${modifiedModuleName.slice('react-native/'.length)}`; | ||
| } | ||
| } | ||
| let result = resolve(context, modifiedModuleName, platform); | ||
| return result; | ||
| } catch (e) { | ||
| throw e; | ||
| } finally { | ||
| context.resolveRequest = backupResolveRequest; | ||
| } | ||
| }; | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.