Skip to content

Commit 6aac060

Browse files
committed
Start migrating fix logic
1 parent eee068b commit 6aac060

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

src/commands/fix.ts

+27
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,33 @@ import type { CliSubcommand } from '../utils/meow-with-subcommands'
77

88
const { SOCKET_CLI_IN_FIX_CMD, SOCKET_IPC_HANDSHAKE } = constants
99

10+
// const prev = new Set(alerts.map(a => a.key))
11+
// let ret: SafeNode | undefined
12+
// /* eslint-disable no-await-in-loop */
13+
// while (alerts.length > 0) {
14+
// await updateAdvisoryNodes(this, alerts)
15+
// ret = await this[kRiskyReify](...args)
16+
// await this.loadActual()
17+
// await this.buildIdealTree()
18+
// needInfoOn = getPackagesToQueryFromDiff(this.diff, {
19+
// includeUnchanged: true
20+
// })
21+
// alerts = (
22+
// await getPackagesAlerts(needInfoOn, {
23+
// includeExisting: true,
24+
// includeUnfixable: true
25+
// })
26+
// ).filter(({ key }) => {
27+
// const unseen = !prev.has(key)
28+
// if (unseen) {
29+
// prev.add(key)
30+
// }
31+
// return unseen
32+
// })
33+
// }
34+
// /* eslint-enable no-await-in-loop */
35+
// return ret!
36+
1037
export const fix: CliSubcommand = {
1138
description: 'Fix "fixable" Socket alerts',
1239
hidden: true,

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

+5-34
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { debugLog } from '../../../../utils/debug'
2727
import { getSocketDevPackageOverviewUrl } from '../../../../utils/socket-url'
2828
import { Edge, SafeEdge } from '../edge'
2929

30-
import type { PackageDetail } from './diff'
3130
import type { ArboristClass, ArboristReifyOptions } from './types'
3231
import type { SocketArtifact } from '../../../../utils/alert/artifact'
3332
import type { SafeNode } from '../node'
@@ -174,7 +173,7 @@ async function getPackagesAlerts(
174173
fixable
175174
})
176175
}
177-
if (includeExisting && !runningFixCmd) {
176+
if (!includeExisting) {
178177
// Before we ask about problematic issues, check to see if they
179178
// already existed in the old version if they did, be quiet.
180179
const existing = needInfoOn.find(d =>
@@ -336,7 +335,7 @@ function updateNode(
336335
packument: Packument,
337336
vulnerableVersionRange?: string,
338337
firstPatchedVersionIdentifier?: string
339-
) {
338+
): boolean {
340339
const availableVersions = Object.keys(packument.versions)
341340
// Find the highest non-vulnerable version within the same major range
342341
const targetVersion = findBestPatchVersion(
@@ -351,7 +350,7 @@ function updateNode(
351350
// Check !targetVersion to make TypeScript happy.
352351
if (!targetVersion || !targetPackument) {
353352
// No suitable patch version found.
354-
return node
353+
return false
355354
}
356355
// Use Object.defineProperty to override the version.
357356
Object.defineProperty(node, 'version', {
@@ -394,6 +393,7 @@ function updateNode(
394393
})) as SafeEdge)
395394
}
396395
}
396+
return true
397397
}
398398

399399
export const kRiskyReify = Symbol('riskyReify')
@@ -407,17 +407,14 @@ export async function reify(
407407
...args: Parameters<InstanceType<ArboristClass>['reify']>
408408
): Promise<SafeNode> {
409409
const IPC = await getIPC()
410-
const runningFixCmd = !!IPC[SOCKET_CLI_IN_FIX_CMD]
411-
const runningOptimizeCmd = !!IPC[SOCKET_CLI_IN_OPTIMIZE_CMD]
412410
await updateSocketRegistryNodes(this)
413-
if (runningOptimizeCmd) {
411+
if (IPC[SOCKET_CLI_IN_FIX_CMD] || IPC[SOCKET_CLI_IN_OPTIMIZE_CMD]) {
414412
return await this[kRiskyReify](...args)
415413
}
416414
const { stderr: output, stdin: input } = process
417415
const alerts = await getPackagesAlerts(this, { output })
418416
if (
419417
alerts.length &&
420-
!runningFixCmd &&
421418
!(await confirm(
422419
{
423420
message: 'Accept risks of installing these packages?',
@@ -433,30 +430,4 @@ export async function reify(
433430
throw new Error('Socket npm exiting due to risks')
434431
}
435432
return await this[kRiskyReify](...args)
436-
// const prev = new Set(alerts.map(a => a.key))
437-
// let ret: SafeNode | undefined
438-
// /* eslint-disable no-await-in-loop */
439-
// while (alerts.length > 0) {
440-
// await updateAdvisoryNodes(this, alerts)
441-
// ret = await this[kRiskyReify](...args)
442-
// await this.loadActual()
443-
// await this.buildIdealTree()
444-
// needInfoOn = getPackagesToQueryFromDiff(this.diff, {
445-
// includeUnchanged: true
446-
// })
447-
// alerts = (
448-
// await getPackagesAlerts(needInfoOn, {
449-
// includeExisting: true,
450-
// includeUnfixable: true
451-
// })
452-
// ).filter(({ key }) => {
453-
// const unseen = !prev.has(key)
454-
// if (unseen) {
455-
// prev.add(key)
456-
// }
457-
// return unseen
458-
// })
459-
// }
460-
// /* eslint-enable no-await-in-loop */
461-
// return ret!
462433
}

0 commit comments

Comments
 (0)