File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -306,6 +306,7 @@ export function useNpmSearch(
306306 ( ) => `search:incremental:${ toValue ( query ) } ` ,
307307 async ( _nuxtApp , { signal } ) => {
308308 const q = toValue ( query )
309+
309310 if ( ! q . trim ( ) ) {
310311 return emptySearchResponse
311312 }
@@ -321,6 +322,35 @@ export function useNpmSearch(
321322 // Use requested size for initial fetch
322323 params . set ( 'size' , String ( opts . size ?? 25 ) )
323324
325+ if ( q . length === 1 ) {
326+ const encodedName = encodePackageName ( q )
327+ const [ { data : pkg , isStale } , { data : downloads } ] = await Promise . all ( [
328+ cachedFetch < Packument > ( `${ NPM_REGISTRY } /${ encodedName } ` , { signal } ) ,
329+ cachedFetch < NpmDownloadCount > ( `${ NPM_API } /downloads/point/last-week/${ encodedName } ` , {
330+ signal,
331+ } ) ,
332+ ] )
333+
334+ if ( ! pkg ) {
335+ return emptySearchResponse
336+ }
337+
338+ const result = packumentToSearchResult ( pkg , downloads ?. downloads )
339+
340+ cache . value = {
341+ query : q ,
342+ objects : [ result ] ,
343+ total : 1 ,
344+ }
345+
346+ return {
347+ objects : [ result ] ,
348+ total : 1 ,
349+ isStale,
350+ time : new Date ( ) . toISOString ( ) ,
351+ }
352+ }
353+
324354 const { data : response , isStale } = await cachedFetch < NpmSearchResponse > (
325355 `${ NPM_REGISTRY } /-/v1/search?${ params . toString ( ) } ` ,
326356 { signal } ,
You can’t perform that action at this time.
0 commit comments