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): add root level forwardAllArgs #22753

Merged
merged 1 commit into from
Apr 22, 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
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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 @@ -84,6 +85,7 @@ const propKeys = [
'usePty',
'streamOutput',
'verbose',
'forwardAllArgs',
];

export interface NormalizedRunCommandsOptions extends RunCommandsOptions {
Expand Down Expand Up @@ -252,7 +254,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