Skip to content

Commit

Permalink
No need to monkeypatch rubygems, actually
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Sep 29, 2020
1 parent 177c408 commit 2d93d8c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bundler/lib/bundler/dsl.rb
Expand Up @@ -63,7 +63,7 @@ def gemspec(opts = nil)
development_group = opts[:development_group] || :development
expanded_path = gemfile_root.join(path)

gemspecs = Gem::Util.glob_files_in_dir("{,*}.gemspec", expanded_path).map {|g| Bundler.load_gemspec(g) }.compact
gemspecs = Bundler::SharedHelpers.glob_files_in_dir("{,*}.gemspec", expanded_path).map {|g| Bundler.load_gemspec(g) }.compact
gemspecs.reject! {|s| s.name != name } if name
Index.sort_specs(gemspecs)
specs_by_name_and_version = gemspecs.group_by {|s| [s.name, s.version] }
Expand Down
4 changes: 2 additions & 2 deletions bundler/lib/bundler/gem_helper.rb
Expand Up @@ -32,7 +32,7 @@ def gemspec(&block)

def initialize(base = nil, name = nil)
@base = File.expand_path(base || SharedHelpers.pwd)
gemspecs = name ? [File.join(@base, "#{name}.gemspec")] : Gem::Util.glob_files_in_dir("{,*}.gemspec", @base)
gemspecs = name ? [File.join(@base, "#{name}.gemspec")] : SharedHelpers.glob_files_in_dir("{,*}.gemspec", @base)
raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1
@spec_path = gemspecs.first
@gemspec = Bundler.load_gemspec(@spec_path)
Expand Down Expand Up @@ -111,7 +111,7 @@ def rubygem_push(path)
end

def built_gem_path
Gem::Util.glob_files_in_dir("#{name}-*.gem", base).sort_by {|f| File.mtime(f) }.last
SharedHelpers.glob_files_in_dir("#{name}-*.gem", base).sort_by {|f| File.mtime(f) }.last
end

def git_push(remote = nil)
Expand Down
16 changes: 0 additions & 16 deletions bundler/lib/bundler/rubygems_ext.rb
Expand Up @@ -173,22 +173,6 @@ def hash
undef_method :eql? if method_defined? :eql?
alias_method :eql?, :==
end

require "rubygems/util"

Util.singleton_class.module_eval do
if Util.singleton_methods.include?(:glob_files_in_dir) # since 3.0.0.beta.2
remove_method :glob_files_in_dir
end

def glob_files_in_dir(glob, base_path)
if RUBY_VERSION >= "2.5"
Dir.glob(glob, :base => base_path).map! {|f| File.expand_path(f, base_path) }
else
Dir.glob(File.join(base_path.to_s.gsub(/[\[\]]/, '\\\\\\&'), glob)).map! {|f| File.expand_path(f) }
end
end
end
end

module Gem
Expand Down
8 changes: 8 additions & 0 deletions bundler/lib/bundler/shared_helpers.rb
Expand Up @@ -205,6 +205,14 @@ def write_to_gemfile(gemfile_path, contents)
filesystem_access(gemfile_path) {|g| File.open(g, "w") {|file| file.puts contents } }
end

def glob_files_in_dir(glob, base_path)
if RUBY_VERSION >= "2.5"
Dir.glob(glob, :base => base_path).map! {|f| File.expand_path(f, base_path) }
else
Dir.glob(File.join(base_path.to_s.gsub(/[\[\]]/, '\\\\\\&'), glob)).map! {|f| File.expand_path(f) }
end
end

private

def validate_bundle_path
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/source/path.rb
Expand Up @@ -171,7 +171,7 @@ def load_spec_files

if File.directory?(expanded_path)
# We sort depth-first since `<<` will override the earlier-found specs
Gem::Util.glob_files_in_dir(@glob, expanded_path).sort_by {|p| -p.split(File::SEPARATOR).size }.each do |file|
SharedHelpers.glob_files_in_dir(@glob, expanded_path).sort_by {|p| -p.split(File::SEPARATOR).size }.each do |file|
next unless spec = load_gemspec(file)
spec.source = self

Expand Down

0 comments on commit 2d93d8c

Please sign in to comment.