Skip to content

Commit

Permalink
feat(run): add LERNA_PACKAGE_NAME env var to run command
Browse files Browse the repository at this point in the history
- ref Lerna PR [#3107](lerna/lerna#3107)
  • Loading branch information
ghiscoding committed May 3, 2022
1 parent 816b7cb commit ae88a0a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/run/README.md
Expand Up @@ -37,6 +37,12 @@ $ lerna run --parallel watch

Run an [npm script](https://docs.npmjs.com/misc/scripts) in each package of the workspace that contains that script. A double-dash (`--`) is necessary to pass dashed arguments to the script execution.

The name of the current package is available through the environment variable `LERNA_PACKAGE_NAME`:

```sh
$ lerna run build \$LERNA_PACKAGE_NAME
```

## Options

`lerna run` accepts all [filter flags](https://www.npmjs.com/package/@lerna/filter-options).
Expand Down
12 changes: 9 additions & 3 deletions packages/run/src/lib/__tests__/npm-run-script.spec.ts
Expand Up @@ -118,7 +118,9 @@ describe('npm-run-script', () => {
['run', script, '--bar', 'baz'],
{
cwd: config.pkg.location,
env: {},
env: {
LERNA_PACKAGE_NAME: 'qux'
},
pkg: config.pkg,
reject: true,
windowsHide: false,
Expand Down Expand Up @@ -147,7 +149,9 @@ describe('npm-run-script', () => {
['run', script, '--bar', 'baz'],
{
cwd: config.pkg.location,
env: {},
env: {
LERNA_PACKAGE_NAME: 'qux'
},
pkg: config.pkg,
reject: true,
windowsHide: false,
Expand Down Expand Up @@ -177,7 +181,9 @@ describe('npm-run-script', () => {
['run', script],
{
cwd: config.pkg.location,
env: {},
env: {
LERNA_PACKAGE_NAME: 'qux'
},
pkg: config.pkg,
reject: false,
windowsHide: false,
Expand Down
4 changes: 3 additions & 1 deletion packages/run/src/lib/get-npm-exec-opts.ts
Expand Up @@ -3,7 +3,9 @@ import log from 'npmlog';

export function getNpmExecOpts(pkg: Package) {
// execa automatically extends process.env
const env: { [key: string]: string } = {};
const env: { [key: string]: string } = {
LERNA_PACKAGE_NAME: pkg.name,
};

log.silly('getNpmExecOpts', pkg.location);
return {
Expand Down

0 comments on commit ae88a0a

Please sign in to comment.