npm
npm i -D @unirelman/plugin-npmpnpm add -D @unirelman/plugin-npmyarn add -D @unirelman/plugin-npmbun add -d @unirelman/plugin-npmimport { createNpmPlugin } from "@unirelman/plugin-npm";
createNpmPlugin();Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
publish |
boolean |
true |
Publication of packages in the publish pipeline. With false, the plugin manages versions in package.json only. |
packageManager |
"npm" | "pnpm" | "yarn" | "bun" |
Detected | Package manager that publishes packages. See Package manager. |
updateInternalDependencies.ranges |
"patch" | "minor" |
"patch" |
Smallest release of an internal dependency that gives a range update. See Internal dependencies. |
updateInternalDependencies.dependents |
"out-of-range" | "always" |
"out-of-range" |
Releases of an internal dependency that give a dependent update. See Internal dependencies. |
Phases
Section titled “Phases”| Phase | Behavior |
|---|---|
getCurrentVersion |
Reads version from the package.json of each scope folder. |
getDependencyChanges |
Gives a change to the dependents of each scope with a next version, as described in Internal dependencies. |
generateFileOperations |
Writes the next version and the updated internal dependency ranges to the package.json of each scope. Its other fields keep their values and order. |
createReleases |
Publishes each scope’s package, as described in Publishing. |
Internal dependencies
Section titled “Internal dependencies”An internal dependency is a dependency on the package of another scope. When @example/cli depends on @example/core, @example/core is the dependency and @example/cli the dependent. When @example/core gets a SemVer next version, two updates can follow:
- Dependent update:
@example/cligets apatchchange,Updated dependencies: @example/core@2.0.0, so it gets a next version too. Its own dependents can then be updated in turn. - Range update: the specifier of
@example/corein@example/climoves to the next version, such as^1.0.0→^1.1.0.
| Condition | Dependent update | Range update |
|---|---|---|
@example/core leaves the range of @example/cli |
✓ | ✓ |
dependents: "always" |
✓ | — |
@example/cli is updated, by its own changes or by a dependency, and ranges: "patch" |
— | ✓ |
@example/cli is updated, by its own changes or by a dependency, and @example/core gets a minor or major release |
— | ✓ |
When @example/cli is updated, its Updated dependencies change lists each dependency outside devDependencies that gives a dependent update or a range update, next to its own changes.
devDependencies never give a dependent update. When @example/core is only in the devDependencies of @example/cli, @example/cli isn’t updated, and @example/core leaves its range (or dependents is "always"), the specifier of @example/core still moves to the next version. @example/cli keeps its version and gets no change.
| Specifier | Range | Updated to |
|---|---|---|
Exact version, ^ or ~ range, such as ^1.0.0 |
The specifier | The next version, with its prefix |
workspace:<range>, such as workspace:^1.0.0 |
The range | workspace: and the next range |
workspace:* |
The current version | Unchanged |
workspace:^, workspace:~ |
The current version, with its prefix | Unchanged |
The package manager resolves workspace:*, workspace:^ and workspace:~ when packing. Other SemVer ranges, such as >=1.0.0, stay as they are while they include the next version, and fail with NpmUnsupportedDependencyRangeError otherwise. Specifiers that are not SemVer ranges, such as catalog: or file:, are ignored.
Publishing
Section titled “Publishing”For each public scope whose version is missing from the registry it publishes to, the plugin publishes the package from its folder with the package manager’s own command:
| Package manager | Command |
|---|---|
| npm | npm publish |
| pnpm | pnpm publish --no-git-checks |
| yarn | yarn npm publish |
| bun | bun publish |
A prerelease gets --tag <channel>. The package manager runs the publish lifecycle scripts, such as prepublishOnly, prepack and postpublish, and resolves workspace: and catalog: specifiers (pnpm, yarn and bun).
Packages with "private": true get no release. npm’s own configuration sets the registry and the authentication: see Publish to npm. The plugin checks the registry with the package manager’s own command (npm view, pnpm info or yarn npm info; npm view for bun), so its configuration and credentials apply. With npm and bun, the registry of publishConfig (registry, or @scope:registry for a scoped package) applies to the check too.
Package manager
Section titled “Package manager”Without the packageManager option, the plugin reads the packageManager field of the closest package.json from the scope folder up to the project root, and uses npm when none has it. With yarn, the plugin requires Yarn 2 or later.
Releases
Section titled “Releases”| Field | Value |
|---|---|
type |
npm-package |
name |
<package name>@<version> |
status |
existing when the registry already has the version. |
Errors
Section titled “Errors”| Error | Cause |
|---|---|
NpmPackageJsonNotFoundError |
A scope folder has no package.json. |
NpmInvalidPackageJsonVersionError |
A package.json has an empty version. |
NpmUnsupportedPackageManagerError |
A packageManager field names a package manager other than npm, pnpm, yarn, or bun. |
NpmUnsupportedYarnClassicError |
A packageManager field names Yarn Classic (1.x). |
NpmUnresolvedSpecifierError |
The package manager is npm and a published dependency uses a workspace: or catalog: specifier. |
NpmRegistryLookupError |
Checking the registry fails for a reason other than a missing version. |
NpmUnsupportedDependencyRangeError |
The next version of an internal dependency leaves a range other than an exact version, ^ or ~. |
NpmPublishAuthError |
npm rejects the publish with ENEEDAUTH, E401, E403 or EOTP. |
NpmPublishError |
npm publish fails for another reason. The message is npm’s. With pnpm, yarn or bun, a failed publish reports the command’s output. |