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,402 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "json"
|
5
|
+
require "sorbet-runtime"
|
6
|
+
require "dependabot/experiments"
|
7
|
+
require "dependabot/logger"
|
8
|
+
require "dependabot/file_fetchers"
|
9
|
+
require "dependabot/file_fetchers/base"
|
10
|
+
require "dependabot/bun/helpers"
|
11
|
+
require "dependabot/bun/package_manager"
|
12
|
+
require "dependabot/bun/file_parser"
|
13
|
+
require "dependabot/bun/file_parser/lockfile_parser"
|
14
|
+
|
15
|
+
module Dependabot
|
16
|
+
module Bun
|
17
|
+
class FileFetcher < Dependabot::FileFetchers::Base
|
18
|
+
extend T::Sig
|
19
|
+
extend T::Helpers
|
20
|
+
|
21
|
+
require_relative "file_fetcher/path_dependency_builder"
|
22
|
+
|
23
|
+
# Npm always prefixes file paths in the lockfile "version" with "file:"
|
24
|
+
# even when a naked path is used (e.g. "../dep")
|
25
|
+
NPM_PATH_DEPENDENCY_STARTS = T.let(%w(file:).freeze, [String])
|
26
|
+
# "link:" is only supported by Yarn but is interchangeable with "file:"
|
27
|
+
# when it specifies a path. Only include Yarn "link:"'s that start with a
|
28
|
+
# path and ignore symlinked package names that have been registered with
|
29
|
+
# "yarn link", e.g. "link:react"
|
30
|
+
PATH_DEPENDENCY_STARTS = T.let(%w(file: link:. link:/ link:~/ / ./ ../ ~/).freeze,
|
31
|
+
[String, String, String, String, String, String, String, String])
|
32
|
+
PATH_DEPENDENCY_CLEAN_REGEX = /^file:|^link:/
|
33
|
+
DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org"
|
34
|
+
|
35
|
+
sig { override.params(filenames: T::Array[String]).returns(T::Boolean) }
|
36
|
+
def self.required_files_in?(filenames)
|
37
|
+
filenames.include?("package.json")
|
38
|
+
end
|
39
|
+
|
40
|
+
sig { override.returns(String) }
|
41
|
+
def self.required_files_message
|
42
|
+
"Repo must contain a package.json."
|
43
|
+
end
|
44
|
+
|
45
|
+
# Overridden to pull any necessary data stored with Git LFS.
|
46
|
+
sig { override.returns(String) }
|
47
|
+
def clone_repo_contents
|
48
|
+
return @git_lfs_cloned_repo_contents_path unless @git_lfs_cloned_repo_contents_path.nil?
|
49
|
+
|
50
|
+
@git_lfs_cloned_repo_contents_path ||= T.let(super, T.nilable(String))
|
51
|
+
begin
|
52
|
+
SharedHelpers.with_git_configured(credentials: credentials) do
|
53
|
+
Dir.chdir(@git_lfs_cloned_repo_contents_path) do
|
54
|
+
SharedHelpers.run_shell_command("git lfs pull --include .yarn")
|
55
|
+
end
|
56
|
+
@git_lfs_cloned_repo_contents_path
|
57
|
+
end
|
58
|
+
rescue StandardError
|
59
|
+
@git_lfs_cloned_repo_contents_path
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
sig { override.returns(T.nilable(T::Hash[Symbol, T.untyped])) }
|
64
|
+
def ecosystem_versions
|
65
|
+
package_managers = {}
|
66
|
+
|
67
|
+
package_managers["bun"] = bun_version if bun_version
|
68
|
+
package_managers["unknown"] = 1 if package_managers.empty?
|
69
|
+
|
70
|
+
{
|
71
|
+
package_managers: package_managers
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
sig { override.returns(T::Array[DependencyFile]) }
|
76
|
+
def fetch_files
|
77
|
+
fetched_files = T.let([], T::Array[DependencyFile])
|
78
|
+
fetched_files << package_json
|
79
|
+
fetched_files << T.must(npmrc) if npmrc
|
80
|
+
fetched_files += bun_files if bun_version
|
81
|
+
fetched_files += workspace_package_jsons
|
82
|
+
fetched_files += path_dependencies(fetched_files)
|
83
|
+
|
84
|
+
fetched_files.uniq
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
sig { returns(T::Array[DependencyFile]) }
|
90
|
+
def bun_files
|
91
|
+
fetched_bun_files = []
|
92
|
+
fetched_bun_files << bun_lock if bun_lock
|
93
|
+
fetched_bun_files
|
94
|
+
end
|
95
|
+
|
96
|
+
# If every entry in the lockfile uses the same registry, we can infer
|
97
|
+
# that there is a global .npmrc file, so add it here as if it were in the repo.
|
98
|
+
|
99
|
+
sig { returns(T.nilable(T.any(Integer, String))) }
|
100
|
+
def bun_version
|
101
|
+
return @bun_version = nil unless allow_beta_ecosystems?
|
102
|
+
|
103
|
+
@bun_version ||= T.let(
|
104
|
+
package_manager_helper.setup(BunPackageManager::NAME),
|
105
|
+
T.nilable(T.any(Integer, String))
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
sig { returns(PackageManagerHelper) }
|
110
|
+
def package_manager_helper
|
111
|
+
@package_manager_helper ||= T.let(
|
112
|
+
PackageManagerHelper.new(
|
113
|
+
parsed_package_json,
|
114
|
+
lockfiles,
|
115
|
+
registry_config_files,
|
116
|
+
credentials
|
117
|
+
), T.nilable(PackageManagerHelper)
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
sig { returns(T::Hash[Symbol, T.nilable(Dependabot::DependencyFile)]) }
|
122
|
+
def lockfiles
|
123
|
+
{
|
124
|
+
bun: bun_lock
|
125
|
+
}
|
126
|
+
end
|
127
|
+
|
128
|
+
# Returns the .npmrc, and .yarnrc files for the repository.
|
129
|
+
# @return [Hash{Symbol => Dependabot::DependencyFile}]
|
130
|
+
sig { returns(T::Hash[Symbol, T.nilable(Dependabot::DependencyFile)]) }
|
131
|
+
def registry_config_files
|
132
|
+
{
|
133
|
+
npmrc: npmrc
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
sig { returns(DependencyFile) }
|
138
|
+
def package_json
|
139
|
+
@package_json ||= T.let(fetch_file_from_host(MANIFEST_FILENAME), T.nilable(DependencyFile))
|
140
|
+
end
|
141
|
+
|
142
|
+
sig { returns(T.nilable(DependencyFile)) }
|
143
|
+
def bun_lock
|
144
|
+
return @bun_lock if defined?(@bun_lock)
|
145
|
+
|
146
|
+
@bun_lock ||= T.let(fetch_file_if_present(BunPackageManager::LOCKFILE_NAME), T.nilable(DependencyFile))
|
147
|
+
|
148
|
+
return @bun_lock if @bun_lock || directory == "/"
|
149
|
+
|
150
|
+
@bun_lock = fetch_file_from_parent_directories(BunPackageManager::LOCKFILE_NAME)
|
151
|
+
end
|
152
|
+
|
153
|
+
sig { returns(T.nilable(DependencyFile)) }
|
154
|
+
def npmrc
|
155
|
+
return @npmrc if defined?(@npmrc)
|
156
|
+
|
157
|
+
@npmrc ||= T.let(fetch_support_file(BunPackageManager::RC_FILENAME), T.nilable(DependencyFile))
|
158
|
+
|
159
|
+
return @npmrc if @npmrc || directory == "/"
|
160
|
+
|
161
|
+
@npmrc = fetch_file_from_parent_directories(BunPackageManager::RC_FILENAME)
|
162
|
+
end
|
163
|
+
|
164
|
+
sig { returns(T::Array[DependencyFile]) }
|
165
|
+
def workspace_package_jsons
|
166
|
+
@workspace_package_jsons ||= T.let(fetch_workspace_package_jsons, T.nilable(T::Array[DependencyFile]))
|
167
|
+
end
|
168
|
+
|
169
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
170
|
+
sig { params(fetched_files: T::Array[DependencyFile]).returns(T::Array[DependencyFile]) }
|
171
|
+
def path_dependencies(fetched_files)
|
172
|
+
package_json_files = T.let([], T::Array[DependencyFile])
|
173
|
+
unfetchable_deps = T.let([], T::Array[[String, String]])
|
174
|
+
|
175
|
+
path_dependency_details(fetched_files).each do |name, path|
|
176
|
+
# This happens with relative paths in the package-lock. Skipping it since it results
|
177
|
+
# in /package.json which is outside of the project directory.
|
178
|
+
next if path == "file:"
|
179
|
+
|
180
|
+
path = path.gsub(PATH_DEPENDENCY_CLEAN_REGEX, "")
|
181
|
+
raise PathDependenciesNotReachable, "#{name} at #{path}" if path.start_with?("/")
|
182
|
+
|
183
|
+
filename = path
|
184
|
+
# NPM/Yarn support loading path dependencies from tarballs:
|
185
|
+
# https://docs.npmjs.com/cli/pack.html
|
186
|
+
filename = File.join(filename, MANIFEST_FILENAME) unless filename.end_with?(".tgz", ".tar", ".tar.gz")
|
187
|
+
cleaned_name = Pathname.new(filename).cleanpath.to_path
|
188
|
+
next if fetched_files.map(&:name).include?(cleaned_name)
|
189
|
+
|
190
|
+
begin
|
191
|
+
file = fetch_file_from_host(filename, fetch_submodules: true)
|
192
|
+
package_json_files << file
|
193
|
+
rescue Dependabot::DependencyFileNotFound
|
194
|
+
# Unfetchable tarballs should not be re-fetched as a package
|
195
|
+
unfetchable_deps << [name, path] unless path.end_with?(".tgz", ".tar", ".tar.gz")
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
if package_json_files.any?
|
200
|
+
package_json_files +=
|
201
|
+
path_dependencies(fetched_files + package_json_files)
|
202
|
+
end
|
203
|
+
|
204
|
+
package_json_files.tap { |fs| fs.each { |f| f.support_file = true } }
|
205
|
+
end
|
206
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
207
|
+
|
208
|
+
sig { params(fetched_files: T::Array[DependencyFile]).returns(T::Array[[String, String]]) }
|
209
|
+
def path_dependency_details(fetched_files)
|
210
|
+
package_json_path_deps = T.let([], T::Array[[String, String]])
|
211
|
+
|
212
|
+
fetched_files.each do |file|
|
213
|
+
package_json_path_deps +=
|
214
|
+
path_dependency_details_from_manifest(file)
|
215
|
+
end
|
216
|
+
|
217
|
+
[*package_json_path_deps].uniq
|
218
|
+
end
|
219
|
+
|
220
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
221
|
+
# rubocop:disable Metrics/AbcSize
|
222
|
+
sig { params(file: DependencyFile).returns(T::Array[[String, String]]) }
|
223
|
+
def path_dependency_details_from_manifest(file)
|
224
|
+
return [] unless file.name.end_with?(MANIFEST_FILENAME)
|
225
|
+
|
226
|
+
current_dir = file.name.rpartition("/").first
|
227
|
+
current_dir = nil if current_dir == ""
|
228
|
+
|
229
|
+
current_depth = File.join(directory, file.name).split("/").count { |path| !path.empty? }
|
230
|
+
path_to_directory = "../" * current_depth
|
231
|
+
|
232
|
+
dep_types = FileParser::DEPENDENCY_TYPES
|
233
|
+
parsed_manifest = JSON.parse(T.must(file.content))
|
234
|
+
dependency_objects = parsed_manifest.values_at(*dep_types).compact
|
235
|
+
# Fetch yarn "file:" path "resolutions" so the lockfile can be resolved
|
236
|
+
resolution_objects = parsed_manifest.values_at("resolutions").compact
|
237
|
+
manifest_objects = dependency_objects + resolution_objects
|
238
|
+
|
239
|
+
raise Dependabot::DependencyFileNotParseable, file.path unless manifest_objects.all?(Hash)
|
240
|
+
|
241
|
+
resolution_deps = resolution_objects.flat_map(&:to_a)
|
242
|
+
.map do |path, value|
|
243
|
+
# skip dependencies that contain invalid values such as inline comments, null, etc.
|
244
|
+
|
245
|
+
unless value.is_a?(String)
|
246
|
+
Dependabot.logger.warn("File fetcher: Skipping dependency \"#{path}\" " \
|
247
|
+
"with value: \"#{value}\"")
|
248
|
+
|
249
|
+
next
|
250
|
+
end
|
251
|
+
|
252
|
+
convert_dependency_path_to_name(path, value)
|
253
|
+
end
|
254
|
+
|
255
|
+
path_starts = PATH_DEPENDENCY_STARTS
|
256
|
+
(dependency_objects.flat_map(&:to_a) + resolution_deps)
|
257
|
+
.select { |_, v| v.is_a?(String) && v.start_with?(*path_starts) }
|
258
|
+
.map do |name, path|
|
259
|
+
path = path.gsub(PATH_DEPENDENCY_CLEAN_REGEX, "")
|
260
|
+
raise PathDependenciesNotReachable, "#{name} at #{path}" if path.start_with?("/", "#{path_to_directory}..")
|
261
|
+
|
262
|
+
path = File.join(current_dir, path) unless current_dir.nil?
|
263
|
+
[name, Pathname.new(path).cleanpath.to_path]
|
264
|
+
end
|
265
|
+
rescue JSON::ParserError
|
266
|
+
raise Dependabot::DependencyFileNotParseable, file.path
|
267
|
+
end
|
268
|
+
# rubocop:enable Metrics/AbcSize
|
269
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
270
|
+
|
271
|
+
sig { params(parsed_lockfile: T.untyped).returns(T::Array[[String, String]]) }
|
272
|
+
def path_dependency_details_from_npm_lockfile(parsed_lockfile)
|
273
|
+
path_starts = NPM_PATH_DEPENDENCY_STARTS
|
274
|
+
parsed_lockfile.fetch("dependencies", []).to_a
|
275
|
+
.select { |_, v| v.is_a?(Hash) }
|
276
|
+
.select { |_, v| v.fetch("version", "").start_with?(*path_starts) }
|
277
|
+
.map { |k, v| [k, v.fetch("version")] }
|
278
|
+
end
|
279
|
+
|
280
|
+
# Re-write the glob name to the targeted dependency name (which is used
|
281
|
+
# in the lockfile), for example "parent-package/**/sub-dep/target-dep" >
|
282
|
+
# "target-dep"
|
283
|
+
sig { params(path: String, value: String).returns([String, String]) }
|
284
|
+
def convert_dependency_path_to_name(path, value)
|
285
|
+
# Picking the last two parts that might include a scope
|
286
|
+
parts = path.split("/").last(2)
|
287
|
+
parts.shift if parts.count == 2 && !T.must(parts.first).start_with?("@")
|
288
|
+
[parts.join("/"), value]
|
289
|
+
end
|
290
|
+
|
291
|
+
sig { returns(T::Array[DependencyFile]) }
|
292
|
+
def fetch_workspace_package_jsons
|
293
|
+
return [] unless parsed_package_json["workspaces"]
|
294
|
+
|
295
|
+
workspace_paths(parsed_package_json["workspaces"]).filter_map do |workspace|
|
296
|
+
fetch_package_json_if_present(workspace)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
sig { params(workspace_object: T.untyped).returns(T::Array[String]) }
|
301
|
+
def workspace_paths(workspace_object)
|
302
|
+
paths_array =
|
303
|
+
if workspace_object.is_a?(Hash)
|
304
|
+
workspace_object.values_at("packages", "nohoist").flatten.compact
|
305
|
+
elsif workspace_object.is_a?(Array) then workspace_object
|
306
|
+
else
|
307
|
+
[] # Invalid lerna.json, which must not be in use
|
308
|
+
end
|
309
|
+
|
310
|
+
paths_array.flat_map { |path| recursive_find_directories(path) }
|
311
|
+
end
|
312
|
+
|
313
|
+
sig { params(glob: String).returns(T::Array[String]) }
|
314
|
+
def find_directories(glob)
|
315
|
+
return [glob] unless glob.include?("*")
|
316
|
+
|
317
|
+
unglobbed_path =
|
318
|
+
glob.gsub(%r{^\./}, "").gsub(/!\(.*?\)/, "*")
|
319
|
+
.split("*")
|
320
|
+
.first&.gsub(%r{(?<=/)[^/]*$}, "") || "."
|
321
|
+
|
322
|
+
dir = directory.gsub(%r{(^/|/$)}, "")
|
323
|
+
|
324
|
+
paths =
|
325
|
+
repo_contents(dir: unglobbed_path, raise_errors: false)
|
326
|
+
.select { |file| file.type == "dir" }
|
327
|
+
.map { |f| f.path.gsub(%r{^/?#{Regexp.escape(dir)}/?}, "") }
|
328
|
+
|
329
|
+
matching_paths(glob, paths)
|
330
|
+
end
|
331
|
+
|
332
|
+
sig { params(glob: String, paths: T::Array[String]).returns(T::Array[String]) }
|
333
|
+
def matching_paths(glob, paths)
|
334
|
+
glob = glob.gsub(%r{^\./}, "").gsub(/!\(.*?\)/, "*")
|
335
|
+
glob = "#{glob}/*" if glob.end_with?("**")
|
336
|
+
|
337
|
+
paths.select { |filename| File.fnmatch?(glob, filename, File::FNM_PATHNAME) }
|
338
|
+
end
|
339
|
+
|
340
|
+
sig { params(glob: String, prefix: String).returns(T::Array[String]) }
|
341
|
+
def recursive_find_directories(glob, prefix = "")
|
342
|
+
return [prefix + glob] unless glob.include?("*")
|
343
|
+
|
344
|
+
glob = glob.gsub(%r{^\./}, "")
|
345
|
+
glob_parts = glob.split("/")
|
346
|
+
|
347
|
+
current_glob = glob_parts.first
|
348
|
+
paths = find_directories(prefix + T.must(current_glob))
|
349
|
+
next_parts = current_glob == "**" ? glob_parts : glob_parts.drop(1)
|
350
|
+
return paths if next_parts.empty?
|
351
|
+
|
352
|
+
paths += paths.flat_map do |expanded_path|
|
353
|
+
recursive_find_directories(next_parts.join("/"), "#{expanded_path}/")
|
354
|
+
end
|
355
|
+
|
356
|
+
matching_paths(prefix + glob, paths)
|
357
|
+
end
|
358
|
+
|
359
|
+
sig { params(workspace: String).returns(T.nilable(DependencyFile)) }
|
360
|
+
def fetch_package_json_if_present(workspace)
|
361
|
+
file = File.join(workspace, MANIFEST_FILENAME)
|
362
|
+
|
363
|
+
begin
|
364
|
+
fetch_file_from_host(file)
|
365
|
+
rescue Dependabot::DependencyFileNotFound
|
366
|
+
# Not all paths matched by a workspace glob may contain a package.json
|
367
|
+
# file. Ignore if that's the case
|
368
|
+
nil
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
sig { returns(T.untyped) }
|
373
|
+
def parsed_package_json
|
374
|
+
parsed = JSON.parse(T.must(package_json.content))
|
375
|
+
raise Dependabot::DependencyFileNotParseable, package_json.path unless parsed.is_a?(Hash)
|
376
|
+
|
377
|
+
parsed
|
378
|
+
rescue JSON::ParserError
|
379
|
+
raise Dependabot::DependencyFileNotParseable, package_json.path
|
380
|
+
end
|
381
|
+
|
382
|
+
sig { params(filename: String).returns(T.nilable(DependencyFile)) }
|
383
|
+
def fetch_file_with_support(filename)
|
384
|
+
fetch_file_from_host(filename).tap { |f| f.support_file = true }
|
385
|
+
rescue Dependabot::DependencyFileNotFound
|
386
|
+
nil
|
387
|
+
end
|
388
|
+
|
389
|
+
sig { params(filename: String).returns(T.nilable(DependencyFile)) }
|
390
|
+
def fetch_file_from_parent_directories(filename)
|
391
|
+
(1..directory.split("/").count).each do |i|
|
392
|
+
file = fetch_file_with_support(("../" * i) + filename)
|
393
|
+
return file if file
|
394
|
+
end
|
395
|
+
nil
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
Dependabot::FileFetchers
|
402
|
+
.register(Dependabot::Bun::ECOSYSTEM, Dependabot::Bun::FileFetcher)
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "yaml"
|
5
|
+
require "dependabot/errors"
|
6
|
+
require "dependabot/bun/helpers"
|
7
|
+
require "sorbet-runtime"
|
8
|
+
|
9
|
+
module Dependabot
|
10
|
+
module Bun
|
11
|
+
class FileParser < Dependabot::FileParsers::Base
|
12
|
+
class BunLock
|
13
|
+
extend T::Sig
|
14
|
+
|
15
|
+
sig { params(dependency_file: DependencyFile).void }
|
16
|
+
def initialize(dependency_file)
|
17
|
+
@dependency_file = dependency_file
|
18
|
+
end
|
19
|
+
|
20
|
+
sig { returns(T::Hash[String, T.untyped]) }
|
21
|
+
def parsed
|
22
|
+
@parsed ||= begin
|
23
|
+
content = begin
|
24
|
+
# Since bun.lock is a JSONC file, which is a subset of YAML, we can use YAML to parse it
|
25
|
+
YAML.load(T.must(@dependency_file.content))
|
26
|
+
rescue Psych::SyntaxError => e
|
27
|
+
raise_invalid!("malformed JSONC at line #{e.line}, column #{e.column}")
|
28
|
+
end
|
29
|
+
raise_invalid!("expected to be an object") unless content.is_a?(Hash)
|
30
|
+
|
31
|
+
version = content["lockfileVersion"]
|
32
|
+
raise_invalid!("expected 'lockfileVersion' to be an integer") unless version.is_a?(Integer)
|
33
|
+
raise_invalid!("expected 'lockfileVersion' to be >= 0") unless version >= 0
|
34
|
+
|
35
|
+
T.let(content, T.untyped)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
sig { returns(Dependabot::FileParsers::Base::DependencySet) }
|
40
|
+
def dependencies
|
41
|
+
dependency_set = Dependabot::FileParsers::Base::DependencySet.new
|
42
|
+
|
43
|
+
# bun.lock v0 format:
|
44
|
+
# https://github.com/oven-sh/bun/blob/c130df6c589fdf28f9f3c7f23ed9901140bc9349/src/install/bun.lock.zig#L595-L605
|
45
|
+
|
46
|
+
packages = parsed["packages"]
|
47
|
+
raise_invalid!("expected 'packages' to be an object") unless packages.is_a?(Hash)
|
48
|
+
|
49
|
+
packages.each do |key, details|
|
50
|
+
raise_invalid!("expected 'packages.#{key}' to be an array") unless details.is_a?(Array)
|
51
|
+
|
52
|
+
resolution = details.first
|
53
|
+
raise_invalid!("expected 'packages.#{key}[0]' to be a string") unless resolution.is_a?(String)
|
54
|
+
|
55
|
+
name, version = resolution.split(/(?<=\w)\@/)
|
56
|
+
next if name.empty?
|
57
|
+
|
58
|
+
semver = Version.semver_for(version)
|
59
|
+
next unless semver
|
60
|
+
|
61
|
+
dependency_set << Dependency.new(
|
62
|
+
name: name,
|
63
|
+
version: semver.to_s,
|
64
|
+
package_manager: "bun",
|
65
|
+
requirements: []
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
dependency_set
|
70
|
+
end
|
71
|
+
|
72
|
+
sig do
|
73
|
+
params(dependency_name: String, requirement: T.untyped, _manifest_name: String)
|
74
|
+
.returns(T.nilable(T::Hash[String, T.untyped]))
|
75
|
+
end
|
76
|
+
def details(dependency_name, requirement, _manifest_name)
|
77
|
+
packages = parsed["packages"]
|
78
|
+
return unless packages.is_a?(Hash)
|
79
|
+
|
80
|
+
candidates =
|
81
|
+
packages
|
82
|
+
.select { |name, _| name == dependency_name }
|
83
|
+
.values
|
84
|
+
|
85
|
+
# If there's only one entry for this dependency, use it, even if
|
86
|
+
# the requirement in the lockfile doesn't match
|
87
|
+
if candidates.one?
|
88
|
+
parse_details(candidates.first)
|
89
|
+
else
|
90
|
+
candidate = candidates.find do |label, _|
|
91
|
+
label.scan(/(?<=\w)\@(?:npm:)?([^\s,]+)/).flatten.include?(requirement)
|
92
|
+
end&.last
|
93
|
+
parse_details(candidate)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
sig { params(message: String).void }
|
100
|
+
def raise_invalid!(message)
|
101
|
+
raise Dependabot::DependencyFileNotParseable.new(@dependency_file.path, "Invalid bun.lock file: #{message}")
|
102
|
+
end
|
103
|
+
|
104
|
+
sig do
|
105
|
+
params(entry: T.nilable(T::Array[T.untyped])).returns(T.nilable(T::Hash[String, T.untyped]))
|
106
|
+
end
|
107
|
+
def parse_details(entry)
|
108
|
+
return unless entry.is_a?(Array)
|
109
|
+
|
110
|
+
# Either:
|
111
|
+
# - "{name}@{version}", registry, details, integrity
|
112
|
+
# - "{name}@{resolution}", details
|
113
|
+
resolution = entry.first
|
114
|
+
return unless resolution.is_a?(String)
|
115
|
+
|
116
|
+
name, version = resolution.split(/(?<=\w)\@/)
|
117
|
+
semver = Version.semver_for(version)
|
118
|
+
|
119
|
+
if semver
|
120
|
+
registry, details, integrity = entry[1..3]
|
121
|
+
{
|
122
|
+
"name" => name,
|
123
|
+
"version" => semver.to_s,
|
124
|
+
"registry" => registry,
|
125
|
+
"details" => details,
|
126
|
+
"integrity" => integrity
|
127
|
+
}
|
128
|
+
else
|
129
|
+
details = entry[1]
|
130
|
+
{
|
131
|
+
"name" => name,
|
132
|
+
"resolution" => version,
|
133
|
+
"details" => details
|
134
|
+
}
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "dependabot/dependency_file"
|
5
|
+
require "dependabot/bun/file_parser"
|
6
|
+
require "dependabot/bun/helpers"
|
7
|
+
require "sorbet-runtime"
|
8
|
+
|
9
|
+
module Dependabot
|
10
|
+
module Bun
|
11
|
+
class FileParser < Dependabot::FileParsers::Base
|
12
|
+
class LockfileParser
|
13
|
+
extend T::Sig
|
14
|
+
|
15
|
+
require "dependabot/bun/file_parser/bun_lock"
|
16
|
+
|
17
|
+
DEFAULT_LOCKFILES = %w(package-lock.json yarn.lock pnpm-lock.yaml bun.lock npm-shrinkwrap.json).freeze
|
18
|
+
|
19
|
+
LockFile = T.type_alias { BunLock }
|
20
|
+
|
21
|
+
sig { params(dependency_files: T::Array[DependencyFile]).void }
|
22
|
+
def initialize(dependency_files:)
|
23
|
+
@dependency_files = dependency_files
|
24
|
+
end
|
25
|
+
|
26
|
+
sig { returns(Dependabot::FileParsers::Base::DependencySet) }
|
27
|
+
def parse_set
|
28
|
+
dependency_set = Dependabot::FileParsers::Base::DependencySet.new
|
29
|
+
|
30
|
+
# NOTE: The DependencySet will de-dupe our dependencies, so they
|
31
|
+
# end up unique by name. That's not a perfect representation of
|
32
|
+
# the nested nature of JS resolution, but it makes everything work
|
33
|
+
# comparably to other flat-resolution strategies
|
34
|
+
bun_locks.each do |file|
|
35
|
+
dependency_set += lockfile_for(file).dependencies
|
36
|
+
end
|
37
|
+
|
38
|
+
dependency_set
|
39
|
+
end
|
40
|
+
|
41
|
+
sig { returns(T::Array[Dependency]) }
|
42
|
+
def parse
|
43
|
+
Helpers.dependencies_with_all_versions_metadata(parse_set)
|
44
|
+
end
|
45
|
+
|
46
|
+
sig do
|
47
|
+
params(dependency_name: String, requirement: T.nilable(String), manifest_name: String)
|
48
|
+
.returns(T.nilable(T::Hash[String, T.untyped]))
|
49
|
+
end
|
50
|
+
def lockfile_details(dependency_name:, requirement:, manifest_name:)
|
51
|
+
details = T.let(nil, T.nilable(T::Hash[String, T.untyped]))
|
52
|
+
potential_lockfiles_for_manifest(manifest_name).each do |lockfile|
|
53
|
+
details = lockfile_for(lockfile).details(dependency_name, requirement, manifest_name)
|
54
|
+
|
55
|
+
break if details
|
56
|
+
end
|
57
|
+
|
58
|
+
details
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
sig { returns(T::Array[DependencyFile]) }
|
64
|
+
attr_reader :dependency_files
|
65
|
+
|
66
|
+
sig { params(manifest_filename: String).returns(T::Array[DependencyFile]) }
|
67
|
+
def potential_lockfiles_for_manifest(manifest_filename)
|
68
|
+
dir_name = File.dirname(manifest_filename)
|
69
|
+
possible_lockfile_names = DEFAULT_LOCKFILES.map do |f|
|
70
|
+
Pathname.new(File.join(dir_name, f)).cleanpath.to_path
|
71
|
+
end + DEFAULT_LOCKFILES
|
72
|
+
|
73
|
+
possible_lockfile_names.uniq
|
74
|
+
.filter_map { |nm| dependency_files.find { |f| f.name == nm } }
|
75
|
+
end
|
76
|
+
|
77
|
+
sig { params(file: DependencyFile).returns(LockFile) }
|
78
|
+
def lockfile_for(file)
|
79
|
+
@lockfiles ||= T.let({}, T.nilable(T::Hash[String, LockFile]))
|
80
|
+
@lockfiles[file.name] ||= case file.name
|
81
|
+
when *bun_locks.map(&:name)
|
82
|
+
BunLock.new(file)
|
83
|
+
else
|
84
|
+
raise "Unexpected lockfile: #{file.name}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
sig { params(extension: String).returns(T::Array[DependencyFile]) }
|
89
|
+
def select_files_by_extension(extension)
|
90
|
+
dependency_files.select { |f| f.name.end_with?(extension) }
|
91
|
+
end
|
92
|
+
|
93
|
+
sig { returns(T::Array[DependencyFile]) }
|
94
|
+
def bun_locks
|
95
|
+
@bun_locks ||= T.let(select_files_by_extension("bun.lock"), T.nilable(T::Array[DependencyFile]))
|
96
|
+
end
|
97
|
+
|
98
|
+
sig { returns(T.class_of(Dependabot::Bun::Version)) }
|
99
|
+
def version_class
|
100
|
+
Bun::Version
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|