dependabot-npm_and_yarn 0.319.1 → 0.320.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d73a564255c059d9eb35b03d5628f88bffabdd2b9f1fc59ea11fe73f1ee8b0c3
4
- data.tar.gz: 3538d93dbc952b9773f9bfa9e8a3e8c9038d94f794d624a18d94ab0d92e9a03f
3
+ metadata.gz: e8d6f1d107d110d67d7bbfc67768a6c1afe62d22e7b327a9a495d5caf0535703
4
+ data.tar.gz: 2f3a64b55706976119011580025b65b199bc3e2e2e1fd7c54dd1f6506414fa9d
5
5
  SHA512:
6
- metadata.gz: 5d9d78d8b94bdbd6ce40b5cae073dfa065163a126a6239fa3d879c375f2e923654431b9da0f4d62362f6cec703d412a982eca49ef652b9fbc1d3cdc88c9f144e
7
- data.tar.gz: 76681332af9e4306942f6002bdaa6ff50fa3652e62e271a9b47043e3bc4e7c65c75d10b39e035b4a357185c3a15d24dd6f0f51b7378a6aa71ca3ca72e9c16b0a
6
+ metadata.gz: 7913cc686f742a69ec86a9f8835079c159fd159bcff483e62d8bc6162d4ae93a498d50ead60886b254d1c714060bfed0e92d31b907b74814f0e663c806241b76
7
+ data.tar.gz: f60d5b3bc19476bf60b85203a7441f694e557f1fe9b9419dfce2369fc271e1e4fad7f76a78f0885453c8aa0e98512ff06af816292f25c6e06a8a7fe89466e5dd
@@ -19,7 +19,7 @@ module Dependabot
19
19
  NPM_V10 = 10
20
20
  NPM_V8 = 8
21
21
  NPM_V6 = 6
22
- NPM_DEFAULT_VERSION = NPM_V8
22
+ NPM_DEFAULT_VERSION = NPM_V10
23
23
 
24
24
  # PNPM Version Constants
25
25
  PNPM_V9 = 9
@@ -56,26 +56,25 @@ module Dependabot
56
56
  def self.detect_npm_version(lockfile)
57
57
  lockfile_content = lockfile&.content
58
58
 
59
- # Return default NPM version if there's no lockfile or it's empty
59
+ # Return npm 10 as the default if the lockfile is missing or empty
60
60
  return NPM_DEFAULT_VERSION if lockfile_content.nil? || lockfile_content.strip.empty?
61
61
 
62
62
  parsed_lockfile = JSON.parse(lockfile_content)
63
63
 
64
64
  lockfile_version_str = parsed_lockfile["lockfileVersion"]
65
65
 
66
- # Default to npm default version if lockfileVersion is missing or empty
67
66
  return NPM_DEFAULT_VERSION if lockfile_version_str.nil? || lockfile_version_str.to_s.strip.empty?
68
67
 
69
68
  lockfile_version = lockfile_version_str.to_i
70
69
 
71
70
  # Using npm 8 as the default for lockfile_version > 2.
72
- # Update needed to support npm 9+ based on lockfile version.
71
+ return NPM_V10 if lockfile_version >= 3
73
72
  return NPM_V8 if lockfile_version >= 2
74
73
 
75
74
  NPM_V6 if lockfile_version >= 1
76
75
  # Return nil if can't capture
77
76
  rescue JSON::ParserError
78
- NPM_DEFAULT_VERSION # Fallback to default npm version if parsing fails
77
+ NPM_DEFAULT_VERSION # Fallback to npm 8 if the lockfile content cannot be parsed
79
78
  end
80
79
 
81
80
  private_class_method :detect_npm_version
@@ -271,15 +270,35 @@ module Dependabot
271
270
  sig { params(command: String, fingerprint: T.nilable(String)).returns(String) }
272
271
  def self.run_npm_command(command, fingerprint: command)
273
272
  if Dependabot::Experiments.enabled?(:enable_corepack_for_npm_and_yarn)
274
- package_manager_run_command(NpmPackageManager::NAME, command, fingerprint: fingerprint)
273
+ package_manager_run_command(
274
+ NpmPackageManager::NAME,
275
+ command,
276
+ fingerprint: fingerprint,
277
+ output_observer: ->(output) { command_observer(output) }
278
+ )
275
279
  else
276
280
  Dependabot::SharedHelpers.run_shell_command(
277
281
  "npm #{command}",
278
- fingerprint: "npm #{fingerprint}"
282
+ fingerprint: "npm #{fingerprint}",
283
+ output_observer: ->(output) { command_observer(output) }
279
284
  )
280
285
  end
281
286
  end
282
287
 
288
+ sig do
289
+ params(output: String)
290
+ .returns(T::Hash[Symbol, T.untyped])
291
+ end
292
+ def self.command_observer(output)
293
+ # Observe the output for specific error
294
+ return {} unless output.include?("npm ERR! ERESOLVE")
295
+
296
+ {
297
+ gracefully_stop: true, # value must be a String
298
+ reason: "NPM Resolution Error"
299
+ }
300
+ end
301
+
283
302
  sig { returns(T.nilable(String)) }
284
303
  def self.node_version
285
304
  version = run_node_command("-v", fingerprint: "-v").strip
@@ -486,20 +505,30 @@ module Dependabot
486
505
  params(
487
506
  name: String,
488
507
  command: String,
489
- fingerprint: T.nilable(String)
508
+ fingerprint: T.nilable(String),
509
+ output_observer: CommandHelpers::OutputObserver
490
510
  ).returns(String)
491
511
  end
492
- def self.package_manager_run_command(name, command, fingerprint: nil)
512
+ def self.package_manager_run_command(
513
+ name,
514
+ command,
515
+ fingerprint: nil,
516
+ output_observer: nil
517
+ )
493
518
  return run_bun_command(command, fingerprint: fingerprint) if name == BunPackageManager::NAME
494
519
 
495
520
  full_command = "corepack #{name} #{command}"
496
-
497
- result = Dependabot::SharedHelpers.run_shell_command(
498
- full_command,
499
- fingerprint: "corepack #{name} #{fingerprint || command}"
500
- ).strip
501
-
502
- result
521
+ fingerprint = "corepack #{name} #{fingerprint || command}"
522
+
523
+ if output_observer
524
+ return Dependabot::SharedHelpers.run_shell_command(
525
+ full_command,
526
+ fingerprint: fingerprint,
527
+ output_observer: output_observer
528
+ ).strip
529
+ else
530
+ Dependabot::SharedHelpers.run_shell_command(full_command, fingerprint: fingerprint)
531
+ end.strip
503
532
  rescue StandardError => e
504
533
  Dependabot.logger.error("Error running package manager command: #{full_command}, Error: #{e.message}")
505
534
  if e.message.match?(/Response Code.*:.*404.*\(Not Found\)/) &&
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-npm_and_yarn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.319.1
4
+ version: 0.320.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.319.1
18
+ version: 0.320.1
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.319.1
25
+ version: 0.320.1
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: debug
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -356,7 +356,7 @@ licenses:
356
356
  - MIT
357
357
  metadata:
358
358
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
359
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.319.1
359
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.320.1
360
360
  rdoc_options: []
361
361
  require_paths:
362
362
  - lib