Skip to content

Commit

Permalink
Allow react-native-macos package.json shims
Browse files Browse the repository at this point in the history
This commit makes it possible to add a `react-native-macos` field to package.json that functions the same way as `react-native` to shim one-level deep requires/imports. See facebook/react-native#5917 for details of `browser` and `react-native fields`.

This commit makes it possible to share code more broadly between react native platforms. For example, take the following package.json field:
```
"react-native-macos": { "react-native": "react-native-macos" }
```
With this set our components can import from react-native rather than react-native-macos, allowing code sharing between react native platforms more easily.
  • Loading branch information
c-h- authored Feb 11, 2017
1 parent bc703d7 commit 375d662
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packager/react-packager/src/node-haste/Package.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,26 @@ class Package {
}

function getReplacements(pkg) {
let rnm = pkg['react-native-macos'];
let rn = pkg['react-native'];
let browser = pkg.browser;
if (rn == null) {

if (rnm == null && rn == null) {
return browser;
}

if (browser == null) {
if (rnm == null && browser == null) {
return rn;
}

if (rn == null && browser == null) {
return rnm;
}

if (typeof rnm === 'string') {
rnm = { [pkg.main]: rnm };
}

if (typeof rn === 'string') {
rn = { [pkg.main]: rn };
}
Expand All @@ -127,8 +137,9 @@ function getReplacements(pkg) {
}

// merge with "browser" as default,
// "react-native" as override
return { ...browser, ...rn };
// "react-native" as override 1
// "react-native-macos" as override 2
return { ...browser, ...rn, ...rnm };
}

module.exports = Package;

0 comments on commit 375d662

Please sign in to comment.