From 48376c860ddf734c8c3ea230ef5bbb39f58f5230 Mon Sep 17 00:00:00 2001 From: Daniel Rose Date: Wed, 31 Jul 2024 15:16:06 +0200 Subject: [PATCH] feat(misc): add more logging while running migrations (#27063) --- .../src/lerna-smoke-tests.test.ts | 10 +++++++- .../nx/src/command-line/migrate/migrate.ts | 23 ++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/e2e/lerna-smoke-tests/src/lerna-smoke-tests.test.ts b/e2e/lerna-smoke-tests/src/lerna-smoke-tests.test.ts index 878276ac696f6..4b7b410ef6d95 100644 --- a/e2e/lerna-smoke-tests/src/lerna-smoke-tests.test.ts +++ b/e2e/lerna-smoke-tests/src/lerna-smoke-tests.test.ts @@ -39,7 +39,15 @@ describe('Lerna Smoke Tests', () => { // If this snapshot fails it means that nx repair generators are making assumptions which don't hold true for lerna workspaces it('should complete successfully on a new lerna workspace', async () => { let result = runLernaCLI(`repair`); - result = result.replace(/.*\/node_modules\/.*\n/, ''); // yarn adds "$ /node_modules/.bin/lerna repair" to the output + result = result + .replace(/.*\/node_modules\/.*\n/, '') // yarn adds "$ /node_modules/.bin/lerna repair" to the output + .replace( + /Running the following migrations:\n(?:.*\n)*---------------------------------------------------------\n\n/, + '' + ) // sorted list of all migrations to be run + .replace(/Running migration.*\n/g, '') // start of individual migration run + .replace(/Ran .* from .*\n .*\n\n/g, '') // end of individual migration run + .replace(/No changes were made\n\n/g, ''); // no changes during individual migration run expect(result).toMatchInlineSnapshot(` Lerna No changes were necessary. This workspace is up to date! diff --git a/packages/nx/src/command-line/migrate/migrate.ts b/packages/nx/src/command-line/migrate/migrate.ts index 83cd3708d65ae..9fdc7f6a733cb 100644 --- a/packages/nx/src/command-line/migrate/migrate.ts +++ b/packages/nx/src/command-line/migrate/migrate.ts @@ -1427,7 +1427,14 @@ export async function executeMigrations( : 1; }); + logger.info(`Running the following migrations:`); + sortedMigrations.forEach((m) => + logger.info(`- ${m.package}: ${m.name} (${m.description})`) + ); + logger.info(`---------------------------------------------------------\n`); + for (const m of sortedMigrations) { + logger.info(`Running migration ${m.package}: ${m.name}`); try { const { collection, collectionPath } = readMigrationCollection( m.package, @@ -1441,15 +1448,17 @@ export async function executeMigrations( m.name ); + logger.info(`Ran ${m.name} from ${m.package}`); + logger.info(` ${m.description}\n`); if (changes.length < 1) { + logger.info(`No changes were made\n`); migrationsWithNoChanges.push(m); - // If no changes are made, continue on without printing anything continue; } - logger.info(`Ran ${m.name} from ${m.package}`); - logger.info(` ${m.description}\n`); + logger.info('Changes:'); printChanges(changes, ' '); + logger.info(''); } else { const ngCliAdapter = await getNgCompatLayer(); const { madeChanges, loggingQueue } = await ngCliAdapter.runMigration( @@ -1462,15 +1471,17 @@ export async function executeMigrations( isVerbose ); + logger.info(`Ran ${m.name} from ${m.package}`); + logger.info(` ${m.description}\n`); if (!madeChanges) { + logger.info(`No changes were made\n`); migrationsWithNoChanges.push(m); - // If no changes are made, continue on without printing anything continue; } - logger.info(`Ran ${m.name} from ${m.package}`); - logger.info(` ${m.description}\n`); + logger.info('Changes:'); loggingQueue.forEach((log) => logger.info(' ' + log)); + logger.info(''); } if (shouldCreateCommits) {