Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const existsAsync = fs.exists || path.exists;
const versioning = require('./util/versioning.js');
const napi = require('./util/napi.js');
// for fetching binaries
const fetch = require('node-fetch');
const { fetch } = require('node-fetch-native');
const { createProxy } = require('node-fetch-native/proxy');
const tar = require('tar');

let npgVersion = 'unknown';
Expand Down Expand Up @@ -53,14 +54,13 @@ function place_binary(uri, targetDir, opts, callback) {
process.env.http_proxy ||
process.env.HTTP_PROXY ||
process.env.npm_config_proxy;
let agent;
let proxy;
if (proxyUrl) {
const { HttpsProxyAgent } = require('https-proxy-agent');
agent = new HttpsProxyAgent(proxyUrl);
proxy = createProxy({ url: proxyUrl });
log.log('download', `proxy agent configured using: "${proxyUrl}"`);
}

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

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"dependencies": {
"consola": "^3.2.3",
"detect-libc": "^2.0.0",
"https-proxy-agent": "^7.0.5",
"node-fetch": "^2.6.7",
"node-fetch-native": "^1.6.4",
"nopt": "^8.0.0",
"semver": "^7.5.3",
"tar": "^7.4.0"
Expand All @@ -39,7 +38,7 @@
"eslint": "^8.57.0",
"eslint-plugin-n": "^17.9.0",
"mock-aws-s3": "^4.0.2",
"nock": "^13.5.4",
"nock": "^14.0.0-beta.19",
"node-addon-api": "^8.1.0",
"nyc": "^17.0.0",
"tape": "^5.5.2",
Expand Down
8 changes: 4 additions & 4 deletions test/proxy-bcrypt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const { createUnzip } = require('zlib');
const os = require('os');

const tar = require('tar-fs');
const { HttpsProxyAgent } = require('https-proxy-agent');
const fetch = require('node-fetch');
const { fetch } = require('node-fetch-native');
const { createProxy } = require('node-fetch-native/proxy');
const { rimraf } = require('rimraf');

const test = require('tape');
Expand All @@ -17,7 +17,7 @@ const proxyPort = 8124;
const proxyServer = `http://localhost:${proxyPort}`;

// options for fetch
const options = {};
let options = {};

// the temporary download directory and file
const downloadDir = `${os.tmpdir()}/npg-download`;
Expand All @@ -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 HttpsProxyAgent(proxyServer);
options = createProxy({ url: proxyServer });

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