Yarn Berry

rm -rf ./**/node_modules

What is Yarn?

Yarn is an alternative package manager to npm. It's been around since 2016.

Yarn's claim to fame is stability. It aims to have a deterministic installation; given a yarn.lock file, Yarn will always create the some node_modules tree.

We use Yarn in the monorepo!

What is Yarn Berry?

Yarn Berry is the codename for a complete rewrite of the Yarn codebase that started two years ago.

All new versions of Yarn (the latest is 3.1.0) live in the yarnpkg/berry GitHub repo.

In addition to PnP-by-default, the new Yarn architecture is composed of small modules with intentional API surfaces. It also includes a plugin framework that can make use of these new modules.

Oh, also

You check it in to your repo!

Why should I migrate off of Yarn v1?

New plugin API allows for really awesome new workflows, PnP improves performance and stability, and Zero-Installs improve development experience and CI performance.

Also... Yarn v1 is deprecated and will not receive any future updates!

What do I get out of it?

A bunch of stuff! But first we need to explain some things we've been glossing over.

Plug'n'Play

It should be the package manager's job to inform the interpreter about the location of the packages on the disk and manage any dependencies between packages

Zero-Installs

Make your projects as stable and fast as possible by removing the main source of entropy from the equation: Yarn itself.

What does that actually get us, practically?

  1. Dramatically reduced install time in CI. git clone takes an extra 15 or 20 seconds, and that's... it. Nothing else needs to be downloaded or written to disk. This led to a 4-minute+ decrease in build time for Oak.
  2. Switching branches? That's all you need to do. No need to run yarn install, yarn clean, rm -rf ./**/node_modules, what have you.
  3. Yarn will now tell you if your packages attempt to import modules they don't declare a dependency on.
  4. Real plugins! Have a thing you wished Yarn did for you? Now you can add support for that thing!

Ok, ok. But how?

  1. .npmrc.yarnrc.yml
  2. Janky freeze-workspace script → yarn-plugin-isolate-workspace
  3. New workspace: protocol
  4. Install and set up Git LFS for .cache/*.zip
  5. Install the Yarn SDKs for your editor
  6. Run yarn install and fix missing dependencies in your packageExtensions configuration. Repeat this ad nauseam until Yarn stops complaining.