NPM.Lockfile (NPM v0.6.0)

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

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.

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

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()}
}

t()

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

Functions

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.

read(path \\ "npm.lock")

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

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

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.