1- // must be set before we import 'global-agent/bootstrap'
2- process . env . GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE = '' ;
3- process . env . HTTPS_PROXY =
4- process . env . HTTPS_PROXY ?? process . env . https_proxy ?? '' ;
5- process . env . HTTP_PROXY = process . env . HTTP_PROXY ?? process . env . http_proxy ?? '' ;
6- process . env . NO_PROXY = process . env . NO_PROXY ?? process . env . no_proxy ?? '' ;
7-
8- import 'global-agent/bootstrap' ;
91import * as path from 'path' ;
102import * as os from 'os' ;
113import * as fs from 'fs' ;
124import { spawnSync } from 'child_process' ;
135import * as https from 'https' ;
146import { createHash } from 'crypto' ;
157import * as Sentry from '@sentry/node' ;
8+ import { getProxyForUrl } from 'proxy-from-env' ;
9+
10+ process . env . HTTPS_PROXY =
11+ process . env . HTTPS_PROXY ?? process . env . https_proxy ?? '' ;
12+ process . env . HTTP_PROXY = process . env . HTTP_PROXY ?? process . env . http_proxy ?? '' ;
13+ process . env . NO_PROXY = process . env . NO_PROXY ?? process . env . no_proxy ?? '' ;
1614
1715export const versionFile = path . join ( __dirname , 'generated' , 'version' ) ;
1816export const shasumFile = path . join ( __dirname , 'generated' , 'sha256sums.txt' ) ;
@@ -24,9 +22,9 @@ const binaryDeploymentsFilePath = path.join(
2422export const integrationName = 'TS_BINARY_WRAPPER' ;
2523
2624export class WrapperConfiguration {
27- private version : string ;
28- private binaryName : string ;
29- private expectedSha256sum : string ;
25+ private readonly version : string ;
26+ private readonly binaryName : string ;
27+ private readonly expectedSha256sum : string ;
3028
3129 public constructor (
3230 version : string ,
@@ -257,7 +255,6 @@ export function downloadExecutable(
257255) : Promise < Error | undefined > {
258256 return new Promise < Error | undefined > ( function ( resolve ) {
259257 logErrorWithTimeStamps ( 'Starting download' ) ;
260- const options = new URL ( `${ downloadUrl } ?utm_source=${ integrationName } ` ) ;
261258 const temp = path . join ( __dirname , Date . now ( ) . toString ( ) ) ;
262259 const fileStream = fs . createWriteStream ( temp ) ;
263260 const shasum = createHash ( 'sha256' ) . setEncoding ( 'hex' ) ;
@@ -291,17 +288,35 @@ export function downloadExecutable(
291288 // finally rename the file and change permissions
292289 fs . renameSync ( temp , filename ) ;
293290 fs . chmodSync ( filename , 0o755 ) ;
294- logErrorWithTimeStamps ( 'Downloaded successfull ! ' ) ;
291+ logErrorWithTimeStamps ( 'Downloaded successful ! ' ) ;
295292 }
296293
297294 resolve ( undefined ) ;
298295 } ) ;
299296
297+ const url = new URL ( `${ downloadUrl } ?utm_source=${ integrationName } ` ) ;
298+
300299 logErrorWithTimeStamps (
301- "Downloading from '" + options . toString ( ) + "' to '" + filename + "'" ,
300+ "Downloading from '" + url . toString ( ) + "' to '" + filename + "'" ,
302301 ) ;
303302
304- const req = https . get ( options , ( res ) => {
303+ let agent ;
304+ let proxyUri : string | URL = getProxyForUrl ( url ) ;
305+ if ( proxyUri ) {
306+ logErrorWithTimeStamps ( 'using proxy:' , proxyUri ) ;
307+ proxyUri = new URL ( proxyUri ) ;
308+ agent = new https . Agent ( {
309+ host : proxyUri . hostname ,
310+ port :
311+ parseInt ( proxyUri . port ) ||
312+ ( proxyUri . protocol === 'https:' ? 443 : 80 ) ,
313+ } ) ;
314+ } else {
315+ agent = https . globalAgent ;
316+ logErrorWithTimeStamps ( 'not using proxy' ) ;
317+ }
318+
319+ const req = https . get ( url , { agent } , ( res ) => {
305320 // response events
306321 res . on ( 'error' , cleanupAfterError ) . on ( 'end' , ( ) => {
307322 shasum . end ( ) ;
0 commit comments