Skip to content

Commit

Permalink
Allow running gem tasks inside paths with brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Sep 29, 2020
1 parent 608d02e commit c0d38ce
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bundler/lib/bundler/gem_helper.rb
Original file line number Diff line number Diff line change
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")] : Dir[File.join(@base, "{,*}.gemspec")]
gemspecs = name ? [File.join(@base, "#{name}.gemspec")] : Gem::Util.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
Dir[File.join(base, "#{name}-*.gem")].sort_by {|f| File.mtime(f) }.last
Gem::Util.glob_files_in_dir("#{name}-*.gem", base).sort_by {|f| File.mtime(f) }.last
end

def git_push(remote = nil)
Expand Down
16 changes: 16 additions & 0 deletions bundler/lib/bundler/rubygems_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,22 @@ 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
12 changes: 12 additions & 0 deletions bundler/spec/runtime/gem_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@
end
end

context "rake build when path has brackets", :ruby_repo do
before do
bracketed_bundled_app = tmp.join("bundled[app")
FileUtils.cp_r bundled_app, bracketed_bundled_app
bundle "exec rake build", :dir => bracketed_bundled_app
end

it "still runs successfully" do
expect(err).to be_empty
end
end

context "bundle path configured locally" do
before do
bundle "config set path vendor/bundle"
Expand Down

0 comments on commit c0d38ce

Please sign in to comment.