Whether we choose Lerna or Workspace, our goal is to choose a relatively mature solution to solve some side effects caused by Monorepo. So what do we hope to solve?
Dependencies management
The ability to manage packages dependencies uniformly
Operations for normal dependencies are not too complicated with Monorepo.
Automatically handles dependencies that exist between packages, rather then using link.
Workflows
Development Workflow
Both rookies and veterans can get into development mode quickly (Half the work is done by tools, and the other half needs to be done by document).
Release Workflow
Publishing multiple packages together or publishing a single package can be done very easily.
In the end, we should choose a solution that solves more problems without incurring too much mental cost.
Solutions
Lerna
Lerna, one of the most popular Monorepo solutions, has three main features.
Packages Management
lerna init: Create a new Lerna repo or upgrade an existing repo to the current version of Lerna.
lerna create: Create a new lerna-managed package.
lerna import: Import a package into the monorepo with commit history.
lerna list: List local packages.
Dependencies Management
lerna boostrap: Installs all dependencies and links any cross-dependencies, like npm install.
lerna add: Add local or remote package as dependency to packages in the current Lerna repo, like npm install <package>.
lerna link: Symlink together all packages that are dependencies of each other, link npm link.
lerna clean: Remove the node_modules directory from all packages.
Release Workflow
lerna version: Bump version of packages changed since the last release.
lerna publish: Publish packages in the current project.
Overall, Lerna is a solution with complete functionality coverage, but there is no silver bullet in software. Therefore, the existing defects of Lerna will be summarized later, especially for this project.
Workspaces
Workspaces is an inherent feature of mainstream PMT(Package Management Tool). It's mainly developed by the natural advantages of package management tools in dependency management.
It has an unparalleled advantage in dependency management, and because it's a inherent feature of PMT, it tends to have no additional mental cost.
This is a survey of Workspaces for mainstream PMT, ranked from top to bottom, good to bad, so it's obvious which one to choose :)
π€ Too many strange features, It is not qualified as a PMT.
When we consider the Workspaces feature of a PMT as a solution, we also need to consider whether the solution is qualified or useful as a PMT.
β
Overall, Workspaces can solve all the existing problems in Dependencies Management, while workflow needs to be done in other ways.
Summary
As mentioned above, Lerna has complete functionality, Workspaces only solves the dependencies management problem well. So why do I still insist on replacing Lerna with PNPM Workspaces?
β
First, Lerna's Packages Management features are not needed. Second, Lerna's Dependencies Management features are completely covered by Workspaces and can do better. Third, Lerna's Release Workflow features are simple and crude. We wanted more flexibility, extensibility, stability, certainty from Release Workflow and Lerna didn't allow us to do it better.
In short, Lerna has some features that are not needed or are difficult to use and can impose additional mental cost, even if the PNPM Workspaces is not complete, it is sufficient for this project, and it is small and easy to use, with no additional burden.
Final Todo
[ ] Remove Lerna
[ ] Add PNPM workspaces, and use PNPM as the main PMT
Intro
Whether we choose Lerna or Workspace, our goal is to choose a relatively mature solution to solve some side effects caused by Monorepo. So what do we hope to solve?
link
.In the end, we should choose a solution that solves more problems without incurring too much mental cost.
Solutions
Lerna
Lerna, one of the most popular Monorepo solutions, has three main features.
lerna init
: Create a new Lerna repo or upgrade an existing repo to the current version of Lerna.lerna create
: Create a new lerna-managed package.lerna import
: Import a package into the monorepo with commit history.lerna list
: List local packages.lerna boostrap
: Installs all dependencies and links any cross-dependencies, likenpm install
.lerna add
: Add local or remote package as dependency to packages in the current Lerna repo, likenpm install <package>
.lerna link
: Symlink together all packages that are dependencies of each other, linknpm link
.lerna clean
: Remove the node_modules directory from all packages.lerna version
: Bump version of packages changed since the last release.lerna publish
: Publish packages in the current project.Overall, Lerna is a solution with complete functionality coverage, but there is no silver bullet in software. Therefore, the existing defects of Lerna will be summarized later, especially for this project.
Workspaces
Workspaces is an inherent feature of mainstream PMT(Package Management Tool). It's mainly developed by the natural advantages of package management tools in dependency management.
It has an unparalleled advantage in dependency management, and because it's a inherent feature of PMT, it tends to have no additional mental cost.
This is a survey of Workspaces for mainstream PMT, ranked from top to bottom, good to bad, so it's obvious which one to choose :)
pnpm-workspace.yml
fileworkspaces
inpackages.json
nohoist
When we consider the Workspaces feature of a PMT as a solution, we also need to consider whether the solution is qualified or useful as a PMT. β Overall, Workspaces can solve all the existing problems in Dependencies Management, while workflow needs to be done in other ways.
Summary
As mentioned above, Lerna has complete functionality, Workspaces only solves the dependencies management problem well. So why do I still insist on replacing Lerna with PNPM Workspaces? β First, Lerna's Packages Management features are not needed. Second, Lerna's Dependencies Management features are completely covered by Workspaces and can do better. Third, Lerna's Release Workflow features are simple and crude. We wanted more flexibility, extensibility, stability, certainty from Release Workflow and Lerna didn't allow us to do it better.
In short, Lerna has some features that are not needed or are difficult to use and can impose additional mental cost, even if the PNPM Workspaces is not complete, it is sufficient for this project, and it is small and easy to use, with no additional burden.
Final Todo
References
RFC & PTAL: @sskyy