Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5d3bea5
feat: Add download button component and install size types
Adebesin-Cell Feb 22, 2026
6a28f59
fix: Update function to use correct translation function
Adebesin-Cell Feb 22, 2026
cf35100
feat: Add tarball URLs for dependencies
Adebesin-Cell Feb 22, 2026
91e2933
style: Add tarball URLs to test dependencies
Adebesin-Cell Feb 23, 2026
7a6e29e
feat(Button, PackageDownloadButton): Add async download functionality
Adebesin-Cell Feb 24, 2026
14912af
fix: address CodeRabbit review feedback
Adebesin-Cell Mar 17, 2026
e4b803a
fix: installSize prop type mismatch (undefined → null)
Adebesin-Cell Mar 17, 2026
16e9dd7
fix: wrap DownloadButton in ClientOnly to prevent hydration mismatch
Adebesin-Cell Mar 17, 2026
6ecfc4d
fix: add download button skeleton to package loading state
Adebesin-Cell Mar 17, 2026
60aac4a
Merge branch 'main' into feat/download-button
Adebesin-Cell Mar 17, 2026
f393057
fix: remove useId() and ClientOnly from DownloadButton
Adebesin-Cell Mar 17, 2026
e98977e
fix: add missing composable imports to package page
Adebesin-Cell Mar 17, 2026
70f9d59
fix: make DownloadButton SSR-safe with useId and CSS reduced motion
Adebesin-Cell Mar 19, 2026
c8e7774
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 19, 2026
36461d7
fix: resolve hydration mismatch on package page
Adebesin-Cell Mar 19, 2026
401e44f
fix: add tarballUrl to dependency-resolver test expectation
Adebesin-Cell Mar 19, 2026
989dfa3
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 19, 2026
cef21bb
Update app/components/Package/DownloadButton.vue
Adebesin-Cell Mar 19, 2026
ba7281d
refactor: replace installSize prop with dependencies in DownloadButton
Adebesin-Cell Mar 19, 2026
1c7a680
fix: add missing useI18n import in DownloadButton
Adebesin-Cell Mar 19, 2026
b8c7570
fix: use $t auto-import instead of useI18n in DownloadButton
Adebesin-Cell Mar 19, 2026
cf724bd
fix: use static i18n keys in DownloadButton for static analysis
Adebesin-Cell Mar 19, 2026
b0de596
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 19, 2026
b1ee806
feat: show loading state for dependencies download option
Adebesin-Cell Mar 19, 2026
a91db2b
fix: hide dependencies option when package has no deps
Adebesin-Cell Mar 19, 2026
8f9ac17
feat: make dependencies download script cross-platform using Node.js
Adebesin-Cell Mar 19, 2026
eaa2de2
fix: correct dependencies download label from .sh to .js
Adebesin-Cell Mar 20, 2026
19eb93c
Merge branch 'main' into feat/download-button
Adebesin-Cell Mar 20, 2026
eb8c0da
fix: use Intl.Segmenter for avatar first character extraction
Adebesin-Cell Mar 20, 2026
c76c15c
Revert "fix: use Intl.Segmenter for avatar first character extraction"
Adebesin-Cell Mar 20, 2026
5e0882f
fix: remove download dependencies script option from download button
Adebesin-Cell Mar 21, 2026
f48b384
Merge branch 'main' into feat/download-button
Adebesin-Cell Mar 21, 2026
992b9ea
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 21, 2026
1b7487a
Merge branch 'main' into feat/download-button
ghostdevv Mar 21, 2026
b56aa2e
refactor: simplify button and css
ghostdevv Mar 21, 2026
52a9dcb
refactor: simplify
ghostdevv Mar 21, 2026
02d6bb1
Merge remote-tracking branch 'origin/main' into feat/download-button
ghostdevv Mar 21, 2026
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
15 changes: 10 additions & 5 deletions app/components/Button/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const props = withDefaults(
/** @default "button" */
type?: 'button' | 'submit'
/** @default "secondary" */
variant?: 'primary' | 'secondary'
variant?: 'primary' | 'secondary' | 'subtle'
/** @default "medium" */
size?: 'small' | 'medium'
/** Keyboard shortcut hint */
Expand Down Expand Up @@ -37,16 +37,21 @@ defineExpose({
<template>
<button
ref="el"
class="group gap-x-1 items-center justify-center font-mono border border-border rounded-md transition-all duration-200 disabled:(opacity-40 cursor-not-allowed border-transparent)"
class="group gap-x-1 items-center justify-center font-mono border rounded-md transition-all duration-200 disabled:(opacity-40 cursor-not-allowed border-transparent)"
:class="{
'inline-flex': !block,
'flex': block,
'text-sm px-4 py-2': size === 'medium',
'text-xs px-2 py-0.5': size === 'small',
'bg-transparent text-fg hover:enabled:(bg-fg/10) focus-visible:enabled:(bg-fg/10) aria-pressed:(bg-fg/10 border-fg/20 hover:enabled:(bg-fg/20 text-fg/50))':
'text-xs px-2 py-0.5': size === 'small' && variant !== 'subtle',
'text-xs px-2 py-2': size === 'small' && variant === 'subtle',
'border-border': variant !== 'subtle',
'border-border-subtle': variant === 'subtle',
'bg-transparent text-fg hover:enabled:(bg-fg/10) aria-pressed:(bg-fg/10 border-fg/20 hover:enabled:(bg-fg/20 text-fg/50))':
variant === 'secondary',
'text-bg bg-fg hover:enabled:(bg-fg/50) focus-visible:enabled:(bg-fg/50) aria-pressed:(bg-fg text-bg border-fg hover:enabled:(text-bg/50))':
'text-bg bg-fg hover:enabled:(bg-fg/50) aria-pressed:(bg-fg text-bg border-fg hover:enabled:(text-bg/50))':
variant === 'primary',
'bg-bg-subtle text-fg-muted hover:enabled:(text-fg border-border-hover) active:enabled:scale-95':
variant === 'subtle',
}"
:type="props.type"
:disabled="
Expand Down
253 changes: 253 additions & 0 deletions app/components/Package/DownloadButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
<script setup lang="ts">
import type { SlimPackumentVersion, InstallSizeResult } from '#shared/types'
import { onClickOutside, useEventListener } from '@vueuse/core'

const props = withDefaults(
defineProps<{
packageName: string
version: SlimPackumentVersion
installSize: InstallSizeResult | null
size?: 'small' | 'medium'
}>(),
{
size: 'medium',
},
)

const triggerRef = useTemplateRef('triggerRef')
const listRef = useTemplateRef('listRef')
const isOpen = shallowRef(false)
const highlightedIndex = shallowRef(-1)
const dropdownPosition = shallowRef<{ top: number; right: number } | null>(null)

const { t } = useI18n()
Comment thread
Adebesin-Cell marked this conversation as resolved.
Outdated
const menuId = useId()
const menuItems = computed(() => {
const items = [{ id: 'package', label: t('package.download.package'), icon: 'i-lucide:package' }]
if (props.installSize) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Since this doesn't have anything to do with "install size" per se, it feels like this is misusing the field a bit?

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.

Good catch! Fixed here ba7281d (this PR)

items.push({
id: 'dependencies',
label: t('package.download.dependencies'),
icon: 'i-lucide:list-tree',
})
}
return items
})

function getDropdownStyle(): Record<string, string> {
if (!dropdownPosition.value) return {}
return {
top: `${dropdownPosition.value.top}px`,
right: `${document.documentElement.clientWidth - dropdownPosition.value.right}px`,
}
}

function toggle() {
if (isOpen.value) {
close()
} else {
const rect = triggerRef.value?.$el?.getBoundingClientRect()
if (rect) {
dropdownPosition.value = {
top: rect.bottom + 4,
right: rect.right,
}
}
isOpen.value = true
highlightedIndex.value = 0
}
}

function close() {
isOpen.value = false
highlightedIndex.value = -1
}

onClickOutside(listRef, close, { ignore: [triggerRef] })

function handleKeydown(event: KeyboardEvent) {
if (!isOpen.value) {
if (event.key === 'ArrowDown' || event.key === 'Enter' || event.key === ' ') {
event.preventDefault()
toggle()
}
return
}

switch (event.key) {
case 'ArrowDown':
event.preventDefault()
highlightedIndex.value = (highlightedIndex.value + 1) % menuItems.value.length
break
case 'ArrowUp':
event.preventDefault()
highlightedIndex.value =
highlightedIndex.value <= 0 ? menuItems.value.length - 1 : highlightedIndex.value - 1
break
case 'Enter':
case ' ':
event.preventDefault()
handleAction(menuItems.value[highlightedIndex.value]?.id)
break
case 'Escape':
event.preventDefault()
close()
triggerRef.value?.$el?.focus()
break
case 'Tab':
close()
break
}
}

function handleAction(id: string | undefined) {
if (id === 'package') {
downloadPackage()
} else if (id === 'dependencies') {
downloadDependenciesScript()
}
close()
}

async function downloadPackage() {
const tarballUrl = props.version.dist.tarball
if (!tarballUrl) return

try {
const response = await fetch(tarballUrl)
if (!response.ok) {
throw new Error(`Failed to fetch tarball (${response.status})`)
}
const blob = await response.blob()
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = `${props.packageName.replace(/\//g, '__')}-${props.version.version}.tgz`
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
URL.revokeObjectURL(url)
} catch {
// Fallback to direct link for non-CORS or other issues, though download attribute may be ignored
const link = document.createElement('a')
link.href = tarballUrl
link.download = `${props.packageName.replace(/\//g, '__')}-${props.version.version}.tgz`
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
}

function downloadDependenciesScript() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm having a hard time imagining the value of this feature. What use cases are you thinking of?

My suggestion would be to punt on this part for this PR and revisit this in a follow-up. Does that seem ok?

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.

That’s fair, I’m happy to revisit later.

The main use case I had in mind is allowing users to download dependency tarballs directly so they can inspect or audit them before installing. It’s not something everyone would use, but it can be helpful in cases where people want more visibility into what’s being pulled in. It aligns with the original author of the feature as well #1528 (comment)

But we can talk about it if we want to implement it, I'm happy to work on that and make it cross-platform as well 👍

if (!props.installSize) return

const lines = [
'#!/bin/bash',
`# Download dependencies for ${props.packageName}@${props.version.version}`,
'mkdir -p node_modules',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This script will only work on Linux and macOS machines, so we'd need to either generate a Windows version conditionally or warn that it isn't Windows compatible.

But see my comment above – I'm not sure this feature is worthwhile 🤔.

'',
]

// Add root package
const rootTarball = props.version.dist.tarball
if (rootTarball) {
lines.push(`# ${props.packageName}@${props.version.version}`)
lines.push(
`curl -L "${rootTarball}" -o "${props.packageName.replace(/\//g, '__')}-${props.version.version}.tgz"`,
)
}

// Add dependencies
props.installSize.dependencies.forEach(dep => {
if (!dep.tarballUrl) return
lines.push(`# ${dep.name}@${dep.version}`)
lines.push(
`curl -L "${dep.tarballUrl}" -o "${dep.name.replace(/\//g, '__')}-${dep.version}.tgz"`,
)
})

const blob = new Blob([lines.join('\n')], { type: 'text/x-shellscript' })
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = `download-${props.packageName.replace(/\//g, '__')}-deps.sh`
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
URL.revokeObjectURL(url)
}

const prefersReducedMotion = useMediaQuery('(prefers-reduced-motion: reduce)')

useEventListener('scroll', () => isOpen.value && close(), { passive: true })

defineOptions({
inheritAttrs: false,
})
</script>

<template>
<ButtonBase
ref="triggerRef"
v-bind="$attrs"
type="button"
:variant="size === 'small' ? 'subtle' : 'secondary'"
:size
classicon="i-lucide:download"
:aria-expanded="isOpen"
aria-haspopup="menu"
:aria-controls="menuId"
@click="toggle"
@keydown="handleKeydown"
>
{{ $t('package.download.button') }}
<span
class="i-lucide:chevron-down ms-1"
:class="[
size === 'small' ? 'w-3 h-3' : 'w-3.5 h-3.5',
{ 'rotate-180': isOpen },
prefersReducedMotion ? '' : 'transition-transform duration-200',
]"
aria-hidden="true"
/>
</ButtonBase>

<Teleport to="body">
<Transition
:enter-active-class="prefersReducedMotion ? '' : 'transition-opacity duration-150'"
:enter-from-class="prefersReducedMotion ? '' : 'opacity-0'"
enter-to-class="opacity-100"
:leave-active-class="prefersReducedMotion ? '' : 'transition-opacity duration-100'"
leave-from-class="opacity-100"
:leave-to-class="prefersReducedMotion ? '' : 'opacity-0'"
>
<div
v-if="isOpen"
:id="menuId"
ref="listRef"
role="menu"
:style="getDropdownStyle()"
class="fixed bg-bg-subtle border border-border rounded-md shadow-lg z-50 py-1 w-64 overscroll-contain"
@keydown="handleKeydown"
>
<button
v-for="(item, index) in menuItems"
:key="item.id"
role="menuitem"
type="button"
class="w-full flex items-center gap-2 px-3 py-2 text-sm text-fg-muted transition-colors duration-150"
:class="[
highlightedIndex === index
? 'bg-bg-elevated text-fg'
: 'hover:bg-bg-elevated hover:text-fg',
]"
@click="handleAction(item.id)"
@mouseenter="highlightedIndex = index"
>
<span :class="item.icon" class="w-4 h-4" aria-hidden="true" />
{{ item.label }}
</button>
</div>
</Transition>
</Teleport>
</template>
13 changes: 11 additions & 2 deletions app/pages/package/[[org]]/[name].vue
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,17 @@
{{ $t('package.get_started.title') }}
</LinkBase>
</h2>
<!-- Package manager dropdown -->
<PackageManagerSelect />
<!-- Package manager dropdown + Download button -->
<div class="flex items-center gap-2">
<PackageDownloadButton
v-if="displayVersion"
:package-name="pkg.name"
:version="displayVersion"
:install-size="installSize ?? undefined"

Check failure on line 780 in app/pages/package/[[org]]/[name].vue

View workflow job for this annotation

GitHub Actions / 💪 Type check

Type 'InstallSizeResult | undefined' is not assignable to type 'InstallSizeResult | null'.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
size="small"
/>
<PackageManagerSelect />
</div>
</div>
<div>
<div
Expand Down
5 changes: 5 additions & 0 deletions i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,11 @@
"b": "{size} B",
"kb": "{size} kB",
"mb": "{size} MB"
},
"download": {
"button": "Download",
"package": "Download Package (.tgz)",
"dependencies": "Download Dependencies (.sh)"
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.

this says .sh but it downloads a JS script?

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.

Good catch! I changed the implementation a bit to run a script instead of downloading an sh file to make it adaptable to any platform.

}
},
"connector": {
Expand Down
15 changes: 15 additions & 0 deletions i18n/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,21 @@
}
},
"additionalProperties": false
},
"download": {
"type": "object",
"properties": {
"button": {
"type": "string"
},
"package": {
"type": "string"
},
"dependencies": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand Down
4 changes: 3 additions & 1 deletion server/utils/dependency-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export interface ResolvedPackage {
name: string
version: string
size: number
tarballUrl: string
optional: boolean
/** Depth level (only when trackDepth is enabled) */
depth?: DependencyDepth
Expand Down Expand Up @@ -152,13 +153,14 @@ export async function resolveDependencyTree(
if (!matchesPlatform(versionData)) return

const size = (versionData.dist as { unpackedSize?: number })?.unpackedSize ?? 0
const tarballUrl = versionData.dist.tarball
const key = `${name}@${version}`

// Build path for this package (path to parent + this package with version)
const currentPath = [...path, `${name}@${version}`]

if (!resolved.has(key)) {
const pkg: ResolvedPackage = { name, version, size, optional }
const pkg: ResolvedPackage = { name, version, size, tarballUrl, optional }
if (options.trackDepth) {
pkg.depth = level === 0 ? 'root' : level === 1 ? 'direct' : 'transitive'
pkg.path = currentPath
Expand Down
1 change: 1 addition & 0 deletions server/utils/install-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const calculateInstallSize = defineCachedFunction(
name: dep.name,
version: dep.version,
size: dep.size,
tarballUrl: dep.tarballUrl,
optional: dep.optional || undefined,
})
totalSize += dep.size
Expand Down
1 change: 1 addition & 0 deletions shared/types/install-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface DependencySize {
name: string
version: string
size: number
tarballUrl: string
/** True if this is an optional dependency */
optional?: boolean
}
Expand Down
Loading
Loading