Search code examples
npmsemantic-versioning

4 digit versioning in npm


I'm surprised that 4 digit versioning is not allowed in npm ecosystem:

https://docs.npmjs.com/about-semantic-versioning

enter image description here

However, I have to merge my end product from npm to other systems where 4 digits are allowed. So, my question is:

(how) can we somehow make an exception for our own projects to use 4 digits?


Solution

  • You can kind of do it, but you need to substitute the last . with a -. However, this is NON-standard and you should probably make sure to comply with NPM's versioning in case you want to upload your project there. As @ylerjen has pointed out in the comments, when someone uses your package something like 1.2.3-1 will be considered a pre-release and your users won't be upgraded automatically unless they specify the full version, or you publish a new full major-minor-patch version.

    E.g. your version would look like 1.1.1-1.

    I have seen it in other projects for alpha versions etc and it allows for non-standard version numbers too. Some examples from NPM:

    • vue-class-component@8.0.0-rc.1
    • react-docgen@3.0.0-beta7

    However, be aware that when you use any of the npm version major / minor / patch commands it will not increase that number at first but simply truncate everything starting from the first - character. Example:

    1.0.6-1

    npm version patch

    1.0.6

    npm version patch

    1.0.7

    I think this is due to the fact that most people use it to mark a version to be in alpha / beta / rc in that order and when the version is final you keep the version number but remove the suffix.

    To automate this, you would need to make your own versioning CLI that knows how to handle your specific versioning scheme.