Skip to content

Commit

Permalink
feat: add concurrency limit
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Oct 30, 2024
1 parent 7e22090 commit abdf4ae
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@antfu/ni": "^0.23.0",
"js-yaml": "^4.1.0",
"ofetch": "^1.4.0",
"p-limit": "^6.1.0",
"package-manager-detector": "^0.2.0",
"tinyexec": "^0.3.0",
"unconfig": "^0.6.0",
Expand Down
21 changes: 19 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions src/io/resolves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { existsSync, promises as fs, lstatSync } from 'node:fs'
import os from 'node:os'
import { resolve } from 'node:path'
import _debug from 'debug'
import pLimit from 'p-limit'
import semver from 'semver'
import { diffSorter } from '../filters/diff-sorter'
import { getPackageMode } from '../utils/config'
Expand Down Expand Up @@ -268,14 +269,19 @@ export async function resolveDependencies(
const total = deps.length
let counter = 0

const {
concurrency = 10,
} = options

const limit = pLimit(concurrency)

return Promise.all(
deps
.map(async (raw) => {
const dep = await resolveDependency(raw, options, filter)
counter += 1
progressCallback(raw.name, counter, total)
return dep
}),
deps.map(raw => limit(async () => {
const dep = await resolveDependency(raw, options, filter)
counter += 1
progressCallback(raw.name, counter, total)
return dep
})),
)
}

Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export interface CheckOptions extends CommonOptions {
install?: boolean
update?: boolean
global?: boolean
/**
* Number of concurrent requests
*
* @default 10
*/
concurrency?: number
/**
* Group dependencies by source, e.g. dependencies, devDependencies, etc.
*
Expand Down

0 comments on commit abdf4ae

Please sign in to comment.