cocoapods-fix-react-native 2018.04.28.09 → 2018.05.03.10

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: c9d83aa260cbf102b14794cb685bb41812f6364df156f85e916fa20d72fdbfdf
4
- data.tar.gz: b6f0a43c648d29ea2cfc5e849dd854bda7864f0260c6b41a0da4c5571ac6635e
3
+ metadata.gz: 9e61ae67e2d6bd5f2e0327bb13bde287c03507fcc1bea282563cb68fee5f62c5
4
+ data.tar.gz: e6b3aef3de1f2a673b2246a344b67154e444059f43b4f9149babafd80866e0a9
5
5
  SHA512:
6
- metadata.gz: 6f08e612a32ad64150d1ffeb3e6beedbf8faa021d8c2430ae200711752485f6b848e094f49320fb2b15c61e1333bca0d98004daf54a79ac5ffddf4a6ff7dc88c
7
- data.tar.gz: 97148bcb5405710afcade77b9ae440f7a87e159bb0704f65c39dbab06fe1df67719e0e3f893155c06abae75e218aed4916e9b0a491a50faee58c7eac0107e74b
6
+ metadata.gz: ed78330f5a4a09f5088e57525c16236f58ef9d0cb82d0e93aa9eef7f064357a14429343b381c0e9ea348e596508b107dba055254ca993d11010780f719ae3502
7
+ data.tar.gz: 71a807a28d9c5c953d82a7a8635709b12d8ddcbd8ce93eb607f08d37f03a4e64b2549245e28dd5717383274adabaf051d550a04781ff0b28dd4763ba80ceddc7
data/README.md CHANGED
@@ -1,22 +1,27 @@
1
- Hi there! This a CocoaPods plugin that **we, the community**, can use to plug the holes in React Native's CocoaPods
2
- support.
1
+ Hi there! This a CocoaPods plugin that **we, the community**, can use to plug
2
+ the holes in React Native's CocoaPods support.
3
3
 
4
- CocoaPods allows you to add code to run at the end of the Podfile via a `post_install` hook. You probably already have
5
- some custom code in there. This plugin allows all that code to be centralized and reasoned about in a single place per
6
- React Native version.
4
+ CocoaPods allows you to add code to run before and at the end of the Podfile via
5
+ installation hooks. You probably already have some custom code in there. This
6
+ plugin allows all that code to be centralized and reasoned about in a single
7
+ place per React Native version.
7
8
 
8
9
  ## Why Does This Need To Exist?
9
10
 
10
- React Native is a pragmatic project, it's great Facebook open sources it, but if you want to work with a flow they don't
11
- use - the onus is on you to make sure it continues to work. Facebook have a big mono-repo, and so they don't need to use
12
- CocoaPods, and they also use static compilation because they don't use Swift. Meaning if you want to use CocoaPods and
13
- Swift, you're pretty far from their workflow.
11
+ React Native is a pragmatic project, it's great Facebook open sources it, but if
12
+ you want to work with a flow they don't use - the onus is on you to make sure it
13
+ continues to work. Facebook have a big mono-repo, and so they don't need to use
14
+ CocoaPods, and they also use static compilation because they don't use Swift.
15
+ Meaning if you want to use CocoaPods and Swift, you're pretty far from their
16
+ workflow.
14
17
 
15
- In order to get it working for just your app you scour, like, a million issues on React Native (or go look at
16
- [artsy/eigen][eigen]) to get it compiling on your setup. Again, not optimal.
18
+ In order to get it working for just your app you scour, like, a million issues
19
+ on React Native (or go look at [artsy/eigen][eigen]) to get it compiling on your
20
+ setup. Again, not optimal.
17
21
 
18
- This plugin _tries_ to fix this by centralizing the code needed to modify React Native. This means makes it easy to
19
- update your versions of React Native, because you can update the gem at the same time.
22
+ This plugin _tries_ to fix this by centralizing the code needed to modify React
23
+ Native. This means makes it easy to update your versions of React Native,
24
+ because you can update the gem at the same time.
20
25
 
21
26
  ## Installation
22
27
 
@@ -24,57 +29,71 @@ Lazy way (bad, but ok if 1 engineer):
24
29
 
25
30
  $ gem install cocoapods-fix-react-native
26
31
 
27
- Correct way, edit [`your Gemfile`](http://www.mokacoding.com/blog/ruby-for-ios-developers-bundler/) to be:
32
+ Correct way, edit
33
+ [`your Gemfile`](http://www.mokacoding.com/blog/ruby-for-ios-developers-bundler/)
34
+ to be:
28
35
 
29
36
  gem "cocoapods"
30
37
  gem "cocoapods-fix-react-native"
31
38
 
32
- Then remove any React Native related `post_install` code, and add this to the top level of your `Podfile`:
39
+ Then remove any React Native related `pre_install` and `post_install` code, and
40
+ add this to the top level of your `Podfile`:
33
41
 
34
42
  plugin 'cocoapods-fix-react-native'
35
43
 
36
- For the first time you do this, I'd recommend running `rm -rf Pods; bundle exec pod install`. After that you can
37
- `bundle exec pod install` like normal.
44
+ For the first time you do this, I'd recommend running `rm -rf Pods; bundle exec
45
+ pod install`. After that you can `bundle exec pod install` like normal.
38
46
 
39
47
  ## How do I Update This?
40
48
 
41
- `bundle update cocoapods-fix-react-native`.
49
+ bundle update cocoapods-fix-react-native
42
50
 
43
- This project is auto-deployed after every merged PR, so it's should always be up-to-date.
51
+ This project is auto-deployed after every merged PR, so it's should always be
52
+ up-to-date.
44
53
 
45
54
  ## How Does This Work?
46
55
 
47
- A CocoaPods plugin can register a `post_install` hook just like you can in your `Podfile`. This hook will first look at
48
- what version of React Native is installed, and will then run a corresponding script to make changes to the environment.
56
+ A CocoaPods plugin can register hooks before and after installation, just like
57
+ you can in your `Podfile`. This hook will first look at what version of React
58
+ Native is installed, and will then run a corresponding scripts to make changes
59
+ to the environment.
49
60
 
50
61
  ## Contributing Back
51
62
 
52
- You'll note that this repo has issues disabled, I'm not going to make the time to support questions and requests for
53
- fixes to this. I have a lot of projects, and only so much time. However, I'm happy to handle the mainainance and upkeep
54
- from code people submit. If you want a change, you'll need to do so yourself, so let's cover how you do that:
63
+ You'll note that this repo has issues disabled, I'm not going to make the time
64
+ to support questions and requests for fixes to this. I have a lot of projects,
65
+ and only so much time. However, I'm happy to handle the mainainance and upkeep
66
+ from code people submit. If you want a change, you'll need to do so yourself, so
67
+ let's cover how you do that:
55
68
 
56
- This project is very specific about what versions of React Native it supports, you can see them in the folder
69
+ This project is very specific about what versions of React Native it supports,
70
+ you can see them in the folder
57
71
  [`lib/cocoapods-fix-react-native/versions/`][versions]:
58
72
 
59
73
  ```
60
74
  ~/dev/projects/react-native/cocoapods-fix-react-native master*
61
75
  ❯ tree lib/cocoapods-fix-react-native/versions/
62
76
  lib/cocoapods-fix-react-native/versions/
63
- └── 0_54_4.rb
77
+ └── 0_54_4-post.rb
64
78
  ```
65
79
 
66
- There's likely more than just one by the time you read this, but if you want to use a version that isn't supported yet,
67
- then you're going to want to copy the most recent into a new file. The files are named by converting dots to
68
- underscores. E.g. `0.54.4` -> `0_54_4.rb`.
80
+ There's likely more than just one by the time you read this, but if you want to
81
+ use a version that isn't supported yet, then you're going to want to copy the
82
+ most recent into a new file. The files are named by converting dots to
83
+ underscores. E.g. `0.54.4` -> `0_54_4-pre.rb`/`0_54_4-post.rb`.
69
84
 
70
- The scripts itself should be entirely self contained, so that it's easy to understand wthout learning the project.
85
+ The scripts itself should be entirely self contained, so that it's easy to
86
+ understand without learning the project.
71
87
 
72
- The biggest change you'd need to make from the sort of code you can find inside the issues is that it needs to support
73
- many different potential roots. So instead of just `Pods/React/*` - this plugin will also handle
74
- `node_modules/react-native/*` and `../node_modules/react-native/*`. Basically, your dev repo, and your prod app.
88
+ The biggest change you'd need to make from the sort of code you can find inside
89
+ the issues is that it needs to support many different potential roots. So
90
+ instead of just `Pods/React/*` - this plugin will also handle
91
+ `node_modules/react-native/*` and `../node_modules/react-native/*`. Basically,
92
+ your dev repo, and your prod app.
75
93
 
76
94
  This can be done by removing `'Pods/React'` from the path and wrapping it with a
77
- `File.join(root, 'Path/InReactLib.js')`. You'll see this in the current scripts.
95
+ `File.join($root, 'Path/InReactLib.js')`. You'll see this in the current
96
+ scripts.
78
97
 
79
98
  ### Getting Setup To Improve
80
99
 
@@ -86,18 +105,19 @@ cd cocoapods-fix-react-native
86
105
  bundle install
87
106
  ```
88
107
 
89
- You want to use a `:path` based gem in your project's Gemfile to point to the cloned repo. Make you to your App's
90
- `Gemfile` something like this:
108
+ You want to use a `:path` based gem in your project's Gemfile to point to the
109
+ cloned repo. Make you to your App's `Gemfile` something like this:
91
110
 
92
111
  ```ruby
93
112
  gem 'cocoapods', '~> 1.4.0'
94
113
  gem 'cocoapods-fix-react-native', path: "../../../../react-native/cocoapods-fix-react-native"
95
114
  ```
96
115
 
97
- Then when you run `bundle exec pod install` in that project, it will use the the code from your cloned copy.
116
+ Then when you run `bundle exec pod install` in that project, it will use the the
117
+ code from your cloned copy.
98
118
 
99
- As `use_frameworks!` is more strict than static libraries, I'd recommend working on this project using a repo that has
100
- frameworks.
119
+ As `use_frameworks!` is more strict than static libraries, I'd recommend working
120
+ on this project using a repo that has frameworks.
101
121
 
102
122
  [eigen]: https://github.com/artsy/eigen/
103
123
  [versions]: https://github.com/orta/cocoapods-fix-react-native/tree/master/lib/cocoapods-fix-react-native/versions
@@ -0,0 +1,91 @@
1
+ require 'molinillo/dependency_graph'
2
+
3
+ class CocoaPodsFixReactNative
4
+ def post_fix_with_context(context)
5
+ # Get the current version of React Native in your app
6
+ react_spec = nil
7
+ context.umbrella_targets.each do |target|
8
+ react = target.specs.find { |s| s.name == 'React' || s.name.start_with?('React/') }
9
+ next if react.nil?
10
+ react_spec = react
11
+ end
12
+
13
+ if react_spec.nil?
14
+ Pod::UI.warn "No React dependency found"
15
+ return
16
+ end
17
+
18
+ version = react_spec.version.to_s
19
+
20
+ unless patch_exist?(version)
21
+ Pod::UI.warn "CP-Fix-React-Native does not support #{version} yet, please send " +
22
+ 'PRs to https://github.com/orta/cocoapods-fix-react-native'
23
+ return
24
+ end
25
+
26
+ path_to_fix = version_file(version)
27
+
28
+ if File.exist? path_to_fix
29
+ Pod::UI.section "Patching React Native #{version}" do
30
+ require(path_to_fix)
31
+ end
32
+ end
33
+ end
34
+
35
+ def pre_fix_with_context(context)
36
+ # Get the current version of React Native in your app
37
+ locked_dependencies = Molinillo::DependencyGraph.new
38
+ context.lockfile.dependencies.each do |dependency|
39
+ locked_dependencies.add_vertex(dependency.name, dependency, true)
40
+ end
41
+
42
+ sources = context.podfile.sources.map do |source|
43
+ Pod::Config.instance.sources_manager.source_with_name_or_url(source)
44
+ end
45
+
46
+ resolver = Pod::Resolver.new(context.sandbox, context.podfile, locked_dependencies, sources, true)
47
+ target_definitions = resolver.resolve
48
+
49
+ react_spec = nil
50
+
51
+ target_definitions.each do |(definition, dependencies)|
52
+ next if definition.name == 'Pods'
53
+
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
57
+ end
58
+
59
+ return if react_spec.nil?
60
+
61
+ version = react_spec.version.to_s
62
+
63
+ # There will probably always be a neeed for the post, but a pre can be ignored
64
+ return unless patch_exist?(version)
65
+
66
+ path_to_fix = version_file(version, 'pre')
67
+
68
+ if File.exist? path_to_fix
69
+ Pod::UI.section "Patching React Native #{version}" do
70
+ require(path_to_fix)
71
+ end
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ def patch_exist?(version)
78
+ version_file_name = version.tr('.', '_')
79
+ patches = Dir.glob(File.join(versions_path, "#{version_file_name}-*"))
80
+ patches.present?
81
+ end
82
+
83
+ def version_file(version, suffix = 'post')
84
+ file_to_parse = version.tr('.', '_') + "-#{suffix}.rb"
85
+ File.join(versions_path, file_to_parse)
86
+ end
87
+
88
+ def versions_path
89
+ File.expand_path('../versions', __FILE__)
90
+ end
91
+ end
@@ -0,0 +1,14 @@
1
+ class ReactDependencyVersion
2
+ def fix_with_context(context)
3
+ all_pods_targets = context.pods_project.targets
4
+ all_pods_targets.each do |t|
5
+ deployment_target = t.build_configurations.first.build_settings['IPHONEOS_DEPLOYMENT_TARGET']
6
+ has_react_dep = t.dependencies.find { |dep| dep.name == 'React' }
7
+
8
+ if has_react_dep && deployment_target == '4.3'
9
+ raise 'You have a Pod which has a deployment target of 4.3, and a dependency on React.' \
10
+ "\nIn order for React Native to compile you need to give the Podspec for #{t.name} a version like `s.platform = :ios, '9.0'`.\n"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,20 +1,20 @@
1
- require 'cocoapods-fix-react-native/version_resolver'
1
+ require 'cocoapods-fix-react-native/fix_with_context'
2
+ require 'cocoapods-fix-react-native/issues/react_dependency_version'
3
+
4
+ Pod::HooksManager.register('cocoapods-fix-react-native', :pre_install) do |context|
5
+ # The pre-fix resolver, usually for modifying Podspecs
6
+ fixer = CocoaPodsFixReactNative.new
7
+ fixer.pre_fix_with_context(context)
8
+ end
9
+
2
10
 
3
11
  Pod::HooksManager.register('cocoapods-fix-react-native', :post_install) do |context|
4
-
5
12
  # Check that the min version of iOS has been set right for CocoaPods
6
13
  # This happens when a pod has a lower than iOS 6 deployment target.
7
- all_pods_targets = context.pods_project.targets
8
- all_pods_targets.each do |t|
9
- deployment_target = t.build_configurations.first.build_settings['IPHONEOS_DEPLOYMENT_TARGET']
10
- has_react_dep = t.dependencies.find { |dep| dep.name == "React" }
11
-
12
- if has_react_dep && deployment_target == '4.3'
13
- raise 'You have a Pod which has a deployment target of 4.3, and a dependency on React.' +
14
- "\nIn order for React Native to compile you need to give the Podspec for #{t.name} a version like `s.platform = :ios, '9.0'`.\n"
15
- end
16
- end
14
+ dep_version = ReactDependencyVersion.new
15
+ dep_version.fix_with_context(context)
17
16
 
17
+ # The post-fix resolver, for editing the RN source code after it's been installed
18
18
  fixer = CocoaPodsFixReactNative.new
19
- fixer.fix_with_context(context)
19
+ fixer.post_fix_with_context(context)
20
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-fix-react-native
3
3
  version: !ruby/object:Gem::Version
4
- version: 2018.04.28.09
4
+ version: 2018.05.03.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orta Therox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-28 00:00:00.000000000 Z
11
+ date: 2018-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,10 +53,11 @@ files:
53
53
  - Rakefile
54
54
  - cocoapods-fix-react-native.gemspec
55
55
  - lib/cocoapods-fix-react-native.rb
56
- - lib/cocoapods-fix-react-native/version_resolver.rb
56
+ - lib/cocoapods-fix-react-native/fix_with_context.rb
57
+ - lib/cocoapods-fix-react-native/issues/react_dependency_version.rb
57
58
  - lib/cocoapods-fix-react-native/versions/0_53_3.rb
58
- - lib/cocoapods-fix-react-native/versions/0_54_2.rb
59
- - lib/cocoapods-fix-react-native/versions/0_54_4.rb
59
+ - lib/cocoapods-fix-react-native/versions/0_54_2-post.rb
60
+ - lib/cocoapods-fix-react-native/versions/0_54_4-post.rb
60
61
  - lib/cocoapods_plugin.rb
61
62
  - spec/command/native_spec.rb
62
63
  - spec/spec_helper.rb
@@ -1,27 +0,0 @@
1
- class CocoaPodsFixReactNative
2
- def fix_with_context(context)
3
- # Get the current version of React Native in your app
4
- react = nil
5
- context.umbrella_targets.each do |target|
6
- react_spec = target.specs.find { |s| s.name == 'React' || s.name.start_with?('React/') }
7
- react = react_spec if react_spec
8
- end
9
-
10
- # 0.44.1 -> 0_44_1
11
- version = react.version.to_s
12
- file_to_parse = version.tr('.', '_')
13
- path_to_fix = File.join(File.dirname(__FILE__), 'versions', file_to_parse + '.rb')
14
-
15
- # require 'pry'
16
- # binding.pry
17
-
18
- if File.exist? path_to_fix
19
- Pod::UI.section "Patching React Native #{version}" do
20
- require(path_to_fix)
21
- end
22
- else
23
- Pod::UI.warn "CP-Fix-React-Native does not support #{version} yet, please send " +
24
- 'PRs to https://github.com/orta/cocoapods-fix-react-native'
25
- end
26
- end
27
- end