npm version to add alpha postfix

How can i bump the package.json version to contain -alpha using npm versioning.

Running npm version <new version> will bump the version of the package.js file, however i want to add -alpha postfix to the version, but i am unable to as it is not stated in the documentation, but its supported by semver itself.

Actual Result:

> npm version prerelease
> v0.2.1-1

Expected Result:

> v0.2.1-alpha

Answer

You cannot set 0.2.1-alpha automatically, but 0.2.1-alpha.0 is possible.

npm supports --preid option to specify the prefix of prereleases. It’s available in combination with pre* versions.

Example 1. Make the alpha of next major version:

# 1.2.3 => 2.0.0-alpha.0
npm version premajor --preid alpha

Example 2. Bump alpha to beta:

# 2.0.0-alpha.0 => 2.0.0-beta.0
npm version prerelease --preid beta

Once you create a prerelease, you can increment the number using prerelease argument.

# 2.0.0-beta.0 => 2.0.0-beta.1
npm version prerelease

Leave a Reply

Your email address will not be published. Required fields are marked *