diff --git a/packages/create-vite/__tests__/cli.spec.ts b/packages/create-vite/__tests__/cli.spec.ts index bbd4a354231b11..07ee4c079fc36d 100644 --- a/packages/create-vite/__tests__/cli.spec.ts +++ b/packages/create-vite/__tests__/cli.spec.ts @@ -300,6 +300,23 @@ test('accepts immediate flag', () => { expect(stdout).toContain('Installing dependencies') }) +test('uses vp commands in the done message when run via vp dlx', () => { + const { stdout } = run([projectName, '--template', 'vue', '--no-immediate'], { + cwd: import.meta.dirname, + env: { + ...process.env, + _VITE_TEST_CLI: 'true', + // `vp dlx` sets VP_USER_AGENT; the underlying package manager overwrites + // npm_config_user_agent, so VP_USER_AGENT must take precedence. + VP_USER_AGENT: 'vp/0.2.1', + npm_config_user_agent: 'pnpm/10.0.0 npm/? node/v24.18.0 darwin arm64', + }, + }) + expect(stdout).toContain('Done. Now run:') + expect(stdout).toContain('vp install') + expect(stdout).toContain('vp dev') +}) + test('accepts immediate flag and skips install prompt', () => { const { stdout } = run([projectName, '--template', 'vue', '--no-immediate'], { cwd: import.meta.dirname, diff --git a/packages/create-vite/src/index.ts b/packages/create-vite/src/index.ts index fe81e9def0582a..52c18562c7a47d 100755 --- a/packages/create-vite/src/index.ts +++ b/packages/create-vite/src/index.ts @@ -463,7 +463,11 @@ async function init() { ) } - const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent) + // Vite+ (`vp`) exposes its own `VP_USER_AGENT` because the underlying package + // manager overwrites `npm_config_user_agent` when running `vp dlx create-vite`. + const pkgInfo = pkgFromUserAgent( + process.env.VP_USER_AGENT ?? process.env.npm_config_user_agent, + ) const cancel = () => prompts.cancel('Operation cancelled') // 1. Get project name and target dir @@ -1064,6 +1068,10 @@ function getFullCustomCommand(customCommand: string, pkgInfo?: PkgInfo) { if (pkgManager === 'pnpm') { return 'pnpm create ' } + // Vite+ uses `vp dlx create-` directly on the package + if (pkgManager === 'vp') { + return 'vp dlx create-' + } // For other package managers, preserve the original format return customCommand.startsWith('npm create -- ') ? `${pkgManager} create -- ` @@ -1086,6 +1094,10 @@ function getFullCustomCommand(customCommand: string, pkgInfo?: PkgInfo) { if (pkgManager === 'deno') { return 'deno run -A npm:' } + // Vite+ uses `vp dlx` to execute package binaries + if (pkgManager === 'vp') { + return 'vp dlx ' + } // Use `npm exec` in all other cases, // including Yarn 1.x and other custom npm clients. return customCommand.startsWith('npm exec -- ') @@ -1117,6 +1129,7 @@ function getRunCommand(agent: string, script: string) { case 'yarn': case 'pnpm': case 'bun': + case 'vp': return [agent, script] case 'deno': return [agent, 'task', script]