From 8f28ec75d64917f074d8d4fdc791098af7b0beb8 Mon Sep 17 00:00:00 2001 From: grabbou Date: Tue, 14 Apr 2020 17:19:15 +0200 Subject: [PATCH] add auto resolution --- RNTester/android/app/build.gradle | 1 - react.gradle | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/RNTester/android/app/build.gradle b/RNTester/android/app/build.gradle index 0a36475ade519b..02920600962494 100644 --- a/RNTester/android/app/build.gradle +++ b/RNTester/android/app/build.gradle @@ -65,7 +65,6 @@ plugins { */ project.ext.react = [ - cliPath: "$rootDir/cli.js", bundleAssetName: "RNTesterApp.android.bundle", entryFile: file("../../js/RNTesterApp.android.js"), root: "$rootDir", diff --git a/react.gradle b/react.gradle index 2c4707843cc3df..7bd820a0474af0 100644 --- a/react.gradle +++ b/react.gradle @@ -21,7 +21,22 @@ def detectEntryFile(config) { return "index.js"; } -def defaultCliPath = "node_modules/react-native/cli.js" +/** + * Detects CLI location in a similar fashion to the React Native CLI + */ +def detectCliPath(config) { + def cliPath = ["node", "-e", "console.log(require('react-native/cli').bin);"].execute([], projectDir).text + + if (cliPath) { + return cliPath + } else if (new File("node_modules/react-native/cli.js").exists()) { + return "node_modules/react-native/cli.js" + } else { + throw new Exception("Couldn't determine CLI location. " + + "Please set `project.ext.react.cliPath` to the path of the react-native cli.js"); + } +} + def composeSourceMapsPath = config.composeSourceMapsPath ?: "node_modules/react-native/scripts/compose-source-maps.js" def bundleAssetName = config.bundleAssetName ?: "index.android.bundle" def entryFile = detectEntryFile(config) @@ -109,7 +124,7 @@ afterEvaluate { execCommand.addAll([*nodeExecutableAndArgs, config.cliPath]) } } else { - execCommand.add(defaultCliPath) + execCommand.add(defaultCliPath()) } def enableHermes = enableHermesForVariant(variant)