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(core): add stub for conformance:check, add messaging #28250

Merged
merged 2 commits into from
Oct 2, 2024
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
46 changes: 36 additions & 10 deletions packages/nx/src/command-line/nx-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
yargsAffectedGraphCommand,
} from './deprecated/command-objects';
import { yargsSyncCheckCommand, yargsSyncCommand } from './sync/command-object';
import { output } from '../utils/output';

// Ensure that the output takes up the available width of the terminal.
yargs.wrap(yargs.terminalWidth());
Expand Down Expand Up @@ -101,26 +102,51 @@ export const commandsObject = yargs
.command(yargsLoginCommand)
.command(yargsLogoutCommand)
.command(resolveConformanceCommandObject())
.command(resolveConformanceCheckCommandObject())
.scriptName('nx')
.help()
// NOTE: we handle --version in nx.ts, this just tells yargs that the option exists
// so that it shows up in help. The default yargs implementation of --version is not
// hit, as the implementation in nx.ts is hit first and calls process.exit(0).
.version();

function createMissingConformanceCommand(
command: 'conformance' | 'conformance:check'
) {
return {
command,
// Hide from --help output in the common case of not having the plugin installed
describe: false,
handler: () => {
output.error({
title: `${command} is not available`,
bodyLines: [
`In order to use the \`nx ${command}\` command you must have an active Powerpack license and the \`@nx/powerpack-conformance\` plugin installed.`,
'',
'To learn more, visit https://nx.dev/features/powerpack/conformance',
],
});
process.exit(1);
},
};
}

function resolveConformanceCommandObject() {
try {
const { yargsConformanceCommand } = require('@nx/powerpack-conformance');
return yargsConformanceCommand;
} catch (e) {
return {
command: 'conformance',
// Hide from --help output in the common case of not having the plugin installed
describe: false,
handler: () => {
// TODO: Add messaging to help with learning more about powerpack and conformance
process.exit(1);
},
};
} catch {
return createMissingConformanceCommand('conformance');
}
}

function resolveConformanceCheckCommandObject() {
try {
const {
yargsConformanceCheckCommand,
} = require('@nx/powerpack-conformance');
return yargsConformanceCheckCommand;
} catch {
return createMissingConformanceCommand('conformance:check');
}
}