Skip to content

Commit

Permalink
Use node resolver to locate React Native package (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekzaw authored Sep 9, 2024
1 parent 2e0bd2c commit 8bf7cb7
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,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 reactNativeFromLiveMarkdownMonorepo = file("${projectDir}/../../../node_modules/react-native")
if (reactNativeFromLiveMarkdownMonorepo.exists()) {
return reactNativeFromLiveMarkdownMonorepo
}

def reactNativeFromNodeModulesWithLiveMarkdown = file("${projectDir}/../../react-native")
if (reactNativeFromNodeModulesWithLiveMarkdown.exists()) {
return reactNativeFromNodeModulesWithLiveMarkdown
// 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-live-markdown] 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 8bf7cb7

Please sign in to comment.