Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

fetchYarnDeps: support hash in pkg.integrity (#177255)

authored by

Chuang Zhu and committed by
GitHub
e3e09167 b1957596

+6 -2
+6 -2
pkgs/build-support/node/fetch-yarn-deps/index.js
··· 33 33 } 34 34 } 35 35 36 - const downloadFileHttps = (fileName, url, expectedHash) => { 36 + const downloadFileHttps = (fileName, url, expectedHash, hashType = 'sha1') => { 37 37 return new Promise((resolve, reject) => { 38 38 https.get(url, (res) => { 39 39 const file = fs.createWriteStream(fileName) 40 - const hash = crypto.createHash('sha1') 40 + const hash = crypto.createHash(hashType) 41 41 res.pipe(file) 42 42 res.pipe(hash).setEncoding('hex') 43 43 res.on('end', () => { ··· 100 100 } else if (isGitUrl(url)) { 101 101 return downloadGit(fileName, url.replace(/^git\+/, ''), hash) 102 102 } else if (url.startsWith('https://')) { 103 + if (typeof pkg.integrity === 'string' || pkg.integrity instanceof String) { 104 + const [ type, checksum ] = pkg.integrity.split('-') 105 + return downloadFileHttps(fileName, url, Buffer.from(checksum, 'base64').toString('hex'), type) 106 + } 103 107 return downloadFileHttps(fileName, url, hash) 104 108 } else if (url.startsWith('file:')) { 105 109 console.warn(`ignoring unsupported file:path url "${url}"`)