Skip to content

Commit

Permalink
fix(misc): fix printing duplicate generators that are actually extens…
Browse files Browse the repository at this point in the history
…ions (#10625)
  • Loading branch information
FrozenPandaz committed Jun 7, 2022
1 parent adec3e0 commit ab00752
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
23 changes: 12 additions & 11 deletions packages/nx/src/command-line/generate.ts
Expand Up @@ -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<string>();

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];
Expand Down
17 changes: 14 additions & 3 deletions packages/nx/src/config/workspaces.ts
Expand Up @@ -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] ||
Expand All @@ -165,6 +169,7 @@ export class Workspaces {
generatorsDir
);
return {
resolvedCollectionName,
normalizedGeneratorName,
schema,
implementationFactory,
Expand Down Expand Up @@ -253,6 +258,7 @@ export class Workspaces {
generatorsFilePath: string;
generatorsJson: GeneratorsJson;
normalizedGeneratorName: string;
resolvedCollectionName: string;
} {
let generatorsFilePath;
if (collectionName.endsWith('.json')) {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit ab00752

Please sign in to comment.