Skip to content

Commit

Permalink
fix: do not throw on missing cliPath, use the default value (#28625)
Browse files Browse the repository at this point in the history
Summary:
The `cliPath` has always been optional value and in fact, even had its default value hardcoded in the React gradle file.

In this PR, I am just taking use of it and remove throwing an error, which is going to be a really annoying breaking change.

## Changelog

[ANDROID] [INTERNAL] - Don't require `cliPath`
Pull Request resolved: #28625

Test Plan:
Run Android project, everything works.
Provide custom `cliPath`, it gets respected

Reviewed By: cpojer

Differential Revision: D21044222

Pulled By: TheSavior

fbshipit-source-id: 8029f988d92abb9f64f30e05932c0d407d0c997e
  • Loading branch information
grabbou committed Apr 16, 2020
1 parent b191809 commit 5f7b44c
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions react.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,26 @@ def detectEntryFile(config) {
return "index.js";
}

def cliPath = config.cliPath ?: "node_modules/react-native/cli.js"
/**
* Detects CLI location in a similar fashion to the React Native CLI
*/
def detectCliPath(config) {
if (config.cliPath) {
return config.cliPath
}

def cliPath = ["node", "-e", "console.log(require('react-native/cli').bin);"].execute([], projectDir).text

if (cliPath) {
return cliPath
} else if (new File("${projectDir}/../../node_modules/react-native/cli.js").exists()) {
return "${projectDir}/../../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 @@ -98,21 +117,16 @@ afterEvaluate {

// Additional node and packager commandline arguments
def nodeExecutableAndArgs = config.nodeExecutableAndArgs ?: ["node"]
def extraPackagerArgs = config.extraPackagerArgs ?: []
def cliPath = detectCliPath(config)

def execCommand = []

if (config.cliPath || config.nodeExecutableAndArgs) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
execCommand.addAll(["cmd", "/c", *nodeExecutableAndArgs, cliPath])
} else {
execCommand.addAll([*nodeExecutableAndArgs, cliPath])
}
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
execCommand.addAll(["cmd", "/c", *nodeExecutableAndArgs, cliPath])
} else {
throw new Exception("Missing cliPath or nodeExecutableAndArgs from build config. " +
"Please set project.ext.react.cliPath to the path of the react-native cli.js");
execCommand.addAll([*nodeExecutableAndArgs, cliPath])
}

def enableHermes = enableHermesForVariant(variant)

def currentBundleTask = tasks.create(
Expand Down Expand Up @@ -145,7 +159,7 @@ afterEvaluate {
def devEnabled = !(config."devDisabledIn${targetName}"
|| targetName.toLowerCase().contains("release"))

def extraArgs = extraPackagerArgs;
def extraArgs = config.extraPackagerArgs ?: [];

if (bundleConfig) {
extraArgs = extraArgs.clone()
Expand Down

0 comments on commit 5f7b44c

Please sign in to comment.