Fix functions that turn on the New Architecture (#40770)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/40770

## Changelog:
[Internal] - Fix functions that turn on the New Architecture

Reviewed By: cortinico

Differential Revision: D50084427

fbshipit-source-id: aae0c77585929eacf8e890321e27e5049e53775e
This commit is contained in:
Riccardo Cipolleschi
2023-10-10 10:16:29 -07:00
committed by Facebook GitHub Bot
parent b1356fe0d6
commit 5c2ec558c1
4 changed files with 31 additions and 30 deletions
@@ -113,8 +113,8 @@ internal object ProjectUtils {
return false
}
val major = matchResult.groupValues[1].toInt()
return major > 0 && major < 1000
val prerelease = matchResult.groupValues[4].toString()
return prerelease.contains("prealpha")
}
internal fun Project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension: ReactExtension): Boolean {
@@ -76,7 +76,7 @@ class ProjectUtilsTest {
}
@Test
fun isNewArchEnabled_withRNVersion1_returnTrue() {
fun isNewArchEnabled_withRNVersionPrealpha_returnTrue() {
val project = createProject()
val extension = TestReactExtension(project)
File(tempFolder.root, "package.json").apply {
@@ -84,7 +84,7 @@ class ProjectUtilsTest {
// language=json
"""
{
"version": "1.2.3"
"version": "0.0.0-prealpha-202310916"
}
"""
.trimIndent())
@@ -322,7 +322,7 @@ class ProjectUtilsTest {
}
@Test
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNewArchIsSetToFalseAndOnMajor_returnTrue() {
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNewArchIsSetToFalseAndOnPrealpha_returnTrue() {
val project = createProject()
project.extensions.extraProperties.set("newArchEnabled", "false")
val extension = TestReactExtension(project)
@@ -331,7 +331,7 @@ class ProjectUtilsTest {
// language=json
"""
{
"version": "1.2.3"
"version": "0.0.0-prealpha-2023100915"
}
"""
.trimIndent())
@@ -341,7 +341,7 @@ class ProjectUtilsTest {
}
@Test
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenScopedNewArchIsSetToFalseAndOnMajor_returnTrue() {
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenScopedNewArchIsSetToFalseAndOnPrealpha_returnTrue() {
val project = createProject()
project.extensions.extraProperties.set("react.newArchEnabled", "false")
val extension = TestReactExtension(project)
@@ -350,7 +350,7 @@ class ProjectUtilsTest {
// language=json
"""
{
"version": "1.2.3"
"version": "0.0.0-prealpha-2023100915"
}
"""
.trimIndent())
@@ -360,7 +360,7 @@ class ProjectUtilsTest {
}
@Test
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenBothAreSetToFalseAndOnMajor_returnTrue() {
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenBothAreSetToFalseAndOnPrealpha_returnTrue() {
val project = createProject()
project.extensions.extraProperties.set("newArchEnabled", "false")
project.extensions.extraProperties.set("react.newArchEnabled", "false")
@@ -370,7 +370,7 @@ class ProjectUtilsTest {
// language=json
"""
{
"version": "1.2.3"
"version": "0.0.0-prealpha-2023100915"
}
"""
.trimIndent())
@@ -380,7 +380,7 @@ class ProjectUtilsTest {
}
@Test
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNewArchIsSetToTrueAndOnMajor_returnFalse() {
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNewArchIsSetToTrueAndOnPrealpha_returnFalse() {
val project = createProject()
project.extensions.extraProperties.set("newArchEnabled", "true")
val extension = TestReactExtension(project)
@@ -389,7 +389,7 @@ class ProjectUtilsTest {
// language=json
"""
{
"version": "1.2.3"
"version": "0.0.0-prealpha-2023100915"
}
"""
.trimIndent())
@@ -399,7 +399,7 @@ class ProjectUtilsTest {
}
@Test
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenScopedNewArchIsSetToTrueAndOnMajor_returnFalse() {
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenScopedNewArchIsSetToTrueAndOnPrealpha_returnFalse() {
val project = createProject()
project.extensions.extraProperties.set("react.newArchEnabled", "true")
val extension = TestReactExtension(project)
@@ -408,7 +408,7 @@ class ProjectUtilsTest {
// language=json
"""
{
"version": "1.2.3"
"version": "0.0.0-prealpha-2023100915"
}
"""
.trimIndent())
@@ -418,7 +418,7 @@ class ProjectUtilsTest {
}
@Test
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenBothAreSetToTrueAndOnMajor_returnFalse() {
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenBothAreSetToTrueAndOnPrealpha_returnFalse() {
val project = createProject()
project.extensions.extraProperties.set("newArchEnabled", "true")
project.extensions.extraProperties.set("react.newArchEnabled", "true")
@@ -428,7 +428,7 @@ class ProjectUtilsTest {
// language=json
"""
{
"version": "1.2.3"
"version": "0.0.0-prealpha-2023100915"
}
"""
.trimIndent())
@@ -438,7 +438,7 @@ class ProjectUtilsTest {
}
@Test
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNoneAreSetAndOnMajor_returnFalse() {
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNoneAreSetAndOnPrealpha_returnFalse() {
val project = createProject()
val extension = TestReactExtension(project)
File(tempFolder.root, "package.json").apply {
@@ -446,7 +446,7 @@ class ProjectUtilsTest {
// language=json
"""
{
"version": "1.2.3"
"version": "0.0.0-prealpha-2023100915"
}
"""
.trimIndent())
@@ -456,7 +456,7 @@ class ProjectUtilsTest {
}
@Test
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNewArchIsSetToTrueAndNotOnMajor_returnFalse() {
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNewArchIsSetToTrueAndNotOnPrealpha_returnFalse() {
val project = createProject()
project.extensions.extraProperties.set("newxArchEnabled", "true")
val extension = TestReactExtension(project)
@@ -475,7 +475,7 @@ class ProjectUtilsTest {
}
@Test
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenScopedNewArchIsSetToTrueAndNotOnMajor_returnFalse() {
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenScopedNewArchIsSetToTrueAndNotOnPrealpha_returnFalse() {
val project = createProject()
project.extensions.extraProperties.set("react.newxArchEnabled", "true")
val extension = TestReactExtension(project)
@@ -494,7 +494,7 @@ class ProjectUtilsTest {
}
@Test
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenBothAreSetToTrueAndNotOnMajor_returnFalse() {
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenBothAreSetToTrueAndNotOnPrealpha_returnFalse() {
val project = createProject()
project.extensions.extraProperties.set("newArchEnabled", "true")
project.extensions.extraProperties.set("react.newxArchEnabled", "true")
@@ -514,7 +514,7 @@ class ProjectUtilsTest {
}
@Test
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNoneAreSetAndNotOnMajor_returnFalse() {
fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNoneAreSetAndNotOnPrealpha_returnFalse() {
val project = createProject()
val extension = TestReactExtension(project)
File(tempFolder.root, "package.json").apply {
@@ -284,7 +284,7 @@ class NewArchitectureTests < Test::Unit::TestCase
end
def test_computeNewArchEnabled_whenOn100AndFlagTrueAndEnvNil_returnTrueWithNoWarning
version = '1.0.0-prealpha.0'
version = '0.0.0-prealpha.0'
new_arch_enabled = true
ENV['RCT_NEW_ARCH_ENABLED'] = nil
@@ -295,7 +295,7 @@ class NewArchitectureTests < Test::Unit::TestCase
end
def test_computeNewArchEnabled_whenOn100AndFlagTrueAndEnv1_returnTrueWithWarning
version = '1.0.0-prealpha.0'
version = '0.0.0-prealpha.0'
new_arch_enabled = true
ENV['RCT_NEW_ARCH_ENABLED'] = "1"
@@ -308,7 +308,7 @@ class NewArchitectureTests < Test::Unit::TestCase
def test_computeNewArchEnabled_whenOn100PrealphaWithDotsAndFlagFalseAndEnv0_returnTrueWithWarning
version = '1.0.0-prealpha.0'
version = '0.0.0-prealpha.0'
new_arch_enabled = false
ENV['RCT_NEW_ARCH_ENABLED'] = "0"
@@ -320,7 +320,7 @@ class NewArchitectureTests < Test::Unit::TestCase
end
def test_computeNewArchEnabled_whenOn100PrealphaWithDashAndFlagFalse_returnTrue
version = '1.0.0-prealpha-0'
version = '0.0.0-prealpha-0'
new_arch_enabled = false
isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)
@@ -329,7 +329,7 @@ class NewArchitectureTests < Test::Unit::TestCase
end
def test_computeNewArchEnabled_whenOn100PrealphaOnlyWordsAndFlagFalse_returnTrue
version = '1.0.0-prealpha0'
version = '0.0.0-prealpha0'
new_arch_enabled = false
isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)
@@ -343,7 +343,8 @@ class NewArchitectureTests < Test::Unit::TestCase
isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)
assert_equal("1", isEnabled)
assert_equal("0", isEnabled)
assert_equal([], Pod::UI.collected_warns);
end
# =================================== #
@@ -186,11 +186,11 @@ class NewArchitectureHelper
if match_data = react_native_version.match(version_regex)
major = match_data[1].to_i
prerelease = match_data[4].to_s
# We want to enforce the new architecture for 1.0.0 and greater,
# but not for 1000 as version 1000 is currently main.
if major > 0 && major < 1000
if prerelease.include?("prealpha")
if ENV['RCT_NEW_ARCH_ENABLED'] != nil && !@@NewArchWarningEmitted
warning_message = "[New Architecture] Starting from version 1.0.0-prealpha the value of the " \
"RCT_NEW_ARCH_ENABLED flag is ignored and the New Architecture is enabled by default."