[rubygems/rubygems] Improve default gem handling

If a gem is specified in the Gemfile (or resolved as a transitive
dependency), it's always resolved from remote/installed sources. Default
gems are only used as a fallback for gems not included in the bundle.

I believe this leads to more consistent behavior and more portable apps,
since all gems will be installed to the configured bundle path,
regardless of whether they are default gems or not.

https://github.com/rubygems/rubygems/commit/091b4fcf2b
This commit is contained in:
David Rodríguez 2023-12-11 13:19:45 +01:00 коммит произвёл Hiroshi SHIBATA
Родитель 1a7aa5560f
Коммит ac939d9ca3
5 изменённых файлов: 9 добавлений и 23 удалений

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

@ -509,7 +509,7 @@ module Bundler
end
def all_specs
Gem::Specification.stubs.map do |stub|
Gem::Specification.stubs.reject(&:default_gem?).map do |stub|
StubSpecification.from_stub(stub)
end
end

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

@ -225,11 +225,7 @@ module Bundler
cached_path = cached_path(spec)
if cached_path.nil?
remote_spec = remote_specs.search(spec).first
if remote_spec
cached_path = fetch_gem(remote_spec)
else
Bundler.ui.warn "#{spec.full_name} is built in to Ruby, and can't be cached because your Gemfile doesn't have any sources that contain it."
end
cached_path = fetch_gem(remote_spec)
end
cached_path
end

17
spec/bundler/cache/gems_spec.rb поставляемый
Просмотреть файл

@ -102,8 +102,8 @@ RSpec.describe "bundle cache" do
it "uses builtin gems when installing to system gems" do
bundle "config set path.system true"
install_gemfile %(source "#{file_uri_for(gem_repo1)}"; gem 'json', '#{default_json_version}'), verbose: true
expect(out).to include("Using json #{default_json_version}")
install_gemfile %(source "#{file_uri_for(gem_repo2)}"; gem 'json', '#{default_json_version}'), verbose: true
expect(out).to include("Installing json #{default_json_version}")
end
it "caches remote and builtin gems" do
@ -143,19 +143,6 @@ RSpec.describe "bundle cache" do
bundle "install --local"
expect(the_bundle).to include_gems("builtin_gem_2 1.0.2")
end
it "errors if the builtin gem isn't available to cache" do
bundle "config set path.system true"
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem 'json', '#{default_json_version}'
G
bundle :cache, raise_on_error: false
expect(exitstatus).to_not eq(0)
expect(err).to include("json-#{default_json_version} is built in to Ruby, and can't be cached")
end
end
describe "when there are also git sources" do

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

@ -164,7 +164,6 @@ RSpec.describe "bundle open" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem "json"
G
end

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

@ -1281,6 +1281,10 @@ end
describe "with gemified standard libraries" do
it "does not load Digest", :ruby_repo do
build_repo2 do
build_gem "digest"
end
build_git "bar", gemspec: false do |s|
s.write "lib/bar/version.rb", %(BAR_VERSION = '1.0')
s.write "bar.gemspec", <<-G
@ -1299,7 +1303,7 @@ end
end
gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "#{file_uri_for(gem_repo2)}"
gem "bar", :git => "#{lib_path("bar-1.0")}"
G