diff options
author | MicroBlock <66859419+MicroCBer@users.noreply.github.com> | 2023-07-26 15:13:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-26 15:13:37 +0800 |
commit | c2b8bf7f4e5c0aff908b61e25cc7b60ef7a18df2 (patch) | |
tree | 1f0fc32bb81422346f9b51db8ab6ba838f1406bb /pkgs/build-support | |
parent | 49caf90f03efe6a25703c79594b703b80fc76bf0 (diff) |
feat: implement redirect for fetch-yarn-deps
This would fix NixOS/nixpkgs#245415
Diffstat (limited to 'pkgs/build-support')
-rwxr-xr-x | pkgs/build-support/node/fetch-yarn-deps/index.js | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/pkgs/build-support/node/fetch-yarn-deps/index.js b/pkgs/build-support/node/fetch-yarn-deps/index.js index 3cae1c16a2e7f..04f47362b10dc 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) }) } |