Simplify furthermore App migration

Summary:
This Diff adds a couple of APIs to the `react_native_pods.rb` file to simplify further the migration to the New Architecture for the iOS app.
Specifically, it aims to simplify [this](https://reactnative.dev/docs/next/new-architecture-app-intro#ios---build-the-project) steps by offering a RN-managed min version and creating the .xcode.env file for the user if it is missing.

## Changelog

[iOS][Added] - Add new API to simplify app migration

Reviewed By: cortinico

Differential Revision: D39469599

fbshipit-source-id: f0323e86c83c2731671fcd5bb4288071304bb43b
This commit is contained in:
Riccardo Cipolleschi
2022-09-14 04:21:02 -07:00
committed by Facebook GitHub Bot
parent f31134af7d
commit 34fafb2b88
5 changed files with 65 additions and 6 deletions
+36
View File
@@ -10,14 +10,27 @@ require_relative "./test_utils/PodMock.rb"
require_relative "./test_utils/InstallerMock.rb"
require_relative "./test_utils/EnvironmentMock.rb"
require_relative "./test_utils/SysctlCheckerMock.rb"
require_relative "./test_utils/FileMock.rb"
require_relative "./test_utils/systemUtils.rb"
require_relative "./test_utils/PathnameMock.rb"
class UtilsTests < Test::Unit::TestCase
def setup
@base_path = "~/app/ios"
Pathname.pwd!(@base_path)
File.enable_testing_mode!
end
def teardown
File.reset()
Pod::UI.reset()
Pathname.reset()
Pod::Config.reset()
SysctlChecker.reset()
Environment.reset()
ENV['RCT_NEW_ARCH_ENABLED'] = '0'
ENV['USE_HERMES'] = '1'
system_reset_commands
end
# ======================= #
@@ -443,6 +456,29 @@ class UtilsTests < Test::Unit::TestCase
assert_equal(pods_projects_mock.save_invocation_count, 1)
assert_equal(Pod::UI.collected_messages, ["Setting REACT_NATIVE build settings"])
end
# =================================== #
# Test - Prepare React Native Project #
# =================================== #
def test_createXcodeEnvIfMissing_whenItIsPresent_doNothing
# Arrange
File.mocked_existing_files("/.xcode.env")
# Act
ReactNativePodsUtils.create_xcode_env_if_missing
# Assert
assert_equal(File.exist_invocation_params, ["/.xcode.env"])
assert_equal($collected_commands, [])
end
def test_createXcodeEnvIfMissing_whenItIsNotPresent_createsIt
# Arrange
# Act
ReactNativePodsUtils.create_xcode_env_if_missing
# Assert
assert_equal(File.exist_invocation_params, ["/.xcode.env"])
assert_equal($collected_commands, ["echo 'export NODE_BINARY=$(command -v node)' > /.xcode.env"])
end
end
def prepare_empty_user_project_mock
+8
View File
@@ -152,5 +152,13 @@ class ReactNativePodsUtils
end
end
def self.create_xcode_env_if_missing
relative_path = Pod::Config.instance.installation_root.relative_path_from(Pathname.pwd)
file_path = File.join(relative_path, '.xcode.env')
if File.exist?(file_path)
return
end
system("echo 'export NODE_BINARY=$(command -v node)' > #{file_path}")
end
end
+17
View File
@@ -23,6 +23,23 @@ $FOLLY_VERSION = '2021.07.22.00'
$START_TIME = Time.now.to_i
# This function returns the min iOS version supported by React Native
# By using this function, you won't have to manualy change your Podfile
# when we change the minimum version supported by the framework.
def min_ios_version_supported
return '12.4'
end
# This function prepares the project for React Native, before processing
# all the target exposed by the framework.
def prepare_react_native_project!
# Temporary solution to suppress duplicated GUID error.
# Can be removed once we move to generate files outside pod install.
install! 'cocoapods', :deterministic_uuids => false
ReactNativePodsUtils.create_xcode_env_if_missing
end
# Function that setup all the react native dependencies
# 
# Parameters