8

I have a npm module which is already released under 4.x.x version and have breaking changes comparing to 3.x.x stable version.

However I have some updates to 3.x.x version and want to patch its' npm version. Is it possible? Can I manage 2 major versions on npm?

Will https://docs.npmjs.com/cli/publish npm publish --tag do the trick?

Kosmetika
  • 20,774
  • 37
  • 108
  • 172

1 Answers1

4

However I have some updates to 3.x.x version and want to patch its' npm version. Is it possible? Can I manage 2 major versions on npm?

Yes, it's possible. Something that's common is to have the master branch for new developement and branch off older versions if you want to patch them and name them e.g. 3.x.

So if we assume your module has previously been released as 3.1.2 and you want to fix a bug, i.e. you want to publish 3.1.3 (patch release). Simply branch off from 3.1.2 (assuming you have a git tag v3.1.1):

git checkout v3.1.2
git checkout -b 3.x
# make changes and commit
npm version patch # will bump package.json, commit that and tag
npm publish
rtn
  • 127,556
  • 20
  • 111
  • 121
  • 1
    Will this work if you release a dev branch, e.g. if you want `npm install` to install version 3, but offer version 4 with an explicit "@4.x.x"? – Michael Sep 14 '19 at 17:58
  • 4
    Nope. Above will publish the _latest_ version of the module. If you want to publish other versions that aren't considered latest version (i.e. default when doing npm install) you need to use `--tag`. For example `npm publish --tag next`, this will enable users getting version 3 by default but need to do `npm install foo@4.0.0` to get that specific version. Makes sense? – rtn Sep 15 '19 at 12:10