Skip to content

Commit f7359e1

Browse files
committed
Suggest to add bundled gems into gemspec if 3rd party gem try to load gem from Gem::BUNDLED_GEMS::SINCE
[Feature #19846]
1 parent 70272ca commit f7359e1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/bundler/rubygems_integration.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,20 @@ def replace_require(specs)
254254
"inline Gemfile"
255255
end
256256
be = RUBY_VERSION < ::Gem::BUNDLED_GEMS::SINCE[name] ? "will be" : "is"
257-
warn "#{name} #{be} not part of the default gems since Ruby #{::Gem::BUNDLED_GEMS::SINCE[name]}." \
258-
" Add it to your #{target_file}.", uplevel: 1
257+
message = "#{name} #{be} not part of the default gems since Ruby #{::Gem::BUNDLED_GEMS::SINCE[name]}." \
258+
" Add #{name} to your #{target_file}."
259+
location = caller_locations(1,1)[0]&.path
260+
if File.file?(location) && !location.start_with?(Gem::BUNDLED_GEMS::LIBDIR)
261+
caller_gem = nil
262+
Gem.path.each do |path|
263+
if location =~ /#{path}\/gems\/([\w\-\.]+)/
264+
caller_gem = $1
265+
break
266+
end
267+
end
268+
message += " Also contact author of #{caller_gem} to add #{name} into its gemspec."
269+
end
270+
warn message, uplevel: 1
259271
end
260272
end
261273
kernel_class.send(:no_warning_require, file)

0 commit comments

Comments
 (0)