Skip to content
Open
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
91 changes: 49 additions & 42 deletions packages/create-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -870,48 +870,55 @@ function getFullCustomCommand(customCommand: string, pkgInfo?: PkgInfo) {
const pkgManager = pkgInfo ? pkgInfo.name : 'npm'
const isYarn1 = pkgManager === 'yarn' && pkgInfo?.version.startsWith('1.')

return (
customCommand
.replace(/^npm create (?:-- )?/, () => {
// `bun create` uses it's own set of templates,
// the closest alternative is using `bun x` directly on the package
if (pkgManager === 'bun') {
return 'bun x create-'
}
// Deno uses `run -A npm:create-` instead of `create` or `init` to also provide needed perms
if (pkgManager === 'deno') {
return 'deno run -A npm:create-'
}
// pnpm doesn't support the -- syntax
if (pkgManager === 'pnpm') {
return 'pnpm create '
}
// For other package managers, preserve the original format
return customCommand.startsWith('npm create -- ')
? `${pkgManager} create -- `
: `${pkgManager} create `
})
// Only Yarn 1.x doesn't support `@version` in the `create` command
.replace('@latest', () => (isYarn1 ? '' : '@latest'))
.replace(/^npm exec /, () => {
// Prefer `pnpm dlx`, `yarn dlx`, or `bun x`
if (pkgManager === 'pnpm') {
return 'pnpm dlx '
}
if (pkgManager === 'yarn' && !isYarn1) {
return 'yarn dlx '
}
if (pkgManager === 'bun') {
return 'bun x '
}
if (pkgManager === 'deno') {
return 'deno run -A npm:'
}
// Use `npm exec` in all other cases,
// including Yarn 1.x and other custom npm clients.
return 'npm exec '
})
)
const command = customCommand
.replace(/^npm create (?:-- )?/, () => {
// `bun create` uses it's own set of templates,
// the closest alternative is using `bun x` directly on the package
if (pkgManager === 'bun') {
return 'bun x create-'
}
// Deno uses `run -A npm:create-` instead of `create` or `init` to also provide needed perms
if (pkgManager === 'deno') {
return 'deno run -A npm:create-'
}
// pnpm doesn't support the -- syntax
if (pkgManager === 'pnpm') {
return 'pnpm create '
}
// For other package managers, preserve the original format
return customCommand.startsWith('npm create -- ')
? `${pkgManager} create -- `
: `${pkgManager} create `
})
// Only Yarn 1.x doesn't support `@version` in the `create` command
.replace('@latest', () => (isYarn1 ? '' : '@latest'))
.replace(/^npm exec /, () => {
// Prefer `pnpm dlx`, `yarn dlx`, or `bun x`
if (pkgManager === 'pnpm') {
return 'pnpm dlx '
}
if (pkgManager === 'yarn' && !isYarn1) {
return 'yarn dlx '
}
if (pkgManager === 'bun') {
return 'bun x '
}
if (pkgManager === 'deno') {
return 'deno run -A npm:'
}
// Use `npm exec` in all other cases,
// including Yarn 1.x and other custom npm clients.
return 'npm exec '
})
// fixed issue #21618
.replace(
/^pnpm dlx (\S+) -- /,
// `npm exec <pkg> -- <args>` uses `--` to split npm flags from package args.
// `pnpm dlx` doesn't need this separator, and keeping it can break CLIs.
'pnpm dlx $1 ',
)

return command
}

function getLabel(variant: FrameworkVariant) {
Expand Down