Skip to content

Commit ec29033

Browse files
authoredOct 19, 2022
Add ARM64 support (#108)
* Add ARM64 support * Add Tests * Test the tests * Fix test * Fix test * Tests * Remove log
1 parent ec8fdd5 commit ec29033

File tree

5 files changed

+68
-3623
lines changed

5 files changed

+68
-3623
lines changed
 

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Use `GECKODRIVER_SKIP_DOWNLOAD` to skip the download of the geckodriver file.
8585
## Versions
8686

8787
* [npm module version] - [geckodriver version]
88+
* 3.2.0 - geckodriver 0.32.0, arm64 support.
8889
* 3.1.0 - geckodriver 0.31.0
8990
* 3.0.x - geckodriver 0.30.0, refactored logic, dependency updates.
9091
* 2.00.x - geckodriver 0.29.1, support changed to node v12+
@@ -113,6 +114,7 @@ Use `GECKODRIVER_SKIP_DOWNLOAD` to skip the download of the geckodriver file.
113114

114115
## Changelog
115116

117+
* 3.2.0 - geckodriver 0.32.0, arm64 support for Mac, Linux and Windows, added `GECKODRIVER_ARCH` for custom arch downloads.
116118
* 3.1.0 - geckodriver 0.31.0
117119
* 2.0.1 - fixed proxy download behaviour.
118120
* 1.20.0 - geckodriver 27. Requires node 8 and higher. Support `HTTPS_PROXY` env and npm_config_geckodriver_version variables.

‎index.js

+31-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var proxyAgent = require('https-proxy-agent');
1010
var Promise = require('bluebird');
1111

1212
var platform = os.platform();
13-
var arch = os.arch();
13+
var arch = process.env.GECKODRIVER_ARCH || process.env.npm_config_geckodriver_arch || os.arch();
1414

1515
var skipDownload = process.env.GECKODRIVER_SKIP_DOWNLOAD || process.env.npm_config_geckodriver_skip_download;
1616
if (skipDownload === 'true') {
@@ -21,20 +21,29 @@ if (skipDownload === 'true') {
2121
var baseCDNURL = process.env.GECKODRIVER_CDNURL || process.env.npm_config_geckodriver_cdnurl || 'https://github.com/mozilla/geckodriver/releases/download';
2222
var CACHED_ARCHIVE = process.env.GECKODRIVER_FILEPATH ? path.resolve(process.env.GECKODRIVER_FILEPATH) : undefined;
2323

24-
var version = process.env.GECKODRIVER_VERSION || process.env.npm_config_geckodriver_version || '0.30.0';
24+
var version = process.env.GECKODRIVER_VERSION || process.env.npm_config_geckodriver_version || '0.32.0';
2525

2626
// Remove trailing slash if included
2727
baseCDNURL = baseCDNURL.replace(/\/+$/, '');
2828

2929
var baseDownloadUrl = baseCDNURL + '/v' + version + '/geckodriver-v' + version;
3030
var DOWNLOAD_MAC = baseDownloadUrl +'-macos.tar.gz';
31+
var DOWNLOAD_MAC_ARM64 = baseDownloadUrl +'-macos-aarch64.tar.gz';
32+
33+
var DOWNLOAD_LINUX_ARM64 = baseDownloadUrl +'-linux-aarch64.tar.gz';
3134
var DOWNLOAD_LINUX64 = baseDownloadUrl +'-linux64.tar.gz';
3235
var DOWNLOAD_LINUX32 = baseDownloadUrl +'-linux32.tar.gz';
36+
37+
var DOWNLOAD_WIN_ARM64 = baseDownloadUrl +'-win-aarch64.zip';
3338
var DOWNLOAD_WIN32 = baseDownloadUrl +'-win32.zip';
3439
var DOWNLOAD_WIN64 = baseDownloadUrl +'-win64.zip';
3540

3641
// TODO: move this to package.json or something
3742
var downloadUrl = DOWNLOAD_MAC;
43+
if (arch === 'arm64') {
44+
downloadUrl = DOWNLOAD_MAC_ARM64;
45+
}
46+
3847
var outFile = 'geckodriver.tar.gz';
3948
var executable = 'geckodriver';
4049

@@ -45,12 +54,29 @@ if (proxy !== null) {
4554
}
4655

4756
if (platform === 'linux') {
48-
downloadUrl = arch === 'x64' ? DOWNLOAD_LINUX64 : DOWNLOAD_LINUX32;
57+
switch (arch) {
58+
case 'arm64':
59+
downloadUrl = DOWNLOAD_LINUX_ARM64;
60+
break;
61+
case 'x64':
62+
downloadUrl = DOWNLOAD_LINUX64;
63+
break;
64+
default:
65+
downloadUrl = DOWNLOAD_LINUX32;
66+
}
4967
}
5068

5169
if (platform === 'win32') {
52-
// No 32-bits of geckodriver for now
53-
downloadUrl = arch === 'x64' ? DOWNLOAD_WIN64 : DOWNLOAD_WIN32;
70+
switch (arch) {
71+
case 'arm64':
72+
downloadUrl = DOWNLOAD_WIN_ARM64;
73+
break;
74+
case 'x64':
75+
downloadUrl = DOWNLOAD_WIN64;
76+
break;
77+
default:
78+
downloadUrl = DOWNLOAD_WIN32;
79+
}
5480
outFile = 'geckodriver.zip';
5581
executable = 'geckodriver.exe';
5682
}

‎lib/geckodriver.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ process.env.PATH += path.delimiter + path.join(__dirname, '..');
77
exports.path = process.platform === 'win32' ? path.join(__dirname, '..', 'geckodriver.exe') : path.join(__dirname, '..', 'geckodriver');
88

99
// specify the version of geckodriver
10-
exports.version = process.env.GECKODRIVER_VERSION || '0.31.0';
10+
exports.version = process.env.GECKODRIVER_VERSION || '0.32.0';
1111

1212
exports.start = function(args) {
1313
exports.defaultInstance = require('child_process').execFile(exports.path, args);

‎package-lock.json

+12-3,614
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/index.js

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
const test = require('ava');
22
const child_process = require('child_process');
33

4-
test.cb('properly extracts', t => {
4+
5+
test.cb('properly extracts custom arch', t => {
6+
var oldArch = process.env.GECKODRIVER_ARCH;
7+
process.env.GECKODRIVER_ARCH = 'arm64';
8+
// Test ARM64
59
child_process.exec('node index.js', (error, stdout, stderr) => {
610
if (error) {
711
return t.fail(`exec error: ${error}`)
812
}
913
t.assert(stdout.includes('Downloading geckodriver'), stdout);
1014
t.is(stderr, '');
11-
t.end();
15+
process.env.GECKODRIVER_ARCH = oldArch;
16+
var out = child_process.execSync('file -b geckodriver').toString();
17+
t.truthy(/arm64|aarch64|Aarch64/.test(out));
18+
process.env.GECKODRIVER_ARCH = 'x64';
19+
20+
// Test x64
21+
child_process.exec('node index.js', (error, stdout, stderr) => {
22+
if (error) {
23+
return t.fail(`exec error: ${error}`)
24+
}
25+
t.assert(stdout.includes('Downloading geckodriver'), stdout);
26+
t.is(stderr, '');
27+
var out = child_process.execSync('file -b geckodriver').toString();
28+
t.truthy(/x86_64|x86-64/.test(out));
29+
t.end();
30+
});
1231
});
1332
});
1433

1534
test('programmatic usage', t => {
1635
var driver = require('../lib/geckodriver')
17-
t.is(driver.version, '0.31.0')
36+
t.is(driver.version, '0.32.0')
1837
});

0 commit comments

Comments
 (0)
Please sign in to comment.