Class: Dependabot::NpmAndYarn::FileUpdater::NpmrcBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/npm_and_yarn/file_updater/npmrc_builder.rb

Overview

Build a .npmrc file from the lockfile content, credentials, and any committed .npmrc

Constant Summary collapse

CENTRAL_REGISTRIES =
%w(
  registry.npmjs.org
  registry.yarnpkg.com
).freeze

Instance Method Summary collapse

Constructor Details

#initialize(dependency_files:, credentials:) ⇒ NpmrcBuilder

Returns a new instance of NpmrcBuilder.



16
17
18
19
# File 'lib/dependabot/npm_and_yarn/file_updater/npmrc_builder.rb', line 16

def initialize(dependency_files:, credentials:)
  @dependency_files = dependency_files
  @credentials = credentials
end

Instance Method Details

#npmrc_contentObject

PROXY WORK



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dependabot/npm_and_yarn/file_updater/npmrc_builder.rb', line 22

def npmrc_content
  initial_content =
    if npmrc_file then complete_npmrc_from_credentials
    elsif yarnrc_file then build_npmrc_from_yarnrc
    else build_npmrc_content_from_lockfile
    end

  return initial_content || "" unless registry_credentials.any?

  ([initial_content] + credential_lines_for_npmrc).compact.join("\n")
end