@@ -10,6 +10,7 @@ import type {
1010} from '#shared/types'
1111import type { PackageVersionsInfoWithMetadata } from 'fast-npm-meta'
1212import type { ReleaseType } from 'semver'
13+ import { mapWithConcurrency } from '#shared/utils/async'
1314import { maxSatisfying , prerelease , major , minor , diff , gt , compare } from 'semver'
1415import { isExactVersion } from '~/utils/versions'
1516import { extractInstallScriptsInfo } from '~/utils/install-scripts'
@@ -537,34 +538,28 @@ export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
537538
538539 // Fetch packuments and downloads in parallel
539540 const [ packuments , downloads ] = await Promise . all ( [
540- // Fetch packuments in parallel ( with concurrency limit)
541+ // Fetch packuments with concurrency limit
541542 ( async ( ) => {
542- const concurrency = 10
543- const results : MinimalPackument [ ] = [ ]
544- for ( let i = 0 ; i < packageNames . length ; i += concurrency ) {
545- const batch = packageNames . slice ( i , i + concurrency )
546- const batchResults = await Promise . all (
547- batch . map ( async name => {
548- try {
549- const encoded = encodePackageName ( name )
550- const { data : pkg } = await cachedFetch < MinimalPackument > (
551- `${ NPM_REGISTRY } /${ encoded } ` ,
552- { signal } ,
553- )
554- return pkg
555- } catch {
556- return null
557- }
558- } ) ,
559- )
560- for ( const pkg of batchResults ) {
561- // Filter out any unpublished packages (missing dist-tags)
562- if ( pkg && pkg [ 'dist-tags' ] ) {
563- results . push ( pkg )
543+ const results = await mapWithConcurrency (
544+ packageNames ,
545+ async name => {
546+ try {
547+ const encoded = encodePackageName ( name )
548+ const { data : pkg } = await cachedFetch < MinimalPackument > (
549+ `${ NPM_REGISTRY } /${ encoded } ` ,
550+ { signal } ,
551+ )
552+ return pkg
553+ } catch {
554+ return null
564555 }
565- }
566- }
567- return results
556+ } ,
557+ 10 ,
558+ )
559+ // Filter out any unpublished packages (missing dist-tags)
560+ return results . filter (
561+ ( pkg ) : pkg is MinimalPackument => pkg !== null && ! ! pkg [ 'dist-tags' ] ,
562+ )
568563 } ) ( ) ,
569564 // Fetch downloads in bulk
570565 fetchBulkDownloads ( packageNames , { signal } ) ,
@@ -762,23 +757,20 @@ export function useOutdatedDependencies(
762757 return
763758 }
764759
765- const results : Record < string , OutdatedDependencyInfo > = { }
766760 const entries = Object . entries ( deps )
767- const batchSize = 5
768-
769- for ( let i = 0 ; i < entries . length ; i += batchSize ) {
770- const batch = entries . slice ( i , i + batchSize )
771- const batchResults = await Promise . all (
772- batch . map ( async ( [ name , constraint ] ) => {
773- const info = await checkDependencyOutdated ( cachedFetch , name , constraint )
774- return [ name , info ] as const
775- } ) ,
776- )
761+ const batchResults = await mapWithConcurrency (
762+ entries ,
763+ async ( [ name , constraint ] ) => {
764+ const info = await checkDependencyOutdated ( cachedFetch , name , constraint )
765+ return [ name , info ] as const
766+ } ,
767+ 5 ,
768+ )
777769
778- for ( const [ name , info ] of batchResults ) {
779- if ( info ) {
780- results [ name ] = info
781- }
770+ const results : Record < string , OutdatedDependencyInfo > = { }
771+ for ( const [ name , info ] of batchResults ) {
772+ if ( info ) {
773+ results [ name ] = info
782774 }
783775 }
784776
0 commit comments