Skip to content

Commit 047a438

Browse files
hsbtclaude
andcommitted
Remove stale plugin wrappers even when --no-install-plugin is specified
When a gem upgrades from a version with plugins to one without, generate_plugins normally removes the old wrapper files. Skipping generate_plugins entirely with --no-install-plugin prevented this cleanup, leaving stale wrappers that would still be loaded. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 24b00a1 commit 047a438

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

bundler/lib/bundler/rubygems_gem_installer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def install
4040
end
4141

4242
if options[:install_plugin] == false
43+
remove_stale_plugins
4344
warn_skipped_plugins
4445
else
4546
generate_plugins

lib/rubygems/installer.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ def install
292292

293293
generate_bin
294294
if options[:install_plugin] == false
295+
remove_stale_plugins
295296
warn_skipped_plugins
296297
else
297298
generate_plugins
@@ -831,6 +832,13 @@ def warn_skipped_plugins # :nodoc:
831832
"To install plugins, run: gem pristine #{spec.name} --only-plugins"
832833
end
833834

835+
def remove_stale_plugins # :nodoc:
836+
return unless spec.plugins.empty?
837+
838+
ensure_writable_dir @plugins_dir
839+
remove_plugins_for(spec, @plugins_dir)
840+
end
841+
834842
##
835843
# Reads the file index and extracts each file into the gem directory.
836844
#

test/rubygems/test_gem_installer.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,6 +2539,39 @@ def test_install_no_install_plugin_without_plugins
25392539
refute_match "contains plugins", @ui.error
25402540
end
25412541

2542+
def test_install_no_install_plugin_removes_stale_wrappers
2543+
# First install a version with a plugin
2544+
installer = util_setup_installer do |spec|
2545+
write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io|
2546+
io.write "# plugin code"
2547+
end
2548+
2549+
spec.files += %w[lib/rubygems_plugin.rb]
2550+
end
2551+
2552+
build_rake_in do
2553+
use_ui @ui do
2554+
installer.install
2555+
end
2556+
end
2557+
2558+
plugin_path = File.join Gem.plugindir, "a_plugin.rb"
2559+
assert File.exist?(plugin_path), "plugin wrapper should exist after first install"
2560+
2561+
# Now install a new version without plugins, using --no-install-plugin
2562+
spec2 = quick_gem "a", 3
2563+
util_build_gem spec2
2564+
2565+
installer2 = util_installer spec2, @gemhome
2566+
installer2.options[:install_plugin] = false
2567+
2568+
use_ui @ui do
2569+
installer2.install
2570+
end
2571+
2572+
refute File.exist?(plugin_path), "stale plugin wrapper must be removed"
2573+
end
2574+
25422575
private
25432576

25442577
def util_execless

0 commit comments

Comments
 (0)