diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt index 3f5e23b35154..801956e5e10f 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt @@ -35,7 +35,9 @@ internal fun detectedCliPath( config: ReactAppExtension, ): String = detectCliPath( - projectDir = projectDir, reactRoot = config.reactRoot, preconfuredCliPath = config.cliPath) + projectDir = projectDir, + reactRoot = config.reactRoot, + preconfiguredCliPath = config.cliPath) /** * Computes the `hermesc` command location. The Algo follows this order: @@ -55,9 +57,15 @@ private fun detectEntryFile(entryFile: File?, reactRoot: File): File = else -> File(reactRoot, "index.js") } -private fun detectCliPath(projectDir: File, reactRoot: File, preconfuredCliPath: String?): String { +private fun detectCliPath( + projectDir: File, + reactRoot: File, + preconfiguredCliPath: String? +): String { // 1. preconfigured path - if (preconfuredCliPath != null) return preconfuredCliPath + if (preconfiguredCliPath != null) { + return File(projectDir, preconfiguredCliPath).toString() + } // 2. node module path val nodeProcess = diff --git a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tests/PathUtilsTest.kt b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tests/PathUtilsTest.kt index 62f1a672e04a..36069234b649 100644 --- a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tests/PathUtilsTest.kt +++ b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tests/PathUtilsTest.kt @@ -58,12 +58,25 @@ class PathUtilsTest { fun detectedCliPath_withCliPathFromExtension() { val project = ProjectBuilder.builder().build() val extension = ReactAppExtension(project) - val expected = tempFolder.newFile("fake-cli.sh") - extension.cliPath = expected.toString() + val expected = File(project.projectDir, "fake-cli.sh").apply { writeText("#!/bin/bash") } + extension.cliPath = "./fake-cli.sh" val actual = detectedCliPath(project.projectDir, extension) - assertEquals(expected.toString(), actual) + assertEquals(expected.canonicalPath, File(actual).canonicalPath) + } + + @Test + fun detectedCliPath_withCliPathFromExtensionInParentFolder() { + val rootProject = ProjectBuilder.builder().build() + val project = ProjectBuilder.builder().withParent(rootProject).build() + val extension = ReactAppExtension(project) + val expected = File(rootProject.projectDir, "cli-in-root.sh").apply { writeText("#!/bin/bash") } + extension.cliPath = "../cli-in-root.sh" + + val actual = detectedCliPath(project.projectDir, extension) + + assertEquals(expected.canonicalPath, File(actual).canonicalPath) } @Test