Skip to content

Commit

Permalink
(fix): download raw cargo.yaml to avoid rate limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Feb 2, 2024
1 parent 9753af8 commit 08a5ecf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os from 'node:os'

export const GECKODRIVER_RELEASES = 'https://api.github.com/repos/mozilla/geckodriver/releases/latest'
export const GECKODRIVER_CARGO_YAML = 'https://raw.githubusercontent.com/mozilla/geckodriver/release/Cargo.toml'
export const BASE_CDN_URL = process.env.GECKODRIVER_CDNURL || process.env.npm_config_geckodriver_cdnurl || 'https://github.com/mozilla/geckodriver/releases/download'
// e.g. https://github.com/mozilla/geckodriver/releases/download/v0.33.0/geckodriver-v0.33.0-macos-aarch64.tar.gz
export const GECKODRIVER_DOWNLOAD_PATH = `${BASE_CDN_URL}/v%s/geckodriver-v%s-%s%s%s`
Expand Down
13 changes: 7 additions & 6 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { HttpsProxyAgent } from 'https-proxy-agent'
import { HttpProxyAgent } from 'http-proxy-agent'
import unzipper, { type Entry } from 'unzipper'

import { BINARY_FILE, GECKODRIVER_RELEASES } from './constants.js'
import { BINARY_FILE, GECKODRIVER_CARGO_YAML } from './constants.js'
import { hasAccess, getDownloadUrl, retryFetch } from './utils.js'

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

Expand Down

0 comments on commit 08a5ecf

Please sign in to comment.