Skip to content
Latchkey

yarn workspaces in CI

Yarn workspaces manage a monorepo of packages from one install.

In CI you often build or test every workspace, or just the ones that changed. Yarn Berry adds the foreach plugin for this.

Common usage

  • yarn workspaces list - list packages
  • yarn workspaces foreach -pt run build - parallel topological build
  • yarn workspace <name> <script> - one package

Example in CI

Build all workspaces in dependency order.

shell
yarn workspaces foreach -pt run build

In CI

foreach needs the workspace-tools plugin in Berry. For heavy monorepos, faster managed runners cut total build time noticeably.

Key takeaways

  • foreach -pt builds in parallel, topologically.
  • yarn workspace <name> targets one package.
  • Berry needs the workspace-tools plugin.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →