Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cache-install-dir.js « lib « libnpmexec « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1bee28989bf76d2633f72590163c5f86031c729f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const crypto = require('crypto')

const { resolve } = require('path')

const cacheInstallDir = ({ cache, packages }) => {
  if (!cache)
    throw new Error('Must provide a valid cache path')

  // only packages not found in ${prefix}/node_modules
  return resolve(cache, '_npx', getHash(packages))
}

const getHash = (packages) =>
  crypto.createHash('sha512')
    .update(packages.sort((a, b) => a.localeCompare(b)).join('\n'))
    .digest('hex')
    .slice(0, 16)

module.exports = cacheInstallDir