Skip to content

Commit

Permalink
feat(core): add root level forwardAllArgs (#22753)
Browse files Browse the repository at this point in the history
(cherry picked from commit c3a3d1b)
  • Loading branch information
xiongemi authored and FrozenPandaz committed Apr 23, 2024
1 parent 3db58e1 commit 397da97
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/generated/packages/nx/executors/run-commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
46 changes: 44 additions & 2 deletions packages/nx/src/executors/run-commands/run-commands.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion packages/nx/src/executors/run-commands/run-commands.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface RunCommandsOptions extends Json {
readyWhen?: string;
cwd?: string;
env?: Record<string, string>;
forwardAllArgs?: boolean; // default is true
args?: string | string[];
envFile?: string;
__unparsed__: string[];
Expand All @@ -75,6 +76,7 @@ const propKeys = [
'usePty',
'streamOutput',
'verbose',
'forwardAllArgs',
];

export interface NormalizedRunCommandsOptions extends RunCommandsOptions {
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions packages/nx/src/executors/run-commands/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 397da97

Please sign in to comment.