DEV Community

Cover image for Lerna is no longer maintained. Now what? - Part 1
Matti Bar-Zeev
Matti Bar-Zeev

Posted on

Lerna is no longer maintained. Now what? - Part 1

In this article join me as I migrate my Pedalboard monorepo from Lerna to NX.

So I've recently seen that the Lerna project announced (in it’s main README) that it will no longer be maintained -

Image description

Just like that with no second warning, a project that was the groundbreaking pioneer in monorepo’s management called it quits,
Indeed a shame but no surprise there, right? I mean, seriously, this project had “not for long, mates” written all over it, and yet I still decide that it will power a small portion of my Pedalboard monorepo.

Why?

Have a look in my “No BS monorepo - Part 1” article where I explain why, at the time, Lerna appealed more to me. As a matter of a fact, if it wasn’t going “deprecated” I probably would still use it, since I kept it very focused on the tasks it does best.
Oh well, this is how our industry rolls sometimes… ¯\_(ツ)_/¯


First of all let’s check what I used Lerna for in my monorepo.

  • Be able to launch npm/yarn scripts from the root project which will run on all the packages on my monorepo
  • Be able to bump a package version, along with generating a CHANGELOG.md file and git tagging it
  • Be able to publish the changed packages to NPM

Great. So I know what I require from the alternative, but what alternatives are out there?
This wonderful monorepo.tools resource compares the leading solutions for monorepos today, check it out if you haven't already.

Scrolling down to the bottom you can see a very detailed comparison and it looks like NX is the clear winner with most “checks”. Adding that to the fact that I hear more and more how NX improved monorepo workflows in the industry, and I think it is time to have a go with it -

NX it is.

So let’s start with our first goal:

Launch npm/yarn scripts from the root project which will run on all the packages on my monorepo

Going to NX docs I found a resource talking about how to add NX to an already Lerna powered monorepo.
As suggested I run this command on the project’s root:

npx add-nx-to-monorepo

I’m prompted with a question of whether I would like to use Nx Cloud or not. Nx Cloud is a feature which allows a project to persist its script running computations (such as tests results, etc.) in the cloud, thus making following calls to those scripts run much faster, given that nothing was altered to bust the cache.
This is something I don’t feel I need at the moment, but if I regret it I can add it later on.

I read that there is a cool feature of seeing the monorepo dependencies graph, and being a FED at heart I cannot resist. Let’s check it out by running yarn nx graph

Image description

Oh nice :) I feel like a proud parent looking at a picture of my kids. Here is my little components package and look there - it depends on the hooks package. How adorable
ok, ok, we’re moving on.

On the root project’s package.json I have the scripts which run on the entire packages, such as testing or linting. Here is how it looks now using lerna:

"scripts": {
   "test": "lerna run test --",
   "coverage": "yarn test --coverage",
   "lint": "lerna run lint",
   "build": "lerna run build",
   "publish:lerna": "lerna publish --yes --no-verify-access",
   "coverage:combined": "pedalboard-scripts aggregatePackagesCoverage && nyc report --reporter lcov"
 },
Enter fullscreen mode Exit fullscreen mode

If I run yarn test for example, it runs the test script for each package and I get this output:

Image description

Now let’s try and make it with NX.
The NX command is a bit different. I need to use the “run-many” command and state the target script I want to run.

So the test command will now look something like this:

"test": "nx run-many --target=test --all",
Enter fullscreen mode Exit fullscreen mode

This works well, let's change the lint and build commands as well:

"scripts": {
       "test": "nx run-many --target=test --all",
       "coverage": "yarn test --coverage",
       "lint": "nx run-many --target=lint --all",
       "build": "nx run-many --target=build --all",
       "publish:lerna": "lerna publish --yes --no-verify-access",
       "coverage:combined": "pedalboard-scripts aggregatePackagesCoverage && nyc report --reporter lcov"
   },
Enter fullscreen mode Exit fullscreen mode

Notice that the “coverage” command is using the “yarn test” command in turn, and this seems to work as expected, passing the “--coverage” param and producing the coverage directory in all relevant packages. One thing I’ve noticed though is that it does not output the coverage results in the terminal as Lerna did.

The coverage:combined does not involve Lerna and still works as before. You can read more about it here

Ok, this completes our first goal of having the ability to run scripts for all packages. Cool and pretty straightforward.

In the next episode we will dive into how to detect changes and bump package versions accordingly, along with generating a CHANGELOG.md file and git tagging it. Stay tuned.

As always, if you know of other means of achieving what's written above, please make sure to share them with the rest of us :)

Hey! If you liked what you've just read check out @mattibarzeev on Twitter 🍻

Art by Cornelis Cort, Achenbach Foundation for Graphic Arts

Top comments (10)

Collapse
 
lakshmaji profile image
Lakshmaji • Edited

Nice one on nx just an update, lerna is back, it is live.
You can find it here again 🤓
Use this small blog post for migrating from lerna 3.x to 5.x.

Collapse
 
mbarzeev profile image
Matti Bar-Zeev

I know mate, check out a post I published just a while later - dev.to/mbarzeev/this-is-no-lerna-i...

Collapse
 
gktim profile image
gkTim

Also rush.js and turborepo are a good alternative.

I have only used nx with angular now (because angular doesn’t really work with today’s standards and not working well with other solutions. Especially ngcc makes it worse)

But with vue.js I have done a few with rush.js and turborepo.

The good thing of them compared to nx they don’t add so much dependencies on there own and don’t try to do so many things.

Collapse
 
mbarzeev profile image
Matti Bar-Zeev

I didn't like the "magic" of NX as well, but as far as I understand you can use its core without all the other magic.

Collapse
 
julrich profile image
Jonas Ulrich

Bookmarked... this can come in quite handy as we will have to migrate away from Lerna now, too. Was thinking about about NX for that, too. Other option would possibly be yarn 3 workspaces.
... will also have to have a look at Turborepo after reading the comments!

Collapse
 
guitarino profile image
Kirill Shestakov

Yarn workspaces is the easiest and cleanest option in my opinion and integrates well with existing yarn workflows. I believe there is also ways to run scripts for all workspaces.

Collapse
 
mbarzeev profile image
Matti Bar-Zeev

True, Yarn workspaces can do that, it appears. Might be a good idea to use yarn for that 🤔
What concerns me more is the version nad publishing.
Thanks for the feedback!

Collapse
 
stephanebischoff profile image
Stephane • Edited

Great articles. I see you change your mind on using nx. @mbarzeev
So no part 2 :)

Collapse
 
mbarzeev profile image
Matti Bar-Zeev

There was actually no part 2. The next article was rethinking this whole direction -
dev.to/mbarzeev/rethinking-the-one...
🙂

Collapse
 
eberfreitas profile image
Éber Freitas Dias

Have you looked at turborepo and if so, do you have any opinions on how it compares to NX?