refactor: use node resolver to locate React Native package (#2461)

# Summary

Twin pull request to
https://github.com/software-mansion/react-native-reanimated/pull/6482
This commit is contained in:
Jakub Grzywacz
2024-09-19 12:18:59 +02:00
committed by GitHub
parent 9049089954
commit 9df974194f
+4 -10
View File
@@ -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.")