NPM.Bin (NPM v0.6.0)

Copy Markdown View Source

Parses and manages package bin field entries.

The bin field in package.json maps command names to script files. Supports both string shorthand and map formats.

Summary

Functions

Scans installed packages and collects all available binaries.

Lists all command names provided by a package.

Counts the number of binaries a package provides.

Extracts bin entries from package.json data.

Checks if a package provides any binaries.

Resolves the script path for a given command.

Functions

all_bins(node_modules_dir)

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

Scans installed packages and collects all available binaries.

commands(pkg_data)

@spec commands(map()) :: [String.t()]

Lists all command names provided by a package.

count(pkg_data)

@spec count(map()) :: non_neg_integer()

Counts the number of binaries a package provides.

extract(arg1)

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

Extracts bin entries from package.json data.

Returns a map of command name → script path.

has_bin?(pkg_data)

@spec has_bin?(map()) :: boolean()

Checks if a package provides any binaries.

resolve(command, pkg_data)

@spec resolve(String.t(), map()) :: String.t() | nil

Resolves the script path for a given command.