Skip to content

Commit 02f0d40

Browse files
Merge pull request #5111 from rubygems/dont_clean_load_path
Don't cleanup paths from gems already activated from `$LOAD_PATH` (cherry picked from commit 6d0b1cc)
1 parent c809244 commit 02f0d40

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

bundler/lib/bundler/shared_helpers.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,11 @@ def bundler_ruby_lib
320320
end
321321

322322
def clean_load_path
323-
bundler_lib = bundler_ruby_lib
324-
325323
loaded_gem_paths = Bundler.rubygems.loaded_gem_paths
326324

327325
$LOAD_PATH.reject! do |p|
328-
next if resolve_path(p).start_with?(bundler_lib)
326+
resolved_path = resolve_path(p)
327+
next if $LOADED_FEATURES.any? {|lf| lf.start_with?(resolved_path) }
329328
loaded_gem_paths.delete(p)
330329
end
331330
$LOAD_PATH.uniq!

bundler/spec/runtime/setup_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,5 +1511,28 @@ def lock_with(ruby_version = nil)
15111511

15121512
expect(out).to include("rack, yard")
15131513
end
1514+
1515+
it "does not cause double loads when higher versions of default gems are activated before bundler" do
1516+
build_repo2 do
1517+
build_gem "json", "999.999.999" do |s|
1518+
s.write "lib/json.rb", <<~RUBY
1519+
module JSON
1520+
VERSION = "999.999.999"
1521+
end
1522+
RUBY
1523+
end
1524+
end
1525+
1526+
system_gems "json-999.999.999", :gem_repo => gem_repo2
1527+
1528+
install_gemfile "source \"#{file_uri_for(gem_repo1)}\""
1529+
ruby <<-RUBY
1530+
require "json"
1531+
require "bundler/setup"
1532+
require "json"
1533+
RUBY
1534+
1535+
expect(err).to be_empty
1536+
end
15141537
end
15151538
end

0 commit comments

Comments
 (0)