Versioning and Publishing Packages in a Monorepo
Manually versioning and publishing packages in a monorepo can be extremely tiresome. Luckily, there's a tool that makes things easy - the Changesets CLI.
We recommend Changesets because it's intuitive to use, and - just like Turborepo - fits with the monorepo tools you're already used to.
Some alternatives are:
- intuit/auto - Generate releases based on semantic version labels on pull requests
- microsoft/beachball - The Sunniest Semantic Version Bumper
Understanding Changesets
We recommend taking a look at the Changesets docs. Here's our recommended reading order:
- Why use changesets? - an intro that takes you through the fundamentals.
- Installation instructions
- If you're using GitHub, consider using the Changeset GitHub bot - a bot to nudge you to add changesets to PR's.
- You should also consider adding the Changesets GitHub action - a tool which makes publishing extremely easy.
Using Changesets with Turborepo
Once you've started using Changesets, you'll gain access to three useful commands:
# Add a new changeset
changeset
# Create new versions of packages
changeset version
# Publish all changed packages to npm
changeset publish
Linking your publishing flow into Turborepo can make organising your deploy a lot simpler and faster.
Our recommendation is to add a publish-packages
script into your root package.json
:
{
"scripts": {
// Include build, lint, test - all the things you need to run
// before publishing
"publish-packages": "turbo run build lint test && changeset version && changeset publish"
}
}
We recommend publish-packages
so that it doesn't conflict with npm's
built-in publish
script.
This means that when you run publish-packages
, your monorepo gets built, linted, tested and published - and you benefit from all of Turborepo's speedups.