Skip to content

Commit

Permalink
fix: two folders are created when the project name contains spaces (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
btea committed Feb 1, 2023
1 parent c34f0d1 commit 758fc6c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/create-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ async function init() {

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

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

const cdProjectName = path.relative(cwd, root)
console.log(`\nDone. Now run:\n`)
if (root !== cwd) {
console.log(` cd ${path.relative(cwd, root)}`)
console.log(
` cd ${
cdProjectName.includes(' ') ? `"${cdProjectName}"` : cdProjectName
}`,
)
}
switch (pkgManager) {
case 'yarn':
Expand Down

0 comments on commit 758fc6c

Please sign in to comment.