From beffe43c45e5f766967c2c47f7c7080eadeee37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Mon, 2 Dec 2024 15:46:12 +0100 Subject: [PATCH] feat(core): improve sync messages --- .../typescript-sync/typescript-sync.ts | 2 +- packages/nx/src/command-line/sync/sync.ts | 9 ++-- packages/nx/src/tasks-runner/run-command.ts | 5 +-- packages/nx/src/utils/sync-generators.ts | 45 +++++++------------ 4 files changed, 23 insertions(+), 38 deletions(-) diff --git a/packages/js/src/generators/typescript-sync/typescript-sync.ts b/packages/js/src/generators/typescript-sync/typescript-sync.ts index 1b0936ac258d8..96ffe40f9627c 100644 --- a/packages/js/src/generators/typescript-sync/typescript-sync.ts +++ b/packages/js/src/generators/typescript-sync/typescript-sync.ts @@ -261,7 +261,7 @@ export async function syncGenerator(tree: Tree): Promise { 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.', }; } } diff --git a/packages/nx/src/command-line/sync/sync.ts b/packages/nx/src/command-line/sync/sync.ts index 663635f57d789..0e187bcba6a61 100644 --- a/packages/nx/src/command-line/sync/sync.ts +++ b/packages/nx/src/command-line/sync/sync.ts @@ -47,10 +47,7 @@ export function syncHandler(options: SyncOptions): Promise { ? '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; @@ -133,9 +130,9 @@ export function syncHandler(options: SyncOptions): Promise { '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', ], }); diff --git a/packages/nx/src/tasks-runner/run-command.ts b/packages/nx/src/tasks-runner/run-command.ts index 9730060cce9e0..cae85b256e199 100644 --- a/packages/nx/src/tasks-runner/run-command.ts +++ b/packages/nx/src/tasks-runner/run-command.ts @@ -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 diff --git a/packages/nx/src/utils/sync-generators.ts b/packages/nx/src/utils/sync-generators.ts index 68fac7d42e173..318cea9221dae 100644 --- a/packages/nx/src/utils/sync-generators.ts +++ b/packages/nx/src/utils/sync-generators.ts @@ -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; @@ -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)) { @@ -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)) { @@ -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', ] ); } @@ -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 += ` @@ -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 : '' }`; }