@davidwells/lerna-smart-run is a monorepo workflow helper for running npm scripts against packages that changed since a previous branch-based tag.

It wraps ordinary Lerna commands with sequencing controls, tagging behavior, and options for running specific packages first or last.

Full documentation, synced from the package README:

Fork of: https://blog.purple-technology.com/make-your-lerna-smarter/. Updated for lerna v9 +

Lerna add-on for only running npm scripts for packages changed since previous tag

Background

This package is a glorified wrapper around ordinary lerna run <script> commands, but it implements a system to control the order of execution and an automated, opinionated tagging system (based on git branches) that takes advantage of lerna's --since option.

This package is intended for use in CI and CD pipelines, especially where sequential deploys are necessary, i.e., where one serverless resource needs to be deployed before the rest.

Usage

Invoke with lerna-run <npm script>, where <npm script> is a script from the scripts section of the package.json of one of your lerna packages.

Example:

lerna-run test

Optional arguments

Pass --tagOnSuccess to generate a tag from the successful execution of the smart run. This tag will be used on the following execution.

Pass --deleteTagOnSuccess to delete the previous tag on the successful execution of the smart run. If there was no previous tag this has no effect.

Pass --runFirst to run a package's script before any others. If multiple packages are passed to this option, they're run in sequence as well. Supports glob patterns.

Pass --runLast to run a package's script after any others. If multiple packages are passed to this option, they're run in sequence as well. Supports glob patterns.

Pass --scope if you want to run the command for a package even if it hasn't changed, but one of its dependencies has.

Pass --ignore if you want to ignore a package, but you still want to run the command for any of its dependents if they've changed.

Special arguments

If --deleteTag is passed, this simply looks for the most recent tag generated by this package and deletes it. After which the script exists. Example:

lerna-run --deleteTag

Disclaimer

This package is in an early, experimental stage, and is likely to change dramatically between different versions.