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(misc): add more logging while running migrations #27063

Merged
merged 1 commit into from
Jul 31, 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
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