Class: Dependabot::FileUpdaters::JavaScript::NpmAndYarn::NpmrcBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/file_updaters/java_script/npm_and_yarn/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.



17
18
19
20
# File 'lib/dependabot/file_updaters/java_script/npm_and_yarn/npmrc_builder.rb', line 17

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

Instance Method Details

#npmrc_contentObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dependabot/file_updaters/java_script/npm_and_yarn/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