-
Notifications
You must be signed in to change notification settings - Fork 249
feat: implement nuxt.care #2189
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
12
commits into
nuxt:main
Choose a base branch
from
Flo0806:feat/nuxt-care
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
913f066
feat: implement nuxt.care
Flo0806 36ba633
fix: type and css
Flo0806 1e573d4
docs: add nuxt.care badge
Flo0806 d452aff
fix: contrast color
Flo0806 b284b5e
fix: load health in chunks
Flo0806 b2d7124
fix: timeout
Flo0806 653518b
Merge branch 'main' into feat/nuxt-care
atinux 86b216d
chore: refactor health badge
Flo0806 cbd6a78
fix: badge name, remove wrong settings.json
Flo0806 4f48fc7
Merge branch 'main' into feat/nuxt-care
HugoRCD 965e1e6
Merge remote-tracking branch 'upstream/main' into feat/nuxt-care
Flo0806 80d765d
chore: health badge makeover
Flo0806 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { parseMarkdown } from '@nuxtjs/mdc/runtime' | ||
|
|
||
| import type { H3Event } from 'h3' | ||
| import type { BaseModule, Module, ModuleContributor, ModuleStats } from '#shared/types' | ||
| import type { BaseModule, Module, ModuleContributor, ModuleHealth, ModuleStats } from '#shared/types' | ||
| import type { NpmDownloadStats } from '../types/npm' | ||
|
|
||
| export function isBot(username: string) { | ||
|
|
@@ -83,6 +83,73 @@ export async function fetchModuleContributors(_event: H3Event, module: BaseModul | |
| } | ||
| } | ||
|
|
||
| interface NuxtCareModuleSlim { | ||
| name: string | ||
| npm: string | ||
| score: number | ||
| status: string | ||
| lastUpdated: string | null | ||
| } | ||
|
|
||
| export async function fetchBulkModuleHealth(_event: H3Event, modules: BaseModule[]): Promise<Record<string, ModuleHealth>> { | ||
| const result: Record<string, ModuleHealth> = {} | ||
| const uncached: BaseModule[] = [] | ||
|
|
||
| // Check KV cache first | ||
| for (const module of modules) { | ||
| const cached = await kv.get<ModuleHealth>(`module:health:${module.name}`) | ||
| if (cached) { | ||
| result[module.name] = cached | ||
| } else { | ||
| uncached.push(module) | ||
| } | ||
| } | ||
|
|
||
| if (!uncached.length) return result | ||
|
|
||
| const CHUNK_SIZE = 50 | ||
| const statusColorMap: Record<string, string> = { | ||
| optimal: '#22c55e', | ||
| stable: '#84cc16', | ||
| degraded: '#eab308', | ||
| critical: '#ef4444', | ||
| unknown: '#6b7280' | ||
| } | ||
| const npmToModule = new Map(uncached.map(m => [m.npm, m])) | ||
|
|
||
| console.info(`Fetching health for ${uncached.length} modules from nuxt.care (${Math.ceil(uncached.length / CHUNK_SIZE)} chunks)...`) | ||
| for (let i = 0; i < uncached.length; i += CHUNK_SIZE) { | ||
| const chunk = uncached.slice(i, i + CHUNK_SIZE) | ||
| try { | ||
| const query = new URLSearchParams() | ||
| query.set('slim', 'true') | ||
| for (const m of chunk) { | ||
| query.append('package', m.npm) | ||
| } | ||
| const data = await $fetch<NuxtCareModuleSlim[]>(`https://nuxt.care/api/v1/modules?${query.toString()}`, { | ||
| timeout: 10_000, | ||
| retry: 2, | ||
| retryDelay: 1000 | ||
| }) | ||
| for (const item of data) { | ||
| const module = npmToModule.get(item.npm) | ||
| if (!module) continue | ||
| const health: ModuleHealth = { | ||
| score: item.score, | ||
| color: statusColorMap[item.status] || '#6b7280', | ||
| status: item.status | ||
| } | ||
| result[module.name] = health | ||
| await kv.set(`module:health:${module.name}`, health, { ttl: 60 * 60 * 24 }) | ||
|
Comment on lines
+118
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle multiple modules sharing the same npm package.
💡 Proposed fix- const npmToModule = new Map(uncached.map(m => [m.npm, m]))
+ const npmToModules = new Map<string, BaseModule[]>()
+ for (const m of uncached) {
+ const existing = npmToModules.get(m.npm)
+ if (existing) existing.push(m)
+ else npmToModules.set(m.npm, [m])
+ }
...
- for (const item of data) {
- const module = npmToModule.get(item.npm)
- if (!module) continue
+ for (const item of data) {
+ const matchedModules = npmToModules.get(item.npm)
+ if (!matchedModules?.length) continue
const health: ModuleHealth = {
score: item.score,
color: statusColorMap[item.status] || '#6b7280',
status: item.status
}
- result[module.name] = health
- await kv.set(`module:health:${module.name}`, health, { ttl: 60 * 60 * 24 })
+ for (const module of matchedModules) {
+ result[module.name] = health
+ await kv.set(`module:health:${module.name}`, health, { ttl: 60 * 60 * 24 })
+ }
}🤖 Prompt for AI Agents |
||
| } | ||
| } catch (err) { | ||
| console.error(`Cannot fetch bulk health from nuxt.care (chunk ${Math.floor(i / CHUNK_SIZE) + 1}): ${err}`) | ||
| } | ||
| } | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| export async function fetchModuleReadme(_event: H3Event, module: BaseModule) { | ||
| console.info(`Fetching module ${module.name} readme ...`) | ||
| const readme = await $fetch(`https://unpkg.com/${module.npm}/README.md`).catch(() => { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.