Original text: github.com/lerna/lerna…

Execute arbitrary commands in each package

Install Lerna to access the LERna CLI.

use

$lerna exec -- <command> [..args] # $lerna exec -- rm -rf./node_modules $lerna exec -- protractor conf.jsCopy the code

Run arbitrary commands in each package. The double dash (–) is required for passing dashed flags to derived commands, but not when all arguments are positional arguments.

The name of the current package can be obtained from the environment variable LERNA_package_name:

$ lerna exec -- npm view \$LERNA_PACKAGE_NAME
Copy the code

You can also run scripts in the root directory in a complex dir structure with the environment variable LERNA_root_PATH:

$ lerna exec -- node \$LERNA_ROOT_PATH/scripts/some-script.js
Copy the code

options

Lerna Exec accepts all filter flags.

$ lerna exec --scope my-component -- ls -la
Copy the code

Generate commands in parallel with the given concurrency (except using –parallel). The output is piped, so it is not deterministic. If you want to run commands in package after package, use them as follows:

lerna exec --concurrency 1 -- ls -la
Copy the code

–stream

Outputs the stream immediately from the child process, prefixed with the original package name. This allows the output from different packages to be interleaved.

$ lerna exec --stream -- babel src -d lib
Copy the code

–parallel

Similar to –stream, but completely ignoring concurrency and topological sorting, the given command or script is run immediately in all matching packages, with prefixed stream output. This is the preferred flag for long-running processes such as Babel src-dlib-w running on many packages.

$ lerna exec --parallel -- babel src -d lib -w
Copy the code

Note: It is recommended to constrain the scope of this command when using the –parallel flag, because generating dozens of child processes can compromise the stability of the shell (for example, the maximum file descriptor limit). YMMV

–no-bail

$lerna exec --no-bail <command>Copy the code

By default, lerna Exec will exit and return an error if any execution returns a non-zero exit code. Disable this behavior by using — no-Bail in all packages regardless of the exit code.

–no-prefix

Disable the package name prefix (–stream or –parallel) when the output is streaming. This option is useful when piping results to other processes, such as editor plug-ins.

–profile

Analysis command execution performance and generate configuration files, can be used in the browser based on Chromium DevTools analysis (direct url: DevTools: / / DevTools bundled devtools_app. HTML). The configuration file displays a timeline of command executions, with each execution assigned to an open slot. The number of slots is determined by the –concurrency option, and the number of open slots is determined by the –concurrency minus the number of in-process operands. The end result is a visualization of parallel execution of commands.

The default location for performance profile output is in the root directory of the project.

$ lerna exec --profile -- <command>
Copy the code

Note: Lerna profiling is only done if topological sorting is enabled (i.e. –parallel and –no sort are not used).

–profile-location

You can provide custom locations for performance profile output. The path provided resolves relative to the current working directory.

$ lerna exec --profile --profile-location=logs/profile/ -- <command>
Copy the code