Class: Dependabot::NpmAndYarn::FileUpdater::NpmrcBuilder
- Inherits:
-
Object
- Object
- Dependabot::NpmAndYarn::FileUpdater::NpmrcBuilder
- Extended by:
- T::Sig
- 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 We should refactor this to use UpdateChecker::RegistryFinder
Constant Summary collapse
- CENTRAL_REGISTRIES =
T.let( %w( registry.npmjs.org registry.yarnpkg.com ).freeze, T::Array[String] )
- SCOPED_REGISTRY =
/^\s*@(?<scope>\S+):registry\s*=\s*(?<registry>\S+)/
Instance Method Summary collapse
-
#initialize(dependency_files:, credentials:, dependencies: []) ⇒ NpmrcBuilder
constructor
A new instance of NpmrcBuilder.
- #npmrc_content ⇒ Object
- #yarnrc_content ⇒ Object
Constructor Details
#initialize(dependency_files:, credentials:, dependencies: []) ⇒ NpmrcBuilder
Returns a new instance of NpmrcBuilder.
34 35 36 37 38 |
# File 'lib/dependabot/npm_and_yarn/file_updater/npmrc_builder.rb', line 34 def initialize(dependency_files:, credentials:, dependencies: []) @dependency_files = dependency_files @credentials = credentials @dependencies = dependencies end |
Instance Method Details
#npmrc_content ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dependabot/npm_and_yarn/file_updater/npmrc_builder.rb', line 42 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 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 |
#yarnrc_content ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/dependabot/npm_and_yarn/file_updater/npmrc_builder.rb', line 67 def yarnrc_content initial_content = if npmrc_file then complete_yarnrc_from_credentials elsif yarnrc_file then build_yarnrc_from_yarnrc else build_yarnrc_content_from_lockfile end initial_content || "" end |