Skip to content

Commit

Permalink
fix(core): add extraParameters support to build and test executors (#514
Browse files Browse the repository at this point in the history
)
  • Loading branch information
AgentEnder authored Sep 6, 2022
1 parent e84d4f1 commit c6c648d
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/core/executors/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ Builds an app via the `dotnet` cli command.
### verbosity

- (string):

### extraParameters

- (string): Extra command-line arguments that are passed verbatim to the dotnet command.
4 changes: 4 additions & 0 deletions docs/core/executors/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,7 @@ Runs test via the dotnet cli
### watch

- (boolean): Determines if `dotnet test` or `dotnet watch test` is used to execute tests.

### extraParameters

- (string): Extra command-line arguments that are passed verbatim to the dotnet command.
5 changes: 4 additions & 1 deletion packages/core/src/executors/build/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ export default async function runExecutor(
workspaceRoot,
await getProjectFileForNxProject(nxProjectConfiguration),
);

const { extraParameters, ...flags } = options;

options.output = options.output
? resolve(workspaceRoot, options.output)
: undefined;

dotnetClient.build(projectFilePath, options);
dotnetClient.build(projectFilePath, flags, extraParameters);

return {
success: true,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/executors/build/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export type BuildExecutorSchema = {
[key in dotnetBuildFlags]?: string | boolean;
} & {
output?: string;
extraParameters?: string;
};
4 changes: 4 additions & 0 deletions packages/core/src/executors/build/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
"type": "string",
"enum": ["quiet", "minimal", "normal", "detailed", "diagnostic"],
"default": "minimal"
},
"extraParameters": {
"type": "string",
"description": "Extra command-line arguments that are passed verbatim to the dotnet command."
}
},
"required": ["configuration"]
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/executors/test/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ export default async function runExecutor(
nxProjectConfiguration,
);
dotnetClient.cwd = projectDirectory;
const { watch, ...parsedOptions } = options;
const { watch, extraParameters, ...parsedOptions } = options;

try {
const result = dotnetClient.test(
resolve(workspaceRoot, projectFilePath),
watch,
parsedOptions,
extraParameters,
);

if (watch && isChildProcess(result)) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/executors/test/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export interface TestExecutorSchema {
| 'diag'
| 'diagnostic';
watch?: boolean;
extraParameters?: string;
}
4 changes: 4 additions & 0 deletions packages/core/src/executors/test/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
"description": "Determines if `dotnet test` or `dotnet watch test` is used to execute tests.",
"type": "boolean",
"default": false
},
"extraParameters": {
"type": "string",
"description": "Extra command-line arguments that are passed verbatim to the dotnet command."
}
},
"required": []
Expand Down
17 changes: 15 additions & 2 deletions packages/dotnet/src/lib/core/dotnet.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,20 @@ export class DotNetClient {
return parseDotnetNewListOutput(output);
}

build(project: string, parameters?: dotnetBuildOptions): void {
build(
project: string,
parameters?: dotnetBuildOptions,
extraParameters?: string,
): void {
const params = [`build`, project];
if (parameters) {
parameters = swapKeysUsingMap(parameters, buildKeyMap);
params.push(...getSpawnParameterArray(parameters));
}
if (extraParameters) {
const matches = extraParameters.match(EXTRA_PARAMS_REGEX);
params.push(...(matches as string[]));
}
return this.logAndExecute(params);
}

Expand All @@ -89,6 +97,7 @@ export class DotNetClient {
project: string,
watch?: boolean,
parameters?: dotnetTestOptions,
extraParameters?: string,
): void | ChildProcess {
const params = watch
? [`watch`, `--project`, project, `test`]
Expand All @@ -98,6 +107,10 @@ export class DotNetClient {
parameters = swapKeysUsingMap(parameters, testKeyMap);
params.push(...getSpawnParameterArray(parameters));
}
if (extraParameters) {
const matches = extraParameters.match(EXTRA_PARAMS_REGEX);
params.push(...(matches as string[]));
}
if (!watch) {
return this.logAndExecute(params);
} else {
Expand Down Expand Up @@ -138,7 +151,7 @@ export class DotNetClient {
}
if (extraParameters) {
const matches = extraParameters.match(EXTRA_PARAMS_REGEX);
params.push(...(matches as RegExpMatchArray));
params.push(...(matches as string[]));
}
return this.logAndExecute(params);
}
Expand Down

0 comments on commit c6c648d

Please sign in to comment.