Skip to content

Commit eaa06c2

Browse files
hsbtclaude
authored andcommitted
Guard the vendored pub_grub against double loading
When the same Gem::PubGrub copy is shipped in two gems (RubyGems and Bundler) and required from different paths, the unguarded entrypoint reloads it and emits "already initialized constant" warnings. Add an idempotent guard at the top of the vendored pub_grub.rb so a second load from any path short-circuits before requiring any subfile. This prepares Bundler to reuse RubyGems' copy. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent c0d2bbc commit eaa06c2

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/rubygems/vendor/pub_grub/lib/pub_grub.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Skip reloading when an identical copy (e.g. the one shipped inside the Bundler
2+
# gem) was already required from a different path, to avoid redefinition warnings.
3+
return if defined?(Gem::PubGrub::VERSION)
4+
15
require_relative "pub_grub/package"
26
require_relative "pub_grub/static_package_source"
37
require_relative "pub_grub/term"

tool/automatiek/pub_grub-rubygems.patch

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
diff --git a/lib/rubygems/vendor/pub_grub/lib/pub_grub.rb b/lib/rubygems/vendor/pub_grub/lib/pub_grub.rb
22
--- a/lib/rubygems/vendor/pub_grub/lib/pub_grub.rb
33
+++ b/lib/rubygems/vendor/pub_grub/lib/pub_grub.rb
4-
@@ -11,6 +11,32 @@
4+
@@ -1,3 +1,7 @@
5+
+# Skip reloading when an identical copy (e.g. the one shipped inside the Bundler
6+
+# gem) was already required from a different path, to avoid redefinition warnings.
7+
+return if defined?(Gem::PubGrub::VERSION)
8+
+
9+
require_relative "pub_grub/package"
10+
require_relative "pub_grub/static_package_source"
11+
require_relative "pub_grub/term"
12+
@@ -11,6 +15,32 @@
513
require_relative 'pub_grub/version'
614

715
module Gem::PubGrub

0 commit comments

Comments
 (0)