Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Generator Presets cannot take arguments with strings that have spaces in them #15995

Open
shaun-jacks opened this issue Mar 31, 2023 · 6 comments
Assignees
Labels
scope: core core nx functionality type: bug

Comments

@shaun-jacks
Copy link

shaun-jacks commented Mar 31, 2023

Current Behavior

When I pass in an argument with a custom preset that is type string, and has a space in it, the generator does not properly take in the string argument.

The string argument is split by spaces, and therefore preset generators that take in strings are broken if there is a space in the string.

Expected Behavior

  1. Using a custom preset, where the preset takes in a type string with key: name, or key: appDescription, run
npx create-nx-workspace@15.8.9 --preset @example/custom-preset --packageManager yarn --name "test name" --nxCloud false --appDescription "test description"
  1. Expected Nx logger should actually run the following command
$ ...../node_modules/.bin/nx '--nxWorkspaceRoot="......"' g @custom-preset/custom-preset:preset --packageManager=yarn --pm=yarn '--name="test name"' '--appDescription="test description"' --no-a --no-g '-......

Notice how string arguments with spaces in them correctly go with the argument

GitHub Repo

No response

Steps to Reproduce

  1. Using a custom preset, where the preset takes in a type string with key: name, or key: appDescription, run
npx create-nx-workspace@15.8.9 --preset @example/custom-preset --packageManager yarn --name "test name" --nxCloud false --appDescription "test description"

In the Nx logger, it outputs that it will run the following:

$ ...../node_modules/.bin/nx '--nxWorkspaceRoot="......"' g @custom-preset/custom-preset:preset --packageManager=yarn --pm=yarn '--name="test' 'name"' '--appDescription="test' 'description"' --no-a --no-g '-......

Notice how

'--name="test' 'name"' 

Therefore, name is treated as an unnamed argument, when it was originally in the string and should be in --name

Nx Report

>  NX   Report complete - copy this into the issue template

   Node : 18.12.1
   OS   : darwin x64
   yarn : 1.22.19
   
   nx               : 15.8.9
   @nrwl/js         : 15.8.9
   @nrwl/jest       : 15.8.9
   @nrwl/linter     : 15.8.9
   @nrwl/workspace  : 15.8.9
   @nrwl/angular    : 15.8.9
   @nrwl/cli        : 15.8.9
   @nrwl/cypress    : 15.8.9
   @nrwl/devkit     : 15.8.9
   @nrwl/tao        : 15.8.9
   @nrwl/webpack    : 15.8.9
   typescript       : 5.0.3
   ---------------------------------------
   Community plugins:
   my custom plugin : x.x.x

Failure Logs

$ ...../node_modules/.bin/nx '--nxWorkspaceRoot="......"' g @custom-preset/custom-preset:preset --packageManager=yarn --pm=yarn '--name="test' 'name"' '--appDescription="test' 'description"' --no-a --no-g '-......

Notice how

'--name="test' 'name"' 

Where it should be

'--name="test name"'

Additional Information

I found a line of code that is causing the issue. It is this line

https://github.com/nrwl/nx/blob/15.9.1/packages/create-nx-workspace/src/create-preset.ts#L52

Since the command is splitting the string by spaces, spaces within the string arguments are separated incorrectly. It should not separate argument string with spaces inside of them

@FrozenPandaz FrozenPandaz added the scope: core core nx functionality label Mar 31, 2023
@ksjogo
Copy link

ksjogo commented Jun 29, 2023

Not sure if it is related or not, but I have a similar issue with arguments with spaces for nx run:

 $ nx cli eurystheus mimir "why o why"
Debugger attached.

> nx run eurystheus:cli mimir why o why

It should keep the why o why as one string preferably.

@shaun-jacks
Copy link
Author

Any updates on this issue?

Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Feb 20, 2024
@ksjogo
Copy link

ksjogo commented Feb 20, 2024

This still is an issue.

@github-actions github-actions bot removed the stale label Feb 21, 2024
@saltman424
Copy link

I am having the same issue as @ksjogo with args, but for args specified in command for a task using nx:run-commands. Specifically:
glob -c=\"tsx --test\" \"./**/*.test.ts\"
Seems to be running as:
[ glob, -c="tsx, --test", "./**/*.test.ts" ]

It seems like there might be a recurring issue where command.split(' ') is used in various places, which causes all of them to ignore quotes

@AdiMarianMutu
Copy link

I encountered this as well. If an argument value of a custom generator contains a space, NX only inserts the part of the string till the space is reached.

MY_PROPERTY="<%= MY_PROPERTY %>"

If MY_PROPERTY value is set to Hello World! then the generator will add only Hello, this seems to be a severe bug as I'm using the generator to build on the fly an .env file on the server during the deployment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: core core nx functionality type: bug
Projects
None yet
Development

No branches or pull requests

6 participants