MCPcopy Create free account
hub / github.com/nodejs/node / exec

Method exec

deps/npm/lib/commands/explain.js:25–83  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

23 }
24
25 async exec (args) {
26 if (!args.length) {
27 throw this.usageError()
28 }
29
30 const Arborist = require('@npmcli/arborist')
31 const arb = new Arborist({ path: this.npm.prefix, ...this.npm.flatOptions })
32 const tree = await arb.loadActual()
33
34 if (this.npm.flatOptions.workspacesEnabled
35 && this.workspaceNames
36 && this.workspaceNames.length
37 ) {
38 this.filterSet = arb.workspaceDependencySet(tree, this.workspaceNames)
39 } else if (!this.npm.flatOptions.workspacesEnabled) {
40 this.filterSet =
41 arb.excludeWorkspacesDependencySet(tree)
42 }
43
44 const nodes = new Set()
45 for (const arg of args) {
46 for (const node of this.getNodes(tree, arg)) {
47 const filteredOut = this.filterSet
48 && this.filterSet.size > 0
49 && !this.filterSet.has(node)
50 if (!filteredOut) {
51 nodes.add(node)
52 }
53 }
54 }
55 if (nodes.size === 0) {
56 throw new Error(`No dependencies found matching ${args.join(', ')}`)
57 }
58
59 const expls = []
60 for (const node of nodes) {
61 const { extraneous, dev, optional, devOptional, peer, inBundle, overridden } = node
62 const expl = node.explain()
63 if (extraneous) {
64 expl.extraneous = true
65 } else {
66 expl.dev = dev
67 expl.optional = optional
68 expl.devOptional = devOptional
69 expl.peer = peer
70 expl.bundled = inBundle
71 expl.overridden = overridden
72 }
73 expls.push(expl)
74 }
75
76 if (this.npm.flatOptions.json) {
77 output.buffer(expls)
78 } else {
79 output.standard(expls.map(expl => {
80 return explainNode(expl, Infinity, this.npm.chalk)
81 }).join('\n\n'))
82 }

Callers

nothing calls this directly

Calls 10

getNodesMethod · 0.95
explainNodeFunction · 0.85
usageErrorMethod · 0.80
hasMethod · 0.65
addMethod · 0.65
mapMethod · 0.65
requireFunction · 0.50
joinMethod · 0.45
pushMethod · 0.45
bufferMethod · 0.45

Tested by

no test coverage detected