From c2a09d0dc9be5aab890c52dea34e1723fc055b0b Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 21 Sep 2018 12:38:36 +0200 Subject: [PATCH] fix(@angular/cli): cannot use same target name in when having multiple projects Closes #12320 --- packages/angular/cli/models/architect-command.ts | 9 ++++++--- .../e2e/tests/misc/multiple-targets.ts | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 tests/legacy-cli/e2e/tests/misc/multiple-targets.ts diff --git a/packages/angular/cli/models/architect-command.ts b/packages/angular/cli/models/architect-command.ts index 184dfc8d450a..b7d89a0b2421 100644 --- a/packages/angular/cli/models/architect-command.ts +++ b/packages/angular/cli/models/architect-command.ts @@ -103,10 +103,13 @@ export abstract class ArchitectCommand< if (this.target) { // Add options IF there's only one builder of this kind. - const projectNames = this.getProjectNamesByTarget(this.target); + const targetSpec: TargetSpecifier = this._makeTargetSpecifier(options); + const projectNames = targetSpec.project + ? [targetSpec.project] + : this.getProjectNamesByTarget(this.target); + const builderConfigurations: BuilderConfiguration[] = []; for (const projectName of projectNames) { - const targetSpec: TargetSpecifier = this._makeTargetSpecifier(options); const targetDesc = this._architect.getBuilderConfiguration({ project: projectName, target: targetSpec.target, @@ -207,7 +210,7 @@ export abstract class ArchitectCommand< // For multi target commands, we always list all projects that have the target. return allProjectsForTargetName; } else { - // For single target commands, we try try the default project project first, + // For single target commands, we try the default project first, // then the full list if it has a single project, then error out. const maybeDefaultProject = this._workspace.getDefaultProjectName(); if (maybeDefaultProject && allProjectsForTargetName.includes(maybeDefaultProject)) { diff --git a/tests/legacy-cli/e2e/tests/misc/multiple-targets.ts b/tests/legacy-cli/e2e/tests/misc/multiple-targets.ts new file mode 100644 index 000000000000..58c92dcfea7d --- /dev/null +++ b/tests/legacy-cli/e2e/tests/misc/multiple-targets.ts @@ -0,0 +1,16 @@ +import { expectFileToExist } from '../../utils/fs'; +import { ng } from '../../utils/process'; +import { updateJsonFile } from '../../utils/project'; + +export default async function () { + await ng('generate', 'app', 'secondary-app'); + + await updateJsonFile('angular.json', workspaceJson => { + workspaceJson.defaultProject = undefined; + }); + + await ng('build', 'secondary-app'); + + expectFileToExist('dist/secondary-app/index.html'); + expectFileToExist('dist/secondary-app/main.js'); +}