diff --git a/packages/cli/lib/parse-run-one-options.ts b/packages/cli/lib/parse-run-one-options.ts index 53aa129839..e3091797cc 100644 --- a/packages/cli/lib/parse-run-one-options.ts +++ b/packages/cli/lib/parse-run-one-options.ts @@ -84,6 +84,7 @@ export function parseRunOneOptions( }, configuration: { 'strip-dashed': true, + 'dot-notation': false, }, }); diff --git a/packages/tao/index.ts b/packages/tao/index.ts index 132c318265..9ab5bef093 100644 --- a/packages/tao/index.ts +++ b/packages/tao/index.ts @@ -3,7 +3,12 @@ import { dirname, join } from 'path'; import { existsSync } from 'fs-extra'; import * as yargsParser from 'yargs-parser'; -const argv = yargsParser(process.argv.slice(2)); +const argv = yargsParser(process.argv.slice(2), { + configuration: { + 'strip-dashed': true, + 'dot-notation': false, + }, +}); export async function invokeCommand( command: string, diff --git a/packages/tao/src/commands/run.ts b/packages/tao/src/commands/run.ts index 67e16c74a5..e668ce1c26 100644 --- a/packages/tao/src/commands/run.ts +++ b/packages/tao/src/commands/run.ts @@ -58,6 +58,10 @@ function parseRunOpts( alias: { c: 'configuration', }, + configuration: { + 'strip-dashed': false, + 'dot-notation': false, + }, }) ); const help = runOptions.help as boolean; diff --git a/packages/workspace/src/command-line/utils.ts b/packages/workspace/src/command-line/utils.ts index 89b210f463..404cf196fd 100644 --- a/packages/workspace/src/command-line/utils.ts +++ b/packages/workspace/src/command-line/utils.ts @@ -82,6 +82,7 @@ export function splitArgsIntoNxArgsAndOverrides( const overrides = yargsParser(args._ as string[], { configuration: { 'strip-dashed': true, + 'dot-notation': false, }, }); // This removes the overrides from the nxArgs._ diff --git a/packages/workspace/src/executors/run-commands/run-commands.impl.spec.ts b/packages/workspace/src/executors/run-commands/run-commands.impl.spec.ts index bc5f3391f9..4c0bf550ba 100644 --- a/packages/workspace/src/executors/run-commands/run-commands.impl.spec.ts +++ b/packages/workspace/src/executors/run-commands/run-commands.impl.spec.ts @@ -73,6 +73,32 @@ describe('Command Runner Builder', () => { }); }); + it('should add args containing spaces to in the command', async () => { + const exec = jest.spyOn(require('child_process'), 'execSync'); + + await runCommands( + { + command: `echo`, + a: 123, + b: '4 5 6', + c: '4 "5" 6', + }, + context + ); + expect(exec).toHaveBeenCalledWith( + `echo --a=123 --b="4 5 6" --c="4 \"5\" 6"`, + { + stdio: [0, 1, 2], + cwd: undefined, + env: { + ...process.env, + ...env(), + }, + maxBuffer: LARGE_BUFFER, + } + ); + }); + it('should forward args by default when using commands (plural)', async () => { const exec = jest.spyOn(require('child_process'), 'exec'); diff --git a/packages/workspace/src/executors/run-commands/run-commands.impl.ts b/packages/workspace/src/executors/run-commands/run-commands.impl.ts index cfe99928ed..7314867fd3 100644 --- a/packages/workspace/src/executors/run-commands/run-commands.impl.ts +++ b/packages/workspace/src/executors/run-commands/run-commands.impl.ts @@ -249,7 +249,11 @@ function transformCommand( return command.replace(regex, (_, group: string) => args[camelCase(group)]); } else if (Object.keys(args).length > 0 && forwardAllArgs) { const stringifiedArgs = Object.keys(args) - .map((a) => `--${a}=${args[a]}`) + .map((a) => + typeof args[a] === 'string' && args[a].includes(' ') + ? `--${a}="${args[a].replace(/"/g, '"')}"` + : `--${a}=${args[a]}` + ) .join(' '); return `${command} ${stringifiedArgs}`; } else {