fix: two folders are created when the project name contains spaces#11630
fix: two folders are created when the project name contains spaces#11630patak-cat merged 3 commits intovitejs:mainfrom
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
| if (targetDir.includes(' ')) { | ||
| args.splice(2, args.length - 2, targetDir) | ||
| } |
There was a problem hiding this comment.
I think simply replacing args instead of replacing the fullCustomCommand would be more easy to understand.
// we replace TARGET_DIR here because targetDir may include a space
let replacedArgs = args.map(arg => arg.replace('TARGET_DIR', targetDir))Would you also add a test here?
https://github.com/vitejs/vite/blob/main/packages/create-vite/__tests__/cli.spec.ts
There was a problem hiding this comment.
The code has been updated, but there seems to be something wrong with my device, could you help to add a test?
There was a problem hiding this comment.
When I add the test, I found that if projectName contains spaces, the value received by progress.argv will be split. Therefore, targetDir can only get the characters before the spaces. How to deal with this scense? 🤔
There was a problem hiding this comment.
In that case, I think the user should quote the project name (e.g. npm init vite@latest "project name with spaces").
There was a problem hiding this comment.
Yes, However, when executing pnpm create vite, the input Project name may contain spaces. I think that after the template is created, if the project name contains spaces, the project name should be wrapped in quotes in the cd projectName output from the terminal.
There was a problem hiding this comment.
So you're suggest updating this line? I think that makes sense.
vite/packages/create-vite/src/index.ts
Line 381 in 697dd00
There was a problem hiding this comment.
Yes, I think it should be updated here. And the previous modification is also necessary. But I don't know how to write this test case?
There was a problem hiding this comment.
I tried writing the test but it seems to be quite complex. I think we can go without tests.
If we replace this execaCommandSync with execaSync, we can test the case of passing the project name from argv.
But for the case of typing the project name, we need to feed the text from stdin and the test seems to hang.
Description
When select
customize with create-vue, If the project name contains a space, two folders will be created, and then the template content will be filled into the folder named with the character before the first space.Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).