From c45e7786875a272e368d06ee7ab640f9ece13148 Mon Sep 17 00:00:00 2001 From: Hans Date: Tue, 24 Jul 2018 16:52:55 -0700 Subject: [PATCH] feat(@angular/cli): allow overrides on multi-target if builder is same It makes sense and is the only way to allow "ng lint --fix". If the builder is the same for all targets, overrides are allowed. --- .../angular/cli/models/architect-command.ts | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/packages/angular/cli/models/architect-command.ts b/packages/angular/cli/models/architect-command.ts index 67d37d1b99..7cf7aee772 100644 --- a/packages/angular/cli/models/architect-command.ts +++ b/packages/angular/cli/models/architect-command.ts @@ -11,7 +11,14 @@ import { BuilderDescription, TargetSpecifier, } from '@angular-devkit/architect'; -import { JsonObject, UnknownException, experimental, schema, strings } from '@angular-devkit/core'; +import { + JsonObject, + UnknownException, + experimental, + schema, + strings, + tags, +} from '@angular-devkit/core'; import { NodeJsSyncHost, createConsoleLogger } from '@angular-devkit/core/node'; import { of } from 'rxjs'; import { from } from 'rxjs'; @@ -88,8 +95,29 @@ export abstract class ArchitectCommand extends Command const projectNames = this.getProjectNamesByTarget(this.target); const { overrides } = this._makeTargetSpecifier(options); if (projectNames.length > 1 && Object.keys(overrides || {}).length > 0) { - throw new Error('Architect commands with multiple targets cannot specify overrides.' - + `'${this.target}' would be run on the following projects: ${projectNames.join()}`); + // Verify that all builders are the same, otherwise error out (since the meaning of an + // option could vary from builder to builder). + + const builders: string[] = []; + for (const projectName of projectNames) { + const targetSpec: TargetSpecifier = this._makeTargetSpecifier(options); + const targetDesc = this._architect.getBuilderConfiguration({ + project: projectName, + target: targetSpec.target, + }); + + if (builders.indexOf(targetDesc.builder) == -1) { + builders.push(targetDesc.builder); + } + } + + if (builders.length > 1) { + throw new Error(tags.oneLine` + Architect commands with command line overrides cannot target different builders. The + '${this.target}' target would run on projects ${projectNames.join()} which have the + following builders: ${'\n ' + builders.join('\n ')} + `); + } } }