Manipulate cache of npm packages
const npcache = require('npcache');
(async () => {
const cache = await npcache.get('make-fetch-happen:request-cache:https://registry.npmjs.org/glob');
cache.metadata; //=> {url: 'https://registry.npmjs.org/glob', ...}
cache.data; //=> <Buffer 7b 22 76 65 72 73 69 6f 6e 73 22 3a 7b 22 ...>
cache.size; //=> 37086
cache.integrity; //=> 'sha512-Non1RHdlmK+8lJaN1a88N ...'
})();
npm install npcache
const npcache = require('npcache');
The API is based on cacache, a cache manipulation library used inside npm CLI.
Note the following differences:
- Original
cache
parameters are omitted, and it defaults to_cacache
in the npm cache directory. - Method aliases, for example
cacache.rm.entry
→cacache.rm
, are removed. clearMemoized()
returns aPromise
instead ofundefined
.setLocale()
method is not supported.
(async () => {
for await (const {path} of npcache.ls.stream()) {
console.log(path);
}
})();
/Users/shinnn/.npm/_cacache/content-v2/sha512/a6/12/5f41506e689339ada ...
/Users/shinnn/.npm/_cacache/content-v2/sha512/ff/1a/f50039b96e74e38cd ...
/Users/shinnn/.npm/_cacache/content-v2/sha512/0b/61/241d7c17bcbb1baee ...
/Users/shinnn/.npm/_cacache/content-v2/sha512/39/a5/358478e025ff9bd0d ...
...
ISC License © 2018 - 2019 Watanabe Shinnosuke