Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Prefer require_relative for internal requires
Browse files Browse the repository at this point in the history
Due to the way rubygems monkey-patched require interacts with default
gems, and given that bundler is a default gem, and that bundler
manipulates the LOAD_PATH in very intricated ways, we can reduce the
risk of "leaking" to a different copy of `bundler` by using
`require_relative` for internal requires.
  • Loading branch information
deivid-rodriguez committed Apr 5, 2019
1 parent 5947131 commit 4775aea
Show file tree
Hide file tree
Showing 49 changed files with 115 additions and 115 deletions.
22 changes: 11 additions & 11 deletions lib/bundler.rb
@@ -1,20 +1,20 @@
# frozen_string_literal: true

require "bundler/compatibility_guard"
require_relative "bundler/compatibility_guard"

require "bundler/vendored_fileutils"
require_relative "bundler/vendored_fileutils"
require "pathname"
require "rbconfig"

require "bundler/errors"
require "bundler/environment_preserver"
require "bundler/plugin"
require "bundler/rubygems_ext"
require "bundler/rubygems_integration"
require "bundler/version"
require "bundler/constants"
require "bundler/current_ruby"
require "bundler/build_metadata"
require_relative "bundler/errors"
require_relative "bundler/environment_preserver"
require_relative "bundler/plugin"
require_relative "bundler/rubygems_ext"
require_relative "bundler/rubygems_integration"
require_relative "bundler/version"
require_relative "bundler/constants"
require_relative "bundler/current_ruby"
require_relative "bundler/build_metadata"

module Bundler
environment_preserver = EnvironmentPreserver.new(ENV, EnvironmentPreserver::BUNDLER_KEYS)
Expand Down
4 changes: 2 additions & 2 deletions lib/bundler/capistrano.rb
@@ -1,14 +1,14 @@
# frozen_string_literal: true

require "bundler/shared_helpers"
require_relative "shared_helpers"
Bundler::SharedHelpers.major_deprecation 2,
"The Bundler task for Capistrano. Please use http://github.com/capistrano/bundler"

# Capistrano task for Bundler.
#
# Add "require 'bundler/capistrano'" in your Capistrano deploy.rb, and
# Bundler will be activated after each new deployment.
require "bundler/deployment"
require_relative "deployment"
require "capistrano/version"

if defined?(Capistrano::Version) && Gem::Version.new(Capistrano::Version).release >= Gem::Version.new("3.0")
Expand Down
58 changes: 29 additions & 29 deletions lib/bundler/cli.rb
@@ -1,10 +1,10 @@
# frozen_string_literal: true

require "bundler/vendored_thor"
require_relative "vendored_thor"

module Bundler
class CLI < Thor
require "bundler/cli/common"
require_relative "cli/common"

package_name "Bundler"

Expand Down Expand Up @@ -138,7 +138,7 @@ def self.handle_no_command_error(command, has_namespace = $thor_runner)
D
method_option "gemspec", :type => :string, :banner => "Use the specified .gemspec to create the Gemfile"
def init
require "bundler/cli/init"
require_relative "cli/init"
Init.new(options.dup).run
end

Expand All @@ -156,7 +156,7 @@ def init
"Specify a different path than the system default ($BUNDLE_PATH or $GEM_HOME).#{" Bundler will remember this value for future installs on this machine" unless Bundler.feature_flag.forget_cli_options?}"
map "c" => "check"
def check
require "bundler/cli/check"
require_relative "cli/check"
Check.new(options).run
end

Expand All @@ -167,7 +167,7 @@ def check
method_option "install", :type => :boolean, :banner =>
"Runs 'bundle install' after removing the gems from the Gemfile"
def remove(*gems)
require "bundler/cli/remove"
require_relative "cli/remove"
Remove.new(gems, options).run
end

Expand Down Expand Up @@ -229,7 +229,7 @@ def install
remembered_flag_deprecation(option)
end

require "bundler/cli/install"
require_relative "cli/install"
Bundler.settings.temporary(:no_install => false) do
Install.new(options.dup).run
end
Expand Down Expand Up @@ -275,7 +275,7 @@ def install
"Update everything."
def update(*gems)
SharedHelpers.major_deprecation(2, "The `--force` option has been renamed to `--redownload`") if ARGV.include?("--force")
require "bundler/cli/update"
require_relative "cli/update"
Bundler.settings.temporary(:no_install => false) do
Update.new(options, gems).run
end
Expand Down Expand Up @@ -311,7 +311,7 @@ def show(gem_name = nil)
Bundler::SharedHelpers.major_deprecation(2, "use `bundle #{new_argv}` instead of `bundle #{old_argv}`")
end
end
require "bundler/cli/show"
require_relative "cli/show"
Show.new(options, gem_name).run
end
end
Expand All @@ -322,7 +322,7 @@ def show(gem_name = nil)
method_option "without-group", :type => :string, :banner => "print all gems except from a group"
method_option "paths", :type => :boolean, :banner => "print the path to each gem in the bundle"
def list
require "bundler/cli/list"
require_relative "cli/list"
List.new(options).run
end

Expand All @@ -331,7 +331,7 @@ def list
desc "info GEM [OPTIONS]", "Show information for the given gem"
method_option "path", :type => :boolean, :banner => "Print full path to gem"
def info(gem_name)
require "bundler/cli/info"
require_relative "cli/info"
Info.new(options, gem_name).run
end

Expand All @@ -352,7 +352,7 @@ def info(gem_name)
method_option "all", :type => :boolean, :banner =>
"Install binstubs for all gems"
def binstubs(*gems)
require "bundler/cli/binstubs"
require_relative "cli/binstubs"
Binstubs.new(options, gems).run
end

Expand All @@ -368,7 +368,7 @@ def binstubs(*gems)
method_option "optimistic", :type => :boolean, :banner => "Adds optimistic declaration of version to gem"
method_option "strict", :type => :boolean, :banner => "Adds strict declaration of version to gem"
def add(*gems)
require "bundler/cli/add"
require_relative "cli/add"
Add.new(options.dup, gems).run
end

Expand Down Expand Up @@ -404,7 +404,7 @@ def add(*gems)
method_option "only-explicit", :type => :boolean, :banner =>
"Only list gems specified in your Gemfile, not their dependencies"
def outdated(*gems)
require "bundler/cli/outdated"
require_relative "cli/outdated"
Outdated.new(options, gems).run
end

Expand All @@ -419,7 +419,7 @@ def outdated(*gems)
method_option "all-platforms", :type => :boolean, :banner => "Include gems for all platforms present in the lockfile, not only the current one"
method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache."
def cache
require "bundler/cli/cache"
require_relative "cli/cache"
Cache.new(options).run
end
end
Expand Down Expand Up @@ -447,7 +447,7 @@ def cache
bundle without having to download any additional gems.
D
def package
require "bundler/cli/package"
require_relative "cli/package"
Package.new(options).run
end
map %w[pack] => :package
Expand All @@ -462,7 +462,7 @@ def package
D
map "e" => "exec"
def exec(*args)
require "bundler/cli/exec"
require_relative "cli/exec"
Exec.new(options, args).run
end

Expand All @@ -478,19 +478,19 @@ def exec(*args)
will show the current value, as well as any superceded values and
where they were specified.
D
require "bundler/cli/config"
require_relative "cli/config"
subcommand "config", Config

desc "open GEM", "Opens the source directory of the given bundled gem"
def open(name)
require "bundler/cli/open"
require_relative "cli/open"
Open.new(options, name).run
end

unless Bundler.feature_flag.bundler_3_mode?
desc "console [GROUP]", "Opens an IRB session with the bundle pre-loaded"
def console(group = nil)
require "bundler/cli/console"
require_relative "cli/console"
Console.new(options, group).run
end
end
Expand Down Expand Up @@ -538,7 +538,7 @@ def licenses
method_option :without, :type => :array, :default => [], :aliases => "-W", :banner => "GROUP[ GROUP...]", :desc => "Exclude gems that are part of the specified named group."
def viz
SharedHelpers.major_deprecation 2, "The `viz` command has been moved to the `bundle-viz` gem, see https://github.com/bundler/bundler-viz"
require "bundler/cli/viz"
require_relative "cli/viz"
Viz.new(options.dup).run
end
end
Expand All @@ -562,7 +562,7 @@ def gem(name)
def gem_command.run(instance, args = [])
arity = 1 # name

require "bundler/cli/gem"
require_relative "cli/gem"
cmd_args = args + [instance]
cmd_args.unshift(instance.options)

Expand Down Expand Up @@ -590,15 +590,15 @@ def self.source_root
method_option "force", :type => :boolean, :default => false, :banner =>
"Forces clean even if --path is not set"
def clean
require "bundler/cli/clean"
require_relative "cli/clean"
Clean.new(options.dup).run
end

desc "platform [OPTIONS]", "Displays platform compatibility information"
method_option "ruby", :type => :boolean, :default => false, :banner =>
"only display ruby related platform information"
def platform
require "bundler/cli/platform"
require_relative "cli/platform"
Platform.new(options).run
end

Expand All @@ -609,7 +609,7 @@ def platform
"Install gem into a bundler group"
def inject(name, version)
SharedHelpers.major_deprecation 2, "The `inject` command has been replaced by the `add` command"
require "bundler/cli/inject"
require_relative "cli/inject"
Inject.new(options.dup, name, version).run
end

Expand Down Expand Up @@ -641,7 +641,7 @@ def inject(name, version)
method_option "conservative", :type => :boolean, :banner =>
"If updating, use bundle install conservative update behavior and do not allow shared dependencies to be updated"
def lock
require "bundler/cli/lock"
require_relative "cli/lock"
Lock.new(options).run
end

Expand All @@ -661,13 +661,13 @@ def env
method_option "quiet", :type => :boolean, :banner =>
"Only output warnings and errors."
def doctor
require "bundler/cli/doctor"
require_relative "cli/doctor"
Doctor.new(options).run
end

desc "issue", "Learn how to report an issue in Bundler"
def issue
require "bundler/cli/issue"
require_relative "cli/issue"
Issue.new.run
end

Expand All @@ -678,12 +678,12 @@ def issue
checkout --force`.
D
def pristine(*gems)
require "bundler/cli/pristine"
require_relative "cli/pristine"
Pristine.new(gems).run
end

if Bundler.feature_flag.plugins?
require "bundler/cli/plugin"
require_relative "cli/plugin"
desc "plugin", "Manage the bundler plugins"
subcommand "plugin", Plugin
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/common.rb
Expand Up @@ -59,7 +59,7 @@ def self.ask_for_spec_from(specs)
end

def self.gem_not_found_message(missing_gem_name, alternatives)
require "bundler/similarity_detector"
require_relative "../similarity_detector"
message = "Could not find gem '#{missing_gem_name}'."
alternate_names = alternatives.map {|a| a.respond_to?(:name) ? a.name : a }
suggestions = SimilarityDetector.new(alternate_names).similar_word_list(missing_gem_name)
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/doctor.rb
Expand Up @@ -56,7 +56,7 @@ def bundles_for_gem(spec)
end

def check!
require "bundler/cli/check"
require_relative "check"
Bundler::CLI::Check.new({}).run
end

Expand Down
4 changes: 2 additions & 2 deletions lib/bundler/cli/exec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "bundler/current_ruby"
require_relative "../current_ruby"

module Bundler
class CLI::Exec
Expand Down Expand Up @@ -69,7 +69,7 @@ def kernel_load(file, *args)
Process.setproctitle(process_title(file, args)) if Process.respond_to?(:setproctitle)
ui = Bundler.ui
Bundler.ui = nil
require "bundler/setup"
require_relative "../setup"
TRAPPED_SIGNALS.each {|s| trap(s, "DEFAULT") }
Kernel.load(file)
rescue SystemExit, SignalException
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/install.rb
Expand Up @@ -80,7 +80,7 @@ def run
warn_ambiguous_gems

if CLI::Common.clean_after_install?
require "bundler/cli/clean"
require_relative "clean"
Bundler::CLI::Clean.new(options).run
end
rescue GemNotFound, VersionConflict => e
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/issue.rb
Expand Up @@ -33,7 +33,7 @@ def run
end

def doctor
require "bundler/cli/doctor"
require_relative "doctor"
Bundler::CLI::Doctor.new({}).run
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/package.rb
Expand Up @@ -25,7 +25,7 @@ def run
private

def install
require "bundler/cli/install"
require_relative "install"
options = self.options.dup
if Bundler.settings[:cache_all_platforms]
options["local"] = false
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/plugin.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "bundler/vendored_thor"
require_relative "../vendored_thor"
module Bundler
class CLI::Plugin < Thor
desc "install PLUGINS", "Install the plugin from the source"
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/update.rb
Expand Up @@ -62,7 +62,7 @@ def run
Bundler.load.cache if Bundler.app_cache.exist?

if CLI::Common.clean_after_install?
require "bundler/cli/clean"
require_relative "clean"
Bundler::CLI::Clean.new(options).run
end

Expand Down
4 changes: 2 additions & 2 deletions lib/bundler/compact_index_client.rb
Expand Up @@ -13,8 +13,8 @@ def self.debug

class Error < StandardError; end

require "bundler/compact_index_client/cache"
require "bundler/compact_index_client/updater"
require_relative "compact_index_client/cache"
require_relative "compact_index_client/updater"

attr_reader :directory

Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/compact_index_client/updater.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "bundler/vendored_fileutils"
require_relative "../vendored_fileutils"
require "stringio"
require "zlib"

Expand Down

0 comments on commit 4775aea

Please sign in to comment.