@@ -65,57 +65,31 @@ function LocalBinary(){
6565 var destBinaryName = ( this . windows ) ? 'BrowserStackLocal.exe' : 'BrowserStackLocal' ;
6666 var binaryPath = path . join ( destParentDir , destBinaryName ) ;
6767
68- var options = url . parse ( this . httpPath ) ;
69- if ( conf . proxyHost && conf . proxyPort ) {
70- options . agent = new HttpsProxyAgent ( {
71- host : conf . proxyHost ,
72- port : conf . proxyPort
73- } ) ;
74- }
75-
76- const osPlatform = os . platform ( ) ;
77- const osVersion = parseInt ( os . release ( ) ) ;
78-
7968 let cmd , opts ;
80-
81- if ( osPlatform . includes ( 'win' ) && osVersion < 10 ) {
82- cmd = 'wget' ;
83- opts = [ ] ;
84- if ( conf . proxyHost && conf . proxyPort ) {
85- opts . push ( '-e' , `https_proxy=${ conf . proxyHost } :${ conf . proxyPort } ` , '--no-check-certificate' ) ;
86- }
87- opts . push ( '-O' , binaryPath , options . href ) ;
88- } else {
89- cmd = 'curl' ;
90- opts = [ '-o' , binaryPath , options . href ] ;
91-
92- if ( conf . proxyHost && conf . proxyPort ) {
93- opts . push ( '--proxy' , `${ conf . proxyHost } :${ conf . proxyPort } ` ) ;
94- }
69+ cmd = 'node' ;
70+ opts = [ path . join ( __dirname , 'download.js' ) , binaryPath , this . httpPath ]
71+ if ( conf . proxyHost && conf . proxyPort ) {
72+ opts . push ( conf . proxyHost , conf . proxyPort ) ;
9573 }
9674
9775 try {
9876 const obj = childProcess . spawnSync ( cmd , opts ) ;
9977 let output ;
10078 if ( obj . stdout . length > 0 ) {
101- output = Buffer . from ( JSON . parse ( JSON . stringify ( obj . stderr ) ) . data ) . toString ( ) ;
102- } else if ( obj . stderr . length > 0 ) {
103- output = Buffer . from ( JSON . parse ( JSON . stringify ( obj . stderr ) ) . data ) . toString ( ) ;
104- }
105- if ( output . includes ( 'failed' ) ) {
106- console . log ( 'failed to download' ) ;
107- return that . retryBinaryDownload ( conf , destParentDir , null , retries , binaryPath ) ;
108- } else {
10979 if ( fs . existsSync ( binaryPath ) ) {
11080 fs . chmodSync ( binaryPath , '0755' ) ;
11181 return binaryPath ;
11282 } else {
11383 console . log ( 'failed to download' ) ;
11484 return that . retryBinaryDownload ( conf , destParentDir , null , retries , binaryPath ) ;
11585 }
86+ } else if ( obj . stderr . length > 0 ) {
87+ output = Buffer . from ( JSON . parse ( JSON . stringify ( obj . stderr ) ) . data ) . toString ( ) ;
88+ console . error ( output )
89+ return that . retryBinaryDownload ( conf , destParentDir , null , retries , binaryPath ) ;
11690 }
11791 } catch ( err ) {
118- console . log ( 'Download failed with error' , err ) ;
92+ console . error ( 'Download failed with error' , err ) ;
11993 return that . retryBinaryDownload ( conf , destParentDir , null , retries , binaryPath ) ;
12094 }
12195 } ;
0 commit comments