Skip to content

Commit

Permalink
Improve default gem handling
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
deivid-rodriguez committed Dec 12, 2023
1 parent 0e919ea commit 091b4fc
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bundler/lib/bundler/rubygems_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def path_separator
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
Expand Down
6 changes: 1 addition & 5 deletions bundler/lib/bundler/source/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,7 @@ def cached_built_in_gem(spec)
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
Expand Down
17 changes: 2 additions & 15 deletions bundler/spec/cache/gems_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@

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
Expand Down Expand Up @@ -143,19 +143,6 @@
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
Expand Down
1 change: 0 additions & 1 deletion bundler/spec/commands/open_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@

install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem "json"
G
end

Expand Down
6 changes: 5 additions & 1 deletion bundler/spec/runtime/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,10 @@ def lock_with(ruby_version = nil)

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
Expand All @@ -1299,7 +1303,7 @@ def lock_with(ruby_version = nil)
end

gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
source "#{file_uri_for(gem_repo2)}"
gem "bar", :git => "#{lib_path("bar-1.0")}"
G

Expand Down

0 comments on commit 091b4fc

Please sign in to comment.