The answer is yes, you still need Lerna or other tool to complement the features that came with npm@7 workspaces. These are the things that are not handled by npm@7 workspaces (as of writing of this answer):
Understanding the monorepo topology
npm workspaces are aware of monorepo package topology to certain level. Workspaces for example know that package-c uses package-a and package-b as its dependencies. But there is a small thing to keep in mind:
$ npm run build --workspaces
This command will run npm run build
for all the monorepo packages.
Let’s say that package-a depends on package-b and package-c depends both on package-a and package-b. The order of execution you get from running the command is depends on your workspaces
array in package.json
. So if you have this:
{
"workspaces": ["package-a", "package-b", "package-c"]
}
then the build order will be:
- package-a
- package-b
- package-c
but the correct order should be:
- package-b
- package-a
- package-c
For things to build in the correct order, you should ensure you list them in the correct order in package.json:
{
"workspaces": ["package-b", "package-a", "package-c"]
}
Change management
Lerna can detect changes in monorepo and provide you with a list of packages that have changed. This is handy if you only want to run tests for changed packages. npm@7 workspaces can do no such thing yet (Oct 5th, 2021).
Publishing
Lerna can manage versioning and publishing of your packages. Comes with two different strategies of managing versions: fixed and independent. It generates changelog, and publishes only changed packages to npm.
There is much more to it for sure, but these are the main things that you still need on top of npm@7 workspaces. If you use Lerna or other tools, that's up to you.
I've documented all the things I have learned while maintaining JavaScript monorepo with Lerna in an article. It describes how monorepo management processes simplified significantly after npm@7 introduction, but why we still need to use Lerna or other tools on top of it.
npm run
andnpm exec
are now supported and can be used to run commands across multiple workspaces/packages. – Stellular