Don't ignore pre-releases when there's only one candidate

This should be a very rare edge case, however, it does happen when using
a .dev version of Bundler because in that case, that's the only version
that the resolver considers, and it should not be ignored.

We could've special cased this specifically for Bundler, but I think it
does make sense for every gem.
This commit is contained in:
David Rodríguez 2023-03-03 13:34:08 +01:00 committed by Hiroshi SHIBATA
parent ddc4fd5644
commit 12f0be14e2
2 changed files with 26 additions and 1 deletions

View File

@ -299,7 +299,7 @@ module Bundler
end
def filter_prereleases(specs, package)
return specs unless package.ignores_prereleases?
return specs unless package.ignores_prereleases? && specs.size > 1
specs.reject {|s| s.version.prerelease? }
end

View File

@ -998,6 +998,31 @@ RSpec.describe "bundle lock" do
expect(lockfile).to include("autobuild (1.10.1)")
end
# Newer rails depends on Bundler, while ancient Rails does not. Bundler tries
# a first resolution pass that does not consider pre-releases. However, when
# using a pre-release Bundler (like the .dev version), that results in that
# pre-release being ignored and resolving to a version that does not depend on
# Bundler at all. We should avoid that and still consider .dev Bundler.
#
it "does not ignore prereleases with there's only one candidate" do
build_repo4 do
build_gem "rails", "7.4.0.2" do |s|
s.add_dependency "bundler", ">= 1.15.0"
end
build_gem "rails", "2.3.18"
end
gemfile <<~G
source "#{file_uri_for(gem_repo4)}"
gem "rails"
G
bundle "lock"
expect(lockfile).to_not include("rails (2.3.18)")
expect(lockfile).to include("rails (7.4.0.2)")
end
it "deals with platform specific incompatibilities" do
build_repo4 do
build_gem "activerecord", "6.0.6"