Repo
Docs
Versioning and Publishing

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 (opens in a new tab) 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:

Understanding Changesets

We recommend taking a look at the Changesets docs. Here's our recommended reading order:

  1. Why use changesets? (opens in a new tab) - an intro that takes you through the fundamentals.
  2. Installation instructions (opens in a new tab)
  3. If you're using GitHub, consider using the Changeset GitHub bot (opens in a new tab) - a bot to nudge you to add changesets to PR's.
  4. You should also consider adding the Changesets GitHub action (opens in a new tab) - 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:

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.

Last updated on 2022-10-18T14:25:33.000Z