4

Does npm allow you to publish earlier versions of a package? The only documentation I could find was on npm’s site:

[npm-publish] Fails if the package name and version combination already exists in the specified registry.

Once a package is published with a given name and version, that specific name and version combination can never be used again…

So by these specs, could I theoretically publish v3.2.0-beta before publishing v3.1.0, as long as none of those name–version combinations already exist? (I assume the answer is “yes,” but you never know if the author left out what they considered obvious: that version numbers should only increase.)

This is the reason I ask. My current latest version is v3.1.0-beta, and I’ve been doing work on my development branch ever since that release. But now I’m at a point where v3.2 is feature-locked, that is, no new features are to be added. So I feel like it’s time to go ahead and publish v3.2.0-beta and start testing for bugs. However, v3.1.0 (stable) hasn’t been published yet, and I don’t want to wait until that release to publish my beta of v3.2.

So essentially, am I free to publish v3.2.0-beta now, even though v3.1 is still in beta, and then next week, would I still be able to publish v3.1.0 even though it is has a lower version number? Or will npm report an error if I attempt to do so?

Can you point to any examples of packages that have done this? And which version does the latest tag point to: the most recent, or the most precedent (having the highest precedence)?

1
  • 6
    Yes, otherwise there'd be no way to publish bugfixes for versions that have otherwise been superseded.
    – jonrsharpe
    Commented Oct 26, 2017 at 23:27

1 Answer 1

4

Yes, you can. As johnrsharpe mentioned, this allows you to publish bugfixes on old versions, as well as concurrently release multiple testing versions.

Which is considered latest? From npm publish:

[--tag <tag>] Registers the published package with the given tag, such that npm install <name>@<tag> will install this version. By default, npm publish updates and npm install installs the latest tag.

So, to publish the v3.1.0 as latest, just check out that branch and npm publish. Omitting --tag will set it to latest.

To make v3.2.0-beta available, use npm publish --tag beta.

In npm land, it's common to apply --tag next for upcoming releases that will become the next stable version. So you could tag your v3.2.0 as "next" so that developers who like the bleeding edge can prepare for that becoming "latest".

See dist-tag for more, especially what tags are for.

To your point "that version numbers should only increase", since semver allows a (basically) arbitrary string to follow the patch version number to, there is no way to know which the author considers "before" between 1.0.0-beta and 1.0.0+exp.sha.5114f85, for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.