How to generate NPM release candidate version
Asked Answered
N

4

28

Say I want to generate a pre-release NPM version.

Originally I have this:

   "version": "0.0.1"

I tried:

npm version prepatch
npm version prepatch
npm version preminor
npm version preminor

that gave me this:

v0.0.2-0
v0.0.3-0
v0.1.0-0
v0.2.0-0

Those don't look useful to me, because they always bump up the actual version number, meaning npm version patch and npm version prepatch don't seem to be making much difference.

So my question is - is there an official way to generate an alpha/beta version with npm at the command line?

npm version minor-alpha
npm version minor-beta
npm version minor-rc

something like that?

Needless answered 13/6, 2018 at 20:58 Comment(1)
Possible duplicate of Are there npm version prerelease identifiers?Morse
A
35

UPDATE

As of npm 6.3.0-next.0 you can now use --preid when tagging pre-releases with version.

npm version prerelease --preid=next

NPM Link: https://docs.npmjs.com/cli/version


Original answer

Sadly (and a little bit ironic) npm does not fully support all the features of semver!

What you need is a feature called pre-id, found in the semver spec #9. I have submitted a PR to npm to fix it but it was rejected. https://github.com/npm/npm/pull/13794

preids basically allow you to specify an id for a prerelease, for example:

1.0.0-alpha or 1.0.0-alpha.1

Forrest rejected this proposal in a comment writing this:

After some further consideration, and discussion within the team, I've decided that this isn't a change the CLI team is going to land. Working with prerelease versions is tricky, and this feature is enough of an edge case that I think it increases, rather than decreases, the number of opportunities for prerelease versions to be a footgun.

My concern about footguns is connected to the decision, in semver@^4, to make prerelease versions fall outside the range matching for ~ and ^. Were semver's behavior to change, it might make more sense to have a way to opt into (and then increment within) a given prerelease identifier. After watching the travails of the React community in using prerelease versions with peerDependencies and other interrelated suites of packages, it's pretty clear that the current behavior of semver with respect to prerelease versions is of pretty limited usefulness. That means there's a substantial possibility that that behavior may change.

As it stands, though, I think users who want to use prerelease versions are better off using third-party tools like npmversion, or build scripts that use npm version "x.y.z-prealpha.2" (or whatever suits your use case) instead. Thanks for your time, and my apologies for the delay!

As he recommends, to get this working you should be using a tool that does support full semver versioning. I presonally recommend semver package, found in the npm documentation itself here https://docs.npmjs.com/misc/semver

Atavistic answered 14/6, 2018 at 11:13 Comment(2)
You could move the update to the top of the answer, hard to see it under the long text.Morse
@MondKin thanks, updated with a more detailed answer as wellAtavistic
I
13

You can use:

npm version prerelease --preid=rc

Result: v1.0.0-rc.0

Ingridingrim answered 17/10, 2019 at 12:48 Comment(2)
how to bump v1.0.0-rc.0 to v1.0.0-rc.1 ?Inflight
@Inflight just run npm version prerelease --preid=rc again and it will increment rc.0 to rc.1`Petulancy
O
2

npm version prerelease will generate 0.0.0-x version

Olatha answered 26/8, 2019 at 7:51 Comment(0)
N
1

Looks like:

npm version prerelease

is basically what I am looking for, but this doesn't add alpha/beta/rc to the version, it just does this x.y.z-n.

Needless answered 13/6, 2018 at 21:48 Comment(1)
npm version does accept a valid semver string. E.g. npm version 0.0.2-rc.0Package

© 2022 - 2024 — McMap. All rights reserved.