Skip to content

Commit

Permalink
Skip warnings if bundled gems is already loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Jul 21, 2023
1 parent 75ef8f8 commit 637ffb9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/bundler/rubygems_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,15 @@ def replace_require(specs)
kernel_class.send(:define_method, :require) do |file|
name = file.tr("/", "-")
if (::Gem::BUNDLED_GEMS.keys - specs.to_a.map(&:name)).include?(name)
target_file = begin
Bundler.default_gemfile.basename
rescue GemfileNotFound
"inline Gemfile"
end
warn "#{name} is not part of the default gems since Ruby #{::Gem::BUNDLED_GEMS[file]}." \
" Add it to your #{target_file}."
unless $LOADED_FEATURES.any?{|f| f.end_with?("#{name}.rb", "#{name}.#{RbConfig::CONFIG['DLEXT']}")}
target_file = begin
Bundler.default_gemfile.basename
rescue GemfileNotFound
"inline Gemfile"
end
warn "#{name} is not part of the default gems since Ruby #{::Gem::BUNDLED_GEMS[file]}." \
" Add it to your #{target_file}."
end
end
kernel_class.send(:no_warning_require, file)
end
Expand Down
19 changes: 19 additions & 0 deletions spec/bundler/runtime/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,25 @@ def require(path)
expect(err).to include("csv is not part of the default gems")
end

it "don't warn with bundled gems when it's loaded twice" do
build_repo4 do
build_gem "rack"
end

install_gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem "rack"
G

ruby <<-R
require 'csv'
require 'bundler/setup'
require 'csv'
R

expect(err).to be_empty
end

it "don't warn with bundled gems when it's declared in Gemfile" do
build_repo4 do
build_gem "csv"
Expand Down

0 comments on commit 637ffb9

Please sign in to comment.