Skip to content

Commit 9157db5

Browse files
committed
Make log optional
1 parent 20cc82e commit 9157db5

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

src/shadow/arborist.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ type SocketPackageAlert = {
239239

240240
interface KnownModules {
241241
npmlog: typeof import('npmlog')
242-
pacote: typeof import('pacote')
243242
'proc-log': typeof import('proc-log')
244243
}
245244

@@ -321,18 +320,10 @@ const log = tryRequire(
321320
<'npmlog'>path.join(npmNmPath, 'npmlog/lib/log.js')
322321
)
323322

324-
if (log === undefined) {
325-
console.error(
326-
`Unable to integrate with npm CLI logging infrastructure.\n\n${POTENTIAL_BUG_ERROR_MESSAGE}.`
327-
)
328-
// The exit code 127 indicates that the command or binary being executed
329-
// could not be found.
330-
process.exit(127)
331-
}
332-
333-
const pacote = tryRequire(<'pacote'>path.join(npmNmPath, 'pacote'), 'pacote')!
334-
const { tarball } = pacote
335-
const translations = require(path.join(rootPath, 'translations.json'))
323+
const pacote: typeof import('pacote') = require(path.join(npmNmPath, 'pacote'))
324+
const translations: typeof import('../../translations.json') = require(
325+
path.join(rootPath, 'translations.json')
326+
)
336327

337328
const Arborist: ArboristClass = require(arboristClassPath)
338329
const depValid: (
@@ -475,7 +466,7 @@ function findSpecificOverrideSet(
475466
overrideSet = overrideSet.parent
476467
}
477468
// The override sets are incomparable. Neither one contains the other.
478-
log!.silly('Conflicting override sets', first, second)
469+
log?.silly('Conflicting override sets', first, second)
479470
return undefined
480471
}
481472

@@ -571,7 +562,7 @@ async function getPackagesAlerts(
571562
if (!blocked) {
572563
const pkg = pkgs.find(p => p.pkgid === id)
573564
if (pkg) {
574-
await tarball.stream(
565+
await pacote.tarball.stream(
575566
id,
576567
stream => {
577568
stream.resume()
@@ -590,7 +581,7 @@ async function getPackagesAlerts(
590581
for (const alert of alerts) {
591582
// Based data from { pageProps: { alertTypes } } of:
592583
// https://socket.dev/_next/data/94666139314b6437ee4491a0864e72b264547585/en-US.json
593-
const info = translations.alerts[alert.type]
584+
const info = (translations.alerts as any)[alert.type]
594585
const title = info?.title ?? alert.type
595586
const attributes = [
596587
...(alert.fixable ? ['fixable'] : []),
@@ -1208,7 +1199,7 @@ class SafeNode extends Node {
12081199
}
12091200
// This is an error condition. We can only get here if the new override set
12101201
// is in conflict with the existing.
1211-
log!.silly('Conflicting override sets', this.name)
1202+
log?.silly('Conflicting override sets', this.name)
12121203
return false
12131204
}
12141205

0 commit comments

Comments
 (0)