Skip to content

Commit

Permalink
Remove for-await of a single array result
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Dec 7, 2024
1 parent 0bc255b commit 7d8b798
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/shadow/arborist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type ArboristClass = typeof BaseArborist & {
new (...args: any): typeof BaseArborist
}

type AwaitedYield<T> = T extends AsyncGenerator<infer Y, any, any> ? Y : never

type EdgeClass = Omit<BaseEdge, 'overrides' | 'reload'> & {
optional: boolean
overrides: OverrideSetClass | undefined
Expand Down Expand Up @@ -434,16 +436,17 @@ async function packagesHaveRiskyIssues(
p => p.pkgid === id && p.existing?.startsWith(`${name}@`)
)
if (pkg?.existing) {
// eslint-disable-next-line no-await-in-loop
for await (const oldPkgData of batchScan([pkg.existing])) {
if (oldPkgData.type === 'success') {
failures = failures.filter(
issue =>
oldPkgData.value.issues.find(
oldIssue => oldIssue.type === issue.type
) === undefined
)
}
const oldPkgData = <AwaitedYield<ReturnType<typeof batchScan>>>(
// eslint-disable-next-line no-await-in-loop
(await batchScan([pkg.existing]).next()).value
)
if (oldPkgData.type === 'success') {
failures = failures.filter(
issue =>
oldPkgData.value.issues.find(
oldIssue => oldIssue.type === issue.type
) === undefined
)
}
}
}
Expand Down

0 comments on commit 7d8b798

Please sign in to comment.