Skip to content

Commit 5c56cdb

Browse files
committed
refactor(@angular/cli): handle undefined ng add collection name
Fixes an issue where JSON help extraction fails if the `ng add` collection name is undefined. (cherry picked from commit f5689e9)
1 parent 71ae86a commit 5c56cdb

File tree

1 file changed

+15
-6
lines changed
  • packages/angular/cli/src/commands/add

1 file changed

+15
-6
lines changed

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

+15-6
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ export default class AddCommandModule
100100
// `ng add @angular/localize -- --package-options`.
101101
.strict(false);
102102

103-
const collectionName = await this.getCollectionName();
103+
const collectionName = this.getCollectionName();
104+
if (!collectionName) {
105+
return localYargs;
106+
}
107+
104108
const workflow = this.getOrCreateWorkflowForBuilder(collectionName);
105109

106110
try {
@@ -401,14 +405,19 @@ export default class AddCommandModule
401405
return false;
402406
}
403407

404-
private async getCollectionName(): Promise<string> {
405-
let [, collectionName] = this.context.args.positional;
408+
private getCollectionName(): string | undefined {
409+
const [, collectionName] = this.context.args.positional;
410+
if (!collectionName) {
411+
return undefined;
412+
}
406413

407414
// The CLI argument may specify also a version, like `ng add @my/[email protected]`,
408-
// but here we need only the name of the package, like `@my/lib`
415+
// but here we need only the name of the package, like `@my/lib`.
409416
try {
410-
const packageIdentifier = npa(collectionName);
411-
collectionName = packageIdentifier.name ?? collectionName;
417+
const packageName = npa(collectionName).name;
418+
if (packageName) {
419+
return packageName;
420+
}
412421
} catch (e) {
413422
assertIsError(e);
414423
this.context.logger.error(e.message);

0 commit comments

Comments
 (0)