DEV Community

Charles Loder
Charles Loder

Posted on

How to create a 'canary' release on npm

This post will show how to create a canary release for an npm package.

tldr;



npm version --preid canary preminor
npm publish --tag canary


Enter fullscreen mode Exit fullscreen mode

canary testing

In short, canary testing is a way to publish packages without affecting all users. Users will have to opt-in to use a canary release.

versioning

The version command has a few built in options.

If our package is at 1.1.0 then running npm version minor will update the package.json to 1.2.0. Additionally, it will update package-lock.json and npm-shrinkwrap.json and add a git tag.

To update 1.1.0 to a canary version, run:



npm version --preid canary preminor


Enter fullscreen mode Exit fullscreen mode

This updates the version to 1.2.0-canary.0.

To make updates to this version, run:



npm version --preid canary prerelease


Enter fullscreen mode Exit fullscreen mode

This updates the version to 1.2.0-canary.1.

publishing

To ensure that the canary branch isn't published to @latest, it can be tagged.

To do so, run:



npm publish --tag canary


Enter fullscreen mode Exit fullscreen mode

This ensures that when a user runs:



npm i your-pkg


Enter fullscreen mode Exit fullscreen mode

That it installs the latest, stable, release.

To install the canary version, they must run:



npm i your-pkg@1.2.0-canary.1


Enter fullscreen mode Exit fullscreen mode

summary



npm version --preid canary preminor # go from 1.1.0 to 1.2.0-canary.0
npm version --preid canary prerelease # go from 1.2.0-canary.0 to 1.2.0-canary.1
npm publish --tag canary # publish your-pkg@1.2.0-canary.1


Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay