From ab0075254a44c0995968594be8fc179c7a1de361 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Tue, 7 Jun 2022 19:29:18 -0400 Subject: [PATCH] fix(misc): fix printing duplicate generators that are actually extensions (#10625) --- packages/nx/src/command-line/generate.ts | 23 ++++++++++++----------- packages/nx/src/config/workspaces.ts | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/packages/nx/src/command-line/generate.ts b/packages/nx/src/command-line/generate.ts index c0383f241f171..470ce59123314 100644 --- a/packages/nx/src/command-line/generate.ts +++ b/packages/nx/src/command-line/generate.ts @@ -48,17 +48,18 @@ async function promptForCollection( ...Object.keys(packageJson.devDependencies || {}), ]) ); - const choices = collections - .map((collectionName) => { - try { - const generator = ws.readGenerator(collectionName, generatorName); - - return `${collectionName}:${generator.normalizedGeneratorName}`; - } catch { - return null; - } - }) - .filter((c) => !!c); + const choicesMap = new Set(); + + for (const collectionName of collections) { + try { + const { resolvedCollectionName, normalizedGeneratorName } = + ws.readGenerator(collectionName, generatorName); + + choicesMap.add(`${resolvedCollectionName}:${normalizedGeneratorName}`); + } catch {} + } + + const choices = Array.from(choicesMap); if (choices.length === 1) { return choices[0]; diff --git a/packages/nx/src/config/workspaces.ts b/packages/nx/src/config/workspaces.ts index e754c6ad4006d..e042abed672ca 100644 --- a/packages/nx/src/config/workspaces.ts +++ b/packages/nx/src/config/workspaces.ts @@ -147,8 +147,12 @@ export class Workspaces { readGenerator(collectionName: string, generatorName: string) { try { - const { generatorsFilePath, generatorsJson, normalizedGeneratorName } = - this.readGeneratorsJson(collectionName, generatorName); + const { + generatorsFilePath, + generatorsJson, + resolvedCollectionName, + normalizedGeneratorName, + } = this.readGeneratorsJson(collectionName, generatorName); const generatorsDir = path.dirname(generatorsFilePath); const generatorConfig = generatorsJson.generators?.[normalizedGeneratorName] || @@ -165,6 +169,7 @@ export class Workspaces { generatorsDir ); return { + resolvedCollectionName, normalizedGeneratorName, schema, implementationFactory, @@ -253,6 +258,7 @@ export class Workspaces { generatorsFilePath: string; generatorsJson: GeneratorsJson; normalizedGeneratorName: string; + resolvedCollectionName: string; } { let generatorsFilePath; if (collectionName.endsWith('.json')) { @@ -291,7 +297,12 @@ export class Workspaces { `Cannot find generator '${generator}' in ${generatorsFilePath}.` ); } - return { generatorsFilePath, generatorsJson, normalizedGeneratorName }; + return { + generatorsFilePath, + generatorsJson, + normalizedGeneratorName, + resolvedCollectionName: collectionName, + }; } private resolvePaths() {