Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename default: to active: #3

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions lib/bundler/multilock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class << self
# @param builder [Dsl] The Bundler DSL
# @param gemfile [String, nil]
# The Gemfile for this lockfile (defaults to Gemfile)
# @param default [Boolean]
# @param active [Boolean]
# If this lockfile should be the default (instead of Gemfile.lock)
# BUNDLE_LOCKFILE will still override a lockfile tagged as active
# @param allow_mismatched_dependencies [true, false]
# Allows version differences in dependencies between this lockfile and
# the default lockfile. Note that even with this option, only top-level
Expand All @@ -32,20 +33,20 @@ class << self
# default lockfile, enforce that they are pinned.
# @yield
# Block executed only when this lockfile is active.
# @return [true, false] if the lockfile is the current lockfile
# @return [true, false] if the lockfile is the active lockfile
def add_lockfile(lockfile = nil,
builder:,
gemfile: nil,
active: nil,
default: nil,
allow_mismatched_dependencies: true,
enforce_pinned_additional_dependencies: false,
&block)
# terminology gets confusing here. The "default" param means
# "use this lockfile when not overridden by BUNDLE_LOCKFILE"
# but Bundler.defaul_lockfile (usually) means "Gemfile.lock"
# so refer to the former as "current" internally
current = default
current = true if current.nil? && lockfile_definitions.empty? && lockfile.nil? && gemfile.nil?
# backcompat
active = default if active.nil?
Bundler.ui.warn("lockfile(default:) is deprecated. Use lockfile(active:) instead.") if default

active = true if active.nil? && lockfile_definitions.empty? && lockfile.nil? && gemfile.nil?

# allow short-form lockfile names
if lockfile.is_a?(String) && !(lockfile.include?("/") || lockfile.end_with?(".lock"))
Expand All @@ -67,17 +68,17 @@ def add_lockfile(lockfile = nil,
env_lockfile = "Gemfile.#{env_lockfile}.lock"
end
env_lockfile = Bundler.root.join(env_lockfile).expand_path
current = env_lockfile == lockfile
active = env_lockfile == lockfile
end

if current && (old_current = lockfile_definitions.find { |definition| definition[:current] })
raise ArgumentError, "Only one lockfile (#{old_current[:lockfile]}) can be flagged as the default"
if active && (old_active = lockfile_definitions.find { |definition| definition[:active] })
raise ArgumentError, "Only one lockfile (#{old_active[:lockfile]}) can be flagged as the default"
end

lockfile_definitions << (lockfile_def = {
gemfile: (gemfile && Bundler.root.join(gemfile).expand_path) || Bundler.default_gemfile,
lockfile: lockfile,
current: current,
active: active,
prepare: block,
allow_mismatched_dependencies: allow_mismatched_dependencies,
enforce_pinned_additional_dependencies: enforce_pinned_additional_dependencies
Expand All @@ -94,10 +95,10 @@ def add_lockfile(lockfile = nil,
# 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
current = lockfile == Bundler.default_lockfile(force_original: true)
active = lockfile == Bundler.default_lockfile(force_original: true)
end

if current
if active
block&.call
Bundler.default_lockfile = lockfile

Expand Down Expand Up @@ -297,9 +298,9 @@ def loaded!
@loaded = true
return if lockfile_definitions.empty?

return unless lockfile_definitions.none? { |definition| definition[:current] }
return unless lockfile_definitions.none? { |definition| definition[:active] }

# Gemfile.lock isn't explicitly specified, otherwise it would be current
# Gemfile.lock isn't explicitly specified, otherwise it would be active
default_lockfile_definition = lockfile_definitions.find do |definition|
definition[:lockfile] == Bundler.default_lockfile(force_original: true)
end
Expand All @@ -309,7 +310,7 @@ def loaded!

raise GemfileNotFound, "Could not locate lockfile #{ENV["BUNDLE_LOCKFILE"].inspect}" if ENV["BUNDLE_LOCKFILE"]

return unless default_lockfile_definition && default_lockfile_definition[:current] == false
return unless default_lockfile_definition && default_lockfile_definition[:active] == false

raise GemfileEvalError, "No lockfiles marked as default"
end
Expand Down