Skip to content

Commit 8c510cd

Browse files
authored
fix: pod install fails in monorepos using React Native 0.60 (#102)
React Native 0.60 depends on `@react-native-community/cli` 2.x which doesn't fully support monorepos. It requires one to specify a custom project root, which we removed when bumping to RN 0.61 because the parameter has been deprecated in `@react-native-community/cli` 3.x.
1 parent f9dbacf commit 8c510cd

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

example/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PODS:
22
- boost-for-react-native (1.63.0)
33
- DoubleConversion (1.1.6)
4-
- Example-Tests (0.1.0):
4+
- Example-Tests (0.1.1):
55
- React
66
- FBLazyVector (0.61.5)
77
- FBReactNativeSpec (0.61.5):
@@ -220,7 +220,7 @@ PODS:
220220
- React-cxxreact (= 0.61.5)
221221
- React-jsi (= 0.61.5)
222222
- ReactCommon/jscallinvoker (= 0.61.5)
223-
- ReactTestApp-DevSupport (0.1.0)
223+
- ReactTestApp-DevSupport (0.1.1)
224224
- ReactTestApp-Resources (1.0.0-dev)
225225
- SwiftLint (0.39.1)
226226
- Yoga (1.14.0)
@@ -327,7 +327,7 @@ EXTERNAL SOURCES:
327327
SPEC CHECKSUMS:
328328
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
329329
DoubleConversion: 5805e889d232975c086db112ece9ed034df7a0b2
330-
Example-Tests: 7debc03c2ca685758cb528ab497c9a7e4e13ca8e
330+
Example-Tests: 0162528650caf3dc473ba08984c5ed811c3e0732
331331
FBLazyVector: aaeaf388755e4f29cd74acbc9e3b8da6d807c37f
332332
FBReactNativeSpec: 118d0d177724c2d67f08a59136eb29ef5943ec75
333333
Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51
@@ -352,7 +352,7 @@ SPEC CHECKSUMS:
352352
React-RCTText: 9ccc88273e9a3aacff5094d2175a605efa854dbe
353353
React-RCTVibration: a49a1f42bf8f5acf1c3e297097517c6b3af377ad
354354
ReactCommon: 198c7c8d3591f975e5431bec1b0b3b581aa1c5dd
355-
ReactTestApp-DevSupport: 727845b0cc18f6fdd84c0cbd622dd6e6314b6b66
355+
ReactTestApp-DevSupport: dd44c3011f367ab72f51ff61fdb7c9c0e525eccf
356356
ReactTestApp-Resources: c070f72dfcb2806d922eec6656259cbf7a4d2bcf
357357
SwiftLint: 55e96a4a4d537d4a3156859fc1c54bd24851a046
358358
Yoga: f2a7cd4280bfe2cca5a7aed98ba0eb3d1310f18b

example/macos/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ PODS:
217217
- React-cxxreact (= 0.61.39)
218218
- React-jsi (= 0.61.39)
219219
- ReactCommon/jscallinvoker (= 0.61.39)
220-
- ReactTestApp-DevSupport (0.1.0)
220+
- ReactTestApp-DevSupport (0.1.1)
221221
- ReactTestApp-Resources (1.0.0-dev)
222222
- SwiftLint (0.39.2)
223223
- Yoga (1.14.0)
@@ -344,7 +344,7 @@ SPEC CHECKSUMS:
344344
React-RCTText: e81f5065516561545ae40f2c5b84d7b14fe6baec
345345
React-RCTVibration: 2ab29818330374b02167caac117d609159f360ab
346346
ReactCommon: e24f8c0d974cdb872d73cbd87cdfea9d72cfae26
347-
ReactTestApp-DevSupport: 727845b0cc18f6fdd84c0cbd622dd6e6314b6b66
347+
ReactTestApp-DevSupport: dd44c3011f367ab72f51ff61fdb7c9c0e525eccf
348348
ReactTestApp-Resources: c070f72dfcb2806d922eec6656259cbf7a4d2bcf
349349
SwiftLint: 22ccbbe3b8008684be5955693bab135e0ed6a447
350350
Yoga: 9cc54b8ca13d6fa87f8214c6eac97745e1df8092

ios/test_app.rb

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ def autolink_script_path
1717
File.join(package_path, 'native_modules')
1818
end
1919

20+
def autolink_script_version
21+
package_path = resolve_module('@react-native-community/cli-platform-ios')
22+
package_version(package_path)[:major].to_i
23+
end
24+
2025
def find_file(file_name, current_dir)
2126
return if current_dir.expand_path.to_s == '/'
2227

@@ -42,6 +47,11 @@ def nearest_node_modules(project_root)
4247
path
4348
end
4449

50+
def package_version(package_path)
51+
package_json = JSON.parse(File.read(File.join(package_path, 'package.json')))
52+
package_json['version'].match(/(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/)
53+
end
54+
4555
def resolve_module(request)
4656
script = "console.log(path.dirname(require.resolve('#{request}/package.json')));"
4757
Pod::Executable.execute_command('node', ['-e', script], true).strip
@@ -85,9 +95,7 @@ def resources_pod(project_root, target_platform)
8595

8696
def use_react_native!(project_root, target_platform)
8797
react_native = Pathname.new(resolve_module('react-native'))
88-
89-
package_json = JSON.parse(File.read(File.join(react_native.to_s, 'package.json')))
90-
version = package_json['version'].match(/(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/)
98+
version = package_version(react_native.to_s)
9199

92100
if version[:major] == '0' && version[:minor] == '60'
93101
require_relative('use_react_native-0.60')
@@ -102,6 +110,7 @@ def use_react_native!(project_root, target_platform)
102110
project_root)
103111
end
104112

113+
# rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
105114
def use_test_app_internal!(target_platform)
106115
assert(%i[ios macos].include?(target_platform), "Unsupported platform: #{target_platform}")
107116

@@ -123,8 +132,10 @@ def use_test_app_internal!(target_platform)
123132
end
124133

125134
# Shared code lives in `ios/ReactTestApp/`
126-
source = File.expand_path(File.join(__dir__, 'ReactTestApp'))
127-
FileUtils.ln_sf(source, File.join(destination, 'ReactTestAppShared'))
135+
if target_platform != :ios
136+
source = File.expand_path(File.join(__dir__, 'ReactTestApp'))
137+
FileUtils.ln_sf(source, File.join(destination, 'ReactTestAppShared'))
138+
end
128139

129140
require_relative(autolink_script_path)
130141

@@ -145,7 +156,11 @@ def use_test_app_internal!(target_platform)
145156

146157
yield ReactTestAppTargets.new(self) if block_given?
147158

148-
use_native_modules!
159+
if autolink_script_version == 2
160+
use_native_modules! '.'
161+
else
162+
use_native_modules!
163+
end
149164
end
150165

151166
post_install do
@@ -156,6 +171,7 @@ def use_test_app_internal!(target_platform)
156171
puts ''
157172
end
158173
end
174+
# rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
159175

160176
class ReactTestAppTargets
161177
def initialize(podfile)

0 commit comments

Comments
 (0)