Lerna is a fast, modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository
npx @tessl/cli install tessl/npm-lerna@8.2.0Lerna is a fast, modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository. It provides tools for workspace management, dependency linking, selective building and testing of changed packages, automated versioning with conventional commits, coordinated publishing to npm registry, and distributed task execution with Nx integration.
npm install lernalernaimport { detectProjects } from "lerna/utils";For CommonJS:
const { detectProjects } = require("lerna/utils");# Initialize a new Lerna workspace
lerna init
# Bootstrap workspace and install dependencies
npm install
# List all packages in the workspace
lerna list
# Run npm scripts across all packages
lerna run build
# Publish changed packages to npm
lerna publish
# Show which packages have changed
lerna changedLerna is built around several key components:
lerna <command>Core package discovery and workspace management functionality for identifying and working with packages in a monorepo.
function detectProjects(rootDir?: string): Promise<{
projectGraph: ProjectGraphWithPackages;
projectFileMap: ProjectFileMap;
}>;Automated versioning of packages with conventional commits, git tagging, and changelog generation.
lerna version [version]
lerna version --conventional-commits
lerna version --create-release githubPublishing packages to npm registry with coordinated releases and access verification.
lerna publish
lerna publish from-git
lerna publish from-packageRunning npm scripts across packages with dependency-aware execution and caching.
lerna run <script>
lerna run <script> --scope=<package>
lerna run <script> --since=<ref>Detecting which packages have changed since a given reference for selective operations.
lerna changed
lerna changed --since=<ref>
lerna diff [package]
lerna diff --since=<ref>Executing arbitrary commands across packages and managing package relationships.
lerna exec <command>
lerna exec <command> --scope=<package>
lerna clean
lerna import <path-to-external-repository>Interactive configuration and optimization tools for monorepo setup and package creation.
lerna init
lerna create <name> [location]
lerna add-caching
lerna repair
lerna watch -- <command>
lerna infointerface Package {
name: string;
version: string;
location: string;
private?: boolean;
scripts?: Record<string, string>;
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
optionalDependencies?: Record<string, string>;
bundleDependencies?: string[];
bin?: string | Record<string, string>;
binLocation?: string;
manifestLocation: string;
nodeModulesLocation: string;
contents: string;
/** Convert package to JSON representation */
toJSON(): PackageJson;
/** Get package manifest property */
get(key: string): any;
/** Set package manifest property */
set(key: string, value: any): void;
}
interface LernaConfig {
version?: string;
packages?: string[];
useNx?: boolean;
npmClient?: string;
registry?: string;
command?: {
publish?: PublishConfig;
version?: VersionConfig;
bootstrap?: BootstrapConfig;
};
}
interface PublishConfig {
registry?: string;
access?: 'public' | 'restricted';
message?: string;
conventionalCommits?: boolean;
yes?: boolean;
distTag?: string;
}
interface VersionConfig {
allowBranch?: string | string[];
conventionalCommits?: boolean;
message?: string;
push?: boolean;
createRelease?: 'github' | 'gitlab';
}
interface BootstrapConfig {
npmClientArgs?: string[];
hoist?: boolean | string[];
nohoist?: string[];
ignore?: string[];
}
interface ProjectGraphWithPackages {
nodes: Record<string, ProjectGraphProjectNodeWithPackage>;
dependencies: Record<string, ProjectGraphDependency[]>;
localPackageDependencies: Record<string, ProjectGraphWorkspacePackageDependency[]>;
}
interface ProjectFileMap {
[projectName: string]: ProjectFileMapProjectFiles;
}
interface ProjectGraphProjectNodeWithPackage {
name: string;
type: string;
data: {
root: string;
sourceRoot?: string;
};
package: Package | null;
}
interface PackageJson {
name: string;
version: string;
description?: string;
main?: string;
bin?: string | Record<string, string>;
scripts?: Record<string, string>;
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
optionalDependencies?: Record<string, string>;
bundleDependencies?: string[];
private?: boolean;
workspaces?: string[] | { packages: string[]; nohoist?: string[] };
[key: string]: any;
}