bundler-multilock 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67b3efef0037c3c22b0b8fccee25a6388b3cc3aa38b92dc2dfdc956b2eca01e8
4
- data.tar.gz: e12da2edaeacc80d5d5b90108a333c1d195be6d0784618ab40ebe5d5807981fc
3
+ metadata.gz: c84016021b1c7595a4e796a80de94d7df2160f016c4bdc286f1616c61bb09170
4
+ data.tar.gz: 8b8ed6c345db6beb1fdf681e603ffee395d39459fc5a81982f1457876bea4037
5
5
  SHA512:
6
- metadata.gz: 64f62f4d2d35d55cacb8d751be9708d56f4d60348c69faa61f8ea8c48a0ff273fd355238fe71175e0d36c2ad7cbe6f55e225fb6ea56be8361d258d5cb6ae45d8
7
- data.tar.gz: 393ca25f67035f032b83442e7dd7bf5a4cec5002f72c94eb1f42a3d962117f79a39e029e1280c845520af398fc7b68d4cbd5d2dd60ab9d6181891a1ee10ab36b
6
+ metadata.gz: 4eb1334a6a9860cea9fbb7ece25741bc35f9dd3e44ab6a17bbf041998116445acf53173a7372f6c1f19dedf1538f1bccc0db859123493b5addae86d134f81146
7
+ data.tar.gz: 6bc840a4f41344443609f00447e87c95a89eab942446b5dd2598e55bcd15a79a7fcdb3952a4e417ce7664e50316073defdb627bba2da1b886323c0d92292d345
@@ -58,7 +58,7 @@ module Bundler
58
58
 
59
59
  # this is mostly equivalent to the built in checks in `bundle check`, but even
60
60
  # more conservative, and returns false instead of exiting on failure
61
- def base_check(lockfile_definition, log_missing: false, return_missing: false)
61
+ def base_check(lockfile_definition, log_missing: false, return_missing: false, check_missing_deps: false)
62
62
  return return_missing ? [] : false unless lockfile_definition[:lockfile].file?
63
63
 
64
64
  Multilock.prepare_block = lockfile_definition[:prepare]
@@ -83,14 +83,17 @@ module Bundler
83
83
 
84
84
  return not_installed if return_missing
85
85
 
86
- not_installed.empty? && definition.no_resolve_needed?
86
+ return false unless not_installed.empty? && definition.no_resolve_needed?
87
+ return true unless check_missing_deps
88
+
89
+ (definition.locked_gems.dependencies.values - definition.dependencies).empty?
87
90
  ensure
88
91
  Multilock.prepare_block = nil
89
92
  end
90
93
 
91
94
  # this checks for mismatches between the parent lockfile and the given lockfile,
92
95
  # and for pinned dependencies in lockfiles requiring them
93
- def check(lockfile_definition, allow_mismatched_dependencies: true)
96
+ def check(lockfile_definition)
94
97
  success = true
95
98
  proven_pinned = Set.new
96
99
  needs_pin_check = []
@@ -109,36 +112,8 @@ module Bundler
109
112
  success = false
110
113
  end
111
114
 
112
- specs = lockfile.specs.group_by(&:name)
113
- if allow_mismatched_dependencies
114
- allow_mismatched_dependencies = lockfile_definition[:allow_mismatched_dependencies]
115
- end
116
-
117
- # build list of top-level dependencies that differ from the parent lockfile,
118
- # and all _their_ transitive dependencies
119
- if allow_mismatched_dependencies
120
- transitive_dependencies = Set.new
121
- # only dependencies that differ from the parent lockfile
122
- pending_transitive_dependencies = lockfile.dependencies.reject do |name, dep|
123
- parent_lockfile.dependencies[name] == dep
124
- end.map(&:first)
125
-
126
- until pending_transitive_dependencies.empty?
127
- dep = pending_transitive_dependencies.shift
128
- next if transitive_dependencies.include?(dep)
129
-
130
- transitive_dependencies << dep
131
- platform_specs = specs[dep]
132
- unless platform_specs
133
- # should only be bundler that's missing a spec
134
- raise "Could not find spec for dependency #{dep}" unless dep == "bundler"
135
-
136
- next
137
- end
138
-
139
- pending_transitive_dependencies.concat(platform_specs.flat_map(&:dependencies).map(&:name).uniq)
140
- end
141
- end
115
+ reverse_dependencies = cache_reverse_dependencies(lockfile)
116
+ parent_reverse_dependencies = cache_reverse_dependencies(parent_lockfile)
142
117
 
143
118
  # look through top-level explicit dependencies for pinned requirements
144
119
  if lockfile_definition[:enforce_pinned_additional_dependencies]
@@ -146,7 +121,7 @@ module Bundler
146
121
  end
147
122
 
148
123
  # check for conflicting requirements (and build list of pins, in the same loop)
149
- specs.values.flatten.each do |spec|
124
+ lockfile.specs.each do |spec|
150
125
  parent_spec = lockfile_specs[parent][[spec.name, spec.platform]]
151
126
 
152
127
  if lockfile_definition[:enforce_pinned_additional_dependencies]
@@ -170,7 +145,15 @@ module Bundler
170
145
  end
171
146
 
172
147
  next if parent_spec.version == spec.version && same_source
173
- next if allow_mismatched_dependencies && transitive_dependencies.include?(spec.name)
148
+
149
+ # the version in the parent lockfile cannot possibly satisfy the requirements
150
+ # in this lockfile, and vice versa, so we assume it's intentional and allow it
151
+ unless reverse_dependencies[spec.name].satisfied_by?(parent_spec.version) ||
152
+ parent_reverse_dependencies[spec.name].satisfied_by?(spec.version)
153
+ # we're allowing it to differ from the parent, so pin check requirement comes into play
154
+ needs_pin_check << spec if lockfile_definition[:enforce_pinned_additional_dependencies]
155
+ next
156
+ end
174
157
 
175
158
  Bundler.ui.error("#{spec}#{spec.git_version} in #{lockfile_path} " \
176
159
  "does not match the parent lockfile's version " \
@@ -206,6 +189,21 @@ module Bundler
206
189
 
207
190
  private
208
191
 
192
+ def cache_reverse_dependencies(lockfile)
193
+ reverse_dependencies = Hash.new { |h, k| h[k] = Gem::Requirement.default_prerelease }
194
+
195
+ lockfile.dependencies.each_value do |spec|
196
+ reverse_dependencies[spec.name].requirements.concat(spec.requirement.requirements)
197
+ end
198
+ lockfile.specs.each do |spec|
199
+ spec.dependencies.each do |dependency|
200
+ reverse_dependencies[dependency.name].requirements.concat(dependency.requirement.requirements)
201
+ end
202
+ end
203
+
204
+ reverse_dependencies
205
+ end
206
+
209
207
  def find_pinned_dependencies(proven_pinned, dependencies)
210
208
  dependencies.each do |dependency|
211
209
  dependency.requirement.requirements.each do |requirement|
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bundler
4
4
  module Multilock
5
- VERSION = "1.1.2"
5
+ VERSION = "1.2.0"
6
6
  end
7
7
  end
@@ -27,11 +27,6 @@ module Bundler
27
27
  # BUNDLE_LOCKFILE will still override a lockfile tagged as active
28
28
  # @param parent [String] The parent lockfile to sync dependencies from.
29
29
  # Also used for comparing enforce_pinned_additional_dependencies against.
30
- # @param allow_mismatched_dependencies [true, false]
31
- # Allows version differences in dependencies between this lockfile and
32
- # the default lockfile. Note that even with this option, only top-level
33
- # dependencies that differ from the default lockfile, and their transitive
34
- # depedencies, are allowed to mismatch.
35
30
  # @param enforce_pinned_additional_dependencies [true, false]
36
31
  # If dependencies are present in this lockfile that are not present in the
37
32
  # default lockfile, enforce that they are pinned.
@@ -44,12 +39,15 @@ module Bundler
44
39
  active: nil,
45
40
  default: nil,
46
41
  parent: nil,
47
- allow_mismatched_dependencies: true,
42
+ allow_mismatched_dependencies: nil,
48
43
  enforce_pinned_additional_dependencies: false,
49
44
  &block)
50
45
  # backcompat
51
46
  active = default if active.nil?
52
47
  Bundler.ui.warn("lockfile(default:) is deprecated. Use lockfile(active:) instead.") if default
48
+ unless allow_mismatched_dependencies.nil?
49
+ Bundler.ui.warn("lockfile(allow_mismatched_dependencies:) is deprecated.")
50
+ end
53
51
 
54
52
  active = true if active.nil? && lockfile_definitions.empty? && lockfile.nil? && gemfile.nil?
55
53
 
@@ -81,7 +79,6 @@ module Bundler
81
79
  active: active,
82
80
  prepare: block,
83
81
  parent: parent,
84
- allow_mismatched_dependencies: allow_mismatched_dependencies,
85
82
  enforce_pinned_additional_dependencies: enforce_pinned_additional_dependencies
86
83
  })
87
84
 
@@ -149,7 +146,6 @@ module Bundler
149
146
  require_relative "multilock/lockfile_generator"
150
147
 
151
148
  Bundler.ui.debug("Syncing to alternate lockfiles")
152
- Bundler.ui.info ""
153
149
 
154
150
  attempts = 1
155
151
 
@@ -171,8 +167,8 @@ module Bundler
171
167
  up_to_date = false
172
168
  Bundler.settings.temporary(frozen: true) do
173
169
  Bundler.ui.silence do
174
- up_to_date = checker.base_check(lockfile_definition) &&
175
- checker.check(lockfile_definition, allow_mismatched_dependencies: false)
170
+ up_to_date = checker.base_check(lockfile_definition, check_missing_deps: true) &&
171
+ checker.check(lockfile_definition)
176
172
  end
177
173
  end
178
174
  if up_to_date
@@ -426,9 +422,16 @@ module Bundler
426
422
 
427
423
  orig_definition = definition.dup # we might need it twice
428
424
 
425
+ # install gems for the exact current version of the lockfile
426
+ # this ensures it doesn't re-resolve with only (different)
427
+ # local gems after you've pulled down an update to the lockfile
428
+ # from someone else
429
429
  if current_lockfile.exist? && install
430
430
  Bundler.settings.temporary(frozen: true) do
431
431
  current_definition = builder.to_definition(current_lockfile, {})
432
+ # if something has changed, we skip this step; it's unlocking anyway
433
+ next unless current_definition.no_resolve_needed?
434
+
432
435
  current_definition.resolve_with_cache!
433
436
  if current_definition.missing_specs.any?
434
437
  Bundler.with_default_lockfile(current_lockfile) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler-multilock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Instructure
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-06 00:00:00.000000000 Z
11
+ date: 2023-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler