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
Core package discovery and workspace management functionality for identifying and working with packages in a monorepo.
Automatically detects and returns all packages in the workspace.
/**
* Detects and returns project graph and file mapping for the workspace
* @param rootDir - Root directory to search (defaults to workspace root)
* @returns Promise resolving to project graph and file map
*/
function detectProjects(rootDir?: string): Promise<{
projectGraph: ProjectGraphWithPackages;
projectFileMap: ProjectFileMap;
}>;Usage Example:
import { detectProjects } from "lerna/utils";
// Detect all packages in current workspace
const { projectGraph, projectFileMap } = await detectProjects();
// Detect packages from specific directory
const { projectGraph, projectFileMap } = await detectProjects("/path/to/workspace");
// Get package names from project graph
const packageNames = Object.values(projectGraph.nodes)
.filter(node => node.package)
.map(node => node.package!.name);
console.log(packageNames);Display all packages in the workspace with various formatting options.
# List all packages
lerna list
lerna ls # Alias for 'list'
lerna la # Alias for 'list --all'
lerna ll # Alias for 'list --long'
# List packages with additional information
lerna list --long
# List packages as JSON
lerna list --json
# List only changed packages
lerna list --since HEAD~1
# List packages in specific scope
lerna list --scope="@myorg/*"
# List packages excluding specific scope
lerna list --ignore="@myorg/internal-*"The lerna list command supports the following options:
--json - Output as JSON array--ndjson - Output as newline-delimited JSON--long - Show extended information (version, location)--parseable - Show parseable output (similar to npm ls --parseable)--toposort - Sort packages in topological order--graph - Show dependency graph--all - Include private packages (default behavior)--since <ref> - List packages changed since ref--scope <glob> - Include packages matching glob--ignore <glob> - Exclude packages matching globRemove node_modules directories from all packages.
# Remove node_modules from all packages
lerna clean
# Remove node_modules with confirmation prompt
lerna clean --yesUsage Example:
# Clean all packages and confirm deletion
lerna clean
# Clean all packages without confirmation
lerna clean --yes
# Clean specific scoped packages
lerna clean --scope="@myorg/*"interface Package {
/** Package name from package.json */
name: string;
/** Package version from package.json */
version: string;
/** Absolute path to package directory */
location: string;
/** Whether package is marked as private */
private?: boolean;
/** npm scripts defined in package.json */
scripts?: Record<string, string>;
/** Production dependencies */
dependencies?: Record<string, string>;
/** Development dependencies */
devDependencies?: Record<string, string>;
/** Peer dependencies */
peerDependencies?: Record<string, string>;
/** Optional dependencies */
optionalDependencies?: Record<string, string>;
/** Bundled dependencies */
bundleDependencies?: string[];
/** Package.json contents */
toJSON(): PackageJson;
/** Get package manifest */
get(key: string): any;
/** Set package manifest property */
set(key: string, value: any): void;
}
interface PackageJson {
name: string;
version: string;
description?: string;
main?: string;
scripts?: Record<string, string>;
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
[key: string]: any;
}Lerna provides powerful filtering capabilities that work across most commands:
# Include packages matching pattern
--scope="pattern"
# Multiple scope patterns
--scope="@myorg/*" --scope="utilities-*"
# Exclude packages matching pattern
--ignore="pattern"
# Multiple ignore patterns
--ignore="@myorg/internal-*" --ignore="*-test"# Only packages changed since ref
--since="HEAD~1"
--since="v1.0.0"
--since="main"
# Include dependencies of changed packages
--include-dependents
# Include dependencies that changed packages depend on
--include-dependencies
# Include packages affected by changes (both directions)
--include-merged-tags# Exclude private packages (private: true in package.json)
--no-private
# Include only private packages
--private