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

Method npxInfo

deps/npm/lib/commands/cache.js:310–360  ·  view source on GitHub ↗
(keys)

Source from the content-addressed store, hash-verified

308 }
309
310 async npxInfo (keys) {
311 const chalk = this.npm.chalk
312 if (!keys.length) {
313 throw this.usageError()
314 }
315 const cache = await this.#npxCache(keys)
316 const Arborist = require('@npmcli/arborist')
317 for (const key in cache) {
318 const { hash, path, package: pkg } = cache[key]
319 let valid = cache[key].valid
320 const results = []
321 try {
322 if (valid) {
323 const arb = new Arborist({ path })
324 const tree = await arb.loadVirtual()
325 if (pkg._npx) {
326 results.push('packages:')
327 for (const p of pkg._npx.packages) {
328 const parsed = npa(p)
329 if (parsed.type === 'directory') {
330 // in the tree the spec is relative, even if the dependency spec is absolute, so we can't find it by name or spec.
331 results.push(`- ${chalk.cyan(p)}`)
332 } else {
333 results.push(`- ${chalk.cyan(p)} (${chalk.blue(tree.children.get(parsed.name).pkgid)})`)
334 }
335 }
336 } else {
337 results.push('packages: (unknown)')
338 results.push(`dependencies:`)
339 for (const dep in pkg.dependencies) {
340 const child = tree.children.get(dep)
341 if (child.isLink) {
342 results.push(`- ${chalk.cyan(child.realpath)}`)
343 } else {
344 results.push(`- ${chalk.cyan(child.pkgid)}`)
345 }
346 }
347 }
348 }
349 } catch (ex) {
350 valid = false
351 }
352 const v = valid ? chalk.green('valid') : chalk.red('invalid')
353 output.standard(`${v} npx cache entry with key ${chalk.blue(hash)}`)
354 output.standard(`location: ${chalk.blue(path)}`)
355 if (valid) {
356 output.standard(results.join('\n'))
357 }
358 output.standard()
359 }
360 }
361}
362
363module.exports = Cache

Callers 1

npxMethod · 0.95

Calls 9

#npxCacheMethod · 0.95
usageErrorMethod · 0.80
blueMethod · 0.80
getMethod · 0.65
requireFunction · 0.50
pushMethod · 0.45
greenMethod · 0.45
redMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected