Is there a best way to publish a previous major version of an npm package without adding a tag for it? Our current major version is 3.x (v3) so we npm publish
that version to automatically give it the latest
tag. When we publish updates to the 2.x
version (v2) we have to give it a tag so that it doesn't automatically grab the latest
tag from v3.
We could do something like previous
, though the meaning of that is subjective. Really we don't need a tag for v2 at all. Semver works great if people want to install v2. Is there a better solution to not add unnecessary tags than publishing it with a tag and adding a postpublish
script that deletes the tag? (That sounds ridiculous as I write it)
Looking at this comment from 2015, "Every publish must be associated with a dist-tag, by design." And I don't see a way to bypass the tag in the current code of libnpmpublish and npm, unfortunately.
Thus, I think you have the best options laid out already: publish under another tag, whether that tag is temporary or not.
However, if I could make a suggestion...
Instead of the subjective previous
tag, you could consider publishing the previous versions under a tag called v2
. This is a pattern that I've noticed the Angular team uses for LTS releases, for example:
While I think it's of minimal use to a consumer since they could just npm install @angular/core@11
instead of npm install @angular/core@v11-lts
, nonetheless it might be a cleaner approach to publish.