From e7de621b5a49a83b6ebf824fd284d24783f95988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 14 Jan 2025 07:41:25 +0100 Subject: [PATCH] [rubygems/rubygems] Revert RubyGems plugins getting loaded on `Bundler.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. https://github.com/rubygems/rubygems/commit/8d56551dcf --- lib/bundler.rb | 18 ------------------ lib/bundler/installer.rb | 16 +++++++++++++++- lib/bundler/rubygems_integration.rb | 12 ------------ spec/bundler/runtime/require_spec.rb | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/bundler.rb b/lib/bundler.rb index 177d7257e6..0480cac1a8 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -212,7 +212,6 @@ module Bundler # Bundler.require(:test) # requires second_gem # def require(*groups) - load_plugins setup(*groups).require(*groups) end @@ -576,23 +575,6 @@ module Bundler @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! diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index e60201e52c..1cd49d8897 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -79,7 +79,7 @@ module Bundler if @definition.setup_domain!(options) ensure_specs_are_compatible! - Bundler.load_plugins(@definition) + load_plugins end install(options) @@ -209,6 +209,20 @@ module Bundler 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? diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 6576330f7a..a8571f5115 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -134,18 +134,6 @@ module Bundler 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 diff --git a/spec/bundler/runtime/require_spec.rb b/spec/bundler/runtime/require_spec.rb index ff45a3c5e2..ece6679eb2 100644 --- a/spec/bundler/runtime/require_spec.rb +++ b/spec/bundler/runtime/require_spec.rb @@ -431,6 +431,22 @@ RSpec.describe "Bundler.require" do 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"