Skip to content

Commit 20b17ed

Browse files
authored
feat(ui): display all engines in Compatibility section and make common ones pretty (#1004)
1 parent b655456 commit 20b17ed

File tree

3 files changed

+50
-26
lines changed

3 files changed

+50
-26
lines changed

app/components/Package/Compatibility.vue

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,55 @@
11
<script setup lang="ts">
22
const props = defineProps<{
3-
engines?: {
4-
node?: string
5-
npm?: string
6-
}
3+
engines?: Record<string, string>
74
}>()
5+
6+
const engineNames: Record<string, string> = {
7+
bun: 'Bun',
8+
node: 'Node.js',
9+
npm: 'npm',
10+
}
11+
12+
// Map engine name to icon class
13+
const engineIcons: Record<string, string> = {
14+
bun: 'i-simple-icons:bun',
15+
node: 'i-simple-icons:nodedotjs',
16+
npm: 'i-simple-icons:npm',
17+
}
18+
19+
function getName(engine: string): string {
20+
return engineNames[engine] || engine
21+
}
22+
23+
function getIcon(engine: string): string {
24+
return engineIcons[engine] || 'i-carbon:code'
25+
}
26+
27+
const sortedEngines = computed(() => {
28+
const entries = Object.entries(props.engines ?? {})
29+
return entries.sort(([a], [b]) => a.localeCompare(b))
30+
})
831
</script>
932
<template>
1033
<CollapsibleSection
11-
v-if="engines && (engines.node || engines.npm)"
34+
v-if="sortedEngines.length"
1235
:title="$t('package.compatibility')"
1336
id="compatibility"
1437
>
1538
<dl class="space-y-2">
16-
<div v-if="engines.node" class="flex justify-between gap-4 py-1">
17-
<dt class="text-fg-muted text-sm shrink-0">node</dt>
18-
<dd class="font-mono text-sm text-fg text-end" :title="engines.node">
19-
{{ engines.node }}
20-
</dd>
21-
</div>
22-
<div v-if="engines.npm" class="flex justify-between gap-4 py-1">
23-
<dt class="text-fg-muted text-sm shrink-0">npm</dt>
24-
<dd class="font-mono text-sm text-fg text-end" :title="engines.npm">
25-
{{ engines.npm }}
39+
<div
40+
v-for="[engine, version] in sortedEngines"
41+
:key="engine"
42+
class="flex justify-between gap-4 py-1"
43+
>
44+
<dt class="flex items-center gap-2 text-fg-muted text-sm shrink-0">
45+
<span
46+
:class="[getIcon(engine), 'inline-block w-4 h-4 shrink-0 text-fg-muted']"
47+
aria-hidden="true"
48+
/>
49+
{{ getName(engine) }}
50+
</dt>
51+
<dd class="font-mono text-sm text-fg text-end" :title="version">
52+
{{ version }}
2653
</dd>
2754
</div>
2855
</dl>

shared/utils/package-analysis.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ export type TypesStatus =
1212
export interface PackageAnalysis {
1313
moduleFormat: ModuleFormat
1414
types: TypesStatus
15-
engines?: {
16-
node?: string
17-
npm?: string
18-
}
15+
engines?: Record<string, string>
1916
/** Associated create-* package if it exists */
2017
createPackage?: CreatePackageInfo
2118
}
@@ -306,12 +303,7 @@ export function analyzePackage(
306303
return {
307304
moduleFormat,
308305
types,
309-
engines: pkg.engines
310-
? {
311-
node: pkg.engines.node,
312-
npm: pkg.engines.npm,
313-
}
314-
: undefined,
306+
engines: pkg.engines,
315307
createPackage: options?.createPackage,
316308
}
317309
}

test/unit/shared/utils/package-analysis.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,17 @@ describe('analyzePackage', () => {
217217
name: 'test',
218218
main: 'index.js',
219219
engines: {
220+
bun: '>=1.0.0',
220221
node: '>=18',
221222
npm: '>=9',
222223
},
223224
})
224225

225-
expect(result.engines).toEqual({ node: '>=18', npm: '>=9' })
226+
expect(result.engines).toEqual({
227+
bun: '>=1.0.0',
228+
node: '>=18',
229+
npm: '>=9',
230+
})
226231
})
227232

228233
it('detects @types package when typesPackage info is provided', () => {

0 commit comments

Comments
 (0)