lerna
Manage JavaScript projects with multiple packages
TLDR
Initialize project files (lerna.json, package.json, .git, etc.)
Install all external dependencies of each package and symlink together local dependencies
Run a specific script for every package that contains it in its package.json
Execute an arbitrary shell command in every package
Publish all packages that have changed since the last release
SYNOPSIS
lerna command [options]
PARAMETERS
--version
Show version number
--help
Show help for command
--loglevel level
Control logging verbosity. level can be: silent, error, warn, info, verbose, silly, debug
--concurrency number
Maximum number of concurrent tasks (default: CPUs + 1)
--reject-cycles
Fail immediately if dependency cycles are detected
--no-private
Omit private packages from command execution
--scope glob
Include only packages matching the given glob
--ignore glob
Exclude packages matching the given glob
--use-nx
Enables Nx integration and incremental builds
--profile
Captures performance trace
DESCRIPTION
Lerna is a tool for managing JavaScript projects with multiple packages. It optimizes the workflow around managing multi-package repositories (monorepos) with git and npm. Lerna allows you to manage dependencies across multiple packages within a single repository, streamline releases, and automate common tasks like versioning and publishing.
It's particularly useful for projects where you want to share code between multiple npm packages or maintain a cohesive ecosystem of interdependent libraries. By providing a centralized toolchain, Lerna simplifies the development and maintenance of complex JavaScript projects. It helps with tasks such as dependency management, versioning, and publishing multiple packages simultaneously, ensuring consistency and reducing the potential for errors.
CAVEATS
Lerna requires a good understanding of monorepo architecture and npm package management. Configuration is crucial for optimal performance.
<B>COMMON LERNA COMMANDS</B>
Some of the most frequently used Lerna commands include:
lerna init: Initializes a new Lerna repository.
lerna bootstrap: Installs dependencies and links packages within the monorepo.
lerna publish: Publishes updated packages to npm.
lerna run: Runs npm scripts across packages.
lerna changed: Lists packages that have changed since the last release.
<B>CONFIGURATION</B>
Lerna is configured via a lerna.json file at the root of the repository. This file defines various settings, including package locations, versioning strategy, and command-specific options. The package.json files in each package directory also play a crucial role in defining dependencies and scripts.
HISTORY
Lerna was originally created by the team at Babel to manage their large monorepo. It gained popularity as a tool for other projects adopting similar architectures and has been actively maintained by the open-source community.