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
Executing arbitrary commands across packages and managing package relationships.
Run arbitrary commands across packages with flexible filtering and execution options.
# Execute command in all packages
lerna exec -- <command>
# Execute specific commands
lerna exec -- rm -rf node_modules
lerna exec -- npm audit fix
lerna exec -- git status
lerna exec -- ls -la
# Execute with package filtering
lerna exec --scope="@myorg/*" -- npm run build
lerna exec --ignore="*-test" -- npm install
lerna exec --since HEAD~1 -- npm test
# Execute in parallel
lerna exec --parallel -- npm run lint
# Execute with streaming output
lerna exec --stream -- npm run start
# Execute in specific directory
lerna exec --scope=package-name -- npm run dev
# Pass environment variables
lerna exec -- env NODE_ENV=production npm run build# Execution control
--parallel # Execute in parallel across packages
--stream # Stream output immediately
--concurrency <n> # Limit concurrent processes
--bail # Stop on first command failure (default)
--no-bail # Continue despite command failures
--no-prefix # Do not prefix streaming output
--profile # Profile command executions and output performance data
--profile-location # Output performance profile to custom location
# 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
--include-dependents # Include dependents
--no-private # Exclude private packages
# Output control
--silent # Suppress command output
--loglevel <level> # Control log verbosityRemove node_modules directories from all packages.
# Remove node_modules from all packages
lerna clean
# Clean with confirmation
lerna clean --yes
# Clean specific packages
lerna clean --scope="@myorg/*"
lerna clean --ignore="core-*"
# Clean changed packages only
lerna clean --since HEAD~1Clean operation:
node_modules directories from all packagesnode_modules (workspace dependencies)--yes is usedImport an external package repository into the monorepo with full commit history.
# Import external repository
lerna import <path-to-external-repository>
# Import with options
lerna import /path/to/external-repo --flatten
lerna import /path/to/external-repo --max-buffer=1048576
# Import examples
lerna import ../my-existing-package
lerna import ~/projects/standalone-libraryImport operation:
packages/<directory-name>/ structureImport options:
--flatten - Import history in "flat" mode (single level)--max-buffer=<size> - Increase buffer size for large repositories--dest=<directory> - Specify destination directory name# Development environment setup
lerna exec -- npm run setup:dev
# Production builds
lerna exec --parallel -- npm run build:prod
# Environment-specific installs
lerna exec -- npm install --production# Remove build artifacts
lerna exec -- rm -rf dist/ build/ lib/
# Copy configuration files
lerna exec -- cp ../shared/.eslintrc.js .
# Create directories
lerna exec -- mkdir -p dist/assets
# Archive packages
lerna exec -- tar -czf "../archive/${PWD##*/}.tar.gz" .# Update dependencies
lerna exec -- npm update
# Audit and fix vulnerabilities
lerna exec -- npm audit fix
# Clean and reinstall
lerna clean --yes && npm install
# Update package metadata
lerna exec -- npm pkg set engines.node=">=18"# Check git status across packages
lerna exec -- git status --porcelain
# Add git hooks
lerna exec -- cp ../shared/pre-commit .git/hooks/
# Reset git state
lerna exec -- git reset --hard HEAD
# Apply git patches
lerna exec -- git apply ../patches/${PWD##*/}.patchCommands executed via lerna exec have access to:
$LERNA_PACKAGE_NAME - Current package name$LERNA_ROOT_PATH - Path to workspace root$PWD - Current package directory# Use package name in command
lerna exec -- echo "Building $LERNA_PACKAGE_NAME"
# Reference workspace root
lerna exec -- cp "$LERNA_ROOT_PATH/shared/config.js" ./
# Package-specific operations
lerna exec -- mkdir -p "$LERNA_ROOT_PATH/dist/$LERNA_PACKAGE_NAME"Commands execute in each package's root directory:
# Current directory is package root
lerna exec -- pwd
# /workspace/packages/package-a
# /workspace/packages/package-b
# Access package.json
lerna exec -- cat package.json
# Access source files
lerna exec -- ls src/# Include packages by pattern
lerna exec --scope="@myorg/*" -- npm run build
lerna exec --scope="*-api" -- npm test
lerna exec --scope="frontend-*" -- npm run lint
# Exclude packages by pattern
lerna exec --ignore="*-test" -- npm run build
lerna exec --ignore="@internal/*" -- npm publish
# Multiple patterns
lerna exec --scope="@myorg/*" --ignore="*-test" -- npm run validate# Execute only in changed packages
lerna exec --since HEAD~1 -- npm run build
# Include dependencies of changed packages
lerna exec --since v1.0.0 --include-dependencies -- npm test
# Include dependents of changed packages
lerna exec --since origin/main --include-dependents -- npm run build# Execute only in public packages
lerna exec --no-private -- npm publish
# Execute only in private packages
lerna exec --private -- npm run internal-check# Maximum parallelism
lerna exec --parallel -- npm run lint
# Controlled concurrency
lerna exec --concurrency 4 -- npm test
# Stream output for monitoring
lerna exec --parallel --stream -- npm run devUse parallel execution for:
Use sequential execution for:
# Stop on first failure (default)
lerna exec --bail -- npm run build
# Continue despite failures
lerna exec --no-bail -- npm test
# Combine with logging for analysis
lerna exec --no-bail --loglevel=error -- npm audit# Pre-deployment checks
lerna exec --parallel -- npm run lint
lerna exec --since HEAD~1 -- npm test
lerna exec --no-private -- npm run build
# Post-deployment cleanup
lerna exec -- npm prune --production# Setup new development environment
lerna clean --yes
npm install
lerna exec -- npm run setup
# Daily development routine
lerna exec --since HEAD~1 --include-dependents -- npm run build
lerna exec --parallel -- npm run test:watch# Security updates
lerna exec -- npm audit fix --force
# Dependency updates
lerna exec -- npm update
lerna exec -- npm outdated
# Code formatting
lerna exec --parallel -- npm run format
lerna exec --parallel -- npm run lint:fix