MCPcopy Index your code
hub / github.com/nodejs/node / exec

Method exec

deps/npm/lib/commands/ls.js:47–208  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

45 }
46
47 async exec (args) {
48 const all = this.npm.config.get('all')
49 const chalk = this.npm.chalk
50 const depth = this.npm.config.get('depth')
51 const global = this.npm.global
52 const json = this.npm.config.get('json')
53 const link = this.npm.config.get('link')
54 const long = this.npm.config.get('long')
55 const omit = this.npm.flatOptions.omit
56 const parseable = this.npm.config.get('parseable')
57 const unicode = this.npm.config.get('unicode')
58 const packageLockOnly = this.npm.config.get('package-lock-only')
59 const workspacesEnabled = this.npm.flatOptions.workspacesEnabled
60 const installStrategy = this.npm.flatOptions.installStrategy
61
62 const path = global ? resolve(this.npm.globalDir, '..') : this.npm.prefix
63
64 const Arborist = require('@npmcli/arborist')
65
66 const arb = new Arborist({
67 global,
68 ...this.npm.flatOptions,
69 legacyPeerDeps: false,
70 path,
71 })
72 const tree = await this.initTree({ arb, args, packageLockOnly })
73
74 // filters by workspaces nodes when using -w <workspace-name>
75 // We only have to filter the first layer of edges, so we don't explore anything that isn't part of the selected workspace set.
76 let wsNodes
77 if (this.workspaceNames && this.workspaceNames.length) {
78 wsNodes = arb.workspaceNodes(tree, this.workspaceNames)
79 }
80 const filterBySelectedWorkspaces = edge => {
81 if (!workspacesEnabled
82 && edge.from.isProjectRoot
83 && edge.to.isWorkspace
84 ) {
85 return false
86 }
87
88 if (!wsNodes || !wsNodes.length) {
89 return true
90 }
91
92 if (this.npm.flatOptions.includeWorkspaceRoot
93 && edge.to && !edge.to.isWorkspace) {
94 return true
95 }
96
97 if (edge.from.isProjectRoot) {
98 return (edge.to
99 && edge.to.isWorkspace
100 && wsNodes.includes(edge.to.target))
101 }
102
103 return true
104 }

Callers 1

entry.jsFile · 0.45

Calls 14

initTreeMethod · 0.95
breadthFunction · 0.85
jsonOutputFunction · 0.85
parseableOutputFunction · 0.85
humanOutputFunction · 0.85
assignMethod · 0.80
everyMethod · 0.80
getMethod · 0.65
filterMethod · 0.65
resolveFunction · 0.50
requireFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected