Welcome to mirror list, hosted at ThFree Co, Russian Federation.

audit.js « bin « arborist « workspaces - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0e32833d4aa3a1b364641c39fbc458438eef84ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const Arborist = require('../')

const printTree = require('./lib/print-tree.js')
const log = require('./lib/logging.js')

const Vuln = require('../lib/vuln.js')
const printReport = report => {
  for (const vuln of report.values()) {
    log.info(printVuln(vuln))
  }
  if (report.topVulns.size) {
    log.info('\n# top-level vulnerabilities')
    for (const vuln of report.topVulns.values()) {
      log.info(printVuln(vuln))
    }
  }
}

const printVuln = vuln => {
  return {
    __proto__: { constructor: Vuln },
    name: vuln.name,
    issues: [...vuln.advisories].map(a => printAdvisory(a)),
    range: vuln.simpleRange,
    nodes: [...vuln.nodes].map(node => `${node.name} ${node.location || '#ROOT'}`),
    ...(vuln.topNodes.size === 0 ? {} : {
      topNodes: [...vuln.topNodes].map(node => `${node.location || '#ROOT'}`),
    }),
  }
}

const printAdvisory = a => `${a.title}${a.url ? ' ' + a.url : ''}`

module.exports = (options, time) => {
  const arb = new Arborist(options)
  return arb
    .audit(options)
    .then(time)
    .then(async ({ timing, result: tree }) => {
      if (options.fix) {
        printTree(tree)
      }
      printReport(arb.auditReport)
      if (tree.meta && options.save) {
        await tree.meta.save()
      }
      return options.fix
        ? `resolved ${tree.inventory.size} deps in ${timing.seconds}`
        : `done in ${timing.seconds}`
    })
}