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

feat(core): pass down help to run-commands #21331

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions packages/nx/src/command-line/run/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '../../project-graph/project-graph';
import { ProjectGraph } from '../../config/project-graph';
import { readNxJson } from '../../config/configuration';
import { runCommand } from '../../native';
import {
getLastValueFromAsyncIterableIterator,
isAsyncIterator,
Expand Down Expand Up @@ -80,10 +81,9 @@ async function iteratorToProcessStatusCode(
}

async function parseExecutorAndTarget(
{ project, target, configuration }: Target,
{ project, target }: Target,
root: string,
projectsConfigurations: ProjectsConfigurations,
nxJsonConfiguration: NxJsonConfiguration
projectsConfigurations: ProjectsConfigurations
) {
const proj = projectsConfigurations.projects[project];
const targetConfig = proj.targets?.[target];
Expand All @@ -104,23 +104,37 @@ async function parseExecutorAndTarget(
}

async function printTargetRunHelpInternal(
{ project, target, configuration }: Target,
{ project, target }: Target,
root: string,
projectsConfigurations: ProjectsConfigurations,
nxJsonConfiguration: NxJsonConfiguration
projectsConfigurations: ProjectsConfigurations
) {
const { executor, nodeModule, schema } = await parseExecutorAndTarget(
{ project, target, configuration },
root,
projectsConfigurations,
nxJsonConfiguration
);
const { executor, nodeModule, schema, targetConfig } =
await parseExecutorAndTarget(
{ project, target },
root,
projectsConfigurations
);

printRunHelp({ project, target }, schema, {
plugin: nodeModule,
entity: executor,
});
process.exit(0);

if (
nodeModule === 'nx' &&
executor === 'run-commands' &&
targetConfig.options.command
) {
const command = targetConfig.options.command.split(' ')[0];
await new Promise(() => {
const cp = runCommand(`${command} --help`);
cp.onExit((code) => {
process.exit(code);
});
});
} else {
process.exit(0);
}
}

async function runExecutorInternal<T extends { success: boolean }>(
Expand All @@ -140,8 +154,7 @@ async function runExecutorInternal<T extends { success: boolean }>(
await parseExecutorAndTarget(
{ project, target, configuration },
root,
projectsConfigurations,
nxJsonConfiguration
projectsConfigurations
);
configuration ??= targetConfig.defaultConfiguration;

Expand Down Expand Up @@ -258,13 +271,11 @@ export function printTargetRunHelp(targetDescription: Target, root: string) {
return handleErrors(false, async () => {
const projectsConfigurations =
readProjectsConfigurationFromProjectGraph(projectGraph);
const nxJsonConfiguration = readNxJson();

printTargetRunHelpInternal(
await printTargetRunHelpInternal(
targetDescription,
root,
projectsConfigurations,
nxJsonConfiguration
projectsConfigurations
);
});
}
Expand Down