forked from react-native-community/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow out of tree platforms to work without custom metro configs (rea…
…ct-native-community#1115) * Allow out of tree platforms to work without custom metro configs * Need to add the platofrm specifc InitializeCore to getModulesRunBeforeMainModule * lock * Add npmPackageName to schema * Some documentation * Use finally to restore resolveRequest
- Loading branch information
1 parent
2d71e50
commit b92fbc6
Showing
7 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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'; | ||
|
||
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 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 |
---|---|---|
|
@@ -7750,7 +7750,7 @@ metro-react-native-babel-transformer@^0.58.0: | |
metro-react-native-babel-preset "0.58.0" | ||
metro-source-map "0.58.0" | ||
|
||
[email protected]: | ||
[email protected], metro-resolver@^0.58.0: | ||
version "0.58.0" | ||
resolved "https://registry.yarnpkg.com/metro-resolver/-/metro-resolver-0.58.0.tgz#4d03edc52e2e25d45f16688adf3b3f268ea60df9" | ||
integrity sha512-XFbAKvCHN2iWqKeiRARzEXn69eTDdJVJC7lu16S4dPQJ+Dy82dZBr5Es12iN+NmbJuFgrAuIHbpWrdnA9tOf6Q== | ||
|