Skip to content

Commit 8bc6cc9

Browse files
committed
Rename walk to getPackagesToQueryFromDiff
1 parent d3ce1e9 commit 8bc6cc9

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/shadow/arborist/lib/arborist/walk.ts renamed to src/shadow/arborist/lib/arborist/diff.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@ function toRepoUrl(resolved: string): string {
1212
return ''
1313
}
1414

15-
export type InstallEffect = {
15+
export type PackageDetail = {
1616
pkgid: SafeNode['pkgid']
1717
repository_url: string
1818
existing?: SafeNode['pkgid'] | undefined
1919
}
2020

21-
export type WalkOptions = { fix?: boolean }
21+
type GetPackagesToQueryFromDiffOptions = { includeUnchanged?: boolean }
2222

23-
export function walk(
23+
export function getPackagesToQueryFromDiff(
2424
diff_: Diff | null,
25-
options?: WalkOptions
26-
): InstallEffect[] {
25+
options?: GetPackagesToQueryFromDiffOptions
26+
): PackageDetail[] {
2727
const {
2828
// Lazily access constants.IPC.
29-
fix = constants.IPC[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]
30-
} = <WalkOptions>{
29+
includeUnchanged = constants.IPC[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]
30+
} = <GetPackagesToQueryFromDiffOptions>{
3131
__proto__: null,
3232
...options
3333
}
34-
const needInfoOn: InstallEffect[] = []
34+
const details: PackageDetail[] = []
3535
// `diff_` is `null` when `npm install --package-lock-only` is passed.
3636
if (!diff_) {
37-
return needInfoOn
37+
return details
3838
}
3939
const queue: Diff[] = [...diff_.children]
4040
let pos = 0
@@ -70,7 +70,7 @@ export function walk(
7070
keep = action !== 'REMOVE'
7171
}
7272
if (keep && pkgNode?.resolved && (!oldNode || oldNode.resolved)) {
73-
needInfoOn.push({
73+
details.push({
7474
existing,
7575
pkgid: pkgNode.pkgid,
7676
repository_url: toRepoUrl(pkgNode.resolved)
@@ -81,16 +81,16 @@ export function walk(
8181
queue[queueLength++] = child
8282
}
8383
}
84-
if (fix) {
84+
if (includeUnchanged) {
8585
const { unchanged } = diff_!
8686
for (let i = 0, { length } = unchanged; i < length; i += 1) {
8787
const pkgNode = unchanged[i]!
88-
needInfoOn.push({
88+
details.push({
8989
existing: pkgNode.pkgid,
9090
pkgid: pkgNode.pkgid,
9191
repository_url: toRepoUrl(pkgNode.resolved!)
9292
})
9393
}
9494
}
95-
return needInfoOn
95+
return details
9696
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { confirm } from '@socketsecurity/registry/lib/prompts'
1313
import { Spinner } from '@socketsecurity/registry/lib/spinner'
1414

1515
import { kCtorArgs, kRiskyReify } from './index'
16-
import { walk } from './walk'
16+
import { getPackagesToQueryFromDiff } from './diff'
1717
import constants from '../../../../constants'
1818
import {
1919
batchScan,
@@ -370,7 +370,7 @@ export async function reify(
370370
this: SafeArborist,
371371
...args: Parameters<InstanceType<ArboristClass>['reify']>
372372
): Promise<SafeNode> {
373-
const needInfoOn = walk(this.diff)
373+
const needInfoOn = getPackagesToQueryFromDiff(this.diff)
374374
if (
375375
!needInfoOn.length ||
376376
needInfoOn.findIndex(c => c.repository_url === NPM_REGISTRY_URL) === -1
@@ -427,9 +427,13 @@ export async function reify(
427427
ret = await this[kRiskyReify](...args)
428428
await this.loadActual()
429429
await this.buildIdealTree()
430-
alerts = await getPackagesAlerts(this, walk(this.diff, { fix: true }), {
431-
fixable: true
432-
})
430+
alerts = await getPackagesAlerts(
431+
this,
432+
getPackagesToQueryFromDiff(this.diff, { includeUnchanged: true }),
433+
{
434+
fixable: true
435+
}
436+
)
433437
alerts = alerts.filter(a => {
434438
const { key } = a
435439
if (prev.has(key)) {

0 commit comments

Comments
 (0)