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

installed-deep.js « completion « utils « lib - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 590955a1ee52082037043512bc546cefbb0b079c (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
const { resolve } = require('path')
const Arborist = require('@npmcli/arborist')
const localeCompare = require('@isaacs/string-locale-compare')('en')

const installedDeep = async (npm) => {
  const {
    depth,
    global,
    prefix,
  } = npm.flatOptions

  const getValues = (tree) =>
    [...tree.inventory.values()]
      .filter(i => i.location !== '' && !i.isRoot)
      .map(i => {
        return i
      })
      .filter(i => (i.depth - 1) <= depth)
      .sort((a, b) => (a.depth - b.depth) || localeCompare(a.name, b.name))

  const res = new Set()
  const gArb = new Arborist({ global: true, path: resolve(npm.globalDir, '..') })
  const gTree = await gArb.loadActual({ global: true })

  for (const node of getValues(gTree))
    res.add(global ? node.name : [node.name, '-g'])

  if (!global) {
    const arb = new Arborist({ global: false, path: prefix })
    const tree = await arb.loadActual()
    for (const node of getValues(tree))
      res.add(node.name)
  }

  return [...res]
}

module.exports = installedDeep