forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallScripts.vue
More file actions
150 lines (142 loc) · 5.13 KB
/
InstallScripts.vue
File metadata and controls
150 lines (142 loc) · 5.13 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<script setup lang="ts">
import { getOutdatedTooltip, getVersionClass } from '~/utils/npm/outdated-dependencies'
const props = defineProps<{
packageName: string
version: string
installScripts: {
scripts: ('preinstall' | 'install' | 'postinstall')[]
content?: Record<string, string>
npxDependencies: Record<string, string>
}
}>()
function getCodeLink(filePath: string): string {
return `/code/${props.packageName}/v/${props.version}/${filePath}`
}
const scriptParts = computed(() => {
const parts: Record<string, { prefix: string | null; filePath: string | null; link: string }> = {}
for (const scriptName of props.installScripts.scripts) {
const content = props.installScripts.content?.[scriptName]
if (!content) continue
const parsed = parseNodeScript(content)
if (parsed) {
parts[scriptName] = {
prefix: parsed.prefix,
filePath: parsed.filePath,
link: getCodeLink(parsed.filePath),
}
} else {
parts[scriptName] = { prefix: null, filePath: null, link: getCodeLink('package.json') }
}
}
return parts
})
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>
<CollapsibleSection
:title="$t('package.install_scripts.title')"
id="installScripts"
icon="i-carbon:warning-alt w-3 h-3 text-yellow-500"
>
<!-- 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
class="font-mono text-sm text-fg-subtle m-0 truncate"
:title="installScripts.content?.[scriptName]"
>
<template v-if="installScripts.content?.[scriptName] && scriptParts[scriptName]">
<template v-if="scriptParts[scriptName].prefix">
{{ scriptParts[scriptName].prefix
}}<LinkBase :to="scriptParts[scriptName].link">{{
scriptParts[scriptName].filePath
}}</LinkBase>
</template>
<LinkBase v-else :to="scriptParts[scriptName].link">
{{ installScripts.content[scriptName] }}
</LinkBase>
</template>
<span v-else tabindex="0" class="cursor-help">
{{ $t('package.install_scripts.script_label') }}
</span>
</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-accent/70 rounded"
:aria-expanded="isExpanded"
aria-controls="npx-packages-details"
@click="isExpanded = !isExpanded"
>
<span
class="i-carbon:chevron-right rtl-flip w-3 h-3 transition-transform duration-200"
:class="{ 'rotate-90': isExpanded }"
aria-hidden="true"
/>
{{
$t(
'package.install_scripts.npx_packages',
{ count: sortedNpxDeps.length },
sortedNpxDeps.length,
)
}}
</button>
<ul
v-show="isExpanded"
id="npx-packages-details"
class="mt-2 space-y-1 list-none m-0 p-0 ps-4"
>
<li
v-for="[dep, version] in sortedNpxDeps"
:key="dep"
class="flex items-center justify-between py-0.5 text-sm gap-2"
>
<LinkBase
:to="packageRoute(dep)"
class="font-mono text-fg-muted hover:text-fg transition-colors duration-200 truncate min-w-0"
>
{{ dep }}
</LinkBase>
<span class="flex items-center gap-1">
<TooltipApp
v-if="
outdatedNpxDeps[dep] &&
outdatedNpxDeps[dep].resolved !== outdatedNpxDeps[dep].latest
"
class="shrink-0 p-2 -m-2"
:class="getVersionClass(outdatedNpxDeps[dep])"
aria-hidden="true"
:text="getOutdatedTooltip(outdatedNpxDeps[dep], $t)"
>
<span class="i-carbon:warning-alt w-3 h-3" />
</TooltipApp>
<span
class="font-mono text-xs text-end truncate"
:class="getVersionClass(outdatedNpxDeps[dep])"
:title="
outdatedNpxDeps[dep]
? outdatedNpxDeps[dep].resolved === outdatedNpxDeps[dep].latest
? $t('package.install_scripts.currently', {
version: outdatedNpxDeps[dep].latest,
})
: getOutdatedTooltip(outdatedNpxDeps[dep], $t)
: version
"
>
{{ version }}
</span>
</span>
</li>
</ul>
</div>
</CollapsibleSection>
</template>