Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions packages/devtools/client/components/ModuleItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const terminalId = useCurrentTerminalId()

<template>
<ModuleItemBase :mod="mod" :info="staticInfo">
<template #badge>
<ModuleScoreBadge class="ml-1" :npm="data.npm" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the UI styling, I wonder if this would be better as an item in the table instead of the badge? As I consider the "score" is only one of the aspects of the modules, and does not always reflects if users needs to do any action on that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A short table item inside the module item? Sure. make sense - I will try something

</template>
<template #items>
<div v-if="mod.entryPath" flex="~ gap-2" title="Open on filesystem">
<span i-carbon-folder-move-to flex-none text-lg op50 />
Expand Down
30 changes: 30 additions & 0 deletions packages/devtools/client/components/ModuleScoreBadge.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script setup lang="ts">
import { computed } from 'vue'
import { statusColors, useModuleScores } from '~/composables/state-module-scores'

const props = defineProps<{
npm?: string
}>()

const { scores, loading } = useModuleScores()
const score = computed(() => props.npm ? scores.value.get(props.npm) : undefined)
const color = computed(() => score.value ? statusColors[score.value.status] : undefined)
</script>

<template>
<span v-if="loading && !score" class="n-badge" op50>
<span i-carbon-circle-dash animate-spin />
</span>
<a
v-else-if="score"
inline-flex items-center
:href="`https://nuxt.care/?search=npm:${npm}`"
target="_blank"
rel="noopener"
:title="`Nuxt Care Score: ${score.score}/100 (${score.status})`"
>
<span class="n-badge" :style="{ color, borderColor: color }">
{{ score.status }}
</span>
</a>
</template>
74 changes: 74 additions & 0 deletions packages/devtools/client/composables/state-module-scores.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { watchDebounced } from '@vueuse/core'
import { computed, ref } from 'vue'
import { useInstalledModules } from './state-modules'

export type ModuleStatus = 'optimal' | 'stable' | 'degraded' | 'critical'

export interface ModuleScore {
name: string
npm: string
score: number
status: ModuleStatus
lastUpdated: string | null
}

// nuxt.care color schema
export const statusColors: Record<ModuleStatus, string> = {
optimal: '#22c55e',
stable: '#84cc16',
degraded: '#eab308',
critical: '#ef4444',
}

const API_BASE = 'https://nuxt.care/api/v1/modules/'
const scores = ref<Map<string, ModuleScore>>(new Map())
const fetched = new Set<string>()
const loading = ref(false)

export function useModuleScores() {
const installedModules = useInstalledModules()

const npmNames = computed(() =>
installedModules.value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohter than the fixed "installedModules", we also reuse the UI for modules to install, I wonder if we also need to show the scores (or actually more interesting/useful?) when users are installing new modules.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally forgot about that. Yes I will work on it!

.map(m => m.info?.npm || m.name)
.filter((name): name is string => !!name && !name.startsWith('.')),
)

watchDebounced(npmNames, async (names) => {
// Only fetch modules we haven't fetched yet
const missing = names.filter(name => !fetched.has(name))
if (!missing.length)
return

missing.forEach(name => fetched.add(name))
loading.value = true

try {
const params = new URLSearchParams([
['slim', 'true'],
...missing.map(name => ['package', name]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a bit out-of-scope of the current PR, but I wonder if nuxt.care should also count for module versions? In many cases, the users might have an out-dated, no-longer-maintained version installed, where the "score" should be relatively low and ask users to upgrade.

Copy link
Member Author

@Flo0806 Flo0806 Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a nice idea! But this time nuxt care doesn't save a history. So I always see the current state. To say: new version available - yes, but nuxt care will have no different score between different versions with the current state.
Anthony, I love this idea... and now I'm sure I can check older versions! I need some days, but I will implement this great feature!

])

const response = await $fetch<ModuleScore[]>(`${API_BASE}?${params}`)

// Merge with existing scores
for (const item of response)
scores.value.set(item.npm, item)
}
catch (e: any) {
// Only block retry for CORS or rate limit, allow retry for other errors
const isCors = e?.message?.includes('NetworkError') || e?.message?.includes('CORS')
const isRateLimit = (e?.response?.status ?? e?.status) === 429

if (!isCors && !isRateLimit)
missing.forEach(name => fetched.delete(name))

console.warn('[DevTools] Failed to fetch module scores:', e)
}
finally {
loading.value = false
}
}, { debounce: 300, immediate: true })

return { scores, loading }
}