Skip to content

Commit dcdea80

Browse files
tido64huntie
authored andcommitted
Fix build_codegen! not finding @react-native/codegen in pnpm setups (#41399)
Summary: `build_codegen!` currently assumes that `react-native/codegen` gets installed next to `react-native`. In a pnpm setup, it's found under `/~/react-native/node_modules/react-native/codegen` instead. However, as dmytrorykun pointed out, we don't actually need to build it outside of this repository. ## Changelog: [GENERAL] [FIXED] - `react-native/codegen` shouldn't be built unless it's in the repo — fixes `pod install` failures in pnpm setups Pull Request resolved: #41399 Test Plan: We have a patched version of `react-native` working in a pnpm setup here: microsoft/rnx-kit#2811 Reviewed By: dmytrorykun Differential Revision: D51201643 Pulled By: cipolleschi fbshipit-source-id: 53767ae08686a20f03b3b93abcbc7d5383083872
1 parent c32064c commit dcdea80

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

packages/react-native/scripts/cocoapods/__tests__/codegen-test.rb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,34 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenFileAlreadyExists_doNothing(
6868
assert_equal(Pod::Executable.executed_commands.length, 0)
6969
end
7070

71-
def testCheckAndGenerateEmptyThirdPartyProvider_whenHeaderMissingAndCodegenMissing_raiseError()
71+
def testCheckAndGenerateEmptyThirdPartyProvider_whenHeaderMissingAndCodegenMissing_dontBuildCodegen()
7272

7373
# Arrange
7474
FileMock.mocked_existing_files([
7575
@base_path + "/build/" + @third_party_provider_implementation,
7676
])
7777

7878
# Act
79-
assert_raise {
79+
assert_nothing_raised {
8080
checkAndGenerateEmptyThirdPartyProvider!(@prefix, false, dir_manager: DirMock, file_manager: FileMock)
8181
}
8282

8383
# Assert
8484
assert_equal(Pathname.pwd_invocation_count, 1)
8585
assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1)
8686
assert_equal(FileMock.exist_invocation_params, [
87-
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_header
87+
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_header,
88+
@base_path + "/" + @prefix + "/React/Fabric/tmpSchemaList.txt",
8889
])
8990
assert_equal(DirMock.exist_invocation_params, [
9091
@base_path + "/"+ @prefix + "/../react-native-codegen",
91-
@base_path + "/"+ @prefix + "/../@react-native/codegen",
9292
])
93-
assert_equal(Pod::UI.collected_messages, [])
93+
assert_equal(Pod::UI.collected_messages, [
94+
"[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider",
95+
])
9496
assert_equal($collected_commands, [])
95-
assert_equal(FileMock.open_files.length, 0)
96-
assert_equal(Pod::Executable.executed_commands.length, 0)
97+
assert_equal(FileMock.open_files.length, 1)
98+
assert_equal(Pod::Executable.executed_commands.length, 1)
9799
end
98100

99101
def testCheckAndGenerateEmptyThirdPartyProvider_whenImplementationMissingAndCodegenrepoExists_dontBuildCodegen()
@@ -145,7 +147,7 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenImplementationMissingAndCode
145147

146148
def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen()
147149
# Arrange
148-
codegen_cli_path = @base_path + "/" + @prefix + "/../@react-native/codegen"
150+
codegen_cli_path = @base_path + "/" + @prefix + "/../react-native-codegen"
149151
DirMock.mocked_existing_dirs([
150152
codegen_cli_path,
151153
])
@@ -160,15 +162,14 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen()
160162
@base_path + "/" + @prefix + "/React/Fabric/" + @tmp_schema_list_file
161163
])
162164
assert_equal(DirMock.exist_invocation_params, [
163-
@base_path + "/" + @prefix + "/../react-native-codegen",
164165
codegen_cli_path,
165166
codegen_cli_path + "/lib",
166167
])
167168
assert_equal(Pod::UI.collected_messages, [
168-
"[Codegen] building #{codegen_cli_path}.",
169+
"[Codegen] building #{codegen_cli_path}",
169170
"[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider"
170171
])
171-
assert_equal($collected_commands, ["~/app/ios/../../../@react-native/codegen/scripts/oss/build.sh"])
172+
assert_equal($collected_commands, ["~/app/ios/../../../react-native-codegen/scripts/oss/build.sh"])
172173
assert_equal(FileMock.open_files[0].collected_write, ["[]"])
173174
assert_equal(FileMock.open_files[0].fsync_invocation_count, 1)
174175
assert_equal(Pod::Executable.executed_commands[0], {
@@ -185,7 +186,7 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen()
185186
def testCheckAndGenerateEmptyThirdPartyProvider_withAbsoluteReactNativePath_buildCodegen()
186187
# Arrange
187188
rn_path = 'packages/react-native'
188-
codegen_cli_path = rn_path + "/../@react-native/codegen"
189+
codegen_cli_path = rn_path + "/../react-native-codegen"
189190
DirMock.mocked_existing_dirs([
190191
@base_path + "/" + codegen_cli_path,
191192
])
@@ -201,15 +202,16 @@ def testCheckAndGenerateEmptyThirdPartyProvider_withAbsoluteReactNativePath_buil
201202
@base_path + "/" + rn_path + "/React/Fabric/" + @tmp_schema_list_file
202203
])
203204
assert_equal(DirMock.exist_invocation_params, [
204-
@base_path + "/" + rn_path + "/../react-native-codegen",
205205
@base_path + "/" + codegen_cli_path,
206206
@base_path + "/" + codegen_cli_path + "/lib",
207207
])
208208
assert_equal(Pod::UI.collected_messages, [
209-
"[Codegen] building #{@base_path + "/" + codegen_cli_path}.",
209+
"[Codegen] building #{@base_path + "/" + codegen_cli_path}",
210210
"[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider"
211211
])
212-
assert_equal($collected_commands, [@base_path + "/" + rn_path + "/../@react-native/codegen/scripts/oss/build.sh"])
212+
assert_equal($collected_commands, [
213+
@base_path + "/" + rn_path + "/../react-native-codegen/scripts/oss/build.sh",
214+
])
213215
assert_equal(FileMock.open_files[0].collected_write, ["[]"])
214216
assert_equal(FileMock.open_files[0].fsync_invocation_count, 1)
215217
assert_equal(Pod::Executable.executed_commands[0], {

packages/react-native/scripts/cocoapods/codegen.rb

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,12 @@
1111
# - dir_manager: a class that implements the `Dir` interface. Defaults to `Dir`, the Dependency can be injected for testing purposes.
1212
# @throws an error if it could not find the codegen folder.
1313
def build_codegen!(react_native_path, relative_installation_root, dir_manager: Dir)
14-
codegen_repo_path = "#{basePath(react_native_path, relative_installation_root)}/../react-native-codegen";
15-
codegen_npm_path = "#{basePath(react_native_path, relative_installation_root)}/../@react-native/codegen";
16-
codegen_cli_path = ""
14+
codegen_repo_path = "#{basePath(react_native_path, relative_installation_root)}/../react-native-codegen"
15+
return unless dir_manager.exist?(codegen_repo_path) && !dir_manager.exist?("#{codegen_repo_path}/lib")
1716

18-
if dir_manager.exist?(codegen_repo_path)
19-
codegen_cli_path = codegen_repo_path
20-
elsif dir_manager.exist?(codegen_npm_path)
21-
codegen_cli_path = codegen_npm_path
22-
else
23-
raise "[codegen] Could not find react-native-codegen."
24-
end
25-
26-
if !dir_manager.exist?("#{codegen_cli_path}/lib")
27-
Pod::UI.puts "[Codegen] building #{codegen_cli_path}."
28-
system("#{codegen_cli_path}/scripts/oss/build.sh")
29-
end
30-
end
17+
Pod::UI.puts "[Codegen] building #{codegen_repo_path}"
18+
system("#{codegen_repo_path}/scripts/oss/build.sh")
19+
end
3120

3221
# It generates an empty `ThirdPartyProvider`, required by Fabric to load the components
3322
#

0 commit comments

Comments
 (0)