Skip to content

Commit 78dd9c4

Browse files
committed
getCreatePackageSpecifier
1 parent ad11fa9 commit 78dd9c4

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

app/utils/install-command.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ export interface ExecuteCommandOptions extends InstallCommandOptions {
125125
isCreatePackage?: boolean
126126
}
127127

128+
function getCreatePackageSpecifier(options: ExecuteCommandOptions): string | null {
129+
const { packageName, packageManager, isCreatePackage } = options
130+
131+
if (!isCreatePackage) {
132+
return null
133+
}
134+
const shortName = getCreateShortName(packageName)
135+
if (shortName === packageName) {
136+
return null
137+
}
138+
if (packageManager === 'deno') {
139+
// npm compatibility: npm:package
140+
return `npm:${shortName}`
141+
}
142+
143+
return shortName
144+
}
145+
128146
export function getExecuteCommand(options: ExecuteCommandOptions): string {
129147
return getExecuteCommandParts(options).join(' ')
130148
}
@@ -133,15 +151,10 @@ export function getExecuteCommandParts(options: ExecuteCommandOptions): string[]
133151
const pm = packageManagers.find(p => p.id === options.packageManager)
134152
if (!pm) return []
135153

136-
// For create-* packages, use the shorthand create command
137-
if (options.isCreatePackage) {
138-
const shortName = getCreateShortName(options.packageName, options.packageManager)
139-
if (shortName !== options.packageName) {
140-
if (options.packageManager === 'deno') {
141-
return ['deno', 'create', `npm:${shortName}`]
142-
}
143-
return [...pm.create.split(' '), shortName]
144-
}
154+
// For create-* packages, use the shorthand create command.
155+
const createSpecifier = getCreatePackageSpecifier(options)
156+
if (createSpecifier) {
157+
return [...pm.create.split(' '), createSpecifier]
145158
}
146159

147160
// Choose remote or local execute based on package type

shared/utils/package-analysis.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export function getCreatePackageName(packageName: string): string {
207207
* Extract the short name from a create-* package for display.
208208
* e.g., "create-vite" -> "vite", "@scope/create-foo" -> "@scope/foo", "@scope/create" -> "@scope"
209209
*/
210-
export function getCreateShortName(createPackageName: string, packageManager: string): string {
210+
export function getCreateShortName(createPackageName: string): string {
211211
if (createPackageName.startsWith('@')) {
212212
// @scope/create -> @scope, @scope/create-foo -> @scope/foo
213213
const slashIndex = createPackageName.indexOf('/')
@@ -225,9 +225,6 @@ export function getCreateShortName(createPackageName: string, packageManager: st
225225
if (createPackageName.startsWith('create-')) {
226226
return createPackageName.slice('create-'.length)
227227
}
228-
if (packageManager === 'deno') {
229-
createPackageName = `npm:${createPackageName}`
230-
}
231228
return createPackageName
232229
}
233230

0 commit comments

Comments
 (0)