forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackageInstallScripts.vue
More file actions
108 lines (102 loc) · 3.89 KB
/
PackageInstallScripts.vue
File metadata and controls
108 lines (102 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<script setup lang="ts">
const props = defineProps<{
packageName: string
installScripts: {
scripts: ('preinstall' | 'install' | 'postinstall')[]
content?: Record<string, string>
npxDependencies: Record<string, string>
}
}>()
const outdatedNpxDeps = useOutdatedDependencies(() => props.installScripts.npxDependencies)
const hasNpxDeps = computed(() => Object.keys(props.installScripts.npxDependencies).length > 0)
const sortedNpxDeps = computed(() => {
return Object.entries(props.installScripts.npxDependencies).sort(([a], [b]) => a.localeCompare(b))
})
const isExpanded = shallowRef(false)
</script>
<template>
<section aria-labelledby="install-scripts-heading">
<h2
id="install-scripts-heading"
class="text-xs text-fg-subtle uppercase tracking-wider mb-3 flex items-center gap-2"
>
<span class="i-carbon-warning-alt w-3 h-3 text-yellow-500" aria-hidden="true" />
Install Scripts
</h2>
<!-- Script list: name as label, content below -->
<dl class="space-y-2 m-0">
<div v-for="scriptName in installScripts.scripts" :key="scriptName">
<dt class="font-mono text-xs text-fg-muted">{{ scriptName }}</dt>
<dd
tabindex="0"
class="font-mono text-sm text-fg-subtle m-0 truncate focus:whitespace-normal focus:overflow-visible cursor-help rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50"
:title="installScripts.content?.[scriptName]"
>
{{ installScripts.content?.[scriptName] || '(script)' }}
</dd>
</div>
</dl>
<!-- npx packages (expandable) -->
<div v-if="hasNpxDeps" class="mt-3">
<button
type="button"
class="flex items-center gap-1.5 text-xs text-fg-muted hover:text-fg transition-colors duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50 rounded"
:aria-expanded="isExpanded"
aria-controls="npx-packages-details"
@click="isExpanded = !isExpanded"
>
<span
class="i-carbon-chevron-right w-3 h-3 transition-transform duration-200"
:class="{ 'rotate-90': isExpanded }"
aria-hidden="true"
/>
{{ sortedNpxDeps.length }} npx package{{ sortedNpxDeps.length !== 1 ? 's' : '' }}
</button>
<ul
v-show="isExpanded"
id="npx-packages-details"
class="mt-2 space-y-1 list-none m-0 p-0 pl-4"
>
<li
v-for="[dep, version] in sortedNpxDeps"
:key="dep"
class="flex items-center justify-between py-0.5 text-sm gap-2"
>
<NuxtLink
:to="{ name: 'package', params: { package: dep.split('/') } }"
class="font-mono text-fg-muted hover:text-fg transition-colors duration-200 truncate min-w-0"
>
{{ dep }}
</NuxtLink>
<span class="flex items-center gap-1">
<span
v-if="
outdatedNpxDeps[dep] &&
outdatedNpxDeps[dep].resolved !== outdatedNpxDeps[dep].latest
"
class="shrink-0"
:class="getVersionClass(outdatedNpxDeps[dep])"
:title="getOutdatedTooltip(outdatedNpxDeps[dep])"
aria-hidden="true"
>
<span class="i-carbon-warning-alt w-3 h-3 block" />
</span>
<span
class="font-mono text-xs text-right truncate"
:class="getVersionClass(outdatedNpxDeps[dep])"
:title="
outdatedNpxDeps[dep]
? outdatedNpxDeps[dep].resolved === outdatedNpxDeps[dep].latest
? `currently ${outdatedNpxDeps[dep].latest}`
: getOutdatedTooltip(outdatedNpxDeps[dep])
: version
"
>
{{ version }}
</span>
</span>
</li>
</ul>
</div>
</section>
</template>