Class: Dependabot::Bun::FileUpdater::NpmrcBuilder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/bun/file_updater/npmrc_builder.rb

Overview

Build a .npmrc file from the lockfile content, credentials, and any committed .npmrc We should refactor this to use Package::RegistryFinder

Constant Summary collapse

CENTRAL_REGISTRIES =
T.let(%w(registry.npmjs.org).freeze, T::Array[String])
SCOPED_REGISTRY =
/^\s*@(?<scope>\S+):registry\s*=\s*(?<registry>\S+)/

Instance Method Summary collapse

Constructor Details

#initialize(dependency_files:, credentials:, dependencies: []) ⇒ NpmrcBuilder

Returns a new instance of NpmrcBuilder.



28
29
30
31
32
# File 'lib/dependabot/bun/file_updater/npmrc_builder.rb', line 28

def initialize(dependency_files:, credentials:, dependencies: [])
  @dependency_files = dependency_files
  @credentials = credentials
  @dependencies = dependencies
end

Instance Method Details

#npmrc_contentObject



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

def npmrc_content
  initial_content =
    if npmrc_file then complete_npmrc_from_credentials
    else
      build_npmrc_content_from_lockfile
    end

  final_content = initial_content || ""

  return final_content unless registry_credentials.any?

  credential_lines_for_npmrc.each do |credential_line|
    next if final_content.include?(credential_line)

    final_content = [final_content, credential_line].reject(&:empty?).join("\n")
  end

  final_content
end