diff --git a/packages/react-native/scripts/cocoapods/__tests__/codegen-test.rb b/packages/react-native/scripts/cocoapods/__tests__/codegen-test.rb index 44ebdb71b6f37c..32769fd6f91d90 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/codegen-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/codegen-test.rb @@ -55,7 +55,7 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenFileAlreadyExists_doNothing( checkAndGenerateEmptyThirdPartyProvider!(@prefix, false, dir_manager: DirMock, file_manager: FileMock) # Assert - assert_equal(Pathname.pwd_invocation_count, 1) + assert_equal(Pathname.pwd_invocation_count, 0) assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1) assert_equal(FileMock.exist_invocation_params, [ @prefix + "/React/Fabric/" + @third_party_provider_header, @@ -81,7 +81,7 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenHeaderMissingAndCodegenMissi } # Assert - assert_equal(Pathname.pwd_invocation_count, 1) + assert_equal(Pathname.pwd_invocation_count, 0) assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1) assert_equal(FileMock.exist_invocation_params, [ @prefix + "/React/Fabric/" + @third_party_provider_header @@ -113,7 +113,7 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenImplementationMissingAndCode checkAndGenerateEmptyThirdPartyProvider!(@prefix, false, dir_manager: DirMock, file_manager: FileMock) # Assert - assert_equal(Pathname.pwd_invocation_count, 1) + assert_equal(Pathname.pwd_invocation_count, 0) assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1) assert_equal(FileMock.exist_invocation_params, [ @prefix + "/React/Fabric/" + @third_party_provider_header, @@ -153,7 +153,7 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen() checkAndGenerateEmptyThirdPartyProvider!(@prefix, false, dir_manager: DirMock, file_manager: FileMock) # Assert - assert_equal(Pathname.pwd_invocation_count, 1) + assert_equal(Pathname.pwd_invocation_count, 0) assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1) assert_equal(FileMock.exist_invocation_params, [ @prefix + "/React/Fabric/" + @third_party_provider_header, @@ -194,7 +194,7 @@ def testCheckAndGenerateEmptyThirdPartyProvider_withAbsoluteReactNativePath_buil checkAndGenerateEmptyThirdPartyProvider!(rn_path, false, dir_manager: DirMock, file_manager: FileMock) # Assert - assert_equal(Pathname.pwd_invocation_count, 1) + assert_equal(Pathname.pwd_invocation_count, 0) assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1) assert_equal(FileMock.exist_invocation_params, [ rn_path + "/React/Fabric/" + @third_party_provider_header, diff --git a/packages/react-native/scripts/cocoapods/__tests__/codegen_utils-test.rb b/packages/react-native/scripts/cocoapods/__tests__/codegen_utils-test.rb index da138e23b86950..639c9d1519ef38 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/codegen_utils-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/codegen_utils-test.rb @@ -75,7 +75,7 @@ def testGenerateReactCodegenPodspec_whenItHasNotBeenAlreadyGenerated_generatesIt CodegenUtils.new().generate_react_codegen_podspec!(spec, codegen_output_dir, file_manager: FileMock) # Assert - assert_equal(Pathname.pwd_invocation_count, 1) + assert_equal(Pathname.pwd_invocation_count, 0) assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1) assert_equal(Pod::Executable.executed_commands, [{ "command" => 'mkdir', "arguments" => ["-p", "~/app/ios/build"]}]) assert_equal(Pod::UI.collected_messages, ["[Codegen] Generating ~/app/ios/build/React-Codegen.podspec.json"]) diff --git a/packages/react-native/scripts/cocoapods/codegen.rb b/packages/react-native/scripts/cocoapods/codegen.rb index 0a69b92d8b4c04..3838227f1d5562 100644 --- a/packages/react-native/scripts/cocoapods/codegen.rb +++ b/packages/react-native/scripts/cocoapods/codegen.rb @@ -3,6 +3,8 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. +require 'pathname' + # It builds the codegen CLI if it is not present # # Parameters: @@ -11,8 +13,8 @@ # - dir_manager: a class that implements the `Dir` interface. Defaults to `Dir`, the Dependency can be injected for testing purposes. # @throws an error if it could not find the codegen folder. def build_codegen!(react_native_path, relative_installation_root, dir_manager: Dir) - codegen_repo_path = "#{basePath(react_native_path, relative_installation_root)}/../react-native-codegen"; - codegen_npm_path = "#{basePath(react_native_path, relative_installation_root)}/../@react-native/codegen"; + codegen_repo_path = File.join(basePath(react_native_path, relative_installation_root), "..", "react-native-codegen") + codegen_npm_path = File.join(basePath(react_native_path, relative_installation_root), "..", "@react-native/codegen") codegen_cli_path = "" if dir_manager.exist?(codegen_repo_path) @@ -110,9 +112,9 @@ def run_codegen!( end def basePath(react_native_path, relative_installation_root) - if react_native_path.start_with?("/") + if Pathname.new(react_native_path).absolute react_native_path else - "#{relative_installation_root.to_s}/#{react_native_path}" + File.join(relative_installation_root.to_s, react_native_path) end end