Skip to content

Commit dc73ec4

Browse files
tjzelmeta-codesync[bot]
authored andcommitted
fix: RNGP using node invocation non-compatible with Gradle Compilation Cache (#54801)
Summary: Invoking `Runtime.getRuntime().exec()` is not compatible with Gradle Configuration Cache and providers should be used instead. This error hasn't surfaced yet due to fact that this branch of code is rarely hit as the users usually provide correct path to the CLI in their `app/build.gradle` file. I stumbled upon it accidentally when bumping RN in monorepo and the CLI path was no longer valid. ## Changelog: [ANDROID] [FIXED] - RNGP using node invocation non-compatible with Gradle Compilation Cache Pull Request resolved: #54801 Test Plan: I tested it in a rnc-cli app, where I provided an invalid path for `cliFile` - the error was fixed after applying this patch. Reviewed By: mdvacca, huntie Differential Revision: D88492310 Pulled By: cortinico fbshipit-source-id: a91e47b90937945066bde938bdf16b2550322afb
1 parent 38513f7 commit dc73ec4

File tree

1 file changed

+11
-9
lines changed
  • packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils

1 file changed

+11
-9
lines changed

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ internal fun detectedEntryFile(config: ReactExtension, envVariableOverride: Stri
4242
*/
4343
internal fun detectedCliFile(config: ReactExtension): File =
4444
detectCliFile(
45+
project = config.project,
4546
reactNativeRoot = config.root.get().asFile,
4647
preconfiguredCliFile = config.cliFile.asFile.orNull,
4748
)
@@ -71,7 +72,11 @@ private fun detectEntryFile(
7172
else -> File(reactRoot, "index.js")
7273
}
7374

74-
private fun detectCliFile(reactNativeRoot: File, preconfiguredCliFile: File?): File {
75+
private fun detectCliFile(
76+
project: Project,
77+
reactNativeRoot: File,
78+
preconfiguredCliFile: File?,
79+
): File {
7580
// 1. preconfigured path
7681
if (preconfiguredCliFile != null) {
7782
if (preconfiguredCliFile.exists()) {
@@ -81,14 +86,11 @@ private fun detectCliFile(reactNativeRoot: File, preconfiguredCliFile: File?): F
8186

8287
// 2. node module path
8388
val nodeProcess =
84-
Runtime.getRuntime()
85-
.exec(
86-
arrayOf("node", "--print", "require.resolve('react-native/cli');"),
87-
emptyArray(),
88-
reactNativeRoot,
89-
)
90-
91-
val nodeProcessOutput = nodeProcess.inputStream.use { it.bufferedReader().readText().trim() }
89+
project.providers.exec {
90+
it.commandLine("node", "--print", "require.resolve('react-native/package.json')")
91+
}
92+
93+
val nodeProcessOutput = nodeProcess.standardOutput.asText.get().trim()
9294

9395
if (nodeProcessOutput.isNotEmpty()) {
9496
val nodeModuleCliJs = File(nodeProcessOutput)

0 commit comments

Comments
 (0)