3

We are attempting to automate some of our versioning and build process for our Angular 2 applications. We would like to make use of

npm version

but are struggling with how to add an 'rc' to our package without having to manually specify the package name.

For example, lets say we have v1.0.0 and would like to go to v1.0.0-rc.1

We could use the below command and it would work fine.

npm version '1.0.0-rc.1'

The issue is we are trying to automate this and would prefer to not have to look at the current package name to get this.

Is there a command the basically says "grab the current package version, and add -rc.1 to it"?

Tony Scialo
  • 5,457
  • 11
  • 35
  • 52
  • Seems odd that you want to go from version `1.0.0` to `1.0.0-rc.1`. Typically, according to _semver_ rules, the `1.0.0-rc.1` _release candidate_ version is released/published before the `1.0.0` _major_ version. More info regarding this is provided in [item 11](https://semver.org/#spec-item-11) of the _semver_ documentation. – RobC Jul 20 '18 at 08:55
  • Updated my answer, starting with npm 6.4.0 there is now a way to set the prerelease identifier from the command line. – Daniel Aug 17 '18 at 04:35

1 Answers1

2

Starting with npm 6.4.0 you can use the --preid option of npm version like this:

$ npm version prerelease --preid=rc
v0.1.1-rc.0
$ npm version prerelease --preid=rc
v0.1.1-rc.1
$ npm version prerelease --preid=rc
v0.1.1-rc.2

In npm 6.3.0 and earlier, the closest you can get is to invoke:

npm version prerelease

which will make your version 1.0.1-0, 1.0.1-1, and so on (but no rc prerelease identifier).

Daniel
  • 21,933
  • 14
  • 72
  • 101