Skip to content
Latchkey

How to Publish Only the Changed Packages in a Monorepo

The reliable signal for what to publish is a version diff: publish a package only when its local version is not already on the registry.

Rather than diffing files, most monorepo tools decide what to publish by comparing the local package.json version to the latest published version. Changesets, pnpm, Lerna from-git, and Rush all follow this version-diff rule.

How each tool decides

ToolWhat it publishes
changeset publishPackages whose version is ahead of the registry
pnpm publish -rPackages with a version not yet published
lerna publish from-gitVersions matching git tags just created
rush publishProjects whose version increased via change files

Manual guard

Terminal
# Skip publish if this version is already on the registry
NAME=$(node -p "require('./package.json').name")
VER=$(node -p "require('./package.json').version")
if npm view "$NAME@$VER" version >/dev/null 2>&1; then
  echo "$NAME@$VER already published, skipping"
else
  npm publish --access public
fi

Gotchas

  • Version-diff publishing is idempotent, so a re-run after a partial failure only publishes what is still missing.
  • Do not gate publish on changed files alone; a dependency bump can require publishing a package whose own files did not change.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →