I have a repository with a bunch of different front-end React projects, which all have package.json files of their own.
I have four requrements:
- I want to keep all of these projects on the same dependency track. (ie, I want all my projects to use the same versions of each npm package)
- I want to be able to update every package.json to their latest version, with one "global" command.
- Ideally, I'd like to use some sort of proven open-source tool like Yarn Workspaces or Lerna, instead of managing this all myself with a global package.json file.
- I'm using the Yarn ecosystem.
These packages do not need to run concurrently. Not every project contains the same exact dependencies, but all contain at least a few common dependencies (ie React, Webpack, Babel, etc). These packages are also entirely private and should not be published on npm, only on GitHub.
I've done some research into the tooling and am confused about if Yarn Workspaces alone is the solution, or if Lerna is necessary. Here's what I've done so far in Yarn Workspaces:
Folder structure:
Repo-root
Packages
Project-1
Project-2
Repo root package.json:
{
"private": true,
"name": "example-monorepo",
"workspaces": ["packages/*"],
"scripts": {}
}
I understand that Yarn Workspaces tries to move all common dependencies to the root node_modules behind-the-scenes, but I'm confused about how to accomplish the shared dependency installation and updating to the latest versions requirement. Can Yarn Workspaces accomplish the requirements on its own, or is Lerna necessary for this? How would this be accomplished in Lerna? Do I need to define a global package.json "single source of truth", or do the tools do some version of it themselves behind the scenes? How does Lerna or Yarn Workspaces "know" how to update all the individual package.json files to their latest versions without a global set of version ranges? (which I want to be the same for all projects)