Class: Dependabot::NpmAndYarn::RegistryHelper

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/npm_and_yarn/registry_helper.rb

Constant Summary collapse

REGISTRY_KEY =

Keys for configurations

"registry"
AUTH_KEY =
"authToken"
NPM_AUTH_TOKEN_KEY_FOR_YARN =

Yarn-specific keys

"npmAuthToken"
NPM_SCOPE_KEY_FOR_YARN =
"npmScopes"
NPM_REGISTER_KEY_FOR_YARN =
"npmRegistryServer"
COREPACK_NPM_REGISTRY_ENV =

Environment variable keys

"COREPACK_NPM_REGISTRY"
COREPACK_NPM_TOKEN_ENV =
"COREPACK_NPM_TOKEN"

Instance Method Summary collapse

Constructor Details

#initialize(registry_config_files, credentials) ⇒ RegistryHelper

Returns a new instance of RegistryHelper.



32
33
34
35
# File 'lib/dependabot/npm_and_yarn/registry_helper.rb', line 32

def initialize(registry_config_files, credentials)
  @registry_config_files = T.let(registry_config_files, T::Hash[Symbol, T.nilable(Dependabot::DependencyFile)])
  @credentials = T.let(credentials, T.nilable(T::Array[Dependabot::Credential]))
end

Instance Method Details

#find_corepack_env_variablesObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dependabot/npm_and_yarn/registry_helper.rb', line 38

def find_corepack_env_variables
  registry_info = find_registry_and_token

  env_variables = {}

  if registry_info[:registry] # Prevent the https from being stripped in the process
    registry = registry_info[:registry]
    registry = "https://#{T.must(registry)}" unless T.must(registry).start_with?("http://", "https://")
    env_variables[COREPACK_NPM_REGISTRY_ENV] = registry
  end

  env_variables[COREPACK_NPM_TOKEN_ENV] = registry_info[:auth_token] if registry_info[:auth_token]

  env_variables
end