From 85366d5cbe3ee82d6cbcb4b7ecb0a4ea7a3cbea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Tue, 25 Apr 2023 17:09:30 +0100 Subject: [PATCH] fix(core): handle symbol in migration path and infer angular material and cdk migration type correctly (#16538) --- packages/nx/src/command-line/migrate.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/nx/src/command-line/migrate.ts b/packages/nx/src/command-line/migrate.ts index c3c805d8b2a60..8a6cb9aa5410e 100644 --- a/packages/nx/src/command-line/migrate.ts +++ b/packages/nx/src/command-line/migrate.ts @@ -1543,8 +1543,12 @@ async function runNxMigration( collection: MigrationsJson, name: string ) { - const implPath = getImplementationPath(collection, collectionPath, name); - const fn = require(implPath).default; + const { path: implPath, fnSymbol } = getImplementationPath( + collection, + collectionPath, + name + ); + const fn = require(implPath)[fnSymbol]; const host = new FsTree(root, false); await fn(host, {}); host.lock(); @@ -1598,14 +1602,16 @@ function getImplementationPath( collection: MigrationsJson, collectionPath: string, name: string -) { +): { path: string; fnSymbol: string } { const g = collection.generators?.[name] || collection.schematics?.[name]; if (!g) { throw new Error( `Unable to determine implementation path for "${collectionPath}:${name}"` ); } - const implRelativePath = g.implementation || g.factory; + const implRelativePathAndMaybeSymbol = g.implementation || g.factory; + const [implRelativePath, fnSymbol = 'default'] = + implRelativePathAndMaybeSymbol.split('#'); let implPath: string; @@ -1620,7 +1626,7 @@ function getImplementationPath( ); } - return implPath; + return { path: implPath, fnSymbol }; } // TODO (v17): This should just become something like: @@ -1643,7 +1649,7 @@ function isAngularMigration( const shouldBeNg = !!collection.schematics?.[name]; let useAngularDevkitToRunMigration = false; - const implementationPath = getImplementationPath( + const { path: implementationPath } = getImplementationPath( collection, collectionPath, name @@ -1651,6 +1657,7 @@ function isAngularMigration( 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',