Skip to content

Commit

Permalink
fix(run): warn on incompatible arguments with useNx (#3326)
Browse files Browse the repository at this point in the history
  • Loading branch information
fahslaj committed Sep 20, 2022
1 parent 068830e commit ebf6542
Show file tree
Hide file tree
Showing 4 changed files with 632 additions and 8 deletions.
23 changes: 16 additions & 7 deletions commands/run/index.js
Expand Up @@ -221,10 +221,13 @@ class RunCommand extends Command {
prepNxOptions() {
const { readNxJson } = require("nx/src/config/configuration");
const nxJson = readNxJson();
const nxJsonExists = existsSync(path.join(this.project.rootPath, "nx.json"));
const useParallel = this.options.parallel && !nxJsonExists;

const targetDependenciesAreDefined =
Object.keys(nxJson.targetDependencies || nxJson.targetDefaults || {}).length > 0;
const targetDependencies =
this.toposort && !this.options.parallel && !targetDependenciesAreDefined
this.toposort && !useParallel && !targetDependenciesAreDefined
? {
[this.script]: [
{
Expand All @@ -247,26 +250,32 @@ class RunCommand extends Command {
* To match lerna's own behavior (via pMap's default concurrency), we set parallel to a very large number if
* the flag has been set (we can't use Infinity because that would cause issues with the task runner).
*/
parallel: this.options.parallel ? 999 : this.concurrency,
parallel: useParallel ? 999 : this.concurrency,
nxBail: this.bail,
nxIgnoreCycles: !this.options.rejectCycles,
skipNxCache: this.options.skipNxCache,
verbose: this.options.verbose,
__overrides__: this.args.map((t) => t.toString()),
};

const excludeTaskDependencies = !existsSync(path.join(this.project.rootPath, "nx.json"));
if (excludeTaskDependencies) {
if (nxJsonExists) {
this.logger.verbose(this.name, "nx.json was found. Task dependencies will be automatically included.");

if (this.options.parallel || this.options.sort !== undefined || this.options.includeDependencies) {
this.logger.warn(
this.name,
`"parallel", "sort", "no-sort", and "include-dependencies" are ignored when nx.json exists. See https://lerna.js.org/docs/recipes/using-lerna-powered-by-nx-to-run-tasks for details.`
);
}
} else {
this.logger.verbose(
this.name,
"nx.json was not found. Task dependencies will not be automatically included."
);
} else {
this.logger.verbose(this.name, "nx.json was found. Task dependencies will be automatically included.");
}

const extraOptions = {
excludeTaskDependencies,
excludeTaskDependencies: !nxJsonExists,
};

return { targetDependencies, options, extraOptions };
Expand Down

0 comments on commit ebf6542

Please sign in to comment.