class Bundler::Patch::DefinitionPrep

Attributes

bundler_def[R]

Public Class Methods

new(bundler_def, gem_patches, options) click to toggle source
# File lib/bundler/patch/conservative_definition.rb, line 65
def initialize(bundler_def, gem_patches, options)
  @bundler_def = bundler_def
  @gems_to_update = GemsToPatch.new(gem_patches)
  @options = options
end

Public Instance Methods

fixup_empty_remotes() click to toggle source

This came out a real-life case with sidekiq and sidekiq-pro where the sidekiq-pro gem is served from their gem server and depends on the open-source sidekiq gem served from rubygems.org, and when patching those, without the appropriate remotes being set in rubygems_aggregrate, it won't work.

The underlying issue in Bundler 1.10 appears to be when the Definition constructor receives `true` as the `unlock` parameter, then @locked_sources is initialized to empty array, and the related rubygems_aggregrate source instance ends up with no @remotes set in it, which I think happens during converge_sources. Without those set, then the index will list no gem versions in some cases. (It was complicated enough to discover this patch, I haven't fully worked out the flaw, though I believe I recreated the problem with plain ol `bundle update`).

# File lib/bundler/patch/conservative_definition.rb, line 98
def fixup_empty_remotes
  STDERR.puts 'fixing empty remotes' if ENV['DEBUG_PATCH_RESOLVER']
  b_sources = @bundler_def.send(:sources)
  empty_remotes = b_sources.rubygems_sources.detect { |s| s.remotes.empty? }
  STDERR.puts "empty_remotes: <#{empty_remotes}>" if ENV['DEBUG_PATCH_RESOLVER']
  empty_remotes.remotes.push(*b_sources.rubygems_remotes) if empty_remotes
  empty_remotes = b_sources.rubygems_sources.detect { |s| s.remotes.empty? }
  STDERR.puts "empty_remotes after fixed: <#{empty_remotes}>" if ENV['DEBUG_PATCH_RESOLVER']
end
prep() click to toggle source
# File lib/bundler/patch/conservative_definition.rb, line 71
def prep
  @bundler_def ||= Bundler.definition(@gems_to_update.to_bundler_definition)
  @bundler_def.extend ConservativeDefinition

  # Starting with 1.17, this method has to be called externally, which isn't
  # ideal in my opinion since the Definition class depends on it.
  # https://github.com/bundler/bundler/commit/22f15209b87e0b0792c8a393549e1a10c963d59c
  @bundler_def.gem_version_promoter if @bundler_def.respond_to?(:gem_version_promoter)

  @bundler_def.gems_to_update = @gems_to_update
  @bundler_def.strict = @options[:strict]
  @bundler_def.minor_preferred = @options[:minor]
  @bundler_def.prefer_minimal = @options[:minimal]
  fixup_empty_remotes if @gems_to_update.to_bundler_definition === true
  @bundler_def
end