Skip to content

Commit 49a3181

Browse files
maleptMarshallOfSound
authored andcommitted
feat: add initializeProxy helper for downstream packages (#118)
* feat: add initializeProxy helper for downstream packages * Fix typo * Auto-initialize proxy support if an environment variable is set * Import as well as export
1 parent 72c3083 commit 49a3181

File tree

5 files changed

+160
-2
lines changed

5 files changed

+160
-2
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,12 @@ locations are:
8585
By default, the module uses [`got`](https://github.com/sindresorhus/got) as the
8686
downloader. As a result, you can use the same [options](https://github.com/sindresorhus/got#options)
8787
via `downloadOptions`.
88+
89+
### Proxies
90+
91+
Downstream packages should utilize the `initializeProxy` function to add HTTP(S) proxy support. A
92+
different proxy module is used, depending on the version of Node in use, and as such, there are
93+
slightly different ways to set the proxy environment variables. For Node 10 and above,
94+
[`global-agent`](https://github.com/gajus/global-agent#environment-variables) is used. Otherwise,
95+
[`global-tunnel-ng`](https://github.com/np-maintain/global-tunnel#auto-config) is used. Refer to the
96+
appropriate linked module to determine how to configure proxy support.

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,9 @@
6666
"get",
6767
"artifact",
6868
"release"
69-
]
69+
],
70+
"optionalDependencies": {
71+
"global-agent": "^2.0.2",
72+
"global-tunnel-ng": "^2.7.1"
73+
}
7074
}

src/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from './types';
1010
import { Cache } from './Cache';
1111
import { getDownloaderForSystem } from './downloader-resolver';
12+
import { initializeProxy } from './proxy';
1213
import {
1314
withTempDirectory,
1415
normalizeVersion,
@@ -18,11 +19,16 @@ import {
1819
} from './utils';
1920

2021
export { getHostArch } from './utils';
22+
export { initializeProxy } from './proxy';
2123
export * from './types';
2224

2325
const d = debug('@electron/get:index');
2426
const sumchecker: typeof import('sumchecker').default = require('sumchecker');
2527

28+
if (process.env.ELECTRON_GET_USE_PROXY) {
29+
initializeProxy();
30+
}
31+
2632
/**
2733
* Downloads a specific version of Electron and returns an absolute path to a
2834
* ZIP file.

src/proxy.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as debug from 'debug';
2+
3+
const d = debug('@electron/get:proxy');
4+
5+
/**
6+
* Initializes a third-party proxy module for HTTP(S) requests.
7+
*/
8+
export function initializeProxy() {
9+
try {
10+
// Code originally from https://github.com/yeoman/yo/blob/b2eea87e/lib/cli.js#L19-L28
11+
const MAJOR_NODEJS_VERSION = parseInt(process.version.slice(1).split('.')[0], 10);
12+
13+
if (MAJOR_NODEJS_VERSION >= 10) {
14+
// `global-agent` works with Node.js v10 and above.
15+
require('global-agent').bootstrap();
16+
} else {
17+
// `global-tunnel-ng` works with Node.js v10 and below.
18+
require('global-tunnel-ng').initialize();
19+
}
20+
} catch (e) {
21+
d('Could not load either proxy modules, built-in proxy support not available:', e);
22+
}
23+
}

yarn.lock

+117-1
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,11 @@ bluebird@^3.5.0, bluebird@^3.5.1, bluebird@^3.5.3:
10491049
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.4.tgz#d6cc661595de30d5b3af5fcedd3c0b3ef6ec5714"
10501050
integrity sha512-FG+nFEZChJrbQ9tIccIfZJBz3J7mLrAhxakAbnrJWn8d7aKOC+LWifa0G+p4ZqKp4y13T7juYvdhq9NzKdsrjw==
10511051

1052+
boolean@^1.0.0:
1053+
version "1.0.0"
1054+
resolved "https://registry.yarnpkg.com/boolean/-/boolean-1.0.0.tgz#45764b4aac187a050995b0a33d7579b6759f0dfd"
1055+
integrity sha512-IB1lgIywn37N9Aff8CciCblVpMUflgL42vyxPUH0IvaDdIi/QwBHKv1lq/HOkATHCfa7c4MbMYJ7Bo7hGuoI+w==
1056+
10521057
bottleneck@^2.0.1:
10531058
version "2.18.1"
10541059
resolved "https://registry.yarnpkg.com/bottleneck/-/bottleneck-2.18.1.tgz#cf7c494d90283ecbe896baa46a1397ae8b3c19d7"
@@ -1501,7 +1506,7 @@ concat-stream@^1.5.0:
15011506
readable-stream "^2.2.2"
15021507
typedarray "^0.0.6"
15031508

1504-
config-chain@^1.1.12:
1509+
config-chain@^1.1.11, config-chain@^1.1.12:
15051510
version "1.1.12"
15061511
resolved "https://registry.yarnpkg.com/config-chain/-/config-chain-1.1.12.tgz#0fde8d091200eb5e808caf25fe618c02f48e4efa"
15071512
integrity sha512-a1eOIcu8+7lUInge4Rpf/n4Krkf3Dd9lqhljRzII1/Zno/kRtUWnznPO3jOKBmTEktkt3fkxisUcivoj0ebzoA==
@@ -1595,6 +1600,11 @@ copy-descriptor@^0.1.0:
15951600
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
15961601
integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=
15971602

1603+
core-js@^3.2.1:
1604+
version "3.2.1"
1605+
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.2.1.tgz#cd41f38534da6cc59f7db050fe67307de9868b09"
1606+
integrity sha512-Qa5XSVefSVPRxy2XfUC13WbvqkxhkwB3ve+pgCQveNgYzbM/UxZeu1dcOX/xr4UmfUd+muuvsaxilQzCyUurMw==
1607+
15981608
[email protected], core-util-is@~1.0.0:
15991609
version "1.0.2"
16001610
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
@@ -1853,6 +1863,11 @@ detect-newline@^2.1.0:
18531863
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-2.1.0.tgz#f41f1c10be4b00e87b5f13da680759f2c5bfd3e2"
18541864
integrity sha1-9B8cEL5LAOh7XxPaaAdZ8sW/0+I=
18551865

1866+
detect-node@^2.0.4:
1867+
version "2.0.4"
1868+
resolved "https://registry.yarnpkg.com/detect-node/-/detect-node-2.0.4.tgz#014ee8f8f669c5c58023da64b8179c083a28c46c"
1869+
integrity sha512-ZIzRpLJrOj7jjP2miAtgqIfmzbxa4ZOr5jJc601zklsfEx9oTzmmj2nVpIPRpNlRTIh8lc1kyViIY7BWSGNmKw==
1870+
18561871
dezalgo@^1.0.0, dezalgo@~1.0.3:
18571872
version "1.0.3"
18581873
resolved "https://registry.yarnpkg.com/dezalgo/-/dezalgo-1.0.3.tgz#7f742de066fc748bc8db820569dddce49bf0d456"
@@ -1949,6 +1964,11 @@ emoji-regex@^7.0.1:
19491964
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156"
19501965
integrity sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==
19511966

1967+
encodeurl@^1.0.2:
1968+
version "1.0.2"
1969+
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59"
1970+
integrity sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=
1971+
19521972
encoding@^0.1.11:
19531973
version "0.1.12"
19541974
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
@@ -2016,6 +2036,11 @@ es-to-primitive@^1.2.0:
20162036
is-date-object "^1.0.1"
20172037
is-symbol "^1.0.2"
20182038

2039+
es6-error@^4.1.1:
2040+
version "4.1.1"
2041+
resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.1.1.tgz#9e3af407459deed47e9a91f9b885a84eb05c561d"
2042+
integrity sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==
2043+
20192044
es6-promise@^4.0.3:
20202045
version "4.2.6"
20212046
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.6.tgz#b685edd8258886365ea62b57d30de28fadcd974f"
@@ -2033,6 +2058,11 @@ escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.4, escape-string-regexp@^
20332058
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
20342059
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
20352060

2061+
escape-string-regexp@^2.0.0:
2062+
version "2.0.0"
2063+
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz#a30304e99daa32e23b2fd20f51babd07cffca344"
2064+
integrity sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==
2065+
20362066
escodegen@^1.9.1:
20372067
version "1.11.1"
20382068
resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.11.1.tgz#c485ff8d6b4cdb89e27f4a856e91f118401ca510"
@@ -2594,18 +2624,50 @@ glob@^7.0.3, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3:
25942624
once "^1.3.0"
25952625
path-is-absolute "^1.0.0"
25962626

2627+
global-agent@^2.0.2:
2628+
version "2.0.2"
2629+
resolved "https://registry.yarnpkg.com/global-agent/-/global-agent-2.0.2.tgz#4c09f89dc3aef78e9304bcd5b42e8d4a5048daab"
2630+
integrity sha512-mQLICTW+QGJPuEI8WvEjdyPCcEnx5OqmJH2ADGtv9NknBfUsTnUsV9NeKfrjkwauT2zrSGQqDrS49f86kvnXoA==
2631+
dependencies:
2632+
boolean "^1.0.0"
2633+
core-js "^3.2.1"
2634+
es6-error "^4.1.1"
2635+
matcher "^2.0.0"
2636+
roarr "^2.14.1"
2637+
semver "^6.3.0"
2638+
serialize-error "^4.1.0"
2639+
25972640
global-dirs@^0.1.0:
25982641
version "0.1.1"
25992642
resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-0.1.1.tgz#b319c0dd4607f353f3be9cca4c72fc148c49f445"
26002643
integrity sha1-sxnA3UYH81PzvpzKTHL8FIxJ9EU=
26012644
dependencies:
26022645
ini "^1.3.4"
26032646

2647+
global-tunnel-ng@^2.7.1:
2648+
version "2.7.1"
2649+
resolved "https://registry.yarnpkg.com/global-tunnel-ng/-/global-tunnel-ng-2.7.1.tgz#d03b5102dfde3a69914f5ee7d86761ca35d57d8f"
2650+
integrity sha512-4s+DyciWBV0eK148wqXxcmVAbFVPqtc3sEtUE/GTQfuU80rySLcMhUmHKSHI7/LDj8q0gDYI1lIhRRB7ieRAqg==
2651+
dependencies:
2652+
encodeurl "^1.0.2"
2653+
lodash "^4.17.10"
2654+
npm-conf "^1.1.3"
2655+
tunnel "^0.0.6"
2656+
26042657
globals@^11.1.0:
26052658
version "11.11.0"
26062659
resolved "https://registry.yarnpkg.com/globals/-/globals-11.11.0.tgz#dcf93757fa2de5486fbeed7118538adf789e9c2e"
26072660
integrity sha512-WHq43gS+6ufNOEqlrDBxVEbb8ntfXrfAUU2ZOpCxrBdGKW3gyv8mCxAfIBD0DroPKGrJ2eSsXsLtY9MPntsyTw==
26082661

2662+
globalthis@^1.0.0:
2663+
version "1.0.0"
2664+
resolved "https://registry.yarnpkg.com/globalthis/-/globalthis-1.0.0.tgz#c5fb98213a9b4595f59cf3e7074f141b4169daae"
2665+
integrity sha512-vcCAZTJ3r5Qcu5l8/2oyVdoFwxKgfYnMTR2vwWeux/NAVZK3PwcMaWkdUIn4GJbmKuRK7xcvDsLuK+CKcXyodg==
2666+
dependencies:
2667+
define-properties "^1.1.2"
2668+
function-bind "^1.1.1"
2669+
object-keys "^1.0.12"
2670+
26092671
globby@^6.1.0:
26102672
version "6.1.0"
26112673
resolved "https://registry.yarnpkg.com/globby/-/globby-6.1.0.tgz#f5a6d70e8395e21c858fb0489d64df02424d506c"
@@ -4419,6 +4481,13 @@ matcher@^1.0.0:
44194481
dependencies:
44204482
escape-string-regexp "^1.0.4"
44214483

4484+
matcher@^2.0.0:
4485+
version "2.0.0"
4486+
resolved "https://registry.yarnpkg.com/matcher/-/matcher-2.0.0.tgz#85fe38d97670dbd2a46590cf099401e2ffb4755c"
4487+
integrity sha512-nlmfSlgHBFx36j/Pl/KQPbIaqE8Zf0TqmSMjsuddHDg6PMSVgmyW9HpkLs0o0M1n2GIZ/S2BZBLIww/xjhiGng==
4488+
dependencies:
4489+
escape-string-regexp "^2.0.0"
4490+
44224491
meant@~1.0.1:
44234492
version "1.0.1"
44244493
resolved "https://registry.yarnpkg.com/meant/-/meant-1.0.1.tgz#66044fea2f23230ec806fb515efea29c44d2115d"
@@ -4840,6 +4909,14 @@ npm-cache-filename@~1.0.2:
48404909
resolved "https://registry.yarnpkg.com/npm-cache-filename/-/npm-cache-filename-1.0.2.tgz#ded306c5b0bfc870a9e9faf823bc5f283e05ae11"
48414910
integrity sha1-3tMGxbC/yHCp6fr4I7xfKD4FrhE=
48424911

4912+
npm-conf@^1.1.3:
4913+
version "1.1.3"
4914+
resolved "https://registry.yarnpkg.com/npm-conf/-/npm-conf-1.1.3.tgz#256cc47bd0e218c259c4e9550bf413bc2192aff9"
4915+
integrity sha512-Yic4bZHJOt9RCFbRP3GgpqhScOY4HH3V2P8yBj6CeYq118Qr+BLXqT2JvpJ00mryLESpgOxf5XlFv4ZjXxLScw==
4916+
dependencies:
4917+
config-chain "^1.1.11"
4918+
pify "^3.0.0"
4919+
48434920
npm-install-checks@~3.0.0:
48444921
version "3.0.0"
48454922
resolved "https://registry.yarnpkg.com/npm-install-checks/-/npm-install-checks-3.0.0.tgz#d4aecdfd51a53e3723b7b2f93b2ee28e307bc0d7"
@@ -6055,6 +6132,18 @@ rimraf@2, rimraf@^2.2.8, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.
60556132
dependencies:
60566133
glob "^7.1.3"
60576134

6135+
roarr@^2.14.1:
6136+
version "2.14.1"
6137+
resolved "https://registry.yarnpkg.com/roarr/-/roarr-2.14.1.tgz#812b51c352debbeda1c0ae984aeaf396e0abf421"
6138+
integrity sha512-Fhm9shQ8JhpjFnOT7bgxKR7Xcg1Tq+0/Tdy+bloB4sUxxAib4MZDMJ6AjUBRE+798l2MnhhF2JTqbqx1+/kRyQ==
6139+
dependencies:
6140+
boolean "^1.0.0"
6141+
detect-node "^2.0.4"
6142+
globalthis "^1.0.0"
6143+
json-stringify-safe "^5.0.1"
6144+
semver-compare "^1.0.0"
6145+
sprintf-js "^1.1.2"
6146+
60586147
rsvp@^4.8.4:
60596148
version "4.8.4"
60606149
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-4.8.4.tgz#b50e6b34583f3dd89329a2f23a8a2be072845911"
@@ -6182,11 +6271,23 @@ semver@^6.0.0:
61826271
resolved "https://registry.yarnpkg.com/semver/-/semver-6.1.0.tgz#e95dc415d45ecf03f2f9f83b264a6b11f49c0cca"
61836272
integrity sha512-kCqEOOHoBcFs/2Ccuk4Xarm/KiWRSLEX9CAZF8xkJ6ZPlIoTZ8V5f7J16vYLJqDbR7KrxTJpR2lqjIEm2Qx9cQ==
61846273

6274+
semver@^6.3.0:
6275+
version "6.3.0"
6276+
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
6277+
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
6278+
61856279
semver@~5.3.0:
61866280
version "5.3.0"
61876281
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
61886282
integrity sha1-myzl094C0XxgEq0yaqa00M9U+U8=
61896283

6284+
serialize-error@^4.1.0:
6285+
version "4.1.0"
6286+
resolved "https://registry.yarnpkg.com/serialize-error/-/serialize-error-4.1.0.tgz#63e1e33ede20bcd89d9f0528ea4c15fbf0f2b78a"
6287+
integrity sha512-5j9GgyGsP9vV9Uj1S0lDCvlsd+gc2LEPVK7HHHte7IyPwOD4lVQFeaX143gx3U5AnoCi+wbcb3mvaxVysjpxEw==
6288+
dependencies:
6289+
type-fest "^0.3.0"
6290+
61906291
set-blocking@^2.0.0, set-blocking@~2.0.0:
61916292
version "2.0.0"
61926293
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
@@ -6466,6 +6567,11 @@ split@^1.0.0:
64666567
dependencies:
64676568
through "2"
64686569

6570+
sprintf-js@^1.1.2:
6571+
version "1.1.2"
6572+
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.1.2.tgz#da1765262bf8c0f571749f2ad6c26300207ae673"
6573+
integrity sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==
6574+
64696575
sprintf-js@~1.0.2:
64706576
version "1.0.3"
64716577
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
@@ -6935,6 +7041,11 @@ tunnel-agent@^0.6.0:
69357041
dependencies:
69367042
safe-buffer "^5.0.1"
69377043

7044+
tunnel@^0.0.6:
7045+
version "0.0.6"
7046+
resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c"
7047+
integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==
7048+
69387049
tweetnacl@^0.14.3, tweetnacl@~0.14.0:
69397050
version "0.14.5"
69407051
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
@@ -6947,6 +7058,11 @@ type-check@~0.3.2:
69477058
dependencies:
69487059
prelude-ls "~1.1.2"
69497060

7061+
type-fest@^0.3.0:
7062+
version "0.3.1"
7063+
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.3.1.tgz#63d00d204e059474fe5e1b7c011112bbd1dc29e1"
7064+
integrity sha512-cUGJnCdr4STbePCgqNFbpVNCepa+kAVohJs1sLhxzdH+gnEoOd8VhbYa7pD3zZYGiURWM2xzEII3fQcRizDkYQ==
7065+
69507066
type-fest@^0.4.1:
69517067
version "0.4.1"
69527068
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.4.1.tgz#8bdf77743385d8a4f13ba95f610f5ccd68c728f8"

0 commit comments

Comments
 (0)