JSBits #6: Lerna vs. Yarn workspaces

Diario del capitán, fecha estelar d75.y38/AB

The other day, one of our developers messaged me on Slack about a tool called Lerna. I've recommended yarn workspaces over Lerna in the past, but now I want to be more specific about why.

Museum of fine arts - Photo by Tony Reid

My general take is:

Use yarn workspaces if you're building something with several packages (like a big application) but, if you intend to publish that packages into a registry (like a library or a framework) use lerna instead.

Splitting the code into small modules is a great way to write clean, decoupled, high quality and well-tested code. The JavaScript ecosystem knows it well. But - surprise! - it has its drawbacks.

At development time, you have to keep up to date the dependencies of each module with each other in order to "see" the changes. That's what yarn workspace and lerna do. In short, they put symlinks inside node_modules, so when you modify a package, the dependent packages can see it.

But there's another problem: when a package A depends on a package B that increases its version number (because it's modified), then package A should change the version number, too. Coordinating several changing version numbers is hard, and that's what lerna is designed for.

Happy monorepo hacking!

Daniel Gómez

Daniel Gómez

Dani tuvo un Oric 1 como primer ordenador, al menos hace 100 años. Ahora combina la programación con sus dos bandas y sus tres hijos. La leyenda dice que tiene un hermano gemelo idéntico y que trabajan como equipo.

comments powered by Disqus

Estás a un paso de conocer a tu mejor socio.