Skip to content

Commit

Permalink
refactor: use node resolver to locate React Native package (#2461)
Browse files Browse the repository at this point in the history
# Summary

Twin pull request to
software-mansion/react-native-reanimated#6482
  • Loading branch information
jakex7 committed Sep 19, 2024
1 parent 9049089 commit 9df9741
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,10 @@ def resolveReactNativeDirectory() {
return file(reactNativeLocation)
}

// monorepo workaround
// react-native can be hoisted or in project's own node_modules
def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
if (reactNativeFromProjectNodeModules.exists()) {
return reactNativeFromProjectNodeModules
}

def reactNativeFromNodeModulesWithSVG = file("${projectDir}/../../react-native")
if (reactNativeFromNodeModulesWithSVG.exists()) {
return reactNativeFromNodeModulesWithSVG
// Fallback to node resolver for custom directory structures like monorepos.
def reactNativePackage = file(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim())
if (reactNativePackage.exists()) {
return reactNativePackage.parentFile
}

throw new GradleException("[react-native-svg] Unable to resolve react-native ___location in node_modules. Your app should define `REACT_NATIVE_NODE_MODULES_DIR` extension property in `app/build.gradle` with a path to react-native in node_modules.")
Expand Down

0 comments on commit 9df9741

Please sign in to comment.