When running npm version, how do I bump both patch and prerelease at the same time?



  • Are there any people who know npm here? I am developing a SPA and I have a question about npm version

    If the current release is 0.1.0 the next development version should be 0.1.1-beta-0, then subsequent development versions should bump the number after beta (so 0.1.1-beta-1, 0.1.1-beta-2, etc), then when the production release is ready it should have version 0.1.1.

    However I can’t find a way to bump both patch and prerelease at the same time or remove prerelease for a version number without bumping patch using npm version. Can I do this with npm version?


  • And then the murders began.

    @magnusmaster Not an expert, but I enjoy reading docs for weird things. ;)

    I think that npm version prerelease is what you want to bump patch and prerelease at the same time. The docs seem to say that it does what you want:

    If called from a non-prerelease version, the prerelease will work the same as prepatch. It increments the patch version, then makes a prerelease. If the input version is already a prerelease it simply increments it.

    As for removing the prerelease... I'd try npm version patch but the docs aren't clear if that does what I'd expect.


  • Considered Harmful

    @Unperverted-Vixen said in When running npm version, how do I bump both patch and prerelease at the same time?:

    I enjoy reading docs for weird things

    I knew your username was a lie.



  • @Unperverted-Vixen I confirm.

    I've configured release builds a couple of months ago, with the goal to make the release process of the npm-managed component (front-end) to match the release process of the maven-managed component (back-end) using the maven release plugin. So we do:

    • Before the release, to get rid of the prerelease tag, we call either npm version patch or npm version minor, depending on which level release we want to do. That is then checked in, tagged and built.
      • npm version patch will set the next available patch release, so 0.1.1-beta.0 becomes 0.1.1. Effectively just removes the prerelease tag.
      • npm version minor will set the next available minor release, so 0.1.0-beta.0 becomes 0.1.0, but 0.1.1-beta.0 becomes 0.2.0, because the patchlevel was requested to be 0.
    • After the release to add the prerelease tag with a new version number, we do either npm version prepatch or npm version preminor.
      • prepatch will bump the patchlevel and add a prerelease tag.
      • preminor will bump the minor version and add a prerelease tag.
      • default pre-release tag is -pre.0. You can set the text part, but IIRC it's always .0 at the end.
      • we use minor for both when releasing from master and patch for both when releasing a hotfix from a branch, but you can just do prepatch or prerelease in both cases and leave it up to the later minor to bump the minor version because the patchlevel was non-zero.


  • Thanks for the help everyone!


Log in to reply