Skip to content

Commit 1c22f7f

Browse files
committed
fix(core): throw when invalid config is provided for initiating project
1 parent 36282e1 commit 1c22f7f

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

e2e/workspace/src/workspace.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ describe('run-one', () => {
4444
`
4545
);
4646

47+
// configuration has to be valid for the initiating project
48+
expect(() => runCLI(`build ${myapp} -c=invalid`)).toThrow();
49+
50+
// configuration doesn't have to exists for deps (here only the app has production)
4751
const buildWithDeps = runCLI(`build ${myapp} --with-deps --prod`);
4852
expect(buildWithDeps).toContain(`Running target "build" succeeded`);
4953
expect(buildWithDeps).toContain(`nx run ${myapp}:build:production`);

packages/cli/lib/parse-run-one-options.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export function parseRunOneOptions(
1717
const parsedArgs = yargsParser(args, {
1818
boolean: ['prod', 'help'],
1919
string: ['configuration', 'project'],
20+
alias: {
21+
c: 'configuration',
22+
},
2023
});
2124

2225
if (parsedArgs['help']) {
@@ -63,6 +66,7 @@ export function parseRunOneOptions(
6366
if (!targets || !targets[target]) return false;
6467

6568
const res = { project, target, configuration, parsedArgs };
69+
delete parsedArgs['c'];
6670
delete parsedArgs['configuration'];
6771
delete parsedArgs['prod'];
6872
delete parsedArgs['project'];

packages/workspace/src/command-line/print-affected.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function createTasks(
4545
target: nxArgs.target,
4646
configuration: nxArgs.configuration,
4747
overrides: overrides,
48+
errorIfCannotFindConfiguration: false,
4849
})
4950
);
5051
const isYarn = basename(process.env.npm_execpath || 'npm').startsWith('yarn');

packages/workspace/src/tasks-runner/run-command.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { NxArgs } from '@nrwl/workspace/src/command-line/utils';
99
import { isRelativePath } from '../utils/fileutils';
1010
import { Hasher } from '../core/hasher/hasher';
1111
import { projectHasTargetAndConfiguration } from '../utils/project-graph-utils';
12+
import { output } from '../utils/output';
1213

1314
type RunArgs = yargs.Arguments & ReporterArgs;
1415

@@ -38,6 +39,7 @@ export async function runCommand<T extends RunArgs>(
3839
target: nxArgs.target,
3940
configuration: nxArgs.configuration,
4041
overrides: overrides,
42+
errorIfCannotFindConfiguration: project.name === initiatingProject,
4143
});
4244
});
4345

@@ -87,18 +89,20 @@ export async function runCommand<T extends RunArgs>(
8789
});
8890
}
8991

90-
export interface TaskParams {
92+
interface TaskParams {
9193
project: ProjectGraphNode;
9294
target: string;
9395
configuration: string;
9496
overrides: Object;
97+
errorIfCannotFindConfiguration: boolean;
9598
}
9699

97100
export function createTask({
98101
project,
99102
target,
100103
configuration,
101104
overrides,
105+
errorIfCannotFindConfiguration,
102106
}: TaskParams): Task {
103107
const config = projectHasTargetAndConfiguration(
104108
project,
@@ -107,6 +111,14 @@ export function createTask({
107111
)
108112
? configuration
109113
: undefined;
114+
115+
if (errorIfCannotFindConfiguration) {
116+
output.error({
117+
title: `Cannot find configuration '${configuration}' for project '${project.name}'`,
118+
});
119+
process.exit(1);
120+
}
121+
110122
const qualifiedTarget = {
111123
project: project.name,
112124
target,
@@ -190,7 +202,10 @@ export function getRunner(
190202
},
191203
};
192204
} else {
193-
throw new Error(`Could not find runner configuration for ${runner}`);
205+
output.error({
206+
title: `Could not find runner configuration for ${runner}`,
207+
});
208+
process.exit(1);
194209
}
195210
}
196211

0 commit comments

Comments
 (0)