Skip to content

Commit

Permalink
fix(core): run-commands should not parse strings as numbers (nrwl#17670)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 authored and meeroslav committed Jun 23, 2023
1 parent 97b98b7 commit 492bada
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/nx/src/executors/run-commands/run-commands.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ describe('Run Commands', () => {
expect(readFile(f)).toEqual('123');
});

it.each([
[`--key=123`, `args.key`, `123`],
[`--key="123.10"`, `args.key`, `123.10`],
[`--nested.key="123.10"`, `args.nested.key`, `123.10`],
])(
'should interpolate %s into %s as %s',
async (cmdLineArg, argKey, expected) => {
const f = fileSync().name;
const result = await runCommands(
{
command: `echo {${argKey}} >> ${f}`,
__unparsed__: [cmdLineArg],
},
context
);
expect(result).toEqual(expect.objectContaining({ success: true }));
expect(readFile(f)).toEqual(expected);
}
);

it('should run commands serially', async () => {
const f = fileSync().name;
const result = await runCommands(
Expand Down
10 changes: 9 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 @@ -312,7 +312,15 @@ function parseArgs(options: RunCommandsOptions) {
const unknownOptionsTreatedAsArgs = Object.keys(options)
.filter((p) => propKeys.indexOf(p) === -1)
.reduce((m, c) => ((m[c] = options[c]), m), {});
return unknownOptionsTreatedAsArgs;

const unparsedCommandArgs = yargsParser(options.__unparsed__, {
configuration: {
'parse-numbers': false,
'parse-positional-numbers': false,
'dot-notation': false,
},
});
return { ...unknownOptionsTreatedAsArgs, ...unparsedCommandArgs };
}
return yargsParser(args.replace(/(^"|"$)/g, ''), {
configuration: { 'camel-case-expansion': false },
Expand Down

0 comments on commit 492bada

Please sign in to comment.