Description: use another fetch to avoid unavailable make-fetch-happen
Author: Jérémy Lal <kapouer@melix.org>
Forwarded: not-needed
Last-Update: 2021-12-01

--- a/lib/download.js
+++ b/lib/download.js
@@ -1,4 +1,4 @@
-const fetch = require('make-fetch-happen')
+const fetch = require('node-fetch')
 const { promises: fs } = require('graceful-fs')
 const log = require('./log')
 
@@ -9,14 +9,22 @@
     headers: {
       'User-Agent': `node-gyp v${gyp.version} (node ${process.version})`,
       Connection: 'keep-alive'
-    },
-    proxy: gyp.opts.proxy,
-    noProxy: gyp.opts.noproxy
+    }
+  }
+  if (gyp.opts.proxy) {
+    let proxy=true
+    if (gyp.opts.noproxy) {
+      let tmp = typeof gyp.opts.noproxy == 'string' ? gyp.opts.noproxy.split(/,\s*/) : gyp.opts.noproxy
+      if (tmp.includes(url)) proxy = false;
+    }
+    if (proxy) {
+      const {HttpsProxyAgent} = require('https-proxy-agent');
+      requestOpts.agent = new HttpsProxyAgent(gyp.opts.proxy);
+    }
   }
 
-  const cafile = gyp.opts.cafile
-  if (cafile) {
-    requestOpts.ca = await readCAFile(cafile)
+  if (gyp.opts.cafile) {
+    console.error('cafile option not implemented here, use NODE_EXTRA_CA_CERTS variable instead');
   }
 
   const res = await fetch(url, requestOpts)
