mirror of
https://github.com/nodejs/node.git
synced 2025-05-13 10:54:13 +00:00

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>
20 lines
510 B
JavaScript
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
|