diff --git a/packages/nx/src/command-line/migrate/migrate.ts b/packages/nx/src/command-line/migrate/migrate.ts index 517fbf0b9756d..c7f3568b42ebe 100644 --- a/packages/nx/src/command-line/migrate/migrate.ts +++ b/packages/nx/src/command-line/migrate/migrate.ts @@ -1699,62 +1699,21 @@ function getImplementationPath( return { path: implPath, fnSymbol }; } -// TODO (v17): This should just become something like: -// ``` -// return !collection.generators[name] && collection.schematics[name] -// ``` +// TODO (v21): Remove CLI determination of Angular Migration function isAngularMigration( collection: MigrationsJson, collectionPath: string, name: string ) { const entry = collection.generators?.[name] || collection.schematics?.[name]; - - // In the future we will determine this based on the location of the entry in the collection. - // If the entry is under `schematics`, it will be assumed to be an angular cli migration. - // If the entry is under `generators`, it will be assumed to be an nx migration. - // For now, we will continue to obey the cli property, if it exists. - // If it doesn't exist, we will check if the implementation references @angular/devkit. const shouldBeNx = !!collection.generators?.[name]; const shouldBeNg = !!collection.schematics?.[name]; - let useAngularDevkitToRunMigration = false; - - const { path: implementationPath } = getImplementationPath( - collection, - collectionPath, - name - ); - const implStringContents = readFileSync(implementationPath, 'utf-8'); - // TODO (v17): Remove this check and the cli property access - it is only here for backwards compatibility. - if ( - ['@angular/material', '@angular/cdk'].includes(collection.name) || - [ - "import('@angular-devkit", - 'import("@angular-devkit', - "require('@angular-devkit", - 'require("@angular-devkit', - "from '@angular-devkit", - 'from "@angular-devkit', - ].some((s) => implStringContents.includes(s)) - ) { - useAngularDevkitToRunMigration = true; - } - - if (useAngularDevkitToRunMigration && shouldBeNx) { + if (entry.cli && entry.cli !== 'nx' && collection.generators?.[name]) { output.warn({ title: `The migration '${collection.name}:${name}' appears to be an Angular CLI migration, but is located in the 'generators' section of migrations.json.`, bodyLines: [ - 'In Nx 17, migrations inside `generators` will be treated as Angular Devkit migrations.', - "Please open an issue on the plugin's repository if you believe this is an error.", - ], - }); - } - - if (!useAngularDevkitToRunMigration && entry.cli === 'nx' && shouldBeNg) { - output.warn({ - title: `The migration '${collection.name}:${name}' appears to be an Nx migration, but is located in the 'schematics' section of migrations.json.`, - bodyLines: [ - 'In Nx 17, migrations inside `generators` will be treated as nx devkit migrations.', + 'In Nx 21, migrations inside `generators` will be treated as Nx Devkit migrations and therefore may not run correctly if they are using Angular Devkit.', + 'If the migration should be run with Angular Devkit, please place the migration inside `schematics` instead.', "Please open an issue on the plugin's repository if you believe this is an error.", ], }); @@ -1762,7 +1721,7 @@ function isAngularMigration( // Currently, if the cli property exists we listen to it. If its nx, its not an ng cli migration. // If the property is not set, we will fall back to our intuition. - return entry.cli ? entry.cli !== 'nx' : useAngularDevkitToRunMigration; + return entry.cli ? entry.cli !== 'nx' : !shouldBeNx && shouldBeNg; } const getNgCompatLayer = (() => {