Skip to content

Commit 08a5ecf

Browse files
(fix): download raw cargo.yaml to avoid rate limiting
1 parent 9753af8 commit 08a5ecf

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
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 GECKODRIVER_RELEASES = 'https://api.github.com/repos/mozilla/geckodriver/releases/latest'
3+
export const GECKODRIVER_CARGO_YAML = 'https://raw.githubusercontent.com/mozilla/geckodriver/release/Cargo.toml'
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: 7 additions & 6 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, GECKODRIVER_RELEASES } from './constants.js'
17+
import { BINARY_FILE, GECKODRIVER_CARGO_YAML } from './constants.js'
1818
import { hasAccess, getDownloadUrl, retryFetch } from './utils.js'
1919

2020
const log = logger('geckodriver')
@@ -40,12 +40,13 @@ export async function download (
4040
* get latest version of Geckodriver
4141
*/
4242
if (!geckodriverVersion) {
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)}`)
43+
const res = await retryFetch(GECKODRIVER_CARGO_YAML, 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: ${JSON.stringify(toml)}`)
4848
}
49+
geckodriverVersion = version.split(' = ').pop().slice(1, -1)
4950
log.info(`Detected Geckodriver v${geckodriverVersion} to be latest`)
5051
}
5152

0 commit comments

Comments
 (0)