Skip to content

Commit 95317bb

Browse files
committed
fix(core): throw a specific error for print-affected and affected graph (#23336)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> ## Current Behavior <!-- This is the behavior we have today --> A non-descriptive error is thrown when using the recently removed `print-affected` and `affected:graph` commands. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> A descriptive error is thrown when using the recently removed `print-affected` and `affected:graph` commands. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # (cherry picked from commit 6f197e9)
1 parent 868ac4c commit 95317bb

File tree

3 files changed

+59
-59
lines changed

3 files changed

+59
-59
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { CommandModule } from 'yargs';
2+
import { handleErrors } from '../../utils/params';
3+
import {
4+
withAffectedOptions,
5+
withDepGraphOptions,
6+
withTargetAndConfigurationOption,
7+
} from '../yargs-utils/shared-options';
8+
9+
const affectedGraphDeprecationMessage =
10+
'Use `nx graph --affected`, or `nx affected --graph` instead depending on which best suits your use case. The `affected:graph` command has been removed in Nx 19.';
11+
const printAffectedDeprecationMessage =
12+
'Use `nx show projects --affected`, `nx affected --graph -t build` or `nx graph --affected` depending on which best suits your use case. The `print-affected` command has been removed in Nx 19.';
13+
14+
/**
15+
* @deprecated 'Use `nx graph --affected`, or` nx affected --graph` instead depending on which best suits your use case. The `affected:graph` command will be removed in Nx 19.'
16+
*/
17+
export const yargsAffectedGraphCommand: CommandModule = {
18+
command: 'affected:graph',
19+
describe: false,
20+
aliases: ['affected:dep-graph'],
21+
builder: (yargs) => withAffectedOptions(withDepGraphOptions(yargs)),
22+
handler: (args) =>
23+
handleErrors(false, () => {
24+
throw new Error(affectedGraphDeprecationMessage);
25+
}),
26+
deprecated: affectedGraphDeprecationMessage,
27+
};
28+
29+
/**
30+
* @deprecated 'Use `nx show --affected`, `nx affected --graph` or `nx graph --affected` depending on which best suits your use case. The `print-affected` command will be removed in Nx 19.'
31+
*/
32+
export const yargsPrintAffectedCommand: CommandModule = {
33+
command: 'print-affected',
34+
describe: false,
35+
builder: (yargs) =>
36+
withAffectedOptions(withTargetAndConfigurationOption(yargs, false))
37+
.option('select', {
38+
type: 'string',
39+
describe:
40+
'Select the subset of the returned json document (e.g., --select=projects)',
41+
})
42+
.option('type', {
43+
type: 'string',
44+
choices: ['app', 'lib'],
45+
describe:
46+
'Select the type of projects to be returned (e.g., --type=app)',
47+
}),
48+
handler: (args) =>
49+
handleErrors(false, () => {
50+
throw new Error(printAffectedDeprecationMessage);
51+
}),
52+
deprecated: printAffectedDeprecationMessage,
53+
};

packages/nx/src/command-line/examples.ts

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,6 @@ export interface Example {
44
}
55

66
export const examples: Record<string, Example[]> = {
7-
'print-affected': [
8-
{
9-
command: 'print-affected',
10-
description:
11-
'Print information about affected projects and the project graph',
12-
},
13-
{
14-
command: 'print-affected --base=main --head=HEAD',
15-
description:
16-
'Print information about the projects affected by the changes between main and HEAD (e.g,. PR)',
17-
},
18-
{
19-
command: 'print-affected -t test',
20-
description:
21-
'Prints information about the affected projects and a list of tasks to test them',
22-
},
23-
{
24-
command: 'print-affected -t build --select=projects',
25-
description:
26-
'Prints the projects property from the print-affected output',
27-
},
28-
{
29-
command: 'print-affected -t build --select=tasks.target.project',
30-
description:
31-
'Prints the tasks.target.project property from the print-affected output',
32-
},
33-
],
347
affected: [
358
{
369
command: 'affected -t custom-target',
@@ -193,38 +166,6 @@ export const examples: Record<string, Example[]> = {
193166
description: 'Watch for changes to project graph and update in-browser',
194167
},
195168
],
196-
'affected:graph': [
197-
{
198-
command: 'affected:graph --files=libs/mylib/src/index.ts',
199-
description:
200-
'Open the project graph of the workspace in the browser, and highlight the projects affected by changing the index.ts file',
201-
},
202-
{
203-
command: 'affected:graph --base=main --head=HEAD',
204-
description:
205-
'Open the project graph of the workspace in the browser, and highlight the projects affected by the changes between main and HEAD (e.g., PR)',
206-
},
207-
{
208-
command: 'affected:graph --base=main --head=HEAD --file=output.json',
209-
description:
210-
'Save the project graph of the workspace in a json file, and highlight the projects affected by the changes between main and HEAD (e.g., PR)',
211-
},
212-
{
213-
command: 'affected:graph --base=main --head=HEAD --file=output.html',
214-
description:
215-
'Generate a static website with project graph data in an html file, highlighting the projects affected by the changes between main and HEAD (e.g., PR)',
216-
},
217-
{
218-
command: 'affected:graph --base=main~1 --head=main',
219-
description:
220-
'Open the project graph of the workspace in the browser, and highlight the projects affected by the last commit on main',
221-
},
222-
{
223-
command: 'affected:graph --exclude=project-one,project-two',
224-
description:
225-
'Open the project graph of the workspace in the browser, highlight the projects affected, but exclude project-one and project-two',
226-
},
227-
],
228169
list: [
229170
{
230171
command: 'list',

packages/nx/src/command-line/nx-commands.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ import { yargsWatchCommand } from './watch/command-object';
3636
import { yargsResetCommand } from './reset/command-object';
3737
import { yargsReleaseCommand } from './release/command-object';
3838
import { yargsAddCommand } from './add/command-object';
39+
import {
40+
yargsPrintAffectedCommand,
41+
yargsAffectedGraphCommand,
42+
} from './deprecated/command-objects';
3943

4044
// Ensure that the output takes up the available width of the terminal.
4145
yargs.wrap(yargs.terminalWidth());
@@ -61,6 +65,7 @@ export const commandsObject = yargs
6165
.command(yargsAffectedE2ECommand)
6266
.command(yargsAffectedLintCommand)
6367
.command(yargsAffectedTestCommand)
68+
.command(yargsAffectedGraphCommand)
6469
.command(yargsConnectCommand)
6570
.command(yargsDaemonCommand)
6671
.command(yargsDepGraphCommand)
@@ -73,6 +78,7 @@ export const commandsObject = yargs
7378
.command(yargsListCommand)
7479
.command(yargsMigrateCommand)
7580
.command(yargsNewCommand)
81+
.command(yargsPrintAffectedCommand)
7682
.command(yargsReleaseCommand)
7783
.command(yargsRepairCommand)
7884
.command(yargsReportCommand)

0 commit comments

Comments
 (0)