mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: resolve Firefox revisions for the latest keyword (#9708)
This commit is contained in:
parent
e0330d82bd
commit
f1b337e78b
@ -18,6 +18,7 @@ import ProgressBar from 'progress';
|
|||||||
import yargs from 'yargs';
|
import yargs from 'yargs';
|
||||||
import {hideBin} from 'yargs/helpers';
|
import {hideBin} from 'yargs/helpers';
|
||||||
|
|
||||||
|
import {resolveRevision} from './browsers/browsers.js';
|
||||||
import {Browser, BrowserPlatform} from './browsers/types.js';
|
import {Browser, BrowserPlatform} from './browsers/types.js';
|
||||||
import {fetch} from './fetch.js';
|
import {fetch} from './fetch.js';
|
||||||
import {computeExecutablePath, launch} from './launcher.js';
|
import {computeExecutablePath, launch} from './launcher.js';
|
||||||
@ -67,6 +68,10 @@ export class CLI {
|
|||||||
},
|
},
|
||||||
async argv => {
|
async argv => {
|
||||||
const args = argv as unknown as InstallArgs;
|
const args = argv as unknown as InstallArgs;
|
||||||
|
args.browser.revision = await resolveRevision(
|
||||||
|
args.browser.name,
|
||||||
|
args.browser.revision
|
||||||
|
);
|
||||||
await fetch({
|
await fetch({
|
||||||
browser: args.browser.name,
|
browser: args.browser.name,
|
||||||
revision: args.browser.revision,
|
revision: args.browser.revision,
|
||||||
@ -77,6 +82,9 @@ export class CLI {
|
|||||||
args.browser.revision
|
args.browser.revision
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
console.log(
|
||||||
|
`${args.browser.name}@${args.browser.revision} downloaded successfully.`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.option('path', {
|
.option('path', {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
import * as chrome from './chrome.js';
|
import * as chrome from './chrome.js';
|
||||||
import * as firefox from './firefox.js';
|
import * as firefox from './firefox.js';
|
||||||
import {Browser, BrowserPlatform} from './types.js';
|
import {Browser, BrowserPlatform, BrowserTag} from './types.js';
|
||||||
|
|
||||||
export const downloadUrls = {
|
export const downloadUrls = {
|
||||||
[Browser.CHROME]: chrome.resolveDownloadUrl,
|
[Browser.CHROME]: chrome.resolveDownloadUrl,
|
||||||
@ -29,3 +29,18 @@ export const executablePathByBrowser = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export {Browser, BrowserPlatform};
|
export {Browser, BrowserPlatform};
|
||||||
|
|
||||||
|
export async function resolveRevision(
|
||||||
|
browser: Browser,
|
||||||
|
tag: string
|
||||||
|
): Promise<string> {
|
||||||
|
switch (browser) {
|
||||||
|
case Browser.FIREFOX:
|
||||||
|
switch (tag as BrowserTag) {
|
||||||
|
case BrowserTag.LATEST:
|
||||||
|
return await firefox.resolveRevision('FIREFOX_NIGHTLY');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// We assume the tag is the revision if it didn't match any keywords.
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
|
import {httpRequest} from '../httpUtil.js';
|
||||||
|
|
||||||
import {BrowserPlatform} from './types.js';
|
import {BrowserPlatform} from './types.js';
|
||||||
|
|
||||||
function archive(platform: BrowserPlatform, revision: string): string {
|
function archive(platform: BrowserPlatform, revision: string): string {
|
||||||
@ -54,3 +56,35 @@ export function relativeExecutablePath(
|
|||||||
return path.join('firefox', 'firefox.exe');
|
return path.join('firefox', 'firefox.exe');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function resolveRevision(
|
||||||
|
channel: 'FIREFOX_NIGHTLY' = 'FIREFOX_NIGHTLY'
|
||||||
|
): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const request = httpRequest(
|
||||||
|
new URL('https://product-details.mozilla.org/1.0/firefox_versions.json'),
|
||||||
|
'GET',
|
||||||
|
response => {
|
||||||
|
let data = '';
|
||||||
|
if (response.statusCode && response.statusCode >= 400) {
|
||||||
|
return reject(new Error(`Got status code ${response.statusCode}`));
|
||||||
|
}
|
||||||
|
response.on('data', chunk => {
|
||||||
|
data += chunk;
|
||||||
|
});
|
||||||
|
response.on('end', () => {
|
||||||
|
try {
|
||||||
|
const versions = JSON.parse(data);
|
||||||
|
return resolve(versions[channel]);
|
||||||
|
} catch {
|
||||||
|
return reject(new Error('Firefox version not found'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
request.on('error', err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -41,3 +41,7 @@ export const downloadUrls = {
|
|||||||
[Browser.CHROME]: chrome.resolveDownloadUrl,
|
[Browser.CHROME]: chrome.resolveDownloadUrl,
|
||||||
[Browser.FIREFOX]: firefox.resolveDownloadUrl,
|
[Browser.FIREFOX]: firefox.resolveDownloadUrl,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export enum BrowserTag {
|
||||||
|
LATEST = 'latest',
|
||||||
|
}
|
||||||
|
@ -22,7 +22,7 @@ import path from 'path';
|
|||||||
import {CLI} from '../../lib/cjs/CLI.js';
|
import {CLI} from '../../lib/cjs/CLI.js';
|
||||||
|
|
||||||
describe('CLI', function () {
|
describe('CLI', function () {
|
||||||
this.timeout(60000);
|
this.timeout(90000);
|
||||||
|
|
||||||
let tmpDir = '/tmp/puppeteer-browsers-test';
|
let tmpDir = '/tmp/puppeteer-browsers-test';
|
||||||
const testChromeRevision = '1083080';
|
const testChromeRevision = '1083080';
|
||||||
@ -72,4 +72,15 @@ describe('CLI', function () {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should download latest Firefox binaries', async () => {
|
||||||
|
await new CLI(tmpDir).run([
|
||||||
|
'npx',
|
||||||
|
'@puppeteer/browsers',
|
||||||
|
'install',
|
||||||
|
`firefox@latest`,
|
||||||
|
`--path=${tmpDir}`,
|
||||||
|
'--platform=linux',
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user