Top Level Namespace

Defined Under Namespace

Classes: CocoaPodsFixReactNative, ReactDependencyVersion

Instance Method Summary collapse

Instance Method Details

#detect_missing_subspec_dependency(subspec_name, source_filename, dependent_source_filename) ⇒ Object



84
85
86
87
88
# File 'lib/cocoapods-fix-react-native/versions/0_54_4-post.rb', line 84

def detect_missing_subspec_dependency(subspec_name, source_filename, dependent_source_filename)
  unless meets_pods_project_source_dependency(source_filename, dependent_source_filename)
    Pod::UI.warn "#{subspec_name} subspec may be required given your current dependencies"
  end
end

#detect_missing_subspecsObject



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/cocoapods-fix-react-native/versions/0_54_4-post.rb', line 90

def detect_missing_subspecs
  return unless $has_frameworks

  # For CocoaPods + Frameworks, RCTNetwork and CxxBridge subspecs are necessary for DevSupport.
  # When the React pod is generated it must include all the required source, and see umbrella deps.
  detect_missing_subspec_dependency('RCTNetwork', 'RCTBlobManager.mm', 'RCTNetworking.mm')
  detect_missing_subspec_dependency('CxxBridge', 'RCTJavaScriptLoader.mm', 'RCTCxxBridge.mm')

  # RCTText itself shouldn't require DevSupport, but it depends on Core -> RCTDevSettings -> RCTPackagerClient
  detect_missing_subspec_dependency('DevSupport', 'RCTDevSettings.mm', 'RCTPackagerClient.m')
end

#edit_pod_file(path, old_code, new_code) ⇒ Object

TODO: move to be both file in pods and file in node_mods?



7
8
9
10
11
12
13
14
15
# File 'lib/cocoapods-fix-react-native/versions/0_54_2-post.rb', line 7

def edit_pod_file(path, old_code, new_code)
  file = File.join($root, path)
  code = File.read(file)
  if code.include?(old_code)
    puts "[CPFRN] Editing #{file}" if Pod::Config.instance.verbose
    FileUtils.chmod('+w', file)
    File.write(file, code.sub(old_code, new_code))
  end
end

#fix_cplusplus_header_compiler_errorObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cocoapods-fix-react-native/versions/0_54_2-post.rb', line 17

def fix_cplusplus_header_compiler_error
  filepath = File.join($root, 'React/Base/Surface/SurfaceHostingView/RCTSurfaceSizeMeasureMode.h')
  FileUtils.chmod('+w', filepath)

  contents = []

  file = File.open(filepath, 'r')
  file.each_line do |line|
    contents << line
  end
  file.close

  if contents[32].include? '&'
    contents.insert(26, '#ifdef __cplusplus')
    contents[36] = '#endif'

    file = File.open(filepath, 'w') do |f|
      f.puts(contents)
    end
  end
end

#fix_unused_yoga_headersObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cocoapods-fix-react-native/versions/0_53_3-post.rb', line 25

def fix_unused_yoga_headers
  filepath = 'Pods/Target Support Files/yoga/yoga-umbrella.h'
  # This only exists when using CocoaPods + Frameworks
  return unless File.exist?(filepath)

  contents = []
  file = File.open(filepath, 'r')
  file.each_line do |line|
    contents << line
  end
  file.close

  if contents[14].include? 'YGNode.h'
    Pod::UI.message "Patching #{filepath}", '- '
    contents.delete_at(14) # #import "YGNode.h"
    contents.delete_at(14) # #import "YGNodePrint.h"
    contents.delete_at(14) # #import "Yoga-internal.h"

    file = File.open(filepath, 'w') do |f|
      f.puts(contents)
    end
  end
end

#get_rootObject

Notes:

- All file paths should be relative to the React repo, rather than the Pods dir, or node_modules
- An enviroment variable of `COCOAPODS_FIX_REACT_NATIVE_DEV_ROOT` will override the defaults for dev.

- Returns the root directory to use for React Native


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
# File 'lib/cocoapods-fix-react-native/helpers/root_helper.rb', line 8

def get_root
  # Are you using :path based Pods?
  dev_pods_react = !File.directory?('Pods/React/React')

  # Check for whether we're in a project that uses relative paths
  same_repo_node_modules = File.directory?('node_modules/react-native')
  previous_repo_node_modules = File.directory?('../node_modules/react-native')

  # Find out where the files could be rooted
  $root = 'Pods/React'

  if dev_pods_react
    # Use this as an override, if present and non empty string
    $env_root = ENV["COCOAPODS_FIX_REACT_NATIVE_DEV_ROOT"]

    if defined?($env_root) && ($env_root != nil) && ($env_root != '')
      $root = $env_root
    else
      $root = 'node_modules/react-native' if same_repo_node_modules
      $root = '../node_modules/react-native' if previous_repo_node_modules
    end
  end

  return $root
end

#has_pods_project_source_file(source_filename) ⇒ Object

Detect source file dependency in the generated Pods.xcodeproj workspace sub-project



74
75
76
77
# File 'lib/cocoapods-fix-react-native/versions/0_54_4-post.rb', line 74

def has_pods_project_source_file(source_filename)
  pods_project = 'Pods/Pods.xcodeproj/project.pbxproj'
  File.open(pods_project).grep(/#{source_filename}/).any?
end

#meets_pods_project_source_dependency(source_filename, dependent_source_filename) ⇒ Object

Detect dependent source file required for building when the given source file is present



80
81
82
# File 'lib/cocoapods-fix-react-native/versions/0_54_4-post.rb', line 80

def meets_pods_project_source_dependency(source_filename, dependent_source_filename)
  has_pods_project_source_file(source_filename) ? has_pods_project_source_file(dependent_source_filename) : true
end

#patch_pod_file(path, old_code, new_code) ⇒ Object

TODO: move to be both file in pods and file in node_mods?



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cocoapods-fix-react-native/versions/0_53_3-post.rb', line 11

def patch_pod_file(path, old_code, new_code)
  file = File.join($root, path)
  unless File.exist?(file)
    Pod::UI.warn "#{file} does not exist so was not patched.."
    return
  end
  code = File.read(file)
  if code.include?(old_code)
    Pod::UI.message "Patching #{file}", '- '
    FileUtils.chmod('+w', file)
    File.write(file, code.sub(old_code, new_code))
  end
end