We can't handle optional dependency without new API of Rubygems.

I don't want to make bundled_gems.rb more complex and complicate.

Revert "Fixed warning condition with LoadError"

This reverts commit 3a9e48b9a4.

Revert "Only warn fiddle as optional dependency"

This reverts commit ff3f61556f.

Revert "Only `warn` about bundled gems when require succeeds"

This reverts commit a70adce1ce.
This commit is contained in:
Hiroshi SHIBATA 2024-11-12 19:34:10 +09:00
Родитель 8ae63ca3be
Коммит 441069c093
1 изменённых файлов: 2 добавлений и 21 удалений

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

@ -49,10 +49,6 @@ module Gem::BUNDLED_GEMS
"syslog" => true,
}.freeze
OPTIONAL = {
"fiddle" => true,
}.freeze
WARNED = {} # unfrozen
conf = ::RbConfig::CONFIG
@ -70,30 +66,15 @@ module Gem::BUNDLED_GEMS
[::Kernel.singleton_class, ::Kernel].each do |kernel_class|
kernel_class.send(:alias_method, :no_warning_require, :require)
kernel_class.send(:define_method, :require) do |name|
message = ::Gem::BUNDLED_GEMS.warning?(name, specs: spec_names)
begin
result = kernel_class.send(:no_warning_require, name)
rescue LoadError => e
result = e
end
# Don't warn if the gem is optional dependency and not found in the Bundler environment.
if !(result.is_a?(LoadError) && OPTIONAL[name]) && message
if message = ::Gem::BUNDLED_GEMS.warning?(name, specs: spec_names)
if ::Gem::BUNDLED_GEMS.uplevel > 0
Kernel.warn message, uplevel: ::Gem::BUNDLED_GEMS.uplevel
else
Kernel.warn message
end
end
if result.is_a?(LoadError)
raise result
else
result
end
kernel_class.send(:no_warning_require, name)
end
if kernel_class == ::Kernel
kernel_class.send(:private, :require)
else