node/deps/npm/node_modules/libnpmexec/lib/cache-install-dir.js
npm-robot 98139dfef1
deps: upgrade npm to 7.18.1
PR-URL: https://github.com/nodejs/node/pull/39065
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruy Adorno <ruyadorno@github.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2021-06-18 11:51:54 -04:00

20 lines
510 B
JavaScript

const crypto = require('crypto')
const { resolve } = require('path')
const cacheInstallDir = ({ npxCache, packages }) => {
if (!npxCache)
throw new Error('Must provide a valid npxCache path')
// only packages not found in ${prefix}/node_modules
return resolve(npxCache, getHash(packages))
}
const getHash = (packages) =>
crypto.createHash('sha512')
.update(packages.sort((a, b) => a.localeCompare(b, 'en')).join('\n'))
.digest('hex')
.slice(0, 16)
module.exports = cacheInstallDir