Skip to content

Commit fe419c3

Browse files
committed
chore: replace node-fetch and https-proxy-agent with undici
1 parent 2c2b7cf commit fe419c3

File tree

5 files changed

+100
-27
lines changed

5 files changed

+100
-27
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ 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');
1415
// for fetching binaries
15-
const fetch = require('node-fetch');
1616
const tar = require('tar');
1717

1818
let npgVersion = 'unknown';
@@ -56,12 +56,11 @@ function place_binary(uri, targetDir, opts, callback) {
5656
process.env.npm_config_proxy;
5757
let agent;
5858
if (proxyUrl) {
59-
const ProxyAgent = require('https-proxy-agent');
6059
agent = new ProxyAgent(proxyUrl);
6160
log.http('download', 'proxy agent configured using: "%s"', proxyUrl);
6261
}
6362

64-
fetch(sanitized, { agent })
63+
fetch(sanitized, { dispatcher: agent })
6564
.then((res) => {
6665
if (!res.ok) {
6766
throw new Error(`response status ${res.status} ${res.statusText} on ${sanitized}`);

package-lock.json

Lines changed: 89 additions & 17 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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@
2424
},
2525
"dependencies": {
2626
"detect-libc": "^2.0.0",
27-
"https-proxy-agent": "^5.0.0",
2827
"make-dir": "^3.1.0",
29-
"node-fetch": "^2.6.7",
3028
"nopt": "^7.2.1",
3129
"npmlog": "^7.0.1",
3230
"semver": "^7.3.5",
33-
"tar": "^7.4.0"
31+
"tar": "^7.4.0",
32+
"undici": "^6.19.2"
3433
},
3534
"devDependencies": {
3635
"@mapbox/cloudfriend": "^5.1.0",
@@ -40,7 +39,7 @@
4039
"eslint": "^8.57.0",
4140
"eslint-plugin-n": "^17.9.0",
4241
"mock-aws-s3": "^4.0.2",
43-
"nock": "^12.0.3",
42+
"nock": "^14.0.0-beta.8",
4443
"node-addon-api": "^4.3.0",
4544
"nyc": "^15.1.0",
4645
"tape": "^5.5.2",

test/proxy-bcrypt.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +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');
9+
const { ProxyAgent } = require('undici');
1010
const fetch = require('node-fetch');
1111
const { rimraf } = require('rimraf');
1212

@@ -44,7 +44,7 @@ test('setup proxy server', (t) => {
4444
proxy.startServer({ port: proxyPort });
4545
process.env.https_proxy = process.env.http_proxy = proxyServer;
4646

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

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

0 commit comments

Comments
 (0)