NPM.Lockfile (NPM v0.7.3)

Copy Markdown View Source

Read and write npm.lock lockfile.

The lockfile records resolved versions, integrity hashes, and dependency relationships to ensure reproducible installs.

Summary

Functions

Return the effective lockfile security policy for new locks.

Return the default npm_ex lockfile path.

Get a single package entry from the lockfile.

Check if a specific package is in the lockfile.

List all package names in the lockfile.

Parse a raw packages map into lockfile entries.

Whether a recorded lockfile policy is compatible with current settings.

Read the lockfile. Returns empty map if it doesn't exist.

Read the security policy recorded in the lockfile.

Get the lockfile version from a file.

Types

entry()

@type entry() :: %{
  version: String.t(),
  integrity: String.t(),
  tarball: String.t(),
  dependencies: %{required(String.t()) => String.t()},
  optional_dependencies: %{required(String.t()) => String.t()},
  has_install_script: boolean()
}

t()

@type t() :: %{required(String.t()) => entry()}

Functions

current_policy()

@spec current_policy() :: map()

Return the effective lockfile security policy for new locks.

default_path()

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

Return the default npm_ex lockfile path.

get_package(name, path \\ "npm.lock")

@spec get_package(String.t(), String.t()) :: {:ok, entry()} | :error

Get a single package entry from the lockfile.

has_package?(name, path \\ "npm.lock")

@spec has_package?(String.t(), String.t()) :: boolean()

Check if a specific package is in the lockfile.

package_names(path \\ "npm.lock")

@spec package_names(String.t()) :: {:ok, [String.t()]} | {:error, term()}

List all package names in the lockfile.

parse_packages(packages)

@spec parse_packages(map()) :: t()

Parse a raw packages map into lockfile entries.

policy_matches?(policy)

@spec policy_matches?(map() | nil) :: boolean()

Whether a recorded lockfile policy is compatible with current settings.

read(path \\ "npm.lock")

@spec read(String.t()) :: {:ok, t()} | {:error, term()}

Read the lockfile. Returns empty map if it doesn't exist.

read_policy(path \\ "npm.lock")

@spec read_policy(String.t()) :: {:ok, map() | nil} | {:error, term()}

Read the security policy recorded in the lockfile.

version(path \\ "npm.lock")

@spec version(String.t()) :: integer() | nil

Get the lockfile version from a file.

write(lockfile, path \\ "npm.lock")

@spec write(t(), String.t()) :: :ok | {:error, term()}

Write the lockfile.