diff --git a/docs/generated/packages/nx/executors/run-commands.json b/docs/generated/packages/nx/executors/run-commands.json index d2d9557444..ff2a1c424f 100644 --- a/docs/generated/packages/nx/executors/run-commands.json +++ b/docs/generated/packages/nx/executors/run-commands.json @@ -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" diff --git a/packages/nx/src/executors/run-commands/run-commands.impl.spec.ts b/packages/nx/src/executors/run-commands/run-commands.impl.spec.ts index a7bb1b796d..8e9e52577b 100644 --- a/packages/nx/src/executors/run-commands/run-commands.impl.spec.ts +++ b/packages/nx/src/executors/run-commands/run-commands.impl.spec.ts @@ -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( diff --git a/packages/nx/src/executors/run-commands/run-commands.impl.ts b/packages/nx/src/executors/run-commands/run-commands.impl.ts index 20d327f10c..14b046fde9 100644 --- a/packages/nx/src/executors/run-commands/run-commands.impl.ts +++ b/packages/nx/src/executors/run-commands/run-commands.impl.ts @@ -42,7 +42,7 @@ export type Json = { }; export interface RunCommandsOptions extends Json { - command?: string; + command?: string | string[]; commands?: ( | { command: string; @@ -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) => diff --git a/packages/nx/src/executors/run-commands/schema.json b/packages/nx/src/executors/run-commands/schema.json index 32b1f4a691..1bb23f1187 100644 --- a/packages/nx/src/executors/run-commands/schema.json +++ b/packages/nx/src/executors/run-commands/schema.json @@ -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"