-
-
Notifications
You must be signed in to change notification settings - Fork 988
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move REACT_NATIVE_VERSION to native-only code (#2666)
## Description Fixes #2660 Depending on this package in a web-only app is causing a compile error. This is due to this package importing `react-native/package.json`, which for web-only builds doesn't exist. This import is only done to obtain the react-native version number, which isn't used for web anyway. So it seems easy enough to move this version number to a native-only file. I chose to export a **function** so that it's a _logic error_ to use `getReactNativeVersion` on web, and an error is thrown (right now it's only used in one place, behind a check that makes sure it runs on native only). It might have been easier to just export a **const**, with fake values on web, but that would hide the error for a potentially more confusing error down the line. ## Test plan Not tested, sorry. Would appreciate if someone could help out here. --------- Co-authored-by: Chris Coomber <[email protected]>
- Loading branch information
1 parent
b0986c3
commit ff3b820
Showing
4 changed files
with
17 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import pack from 'react-native/package.json'; | ||
|
||
const [majorStr, minorStr] = pack.version.split('.'); | ||
const REACT_NATIVE_VERSION = { | ||
major: parseInt(majorStr, 10), | ||
minor: parseInt(minorStr, 10), | ||
}; | ||
|
||
export function getReactNativeVersion() { | ||
return REACT_NATIVE_VERSION; | ||
} |
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,3 @@ | ||
export function getReactNativeVersion() { | ||
throw new Error('getReactNativeVersion is not supported on web'); | ||
} |
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