Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(misc): fix printing duplicate generators that are actually extens… #10625

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 12 additions & 11 deletions packages/nx/src/command-line/generate.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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