Skip to content

Commit c6c648d

Browse files
authored
fix(core): add extraParameters support to build and test executors (#514)
1 parent e84d4f1 commit c6c648d

File tree

9 files changed

+39
-4
lines changed

9 files changed

+39
-4
lines changed

docs/core/executors/build.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ Builds an app via the `dotnet` cli command.
4545
### verbosity
4646

4747
- (string):
48+
49+
### extraParameters
50+
51+
- (string): Extra command-line arguments that are passed verbatim to the dotnet command.

docs/core/executors/test.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,7 @@ Runs test via the dotnet cli
104104
### watch
105105

106106
- (boolean): Determines if `dotnet test` or `dotnet watch test` is used to execute tests.
107+
108+
### extraParameters
109+
110+
- (string): Extra command-line arguments that are passed verbatim to the dotnet command.

packages/core/src/executors/build/executor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ export default async function runExecutor(
2222
workspaceRoot,
2323
await getProjectFileForNxProject(nxProjectConfiguration),
2424
);
25+
26+
const { extraParameters, ...flags } = options;
27+
2528
options.output = options.output
2629
? resolve(workspaceRoot, options.output)
2730
: undefined;
2831

29-
dotnetClient.build(projectFilePath, options);
32+
dotnetClient.build(projectFilePath, flags, extraParameters);
3033

3134
return {
3235
success: true,

packages/core/src/executors/build/schema.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export type BuildExecutorSchema = {
44
[key in dotnetBuildFlags]?: string | boolean;
55
} & {
66
output?: string;
7+
extraParameters?: string;
78
};

packages/core/src/executors/build/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
"type": "string",
4848
"enum": ["quiet", "minimal", "normal", "detailed", "diagnostic"],
4949
"default": "minimal"
50+
},
51+
"extraParameters": {
52+
"type": "string",
53+
"description": "Extra command-line arguments that are passed verbatim to the dotnet command."
5054
}
5155
},
5256
"required": ["configuration"]

packages/core/src/executors/test/executor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ export default async function runExecutor(
2626
nxProjectConfiguration,
2727
);
2828
dotnetClient.cwd = projectDirectory;
29-
const { watch, ...parsedOptions } = options;
29+
const { watch, extraParameters, ...parsedOptions } = options;
3030

3131
try {
3232
const result = dotnetClient.test(
3333
resolve(workspaceRoot, projectFilePath),
3434
watch,
3535
parsedOptions,
36+
extraParameters,
3637
);
3738

3839
if (watch && isChildProcess(result)) {

packages/core/src/executors/test/schema.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ export interface TestExecutorSchema {
3232
| 'diag'
3333
| 'diagnostic';
3434
watch?: boolean;
35+
extraParameters?: string;
3536
}

packages/core/src/executors/test/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@
113113
"description": "Determines if `dotnet test` or `dotnet watch test` is used to execute tests.",
114114
"type": "boolean",
115115
"default": false
116+
},
117+
"extraParameters": {
118+
"type": "string",
119+
"description": "Extra command-line arguments that are passed verbatim to the dotnet command."
116120
}
117121
},
118122
"required": []

packages/dotnet/src/lib/core/dotnet.client.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,20 @@ export class DotNetClient {
6060
return parseDotnetNewListOutput(output);
6161
}
6262

63-
build(project: string, parameters?: dotnetBuildOptions): void {
63+
build(
64+
project: string,
65+
parameters?: dotnetBuildOptions,
66+
extraParameters?: string,
67+
): void {
6468
const params = [`build`, project];
6569
if (parameters) {
6670
parameters = swapKeysUsingMap(parameters, buildKeyMap);
6771
params.push(...getSpawnParameterArray(parameters));
6872
}
73+
if (extraParameters) {
74+
const matches = extraParameters.match(EXTRA_PARAMS_REGEX);
75+
params.push(...(matches as string[]));
76+
}
6977
return this.logAndExecute(params);
7078
}
7179

@@ -89,6 +97,7 @@ export class DotNetClient {
8997
project: string,
9098
watch?: boolean,
9199
parameters?: dotnetTestOptions,
100+
extraParameters?: string,
92101
): void | ChildProcess {
93102
const params = watch
94103
? [`watch`, `--project`, project, `test`]
@@ -98,6 +107,10 @@ export class DotNetClient {
98107
parameters = swapKeysUsingMap(parameters, testKeyMap);
99108
params.push(...getSpawnParameterArray(parameters));
100109
}
110+
if (extraParameters) {
111+
const matches = extraParameters.match(EXTRA_PARAMS_REGEX);
112+
params.push(...(matches as string[]));
113+
}
101114
if (!watch) {
102115
return this.logAndExecute(params);
103116
} else {
@@ -138,7 +151,7 @@ export class DotNetClient {
138151
}
139152
if (extraParameters) {
140153
const matches = extraParameters.match(EXTRA_PARAMS_REGEX);
141-
params.push(...(matches as RegExpMatchArray));
154+
params.push(...(matches as string[]));
142155
}
143156
return this.logAndExecute(params);
144157
}

0 commit comments

Comments
 (0)