Skip to content

Commit 7d8b798

Browse files
committed
Remove for-await of a single array result
1 parent 0bc255b commit 7d8b798

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/shadow/arborist.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type ArboristClass = typeof BaseArborist & {
3838
new (...args: any): typeof BaseArborist
3939
}
4040

41+
type AwaitedYield<T> = T extends AsyncGenerator<infer Y, any, any> ? Y : never
42+
4143
type EdgeClass = Omit<BaseEdge, 'overrides' | 'reload'> & {
4244
optional: boolean
4345
overrides: OverrideSetClass | undefined
@@ -434,16 +436,17 @@ async function packagesHaveRiskyIssues(
434436
p => p.pkgid === id && p.existing?.startsWith(`${name}@`)
435437
)
436438
if (pkg?.existing) {
437-
// eslint-disable-next-line no-await-in-loop
438-
for await (const oldPkgData of batchScan([pkg.existing])) {
439-
if (oldPkgData.type === 'success') {
440-
failures = failures.filter(
441-
issue =>
442-
oldPkgData.value.issues.find(
443-
oldIssue => oldIssue.type === issue.type
444-
) === undefined
445-
)
446-
}
439+
const oldPkgData = <AwaitedYield<ReturnType<typeof batchScan>>>(
440+
// eslint-disable-next-line no-await-in-loop
441+
(await batchScan([pkg.existing]).next()).value
442+
)
443+
if (oldPkgData.type === 'success') {
444+
failures = failures.filter(
445+
issue =>
446+
oldPkgData.value.issues.find(
447+
oldIssue => oldIssue.type === issue.type
448+
) === undefined
449+
)
447450
}
448451
}
449452
}

0 commit comments

Comments
 (0)