1 # frozen_string_literal: true
5 attr_reader :options, :gems
6 def initialize(options, gems)
12 Bundler.ui.level = "warn" if options[:quiet]
14 update_bundler = options[:bundler]
16 Bundler.self_manager.update_bundler_and_restart_with_it_if_needed(update_bundler) if update_bundler
18 Plugin.gemfile_install(Bundler.default_gemfile) if Bundler.feature_flag.plugins?
20 sources = Array(options[:source])
21 groups = Array(options[:group]).map(&:to_sym)
23 full_update = gems.empty? && sources.empty? && groups.empty? && !options[:ruby] && !update_bundler
25 if full_update && !options[:all]
26 if Bundler.feature_flag.update_requires_all_flag?
27 raise InvalidOption, "To update everything, pass the `--all` flag."
29 SharedHelpers.major_deprecation 3, "Pass --all to `bundle update` to update everything"
30 elsif !full_update && options[:all]
31 raise InvalidOption, "Cannot specify --all along with specific options."
34 conservative = options[:conservative]
38 Bundler.definition(conservative: conservative)
40 Bundler.definition(true)
43 unless Bundler.default_lockfile.exist?
44 raise GemfileLockNotFound, "This Bundle hasn't been installed yet. " \
45 "Run `bundle install` to update and install the bundled gems."
47 Bundler::CLI::Common.ensure_all_gems_in_lockfile!(gems)
50 deps = Bundler.definition.dependencies.select {|d| (d.groups & groups).any? }
51 gems.concat(deps.map(&:name))
54 Bundler.definition(gems: gems, sources: sources, ruby: options[:ruby],
55 conservative: conservative,
56 bundler: update_bundler)
59 Bundler::CLI::Common.configure_gem_version_promoter(Bundler.definition, options)
61 Bundler::Fetcher.disable_endpoint = options["full-index"]
65 opts["local"] = options[:local]
66 opts["force"] = options[:redownload]
68 Bundler.settings.set_command_option_if_given :jobs, opts["jobs"]
70 Bundler.definition.validate_runtime!
72 if locked_gems = Bundler.definition.locked_gems
73 previous_locked_info = locked_gems.specs.reduce({}) do |h, s|
74 h[s.name] = { spec: s, version: s.version, source: s.source.identifier }
79 installer = Installer.install Bundler.root, Bundler.definition, opts
80 Bundler.load.cache if Bundler.app_cache.exist?
82 if CLI::Common.clean_after_install?
83 require_relative "clean"
84 Bundler::CLI::Clean.new(options).run
89 locked_info = previous_locked_info[name]
90 next unless locked_info
92 locked_spec = locked_info[:spec]
93 new_spec = Bundler.definition.specs[name].first
95 unless locked_spec.match_platform(Bundler.local_platform)
96 Bundler.ui.warn "Bundler attempted to update #{name} but it was not considered because it is for a different platform from the current one"
102 locked_source = locked_info[:source]
103 new_source = new_spec.source.identifier
104 next if locked_source != new_source
106 new_version = new_spec.version
107 locked_version = locked_info[:version]
108 if new_version < locked_version
109 Bundler.ui.warn "Note: #{name} version regressed from #{locked_version} to #{new_version}"
110 elsif new_version == locked_version
111 Bundler.ui.warn "Bundler attempted to update #{name} but its version stayed the same"
116 Bundler.ui.confirm "Bundle updated!"
117 Bundler::CLI::Common.output_without_groups_message(:update)
118 Bundler::CLI::Common.output_post_install_messages installer.post_install_messages
120 Bundler::CLI::Common.output_fund_metadata_summary