diff options
| author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2023-10-12 14:48:18 +0900 |
|---|---|---|
| committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2023-10-13 16:22:09 +0900 |
| commit | 57c2ae206f46e3c37ec8927dc51cffc53d47cda8 (patch) | |
| tree | c2ee660d736246ab020ffd4fde79afc6bf2b49bc | |
| parent | ea05ddbeff99b1c0766b0171d11a9fa84dce62ec (diff) | |
Move additional warnings for Gem author under Gem::BUNDLED_GEMS.
| -rw-r--r-- | lib/bundled_gems.rb | 22 | ||||
| -rw-r--r-- | lib/bundler/rubygems_integration.rb | 12 |
2 files changed, 20 insertions, 14 deletions
diff --git a/lib/bundled_gems.rb b/lib/bundled_gems.rb index 9e5c5b2082..fa7f77f327 100644 --- a/lib/bundled_gems.rb +++ b/lib/bundled_gems.rb @@ -76,7 +76,7 @@ module Gem::BUNDLED_GEMS return if find_gem(caller&.absolute_path) return if WARNED[name] WARNED[name] = true - if gem == true + msg = if gem == true gem = name.sub(LIBEXT, "") # assume "foo.rb"/"foo.so" belongs to "foo" gem elsif gem return if WARNED[gem] @@ -84,7 +84,25 @@ module Gem::BUNDLED_GEMS "#{name} is found in #{gem}" else return - end + " which #{RUBY_VERSION < SINCE[gem] ? "will be" : "is"} not part of the default gems since Ruby #{SINCE[gem]}" + end + msg += " which #{RUBY_VERSION < SINCE[gem] ? "will be" : "is"} not part of the default gems since Ruby #{SINCE[gem]}." + + if defined?(Bundler) + msg += " Add #{name} to your Gemfile." + location = caller_locations(2,2)[0]&.path + if File.file?(location) && !location.start_with?(Gem::BUNDLED_GEMS::LIBDIR) + caller_gem = nil + Gem.path.each do |path| + if location =~ %r{#{path}/gems/([\w\-\.]+)} + caller_gem = $1 + break + end + end + msg += " Also contact author of #{caller_gem} to add #{name} into its gemspec." + end + end + + msg end bundled_gems = self diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index b15bd31c47..29bd83a65a 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -245,18 +245,6 @@ module Bundler kernel_class.send(:alias_method, :no_warning_require, :require) kernel_class.send(:define_method, :require) do |name| if message = ::Gem::BUNDLED_GEMS.warning?(name) - message += " Add #{name} to your Gemfile." - location = caller_locations(1,1)[0]&.path - if File.file?(location) && !location.start_with?(Gem::BUNDLED_GEMS::LIBDIR) - caller_gem = nil - Gem.path.each do |path| - if location =~ %r{#{path}/gems/([\w\-\.]+)} - caller_gem = $1 - break - end - end - message += " Also contact author of #{caller_gem} to add #{name} into its gemspec." - end warn message, :uplevel => 1 end kernel_class.send(:no_warning_require, name) |
