@zuke/npm

← API reference

`@zuke/npm` — typed `NpmTasks` wrappers for the `npm` CLI, for use in Zuke

Symbols

#

NpmAccess

type
type NpmAccess = public | restricted

An access level accepted by npm's --access flag.

#

NpmAccessSettings

class
class NpmAccessSettings extends NpmSettings

Settings for npm access.

MemberSignatureDoc
listPackages listPackages(owner?: string, pkg?: string): this List the packages a user, scope, or team can reach (access list packages).
listCollaborators listCollaborators(pkg?: string, user?: string): this List a package's collaborators (access list collaborators).
getStatus getStatus(pkg?: string): this Read whether a package is public or private (access get status), the default.
setStatus setStatus(level: public | private, pkg?: string): this Set a package public or private (access set status=<level>).
setMfa setMfa(mode: none | publish | automation, pkg?: string): this Require two-factor auth for publishing (access set mfa=<mode>).
grant grant(permission: read-only | read-write, team: string, pkg?: string): this Give a team access (access grant <permission> <scope:team>).
revoke revoke(team: string, pkg?: string): this Take a team's access away (access revoke <scope:team>).
otp otp(code: string): this Provide a one-time password. Carried in npm_config_otp rather than on the command line — see NpmSettings.applyOtp for why.
#

NpmAuditSettings

class
class NpmAuditSettings extends NpmWorkspaceSettings

Settings for npm audit.

MemberSignatureDoc
fix fix(): this Install compatible updates for what it finds (npm audit fix).
signatures signatures(): this Verify the registry signatures of what is installed (npm audit signatures).
auditLevel auditLevel(level: info | low | moderate | high | critical | none): this The severity at which the command fails (--audit-level=<info|low|moderate|high|critical|none>).
omit omit(...types: NpmOmitType[]): this Skip a dependency group (--omit=<group>); repeatable.
include include(...types: NpmIncludeType[]): this Keep a dependency group npm would otherwise omit (--include=<group>); repeatable.
packageLockOnly packageLockOnly(): this Audit the lockfile without touching node_modules (--package-lock-only).
dryRun dryRun(): this Report what a fix would change without changing it (--dry-run).
#

NpmAuditSummary

interface
interface NpmAuditSummary

How many vulnerabilities npm audit found, by severity.

MemberSignatureDoc
info info: number Informational findings.
low low: number Low-severity findings.
moderate moderate: number Moderate-severity findings.
high high: number High-severity findings.
critical critical: number Critical-severity findings.
total total: number Every finding, whatever its severity.
#

NpmCacheSettings

class
class NpmCacheSettings extends NpmSettings

Settings for npm cache. Pick the operation with add, clean, ls, or verify.

MemberSignatureDoc
add add(...specs: string[]): this Add a package to the cache (cache add <spec>).
clean clean(key?: string): this Empty the cache (cache clean). npm refuses this without --force, so pair it with force — see the error this reports otherwise.
ls ls(...specs: string[]): this List what the cache holds (cache ls).
verify verify(): this Check and compact the cache (cache verify), the default.
cache cache(path: PathLike): this Use a specific cache directory (--cache=<path>).
force force(): this Confirm a clean npm would otherwise refuse (--force).
#

NpmCiSettings

class
class NpmCiSettings extends NpmDependencySettings

Settings for npm ci.

MemberSignatureDoc
noAudit noAudit(): this Skip the audit npm runs after installing (--no-audit).
noFund noFund(): this Skip the funding message (--no-fund).
#

NpmConfigSettings

class
class NpmConfigSettings extends NpmSettings

Settings for npm config. Pick the operation with get, set, deleteKeys, list, or fix.

MemberSignatureDoc
get get(...keys: string[]): this Read config keys (config get <key>...).
set set(...assignments: string[]): this Write config keys (config set <key>=<value>...).
deleteKeys deleteKeys(...keys: string[]): this Remove config keys (config delete <key>...).
list list(): this List the effective configuration (config list).
fix fix(): this Repair invalid config entries (config fix).
location location(where: global | user | project): this Which file to read or write (--location=<global|user|project>).
long long(): this Include defaults in a listing (--long).
#

NpmDedupeSettings

class
class NpmDedupeSettings extends NpmDependencySettings

Settings for npm dedupe.

MemberSignatureDoc
dryRun dryRun(): this Report what would move without changing the tree (--dry-run).
#

NpmDependencySettings

class
class NpmDependencySettings extends NpmWorkspaceSettings

Shared base for the install-shaped commands: the --omit/--include dependency-group selectors npm accepts on all of them, plus the package specs most of them take.

MemberSignatureDoc
packages packages(...specs: string[]): this Package specs the command operates on (positional); repeatable.
omit omit(...types: NpmOmitType[]): this Skip a dependency group (--omit=<group>); repeatable.
include include(...types: NpmIncludeType[]): this Keep a dependency group npm would otherwise omit (--include=<group>); repeatable.
ignoreScripts ignoreScripts(): this Do not run lifecycle scripts (--ignore-scripts).
foregroundScripts foregroundScripts(): this Show lifecycle-script output as it runs (--foreground-scripts).
#

NpmDeprecateSettings

class
class NpmDeprecateSettings extends NpmSettings

Settings for npm deprecate.

MemberSignatureDoc
spec spec(value: string): this The package spec to deprecate, e.g. app@<2 (required).
message message(text: string): this The warning installers will see (required). An empty message is how npm *un*-deprecates a version, so it must be given deliberately rather than by omission.
otp otp(code: string): this Provide a one-time password. Carried in npm_config_otp rather than on the command line — see NpmSettings.applyOtp for why.
#

NpmDistTagSettings

class
class NpmDistTagSettings extends NpmWorkspaceSettings

Settings for npm dist-tag. Pick the subcommand with add, rm, or ls.

MemberSignatureDoc
add add(spec: string, tag?: string): this Point a tag at a published version (dist-tag add <pkg@version> [<tag>]). The spec must carry the version; a tag cannot point at a range. With no tag npm uses latest, as it does on the command line.
rm rm(spec: string, tag: string): this Remove a tag (dist-tag rm <pkg> <tag>).
ls ls(spec?: string): this List a package's tags (dist-tag ls [<pkg>]), the default.
#

NpmExecSettings

class
class NpmExecSettings extends NpmWorkspaceSettings

Settings for npm exec.

MemberSignatureDoc
command command(name: string): this The command to execute (required).
package package(spec: string): this The package providing the command (--package=).
yes yes(): this Skip the install prompt (--yes).
no no(): this Refuse to install anything (--no), so the command runs only if it is already present — what a hermetic CI step wants instead of a silent fetch.
execArgs execArgs(...args: Array<string | number>): this Arguments forwarded to the command (after --).
#

NpmIncludeType

type
type NpmIncludeType = prod | dev | optional | peer

A dependency group accepted by npm's --include flag.

#

NpmInitSettings

class
class NpmInitSettings extends NpmWorkspaceSettings

Settings for npm init.

MemberSignatureDoc
initializer initializer(spec: string): this The initializer package to run, e.g. vite for npm init vite (positional). With none, npm writes a package.json itself.
yes yes(): this Accept the defaults instead of prompting (--yes).
scope scope(name: string): this Scope the created package (--scope=<@scope>).
initArgs initArgs(...args: Array<string | number>): this Arguments forwarded to the initializer (after --).
#

NpmInstallSettings

class
class NpmInstallSettings extends NpmDependencySettings

Settings for npm install.

MemberSignatureDoc
saveDev saveDev(): this Save to devDependencies (--save-dev).
saveOptional saveOptional(): this Save to optionalDependencies (--save-optional).
savePeer savePeer(): this Save to peerDependencies (--save-peer).
saveExact saveExact(): this Pin exact versions (--save-exact).
noSave noSave(): this Install without recording the dependency (--no-save).
installStrategy installStrategy(strategy: hoisted | nested | shallow | linked): this How npm lays out the tree (--install-strategy=<strategy>).
noAudit noAudit(): this Skip the audit npm runs after installing (--no-audit).
noFund noFund(): this Skip the funding message (--no-fund).
#

NpmLinkSettings

class
class NpmLinkSettings extends NpmDependencySettings

Settings for npm link.

MemberSignatureDoc
saveDev saveDev(): this Record the linked package in devDependencies (--save-dev).
#

NpmLogLevel

type
type NpmLogLevel = silent | error | warn | notice | http | info | verbose | silly

How verbose npm should be (--loglevel).

#

NpmLsSettings

class
class NpmLsSettings extends NpmWorkspaceSettings

Settings for npm ls.

MemberSignatureDoc
spec spec(value: string): this Limit the listing to one package spec (positional).
depth depth(levels: number): this How deep to walk the tree (--depth=<n>); 0 lists direct dependencies.
all all(): this Show every dependency, not just the top level (--all).
long long(): this Include extended information (--long).
parseable parseable(): this Emit one line per package, tab-separated (--parseable).
omit omit(...types: NpmOmitType[]): this Skip a dependency group (--omit=<group>); repeatable.
#

NpmOmitType

type
type NpmOmitType = dev | optional | peer

A dependency group accepted by npm's --omit flag.

#

NpmOutdatedEntry

interface
interface NpmOutdatedEntry

One dependency npm outdated reports as behind.

MemberSignatureDoc
name name: string The package name.
current? current?: string The version installed now, absent when the package is missing entirely.
wanted? wanted?: string The newest version the range in package.json allows.
latest? latest?: string The newest version published.
location? location?: string Where in the tree it is installed.
dependent? dependent?: string The package that depends on it.
#

NpmOutdatedSettings

class
class NpmOutdatedSettings extends NpmWorkspaceSettings

Settings for npm outdated.

MemberSignatureDoc
packages packages(...specs: string[]): this Limit the report to these package specs (positional); repeatable.
all all(): this Report transitive dependencies too (--all).
long long(): this Include the package type and homepage (--long).
#

NpmOwnerSettings

class
class NpmOwnerSettings extends NpmWorkspaceSettings

Settings for npm owner.

MemberSignatureDoc
add add(user: string, pkg: string): this Add a maintainer (owner add <user> <pkg>).
rm rm(user: string, pkg: string): this Remove a maintainer (owner rm <user> <pkg>).
ls ls(pkg: string): this List a package's maintainers (owner ls <pkg>).
otp otp(code: string): this Provide a one-time password. Carried in npm_config_otp rather than on the command line — see NpmSettings.applyOtp for why.
#

NpmPackSettings

class
class NpmPackSettings extends NpmWorkspaceSettings

Settings for npm pack.

MemberSignatureDoc
packages packages(...specs: string[]): this Package specs to pack (positional); defaults to the current project.
packDestination packDestination(dir: PathLike): this Where to write the tarball (--pack-destination=<dir>).
dryRun dryRun(): this Report what would be packed without writing a tarball (--dry-run).
#

NpmPingSettings

class
class NpmPingSettings extends NpmSettings

Settings for npm ping.

#

NpmPkgSettings

class
class NpmPkgSettings extends NpmWorkspaceSettings

Settings for npm pkg. Pick the operation with get, set, deleteKeys, or fix.

MemberSignatureDoc
get get(...keys: string[]): this Read one or more package.json fields (pkg get <key>...).
set set(...assignments: string[]): this Write fields (pkg set <key>=<value>...). Each argument is npm's own key=value form, which is also how it addresses arrays and nested keys.
deleteKeys deleteKeys(...keys: string[]): this Remove fields (pkg delete <key>...).
fix fix(): this Repair what npm can correct automatically (pkg fix).
force force(): this Skip npm's confirmation for a destructive edit (--force).
#

NpmPruneSettings

class
class NpmPruneSettings extends NpmDependencySettings

Settings for npm prune.

MemberSignatureDoc
dryRun dryRun(): this Report what would be removed without removing it (--dry-run).
#

NpmPublishSettings

class
class NpmPublishSettings extends NpmWorkspaceSettings

Settings for npm publish.

MemberSignatureDoc
tag tag(name: string): this Publish under a dist-tag (--tag=).
access access(level: NpmAccess): this Set the package access level (--access=).
dryRun dryRun(): this Report what would be published without uploading (--dry-run).
otp otp(code: string): this Provide a one-time password. Carried in npm_config_otp rather than on the command line — see NpmSettings.applyOtp for why.
provenance provenance(): this Publish with a provenance attestation (--provenance), which npm can generate from a trusted CI run — the supply-chain signal a consumer can verify against the workflow that built the tarball.
#

NpmRebuildSettings

class
class NpmRebuildSettings extends NpmDependencySettings

Settings for npm rebuild.

MemberSignatureDoc
noBinLinks noBinLinks(): this Do not create the .bin symlinks (--no-bin-links).
#

NpmRunSettings

class
class NpmRunSettings extends NpmWorkspaceSettings

Settings for npm run.

MemberSignatureDoc
script script(name: string): this The package.json script to run (required).
ifPresent ifPresent(): this Do not fail when the script is missing (--if-present).
scriptArgs scriptArgs(...args: Array<string | number>): this Arguments forwarded to the script (after --).
#

NpmSbomSettings

class
class NpmSbomSettings extends NpmWorkspaceSettings

Settings for npm sbom.

MemberSignatureDoc
sbomFormat sbomFormat(format: cyclonedx | spdx): this Which document to emit (--sbom-format=<cyclonedx|spdx>), required by npm.
sbomType sbomType(type: library | application | framework): this What the project is (--sbom-type=<library|application|framework>).
omit omit(...types: NpmOmitType[]): this Skip a dependency group (--omit=<group>); repeatable.
packageLockOnly packageLockOnly(): this Build the document from the lockfile alone (--package-lock-only).
#

NpmSettings

class
class NpmSettings extends ToolSettings

Shared base for every npm subcommand: the binary, and the flags npm treats as configuration rather than as a command's own — it accepts these on any command, which is why they live here instead of being repeated.

MemberSignatureDoc
registry registry(url: string): this Use a specific registry (--registry=<url>).
json json(): this Emit JSON (--json). The value-returning tasks set this themselves; a caller reaches for it to parse output the wrapper does not yet model.
logLevel logLevel(level: NpmLogLevel): this How much npm prints (--loglevel=<level>).
global global(): this Operate on the global install rather than the project (--global).
prefix prefix(path: PathLike): this Run as if npm were started in this directory (--prefix=<path>).
userconfig userconfig(path: PathLike): this Read this user config file rather than ~/.npmrc (--userconfig=<path>).
#

NpmTasks

const
const NpmTasks: NpmTasksApi

Typed task functions for the npm CLI.

#

NpmTasksApi

interface
interface NpmTasksApi

The shape of NpmTasks.

MemberSignatureDoc
install install(configure?: Configure<NpmInstallSettings>): Promise<CommandOutput> Install dependencies: npm install.
ci ci(configure?: Configure<NpmCiSettings>): Promise<CommandOutput> Clean install from the lockfile: npm ci.
uninstall uninstall(configure?: Configure<NpmUninstallSettings>): Promise<CommandOutput> Remove dependencies: npm uninstall.
update update(configure?: Configure<NpmUpdateSettings>): Promise<CommandOutput> Update dependencies within their ranges: npm update.
dedupe dedupe(configure?: Configure<NpmDedupeSettings>): Promise<CommandOutput> Flatten duplicated packages: npm dedupe.
prune prune(configure?: Configure<NpmPruneSettings>): Promise<CommandOutput> Remove packages nothing depends on: npm prune.
rebuild rebuild(configure?: Configure<NpmRebuildSettings>): Promise<CommandOutput> Rebuild native packages: npm rebuild.
link link(configure?: Configure<NpmLinkSettings>): Promise<CommandOutput> Symlink a package for local development: npm link.
run run(configure?: Configure<NpmRunSettings>): Promise<CommandOutput> Run a package.json script: npm run.
test test(configure?: Configure<NpmTestSettings>): Promise<CommandOutput> Run the project's test script: npm test.
exec exec(configure?: Configure<NpmExecSettings>): Promise<CommandOutput> Execute a package binary: npm exec.
publish publish(configure?: Configure<NpmPublishSettings>): Promise<CommandOutput> Publish the package: npm publish.
pack pack(configure?: Configure<NpmPackSettings>): Promise<CommandOutput> Build a tarball without publishing it: npm pack.
version version(configure?: Configure<NpmVersionSettings>): Promise<CommandOutput> Bump the package version: npm version.
unpublish unpublish(configure?: Configure<NpmUnpublishSettings>): Promise<CommandOutput> Remove a published version: npm unpublish.
deprecate deprecate(configure?: Configure<NpmDeprecateSettings>): Promise<CommandOutput> Warn installers off a version: npm deprecate.
distTag distTag(configure?: Configure<NpmDistTagSettings>): Promise<CommandOutput> Manage dist-tags: npm dist-tag add|rm|ls.
view view(configure?: Configure<NpmViewSettings>): Promise<CommandOutput> Read registry metadata: npm view.
ping ping(configure?: Configure<NpmPingSettings>): Promise<CommandOutput> Check the registry is reachable: npm ping.
whoami whoami(configure?: Configure<NpmWhoamiSettings>): Promise<CommandOutput> Print the authenticated user: npm whoami.
whoamiName whoamiName(configure?: Configure<NpmWhoamiSettings>): Promise<string | undefined> The authenticated user's name, or undefined when this machine is not logged in — an answer a release target can act on, rather than the non-zero exit npm reports.
access access(configure?: Configure<NpmAccessSettings>): Promise<CommandOutput> Manage package access: npm access.
owner owner(configure?: Configure<NpmOwnerSettings>): Promise<CommandOutput> Manage package maintainers: npm owner add|rm|ls.
token token(configure?: Configure<NpmTokenSettings>): Promise<CommandOutput> Manage registry tokens: npm token list|create|revoke.
ls ls(configure?: Configure<NpmLsSettings>): Promise<CommandOutput> List the installed tree: npm ls.
outdated outdated(configure?: Configure<NpmOutdatedSettings>): Promise<CommandOutput> Report dependencies behind their latest: npm outdated.
outdatedEntries outdatedEntries(configure?: Configure<NpmOutdatedSettings>): Promise<NpmOutdatedEntry[]> The outdated dependencies as parsed NpmOutdatedEntry values. npm exits non-zero *because* something is outdated, so this reads that as the answer rather than as a failure; an empty array means everything is current.
audit audit(configure?: Configure<NpmAuditSettings>): Promise<CommandOutput> Audit dependencies for vulnerabilities: npm audit.
auditSummary auditSummary(configure?: Configure<NpmAuditSettings>): Promise<NpmAuditSummary> The audit's vulnerability counts by severity, so a target decides for itself what is worth failing on. npm's non-zero exit is the finding, not an error.
sbom sbom(configure?: Configure<NpmSbomSettings>): Promise<CommandOutput> Emit a software bill of materials: npm sbom.
init init(configure?: Configure<NpmInitSettings>): Promise<CommandOutput> Create a package or run an initializer: npm init.
pkg pkg(configure?: Configure<NpmPkgSettings>): Promise<CommandOutput> Read or write package.json fields: npm pkg get|set|delete|fix.
pkgGet pkgGet(key: string, configure?: Configure<NpmPkgSettings>): Promise<string | undefined> One package.json field as a string, or undefined when it is unset or is not a scalar — how a build reads its own version without parsing the manifest or guessing where it lives.
config config(configure?: Configure<NpmConfigSettings>): Promise<CommandOutput> Read or write npm configuration: npm config get|set|delete|list|fix.
cache cache(configure?: Configure<NpmCacheSettings>): Promise<CommandOutput> Maintain the package cache: npm cache add|clean|ls|verify.
#

NpmTestSettings

class
class NpmTestSettings extends NpmWorkspaceSettings

Settings for npm test.

MemberSignatureDoc
testArgs testArgs(...args: Array<string | number>): this Arguments forwarded to the test script (after --).
#

NpmTokenSettings

class
class NpmTokenSettings extends NpmSettings

Settings for npm token. Pick the subcommand with list, create, or revoke.

MemberSignatureDoc
list list(): this List this account's tokens (token list), the default.
create create(): this Create a token (token create).
revoke revoke(idOrToken: string): this Revoke a token by id or value (token revoke <id|token>). npm takes this positionally, with no environment route, so the value reaches the child's argv either way. It is registered with the run's redactor so every *rendering* of the command masks it; the process table is not something the wrapper can do anything about here. Masked whichever it is, because the two are indistinguishable from here — npm accepts the id or the token itself, and nothing in the string says which. Masking an id costs a [redacted] in this run's output; not masking a token puts a live credential in it.
readOnly readOnly(): this Create a token that cannot publish (--read-only).
cidr cidr(...ranges: string[]): this Restrict a created token to these ranges (--cidr=<range>); repeatable.
otp otp(code: string): this Provide a one-time password. Carried in npm_config_otp rather than on the command line — see NpmSettings.applyOtp for why.
#

NpmUninstallSettings

class
class NpmUninstallSettings extends NpmDependencySettings

Settings for npm uninstall.

MemberSignatureDoc
noSave noSave(): this Remove the package without updating package.json (--no-save).
#

NpmUnpublishSettings

class
class NpmUnpublishSettings extends NpmWorkspaceSettings

Settings for npm unpublish.

MemberSignatureDoc
spec spec(value: string): this The package spec to remove, e.g. app@1.2.3 (positional).
force force(): this Confirm an unpublish npm would otherwise refuse (--force) — removing a whole package, or a version outside the 72-hour window.
dryRun dryRun(): this Report what would be removed without removing it (--dry-run).
#

NpmUpdateSettings

class
class NpmUpdateSettings extends NpmDependencySettings

Settings for npm update.

MemberSignatureDoc
save save(): this Write the updated ranges back to package.json (--save).
#

NpmVersionSettings

class
class NpmVersionSettings extends NpmWorkspaceSettings

Settings for npm version.

MemberSignatureDoc
bump bump(value: string): this The bump: patch | minor | major or an explicit semver (required).
message message(text: string): this Commit message; %s expands to the new version (--message).
noGitTagVersion noGitTagVersion(): this Do not create a git commit and tag (--no-git-tag-version).
preid preid(id: string): this The prerelease identifier for a pre* bump (--preid=<id>), e.g. rc.
allowSameVersion allowSameVersion(): this Accept a bump to the version already set (--allow-same-version).
#

NpmViewSettings

class
class NpmViewSettings extends NpmWorkspaceSettings

Settings for npm view.

MemberSignatureDoc
spec spec(value: string): this The package spec to read, e.g. react@18 (positional).
field field(...names: string[]): this A field of the registry metadata to print, e.g. version or dist-tags.latest (positional); repeatable. With none, npm prints the whole record.
#

NpmWhoamiSettings

class
class NpmWhoamiSettings extends NpmSettings

Settings for npm whoami.

#

NpmWorkspaceSettings

class
class NpmWorkspaceSettings extends NpmSettings

Base for the npm commands that accept workspace selection. --workspace names one (repeatable) and --workspaces means all of them; npm takes one or the other, and this refuses the combination rather than passing on a command whose meaning is ambiguous.

MemberSignatureDoc
workspace workspace(...names: string[]): this Run in this workspace (--workspace=<name>); repeatable.
workspaces workspaces(): this Run in every workspace (--workspaces). Mutually exclusive with workspace — setting both is a build error.
includeWorkspaceRoot includeWorkspaceRoot(): this Include the root project alongside the workspaces (--include-workspace-root).
#

parsePkgField

function
function parsePkgField(stdout: string, key: string): string | undefined

The scalar npm pkg get <key> reported, or undefined when the field is unset or is not a scalar.

npm answers with JSON, so a string field arrives quoted, a missing one arrives as {}, and asking within a workspace (or for several keys) yields an object keyed by what was asked for — this reads all three. An object or array field yields undefined, because there is no single string to hand back.

Not part of the package's public surface — exported for its unit test.

#

readPkgField

function
async function readPkgField(key: string, configure?: Configure<NpmPkgSettings>): Promise<string | undefined>

Run npm pkg get <key> --json and read the field out of it. Backs "./npm.ts".NpmTasks.pkgGet.

#

readWhoami

function
async function readWhoami(configure?: Configure<NpmWhoamiSettings>): Promise<string | undefined>

Read the authenticated user's name, or undefined when the registry does not recognise this machine. Backs "./npm.ts".NpmTasks.whoamiName.

Being logged out is an answer, not a failure — a release target asks so it can report the missing credential itself, rather than dying on npm's exit code partway through.