spm_version_updates 1.2.0 → 3.0.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 +4 -4
- data/README.md +11 -10
- data/lib/spm_version_updates/fail_on_threshold.rb +7 -12
- data/lib/spm_version_updates/manifest_parser.rb +183 -35
- data/lib/spm_version_updates/manifest_updater.rb +481 -0
- data/lib/spm_version_updates/package_resolved.rb +23 -6
- data/lib/spm_version_updates/repository_update_rules.rb +19 -19
- data/lib/spm_version_updates/semver.rb +1 -1
- data/lib/spm_version_updates/spm_checker.rb +245 -34
- data/lib/spm_version_updates/version.rb +1 -1
- data/lib/spm_version_updates.rb +1 -0
- data/spm_version_updates.gemspec +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9b4efc6dc58bca7ff71479a38ce2d19afd304a3e973743d93902fa287734338f
|
|
4
|
+
data.tar.gz: b1444c96937f9acfa63f308aa72de2173b23b6c4452133d2e3f2ceea75247be5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bad397741c32d137d087ff997a35d91f25c82ba531b78eca2cfed26369939e142cfc6dad2533e2f2bb2ab45070ff34bbc3a42b7b9fd8291ebcef71cccc84c736
|
|
7
|
+
data.tar.gz: 59b6eb5d2f7658d2faf56f71702ac4e87f130085a6035a100d454fd0769a17b78c7eb360a88ae91f7a43dc9d0f56695a84d5c5826410e7510e9963bee3a105d6
|
data/README.md
CHANGED
|
@@ -9,6 +9,8 @@ and can be used directly from any Ruby program.
|
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
12
|
+
Requires Ruby 3.3 or newer.
|
|
13
|
+
|
|
12
14
|
```sh
|
|
13
15
|
gem install spm_version_updates
|
|
14
16
|
```
|
|
@@ -23,18 +25,17 @@ require "spm_version_updates"
|
|
|
23
25
|
|
|
24
26
|
checker = SpmChecker.new
|
|
25
27
|
|
|
26
|
-
# Manifest mode: check one or more Package.swift files
|
|
27
|
-
|
|
28
|
-
warnings = checker.check_manifests(["path/to/Package.swift"])
|
|
28
|
+
# Manifest mode: check one or more Package.swift files.
|
|
29
|
+
result = checker.check_manifests(["path/to/Package.swift"])
|
|
29
30
|
|
|
30
31
|
# Xcode mode: check the packages referenced by an Xcode project.
|
|
31
|
-
#
|
|
32
|
+
# result = checker.check_for_updates("path/to/App.xcodeproj")
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
result.updates.each { |update| puts update["message"] }
|
|
34
35
|
|
|
35
|
-
#
|
|
36
|
-
# suggested update command,
|
|
37
|
-
|
|
36
|
+
# String-keyed details include repository URL, current/available version,
|
|
37
|
+
# suggested update command, source, and related report fields.
|
|
38
|
+
result.updates.each { |update| p update }
|
|
38
39
|
```
|
|
39
40
|
|
|
40
41
|
Behavior is configurable through accessors on `SpmChecker` — for example
|
|
@@ -113,9 +114,9 @@ is recorded on the checker — separate from update warnings, so update counts
|
|
|
113
114
|
and fail-on thresholds are unaffected:
|
|
114
115
|
|
|
115
116
|
```ruby
|
|
116
|
-
checker.check_manifests(["Modules/Package.swift"])
|
|
117
|
+
result = checker.check_manifests(["Modules/Package.swift"])
|
|
117
118
|
|
|
118
|
-
|
|
119
|
+
result.parse_warnings.each do |record|
|
|
119
120
|
# String-keyed hash: "type" ("parse_warning"), "reason", "source"
|
|
120
121
|
# (the manifest path), "snippet" (credential-redacted, truncated),
|
|
121
122
|
# and a human-readable "message".
|
|
@@ -7,13 +7,8 @@ require_relative "update_severity"
|
|
|
7
7
|
module FailOnThreshold
|
|
8
8
|
ANY = "any"
|
|
9
9
|
|
|
10
|
-
def self.
|
|
11
|
-
|
|
12
|
-
["fail-on", explicit_fail_on],
|
|
13
|
-
["fail-on-updates", legacy_fail_on],
|
|
14
|
-
["fail-on-updates", "false"],
|
|
15
|
-
].find { |_name, candidate| candidate }
|
|
16
|
-
normalize(value, input_name)
|
|
10
|
+
def self.from_input(value)
|
|
11
|
+
normalize(value)
|
|
17
12
|
end
|
|
18
13
|
|
|
19
14
|
def self.failure_message(threshold, reporter)
|
|
@@ -29,13 +24,13 @@ module FailOnThreshold
|
|
|
29
24
|
UpdateSeverity.count_at_or_above(reporter.severity_counts, threshold)
|
|
30
25
|
end
|
|
31
26
|
|
|
32
|
-
def self.normalize(value
|
|
33
|
-
normalized = value.downcase
|
|
34
|
-
return nil if ["false", "none"].include?(normalized)
|
|
35
|
-
return ANY if
|
|
27
|
+
def self.normalize(value)
|
|
28
|
+
normalized = value.to_s.strip.downcase
|
|
29
|
+
return nil if ["", "false", "none"].include?(normalized)
|
|
30
|
+
return ANY if ["true", ANY].include?(normalized)
|
|
36
31
|
return normalized if UpdateSeverity.threshold?(normalized)
|
|
37
32
|
|
|
38
|
-
raise(SpmVersionUpdates::ConfigurationError, "
|
|
33
|
+
raise(SpmVersionUpdates::ConfigurationError, "fail-on must be false, true, any, major, minor, or patch")
|
|
39
34
|
end
|
|
40
35
|
|
|
41
36
|
def self.build_message(threshold, count)
|
|
@@ -21,6 +21,123 @@ require_relative "package_resolved"
|
|
|
21
21
|
# `"revision"`) so the same comparison logic can be reused for both modes.
|
|
22
22
|
module ManifestParser
|
|
23
23
|
PACKAGE_CALL = ".package("
|
|
24
|
+
# Raw body and byte offsets for a direct `.package(...)` declaration.
|
|
25
|
+
PackageCallSpan = Struct.new(:body, :body_start, :body_end, keyword_init: true)
|
|
26
|
+
|
|
27
|
+
# Navigates a normal Swift double-quoted string literal.
|
|
28
|
+
class StringLiteral
|
|
29
|
+
def initialize(content, index)
|
|
30
|
+
@content = content
|
|
31
|
+
@index = index
|
|
32
|
+
@cursor = index
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def copy_to(output)
|
|
36
|
+
output << @content[@index...skip_index]
|
|
37
|
+
skip_index
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def skip_index
|
|
41
|
+
@cursor = @index + 1
|
|
42
|
+
@cursor = next_cursor until finished?
|
|
43
|
+
finish_index
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def finished?
|
|
49
|
+
@cursor >= @content.length || @content[@cursor] == '"'
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def next_cursor
|
|
53
|
+
@content[@cursor] == "\\" ? @cursor + 2 : @cursor + 1
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def finish_index
|
|
57
|
+
@cursor >= @content.length ? @cursor : @cursor + 1
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
private_constant :StringLiteral
|
|
61
|
+
|
|
62
|
+
# Navigates a Swift raw string literal such as #"..."# or #"""..."""#.
|
|
63
|
+
class RawStringLiteral
|
|
64
|
+
def initialize(content, index)
|
|
65
|
+
@content = content
|
|
66
|
+
@index = index
|
|
67
|
+
@hash_count = leading_hash_count
|
|
68
|
+
@quote_count = quote_count
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def literal?
|
|
72
|
+
@hash_count.positive? && @quote_count.positive?
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def copy_to(output)
|
|
76
|
+
output << @content[@index...skip_index]
|
|
77
|
+
skip_index
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def skip_index
|
|
81
|
+
length = @content.length
|
|
82
|
+
index = @index + @hash_count + @quote_count
|
|
83
|
+
index += 1 until index >= length || ends_at?(index)
|
|
84
|
+
[index + @quote_count + @hash_count, length].min
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def leading_hash_count
|
|
90
|
+
index = @index
|
|
91
|
+
index += 1 while @content[index] == "#"
|
|
92
|
+
index - @index
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def quote_count
|
|
96
|
+
quote_index = @index + @hash_count
|
|
97
|
+
return 3 if @content[quote_index, 3] == '"""'
|
|
98
|
+
return 1 if @content[quote_index] == '"'
|
|
99
|
+
|
|
100
|
+
0
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def ends_at?(index)
|
|
104
|
+
@content[index, @quote_count] == '"' * @quote_count &&
|
|
105
|
+
@content[(index + @quote_count), @hash_count] == "#" * @hash_count
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
private_constant :RawStringLiteral
|
|
109
|
+
|
|
110
|
+
# Finds `.package(` markers while skipping Swift string literals.
|
|
111
|
+
class PackageCallFinder
|
|
112
|
+
def initialize(content)
|
|
113
|
+
@content = content
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def next_from(search_start)
|
|
117
|
+
index = search_start
|
|
118
|
+
while index < @content.length
|
|
119
|
+
return index if package_call_at?(index)
|
|
120
|
+
|
|
121
|
+
index = next_index(index)
|
|
122
|
+
end
|
|
123
|
+
nil
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
private
|
|
127
|
+
|
|
128
|
+
def package_call_at?(index)
|
|
129
|
+
@content[index, PACKAGE_CALL.length] == PACKAGE_CALL
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def next_index(index)
|
|
133
|
+
raw_string = RawStringLiteral.new(@content, index)
|
|
134
|
+
return raw_string.skip_index if raw_string.literal?
|
|
135
|
+
return StringLiteral.new(@content, index).skip_index if @content[index] == '"'
|
|
136
|
+
|
|
137
|
+
index + 1
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
private_constant :PackageCallFinder
|
|
24
141
|
|
|
25
142
|
# Find the direct SPM dependencies declared in a `Package.swift` manifest.
|
|
26
143
|
#
|
|
@@ -44,6 +161,15 @@ module ManifestParser
|
|
|
44
161
|
|
|
45
162
|
content = strip_comments(File.read(manifest_path))
|
|
46
163
|
package_calls(content, &on_skip).each_with_object({}) { |call, packages|
|
|
164
|
+
if call.include?("\\(")
|
|
165
|
+
on_skip&.call({ reason: "unsupported_string_interpolation", snippet: call })
|
|
166
|
+
next
|
|
167
|
+
end
|
|
168
|
+
if call.match?(/#+"/)
|
|
169
|
+
on_skip&.call({ reason: "unsupported_raw_string", snippet: call })
|
|
170
|
+
next
|
|
171
|
+
end
|
|
172
|
+
|
|
47
173
|
url = call[/\burl\s*:\s*"([^"]+)"/, 1]
|
|
48
174
|
next if url.nil? # local package (path:) or otherwise unrecognized
|
|
49
175
|
|
|
@@ -73,6 +199,15 @@ module ManifestParser
|
|
|
73
199
|
File.join(File.dirname(manifest_path), "Package.resolved")
|
|
74
200
|
end
|
|
75
201
|
|
|
202
|
+
# Extract raw source spans for `.package(...)` calls. Offsets are byte indexes
|
|
203
|
+
# into the original content and point to the call body, excluding outer parens.
|
|
204
|
+
#
|
|
205
|
+
# @param [String] content raw manifest source
|
|
206
|
+
# @return [Array<PackageCallSpan>]
|
|
207
|
+
def self.package_call_spans(content)
|
|
208
|
+
package_spans(content).map { |span| PackageCallSpan.new(**span) }
|
|
209
|
+
end
|
|
210
|
+
|
|
76
211
|
# Extract the argument body of each `.package( ... )` call, honoring nested
|
|
77
212
|
# parentheses (e.g. `.upToNextMajor(from: "1.0.0")`) and string literals.
|
|
78
213
|
#
|
|
@@ -82,20 +217,42 @@ module ManifestParser
|
|
|
82
217
|
# @param [String] content The (comment-stripped) manifest source
|
|
83
218
|
# @return [Array<String>]
|
|
84
219
|
def self.package_calls(content, &on_skip)
|
|
220
|
+
package_spans(content, &on_skip).map { |span| span[:body] }
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def self.package_spans(content, &on_skip)
|
|
85
224
|
calls = []
|
|
225
|
+
scan_package_spans(content, on_skip) { |span| calls << span }
|
|
226
|
+
calls
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def self.scan_package_spans(content, on_skip)
|
|
86
230
|
search_start = 0
|
|
87
|
-
while (marker_index = content
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if close_index.nil?
|
|
91
|
-
on_skip&.call({ reason: "unbalanced_parentheses", snippet: content[marker_index, 300] })
|
|
92
|
-
break
|
|
93
|
-
end
|
|
231
|
+
while (marker_index = next_package_call(content, search_start))
|
|
232
|
+
span = package_span(content, marker_index, on_skip)
|
|
233
|
+
break unless span
|
|
94
234
|
|
|
95
|
-
|
|
96
|
-
search_start =
|
|
235
|
+
yield(span)
|
|
236
|
+
search_start = span[:body_end] + 1
|
|
97
237
|
end
|
|
98
|
-
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def self.package_span(content, marker_index, on_skip)
|
|
241
|
+
open_index = marker_index + PACKAGE_CALL.length - 1
|
|
242
|
+
close_index = matching_paren(content, open_index)
|
|
243
|
+
return unbalanced_package_span(content, marker_index, on_skip) unless close_index
|
|
244
|
+
|
|
245
|
+
body_start = open_index + 1
|
|
246
|
+
{ body: content[body_start...close_index], body_start:, body_end: close_index }
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def self.unbalanced_package_span(content, marker_index, on_skip)
|
|
250
|
+
on_skip&.call({ reason: "unbalanced_parentheses", snippet: content[marker_index, 300] })
|
|
251
|
+
nil
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def self.next_package_call(content, search_start)
|
|
255
|
+
PackageCallFinder.new(content).next_from(search_start)
|
|
99
256
|
end
|
|
100
257
|
|
|
101
258
|
# Map the body of a `.package(...)` call to an Xcodeproj-style requirement.
|
|
@@ -156,17 +313,15 @@ module ManifestParser
|
|
|
156
313
|
depth = 0
|
|
157
314
|
index = open_index
|
|
158
315
|
length = content.length
|
|
159
|
-
in_string = false
|
|
160
316
|
while index < length
|
|
161
317
|
char = content[index]
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
end
|
|
167
|
-
in_string = false if char == '"'
|
|
318
|
+
raw_string = RawStringLiteral.new(content, index)
|
|
319
|
+
if raw_string.literal?
|
|
320
|
+
index = raw_string.skip_index
|
|
321
|
+
next
|
|
168
322
|
elsif char == '"'
|
|
169
|
-
|
|
323
|
+
index = StringLiteral.new(content, index).skip_index
|
|
324
|
+
next
|
|
170
325
|
elsif char == "("
|
|
171
326
|
depth += 1
|
|
172
327
|
elsif char == ")"
|
|
@@ -190,7 +345,10 @@ module ManifestParser
|
|
|
190
345
|
while index < length
|
|
191
346
|
char = content[index]
|
|
192
347
|
nxt = content[index + 1]
|
|
193
|
-
|
|
348
|
+
raw_string = RawStringLiteral.new(content, index)
|
|
349
|
+
if raw_string.literal?
|
|
350
|
+
index = raw_string.copy_to(output)
|
|
351
|
+
elsif char == '"'
|
|
194
352
|
index = copy_string_literal(content, index, output)
|
|
195
353
|
elsif char == "/" && nxt == "/"
|
|
196
354
|
index += 1 while index < length && content[index] != "\n"
|
|
@@ -209,21 +367,7 @@ module ManifestParser
|
|
|
209
367
|
#
|
|
210
368
|
# @return [Integer]
|
|
211
369
|
def self.copy_string_literal(content, index, output)
|
|
212
|
-
|
|
213
|
-
output << content[index] # opening quote
|
|
214
|
-
index += 1
|
|
215
|
-
while index < length
|
|
216
|
-
char = content[index]
|
|
217
|
-
output << char
|
|
218
|
-
if char == "\\"
|
|
219
|
-
output << content[index + 1] if index + 1 < length
|
|
220
|
-
index += 2
|
|
221
|
-
next
|
|
222
|
-
end
|
|
223
|
-
index += 1
|
|
224
|
-
break if char == '"'
|
|
225
|
-
end
|
|
226
|
-
index
|
|
370
|
+
StringLiteral.new(content, index).copy_to(output)
|
|
227
371
|
end
|
|
228
372
|
|
|
229
373
|
# Return the index just past the closing `*/` of a block comment. Swift block
|
|
@@ -249,7 +393,11 @@ module ManifestParser
|
|
|
249
393
|
end
|
|
250
394
|
|
|
251
395
|
private_class_method :package_calls,
|
|
252
|
-
:
|
|
396
|
+
:package_spans,
|
|
397
|
+
:scan_package_spans,
|
|
398
|
+
:package_span,
|
|
399
|
+
:unbalanced_package_span,
|
|
400
|
+
:next_package_call,
|
|
253
401
|
:version_range_requirement,
|
|
254
402
|
:increment_patch_version,
|
|
255
403
|
:matching_paren,
|