Skip to content

Commit

Permalink
ignore errors installing gems due to a gem version not allowed on the…
Browse files Browse the repository at this point in the history
… current ruby version (#33)
  • Loading branch information
ccutrer authored Mar 29, 2024
1 parent fc8147a commit 334c4f8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/bundler/multilock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def write_lockfile(lockfile_definition,
Installer.install(gemfile.dirname, current_definition, {})
end
end
rescue RubyVersionMismatch, GemNotFound, SolveFailure
rescue RubyVersionMismatch, GemNotFound, SolveFailure, InstallError, ProductionError
# ignore
end
end
Expand Down
35 changes: 34 additions & 1 deletion spec/bundler/multilock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,39 @@
end
end

it "ignores installation errors when an alternate lockfile specifies a gem " \
"version incompatible with the current ruby" do
with_gemfile(<<~RUBY) do
gem "nokogiri"
lockfile do
end
lockfile "alt" do
end
RUBY
invoke_bundler("install")

incompatible_nokogiri_version = case RUBY_VERSION
when ("3.3"..)
"1.15.6"
when ("3.0"..)
skip "There isn't a recent nokogiri version incompatible " \
"with this version of ruby; just rely on this test " \
"running on other ruby versions"
else
"1.16.0"
end

replace_lockfile_pin("Gemfile.lock", "nokogiri", incompatible_nokogiri_version)
replace_lockfile_pin("Gemfile.alt.lock", "nokogiri", incompatible_nokogiri_version)

expect { invoke_bundler("check") }.to raise_error(/The following gems are missing/)

invoke_bundler("install")
end
end

private

def create_local_gem(name, content = "", subdirectory: true)
Expand Down Expand Up @@ -988,7 +1021,7 @@ def invoke_bundler(subcommand, env: {}, allow_failure: false)
# @param gem [String] The gem's name
# @param version [String] The new version to "pin" the gem to
def replace_lockfile_pin(lockfile, gem, version)
new_contents = File.read(lockfile).gsub(%r{#{gem} \([0-9.]+\)}, "#{gem} (#{version})")
new_contents = File.read(lockfile).gsub(%r{#{gem} \([0-9a-z.]+((?:-[a-z0-9_]+)*)\)}, "#{gem} (#{version}\\1)")

File.write(lockfile, new_contents)
end
Expand Down

0 comments on commit 334c4f8

Please sign in to comment.