Skip to content

Commit 8192276

Browse files
committed
fix(@angular/cli): add schema.json options to parsed command, also 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
1 parent aea9ea6 commit 8192276

File tree

1 file changed

+11
-1
lines changed
  • packages/angular/cli/src/commands/add

1 file changed

+11
-1
lines changed

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,17 @@ export default class AddCommandModule
346346
}
347347

348348
private async getCollectionName(): Promise<string> {
349-
const [, collectionName] = this.context.args.positional;
349+
let [, collectionName] = this.context.args.positional;
350+
351+
// The CLI argument may specify also a version, like `ng add @my/[email protected]`,
352+
// but here we need only the name of the package, like `@my/lib`.
353+
354+
const versionIdx = collectionName.lastIndexOf('@');
355+
// We assume any `@` character on the position other than 0 is a version separator.
356+
// We disregard the edge case of using npm package aliases, like `ng add alias-name@npm:real-name`.
357+
if (versionIdx > 0) {
358+
collectionName = collectionName.slice(0, versionIdx);
359+
}
350360

351361
return collectionName;
352362
}

0 commit comments

Comments
 (0)