or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

change-detection.mdconfiguration.mdindex.mdpackage-management.mdpackage-operations.mdpublishing.mdscript-execution.mdversion-management.md
tile.json

tessl/npm-lerna

Lerna is a fast, modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lerna@8.2.x

To install, run

npx @tessl/cli install tessl/npm-lerna@8.2.0

index.mddocs/

Lerna

Lerna 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.

Package Information

  • Package Name: lerna
  • Package Type: npm
  • Language: TypeScript/JavaScript
  • Installation: npm install lerna
  • CLI Binary: lerna

Core Imports

import { detectProjects } from "lerna/utils";

For CommonJS:

const { detectProjects } = require("lerna/utils");

Basic Usage

# 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 changed

Architecture

Lerna is built around several key components:

  • CLI Interface: Primary interaction point providing all commands via lerna <command>
  • Command System: Modular commands for different aspects of monorepo management
  • Package Discovery: Automatic detection and management of packages within the workspace
  • Nx Integration: Optional integration with Nx for enhanced caching and task orchestration
  • Git Integration: Deep integration with git for change detection and version management
  • npm Integration: Publishing, versioning, and dependency management with npm registry

Capabilities

Package Management

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;
}>;

Package Management

Version Management

Automated versioning of packages with conventional commits, git tagging, and changelog generation.

lerna version [version]
lerna version --conventional-commits
lerna version --create-release github

Version Management

Publishing

Publishing packages to npm registry with coordinated releases and access verification.

lerna publish
lerna publish from-git
lerna publish from-package

Publishing

Script Execution

Running npm scripts across packages with dependency-aware execution and caching.

lerna run <script>
lerna run <script> --scope=<package>
lerna run <script> --since=<ref>

Script Execution

Change Detection

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>

Change Detection

Package Operations

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>

Package Operations

Workspace Configuration

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 info

Configuration

Core Types

interface 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;
}