What is @lerna/run-lifecycle?
@lerna/run-lifecycle is a package that allows you to run lifecycle scripts for npm packages within a Lerna-managed monorepo. It helps in executing pre-defined scripts like preinstall, install, postinstall, prepublish, publish, postpublish, etc., across multiple packages in a monorepo setup.
What are @lerna/run-lifecycle's main functionalities?
Run Predefined Lifecycle Scripts
This feature allows you to run predefined lifecycle scripts like preinstall, install, postinstall, etc., for a given package. The code sample demonstrates how to run the 'preinstall' script for a package.
const { runLifecycle } = require('@lerna/run-lifecycle');
async function runScript(pkg, script) {
await runLifecycle(pkg, script, {
stdio: 'inherit',
});
}
const pkg = { name: 'my-package', location: '/path/to/package' };
runScript(pkg, 'preinstall');
Custom Script Execution
This feature allows you to run custom scripts defined in the package.json of a given package. The code sample demonstrates how to run a custom script named 'custom-script' for a package.
const { runLifecycle } = require('@lerna/run-lifecycle');
async function runCustomScript(pkg, script) {
await runLifecycle(pkg, script, {
stdio: 'inherit',
scriptShell: '/bin/bash',
});
}
const pkg = { name: 'my-package', location: '/path/to/package' };
runCustomScript(pkg, 'custom-script');
Other packages similar to @lerna/run-lifecycle
npm-lifecycle
npm-lifecycle is a package that provides the functionality to run lifecycle scripts for npm packages. It is similar to @lerna/run-lifecycle but is not specifically designed for monorepo setups managed by Lerna. It can be used for individual npm packages.
yarn
Yarn is a package manager that also supports running lifecycle scripts for packages. While it is not a direct replacement for @lerna/run-lifecycle, it provides similar functionalities in terms of script execution and can be used in monorepo setups with Yarn Workspaces.
pnpm
pnpm is another package manager that supports running lifecycle scripts. It is known for its efficient handling of node_modules and can be used in monorepo setups. Like Yarn, it provides similar functionalities but is not specifically tailored for Lerna-managed monorepos.
@lerna/run-lifecycle
An internal Lerna tool
Usage
You probably shouldn't, at least directly.
Install lerna for access to the lerna
CLI.