Skip to content

Commit

Permalink
Cleanup prealpha logic from Cocoapods
Browse files Browse the repository at this point in the history
Summary:
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] -

Differential Revision: D68205691
  • Loading branch information
cortinico authored and facebook-github-bot committed Jan 15, 2025
1 parent ef4cefd commit f5c198b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,160 +207,6 @@ def test_installModulesDependencies_whenNewArchDisabledAndSearchPathsAndCompiler
)
end

# =============================== #
# Test - Compute New Arch Enabled #
# =============================== #

def test_computeNewArchEnabled_whenOnMainAndFlagTrueAndEnvVarNil_returnTrueWithNoWarning
version = '1000.0.0'
new_arch_enabled = true
ENV['RCT_NEW_ARCH_ENABLED'] = nil
isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)

assert_equal("1", isEnabled)
assert_equal([], Pod::UI.collected_warns)
end

def test_computeNewArchEnabled_whenOnMainAndFlagTrueAndEnvVar1_returnTrueWithNoWarning
version = '1000.0.0'
new_arch_enabled = true
ENV['RCT_NEW_ARCH_ENABLED'] = "1"
isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)

assert_equal("1", isEnabled)
assert_equal([], Pod::UI.collected_warns)
end

def test_computeNewArchEnabled_whenOnMainAndFlagFalseAndEnvVarNil_returnFalseWithNoWarning
version = '1000.0.0'
new_arch_enabled = false
ENV['RCT_NEW_ARCH_ENABLED'] = nil

isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)

assert_equal("0", isEnabled)
assert_equal([], Pod::UI.collected_warns)
end

def test_computeNewArchEnabled_whenOnMainAndFlagFalseAndEnvVar0_returnFalseWithNoWarning
version = '1000.0.0'
new_arch_enabled = false
ENV['RCT_NEW_ARCH_ENABLED'] = "0"

isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)

assert_equal("0", isEnabled)
assert_equal([], Pod::UI.collected_warns)
end

def test_computeNewArchEnabled_whenOnStableAndFlagTrueAndEnvNil_returnTrueWithNoWarning
version = '0.73.0'
new_arch_enabled = true
ENV['RCT_NEW_ARCH_ENABLED'] = nil

isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)

assert_equal("1", isEnabled)
assert_equal([], Pod::UI.collected_warns)
end

def test_computeNewArchEnabled_whenOnStableAndFlagTrueAndEnv1_returnTrueWithNoWarning
version = '0.73.0'
new_arch_enabled = true
ENV['RCT_NEW_ARCH_ENABLED'] = "1"

isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)

assert_equal("1", isEnabled)
assert_equal([], Pod::UI.collected_warns)
end

def test_computeNewArchEnabled_whenOnStableAndFlagFalseAndEnvNil_returnFalseWithNoWarning
version = '0.73.0'
new_arch_enabled = false
ENV['RCT_NEW_ARCH_ENABLED'] = nil

isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)

assert_equal("0", isEnabled)
assert_equal([], Pod::UI.collected_warns)
end

def test_computeNewArchEnabled_whenOnStableAndFlagFalseAndEnv0_returnFalseWithNoWarning
version = '0.73.0'
new_arch_enabled = false
ENV['RCT_NEW_ARCH_ENABLED'] = "0"

isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)

assert_equal("0", isEnabled)
assert_equal([], Pod::UI.collected_warns)
end

def test_computeNewArchEnabled_whenOn100AndFlagTrueAndEnvNil_returnTrueWithNoWarning
version = '0.0.0-prealpha.0'
new_arch_enabled = true
ENV['RCT_NEW_ARCH_ENABLED'] = nil

isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)

assert_equal("1", isEnabled)
assert_equal([], Pod::UI.collected_warns)
end

def test_computeNewArchEnabled_whenOn100AndFlagTrueAndEnv1_returnTrueWithWarning
version = '0.0.0-prealpha.0'
new_arch_enabled = true
ENV['RCT_NEW_ARCH_ENABLED'] = "1"

isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)

assert_equal("1", isEnabled)
assert_equal(["[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."], Pod::UI.collected_warns)
end


def test_computeNewArchEnabled_whenOn100PrealphaWithDotsAndFlagFalseAndEnv0_returnTrueWithWarning
version = '0.0.0-prealpha.0'
new_arch_enabled = false
ENV['RCT_NEW_ARCH_ENABLED'] = "0"

isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)

assert_equal("1", isEnabled)
assert_equal(["[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."], Pod::UI.collected_warns)
end

def test_computeNewArchEnabled_whenOn100PrealphaWithDashAndFlagFalse_returnTrue
version = '0.0.0-prealpha-0'
new_arch_enabled = false

isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)

assert_equal("1", isEnabled)
end

def test_computeNewArchEnabled_whenOn100PrealphaOnlyWordsAndFlagFalse_returnTrue
version = '0.0.0-prealpha0'
new_arch_enabled = false

isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)

assert_equal("1", isEnabled)
end

def test_computeNewArchEnabled_whenOnGreaterThan100AndFlagFalse_returnTrue
version = '3.2.1'
new_arch_enabled = false

isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)

assert_equal("0", isEnabled)
assert_equal([], Pod::UI.collected_warns);
end

# =================================== #
# Test - Extract React Native Version #
# =================================== #
Expand All @@ -377,15 +223,15 @@ def test_extractReactNativeVersion_whenFileDoesNotExists_raiseError()
def test_extractReactNativeVersion_whenFileExists_returnTheRightVersion()
react_native_path = "./node_modules/react-native/"
full_path = File.join(react_native_path, "package.json")
json = "{\"version\": \"1.0.0-prealpha.0\"}"
json = "{\"version\": \"1.2.3-prerelease.4\"}"
FileMock.mocked_existing_files([full_path])
FileMock.files_to_read({
full_path => json
})

version = NewArchitectureHelper.extract_react_native_version(react_native_path, :file_manager => FileMock)

assert_equal("1.0.0-prealpha.0", version)
assert_equal("1.2.3-prerelease.4", version)
end

# =============================== #
Expand Down
30 changes: 0 additions & 30 deletions packages/react-native/scripts/cocoapods/new_architecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,36 +158,6 @@ def self.extract_react_native_version(react_native_path, file_manager: File, jso
return package["version"]
end

def self.compute_new_arch_enabled(new_arch_enabled, react_native_version)
# Regex that identify a version with the syntax `<major>.<minor>.<patch>[-<prerelease>[.-]k]
# where
# - major is a number
# - minor is a number
# - patch is a number
# - prerelease is a string (can include numbers)
# - k is a number
version_regex = /^(\d+)\.(\d+)\.(\d+)(?:-(\w+(?:[-.]\d+)?))?$/

if match_data = react_native_version.match(version_regex)

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 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."
Pod::UI.warn warning_message
@@NewArchWarningEmitted = true
end

return "1"
end
end
return new_arch_enabled ? "1" : "0"
end

def self.new_arch_enabled
return ENV["RCT_NEW_ARCH_ENABLED"] == nil || ENV["RCT_NEW_ARCH_ENABLED"] == "1"
end
Expand Down
1 change: 0 additions & 1 deletion packages/react-native/scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def use_react_native! (
# Better to rely and enable this environment flag if the new architecture is turned on using flags.
relative_path_from_current = Pod::Config.instance.installation_root.relative_path_from(Pathname.pwd)
react_native_version = NewArchitectureHelper.extract_react_native_version(File.join(relative_path_from_current, path))
ENV['RCT_NEW_ARCH_ENABLED'] = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, react_native_version)
fabric_enabled = fabric_enabled || NewArchitectureHelper.new_arch_enabled

ENV['RCT_FABRIC_ENABLED'] = fabric_enabled ? "1" : "0"
Expand Down

0 comments on commit f5c198b

Please sign in to comment.