Lerna is the original JavaScript monorepo tool, now maintained by Nx. It handles versioning, publishing, and task running for multi-package repositories.
Getting Started
npx lerna init
lerna.json Configuration
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "independent",
"npmClient": "pnpm",
"useWorkspaces": true
}
Running Commands Across Packages
# Run build in all packages (topological order)
lerna run build
# Run tests in parallel
lerna run test --parallel
# Run only in specific packages
lerna run build --scope=@myorg/core --scope=@myorg/utils
# Run in changed packages only
lerna run build --since=main
Versioning
# Independent versioning — each package versioned separately
lerna version --conventional-commits
# Fixed versioning — all packages share same version
lerna version patch
# Preview changes without committing
lerna version --no-push --no-git-tag-version
# See what changed
lerna changed
lerna diff
Publishing to npm
# Publish all changed packages
lerna publish
# Publish from Git tags
lerna publish from-git
# Publish pre-release
lerna publish --canary
# Dry run
lerna publish --no-push
Package Listing and Filtering
# List all packages
lerna ls
# List with details
lerna ls -l
# List changed packages
lerna changed
# Show dependency graph
lerna ls --graph --all
Task Caching (with Nx)
Since Lerna 6+, Nx powers task execution. This means free computation caching:
// nx.json
{
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": ["build", "test", "lint"]
}
}
}
}
Need to extract or automate web content at scale? Check out my web scraping tools on Apify — no coding required. Or email me at spinov001@gmail.com for custom solutions.
Top comments (0)