Skip to content

Commit 758fc6c

Browse files
authored
fix: two folders are created when the project name contains spaces (#11630)
1 parent c34f0d1 commit 758fc6c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/create-vite/src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ async function init() {
318318

319319
if (customCommand) {
320320
const fullCustomCommand = customCommand
321-
.replace('TARGET_DIR', targetDir)
322321
.replace(/^npm create/, `${pkgManager} create`)
323322
// Only Yarn 1.x doesn't support `@version` in the `create` command
324323
.replace('@latest', () => (isYarn1 ? '' : '@latest'))
@@ -336,7 +335,9 @@ async function init() {
336335
})
337336

338337
const [command, ...args] = fullCustomCommand.split(' ')
339-
const { status } = spawn.sync(command, args, {
338+
// we replace TARGET_DIR here because targetDir may include a space
339+
const replacedArgs = args.map((arg) => arg.replace('TARGET_DIR', targetDir))
340+
const { status } = spawn.sync(command, replacedArgs, {
340341
stdio: 'inherit',
341342
})
342343
process.exit(status ?? 0)
@@ -376,9 +377,14 @@ async function init() {
376377
setupReactSwc(root, template.endsWith('-ts'))
377378
}
378379

380+
const cdProjectName = path.relative(cwd, root)
379381
console.log(`\nDone. Now run:\n`)
380382
if (root !== cwd) {
381-
console.log(` cd ${path.relative(cwd, root)}`)
383+
console.log(
384+
` cd ${
385+
cdProjectName.includes(' ') ? `"${cdProjectName}"` : cdProjectName
386+
}`,
387+
)
382388
}
383389
switch (pkgManager) {
384390
case 'yarn':

0 commit comments

Comments
 (0)