Skip to content

Commit 292931f

Browse files
committed
chore: replace node-fetch and https-proxy-agent with undici
1 parent 12ceecb commit 292931f

File tree

5 files changed

+51
-38
lines changed

5 files changed

+51
-38
lines changed

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
{
2727
"checkLoops": false
2828
}
29-
]
29+
],
30+
"n/no-unsupported-features/node-builtins": ["error", {
31+
"allowExperimental": true
32+
}]
3033
}
3134
}

lib/install.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ exports.usage = 'Attempts to install pre-built binary for module';
77
const fs = require('fs');
88
const path = require('path');
99
const log = require('npmlog');
10+
const { ProxyAgent } = require('undici');
1011
const existsAsync = fs.exists || path.exists;
1112
const versioning = require('./util/versioning.js');
1213
const napi = require('./util/napi.js');
1314
const makeDir = require('make-dir');
14-
// for fetching binaries
15-
const fetch = require('node-fetch');
1615
const tar = require('tar');
1716

1817
let npgVersion = 'unknown';
@@ -56,12 +55,11 @@ function place_binary(uri, targetDir, opts, callback) {
5655
process.env.npm_config_proxy;
5756
let agent;
5857
if (proxyUrl) {
59-
const ProxyAgent = require('https-proxy-agent');
6058
agent = new ProxyAgent(proxyUrl);
6159
log.http('download', 'proxy agent configured using: "%s"', proxyUrl);
6260
}
6361

64-
fetch(sanitized, { agent })
62+
fetch(sanitized, { dispatcher: agent })
6563
.then((res) => {
6664
if (!res.ok) {
6765
throw new Error(`response status ${res.status} ${res.statusText} on ${sanitized}`);

package-lock.json

Lines changed: 41 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
"detect-libc": "^2.0.0",
2727
"https-proxy-agent": "^5.0.0",
2828
"make-dir": "^3.1.0",
29-
"node-fetch": "^2.6.7",
3029
"nopt": "^7.2.1",
3130
"npmlog": "^7.0.1",
3231
"semver": "^7.5.3",
33-
"tar": "^7.4.0"
32+
"tar": "^7.4.0",
33+
"undici": "^6.19.8"
3434
},
3535
"devDependencies": {
3636
"@mapbox/cloudfriend": "^5.1.0",

test/proxy-bcrypt.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const { createUnzip } = require('zlib');
66
const os = require('os');
77

88
const tar = require('tar-fs');
9-
const Agent = require('https-proxy-agent');
10-
const fetch = require('node-fetch');
9+
const { ProxyAgent } = require('undici');
1110
const { rimraf } = require('rimraf');
1211

1312
const test = require('tape');
@@ -44,7 +43,7 @@ test('setup proxy server', (t) => {
4443
proxy.startServer({ port: proxyPort });
4544
process.env.https_proxy = process.env.http_proxy = proxyServer;
4645

47-
options.agent = new Agent(proxyServer);
46+
options.dispatcher = new ProxyAgent(proxyServer);
4847

4948
// make sure the download directory deleted then create an empty one
5049
rimraf(downloadDir).then(() => {

0 commit comments

Comments
 (0)