NPM.Config (NPM v0.6.0)

Copy Markdown View Source

Read npm configuration from .npmrc files.

Checks for .npmrc in the project directory and home directory. Environment variables take precedence over file configuration.

Summary

Functions

Read the auth token.

Gets a config value with fallback to defaults.

Loads config from all levels: project .npmrc then user .npmrc. Project values override user values.

Merges multiple config maps (later overrides earlier).

Parse an .npmrc file into a map of key-value pairs.

Read a value from .npmrc files.

Read the effective registry URL.

Returns the registry URL for a given scope, or the default.

Functions

auth_token()

@spec auth_token() :: String.t() | nil

Read the auth token.

Priority: NPM_TOKEN env var > project .npmrc > home .npmrc.

get(config, key, default \\ nil)

@spec get(map(), String.t(), term()) :: term()

Gets a config value with fallback to defaults.

load(project_dir \\ ".")

@spec load(String.t()) :: map()

Loads config from all levels: project .npmrc then user .npmrc. Project values override user values.

merge(configs)

@spec merge([map()]) :: map()

Merges multiple config maps (later overrides earlier).

parse_npmrc(content)

@spec parse_npmrc(String.t()) :: %{required(String.t()) => String.t()}

Parse an .npmrc file into a map of key-value pairs.

read_npmrc_value(key)

@spec read_npmrc_value(String.t()) :: String.t() | nil

Read a value from .npmrc files.

Checks project-level first, then home-level.

registry()

@spec registry() :: String.t()

Read the effective registry URL.

Priority: NPM_REGISTRY env var > project .npmrc > home .npmrc > default.

scoped_registry(config, scope)

@spec scoped_registry(map(), String.t()) :: String.t()

Returns the registry URL for a given scope, or the default.