Lerna is a fast, modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Running npm scripts across packages with dependency-aware execution and caching.
Execute npm scripts across multiple packages with intelligent dependency handling.
# Run script in all packages that have it
lerna run <script>
# Run specific script examples
lerna run test
lerna run build
lerna run lint
lerna run start
# Run script in specific packages
lerna run test --scope=package-name
lerna run build --scope="@myorg/*"
# Run script in changed packages only
lerna run test --since HEAD~1
lerna run build --since v1.0.0
# Run script with parallel execution
lerna run test --parallel
# Run script with streaming output
lerna run test --stream
# Run script in topological order (dependencies first)
lerna run build --sort
# Ignore script failures and continue
lerna run test --no-bail
# Include dependencies/dependents
lerna run build --include-dependencies
lerna run test --include-dependents
# Pass arguments to scripts
lerna run test -- --coverage
lerna run build -- --minify --sourcemap
# Run multiple scripts concurrently (comma-separated)
lerna run "lint,test,build"
lerna run "test,lint" --parallel# Execution control
--parallel # Run scripts in parallel (ignores concurrency)
--stream # Stream output immediately (implies --parallel)
--no-sort # Don't run in topological order
--concurrency <n> # Maximum number of concurrent processes
--bail # Stop on first script failure (default)
--no-bail # Continue despite script failures
# Output control
--silent # Suppress script output
--loglevel <level> # Set log level (silent, error, warn, notice, http, timing, info, verbose, silly)
--no-prefix # Do not prefix streaming output
--npm-client <cmd> # Executable used to run scripts (npm, yarn, pnpm, etc.)
# Package filtering
--scope <glob> # Include packages matching glob
--ignore <glob> # Exclude packages matching glob
--since <ref> # Include packages changed since ref
--include-dependencies # Include dependencies of matched packages
--include-dependents # Include dependents of matched packages
--include-merged-tags # Include packages from merged tags
# Nx integration (when useNx: true)
--skip-nx-cache # Skip Nx caching
--nx-bail # Stop on first Nx task failure
--nx-ignore-cycles # Ignore dependency cycles in Nx# Run scripts in parallel
lerna run build --parallel
# Control concurrency
lerna run test --concurrency 4
# Stream output for better feedback
lerna run start --streamParallel execution:
--stream for real-time outputSequential execution (default):
When useNx: true in lerna.json, script execution uses Nx task runner:
# Nx-powered script execution with caching
lerna run build
# Skip Nx cache
lerna run build --skip-nx-cache
# Nx task configuration via nx.json
lerna run build --with-deps # Uses Nx dependency detectionNx benefits:
Define scripts in package.json:
{
"scripts": {
"build": "tsc",
"test": "jest",
"lint": "eslint src/",
"start": "node dist/index.js",
"clean": "rimraf dist/"
}
}Run scripts across the workspace:
# Run build in all packages that have it
lerna run build
# Packages without the script are skipped automatically
lerna run nonexistent-script # Runs successfully, skips packagesFor dependent builds, use topological ordering:
# Build dependencies first, then dependents
lerna run build --sort
# Equivalent: (default behavior unless --parallel)
lerna run build# Run only in packages with changes
lerna run build --since origin/main
# Run in packages with specific dependency
lerna run integration-test --scope="*api*"
# Run excluding test packages
lerna run build --ignore="*-test" --ignore="test-*"Pass arguments to underlying scripts:
# Pass coverage flag to test script
lerna run test -- --coverage --reporter=lcov
# Pass multiple arguments
lerna run build -- --minify --sourcemap --verbose
# Environment-specific builds
lerna run build -- --env=production --optimize# Stop on first failure (default)
lerna run test --bail
# Continue despite failures
lerna run test --no-bail
# Combine with reporting
lerna run test --no-bail --stream > test-results.log# Suppress script output
lerna run build --silent
# Stream output for long-running processes
lerna run start --stream
# Control log levels
lerna run build --loglevel=error # Only show errors
lerna run test --loglevel=verbose # Show detailed outputConfigure nx.json for optimal caching:
{
"targetDefaults": {
"build": {
"dependsOn": ["^build"],
"cache": true,
"outputs": ["{projectRoot}/dist"]
},
"test": {
"cache": true,
"outputs": ["{projectRoot}/coverage"]
}
}
}# Optimize for CPU cores
lerna run build --concurrency $(nproc)
# Conservative concurrency for memory-intensive tasks
lerna run test --concurrency 2
# Maximum parallelism for independent tasks
lerna run lint --parallel# Only build changed packages and their dependents
lerna run build --since HEAD~1 --include-dependents
# Test only packages with changes
lerna run test --since origin/main
# Build only public packages
lerna run build --no-private