From ee779a16a3820d5759c86455d35d8f27933cf152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Tue, 13 Feb 2024 12:26:17 +0100 Subject: [PATCH] fix(core): run migrations ordered by their target version --- packages/nx/src/command-line/migrate/migrate.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/nx/src/command-line/migrate/migrate.ts b/packages/nx/src/command-line/migrate/migrate.ts index d214f0eddb613..5365d28e3f2e5 100644 --- a/packages/nx/src/command-line/migrate/migrate.ts +++ b/packages/nx/src/command-line/migrate/migrate.ts @@ -1367,8 +1367,19 @@ export async function executeMigrations( const depsBeforeMigrations = getStringifiedPackageJsonDeps(root); const migrationsWithNoChanges: typeof migrations = []; + const sortedMigrations = migrations.sort((a, b) => { + // special case for the split configuration migration to run first + if (a.name === '15-7-0-split-configuration-into-project-json-files') { + return -1; + } + if (b.name === '15-7-0-split-configuration-into-project-json-files') { + return 1; + } + + return lt(a.version, b.version) ? -1 : 1; + }); - for (const m of migrations) { + for (const m of sortedMigrations) { try { const { collection, collectionPath } = readMigrationCollection( m.package,