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): create structured project graph errors with all plugin er… #22404

Merged
merged 1 commit into from
Mar 21, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/generated/cli/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ Type: `boolean`

Untracked changes

##### verbose

Type: `boolean`

Prints additional information about the commands (e.g., stack traces)

##### version

Type: `boolean`
Expand Down Expand Up @@ -199,6 +205,12 @@ Type: `string`

Which project should be viewed?

##### verbose

Type: `boolean`

Prints additional information about the commands (e.g., stack traces)

##### version

Type: `boolean`
Expand Down
12 changes: 12 additions & 0 deletions docs/generated/packages/nx/documents/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ Type: `boolean`

Untracked changes

##### verbose

Type: `boolean`

Prints additional information about the commands (e.g., stack traces)

##### version

Type: `boolean`
Expand Down Expand Up @@ -199,6 +205,12 @@ Type: `string`

Which project should be viewed?

##### verbose

Type: `boolean`

Prints additional information about the commands (e.g., stack traces)

##### version

Type: `boolean`
Expand Down
111 changes: 78 additions & 33 deletions packages/nx/src/command-line/affected/command-object.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { boolean, CommandModule, middleware } from 'yargs';
import { CommandModule } from 'yargs';
import { linkToNxDevAndExamples } from '../yargs-utils/documentation';
import {
withAffectedOptions,
Expand All @@ -10,6 +10,7 @@ import {
withRunOptions,
withTargetAndConfigurationOption,
} from '../yargs-utils/shared-options';
import { handleErrors } from '../../utils/params';

export const yargsAffectedCommand: CommandModule = {
command: 'affected',
Expand All @@ -36,8 +37,17 @@ export const yargsAffectedCommand: CommandModule = {
}),
'affected'
),
handler: async (args) =>
(await import('./affected')).affected('affected', withOverrides(args)),
handler: async (args) => {
return handleErrors(
(args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true',
async () => {
return (await import('./affected')).affected(
'affected',
withOverrides(args)
);
}
);
},
};

export const yargsAffectedTestCommand: CommandModule = {
Expand All @@ -50,11 +60,17 @@ export const yargsAffectedTestCommand: CommandModule = {
),
'affected'
),
handler: async (args) =>
(await import('./affected')).affected('affected', {
...withOverrides(args),
target: 'test',
}),
handler: async (args) => {
return handleErrors(
(args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true',
async () => {
return (await import('./affected')).affected('affected', {
...withOverrides(args),
target: 'test',
});
}
);
},
};

export const yargsAffectedBuildCommand: CommandModule = {
Expand All @@ -67,11 +83,17 @@ export const yargsAffectedBuildCommand: CommandModule = {
),
'affected'
),
handler: async (args) =>
(await import('./affected')).affected('affected', {
...withOverrides(args),
target: 'build',
}),
handler: async (args) => {
return handleErrors(
(args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true',
async () => {
return (await import('./affected')).affected('affected', {
...withOverrides(args),
target: 'build',
});
}
);
},
};

export const yargsAffectedLintCommand: CommandModule = {
Expand All @@ -84,11 +106,17 @@ export const yargsAffectedLintCommand: CommandModule = {
),
'affected'
),
handler: async (args) =>
(await import('./affected')).affected('affected', {
...withOverrides(args),
target: 'lint',
}),
handler: async (args) => {
return handleErrors(
(args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true',
async () => {
return (await import('./affected')).affected('affected', {
...withOverrides(args),
target: 'lint',
});
}
);
},
};

export const yargsAffectedE2ECommand: CommandModule = {
Expand All @@ -101,11 +129,17 @@ export const yargsAffectedE2ECommand: CommandModule = {
),
'affected'
),
handler: async (args) =>
(await import('./affected')).affected('affected', {
...withOverrides(args),
target: 'e2e',
}),
handler: async (args) => {
return handleErrors(
(args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true',
async () => {
return (await import('./affected')).affected('affected', {
...withOverrides(args),
target: 'e2e',
});
}
);
},
};

export const affectedGraphDeprecationMessage =
Expand All @@ -122,12 +156,18 @@ export const yargsAffectedGraphCommand: CommandModule = {
withAffectedOptions(withDepGraphOptions(yargs)),
'affected:graph'
),
handler: async (args) =>
await (
await import('./affected')
).affected('graph', {
...args,
}),
handler: async (args) => {
return handleErrors(
(args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true',
async () => {
return await (
await import('./affected')
).affected('graph', {
...args,
});
}
);
},
deprecated: affectedGraphDeprecationMessage,
};

Expand Down Expand Up @@ -157,10 +197,15 @@ export const yargsPrintAffectedCommand: CommandModule = {
'Select the type of projects to be returned (e.g., --type=app)',
}),
handler: async (args) => {
await (
await import('./affected')
).affected('print-affected', withOverrides(args));
process.exit(0);
return handleErrors(
(args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true',
async () => {
await (
await import('./affected')
).affected('print-affected', withOverrides(args));
process.exit(0);
}
);
},
deprecated: printAffectedDeprecationMessage,
};
10 changes: 5 additions & 5 deletions packages/nx/src/command-line/generate/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ function throwInvalidInvocation(availableGenerators: string[]) {
)})`
);
}

export function printGenHelp(
opts: GenerateOptions,
schema: Schema,
Expand Down Expand Up @@ -306,12 +307,11 @@ export async function generate(cwd: string, args: { [k: string]: any }) {
}
const verbose = process.env.NX_VERBOSE_LOGGING === 'true';

const nxJsonConfiguration = readNxJson();
const projectGraph = await createProjectGraphAsync({ exitOnError: true });
const projectsConfigurations =
readProjectsConfigurationFromProjectGraph(projectGraph);

return handleErrors(verbose, async () => {
const nxJsonConfiguration = readNxJson();
const projectGraph = await createProjectGraphAsync();
const projectsConfigurations =
readProjectsConfigurationFromProjectGraph(projectGraph);
const opts = await convertToGenerateOptions(
args,
'generate',
Expand Down
8 changes: 7 additions & 1 deletion packages/nx/src/command-line/run-many/command-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
withOverrides,
withBatch,
} from '../yargs-utils/shared-options';
import { handleErrors } from '../../utils/params';

export const yargsRunManyCommand: CommandModule = {
command: 'run-many',
Expand All @@ -21,5 +22,10 @@ export const yargsRunManyCommand: CommandModule = {
'run-many'
),
handler: async (args) =>
(await import('./run-many')).runMany(withOverrides(args)),
await handleErrors(
(args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true',
async () => {
(await import('./run-many')).runMany(withOverrides(args));
}
),
};
21 changes: 18 additions & 3 deletions packages/nx/src/command-line/run/command-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
withOverrides,
withRunOneOptions,
} from '../yargs-utils/shared-options';
import { handleErrors } from '../../utils/params';

export const yargsRunCommand: CommandModule = {
command: 'run [project][:target][:configuration] [_..]',
Expand All @@ -16,7 +17,12 @@ export const yargsRunCommand: CommandModule = {
You can skip the use of Nx cache by using the --skip-nx-cache option.`,
builder: (yargs) => withRunOneOptions(withBatch(yargs)),
handler: async (args) =>
(await import('./run-one')).runOne(process.cwd(), withOverrides(args)),
await handleErrors(
(args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true',
async () => {
(await import('./run-one')).runOne(process.cwd(), withOverrides(args));
}
),
};

/**
Expand All @@ -26,6 +32,15 @@ export const yargsNxInfixCommand: CommandModule = {
...yargsRunCommand,
command: '$0 <target> [project] [_..]',
describe: 'Run a target for a project',
handler: async (args) =>
(await import('./run-one')).runOne(process.cwd(), withOverrides(args, 0)),
handler: async (args) => {
await handleErrors(
(args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true',
async () => {
return (await import('./run-one')).runOne(
process.cwd(),
withOverrides(args, 0)
);
}
);
},
};
2 changes: 1 addition & 1 deletion packages/nx/src/command-line/run/run-one.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function runOne(
workspaceConfigurationCheck();

const nxJson = readNxJson();
const projectGraph = await createProjectGraphAsync({ exitOnError: true });
const projectGraph = await createProjectGraphAsync();

const opts = parseRunOneOptions(cwd, args, projectGraph, nxJson);

Expand Down
31 changes: 29 additions & 2 deletions packages/nx/src/command-line/show/command-object.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ProjectGraphProjectNode } from '../../config/project-graph';
import { CommandModule, showHelp } from 'yargs';
import { parseCSV, withAffectedOptions } from '../yargs-utils/shared-options';
import { handleErrors } from '../../utils/params';

export interface NxShowArgs {
json?: boolean;
Expand All @@ -17,11 +18,13 @@ export type ShowProjectsOptions = NxShowArgs & {
type: ProjectGraphProjectNode['type'];
projects: string[];
withTarget: string[];
verbose: boolean;
};

export type ShowProjectOptions = NxShowArgs & {
projectName: string;
web?: boolean;
verbose: boolean;
};

export const yargsShowCommand: CommandModule<
Expand Down Expand Up @@ -83,6 +86,11 @@ const showProjectsCommand: CommandModule<NxShowArgs, ShowProjectsOptions> = {
description: 'Select only projects of the given type',
choices: ['app', 'lib', 'e2e'],
})
.option('verbose', {
type: 'boolean',
description:
'Prints additional information about the commands (e.g., stack traces)',
})
.implies('untracked', 'affected')
.implies('uncommitted', 'affected')
.implies('files', 'affected')
Expand All @@ -108,7 +116,14 @@ const showProjectsCommand: CommandModule<NxShowArgs, ShowProjectsOptions> = {
'$0 show projects --affected --exclude=*-e2e',
'Show affected projects in the workspace, excluding end-to-end projects'
) as any,
handler: (args) => import('./show').then((m) => m.showProjectsHandler(args)),
handler: (args) => {
return handleErrors(
args.verbose ?? process.env.NX_VERBOSE_LOGGING === 'true',
async () => {
return (await import('./show')).showProjectsHandler(args);
}
);
},
};

const showProjectCommand: CommandModule<NxShowArgs, ShowProjectOptions> = {
Expand All @@ -126,6 +141,11 @@ const showProjectCommand: CommandModule<NxShowArgs, ShowProjectOptions> = {
type: 'boolean',
description: 'Show project details in the browser',
})
.option('verbose', {
type: 'boolean',
description:
'Prints additional information about the commands (e.g., stack traces)',
})
.check((argv) => {
if (argv.web) {
argv.json = false;
Expand All @@ -136,5 +156,12 @@ const showProjectCommand: CommandModule<NxShowArgs, ShowProjectOptions> = {
'$0 show project my-app',
'View project information for my-app in JSON format'
),
handler: (args) => import('./show').then((m) => m.showProjectHandler(args)),
handler: (args) => {
return handleErrors(
args.verbose ?? process.env.NX_VERBOSE_LOGGING === 'true',
async () => {
return (await import('./show')).showProjectHandler(args);
}
);
},
};
Loading