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
SCOPED_REGISTRY =
/^\s*@(?<scope>\S+):registry\s*=\s*(?<registry>\S+)/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(dependency_files:, credentials:) ⇒ NpmrcBuilder

Returns a new instance of NpmrcBuilder.



18
19
20
21
# File 'lib/dependabot/npm_and_yarn/file_updater/npmrc_builder.rb', line 18

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

Instance Method Details

#npmrc_contentObject

PROXY WORK



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

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