From c3f59f3ff55740268c7796af7da0566f45c0f2f4 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Mon, 2 Mar 2026 16:28:20 -0800 Subject: [PATCH] Include npm keywords in topic search Extract keywords from the npm registry response (via processTopics) and merge them into topicSearchString for search discoverability. A Set deduplicates against GitHub topics so each term is counted once. --- scripts/build-and-score-data.ts | 18 ++++++------------ scripts/fetch-npm-registry-data.ts | 3 ++- types/index.ts | 1 + 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/scripts/build-and-score-data.ts b/scripts/build-and-score-data.ts index 1c4e8a910..63e6ea901 100644 --- a/scripts/build-and-score-data.ts +++ b/scripts/build-and-score-data.ts @@ -153,22 +153,16 @@ async function buildAndScoreData() { const topicCounts: Record = missingOnly ? (topics ?? {}) : {}; data.forEach((project, index, projectList) => { - let topicSearchString = ''; + const topics = new Set(); - if (project.github.topics) { - project.github.topics.forEach(topic => { - topicSearchString = `${topicSearchString} ${topic}`; + project.github.topics?.forEach(topic => topics.add(topic)); + project.npm?.keywords?.forEach(keyword => topics.add(keyword)); - if (!topicCounts[topic]) { - topicCounts[topic] = 1; - return; - } - - topicCounts[topic] += 1; - }); + for (const topic of topics) { + topicCounts[topic] = (topicCounts[topic] ?? 0) + 1; } - projectList[index].topicSearchString = topicSearchString.trim(); + projectList[index].topicSearchString = [...topics].join(' '); }); if (invalidRepos.length) { diff --git a/scripts/fetch-npm-registry-data.ts b/scripts/fetch-npm-registry-data.ts index 44e2fd994..c66224922 100644 --- a/scripts/fetch-npm-registry-data.ts +++ b/scripts/fetch-npm-registry-data.ts @@ -2,7 +2,7 @@ import { fetch } from 'bun'; import { type LibraryType, type NpmRegistryData } from '~/types'; -import { REQUEST_SLEEP, sleep } from './helpers'; +import { processTopics, REQUEST_SLEEP, sleep } from './helpers'; const ATTEMPTS_LIMIT = 2; @@ -53,6 +53,7 @@ export async function fetchNpmRegistryData( 'deprecated' in registryData.versions[latestRelease] ? true : pkgData.unmaintained, npm: { ...pkgData.npm, + keywords: processTopics(registryData.keywords), size: registryData.versions[latestRelease].dist.unpackedSize, versionsCount: Object.keys(registryData.versions).length, latestRelease, diff --git a/types/index.ts b/types/index.ts index 7517166aa..db1a2eae4 100644 --- a/types/index.ts +++ b/types/index.ts @@ -122,6 +122,7 @@ export type LibraryType = LibraryDataEntryType & { npm?: { downloads?: number; weekDownloads?: number; + keywords?: string[]; size?: number; versionsCount?: number; latestRelease?: string;