From 5a012b5fce2f38fa6b97c84c874e85dc726d2f0d Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 27 Jun 2022 08:09:08 +0000 Subject: [PATCH] fix(@angular/cli): correctly handle `--collection` option in `ng new` Previously, this option was ignored due to an incorrect deconstruction. Closes #23414 --- packages/angular/cli/src/commands/new/cli.ts | 2 +- .../e2e/tests/commands/ng-new-collection.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/legacy-cli/e2e/tests/commands/ng-new-collection.ts diff --git a/packages/angular/cli/src/commands/new/cli.ts b/packages/angular/cli/src/commands/new/cli.ts index 1d4b39f3e462..e5014dac3753 100644 --- a/packages/angular/cli/src/commands/new/cli.ts +++ b/packages/angular/cli/src/commands/new/cli.ts @@ -45,7 +45,7 @@ export class NewCommandModule }); const { - options: { collectionNameFromArgs }, + options: { collection: collectionNameFromArgs }, } = this.context.args; const collectionName = diff --git a/tests/legacy-cli/e2e/tests/commands/ng-new-collection.ts b/tests/legacy-cli/e2e/tests/commands/ng-new-collection.ts new file mode 100644 index 000000000000..e55c75ee69b4 --- /dev/null +++ b/tests/legacy-cli/e2e/tests/commands/ng-new-collection.ts @@ -0,0 +1,19 @@ +import { execAndWaitForOutputToMatch } from '../../utils/process'; + +export default async function () { + const currentDirectory = process.cwd(); + + try { + process.chdir('..'); + + // The below is a way to validate that the `--collection` option is being considered. + await execAndWaitForOutputToMatch( + 'ng', + ['new', '--collection', 'invalid-schematic'], + /Collection "invalid-schematic" cannot be resolved/, + ); + } finally { + // Change directory back + process.chdir(currentDirectory); + } +}