Skip to content

Commit 7ce3b89

Browse files
committed
fix: improve esm/types/cjs badges
1 parent f5ffde3 commit 7ce3b89

7 files changed

Lines changed: 60 additions & 78 deletions

File tree

app/components/PackageMetricsBadges.vue

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,19 @@ const { data: analysis } = usePackageAnalysis(
1111
() => props.version,
1212
)
1313
14-
const moduleFormatLabel = computed(() => {
15-
if (!analysis.value) return null
16-
switch (analysis.value.moduleFormat) {
17-
case 'esm':
18-
return 'ESM'
19-
case 'cjs':
20-
return 'CJS'
21-
case 'dual':
22-
return 'CJS/ESM'
23-
default:
24-
return null
25-
}
14+
// ESM support
15+
const hasEsm = computed(() => {
16+
if (!analysis.value) return false
17+
return analysis.value.moduleFormat === 'esm' || analysis.value.moduleFormat === 'dual'
2618
})
2719
28-
const moduleFormatTooltip = computed(() => {
29-
if (!analysis.value) return ''
30-
switch (analysis.value.moduleFormat) {
31-
case 'esm':
32-
return $t('package.metrics.esm')
33-
case 'cjs':
34-
return $t('package.metrics.cjs')
35-
case 'dual':
36-
return $t('package.metrics.dual')
37-
default:
38-
return $t('package.metrics.unknown_format')
39-
}
20+
// CJS support (only show badge if present, omit if missing)
21+
const hasCjs = computed(() => {
22+
if (!analysis.value) return false
23+
return analysis.value.moduleFormat === 'cjs' || analysis.value.moduleFormat === 'dual'
4024
})
4125
26+
// Types support
4227
const hasTypes = computed(() => {
4328
if (!analysis.value) return false
4429
return analysis.value.types?.kind === 'included' || analysis.value.types?.kind === '@types'
@@ -48,11 +33,11 @@ const typesTooltip = computed(() => {
4833
if (!analysis.value) return ''
4934
switch (analysis.value.types?.kind) {
5035
case 'included':
51-
return $t('package.metrics.ts_included')
36+
return $t('package.metrics.types_included')
5237
case '@types':
53-
return $t('package.metrics.types_from', { package: analysis.value.types.packageName })
38+
return $t('package.metrics.types_available', { package: analysis.value.types.packageName })
5439
default:
55-
return ''
40+
return $t('package.metrics.no_types')
5641
}
5742
})
5843
@@ -68,29 +53,58 @@ const typesHref = computed(() => {
6853
<template>
6954
<ul v-if="analysis" class="flex items-center gap-1.5 list-none m-0 p-0">
7055
<!-- TypeScript types -->
71-
<li v-if="hasTypes">
56+
<li>
7257
<component
7358
:is="typesHref ? NuxtLink : 'span'"
7459
:to="typesHref"
75-
class="inline-flex items-center px-1.5 py-0.5 font-mono text-xs text-fg-muted bg-bg-muted border border-border rounded transition-colors duration-200"
76-
:class="
60+
class="inline-flex items-center gap-1 px-1.5 py-0.5 font-mono text-xs rounded transition-colors duration-200"
61+
:class="[
62+
hasTypes
63+
? 'text-fg-muted bg-bg-muted border border-border'
64+
: 'text-fg-subtle bg-bg-subtle border border-border-subtle',
7765
typesHref
7866
? 'hover:text-fg hover:border-border-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50'
79-
: ''
80-
"
67+
: '',
68+
]"
8169
:title="typesTooltip"
8270
>
83-
TS
71+
<span
72+
class="w-3 h-3"
73+
:class="hasTypes ? 'i-carbon-checkmark' : 'i-carbon-close'"
74+
aria-hidden="true"
75+
/>
76+
Types
8477
</component>
8578
</li>
8679

87-
<!-- Module format -->
88-
<li v-if="moduleFormatLabel">
80+
<!-- ESM badge (show with X if missing) -->
81+
<li>
82+
<span
83+
class="inline-flex items-center gap-1 px-1.5 py-0.5 font-mono text-xs rounded transition-colors duration-200"
84+
:class="
85+
hasEsm
86+
? 'text-fg-muted bg-bg-muted border border-border'
87+
: 'text-fg-subtle bg-bg-subtle border border-border-subtle'
88+
"
89+
:title="hasEsm ? $t('package.metrics.esm') : $t('package.metrics.no_esm')"
90+
>
91+
<span
92+
class="w-3 h-3"
93+
:class="hasEsm ? 'i-carbon-checkmark' : 'i-carbon-close'"
94+
aria-hidden="true"
95+
/>
96+
ESM
97+
</span>
98+
</li>
99+
100+
<!-- CJS badge (only show if present) -->
101+
<li v-if="hasCjs">
89102
<span
90-
class="inline-flex items-center px-1.5 py-0.5 font-mono text-xs text-fg-muted bg-bg-muted border border-border rounded transition-colors duration-200"
91-
:title="moduleFormatTooltip"
103+
class="inline-flex items-center gap-1 px-1.5 py-0.5 font-mono text-xs text-fg-muted bg-bg-muted border border-border rounded transition-colors duration-200"
104+
:title="$t('package.metrics.cjs')"
92105
>
93-
{{ moduleFormatLabel }}
106+
<span class="i-carbon-checkmark w-3 h-3" aria-hidden="true" />
107+
CJS
94108
</span>
95109
</li>
96110
</ul>

app/pages/[...package].vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,10 @@ defineOgImageComponent('Package', {
508508
v-if="displayVersion"
509509
:package-name="pkg.name"
510510
:version="displayVersion.version"
511-
class="self-center ml-1 sm:ml-2"
511+
class="self-baseline ml-1 sm:ml-2"
512512
/>
513513
<template #fallback>
514-
<ul class="flex items-center gap-1.5 self-center ml-1 sm:ml-2">
514+
<ul class="flex items-center gap-1.5 self-baseline ml-1 sm:ml-2">
515515
<li class="skeleton w-8 h-5 rounded" />
516516
<li class="skeleton w-12 h-5 rounded" />
517517
</ul>

i18n/locales/de.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,6 @@
203203
"title": "Ausprobieren",
204204
"choose": "Playground wählen"
205205
},
206-
"metrics": {
207-
"esm": "Nur ES-Module",
208-
"cjs": "Nur CommonJS",
209-
"dual": "Unterstützt CommonJS und ES-Module",
210-
"unknown_format": "Unbekanntes Modulformat",
211-
"ts_included": "TypeScript-Typen enthalten",
212-
"types_from": "Typen von {package}"
213-
},
214206
"license": {
215207
"view_spdx": "Lizenztext auf SPDX ansehen"
216208
},

i18n/locales/en.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@
205205
"choose": "choose playground"
206206
},
207207
"metrics": {
208-
"esm": "ES Modules only",
209-
"cjs": "CommonJS only",
210-
"dual": "Supports both CommonJS and ES Modules",
211-
"unknown_format": "Unknown module format",
212-
"ts_included": "TypeScript types included",
213-
"types_from": "Types from {package}"
208+
"esm": "ES Modules supported",
209+
"cjs": "CommonJS supported",
210+
"no_esm": "No ES Modules support",
211+
"types_included": "Types included",
212+
"types_available": "Types available via {package}",
213+
"no_types": "No TypeScript types"
214214
},
215215
"license": {
216216
"view_spdx": "View license text on SPDX"

i18n/locales/fr.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,6 @@
194194
"title": "Essayer",
195195
"choose": "choisir un playground"
196196
},
197-
"metrics": {
198-
"esm": "ES Modules uniquement",
199-
"cjs": "CommonJS uniquement",
200-
"dual": "Supporte CommonJS et ES Modules",
201-
"unknown_format": "Format de module inconnu",
202-
"ts_included": "Types TypeScript inclus",
203-
"types_from": "Types depuis {package}"
204-
},
205197
"license": {
206198
"view_spdx": "Voir le texte de la licence sur SPDX"
207199
},

i18n/locales/it.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,6 @@
204204
"title": "Provalo",
205205
"choose": "sciegli il playground"
206206
},
207-
"metrics": {
208-
"esm": "solo ES Modules",
209-
"cjs": "solo CommonJS",
210-
"dual": "Supporto per entrambi CommonJS e ES Modules",
211-
"unknown_format": "Formato modulo sconosciuto",
212-
"ts_included": "TypeScript types incluso",
213-
"types_from": "Types da {package}"
214-
},
215207
"license": {
216208
"view_spdx": "Vedi il testo della licenza su SPDX"
217209
},

i18n/locales/zh-CN.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,6 @@
204204
"title": "试一试",
205205
"choose": "选择 Playground"
206206
},
207-
"metrics": {
208-
"esm": "只支持 ES Modules",
209-
"cjs": "只支持 CommonJS",
210-
"dual": "同时支持 CommonJS 和 ES Modules",
211-
"unknown_format": "未知模块格式",
212-
"ts_included": "包含 TypeScript 类型",
213-
"types_from": "类型来自 {package}"
214-
},
215207
"license": {
216208
"view_spdx": "在 SPDX 上查看许可证文本"
217209
},

0 commit comments

Comments
 (0)