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
Detecting which packages have changed since a given reference for selective operations.
List packages that have changed since the last release or specified reference.
# List changed packages since last release
lerna changed
lerna updated # Alias for 'changed'
# List changed packages since specific ref
lerna changed --since HEAD~1
lerna changed --since v1.0.0
lerna changed --since origin/main
# Include dependencies of changed packages
lerna changed --include-dependencies
# Include dependents of changed packages
lerna changed --include-dependents
# Include packages from merged tags
lerna changed --include-merged-tags
# Output formats
lerna changed --json # JSON array
lerna changed --ndjson # Newline-delimited JSON
lerna changed --parseable # Parseable format
lerna changed --long # Extended information
# Filtering
lerna changed --scope="@myorg/*" # Include only matching packages
lerna changed --ignore="*-test" # Exclude matching packages
lerna changed --no-private # Exclude private packages
lerna changed --all # Include all packagesShow git diff for packages that have changed since the last release.
# Show diff for all changed packages
lerna diff
# Show diff for specific package
lerna diff package-name
# Show diff since specific reference
lerna diff --since HEAD~1
lerna diff --since v1.0.0
# Show diff for specific package since reference
lerna diff package-name --since origin/mainDiff command:
git diff on packages that have changedlerna changed but shows actual file differenceslerna changedLerna detects changes using git diff between:
--sinceDetection includes:
# Commit references
lerna changed --since HEAD~3
lerna changed --since abc1234
# Branch references
lerna changed --since origin/main
lerna changed --since feature/new-api
# Tag references
lerna changed --since v1.0.0
lerna changed --since latest
# Time-based references
lerna changed --since "2 weeks ago"
lerna changed --since "2023-01-01"Include packages based on their relationships:
# Include dependencies (packages that changed packages depend on)
lerna changed --include-dependencies
# Include dependents (packages that depend on changed packages)
lerna changed --include-dependents
# Include both dependencies and dependents
lerna changed --include-dependencies --include-dependentsExample scenario:
--include-dependents includes Package A (depends on changed B)--include-dependencies includes Package B's dependencies# Include packages affected by merged pull requests
lerna changed --include-merged-tags
# Useful for CI/CD after merging features
lerna changed --since origin/main --include-merged-tagsThis option is particularly useful when:
# Force include all packages (ignore change detection)
lerna changed --force-publish
# Force include specific packages
lerna changed --force-publish package-a,package-b
# Force include packages matching pattern
lerna changed --force-publish "@myorg/*"# JSON array format
lerna changed --json
# ["package-a", "package-b", "package-c"]
# Newline-delimited JSON
lerna changed --ndjson
# "package-a"
# "package-b"
# "package-c"# Show version and location
lerna changed --long
# package-a v1.2.3 packages/package-a
# package-b v0.5.1 packages/package-b
# Parseable output (machine-readable)
lerna changed --parseable
# /path/to/workspace/packages/package-a:package-a:1.2.3
# /path/to/workspace/packages/package-b:package-b:0.5.1# Run tests only on changed packages
lerna run test --since HEAD~1
# Build changed packages and their dependents
lerna run build --since v1.0.0 --include-dependents# Publish only changed packages
lerna publish --since HEAD~1
# Version only changed packages
lerna version --since v1.0.0# Execute command only in changed packages
lerna exec --since HEAD~1 -- rm -rf node_modules
# List only changed packages
lerna list --since origin/mainConfigure default reference in lerna.json:
{
"command": {
"changed": {
"since": "origin/main",
"includeDependents": true
}
}
}Ignore specific files/directories for change detection:
{
"command": {
"changed": {
"ignoreChanges": [
"**/*.md",
"**/test/**",
"**/*.test.js"
]
}
}
}Ignore patterns:
**/*.md - Ignore all markdown files**/test/** - Ignore test directories**/__tests__/** - Ignore Jest test directories**/stories/** - Ignore Storybook files**/*.test.{js,ts} - Ignore test files- name: Check for changes
id: changes
run: |
if lerna changed --since origin/main; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Run tests on changed packages
if: steps.changes.outputs.changed == 'true'
run: lerna run test --since origin/main# Exit with code 1 if no changes (useful for CI)
lerna changed --since origin/main || exit 1
# Store changed packages for later use
CHANGED_PACKAGES=$(lerna changed --since HEAD~1 --json)
echo "Changed packages: $CHANGED_PACKAGES"Common causes and solutions:
# Verify git history
git log --oneline --graph
# Check for uncommitted changes
git status
# Verify package locations match lerna.json
lerna list --all
# Check ignore patterns
lerna changed --since HEAD~1 --loglevel verbose# Add ignore patterns for non-functional changes
lerna changed --ignore-changes "**/*.md" --ignore-changes "**/test/**"
# Use specific since reference
lerna changed --since $(git describe --tags --abbrev=0)