@@ -17,6 +17,11 @@ def autolink_script_path
17
17
File . join ( package_path , 'native_modules' )
18
18
end
19
19
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
+
20
25
def find_file ( file_name , current_dir )
21
26
return if current_dir . expand_path . to_s == '/'
22
27
@@ -42,6 +47,11 @@ def nearest_node_modules(project_root)
42
47
path
43
48
end
44
49
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
+
45
55
def resolve_module ( request )
46
56
script = "console.log(path.dirname(require.resolve('#{ request } /package.json')));"
47
57
Pod ::Executable . execute_command ( 'node' , [ '-e' , script ] , true ) . strip
@@ -85,9 +95,7 @@ def resources_pod(project_root, target_platform)
85
95
86
96
def use_react_native! ( project_root , target_platform )
87
97
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 )
91
99
92
100
if version [ :major ] == '0' && version [ :minor ] == '60'
93
101
require_relative ( 'use_react_native-0.60' )
@@ -102,6 +110,7 @@ def use_react_native!(project_root, target_platform)
102
110
project_root )
103
111
end
104
112
113
+ # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
105
114
def use_test_app_internal! ( target_platform )
106
115
assert ( %i[ ios macos ] . include? ( target_platform ) , "Unsupported platform: #{ target_platform } " )
107
116
@@ -123,8 +132,10 @@ def use_test_app_internal!(target_platform)
123
132
end
124
133
125
134
# 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
128
139
129
140
require_relative ( autolink_script_path )
130
141
@@ -145,7 +156,11 @@ def use_test_app_internal!(target_platform)
145
156
146
157
yield ReactTestAppTargets . new ( self ) if block_given?
147
158
148
- use_native_modules!
159
+ if autolink_script_version == 2
160
+ use_native_modules! '.'
161
+ else
162
+ use_native_modules!
163
+ end
149
164
end
150
165
151
166
post_install do
@@ -156,6 +171,7 @@ def use_test_app_internal!(target_platform)
156
171
puts ''
157
172
end
158
173
end
174
+ # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
159
175
160
176
class ReactTestAppTargets
161
177
def initialize ( podfile )
0 commit comments