Skip to content

Commit 66d9ee5

Browse files
authored
Merge branch 'main' into feat/convert-npmjs-readme-urls-to-npmx
2 parents 0a3f4af + 60a7759 commit 66d9ee5

50 files changed

Lines changed: 575 additions & 116 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,20 @@ jobs:
9898
run: ./scripts/lighthouse-a11y.sh
9999
env:
100100
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
101+
102+
knip:
103+
runs-on: ubuntu-latest
104+
105+
steps:
106+
- uses: actions/checkout@v6
107+
- run: corepack enable
108+
- uses: actions/setup-node@v6
109+
with:
110+
node-version: lts/*
111+
cache: pnpm
112+
113+
- name: 📦 Install dependencies
114+
run: pnpm install
115+
116+
- name: 🔍 Check for unused code
117+
run: pnpm knip:production

app/composables/useCachedFetch.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { H3Event } from 'h3'
2-
31
/**
42
* Type for the cachedFetch function attached to event context.
53
*/
@@ -32,6 +30,7 @@ export type CachedFetchFunction = <T = unknown>(
3230
* )
3331
* }
3432
* ```
33+
* @public
3534
*/
3635
export function useCachedFetch(): CachedFetchFunction {
3736
// On client, return a function that just uses $fetch
@@ -72,28 +71,3 @@ export function useCachedFetch(): CachedFetchFunction {
7271
return (await $fetch(url, options as Parameters<typeof $fetch>[1])) as T
7372
}
7473
}
75-
76-
/**
77-
* Create a cachedFetch function from an H3Event.
78-
* Useful when you have direct access to the event.
79-
*/
80-
export function getCachedFetchFromEvent(event: H3Event | undefined): CachedFetchFunction {
81-
const serverCachedFetch = event?.context?.cachedFetch
82-
83-
if (serverCachedFetch) {
84-
return serverCachedFetch as CachedFetchFunction
85-
}
86-
87-
// Fallback to regular $fetch
88-
return async <T = unknown>(
89-
url: string,
90-
options: {
91-
method?: string
92-
body?: unknown
93-
headers?: Record<string, string>
94-
} = {},
95-
_ttl?: number,
96-
): Promise<T> => {
97-
return (await $fetch(url, options as Parameters<typeof $fetch>[1])) as T
98-
}
99-
}

app/composables/useCharts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ function getNpmPackageCreationDate(packument: PackumentLikeForTime): string | nu
286286
return versionDates[0] ?? null
287287
}
288288

289+
/** @public */
289290
export function useCharts() {
290291
function resolveDateRange(
291292
downloadEvolutionOptions: PackageDownloadEvolutionOptions,

app/composables/useConnector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ interface StateResponse {
5555
const STORAGE_KEY = 'npmx-connector'
5656
const DEFAULT_PORT = 31415
5757

58+
/** @public */
5859
export const useConnector = createSharedComposable(function useConnector() {
5960
// Persisted connection config
6061
const config = useState<{ token: string; port: number } | null>('connector-config', () => null)

app/composables/useFileTreeState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @public */
12
export function useFileTreeState(baseUrl: string) {
23
const stateKey = computed(() => `npmx-file-tree${baseUrl}`)
34

app/composables/useInstallCommand.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { JsrPackageInfo } from '#shared/types/jsr'
33
/**
44
* Composable for generating install commands with support for
55
* multiple package managers, @types packages, and JSR.
6+
* @public
67
*/
78
export function useInstallCommand(
89
packageName: MaybeRefOrGetter<string | null>,

app/composables/useNpmRegistry.ts

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function transformPackument(pkg: Packument, requestedVersion?: string | null): S
108108
}
109109
}
110110

111+
/** @public */
111112
export function usePackage(
112113
name: MaybeRefOrGetter<string>,
113114
requestedVersion?: MaybeRefOrGetter<string | null>,
@@ -147,6 +148,7 @@ function getResolvedVersion(pkg: SlimPackument, reqVer?: string | null): string
147148
return resolved
148149
}
149150

151+
/** @public */
150152
export function usePackageDownloads(
151153
name: MaybeRefOrGetter<string>,
152154
period: MaybeRefOrGetter<'last-day' | 'last-week' | 'last-month' | 'last-year'> = 'last-week',
@@ -174,6 +176,7 @@ type NpmDownloadsRangeResponse = {
174176
/**
175177
* Fetch download range data from npm API.
176178
* Exported for external use (e.g., in components).
179+
* @public
177180
*/
178181
export async function fetchNpmDownloadsRange(
179182
packageName: string,
@@ -186,48 +189,13 @@ export async function fetchNpmDownloadsRange(
186189
)
187190
}
188191

189-
export function usePackageWeeklyDownloadEvolution(
190-
name: MaybeRefOrGetter<string>,
191-
options: MaybeRefOrGetter<{
192-
weeks?: number
193-
endDate?: string
194-
}> = {},
195-
) {
196-
const cachedFetch = useCachedFetch()
197-
198-
return useLazyAsyncData(
199-
() => `downloads-weekly-evolution:${toValue(name)}:${JSON.stringify(toValue(options))}`,
200-
async () => {
201-
const packageName = toValue(name)
202-
const { weeks = 12, endDate } = toValue(options) ?? {}
203-
204-
const today = new Date()
205-
const yesterday = new Date(
206-
Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() - 1),
207-
)
208-
209-
const end = endDate ? new Date(`${endDate}T00:00:00.000Z`) : yesterday
210-
211-
const start = addDays(end, -(weeks * 7) + 1)
212-
const startIso = toIsoDateString(start)
213-
const endIso = toIsoDateString(end)
214-
215-
const encodedName = encodePackageName(packageName)
216-
const range = await cachedFetch<NpmDownloadsRangeResponse>(
217-
`${NPM_API}/downloads/range/${startIso}:${endIso}/${encodedName}`,
218-
)
219-
const sortedDaily = [...range.downloads].sort((a, b) => a.day.localeCompare(b.day))
220-
return buildWeeklyEvolutionFromDaily(sortedDaily)
221-
},
222-
)
223-
}
224-
225192
const emptySearchResponse = {
226193
objects: [],
227194
total: 0,
228195
time: new Date().toISOString(),
229196
} satisfies NpmSearchResponse
230197

198+
/** @public */
231199
export function useNpmSearch(
232200
query: MaybeRefOrGetter<string>,
233201
options: MaybeRefOrGetter<{
@@ -305,6 +273,7 @@ function packumentToSearchResult(pkg: MinimalPackument): NpmSearchResult {
305273
/**
306274
* Fetch all packages for an npm organization
307275
* Returns search-result-like objects for compatibility with PackageList
276+
* @public
308277
*/
309278
export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
310279
const cachedFetch = useCachedFetch()
@@ -418,35 +387,6 @@ export async function fetchAllPackageVersions(packageName: string): Promise<Pack
418387
return promise
419388
}
420389

421-
/**
422-
* Composable to fetch all versions of a package.
423-
* Uses SWR caching on the server.
424-
*/
425-
export function useAllPackageVersions(packageName: MaybeRefOrGetter<string>) {
426-
const cachedFetch = useCachedFetch()
427-
428-
return useLazyAsyncData(
429-
() => `all-versions:${toValue(packageName)}`,
430-
async () => {
431-
const encodedName = encodePackageName(toValue(packageName))
432-
const data = await cachedFetch<{
433-
versions: Record<string, { deprecated?: string }>
434-
time: Record<string, string>
435-
}>(`${NPM_REGISTRY}/${encodedName}`)
436-
437-
return Object.entries(data.versions)
438-
.filter(([v]) => data.time[v])
439-
.map(([version, versionData]) => ({
440-
version,
441-
time: data.time[version],
442-
hasProvenance: false, // Would need to check dist.attestations for each version
443-
deprecated: versionData.deprecated,
444-
}))
445-
.sort((a, b) => compare(b.version, a.version)) as PackageVersionInfo[]
446-
},
447-
)
448-
}
449-
450390
// ============================================================================
451391
// Outdated Dependencies
452392
// ============================================================================
@@ -567,6 +507,7 @@ async function checkDependencyOutdated(
567507
/**
568508
* Composable to check for outdated dependencies.
569509
* Returns a reactive map of dependency name to outdated info.
510+
* @public
570511
*/
571512
export function useOutdatedDependencies(
572513
dependencies: MaybeRefOrGetter<Record<string, string> | undefined>,
@@ -616,6 +557,7 @@ export function useOutdatedDependencies(
616557

617558
/**
618559
* Get tooltip text for an outdated dependency
560+
* @public
619561
*/
620562
export function getOutdatedTooltip(info: OutdatedDependencyInfo): string {
621563
if (info.majorsBehind > 0) {
@@ -631,6 +573,7 @@ export function getOutdatedTooltip(info: OutdatedDependencyInfo): string {
631573

632574
/**
633575
* Get CSS class for a dependency version based on outdated status
576+
* @public
634577
*/
635578
export function getVersionClass(info: OutdatedDependencyInfo | undefined): string {
636579
if (!info) return 'text-fg-subtle'

app/composables/usePackageAnalysis.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface PackageAnalysisResponse {
1414

1515
/**
1616
* Composable for fetching package analysis data (module format, types info, etc.)
17+
* @public
1718
*/
1819
export function usePackageAnalysis(
1920
packageName: MaybeRefOrGetter<string>,

app/composables/usePackageRoute.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* /@nuxt/kit/v/1.0.0 → packageName: "@nuxt/kit", requestedVersion: "1.0.0"
99
* /axios@1.13.3 → packageName: "axios", requestedVersion: "1.13.3"
1010
* /@nuxt/kit@1.0.0 → packageName: "@nuxt/kit", requestedVersion: "1.0.0"
11+
* @public
1112
*/
1213
export function usePackageRoute() {
1314
const route = useRoute('package')

app/composables/useRepoMeta.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ const providers: readonly ProviderAdapter[] = [
760760

761761
const parseRepoFromUrl = parseRepoUrl
762762

763+
/** @public */
763764
export function useRepoMeta(repositoryUrl: MaybeRefOrGetter<string | null | undefined>) {
764765
// Get cachedFetch in setup context (outside async handler)
765766
const cachedFetch = useCachedFetch()

0 commit comments

Comments
 (0)