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): warn on incompatible arguments with useNx #3326

Merged
merged 3 commits into from Sep 20, 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
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