Class: CocoaPodsFixReactNative

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-fix-react-native/fix_with_context.rb

Instance Method Summary collapse

Instance Method Details

#post_fix_with_context(context) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cocoapods-fix-react-native/fix_with_context.rb', line 4

def post_fix_with_context(context)
  # Get the current version of React Native in your app
  react_spec = nil
  context.umbrella_targets.each do |target|
    react = target.specs.find { |s| s.name == 'React' || s.name.start_with?('React/') }
    next if react.nil?
    react_spec = react
  end

  if react_spec.nil?
    Pod::UI.warn "No React dependency found"
    return
  end

  version = react_spec.version.to_s

  unless patch_exist?(version)
    Pod::UI.warn "CP-Fix-React-Native does not support #{version} yet, please send " +
                 'PRs to https://github.com/orta/cocoapods-fix-react-native'
    return
  end

  path_to_fix = version_file(version)

  if File.exist? path_to_fix
    Pod::UI.section "Patching React Native #{version}" do
      require(path_to_fix)
    end
  end
end

#pre_fix_with_context(context) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cocoapods-fix-react-native/fix_with_context.rb', line 35

def pre_fix_with_context(context)
  # Get the current version of React Native in your app
  locked_dependencies = Molinillo::DependencyGraph.new
  if context.lockfile
    context.lockfile.dependencies.each do |dependency|
      locked_dependencies.add_vertex(dependency.name, dependency, true)
    end
  else
    Pod::UI.warn 'No Podfile.lock present. Continuing without locked dependencies.'
  end

  sources = context.podfile.sources.map do |source|
    Pod::Config.instance.sources_manager.source_with_name_or_url(source)
  end

  react_spec = nil
  
  begin
    resolver = Pod::Resolver.new(context.sandbox, context.podfile, locked_dependencies, sources, true)
    target_definitions = resolver.resolve

    target_definitions.each do |(definition, dependencies)|
      next if definition.name == 'Pods'

      react = dependencies.find { |d| d.spec.name == 'React' || d.spec.name.start_with?('React/') }
      next if react.nil?
      react_spec = react.spec
    end
  rescue StandardError => e
    Pod::UI.warn 'Failed to resolve dependencies, so pre-patch was not applied, ' +
                 'please try running `pod install` again to apply the patch.'
  end

  return if react_spec.nil?

  version = react_spec.version.to_s

  # There will probably always be a neeed for the post, but a pre can be ignored
  return unless patch_exist?(version)

  path_to_fix = version_file(version, 'pre')

  if File.exist? path_to_fix
    Pod::UI.section "Patching React Native #{version}" do
      require(path_to_fix)
    end
  end
end