cocoapods-fix-react-native 2018.05.03.10 → 2018.05.03.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e61ae67e2d6bd5f2e0327bb13bde287c03507fcc1bea282563cb68fee5f62c5
4
- data.tar.gz: e6b3aef3de1f2a673b2246a344b67154e444059f43b4f9149babafd80866e0a9
3
+ metadata.gz: 20e64ade78568578b3c9af60bcccc3125464dd19fc1227709d5855fb1ad946e5
4
+ data.tar.gz: 3e89ca1f4b9bea94a7ed49bfc340be2386d0f3c95766147f91a6215a429af705
5
5
  SHA512:
6
- metadata.gz: ed78330f5a4a09f5088e57525c16236f58ef9d0cb82d0e93aa9eef7f064357a14429343b381c0e9ea348e596508b107dba055254ca993d11010780f719ae3502
7
- data.tar.gz: 71a807a28d9c5c953d82a7a8635709b12d8ddcbd8ce93eb607f08d37f03a4e64b2549245e28dd5717383274adabaf051d550a04781ff0b28dd4763ba80ceddc7
6
+ metadata.gz: cdac39965eef4dd8dfd8612ed8e342d11289c36f2df06f52d7ad8381ee1d523936fd1d3d19df12325e922391c9c705c10eed7149956099988b9f3672dfa2e653
7
+ data.tar.gz: c53fe8388eff3a8da82c1ad5bcc3d1bd0c556b01352aa16cb8b5406da2d1682f737c76a61eee5896cbfcad748cbd2f9515939feaa4b75d7517581029a63e563f
@@ -43,17 +43,22 @@ class CocoaPodsFixReactNative
43
43
  Pod::Config.instance.sources_manager.source_with_name_or_url(source)
44
44
  end
45
45
 
46
- resolver = Pod::Resolver.new(context.sandbox, context.podfile, locked_dependencies, sources, true)
47
- target_definitions = resolver.resolve
48
-
49
46
  react_spec = nil
47
+
48
+ begin
49
+ resolver = Pod::Resolver.new(context.sandbox, context.podfile, locked_dependencies, sources, true)
50
+ target_definitions = resolver.resolve
50
51
 
51
- target_definitions.each do |(definition, dependencies)|
52
- next if definition.name == 'Pods'
52
+ target_definitions.each do |(definition, dependencies)|
53
+ next if definition.name == 'Pods'
53
54
 
54
- react = dependencies.find { |d| d.spec.name == 'React' || d.spec.name.start_with?('React/') }
55
- next if react.nil?
56
- react_spec = react.spec
55
+ react = dependencies.find { |d| d.spec.name == 'React' || d.spec.name.start_with?('React/') }
56
+ next if react.nil?
57
+ react_spec = react.spec
58
+ end
59
+ rescue StandardError => e
60
+ Pod::UI.warn 'Failed to resolve dependencies, so pre-patch was not applied, ' +
61
+ 'please try running `pod install` again to apply the patch.'
57
62
  end
58
63
 
59
64
  return if react_spec.nil?
@@ -0,0 +1,165 @@
1
+ require 'cocoapods'
2
+
3
+ # Notes:
4
+ #
5
+ # - All file paths should be relative to the React repo, rather than the Pods dir, or node_modules
6
+ #
7
+
8
+ # Are you using :path based Pods?
9
+ dev_pods_react = !File.directory?('Pods/React/React')
10
+
11
+ # Detect CocoaPods + Frameworks
12
+ $has_frameworks = File.exists?'Pods/Target Support Files/React/React-umbrella.h'
13
+
14
+ # Check for whether we're in a project that uses relative paths
15
+ same_repo_node_modules = File.directory?('node_modules/react-native')
16
+ previous_repo_node_modules = File.directory?('../node_modules/react-native')
17
+
18
+ # Find out where the files could be rooted
19
+ $root = 'Pods/React'
20
+ if dev_pods_react
21
+ $root = 'node_modules/react-native' if same_repo_node_modules
22
+ $root = '../node_modules/react-native' if previous_repo_node_modules
23
+ end
24
+
25
+ # TODO: move to be both file in pods and file in node_mods?
26
+ def patch_pod_file(path, old_code, new_code)
27
+ file = File.join($root, path)
28
+ unless File.exist?(file)
29
+ Pod::UI.warn "#{file} does not exist so was not patched.."
30
+ return
31
+ end
32
+ code = File.read(file)
33
+ if code.include?(old_code)
34
+ Pod::UI.message "Patching #{file}", '- '
35
+ FileUtils.chmod('+w', file)
36
+ File.write(file, code.sub(old_code, new_code))
37
+ end
38
+ end
39
+
40
+ def fix_cplusplus_header_compiler_error
41
+ filepath = File.join($root, 'React/Base/Surface/SurfaceHostingView/RCTSurfaceSizeMeasureMode.h')
42
+ FileUtils.chmod('+w', filepath)
43
+
44
+ contents = []
45
+
46
+ file = File.open(filepath, 'r')
47
+ file.each_line do |line|
48
+ contents << line
49
+ end
50
+ file.close
51
+
52
+ if contents[30].include? '&'
53
+ Pod::UI.message "Patching #{filepath}", '- '
54
+ contents.insert(27, '#ifdef __cplusplus')
55
+ contents[34] = '#endif'
56
+
57
+ file = File.open(filepath, 'w') do |f|
58
+ f.puts(contents)
59
+ end
60
+ end
61
+ end
62
+
63
+ def fix_unused_yoga_headers
64
+ filepath = 'Pods/Target Support Files/yoga/yoga-umbrella.h'
65
+ # This only exists when using CocoaPods + Frameworks
66
+ return unless File.exists?(filepath)
67
+
68
+ contents = []
69
+ file = File.open(filepath, 'r')
70
+ file.each_line do |line|
71
+ contents << line
72
+ end
73
+ file.close
74
+
75
+ if contents[12].include? 'Utils.h'
76
+ Pod::UI.message "Patching #{filepath}", '- '
77
+ contents.delete_at(14) # #import "YGLayout.h"
78
+ contents.delete_at(15) # #import "YGNode.h"
79
+ contents.delete_at(15) # #import "YGNodePrint.h"
80
+ contents.delete_at(15) # #import "YGStyle.h"
81
+ contents.delete_at(15) # #import "Yoga-internal.h"
82
+ contents.delete_at(12) # #import "Utils.h"
83
+
84
+ file = File.open(filepath, 'w') do |f|
85
+ f.puts(contents)
86
+ end
87
+ end
88
+ end
89
+
90
+ # Detect source file dependency in the generated Pods.xcodeproj workspace sub-project
91
+ def has_pods_project_source_file(source_filename)
92
+ pods_project = 'Pods/Pods.xcodeproj/project.pbxproj'
93
+ File.open(pods_project).grep(/#{source_filename}/).any?
94
+ end
95
+
96
+ # Detect dependent source file required for building when the given source file is present
97
+ def meets_pods_project_source_dependency(source_filename, dependent_source_filename)
98
+ has_pods_project_source_file(source_filename) ? has_pods_project_source_file(dependent_source_filename) : true
99
+ end
100
+
101
+ def detect_missing_subspec_dependency(subspec_name, source_filename, dependent_source_filename)
102
+ unless meets_pods_project_source_dependency(source_filename, dependent_source_filename)
103
+ Pod::UI.warn "#{subspec_name} subspec may be required given your current dependencies"
104
+ end
105
+ end
106
+
107
+ def detect_missing_subspecs
108
+ return unless $has_frameworks
109
+
110
+ # For CocoaPods + Frameworks, RCTNetwork and CxxBridge subspecs are necessary for DevSupport.
111
+ # When the React pod is generated it must include all the required source, and see umbrella deps.
112
+ detect_missing_subspec_dependency('RCTNetwork', 'RCTBlobManager.mm', 'RCTNetworking.mm')
113
+ detect_missing_subspec_dependency('CxxBridge', 'RCTJavaScriptLoader.mm', 'RCTCxxBridge.mm')
114
+
115
+ # RCTText itself shouldn't require DevSupport, but it depends on Core -> RCTDevSettings -> RCTPackagerClient
116
+ detect_missing_subspec_dependency('DevSupport', 'RCTDevSettings.mm', 'RCTPackagerClient.m')
117
+ end
118
+
119
+ fix_unused_yoga_headers
120
+ fix_cplusplus_header_compiler_error
121
+ detect_missing_subspecs
122
+
123
+ # # https://github.com/facebook/react-native/pull/14664
124
+ animation_view_file = 'Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h'
125
+ animation_view_old_code = 'import <RCTAnimation/RCTValueAnimatedNode.h>'
126
+ animation_view_new_code = 'import "RCTValueAnimatedNode.h"'
127
+ patch_pod_file animation_view_file, animation_view_old_code, animation_view_new_code
128
+
129
+ # https://github.com/facebook/react-native/issues/13198
130
+ # Only needed when you have the DevSupport subspec
131
+ has_dev_support = File.exist?(File.join($root, 'Libraries/WebSocket/RCTReconnectingWebSocket.m'))
132
+
133
+ if has_dev_support
134
+ # Move Fishhook to be based on RN's imports
135
+ websocket = 'Libraries/WebSocket/RCTReconnectingWebSocket.m'
136
+ websocket_old_code = 'import <fishhook/fishhook.h>'
137
+ websocket_new_code = 'import <React/fishhook.h>'
138
+ patch_pod_file websocket, websocket_old_code, websocket_new_code
139
+ else
140
+ # There's a link in the DevSettings to dev-only import
141
+ filepath = "#{$root}/React/Modules/RCTDevSettings.mm"
142
+ contents = []
143
+ file = File.open(filepath, 'r')
144
+ found = false
145
+ file.each_line do |line|
146
+ contents << line
147
+ end
148
+ file.close
149
+
150
+ comment_start = '#if ENABLE_PACKAGER_CONNECTION'
151
+ comment_end = '#endif'
152
+
153
+ if contents[20].include? 'RCTPackagerClient.h'
154
+ Pod::UI.message "Patching #{filepath}", '- '
155
+ contents.insert(20, comment_start)
156
+ contents.insert(22, comment_end)
157
+
158
+ contents.insert(205, comment_start)
159
+ contents.insert(229, comment_end)
160
+
161
+ file = File.open(filepath, 'w') do |f|
162
+ f.puts(contents)
163
+ end
164
+ end
165
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-fix-react-native
3
3
  version: !ruby/object:Gem::Version
4
- version: 2018.05.03.10
4
+ version: 2018.05.03.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orta Therox
@@ -58,6 +58,7 @@ files:
58
58
  - lib/cocoapods-fix-react-native/versions/0_53_3.rb
59
59
  - lib/cocoapods-fix-react-native/versions/0_54_2-post.rb
60
60
  - lib/cocoapods-fix-react-native/versions/0_54_4-post.rb
61
+ - lib/cocoapods-fix-react-native/versions/0_55_3-post.rb
61
62
  - lib/cocoapods_plugin.rb
62
63
  - spec/command/native_spec.rb
63
64
  - spec/spec_helper.rb