What is @microsoft/rush-lib?
@microsoft/rush-lib is a library for managing large monorepos with many projects. It provides tools for orchestrating builds, managing dependencies, and automating workflows in a consistent and efficient manner.
What are @microsoft/rush-lib's main functionalities?
Project Management
This feature allows you to load and manage the configuration of projects within a Rush monorepo. The code sample demonstrates how to load the Rush configuration and print the list of projects.
const rushLib = require('@microsoft/rush-lib');
const rushConfiguration = rushLib.RushConfiguration.loadFromDefaultLocation();
console.log(rushConfiguration.projects);
Dependency Management
This feature helps in managing dependencies across projects in the monorepo. The code sample shows how to load the Rush configuration and print the package manager being used.
const rushLib = require('@microsoft/rush-lib');
const rushConfiguration = rushLib.RushConfiguration.loadFromDefaultLocation();
const packageManager = rushConfiguration.packageManager;
console.log(`Using package manager: ${packageManager}`);
Build Orchestration
This feature allows you to orchestrate builds across multiple projects in the monorepo. The code sample demonstrates how to execute the Rush build command programmatically.
const rushLib = require('@microsoft/rush-lib');
const rushConfiguration = rushLib.RushConfiguration.loadFromDefaultLocation();
const buildCommand = rushLib.Utilities.executeCommand({
command: 'rush',
args: ['build'],
workingDirectory: rushConfiguration.rushJsonFolder
});
buildCommand.then(() => console.log('Build completed successfully')).catch(err => console.error('Build failed', err));
Other packages similar to @microsoft/rush-lib
lerna
Lerna is a popular tool for managing JavaScript projects with multiple packages. It optimizes the workflow around managing multi-package repositories with git and npm. Compared to @microsoft/rush-lib, Lerna is more focused on JavaScript and TypeScript projects and offers a simpler setup, but it may not scale as well for very large monorepos.
nx
Nx is a set of extensible dev tools for monorepos, which helps you develop like Google, Facebook, and Microsoft. It offers powerful integrations with modern frameworks and libraries. Compared to @microsoft/rush-lib, Nx provides more advanced features for code generation, testing, and CI/CD pipelines, making it a more comprehensive solution for modern web development.
@microsoft/rush-lib
This is a companion package for the Rush tool. See the
@microsoft/rush
package for details.
The rush-lib package implements the rush.json config file loader
and some other helpful utilities. Tools that want to reuse this
functionality can install rush-lib alone to avoid inadvertently
adding another "rush" executable to the command-line path (which
might interfere with the globally installed Rush).
The @microsoft/rush version number is always exactly equal
to the @microsoft/rush-lib version number that it depends on.
API documentation for this package: https://rushjs.io/pages/advanced/api/
Links
Rush is part of the Rush Stack family of projects.