Skip to content

Commit

Permalink
feat(run)!: remove --use-nx (powered by Nx) option from run comma…
Browse files Browse the repository at this point in the history
…nd (#554)

* feat(run)!: remove `--use-nx` (powered by Nx) option from `run` command
  • Loading branch information
ghiscoding committed Apr 7, 2023
1 parent 1baa0d1 commit b5ff9c9
Show file tree
Hide file tree
Showing 27 changed files with 15 additions and 1,300 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"exec-win": "lerna exec --scope {@lerna-lite/cli,@lerna-lite/core} -- cross-env-shell echo hello from package: $LERNA_PACKAGE_NAME",
"exec:preview": "lerna exec -- git log -p -2",
"pack-tarball": "lerna run pack-tarball",
"pack-tarball:nx": "lerna run pack-tarball --stream --use-nx",
"preview:build": "lerna run build --stream --include-dependents --scope=@lerna-lite/listable",
"preview:watch:build": "lerna watch --no-bail --scope=@lerna-lite/listable --include-dependents -- cross-env-shell lerna run build:incremental --stream --include-dependents --scope=$LERNA_PACKAGE_NAME",
"preview:watch:build:pnpm": "lerna watch --no-bail --scope=@lerna-lite/listable --include-dependents -- cross-env-shell pnpm run --stream --filter ...$LERNA_PACKAGE_NAME build:incremental",
Expand Down Expand Up @@ -93,7 +92,6 @@
"normalize-newline": "^4.1.0",
"normalize-path": "^3.0.0",
"npmlog": "^7.0.1",
"nx": "15.9.2",
"path": "0.12.7",
"prettier": "^2.8.7",
"rimraf": "^4.4.1",
Expand Down
27 changes: 1 addition & 26 deletions packages/cli/schemas/lerna-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
"description": "An array of globs where packages can be located.",
"default": ["packages/*"]
},
"useNx": {
"type": "boolean",
"description": "When true, Lerna will delegate the implementation details of `lerna run` to the Nx task runner instead of the default Lerna task runner (which uses `p-map` and `p-queue`).",
"default": false
},
"command": {
"type": "object",
"description": "Options for individual Lerna commands.",
Expand Down Expand Up @@ -476,13 +471,6 @@
"verbose": {
"$ref": "#/$defs/commandOptions/shared/verbose"
},
"skipNxCache": {
"$ref": "#/$defs/commandOptions/run/skipNxCache"
},
"loadEnvFiles": {
"$ref": "#/$defs/commandOptions/run/loadEnvFiles"
},

"npmClient": {
"$ref": "#/$defs/globals/npmClient"
},
Expand Down Expand Up @@ -920,11 +908,6 @@
"verifyAccess": {
"$ref": "#/$defs/commandOptions/publish/verifyAccess"
},

"skipNxCache": {
"$ref": "#/$defs/commandOptions/run/skipNxCache"
},

"allowBranch": {
"$ref": "#/$defs/commandOptions/version/allowBranch"
},
Expand Down Expand Up @@ -1237,14 +1220,6 @@
"dryRun": {
"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."
}
},
"version": {
Expand Down Expand Up @@ -1543,7 +1518,7 @@
},
"verbose": {
"type": "boolean",
"description": "When true, escalates loglevel to 'verbose' and shows nx verbose output if useNx is true."
"description": "When true, escalates loglevel to 'verbose'."
}
}
}
Expand Down
19 changes: 0 additions & 19 deletions packages/cli/src/cli-commands/cli-run-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,6 @@ export default {
describe: 'Output performance profile to custom location instead of default project root.',
type: 'string',
},
'skip-nx-cache': {
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: 'enables integration with Nx instead of the default Lerna task runner (which uses `p-map` and `p-queue`).',
type: 'boolean',
},
verbose: {
group: 'Command Options:',
describe: 'When "useNx" is true, show verbose output from dependent tasks.',
type: 'boolean',
},
});

return filterOptions(yargs);
Expand Down
9 changes: 0 additions & 9 deletions packages/core/src/models/command-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,6 @@ export interface RunCommandOption {
/** proxy for `--no-bail`. */
bail?: boolean;

/** When useNx is enabled, do we want to automatically load .env files */
loadEnvFiles?: boolean;

/** Do not prefix streaming output. */
noPrefix?: boolean;

Expand All @@ -419,12 +416,6 @@ export interface RunCommandOption {

/** npm script to run by the command. */
script: string;

/** when "useNx" is enabled, do we want to skip caching with Nx? */
skipNxCache?: boolean;

/** enables integration with [Nx](https://nx.dev) instead of the default Lerna task runner (which uses `p-map` and `p-queue`). */
useNx?: boolean;
}

/** Watch Command will run a script whenever package(s) or their dependents change. */
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@ export interface ProjectConfig extends LernaConfig, QueryGraphConfig {
/** During `lerna exec` and `lerna run`, stream output with lines prefixed by originating package name. */
stream?: boolean;

/** Enables integration with [Nx](https://nx.dev). */
useNx?: boolean;

/** When useNx is true, show verbose output from dependent tasks. */
verbose?: boolean;

Expand Down
6 changes: 1 addition & 5 deletions packages/profiler/src/profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ const getTimeBasedFilename = () => {
return `Lerna-Profile-${datetimeNormalized}.json`;
};

export function generateProfileOutputPath(outputDirectory?: string) {
return upath.join(upath.resolve(outputDirectory || '.'), getTimeBasedFilename());
}

const hrtimeToMicroseconds = (hrtime: any) => {
return (hrtime[0] * 1e9 + hrtime[1]) / 1000;
};
Expand Down Expand Up @@ -44,7 +40,7 @@ export class Profiler {
constructor({ concurrency, log = npmlog, outputDirectory }: ProfilerConfig) {
this.events = [];
this.logger = log;
this.outputPath = generateProfileOutputPath(outputDirectory);
this.outputPath = upath.join(upath.resolve(outputDirectory || '.'), getTimeBasedFilename());
this.threads = range(concurrency);
}

Expand Down
63 changes: 0 additions & 63 deletions packages/run/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ $ 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 @@ -159,64 +157,3 @@ You can provide a custom location for the performance profile output. The path p
```sh
$ 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
running tasks to Nx instead of using `p-map` and `p-queue`. This only works if Nx is installed and `nx.json` is present. You can also skip cache by providing `--skip-nx-cache`

Example of `nx.json`:

```json
{
"extends": "nx/presets/npm.json",
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": ["build"]
}
}
}
}
```

When [Nx](https://nx.dev/) is installed and `nx.json` is detected in the current workspace with `useNx` set to `true` in `lerna.json`, Lerna will respect `nx.json` configuration during `lerna run` and delegate to the Nx task runner.

Nx will run tasks in an order and with a concurrency that it determines appropriate based on the task graph that it creates. For more information, see [Nx Mental Model: The Task Graph](https://nx.dev/concepts/mental-model#the-task-graph).

**This behavior allows Nx to run tasks in the most efficient way possible, but it also means that some existing options for `lerna run` become obsolete as explained below.**

> **Note** when Lerna is set to use Nx and detects `nx.json` with `targetDefaults` in the workspace, it will defer to Nx to detect task dependencies. Some options for `lerna run` will behave differently. See [Using Lerna (Powered by Nx) to Run Tasks](./recipes/using-lerna-powered-by-nx-to-run-tasks) for more details.
#### Obsolete Options when `useNx` is enabled

##### `--sort` and `--no-sort`

Nx will always run tasks in the order it deems is correct based on its knowledge of project and task dependencies, so `--sort` and `--no-sort` have no effect.

##### `--parallel`

Nx will use the task graph to determine which tasks can be run in parallel and do so automatically, so `--parallel` has no effect.

> **Note** if you want to limit the concurrency of tasks, you can still use the [concurrency global option](https://github.com/lerna/lerna/blob/6cb8ab2d4af7ce25c812e8fb05cd04650105705f/core/global-options/README.md#--concurrency) to accomplish this.

##### `--include-dependencies`

Lerna by itself does not have knowledge of which tasks depend on others, so it defaults to excluding tasks on dependent projects when using [filter options](https://github.com/lerna/lerna/tree/6cb8ab2d4af7ce25c812e8fb05cd04650105705f/core/filter-options#lernafilter-options) and relies on `--include-dependencies` to manually specify that dependent projects' tasks should be included.

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`

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).

> **Tip** the effects on the options above will only apply if `nx.json` exists in the root with the `targetDefaults` property defined. Otherwise, they will behave just as they would with Lerna's base task runner (if `useNx` is `false`).
1 change: 0 additions & 1 deletion packages/run/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"devDependencies": {
"@types/fs-extra": "11.0.1",
"globby": "13.1.3",
"nx": "15.8.9",
"perf_hooks": "^0.0.1",
"yargs": "^17.7.1",
"yargs-parser": "^21.1.1"
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions packages/run/src/__fixtures__/powered-by-nx/lerna.json

This file was deleted.

11 changes: 0 additions & 11 deletions packages/run/src/__fixtures__/powered-by-nx/nx.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/run/src/__fixtures__/powered-by-nx/package.json

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit b5ff9c9

Please sign in to comment.