node/deps/npm/node_modules/libnpmexec/lib/cache-install-dir.js
Ruy Adorno c975dff3c0
deps: upgrade npm to 7.11.2
PR-URL: https://github.com/nodejs/node/pull/38475
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
2021-04-30 17:39:15 -04:00

20 lines
500 B
JavaScript

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