Skip to content

Commit

Permalink
Backport the cliPath fix to the Gradle Plugin (#32193)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #32193

This Diff is backporting the change in #31839
applied to `react.gradle` also to the React Gradle Plugin. Ideally we would like to two
logic to be in sync as much as possible.

Changelog:
[Internal] [Changed] - Backport the cliPath fix to the Gradle Plugin

Reviewed By: ShikaSD

Differential Revision: D30899057

fbshipit-source-id: a28628b36b3dfe565dbdc8d6416c5d25ddf1fe03
  • Loading branch information
cortinico authored and facebook-github-bot committed Sep 13, 2021
1 parent 24bf1c5 commit 8d4fe82
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
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

0 comments on commit 8d4fe82

Please sign in to comment.