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 #27766

(cherry picked from commit ce8b5a3)
  • Loading branch information
Platonn authored and dgp1130 committed Jun 4, 2024
1 parent 6526a5f commit b709d2a
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/lib@13.0.0`,
// 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 b709d2a

Please sign in to comment.