diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt index 26a5eb07eb7799..0e56882578a759 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt @@ -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 { 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 { } } - 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( diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/ProjectUtils.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/ProjectUtils.kt index 62f4019ae33e18..c6a72d89fde8ca 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/ProjectUtils.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/ProjectUtils.kt @@ -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[-[[-.]k]] - // Where - // major is a number - // minor is a number - // patch is a number - // [-.]k is optional, but if present is preceeded by a `-` - // the 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 } diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/ProjectUtilsTest.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/ProjectUtilsTest.kt index 9b04b3c7c6acd4..7cd48df1ee43f2 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/ProjectUtilsTest.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/ProjectUtilsTest.kt @@ -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() - } }