Skip to content

Commit

Permalink
RNGP - Cleanup prealpha logic from the Gradle Plugin (#48689)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #48689

We don't intent to use the prealpha logic in the near future so it makes sense to remove it for
to simplify our already complicated release process. We can always revive it if we wish.

Changelog:
[Internal] [Changed] - RNGP - Cleanup prealpha logic from the Gradle Plugin

Reviewed By: cipolleschi

Differential Revision: D68205665

fbshipit-source-id: 81d5257544df97b566421164944e3b6e71f06635
  • Loading branch information
cortinico authored and facebook-github-bot committed Jan 15, 2025
1 parent c09b71b commit 63442d3
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 349 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.facebook.react.utils.JsonUtils
import com.facebook.react.utils.NdkConfiguratorUtils.configureReactNativeNdk
import com.facebook.react.utils.ProjectUtils.isNewArchEnabled
import com.facebook.react.utils.ProjectUtils.needsCodegenFromPackageJson
import com.facebook.react.utils.ProjectUtils.shouldWarnIfNewArchFlagIsSetInPrealpha
import com.facebook.react.utils.findPackageJsonFile
import java.io.File
import kotlin.system.exitProcess
Expand All @@ -42,7 +41,6 @@ class ReactPlugin : Plugin<Project> {
override fun apply(project: Project) {
checkJvmVersion(project)
val extension = project.extensions.create("react", ReactExtension::class.java, project)
checkIfNewArchFlagIsSet(project, extension)

// We register a private extension on the rootProject so that project wide configs
// like codegen config can be propagated from app project to libraries.
Expand Down Expand Up @@ -112,23 +110,6 @@ class ReactPlugin : Plugin<Project> {
}
}

private fun checkIfNewArchFlagIsSet(project: Project, extension: ReactExtension) {
if (project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension)) {
project.logger.warn(
"""
********************************************************************************
WARNING: This version of React Native is ignoring the `newArchEnabled` flag you set. Please set it to true or remove it to suppress this warning.
********************************************************************************
"""
.trimIndent())
}
}

/** This function sets up `react-native-codegen` in our Gradle plugin. */
@Suppress("UnstableApiUsage")
private fun configureCodegen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import com.facebook.react.utils.PropertyUtils.REACT_NATIVE_ARCHITECTURES
import com.facebook.react.utils.PropertyUtils.SCOPED_HERMES_ENABLED
import com.facebook.react.utils.PropertyUtils.SCOPED_NEW_ARCH_ENABLED
import com.facebook.react.utils.PropertyUtils.SCOPED_REACT_NATIVE_ARCHITECTURES
import java.io.File
import org.gradle.api.Project
import org.gradle.api.file.DirectoryProperty

Expand All @@ -29,8 +28,7 @@ internal object ProjectUtils {
return (project.hasProperty(NEW_ARCH_ENABLED) &&
project.property(NEW_ARCH_ENABLED).toString().toBoolean()) ||
(project.hasProperty(SCOPED_NEW_ARCH_ENABLED) &&
project.property(SCOPED_NEW_ARCH_ENABLED).toString().toBoolean()) ||
shouldEnableNewArchForReactNativeVersion(project.reactNativeDir(extension))
project.property(SCOPED_NEW_ARCH_ENABLED).toString().toBoolean())
}

internal val Project.isHermesEnabled: Boolean
Expand Down Expand Up @@ -83,50 +81,6 @@ internal object ProjectUtils {
internal fun Project.reactNativeDir(extension: ReactExtension): String =
extension.reactNativeDir.get().asFile.absolutePath

internal fun shouldEnableNewArchForReactNativeVersion(reactNativeDir: String): Boolean {
val packageJsonFile = File(reactNativeDir, "package.json")
if (!packageJsonFile.exists()) {
return false
}

val rnPackageJson = JsonUtils.fromPackageJson(packageJsonFile)
if (rnPackageJson == null) {
return false
}

// This regex describe the version syntax for React Native in the shape of
// major.minor.patch[-<prerelease>[[-.]k]]
// Where
// major is a number
// minor is a number
// patch is a number
// <prerelease>[-.]k is optional, but if present is preceeded by a `-`
// the <prerelease> tag is a string.
// it can be followed by `-` or `.` and k is a number.
val regex = """^(\d+)\.(\d+)\.(\d+)(?:-(\w+(?:[-.]\d+)?))?$""".toRegex()

val matchResult = regex.find(rnPackageJson.version)

if (matchResult == null) {
return false
}

val prerelease = matchResult.groupValues[4].toString()
return prerelease.contains("prealpha")
}

internal fun Project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension: ReactExtension): Boolean {

val propertySetToFalse =
(this.hasPropertySetToFalse(NEW_ARCH_ENABLED)) ||
(this.hasPropertySetToFalse(SCOPED_NEW_ARCH_ENABLED))

val shouldEnableNewArch =
shouldEnableNewArchForReactNativeVersion(this.reactNativeDir(extension))

return shouldEnableNewArch && propertySetToFalse
}

internal fun Project.hasPropertySetToFalse(property: String): Boolean =
this.hasProperty(property) && this.property(property).toString().toBoolean() == false
}
Loading

0 comments on commit 63442d3

Please sign in to comment.