Skip to content

Commit

Permalink
feat(core): improve sync messages
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Dec 2, 2024
1 parent 06d549b commit beffe43
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export async function syncGenerator(tree: Tree): Promise<SyncGeneratorResult> {

return {
outOfSyncMessage:
'Based on the workspace project graph, some TypeScript configuration files are missing project references to the projects they depend on or contain outdated project references.',
'Some TypeScript configuration files are missing project references to the projects they depend on or contain outdated project references.',
};
}
}
Expand Down
9 changes: 3 additions & 6 deletions packages/nx/src/command-line/sync/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ export function syncHandler(options: SyncOptions): Promise<number> {
? 'The workspace is up to date'
: 'The workspace is already up to date',
bodyLines: syncGenerators.map(
(generator) =>
`The ${chalk.bold(
generator
)} sync generator didn't identify any files in the workspace that are out of sync.`
(generator) => `[${chalk.bold(generator)}]: All files are up to date.`
),
});
return 0;
Expand Down Expand Up @@ -133,9 +130,9 @@ export function syncHandler(options: SyncOptions): Promise<number> {
'Syncing the workspace failed with the following error:',
'',
e.message,
...(options.verbose && !!e.stack ? [`\n${e.stack}`] : []),
...(!!e.stack ? [`\n${e.stack}`] : []),
'',
'Please rerun with `--verbose` and report the error at: https://github.com/nrwl/nx/issues/new/choose',
'Please report the error at: https://github.com/nrwl/nx/issues/new/choose',
],
});

Expand Down
5 changes: 2 additions & 3 deletions packages/nx/src/tasks-runner/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,8 @@ async function ensureWorkspaceIsInSyncAndGetGraphs(
const outOfSyncTitle = 'The workspace is out of sync';
const resultBodyLines = getSyncGeneratorSuccessResultsMessageLines(results);
const fixMessage =
'You can manually run `nx sync` to update your workspace with the identified changes or you can set `sync.applyChanges` to `true` in your `nx.json` to apply the changes automatically when running tasks in interactive environments.';
const willErrorOnCiMessage =
'Please note that having the workspace out of sync will result in an error in CI.';
'Make sure to run `nx sync` to apply the identified changes or set `sync.applyChanges` to `true` in your `nx.json` to apply them automatically when running tasks in interactive environments.';
const willErrorOnCiMessage = 'This will result in an error in CI.';

if (isCI() || !process.stdout.isTTY) {
// If the user is running in CI or is running in a non-TTY environment we
Expand Down
45 changes: 17 additions & 28 deletions packages/nx/src/utils/sync-generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,10 @@ export function getSyncGeneratorSuccessResultsMessageLines(
}

messageLines.push(
`The ${chalk.bold(
result.generatorName
)} sync generator identified ${chalk.bold(result.changes.length)} file${
result.changes.length === 1 ? '' : 's'
} in the workspace that ${
result.changes.length === 1 ? 'is' : 'are'
} out of sync${result.outOfSyncMessage ? ':' : '.'}`
`[${chalk.bold(result.generatorName)}]: ${
result.outOfSyncMessage ?? `Some files are out of sync.`
}`
);
if (result.outOfSyncMessage) {
messageLines.push(result.outOfSyncMessage);
}
}

return messageLines;
Expand All @@ -295,16 +288,15 @@ export function getFailedSyncGeneratorsFixMessageLines(
let isFirst = true;
for (const result of results) {
if ('error' in result) {
if (!isFirst) {
if (!isFirst && verbose) {
messageLines.push('');
}
isFirst = false;
messageLines.push(
`The ${chalk.bold(
result.generatorName
)} sync generator reported the following error:`,
'',
errorToString(result.error, verbose)
`[${chalk.bold(result.generatorName)}]: ${errorToString(
result.error,
verbose
)}`
);

if (globalGeneratorSet.has(result.generatorName)) {
Expand Down Expand Up @@ -336,16 +328,15 @@ export function getFlushFailureMessageLines(
const taskGenerators: string[] = [];
let isFirst = true;
for (const failure of result.generatorFailures) {
if (!isFirst) {
if (!isFirst && verbose) {
messageLines.push('');
}
isFirst = false;
messageLines.push(
`The ${chalk.bold(
failure.generator
)} sync generator failed to apply its changes with the following error:`,
'',
errorToString(failure.error, verbose)
`[${chalk.bold(failure.generator)}]: ${errorToString(
failure.error,
verbose
)}`
);

if (globalGeneratorSet.has(failure.generator)) {
Expand Down Expand Up @@ -375,13 +366,11 @@ export function getFlushFailureMessageLines(
...[
'',
result.generalFailure.message,
...(verbose && !!result.generalFailure.stack
...(!!result.generalFailure.stack
? [`\n${result.generalFailure.stack}`]
: []),
'',
verbose
? 'Please report the error at: https://github.com/nrwl/nx/issues/new/choose'
: 'Please run with `--verbose` and report the error at: https://github.com/nrwl/nx/issues/new/choose',
'Please report the error at: https://github.com/nrwl/nx/issues/new/choose',
]
);
}
Expand Down Expand Up @@ -545,7 +534,7 @@ function getFailedSyncGeneratorsMessageLines(

function errorToString(error: SerializableSimpleError, verbose: boolean) {
if (error.title) {
let message = ` ${chalk.red(error.title)}`;
let message = `${chalk.red(error.title)}`;
if (error.bodyLines?.length) {
message += `
Expand All @@ -557,7 +546,7 @@ function errorToString(error: SerializableSimpleError, verbose: boolean) {
}
}

return ` ${chalk.red(error.message)}${
return `${chalk.red(error.message)}${
verbose && error.stack ? '\n ' + error.stack : ''
}`;
}
Expand Down

0 comments on commit beffe43

Please sign in to comment.