Skip to content

Commit

Permalink
feat(@angular/cli): allow overrides on multi-target if builder is same
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hansl committed Jul 26, 2018
1 parent 14357e3 commit c45e778
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions packages/angular/cli/models/architect-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -88,8 +95,29 @@ export abstract class ArchitectCommand extends Command<ArchitectCommandOptions>
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 ')}
`);
}
}
}

Expand Down

0 comments on commit c45e778

Please sign in to comment.