Skip to content

Commit

Permalink
chore: fetch Firefox from JSON source instead of RegExp (#5864)
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed May 13, 2020
1 parent 69c38fc commit b510c35
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
25 changes: 11 additions & 14 deletions install.js
Expand Up @@ -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',
Expand Down Expand Up @@ -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\-(?<version>\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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/BrowserFetcher.ts
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions test/launcher.spec.js
Expand Up @@ -81,15 +81,15 @@ 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),
(req, res) => {
server.serveFile(
req,
res,
`/firefox-${expectedVersion}.0a1.en-US.linux-x86_64.tar.bz2`
`/firefox-${expectedVersion}.en-US.linux-x86_64.tar.bz2`
);
}
);
Expand Down

0 comments on commit b510c35

Please sign in to comment.