From fbb370ef35fe590f89fce430aaf7446f6bf145b8 Mon Sep 17 00:00:00 2001
From: Eemeli Aro
Date: Mon, 30 Oct 2023 22:09:16 +0200
Subject: [PATCH] Retry BSL fetch with arch=x64 for Darwin ARM64 systems
---
lib/local.js | 47 +++++++++++++++++++++++++++++++----------------
1 file changed, 31 insertions(+), 16 deletions(-)
diff --git a/lib/local.js b/lib/local.js
index f5fad2d..d49694c 100644
--- a/lib/local.js
+++ b/lib/local.js
@@ -175,28 +175,43 @@ var Tunnel = function Tunnel(key, port, uniqueIdentifier, config, callback) {
});
}
+ function fetchTunnelBinary(retryDarwinArm64) {
+ var file = fs.createWriteStream(localBinary);
+ var isDarwinArm64 = process.platform === 'darwin' && process.arch === 'arm64';
+ var arch = isDarwinArm64 && retryDarwinArm64 ? 'x64' : process.arch;
+ https.get('https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal' + (windows ? '.exe' : '-' + process.platform + '-' + arch),
+ function(response) {
+ if (response.statusCode !== 200) {
+ if (isDarwinArm64 && !retryDarwinArm64) {
+ fetchTunnelBinary(true);
+ } else {
+ var message = 'Got error while downloading binary: ' + response.statusCode + ' ' + response.statusMessage;
+ logger.info(message);
+ throw new Error(message);
+ }
+ } else {
+ response.pipe(file);
+
+ response.on('end', function() {
+ fs.chmodSync(localBinary, 0700);
+ setTimeout(function() {
+ tunnelLauncher();
+ }, 100);
+ }).on('error', function(e) {
+ logger.info('Got error while downloading binary: ' + e.message);
+ throw new Error('Got error while downloading binary: ' + e.message);
+ });
+ }
+ });
+ }
+
verifyTunnelBinary(function (exists) {
if (exists) {
tunnelLauncher();
return;
}
logger.debug('Downloading BrowserStack Local to "%s"', localBinary);
-
- var file = fs.createWriteStream(localBinary);
- https.get('https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal' + (windows ? '.exe' : '-' + process.platform + '-' + process.arch),
- function(response) {
- response.pipe(file);
-
- response.on('end', function() {
- fs.chmodSync(localBinary, 0700);
- setTimeout(function() {
- tunnelLauncher();
- }, 100);
- }).on('error', function(e) {
- logger.info('Got error while downloading binary: ' + e.message);
- throw new Error('Got error while downloading binary: ' + e.message);
- });
- });
+ fetchTunnelBinary(false);
});
return that;