Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build_codegen! not finding @react-native/codegen in pnpm setups #41456

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions packages/react-native/scripts/cocoapods/__tests__/codegen-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,32 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenFileAlreadyExists_doNothing(
assert_equal(Pod::Executable.executed_commands.length, 0)
end

def testCheckAndGenerateEmptyThirdPartyProvider_whenHeaderMissingAndCodegenMissing_raiseError()
def testCheckAndGenerateEmptyThirdPartyProvider_whenHeaderMissingAndCodegenMissing_dontBuildCodegen()

# Arrange
FileMock.mocked_existing_files([
@base_path + "/build/" + @third_party_provider_implementation,
])

# Act
assert_raise {
assert_nothing_raised {
checkAndGenerateEmptyThirdPartyProvider!(@prefix, 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, [
@prefix + "/React/Fabric/" + @third_party_provider_header
@prefix + "/React/Fabric/" + @third_party_provider_header,
@prefix + "/React/Fabric/tmpSchemaList.txt",
])
assert_equal(DirMock.exist_invocation_params, [
@base_path + "/"+ @prefix + "/../react-native-codegen",
@base_path + "/"+ @prefix + "/../@react-native/codegen",
])
assert_equal(Pod::UI.collected_messages, [])
assert_equal(Pod::UI.collected_messages, ["[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider"])
assert_equal($collected_commands, [])
assert_equal(FileMock.open_files.length, 0)
assert_equal(Pod::Executable.executed_commands.length, 0)
assert_equal(FileMock.open_files.length, 1)
assert_equal(Pod::Executable.executed_commands.length, 1)
end

def testCheckAndGenerateEmptyThirdPartyProvider_whenImplementationMissingAndCodegenrepoExists_dontBuildCodegen()
Expand Down Expand Up @@ -145,7 +145,7 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenImplementationMissingAndCode

def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen()
# Arrange
codegen_cli_path = @base_path + "/" + @prefix + "/../@react-native/codegen"
codegen_cli_path = @base_path + "/" + @prefix + "/../react-native-codegen"
DirMock.mocked_existing_dirs([
codegen_cli_path,
])
Expand All @@ -160,15 +160,14 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen()
@prefix + "/React/Fabric/" + @tmp_schema_list_file
])
assert_equal(DirMock.exist_invocation_params, [
@base_path + "/" + @prefix + "/../react-native-codegen",
codegen_cli_path,
codegen_cli_path + "/lib",
])
assert_equal(Pod::UI.collected_messages, [
"[Codegen] building #{codegen_cli_path}.",
"[Codegen] building #{codegen_cli_path}",
"[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider"
])
assert_equal($collected_commands, ["~/app/ios/../../../@react-native/codegen/scripts/oss/build.sh"])
assert_equal($collected_commands, ["~/app/ios/../../../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], {
Expand Down
21 changes: 5 additions & 16 deletions packages/react-native/scripts/cocoapods/codegen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,12 @@
# - 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_cli_path = ""
codegen_repo_path = "#{relative_installation_root}/#{react_native_path}/../react-native-codegen";
return unless dir_manager.exist?(codegen_repo_path) && !dir_manager.exist?("#{codegen_repo_path}/lib")

if dir_manager.exist?(codegen_repo_path)
codegen_cli_path = codegen_repo_path
elsif dir_manager.exist?(codegen_npm_path)
codegen_cli_path = codegen_npm_path
else
raise "[codegen] Could not find react-native-codegen."
end

if !dir_manager.exist?("#{codegen_cli_path}/lib")
Pod::UI.puts "[Codegen] building #{codegen_cli_path}."
system("#{codegen_cli_path}/scripts/oss/build.sh")
end
end
Pod::UI.puts "[Codegen] building #{codegen_repo_path}"
system("#{codegen_repo_path}/scripts/oss/build.sh")
end

# It generates an empty `ThirdPartyProvider`, required by Fabric to load the components
#
Expand Down