From b510c354c74b8546598b023c77461fc24c8467f1 Mon Sep 17 00:00:00 2001 From: Christian Bromann Date: Wed, 13 May 2020 15:48:39 +0200 Subject: [PATCH] chore: fetch Firefox from JSON source instead of RegExp (#5864) Fetch Firefox from https://product-details.mozilla.org/1.0/firefox_versions.json. Fixes #5742. --- install.js | 25 +++++++++++-------------- src/BrowserFetcher.ts | 8 ++++---- test/launcher.spec.js | 4 ++-- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/install.js b/install.js index 61d0025a..7398398f 100644 --- a/install.js +++ b/install.js @@ -26,6 +26,8 @@ const compileTypeScriptIfRequired = require('./typescript-if-required'); +const firefoxVersions = + 'https://product-details.mozilla.org/1.0/firefox_versions.json'; const supportedProducts = { chrome: 'Chromium', firefox: 'Firefox Nightly', @@ -160,27 +162,22 @@ async function download() { let data = ''; logPolitely(`Requesting latest Firefox Nightly version from ${host}`); https - .get(host + '/', (r) => { + .get(firefoxVersions, (r) => { if (r.statusCode >= 400) return reject(new Error(`Got status code ${r.statusCode}`)); r.on('data', (chunk) => { data += chunk; }); - r.on('end', parseVersion); + r.on('end', () => { + try { + const versions = JSON.parse(data); + return resolve(versions.FIREFOX_NIGHTLY); + } catch { + return reject(new Error('Firefox version not found')); + } + }); }) .on('error', reject); - - function parseVersion() { - const regex = /firefox\-(?\d\d)\..*/gm; - let result = 0; - let match; - while ((match = regex.exec(data)) !== null) { - const version = parseInt(match.groups.version, 10); - if (version > result) result = version; - } - if (result) resolve(result.toString()); - else reject(new Error('Firefox version not found')); - } }); return promise; } diff --git a/src/BrowserFetcher.ts b/src/BrowserFetcher.ts index be3363ee..b46fec88 100644 --- a/src/BrowserFetcher.ts +++ b/src/BrowserFetcher.ts @@ -40,10 +40,10 @@ const downloadURLs = { win64: '%s/chromium-browser-snapshots/Win_x64/%d/%s.zip', }, firefox: { - linux: '%s/firefox-%s.0a1.en-US.%s-x86_64.tar.bz2', - mac: '%s/firefox-%s.0a1.en-US.%s.dmg', - win32: '%s/firefox-%s.0a1.en-US.%s.zip', - win64: '%s/firefox-%s.0a1.en-US.%s.zip', + linux: '%s/firefox-%s.en-US.%s-x86_64.tar.bz2', + mac: '%s/firefox-%s.en-US.%s.dmg', + win32: '%s/firefox-%s.en-US.%s.zip', + win64: '%s/firefox-%s.en-US.%s.zip', }, } as const; diff --git a/test/launcher.spec.js b/test/launcher.spec.js index 20e694ad..6e98824e 100644 --- a/test/launcher.spec.js +++ b/test/launcher.spec.js @@ -81,7 +81,7 @@ describe('Launcher specs', function () { host: server.PREFIX, product: 'firefox', }); - const expectedVersion = '75'; + const expectedVersion = '75.0a1'; let revisionInfo = browserFetcher.revisionInfo(expectedVersion); server.setRoute( revisionInfo.url.substring(server.PREFIX.length), @@ -89,7 +89,7 @@ describe('Launcher specs', function () { server.serveFile( req, res, - `/firefox-${expectedVersion}.0a1.en-US.linux-x86_64.tar.bz2` + `/firefox-${expectedVersion}.en-US.linux-x86_64.tar.bz2` ); } );