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,256 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "sorbet-runtime"
|
5
|
+
|
6
|
+
require "dependabot/bun/file_updater"
|
7
|
+
|
8
|
+
module Dependabot
|
9
|
+
module Bun
|
10
|
+
class FileUpdater < Dependabot::FileUpdaters::Base
|
11
|
+
# Build a .npmrc file from the lockfile content, credentials, and any
|
12
|
+
# committed .npmrc
|
13
|
+
# We should refactor this to use UpdateChecker::RegistryFinder
|
14
|
+
class NpmrcBuilder
|
15
|
+
extend T::Sig
|
16
|
+
|
17
|
+
CENTRAL_REGISTRIES = T.let(%w(registry.npmjs.org).freeze, T::Array[String])
|
18
|
+
|
19
|
+
SCOPED_REGISTRY = /^\s*@(?<scope>\S+):registry\s*=\s*(?<registry>\S+)/
|
20
|
+
|
21
|
+
sig do
|
22
|
+
params(
|
23
|
+
dependency_files: T::Array[Dependabot::DependencyFile],
|
24
|
+
credentials: T::Array[Dependabot::Credential],
|
25
|
+
dependencies: T::Array[Dependabot::Dependency]
|
26
|
+
).void
|
27
|
+
end
|
28
|
+
def initialize(dependency_files:, credentials:, dependencies: [])
|
29
|
+
@dependency_files = dependency_files
|
30
|
+
@credentials = credentials
|
31
|
+
@dependencies = dependencies
|
32
|
+
end
|
33
|
+
|
34
|
+
# PROXY WORK
|
35
|
+
sig { returns(String) }
|
36
|
+
def npmrc_content
|
37
|
+
initial_content =
|
38
|
+
if npmrc_file then complete_npmrc_from_credentials
|
39
|
+
else
|
40
|
+
build_npmrc_content_from_lockfile
|
41
|
+
end
|
42
|
+
|
43
|
+
final_content = initial_content || ""
|
44
|
+
|
45
|
+
return final_content unless registry_credentials.any?
|
46
|
+
|
47
|
+
credential_lines_for_npmrc.each do |credential_line|
|
48
|
+
next if final_content.include?(credential_line)
|
49
|
+
|
50
|
+
final_content = [final_content, credential_line].reject(&:empty?).join("\n")
|
51
|
+
end
|
52
|
+
|
53
|
+
final_content
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
sig { returns(T::Array[Dependabot::DependencyFile]) }
|
59
|
+
attr_reader :dependency_files
|
60
|
+
|
61
|
+
sig { returns(T::Array[Dependabot::Credential]) }
|
62
|
+
attr_reader :credentials
|
63
|
+
|
64
|
+
sig { returns(T::Array[Dependabot::Dependency]) }
|
65
|
+
attr_reader :dependencies
|
66
|
+
|
67
|
+
sig { returns(T.nilable(String)) }
|
68
|
+
def build_npmrc_content_from_lockfile
|
69
|
+
return unless global_registry
|
70
|
+
|
71
|
+
registry = T.must(global_registry)["registry"]
|
72
|
+
registry = "https://#{registry}" unless registry&.start_with?("http")
|
73
|
+
"registry = #{registry}\n" \
|
74
|
+
"#{npmrc_global_registry_auth_line}" \
|
75
|
+
"always-auth = true"
|
76
|
+
end
|
77
|
+
|
78
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
79
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
80
|
+
sig { returns(T.nilable(Dependabot::Credential)) }
|
81
|
+
def global_registry
|
82
|
+
return @global_registry if defined?(@global_registry)
|
83
|
+
|
84
|
+
@global_registry = T.let(
|
85
|
+
registry_credentials.find do |cred|
|
86
|
+
next false if CENTRAL_REGISTRIES.include?(cred["registry"])
|
87
|
+
|
88
|
+
# If all the URLs include this registry, it's global
|
89
|
+
next true if dependency_urls&.size&.positive? && dependency_urls&.all? do |url|
|
90
|
+
url.include?(T.must(cred["registry"]))
|
91
|
+
end
|
92
|
+
|
93
|
+
# Check if this registry has already been defined in .npmrc as a scoped registry
|
94
|
+
next false if npmrc_scoped_registries&.any? { |sr| sr.include?(T.must(cred["registry"])) }
|
95
|
+
|
96
|
+
# If any unscoped URLs include this registry, assume it's global
|
97
|
+
dependency_urls
|
98
|
+
&.reject { |u| u.include?("@") || u.include?("%40") }
|
99
|
+
&.any? { |url| url.include?(T.must(cred["registry"])) }
|
100
|
+
end,
|
101
|
+
T.nilable(Dependabot::Credential)
|
102
|
+
)
|
103
|
+
end
|
104
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
105
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
106
|
+
sig { returns(String) }
|
107
|
+
def npmrc_global_registry_auth_line
|
108
|
+
# This token is passed in from the Dependabot Config
|
109
|
+
# We write it to the .npmrc file so that it can be used by the VulnerabilityAuditor
|
110
|
+
token = global_registry&.fetch("token", nil)
|
111
|
+
return "" unless token
|
112
|
+
|
113
|
+
auth_line(token, global_registry&.fetch("registry")) + "\n"
|
114
|
+
end
|
115
|
+
|
116
|
+
sig { returns(T.nilable(T::Array[String])) }
|
117
|
+
def dependency_urls
|
118
|
+
return @dependency_urls if defined?(@dependency_urls)
|
119
|
+
|
120
|
+
@dependency_urls = []
|
121
|
+
|
122
|
+
if dependencies.any?
|
123
|
+
@dependency_urls = dependencies.map do |dependency|
|
124
|
+
UpdateChecker::RegistryFinder.new(
|
125
|
+
dependency: dependency,
|
126
|
+
credentials: credentials,
|
127
|
+
npmrc_file: npmrc_file
|
128
|
+
).dependency_url
|
129
|
+
end
|
130
|
+
return @dependency_urls
|
131
|
+
end
|
132
|
+
|
133
|
+
# The registry URL for Bintray goes into the lockfile in a
|
134
|
+
# modified format, so we modify it back before checking against
|
135
|
+
# our credentials
|
136
|
+
@dependency_urls = T.let(
|
137
|
+
@dependency_urls.map do |url|
|
138
|
+
url.gsub("dl.bintray.com//", "api.bintray.com/npm/")
|
139
|
+
end,
|
140
|
+
T.nilable(T::Array[String])
|
141
|
+
)
|
142
|
+
end
|
143
|
+
sig { returns(String) }
|
144
|
+
def complete_npmrc_from_credentials
|
145
|
+
# removes attribute timeout to allow for job update,
|
146
|
+
# having a timeout=xxxxx value is causing some jobs to fail
|
147
|
+
initial_content = T.must(T.must(npmrc_file).content)
|
148
|
+
.gsub(/^.*\$\{.*\}.*/, "").strip.gsub(/^timeout.*/, "").strip + "\n"
|
149
|
+
|
150
|
+
return initial_content unless global_registry
|
151
|
+
|
152
|
+
registry = T.must(global_registry)["registry"]
|
153
|
+
registry = "https://#{registry}" unless registry&.start_with?("http")
|
154
|
+
initial_content +
|
155
|
+
"registry = #{registry}\n" \
|
156
|
+
"#{npmrc_global_registry_auth_line}" \
|
157
|
+
"always-auth = true\n"
|
158
|
+
end
|
159
|
+
|
160
|
+
sig { returns(T::Array[String]) }
|
161
|
+
def credential_lines_for_npmrc
|
162
|
+
lines = T.let([], T::Array[String])
|
163
|
+
registry_credentials.each do |cred|
|
164
|
+
registry = cred.fetch("registry")
|
165
|
+
|
166
|
+
lines += T.must(registry_scopes(registry)) if registry_scopes(registry)
|
167
|
+
|
168
|
+
token = cred.fetch("token", nil)
|
169
|
+
next unless token
|
170
|
+
|
171
|
+
lines << auth_line(token, registry)
|
172
|
+
end
|
173
|
+
|
174
|
+
return lines unless lines.any? { |str| str.include?("auth=") }
|
175
|
+
|
176
|
+
# Work around a suspected yarn bug
|
177
|
+
["always-auth = true"] + lines
|
178
|
+
end
|
179
|
+
|
180
|
+
sig { params(token: String, registry: T.nilable(String)).returns(String) }
|
181
|
+
def auth_line(token, registry = nil)
|
182
|
+
auth = if token.include?(":")
|
183
|
+
encoded_token = Base64.encode64(token).delete("\n")
|
184
|
+
"_auth=#{encoded_token}"
|
185
|
+
elsif Base64.decode64(token).ascii_only? &&
|
186
|
+
Base64.decode64(token).include?(":")
|
187
|
+
"_auth=#{token.delete("\n")}"
|
188
|
+
else
|
189
|
+
"_authToken=#{token}"
|
190
|
+
end
|
191
|
+
|
192
|
+
return auth unless registry
|
193
|
+
|
194
|
+
# We need to ensure the registry uri ends with a trailing slash in the npmrc file
|
195
|
+
# but we do not want to add one if it already exists
|
196
|
+
registry_with_trailing_slash = registry.sub(%r{\/?$}, "/")
|
197
|
+
|
198
|
+
"//#{registry_with_trailing_slash}:#{auth}"
|
199
|
+
end
|
200
|
+
|
201
|
+
sig { returns(T.nilable(T::Array[String])) }
|
202
|
+
def npmrc_scoped_registries
|
203
|
+
return [] unless npmrc_file
|
204
|
+
|
205
|
+
@npmrc_scoped_registries ||= T.let(
|
206
|
+
T.must(T.must(npmrc_file).content).lines.select { |line| line.match?(SCOPED_REGISTRY) }
|
207
|
+
.filter_map { |line| line.match(SCOPED_REGISTRY)&.named_captures&.fetch("registry") },
|
208
|
+
T.nilable(T::Array[String])
|
209
|
+
)
|
210
|
+
end
|
211
|
+
|
212
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
213
|
+
sig { params(registry: String).returns(T.nilable(T::Array[String])) }
|
214
|
+
def registry_scopes(registry)
|
215
|
+
# Central registries don't just apply to scopes
|
216
|
+
return if CENTRAL_REGISTRIES.include?(registry)
|
217
|
+
return unless dependency_urls
|
218
|
+
|
219
|
+
other_regs =
|
220
|
+
registry_credentials.map { |c| c.fetch("registry") } -
|
221
|
+
[registry]
|
222
|
+
affected_urls =
|
223
|
+
dependency_urls
|
224
|
+
&.select do |url|
|
225
|
+
next false unless url.include?(registry)
|
226
|
+
|
227
|
+
other_regs.none? { |r| r.include?(registry) && url.include?(r) }
|
228
|
+
end
|
229
|
+
|
230
|
+
scopes = T.must(affected_urls).map do |url|
|
231
|
+
url.split(/\%40|@/)[1]&.split(%r{\%2[fF]|/})&.first
|
232
|
+
end.uniq
|
233
|
+
|
234
|
+
# Registry used for unscoped packages
|
235
|
+
return if scopes.include?(nil)
|
236
|
+
|
237
|
+
scopes.map { |scope| "@#{scope}:registry=https://#{registry}" }
|
238
|
+
end
|
239
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
240
|
+
|
241
|
+
sig { returns(T::Array[Dependabot::Credential]) }
|
242
|
+
def registry_credentials
|
243
|
+
credentials.select { |cred| cred.fetch("type") == "npm_registry" }
|
244
|
+
end
|
245
|
+
|
246
|
+
sig { returns(T.nilable(Dependabot::DependencyFile)) }
|
247
|
+
def npmrc_file
|
248
|
+
@npmrc_file ||= T.let(
|
249
|
+
dependency_files.find { |f| f.name.end_with?(".npmrc") },
|
250
|
+
T.nilable(Dependabot::DependencyFile)
|
251
|
+
)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "dependabot/bun/file_updater"
|
5
|
+
require "dependabot/bun/file_parser"
|
6
|
+
|
7
|
+
module Dependabot
|
8
|
+
module Bun
|
9
|
+
class FileUpdater < Dependabot::FileUpdaters::Base
|
10
|
+
class PackageJsonPreparer
|
11
|
+
def initialize(package_json_content:)
|
12
|
+
@package_json_content = package_json_content
|
13
|
+
end
|
14
|
+
|
15
|
+
def prepared_content
|
16
|
+
content = package_json_content
|
17
|
+
content = replace_ssh_sources(content)
|
18
|
+
content = remove_workspace_path_prefixes(content)
|
19
|
+
content = remove_invalid_characters(content)
|
20
|
+
content
|
21
|
+
end
|
22
|
+
|
23
|
+
def replace_ssh_sources(content)
|
24
|
+
updated_content = content
|
25
|
+
|
26
|
+
git_ssh_requirements_to_swap.each do |req|
|
27
|
+
new_req = req.gsub(%r{git\+ssh://git@(.*?)[:/]}, 'https://\1/')
|
28
|
+
updated_content = updated_content.gsub(req, new_req)
|
29
|
+
end
|
30
|
+
|
31
|
+
updated_content
|
32
|
+
end
|
33
|
+
|
34
|
+
# A bug prevents Yarn recognising that a directory is part of a
|
35
|
+
# workspace if it is specified with a `./` prefix.
|
36
|
+
def remove_workspace_path_prefixes(content)
|
37
|
+
json = JSON.parse(content)
|
38
|
+
return content unless json.key?("workspaces")
|
39
|
+
|
40
|
+
workspace_object = json.fetch("workspaces")
|
41
|
+
paths_array =
|
42
|
+
if workspace_object.is_a?(Hash)
|
43
|
+
workspace_object.values_at("packages", "nohoist")
|
44
|
+
.flatten.compact
|
45
|
+
elsif workspace_object.is_a?(Array) then workspace_object
|
46
|
+
else
|
47
|
+
raise "Unexpected workspace object"
|
48
|
+
end
|
49
|
+
|
50
|
+
paths_array.each { |path| path.gsub!(%r{^\./}, "") }
|
51
|
+
|
52
|
+
JSON.pretty_generate(json)
|
53
|
+
end
|
54
|
+
|
55
|
+
def remove_invalid_characters(content)
|
56
|
+
content
|
57
|
+
.gsub(/\{\{[^\}]*?\}\}/, "something") # {{ nm }} syntax not allowed
|
58
|
+
.gsub(/(?<!\\)\\ /, " ") # escaped whitespace not allowed
|
59
|
+
.gsub(%r{^\s*//.*}, " ") # comments are not allowed
|
60
|
+
end
|
61
|
+
|
62
|
+
def swapped_ssh_requirements
|
63
|
+
git_ssh_requirements_to_swap
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
attr_reader :package_json_content
|
69
|
+
|
70
|
+
def git_ssh_requirements_to_swap
|
71
|
+
return @git_ssh_requirements_to_swap if @git_ssh_requirements_to_swap
|
72
|
+
|
73
|
+
@git_ssh_requirements_to_swap = []
|
74
|
+
|
75
|
+
Bun::FileParser.each_dependency(JSON.parse(package_json_content)) do |_, req, _t|
|
76
|
+
next unless req.is_a?(String)
|
77
|
+
next unless req.start_with?("git+ssh:")
|
78
|
+
|
79
|
+
req = req.split("#").first
|
80
|
+
@git_ssh_requirements_to_swap << req
|
81
|
+
end
|
82
|
+
|
83
|
+
@git_ssh_requirements_to_swap
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|