Skip to content

Commit d023150

Browse files
committed
Cleanup reify
1 parent 71f6734 commit d023150

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

src/shadow/arborist/lib/arborist/alerts.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,18 @@ function toRepoUrl(resolved: string): string {
124124

125125
export type WalkOptions = { fix?: boolean }
126126

127-
export function walk(diff_: Diff, options?: WalkOptions): InstallEffect[] {
127+
export function walk(
128+
diff_: Diff | null,
129+
options?: WalkOptions
130+
): InstallEffect[] {
128131
const { fix = ENV[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE] } = <WalkOptions>{
129132
__proto__: null,
130133
...options
131134
}
132135
const needInfoOn: InstallEffect[] = []
136+
if (!diff_) {
137+
return needInfoOn
138+
}
133139
const queue: Diff[] = [...diff_.children]
134140
let pos = 0
135141
let { length: queueLength } = queue

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,17 @@ async function getPackagesAlerts(
196196
const lines = new Set()
197197
const translations = getTranslations()
198198
for (const alert of alerts) {
199-
// Based data from { pageProps: { alertTypes } } of:
200-
// https://socket.dev/_next/data/94666139314b6437ee4491a0864e72b264547585/en-US.json
201-
const info = (translations.alerts as any)[alert.type]
202-
const title = info?.title ?? alert.type
203199
const attributes = [
204200
...(alert.fixable ? ['fixable'] : []),
205201
...(alert.block ? [] : ['non-blocking'])
206202
]
207203
const maybeAttributes = attributes.length
208204
? ` (${attributes.join('; ')})`
209205
: ''
206+
// Based data from { pageProps: { alertTypes } } of:
207+
// https://socket.dev/_next/data/94666139314b6437ee4491a0864e72b264547585/en-US.json
208+
const info = (translations.alerts as any)[alert.type]
209+
const title = info?.title ?? alert.type
210210
const maybeDesc = info?.description ? ` - ${info.description}` : ''
211211
// TODO: emoji seems to mis-align terminals sometimes
212212
lines.add(` ${title}${maybeAttributes}${maybeDesc}\n`)
@@ -362,8 +362,11 @@ export async function reify(
362362
): Promise<SafeNode> {
363363
// `this.diff` is `null` when `options.packageLockOnly`, --package-lock-only,
364364
// is `true`.
365-
const needInfoOn = this.diff ? walk(this.diff) : []
366-
if (needInfoOn.findIndex(c => c.repository_url === NPM_REGISTRY_URL) === -1) {
365+
const needInfoOn = walk(this.diff)
366+
if (
367+
needInfoOn.length! ||
368+
needInfoOn.findIndex(c => c.repository_url === NPM_REGISTRY_URL) === -1
369+
) {
367370
// Nothing to check, hmmm already installed or all private?
368371
return await this[kRiskyReify](...args)
369372
}
@@ -413,11 +416,9 @@ export async function reify(
413416
ret = await this[kRiskyReify](...args)
414417
await this.loadActual()
415418
await this.buildIdealTree()
416-
alerts = await getPackagesAlerts(
417-
this,
418-
this.diff ? walk(this.diff, { fix: true }) : [],
419-
{ fixable: true }
420-
)
419+
alerts = await getPackagesAlerts(this, walk(this.diff, { fix: true }), {
420+
fixable: true
421+
})
421422
alerts = alerts.filter(a => {
422423
const { key } = a
423424
if (prev.has(key)) {

0 commit comments

Comments
 (0)