Skip to content

Commit 4c41b7b

Browse files
knotbinghostdevv
andauthored
fix: command for create-* packages in Deno (#2357)
Co-authored-by: Willow (GHOST) <ghostdevbusiness@gmail.com>
1 parent af6a590 commit 4c41b7b

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

app/components/Terminal/Install.vue

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,12 @@ function getRunPartsForPM(pmId: PackageManagerId, command?: string) {
6060
// Generate create command parts for a specific package manager
6161
function getCreatePartsForPM(pmId: PackageManagerId) {
6262
if (!props.createPackageInfo) return []
63-
const pm = packageManagers.find(p => p.id === pmId)
64-
if (!pm) return []
65-
66-
const createPkgName = props.createPackageInfo.packageName
67-
let shortName: string
68-
if (createPkgName.startsWith('@')) {
69-
const slashIndex = createPkgName.indexOf('/')
70-
const name = createPkgName.slice(slashIndex + 1)
71-
shortName = name.startsWith('create-') ? name.slice('create-'.length) : name
72-
} else {
73-
shortName = createPkgName.startsWith('create-')
74-
? createPkgName.slice('create-'.length)
75-
: createPkgName
76-
}
77-
78-
return [...pm.create.split(' '), shortName]
63+
return getExecuteCommandParts({
64+
packageName: props.createPackageInfo.packageName,
65+
packageManager: pmId,
66+
jsrInfo: null,
67+
isCreatePackage: true,
68+
})
7969
}
8070
8171
// Generate @types install command parts for a specific package manager
@@ -102,7 +92,14 @@ function getFullRunCommand(command?: string) {
10292
10393
// Full create command for copying (uses current selected PM)
10494
function getFullCreateCommand() {
105-
return getCreatePartsForPM(selectedPM.value).join(' ')
95+
if (!props.createPackageInfo) return ''
96+
97+
return getExecuteCommand({
98+
packageName: props.createPackageInfo.packageName,
99+
packageManager: selectedPM.value,
100+
jsrInfo: null,
101+
isCreatePackage: true,
102+
})
106103
}
107104
108105
// Copy handlers

app/utils/install-command.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const packageManagers = [
4747
action: 'add',
4848
executeLocal: 'deno run',
4949
executeRemote: 'deno run',
50-
create: 'deno run',
50+
create: 'deno create',
5151
icon: 'i-simple-icons:deno',
5252
},
5353
{
@@ -125,6 +125,24 @@ export interface ExecuteCommandOptions extends InstallCommandOptions {
125125
isCreatePackage?: boolean
126126
}
127127

128+
function getCreatePackageSpecifier(options: ExecuteCommandOptions): string | null {
129+
if (!options.isCreatePackage) {
130+
return null
131+
}
132+
133+
const shortName = getCreateShortName(options.packageName)
134+
if (shortName === options.packageName) {
135+
return null
136+
}
137+
138+
if (options.packageManager === 'deno') {
139+
// npm compatibility: npm:package-name
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,12 +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)
139-
if (shortName !== options.packageName) {
140-
return [...pm.create.split(' '), shortName]
141-
}
154+
// For create-* packages, use the shorthand create command.
155+
const createSpecifier = getCreatePackageSpecifier(options)
156+
if (createSpecifier) {
157+
return [...pm.create.split(' '), createSpecifier]
142158
}
143159

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

test/unit/app/utils/install-command.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ describe('install command generation', () => {
381381
['pnpm', ['pnpm', 'create', 'vite']],
382382
['yarn', ['yarn', 'create', 'vite']],
383383
['bun', ['bun', 'create', 'vite']],
384-
['deno', ['deno', 'run', 'vite']],
384+
['deno', ['deno', 'create', 'npm:vite']],
385385
['vlt', ['vlx', 'vite']],
386386
] as const)('%s → %s', (pm, expected) => {
387387
expect(

0 commit comments

Comments
 (0)