Skip to content

Commit c45e778

Browse files
committed
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.
1 parent 14357e3 commit c45e778

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

packages/angular/cli/models/architect-command.ts

+31-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ import {
1111
BuilderDescription,
1212
TargetSpecifier,
1313
} from '@angular-devkit/architect';
14-
import { JsonObject, UnknownException, experimental, schema, strings } from '@angular-devkit/core';
14+
import {
15+
JsonObject,
16+
UnknownException,
17+
experimental,
18+
schema,
19+
strings,
20+
tags,
21+
} from '@angular-devkit/core';
1522
import { NodeJsSyncHost, createConsoleLogger } from '@angular-devkit/core/node';
1623
import { of } from 'rxjs';
1724
import { from } from 'rxjs';
@@ -88,8 +95,29 @@ export abstract class ArchitectCommand extends Command<ArchitectCommandOptions>
8895
const projectNames = this.getProjectNamesByTarget(this.target);
8996
const { overrides } = this._makeTargetSpecifier(options);
9097
if (projectNames.length > 1 && Object.keys(overrides || {}).length > 0) {
91-
throw new Error('Architect commands with multiple targets cannot specify overrides.'
92-
+ `'${this.target}' would be run on the following projects: ${projectNames.join()}`);
98+
// Verify that all builders are the same, otherwise error out (since the meaning of an
99+
// option could vary from builder to builder).
100+
101+
const builders: string[] = [];
102+
for (const projectName of projectNames) {
103+
const targetSpec: TargetSpecifier = this._makeTargetSpecifier(options);
104+
const targetDesc = this._architect.getBuilderConfiguration({
105+
project: projectName,
106+
target: targetSpec.target,
107+
});
108+
109+
if (builders.indexOf(targetDesc.builder) == -1) {
110+
builders.push(targetDesc.builder);
111+
}
112+
}
113+
114+
if (builders.length > 1) {
115+
throw new Error(tags.oneLine`
116+
Architect commands with command line overrides cannot target different builders. The
117+
'${this.target}' target would run on projects ${projectNames.join()} which have the
118+
following builders: ${'\n ' + builders.join('\n ')}
119+
`);
120+
}
93121
}
94122
}
95123

0 commit comments

Comments
 (0)