Skip to content

Commit

Permalink
Simplify furthermore App migration
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Riccardo Cipolleschi authored and facebook-github-bot committed Sep 14, 2022
1 parent f31134a commit 34fafb2
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 6 deletions.
6 changes: 2 additions & 4 deletions packages/rn-tester/Podfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require_relative '../../scripts/react_native_pods'

source 'https://cdn.cocoapods.org/'
platform :ios, '12.4'
platform :ios, min_ios_version_supported

# Temporary solution to suppress duplicated GUID error.
# Can be removed once we move to generate files outside pod install.
install! 'cocoapods', :deterministic_uuids => false
prepare_react_native_project!

USE_FRAMEWORKS = ENV['USE_FRAMEWORKS'] == '1'
IN_CI = ENV['CI'] == 'true'
Expand Down
36 changes: 36 additions & 0 deletions scripts/cocoapods/__tests__/utils-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,27 @@
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

# ======================= #
Expand Down Expand Up @@ -443,6 +456,29 @@ def test_setNodeModulesUserSettings_addTheUserSetting
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
Expand Down
8 changes: 8 additions & 0 deletions scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,13 @@ def self.fix_library_search_path(config)
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 changes: 17 additions & 0 deletions scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@

$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
Expand Down
4 changes: 2 additions & 2 deletions template/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/react-native/scripts/native_modules'

platform :ios, '12.4'
install! 'cocoapods', :deterministic_uuids => false
platform :ios, min_ios_version_supported
prepare_react_native_project!

flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled

Expand Down

0 comments on commit 34fafb2

Please sign in to comment.