Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ internal fun detectedEntryFile(config: ReactExtension, envVariableOverride: Stri
*/
internal fun detectedCliFile(config: ReactExtension): File =
detectCliFile(
project = config.project,
reactNativeRoot = config.root.get().asFile,
preconfiguredCliFile = config.cliFile.asFile.orNull,
)
Expand Down Expand Up @@ -71,7 +72,11 @@ private fun detectEntryFile(
else -> File(reactRoot, "index.js")
}

private fun detectCliFile(reactNativeRoot: File, preconfiguredCliFile: File?): File {
private fun detectCliFile(
project: Project,
reactNativeRoot: File,
preconfiguredCliFile: File?
): File {
// 1. preconfigured path
if (preconfiguredCliFile != null) {
if (preconfiguredCliFile.exists()) {
Expand All @@ -81,14 +86,11 @@ private fun detectCliFile(reactNativeRoot: File, preconfiguredCliFile: File?): F

// 2. node module path
val nodeProcess =
Runtime.getRuntime()
.exec(
arrayOf("node", "--print", "require.resolve('react-native/cli');"),
emptyArray(),
reactNativeRoot,
)

val nodeProcessOutput = nodeProcess.inputStream.use { it.bufferedReader().readText().trim() }
project.providers.exec {
it.commandLine("node", "--print", "require.resolve('react-native/package.json')")
}

val nodeProcessOutput = nodeProcess.standardOutput.asText.get().trim()

if (nodeProcessOutput.isNotEmpty()) {
val nodeModuleCliJs = File(nodeProcessOutput)
Expand Down
Loading