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

Method findVersionsByPackageName

deps/npm/lib/commands/diff.js:247–277  ·  view source on GitHub ↗
(specs)

Source from the content-addressed store, hash-verified

245 }
246
247 async findVersionsByPackageName (specs) {
248 let actualTree
249 const Arborist = require('@npmcli/arborist')
250 try {
251 const opts = {
252 ...this.npm.flatOptions,
253 path: this.top,
254 }
255 const arb = new Arborist(opts)
256 actualTree = await arb.loadActual(opts)
257 } catch {
258 log.verbose('diff', 'failed to load actual install tree')
259 }
260
261 return specs.map(i => {
262 const spec = npa(i)
263 if (spec.rawSpec !== '*') {
264 return i
265 }
266
267 const node = actualTree
268 && actualTree.inventory.query('name', spec.name)
269 .values().next().value
270
271 const res = !node || !node.package || !node.package.version
272 ? spec.fetchSpec
273 : `file:${node.realpath}`
274
275 return `${spec.name}@${res}`
276 })
277 }
278}
279
280module.exports = Diff

Callers 1

retrieveSpecsMethod · 0.95

Calls 6

verboseMethod · 0.80
mapMethod · 0.65
nextMethod · 0.65
queryMethod · 0.65
requireFunction · 0.50
valuesMethod · 0.45

Tested by

no test coverage detected