Skip to content

Commit

Permalink
[rubygems/rubygems] Revert RubyGems plugins getting loaded on `Bundle…
Browse files Browse the repository at this point in the history
…r.require`

These changes were included when adding bundler plugin hooks for
`Bundler.require`, but they seem completely unrelated to that feature,
and have caused several issues.

rubygems/rubygems@8d56551dcf
  • Loading branch information
deivid-rodriguez authored and hsbt committed Jan 16, 2025
1 parent 10e7e92 commit e7de621
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
18 changes: 0 additions & 18 deletions lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ def auto_install
# Bundler.require(:test) # requires second_gem
#
def require(*groups)
load_plugins
setup(*groups).require(*groups)
end

Expand Down Expand Up @@ -576,23 +575,6 @@ def feature_flag
@feature_flag ||= FeatureFlag.new(VERSION)
end

def load_plugins(definition = Bundler.definition)
return if defined?(@load_plugins_ran)

Bundler.rubygems.load_plugins

requested_path_gems = definition.requested_specs.select {|s| s.source.is_a?(Source::Path) }
path_plugin_files = requested_path_gems.flat_map do |spec|
spec.matches_for_glob("rubygems_plugin#{Bundler.rubygems.suffix_pattern}")
rescue TypeError
error_message = "#{spec.name} #{spec.version} has an invalid gemspec"
raise Gem::InvalidSpecificationException, error_message
end
Bundler.rubygems.load_plugin_files(path_plugin_files)
Bundler.rubygems.load_env_plugins
@load_plugins_ran = true
end

def reset!
reset_paths!
Plugin.reset!
Expand Down
16 changes: 15 additions & 1 deletion lib/bundler/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def run(options)

if @definition.setup_domain!(options)
ensure_specs_are_compatible!
Bundler.load_plugins(@definition)
load_plugins
end
install(options)

Expand Down Expand Up @@ -209,6 +209,20 @@ def installation_parallelization
Bundler.settings.processor_count
end

def load_plugins
Gem.load_plugins

requested_path_gems = @definition.requested_specs.select {|s| s.source.is_a?(Source::Path) }
path_plugin_files = requested_path_gems.flat_map do |spec|
spec.matches_for_glob("rubygems_plugin#{Bundler.rubygems.suffix_pattern}")
rescue TypeError
error_message = "#{spec.name} #{spec.version} has an invalid gemspec"
raise Gem::InvalidSpecificationException, error_message
end
Gem.load_plugin_files(path_plugin_files)
Gem.load_env_plugins
end

def ensure_specs_are_compatible!
@definition.specs.each do |spec|
unless spec.matches_current_ruby?
Expand Down
12 changes: 0 additions & 12 deletions lib/bundler/rubygems_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,6 @@ def loaded_gem_paths
loaded_gem_paths.flatten
end

def load_plugins
Gem.load_plugins
end

def load_plugin_files(plugin_files)
Gem.load_plugin_files(plugin_files)
end

def load_env_plugins
Gem.load_env_plugins
end

def ui=(obj)
Gem::DefaultUserInteraction.ui = obj
end
Expand Down
16 changes: 16 additions & 0 deletions spec/bundler/runtime/require_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,22 @@ def self.two
expect(out).to eq("WIN")
end

it "does not load plugins" do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
G

create_file "plugins/rubygems_plugin.rb", "puts 'FAIL'"

run <<~R, env: { "RUBYLIB" => rubylib.unshift(bundled_app("plugins").to_s).join(File::PATH_SEPARATOR) }
Bundler.require
puts "WIN"
R

expect(out).to eq("WIN")
end

it "does not extract gemspecs from application cache packages" do
gemfile <<-G
source "https://gem.repo1"
Expand Down

0 comments on commit e7de621

Please sign in to comment.