npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-dist-tag

v1.0.2

Published

A simple tool for selecting a dist tag for npm publish.

Downloads

87

Readme

This is an extremely simple tool for selecting the dist tag that npm publish should use.

This tool has no configuration... and it is likely to stay this way. I see the lack of configuration as a feature. Configuration is easy to mess up.

Moreover, this tool certainly does not support all possible usages of dist tags. This tool was created to satisfy my own needs. If it suits you too, fine. If not, you can use another tool.

Algorithm

This tool must run after the new version number has been edited into package.json. You can edit it manually, or tools like npm version can edit it for you. It read the version number from package.json, this version number is called newVersion in the following explanations.

The tool fetches the previous dist tag usage from https://registry.npmjs.org/.

  1. If newVersion is not a prerelease, then the selected dist tag is provisionally "latest".

  2. If newVersion is a prerelease, then the selected dist tag depends on the first part of the prerelease. This tool uses semver.prerelease() to break the prerelease into parts. A dist tag is provisionally set to the value obtained from a lookup in this table:

    | prerelease part | dist tag | |-----------------|----------| | alpha | dev | | beta | dev | | rc | next |

A prerelease part other than those above is an error.

  1. If the provisional dist tag already has a version history and the latest version in that version history is greater than newVersion then the final dist tag is patch. Otherwise, the provisional dist tag becomes the final dist tag. (Note that the case where the latest version is equal to newVersion is not considered. When this happens, you're trying to publish anew a version that was already published, which npm forbids. There's no correct solution in such a case.)

The last step is there for scenarios where you maintain multiple branches of a project. Say you have released version 2.0.0 and then want to release a patch with version 1.2.3 because series 1 is still supported. Prior to releasing 1.2.3, latest points to 2.0.0 **and you want to keep it this way after releasing 1.2.3. Unfortunately, npm provides no way to publish a new version without associating a dist tag with it. We use patch for that purpose. In the hypothetical scenario we just gave 1.2.3 would be assigned the patch dist tag. Note that the progression of the patch dist tag is not organized in any logical order. If 3.0.0 has been released and then you release 2.1.3 and then you release 1.2.3 then patch will point to 1.2.3. The version published latest wins (not the one with the highest version number). patch is merely a dumping ground to prevent those dist tags that matter from being clobbered.

IMPORTANT NOTE: If you start publishing your package with semvers that have prerelease parts like alpha or rc then you'll be publishing to dist tags other than latest. If that bothers you, your solutions are: 1) use 0.x.x releases, 2) fix it manually.

Integration

This package installs a script among the bins installed by npm named simple-dist-tag. This command computes the dist tag to use and outputs it to stdout.

If you invoke npm publish in a script directly, you can pass the output as argument:

npm publish --tag `simple-dist-tag`

If you are using a tool that invokes npm publish for you, you can use it to set the npm_config_tag environment variable so that npm publish uses the tag specified. Example:

env npm_config_tag=`simple-dist-tag` tool-that-invokes-npm-publish