Skip to content

Commit

Permalink
[rubygems/rubygems] Require things right before they're needed
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez authored and matzbot committed May 13, 2024
1 parent 3c16d93 commit e926298
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/bundler/rubygems_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

require "rubygems" unless defined?(Gem)

require "rubygems/specification"

# We can't let `Gem::Source` be autoloaded in the `Gem::Specification#source`
# redefinition below, so we need to load it upfront. The reason is that if
# Bundler monkeypatches are loaded before RubyGems activates an executable (for
Expand All @@ -17,10 +15,6 @@
# `Gem::Source` from the redefined `Gem::Specification#source`.
require "rubygems/source"

require_relative "match_metadata"
require_relative "force_platform"
require_relative "match_platform"

# Cherry-pick fixes to `Gem.ruby_version` to be useful for modern Bundler
# versions and ignore patchlevels
# (https://github.com/rubygems/rubygems/pull/5472,
Expand All @@ -31,7 +25,12 @@
end

module Gem
require "rubygems/specification"

class Specification
require_relative "match_metadata"
require_relative "match_platform"

include ::Bundler::MatchMetadata
include ::Bundler::MatchPlatform

Expand Down Expand Up @@ -148,17 +147,23 @@ def dependencies_to_gemfile(dependencies, group = nil)

module BetterPermissionError
def data
require_relative "shared_helpers"

Bundler::SharedHelpers.filesystem_access(loaded_from, :read) do
super
end
end
end

require "rubygems/stub_specification"

class StubSpecification
prepend BetterPermissionError
end

class Dependency
require_relative "force_platform"

include ::Bundler::ForcePlatform

attr_accessor :source, :groups
Expand Down

0 comments on commit e926298

Please sign in to comment.