MCPcopy
hub / github.com/vitejs/vite / getFullCustomCommand

Function getFullCustomCommand

packages/create-vite/src/index.ts:1047–1096  ·  view source on GitHub ↗
(customCommand: string, pkgInfo?: PkgInfo)

Source from the content-addressed store, hash-verified

1045}
1046
1047function getFullCustomCommand(customCommand: string, pkgInfo?: PkgInfo) {
1048 const pkgManager = pkgInfo ? pkgInfo.name : 'npm'
1049 const isYarn1 = pkgManager === 'yarn' && pkgInfo?.version.startsWith('1.')
1050
1051 return (
1052 customCommand
1053 .replace(/^npm create (?:-- )?/, () => {
1054 // `bun create` uses its own set of templates,
1055 // the closest alternative is using `bun x` directly on the package
1056 if (pkgManager === 'bun') {
1057 return 'bun x create-'
1058 }
1059 // Deno uses `run -A npm:create-` instead of `create` or `init` to also provide needed perms
1060 if (pkgManager === 'deno') {
1061 return 'deno run -A npm:create-'
1062 }
1063 // pnpm doesn't support the -- syntax
1064 if (pkgManager === 'pnpm') {
1065 return 'pnpm create '
1066 }
1067 // For other package managers, preserve the original format
1068 return customCommand.startsWith('npm create -- ')
1069 ? `${pkgManager} create -- `
1070 : `${pkgManager} create `
1071 })
1072 // Only Yarn 1.x doesn't support `@version` in the `create` command
1073 .replace('@latest', () => (isYarn1 ? '' : '@latest'))
1074 .replace(/^npm exec (?:-- )?/, () => {
1075 // Prefer `pnpm dlx`, `yarn dlx`, or `bun x`
1076 if (pkgManager === 'pnpm') {
1077 // pnpm doesn't support the -- syntax
1078 return 'pnpm dlx '
1079 }
1080 if (pkgManager === 'yarn' && !isYarn1) {
1081 return 'yarn dlx '
1082 }
1083 if (pkgManager === 'bun') {
1084 return 'bun x '
1085 }
1086 if (pkgManager === 'deno') {
1087 return 'deno run -A npm:'
1088 }
1089 // Use `npm exec` in all other cases,
1090 // including Yarn 1.x and other custom npm clients.
1091 return customCommand.startsWith('npm exec -- ')
1092 ? 'npm exec -- '
1093 : 'npm exec '
1094 })
1095 )
1096}
1097
1098function getLabel(variant: FrameworkVariant) {
1099 const labelText = variant.display || variant.name

Callers 1

initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected