fetchYarnDeps: support hash in pkg.integrity (#177255)
This commit is contained in:
parent
b1957596ff
commit
e3e091672f
@ -33,11 +33,11 @@ const urlToName = url => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const downloadFileHttps = (fileName, url, expectedHash) => {
|
const downloadFileHttps = (fileName, url, expectedHash, hashType = 'sha1') => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
https.get(url, (res) => {
|
https.get(url, (res) => {
|
||||||
const file = fs.createWriteStream(fileName)
|
const file = fs.createWriteStream(fileName)
|
||||||
const hash = crypto.createHash('sha1')
|
const hash = crypto.createHash(hashType)
|
||||||
res.pipe(file)
|
res.pipe(file)
|
||||||
res.pipe(hash).setEncoding('hex')
|
res.pipe(hash).setEncoding('hex')
|
||||||
res.on('end', () => {
|
res.on('end', () => {
|
||||||
@ -100,6 +100,10 @@ const downloadPkg = (pkg, verbose) => {
|
|||||||
} else if (isGitUrl(url)) {
|
} else if (isGitUrl(url)) {
|
||||||
return downloadGit(fileName, url.replace(/^git\+/, ''), hash)
|
return downloadGit(fileName, url.replace(/^git\+/, ''), hash)
|
||||||
} else if (url.startsWith('https://')) {
|
} else if (url.startsWith('https://')) {
|
||||||
|
if (typeof pkg.integrity === 'string' || pkg.integrity instanceof String) {
|
||||||
|
const [ type, checksum ] = pkg.integrity.split('-')
|
||||||
|
return downloadFileHttps(fileName, url, Buffer.from(checksum, 'base64').toString('hex'), type)
|
||||||
|
}
|
||||||
return downloadFileHttps(fileName, url, hash)
|
return downloadFileHttps(fileName, url, hash)
|
||||||
} else if (url.startsWith('file:')) {
|
} else if (url.startsWith('file:')) {
|
||||||
console.warn(`ignoring unsupported file:path url "${url}"`)
|
console.warn(`ignoring unsupported file:path url "${url}"`)
|
||||||
|
Loading…
Reference in New Issue
Block a user