restore-npm-cache

0.1.0 • Public • Published

restore-npm-cache

npm version Build Status Coverage Status

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

Use npm.

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

Package Sidebar

Install

npm i restore-npm-cache

Weekly Downloads

4

Version

0.1.0

License

ISC

Unpacked Size

6.9 kB

Total Files

4

Last publish

Collaborators

  • shinnn