[rubygems/rubygems] Respect files loaded from default gems before rubygems

https://github.com/rubygems/rubygems/commit/f3da3c1190
This commit is contained in:
David Rodríguez 2020-03-25 15:55:16 +01:00 коммит произвёл Hiroshi SHIBATA
Родитель ff5ca548c3
Коммит f8f5e7fadf
3 изменённых файлов: 33 добавлений и 0 удалений

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

@ -1226,6 +1226,8 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
next unless $~
end
spec.activate if already_loaded?(file)
@path_to_default_spec_map[file] = spec
@path_to_default_spec_map[file.sub(suffix_regexp, "")] = spec
end
@ -1291,6 +1293,18 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
attr_reader :pre_uninstall_hooks
private
def already_loaded?(file)
default_gem_load_paths.find do |load_path_entry|
$LOADED_FEATURES.include?("#{load_path_entry}/#{file}")
end
end
def default_gem_load_paths
@default_gem_load_paths ||= $LOAD_PATH[load_path_insert_index..-1]
end
end
##

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

@ -803,6 +803,7 @@ class Gem::TestCase < Minitest::Test
lib_dir = File.join(@tempdir, "default_gems", "lib")
lib_dir.instance_variable_set(:@gem_prelude_index, lib_dir)
Gem.instance_variable_set(:@default_gem_load_paths, [*Gem.instance_variable_get(:@default_gem_load_paths), lib_dir])
$LOAD_PATH.unshift(lib_dir)
files.each do |file|
rb_path = File.join(lib_dir, file)

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

@ -300,6 +300,24 @@ class TestGemRequire < Gem::TestCase
$LOAD_PATH.replace lp if load_path_changed
end
def test_activate_via_require_respects_loaded_default_from_default_gems
a1 = new_default_spec "a", "1", nil, "a.rb"
# simulate requiring a default gem before rubygems is loaded
Kernel.send(:gem_original_require, "a")
# simulate registering default specs on loading rubygems
install_default_gems a1
a2 = util_spec "a", "2", nil, "lib/a.rb"
install_specs a2
refute_require 'a'
assert_equal %w[a-1], loaded_spec_names
end
def test_already_activated_direct_conflict
a1 = util_spec "a", "1", { "b" => "> 0" }
b1 = util_spec "b", "1", { "c" => ">= 1" }, "lib/ib.rb"