Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): added the ability to split command property into an array in nx:run-commands executor #20201

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/generated/packages/nx/executors/run-commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@
"x-priority": "important"
},
"command": {
"oneOf": [
{
"type": "array",
"description": "Command to run in child process, but divided into parts.",
"items": { "type": "string" },
"x-priority": "important"
},
{
"type": "string",
"description": "Command to run in child process."
}
],
"type": "string",
"description": "Command to run in child process.",
"x-priority": "important"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,42 @@ describe('Run Commands', () => {
expect(readFile(f)).toEqual('1212');
});

it('should run the command, but divided into paths', async () => {
const f = fileSync().name;
const result = await runCommands(
{
command: [`echo 1 >> ${f}`, '&&', `echo 2 >> ${f}`],
parallel: false,

__unparsed__: [],
},
context
);
expect(result).toEqual(expect.objectContaining({ success: true }));
expect(readFile(f)).toEqual('12');
});

it('should run the command, but divided into several paths', async () => {
const f = fileSync().name;
const result = await runCommands(
{
command: [
`echo 1 >> ${f} `,
`&&`,
`echo 2 >> ${f}`,
';',
`echo 34 >> ${f}`,
],
parallel: false,

__unparsed__: [],
},
context
);
expect(result).toEqual(expect.objectContaining({ success: true }));
expect(readFile(f)).toEqual('1234');
});

it('should run commands in parallel', async () => {
const f = fileSync().name;
const result = await runCommands(
Expand Down
10 changes: 8 additions & 2 deletions packages/nx/src/executors/run-commands/run-commands.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type Json = {
};

export interface RunCommandsOptions extends Json {
command?: string;
command?: string | string[];
commands?: (
| {
command: string;
Expand Down Expand Up @@ -237,7 +237,13 @@ function normalizeOptions(
}

if (options.command) {
options.commands = [{ command: options.command }];
options.commands = [
{
command: Array.isArray(options.command)
? options.command.join(' ')
: options.command,
},
];
options.parallel = options.readyWhenStatus?.length > 0;
} else {
options.commands = options.commands.map((c) =>
Expand Down
14 changes: 14 additions & 0 deletions packages/nx/src/executors/run-commands/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@
"x-priority": "important"
},
"command": {
"oneOf": [
{
"type": "array",
"description": "Command to run in child process, but divided into parts.",
"items": {
"type": "string"
},
"x-priority": "important"
},
{
"type": "string",
"description": "Command to run in child process."
}
],
"type": "string",
"description": "Command to run in child process.",
"x-priority": "important"
Expand Down