Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(modules): add nuxt.care health score badges #924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Flo0806 wants to merge 1 commit into nuxt:main
base: main
Choose a base branch
Loading
from Flo0806:feat/nuxt-care
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
edited
Loading

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!

antfu reacted with heart emoji
])

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 }
}

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /