mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
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>
20 lines
500 B
JavaScript
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
|