Skip to content

Commit 53d0278

Browse files
alan-agius4Keen Yee Liau
authored and
Keen Yee Liau
committed
fix(@angular-devkit/architect): error out when invalid configurations are provided
Fixes #14654
1 parent 8792ecd commit 53d0278

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

‎packages/angular_devkit/architect/node/node-modules-architect-host.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,11 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
104104
if (targetSpec === undefined) {
105105
return null;
106106
}
107-
if (target.configuration && !targetSpec['configurations']) {
108-
throw new Error('Configuration not set in the workspace.');
107+
if (
108+
target.configuration
109+
&& !(targetSpec['configurations'] && targetSpec['configurations'][target.configuration])
110+
) {
111+
throw new Error(`Configuration '${target.configuration}' is not set in the workspace.`);
109112
}
110113

111114
return {

‎packages/angular_devkit/architect/src/architect.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ export class Architect {
361361
options: json.JsonObject,
362362
scheduleOptions: ScheduleOptions = {},
363363
): Promise<BuilderRun> {
364-
if (!/^[^:]+:[^:]+$/.test(name)) {
364+
// The below will match 'project:target:configuration'
365+
if (!/^[^:]+:[^:]+(:[^:]+)?$/.test(name)) {
365366
throw new Error('Invalid builder name: ' + JSON.stringify(name));
366367
}
367368

‎packages/angular_devkit/architect/src/index_spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ describe('architect', () => {
106106
await run.stop();
107107
});
108108

109+
it(`errors when target configuration doesn't exists`, async () => {
110+
try {
111+
await architect.scheduleBuilder('test:test:invalid', {});
112+
throw new Error('should have thrown');
113+
} catch (err) {
114+
expect(err.message).toContain('Job name "test:test:invalid" does not exist.');
115+
}
116+
});
117+
109118
it('errors when builder cannot be resolved', async () => {
110119
try {
111120
await architect.scheduleBuilder('non:existent', {});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ng } from "../../utils/process";
2+
3+
export default async function () {
4+
try {
5+
await ng('build', '--configuration', 'invalid');
6+
throw new Error('should have failed.');
7+
} catch (error) {
8+
if (!error.message.includes(`Configuration 'invalid' is not set in the workspace`)) {
9+
throw error;
10+
}
11+
}
12+
};

0 commit comments

Comments
 (0)