diff options
author | Hiroshi SHIBATA <[email protected]> | 2019-06-01 12:49:40 +0300 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2019-06-09 12:44:10 +0900 |
commit | 8f37629519ad330032a38ac0e871b2912ed38a1b (patch) | |
tree | bb0529b77583d47993d8b0d608d68896aa3a5298 /lib | |
parent | 66508992483ae5d77b56a98427c50c772341c0ac (diff) |
Merge bundler master from upstream.
Pick from 8dd59e3ba97eb80a599f8149f31bf40773b69dc0
Diffstat (limited to 'lib')
84 files changed, 482 insertions, 811 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index f792a3bc98..d8f9462c6d 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) @@ -22,43 +22,43 @@ module Bundler ENV.replace(environment_preserver.backup) SUDO_MUTEX = Mutex.new - autoload :Definition, "bundler/definition" - autoload :Dependency, "bundler/dependency" - autoload :DepProxy, "bundler/dep_proxy" - autoload :Deprecate, "bundler/deprecate" - autoload :Dsl, "bundler/dsl" - autoload :EndpointSpecification, "bundler/endpoint_specification" - autoload :Env, "bundler/env" - autoload :Fetcher, "bundler/fetcher" - autoload :FeatureFlag, "bundler/feature_flag" - autoload :GemHelper, "bundler/gem_helper" - autoload :GemHelpers, "bundler/gem_helpers" - autoload :GemRemoteFetcher, "bundler/gem_remote_fetcher" - autoload :GemVersionPromoter, "bundler/gem_version_promoter" - autoload :Graph, "bundler/graph" - autoload :Index, "bundler/index" - autoload :Injector, "bundler/injector" - autoload :Installer, "bundler/installer" - autoload :LazySpecification, "bundler/lazy_specification" - autoload :LockfileParser, "bundler/lockfile_parser" - autoload :MatchPlatform, "bundler/match_platform" - autoload :ProcessLock, "bundler/process_lock" - autoload :RemoteSpecification, "bundler/remote_specification" - autoload :Resolver, "bundler/resolver" - autoload :Retry, "bundler/retry" - autoload :RubyDsl, "bundler/ruby_dsl" - autoload :RubyGemsGemInstaller, "bundler/rubygems_gem_installer" - autoload :RubyVersion, "bundler/ruby_version" - autoload :Runtime, "bundler/runtime" - autoload :Settings, "bundler/settings" - autoload :SharedHelpers, "bundler/shared_helpers" - autoload :Source, "bundler/source" - autoload :SourceList, "bundler/source_list" - autoload :SpecSet, "bundler/spec_set" - autoload :StubSpecification, "bundler/stub_specification" - autoload :UI, "bundler/ui" - autoload :URICredentialsFilter, "bundler/uri_credentials_filter" - autoload :VersionRanges, "bundler/version_ranges" + autoload :Definition, File.expand_path("bundler/definition", __dir__) + autoload :Dependency, File.expand_path("bundler/dependency", __dir__) + autoload :DepProxy, File.expand_path("bundler/dep_proxy", __dir__) + autoload :Deprecate, File.expand_path("bundler/deprecate", __dir__) + autoload :Dsl, File.expand_path("bundler/dsl", __dir__) + autoload :EndpointSpecification, File.expand_path("bundler/endpoint_specification", __dir__) + autoload :Env, File.expand_path("bundler/env", __dir__) + autoload :Fetcher, File.expand_path("bundler/fetcher", __dir__) + autoload :FeatureFlag, File.expand_path("bundler/feature_flag", __dir__) + autoload :GemHelper, File.expand_path("bundler/gem_helper", __dir__) + autoload :GemHelpers, File.expand_path("bundler/gem_helpers", __dir__) + autoload :GemRemoteFetcher, File.expand_path("bundler/gem_remote_fetcher", __dir__) + autoload :GemVersionPromoter, File.expand_path("bundler/gem_version_promoter", __dir__) + autoload :Graph, File.expand_path("bundler/graph", __dir__) + autoload :Index, File.expand_path("bundler/index", __dir__) + autoload :Injector, File.expand_path("bundler/injector", __dir__) + autoload :Installer, File.expand_path("bundler/installer", __dir__) + autoload :LazySpecification, File.expand_path("bundler/lazy_specification", __dir__) + autoload :LockfileParser, File.expand_path("bundler/lockfile_parser", __dir__) + autoload :MatchPlatform, File.expand_path("bundler/match_platform", __dir__) + autoload :ProcessLock, File.expand_path("bundler/process_lock", __dir__) + autoload :RemoteSpecification, File.expand_path("bundler/remote_specification", __dir__) + autoload :Resolver, File.expand_path("bundler/resolver", __dir__) + autoload :Retry, File.expand_path("bundler/retry", __dir__) + autoload :RubyDsl, File.expand_path("bundler/ruby_dsl", __dir__) + autoload :RubyGemsGemInstaller, File.expand_path("bundler/rubygems_gem_installer", __dir__) + autoload :RubyVersion, File.expand_path("bundler/ruby_version", __dir__) + autoload :Runtime, File.expand_path("bundler/runtime", __dir__) + autoload :Settings, File.expand_path("bundler/settings", __dir__) + autoload :SharedHelpers, File.expand_path("bundler/shared_helpers", __dir__) + autoload :Source, File.expand_path("bundler/source", __dir__) + autoload :SourceList, File.expand_path("bundler/source_list", __dir__) + autoload :SpecSet, File.expand_path("bundler/spec_set", __dir__) + autoload :StubSpecification, File.expand_path("bundler/stub_specification", __dir__) + autoload :UI, File.expand_path("bundler/ui", __dir__) + autoload :URICredentialsFilter, File.expand_path("bundler/uri_credentials_filter", __dir__) + autoload :VersionRanges, File.expand_path("bundler/version_ranges", __dir__) class << self def configure @@ -197,19 +197,19 @@ module Bundler def user_bundle_path(dir = "home") env_var, fallback = case dir when "home" - ["BUNDLE_USER_HOME", Pathname.new(user_home).join(".bundle")] + ["BUNDLE_USER_HOME", proc { Pathname.new(user_home).join(".bundle") }] when "cache" - ["BUNDLE_USER_CACHE", user_bundle_path.join("cache")] + ["BUNDLE_USER_CACHE", proc { user_bundle_path.join("cache") }] when "config" - ["BUNDLE_USER_CONFIG", user_bundle_path.join("config")] + ["BUNDLE_USER_CONFIG", proc { user_bundle_path.join("config") }] when "plugin" - ["BUNDLE_USER_PLUGIN", user_bundle_path.join("plugin")] + ["BUNDLE_USER_PLUGIN", proc { user_bundle_path.join("plugin") }] else raise BundlerError, "Unknown user path requested: #{dir}" end # `fallback` will already be a Pathname, but Pathname.new() is # idempotent so it's OK - Pathname.new(ENV.fetch(env_var, fallback)) + Pathname.new(ENV.fetch(env_var, &fallback)) end def user_cache diff --git a/lib/bundler/bundler.gemspec b/lib/bundler/bundler.gemspec index d8abb2b16f..6ce881e51a 100644 --- a/lib/bundler/bundler.gemspec +++ b/lib/bundler/bundler.gemspec @@ -1,10 +1,10 @@ # frozen_string_literal: true begin - require File.expand_path("../lib/bundler/version", __FILE__) + require_relative "lib/bundler/version" rescue LoadError # for Ruby core repository - require File.expand_path("../version", __FILE__) + require_relative "version" end Gem::Specification.new do |s| @@ -31,27 +31,23 @@ Gem::Specification.new do |s| } end - if s.version >= Gem::Version.new("2.a".dup) - s.required_ruby_version = ">= 2.3.0" - s.required_rubygems_version = ">= 2.5.0" - else - s.required_ruby_version = ">= 1.8.7" - s.required_rubygems_version = ">= 1.3.6" - end + s.required_ruby_version = ">= 2.3.0" + s.required_rubygems_version = ">= 2.5.0" s.add_development_dependency "automatiek", "~> 0.1.0" s.add_development_dependency "rake", "~> 12.0" s.add_development_dependency "ronn", "~> 0.7.3" s.add_development_dependency "rspec", "~> 3.6" - s.add_development_dependency "rubocop", "= 0.65.0" + s.add_development_dependency "rubocop", "= 0.68.1" + s.add_development_dependency "rubocop-performance", "~> 1.1" - # s.files = Dir.glob("{lib,exe}/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) } + s.files = Dir.glob("{lib,exe}/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) } # we don't check in man pages, but we need to ship them because # we use them to generate the long-form help for each command. - # s.files += Dir.glob("man/**/*") + s.files += Dir.glob("man/**/*") # Include the CHANGELOG.md, LICENSE.md, README.md manually - # s.files += %w[CHANGELOG.md LICENSE.md README.md] + s.files += %w[CHANGELOG.md LICENSE.md README.md] # include the gemspec itself because warbler breaks w/o it s.files += %w[bundler.gemspec] diff --git a/lib/bundler/capistrano.rb b/lib/bundler/capistrano.rb index 1b7145b72b..573df95043 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 @@ Bundler::SharedHelpers.major_deprecation 2, # # 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 4e3735847e..dd733a22ed 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -1,11 +1,10 @@ # frozen_string_literal: true -require "bundler" -require "bundler/vendored_thor" +require_relative "vendored_thor" module Bundler class CLI < Thor - require "bundler/cli/common" + require_relative "cli/common" package_name "Bundler" @@ -139,7 +138,7 @@ module Bundler 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 @@ -157,7 +156,7 @@ module Bundler "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 @@ -168,7 +167,7 @@ module Bundler 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 @@ -230,7 +229,7 @@ module Bundler 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 @@ -276,7 +275,7 @@ module Bundler "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 @@ -312,7 +311,7 @@ module Bundler 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 @@ -323,7 +322,7 @@ module Bundler 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 @@ -332,7 +331,7 @@ module Bundler 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 @@ -353,7 +352,7 @@ module Bundler 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 @@ -364,12 +363,14 @@ module Bundler method_option "version", :aliases => "-v", :type => :string method_option "group", :aliases => "-g", :type => :string method_option "source", :aliases => "-s", :type => :string + method_option "git", :type => :string + method_option "branch", :type => :string method_option "skip-install", :type => :boolean, :banner => "Adds gem to the Gemfile but does not install it" 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 @@ -405,7 +406,7 @@ module Bundler 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 @@ -420,7 +421,7 @@ module Bundler 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 @@ -448,7 +449,7 @@ module Bundler 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 @@ -463,7 +464,7 @@ module Bundler D map "e" => "exec" def exec(*args) - require "bundler/cli/exec" + require_relative "cli/exec" Exec.new(options, args).run end @@ -479,19 +480,19 @@ module Bundler 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 @@ -539,7 +540,7 @@ module Bundler 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 @@ -563,7 +564,7 @@ module Bundler 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) @@ -591,7 +592,7 @@ module Bundler 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 @@ -599,7 +600,7 @@ module Bundler 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 @@ -610,7 +611,7 @@ module Bundler "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 @@ -642,7 +643,7 @@ module Bundler 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 @@ -662,13 +663,13 @@ module Bundler 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 @@ -679,12 +680,12 @@ module Bundler 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/add.rb b/lib/bundler/cli/add.rb index 9709e71be0..7c6235f17c 100644 --- a/lib/bundler/cli/add.rb +++ b/lib/bundler/cli/add.rb @@ -2,34 +2,45 @@ module Bundler class CLI::Add + attr_reader :gems, :options, :version + def initialize(options, gems) @gems = gems @options = options - @options[:group] = @options[:group].split(",").map(&:strip) if !@options[:group].nil? && !@options[:group].empty? + @options[:group] = options[:group].split(",").map(&:strip) unless options[:group].nil? + @version = options[:version].split(",").map(&:strip) unless options[:version].nil? end def run - raise InvalidOption, "You can not specify `--strict` and `--optimistic` at the same time." if @options[:strict] && @options[:optimistic] - - # raise error when no gems are specified - raise InvalidOption, "Please specify gems to add." if @gems.empty? + validate_options! + inject_dependencies + perform_bundle_install unless options["skip-install"] + end - version = @options[:version].nil? ? nil : @options[:version].split(",").map(&:strip) + private - unless version.nil? - version.each do |v| - raise InvalidOption, "Invalid gem requirement pattern '#{v}'" unless Gem::Requirement::PATTERN =~ v.to_s - end - end + def perform_bundle_install + Installer.install(Bundler.root, Bundler.definition) + end - dependencies = @gems.map {|g| Bundler::Dependency.new(g, version, @options) } + def inject_dependencies + dependencies = gems.map {|g| Bundler::Dependency.new(g, version, options) } Injector.inject(dependencies, - :conservative_versioning => @options[:version].nil?, # Perform conservative versioning only when version is not specified - :optimistic => @options[:optimistic], - :strict => @options[:strict]) + :conservative_versioning => options[:version].nil?, # Perform conservative versioning only when version is not specified + :optimistic => options[:optimistic], + :strict => options[:strict]) + end + + def validate_options! + raise InvalidOption, "You can not specify `--strict` and `--optimistic` at the same time." if options[:strict] && options[:optimistic] - Installer.install(Bundler.root, Bundler.definition) unless @options["skip-install"] + # raise error when no gems are specified + raise InvalidOption, "Please specify gems to add." if gems.empty? + + version.to_a.each do |v| + raise InvalidOption, "Invalid gem requirement pattern '#{v}'" unless Gem::Requirement::PATTERN =~ v.to_s + end end end end diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb index 9ea52baa6b..cec7bcadb4 100644 --- a/lib/bundler/cli/common.rb +++ b/lib/bundler/cli/common.rb @@ -14,17 +14,18 @@ module Bundler Bundler.ui.info msg end - def self.output_without_groups_message + def self.output_without_groups_message(command) return if Bundler.settings[:without].empty? - Bundler.ui.confirm without_groups_message + Bundler.ui.confirm without_groups_message(command) end - def self.without_groups_message + def self.without_groups_message(command) + command_in_past_tense = command == :install ? "installed" : "updated" groups = Bundler.settings[:without] group_list = [groups[0...-1].join(", "), groups[-1..-1]]. reject {|s| s.to_s.empty? }.join(" and ") group_str = groups.size == 1 ? "group" : "groups" - "Gems in the #{group_str} #{group_list} were not installed." + "Gems in the #{group_str} #{group_list} were not #{command_in_past_tense}." end def self.select_spec(name, regex_match = nil) @@ -59,7 +60,7 @@ module Bundler 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 6d038937c0..1b3913a300 100644 --- a/lib/bundler/cli/doctor.rb +++ b/lib/bundler/cli/doctor.rb @@ -56,7 +56,7 @@ module Bundler 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 c29d632307..5dcf4a01ef 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 @@ -27,12 +27,7 @@ module Bundler if !Bundler.settings[:disable_exec_load] && ruby_shebang?(bin_path) return kernel_load(bin_path, *args) end - # First, try to exec directly to something in PATH - if Bundler.current_ruby.jruby_18? - kernel_exec(bin_path, *args) - else - kernel_exec([bin_path, cmd], *args) - end + kernel_exec(bin_path, *args) else # exec using the given command kernel_exec(cmd, *args) @@ -69,7 +64,7 @@ module Bundler 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 03edc7fbd2..d823fb632f 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -66,7 +66,7 @@ module Bundler Bundler.load.cache if Bundler.app_cache.exist? && !options["no-cache"] && !Bundler.frozen_bundle? Bundler.ui.confirm "Bundle complete! #{dependencies_count_for(definition)}, #{gems_installed_for(definition)}." - Bundler::CLI::Common.output_without_groups_message + Bundler::CLI::Common.output_without_groups_message(:install) if Bundler.use_system_gems? Bundler.ui.confirm "Use `bundle info [gemname]` to see where a bundled gem is installed." @@ -80,7 +80,7 @@ module Bundler 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 bba1619340..054ce76315 100644 --- a/lib/bundler/cli/issue.rb +++ b/lib/bundler/cli/issue.rb @@ -33,7 +33,7 @@ module Bundler end def doctor - require "bundler/cli/doctor" + require_relative "doctor" Bundler::CLI::Doctor.new({}).run end end diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 3a0521de1e..857caf0a03 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -133,7 +133,7 @@ module Bundler unless options[:parseable] if groups - Bundler.ui.info "===== Group #{groups} =====" + Bundler.ui.info "===== #{groups_text("Group", groups)} =====" else Bundler.ui.info "===== Without group =====" end @@ -167,6 +167,10 @@ module Bundler private + def groups_text(group_text, groups) + "#{group_text}#{groups.split(",").size > 1 ? "s" : ""} \"#{groups}\"" + end + def retrieve_active_spec(strict, definition, current_spec) if strict active_spec = definition.find_resolved_spec(current_spec) @@ -212,7 +216,7 @@ module Bundler elsif options_include_groups || !groups " * #{spec_outdated_info}" else - " * #{spec_outdated_info} in groups \"#{groups}\"" + " * #{spec_outdated_info} in #{groups_text("group", groups)}" end Bundler.ui.info output_message.rstrip diff --git a/lib/bundler/cli/package.rb b/lib/bundler/cli/package.rb index cd01ce422e..120a3fdcf3 100644 --- a/lib/bundler/cli/package.rb +++ b/lib/bundler/cli/package.rb @@ -25,7 +25,7 @@ module Bundler 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 b5dd5b6d4b..1155c4ec9b 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 b088853768..afd386bd54 100644 --- a/lib/bundler/cli/update.rb +++ b/lib/bundler/cli/update.rb @@ -58,24 +58,44 @@ module Bundler Bundler.settings.set_command_option_if_given :jobs, opts["jobs"] Bundler.definition.validate_runtime! + + if locked_gems = Bundler.definition.locked_gems + previous_locked_info = locked_gems.specs.reduce({}) do |h, s| + h[s.name] = { :spec => s, :version => s.version, :source => s.source.to_s } + h + end + end + installer = Installer.install Bundler.root, Bundler.definition, opts 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 - if locked_gems = Bundler.definition.locked_gems + if locked_gems gems.each do |name| - locked_version = locked_gems.specs.find {|s| s.name == name } - locked_version &&= locked_version.version - next unless locked_version - new_version = Bundler.definition.specs[name].first - new_version &&= new_version.version - if !new_version - Bundler.ui.warn "Bundler attempted to update #{name} but it was removed from the bundle" - elsif new_version < locked_version + locked_info = previous_locked_info[name] + next unless locked_info + + locked_spec = locked_info[:spec] + new_spec = Bundler.definition.specs[name].first + unless new_spec + if Bundler.rubygems.platforms.none? {|p| locked_spec.match_platform(p) } + Bundler.ui.warn "Bundler attempted to update #{name} but it was not considered because it is for a different platform from the current one" + end + + next + end + + locked_source = locked_info[:source] + new_source = new_spec.source.to_s + next if locked_source != new_source + + new_version = new_spec.version + locked_version = locked_info[:version] + if new_version < locked_version Bundler.ui.warn "Note: #{name} version regressed from #{locked_version} to #{new_version}" elsif new_version == locked_version Bundler.ui.warn "Bundler attempted to update #{name} but its version stayed the same" @@ -84,7 +104,7 @@ module Bundler end Bundler.ui.confirm "Bundle updated!" - Bundler::CLI::Common.output_without_groups_message + Bundler::CLI::Common.output_without_groups_message(:update) Bundler::CLI::Common.output_post_install_messages installer.post_install_messages end end diff --git a/lib/bundler/compact_index_client.rb b/lib/bundler/compact_index_client.rb index 2f713041c8..a5120dbba4 100644 --- a/lib/bundler/compact_index_client.rb +++ b/lib/bundler/compact_index_client.rb @@ -13,8 +13,8 @@ module Bundler 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 d77285072c..40232019bc 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 958116ce55..eaff1a10d4 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 f9daae067c..76950ff96a 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 @@ module Bundler end def to_lock - require "bundler/lockfile_generator" + require_relative "lockfile_generator" LockfileGenerator.generate(self) end @@ -782,7 +782,7 @@ module Bundler # Path sources have special logic if s.source.instance_of?(Source::Path) || s.source.instance_of?(Source::Gemspec) - other_sources_specs = begin + new_specs = begin s.source.specs rescue PathError, GitError # if we won't need the source (according to the lockfile), @@ -794,16 +794,18 @@ module Bundler raise end - other = other_sources_specs[s].first + new_spec = new_specs[s].first # If the spec is no longer in the path source, unlock it. This # commonly happens if the version changed in the gemspec - next unless other + next unless new_spec - deps2 = other.dependencies.select {|d| d.type != :development } - runtime_dependencies = s.dependencies.select {|d| d.type != :development } - # If the dependencies of the path source have changed, unlock it - next unless runtime_dependencies.sort == deps2.sort + new_runtime_deps = new_spec.dependencies.select {|d| d.type != :development } + old_runtime_deps = s.dependencies.select {|d| d.type != :development } + # If the dependencies of the path source have changed and locked spec can't satisfy new dependencies, unlock it + next unless new_runtime_deps.sort == old_runtime_deps.sort || new_runtime_deps.all? {|d| satisfies_locked_spec?(d) } + + s.dependencies.replace(new_spec.dependencies) end converged << s diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb index 8840ad6a9c..0d588bc892 100644 --- a/lib/bundler/dependency.rb +++ b/lib/bundler/dependency.rb @@ -1,13 +1,13 @@ # 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 attr_reader :autorequire - attr_reader :groups, :platforms, :gemfile + attr_reader :groups, :platforms, :gemfile, :git, :branch PLATFORM_MAP = { :ruby => Gem::Platform::RUBY, @@ -84,6 +84,8 @@ module Bundler @autorequire = nil @groups = Array(options["group"] || :default).map(&:to_sym) @source = options["source"] + @git = options["git"] + @branch = options["branch"] @platforms = Array(options["platforms"]) @env = options["env"] @should_include = options.fetch("should_include", true) diff --git a/lib/bundler/deployment.rb b/lib/bundler/deployment.rb index 291e158ca0..b432ae6ae1 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 7424a5c8a4..534c9b5537 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 @@ -291,12 +291,7 @@ module Bundler "https://github.com/#{repo_name}.git" RUBY repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") - if Bundler.feature_flag.github_https? - "https://github.com/#{repo_name}.git" - else - Bundler::SharedHelpers.major_deprecation 2, "Setting `github.https` to false is deprecated and won't be supported in the future." - "git://github.com/#{repo_name}.git" - end + "https://github.com/#{repo_name}.git" end git_source(:gist) do |repo_name| diff --git a/lib/bundler/env.rb b/lib/bundler/env.rb index 9cd9b8baca..a08db08aa0 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 @@ -100,8 +100,9 @@ module Bundler out << [" Full Path", Gem.ruby] out << [" Config Dir", Pathname.new(Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE).dirname] out << ["RubyGems", Gem::VERSION] - out << [" Gem Home", ENV.fetch("GEM_HOME") { Gem.dir }] - out << [" Gem Path", ENV.fetch("GEM_PATH") { Gem.path.join(File::PATH_SEPARATOR) }] + out << [" Gem Home", Gem.dir] + out << [" Gem Path", Gem.path.join(File::PATH_SEPARATOR)] + out << [" User Home", Gem.user_home] out << [" User Path", Gem.user_dir] out << [" Bin Dir", Gem.bindir] if defined?(OpenSSL) diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb index 982f0fa540..a45694dd8e 100644 --- a/lib/bundler/feature_flag.rb +++ b/lib/bundler/feature_flag.rb @@ -36,16 +36,14 @@ module Bundler settings_flag(:default_install_uses_path) { bundler_3_mode? } settings_flag(:deployment_means_frozen) { bundler_3_mode? } settings_flag(:disable_multisource) { bundler_3_mode? } - settings_flag(:error_on_stderr) { bundler_2_mode? } settings_flag(:forget_cli_options) { bundler_3_mode? } - settings_flag(:global_path_appends_ruby_scope) { bundler_3_mode? } settings_flag(:global_gem_cache) { bundler_3_mode? } settings_flag(:only_update_to_newer_versions) { bundler_3_mode? } settings_flag(:path_relative_to_cwd) { bundler_3_mode? } settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") } settings_flag(:print_only_version_number) { bundler_3_mode? } settings_flag(:setup_makes_kernel_gem_public) { !bundler_3_mode? } - settings_flag(:skip_default_git_sources) { bundler_4_mode? } + settings_flag(:skip_default_git_sources) { bundler_3_mode? } settings_flag(:specific_platform) { bundler_3_mode? } settings_flag(:suppress_install_using_messages) { bundler_3_mode? } settings_flag(:unlock_source_unlocks_spec) { !bundler_3_mode? } @@ -54,8 +52,6 @@ module Bundler settings_option(:default_cli_command) { bundler_3_mode? ? :cli_help : :install } - settings_method(:github_https?, "github.https") { bundler_2_mode? } - def initialize(bundler_version) @bundler_version = Gem::Version.create(bundler_version) end diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb index 8397f7b72b..d21baf659d 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" @@ -9,10 +9,10 @@ require "rubygems/request" module Bundler # Handles all the fetching with the rubygems server class Fetcher - autoload :CompactIndex, "bundler/fetcher/compact_index" - autoload :Downloader, "bundler/fetcher/downloader" - autoload :Dependency, "bundler/fetcher/dependency" - autoload :Index, "bundler/fetcher/index" + autoload :CompactIndex, File.expand_path("fetcher/compact_index", __dir__) + autoload :Downloader, File.expand_path("fetcher/downloader", __dir__) + autoload :Dependency, File.expand_path("fetcher/dependency", __dir__) + autoload :Index, File.expand_path("fetcher/index", __dir__) # This error is raised when it looks like the network is down class NetworkDownError < HTTPError; end diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb index a117af72fa..f36d76d4ae 100644 --- a/lib/bundler/fetcher/compact_index.rb +++ b/lib/bundler/fetcher/compact_index.rb @@ -1,10 +1,10 @@ # 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" + autoload :CompactIndexClient, File.expand_path("../compact_index_client", __dir__) class Fetcher class CompactIndex < Base diff --git a/lib/bundler/fetcher/dependency.rb b/lib/bundler/fetcher/dependency.rb index 1430d1ebeb..c52c32fb5b 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/downloader.rb b/lib/bundler/fetcher/downloader.rb index 2aeb9962c4..73f125af91 100644 --- a/lib/bundler/fetcher/downloader.rb +++ b/lib/bundler/fetcher/downloader.rb @@ -37,6 +37,7 @@ module Bundler when Net::HTTPTooManyRequests raise TooManyRequestsError, response.body when Net::HTTPUnauthorized + raise BadAuthenticationError, uri.host if uri.userinfo raise AuthenticationRequiredError, uri.host when Net::HTTPNotFound raise FallbackError, "Net::HTTPNotFound: #{URICredentialsFilter.credential_filtered_uri(uri)}" diff --git a/lib/bundler/fetcher/index.rb b/lib/bundler/fetcher/index.rb index 1a8064624d..9beb0e27d8 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 @@ -13,6 +13,7 @@ module Bundler when /certificate verify failed/ raise CertificateFailureError.new(display_uri) when /401/ + raise BadAuthenticationError, remote_uri if remote_uri.userinfo raise AuthenticationRequiredError, remote_uri when /403/ raise BadAuthenticationError, remote_uri if remote_uri.userinfo diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb index dd9b847f10..b93ae68012 100644 --- a/lib/bundler/friendly_errors.rb +++ b/lib/bundler/friendly_errors.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true require "cgi" -require "bundler/vendored_thor" +require_relative "vendored_thor" module Bundler module FriendlyErrors - module_function + module_function # rubocop:disable Layout/AccessModifierIndentation def log_error(error) case error diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index e9ee03b8a2..33f1d51592 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 f736517bd7..bc725d3602 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/gem_version_promoter.rb b/lib/bundler/gem_version_promoter.rb index ed950ad28b..311b0cbbf3 100644 --- a/lib/bundler/gem_version_promoter.rb +++ b/lib/bundler/gem_version_promoter.rb @@ -81,8 +81,8 @@ module Bundler sort_dep_specs(spec_groups, locked_spec) end.tap do |specs| if DEBUG - STDERR.puts before_result - STDERR.puts " after sort_versions: #{debug_format_result(dep, specs).inspect}" + warn before_result + warn " after sort_versions: #{debug_format_result(dep, specs).inspect}" end end end diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index e67469f2dd..2cdda578e2 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -111,8 +111,10 @@ module Bundler end source = ", :source => \"#{d.source}\"" unless d.source.nil? + git = ", :git => \"#{d.git}\"" unless d.git.nil? + branch = ", :branch => \"#{d.branch}\"" unless d.branch.nil? - %(gem #{name}#{requirement}#{group}#{source}) + %(gem #{name}#{requirement}#{group}#{source}#{git}#{branch}) end.join("\n") end diff --git a/lib/bundler/inline.rb b/lib/bundler/inline.rb index 93355c9460..317bf892ab 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 @@ require "bundler/compatibility_guard" # 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 } @@ -49,26 +49,28 @@ def gemfile(install = false, options = {}, &gemfile) builder = Bundler::Dsl.new builder.instance_eval(&gemfile) - definition = builder.to_definition(nil, true) - def definition.lock(*); end - definition.validate_runtime! + Bundler.settings.temporary(:frozen => false) do + definition = builder.to_definition(nil, true) + def definition.lock(*); end + definition.validate_runtime! - missing_specs = proc do - definition.missing_specs? - end + missing_specs = proc do + definition.missing_specs? + end - Bundler.ui = ui if install - if install || missing_specs.call - Bundler.settings.temporary(:inline => true) do - installer = Bundler::Installer.install(Bundler.root, definition, :system => true) - installer.post_install_messages.each do |name, message| - Bundler.ui.info "Post-install message from #{name}:\n#{message}" + Bundler.ui = ui if install + if install || missing_specs.call + Bundler.settings.temporary(:inline => true, :disable_platform_warnings => true) do + installer = Bundler::Installer.install(Bundler.root, definition, :system => true) + installer.post_install_messages.each do |name, message| + Bundler.ui.info "Post-install message from #{name}:\n#{message}" + end end end - end - runtime = Bundler::Runtime.new(nil, definition) - runtime.setup.require + runtime = Bundler::Runtime.new(nil, definition) + runtime.setup.require + end ensure bundler_module = class << Bundler; self; end bundler_module.send(:define_method, :root, old_root) if old_root diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 49143b38f9..5bc53a8b61 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 469b15b96c..391540af0b 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 69a721c120..cbd04b2c90 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/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index 50dc1381fe..5658ec1205 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -101,17 +101,11 @@ module Bundler return unless bundler_version prerelease_text = bundler_version.prerelease? ? " --pre" : "" current_version = Gem::Version.create(Bundler::VERSION) - case current_version.segments.first <=> bundler_version.segments.first - when -1 - raise LockfileError, "You must use Bundler #{bundler_version.segments.first} or greater with this lockfile." - when 0 - if current_version < bundler_version - Bundler.ui.warn "Warning: the running version of Bundler (#{current_version}) is older " \ - "than the version that created the lockfile (#{bundler_version}). We suggest you to " \ - "upgrade to the version that created the lockfile by running `gem install " \ - "bundler:#{bundler_version}#{prerelease_text}`.\n" - end - end + return unless current_version < bundler_version + Bundler.ui.warn "Warning: the running version of Bundler (#{current_version}) is older " \ + "than the version that created the lockfile (#{bundler_version}). We suggest you to " \ + "upgrade to the version that created the lockfile by running `gem install " \ + "bundler:#{bundler_version}#{prerelease_text}`.\n" end private diff --git a/lib/bundler/match_platform.rb b/lib/bundler/match_platform.rb index 56cbbfb95d..69074925a6 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 996d29aafb..ffb3ee9883 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 @@ -256,7 +256,7 @@ module Bundler @hooks_by_event = Hash.new {|h, k| h[k] = [] } load_paths = spec.load_paths - add_to_load_path(load_paths) + Bundler.rubygems.add_to_load_path(load_paths) path = Pathname.new spec.full_gem_path begin @@ -288,7 +288,7 @@ module Bundler # done to avoid conflicts path = index.plugin_path(name) - add_to_load_path(index.load_paths(name)) + Bundler.rubygems.add_to_load_path(index.load_paths(name)) load path.join(PLUGIN_FILE_NAME) @@ -298,17 +298,8 @@ module Bundler raise end - def add_to_load_path(load_paths) - if insert_index = Bundler.rubygems.load_path_insert_index - $LOAD_PATH.insert(insert_index, *load_paths) - else - $LOAD_PATH.unshift(*load_paths) - end - end - class << self - private :load_plugin, :register_plugin, :save_plugins, :validate_plugin!, - :add_to_load_path + private :load_plugin, :register_plugin, :save_plugins, :validate_plugin! end end end diff --git a/lib/bundler/plugin/api.rb b/lib/bundler/plugin/api.rb index a2d5cbb4ac..ee2bffe3ab 100644 --- a/lib/bundler/plugin/api.rb +++ b/lib/bundler/plugin/api.rb @@ -23,7 +23,7 @@ module Bundler # and hooks). module Plugin class API - autoload :Source, "bundler/plugin/api/source" + autoload :Source, File.expand_path("api/source", __dir__) # The plugins should declare that they handle a command through this helper. # diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb index faabf3a8d1..2d70a046bb 100644 --- a/lib/bundler/plugin/index.rb +++ b/lib/bundler/plugin/index.rb @@ -139,7 +139,7 @@ module Bundler data = index_f.read - require "bundler/yaml_serializer" + require_relative "../yaml_serializer" index = YAMLSerializer.load(data) @commands.merge!(index["commands"]) @@ -162,7 +162,7 @@ module Bundler "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/plugin/installer.rb b/lib/bundler/plugin/installer.rb index 4a262efac2..bcea3f0e45 100644 --- a/lib/bundler/plugin/installer.rb +++ b/lib/bundler/plugin/installer.rb @@ -8,8 +8,8 @@ module Bundler # are heavily dependent on the Gemfile. module Plugin class Installer - autoload :Rubygems, "bundler/plugin/installer/rubygems" - autoload :Git, "bundler/plugin/installer/git" + autoload :Rubygems, File.expand_path("installer/rubygems", __dir__) + autoload :Git, File.expand_path("installer/git", __dir__) def install(names, options) check_sources_consistency!(options) diff --git a/lib/bundler/psyched_yaml.rb b/lib/bundler/psyched_yaml.rb index e654416a5a..c086b7651c 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 90f833bef1..c7caf01c7d 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 @@ -75,7 +75,7 @@ module Bundler return unless debug? debug_info = yield debug_info = debug_info.inspect unless debug_info.is_a?(String) - STDERR.puts debug_info.split("\n").map {|s| " " * depth + s } + warn debug_info.split("\n").map {|s| " " * depth + s } end def debug? diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index ccf71c8c00..96b93836c7 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -4,40 +4,25 @@ require "pathname" require "rubygems/specification" -begin - # Possible use in Gem::Specification#source below and require - # shouldn't be deferred. - require "rubygems/source" -rescue LoadError - # Not available before RubyGems 2.0.0, ignore - nil -end +# Possible use in Gem::Specification#source below and require +# shouldn't be deferred. +require "rubygems/source" -require "bundler/match_platform" +require_relative "match_platform" module Gem - @loaded_stacks = Hash.new {|h, k| h[k] = [] } - class Specification attr_accessor :remote, :location, :relative_loaded_from - if instance_methods(false).include?(:source) - remove_method :source - attr_writer :source - def source - (defined?(@source) && @source) || Gem::Source::Installed.new - end - else - # rubocop:disable Lint/DuplicateMethods - attr_accessor :source - # rubocop:enable Lint/DuplicateMethods + remove_method :source + attr_writer :source + def source + (defined?(@source) && @source) || Gem::Source::Installed.new end alias_method :rg_full_gem_path, :full_gem_path alias_method :rg_loaded_from, :loaded_from - attr_writer :full_gem_path unless instance_methods.include?(:full_gem_path=) - def full_gem_path # this cannot check source.is_a?(Bundler::Plugin::API::Source) # because that _could_ trip the autoload, and if there are unresolved @@ -59,15 +44,7 @@ module Gem end def load_paths - return full_require_paths if respond_to?(:full_require_paths) - - require_paths.map do |require_path| - if require_path.include?(full_gem_path) - require_path - else - File.join(full_gem_path, require_path) - end - end + full_require_paths end if method_defined?(:extension_dir) @@ -151,32 +128,6 @@ module Gem end out end - - # Backport of performance enhancement added to RubyGems 1.4 - def matches_spec?(spec) - # name can be a Regexp, so use === - return false unless name === spec.name - return true if requirement.none? - - requirement.satisfied_by?(spec.version) - end unless allocate.respond_to?(:matches_spec?) - end - - class Requirement - # Backport of performance enhancement added to RubyGems 1.4 - def none? - # note that it might be tempting to replace with with RubyGems 2.0's - # improved implementation. Don't. It requires `DefaultRequirement` to be - # defined, and more importantantly, these overrides are not used when the - # running RubyGems defines these methods - to_s == ">= 0" - end unless allocate.respond_to?(:none?) - - # Backport of performance enhancement added to RubyGems 2.2 - def exact? - return false unless @requirements.size == 1 - @requirements[0][0] == "=" - end unless allocate.respond_to?(:exact?) end class Platform diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index a4519246a9..9df0897ca2 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require "monitor" - module Bundler class RubygemsIntegration if defined?(Gem::Ext::Builder::CHDIR_MONITOR) EXT_LOCK = Gem::Ext::Builder::CHDIR_MONITOR else + require "monitor" + EXT_LOCK = Monitor.new end @@ -20,6 +20,7 @@ module Bundler def initialize @replaced_methods = {} + backport_ext_builder_monitor end def version @@ -38,14 +39,22 @@ module Bundler Gem::Command.build_args = args end - def load_path_insert_index - Gem.load_path_insert_index - end - def loaded_specs(name) Gem.loaded_specs[name] end + def add_to_load_path(paths) + return Gem.add_to_load_path(*paths) if Gem.respond_to?(:add_to_load_path) + + if insert_index = Gem.load_path_insert_index + # Gem directories must come after -I and ENV['RUBYLIB'] + $LOAD_PATH.insert(insert_index, *paths) + else + # We are probably testing in core, -I and RUBYLIB don't apply + $LOAD_PATH.unshift(*paths) + end + end + def mark_loaded(spec) if spec.respond_to?(:activated=) current = Gem.loaded_specs[spec.name] @@ -110,7 +119,7 @@ module Bundler 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}" @@ -198,10 +207,6 @@ module Bundler Gem::ConfigMap end - def repository_subdirectories - %w[cache doc gems specifications] - end - def clear_paths Gem.clear_paths end @@ -210,26 +215,14 @@ module Bundler Gem.bin_path(gem, bin, ver) end - def path_separator - File::PATH_SEPARATOR - end - def preserve_paths # this is a no-op outside of RubyGems 1.8 yield end def loaded_gem_paths - # RubyGems 2.2+ can put binary extension into dedicated folders, - # therefore use RubyGems facilities to obtain their load paths. - if Gem::Specification.method_defined? :full_require_paths - loaded_gem_paths = Gem.loaded_specs.map {|_, s| s.full_require_paths } - loaded_gem_paths.flatten - else - $LOAD_PATH.select do |p| - Bundler.rubygems.gem_path.any? {|gp| p =~ /^#{Regexp.escape(gp)}/ } - end - end + loaded_gem_paths = Gem.loaded_specs.map {|_, s| s.full_require_paths } + loaded_gem_paths.flatten end def load_plugins @@ -248,36 +241,12 @@ module Bundler EXT_LOCK end - def fetch_specs(all, pre, &blk) - require "rubygems/spec_fetcher" - specs = Gem::SpecFetcher.new.list(all, pre) - specs.each { yield } if block_given? - specs - end - def fetch_prerelease_specs fetch_specs(false, true) rescue Gem::RemoteFetcher::FetchError {} # if we can't download them, there aren't any end - # TODO: This is for older versions of RubyGems... should we support the - # X-Gemfile-Source header on these old versions? - # Maybe the newer implementation will work on older RubyGems? - # It seems difficult to keep this implementation and still send the header. - def fetch_all_remote_specs(remote) - old_sources = Bundler.rubygems.sources - Bundler.rubygems.sources = [remote.uri.to_s] - # Fetch all specs, minus prerelease specs - spec_list = fetch_specs(true, false) - # Then fetch the prerelease specs - fetch_prerelease_specs.each {|k, v| spec_list[k].concat(v) } - - spec_list.values.first - ensure - Bundler.rubygems.sources = old_sources - end - def with_build_args(args) ext_lock.synchronize do old_args = build_args @@ -290,18 +259,9 @@ module Bundler end end - def install_with_build_args(args) - with_build_args(args) { yield } - end - - def gem_from_path(path, policy = nil) - require "rubygems/format" - Gem::Format.from_file_by_path(path, policy) - end - 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." @@ -317,23 +277,10 @@ module Bundler end end - def build(spec, skip_validation = false) - require "rubygems/builder" - Gem::Builder.new(spec).build - end - def build_gem(gem_dir, spec) build(spec) end - def download_gem(spec, uri, path) - uri = Bundler.settings.mirror_for(uri) - fetcher = Gem::RemoteFetcher.new(configuration[:http_proxy]) - Bundler::Retry.new("download gem from #{uri}").attempts do - fetcher.download(spec, uri, path) - end - end - def security_policy_keys %w[High Medium Low AlmostNo No].map {|level| "#{level}Security" } end @@ -357,12 +304,17 @@ module Bundler end end + # RubyGems-generated binstubs call Kernel#gem def binstubs_call_gem? - true + !provides?(">= 2.5.2") end + # only 2.5.2+ has all of the stub methods we want to use, and since this + # is a performance optimization _only_, + # we'll restrict ourselves to the most + # recent RG versions instead of all versions that have stubs def stubs_provide_full_functionality? - false + provides?(">= 2.5.2") end def replace_gem(specs, specs_by_name) @@ -411,26 +363,6 @@ module Bundler end end - def stub_source_index(specs) - Gem::SourceIndex.send(:alias_method, :old_initialize, :initialize) - redefine_method(Gem::SourceIndex, :initialize) do |*args| - @gems = {} - # You're looking at this thinking: Oh! This is how I make those - # rubygems deprecations go away! - # - # You'd be correct BUT using of this method in production code - # must be approved by the rubygems team itself! - # - # This is your warning. If you use this and don't have approval - # we can't protect you. - # - Deprecate.skip_during do - self.spec_dirs = *args - add_specs(*specs) - end - end - end - # Used to make bin stubs that are not created by bundler work # under bundler. The new Gem.bin_path only considers gems in # +specs+ @@ -531,25 +463,6 @@ module Bundler Gem.clear_paths end - # This backports the correct segment generation code from RubyGems 1.4+ - # by monkeypatching it into the method in RubyGems 1.3.6 and 1.3.7. - def backport_segment_generation - redefine_method(Gem::Version, :segments) do - @segments ||= @version.scan(/[0-9]+|[a-z]+/i).map do |s| - /^\d+$/ =~ s ? s.to_i : s - end - end - end - - # This backport fixes the marshaling of @segments. - def backport_yaml_initialize - redefine_method(Gem::Version, :yaml_initialize) do |_, map| - @version = map["version"] - @segments = nil - @hash = nil - end - end - # This backports base_dir which replaces installation path # RubyGems 1.8+ def backport_base_dir @@ -622,296 +535,129 @@ module Bundler end end - # RubyGems 1.4 through 1.6 - class Legacy < RubygemsIntegration - def initialize - super - backport_base_dir - backport_cache_file - backport_spec_file - backport_yaml_initialize - end + def stub_rubygems(specs) + Gem::Specification.all = specs - def stub_rubygems(specs) - # RubyGems versions lower than 1.7 use SourceIndex#from_gems_in - source_index_class = (class << Gem::SourceIndex; self; end) - redefine_method(source_index_class, :from_gems_in) do |*args| - Gem::SourceIndex.new.tap do |source_index| - source_index.spec_dirs = *args - source_index.add_specs(*specs) - end - end + Gem.post_reset do + Gem::Specification.all = specs end - def all_specs - Gem.source_index.gems.values + redefine_method((class << Gem; self; end), :finish_resolve) do |*| + [] end + end - def find_name(name) - Gem.source_index.find_name(name) - end + def fetch_specs(source, remote, name) + path = source + "#{name}.#{Gem.marshal_version}.gz" + fetcher = gem_remote_fetcher + fetcher.headers = { "X-Gemfile-Source" => remote.original_uri.to_s } if remote.original_uri + string = fetcher.fetch_path(path) + Bundler.load_marshal(string) + rescue Gem::RemoteFetcher::FetchError => e + # it's okay for prerelease to fail + raise e unless name == "prerelease_specs" + end - def validate(spec) - # These versions of RubyGems always validate in "packaging" mode, - # which is too strict for the kinds of checks we care about. As a - # result, validation is disabled on versions of RubyGems below 1.7. - end + def fetch_all_remote_specs(remote) + source = remote.uri.is_a?(URI) ? remote.uri : URI.parse(source.to_s) - def post_reset_hooks - [] - end + specs = fetch_specs(source, remote, "specs") + pres = fetch_specs(source, remote, "prerelease_specs") || [] - def reset - end + specs.concat(pres) end - # RubyGems versions 1.3.6 and 1.3.7 - class Ancient < Legacy - def initialize - super - backport_segment_generation + def download_gem(spec, uri, path) + uri = Bundler.settings.mirror_for(uri) + fetcher = gem_remote_fetcher + fetcher.headers = { "X-Gemfile-Source" => spec.remote.original_uri.to_s } if spec.remote.original_uri + Bundler::Retry.new("download gem from #{uri}").attempts do + fetcher.download(spec, uri, path) end end - # RubyGems 1.7 - class Transitional < Legacy - def stub_rubygems(specs) - stub_source_index(specs) - end - - def validate(spec) - # Missing summary is downgraded to a warning in later versions, - # so we set it to an empty string to prevent an exception here. - spec.summary ||= "" - RubygemsIntegration.instance_method(:validate).bind(self).call(spec) - end + def gem_remote_fetcher + require "resolv" + proxy = configuration[:http_proxy] + dns = Resolv::DNS.new + Bundler::GemRemoteFetcher.new(proxy, dns) end - # RubyGems 1.8.5-1.8.19 - class Modern < RubygemsIntegration - def stub_rubygems(specs) - Gem::Specification.all = specs - - Gem.post_reset do - Gem::Specification.all = specs - end + def gem_from_path(path, policy = nil) + require "rubygems/package" + p = Gem::Package.new(path) + p.security_policy = policy if policy + p + end - stub_source_index(specs) - end + def build(spec, skip_validation = false) + require "rubygems/package" + Gem::Package.build(spec, skip_validation) + end - def all_specs - Gem::Specification.to_a - end + def repository_subdirectories + Gem::REPOSITORY_SUBDIRECTORIES + end - def find_name(name) - Gem::Specification.find_all_by_name name - end + def install_with_build_args(args) + yield end - # RubyGems 1.8.0 to 1.8.4 - class AlmostModern < Modern - # RubyGems [>= 1.8.0, < 1.8.5] has a bug that changes Gem.dir whenever - # you call Gem::Installer#install with an :install_dir set. We have to - # change it back for our sudo mode to work. - def preserve_paths - old_dir = gem_dir - old_path = gem_path - yield - Gem.use_paths(old_dir, old_path) - end + def path_separator + Gem.path_separator end - # RubyGems 1.8.20+ - class MoreModern < Modern - # RubyGems 1.8.20 and adds the skip_validation parameter, so that's - # when we start passing it through. - def build(spec, skip_validation = false) - require "rubygems/builder" - Gem::Builder.new(spec).build(skip_validation) + def all_specs + require_relative "remote_specification" + Gem::Specification.stubs.map do |stub| + StubSpecification.from_stub(stub) end end - # RubyGems 2.0 - class Future < RubygemsIntegration - def stub_rubygems(specs) - Gem::Specification.all = specs - - Gem.post_reset do - Gem::Specification.all = specs + def backport_ext_builder_monitor + # So we can avoid requiring "rubygems/ext" in its entirety + Gem.module_eval <<-RB, __FILE__, __LINE__ + 1 + module Ext end + RB - redefine_method((class << Gem; self; end), :finish_resolve) do |*| - [] - end - end - - def all_specs - Gem::Specification.to_a - end - - def find_name(name) - Gem::Specification.find_all_by_name name - end - - def fetch_specs(source, remote, name) - path = source + "#{name}.#{Gem.marshal_version}.gz" - fetcher = gem_remote_fetcher - fetcher.headers = { "X-Gemfile-Source" => remote.original_uri.to_s } if remote.original_uri - string = fetcher.fetch_path(path) - Bundler.load_marshal(string) - rescue Gem::RemoteFetcher::FetchError => e - # it's okay for prerelease to fail - raise e unless name == "prerelease_specs" - end - - def fetch_all_remote_specs(remote) - source = remote.uri.is_a?(URI) ? remote.uri : URI.parse(source.to_s) + require "rubygems/ext/builder" - specs = fetch_specs(source, remote, "specs") - pres = fetch_specs(source, remote, "prerelease_specs") || [] - - specs.concat(pres) - end - - def download_gem(spec, uri, path) - uri = Bundler.settings.mirror_for(uri) - fetcher = gem_remote_fetcher - fetcher.headers = { "X-Gemfile-Source" => spec.remote.original_uri.to_s } if spec.remote.original_uri - Bundler::Retry.new("download gem from #{uri}").attempts do - fetcher.download(spec, uri, path) + Gem::Ext::Builder.class_eval do + unless const_defined?(:CHDIR_MONITOR) + const_set(:CHDIR_MONITOR, EXT_LOCK) end - end - - def gem_remote_fetcher - require "resolv" - proxy = configuration[:http_proxy] - dns = Resolv::DNS.new - Bundler::GemRemoteFetcher.new(proxy, dns) - end - - def gem_from_path(path, policy = nil) - require "rubygems/package" - p = Gem::Package.new(path) - p.security_policy = policy if policy - p - end - def build(spec, skip_validation = false) - require "rubygems/package" - Gem::Package.build(spec, skip_validation) - end - - def repository_subdirectories - Gem::REPOSITORY_SUBDIRECTORIES - end - - def install_with_build_args(args) - yield - end - - def path_separator - Gem.path_separator + remove_const(:CHDIR_MUTEX) if const_defined?(:CHDIR_MUTEX) + const_set(:CHDIR_MUTEX, const_get(:CHDIR_MONITOR)) end end - # RubyGems 2.1.0 - class MoreFuture < Future - def initialize - super - backport_ext_builder_monitor - end - - def all_specs - require "bundler/remote_specification" - Gem::Specification.stubs.map do |stub| - StubSpecification.from_stub(stub) - end - end - - def backport_ext_builder_monitor - # So we can avoid requiring "rubygems/ext" in its entirety - Gem.module_eval <<-RB, __FILE__, __LINE__ + 1 - module Ext - end - RB - - require "rubygems/ext/builder" - - Gem::Ext::Builder.class_eval do - unless const_defined?(:CHDIR_MONITOR) - const_set(:CHDIR_MONITOR, EXT_LOCK) - end - - remove_const(:CHDIR_MUTEX) if const_defined?(:CHDIR_MUTEX) - const_set(:CHDIR_MUTEX, const_get(:CHDIR_MONITOR)) - end - end - - if Gem::Specification.respond_to?(:stubs_for) - def find_name(name) - Gem::Specification.stubs_for(name).map(&:to_spec) - end - else - def find_name(name) - Gem::Specification.stubs.find_all do |spec| - spec.name == name - end.map(&:to_spec) - end - end + def find_name(name) + Gem::Specification.stubs_for(name).map(&:to_spec) + end - if Gem::Specification.respond_to?(:default_stubs) - def default_stubs - Gem::Specification.default_stubs("*.gemspec") - end - else - def default_stubs - Gem::Specification.send(:default_stubs, "*.gemspec") - end + if Gem::Specification.respond_to?(:default_stubs) + def default_stubs + Gem::Specification.default_stubs("*.gemspec") end - - def use_gemdeps(gemfile) - ENV["BUNDLE_GEMFILE"] ||= File.expand_path(gemfile) - require "bundler/gemdeps" - runtime = Bundler.setup - Bundler.ui = nil - activated_spec_names = runtime.requested_specs.map(&:to_spec).sort_by(&:name) - [Gemdeps.new(runtime), activated_spec_names] + else + def default_stubs + Gem::Specification.send(:default_stubs, "*.gemspec") end + end - if provides?(">= 2.5.2") - # RubyGems-generated binstubs call Kernel#gem - def binstubs_call_gem? - false - end - - # only 2.5.2+ has all of the stub methods we want to use, and since this - # is a performance optimization _only_, - # we'll restrict ourselves to the most - # recent RG versions instead of all versions that have stubs - def stubs_provide_full_functionality? - true - end - end + def use_gemdeps(gemfile) + ENV["BUNDLE_GEMFILE"] ||= File.expand_path(gemfile) + require_relative "gemdeps" + runtime = Bundler.setup + Bundler.ui = nil + activated_spec_names = runtime.requested_specs.map(&:to_spec).sort_by(&:name) + [Gemdeps.new(runtime), activated_spec_names] end end def self.rubygems - @rubygems ||= if RubygemsIntegration.provides?(">= 2.1.0") - RubygemsIntegration::MoreFuture.new - elsif RubygemsIntegration.provides?(">= 1.99.99") - RubygemsIntegration::Future.new - elsif RubygemsIntegration.provides?(">= 1.8.20") - RubygemsIntegration::MoreModern.new - elsif RubygemsIntegration.provides?(">= 1.8.5") - RubygemsIntegration::Modern.new - elsif RubygemsIntegration.provides?(">= 1.8.0") - RubygemsIntegration::AlmostModern.new - elsif RubygemsIntegration.provides?(">= 1.7.0") - RubygemsIntegration::Transitional.new - elsif RubygemsIntegration.provides?(">= 1.4.0") - RubygemsIntegration::Legacy.new - else # RubyGems 1.3.6 and 1.3.7 - RubygemsIntegration::Ancient.new - end + @rubygems ||= RubygemsIntegration.new end end diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 83945868f9..93a801eb6c 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -34,14 +34,7 @@ module Bundler spec.load_paths.reject {|path| $LOAD_PATH.include?(path) } end.reverse.flatten - # See Gem::Specification#add_self_to_load_path (since RubyGems 1.8) - if insert_index = Bundler.rubygems.load_path_insert_index - # Gem directories must come after -I and ENV['RUBYLIB'] - $LOAD_PATH.insert(insert_index, *load_paths) - else - # We are probably testing in core, -I and RUBYLIB don't apply - $LOAD_PATH.unshift(*load_paths) - end + Bundler.rubygems.add_to_load_path(load_paths) setup_manpath diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 5bc190865f..3888ac51d3 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -4,9 +4,9 @@ require "uri" module Bundler class Settings - autoload :Mirror, "bundler/mirror" - autoload :Mirrors, "bundler/mirror" - autoload :Validator, "bundler/settings/validator" + autoload :Mirror, File.expand_path("mirror", __dir__) + autoload :Mirrors, File.expand_path("mirror", __dir__) + autoload :Validator, File.expand_path("settings/validator", __dir__) BOOL_KEYS = %w[ allow_bundler_dependency_conflicts @@ -28,14 +28,11 @@ module Bundler disable_platform_warnings disable_shared_gems disable_version_check - error_on_stderr force_ruby_platform forget_cli_options frozen gem.coc gem.mit - github.https - global_path_appends_ruby_scope global_gem_cache ignore_messages init_gems_rb @@ -207,23 +204,22 @@ module Bundler locations end - # for legacy reasons, in Bundler 1, the ruby scope isnt appended when the setting comes from ENV or the global config, - # nor do we respect :disable_shared_gems + # for legacy reasons, in Bundler 2, we do not respect :disable_shared_gems def path key = key_for(:path) path = ENV[key] || @global_config[key] if path && [email protected]?(key) && !@local_config.key?(key) - return Path.new(path, Bundler.feature_flag.global_path_appends_ruby_scope?, false, false) + return Path.new(path, false, false) end system_path = self["path.system"] || (self[:disable_shared_gems] == false) - Path.new(self[:path], true, system_path, Bundler.feature_flag.default_install_uses_path?) + Path.new(self[:path], system_path, Bundler.feature_flag.default_install_uses_path?) end - Path = Struct.new(:explicit_path, :append_ruby_scope, :system_path, :default_install_uses_path) do + Path = Struct.new(:explicit_path, :system_path, :default_install_uses_path) do def path path = base_path - path = File.join(path, Bundler.ruby_scope) if append_ruby_scope && !use_system_gems? + path = File.join(path, Bundler.ruby_scope) unless use_system_gems? path end @@ -358,7 +354,7 @@ module Bundler 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 @@ -398,7 +394,7 @@ module Bundler 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 52a5b8889a..d156f494a8 100644 --- a/lib/bundler/setup.rb +++ b/lib/bundler/setup.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require "bundler/shared_helpers" +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 diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 1b703c5cbc..d259f20e6b 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 @@ -103,9 +103,7 @@ module Bundler # # @see {Bundler::PermissionError} def filesystem_access(path, action = :write, &block) - # Use block.call instead of yield because of a bug in Ruby 2.2.2 - # See https://github.com/bundler/bundler/issues/5341 for details - block.call(path.dup.untaint) + yield(path.dup.untaint) rescue Errno::EACCES raise PermissionError.new(path, action) rescue Errno::EAGAIN @@ -132,7 +130,7 @@ module Bundler 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 @@ -289,20 +287,10 @@ module Bundler 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 - - # Set BUNDLE_GEMFILE + 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 Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", find_gemfile(:order_matters).to_s Bundler::SharedHelpers.set_env "BUNDLER_VERSION", Bundler::VERSION end @@ -316,8 +304,9 @@ module Bundler def set_rubyopt rubyopt = [ENV["RUBYOPT"]].compact - return if !rubyopt.empty? && rubyopt.first =~ %r{-rbundler/setup} - rubyopt.unshift %(-rbundler/setup) + setup_require = "-r#{File.expand_path("setup", __dir__)}" + return if !rubyopt.empty? && rubyopt.first =~ /#{setup_require}/ + rubyopt.unshift %(#{setup_require}) Bundler::SharedHelpers.set_env "RUBYOPT", rubyopt.join(" ") end @@ -351,9 +340,9 @@ module Bundler 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.rb b/lib/bundler/source.rb index 26a3625bb1..4b2e305bda 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -2,11 +2,11 @@ module Bundler class Source - autoload :Gemspec, "bundler/source/gemspec" - autoload :Git, "bundler/source/git" - autoload :Metadata, "bundler/source/metadata" - autoload :Path, "bundler/source/path" - autoload :Rubygems, "bundler/source/rubygems" + autoload :Gemspec, File.expand_path("source/gemspec", __dir__) + autoload :Git, File.expand_path("source/git", __dir__) + autoload :Metadata, File.expand_path("source/metadata", __dir__) + autoload :Path, File.expand_path("source/path", __dir__) + autoload :Rubygems, File.expand_path("source/rubygems", __dir__) attr_accessor :dependency_names diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index a8afb341d8..ed16f4a4e0 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require "bundler/vendored_fileutils" +require_relative "../vendored_fileutils" require "uri" module Bundler class Source class Git < Path - autoload :GitProxy, "bundler/source/git/git_proxy" + autoload :GitProxy, File.expand_path("git/git_proxy", __dir__) attr_reader :uri, :ref, :branch, :options, :submodules diff --git a/lib/bundler/source/metadata.rb b/lib/bundler/source/metadata.rb index 559b912ffd..0867879861 100644 --- a/lib/bundler/source/metadata.rb +++ b/lib/bundler/source/metadata.rb @@ -13,10 +13,13 @@ module Bundler idx << Gem::Specification.new do |s| s.name = "bundler" s.version = VERSION + s.license = "MIT" s.platform = Gem::Platform::RUBY s.source = self s.authors = ["bundler team"] s.bindir = "exe" + s.homepage = "https://bundler.io" + s.summary = "The best way to manage your application's dependencies" s.executables = %w[bundle] # can't point to the actual gemspec or else the require paths will be wrong s.loaded_from = File.expand_path("..", __FILE__) diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index 5f3f1bc2e4..c1d25fc4da 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -3,7 +3,7 @@ module Bundler class Source class Path < Source - autoload :Installer, "bundler/source/path/installer" + autoload :Installer, File.expand_path("path/installer", __dir__) attr_reader :path, :options, :root_path, :original_path attr_writer :name diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 86fd329089..103faa6b80 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -6,7 +6,7 @@ require "rubygems/user_interaction" module Bundler class Source class Rubygems < Source - autoload :Remote, "bundler/source/rubygems/remote" + autoload :Remote, File.expand_path("rubygems/remote", __dir__) # Use the API when installing less than X gems API_REQUEST_LIMIT = 500 diff --git a/lib/bundler/stub_specification.rb b/lib/bundler/stub_specification.rb index bef94b505e..bad69c9a14 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 @@ -55,8 +55,6 @@ module Bundler stub.full_require_paths end - # This is what we do in bundler/rubygems_ext - # full_require_paths is always implemented def load_paths full_require_paths end diff --git a/lib/bundler/templates/newgem/newgem.gemspec.tt b/lib/bundler/templates/newgem/newgem.gemspec.tt index 5505540b9e..18060942c3 100644 --- a/lib/bundler/templates/newgem/newgem.gemspec.tt +++ b/lib/bundler/templates/newgem/newgem.gemspec.tt @@ -1,6 +1,4 @@ -lib = File.expand_path("lib", __dir__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "<%= config[:namespaced_path] %>/version" +require_relative 'lib/<%=config[:namespaced_path]%>/version' Gem::Specification.new do |spec| spec.name = <%= config[:name].inspect %> diff --git a/lib/bundler/ui.rb b/lib/bundler/ui.rb index 8138b30d38..7a4fa03669 100644 --- a/lib/bundler/ui.rb +++ b/lib/bundler/ui.rb @@ -2,8 +2,8 @@ module Bundler module UI - autoload :RGProxy, "bundler/ui/rg_proxy" - autoload :Shell, "bundler/ui/shell" - autoload :Silent, "bundler/ui/silent" + autoload :RGProxy, File.expand_path("ui/rg_proxy", __dir__) + autoload :Shell, File.expand_path("ui/shell", __dir__) + autoload :Silent, File.expand_path("ui/silent", __dir__) end end diff --git a/lib/bundler/ui/rg_proxy.rb b/lib/bundler/ui/rg_proxy.rb index e2f98481db..ef6def225b 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 16e3d15713..8e49fa5885 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 @@ -35,14 +35,12 @@ module Bundler return if @warning_history.include? msg @warning_history << msg - return tell_err(msg, :yellow, newline) if Bundler.feature_flag.error_on_stderr? - tell_me(msg, :yellow, newline) + tell_err(msg, :yellow, newline) end def error(msg, newline = nil) return unless level("error") - return tell_err(msg, :red, newline) if Bundler.feature_flag.error_on_stderr? - tell_me(msg, :red, newline) + tell_err(msg, :red, newline) end def debug(msg, newline = nil) diff --git a/lib/bundler/uri_credentials_filter.rb b/lib/bundler/uri_credentials_filter.rb index ee3692268c..0f6ea4cefa 100644 --- a/lib/bundler/uri_credentials_filter.rb +++ b/lib/bundler/uri_credentials_filter.rb @@ -2,7 +2,7 @@ module Bundler module URICredentialsFilter - module_function + module_function # rubocop:disable Layout/AccessModifierIndentation def credential_filtered_uri(uri_to_anonymize) return uri_to_anonymize if uri_to_anonymize.nil? diff --git a/lib/bundler/vendor/fileutils/lib/fileutils.rb b/lib/bundler/vendor/fileutils/lib/fileutils.rb index fb7777eb49..6fbe741498 100644 --- a/lib/bundler/vendor/fileutils/lib/fileutils.rb +++ b/lib/bundler/vendor/fileutils/lib/fileutils.rb @@ -6,7 +6,7 @@ rescue LoadError # for make mjit-headers end -require "bundler/vendor/fileutils/lib/fileutils/version" +require_relative "fileutils/version" # # = fileutils.rb diff --git a/lib/bundler/vendor/molinillo/lib/molinillo.rb b/lib/bundler/vendor/molinillo/lib/molinillo.rb index 9e2867144f..baedefe98b 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'bundler/vendor/molinillo/lib/molinillo/compatibility' -require 'bundler/vendor/molinillo/lib/molinillo/gem_metadata' -require 'bundler/vendor/molinillo/lib/molinillo/errors' -require 'bundler/vendor/molinillo/lib/molinillo/resolver' -require 'bundler/vendor/molinillo/lib/molinillo/modules/ui' -require 'bundler/vendor/molinillo/lib/molinillo/modules/specification_provider' +require_relative 'molinillo/compatibility' +require_relative 'molinillo/gem_metadata' +require_relative 'molinillo/errors' +require_relative 'molinillo/resolver' +require_relative 'molinillo/modules/ui' +require_relative 'molinillo/modules/specification_provider' # Bundler::Molinillo is a generic dependency resolution algorithm. module Bundler::Molinillo diff --git a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb index 677a8bd916..31578bb5bf 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb @@ -3,8 +3,8 @@ require 'set' require 'tsort' -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/log' -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex' +require_relative 'dependency_graph/log' +require_relative 'dependency_graph/vertex' module Bundler::Molinillo # A directed acyclic graph that is tuned to hold named dependencies diff --git a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb index 9849aea2fe..946a08236e 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/action' +require_relative 'action' module Bundler::Molinillo class DependencyGraph # @!visibility private diff --git a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb index 0a1e08255b..483527daf8 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/action' +require_relative 'action' module Bundler::Molinillo class DependencyGraph # @!visibility private diff --git a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb index 1d9f4b327d..d81940585a 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/action' +require_relative 'action' module Bundler::Molinillo class DependencyGraph # @!visibility private diff --git a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb index 385dcbdd06..36fce7c526 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/action' +require_relative 'action' module Bundler::Molinillo class DependencyGraph # @!visibility private diff --git a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb index 8582dd19c1..6f0de19886 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular' -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex' -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge' -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named' -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload' -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag' +require_relative 'add_edge_no_circular' +require_relative 'add_vertex' +require_relative 'delete_edge' +require_relative 'detach_vertex_named' +require_relative 'set_payload' +require_relative 'tag' module Bundler::Molinillo class DependencyGraph diff --git a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb index 37286d104a..2e9b90e6cd 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/action' +require_relative 'action' module Bundler::Molinillo class DependencyGraph # @!visibility private diff --git a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb index d6ad16e07a..fccfc78cc7 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/action' +require_relative 'action' module Bundler::Molinillo class DependencyGraph # @!visibility private diff --git a/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb b/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb index ce0931f103..89c7c324d5 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb @@ -80,7 +80,7 @@ module Bundler::Molinillo @specification_provider = specification_provider end - require 'bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider' + require_relative 'delegates/specification_provider' include Delegates::SpecificationProvider # @return [String] An error message that includes requirement trees, diff --git a/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb b/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb index 0eb665d17a..acf7777414 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb @@ -238,11 +238,11 @@ module Bundler::Molinillo debug { 'Activated: ' + Hash[activated.vertices.select { |_n, v| v.payload }].keys.join(', ') } if state end - require 'bundler/vendor/molinillo/lib/molinillo/state' - require 'bundler/vendor/molinillo/lib/molinillo/modules/specification_provider' + require_relative 'state' + require_relative 'modules/specification_provider' - require 'bundler/vendor/molinillo/lib/molinillo/delegates/resolution_state' - require 'bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider' + require_relative 'delegates/resolution_state' + require_relative 'delegates/specification_provider' include Bundler::Molinillo::Delegates::ResolutionState include Bundler::Molinillo::Delegates::SpecificationProvider diff --git a/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb b/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb index 7d36858778..95eaab5991 100644 --- a/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +++ b/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph' +require_relative 'dependency_graph' module Bundler::Molinillo # This class encapsulates a dependency resolver. @@ -9,7 +9,7 @@ module Bundler::Molinillo # # class Resolver - require 'bundler/vendor/molinillo/lib/molinillo/resolution' + require_relative 'resolution' # @return [SpecificationProvider] the specification provider used # in the resolution process diff --git a/lib/bundler/vendor/thor/lib/thor/base.rb b/lib/bundler/vendor/thor/lib/thor/base.rb index e79d03d087..f55b14fbfc 100644 --- a/lib/bundler/vendor/thor/lib/thor/base.rb +++ b/lib/bundler/vendor/thor/lib/thor/base.rb @@ -9,9 +9,9 @@ require "bundler/vendor/thor/lib/thor/line_editor" require "bundler/vendor/thor/lib/thor/util" class Bundler::Thor - autoload :Actions, "bundler/vendor/thor/lib/thor/actions" - autoload :RakeCompat, "bundler/vendor/thor/lib/thor/rake_compat" - autoload :Group, "bundler/vendor/thor/lib/thor/group" + autoload :Actions, File.expand_path("actions", __dir__) + autoload :RakeCompat, File.expand_path("rake_compat", __dir__) + autoload :Group, File.expand_path("group", __dir__) # Shortcuts for help. HELP_MAPPINGS = %w(-h -? --help -D) diff --git a/lib/bundler/vendor/thor/lib/thor/shell.rb b/lib/bundler/vendor/thor/lib/thor/shell.rb index a68cdf8a98..e36fa472d6 100644 --- a/lib/bundler/vendor/thor/lib/thor/shell.rb +++ b/lib/bundler/vendor/thor/lib/thor/shell.rb @@ -24,9 +24,9 @@ class Bundler::Thor SHELL_DELEGATED_METHODS = [:ask, :error, :set_color, :yes?, :no?, :say, :say_status, :print_in_columns, :print_table, :print_wrapped, :file_collision, :terminal_width] attr_writer :shell - autoload :Basic, "bundler/vendor/thor/lib/thor/shell/basic" - autoload :Color, "bundler/vendor/thor/lib/thor/shell/color" - autoload :HTML, "bundler/vendor/thor/lib/thor/shell/html" + autoload :Basic, File.expand_path("shell/basic", __dir__) + autoload :Color, File.expand_path("shell/color", __dir__) + autoload :HTML, File.expand_path("shell/html", __dir__) # Add shell to initialize config values. # diff --git a/lib/bundler/vendored_fileutils.rb b/lib/bundler/vendored_fileutils.rb index d14e98baf7..4b71759224 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 061b634f72..d1976f5cb4 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 de9c42fcc1..7670b83992 100644 --- a/lib/bundler/vendored_persistent.rb +++ b/lib/bundler/vendored_persistent.rb @@ -15,7 +15,7 @@ module Bundler 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 8cca090f55..b0b7e7be84 100644 --- a/lib/bundler/vendored_thor.rb +++ b/lib/bundler/vendored_thor.rb @@ -5,4 +5,4 @@ module Bundler 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/version.rb b/lib/bundler/version.rb index cfd6300950..21eeeb0fd4 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,23 +1,7 @@ # frozen_string_literal: false module Bundler - # We're doing this because we might write tests that deal - # with other versions of bundler and we are unsure how to - # handle this better. - VERSION = "2.1.0.pre.1".freeze unless defined?(::Bundler::VERSION) - - def self.overwrite_loaded_gem_version - begin - require "rubygems" - rescue LoadError - return - end - return unless bundler_spec = Gem.loaded_specs["bundler"] - return if bundler_spec.version == VERSION - bundler_spec.version = Bundler::VERSION - end - private_class_method :overwrite_loaded_gem_version - overwrite_loaded_gem_version + VERSION = "2.1.0.pre.1".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i diff --git a/lib/bundler/vlad.rb b/lib/bundler/vlad.rb index 68181e7db8..538e8c3e74 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 @@ Bundler::SharedHelpers.major_deprecation 2, # # 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 diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb index 374b3bb5e3..1965853931 100644 --- a/lib/bundler/yaml_serializer.rb +++ b/lib/bundler/yaml_serializer.rb @@ -3,7 +3,7 @@ module Bundler # A stub yaml serializer that can handle only hashes and strings (as of now). module YAMLSerializer - module_function + module_function # rubocop:disable Layout/AccessModifierIndentation def dump(hash) yaml = String.new("---") |