[rubygems/rubygems] Don't cleanup paths from gems already activated from `$LOAD_PATH`

This way, if some default gem has been required before bundler, and
rubygems has enhanced the `$LOAD_PATH` to use the latest version in the
system, further requires of that default gem after bundler has been
activated will use the same version and don't cause redefinition
warnings or worse problems derived from the fact of mixing up two
different versions. That, unless the gem is a `Gemfile` dependency. In
that case, we'll get a mismatch error anyways as we do now.

This fix doesn't mean that all default gems internally used by
bundler/rubygems are now supported inside `Gemfile`'s. That should be
handled case by case, but it will now bite people only when they try to
add the gem to their `Gemfile`, not before.

https://github.com/rubygems/rubygems/commit/7325530547
This commit is contained in:
David Rodríguez 2021-11-29 18:18:24 +01:00 коммит произвёл git
Родитель 715a51a0d6
Коммит 526c9359ca
2 изменённых файлов: 25 добавлений и 3 удалений

Просмотреть файл

@ -313,12 +313,11 @@ module Bundler
end
def clean_load_path
bundler_lib = bundler_ruby_lib
loaded_gem_paths = Bundler.rubygems.loaded_gem_paths
$LOAD_PATH.reject! do |p|
next if resolve_path(p).start_with?(bundler_lib)
resolved_path = resolve_path(p)
next if $LOADED_FEATURES.any? {|lf| lf.start_with?(resolved_path) }
loaded_gem_paths.delete(p)
end
$LOAD_PATH.uniq!

Просмотреть файл

@ -1511,5 +1511,28 @@ end
expect(out).to include("rack, yard")
end
it "does not cause double loads when higher versions of default gems are activated before bundler" do
build_repo2 do
build_gem "json", "999.999.999" do |s|
s.write "lib/json.rb", <<~RUBY
module JSON
VERSION = "999.999.999"
end
RUBY
end
end
system_gems "json-999.999.999", :gem_repo => gem_repo2
install_gemfile "source \"#{file_uri_for(gem_repo1)}\""
ruby <<-RUBY
require "json"
require "bundler/setup"
require "json"
RUBY
expect(err).to be_empty
end
end
end