diff --git a/packages/create-vite/src/index.ts b/packages/create-vite/src/index.ts index 16a97a2a485255..a995c47d7a5101 100755 --- a/packages/create-vite/src/index.ts +++ b/packages/create-vite/src/index.ts @@ -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')) @@ -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) @@ -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':