Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there npm version prerelease identifiers?

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.

like image 411
timetowonder Avatar asked Jun 15 '17 12:06

timetowonder


People also ask

How should this pre release version be tagged in npm?

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.

Does npm version create a tag?

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.

How do I specify npm version?

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.


2 Answers

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 image 75
Daniel Avatar answered Sep 22 '22 23:09

Daniel


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 
like image 45
Anand S Avatar answered Sep 24 '22 23:09

Anand S