lerna
:dragon: Lerna is a fast, modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository.
Top Related Projects
Smart Monorepos · Fast CI
Fast, disk space efficient package manager
📦🐈 Active development trunk for Yarn ⚒
Build system optimized for JavaScript and TypeScript, written in Rust
Monorepo for tools developed by the Rush Stack community
🦋 A way to manage your versioning and changelogs with a focus on monorepos
Quick Overview
Lerna is a tool for managing JavaScript projects with multiple packages, optimizing the workflow of developing and publishing many packages from the same repository (monorepo). It simplifies the process of versioning, publishing, and managing dependencies across multiple packages within a single project.
Pros
- Streamlines version management and publishing for monorepos
- Automates package linking and dependency management
- Provides powerful CLI tools for efficient project management
- Supports both fixed and independent versioning strategies
Cons
- Learning curve for developers new to monorepo structures
- Can be complex to set up and configure for larger projects
- Some users report occasional issues with version bumping
- May be overkill for smaller projects or single-package repositories
Code Examples
- Initialize a Lerna project:
npx lerna init
This command initializes a new Lerna repository, creating the necessary configuration files.
- Add a new package to the project:
npx lerna create my-package
This creates a new package named "my-package" in the packages directory.
- Run a command across all packages:
npx lerna run test
This executes the "test" script in all packages that have it defined in their package.json.
Getting Started
To get started with Lerna, follow these steps:
-
Install Lerna globally:
npm install -g lerna
-
Initialize a new Lerna project:
mkdir my-lerna-project && cd my-lerna-project lerna init
-
Add packages to your project:
lerna create package-1 lerna create package-2
-
Install dependencies and link packages:
lerna bootstrap
-
Run commands across all packages:
lerna run test lerna run build
-
Publish changes:
lerna publish
This will guide you through versioning and publishing your packages.
Competitor Comparisons
Smart Monorepos · Fast CI
Pros of Nx
- More comprehensive toolset, including code generation and advanced dependency analysis
- Better support for monorepos with multiple frameworks (React, Angular, etc.)
- Powerful caching and incremental build capabilities for faster development
Cons of Nx
- Steeper learning curve due to more complex configuration and concepts
- Heavier setup and potentially more overhead for smaller projects
- Less flexible for projects that don't fit into Nx's opinionated structure
Code Comparison
Nx workspace configuration:
{
"name": "my-workspace",
"projects": {
"app1": { "root": "apps/app1" },
"lib1": { "root": "libs/lib1" }
}
}
Lerna configuration:
{
"packages": ["packages/*"],
"version": "independent"
}
Nx offers a more structured approach with explicit project definitions, while Lerna uses a simpler package-based configuration. Nx provides more built-in features and tooling, whereas Lerna focuses on package management and versioning in monorepos. Choose Nx for larger, more complex projects that benefit from its advanced features, and Lerna for simpler monorepo setups with a focus on package management.
Fast, disk space efficient package manager
Pros of pnpm
- Faster and more efficient package installation due to content-addressable storage
- Strict dependency management, preventing phantom dependencies
- Built-in monorepo support without additional tools
Cons of pnpm
- Less widespread adoption compared to npm and Yarn
- Some tools and CI environments may not be fully compatible with pnpm
Code comparison
Lerna:
{
"packages": ["packages/*"],
"version": "independent",
"npmClient": "npm"
}
pnpm:
{
"packages": ["packages/*"],
"version": "independent",
"npmClient": "pnpm"
}
The code comparison shows that both Lerna and pnpm can be used for monorepo management with similar configuration. The main difference is the npmClient
field, which specifies the package manager to use.
Lerna is primarily a monorepo management tool that can work with various package managers, while pnpm is a package manager that includes built-in monorepo support. pnpm offers better performance and disk space efficiency, but Lerna has been around longer and has more extensive ecosystem support.
Ultimately, the choice between Lerna and pnpm depends on specific project requirements, team preferences, and existing infrastructure compatibility.
📦🐈 Active development trunk for Yarn ⚒
Pros of Berry
- Faster package installation and resolution due to its advanced caching system
- Built-in support for monorepos with workspaces, eliminating the need for additional tools
- Improved security features, including Plug'n'Play mode and checksums for package integrity
Cons of Berry
- Steeper learning curve, especially for developers familiar with npm or Yarn Classic
- Some third-party tools and CI systems may have compatibility issues with Berry's new features
Code Comparison
Berry (Yarn 2+):
plugins:
- ./plugins/plugin-workspace-tools.js
workspaces:
- packages/*
nodeLinker: node-modules
Lerna:
{
"packages": ["packages/*"],
"version": "independent",
"npmClient": "yarn"
}
Summary
Berry (Yarn 2+) offers advanced features for monorepo management and package handling, while Lerna focuses on versioning and publishing. Berry provides a more integrated solution for workspace management, but may require more setup and learning. Lerna, on the other hand, is simpler to use and has broader compatibility with existing tools and workflows. The choice between them depends on project requirements and team preferences.
Build system optimized for JavaScript and TypeScript, written in Rust
Pros of Turborepo
- Faster build times with intelligent caching and parallel execution
- Built-in support for remote caching, enhancing CI/CD performance
- Simpler configuration with a single
turbo.json
file
Cons of Turborepo
- Less mature ecosystem compared to Lerna
- Limited to JavaScript/TypeScript projects, while Lerna supports other languages
- Steeper learning curve for teams already familiar with Lerna
Code Comparison
Turborepo configuration (turbo.json
):
{
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**"]
}
}
}
Lerna configuration (lerna.json
):
{
"version": "independent",
"npmClient": "yarn",
"command": {
"publish": {
"ignoreChanges": ["*.md"]
}
}
}
Turborepo focuses on pipeline configuration, while Lerna emphasizes version management and publishing. Turborepo's approach allows for more granular control over task dependencies and outputs, potentially leading to more efficient builds in complex monorepos. Lerna's configuration is simpler but may require additional scripts for similar functionality.
Monorepo for tools developed by the Rush Stack community
Pros of Rush Stack
- More comprehensive toolset for large-scale monorepo management
- Better integration with TypeScript and other Microsoft technologies
- Offers advanced features like incremental builds and project isolation
Cons of Rush Stack
- Steeper learning curve due to its complexity
- Less flexible for non-TypeScript projects
- Requires more configuration and setup compared to Lerna
Code Comparison
Lerna configuration:
{
"packages": ["packages/*"],
"version": "independent",
"npmClient": "yarn"
}
Rush Stack configuration:
{
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush.schema.json",
"rushVersion": "5.38.0",
"projects": [
{
"packageName": "my-app",
"projectFolder": "apps/my-app"
}
]
}
Both Lerna and Rush Stack are popular monorepo management tools, but they cater to different needs. Lerna is simpler and more flexible, making it easier to adopt for smaller projects or those not heavily invested in the Microsoft ecosystem. Rush Stack, on the other hand, offers more advanced features and better integration with TypeScript and other Microsoft technologies, making it a strong choice for large-scale projects, especially those using TypeScript.
🦋 A way to manage your versioning and changelogs with a focus on monorepos
Pros of Changesets
- More flexible and customizable versioning strategy
- Better support for monorepos with independent package versioning
- Encourages detailed changelogs through interactive CLI prompts
Cons of Changesets
- Steeper learning curve for new users
- Requires more manual intervention for version bumps and releases
- Less integrated tooling for common monorepo tasks
Code Comparison
Changesets:
// Adding a changeset
await changeset({
cwd: process.cwd(),
emptySinceLastRelease: false,
});
// Releasing packages
await release({
cwd: process.cwd(),
});
Lerna:
// Publishing packages
await lerna.publish({
conventionalCommits: true,
yes: true,
});
// Versioning packages
await lerna.version({
conventionalCommits: true,
yes: true,
});
Summary
Changesets offers more granular control over versioning and changelog generation, making it ideal for complex monorepos with independent package lifecycles. However, it requires more manual input and has a steeper learning curve compared to Lerna.
Lerna provides a more streamlined experience with integrated tooling for common monorepo tasks, but may be less flexible for projects with diverse versioning needs. It's generally easier to get started with Lerna, especially for simpler monorepo setups.
The choice between Changesets and Lerna depends on the specific needs of your project, team preferences, and the level of control you require over versioning and release processes.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Important note: this project recently changed stewardship to Nrwl!
Your favorite tool is alive and well: https://blog.nrwl.io/lerna-5-1-new-website-new-guides-new-lerna-example-repo-distributed-caching-support-and-speed-64d66410bec7
Lerna is a fast, modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository.
A few links to help you get started:
- lerna.js.org: Documentation, Guides, Interactive Tutorials
- Getting Started
- Features
- Official Nx and Lerna YouTube Channel
- Blog Posts About Lerna and Nx
Engage with the Core Team and the Community
Want to help?
If you want to file a bug or submit a PR, read up on our guidelines for contributing
Core Team
Victor Savkin | James Henry | Austin Fahsl |
---|---|---|
vsavkin | JamesHenry | fahslaj |
Benjamin Cabanes | Juri Strumpflohner |
---|---|
bcabanes | juristr |
Contributors â¨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
Top Related Projects
Smart Monorepos · Fast CI
Fast, disk space efficient package manager
📦🐈 Active development trunk for Yarn ⚒
Build system optimized for JavaScript and TypeScript, written in Rust
Monorepo for tools developed by the Rush Stack community
🦋 A way to manage your versioning and changelogs with a focus on monorepos
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot