MCPcopy Create free account
hub / github.com/nodejs/node / #npxCache

Method #npxCache

deps/npm/lib/commands/cache.js:232–271  ·  view source on GitHub ↗
(keys = [])

Source from the content-addressed store, hash-verified

230 }
231
232 async #npxCache (keys = []) {
233 // This is a derived value
234 const { npxCache } = this.npm.flatOptions
235 let dirs
236 try {
237 dirs = await fs.readdir(npxCache, { encoding: 'utf-8' })
238 } catch {
239 output.standard('npx cache does not exist')
240 return
241 }
242 const cache = {}
243 const { default: pMap } = await import('p-map')
244 await pMap(dirs, async e => {
245 const pkgPath = join(npxCache, e)
246 cache[e] = {
247 hash: e,
248 path: pkgPath,
249 valid: false,
250 }
251 try {
252 const pkgJson = await PkgJson.load(pkgPath)
253 cache[e].package = pkgJson.content
254 cache[e].valid = true
255 } catch {
256 // Defaults to not valid already
257 }
258 }, { concurrency: 20 })
259 if (!keys.length) {
260 return cache
261 }
262 const result = {}
263 const abbrevs = abbrev(Object.keys(cache))
264 for (const key of keys) {
265 if (!abbrevs[key]) {
266 throw this.usageError(`Invalid npx key ${key}`)
267 }
268 result[abbrevs[key]] = cache[abbrevs[key]]
269 }
270 return result
271 }
272
273 async npxLs () {
274 const cache = await this.#npxCache()

Callers 3

npxLsMethod · 0.95
npxRmMethod · 0.95
npxInfoMethod · 0.95

Calls 5

usageErrorMethod · 0.80
keysMethod · 0.65
joinFunction · 0.50
readdirMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected