From 1465576f9c7b34c3a6f1050363962af549c2162d Mon Sep 17 00:00:00 2001 From: Florian Dieminger Date: Fri, 20 Dec 2024 15:39:17 +0100 Subject: [PATCH] fix(rari-npm): make install faster Reported to vscode-ripgrep https://github.com/microsoft/vscode-ripgrep/pull/62 --- rari-npm/lib/download.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/rari-npm/lib/download.js b/rari-npm/lib/download.js index 1d7ed91..e8ac53e 100644 --- a/rari-npm/lib/download.js +++ b/rari-npm/lib/download.js @@ -85,20 +85,22 @@ export async function do_download(url, dest, opts) { .get(url, opts, (response) => { console.log("statusCode: " + response.statusCode); if (response.statusCode === 302 && response.headers.location) { + response.resume(); // See https://github.com/nodejs/node/issues/47228 🤷 + outFile.close(); console.log("Following redirect to: " + response.headers.location); - return do_download(response.headers.location, dest, opts).then( - resolve, - reject, - ); + return do_download(response.headers.location, dest, opts) + .then(resolve) + .catch(reject); } else if (response.statusCode !== 200) { - reject(new Error("Download failed with " + response.statusCode)); - return; + return reject( + new Error("Download failed with " + response.statusCode), + ); + } else { + response.pipe(outFile); + outFile.on("finish", () => { + resolve(null); + }); } - - response.pipe(outFile); - outFile.on("finish", () => { - resolve(null); - }); }) .on("error", async (err) => { await unlink(dest);