Skip to content

Commit 57a1aca

Browse files
(fix): pull latest release version from new endpoint (#346)
1 parent 61bb323 commit 57a1aca

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os from 'node:os'
22

3-
export const MOZ_CENTRAL_CARGO_TOML = 'https://hg.mozilla.org/mozilla-central/raw-file/tip/testing/geckodriver/Cargo.toml'
3+
export const GECKODRIVER_RELEASES = 'https://api.github.com/repos/mozilla/geckodriver/releases/latest'
44
export const BASE_CDN_URL = process.env.GECKODRIVER_CDNURL || process.env.npm_config_geckodriver_cdnurl || 'https://github.com/mozilla/geckodriver/releases/download'
55
// e.g. https://github.com/mozilla/geckodriver/releases/download/v0.33.0/geckodriver-v0.33.0-macos-aarch64.tar.gz
66
export const GECKODRIVER_DOWNLOAD_PATH = `${BASE_CDN_URL}/v%s/geckodriver-v%s-%s%s%s`

src/install.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { HttpsProxyAgent } from 'https-proxy-agent'
1414
import { HttpProxyAgent } from 'http-proxy-agent'
1515
import unzipper, { type Entry } from 'unzipper'
1616

17-
import { BINARY_FILE, MOZ_CENTRAL_CARGO_TOML } from './constants.js'
17+
import { BINARY_FILE, GECKODRIVER_RELEASES } from './constants.js'
1818
import { hasAccess, getDownloadUrl, retryFetch } from './utils.js'
1919

2020
const log = logger('geckodriver')
@@ -40,13 +40,12 @@ export async function download (
4040
* get latest version of Geckodriver
4141
*/
4242
if (!geckodriverVersion) {
43-
const res = await retryFetch(MOZ_CENTRAL_CARGO_TOML, fetchOpts)
44-
const toml = await res.text()
45-
const version = toml.split('\n').find((l) => l.startsWith('version = '))
46-
if (!version) {
47-
throw new Error(`Couldn't find version property in Cargo.toml file: ${toml}`)
43+
const res = await retryFetch(GECKODRIVER_RELEASES, fetchOpts)
44+
const releases = await res.json() as { name: string }
45+
geckodriverVersion = releases.name
46+
if (!geckodriverVersion) {
47+
throw new Error(`Couldn't find version name in releases: ${JSON.stringify(releases)}`)
4848
}
49-
geckodriverVersion = version.split(' = ').pop().slice(1, -1)
5049
log.info(`Detected Geckodriver v${geckodriverVersion} to be latest`)
5150
}
5251

0 commit comments

Comments
 (0)