mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
fix: do not throw on missing cliPath, use the default value (#28625)
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: https://github.com/facebook/react-native/pull/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
This commit is contained in:
+26
-12
@@ -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)
|
||||
@@ -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(
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user