Module: Dependabot::Bun::Helpers

Extended by:
T::Sig
Defined in:
lib/dependabot/bun/helpers.rb

Constant Summary collapse

BUN_V1 =

BUN Version Constants

1
BUN_DEFAULT_VERSION =
BUN_V1

Class Method Summary collapse

Class Method Details

.bun_versionObject



56
57
58
59
60
61
62
63
64
# File 'lib/dependabot/bun/helpers.rb', line 56

def self.bun_version
  version = run_bun_command("--version", fingerprint: "--version").strip
  if version.include?("+")
    version.split("+").first # Remove build info, if present
  end
rescue StandardError => e
  Dependabot.logger.error("Error retrieving Bun version: #{e.message}")
  nil
end

.bun_version_numeric(_bun_lock) ⇒ Object



20
21
22
# File 'lib/dependabot/bun/helpers.rb', line 20

def self.bun_version_numeric(_bun_lock)
  BUN_DEFAULT_VERSION
end

.dependencies_with_all_versions_metadata(dependency_set) ⇒ Object



85
86
87
88
89
90
# File 'lib/dependabot/bun/helpers.rb', line 85

def self.(dependency_set)
  dependency_set.dependencies.map do |dependency|
    dependency.[:all_versions] = dependency_set.all_versions_for_name(dependency.name)
    dependency
  end
end

.node_versionObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dependabot/bun/helpers.rb', line 25

def self.node_version
  version = run_node_command("-v", fingerprint: "-v").strip

  # Validate the output format (e.g., "v20.18.1" or "20.18.1")
  if version.match?(/^v?\d+(\.\d+){2}$/)
    version.strip.delete_prefix("v") # Remove the "v" prefix if present
  end
rescue StandardError => e
  Dependabot.logger.error("Error retrieving Node.js version: #{e.message}")
  nil
end

.run_bun_command(command, fingerprint: nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/dependabot/bun/helpers.rb', line 67

def self.run_bun_command(command, fingerprint: nil)
  full_command = "bun #{command}"

  Dependabot.logger.info("Running bun command: #{full_command}")

  result = Dependabot::SharedHelpers.run_shell_command(
    full_command,
    fingerprint: "bun #{fingerprint || command}"
  )

  Dependabot.logger.info("Command executed successfully: #{full_command}")
  result
rescue StandardError => e
  Dependabot.logger.error("Error running bun command: #{full_command}, Error: #{e.message}")
  raise
end

.run_node_command(command, fingerprint: nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dependabot/bun/helpers.rb', line 38

def self.run_node_command(command, fingerprint: nil)
  full_command = "node #{command}"

  Dependabot.logger.info("Running node command: #{full_command}")

  result = Dependabot::SharedHelpers.run_shell_command(
    full_command,
    fingerprint: "node #{fingerprint || command}"
  )

  Dependabot.logger.info("Command executed successfully: #{full_command}")
  result
rescue StandardError => e
  Dependabot.logger.error("Error running node command: #{full_command}, Error: #{e.message}")
  raise
end