From ce8b5a3a745062f926491d5a299df728b7de8790 Mon Sep 17 00:00:00 2001 From: Krzysztof Platis Date: Mon, 3 Jun 2024 15:43:59 +0200 Subject: [PATCH] fix(@angular/cli): add `schema.json` options to parsed command, also when a version is passed to `ng add @` This commit fixes the method `AddCommandModule.getCollectionName()`, so it now returns only the package name, but remove the specified version (if present). Previously, a `@` 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 https://github.com/angular/angular-cli/issues/27766 --- packages/angular/cli/src/commands/add/cli.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/angular/cli/src/commands/add/cli.ts b/packages/angular/cli/src/commands/add/cli.ts index 5aaabbcd7ea4..5e55385d9984 100644 --- a/packages/angular/cli/src/commands/add/cli.ts +++ b/packages/angular/cli/src/commands/add/cli.ts @@ -346,7 +346,17 @@ export default class AddCommandModule } private async getCollectionName(): Promise { - 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; }