Skip to content

Commit 33f03e2

Browse files
committed
chore: replace node-fetch and https-proxy-agent with undici
1 parent a68460d commit 33f03e2

File tree

4 files changed

+55
-43
lines changed

4 files changed

+55
-43
lines changed

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: 48 additions & 34 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,14 +24,13 @@
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
"rimraf": "^5.0.5",
3331
"semver": "^7.3.5",
34-
"tar": "^7.4.0"
32+
"tar": "^7.4.0",
33+
"undici": "^6.19.2"
3534
},
3635
"devDependencies": {
3736
"@mapbox/cloudfriend": "^5.1.0",
@@ -41,7 +40,7 @@
4140
"eslint": "^8.57.0",
4241
"eslint-plugin-node": "^11.1.0",
4342
"mock-aws-s3": "^4.0.2",
44-
"nock": "^12.0.3",
43+
"nock": "^14.0.0-beta.7",
4544
"node-addon-api": "^4.3.0",
4645
"nyc": "^15.1.0",
4746
"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)