Skip to content

Commit 9389ab0

Browse files
leosvelperezFrozenPandaz
authored andcommitted
fix(core): merge args and options in nx:run-commands executor (#26573)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> When a target using `nx:run-commands` has the `args` option set, the rest of the options are completely ignored and not forwarded to the command. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> When a target using `nx:run-commands` has the `args` option set, the rest of the options that don't match any of the options set in `args` and are not specific to the executor should be forwarded to the command. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> <!-- Fixes NXP-811 --> Fixes # (cherry picked from commit 59ab43a)
1 parent 04b959d commit 9389ab0

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

packages/nx/src/executors/run-commands/run-commands.impl.spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('Run Commands', () => {
6464
}
6565
);
6666

67-
it('should overwrite options with args', async () => {
67+
it('should overwrite matching options with args', async () => {
6868
let result = (
6969
await runCommands(
7070
{
@@ -115,6 +115,21 @@ describe('Run Commands', () => {
115115
).terminalOutput.trim();
116116
expect(result).not.toContain('--key=123');
117117
expect(result).toContain('--key=789'); // should take args over unknown options
118+
119+
result = (
120+
await runCommands(
121+
{
122+
command: 'echo',
123+
__unparsed__: [],
124+
key1: 'from options',
125+
key2: 'from options',
126+
args: '--key1="from args"',
127+
},
128+
context
129+
)
130+
).terminalOutput.trim();
131+
expect(result).not.toContain('--key1="from options"');
132+
expect(result).toContain('echo --key2="from options" --key1="from args"'); // take args over options with the same name while keeping the rest
118133
});
119134

120135
it('should not foward any args to underlying command if forwardAllArgs is false', async () => {

packages/nx/src/executors/run-commands/run-commands.impl.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,12 @@ export function interpolateArgsIntoCommand(
516516
args += ` ${opts.args}`;
517517
}
518518
if (opts.__unparsed__?.length > 0) {
519-
const filterdParsedOptions = filterPropKeysFromUnParsedOptions(
519+
const filteredParsedOptions = filterPropKeysFromUnParsedOptions(
520520
opts.__unparsed__,
521521
opts.parsedArgs
522522
);
523-
if (filterdParsedOptions.length > 0) {
524-
args += ` ${filterdParsedOptions
523+
if (filteredParsedOptions.length > 0) {
524+
args += ` ${filteredParsedOptions
525525
.map(wrapArgIntoQuotesIfNeeded)
526526
.join(' ')}`;
527527
}
@@ -540,9 +540,14 @@ function parseArgs(
540540
if (!args) {
541541
return { ...unknownOptions, ...unparsedCommandArgs };
542542
}
543-
return yargsParser(args.replace(/(^"|"$)/g, ''), {
544-
configuration: { 'camel-case-expansion': false },
545-
});
543+
544+
return {
545+
...unknownOptions,
546+
...yargsParser(args.replace(/(^"|"$)/g, ''), {
547+
configuration: { 'camel-case-expansion': true },
548+
}),
549+
...unparsedCommandArgs,
550+
};
546551
}
547552

548553
/**

0 commit comments

Comments
 (0)