Skip to content

Commit 07bb98f

Browse files
committed
chore: replace node-fetch and https-proxy-agent with undici
1 parent bd7cf69 commit 07bb98f

File tree

5 files changed

+97
-20
lines changed

5 files changed

+97
-20
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: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ const log = require('./util/log.js');
1010
const existsAsync = fs.exists || path.exists;
1111
const versioning = require('./util/versioning.js');
1212
const napi = require('./util/napi.js');
13-
// for fetching binaries
14-
const fetch = require('node-fetch');
13+
const { ProxyAgent } = require('undici');
1514
const tar = require('tar');
1615

1716
let npgVersion = 'unknown';
@@ -55,12 +54,11 @@ function place_binary(uri, targetDir, opts, callback) {
5554
process.env.npm_config_proxy;
5655
let agent;
5756
if (proxyUrl) {
58-
const { HttpsProxyAgent } = require('https-proxy-agent');
59-
agent = new HttpsProxyAgent(proxyUrl);
57+
agent = new ProxyAgent(proxyUrl);
6058
log.log('download', `proxy agent configured using: "${proxyUrl}"`);
6159
}
6260

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

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
"consola": "^3.2.3",
2727
"detect-libc": "^2.0.0",
2828
"https-proxy-agent": "^7.0.5",
29-
"node-fetch": "^2.6.7",
3029
"nopt": "^8.0.0",
3130
"semver": "^7.5.3",
32-
"tar": "^7.4.0"
31+
"tar": "^7.4.0",
32+
"undici": "^6.19.8"
3333
},
3434
"devDependencies": {
3535
"@mapbox/cloudfriend": "^8.1.0",
@@ -39,7 +39,7 @@
3939
"eslint": "^8.57.0",
4040
"eslint-plugin-n": "^17.9.0",
4141
"mock-aws-s3": "^4.0.2",
42-
"nock": "^13.5.4",
42+
"nock": "^14.0.0-beta.19",
4343
"node-addon-api": "^8.1.0",
4444
"nyc": "^17.0.0",
4545
"tape": "^5.5.2",

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 { HttpsProxyAgent } = 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 HttpsProxyAgent(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)