Skip to content

Commit

Permalink
fix(@angular/cli): add schema.json options to parsed command, also …
Browse files Browse the repository at this point in the history
…when a version is passed to `ng add <package>@<version>`

This commit fixes the method `AddCommandModule.getCollectionName()`, so it now returns only the package name, but remove the specified version (if present).

Previously, a `@<version>` specified in the const `collectionName` was causing a (silenced) error during the invocation of `workflow.engine.createCollection(collectionName)`, which lead to skipping eventually the invocation of the method `this.addSchemaOptionsToCommand()` in the try/catch block.

fixes angular#27766
  • Loading branch information
Platonn committed Jun 4, 2024
1 parent aea9ea6 commit ae6e6a1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/angular/cli/src/commands/add/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,17 @@ export default class AddCommandModule
}

private async getCollectionName(): Promise<string> {
const [, collectionName] = this.context.args.positional;
let [, collectionName] = this.context.args.positional;

// The CLI argument may specify also a version, like `ng add @my/[email protected]`,
// but here we need only the name of the package, like `@my/lib`
try {
const packageIdentifier = npa(collectionName);
collectionName = packageIdentifier.name ?? collectionName;
} catch (e) {
assertIsError(e);
this.context.logger.error(e.message);
}

return collectionName;
}
Expand Down

0 comments on commit ae6e6a1

Please sign in to comment.