From 492bada6acae30848f1434880ce604fd4db84d8e Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Tue, 20 Jun 2023 23:20:24 +0100 Subject: [PATCH] fix(core): run-commands should not parse strings as numbers (#17670) --- .../run-commands/run-commands.impl.spec.ts | 20 +++++++++++++++++++ .../run-commands/run-commands.impl.ts | 10 +++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/nx/src/executors/run-commands/run-commands.impl.spec.ts b/packages/nx/src/executors/run-commands/run-commands.impl.spec.ts index 104a722acb38f1..f4dce1df5d3e1b 100644 --- a/packages/nx/src/executors/run-commands/run-commands.impl.spec.ts +++ b/packages/nx/src/executors/run-commands/run-commands.impl.spec.ts @@ -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( diff --git a/packages/nx/src/executors/run-commands/run-commands.impl.ts b/packages/nx/src/executors/run-commands/run-commands.impl.ts index f8a8b775e2250b..ea2eda93f1d9cb 100644 --- a/packages/nx/src/executors/run-commands/run-commands.impl.ts +++ b/packages/nx/src/executors/run-commands/run-commands.impl.ts @@ -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 },