Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 14 additions & 17 deletions app/components/Terminal/Install.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,12 @@ function getRunPartsForPM(pmId: PackageManagerId, command?: string) {
// Generate create command parts for a specific package manager
function getCreatePartsForPM(pmId: PackageManagerId) {
if (!props.createPackageInfo) return []
const pm = packageManagers.find(p => p.id === pmId)
if (!pm) return []

const createPkgName = props.createPackageInfo.packageName
let shortName: string
if (createPkgName.startsWith('@')) {
const slashIndex = createPkgName.indexOf('/')
const name = createPkgName.slice(slashIndex + 1)
shortName = name.startsWith('create-') ? name.slice('create-'.length) : name
} else {
shortName = createPkgName.startsWith('create-')
? createPkgName.slice('create-'.length)
: createPkgName
}

return [...pm.create.split(' '), shortName]
return getExecuteCommandParts({
packageName: props.createPackageInfo.packageName,
packageManager: pmId,
jsrInfo: null,
isCreatePackage: true,
})
}

// Generate @types install command parts for a specific package manager
Expand All @@ -102,7 +92,14 @@ function getFullRunCommand(command?: string) {

// Full create command for copying (uses current selected PM)
function getFullCreateCommand() {
return getCreatePartsForPM(selectedPM.value).join(' ')
if (!props.createPackageInfo) return ''

return getExecuteCommand({
packageName: props.createPackageInfo.packageName,
packageManager: selectedPM.value,
jsrInfo: null,
isCreatePackage: true,
})
}

// Copy handlers
Expand Down
5 changes: 4 additions & 1 deletion app/utils/install-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const packageManagers = [
action: 'add',
executeLocal: 'deno run',
executeRemote: 'deno run',
create: 'deno run',
create: 'deno create',
icon: 'i-simple-icons:deno',
},
{
Expand Down Expand Up @@ -137,6 +137,9 @@ export function getExecuteCommandParts(options: ExecuteCommandOptions): string[]
if (options.isCreatePackage) {
const shortName = getCreateShortName(options.packageName)
if (shortName !== options.packageName) {
if (options.packageManager === 'deno') {
return ['deno', 'create', `npm:${shortName}`]
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we instead set the shortName to npm:? How are we handling the other cases where we need to prefix with npm: for deno?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a helper function getCreatePackageSpecifier to handle this logic, similar to the getPackageSpecifier function that handles other cases of the npm: prefix.

This logic is purposefully separate from the other npm prefix logic because JSR is not yet handled (out of this PR's scope) for create-* packages and if checks for matching JSR packages of create-* packages are added in the future (as they are for the other logic), it would be very different from the JSR logic in getPackageSpecifier because:

  • jsr: specifier isn't needed for create command, unlike install command
  • JSR "create" or "template" packages are required to have a ./create export

return [...pm.create.split(' '), shortName]
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/app/utils/install-command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ describe('install command generation', () => {
['pnpm', ['pnpm', 'create', 'vite']],
['yarn', ['yarn', 'create', 'vite']],
['bun', ['bun', 'create', 'vite']],
['deno', ['deno', 'run', 'vite']],
['deno', ['deno', 'create', 'npm:vite']],
['vlt', ['vlx', 'vite']],
] as const)('%s → %s', (pm, expected) => {
expect(
Expand Down
Loading