From 95728a8b4208bb9a3427cde95a4ceba76e349b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 18 Jul 2024 00:06:26 +0200 Subject: [PATCH] [rubygems/rubygems] Warn non flattened require paths in old RubyGems versions too https://github.com/rubygems/rubygems/commit/b3cdccc6fb --- lib/bundler/rubygems_ext.rb | 24 ++++++++++++++++++++++++ spec/bundler/realworld/edgecases_spec.rb | 13 +------------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 503959bba7..3d53368659 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -56,6 +56,9 @@ module Gem # Can be removed once RubyGems 3.5.14 support is dropped 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 require_relative "match_metadata" require_relative "match_platform" @@ -161,6 +164,27 @@ module Gem 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 def dependencies_to_gemfile(dependencies, group = nil) diff --git a/spec/bundler/realworld/edgecases_spec.rb b/spec/bundler/realworld/edgecases_spec.rb index 94ca3554b1..dc15c56c79 100644 --- a/spec/bundler/realworld/edgecases_spec.rb +++ b/spec/bundler/realworld/edgecases_spec.rb @@ -198,18 +198,7 @@ RSpec.describe "real world edgecases", realworld: true do expect(lockfile).to include(rubygems_version("paperclip", "~> 5.1.0")) end - it "outputs a helpful error message when gems have invalid gemspecs", rubygems: "< 3.3.16" 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 + it "outputs a helpful warning when gems have a gemspec with invalid `require_paths`" do install_gemfile <<-G, standalone: true, env: { "BUNDLE_FORCE_RUBY_PLATFORM" => "1" } source 'https://rubygems.org' gem "resque-scheduler", "2.2.0"