Skip to content

Commit 3773787

Browse files
committed
fix(@angular/cli): add support for passing version to ng add
1 parent 729d407 commit 3773787

File tree

1 file changed

+12
-5
lines changed
  • packages/@angular/cli/commands

1 file changed

+12
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ export default class AddCommand extends SchematicCommand {
4343
}
4444

4545
async run(options: any) {
46-
const collectionName = options._[0];
46+
const firstArg = options._[0];
4747

48-
if (!collectionName) {
48+
if (!firstArg) {
4949
throw new SilentError(
5050
`The "ng ${this.name}" command requires a name argument to be specified eg. `
5151
+ `${terminal.yellow('ng add [name] ')}. For more details, use "ng help".`
@@ -56,9 +56,16 @@ export default class AddCommand extends SchematicCommand {
5656

5757
const npmInstall: NpmInstall = require('../tasks/npm-install').default;
5858

59-
const packageName = collectionName.startsWith('@')
60-
? collectionName.split('/', 2).join('/')
61-
: collectionName.split('/', 1)[0];
59+
const packageName = firstArg.startsWith('@')
60+
? firstArg.split('/', 2).join('/')
61+
: firstArg.split('/', 1)[0];
62+
63+
// Remove the tag/version from the package name.
64+
const collectionName = (
65+
packageName.startsWith('@')
66+
? packageName.split('@', 2).join('@')
67+
: packageName.split('@', 1).join('@')
68+
) + firstArg.slice(packageName.length);
6269

6370
// We don't actually add the package to package.json, that would be the work of the package
6471
// itself.

0 commit comments

Comments
 (0)