Skip to content

Commit

Permalink
chore: replace node-fetch and https-proxy-agent with undici
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Sep 9, 2024
1 parent 12ceecb commit 7e1c33f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 37 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
{
"checkLoops": false
}
]
],
"n/no-unsupported-features/node-builtins": ["error", {
"allowExperimental": true
}]
}
}
6 changes: 2 additions & 4 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ exports.usage = 'Attempts to install pre-built binary for module';
const fs = require('fs');
const path = require('path');
const log = require('npmlog');
const { ProxyAgent } = require('undici');
const existsAsync = fs.exists || path.exists;
const versioning = require('./util/versioning.js');
const napi = require('./util/napi.js');
const makeDir = require('make-dir');
// for fetching binaries
const fetch = require('node-fetch');
const tar = require('tar');

let npgVersion = 'unknown';
Expand Down Expand Up @@ -56,12 +55,11 @@ function place_binary(uri, targetDir, opts, callback) {
process.env.npm_config_proxy;
let agent;
if (proxyUrl) {
const ProxyAgent = require('https-proxy-agent');
agent = new ProxyAgent(proxyUrl);
log.http('download', 'proxy agent configured using: "%s"', proxyUrl);
}

fetch(sanitized, { agent })
fetch(sanitized, { dispatcher: agent })
.then((res) => {
if (!res.ok) {
throw new Error(`response status ${res.status} ${res.statusText} on ${sanitized}`);
Expand Down
69 changes: 41 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
"detect-libc": "^2.0.0",
"https-proxy-agent": "^5.0.0",
"make-dir": "^3.1.0",
"node-fetch": "^2.6.7",
"nopt": "^7.2.1",
"npmlog": "^7.0.1",
"semver": "^7.5.3",
"tar": "^7.4.0"
"tar": "^7.4.0",
"undici": "^6.19.8"
},
"devDependencies": {
"@mapbox/cloudfriend": "^5.1.0",
Expand Down
4 changes: 2 additions & 2 deletions test/proxy-bcrypt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { createUnzip } = require('zlib');
const os = require('os');

const tar = require('tar-fs');
const Agent = require('https-proxy-agent');
const { ProxyAgent } = require('undici');
const fetch = require('node-fetch');

Check failure on line 10 in test/proxy-bcrypt.test.js

View workflow job for this annotation

GitHub Actions / ci (18.x, macos-latest)

Can't resolve 'node-fetch' in '/Users/runner/work/node-pre-gyp/node-pre-gyp/test'

Check failure on line 10 in test/proxy-bcrypt.test.js

View workflow job for this annotation

GitHub Actions / ci (18.x, ubuntu-latest)

Can't resolve 'node-fetch' in '/home/runner/work/node-pre-gyp/node-pre-gyp/test'

Check failure on line 10 in test/proxy-bcrypt.test.js

View workflow job for this annotation

GitHub Actions / ci (18.x, windows-latest)

Can't resolve 'node-fetch' in 'D:\a\node-pre-gyp\node-pre-gyp\test'

Check failure on line 10 in test/proxy-bcrypt.test.js

View workflow job for this annotation

GitHub Actions / ci (20.x, macos-latest)

Can't resolve 'node-fetch' in '/Users/runner/work/node-pre-gyp/node-pre-gyp/test'

Check failure on line 10 in test/proxy-bcrypt.test.js

View workflow job for this annotation

GitHub Actions / ci (20.x, ubuntu-latest)

Can't resolve 'node-fetch' in '/home/runner/work/node-pre-gyp/node-pre-gyp/test'

Check failure on line 10 in test/proxy-bcrypt.test.js

View workflow job for this annotation

GitHub Actions / ci (20.x, windows-latest)

Can't resolve 'node-fetch' in 'D:\a\node-pre-gyp\node-pre-gyp\test'

Check failure on line 10 in test/proxy-bcrypt.test.js

View workflow job for this annotation

GitHub Actions / ci (22.x, macos-latest)

Can't resolve 'node-fetch' in '/Users/runner/work/node-pre-gyp/node-pre-gyp/test'

Check failure on line 10 in test/proxy-bcrypt.test.js

View workflow job for this annotation

GitHub Actions / ci (22.x, ubuntu-latest)

Can't resolve 'node-fetch' in '/home/runner/work/node-pre-gyp/node-pre-gyp/test'

Check failure on line 10 in test/proxy-bcrypt.test.js

View workflow job for this annotation

GitHub Actions / ci (22.x, windows-latest)

Can't resolve 'node-fetch' in 'D:\a\node-pre-gyp\node-pre-gyp\test'
const { rimraf } = require('rimraf');

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

options.agent = new Agent(proxyServer);
options.dispatcher = new ProxyAgent(proxyServer);

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

0 comments on commit 7e1c33f

Please sign in to comment.