diff --git a/packages/react-native/scripts/cocoapods/__tests__/codegen-test.rb b/packages/react-native/scripts/cocoapods/__tests__/codegen-test.rb index 70573b4f3162ef..44ebdb71b6f37c 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/codegen-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/codegen-test.rb @@ -182,6 +182,47 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen() }) end + def testCheckAndGenerateEmptyThirdPartyProvider_withAbsoluteReactNativePath_buildCodegen() + # Arrange + rn_path = '/Users/distiller/react-native/packages/react-native' + codegen_cli_path = rn_path + "/../@react-native/codegen" + DirMock.mocked_existing_dirs([ + codegen_cli_path, + ]) + + # Act + checkAndGenerateEmptyThirdPartyProvider!(rn_path, false, dir_manager: DirMock, file_manager: FileMock) + + # Assert + assert_equal(Pathname.pwd_invocation_count, 1) + 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, + rn_path + "/React/Fabric/" + @tmp_schema_list_file + ]) + assert_equal(DirMock.exist_invocation_params, [ + rn_path + "/../react-native-codegen", + codegen_cli_path, + codegen_cli_path + "/lib", + ]) + assert_equal(Pod::UI.collected_messages, [ + "[Codegen] building #{codegen_cli_path}.", + "[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider" + ]) + assert_equal($collected_commands, [rn_path + "/../@react-native/codegen/scripts/oss/build.sh"]) + assert_equal(FileMock.open_files[0].collected_write, ["[]"]) + assert_equal(FileMock.open_files[0].fsync_invocation_count, 1) + assert_equal(Pod::Executable.executed_commands[0], { + "command" => "node", + "arguments" => [ + rn_path + "/scripts/generate-provider-cli.js", + "--platform", 'ios', + "--schemaListPath", rn_path + "/React/Fabric/" + @tmp_schema_list_file, + "--outputDir", rn_path + "/React/Fabric" + ] + }) + end + # ================= # # Test - RunCodegen # # ================= # diff --git a/packages/react-native/scripts/cocoapods/codegen.rb b/packages/react-native/scripts/cocoapods/codegen.rb index 56d120fcceda05..9c8e83bbb887bc 100644 --- a/packages/react-native/scripts/cocoapods/codegen.rb +++ b/packages/react-native/scripts/cocoapods/codegen.rb @@ -11,8 +11,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 = "#{relative_installation_root}/#{react_native_path}/../react-native-codegen"; - codegen_npm_path = "#{relative_installation_root}/#{react_native_path}/../@react-native/codegen"; + 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_cli_path = "" if dir_manager.exist?(codegen_repo_path) @@ -61,7 +61,7 @@ def checkAndGenerateEmptyThirdPartyProvider!(react_native_path, new_arch_enabled Pod::Executable.execute_command( 'node', [ - "#{relative_installation_root}/#{react_native_path}/scripts/generate-provider-cli.js", + "#{basePath(react_native_path, relative_installation_root)}/scripts/generate-provider-cli.js", "--platform", 'ios', "--schemaListPath", temp_schema_list_path, "--outputDir", "#{output_dir}" @@ -108,3 +108,12 @@ def run_codegen!( codegen_utils.generate_react_codegen_podspec!(react_codegen_spec, codegen_output_dir) end end + +def basePath(react_native_path, relative_installation_root) + expanded_path = File.expand_path(react_native_path) + if expanded_path == react_native_path + react_native_path + else + File.join(relative_installation_root.to_s, react_native_path) + end +end