npm-version
Bump package version and tag
TLDR
Check current version
Bump the minor version
Set a specific version
Bump the patch version without creating a Git tag
Bump the major version with a custom commit message
SYNOPSIS
npm version <newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--message "message"]
PARAMETERS
<newversion>
A specific version number to set. Must be a valid semantic version string (e.g., 1.2.3).
major
Increments the major version number (e.g., 1.0.0 -> 2.0.0).
minor
Increments the minor version number (e.g., 1.2.0 -> 1.3.0).
patch
Increments the patch version number (e.g., 1.2.3 -> 1.2.4).
premajor
Increments the major version number and adds a prerelease identifier (e.g., 1.0.0 -> 2.0.0-0).
preminor
Increments the minor version number and adds a prerelease identifier (e.g., 1.2.0 -> 1.3.0-0).
prepatch
Increments the patch version number and adds a prerelease identifier (e.g., 1.2.3 -> 1.2.4-0).
prerelease
Increments the prerelease version number if it exists, otherwise initializes it (e.g., 1.2.3-0 -> 1.2.3-1, or 1.2.3 -> 1.2.4-0).
--message "message"
Specifies a custom commit message. The string "%s" will be replaced with the new version number.
--no-git-tag-version
Do not commit or tag the new version.
DESCRIPTION
The `npm version` command is used to increment the version number in a `package.json` file and create a new Git tag. It automates the process of updating your project's version, committing the changes, and tagging the commit with the new version. This command is critical for managing software releases and ensuring proper versioning for package management. It integrates seamlessly with Git to maintain a consistent version history. The version can be incremented by a semantic version part (`major`, `minor`, `patch`), a prerelease identifier (`premajor`, `preminor`, `prepatch`, `prerelease`), or a specific version number. It also runs lifecycle scripts like `preversion`, `version`, and `postversion` if they are defined in the `package.json` file. This makes it a central tool in the release workflow for npm packages, allowing for automated version bumps and tagging, facilitating continuous deployment.
CAVEATS
Requires a Git repository to function correctly. It also requires a `package.json` file in the current directory. Fails if the version bump results in a non-semantic version.
LIFECYCLE SCRIPTS
The `npm version` command runs lifecycle scripts during the versioning process. The order is: `preversion`, then `version`, and lastly `postversion`.
If any of these scripts exit with a non-zero code, the `npm version` command will abort. The VERSION environment variable is set during these scripts.
SEMANTIC VERSIONING (SEMVER)
The command uses Semantic Versioning (SemVer) to determine how the version number is incremented. SemVer is a widely adopted standard for versioning software packages and is crucial for dependency management.
HISTORY
The `npm version` command has been a core feature of npm since its inception, providing a standardized way to manage package versions. It evolved alongside npm's growth and the increasing importance of semantic versioning. It has been crucial to automate package publishing and dependency resolution.