Skip to content

Commit

Permalink
Rename extension to just ReactExtension
Browse files Browse the repository at this point in the history
Summary:
I'm cleaning up the extension to be just ReactExtension and not ReactAppExtension.
Similarly the name of the extension will be just `react` and not `reactApp`.

Changelog:
[Internal] [Changed] - Rename extension to just ReactExtension

Reviewed By: ShikaSD

Differential Revision: D30964793

fbshipit-source-id: 8a4207825d424e133e51495c34c21284c50363ae
  • Loading branch information
cortinico authored and facebook-github-bot committed Sep 16, 2021
1 parent 972a43c commit 85031d0
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 37 deletions.
2 changes: 1 addition & 1 deletion ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ dependencies {
androidTestImplementation("org.mockito:mockito-core:${MOCKITO_CORE_VERSION}")
}

reactApp {
react {
// TODO: The library name is chosen for parity with Fabric components & iOS
// This should be changed to a more generic name, e.g. `ReactCoreSpec`.
libraryName = "rncore"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package com.facebook.react.codegen.plugin;

import com.android.build.gradle.BaseExtension;
import com.facebook.react.ReactAppExtension;
import com.facebook.react.ReactExtension;
import com.facebook.react.codegen.generator.JavaGenerator;
import com.facebook.react.utils.GradleUtils;
import com.facebook.react.utils.PathUtils;
Expand All @@ -30,9 +30,8 @@
public class CodegenPlugin {

public void apply(final Project project) {
final ReactAppExtension extension =
GradleUtils.createOrGet(
project.getExtensions(), "reactApp", ReactAppExtension.class, project);
final ReactExtension extension =
GradleUtils.createOrGet(project.getExtensions(), "react", ReactExtension.class, project);

// 1. Set up build dir.
final File generatedSrcDir = new File(project.getBuildDir(), "generated/source/codegen");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ReactAppPlugin : Plugin<Project> {
}

private fun applyAppPlugin(project: Project) {
val config = project.extensions.createOrGet("reactApp", ReactAppExtension::class.java, project)
val config = project.extensions.createOrGet("react", ReactExtension::class.java, project)

if (config.applyAppPlugin.getOrElse(false)) {
project.afterEvaluate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property

abstract class ReactAppExtension @Inject constructor(project: Project) {
abstract class ReactExtension @Inject constructor(project: Project) {

private val objects = project.objects

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.gradle.api.tasks.Copy
private const val REACT_GROUP = "react"

@Suppress("SpreadOperator")
internal fun Project.configureReactTasks(variant: BaseVariant, config: ReactAppExtension) {
internal fun Project.configureReactTasks(variant: BaseVariant, config: ReactExtension) {
val targetName = variant.name.capitalize(Locale.ROOT)
val isRelease = variant.isRelease
val targetPath = variant.dirName
Expand Down Expand Up @@ -227,7 +227,7 @@ private fun Project.cleanupVMFiles(enableHermes: Boolean, isRelease: Boolean, ta
}
}

private fun BaseVariant.checkBundleEnabled(config: ReactAppExtension): Boolean {
private fun BaseVariant.checkBundleEnabled(config: ReactExtension): Boolean {
if (config.bundleIn.getting(name).isPresent) {
return config.bundleIn.getting(name).get()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

package com.facebook.react.utils

import com.facebook.react.ReactAppExtension
import com.facebook.react.ReactExtension
import java.io.File
import java.util.*
import org.apache.tools.ant.taskdefs.condition.Os
Expand All @@ -21,9 +21,9 @@ import org.apache.tools.ant.taskdefs.condition.Os
* 3. The `index.android.js` file, if available.
* 4. Fallback to the `index.js` file.
*
* @param config The [ReactAppExtension] configured for this project
* @param config The [ReactExtension] configured for this project
*/
internal fun detectedEntryFile(config: ReactAppExtension): File =
internal fun detectedEntryFile(config: ReactExtension): File =
detectEntryFile(
entryFile = config.entryFile.orNull?.asFile, reactRoot = config.reactRoot.get().asFile)

Expand All @@ -36,7 +36,7 @@ internal fun detectedEntryFile(config: ReactAppExtension): File =
*/
internal fun detectedCliPath(
projectDir: File,
config: ReactAppExtension,
config: ReactExtension,
): String =
detectCliPath(
projectDir = projectDir,
Expand All @@ -50,7 +50,7 @@ internal fun detectedCliPath(
* substituted with the correct OS arch.
* 3. Fails otherwise
*/
internal fun detectedHermesCommand(config: ReactAppExtension): String =
internal fun detectedHermesCommand(config: ReactExtension): String =
detectOSAwareHermesCommand(config.hermesCommand.get())

private fun detectEntryFile(entryFile: File?, reactRoot: File): File =
Expand Down Expand Up @@ -123,8 +123,8 @@ internal fun projectPathToLibraryName(projectPath: String): String =
.joinToString("") { it.capitalize(Locale.ROOT) }
.plus("Spec")

fun codegenGenerateSchemaCLI(config: ReactAppExtension): File =
fun codegenGenerateSchemaCLI(config: ReactExtension): File =
config.codegenDir.file("lib/cli/combine/combine-js-to-schema-cli.js").get().asFile

fun codegenGenerateNativeModuleSpecsCLI(config: ReactAppExtension): File =
fun codegenGenerateNativeModuleSpecsCLI(config: ReactExtension): File =
config.reactRoot.file("scripts/generate-specs-cli.js").get().asFile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ package com.facebook.react

import org.gradle.api.Project

class TestReactAppExtension(project: Project) : ReactAppExtension(project)
class TestReactExtension(project: Project) : ReactExtension(project)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

package com.facebook.react.tests

import com.facebook.react.ReactAppExtension
import com.facebook.react.ReactExtension
import com.facebook.react.utils.GradleUtils.createOrGet
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Assert.*
Expand All @@ -19,21 +19,20 @@ class GradleUtilsTest {
fun createOrGet_createsNewExtension() {
val project = ProjectBuilder.builder().build()

assertNull(project.extensions.findByType(ReactAppExtension::class.java))
assertNull(project.extensions.findByType(ReactExtension::class.java))

project.extensions.createOrGet("testExtension", ReactAppExtension::class.java, project)
project.extensions.createOrGet("testExtension", ReactExtension::class.java, project)

assertNotNull(project.extensions.findByType(ReactAppExtension::class.java))
assertNotNull(project.extensions.findByType(ReactExtension::class.java))
}

@Test
fun createOrGet_returnsExistingExtension() {
val project = ProjectBuilder.builder().build()
val expected =
project.extensions.create("testExtension", ReactAppExtension::class.java, project)
val expected = project.extensions.create("testExtension", ReactExtension::class.java, project)

assertEquals(
expected,
project.extensions.createOrGet("testExtension", ReactAppExtension::class.java, project))
project.extensions.createOrGet("testExtension", ReactExtension::class.java, project))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

package com.facebook.react.tests

import com.facebook.react.TestReactAppExtension
import com.facebook.react.TestReactExtension
import com.facebook.react.utils.*
import java.io.File
import org.gradle.testfixtures.ProjectBuilder
Expand All @@ -22,7 +22,7 @@ class PathUtilsTest {

@Test
fun detectedEntryFile_withProvidedVariable() {
val extension = TestReactAppExtension(ProjectBuilder.builder().build())
val extension = TestReactExtension(ProjectBuilder.builder().build())
val expected = tempFolder.newFile("fake.index.js")
extension.entryFile.set(expected)

Expand All @@ -33,7 +33,7 @@ class PathUtilsTest {

@Test
fun detectedEntryFile_withAndroidEntryPoint() {
val extension = TestReactAppExtension(ProjectBuilder.builder().build())
val extension = TestReactExtension(ProjectBuilder.builder().build())
extension.reactRoot.set(tempFolder.root)
tempFolder.newFile("index.android.js")

Expand All @@ -44,7 +44,7 @@ class PathUtilsTest {

@Test
fun detectedEntryFile_withDefaultEntryPoint() {
val extension = TestReactAppExtension(ProjectBuilder.builder().build())
val extension = TestReactExtension(ProjectBuilder.builder().build())
extension.reactRoot.set(tempFolder.root)

val actual = detectedEntryFile(extension)
Expand All @@ -55,7 +55,7 @@ class PathUtilsTest {
@Test
fun detectedCliPath_withCliPathFromExtension() {
val project = ProjectBuilder.builder().build()
val extension = TestReactAppExtension(project)
val extension = TestReactExtension(project)
val expected = File(project.projectDir, "fake-cli.sh")
extension.cliPath.set("fake-cli.sh")

Expand All @@ -68,7 +68,7 @@ class PathUtilsTest {
fun detectedCliPath_withCliPathFromExtensionInParentFolder() {
val rootProject = ProjectBuilder.builder().build()
val project = ProjectBuilder.builder().withParent(rootProject).build()
val extension = TestReactAppExtension(project)
val extension = TestReactExtension(project)
val expected = File(rootProject.projectDir, "cli-in-root.sh").apply { writeText("#!/bin/bash") }
extension.cliPath.set("../cli-in-root.sh")

Expand All @@ -80,7 +80,7 @@ class PathUtilsTest {
@Test
fun detectedCliPath_withCliFromNodeModules() {
val project = ProjectBuilder.builder().build()
val extension = TestReactAppExtension(project)
val extension = TestReactExtension(project)
extension.reactRoot.set(tempFolder.root)
val expected =
File(tempFolder.root, "node_modules/react-native/cli.js").apply {
Expand All @@ -96,14 +96,14 @@ class PathUtilsTest {
@Test(expected = IllegalStateException::class)
fun detectedCliPath_failsIfNotFound() {
val project = ProjectBuilder.builder().build()
val extension = TestReactAppExtension(project)
val extension = TestReactExtension(project)

detectedCliPath(project.projectDir, extension)
}

@Test
fun detectedHermesCommand_withPathFromExtension() {
val extension = TestReactAppExtension(ProjectBuilder.builder().build())
val extension = TestReactExtension(ProjectBuilder.builder().build())
val expected = tempFolder.newFile("hermesc")
extension.hermesCommand.set(expected.toString())

Expand All @@ -114,7 +114,7 @@ class PathUtilsTest {

@Test
fun detectedHermesCommand_withOSSpecificBin() {
val extension = TestReactAppExtension(ProjectBuilder.builder().build())
val extension = TestReactExtension(ProjectBuilder.builder().build())

val actual = detectedHermesCommand(extension)

Expand Down Expand Up @@ -145,7 +145,7 @@ class PathUtilsTest {

@Test
fun codegenGenerateSchemaCLI_worksCorrectly() {
val extension = TestReactAppExtension(ProjectBuilder.builder().build())
val extension = TestReactExtension(ProjectBuilder.builder().build())
extension.codegenDir.set(tempFolder.root)
val expected =
File(tempFolder.root, "lib/cli/combine/combine-js-to-schema-cli.js").apply {
Expand All @@ -158,7 +158,7 @@ class PathUtilsTest {

@Test
fun codegenGenerateNativeModuleSpecsCLI_worksCorrectly() {
val extension = TestReactAppExtension(ProjectBuilder.builder().build())
val extension = TestReactExtension(ProjectBuilder.builder().build())
extension.reactRoot.set(tempFolder.root)
val expected =
File(tempFolder.root, "scripts/generate-specs-cli.js").apply {
Expand Down
2 changes: 1 addition & 1 deletion packages/rn-tester/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ plugins {
* ]
*/

reactApp {
react {
applyAppPlugin = true
cliPath = "../../../../cli.js"
bundleAssetName = "RNTesterApp.android.bundle"
Expand Down

0 comments on commit 85031d0

Please sign in to comment.