From 49ab5efe769c1f7f6fd13c93ebccca71b0fe15ef Mon Sep 17 00:00:00 2001 From: Wilson Lin Date: Sun, 7 May 2023 17:52:30 +0700 Subject: [PATCH] Fix Node.js postinstall.js building from source --- nodejs/postinstall.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nodejs/postinstall.js b/nodejs/postinstall.js index 63b286f..1dcc485 100644 --- a/nodejs/postinstall.js +++ b/nodejs/postinstall.js @@ -22,7 +22,11 @@ const fetch = (url) => new Promise((resolve, reject) => { const stream = https.get(url, (resp) => { if (!resp.statusCode || resp.statusCode < 200 || resp.statusCode > 299) { - return reject(new StatusError(resp.statusCode)); + reject(new StatusError(resp.statusCode)); + // Destroy stream to allow Node.js to exit. + // Destroy after `reject` in case "error" handler is unintentionally triggered. + resp.destroy(); + return; } const parts = []; resp.on("data", (chunk) => parts.push(chunk));