Skip to content

Commit d9ef7a9

Browse files
committed
fix: hoist useNuxtApp calls
1 parent d764b3c commit d9ef7a9

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

app/composables/npm/useNpmSearch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export function useNpmSearch(
5454
query: MaybeRefOrGetter<string>,
5555
options: MaybeRefOrGetter<NpmSearchOptions> = {},
5656
) {
57+
const { $npmRegistry } = useNuxtApp()
58+
5759
// Client-side cache
5860
const cache = shallowRef<{
5961
query: string
@@ -144,7 +146,6 @@ export function useNpmSearch(
144146

145147
// Fetch more results incrementally (only used in incremental mode)
146148
async function fetchMore(targetSize: number): Promise<void> {
147-
const { $npmRegistry } = useNuxtApp()
148149
const q = toValue(query).trim()
149150
if (!q) {
150151
cache.value = null

app/composables/npm/useOrgPackages.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { NuxtApp } from '#app'
12
import type { NpmSearchResponse, NpmSearchResult, MinimalPackument } from '#shared/types'
23
import { emptySearchResponse, packumentToSearchResult } from './useNpmSearch'
34
import { mapWithConcurrency } from '#shared/utils/async'
@@ -9,10 +10,10 @@ import { mapWithConcurrency } from '#shared/utils/async'
910
* Note: npm bulk downloads API does not support scoped packages.
1011
*/
1112
async function fetchBulkDownloads(
13+
$npmApi: NuxtApp['$npmApi'],
1214
packageNames: string[],
1315
options: Parameters<typeof $fetch>[1] = {},
1416
): Promise<Map<string, number>> {
15-
const { $npmApi } = useNuxtApp()
1617
const downloads = new Map<string, number>()
1718
if (packageNames.length === 0) return downloads
1819

@@ -82,7 +83,7 @@ async function fetchBulkDownloads(
8283
export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
8384
const asyncData = useLazyAsyncData(
8485
() => `org-packages:${toValue(orgName)}`,
85-
async ({ $npmRegistry }, { signal }) => {
86+
async ({ $npmRegistry, $npmApi }, { signal }) => {
8687
const org = toValue(orgName)
8788
if (!org) {
8889
return emptySearchResponse
@@ -138,7 +139,7 @@ export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
138139
)
139140
})(),
140141
// Fetch downloads in bulk
141-
fetchBulkDownloads(packageNames, { signal }),
142+
fetchBulkDownloads($npmApi, packageNames, { signal }),
142143
])
143144

144145
// Convert to search results with download data

app/composables/npm/useOutdatedDependencies.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { NuxtApp } from '#app'
12
import { maxSatisfying, prerelease, major, minor, diff, gt } from 'semver'
23
import type { Packument } from '#shared/types'
34
import { mapWithConcurrency } from '#shared/utils/async'
@@ -17,11 +18,10 @@ const packumentCache = new Map<string, Promise<Packument | null>>()
1718
*/
1819
async function checkDependencyOutdated(
1920
cachedFetch: CachedFetchFunction,
21+
$npmRegistry: NuxtApp['$npmRegistry'],
2022
packageName: string,
2123
constraint: string,
2224
): Promise<OutdatedDependencyInfo | null> {
23-
const { $npmRegistry } = useNuxtApp()
24-
2525
if (isNonSemverConstraint(constraint)) {
2626
return null
2727
}
@@ -93,6 +93,7 @@ async function checkDependencyOutdated(
9393
export function useOutdatedDependencies(
9494
dependencies: MaybeRefOrGetter<Record<string, string> | undefined>,
9595
) {
96+
const { $npmRegistry } = useNuxtApp()
9697
const cachedFetch = useCachedFetch()
9798
const outdated = shallowRef<Record<string, OutdatedDependencyInfo>>({})
9899

@@ -106,7 +107,7 @@ export function useOutdatedDependencies(
106107
const batchResults = await mapWithConcurrency(
107108
entries,
108109
async ([name, constraint]) => {
109-
const info = await checkDependencyOutdated(cachedFetch, name, constraint)
110+
const info = await checkDependencyOutdated(cachedFetch, $npmRegistry, name, constraint)
110111
return [name, info] as const
111112
},
112113
5,

0 commit comments

Comments
 (0)