6

I am looking at the cache docs: https://docs.npmjs.com/cli/cache

if I ran this:

npm cache add lodash@x.y.z

how can I check later, if this is in the npm cache?

I don't see npm cache get lodash@x.y.z in the docs...

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • this is what I currently have to check if the npm cache has a certain package, but I don't think it's correct. https://github.com/ORESoftware/npm.cache/blob/master/src/cache-has.ts – Alexander Mills Jun 15 '18 at 21:47
  • this will be help . try with cacache module that managing local key and content address cache. https://github.com/zkat/cacache – channasmcs Jun 22 '18 at 13:39
  • @channasmcs update that library to TypeScript and I might use it – Alexander Mills Jun 23 '18 at 20:49

1 Answers1

5

Looks like npm has not a direct way to achieve this, but this script does the trick

create a file cache.js and paste code below

const cacache = require('cacache/en')
const cachePath = require('os').homedir()+'/.npm/_cacache'

cacache.ls(cachePath)
  .then((packages) => {
    for(const i in packages) {
      console.log(packages[i].key)
    }
  }) 

run

npm install cacache

then run

node cache.js | grep lodash

personal opinion: yarn is designed to cache npm packages, if you are going to do that, you could give it a chance

EDIT: I made a script that does all of the above, every feedback is welcome

https://www.npmjs.com/package/npm-check-cache

Simone Sanfratello
  • 1,520
  • 1
  • 10
  • 21