Talk Notes: Releasing Many Packages From One Repository

A monorepo makes it easy to change five packages in one pull request. It also makes it easy to release five packages in the wrong order, with the wrong versions, pointing at each other with ranges that no longer exist on the registry. These are notes from a talk on getting monorepo releases under control. They are written up in full; there is no video or event to attend.

Agenda

Choosing a versioning model

Fixed (lockstep)Independent
How it worksEvery package shares one version numberEach package bumps on its own changes
StrengthUsers know which versions go togetherNo meaningless bumps for untouched packages
WeaknessA fix in one package bumps all of themUsers need a compatibility table
FitsTightly coupled families such as a framework and its official pluginsLoosely related utilities sharing tooling

The point made in the talk: choose consciously and write it in the contributing guide. Mixed, accidental policies are the real problem.

Internal dependency ranges

Inside the repo, package P depends on package Q. You want local development to use the working copy of Q, but the published P must depend on a real published Q version. pnpm and Yarn support a workspace: protocol for this, and replace it with a concrete range when packing:

// packages/p/package.json (in the repo)
"dependencies": {
  "@example-org/q": "workspace:^"
}

// what the published tarball contains
"dependencies": {
  "@example-org/q": "^2.4.0"
}

npm workspaces link local packages too, but you write normal ranges and must keep them current yourself. Whichever manager you use, inspect a packed tarball at least once to see what consumers will receive.

Publishing in order

  1. Compute the internal dependency graph.
  2. Publish dependencies before dependents: packages that others in the batch rely on go first, and packages nothing else depends on go last.
  3. If a publish fails midway, stop. Re-running should skip versions that already exist rather than failing the whole batch.

Release tools built for monorepos, Changesets being a widely used example in JavaScript, do the graph sorting and the version bumping for you. Their main contribution is forcing each pull request to state which packages it affects and how.

Changelogs per package

A single root changelog quickly becomes useless to someone who only installs one package. Keep a CHANGELOG.md in each package directory, generated from the same change notes. When a package is bumped only because a dependency changed, say so in one line, so readers do not hunt for a change that is not there.

Notes for Go and Rust

Audience questions

Can we release only what changed?

Yes, with independent versioning. Make sure "changed" includes changes to shared build config that alter the output.

Should private internal packages live in the same workspace?

That is fine; mark them "private": true so a publish command can never send them to a registry.

How do we preview a release?

Many teams publish snapshot versions to a pre-release tag such as next from the release branch. Users opt in with npm install pkg@next, and the latest tag is untouched.

If your packages are scoped, the scoped packages session notes cover access and registry setup, and the release pipeline diagrams show where these steps sit.

Related pages

An independent site with articles and free browser tools about building, evaluating, licensing and pricing reusable code modules. Informational only; nothing is sold on this site. Disclaimer