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

Method missingArgsFromTree

lib/commands/link.js:172–202  ·  view source on GitHub ↗
(tree, args)

Source from the content-addressed store, hash-verified

170
171 // Returns a list of items that can't be fulfilled by things found in the current arborist inventory
172 missingArgsFromTree (tree, args) {
173 if (tree.isLink) {
174 return this.missingArgsFromTree(tree.target, args)
175 }
176
177 const foundNodes = []
178 const missing = args.filter(a => {
179 const arg = npa(a)
180 const nodes = tree.children.values()
181 const argFound = [...nodes].every(node => {
182 // TODO: write tests for unmatching version specs
183 // this is hard to test atm but should be simple once we have a mocked registry again
184 if (arg.name !== node.name /* istanbul ignore next */ || (
185 arg.version &&
186 /* istanbul ignore next */
187 !semver.satisfies(node.version, arg.version)
188 )) {
189 foundNodes.push(node)
190 return true
191 }
192 })
193 return argFound
194 })
195
196 // remote nodes from the loaded tree in order to avoid dropping them later when reifying
197 for (const node of foundNodes) {
198 node.parent = null
199 }
200
201 return missing
202 }
203}
204
205module.exports = Link

Callers 1

linkInstallMethod · 0.95

Calls 3

filterMethod · 0.80
satisfiesMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected