feat: add experimental support to run tasks via Nx #3139
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Nx is the third option in addition to p-map and p-queue
Description
Currently running
lerna run
will result in Lerna either delegating top-map
orp-queue
to schedule tasks/processes. Lerna has direct dependencies on bothp-map
andp-queue
.The industry has advanced since the time of
p-map
andp-queue
. Tools like Nx and Lage are much more powerful and efficient task orchestrators. They support computation caching and, in case of Nx, config-free task distribution. A lot of teams are moving away from Lerna for this reason.This PR adds Nx (which is a MIT-licenced extensible build system) as a third option (in addition to
p-map
andp-queue
). If you have the nx package installed, and you havenx.json
in your workspace, Lerna can now delegate itslerna run
commands to Nx. This is optional: you have to opt into it. And it's done in a backwards-compatible way: everylerna run
command will work but will be significantly faster and can be distributed across multiple machines without any config.How Has This Been Tested?
We have tested on several small Lerna repos. For instance, this repo contains a benchmark measuring cache restoration of different monorepo-based tools: https://github.com/vsavkin/large-monorepo
With this change enabled, Lerna is on par with Nx, and is significantly faster than other tools.
Once the beta with this change is out, we are going to add it on several large enterprise Lerna repos to measure the perf and make sure the change handles all edge cases well.