(options: CheckOptions, callbacks: CheckEventCallbacks = {})
| 15 | } |
| 16 | |
| 17 | export async function CheckPackages(options: CheckOptions, callbacks: CheckEventCallbacks = {}) { |
| 18 | if (!options.force) |
| 19 | await loadCache() |
| 20 | |
| 21 | // packages loading |
| 22 | const packages = await loadPackages(options) |
| 23 | callbacks.afterPackagesLoaded?.(packages) |
| 24 | |
| 25 | const privatePackageNames = packages |
| 26 | .filter(i => i.private) |
| 27 | .map(i => i.name) |
| 28 | .filter(i => i) |
| 29 | |
| 30 | // to filter out private dependency in monorepo |
| 31 | const filter = (dep: RawDep) => !privatePackageNames.includes(dep.name) |
| 32 | |
| 33 | let resolvedCount = 0 |
| 34 | const onDependencyResolved: DependencyResolvedCallback = (pkgName, name, progress, total) => { |
| 35 | resolvedCount++ |
| 36 | callbacks.onDependencyResolved?.(pkgName, name, resolvedCount, total) |
| 37 | } |
| 38 | |
| 39 | const queue = newQueue(options.concurrency || 10) |
| 40 | |
| 41 | await queueContext.run(queue, () => { |
| 42 | // run all CheckSingleProject in parallel |
| 43 | // the actual resolveDependencies within CheckSingleProject -> resolvePackage -> resolveDependencies is |
| 44 | // actually limited by the queueContext/queue, so it won't overwhelm the npm meta server. |
| 45 | return Promise.all(packages.map(async (pkg) => { |
| 46 | callbacks.beforePackageStart?.(pkg) |
| 47 | await CheckSingleProject(pkg, options, filter, { ...callbacks, onDependencyResolved }) |
| 48 | callbacks.afterPackageEnd?.(pkg) |
| 49 | })) |
| 50 | }) |
| 51 | |
| 52 | callbacks.afterPackagesEnd?.(packages) |
| 53 | |
| 54 | await dumpCache() |
| 55 | |
| 56 | return { |
| 57 | packages, |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | async function CheckSingleProject(pkg: PackageMeta, options: CheckOptions, filter: DependencyFilter = () => true, callbacks: CheckEventCallbacks = {}) { |
| 62 | await resolvePackage(pkg, options, filter, callbacks.onDependencyResolved) |
no test coverage detected
searching dependent graphs…