Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(run): allow for loading of env files to be skipped #391

Merged
merged 1 commit into from Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/cli/schemas/lerna-schema.json
Expand Up @@ -480,6 +480,9 @@
"skipNxCache": {
"$ref": "#/$defs/commandOptions/run/skipNxCache"
},
"loadEnvFiles": {
"$ref": "#/$defs/commandOptions/run/loadEnvFiles"
},

"npmClient": {
"$ref": "#/$defs/globals/npmClient"
Expand Down Expand Up @@ -1265,6 +1268,10 @@
"type": "boolean",
"description": "During `lerna run`, when true, displays the process command that would be performed without executing it."
},
"loadEnvFiles": {
"type": "boolean",
"description": "During `lerna run`, when false, skip loading of environment variables from .env files."
},
"skipNxCache": {
"type": "boolean",
"description": "During `lerna run`, when true, skip the nx cache."
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/cli-commands/cli-run-commands.ts
Expand Up @@ -78,6 +78,11 @@ export default {
hidden: true,
type: 'boolean',
},
'load-env-files': {
group: 'Command Options:',
describe: 'When useNx is enabled, do we want to automatically load .env files',
type: 'boolean',
},
'use-nx': {
group: 'Command Options:',
describe:
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/models/command-options.ts
Expand Up @@ -367,8 +367,8 @@ export interface RunCommandOption {
/** proxy for `--no-bail`. */
bail?: boolean;

// This option controls prefix for stream output so that it can be disabled to be friendly
// to tools like Visual Studio Code to highlight the raw results
/** When useNx is enabled, do we want to automatically load .env files */
loadEnvFiles?: boolean;

/** Do not prefix streaming output. */
noPrefix?: boolean;
Expand Down
10 changes: 9 additions & 1 deletion packages/run/README.md
Expand Up @@ -62,6 +62,7 @@ $ lerna run --scope my-component test
- [`--no-prefix`](#--no-prefix)
- [`--profile`](#--profile)
- [`--profile-location <location>`](#--profile-location-location)
- [`--load-env-files`](#load-env-files)
- [`--use-nx`](#use-nx)

### `--npm-client <client>`
Expand Down Expand Up @@ -154,6 +155,13 @@ You can provide a custom location for the performance profile output. The path p
$ lerna run build --profile --profile-location=logs/profile/
```


### `--load-env-files`

When the task runner is powered by Nx (via [`--use-nx`](#use-nx)) it will automatically load `.env` files for you. You can set `--load-env-files` to false if you want to disable this behavior for any reason.

For more details about what `.env` files will be loaded by default please see: https://nx.dev/recipes/environment-variables/define-environment-variables

### `--use-nx`

Enables integration with [Nx](https://nx.dev). Enabling this option will tell Lerna to delegate
Expand Down Expand Up @@ -202,7 +210,7 @@ Lerna by itself does not have knowledge of which tasks depend on others, so it d

This is no longer a problem when Lerna uses Nx to run tasks. Nx, utilizing its [task graph](https://nx.dev/concepts/mental-model#the-task-graph), will automatically run dependent tasks first when necessary, so `--include-dependencies` is obsolete. However, it can still be used to include project dependencies that Lerna detects but Nx does not deem necessary and would otherwise exclude.

### `--ignore`
#### `--ignore`

When used with Nx, `--ignore` will never cause `lerna run` to exclude any tasks that are deemed to be required by the Nx [task graph](https://nx.dev/concepts/mental-model#the-task-graph).

Expand Down
1 change: 1 addition & 0 deletions packages/run/src/run-command.ts
Expand Up @@ -342,6 +342,7 @@ export class RunCommand extends Command<RunCommandOption & FilterOptions> {

const extraOptions = {
excludeTaskDependencies: mimicLernaDefaultBehavior,
loadDotEnvFiles: this.options.loadEnvFiles ?? true,
};

return { targetDependencies, options, extraOptions };
Expand Down