DEV Community

Noviny 🦋
Noviny 🦋

Posted on

Dependencies in Monorepos with Manypkg ☔️

Or: Make upgrading dependencies of your monorepo quick and easy with this one simple package*

yarn add @manypkg/cli

A common bit of wisdom in monorepos, is when you depend on external versions of a package, you should depend on the same version everywhere. This ensures more consistent behaviour across different packages, reduced install time, and reduced bundle size.

manypkg has been able to detect when packages depend on different versions, and fix for them since it started, but there hasn’t been a good path on how to do updates. Enter our newest helper command:

manypkg upgrade react

This command will find every package that relies on react , and upgrades it to latest. Nice and simple.

This works with a tag, such as

manypkg upgrade react next

And works with a version range such as:

manypkg upgrade react ^16.3.0

For packages from monorepos

If you are installing packages from a monorepo, you may want to upgrade all packages from that monorepo at once, to the same point in time. For this, you can specify a scope:

manypkg upgrade @keystonejs

You can still specify a tag, or a version, and all packages will be upgraded the first tag

Tagging in a monorepo

I have a theory, which is that in a monorepo, being able to install a particular release of all packages is useful (for when you don’t want latest), but it’s still nice if each version for packages can remain separate.

To allow both these things, we want to be able to name a release, and make that name meaningful on npm. The best way is to tag all the packages on npm:

manypkg npm-tag arcade

This will add the tag arcade to the current version for every package in your monorepo. Now you’re all set up to manypkg upgrade everything to arcade 😎

With these new tools under your belt, it should be even easier both to manage your monorepo, and to make it easier for consumers of your packages.

This is neat, but I see manypkg has some other commands?

It does! manypkg check and manypkg fix are opinionated linting of your dependencies, mostly focused on your monorepos installs or links being more efficient. If you are developing in a monorepo, you might find these helpful - otherwise, you can just use manypkg for upgrading, no worries.

*Yes I write titles like an academic ¯\_(ツ)_/¯

Top comments (0)