mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
RNGP - Cleanup prealpha logic from the Gradle Plugin (#48689)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c09b71b990
commit
63442d3757
-19
@@ -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
|
||||
@@ -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.
|
||||
@@ -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(
|
||||
|
||||
+1
-47
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
-283
@@ -15,7 +15,6 @@ import com.facebook.react.utils.ProjectUtils.getReactNativeArchitectures
|
||||
import com.facebook.react.utils.ProjectUtils.isHermesEnabled
|
||||
import com.facebook.react.utils.ProjectUtils.isNewArchEnabled
|
||||
import com.facebook.react.utils.ProjectUtils.needsCodegenFromPackageJson
|
||||
import com.facebook.react.utils.ProjectUtils.shouldWarnIfNewArchFlagIsSetInPrealpha
|
||||
import java.io.File
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Rule
|
||||
@@ -75,78 +74,6 @@ class ProjectUtilsTest {
|
||||
assertThat(project.isNewArchEnabled(extension)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isNewArchEnabled_withRNVersionPrealpha_returnTrue() {
|
||||
val project = createProject()
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "0.0.0-prealpha-202310916"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.isNewArchEnabled(extension)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isNewArchEnabled_withRNVersion1PrereleaseString_returnTrue() {
|
||||
val project = createProject()
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "1.2.3-prealpha0"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.isNewArchEnabled(extension)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isNewArchEnabled_withRNVersion1PrereleaseStringDotNumber_returnTrue() {
|
||||
val project = createProject()
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "1.2.3-prealpha.0"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.isNewArchEnabled(extension)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isNewArchEnabled_withRNVersion1PrereleaseStringDashNumber_returnTrue() {
|
||||
val project = createProject()
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "1.2.3-prealpha-0"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.isNewArchEnabled(extension)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isNewArchEnabled_withRNVersion1000_returnFalse() {
|
||||
val project = createProject()
|
||||
@@ -320,214 +247,4 @@ class ProjectUtilsTest {
|
||||
assertThat(archs[2]).isEqualTo("x86")
|
||||
assertThat(archs[3]).isEqualTo("x86_64")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNewArchIsSetToFalseAndOnPrealpha_returnTrue() {
|
||||
val project = createProject()
|
||||
project.extensions.extraProperties.set("newArchEnabled", "false")
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "0.0.0-prealpha-2023100915"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenScopedNewArchIsSetToFalseAndOnPrealpha_returnTrue() {
|
||||
val project = createProject()
|
||||
project.extensions.extraProperties.set("react.newArchEnabled", "false")
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "0.0.0-prealpha-2023100915"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenBothAreSetToFalseAndOnPrealpha_returnTrue() {
|
||||
val project = createProject()
|
||||
project.extensions.extraProperties.set("newArchEnabled", "false")
|
||||
project.extensions.extraProperties.set("react.newArchEnabled", "false")
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "0.0.0-prealpha-2023100915"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNewArchIsSetToTrueAndOnPrealpha_returnFalse() {
|
||||
val project = createProject()
|
||||
project.extensions.extraProperties.set("newArchEnabled", "true")
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "0.0.0-prealpha-2023100915"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenScopedNewArchIsSetToTrueAndOnPrealpha_returnFalse() {
|
||||
val project = createProject()
|
||||
project.extensions.extraProperties.set("react.newArchEnabled", "true")
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "0.0.0-prealpha-2023100915"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenBothAreSetToTrueAndOnPrealpha_returnFalse() {
|
||||
val project = createProject()
|
||||
project.extensions.extraProperties.set("newArchEnabled", "true")
|
||||
project.extensions.extraProperties.set("react.newArchEnabled", "true")
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "0.0.0-prealpha-2023100915"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNoneAreSetAndOnPrealpha_returnFalse() {
|
||||
val project = createProject()
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "0.0.0-prealpha-2023100915"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNewArchIsSetToTrueAndNotOnPrealpha_returnFalse() {
|
||||
val project = createProject()
|
||||
project.extensions.extraProperties.set("newxArchEnabled", "true")
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "0.73.0"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenScopedNewArchIsSetToTrueAndNotOnPrealpha_returnFalse() {
|
||||
val project = createProject()
|
||||
project.extensions.extraProperties.set("react.newxArchEnabled", "true")
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "0.73.0"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenBothAreSetToTrueAndNotOnPrealpha_returnFalse() {
|
||||
val project = createProject()
|
||||
project.extensions.extraProperties.set("newArchEnabled", "true")
|
||||
project.extensions.extraProperties.set("react.newxArchEnabled", "true")
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "0.73.0"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNoneAreSetAndNotOnPrealpha_returnFalse() {
|
||||
val project = createProject()
|
||||
val extension = TestReactExtension(project)
|
||||
File(tempFolder.root, "package.json").apply {
|
||||
writeText(
|
||||
// language=json
|
||||
"""
|
||||
{
|
||||
"version": "0.73.0"
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
}
|
||||
extension.reactNativeDir.set(tempFolder.root)
|
||||
assertThat(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension)).isFalse()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user