Skip to content

Commit b5737ef

Browse files
alan-agius4angular-robot[bot]
authored andcommitted
fix(@angular/cli): handle extended schematics when retrieving aliases
Previously base collections where not being taken into account and the recent changes caused an exception ``` An unhandled exception occurred: Cannot destructure property 'aliases' of 'collection.description.schematics[schematicName]' as it is undefined. ``` See: https://angular-team.slack.com/archives/CHEEH2LCA/p1674122139247359
1 parent f7c78dd commit b5737ef

File tree

1 file changed

+34
-6
lines changed
  • packages/angular/cli/src/commands/generate

1 file changed

+34
-6
lines changed

packages/angular/cli/src/commands/generate/cli.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
*/
88

99
import { strings } from '@angular-devkit/core';
10+
import { Collection } from '@angular-devkit/schematics';
11+
import {
12+
FileSystemCollectionDescription,
13+
FileSystemSchematicDescription,
14+
} from '@angular-devkit/schematics/tools';
1015
import { Argv } from 'yargs';
1116
import {
1217
CommandModuleError,
@@ -69,7 +74,6 @@ export class GenerateCommandModule
6974
const {
7075
'x-deprecated': xDeprecated,
7176
description = schematicDescription,
72-
aliases = schematicAliases,
7377
hidden = schematicHidden,
7478
} = schemaJson;
7579
const options = await this.getSchematicOptions(collection, schematicName, workflow);
@@ -79,8 +83,8 @@ export class GenerateCommandModule
7983
// When 'describe' is set to false, it results in a hidden command.
8084
describe: hidden === true ? false : typeof description === 'string' ? description : '',
8185
deprecated: xDeprecated === true || typeof xDeprecated === 'string' ? xDeprecated : false,
82-
aliases: Array.isArray(aliases)
83-
? await this.generateCommandAliasesStrings(collectionName, aliases as string[])
86+
aliases: Array.isArray(schematicAliases)
87+
? await this.generateCommandAliasesStrings(collectionName, schematicAliases)
8488
: undefined,
8589
builder: (localYargs) => this.addSchemaOptionsToCommand(localYargs, options).strict(),
8690
handler: (options) =>
@@ -205,13 +209,37 @@ export class GenerateCommandModule
205209
// If a schematic with this same name is already registered skip.
206210
if (!seenNames.has(schematicName)) {
207211
seenNames.add(schematicName);
208-
const { aliases } = collection.description.schematics[schematicName];
209-
const schematicAliases = aliases && new Set(aliases);
210212

211-
yield { schematicName, schematicAliases, collectionName };
213+
yield {
214+
schematicName,
215+
collectionName,
216+
schematicAliases: this.listSchematicAliases(collection, schematicName),
217+
};
218+
}
219+
}
220+
}
221+
}
222+
223+
private listSchematicAliases(
224+
collection: Collection<FileSystemCollectionDescription, FileSystemSchematicDescription>,
225+
schematicName: string,
226+
): Set<string> | undefined {
227+
const description = collection.description.schematics[schematicName];
228+
if (description) {
229+
return description.aliases && new Set(description.aliases);
230+
}
231+
232+
// Extended collections
233+
if (collection.baseDescriptions) {
234+
for (const base of collection.baseDescriptions) {
235+
const description = base.schematics[schematicName];
236+
if (description) {
237+
return description.aliases && new Set(description.aliases);
212238
}
213239
}
214240
}
241+
242+
return undefined;
215243
}
216244

217245
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy