dependabot-npm_and_yarn 0.292.0 → 0.293.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,11 @@ require "dependabot/ecosystem"
6
6
  require "dependabot/npm_and_yarn/requirement"
7
7
  require "dependabot/npm_and_yarn/version_selector"
8
8
  require "dependabot/npm_and_yarn/registry_helper"
9
+ require "dependabot/npm_and_yarn/npm_package_manager"
10
+ require "dependabot/npm_and_yarn/yarn_package_manager"
11
+ require "dependabot/npm_and_yarn/pnpm_package_manager"
12
+ require "dependabot/npm_and_yarn/bun_package_manager"
13
+ require "dependabot/npm_and_yarn/language"
9
14
 
10
15
  module Dependabot
11
16
  module NpmAndYarn
@@ -47,163 +52,6 @@ module Dependabot
47
52
  MANIFEST_PACKAGE_MANAGER_KEY = "packageManager"
48
53
  MANIFEST_ENGINES_KEY = "engines"
49
54
 
50
- class NpmPackageManager < Ecosystem::VersionManager
51
- extend T::Sig
52
- NAME = "npm"
53
- RC_FILENAME = ".npmrc"
54
- LOCKFILE_NAME = "package-lock.json"
55
- SHRINKWRAP_LOCKFILE_NAME = "npm-shrinkwrap.json"
56
-
57
- NPM_V6 = "6"
58
- NPM_V7 = "7"
59
- NPM_V8 = "8"
60
- NPM_V9 = "9"
61
- NPM_V10 = "10"
62
-
63
- # Keep versions in ascending order
64
- SUPPORTED_VERSIONS = T.let([
65
- Version.new(NPM_V7),
66
- Version.new(NPM_V8),
67
- Version.new(NPM_V9),
68
- Version.new(NPM_V10)
69
- ].freeze, T::Array[Dependabot::Version])
70
-
71
- DEPRECATED_VERSIONS = T.let([Version.new(NPM_V6)].freeze, T::Array[Dependabot::Version])
72
-
73
- sig do
74
- params(
75
- detected_version: T.nilable(String),
76
- raw_version: T.nilable(String),
77
- requirement: T.nilable(Dependabot::NpmAndYarn::Requirement)
78
- ).void
79
- end
80
- def initialize(detected_version: nil, raw_version: nil, requirement: nil)
81
- super(
82
- name: NAME,
83
- detected_version: detected_version ? Version.new(detected_version) : nil,
84
- version: raw_version ? Version.new(raw_version) : nil,
85
- deprecated_versions: DEPRECATED_VERSIONS,
86
- supported_versions: SUPPORTED_VERSIONS,
87
- requirement: requirement
88
- )
89
- end
90
-
91
- sig { override.returns(T::Boolean) }
92
- def deprecated?
93
- return false unless detected_version
94
-
95
- return false if unsupported?
96
-
97
- return false unless Dependabot::Experiments.enabled?(:npm_v6_deprecation_warning)
98
-
99
- deprecated_versions.include?(detected_version)
100
- end
101
-
102
- sig { override.returns(T::Boolean) }
103
- def unsupported?
104
- return false unless detected_version
105
-
106
- return false unless Dependabot::Experiments.enabled?(:npm_v6_unsupported_error)
107
-
108
- supported_versions.all? { |supported| supported > detected_version }
109
- end
110
- end
111
-
112
- class YarnPackageManager < Ecosystem::VersionManager
113
- extend T::Sig
114
- NAME = "yarn"
115
- RC_FILENAME = ".yarnrc"
116
- RC_YML_FILENAME = ".yarnrc.yml"
117
- LOCKFILE_NAME = "yarn.lock"
118
-
119
- YARN_V1 = "1"
120
- YARN_V2 = "2"
121
- YARN_V3 = "3"
122
-
123
- SUPPORTED_VERSIONS = T.let([
124
- Version.new(YARN_V1),
125
- Version.new(YARN_V2),
126
- Version.new(YARN_V3)
127
- ].freeze, T::Array[Dependabot::Version])
128
-
129
- DEPRECATED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])
130
-
131
- sig do
132
- params(
133
- detected_version: T.nilable(String),
134
- raw_version: T.nilable(String),
135
- requirement: T.nilable(Dependabot::NpmAndYarn::Requirement)
136
- ).void
137
- end
138
- def initialize(detected_version: nil, raw_version: nil, requirement: nil)
139
- super(
140
- name: NAME,
141
- detected_version: detected_version ? Version.new(detected_version) : nil,
142
- version: raw_version ? Version.new(raw_version) : nil,
143
- deprecated_versions: DEPRECATED_VERSIONS,
144
- supported_versions: SUPPORTED_VERSIONS,
145
- requirement: requirement
146
- )
147
- end
148
-
149
- sig { override.returns(T::Boolean) }
150
- def deprecated?
151
- false
152
- end
153
-
154
- sig { override.returns(T::Boolean) }
155
- def unsupported?
156
- false
157
- end
158
- end
159
-
160
- class PNPMPackageManager < Ecosystem::VersionManager
161
- extend T::Sig
162
- NAME = "pnpm"
163
- LOCKFILE_NAME = "pnpm-lock.yaml"
164
- PNPM_WS_YML_FILENAME = "pnpm-workspace.yaml"
165
-
166
- PNPM_V7 = "7"
167
- PNPM_V8 = "8"
168
- PNPM_V9 = "9"
169
-
170
- SUPPORTED_VERSIONS = T.let([
171
- Version.new(PNPM_V7),
172
- Version.new(PNPM_V8),
173
- Version.new(PNPM_V9)
174
- ].freeze, T::Array[Dependabot::Version])
175
-
176
- DEPRECATED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])
177
-
178
- sig do
179
- params(
180
- detected_version: T.nilable(String),
181
- raw_version: T.nilable(String),
182
- requirement: T.nilable(Dependabot::NpmAndYarn::Requirement)
183
- ).void
184
- end
185
- def initialize(detected_version: nil, raw_version: nil, requirement: nil)
186
- super(
187
- name: NAME,
188
- detected_version: detected_version ? Version.new(detected_version) : nil,
189
- version: raw_version ? Version.new(raw_version) : nil,
190
- deprecated_versions: DEPRECATED_VERSIONS,
191
- supported_versions: SUPPORTED_VERSIONS,
192
- requirement: requirement
193
- )
194
- end
195
-
196
- sig { override.returns(T::Boolean) }
197
- def deprecated?
198
- false
199
- end
200
-
201
- sig { override.returns(T::Boolean) }
202
- def unsupported?
203
- false
204
- end
205
- end
206
-
207
55
  DEFAULT_PACKAGE_MANAGER = NpmPackageManager::NAME
208
56
 
209
57
  # Define a type alias for the expected class interface
@@ -221,6 +69,9 @@ module Dependabot
221
69
  PNPMPackageManager::NAME => PNPMPackageManager
222
70
  }.freeze, T::Hash[String, NpmAndYarnPackageManagerClassType])
223
71
 
72
+ # Error malformed version number string
73
+ ERROR_MALFORMED_VERSION_NUMBER = "Malformed version number"
74
+
224
75
  class PackageManagerDetector
225
76
  extend T::Sig
226
77
  extend T::Helpers
@@ -285,43 +136,6 @@ module Dependabot
285
136
  end
286
137
  end
287
138
 
288
- class Language < Ecosystem::VersionManager
289
- extend T::Sig
290
- NAME = "node"
291
-
292
- SUPPORTED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])
293
-
294
- DEPRECATED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])
295
-
296
- sig do
297
- params(
298
- detected_version: T.nilable(String),
299
- raw_version: T.nilable(String),
300
- requirement: T.nilable(Dependabot::NpmAndYarn::Requirement)
301
- ).void
302
- end
303
- def initialize(detected_version: nil, raw_version: nil, requirement: nil)
304
- super(
305
- name: NAME,
306
- detected_version: detected_version ? Version.new(detected_version) : nil,
307
- version: raw_version ? Version.new(raw_version) : nil,
308
- deprecated_versions: DEPRECATED_VERSIONS,
309
- supported_versions: SUPPORTED_VERSIONS,
310
- requirement: requirement
311
- )
312
- end
313
-
314
- sig { override.returns(T::Boolean) }
315
- def deprecated?
316
- false
317
- end
318
-
319
- sig { override.returns(T::Boolean) }
320
- def unsupported?
321
- false
322
- end
323
- end
324
-
325
139
  class PackageManagerHelper
326
140
  extend T::Sig
327
141
  extend T::Helpers
@@ -520,6 +334,10 @@ module Dependabot
520
334
  raw_version: installed_version,
521
335
  requirement: package_manager_requirement
522
336
  )
337
+ rescue ArgumentError => e
338
+ raise DependencyFileNotParseable, e.message if e.message.include?(ERROR_MALFORMED_VERSION_NUMBER)
339
+
340
+ raise
523
341
  rescue StandardError => e
524
342
  Dependabot.logger.error("Error resolving package manager for #{name || 'default'}: #{e.message}")
525
343
  raise
@@ -0,0 +1,55 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ require "dependabot/npm_and_yarn/package_manager"
5
+
6
+ module Dependabot
7
+ module NpmAndYarn
8
+ class PNPMPackageManager < Ecosystem::VersionManager
9
+ extend T::Sig
10
+ NAME = "pnpm"
11
+ LOCKFILE_NAME = "pnpm-lock.yaml"
12
+ PNPM_WS_YML_FILENAME = "pnpm-workspace.yaml"
13
+
14
+ PNPM_V7 = "7"
15
+ PNPM_V8 = "8"
16
+ PNPM_V9 = "9"
17
+
18
+ SUPPORTED_VERSIONS = T.let([
19
+ Version.new(PNPM_V7),
20
+ Version.new(PNPM_V8),
21
+ Version.new(PNPM_V9)
22
+ ].freeze, T::Array[Dependabot::Version])
23
+
24
+ DEPRECATED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])
25
+
26
+ sig do
27
+ params(
28
+ detected_version: T.nilable(String),
29
+ raw_version: T.nilable(String),
30
+ requirement: T.nilable(Dependabot::NpmAndYarn::Requirement)
31
+ ).void
32
+ end
33
+ def initialize(detected_version: nil, raw_version: nil, requirement: nil)
34
+ super(
35
+ name: NAME,
36
+ detected_version: detected_version ? Version.new(detected_version) : nil,
37
+ version: raw_version ? Version.new(raw_version) : nil,
38
+ deprecated_versions: DEPRECATED_VERSIONS,
39
+ supported_versions: SUPPORTED_VERSIONS,
40
+ requirement: requirement
41
+ )
42
+ end
43
+
44
+ sig { override.returns(T::Boolean) }
45
+ def deprecated?
46
+ false
47
+ end
48
+
49
+ sig { override.returns(T::Boolean) }
50
+ def unsupported?
51
+ false
52
+ end
53
+ end
54
+ end
55
+ end
@@ -68,6 +68,7 @@ module Dependabot
68
68
  "package-lock.json",
69
69
  "yarn.lock",
70
70
  "npm-shrinkwrap.json",
71
+ "bun.lock",
71
72
  "pnpm-lock.yaml"
72
73
  )
73
74
  end
@@ -49,6 +49,12 @@ module Dependabot
49
49
  .select { |f| f.name.end_with?("pnpm-lock.yaml") }
50
50
  end
51
51
 
52
+ def bun_locks
53
+ @bun_locks ||=
54
+ dependency_files
55
+ .select { |f| f.name.end_with?("bun.lock") }
56
+ end
57
+
52
58
  def root_yarn_lock
53
59
  @root_yarn_lock ||=
54
60
  dependency_files
@@ -61,6 +67,12 @@ module Dependabot
61
67
  .find { |f| f.name == "pnpm-lock.yaml" }
62
68
  end
63
69
 
70
+ def root_bun_lock
71
+ @root_bun_lock ||=
72
+ dependency_files
73
+ .find { |f| f.name == "bun.lock" }
74
+ end
75
+
64
76
  def shrinkwraps
65
77
  @shrinkwraps ||=
66
78
  dependency_files
@@ -68,7 +80,7 @@ module Dependabot
68
80
  end
69
81
 
70
82
  def lockfiles
71
- [*package_locks, *shrinkwraps, *yarn_locks, *pnpm_locks]
83
+ [*package_locks, *shrinkwraps, *yarn_locks, *pnpm_locks, *bun_locks]
72
84
  end
73
85
 
74
86
  def package_files
@@ -89,12 +101,7 @@ module Dependabot
89
101
  File.write(f.name, prepared_yarn_lockfile_content(f.content))
90
102
  end
91
103
 
92
- pnpm_locks.each do |f|
93
- FileUtils.mkdir_p(Pathname.new(f.name).dirname)
94
- File.write(f.name, f.content)
95
- end
96
-
97
- [*package_locks, *shrinkwraps].each do |f|
104
+ [*package_locks, *shrinkwraps, *pnpm_locks, *bun_locks].each do |f|
98
105
  FileUtils.mkdir_p(Pathname.new(f.name).dirname)
99
106
  File.write(f.name, f.content)
100
107
  end
@@ -70,6 +70,8 @@ module Dependabot
70
70
  run_yarn_updater(path, lockfile_name)
71
71
  elsif lockfile.name.end_with?("pnpm-lock.yaml")
72
72
  run_pnpm_updater(path, lockfile_name)
73
+ elsif lockfile.name.end_with?("bun.lock")
74
+ run_bun_updater(path, lockfile_name)
73
75
  elsif !Helpers.npm8?(lockfile)
74
76
  run_npm6_updater(path, lockfile_name)
75
77
  else
@@ -153,6 +155,18 @@ module Dependabot
153
155
  end
154
156
  end
155
157
 
158
+ def run_bun_updater(path, lockfile_name)
159
+ SharedHelpers.with_git_configured(credentials: credentials) do
160
+ Dir.chdir(path) do
161
+ Helpers.run_bun_command(
162
+ "update #{dependency.name} --save-text-lockfile",
163
+ fingerprint: "update <dependency_name> --save-text-lockfile"
164
+ )
165
+ { lockfile_name => File.read(lockfile_name) }
166
+ end
167
+ end
168
+ end
169
+
156
170
  def run_npm6_updater(path, lockfile_name)
157
171
  SharedHelpers.with_git_configured(credentials: credentials) do
158
172
  Dir.chdir(path) do
@@ -413,6 +413,8 @@ module Dependabot
413
413
  end
414
414
 
415
415
  def error_details_from_captures(captures)
416
+ return {} unless captures.is_a?(Hash)
417
+
416
418
  required_dep_captures = captures.fetch("required_dep")
417
419
  requiring_dep_captures = captures.fetch("requiring_dep")
418
420
  return {} unless required_dep_captures && requiring_dep_captures
@@ -549,12 +551,18 @@ module Dependabot
549
551
  npm_lockfiles = lockfiles_for_path(lockfiles: dependency_files_builder.package_locks, path: path)
550
552
  return run_npm_checker(path: path, version: version) if npm_lockfiles.any?
551
553
 
554
+ bun_lockfiles = lockfiles_for_path(lockfiles: dependency_files_builder.bun_locks, path: path)
555
+ return run_bun_checker(path: path, version: version) if bun_lockfiles.any?
556
+
552
557
  root_yarn_lock = dependency_files_builder.root_yarn_lock
553
558
  return run_yarn_checker(path: path, version: version, lockfile: root_yarn_lock) if root_yarn_lock
554
559
 
555
560
  root_pnpm_lock = dependency_files_builder.root_pnpm_lock
556
561
  return run_pnpm_checker(path: path, version: version) if root_pnpm_lock
557
562
 
563
+ root_bun_lock = dependency_files_builder.root_bun_lock
564
+ return run_bun_checker(path: path, version: version) if root_bun_lock
565
+
558
566
  run_npm_checker(path: path, version: version)
559
567
  rescue SharedHelpers::HelperSubprocessFailed => e
560
568
  handle_peer_dependency_errors(e.message)
@@ -583,6 +591,17 @@ module Dependabot
583
591
  end
584
592
  end
585
593
 
594
+ def run_bun_checker(path:, version:)
595
+ SharedHelpers.with_git_configured(credentials: credentials) do
596
+ Dir.chdir(path) do
597
+ Helpers.run_bun_command(
598
+ "update #{dependency.name}@#{version} --save-text-lockfile",
599
+ fingerprint: "update <dependency_name>@<version> --save-text-lockfile"
600
+ )
601
+ end
602
+ end
603
+ end
604
+
586
605
  def run_yarn_berry_checker(path:, version:)
587
606
  # This method mimics calling a native helper in order to comply with the caller's expectations
588
607
  # Specifically we add the dependency at the specified updated version
@@ -0,0 +1,56 @@
1
+ # typed: strong
2
+ # frozen_string_literal: true
3
+
4
+ require "dependabot/npm_and_yarn/package_manager"
5
+
6
+ module Dependabot
7
+ module NpmAndYarn
8
+ class YarnPackageManager < Ecosystem::VersionManager
9
+ extend T::Sig
10
+ NAME = "yarn"
11
+ RC_FILENAME = ".yarnrc"
12
+ RC_YML_FILENAME = ".yarnrc.yml"
13
+ LOCKFILE_NAME = "yarn.lock"
14
+
15
+ YARN_V1 = "1"
16
+ YARN_V2 = "2"
17
+ YARN_V3 = "3"
18
+
19
+ SUPPORTED_VERSIONS = T.let([
20
+ Version.new(YARN_V1),
21
+ Version.new(YARN_V2),
22
+ Version.new(YARN_V3)
23
+ ].freeze, T::Array[Dependabot::Version])
24
+
25
+ DEPRECATED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])
26
+
27
+ sig do
28
+ params(
29
+ detected_version: T.nilable(String),
30
+ raw_version: T.nilable(String),
31
+ requirement: T.nilable(Dependabot::NpmAndYarn::Requirement)
32
+ ).void
33
+ end
34
+ def initialize(detected_version: nil, raw_version: nil, requirement: nil)
35
+ super(
36
+ name: NAME,
37
+ detected_version: detected_version ? Version.new(detected_version) : nil,
38
+ version: raw_version ? Version.new(raw_version) : nil,
39
+ deprecated_versions: DEPRECATED_VERSIONS,
40
+ supported_versions: SUPPORTED_VERSIONS,
41
+ requirement: requirement
42
+ )
43
+ end
44
+
45
+ sig { override.returns(T::Boolean) }
46
+ def deprecated?
47
+ false
48
+ end
49
+
50
+ sig { override.returns(T::Boolean) }
51
+ def unsupported?
52
+ false
53
+ end
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-npm_and_yarn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.292.0
4
+ version: 0.293.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-09 00:00:00.000000000 Z
11
+ date: 2025-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dependabot-common
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.292.0
19
+ version: 0.293.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.292.0
26
+ version: 0.293.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: debug
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -306,15 +306,18 @@ files:
306
306
  - helpers/test/yarn/helpers.js
307
307
  - helpers/test/yarn/updater.test.js
308
308
  - lib/dependabot/npm_and_yarn.rb
309
+ - lib/dependabot/npm_and_yarn/bun_package_manager.rb
309
310
  - lib/dependabot/npm_and_yarn/dependency_files_filterer.rb
310
311
  - lib/dependabot/npm_and_yarn/file_fetcher.rb
311
312
  - lib/dependabot/npm_and_yarn/file_fetcher/path_dependency_builder.rb
312
313
  - lib/dependabot/npm_and_yarn/file_parser.rb
314
+ - lib/dependabot/npm_and_yarn/file_parser/bun_lock.rb
313
315
  - lib/dependabot/npm_and_yarn/file_parser/json_lock.rb
314
316
  - lib/dependabot/npm_and_yarn/file_parser/lockfile_parser.rb
315
317
  - lib/dependabot/npm_and_yarn/file_parser/pnpm_lock.rb
316
318
  - lib/dependabot/npm_and_yarn/file_parser/yarn_lock.rb
317
319
  - lib/dependabot/npm_and_yarn/file_updater.rb
320
+ - lib/dependabot/npm_and_yarn/file_updater/bun_lockfile_updater.rb
318
321
  - lib/dependabot/npm_and_yarn/file_updater/npm_lockfile_updater.rb
319
322
  - lib/dependabot/npm_and_yarn/file_updater/npmrc_builder.rb
320
323
  - lib/dependabot/npm_and_yarn/file_updater/package_json_preparer.rb
@@ -322,10 +325,13 @@ files:
322
325
  - lib/dependabot/npm_and_yarn/file_updater/pnpm_lockfile_updater.rb
323
326
  - lib/dependabot/npm_and_yarn/file_updater/yarn_lockfile_updater.rb
324
327
  - lib/dependabot/npm_and_yarn/helpers.rb
328
+ - lib/dependabot/npm_and_yarn/language.rb
325
329
  - lib/dependabot/npm_and_yarn/metadata_finder.rb
326
330
  - lib/dependabot/npm_and_yarn/native_helpers.rb
331
+ - lib/dependabot/npm_and_yarn/npm_package_manager.rb
327
332
  - lib/dependabot/npm_and_yarn/package_manager.rb
328
333
  - lib/dependabot/npm_and_yarn/package_name.rb
334
+ - lib/dependabot/npm_and_yarn/pnpm_package_manager.rb
329
335
  - lib/dependabot/npm_and_yarn/registry_helper.rb
330
336
  - lib/dependabot/npm_and_yarn/registry_parser.rb
331
337
  - lib/dependabot/npm_and_yarn/requirement.rb
@@ -342,12 +348,13 @@ files:
342
348
  - lib/dependabot/npm_and_yarn/update_checker/vulnerability_auditor.rb
343
349
  - lib/dependabot/npm_and_yarn/version.rb
344
350
  - lib/dependabot/npm_and_yarn/version_selector.rb
351
+ - lib/dependabot/npm_and_yarn/yarn_package_manager.rb
345
352
  homepage: https://github.com/dependabot/dependabot-core
346
353
  licenses:
347
354
  - MIT
348
355
  metadata:
349
356
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
350
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.292.0
357
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.293.0
351
358
  post_install_message:
352
359
  rdoc_options: []
353
360
  require_paths: