restore-npm-cache
v0.1.0
Published
Restore contents from an npm cache
Downloads
26
Maintainers
Readme
restore-npm-cache
Restore contents from an npm cache
const restoreNpmCache = require('restore-npm-cache');
(async () => {
await restoreNpmCache('make-fetch-happen:request-cache:https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz');
require('./package/package.json');
//=> {name: 'lodash', version: '4.17.10', description: 'Lodash modular utilities.', ...}
})();
Installation
npm install restore-npm-cache
API
const restoreNpmCache = require('restore-npm-cache');
restoreNpmCache(key [, options])
key: string
options: Object
(node-tar's Unpack
constructor options with strict
defaulting to true
)
Return: Promise<Object>
It finds an npm cache entry identified by the given key, extract its contents from the gzipped tarball to a directory where cwd
option points (or process.cwd()
if cwd
is not provided), and returns a Promise
for information of the entry.
It automatically creates directories when the directory specified by cwd
option doesn't exist.
const {readdir} = require('fs').promises;
const restoreNpmCache = require('restore-npm-cache');
(async () => {
const info = await restoreNpmCache('make-fetch-happen:request-cache:https://registry.npmjs.org/eslint/-/eslint-5.6.1.tgz', {
cwd: 'new/dir',
strip: 1
});
info.integrity; //=> 'sha512-hgrDtGWz368b7Wqf+ ... 5WRN1TAS6eo7AYA=='
info.size; //=> 514066
info.time; //=> 538368647819
await readdir('new/dir');
/*=> [
'CHANGELOG.md',
'LICENSE',
'README.md',
'bin',
'conf',
'lib',
'messages',
'package.json'
] */
})();
License
ISC License © 2018 Shinnosuke Watanabe