Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8ebefec
feat: version history page display download count
btea Mar 21, 2026
6e6bbcb
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 21, 2026
c12f507
feat: update
btea Mar 21, 2026
9923d48
feat: update
btea Mar 24, 2026
a58326f
feat: update
btea Mar 24, 2026
58a0108
style: update
btea Mar 24, 2026
9ff48d8
feat: update
btea Mar 24, 2026
b3a6436
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 24, 2026
189bef9
feat: update
btea Mar 24, 2026
e1b1005
feat: update
btea Mar 24, 2026
bfba80e
style: update
btea Mar 26, 2026
95240a9
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 26, 2026
3a58861
feat: update
btea Mar 26, 2026
333d8ae
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 26, 2026
c9dd826
feat: update
btea Mar 30, 2026
3d451f3
feat: update
btea Mar 30, 2026
47f726e
Merge branch 'main' into feat/history-versions-display-download
ghostdevv Apr 4, 2026
604836a
Merge remote-tracking branch 'origin/main' into feat/history-versions…
btea Apr 5, 2026
8af1162
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 5, 2026
6c5bdc3
feat: update
btea Apr 5, 2026
fa864fd
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 5, 2026
2642a3c
feat: update
btea Apr 6, 2026
f843c73
Merge branch 'main' into feat/history-versions-display-download
btea Apr 7, 2026
35491c0
feat: move deprecated
btea Apr 12, 2026
70af23b
feat: move provenance
btea Apr 12, 2026
1645aa5
test: update
btea Apr 12, 2026
e5040cc
test: update
btea Apr 12, 2026
1cfedb2
refactor: code
btea Apr 14, 2026
7871c06
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 14, 2026
577afc2
style: update
btea Apr 15, 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
97 changes: 94 additions & 3 deletions app/pages/package/[[org]]/[name]/versions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ definePageMeta({
name: 'package-versions',
})

interface NpmWebsiteVersionDownload {
version: string
downloads: number
}

interface NpmWebsiteVersionsResponse {
weeklyDownloads?: number
versions: NpmWebsiteVersionDownload[]
}

/** Number of flat items (headers + version rows) to render statically during SSR */
const SSR_COUNT = 20

Expand Down Expand Up @@ -49,6 +59,47 @@ const distTags = computed(() => versionSummary.value?.distTags ?? {})
const versionStrings = computed(() => versionSummary.value?.versions ?? [])
const versionTimes = computed(() => versionSummary.value?.time ?? {})

const { data: npmWebsiteVersions } = useLazyFetch<NpmWebsiteVersionsResponse>(
() => `/api/registry/npmjs-versions/${encodeURIComponent(packageName.value)}`,
Comment thread
btea marked this conversation as resolved.
Outdated
{
key: () => `npmjs-versions:${packageName.value}`,
deep: false,
default: () => ({ versions: [] }),
getCachedData(key, nuxtApp) {
return nuxtApp.static.data[key] ?? nuxtApp.payload.data[key]
},
},
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const numberFormatter = useNumberFormatter()
const versionDownloadsMap = computed(
() =>
new Map(
(npmWebsiteVersions.value?.versions ?? []).map(({ version, downloads }) => [
version,
downloads,
]),
),
)

function getVersionDownloads(version: string): number | undefined {
return versionDownloadsMap.value.get(version)
}

function getGroupDownloads(versions: string[]): number | undefined {
let total = 0
let hasValue = false

for (const version of versions) {
const downloads = getVersionDownloads(version)
if (downloads === undefined) continue
total += downloads
hasValue = true
}
Comment thread
btea marked this conversation as resolved.

return hasValue ? total : undefined
}

// ─── Phase 2: full metadata (loaded on first group expand) ────────────────────
// Fetches deprecated status, provenance, and exact times needed for version rows.

Expand Down Expand Up @@ -241,6 +292,14 @@ const flatItems = computed<FlatItem[]>(() => {
>
</div>
<!-- Right: date + provenance -->
<div
v-if="getVersionDownloads(latestTagRow!.version) !== undefined"
class="text-sm font-medium text-fg tabular-nums shrink-0"
:aria-label="$t('package.downloads.title')"
dir="ltr"
>
{{ numberFormatter.format(getVersionDownloads(latestTagRow!.version)!) }}
</div>
Comment thread
btea marked this conversation as resolved.
Outdated
<div class="flex flex-col items-end gap-1.5 shrink-0 relative z-10">
<ProvenanceBadge
v-if="fullVersionMap?.get(latestTagRow!.version)?.hasProvenance"
Expand Down Expand Up @@ -290,6 +349,14 @@ const flatItems = computed<FlatItem[]>(() => {
</LinkBase>

<!-- Date -->
<span
v-if="getVersionDownloads(row.version) !== undefined"
class="text-xs text-fg-muted shrink-0 tabular-nums w-24 text-end"
:aria-label="$t('package.downloads.title')"
dir="ltr"
>
{{ numberFormatter.format(getVersionDownloads(row.version)!) }}
</span>
<DateTime
v-if="getVersionTime(row.version)"
:datetime="getVersionTime(row.version)!"
Expand Down Expand Up @@ -373,7 +440,15 @@ const flatItems = computed<FlatItem[]>(() => {
</span>
<span class="text-sm font-medium">{{ item.label }}</span>
<span class="text-xs text-fg-subtle">({{ item.versions.length }})</span>
<span class="ms-auto flex items-center gap-3 shrink-0">
<span
v-if="getGroupDownloads(item.versions) !== undefined"
class="ms-auto text-xs text-fg-muted tabular-nums w-24 text-end"
:aria-label="$t('package.downloads.title')"
dir="ltr"
>
{{ numberFormatter.format(getGroupDownloads(item.versions)!) }}
</span>
<span class="flex items-center gap-3 shrink-0">
<span class="text-xs text-fg-muted" dir="ltr">{{ item.versions[0] }}</span>
<DateTime
v-if="getVersionTime(item.versions[0])"
Expand Down Expand Up @@ -437,8 +512,16 @@ const flatItems = computed<FlatItem[]>(() => {
</span>
</div>

<span
v-if="getVersionDownloads(item.version) !== undefined"
class="text-xs text-fg-muted tabular-nums w-24 text-end shrink-0"
:aria-label="$t('package.downloads.title')"
dir="ltr"
>
{{ numberFormatter.format(getVersionDownloads(item.version)!) }}
</span>
<!-- Right side -->
<div class="flex items-center gap-2 shrink-0 relative z-10">
<div class="flex items-center gap-2 shrink-0 relative z-10 w-36 justify-end">
<!-- Metadata: date + provenance -->
<DateTime
v-if="getVersionTime(item.version)"
Expand Down Expand Up @@ -477,7 +560,15 @@ const flatItems = computed<FlatItem[]>(() => {
</span>
<span class="text-sm font-medium">{{ item.label }}</span>
<span class="text-xs text-fg-subtle">({{ item.versions.length }})</span>
<span class="ms-auto flex items-center gap-3 shrink-0">
<span
v-if="getGroupDownloads(item.versions) !== undefined"
class="ms-auto text-xs text-fg-muted tabular-nums w-24 text-end"
:aria-label="$t('package.downloads.title')"
dir="ltr"
>
{{ numberFormatter.format(getGroupDownloads(item.versions)!) }}
</span>
<span class="flex items-center gap-3 shrink-0">
<span class="text-xs text-fg-muted" dir="ltr">{{ item.versions[0] }}</span>
<DateTime
v-if="getVersionTime(item.versions[0] ?? '')"
Expand Down
46 changes: 46 additions & 0 deletions server/api/registry/npmjs-versions/[...pkg].get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { CACHE_MAX_AGE_ONE_HOUR } from '#shared/utils/constants'
import { fetchNpmVersionDownloadsFromApi } from '#server/utils/npm-website-versions'

export default defineCachedEventHandler(
async event => {
const pkgParam = getRouterParam(event, 'pkg')
if (!pkgParam) {
throw createError({ statusCode: 404, message: 'Package name is required' })
}

const packageName = decodeURIComponent(pkgParam)

try {
const parsed = await fetchNpmVersionDownloadsFromApi(packageName)
Comment thread
btea marked this conversation as resolved.
Outdated

if (parsed.versions.length === 0) {
throw createError({
statusCode: 502,
message: 'Failed to fetch version download data',
})
}

return {
packageName,
source: 'npm-api',
sourceUrl: `https://api.npmjs.org/versions/${encodePackageName(packageName)}/last-week`,
fetchedAt: new Date().toISOString(),
weeklyDownloads: parsed.weeklyDownloads,
versions: parsed.versions,
}
} catch (error: unknown) {
handleApiError(error, {
statusCode: 502,
message: 'Failed to fetch version download data from npm API',
})
}
},
{
maxAge: CACHE_MAX_AGE_ONE_HOUR,
swr: true,
getKey: event => {
const pkg = getRouterParam(event, 'pkg') ?? ''
return `npmjs-versions:v2:${pkg}`
},
},
)
55 changes: 55 additions & 0 deletions server/utils/npm-website-versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export interface NpmWebsiteVersionDownload {
version: string
downloads: number
}

export interface NpmWebsiteVersionsData {
weeklyDownloads?: number
versions: NpmWebsiteVersionDownload[]
}

interface NpmApiVersionDownloadsResponse {
downloads: Record<string, number>
}

interface NpmApiWeeklyDownloadsResponse {
downloads: number
}

export async function fetchNpmVersionDownloadsFromApi(
packageName: string,
): Promise<NpmWebsiteVersionsData> {
const encodedName = encodePackageName(packageName)

const [versionsResponse, weeklyDownloadsResponse] = await Promise.all([
fetch(`https://api.npmjs.org/versions/${encodedName}/last-week`),
fetch(`https://api.npmjs.org/downloads/point/last-week/${encodedName}`),
])

if (!versionsResponse.ok) {
if (versionsResponse.status === 404) {
throw createError({
statusCode: 404,
message: 'Package not found',
})
}

throw createError({
statusCode: 502,
message: 'Failed to fetch version download data from npm API',
})
}

const versionsData = (await versionsResponse.json()) as NpmApiVersionDownloadsResponse
const weeklyDownloadsData = weeklyDownloadsResponse.ok
? ((await weeklyDownloadsResponse.json()) as NpmApiWeeklyDownloadsResponse)
: null
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

return {
weeklyDownloads: weeklyDownloadsData?.downloads,
versions: Object.entries(versionsData.downloads).map(([version, downloads]) => ({
version,
downloads,
})),
}
}
Loading