Skip to content

Commit 61c3ffd

Browse files
committed
Cleanup getPackagesAlerts use
1 parent 7716c08 commit 61c3ffd

File tree

1 file changed

+27
-19
lines changed
  • src/shadow/arborist/lib/arborist

1 file changed

+27
-19
lines changed

src/shadow/arborist/lib/arborist/reify.ts

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ function findPackage(tree: SafeNode, packageName: string): SafeNode | null {
102102

103103
type GetPackageAlertsOptions = {
104104
output?: Writable
105-
fixable?: boolean
105+
includeExisting?: boolean
106+
includeUnfixable?: boolean
106107
}
107108

108109
async function getPackagesAlerts(
@@ -115,7 +116,11 @@ async function getPackagesAlerts(
115116
if (!remaining) {
116117
return packageAlerts
117118
}
118-
const { fixable, output } = <GetPackageAlertsOptions>{
119+
const {
120+
includeExisting = false,
121+
includeUnfixable = true,
122+
output
123+
} = <GetPackageAlertsOptions>{
119124
__proto__: null,
120125
...options
121126
}
@@ -149,24 +154,27 @@ async function getPackagesAlerts(
149154
displayWarning = true
150155
}
151156
if (ux.block || ux.display) {
152-
const isFixable = isArtifactAlertFixable(alert)
153-
if (!fixable || isFixable) {
157+
const fixable = isArtifactAlertFixable(alert)
158+
if (includeUnfixable || fixable) {
154159
alerts.push({
155160
name,
156161
version,
157162
key: alert.key,
158163
type: alert.type,
159164
block: ux.block,
160165
raw: alert,
161-
fixable: isFixable
166+
fixable
162167
})
163168
}
164169
// Lazily access constants.IPC.
165-
if (!fixable && !constants.IPC[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]) {
170+
if (
171+
includeExisting &&
172+
!constants.IPC[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]
173+
) {
166174
// Before we ask about problematic issues, check to see if they
167175
// already existed in the old version if they did, be quiet.
168-
const existing = pkgs.find(p =>
169-
p.existing?.startsWith(`${name}@`)
176+
const existing = details.find(d =>
177+
d.existing?.startsWith(`${name}@`)
170178
)?.existing
171179
if (existing) {
172180
const oldArtifact: SocketArtifact | undefined =
@@ -182,8 +190,7 @@ async function getPackagesAlerts(
182190
}
183191
}
184192
if (!blocked) {
185-
const pkg = pkgs.find(p => p.pkgid === id)
186-
if (pkg) {
193+
if (details.find(d => d.pkgid === id)) {
187194
await pacote.tarball.stream(
188195
id,
189196
stream => {
@@ -424,15 +431,16 @@ export async function reify(
424431
ret = await this[kRiskyReify](...args)
425432
await this.loadActual()
426433
await this.buildIdealTree()
427-
alerts = await getPackagesAlerts(
428-
this,
429-
getPackagesToQueryFromDiff(this.diff, { includeUnchanged: true }),
430-
{
431-
fixable: true
432-
}
433-
)
434-
alerts = alerts.filter(a => {
435-
const { key } = a
434+
alerts = (
435+
await getPackagesAlerts(
436+
this,
437+
getPackagesToQueryFromDiff(this.diff, { includeUnchanged: true }),
438+
{
439+
includeExisting: true,
440+
includeUnfixable: true
441+
}
442+
)
443+
).filter(({ key }) => {
436444
if (prev.has(key)) {
437445
return false
438446
}

0 commit comments

Comments
 (0)