1require_relative '../project_integrator' 2 3# Unfortunately there is no good and official place that we could use to generate module providers 4# and integrate them with user targets by operating on the PBXProj kept and saved by CocoaPods. 5# So we have to hook into the private method called `integrate_user_targets` 6# where we have public access to everything that we need. 7# Original implementation: https://github.com/CocoaPods/CocoaPods/blob/master/lib/cocoapods/installer/user_project_integrator.rb 8 9module Pod 10 class Installer 11 class UserProjectIntegrator 12 include Expo::ProjectIntegrator 13 14 private 15 16 _original_integrate_user_targets = instance_method(:integrate_user_targets) 17 18 # Integrates the targets of the user projects with the libraries 19 # generated from the {Podfile}. 20 # 21 # @note {TargetDefinition} without dependencies are skipped to prevent 22 # creating empty libraries for target definitions which are only 23 # wrappers for others. 24 # 25 # @return [void] 26 # 27 define_method(:integrate_user_targets) do 28 # Call original method first 29 results = _original_integrate_user_targets.bind(self).() 30 31 UI.message '- Integrating Expo modules providers' do 32 # All user targets mapped to user projects. 33 all_projects = targets.map { |target| target.user_project }.uniq 34 35 # Array of projects to integrate is usually a subset of `all_projects`, 36 # and it might be empty subsequent installs after the first install. 37 # CocoaPods integrates only these ones. 38 projects_to_integrate = user_projects_to_integrate() 39 40 # However, we need to make sure that all projects are integrated, 41 # regardless of the CocoaPods cache. 42 all_projects.each do |project| 43 project_targets = targets.select { |target| target.user_project.equal?(project) } 44 45 Expo::ProjectIntegrator::integrate_targets_in_project(project_targets, project) 46 Expo::ProjectIntegrator::remove_nils_from_source_files(project) 47 Expo::ProjectIntegrator::set_autolinking_configuration(project) 48 49 # CocoaPods saves the projects to integrate at the next step, 50 # but in some cases we're modifying other projects as well. 51 # Below we make sure the project will be saved and no more than once! 52 if project.dirty? && !projects_to_integrate.include?(project) 53 save_projects([project]) 54 end 55 end 56 end 57 58 results 59 end 60 end # class UserProjectIntegrator 61 end # class Installer 62end # module Pod 63