There is a very handy npm version
command. Besides arguments like major
, minor
and patch
it accepts arguments like prerelease
, prepatch
, etc.
It says in the docs that the commands work in accordance with the semver.inc
function.
These pre
commands I have a question about.
Say I'm currently at version v1.0.0
.
If I run npm version prerelease
it will bump version to v1.0.1-0
.
Is it possible to provide an extra agrument for a prerelease identifier according to https://github.com/npm/node-semver#prerelease-identifiers?
I wish something like npm version prerelease alpha
would bump version to v1.0.1-alpha.0
but that doesn't work.
Naming convention for pre-release versions An npm package must use Semantic Versioning 's naming convention for its version. In Semantic Versioning, the version number and pre-release identifier (like rc1 ) must be separated by a dash, like this: 1.0. 0-rc1.
If run in a git repo, it will also create a version commit and tag. This behavior is controlled by git-tag-version (see below), and can be disabled on the command line by running npm --no-git-tag-version version . It will fail if the working directory is not clean, unless the -f or --force flag is set.
For npm install specific version, use npm install [package-name]@[version-number]. Use npm view [package-name] version to know the specific latest version of a package available on the npm registry. Use npm list [package-name] to know the specific latest version of an installed package.
Starting with npm 6.4.0 you can use the --preid
option of npm version
like this:
$ npm version prerelease --preid=alpha v0.1.1-alpha.0 $ npm version prerelease --preid=alpha v0.1.1-alpha.1 $ npm version prerelease --preid=alpha v0.1.1-alpha.2
Like the other answer mentioned this is not supported by npm because of the reason mentioned in this comment
But you can achieve the same using semver package and npm scripts by adding something like the following to the package.json
"scripts": { "beta-version-patch": "npm version $(semver $npm_package_version -i prerelease --preid beta)", "beta-version-minor": "npm version $(semver $npm_package_version -i preminor --preid beta)", "beta-version-major": "npm version $(semver $npm_package_version -i premajor --preid beta)", "rc-version": "npm version $(semver $npm_package_version -i prerelease --preid rc)", "final-release": "npm version $(semver $npm_package_version -i)" }
and run npm run beta-version-patch
To be more generic you can use the following:
"scripts": { "semver": "npm version $(semver $npm_package_version -i $release --preid $preid)" }
and run commands like:
release=prerelease preid=alpha npm run semver release=prerelease preid=beta npm run semver release=premajor preid=alpha npm run semver
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With