From 64e985333f4fa7e4ba06454ef50c41e56a22768d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 7 Dec 2023 21:35:47 +0100 Subject: [PATCH] Improve bundled gems warnings for subfeatures Before, when requiring "bigdecimal/math" in a Bundler context: > /Users/deivid/.asdf/installs/ruby/3.3.0-dev/lib/ruby/3.3.0+0/bigdecimal/math.rb:2: warning: bigdecimal was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.4.0. Add bigdecimal to your Gemfile or gemspec. After: > foo.rb:1: warning: bigdecimal/math is found in bigdecimal, which will no longer be part of the default gems since Ruby 3.4.0. Add bigdecimal to your Gemfile or gemspec. --- lib/bundled_gems.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/bundled_gems.rb b/lib/bundled_gems.rb index 6b13adf91d9af2..3967511cd1af3a 100644 --- a/lib/bundled_gems.rb +++ b/lib/bundled_gems.rb @@ -89,10 +89,10 @@ def self.find_gem(path) end def self.warning?(name, specs: nil) - name = File.path(name) # name can be a feature name or a file path with String or Pathname - return if specs.to_a.map(&:name).include?(name.sub(LIBEXT, "")) - name = name.tr("/", "-") - _t, path = $:.resolve_feature_path(name) + feature = File.path(name) # name can be a feature name or a file path with String or Pathname + return if specs.to_a.map(&:name).include?(feature.sub(LIBEXT, "")) + _t, path = $:.resolve_feature_path(feature) + name = feature.tr("/", "-") if gem = find_gem(path) caller = caller_locations(3, 3).find {|c| c&.absolute_path} return if find_gem(caller&.absolute_path) @@ -106,11 +106,11 @@ def self.warning?(name, specs: nil) WARNED[name] = true if gem == true gem = name - "#{name} was loaded from the standard library, but" + "#{feature} was loaded from the standard library, but" elsif gem return if WARNED[gem] WARNED[gem] = true - "#{name} is found in #{gem}, which" + "#{feature} is found in #{gem}, which" else return end + build_message(gem)