This is an alpha, sneak peek of Monorepo Maestros. For this iteration, I'm getting all of my thoughts down. In the future, we'll have better information architecture, graphics, and other awesomeness. Your feedback is welcome!

Yarn

yarn was the second package manager to be made after npm. Yarn introduced many innovations at the time including native monorepo support, caching, and lock files.

The first version of Yarn, now known as Yarn Classic, works similar to npm, installing bundled versions of package source code. But the second version of Yarn introduced a strategy called "Plug 'n' Play" as an effort to reduce installation times and use less desk space compared to node_modules.

Yarn Classic

Setting up workspaces

To create your workspaces, you'll need a workspaces field in your package.json:

package.json
{
"name": "my-repo",
"private": true,
"scripts": { ... },
"devDependencies": { ... },
"packageManager": "yarn@1.22.15", // Needed for Turborepo
"workspaces": ["apps/*", "packages/*"]
}
package.json
{
"name": "my-repo",
"private": true,
"scripts": { ... },
"devDependencies": { ... },
"packageManager": "yarn@1.22.15", // Needed for Turborepo
"workspaces": ["apps/*", "packages/*"]
}

Now, any directory in your apps and packages directories that contains a package.json will be treated as a workspace.

  • package.json
  • package-lock.json
  • apps
    • docs (Workspace!)
    • web (Workspace!)
  • packages
    • logger (Workspace!)
    • ui (Workspace!)
  • Tips and tricks

    Interact with a specific workspace

    You can run Yarn commands on a specific workspace using the --workspace command (or -w, for short).

    Terminal
    yarn add react -w ui
    Terminal
    yarn add react -w ui

    This will install React to a workspace with the "name": "ui" in its package.json.

    Figure out where a package is being installed

    Package dependencies trees can be hard to debug. Sometimes, you just want to figure out what a package is in your repository in the first place.

    Terminal
    yarn why react
    Terminal
    yarn why react

    This command will show you everywhere in your dependency tree where react is being brought in and why.

    Yarn Berry

    This music is still being written...