MCPcopy Create free account
hub / github.com/npm/cli / reifyOutput

Function reifyOutput

lib/utils/reify-output.js:21–137  ·  view source on GitHub ↗
(npm, arb, extras = {})

Source from the content-addressed store, hash-verified

19const { configSetAllowScripts } = require('./allow-scripts-remediation.js')
20
21const reifyOutput = (npm, arb, extras = {}) => {
22 const { diff, actualTree } = arb
23 const unreviewedScripts = extras.unreviewedScripts || []
24
25 // note: fails and crashes if we're running audit fix and there was an error which is a good thing, because there's no point printing all this other stuff in that case!
26 const auditReport = auditError(npm, arb.auditReport) ? null : arb.auditReport
27
28 // don't print any info in --silent mode, but we still need to set the exitCode properly from the audit report, if we have one.
29 if (npm.silent) {
30 getAuditReport(npm, auditReport)
31 return
32 }
33
34 const summary = {
35 add: [],
36 added: 0,
37 // audit gets added later
38 audited: auditReport && !auditReport.error ? actualTree.inventory.size : 0,
39 change: [],
40 changed: 0,
41 funding: 0,
42 remove: [],
43 removed: 0,
44 }
45
46 if (diff) {
47 const showDiff = npm.config.get('dry-run') || npm.config.get('long')
48 const chalk = npm.chalk
49
50 depth({
51 tree: diff,
52 visit: d => {
53 switch (d.action) {
54 case 'REMOVE':
55 if (showDiff) {
56 output.standard(`${chalk.blue('remove')} ${d.actual.name} ${d.actual.package.version}`)
57 }
58 summary.removed++
59 summary.remove.push({
60 name: d.actual.name,
61 version: d.actual.package.version,
62 path: d.actual.path,
63 })
64 break
65 case 'ADD':
66 if (showDiff) {
67 output.standard(`${chalk.green('add')} ${d.ideal.name} ${d.ideal.package.version}`)
68 }
69 // Linked store packages live under .store, absent from the logical actualTree, so identity lookup misses them; count each store package node (non-link).
70 if (actualTree.inventory.has(d.ideal) || (d.ideal.isInStore && !d.ideal.isLink)) {
71 summary.added++
72 summary.add.push({
73 name: d.ideal.name,
74 version: d.ideal.package.version,
75 path: d.ideal.path,
76 })
77 }
78 break

Callers 4

reifyFinishFunction · 0.85
mockReifyFunction · 0.85
mockReifyWithExtrasFunction · 0.85
reify-output.jsFile · 0.85

Calls 11

getAuditReportFunction · 0.85
trustedDisplayFunction · 0.85
packagesChangedMessageFunction · 0.85
packagesFundingMessageFunction · 0.85
printAuditReportFunction · 0.85
unreviewedScriptsMessageFunction · 0.85
pushMethod · 0.80
auditErrorFunction · 0.70
getMethod · 0.45
hasMethod · 0.45
toJSONMethod · 0.45

Tested by

no test coverage detected