From c2b8bf7f4e5c0aff908b61e25cc7b60ef7a18df2 Mon Sep 17 00:00:00 2001 From: MicroBlock <66859419+MicroCBer@users.noreply.github.com> Date: Wed, 26 Jul 2023 15:13:37 +0800 Subject: [PATCH] feat: implement redirect for fetch-yarn-deps This would fix NixOS/nixpkgs#245415 --- pkgs/build-support/node/fetch-yarn-deps/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/node/fetch-yarn-deps/index.js b/pkgs/build-support/node/fetch-yarn-deps/index.js index 3cae1c16a2e7..04f47362b10d 100755 --- a/pkgs/build-support/node/fetch-yarn-deps/index.js +++ b/pkgs/build-support/node/fetch-yarn-deps/index.js @@ -22,7 +22,14 @@ const exec = async (...args) => { const downloadFileHttps = (fileName, url, expectedHash, hashType = 'sha1') => { return new Promise((resolve, reject) => { - https.get(url, (res) => { + const get = (url, redirects = 0) => https.get(url, (res) => { + if(redirects > 10) { + reject('Too many redirects!'); + return; + } + if(res.statusCode === 301 || res.statusCode === 302) { + return get(res.headers.location, redirects + 1) + } const file = fs.createWriteStream(fileName) const hash = crypto.createHash(hashType) res.pipe(file) @@ -35,6 +42,7 @@ const downloadFileHttps = (fileName, url, expectedHash, hashType = 'sha1') => { }) res.on('error', e => reject(e)) }) + get(url) }) }