Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/create-vite/__tests__/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 14 additions & 1 deletion packages/create-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 -- `
Expand All @@ -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 -- ')
Expand Down Expand Up @@ -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]
Expand Down
Loading