Skip to content

Commit

Permalink
feat(misc): add more logging while running migrations (nrwl#27063)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRose authored and ZackDeRose committed Aug 8, 2024
1 parent 1497f5f commit 48376c8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
10 changes: 9 additions & 1 deletion e2e/lerna-smoke-tests/src/lerna-smoke-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
23 changes: 17 additions & 6 deletions packages/nx/src/command-line/migrate/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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) {
Expand Down

0 comments on commit 48376c8

Please sign in to comment.