mirror of
https://github.com/nodejs/node.git
synced 2025-05-15 17:51:35 +00:00

PR-URL: https://github.com/nodejs/node/pull/41503 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruy Adorno <ruyadorno@github.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
21 lines
516 B
JavaScript
21 lines
516 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
|