Skip to content

Commit 0c478ad

Browse files
authored
chore: use node-fetch-native support for proxy env vars (#3483)
1 parent 6d751ce commit 0c478ad

File tree

4 files changed

+3
-134
lines changed

4 files changed

+3
-134
lines changed

dist/index.js

+1-121
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,6 @@ const core_1 = __nccwpck_require__(767);
16161616
const plugin_paginate_rest_1 = __nccwpck_require__(3779);
16171617
const plugin_rest_endpoint_methods_1 = __nccwpck_require__(9210);
16181618
const plugin_throttling_1 = __nccwpck_require__(6856);
1619-
const proxy_from_env_1 = __nccwpck_require__(7777);
16201619
const proxy_1 = __nccwpck_require__(3459);
16211620
exports.Octokit = core_1.Octokit.plugin(plugin_paginate_rest_1.paginateRest, plugin_rest_endpoint_methods_1.restEndpointMethods, plugin_throttling_1.throttling, autoProxyAgent);
16221621
exports.throttleOptions = {
@@ -1636,10 +1635,7 @@ exports.throttleOptions = {
16361635
// Octokit plugin to support the standard environment variables http_proxy, https_proxy and no_proxy
16371636
function autoProxyAgent(octokit) {
16381637
octokit.hook.before('request', options => {
1639-
const proxy = (0, proxy_from_env_1.getProxyForUrl)(options.baseUrl);
1640-
if (proxy) {
1641-
options.request.fetch = (0, proxy_1.createFetch)(proxy);
1642-
}
1638+
options.request.fetch = proxy_1.fetch;
16431639
});
16441640
}
16451641

@@ -28666,122 +28662,6 @@ function copyFile(srcFile, destFile, force) {
2866628662
})));
2866728663

2866828664

28669-
/***/ }),
28670-
28671-
/***/ 7777:
28672-
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
28673-
28674-
"use strict";
28675-
28676-
28677-
var parseUrl = (__nccwpck_require__(7016).parse);
28678-
28679-
var DEFAULT_PORTS = {
28680-
ftp: 21,
28681-
gopher: 70,
28682-
http: 80,
28683-
https: 443,
28684-
ws: 80,
28685-
wss: 443,
28686-
};
28687-
28688-
var stringEndsWith = String.prototype.endsWith || function(s) {
28689-
return s.length <= this.length &&
28690-
this.indexOf(s, this.length - s.length) !== -1;
28691-
};
28692-
28693-
/**
28694-
* @param {string|object} url - The URL, or the result from url.parse.
28695-
* @return {string} The URL of the proxy that should handle the request to the
28696-
* given URL. If no proxy is set, this will be an empty string.
28697-
*/
28698-
function getProxyForUrl(url) {
28699-
var parsedUrl = typeof url === 'string' ? parseUrl(url) : url || {};
28700-
var proto = parsedUrl.protocol;
28701-
var hostname = parsedUrl.host;
28702-
var port = parsedUrl.port;
28703-
if (typeof hostname !== 'string' || !hostname || typeof proto !== 'string') {
28704-
return ''; // Don't proxy URLs without a valid scheme or host.
28705-
}
28706-
28707-
proto = proto.split(':', 1)[0];
28708-
// Stripping ports in this way instead of using parsedUrl.hostname to make
28709-
// sure that the brackets around IPv6 addresses are kept.
28710-
hostname = hostname.replace(/:\d*$/, '');
28711-
port = parseInt(port) || DEFAULT_PORTS[proto] || 0;
28712-
if (!shouldProxy(hostname, port)) {
28713-
return ''; // Don't proxy URLs that match NO_PROXY.
28714-
}
28715-
28716-
var proxy =
28717-
getEnv('npm_config_' + proto + '_proxy') ||
28718-
getEnv(proto + '_proxy') ||
28719-
getEnv('npm_config_proxy') ||
28720-
getEnv('all_proxy');
28721-
if (proxy && proxy.indexOf('://') === -1) {
28722-
// Missing scheme in proxy, default to the requested URL's scheme.
28723-
proxy = proto + '://' + proxy;
28724-
}
28725-
return proxy;
28726-
}
28727-
28728-
/**
28729-
* Determines whether a given URL should be proxied.
28730-
*
28731-
* @param {string} hostname - The host name of the URL.
28732-
* @param {number} port - The effective port of the URL.
28733-
* @returns {boolean} Whether the given URL should be proxied.
28734-
* @private
28735-
*/
28736-
function shouldProxy(hostname, port) {
28737-
var NO_PROXY =
28738-
(getEnv('npm_config_no_proxy') || getEnv('no_proxy')).toLowerCase();
28739-
if (!NO_PROXY) {
28740-
return true; // Always proxy if NO_PROXY is not set.
28741-
}
28742-
if (NO_PROXY === '*') {
28743-
return false; // Never proxy if wildcard is set.
28744-
}
28745-
28746-
return NO_PROXY.split(/[,\s]/).every(function(proxy) {
28747-
if (!proxy) {
28748-
return true; // Skip zero-length hosts.
28749-
}
28750-
var parsedProxy = proxy.match(/^(.+):(\d+)$/);
28751-
var parsedProxyHostname = parsedProxy ? parsedProxy[1] : proxy;
28752-
var parsedProxyPort = parsedProxy ? parseInt(parsedProxy[2]) : 0;
28753-
if (parsedProxyPort && parsedProxyPort !== port) {
28754-
return true; // Skip if ports don't match.
28755-
}
28756-
28757-
if (!/^[.*]/.test(parsedProxyHostname)) {
28758-
// No wildcards, so stop proxying if there is an exact match.
28759-
return hostname !== parsedProxyHostname;
28760-
}
28761-
28762-
if (parsedProxyHostname.charAt(0) === '*') {
28763-
// Remove leading wildcard.
28764-
parsedProxyHostname = parsedProxyHostname.slice(1);
28765-
}
28766-
// Stop proxying if the hostname ends with the no_proxy host.
28767-
return !stringEndsWith.call(hostname, parsedProxyHostname);
28768-
});
28769-
}
28770-
28771-
/**
28772-
* Get the value for an environment variable.
28773-
*
28774-
* @param {string} key - The name of the environment variable.
28775-
* @return {string} The value of the environment variable.
28776-
* @private
28777-
*/
28778-
function getEnv(key) {
28779-
return process.env[key.toLowerCase()] || process.env[key.toUpperCase()] || '';
28780-
}
28781-
28782-
exports.getProxyForUrl = getProxyForUrl;
28783-
28784-
2878528665
/***/ }),
2878628666

2878728667
/***/ 770:

package-lock.json

-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"@octokit/plugin-throttling": "^9.3.2",
3838
"node-fetch-native": "^1.6.4",
3939
"p-limit": "^6.1.0",
40-
"proxy-from-env": "^1.1.0",
4140
"uuid": "^9.0.1"
4241
},
4342
"devDependencies": {

src/octokit-client.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {Octokit as OctokitCore} from '@octokit/core'
33
import {paginateRest} from '@octokit/plugin-paginate-rest'
44
import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods'
55
import {throttling} from '@octokit/plugin-throttling'
6-
import {getProxyForUrl} from 'proxy-from-env'
7-
import {createFetch} from 'node-fetch-native/proxy'
6+
import {fetch} from 'node-fetch-native/proxy'
87
export {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods'
98
// eslint-disable-next-line import/no-unresolved
109
export {OctokitOptions} from '@octokit/core/dist-types/types'
@@ -36,9 +35,6 @@ export const throttleOptions = {
3635
// Octokit plugin to support the standard environment variables http_proxy, https_proxy and no_proxy
3736
function autoProxyAgent(octokit: OctokitCore) {
3837
octokit.hook.before('request', options => {
39-
const proxy = getProxyForUrl(options.baseUrl)
40-
if (proxy) {
41-
options.request.fetch = createFetch(proxy)
42-
}
38+
options.request.fetch = fetch
4339
})
4440
}

0 commit comments

Comments
 (0)