Skip to content

Commit

Permalink
fix(core): merge args and options in nx:run-commands executor
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Jun 17, 2024
1 parent f431d0a commit 2dc089f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
17 changes: 16 additions & 1 deletion packages/nx/src/executors/run-commands/run-commands.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Run Commands', () => {
}
);

it('should overwrite options with args', async () => {
it('should overwrite matching options with args', async () => {
let result = (
await runCommands(
{
Expand Down Expand Up @@ -115,6 +115,21 @@ describe('Run Commands', () => {
).terminalOutput.trim();
expect(result).not.toContain('--key=123');
expect(result).toContain('--key=789'); // should take args over unknown options

result = (
await runCommands(
{
command: 'echo',
__unparsed__: [],
key1: 'from options',
key2: 'from options',
args: '--key1="from args"',
},
context
)
).terminalOutput.trim();
expect(result).not.toContain('--key1="from options"');
expect(result).toContain('echo --key2="from options" --key1="from args"'); // take args over options with the same name while keeping the rest
});

it('should not foward any args to underlying command if forwardAllArgs is false', async () => {
Expand Down
17 changes: 11 additions & 6 deletions packages/nx/src/executors/run-commands/run-commands.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,12 @@ export function interpolateArgsIntoCommand(
args += ` ${opts.args}`;
}
if (opts.__unparsed__?.length > 0) {
const filterdParsedOptions = filterPropKeysFromUnParsedOptions(
const filteredParsedOptions = filterPropKeysFromUnParsedOptions(
opts.__unparsed__,
opts.parsedArgs
);
if (filterdParsedOptions.length > 0) {
args += ` ${filterdParsedOptions
if (filteredParsedOptions.length > 0) {
args += ` ${filteredParsedOptions
.map(wrapArgIntoQuotesIfNeeded)
.join(' ')}`;
}
Expand All @@ -540,9 +540,14 @@ function parseArgs(
if (!args) {
return { ...unknownOptions, ...unparsedCommandArgs };
}
return yargsParser(args.replace(/(^"|"$)/g, ''), {
configuration: { 'camel-case-expansion': false },
});

return {
...unknownOptions,
...yargsParser(args.replace(/(^"|"$)/g, ''), {
configuration: { 'camel-case-expansion': true },
}),
...unparsedCommandArgs,
};
}

/**
Expand Down

0 comments on commit 2dc089f

Please sign in to comment.