Skip to content

Commit

Permalink
add auto resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
grabbou committed Apr 14, 2020
1 parent ef9ef01 commit 8f28ec7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
1 change: 0 additions & 1 deletion RNTester/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ plugins {
*/

project.ext.react = [
cliPath: "$rootDir/cli.js",
bundleAssetName: "RNTesterApp.android.bundle",
entryFile: file("../../js/RNTesterApp.android.js"),
root: "$rootDir",
Expand Down
19 changes: 17 additions & 2 deletions react.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -109,7 +124,7 @@ afterEvaluate {
execCommand.addAll([*nodeExecutableAndArgs, config.cliPath])
}
} else {
execCommand.add(defaultCliPath)
execCommand.add(defaultCliPath())
}

def enableHermes = enableHermesForVariant(variant)
Expand Down

0 comments on commit 8f28ec7

Please sign in to comment.