dependabot-bun 0.296.2 → 0.296.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/helpers/.eslintrc +11 -0
- data/helpers/README.md +29 -0
- data/helpers/build +26 -0
- data/helpers/jest.config.js +5 -0
- data/helpers/lib/npm/conflicting-dependency-parser.js +78 -0
- data/helpers/lib/npm/index.js +9 -0
- data/helpers/lib/npm/vulnerability-auditor.js +291 -0
- data/helpers/lib/npm6/helpers.js +25 -0
- data/helpers/lib/npm6/index.js +9 -0
- data/helpers/lib/npm6/peer-dependency-checker.js +111 -0
- data/helpers/lib/npm6/remove-dependencies-from-lockfile.js +22 -0
- data/helpers/lib/npm6/subdependency-updater.js +78 -0
- data/helpers/lib/npm6/updater.js +199 -0
- data/helpers/lib/pnpm/index.js +5 -0
- data/helpers/lib/pnpm/lockfile-parser.js +82 -0
- data/helpers/lib/yarn/conflicting-dependency-parser.js +176 -0
- data/helpers/lib/yarn/fix-duplicates.js +80 -0
- data/helpers/lib/yarn/helpers.js +54 -0
- data/helpers/lib/yarn/index.js +14 -0
- data/helpers/lib/yarn/lockfile-parser.js +21 -0
- data/helpers/lib/yarn/peer-dependency-checker.js +132 -0
- data/helpers/lib/yarn/replace-lockfile-declaration.js +57 -0
- data/helpers/lib/yarn/subdependency-updater.js +83 -0
- data/helpers/lib/yarn/updater.js +209 -0
- data/helpers/package-lock.json +28519 -0
- data/helpers/package.json +29 -0
- data/helpers/patches/npm++pacote+9.5.12.patch +14 -0
- data/helpers/run.js +30 -0
- data/helpers/test/npm6/conflicting-dependency-parser.test.js +66 -0
- data/helpers/test/npm6/fixtures/conflicting-dependency-parser/deeply-nested/package-lock.json +591 -0
- data/helpers/test/npm6/fixtures/conflicting-dependency-parser/deeply-nested/package.json +14 -0
- data/helpers/test/npm6/fixtures/conflicting-dependency-parser/nested/package-lock.json +188 -0
- data/helpers/test/npm6/fixtures/conflicting-dependency-parser/nested/package.json +14 -0
- data/helpers/test/npm6/fixtures/conflicting-dependency-parser/simple/package-lock.json +27 -0
- data/helpers/test/npm6/fixtures/conflicting-dependency-parser/simple/package.json +14 -0
- data/helpers/test/npm6/fixtures/updater/original/package-lock.json +16 -0
- data/helpers/test/npm6/fixtures/updater/original/package.json +9 -0
- data/helpers/test/npm6/fixtures/updater/updated/package-lock.json +16 -0
- data/helpers/test/npm6/helpers.js +21 -0
- data/helpers/test/npm6/updater.test.js +30 -0
- data/helpers/test/pnpm/fixtures/parser/empty_version/pnpm-lock.yaml +72 -0
- data/helpers/test/pnpm/fixtures/parser/no_lockfile_change/pnpm-lock.yaml +2744 -0
- data/helpers/test/pnpm/fixtures/parser/only_dev_dependencies/pnpm-lock.yaml +16 -0
- data/helpers/test/pnpm/fixtures/parser/peer_disambiguation/pnpm-lock.yaml +855 -0
- data/helpers/test/pnpm/lockfile-parser.test.js +62 -0
- data/helpers/test/yarn/conflicting-dependency-parser.test.js +83 -0
- data/helpers/test/yarn/fixtures/conflicting-dependency-parser/deeply-nested/package.json +14 -0
- data/helpers/test/yarn/fixtures/conflicting-dependency-parser/deeply-nested/yarn.lock +496 -0
- data/helpers/test/yarn/fixtures/conflicting-dependency-parser/dev-dependencies/package.json +14 -0
- data/helpers/test/yarn/fixtures/conflicting-dependency-parser/dev-dependencies/yarn.lock +21 -0
- data/helpers/test/yarn/fixtures/conflicting-dependency-parser/nested/package.json +14 -0
- data/helpers/test/yarn/fixtures/conflicting-dependency-parser/nested/yarn.lock +183 -0
- data/helpers/test/yarn/fixtures/conflicting-dependency-parser/simple/package.json +14 -0
- data/helpers/test/yarn/fixtures/conflicting-dependency-parser/simple/yarn.lock +21 -0
- data/helpers/test/yarn/fixtures/updater/illegal_character/package.json +8 -0
- data/helpers/test/yarn/fixtures/updater/illegal_character/yarn.lock +14 -0
- data/helpers/test/yarn/fixtures/updater/original/package.json +6 -0
- data/helpers/test/yarn/fixtures/updater/original/yarn.lock +11 -0
- data/helpers/test/yarn/fixtures/updater/updated/yarn.lock +12 -0
- data/helpers/test/yarn/fixtures/updater/with-version-comments/package.json +5 -0
- data/helpers/test/yarn/fixtures/updater/with-version-comments/yarn.lock +13 -0
- data/helpers/test/yarn/helpers.js +18 -0
- data/helpers/test/yarn/updater.test.js +117 -0
- data/lib/dependabot/bun/bun_package_manager.rb +47 -0
- data/lib/dependabot/bun/constraint_helper.rb +359 -0
- data/lib/dependabot/bun/dependency_files_filterer.rb +157 -0
- data/lib/dependabot/bun/file_fetcher/path_dependency_builder.rb +184 -0
- data/lib/dependabot/bun/file_fetcher.rb +402 -0
- data/lib/dependabot/bun/file_parser/bun_lock.rb +140 -0
- data/lib/dependabot/bun/file_parser/lockfile_parser.rb +105 -0
- data/lib/dependabot/bun/file_parser.rb +477 -0
- data/lib/dependabot/bun/file_updater/bun_lockfile_updater.rb +144 -0
- data/lib/dependabot/bun/file_updater/npmrc_builder.rb +256 -0
- data/lib/dependabot/bun/file_updater/package_json_preparer.rb +88 -0
- data/lib/dependabot/bun/file_updater/package_json_updater.rb +378 -0
- data/lib/dependabot/bun/file_updater.rb +203 -0
- data/lib/dependabot/bun/helpers.rb +93 -0
- data/lib/dependabot/bun/language.rb +45 -0
- data/lib/dependabot/bun/metadata_finder.rb +214 -0
- data/lib/dependabot/bun/native_helpers.rb +19 -0
- data/lib/dependabot/bun/package_manager.rb +280 -0
- data/lib/dependabot/bun/package_name.rb +118 -0
- data/lib/dependabot/bun/pnpm_package_manager.rb +55 -0
- data/lib/dependabot/bun/registry_helper.rb +188 -0
- data/lib/dependabot/bun/registry_parser.rb +93 -0
- data/lib/dependabot/bun/requirement.rb +146 -0
- data/lib/dependabot/bun/sub_dependency_files_filterer.rb +82 -0
- data/lib/dependabot/bun/update_checker/conflicting_dependency_resolver.rb +59 -0
- data/lib/dependabot/bun/update_checker/dependency_files_builder.rb +79 -0
- data/lib/dependabot/bun/update_checker/latest_version_finder.rb +448 -0
- data/lib/dependabot/bun/update_checker/library_detector.rb +76 -0
- data/lib/dependabot/bun/update_checker/registry_finder.rb +279 -0
- data/lib/dependabot/bun/update_checker/requirements_updater.rb +206 -0
- data/lib/dependabot/bun/update_checker/subdependency_version_resolver.rb +154 -0
- data/lib/dependabot/bun/update_checker/version_resolver.rb +583 -0
- data/lib/dependabot/bun/update_checker/vulnerability_auditor.rb +164 -0
- data/lib/dependabot/bun/update_checker.rb +455 -0
- data/lib/dependabot/bun/version.rb +138 -0
- data/lib/dependabot/bun/version_selector.rb +61 -0
- data/lib/dependabot/bun.rb +337 -35
- metadata +108 -65
- data/lib/dependabot/javascript/bun/file_fetcher.rb +0 -77
- data/lib/dependabot/javascript/bun/file_parser/bun_lock.rb +0 -156
- data/lib/dependabot/javascript/bun/file_parser/lockfile_parser.rb +0 -55
- data/lib/dependabot/javascript/bun/file_parser.rb +0 -74
- data/lib/dependabot/javascript/bun/file_updater/lockfile_updater.rb +0 -138
- data/lib/dependabot/javascript/bun/file_updater.rb +0 -75
- data/lib/dependabot/javascript/bun/helpers.rb +0 -72
- data/lib/dependabot/javascript/bun/package_manager.rb +0 -48
- data/lib/dependabot/javascript/bun/requirement.rb +0 -11
- data/lib/dependabot/javascript/bun/update_checker/conflicting_dependency_resolver.rb +0 -64
- data/lib/dependabot/javascript/bun/update_checker/dependency_files_builder.rb +0 -47
- data/lib/dependabot/javascript/bun/update_checker/latest_version_finder.rb +0 -450
- data/lib/dependabot/javascript/bun/update_checker/library_detector.rb +0 -76
- data/lib/dependabot/javascript/bun/update_checker/requirements_updater.rb +0 -203
- data/lib/dependabot/javascript/bun/update_checker/subdependency_version_resolver.rb +0 -144
- data/lib/dependabot/javascript/bun/update_checker/version_resolver.rb +0 -525
- data/lib/dependabot/javascript/bun/update_checker/vulnerability_auditor.rb +0 -165
- data/lib/dependabot/javascript/bun/update_checker.rb +0 -440
- data/lib/dependabot/javascript/bun/version.rb +0 -11
- data/lib/dependabot/javascript/shared/constraint_helper.rb +0 -359
- data/lib/dependabot/javascript/shared/dependency_files_filterer.rb +0 -164
- data/lib/dependabot/javascript/shared/file_fetcher.rb +0 -283
- data/lib/dependabot/javascript/shared/file_parser/lockfile_parser.rb +0 -106
- data/lib/dependabot/javascript/shared/file_parser.rb +0 -454
- data/lib/dependabot/javascript/shared/file_updater/npmrc_builder.rb +0 -394
- data/lib/dependabot/javascript/shared/file_updater/package_json_preparer.rb +0 -87
- data/lib/dependabot/javascript/shared/file_updater/package_json_updater.rb +0 -376
- data/lib/dependabot/javascript/shared/file_updater.rb +0 -179
- data/lib/dependabot/javascript/shared/language.rb +0 -45
- data/lib/dependabot/javascript/shared/metadata_finder.rb +0 -209
- data/lib/dependabot/javascript/shared/native_helpers.rb +0 -21
- data/lib/dependabot/javascript/shared/package_manager_detector.rb +0 -72
- data/lib/dependabot/javascript/shared/package_name.rb +0 -118
- data/lib/dependabot/javascript/shared/registry_helper.rb +0 -190
- data/lib/dependabot/javascript/shared/registry_parser.rb +0 -93
- data/lib/dependabot/javascript/shared/requirement.rb +0 -144
- data/lib/dependabot/javascript/shared/sub_dependency_files_filterer.rb +0 -79
- data/lib/dependabot/javascript/shared/update_checker/dependency_files_builder.rb +0 -87
- data/lib/dependabot/javascript/shared/update_checker/registry_finder.rb +0 -358
- data/lib/dependabot/javascript/shared/version.rb +0 -133
- data/lib/dependabot/javascript/shared/version_selector.rb +0 -60
- data/lib/dependabot/javascript.rb +0 -39
@@ -0,0 +1,359 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "sorbet-runtime"
|
5
|
+
|
6
|
+
module Dependabot
|
7
|
+
module Bun
|
8
|
+
module ConstraintHelper
|
9
|
+
extend T::Sig
|
10
|
+
|
11
|
+
# Regex Components for Semantic Versioning
|
12
|
+
DIGIT = "\\d+" # Matches a single number (e.g., "1")
|
13
|
+
PRERELEASE = "(?:-[a-zA-Z0-9.-]+)?" # Matches optional pre-release tag (e.g., "-alpha")
|
14
|
+
BUILD_METADATA = "(?:\\+[a-zA-Z0-9.-]+)?" # Matches optional build metadata (e.g., "+001")
|
15
|
+
|
16
|
+
# Matches semantic versions:
|
17
|
+
VERSION = T.let("#{DIGIT}(?:\\.#{DIGIT}){0,2}#{PRERELEASE}#{BUILD_METADATA}".freeze, String)
|
18
|
+
|
19
|
+
VERSION_REGEX = T.let(/^#{VERSION}$/, Regexp)
|
20
|
+
|
21
|
+
# Base regex for SemVer (major.minor.patch[-prerelease][+build])
|
22
|
+
# This pattern extracts valid semantic versioning strings based on the SemVer 2.0 specification.
|
23
|
+
SEMVER_REGEX = T.let(/
|
24
|
+
(?<version>\d+\.\d+\.\d+) # Match major.minor.patch (e.g., 1.2.3)
|
25
|
+
(?:-(?<prerelease>[a-zA-Z0-9.-]+))? # Optional prerelease (e.g., -alpha.1, -rc.1, -beta.5)
|
26
|
+
(?:\+(?<build>[a-zA-Z0-9.-]+))? # Optional build metadata (e.g., +build.20231101, +exp.sha.5114f85)
|
27
|
+
/x, Regexp)
|
28
|
+
|
29
|
+
# Full SemVer validation regex (ensures the entire string is a valid SemVer)
|
30
|
+
# This ensures the entire input strictly follows SemVer, without extra characters before/after.
|
31
|
+
SEMVER_VALIDATION_REGEX = T.let(/^#{SEMVER_REGEX}$/, Regexp)
|
32
|
+
|
33
|
+
# SemVer constraint regex (supports package.json version constraints)
|
34
|
+
# This pattern ensures proper parsing of SemVer versions with optional operators.
|
35
|
+
SEMVER_CONSTRAINT_REGEX = T.let(/
|
36
|
+
(?: (>=|<=|>|<|=|~|\^)\s*)? # Make operators optional (e.g., >=, ^, ~)
|
37
|
+
(\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?(?:\+[a-zA-Z0-9.-]+)?) # Match full SemVer versions
|
38
|
+
| (\*|latest) # Match wildcard (*) or 'latest'
|
39
|
+
/x, Regexp)
|
40
|
+
|
41
|
+
# /(>=|<=|>|<|=|~|\^)\s*(\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?(?:\+[a-zA-Z0-9.-]+)?)|(\*|latest)/
|
42
|
+
|
43
|
+
SEMVER_OPERATOR_REGEX = /^(>=|<=|>|<|~|\^|=)$/
|
44
|
+
|
45
|
+
# Constraint Types as Constants
|
46
|
+
CARET_CONSTRAINT_REGEX = T.let(/^\^\s*(#{VERSION})$/, Regexp)
|
47
|
+
TILDE_CONSTRAINT_REGEX = T.let(/^~\s*(#{VERSION})$/, Regexp)
|
48
|
+
EXACT_CONSTRAINT_REGEX = T.let(/^\s*(#{VERSION})$/, Regexp)
|
49
|
+
GREATER_THAN_EQUAL_REGEX = T.let(/^>=\s*(#{VERSION})$/, Regexp)
|
50
|
+
LESS_THAN_EQUAL_REGEX = T.let(/^<=\s*(#{VERSION})$/, Regexp)
|
51
|
+
GREATER_THAN_REGEX = T.let(/^>\s*(#{VERSION})$/, Regexp)
|
52
|
+
LESS_THAN_REGEX = T.let(/^<\s*(#{VERSION})$/, Regexp)
|
53
|
+
WILDCARD_REGEX = T.let(/^\*$/, Regexp)
|
54
|
+
LATEST_REGEX = T.let(/^latest$/, Regexp)
|
55
|
+
SEMVER_CONSTANTS = ["*", "latest"].freeze
|
56
|
+
|
57
|
+
# Unified Regex for Valid Constraints
|
58
|
+
VALID_CONSTRAINT_REGEX = T.let(Regexp.union(
|
59
|
+
CARET_CONSTRAINT_REGEX,
|
60
|
+
TILDE_CONSTRAINT_REGEX,
|
61
|
+
EXACT_CONSTRAINT_REGEX,
|
62
|
+
GREATER_THAN_EQUAL_REGEX,
|
63
|
+
LESS_THAN_EQUAL_REGEX,
|
64
|
+
GREATER_THAN_REGEX,
|
65
|
+
LESS_THAN_REGEX,
|
66
|
+
WILDCARD_REGEX,
|
67
|
+
LATEST_REGEX
|
68
|
+
).freeze, Regexp)
|
69
|
+
|
70
|
+
# Extract unique constraints from the given constraint expression.
|
71
|
+
# @param constraint_expression [T.nilable(String)] The semver constraint expression.
|
72
|
+
# @return [T::Array[String]] The list of unique Ruby-compatible constraints.
|
73
|
+
sig do
|
74
|
+
params(
|
75
|
+
constraint_expression: T.nilable(String),
|
76
|
+
dependabot_versions: T.nilable(T::Array[Dependabot::Version])
|
77
|
+
)
|
78
|
+
.returns(T.nilable(T::Array[String]))
|
79
|
+
end
|
80
|
+
def self.extract_ruby_constraints(constraint_expression, dependabot_versions = nil)
|
81
|
+
parsed_constraints = parse_constraints(constraint_expression, dependabot_versions)
|
82
|
+
|
83
|
+
return nil unless parsed_constraints
|
84
|
+
|
85
|
+
parsed_constraints.filter_map { |parsed| parsed[:constraint] }
|
86
|
+
end
|
87
|
+
|
88
|
+
# rubocop:disable Metrics/AbcSize
|
89
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
90
|
+
# rubocop:disable Metrics/MethodLength
|
91
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
92
|
+
sig do
|
93
|
+
params(constraint_expression: T.nilable(String))
|
94
|
+
.returns(T.nilable(T::Array[String]))
|
95
|
+
end
|
96
|
+
def self.split_constraints(constraint_expression)
|
97
|
+
normalized_constraint = constraint_expression&.strip
|
98
|
+
return [] if normalized_constraint.nil? || normalized_constraint.empty?
|
99
|
+
|
100
|
+
# Split constraints by logical OR (`||`)
|
101
|
+
constraint_groups = normalized_constraint.split("||")
|
102
|
+
|
103
|
+
# Split constraints by logical AND (`,`)
|
104
|
+
constraint_groups = constraint_groups.map do |or_constraint|
|
105
|
+
or_constraint.split(",").map(&:strip)
|
106
|
+
end.flatten
|
107
|
+
|
108
|
+
constraint_groups = constraint_groups.map do |constraint|
|
109
|
+
tokens = constraint.split(/\s+/).map(&:strip)
|
110
|
+
|
111
|
+
and_constraints = []
|
112
|
+
|
113
|
+
previous = T.let(nil, T.nilable(String))
|
114
|
+
operator = T.let(false, T.nilable(T::Boolean))
|
115
|
+
wildcard = T.let(false, T::Boolean)
|
116
|
+
|
117
|
+
tokens.each do |token|
|
118
|
+
token = token.strip
|
119
|
+
next if token.empty?
|
120
|
+
|
121
|
+
# Invalid constraint if wildcard and anything else
|
122
|
+
return nil if wildcard
|
123
|
+
|
124
|
+
# If token is one of the operators (>=, <=, >, <, ~, ^, =)
|
125
|
+
if token.match?(SEMVER_OPERATOR_REGEX)
|
126
|
+
wildcard = false
|
127
|
+
operator = true
|
128
|
+
# If token is wildcard or latest
|
129
|
+
elsif token.match?(/(\*|latest)/)
|
130
|
+
and_constraints << token
|
131
|
+
wildcard = true
|
132
|
+
operator = false
|
133
|
+
# If token is exact version (e.g., "1.2.3")
|
134
|
+
elsif token.match(VERSION_REGEX)
|
135
|
+
and_constraints << if operator
|
136
|
+
"#{previous}#{token}"
|
137
|
+
else
|
138
|
+
token
|
139
|
+
end
|
140
|
+
wildcard = false
|
141
|
+
operator = false
|
142
|
+
# If token is a valid constraint (e.g., ">=1.2.3", "<=2.0.0")
|
143
|
+
elsif token.match(VALID_CONSTRAINT_REGEX)
|
144
|
+
return nil if operator
|
145
|
+
|
146
|
+
and_constraints << token
|
147
|
+
|
148
|
+
wildcard = false
|
149
|
+
operator = false
|
150
|
+
else
|
151
|
+
# invalid constraint
|
152
|
+
return nil
|
153
|
+
end
|
154
|
+
previous = token
|
155
|
+
end
|
156
|
+
and_constraints.uniq
|
157
|
+
end.flatten
|
158
|
+
constraint_groups if constraint_groups.any?
|
159
|
+
end
|
160
|
+
|
161
|
+
# rubocop:enable Metrics/AbcSize
|
162
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
163
|
+
# rubocop:enable Metrics/MethodLength
|
164
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
165
|
+
|
166
|
+
# Find the highest version from the given constraint expression.
|
167
|
+
# @param constraint_expression [T.nilable(String)] The semver constraint expression.
|
168
|
+
# @return [T.nilable(String)] The highest version, or nil if no versions are available.
|
169
|
+
sig do
|
170
|
+
params(
|
171
|
+
constraint_expression: T.nilable(String),
|
172
|
+
dependabot_versions: T.nilable(T::Array[Dependabot::Version])
|
173
|
+
)
|
174
|
+
.returns(T.nilable(String))
|
175
|
+
end
|
176
|
+
def self.find_highest_version_from_constraint_expression(constraint_expression, dependabot_versions = nil)
|
177
|
+
parsed_constraints = parse_constraints(constraint_expression, dependabot_versions)
|
178
|
+
|
179
|
+
return nil unless parsed_constraints
|
180
|
+
|
181
|
+
parsed_constraints
|
182
|
+
.filter_map { |parsed| parsed[:version] } # Extract all versions
|
183
|
+
.max_by { |version| Version.new(version) }
|
184
|
+
end
|
185
|
+
|
186
|
+
# Parse all constraints (split by logical OR `||`) and convert to Ruby-compatible constraints.
|
187
|
+
# Return:
|
188
|
+
# - `nil` if the constraint expression is invalid
|
189
|
+
# - `[]` if the constraint expression is valid but represents "no constraints"
|
190
|
+
# - An array of hashes for valid constraints with details about the constraint and version
|
191
|
+
sig do
|
192
|
+
params(
|
193
|
+
constraint_expression: T.nilable(String),
|
194
|
+
dependabot_versions: T.nilable(T::Array[Dependabot::Version])
|
195
|
+
)
|
196
|
+
.returns(T.nilable(T::Array[T::Hash[Symbol, T.nilable(String)]]))
|
197
|
+
end
|
198
|
+
def self.parse_constraints(constraint_expression, dependabot_versions = nil)
|
199
|
+
splitted_constraints = split_constraints(constraint_expression)
|
200
|
+
|
201
|
+
return unless splitted_constraints
|
202
|
+
|
203
|
+
constraints = to_ruby_constraints_with_versions(splitted_constraints, dependabot_versions)
|
204
|
+
constraints
|
205
|
+
end
|
206
|
+
|
207
|
+
sig do
|
208
|
+
params(
|
209
|
+
constraints: T::Array[String],
|
210
|
+
dependabot_versions: T.nilable(T::Array[Dependabot::Version])
|
211
|
+
).returns(T::Array[T::Hash[Symbol, T.nilable(String)]])
|
212
|
+
end
|
213
|
+
def self.to_ruby_constraints_with_versions(constraints, dependabot_versions = [])
|
214
|
+
constraints.filter_map do |constraint|
|
215
|
+
parsed = to_ruby_constraint_with_version(constraint, dependabot_versions)
|
216
|
+
parsed if parsed
|
217
|
+
end.uniq
|
218
|
+
end
|
219
|
+
|
220
|
+
# rubocop:disable Metrics/MethodLength
|
221
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
222
|
+
# rubocop:disable Metrics/AbcSize
|
223
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
224
|
+
# Converts a semver constraint to a Ruby-compatible constraint and extracts the version, if available.
|
225
|
+
# @param constraint [String] The semver constraint to parse.
|
226
|
+
# @return [T.nilable(T::Hash[Symbol, T.nilable(String)])] Returns the Ruby-compatible constraint and the version,
|
227
|
+
# if available, or nil if the constraint is invalid.
|
228
|
+
#
|
229
|
+
# @example
|
230
|
+
# to_ruby_constraint_with_version("=1.2.3") # => { constraint: "=1.2.3", version: "1.2.3" }
|
231
|
+
# to_ruby_constraint_with_version("^1.2.3") # => { constraint: ">=1.2.3 <2.0.0", version: "1.2.3" }
|
232
|
+
# to_ruby_constraint_with_version("*") # => { constraint: nil, version: nil }
|
233
|
+
# to_ruby_constraint_with_version("invalid") # => nil
|
234
|
+
sig do
|
235
|
+
params(
|
236
|
+
constraint: String,
|
237
|
+
dependabot_versions: T.nilable(T::Array[Dependabot::Version])
|
238
|
+
)
|
239
|
+
.returns(T.nilable(T::Hash[Symbol, T.nilable(String)]))
|
240
|
+
end
|
241
|
+
def self.to_ruby_constraint_with_version(constraint, dependabot_versions = [])
|
242
|
+
return nil if constraint.empty?
|
243
|
+
|
244
|
+
case constraint
|
245
|
+
when EXACT_CONSTRAINT_REGEX # Exact version, e.g., "1.2.3-alpha"
|
246
|
+
return unless Regexp.last_match
|
247
|
+
|
248
|
+
full_version = Regexp.last_match(1)
|
249
|
+
{ constraint: "=#{full_version}", version: full_version }
|
250
|
+
when CARET_CONSTRAINT_REGEX # Caret constraint, e.g., "^1.2.3"
|
251
|
+
return unless Regexp.last_match
|
252
|
+
|
253
|
+
full_version = Regexp.last_match(1)
|
254
|
+
_, major, minor = version_components(full_version)
|
255
|
+
return nil if major.nil?
|
256
|
+
|
257
|
+
ruby_constraint =
|
258
|
+
if major.to_i.zero?
|
259
|
+
minor.nil? ? ">=#{full_version} <1.0.0" : ">=#{full_version} <0.#{minor.to_i + 1}.0"
|
260
|
+
else
|
261
|
+
">=#{full_version} <#{major.to_i + 1}.0.0"
|
262
|
+
end
|
263
|
+
{ constraint: ruby_constraint, version: full_version }
|
264
|
+
when TILDE_CONSTRAINT_REGEX # Tilde constraint, e.g., "~1.2.3"
|
265
|
+
return unless Regexp.last_match
|
266
|
+
|
267
|
+
full_version = Regexp.last_match(1)
|
268
|
+
_, major, minor = version_components(full_version)
|
269
|
+
ruby_constraint =
|
270
|
+
if minor.nil?
|
271
|
+
">=#{full_version} <#{major.to_i + 1}.0.0"
|
272
|
+
else
|
273
|
+
">=#{full_version} <#{major}.#{minor.to_i + 1}.0"
|
274
|
+
end
|
275
|
+
{ constraint: ruby_constraint, version: full_version }
|
276
|
+
when GREATER_THAN_EQUAL_REGEX # Greater than or equal, e.g., ">=1.2.3"
|
277
|
+
|
278
|
+
return unless Regexp.last_match && Regexp.last_match(1)
|
279
|
+
|
280
|
+
found_version = highest_matching_version(
|
281
|
+
dependabot_versions,
|
282
|
+
T.must(Regexp.last_match(1))
|
283
|
+
) do |version, constraint_version|
|
284
|
+
version >= Version.new(constraint_version)
|
285
|
+
end
|
286
|
+
{ constraint: ">=#{Regexp.last_match(1)}", version: found_version&.to_s }
|
287
|
+
when LESS_THAN_EQUAL_REGEX # Less than or equal, e.g., "<=1.2.3"
|
288
|
+
return unless Regexp.last_match
|
289
|
+
|
290
|
+
full_version = Regexp.last_match(1)
|
291
|
+
{ constraint: "<=#{full_version}", version: full_version }
|
292
|
+
when GREATER_THAN_REGEX # Greater than, e.g., ">1.2.3"
|
293
|
+
return unless Regexp.last_match && Regexp.last_match(1)
|
294
|
+
|
295
|
+
found_version = highest_matching_version(
|
296
|
+
dependabot_versions,
|
297
|
+
T.must(Regexp.last_match(1))
|
298
|
+
) do |version, constraint_version|
|
299
|
+
version > Version.new(constraint_version)
|
300
|
+
end
|
301
|
+
{ constraint: ">#{Regexp.last_match(1)}", version: found_version&.to_s }
|
302
|
+
when LESS_THAN_REGEX # Less than, e.g., "<1.2.3"
|
303
|
+
return unless Regexp.last_match && Regexp.last_match(1)
|
304
|
+
|
305
|
+
found_version = highest_matching_version(
|
306
|
+
dependabot_versions,
|
307
|
+
T.must(Regexp.last_match(1))
|
308
|
+
) do |version, constraint_version|
|
309
|
+
version < Version.new(constraint_version)
|
310
|
+
end
|
311
|
+
{ constraint: "<#{Regexp.last_match(1)}", version: found_version&.to_s }
|
312
|
+
when WILDCARD_REGEX # No specific constraint, resolves to the highest available version
|
313
|
+
{ constraint: nil, version: dependabot_versions&.max&.to_s }
|
314
|
+
when LATEST_REGEX
|
315
|
+
{ constraint: nil, version: dependabot_versions&.max&.to_s } # Resolves to the latest available version
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
sig do
|
320
|
+
params(
|
321
|
+
dependabot_versions: T.nilable(T::Array[Dependabot::Version]),
|
322
|
+
constraint_version: String,
|
323
|
+
condition: T.proc.params(version: Dependabot::Version, constraint: Dependabot::Version).returns(T::Boolean)
|
324
|
+
)
|
325
|
+
.returns(T.nilable(Dependabot::Version))
|
326
|
+
end
|
327
|
+
def self.highest_matching_version(dependabot_versions, constraint_version, &condition)
|
328
|
+
return unless dependabot_versions&.any?
|
329
|
+
|
330
|
+
# Returns the highest version that satisfies the condition, or nil if none.
|
331
|
+
dependabot_versions
|
332
|
+
.sort
|
333
|
+
.reverse
|
334
|
+
.find { |version| condition.call(version, Version.new(constraint_version)) } # rubocop:disable Performance/RedundantBlockCall
|
335
|
+
end
|
336
|
+
|
337
|
+
# rubocop:enable Metrics/MethodLength
|
338
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
339
|
+
# rubocop:enable Metrics/AbcSize
|
340
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
341
|
+
|
342
|
+
# Parses a semantic version string into its components as per the SemVer spec
|
343
|
+
# Example: "1.2.3-alpha+001" → ["1.2.3", "1", "2", "3", "alpha", "001"]
|
344
|
+
sig { params(full_version: T.nilable(String)).returns(T.nilable(T::Array[String])) }
|
345
|
+
def self.version_components(full_version)
|
346
|
+
return [] if full_version.nil?
|
347
|
+
|
348
|
+
match = full_version.match(SEMVER_VALIDATION_REGEX)
|
349
|
+
return [] unless match
|
350
|
+
|
351
|
+
version = match[:version]
|
352
|
+
return [] unless version
|
353
|
+
|
354
|
+
major, minor, patch = version.split(".")
|
355
|
+
[version, major, minor, patch, match[:prerelease], match[:build]].compact
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "dependabot/utils"
|
5
|
+
require "dependabot/bun/file_parser/lockfile_parser"
|
6
|
+
require "sorbet-runtime"
|
7
|
+
|
8
|
+
# Used in the version resolver and file updater to only run yarn/npm helpers on
|
9
|
+
# dependency files that require updates. This is useful for large monorepos with
|
10
|
+
# lots of sub-projects that don't all have the same dependencies.
|
11
|
+
module Dependabot
|
12
|
+
module Bun
|
13
|
+
class DependencyFilesFilterer
|
14
|
+
extend T::Sig
|
15
|
+
|
16
|
+
sig { params(dependency_files: T::Array[DependencyFile], updated_dependencies: T::Array[Dependency]).void }
|
17
|
+
def initialize(dependency_files:, updated_dependencies:)
|
18
|
+
@dependency_files = dependency_files
|
19
|
+
@updated_dependencies = updated_dependencies
|
20
|
+
end
|
21
|
+
|
22
|
+
sig { returns(T::Array[String]) }
|
23
|
+
def paths_requiring_update_check
|
24
|
+
@paths_requiring_update_check ||= T.let(fetch_paths_requiring_update_check, T.nilable(T::Array[String]))
|
25
|
+
end
|
26
|
+
|
27
|
+
sig { returns(T::Array[Dependabot::DependencyFile]) }
|
28
|
+
def files_requiring_update
|
29
|
+
@files_requiring_update ||= T.let(
|
30
|
+
dependency_files.select do |file|
|
31
|
+
package_files_requiring_update.include?(file) ||
|
32
|
+
package_required_lockfile?(file) ||
|
33
|
+
workspaces_lockfile?(file)
|
34
|
+
end, T.nilable(T::Array[DependencyFile])
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
sig { returns(T::Array[Dependabot::DependencyFile]) }
|
39
|
+
def package_files_requiring_update
|
40
|
+
@package_files_requiring_update ||= T.let(
|
41
|
+
dependency_files.select do |file|
|
42
|
+
dependency_manifest_requirements.include?(file.name)
|
43
|
+
end, T.nilable(T::Array[DependencyFile])
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
sig { returns(T::Array[DependencyFile]) }
|
50
|
+
attr_reader :dependency_files
|
51
|
+
|
52
|
+
sig { returns(T::Array[Dependency]) }
|
53
|
+
attr_reader :updated_dependencies
|
54
|
+
|
55
|
+
sig { returns(T::Array[String]) }
|
56
|
+
def fetch_paths_requiring_update_check
|
57
|
+
# if only a root lockfile exists, it tracks all dependencies
|
58
|
+
return [File.dirname(T.must(root_lockfile).name)] if lockfiles == [root_lockfile]
|
59
|
+
|
60
|
+
package_files_requiring_update.map do |file|
|
61
|
+
File.dirname(file.name)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
sig { returns(T::Array[String]) }
|
66
|
+
def dependency_manifest_requirements
|
67
|
+
@dependency_manifest_requirements ||= T.let(
|
68
|
+
updated_dependencies.flat_map do |dep|
|
69
|
+
dep.requirements.map { |requirement| requirement[:file] }
|
70
|
+
end, T.nilable(T::Array[String])
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
sig { params(lockfile: DependencyFile).returns(T::Boolean) }
|
75
|
+
def package_required_lockfile?(lockfile)
|
76
|
+
return false unless lockfile?(lockfile)
|
77
|
+
|
78
|
+
package_files_requiring_update.any? do |package_file|
|
79
|
+
File.dirname(package_file.name) == File.dirname(lockfile.name)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
sig { params(lockfile: DependencyFile).returns(T::Boolean) }
|
84
|
+
def workspaces_lockfile?(lockfile)
|
85
|
+
return false unless ["yarn.lock", "package-lock.json", "pnpm-lock.yaml", "bun.lock"].include?(lockfile.name)
|
86
|
+
|
87
|
+
return false unless parsed_root_package_json["workspaces"] || dependency_files.any? do |file|
|
88
|
+
file.name.end_with?("pnpm-workspace.yaml") && File.dirname(file.name) == File.dirname(lockfile.name)
|
89
|
+
end
|
90
|
+
|
91
|
+
updated_dependencies_in_lockfile?(lockfile)
|
92
|
+
end
|
93
|
+
|
94
|
+
sig { returns(T.nilable(DependencyFile)) }
|
95
|
+
def root_lockfile
|
96
|
+
@root_lockfile ||= T.let(
|
97
|
+
lockfiles.find do |file|
|
98
|
+
File.dirname(file.name) == "."
|
99
|
+
end, T.nilable(DependencyFile)
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
sig { returns(T::Array[DependencyFile]) }
|
104
|
+
def lockfiles
|
105
|
+
@lockfiles ||= T.let(
|
106
|
+
dependency_files.select do |file|
|
107
|
+
lockfile?(file)
|
108
|
+
end, T.nilable(T::Array[DependencyFile])
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
112
|
+
sig { returns(T::Hash[String, T.untyped]) }
|
113
|
+
def parsed_root_package_json
|
114
|
+
@parsed_root_package_json ||= T.let(
|
115
|
+
begin
|
116
|
+
package = T.must(dependency_files.find { |f| f.name == "package.json" })
|
117
|
+
JSON.parse(T.must(package.content))
|
118
|
+
end, T.nilable(T::Hash[String, T.untyped])
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
sig { params(lockfile: Dependabot::DependencyFile).returns(T::Boolean) }
|
123
|
+
def updated_dependencies_in_lockfile?(lockfile)
|
124
|
+
lockfile_dependencies(lockfile).any? do |sub_dep|
|
125
|
+
updated_dependencies.any? do |updated_dep|
|
126
|
+
sub_dep.name == updated_dep.name
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
sig { params(lockfile: DependencyFile).returns(T::Array[Dependency]) }
|
132
|
+
def lockfile_dependencies(lockfile)
|
133
|
+
@lockfile_dependencies ||= T.let({}, T.nilable(T::Hash[String, T::Array[Dependency]]))
|
134
|
+
@lockfile_dependencies[lockfile.name] ||=
|
135
|
+
Bun::FileParser::LockfileParser.new(
|
136
|
+
dependency_files: [lockfile]
|
137
|
+
).parse
|
138
|
+
end
|
139
|
+
|
140
|
+
sig { params(file: DependencyFile).returns(T::Boolean) }
|
141
|
+
def manifest?(file)
|
142
|
+
file.name.end_with?("package.json")
|
143
|
+
end
|
144
|
+
|
145
|
+
sig { params(file: DependencyFile).returns(T::Boolean) }
|
146
|
+
def lockfile?(file)
|
147
|
+
file.name.end_with?(
|
148
|
+
"package-lock.json",
|
149
|
+
"yarn.lock",
|
150
|
+
"pnpm-lock.yaml",
|
151
|
+
"bun.lock",
|
152
|
+
"npm-shrinkwrap.json"
|
153
|
+
)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "json"
|
5
|
+
require "dependabot/dependency_file"
|
6
|
+
require "dependabot/errors"
|
7
|
+
require "dependabot/bun/file_fetcher"
|
8
|
+
require "sorbet-runtime"
|
9
|
+
|
10
|
+
module Dependabot
|
11
|
+
module Bun
|
12
|
+
class FileFetcher
|
13
|
+
class PathDependencyBuilder
|
14
|
+
extend T::Sig
|
15
|
+
|
16
|
+
sig do
|
17
|
+
params(
|
18
|
+
dependency_name: String,
|
19
|
+
path: String,
|
20
|
+
directory: String,
|
21
|
+
package_lock: T.nilable(DependencyFile),
|
22
|
+
yarn_lock: T.nilable(DependencyFile)
|
23
|
+
)
|
24
|
+
.void
|
25
|
+
end
|
26
|
+
def initialize(dependency_name:, path:, directory:, package_lock:,
|
27
|
+
yarn_lock:)
|
28
|
+
@dependency_name = dependency_name
|
29
|
+
@path = path
|
30
|
+
@directory = directory
|
31
|
+
@package_lock = package_lock
|
32
|
+
@yarn_lock = yarn_lock
|
33
|
+
end
|
34
|
+
|
35
|
+
sig { returns(DependencyFile) }
|
36
|
+
def dependency_file
|
37
|
+
filename = File.join(path, "package.json")
|
38
|
+
|
39
|
+
DependencyFile.new(
|
40
|
+
name: Pathname.new(filename).cleanpath.to_path,
|
41
|
+
content: build_path_dep_content(dependency_name),
|
42
|
+
directory: directory,
|
43
|
+
support_file: true
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
sig { returns(String) }
|
50
|
+
attr_reader :dependency_name
|
51
|
+
|
52
|
+
sig { returns(String) }
|
53
|
+
attr_reader :path
|
54
|
+
|
55
|
+
sig { returns(T.nilable(DependencyFile)) }
|
56
|
+
attr_reader :package_lock
|
57
|
+
|
58
|
+
sig { returns(T.nilable(DependencyFile)) }
|
59
|
+
attr_reader :yarn_lock
|
60
|
+
|
61
|
+
sig { returns(String) }
|
62
|
+
attr_reader :directory
|
63
|
+
|
64
|
+
sig { returns(T.untyped) }
|
65
|
+
def details_from_yarn_lock
|
66
|
+
path_starts = FileFetcher::PATH_DEPENDENCY_STARTS
|
67
|
+
parsed_yarn_lock.to_a
|
68
|
+
.find do |n, _|
|
69
|
+
next false unless n.split(/(?<=\w)\@/).first == dependency_name
|
70
|
+
|
71
|
+
T.must(n.split(/(?<=\w)\@/).last).start_with?(*path_starts)
|
72
|
+
end&.last
|
73
|
+
end
|
74
|
+
|
75
|
+
sig { returns(T.untyped) }
|
76
|
+
def details_from_npm_lock
|
77
|
+
path_starts = FileFetcher::NPM_PATH_DEPENDENCY_STARTS
|
78
|
+
path_deps = parsed_package_lock.fetch("dependencies", []).to_a
|
79
|
+
.select do |_, v|
|
80
|
+
v.fetch("version", "").start_with?(*path_starts)
|
81
|
+
end
|
82
|
+
path_deps.find { |n, _| n == dependency_name }&.last
|
83
|
+
end
|
84
|
+
|
85
|
+
sig { params(dependency_name: String).returns(String) }
|
86
|
+
def build_path_dep_content(dependency_name)
|
87
|
+
unless details_from_yarn_lock || details_from_npm_lock
|
88
|
+
raise Dependabot::PathDependenciesNotReachable, [dependency_name]
|
89
|
+
end
|
90
|
+
|
91
|
+
if details_from_yarn_lock
|
92
|
+
{
|
93
|
+
name: dependency_name,
|
94
|
+
version: details_from_yarn_lock["version"] || "0.0.1",
|
95
|
+
dependencies:
|
96
|
+
replace_yarn_lockfile_paths(
|
97
|
+
details_from_yarn_lock["dependencies"]
|
98
|
+
),
|
99
|
+
optionalDependencies:
|
100
|
+
replace_yarn_lockfile_paths(
|
101
|
+
details_from_yarn_lock["optionalDependencies"]
|
102
|
+
)
|
103
|
+
}.compact.to_json
|
104
|
+
else
|
105
|
+
{
|
106
|
+
name: dependency_name,
|
107
|
+
version: "0.0.1",
|
108
|
+
dependencies: details_from_npm_lock["requires"]
|
109
|
+
}.compact.to_json
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# If an unfetchable path dependency itself has path dependencies
|
114
|
+
# then the paths in the yarn.lock for them will be absolute, not
|
115
|
+
# relative. Worse, they may point to the user's local cache.
|
116
|
+
# We work around this by constructing a relative path to the
|
117
|
+
# (second-level) path dependencies.
|
118
|
+
sig { params(dependencies_hash: T.nilable(T::Hash[String, T.untyped])).returns(T.untyped) }
|
119
|
+
def replace_yarn_lockfile_paths(dependencies_hash)
|
120
|
+
return unless dependencies_hash
|
121
|
+
|
122
|
+
dependencies_hash.each_with_object({}) do |(name, value), obj|
|
123
|
+
obj[name] = value
|
124
|
+
next unless value.start_with?(*FileFetcher::PATH_DEPENDENCY_STARTS)
|
125
|
+
|
126
|
+
path_from_base =
|
127
|
+
parsed_yarn_lock.to_a
|
128
|
+
.find do |n, _|
|
129
|
+
next false unless n.split(/(?<=\w)\@/).first == name
|
130
|
+
|
131
|
+
T.must(n.split(/(?<=\w)\@/).last)
|
132
|
+
.start_with?(*FileFetcher::PATH_DEPENDENCY_STARTS)
|
133
|
+
end&.first&.split(/(?<=\w)\@/)&.last
|
134
|
+
|
135
|
+
next unless path_from_base
|
136
|
+
|
137
|
+
cleaned_path = path_from_base
|
138
|
+
.gsub(FileFetcher::PATH_DEPENDENCY_CLEAN_REGEX, "")
|
139
|
+
obj[name] = "file:" + File.join(inverted_path, cleaned_path)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
sig { returns(T.untyped) }
|
144
|
+
def parsed_package_lock
|
145
|
+
return {} unless package_lock
|
146
|
+
|
147
|
+
JSON.parse(T.must(T.must(package_lock).content))
|
148
|
+
rescue JSON::ParserError
|
149
|
+
{}
|
150
|
+
end
|
151
|
+
|
152
|
+
sig { returns(T.nilable(T::Hash[String, T.untyped])) }
|
153
|
+
def parsed_yarn_lock
|
154
|
+
return unless yarn_lock
|
155
|
+
return @parsed_yarn_lock if defined?(@parsed_yarn_lock)
|
156
|
+
|
157
|
+
parsed = T.cast(SharedHelpers.in_a_temporary_directory do
|
158
|
+
File.write("yarn.lock", T.must(yarn_lock).content)
|
159
|
+
|
160
|
+
SharedHelpers.run_helper_subprocess(
|
161
|
+
command: NativeHelpers.helper_path,
|
162
|
+
function: "yarn:parseLockfile",
|
163
|
+
args: [Dir.pwd]
|
164
|
+
)
|
165
|
+
rescue SharedHelpers::HelperSubprocessFailed
|
166
|
+
raise Dependabot::DependencyFileNotParseable, T.must(yarn_lock).path
|
167
|
+
end, T::Hash[String, T.untyped])
|
168
|
+
@parsed_yarn_lock = T.let(parsed, T.nilable(T::Hash[String, T.untyped]))
|
169
|
+
end
|
170
|
+
|
171
|
+
# The path back to the root lockfile
|
172
|
+
sig { returns(String) }
|
173
|
+
def inverted_path
|
174
|
+
path.split("/").map do |part|
|
175
|
+
next part if part == "."
|
176
|
+
next "tmp" if part == ".."
|
177
|
+
|
178
|
+
".."
|
179
|
+
end.join("/")
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|