diff --git a/docs/generated/packages/nx/executors/run-commands.json b/docs/generated/packages/nx/executors/run-commands.json index b4717441fd944..9440a545996d9 100644 --- a/docs/generated/packages/nx/executors/run-commands.json +++ b/docs/generated/packages/nx/executors/run-commands.json @@ -121,6 +121,11 @@ "items": { "type": "string" }, "$default": { "$source": "unparsed" }, "x-priority": "internal" + }, + "forwardAllArgs": { + "type": "boolean", + "description": "Whether arguments should be forwarded when interpolation is not present.", + "default": true } }, "additionalProperties": true, 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 bc75688cfd33e..65b79e9f1078c 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 @@ -37,19 +37,61 @@ describe('Run Commands', () => { }); it('should not pass --args into underlying command', async () => { - const f = fileSync().name; const result = await runCommands( { command: `echo`, __unparsed__: ['--args=--key=123'], args: '--key=123', - unparsedCommandArgs: { args: '--key=123' }, }, context ); expect(result.terminalOutput.trim()).not.toContain('--args=--key=123'); }); + it('should not foward any args to underlying command if forwardAllArgs is false', async () => { + let result = await runCommands( + { + command: `echo`, + key: 123, + __unparsed__: [], + forwardAllArgs: false, + }, + context + ); + expect(result.terminalOutput.trim()).not.toContain('--key=123'); + + result = await runCommands( + { + command: `echo`, + key: 123, + __unparsed__: [], + forwardAllArgs: true, + }, + context + ); + expect(result.terminalOutput.trim()).toContain('--key=123'); + + result = await runCommands( + { + commands: [ + { + command: `echo 1`, + forwardAllArgs: true, + }, + { + command: `echo 2`, + }, + ], + __unparsed__: ['--args=--key=123'], + args: '--key=123', + forwardAllArgs: false, + }, + context + ); + expect(result.terminalOutput).toContain('1 --key=123'); + expect(result.terminalOutput).not.toContain('2 --key=123'); + }); + it('should interpolate all unknown args as if they were --args', 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 f269657a1c177..6d28de1f6436e 100644 --- a/packages/nx/src/executors/run-commands/run-commands.impl.ts +++ b/packages/nx/src/executors/run-commands/run-commands.impl.ts @@ -54,6 +54,7 @@ export interface RunCommandsOptions extends Json { readyWhen?: string; cwd?: string; env?: Record; + forwardAllArgs?: boolean; // default is true args?: string | string[]; envFile?: string; __unparsed__: string[]; @@ -75,6 +76,7 @@ const propKeys = [ 'usePty', 'streamOutput', 'verbose', + 'forwardAllArgs', ]; export interface NormalizedRunCommandsOptions extends RunCommandsOptions { @@ -244,7 +246,7 @@ function normalizeOptions( c.command = interpolateArgsIntoCommand( c.command, options as NormalizedRunCommandsOptions, - c.forwardAllArgs ?? true + c.forwardAllArgs ?? options.forwardAllArgs ?? true ); }); return options as NormalizedRunCommandsOptions; diff --git a/packages/nx/src/executors/run-commands/schema.json b/packages/nx/src/executors/run-commands/schema.json index cfb307d521c35..1a314e07c5122 100644 --- a/packages/nx/src/executors/run-commands/schema.json +++ b/packages/nx/src/executors/run-commands/schema.json @@ -135,6 +135,11 @@ "$source": "unparsed" }, "x-priority": "internal" + }, + "forwardAllArgs": { + "type": "boolean", + "description": "Whether arguments should be forwarded when interpolation is not present.", + "default": true } }, "additionalProperties": true,