@@ -58,17 +58,28 @@ def self.build(gemfile, lockfile, unlock)
5858 # @param ruby_version [Bundler::RubyVersion, nil] Requested Ruby Version
5959 # @param optional_groups [Array(String)] A list of optional groups
6060 def initialize ( lockfile , dependencies , sources , unlock , ruby_version = nil , optional_groups = [ ] , gemfiles = [ ] )
61- if [ true , false ] . include? ( unlock )
61+ unlock ||= { }
62+
63+ if unlock == true
64+ @unlocking_all = true
6265 @unlocking_bundler = false
6366 @unlocking = unlock
67+ @sources_to_unlock = [ ]
68+ @unlocking_ruby = false
69+ @explicit_unlocks = [ ]
70+ conservative = false
6471 else
72+ @unlocking_all = false
6573 @unlocking_bundler = unlock . delete ( :bundler )
6674 @unlocking = unlock . any? { |_k , v | !Array ( v ) . empty? }
75+ @sources_to_unlock = unlock . delete ( :sources ) || [ ]
76+ @unlocking_ruby = unlock . delete ( :ruby )
77+ @explicit_unlocks = unlock . delete ( :gems ) || [ ]
78+ conservative = unlock . delete ( :conservative )
6779 end
6880
6981 @dependencies = dependencies
7082 @sources = sources
71- @unlock = unlock
7283 @optional_groups = optional_groups
7384 @prefer_local = false
7485 @specs = nil
@@ -97,17 +108,15 @@ def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, opti
97108 @originally_locked_specs = SpecSet . new ( @locked_gems . specs )
98109 @locked_checksums = @locked_gems . checksums
99110
100- if unlock != true
101- @locked_specs = @originally_locked_specs
102- @locked_sources = @locked_gems . sources
103- else
104- @unlock = { }
111+ if @unlocking_all
105112 @locked_specs = SpecSet . new ( [ ] )
106113 @locked_sources = [ ]
114+ else
115+ @locked_specs = @originally_locked_specs
116+ @locked_sources = @locked_gems . sources
107117 end
108118 else
109- @unlock = { }
110- @locked_gems = nil
119+ @locked_gems = nil
111120 @locked_platforms = [ ]
112121 @most_specific_locked_platform = nil
113122 @platforms = [ ]
@@ -131,21 +140,18 @@ def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, opti
131140 @sources . merged_gem_lockfile_sections! ( locked_gem_sources . first )
132141 end
133142
134- @sources_to_unlock = @unlock . delete ( :sources ) || [ ]
135- @unlock [ :ruby ] ||= if @ruby_version && locked_ruby_version_object
143+ @unlocking_ruby ||= if @ruby_version && locked_ruby_version_object
136144 @ruby_version . diff ( locked_ruby_version_object )
137145 end
138- @unlocking ||= @unlock [ :ruby ] ||= ( !@locked_ruby_version ^ !@ruby_version )
146+ @unlocking ||= @unlocking_ruby ||= ( !@locked_ruby_version ^ !@ruby_version )
139147
140148 @current_platform_missing = add_current_platform unless Bundler . frozen_bundle?
141149
142150 converge_path_sources_to_gemspec_sources
143151 @path_changes = converge_paths
144152 @source_changes = converge_sources
145153
146- @explicit_unlocks = @unlock . delete ( :gems ) || [ ]
147-
148- if @unlock [ :conservative ]
154+ if conservative
149155 @gems_to_unlock = @explicit_unlocks . any? ? @explicit_unlocks : @dependencies . map ( &:name )
150156 else
151157 eager_unlock = @explicit_unlocks . map { |name | Dependency . new ( name , ">= 0" ) }
@@ -373,7 +379,7 @@ def lock(file_or_preserve_unknown_sections = false, preserve_unknown_sections_or
373379
374380 def locked_ruby_version
375381 return unless ruby_version
376- if @unlock [ :ruby ] || !@locked_ruby_version
382+ if @unlocking_ruby || !@locked_ruby_version
377383 Bundler ::RubyVersion . system
378384 else
379385 @locked_ruby_version
@@ -434,7 +440,7 @@ def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
434440 changed << "* #{ name } from `#{ lockfile_source_name } ` to `#{ gemfile_source_name } `"
435441 end
436442
437- reason = nothing_changed ? ? "some dependencies were deleted from your gemfile" : change_reason
443+ reason = resolve_needed ? ? change_reason : "some dependencies were deleted from your gemfile"
438444 msg = String . new
439445 msg << "#{ reason . capitalize . strip } , but the lockfile can't be updated because frozen mode is set"
440446 msg << "\n \n You have added to the Gemfile:\n " << added . join ( "\n " ) if added . any?
@@ -450,7 +456,7 @@ def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
450456 "freeze by running `#{ suggested_command } `." if suggested_command
451457 end
452458
453- raise ProductionError , msg if added . any? || deleted . any? || changed . any? || ! nothing_changed ?
459+ raise ProductionError , msg if added . any? || deleted . any? || changed . any? || resolve_needed ?
454460 end
455461
456462 def validate_runtime!
@@ -619,7 +625,7 @@ def resolution_packages
619625 @resolution_packages ||= begin
620626 last_resolve = converge_locked_specs
621627 remove_invalid_platforms!
622- packages = Resolver ::Base . new ( source_requirements , expanded_dependencies , last_resolve , @platforms , locked_specs : @originally_locked_specs , unlock : @gems_to_unlock , prerelease : gem_version_promoter . pre? , prefer_local : @prefer_local )
628+ packages = Resolver ::Base . new ( source_requirements , expanded_dependencies , last_resolve , @platforms , locked_specs : @originally_locked_specs , unlock : @unlocking_all || @ gems_to_unlock, prerelease : gem_version_promoter . pre? , prefer_local : @prefer_local , new_platforms : @new_platforms )
623629 packages = additional_base_requirements_to_prevent_downgrades ( packages , last_resolve )
624630 packages = additional_base_requirements_to_force_updates ( packages )
625631 packages
@@ -762,6 +768,7 @@ def add_current_platform
762768 @most_specific_non_local_locked_ruby_platform = find_most_specific_locked_ruby_platform
763769 return if @most_specific_non_local_locked_ruby_platform
764770
771+ @new_platforms << local_platform
765772 @platforms << local_platform
766773 true
767774 end
@@ -783,7 +790,7 @@ def change_reason
783790 unlock_reason = if unlock_targets
784791 "#{ unlock_targets . first } : (#{ unlock_targets . last . join ( ", " ) } )"
785792 else
786- @unlock [ :ruby ] ? "ruby" : ""
793+ @unlocking_ruby ? "ruby" : ""
787794 end
788795
789796 return "bundler is unlocking #{ unlock_reason } "
@@ -853,8 +860,6 @@ def converge_locals
853860 end
854861
855862 def check_lockfile
856- @missing_lockfile_dep = nil
857-
858863 @locked_spec_with_invalid_deps = nil
859864 @locked_spec_with_missing_deps = nil
860865
@@ -872,10 +877,6 @@ def check_lockfile
872877 @locked_specs . delete ( missing )
873878
874879 @locked_spec_with_missing_deps = missing . first . name
875- elsif !@dependency_changes
876- @missing_lockfile_dep = current_dependencies . find do |d |
877- @locked_specs [ d . name ] . empty? && d . name != "bundler"
878- end &.name
879880 end
880881
881882 if invalid . any?
@@ -936,21 +937,30 @@ def converge_sources
936937 end
937938
938939 def converge_dependencies
940+ @missing_lockfile_dep = nil
939941 changes = false
940942
941- @dependencies . each do |dep |
943+ current_dependencies . each do |dep |
942944 if dep . source
943945 dep . source = sources . get ( dep . source )
944946 end
945947
946- unless locked_dep = @locked_deps [ dep . name ]
947- changes = true
948- next
948+ name = dep . name
949+
950+ dep_changed = @locked_deps [ name ] . nil?
951+
952+ unless name == "bundler"
953+ locked_specs = @originally_locked_specs [ name ]
954+
955+ if locked_specs . any? && !dep . matches_spec? ( locked_specs . first )
956+ @gems_to_unlock << name
957+ dep_changed = true
958+ elsif locked_specs . empty? && dep_changed == false
959+ @missing_lockfile_dep = name
960+ end
949961 end
950962
951- # We already know the name matches from the hash lookup
952- # so we only need to check the requirement now
953- changes ||= dep . requirement != locked_dep . requirement
963+ changes ||= dep_changed
954964 end
955965
956966 changes
@@ -1015,11 +1025,6 @@ def converge_specs(specs)
10151025 end
10161026 end
10171027
1018- if dep . nil? && requested_dep = requested_dependencies . find { |d | name == d . name }
1019- @gems_to_unlock << name
1020- deps << requested_dep
1021- end
1022-
10231028 converged << s
10241029 end
10251030
0 commit comments