File: use-other-fetch.patch

package info (click to toggle)
node-gyp 11.4.0%2B~5.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,368 kB
  • sloc: python: 24,953; javascript: 5,133; lisp: 258; cs: 186; ansic: 46; cpp: 29; sh: 23; makefile: 7
file content (42 lines) | stat: -rw-r--r-- 1,266 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)