What is @semantic-release/npm?
The @semantic-release/npm package is designed to automate the process of releasing new versions of npm packages. It updates the package version in package.json and publishes the package to the npm registry based on semantic versioning rules and the commit messages history. This tool is part of the Semantic Release ecosystem, which aims to fully automate the package release workflow, including determining the next version number, generating the release notes, and publishing the package.
What are @semantic-release/npm's main functionalities?
Update package version
This configuration snippet for the Semantic Release setup in the package.json file demonstrates how to automatically update the package version in package.json and publish the package to the npm registry. The 'npmPublish' option is set to true to enable publishing.
"release": {
"prepare": [
{
"path": "@semantic-release/npm",
"npmPublish": true
}
]
}
Publish to npm registry
This configuration enables the automatic publishing of the package to the npm registry as part of the release process. It specifies that the @semantic-release/npm plugin should be used for the publishing step.
"release": {
"publish": [
{
"path": "@semantic-release/npm",
"npmPublish": true
}
]
}
Other packages similar to @semantic-release/npm
standard-version
Standard Version is a utility for versioning using semver and CHANGELOG generation powered by conventional commits. Unlike @semantic-release/npm, it is more focused on manual versioning control and does not automatically publish to npm, but it automates version bumping and changelog generation.
release-it
Release It! is a CLI tool to automate versioning and package publishing, similar to @semantic-release/npm. It supports various plugins for different release steps, including changelog generation, version bumping, and publishing. Release It! offers more configurability for manual intervention in the release process compared to the fully automated approach of @semantic-release/npm.
@semantic-release/npm
Set of semantic-release plugins for publishing to a npm registry.
verifyConditions
Verify the presence of the NPM_TOKEN
environment variable, create or update the .npmrc
file with the token and verify the token is valid.
getLastRelease
Determine the last release of the package on the npm
registry.
publish
Publish the package on the npm
registry.
Configuration
Environment variables
The npm
authentication configuration is required and can be set via environment variables.
Both the token and the legacy (username
, password
and email
) authentication are supported. It is recommended to use the token authentication. The legacy authentication is supported as the alternative npm registries Artifactory and npm-registry-couchapp only supports that form of authentication at this point.
Variable | Description |
---|
NPM_TOKEN | Npm token created via npm token create |
NPM_USERNAME | Npm username created via npm adduser or on npmjs.com |
NPM_PASSWORD | Password of the npm user. |
NPM_EMAIL | Email address associated with the npm user |
Use either NPM_TOKEN
for token authentication or NPM_USERNAME
, NPM_PASSWORD
and NPM_EMAIL
for legacy authentication
Options
The plugins are based on npm
and will use the configuration from .npmrc
. See npm config for the option list.
The registry
and dist-tag
can be configured in the package.json
and will take precedence over the configuration in .npmrc
:
{
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"tag": "latest"
}
}
Usage
The plugins are used by default by semantic-release so no specific configuration is requiered to use them.
Each individual plugin can be disabled, replaced or used with other plugins in the package.json
:
{
"release": {
"verifyConditions": ["@semantic-release/npm", "verify-other-condition"],
"getLastRelease": "custom-get-last-release",
"publish": ["@semantic-release/npm", "custom-publish"]
}
}