[rubygems/rubygems] Warn non flattened require paths in old RubyGems versions too

https://github.com/rubygems/rubygems/commit/b3cdccc6fb
This commit is contained in:
David Rodríguez 2024-07-18 00:06:26 +02:00 committed by git
parent f78a8761c4
commit 95728a8b42
2 changed files with 25 additions and 12 deletions

View File

@ -56,6 +56,9 @@ module Gem
# Can be removed once RubyGems 3.5.14 support is dropped # Can be removed once RubyGems 3.5.14 support is dropped
VALIDATES_FOR_RESOLUTION = Specification.new.respond_to?(:validate_for_resolution).freeze VALIDATES_FOR_RESOLUTION = Specification.new.respond_to?(:validate_for_resolution).freeze
# Can be removed once RubyGems 3.3.15 support is dropped
FLATTENS_REQUIRED_PATHS = Specification.new.respond_to?(:flatten_require_paths).freeze
class Specification class Specification
require_relative "match_metadata" require_relative "match_metadata"
require_relative "match_platform" require_relative "match_platform"
@ -161,6 +164,27 @@ module Gem
end end
end end
unless FLATTENS_REQUIRED_PATHS
def flatten_require_paths
return unless raw_require_paths.first.is_a?(Array)
warn "#{name} #{version} includes a gemspec with `require_paths` set to an array of arrays. Newer versions of this gem might've already fixed this"
raw_require_paths.flatten!
end
class << self
module RequirePathFlattener
def from_yaml(input)
spec = super(input)
spec.flatten_require_paths
spec
end
end
prepend RequirePathFlattener
end
end
private private
def dependencies_to_gemfile(dependencies, group = nil) def dependencies_to_gemfile(dependencies, group = nil)

View File

@ -198,18 +198,7 @@ RSpec.describe "real world edgecases", realworld: true do
expect(lockfile).to include(rubygems_version("paperclip", "~> 5.1.0")) expect(lockfile).to include(rubygems_version("paperclip", "~> 5.1.0"))
end end
it "outputs a helpful error message when gems have invalid gemspecs", rubygems: "< 3.3.16" do it "outputs a helpful warning when gems have a gemspec with invalid `require_paths`" do
install_gemfile <<-G, standalone: true, raise_on_error: false, env: { "BUNDLE_FORCE_RUBY_PLATFORM" => "1" }
source 'https://rubygems.org'
gem "resque-scheduler", "2.2.0"
gem "redis-namespace", "1.6.0" # for a consistent resolution including ruby 2.3.0
gem "ruby2_keywords", "0.0.5"
G
expect(err).to include("You have one or more invalid gemspecs that need to be fixed.")
expect(err).to include("resque-scheduler 2.2.0 has an invalid gemspec")
end
it "outputs a helpful warning when gems have a gemspec with invalid `require_paths`", rubygems: ">= 3.3.16" do
install_gemfile <<-G, standalone: true, env: { "BUNDLE_FORCE_RUBY_PLATFORM" => "1" } install_gemfile <<-G, standalone: true, env: { "BUNDLE_FORCE_RUBY_PLATFORM" => "1" }
source 'https://rubygems.org' source 'https://rubygems.org'
gem "resque-scheduler", "2.2.0" gem "resque-scheduler", "2.2.0"