Skip to content

Commit 091b4fc

Browse files
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.
1 parent 0e919ea commit 091b4fc

File tree

5 files changed

+9
-23
lines changed

5 files changed

+9
-23
lines changed

bundler/lib/bundler/rubygems_integration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def path_separator
509509
end
510510

511511
def all_specs
512-
Gem::Specification.stubs.map do |stub|
512+
Gem::Specification.stubs.reject(&:default_gem?).map do |stub|
513513
StubSpecification.from_stub(stub)
514514
end
515515
end

bundler/lib/bundler/source/rubygems.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,7 @@ def cached_built_in_gem(spec)
225225
cached_path = cached_path(spec)
226226
if cached_path.nil?
227227
remote_spec = remote_specs.search(spec).first
228-
if remote_spec
229-
cached_path = fetch_gem(remote_spec)
230-
else
231-
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."
232-
end
228+
cached_path = fetch_gem(remote_spec)
233229
end
234230
cached_path
235231
end

bundler/spec/cache/gems_spec.rb

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@
102102

103103
it "uses builtin gems when installing to system gems" do
104104
bundle "config set path.system true"
105-
install_gemfile %(source "#{file_uri_for(gem_repo1)}"; gem 'json', '#{default_json_version}'), verbose: true
106-
expect(out).to include("Using json #{default_json_version}")
105+
install_gemfile %(source "#{file_uri_for(gem_repo2)}"; gem 'json', '#{default_json_version}'), verbose: true
106+
expect(out).to include("Installing json #{default_json_version}")
107107
end
108108

109109
it "caches remote and builtin gems" do
@@ -143,19 +143,6 @@
143143
bundle "install --local"
144144
expect(the_bundle).to include_gems("builtin_gem_2 1.0.2")
145145
end
146-
147-
it "errors if the builtin gem isn't available to cache" do
148-
bundle "config set path.system true"
149-
150-
install_gemfile <<-G
151-
source "#{file_uri_for(gem_repo1)}"
152-
gem 'json', '#{default_json_version}'
153-
G
154-
155-
bundle :cache, raise_on_error: false
156-
expect(exitstatus).to_not eq(0)
157-
expect(err).to include("json-#{default_json_version} is built in to Ruby, and can't be cached")
158-
end
159146
end
160147

161148
describe "when there are also git sources" do

bundler/spec/commands/open_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@
164164

165165
install_gemfile <<-G
166166
source "#{file_uri_for(gem_repo1)}"
167-
gem "json"
168167
G
169168
end
170169

bundler/spec/runtime/setup_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,10 @@ def lock_with(ruby_version = nil)
12811281

12821282
describe "with gemified standard libraries" do
12831283
it "does not load Digest", :ruby_repo do
1284+
build_repo2 do
1285+
build_gem "digest"
1286+
end
1287+
12841288
build_git "bar", gemspec: false do |s|
12851289
s.write "lib/bar/version.rb", %(BAR_VERSION = '1.0')
12861290
s.write "bar.gemspec", <<-G
@@ -1299,7 +1303,7 @@ def lock_with(ruby_version = nil)
12991303
end
13001304

13011305
gemfile <<-G
1302-
source "#{file_uri_for(gem_repo1)}"
1306+
source "#{file_uri_for(gem_repo2)}"
13031307
gem "bar", :git => "#{lib_path("bar-1.0")}"
13041308
G
13051309

0 commit comments

Comments
 (0)