Lerna — Publish Release for All Packages

Lerna is a great tool to manage your monorepo. It installs and links project dependencies within the repository. Lerna can also run commands against all managed packages and help you with the publishing project.

We at Future Studio maintain the Supercharge Node.js framework using Lerna. It allows us to streamline the development, testing, and publishing processes.

This tutorial shows you how to publish a new version for all packages in a Lerna-managed monorepo.

Lerna Series Overview

Publish a Release for All Packages in a Lerna Monorepo

Developing code in a monorepo keeps dependencies close together. Adding new features to one package may require additions or changes in another package. The benefit of a monorepo is having that dependent code side by side.

When it comes to the publishing part, you may not have touched all the packages in the repo.

For example, we always publish a new version for all packages in the @supercharge/framework monorepo. It helps users to see that all dependencies of the framework received an update (even though there might not be new functionality).

Lerna allows you to “force” publish new versions for all managed packages using the —force-publish flag:

lerna publish --force-publish  

We’ve added an NPM publish script that builds all packages before publishing and then uses Lerna’s force-publish to tag a new version for each package:

{
  "name": "@your/package",
  "scripts": {
    "build": "lerna run build",
    "test": "lerna run test",
    "publish": "npm run build && lerna publish --force-publish"
  }
}

Enjoy publishing releases!


Mentioned Resources

Explore the Library

Find interesting tutorials and solutions for your problems.