diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 86e2d6b..e2ad06e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,13 +13,13 @@ jobs: strategy: fail-fast: false matrix: - ruby-version: [2.6, 2.7, "3.0", 3.1, 3.2] - bundler-version: [2.4.19, 2.4.22, 2.5.9] + ruby-version: [2.6, 2.7, "3.0", 3.1, 3.2, 3.3] + bundler-version: [2.4.19, 2.4.22, 2.5.10] exclude: - ruby-version: 2.6 - bundler-version: 2.5.9 + bundler-version: 2.5.10 - ruby-version: 2.7 - bundler-version: 2.5.9 + bundler-version: 2.5.10 env: BUNDLER_VERSION: ${{ matrix.bundler-version }} BUNDLE_LOCKFILE: active diff --git a/Gemfile.lock b/Gemfile.lock index 1970025..b419586 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -102,4 +102,4 @@ DEPENDENCIES stringio (~> 3.1) BUNDLED WITH - 2.5.9 + 2.5.10 diff --git a/Gemfile.ruby-2.6.lock b/Gemfile.ruby-2.6.lock index 4c7bdb0..7bf465c 100644 --- a/Gemfile.ruby-2.6.lock +++ b/Gemfile.ruby-2.6.lock @@ -50,4 +50,4 @@ DEPENDENCIES stringio (= 3.0.6) BUNDLED WITH - 2.5.9 + 2.5.10 diff --git a/lib/bundler/multilock.rb b/lib/bundler/multilock.rb index 828b584..b5cfa59 100644 --- a/lib/bundler/multilock.rb +++ b/lib/bundler/multilock.rb @@ -82,17 +82,13 @@ def add_lockfile(lockfile = nil, enforce_pinned_additional_dependencies: enforce_pinned_additional_dependencies }) - if (defined?(CLI::Check) || - defined?(CLI::Install) || - defined?(CLI::Lock) || - defined?(CLI::Update)) && - !defined?(CLI::Cache) && !env_lockfile + # If they're using BUNDLE_LOCKFILE, then they really do want to + # use a particular lockfile, and it overrides whatever they + # dynamically set in their gemfile + if !env_lockfile && defined?(CLI) && + %i[check install lock update].include?(CLI.instance&.current_command_chain&.first) # always use Gemfile.lock for `bundle check`, `bundle install`, - # `bundle lock`, and `bundle update`. `bundle cache` delegates to - # `bundle install`, but we want that to run as normal. - # If they're using BUNDLE_LOCKFILE, then they really do want to - # use a particular lockfile, and it overrides whatever they - # dynamically set in their gemfile + # `bundle lock`, and `bundle update`. active = lockfile == Bundler.default_lockfile(force_original: true) end @@ -577,25 +573,29 @@ def write_lockfile(lockfile_definition, Bundler::LazySpecification.include(Bundler::MatchMetadata) if defined?(Bundler::MatchMetadata) Bundler::Multilock.inject_preamble unless Bundler::Multilock.loaded? -# this is terrible, but we can't prepend into these modules because we only load -# _inside_ of the CLI commands already running -if defined?(Bundler::CLI::Check) - require_relative "multilock/check" - at_exit do - next unless $!.nil? - next if $!.is_a?(SystemExit) && !$!.success? +if defined?(Bundler::CLI) + require_relative "multilock/ext/cli" - next if Bundler::Multilock::Check.run + # this is terrible, but we can't prepend into these modules because we only load + # _inside_ of the CLI commands already running + if Bundler::CLI.instance&.current_command_chain&.first == :check + require_relative "multilock/check" + at_exit do + next unless $!.nil? + next if $!.is_a?(SystemExit) && !$!.success? - Bundler.ui.warn("You can attempt to fix by running `bundle install`") - exit 1 + next if Bundler::Multilock::Check.run + + Bundler.ui.warn("You can attempt to fix by running `bundle install`") + exit 1 + end end -end -if defined?(Bundler::CLI::Lock) - at_exit do - next unless $!.nil? - next if $!.is_a?(SystemExit) && !$!.success? + if Bundler::CLI.instance&.current_command_chain&.first == :lock + at_exit do + next unless $!.nil? + next if $!.is_a?(SystemExit) && !$!.success? - Bundler::Multilock.after_install_all(install: false) + Bundler::Multilock.after_install_all(install: false) + end end end diff --git a/lib/bundler/multilock/ext/cli.rb b/lib/bundler/multilock/ext/cli.rb new file mode 100644 index 0000000..b25672f --- /dev/null +++ b/lib/bundler/multilock/ext/cli.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Bundler + module Multilock + module Ext + module CLI + module ClassMethods + def instance + return @instance if instance_variable_defined?(:@instance) + + # this is a little icky, but there's no other way to determine which command was run + @instance = ObjectSpace.each_object(::Bundler::CLI).first + end + end + + ::Bundler::CLI.extend(ClassMethods) + end + end + end +end