Skip to content
Closed
Show file tree
Hide file tree
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 @@ -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:
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down