Skip to content

Commit

Permalink
fix(apple): avoid invoking Node for module resolution (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 authored Aug 16, 2021
1 parent b1cd30b commit be1f63d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
"platform: macOS":
- ReactTestApp-DevSupport.podspec
- example/macos/**/*
- ios/*.rb
- ios/ReactTestApp/Manifest.swift
- ios/ReactTestApp/React+Compatibility.{h,m}
- ios/ReactTestApp/ReactInstance.swift
- ios/ReactTestApp/ReactTestApp-Bridging-Header.h
- ios/ReactTestApp/Session.swift
- ios/ReactTestApp/UIViewController+ReactTestApp.{h,m}
- ios/use_react_native-*.rb
- macos/**/*
"platform: Windows":
- example/windows/**/*
Expand Down
16 changes: 13 additions & 3 deletions ios/pod_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@
# LICENSE file in the root directory of this source tree.
#

def find_file(file_name, current_dir)
return if current_dir.expand_path.to_s == '/'

path = current_dir + file_name
return path if File.exist?(path)

find_file(file_name, current_dir.parent)
end

def resolve_module(request)
@module_cache ||= {}
return @module_cache[request] if @module_cache.key?(request)

script = "console.log(path.dirname(require.resolve('#{request}/package.json')));"
path = Pod::Executable.execute_command('node', ['-e', script], true).strip
@module_cache[request] = path
package_json = find_file("node_modules/#{request}/package.json", Pathname.pwd)
raise "Cannot find module '#{request}'" if package_json.nil?

@module_cache[request] = package_json.dirname.to_s
end

def try_pod(name, podspec, project_root)
Expand Down
9 changes: 0 additions & 9 deletions ios/test_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ def react_native_from_manifest(project_root, target_platform)
return react_native_path if react_native_path.is_a? String
end

def find_file(file_name, current_dir)
return if current_dir.expand_path.to_s == '/'

path = current_dir + file_name
return path if File.exist?(path)

find_file(file_name, current_dir.parent)
end

def find_project_root
podfile_path = Thread.current.backtrace_locations.find do |location|
File.basename(location.absolute_path) == 'Podfile'
Expand Down

0 comments on commit be1f63d

Please sign in to comment.