From e107f3f4cb2e11ef6fd46db21392a22fdab4eb2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 4 Apr 2019 17:01:11 +0200 Subject: [PATCH 1/7] Remove unnecessary require --- lib/bundler/cli.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 4e3735847e4..a9c83e982fa 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require "bundler" require "bundler/vendored_thor" module Bundler From cf9a2883fea3c28c8d869c72b1b407162a28e0b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 4 Apr 2019 17:01:19 +0200 Subject: [PATCH 2/7] Prefer `require_relative` for internal requires 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. --- lib/bundler.rb | 22 ++++---- lib/bundler/capistrano.rb | 4 +- lib/bundler/cli.rb | 58 ++++++++++----------- lib/bundler/cli/common.rb | 2 +- lib/bundler/cli/doctor.rb | 2 +- lib/bundler/cli/exec.rb | 4 +- lib/bundler/cli/install.rb | 2 +- lib/bundler/cli/issue.rb | 2 +- lib/bundler/cli/package.rb | 2 +- lib/bundler/cli/plugin.rb | 2 +- lib/bundler/cli/update.rb | 2 +- lib/bundler/compact_index_client.rb | 4 +- lib/bundler/compact_index_client/updater.rb | 2 +- lib/bundler/compatibility_guard.rb | 2 +- lib/bundler/definition.rb | 4 +- lib/bundler/dependency.rb | 4 +- lib/bundler/deployment.rb | 2 +- lib/bundler/dsl.rb | 4 +- lib/bundler/env.rb | 4 +- lib/bundler/fetcher.rb | 2 +- lib/bundler/fetcher/compact_index.rb | 4 +- lib/bundler/fetcher/dependency.rb | 2 +- lib/bundler/fetcher/index.rb | 2 +- lib/bundler/friendly_errors.rb | 2 +- lib/bundler/gem_helper.rb | 4 +- lib/bundler/gem_tasks.rb | 2 +- lib/bundler/inline.rb | 4 +- lib/bundler/installer.rb | 8 +-- lib/bundler/installer/parallel_installer.rb | 4 +- lib/bundler/lazy_specification.rb | 2 +- lib/bundler/match_platform.rb | 2 +- lib/bundler/plugin.rb | 2 +- lib/bundler/plugin/index.rb | 4 +- lib/bundler/psyched_yaml.rb | 2 +- lib/bundler/resolver.rb | 4 +- lib/bundler/rubygems_ext.rb | 2 +- lib/bundler/rubygems_integration.rb | 6 +-- lib/bundler/settings.rb | 4 +- lib/bundler/setup.rb | 2 +- lib/bundler/shared_helpers.rb | 16 +++--- lib/bundler/source/git.rb | 2 +- lib/bundler/stub_specification.rb | 2 +- lib/bundler/ui/rg_proxy.rb | 2 +- lib/bundler/ui/shell.rb | 2 +- lib/bundler/vendored_fileutils.rb | 2 +- lib/bundler/vendored_molinillo.rb | 2 +- lib/bundler/vendored_persistent.rb | 2 +- lib/bundler/vendored_thor.rb | 2 +- lib/bundler/vlad.rb | 4 +- 49 files changed, 114 insertions(+), 114 deletions(-) diff --git a/lib/bundler.rb b/lib/bundler.rb index f792a3bc985..0c24a21d7a5 100644 --- a/lib/bundler.rb +++ b/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) diff --git a/lib/bundler/capistrano.rb b/lib/bundler/capistrano.rb index 1b7145b72be..573df950439 100644 --- a/lib/bundler/capistrano.rb +++ b/lib/bundler/capistrano.rb @@ -1,6 +1,6 @@ # 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" @@ -8,7 +8,7 @@ # # 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") diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index a9c83e982fa..5d5363aee8e 100644 --- a/lib/bundler/cli.rb +++ b/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" @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) @@ -590,7 +590,7 @@ 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 @@ -598,7 +598,7 @@ def clean 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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb index 9ea52baa6b2..5ec541f722c 100644 --- a/lib/bundler/cli/common.rb +++ b/lib/bundler/cli/common.rb @@ -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) diff --git a/lib/bundler/cli/doctor.rb b/lib/bundler/cli/doctor.rb index 6d038937c06..1b3913a3006 100644 --- a/lib/bundler/cli/doctor.rb +++ b/lib/bundler/cli/doctor.rb @@ -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 diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index c29d6323070..6fdd55d1069 100644 --- a/lib/bundler/cli/exec.rb +++ b/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 @@ -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 diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index 03edc7fbd24..cf0c71d7664 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -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 diff --git a/lib/bundler/cli/issue.rb b/lib/bundler/cli/issue.rb index bba1619340a..054ce763152 100644 --- a/lib/bundler/cli/issue.rb +++ b/lib/bundler/cli/issue.rb @@ -33,7 +33,7 @@ def run end def doctor - require "bundler/cli/doctor" + require_relative "doctor" Bundler::CLI::Doctor.new({}).run end end diff --git a/lib/bundler/cli/package.rb b/lib/bundler/cli/package.rb index cd01ce422e8..120a3fdcf35 100644 --- a/lib/bundler/cli/package.rb +++ b/lib/bundler/cli/package.rb @@ -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 diff --git a/lib/bundler/cli/plugin.rb b/lib/bundler/cli/plugin.rb index b5dd5b6d4b3..1155c4ec9bb 100644 --- a/lib/bundler/cli/plugin.rb +++ b/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" diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb index b088853768f..13d71bb50ec 100644 --- a/lib/bundler/cli/update.rb +++ b/lib/bundler/cli/update.rb @@ -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 diff --git a/lib/bundler/compact_index_client.rb b/lib/bundler/compact_index_client.rb index 2f713041c86..a5120dbba4d 100644 --- a/lib/bundler/compact_index_client.rb +++ b/lib/bundler/compact_index_client.rb @@ -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 diff --git a/lib/bundler/compact_index_client/updater.rb b/lib/bundler/compact_index_client/updater.rb index d77285072cb..40232019bca 100644 --- a/lib/bundler/compact_index_client/updater.rb +++ b/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" diff --git a/lib/bundler/compatibility_guard.rb b/lib/bundler/compatibility_guard.rb index 958116ce553..eaff1a10d40 100644 --- a/lib/bundler/compatibility_guard.rb +++ b/lib/bundler/compatibility_guard.rb @@ -1,6 +1,6 @@ # frozen_string_literal: false -require "bundler/version" +require_relative "version" if Bundler::VERSION.split(".").first.to_i >= 2 if Gem::Version.new(Object::RUBY_VERSION.dup) < Gem::Version.new("2.3") diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index f9daae067cc..506b0620d24 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/lockfile_parser" +require_relative "lockfile_parser" require "set" module Bundler @@ -385,7 +385,7 @@ def locked_ruby_version_object end def to_lock - require "bundler/lockfile_generator" + require_relative "lockfile_generator" LockfileGenerator.generate(self) end diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb index 8840ad6a9ca..e76c2bc08ef 100644 --- a/lib/bundler/dependency.rb +++ b/lib/bundler/dependency.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true require "rubygems/dependency" -require "bundler/shared_helpers" -require "bundler/rubygems_ext" +require_relative "shared_helpers" +require_relative "rubygems_ext" module Bundler class Dependency < Gem::Dependency diff --git a/lib/bundler/deployment.rb b/lib/bundler/deployment.rb index 291e158ca01..b432ae6ae1a 100644 --- a/lib/bundler/deployment.rb +++ b/lib/bundler/deployment.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/shared_helpers" +require_relative "shared_helpers" Bundler::SharedHelpers.major_deprecation 2, "Bundler no longer integrates with " \ "Capistrano, but Capistrano provides its own integration with " \ "Bundler via the capistrano-bundler gem. Use it instead." diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 7424a5c8a46..d3ead2a1ffe 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require "bundler/dependency" -require "bundler/ruby_dsl" +require_relative "dependency" +require_relative "ruby_dsl" module Bundler class Dsl diff --git a/lib/bundler/env.rb b/lib/bundler/env.rb index 9cd9b8baca3..8be4746e595 100644 --- a/lib/bundler/env.rb +++ b/lib/bundler/env.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require "bundler/rubygems_integration" -require "bundler/source/git/git_proxy" +require_relative "rubygems_integration" +require_relative "source/git/git_proxy" module Bundler class Env diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb index 8397f7b72b0..7ec41d62c02 100644 --- a/lib/bundler/fetcher.rb +++ b/lib/bundler/fetcher.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/vendored_persistent" +require_relative "vendored_persistent" require "cgi" require "securerandom" require "zlib" diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb index a117af72fa4..1efd3e03af9 100644 --- a/lib/bundler/fetcher/compact_index.rb +++ b/lib/bundler/fetcher/compact_index.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require "bundler/fetcher/base" -require "bundler/worker" +require_relative "base" +require_relative "../worker" module Bundler autoload :CompactIndexClient, "bundler/compact_index_client" diff --git a/lib/bundler/fetcher/dependency.rb b/lib/bundler/fetcher/dependency.rb index 1430d1ebeb9..c52c32fb5b5 100644 --- a/lib/bundler/fetcher/dependency.rb +++ b/lib/bundler/fetcher/dependency.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/fetcher/base" +require_relative "base" require "cgi" module Bundler diff --git a/lib/bundler/fetcher/index.rb b/lib/bundler/fetcher/index.rb index 1a8064624d8..e7baf638737 100644 --- a/lib/bundler/fetcher/index.rb +++ b/lib/bundler/fetcher/index.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/fetcher/base" +require_relative "base" require "rubygems/remote_fetcher" module Bundler diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb index dd9b847f100..45faf02020a 100644 --- a/lib/bundler/friendly_errors.rb +++ b/lib/bundler/friendly_errors.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "cgi" -require "bundler/vendored_thor" +require_relative "vendored_thor" module Bundler module FriendlyErrors diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index e9ee03b8a2b..33f1d515922 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require "bundler/vendored_thor" unless defined?(Thor) -require "bundler" +require_relative "vendored_thor" unless defined?(Thor) +require_relative "../bundler" require "shellwords" module Bundler diff --git a/lib/bundler/gem_tasks.rb b/lib/bundler/gem_tasks.rb index f736517bd76..bc725d36029 100644 --- a/lib/bundler/gem_tasks.rb +++ b/lib/bundler/gem_tasks.rb @@ -3,5 +3,5 @@ require "rake/clean" CLOBBER.include "pkg" -require "bundler/gem_helper" +require_relative "gem_helper" Bundler::GemHelper.install_tasks diff --git a/lib/bundler/inline.rb b/lib/bundler/inline.rb index 93355c94602..034838b4b43 100644 --- a/lib/bundler/inline.rb +++ b/lib/bundler/inline.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/compatibility_guard" +require_relative "compatibility_guard" # Allows for declaring a Gemfile inline in a ruby script, optionally installing # any gems that aren't already installed on the user's system. @@ -32,7 +32,7 @@ # puts Pod::VERSION # => "0.34.4" # def gemfile(install = false, options = {}, &gemfile) - require "bundler" + require_relative "../bundler" opts = options.dup ui = opts.delete(:ui) { Bundler::UI::Shell.new } diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 49143b38f9f..5bc53a8b618 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -2,10 +2,10 @@ require "erb" require "rubygems/dependency_installer" -require "bundler/worker" -require "bundler/installer/parallel_installer" -require "bundler/installer/standalone" -require "bundler/installer/gem_installer" +require_relative "worker" +require_relative "installer/parallel_installer" +require_relative "installer/standalone" +require_relative "installer/gem_installer" module Bundler class Installer diff --git a/lib/bundler/installer/parallel_installer.rb b/lib/bundler/installer/parallel_installer.rb index 469b15b96cc..391540af0b4 100644 --- a/lib/bundler/installer/parallel_installer.rb +++ b/lib/bundler/installer/parallel_installer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require "bundler/worker" -require "bundler/installer/gem_installer" +require_relative "../worker" +require_relative "gem_installer" module Bundler class ParallelInstaller diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index 69a721c120d..cbd04b2c90c 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "uri" -require "bundler/match_platform" +require_relative "match_platform" module Bundler class LazySpecification diff --git a/lib/bundler/match_platform.rb b/lib/bundler/match_platform.rb index 56cbbfb95dc..69074925a61 100644 --- a/lib/bundler/match_platform.rb +++ b/lib/bundler/match_platform.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/gem_helpers" +require_relative "gem_helpers" module Bundler module MatchPlatform diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index 996d29aafb7..02985fa9b08 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/plugin/api" +require_relative "plugin/api" module Bundler module Plugin diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb index faabf3a8d1b..2d70a046bb6 100644 --- a/lib/bundler/plugin/index.rb +++ b/lib/bundler/plugin/index.rb @@ -139,7 +139,7 @@ def load_index(index_file, global = false) data = index_f.read - require "bundler/yaml_serializer" + require_relative "../yaml_serializer" index = YAMLSerializer.load(data) @commands.merge!(index["commands"]) @@ -162,7 +162,7 @@ def save_index "sources" => @sources, } - require "bundler/yaml_serializer" + require_relative "../yaml_serializer" SharedHelpers.filesystem_access(index_file) do |index_f| FileUtils.mkdir_p(index_f.dirname) File.open(index_f, "w") {|f| f.puts YAMLSerializer.dump(index) } diff --git a/lib/bundler/psyched_yaml.rb b/lib/bundler/psyched_yaml.rb index e654416a5a2..c086b7651ce 100644 --- a/lib/bundler/psyched_yaml.rb +++ b/lib/bundler/psyched_yaml.rb @@ -27,7 +27,7 @@ module Bundler end end -require "bundler/deprecate" +require_relative "deprecate" begin Bundler::Deprecate.skip_during do require "rubygems/safe_yaml" diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index 90f833bef1b..d3e5f268cfa 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -2,8 +2,8 @@ module Bundler class Resolver - require "bundler/vendored_molinillo" - require "bundler/resolver/spec_group" + require_relative "vendored_molinillo" + require_relative "resolver/spec_group" # Figures out the best possible configuration of gems that satisfies # the list of passed dependencies and any child dependencies without diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index beed6372a39..df8646a2bba 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -8,7 +8,7 @@ # shouldn't be deferred. require "rubygems/source" -require "bundler/match_platform" +require_relative "match_platform" module Gem class Specification diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index ca7dd32611c..6d93ed6fa17 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -111,7 +111,7 @@ def platforms end def configuration - require "bundler/psyched_yaml" + require_relative "psyched_yaml" Gem.configuration rescue Gem::SystemExitException, LoadError => e Bundler.ui.error "#{e.class}: #{e.message}" @@ -261,7 +261,7 @@ def with_build_args(args) def spec_from_gem(path, policy = nil) require "rubygems/security" - require "bundler/psyched_yaml" + require_relative "psyched_yaml" gem_from_path(path, security_policies[policy]).spec rescue Gem::Package::FormatError raise GemspecError, "Could not read gem at #{path}. It may be corrupted." @@ -686,7 +686,7 @@ def default_stubs def use_gemdeps(gemfile) ENV["BUNDLE_GEMFILE"] ||= File.expand_path(gemfile) - require "bundler/gemdeps" + require_relative "gemdeps" runtime = Bundler.setup Bundler.ui = nil activated_spec_names = runtime.requested_specs.map(&:to_spec).sort_by(&:name) diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index d21789dba1d..2d0c4174aea 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -357,7 +357,7 @@ def set_key(raw_key, value, hash, file) return unless file SharedHelpers.filesystem_access(file) do |p| FileUtils.mkdir_p(p.dirname) - require "bundler/yaml_serializer" + require_relative "yaml_serializer" p.open("w") {|f| f.write(YAMLSerializer.dump(hash)) } end end @@ -397,7 +397,7 @@ def load_config(config_file) SharedHelpers.filesystem_access(config_file, :read) do |file| valid_file = file.exist? && !file.size.zero? return {} unless valid_file - require "bundler/yaml_serializer" + require_relative "yaml_serializer" YAMLSerializer.load file.read end end diff --git a/lib/bundler/setup.rb b/lib/bundler/setup.rb index 52a5b8889af..e42f2d2522a 100644 --- a/lib/bundler/setup.rb +++ b/lib/bundler/setup.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/shared_helpers" +require_relative "shared_helpers" if Bundler::SharedHelpers.in_bundle? require "bundler" diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 1b703c5cbc9..c7b10243092 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -require "bundler/compatibility_guard" +require_relative "compatibility_guard" require "pathname" require "rbconfig" require "rubygems" -require "bundler/version" -require "bundler/constants" -require "bundler/rubygems_integration" -require "bundler/current_ruby" +require_relative "version" +require_relative "constants" +require_relative "rubygems_integration" +require_relative "current_ruby" module Bundler module SharedHelpers @@ -132,7 +132,7 @@ def const_get_safely(constant_name, namespace) def major_deprecation(major_version, message) bundler_major_version = Bundler.bundler_major_version if bundler_major_version > major_version - require "bundler/errors" + require_relative "errors" raise DeprecatedError, "[REMOVED] #{message}" end @@ -351,9 +351,9 @@ def resolve_path(path) end def prints_major_deprecations? - require "bundler" + require_relative "../bundler" return false if Bundler.settings[:silence_deprecations] - require "bundler/deprecate" + require_relative "deprecate" return false if Bundler::Deprecate.skip true end diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index a8afb341d8f..aa24a87ed78 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/vendored_fileutils" +require_relative "../vendored_fileutils" require "uri" module Bundler diff --git a/lib/bundler/stub_specification.rb b/lib/bundler/stub_specification.rb index bef94b505e4..64b6d1b7246 100644 --- a/lib/bundler/stub_specification.rb +++ b/lib/bundler/stub_specification.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/remote_specification" +require_relative "remote_specification" module Bundler class StubSpecification < RemoteSpecification diff --git a/lib/bundler/ui/rg_proxy.rb b/lib/bundler/ui/rg_proxy.rb index e2f98481db3..ef6def225b0 100644 --- a/lib/bundler/ui/rg_proxy.rb +++ b/lib/bundler/ui/rg_proxy.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/ui" +require_relative "../ui" require "rubygems/user_interaction" module Bundler diff --git a/lib/bundler/ui/shell.rb b/lib/bundler/ui/shell.rb index 7136fdfbf94..8e49fa58854 100644 --- a/lib/bundler/ui/shell.rb +++ b/lib/bundler/ui/shell.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/vendored_thor" +require_relative "../vendored_thor" module Bundler module UI diff --git a/lib/bundler/vendored_fileutils.rb b/lib/bundler/vendored_fileutils.rb index d14e98baf72..4b71759224e 100644 --- a/lib/bundler/vendored_fileutils.rb +++ b/lib/bundler/vendored_fileutils.rb @@ -2,7 +2,7 @@ module Bundler; end if RUBY_VERSION >= "2.4" - require "bundler/vendor/fileutils/lib/fileutils" + require_relative "vendor/fileutils/lib/fileutils" else # the version we vendor is 2.4+ require "fileutils" diff --git a/lib/bundler/vendored_molinillo.rb b/lib/bundler/vendored_molinillo.rb index 061b634f728..d1976f5cb44 100644 --- a/lib/bundler/vendored_molinillo.rb +++ b/lib/bundler/vendored_molinillo.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true module Bundler; end -require "bundler/vendor/molinillo/lib/molinillo" +require_relative "vendor/molinillo/lib/molinillo" diff --git a/lib/bundler/vendored_persistent.rb b/lib/bundler/vendored_persistent.rb index de9c42fcc14..7670b83992e 100644 --- a/lib/bundler/vendored_persistent.rb +++ b/lib/bundler/vendored_persistent.rb @@ -15,7 +15,7 @@ module HTTP end end end -require "bundler/vendor/net-http-persistent/lib/net/http/persistent" +require_relative "vendor/net-http-persistent/lib/net/http/persistent" module Bundler class PersistentHTTP < Persistent::Net::HTTP::Persistent diff --git a/lib/bundler/vendored_thor.rb b/lib/bundler/vendored_thor.rb index 8cca090f551..b0b7e7be844 100644 --- a/lib/bundler/vendored_thor.rb +++ b/lib/bundler/vendored_thor.rb @@ -5,4 +5,4 @@ def self.require_thor_actions Kernel.send(:require, "bundler/vendor/thor/lib/thor/actions") end end -require "bundler/vendor/thor/lib/thor" +require_relative "vendor/thor/lib/thor" diff --git a/lib/bundler/vlad.rb b/lib/bundler/vlad.rb index 68181e7db83..538e8c3e749 100644 --- a/lib/bundler/vlad.rb +++ b/lib/bundler/vlad.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/shared_helpers" +require_relative "shared_helpers" Bundler::SharedHelpers.major_deprecation 2, "The Bundler task for Vlad" @@ -8,7 +8,7 @@ # # Add "require 'bundler/vlad'" in your Vlad deploy.rb, and # include the vlad:bundle:install task in your vlad:deploy task. -require "bundler/deployment" +require_relative "deployment" include Rake::DSL if defined? Rake::DSL From e742c3d5f458a4a59cf0eaab2567eca844f956d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 4 Apr 2019 17:05:12 +0200 Subject: [PATCH 3/7] Load executable relatively in the first place --- lib/bundler/shared_helpers.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index c7b10243092..14d09b72d58 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -289,18 +289,10 @@ def set_env(key, value) public :set_env def set_bundle_variables - begin - exe_file = Bundler.rubygems.bin_path("bundler", "bundle", VERSION) - unless File.exist?(exe_file) - exe_file = File.expand_path("../../../exe/bundle", __FILE__) - end - Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", exe_file - rescue Gem::GemNotFoundException - exe_file = File.expand_path("../../../exe/bundle", __FILE__) - # for Ruby core repository - exe_file = File.expand_path("../../../../bin/bundle", __FILE__) unless File.exist?(exe_file) - Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", exe_file - end + exe_file = File.expand_path("../../../exe/bundle", __FILE__) + # for Ruby core repository + exe_file = File.expand_path("../../../../bin/bundle", __FILE__) unless File.exist?(exe_file) + Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", exe_file # Set BUNDLE_GEMFILE Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", find_gemfile(:order_matters).to_s From c32c7fafd590697f6d06f6f7605686e31126b691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 4 Apr 2019 17:05:50 +0200 Subject: [PATCH 4/7] Remove dummy comment --- lib/bundler/shared_helpers.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 14d09b72d58..73c6dc30975 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -293,8 +293,6 @@ def set_bundle_variables # for Ruby core repository exe_file = File.expand_path("../../../../bin/bundle", __FILE__) unless File.exist?(exe_file) Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", exe_file - - # Set BUNDLE_GEMFILE Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", find_gemfile(:order_matters).to_s Bundler::SharedHelpers.set_env "BUNDLER_VERSION", Bundler::VERSION end From 3a82a69b74453c7daa5723026363d82b590f2f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 12 Apr 2019 20:40:12 +0200 Subject: [PATCH 5/7] One more --- lib/bundler/setup.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bundler/setup.rb b/lib/bundler/setup.rb index e42f2d2522a..d156f494a8b 100644 --- a/lib/bundler/setup.rb +++ b/lib/bundler/setup.rb @@ -3,7 +3,7 @@ require_relative "shared_helpers" if Bundler::SharedHelpers.in_bundle? - require "bundler" + require_relative "../bundler" if STDOUT.tty? || ENV["BUNDLER_FORCE_TTY"] Bundler.ui = Bundler::UI::Shell.new From c3b917c620652120dd3c23719d6941be1de4a211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 22 Apr 2019 10:24:44 +0200 Subject: [PATCH 6/7] Add missing require So that the spec can be run in isolation. --- spec/quality_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb index e303b691b0a..07bd05049a5 100644 --- a/spec/quality_spec.rb +++ b/spec/quality_spec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "set" + if defined?(Encoding) && Encoding.default_external.name != "UTF-8" # An approximation of ruby -E UTF-8, since it works on 1.8.7 Encoding.default_external = Encoding.find("UTF-8") From 0dff2a9a26ac5afcb76c65a2939f9f72ca613af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 22 Apr 2019 10:24:27 +0200 Subject: [PATCH 7/7] Add spec for using relative requires --- lib/bundler/rubygems_integration.rb | 2 +- spec/quality_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 6d93ed6fa17..32ddf185a00 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -637,7 +637,7 @@ def path_separator end def all_specs - require "bundler/remote_specification" + require_relative "remote_specification" Gem::Specification.stubs.map do |stub| StubSpecification.from_stub(stub) end diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb index 07bd05049a5..87279ebb743 100644 --- a/spec/quality_spec.rb +++ b/spec/quality_spec.rb @@ -275,4 +275,20 @@ def check_for_specific_pronouns(filename) expect(warnings).to be_well_formed end end + + it "does not use require internally, but require_relative" do + Dir.chdir(root) do + exempt = %r{templates/|vendor/} + all_bad_requires = [] + lib_files = ruby_core? ? `git ls-files -z -- lib/bundler lib/bundler.rb` : `git ls-files -z -- lib` + lib_files.split("\x0").each do |filename| + next if filename =~ exempt + File.readlines(filename).each_with_index do |line, number| + line.scan(/^ *require "bundler/).each { all_bad_requires << "#{filename}:#{number.succ}" } + end + end + + expect(all_bad_requires).to be_empty, "#{all_bad_requires.size} internal requires that should use `require_relative`: #{all_bad_requires}" + end + end end