chore: read browser revisions off browsers.json (#2009)
This commit is contained in:
parent
c866c665f0
commit
d52bd92983
|
|
@ -16,5 +16,5 @@ lib/injected/
|
|||
# root for "playwright-core" package
|
||||
!index.js
|
||||
|
||||
# root for "playwright-core/web"
|
||||
!web.js
|
||||
# browser descriptor
|
||||
!browsers.json
|
||||
|
|
|
|||
|
|
@ -64,4 +64,4 @@ You can check the CDN status:
|
|||
$ ./browser_patches/tools/check_cdn.sh
|
||||
```
|
||||
|
||||
As the builds appear, you can roll to a new browser version in the `./package.json` file.
|
||||
As the builds appear, you can roll to a new browser version in the `./browsers.json` file.
|
||||
|
|
|
|||
16
browsers.json
Normal file
16
browsers.json
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"browsers": [
|
||||
{
|
||||
"name": "chromium",
|
||||
"revision": "760827"
|
||||
},
|
||||
{
|
||||
"name": "firefox",
|
||||
"revision": "1087"
|
||||
},
|
||||
{
|
||||
"name": "webkit",
|
||||
"revision": "1211"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -15,44 +15,55 @@
|
|||
*/
|
||||
|
||||
const path = require('path');
|
||||
const { getFromENV, logPolitely } = require('./lib/helper.js');
|
||||
const { Playwright } = require('./lib/server/playwright.js');
|
||||
const browserFetcher = require('./lib/server/browserFetcher.js');
|
||||
const packageJSON = require('./package.json');
|
||||
|
||||
function resolveBrowser(packagePath, browserName) {
|
||||
const browsersPath = getFromENV('PLAYWRIGHT_BROWSERS_PATH');
|
||||
const baseDir = browsersPath || path.join(packagePath, '.local-browsers');
|
||||
const browserRevision = packageJSON.playwright[`${browserName}_revision`];
|
||||
return { baseDir, browserRevision };
|
||||
function browsersPath(packagePath) {
|
||||
const result = getFromENV('PLAYWRIGHT_BROWSERS_PATH');
|
||||
return result || path.join(packagePath, '.local-browsers');
|
||||
}
|
||||
|
||||
function executablePath(packagePath, browserName) {
|
||||
const { baseDir, browserRevision } = resolveBrowser(packagePath, browserName);
|
||||
return browserFetcher.executablePath(baseDir, browserName, browserRevision);
|
||||
function executablePath(packagePath, browser) {
|
||||
return browserFetcher.executablePath(browsersPath(packagePath), browser.name, browser.revision);
|
||||
}
|
||||
|
||||
function targetDirectory(packagePath, browserName) {
|
||||
const { baseDir, browserRevision } = resolveBrowser(packagePath, browserName);
|
||||
return browserFetcher.targetDirectory(baseDir, browserName, browserRevision);
|
||||
function targetDirectory(packagePath, browser) {
|
||||
return browserFetcher.targetDirectory(browsersPath(packagePath), browser.name, browser.revision);
|
||||
}
|
||||
|
||||
async function downloadBrowserWithProgressBar(packagePath, browserName) {
|
||||
const { baseDir, browserRevision } = resolveBrowser(packagePath, browserName);
|
||||
if (getFromENV('PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD'))
|
||||
return browserFetcher.downloadBrowserWithProgressBar(null);
|
||||
async function downloadBrowsersWithProgressBar(packagePath, browsersJSON) {
|
||||
if (getFromENV('PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD')) {
|
||||
logPolitely('Skipping browsers download because `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` env variable is set');
|
||||
return false;
|
||||
}
|
||||
for (const browser of browsersJSON.browsers)
|
||||
await downloadBrowserWithProgressBar(packagePath, browser);
|
||||
}
|
||||
|
||||
async function downloadBrowserWithProgressBar(packagePath, browser) {
|
||||
return browserFetcher.downloadBrowserWithProgressBar({
|
||||
baseDir,
|
||||
browserName,
|
||||
browserRevision,
|
||||
progressBarName: `${browserName} for playwright v${packageJSON.version}`,
|
||||
baseDir: browsersPath(packagePath),
|
||||
browserName: browser.name,
|
||||
browserRevision: browser.revision,
|
||||
serverHost: getFromENV('PLAYWRIGHT_DOWNLOAD_HOST'),
|
||||
});
|
||||
}
|
||||
|
||||
function getFromENV(name) {
|
||||
let value = process.env[name];
|
||||
value = value || process.env[`npm_config_${name.toLowerCase()}`];
|
||||
value = value || process.env[`npm_package_config_${name.toLowerCase()}`];
|
||||
return value;
|
||||
function initializePlaywright(packagePath, browsersJSON) {
|
||||
const browsers = browsersJSON.browsers;
|
||||
const playwright = new Playwright({
|
||||
browsers: browsers.map(browser => browser.name),
|
||||
});
|
||||
for (const browser of browsers)
|
||||
playwright[browser.name]._executablePath = executablePath(packagePath, browser);
|
||||
return playwright;
|
||||
}
|
||||
|
||||
module.exports = { targetDirectory, executablePath, downloadBrowserWithProgressBar };
|
||||
module.exports = {
|
||||
executablePath,
|
||||
targetDirectory,
|
||||
downloadBrowserWithProgressBar,
|
||||
downloadBrowsersWithProgressBar,
|
||||
initializePlaywright
|
||||
};
|
||||
|
|
|
|||
14
index.js
14
index.js
|
|
@ -13,17 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { Playwright } = require('./lib/server/playwright.js');
|
||||
const { executablePath } = require('./download-browser.js');
|
||||
|
||||
const playwright = new Playwright({
|
||||
browsers: ['webkit', 'chromium', 'firefox'],
|
||||
});
|
||||
const { initializePlaywright } = require('./download-browser');
|
||||
|
||||
playwright.chromium._executablePath = executablePath(__dirname, 'chromium');
|
||||
playwright.firefox._executablePath = executablePath(__dirname, 'firefox');
|
||||
playwright.webkit._executablePath = executablePath(__dirname, 'webkit');
|
||||
|
||||
module.exports = playwright;
|
||||
module.exports = initializePlaywright(__dirname, require('./browsers.json'));
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ const path = require('path');
|
|||
const fs = require('fs');
|
||||
const util = require('util');
|
||||
const rmAsync = util.promisify(require('rimraf'));
|
||||
const existsAsync = path => fs.promises.access(path).then(() => true, e => false);
|
||||
|
||||
(async () => {
|
||||
const SRC_FOLDER = path.join(__dirname, 'src');
|
||||
|
|
@ -66,18 +65,16 @@ async function listFiles(dirpath) {
|
|||
async function downloadAllBrowsersAndGenerateProtocolTypes() {
|
||||
const { targetDirectory, executablePath, downloadBrowserWithProgressBar } = require('./download-browser');
|
||||
const protocolGenerator = require('./utils/protocol-types-generator');
|
||||
if (await downloadBrowserWithProgressBar(__dirname, 'chromium'))
|
||||
await protocolGenerator.generateChromiumProtocol(executablePath(__dirname, 'chromium')).catch(console.warn);
|
||||
if (await downloadBrowserWithProgressBar(__dirname, 'firefox'))
|
||||
await protocolGenerator.generateFirefoxProtocol(executablePath(__dirname, 'firefox')).catch(console.warn);
|
||||
if (await downloadBrowserWithProgressBar(__dirname, 'webkit'))
|
||||
await protocolGenerator.generateWebKitProtocol(executablePath(__dirname, 'webkit')).catch(console.warn);
|
||||
const browsers = require('./browsers.json')['browsers'];
|
||||
for (const browser of browsers) {
|
||||
if (await downloadBrowserWithProgressBar(__dirname, browser))
|
||||
await protocolGenerator.generateProtocol(browser.name, executablePath(__dirname, browser)).catch(console.warn);
|
||||
}
|
||||
|
||||
// Cleanup stale revisions.
|
||||
const directories = new Set(await readdirAsync(path.join(__dirname, '.local-browsers')));
|
||||
directories.delete(targetDirectory(__dirname, 'chromium'));
|
||||
directories.delete(targetDirectory(__dirname, 'firefox'));
|
||||
directories.delete(targetDirectory(__dirname, 'webkit'));
|
||||
for (const browser of browsers)
|
||||
directories.delete(targetDirectory(__dirname, browser));
|
||||
await Promise.all([...directories].map(directory => rmAsync(directory)));
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -7,11 +7,6 @@
|
|||
"node": ">=10.15.0"
|
||||
},
|
||||
"main": "index.js",
|
||||
"playwright": {
|
||||
"chromium_revision": "760827",
|
||||
"firefox_revision": "1087",
|
||||
"webkit_revision": "1211"
|
||||
},
|
||||
"scripts": {
|
||||
"ctest": "cross-env BROWSER=chromium node --unhandled-rejections=strict test/test.js",
|
||||
"ftest": "cross-env BROWSER=firefox node --unhandled-rejections=strict test/test.js",
|
||||
|
|
|
|||
8
packages/playwright-chromium/browsers.json
Normal file
8
packages/playwright-chromium/browsers.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"browsers": [
|
||||
{
|
||||
"name": "chromium",
|
||||
"revision": "760827"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -14,13 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const { Playwright } = require('playwright-core/lib/server/playwright.js');
|
||||
const { executablePath } = require('playwright-core/download-browser.js');
|
||||
const { initializePlaywright } = require('playwright-core/download-browser');
|
||||
|
||||
const playwright = new Playwright({
|
||||
browsers: ['chromium'],
|
||||
});
|
||||
|
||||
playwright.chromium._executablePath = executablePath(__dirname, 'chromium');
|
||||
|
||||
module.exports = playwright;
|
||||
module.exports = initializePlaywright(__dirname, require('./browsers.json'));
|
||||
|
|
@ -14,8 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const { downloadBrowserWithProgressBar } = require('playwright-core/download-browser');
|
||||
const { downloadBrowsersWithProgressBar } = require('playwright-core/download-browser');
|
||||
|
||||
(async function() {
|
||||
await downloadBrowserWithProgressBar(__dirname, 'chromium');
|
||||
})();
|
||||
downloadBrowsersWithProgressBar(__dirname, require('./browsers.json'));
|
||||
|
|
|
|||
8
packages/playwright-firefox/browsers.json
Normal file
8
packages/playwright-firefox/browsers.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"browsers": [
|
||||
{
|
||||
"name": "firefox",
|
||||
"revision": "1087"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -14,13 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const { Playwright } = require('playwright-core/lib/server/playwright.js');
|
||||
const { executablePath } = require('playwright-core/download-browser.js');
|
||||
const { initializePlaywright } = require('playwright-core/download-browser');
|
||||
|
||||
const playwright = new Playwright({
|
||||
browsers: ['firefox'],
|
||||
});
|
||||
|
||||
playwright.firefox._executablePath = executablePath(__dirname, 'firefox');
|
||||
|
||||
module.exports = playwright;
|
||||
module.exports = initializePlaywright(__dirname, require('./browsers.json'));
|
||||
|
|
@ -14,8 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const { downloadBrowserWithProgressBar } = require('playwright-core/download-browser');
|
||||
const { downloadBrowsersWithProgressBar } = require('playwright-core/download-browser');
|
||||
|
||||
(async function() {
|
||||
await downloadBrowserWithProgressBar(__dirname, 'firefox');
|
||||
})();
|
||||
downloadBrowsersWithProgressBar(__dirname, require('./browsers.json'));
|
||||
|
|
|
|||
8
packages/playwright-webkit/browsers.json
Normal file
8
packages/playwright-webkit/browsers.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"browsers": [
|
||||
{
|
||||
"name": "webkit",
|
||||
"revision": "1211"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -14,13 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const { Playwright } = require('playwright-core/lib/server/playwright.js');
|
||||
const { executablePath } = require('playwright-core/download-browser.js');
|
||||
const { initializePlaywright } = require('playwright-core/download-browser');
|
||||
|
||||
const playwright = new Playwright({
|
||||
browsers: ['webkit'],
|
||||
});
|
||||
|
||||
playwright.webkit._executablePath = executablePath(__dirname, 'webkit');
|
||||
|
||||
module.exports = playwright;
|
||||
module.exports = initializePlaywright(__dirname, require('./browsers.json'));
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const { downloadBrowserWithProgressBar } = require('playwright-core/download-browser');
|
||||
const { downloadBrowsersWithProgressBar } = require('playwright-core/download-browser');
|
||||
|
||||
(async function() {
|
||||
await downloadBrowserWithProgressBar(__dirname, 'webkit');
|
||||
})();
|
||||
downloadBrowsersWithProgressBar(__dirname, require('./browsers.json'));
|
||||
|
|
|
|||
16
packages/playwright/browsers.json
Normal file
16
packages/playwright/browsers.json
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"browsers": [
|
||||
{
|
||||
"name": "chromium",
|
||||
"revision": "760827"
|
||||
},
|
||||
{
|
||||
"name": "firefox",
|
||||
"revision": "1087"
|
||||
},
|
||||
{
|
||||
"name": "webkit",
|
||||
"revision": "1211"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -14,16 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const { Playwright } = require('playwright-core/lib/server/playwright.js');
|
||||
const { executablePath } = require('playwright-core/download-browser.js');
|
||||
|
||||
const playwright = new Playwright({
|
||||
browsers: ['webkit', 'chromium', 'firefox'],
|
||||
});
|
||||
|
||||
playwright.chromium._executablePath = executablePath(__dirname, 'chromium');
|
||||
playwright.webkit._executablePath = executablePath(__dirname, 'webkit');
|
||||
playwright.firefox._executablePath = executablePath(__dirname, 'firefox');
|
||||
|
||||
module.exports = playwright;
|
||||
const { initializePlaywright } = require('playwright-core/download-browser');
|
||||
|
||||
module.exports = initializePlaywright(__dirname, require('./browsers.json'));
|
||||
|
|
|
|||
|
|
@ -14,10 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const { downloadBrowserWithProgressBar } = require('playwright-core/download-browser');
|
||||
const { downloadBrowsersWithProgressBar } = require('playwright-core/download-browser');
|
||||
|
||||
(async function() {
|
||||
await downloadBrowserWithProgressBar(__dirname, 'chromium');
|
||||
await downloadBrowserWithProgressBar(__dirname, 'firefox');
|
||||
await downloadBrowserWithProgressBar(__dirname, 'webkit');
|
||||
})();
|
||||
downloadBrowsersWithProgressBar(__dirname, require('./browsers.json'));
|
||||
|
|
|
|||
|
|
@ -337,6 +337,21 @@ export function assert(value: any, message?: string): asserts value {
|
|||
throw new Error(message);
|
||||
}
|
||||
|
||||
export function getFromENV(name: string) {
|
||||
let value = process.env[name];
|
||||
value = value || process.env[`npm_config_${name.toLowerCase()}`];
|
||||
value = value || process.env[`npm_package_config_${name.toLowerCase()}`];
|
||||
return value;
|
||||
}
|
||||
|
||||
export function logPolitely(toBeLogged: string) {
|
||||
const logLevel = process.env.npm_config_loglevel;
|
||||
const logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel || '') > -1;
|
||||
|
||||
if (!logLevelDisplay)
|
||||
console.log(toBeLogged); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
const escapeGlobChars = new Set(['/', '$', '^', '+', '.', '(', ')', '=', '!', '|']);
|
||||
|
||||
export const helper = Helper;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import * as ProgressBar from 'progress';
|
|||
import { getProxyForUrl } from 'proxy-from-env';
|
||||
import * as URL from 'url';
|
||||
import * as util from 'util';
|
||||
import { assert } from '../helper';
|
||||
import { assert, logPolitely } from '../helper';
|
||||
|
||||
const unlinkAsync = util.promisify(fs.unlink.bind(fs));
|
||||
const chmodAsync = util.promisify(fs.chmod.bind(fs));
|
||||
|
|
@ -129,7 +129,6 @@ export type DownloadOptions = {
|
|||
baseDir: string,
|
||||
browserName: BrowserName,
|
||||
browserRevision: string,
|
||||
progressBarName: string,
|
||||
serverHost?: string,
|
||||
};
|
||||
|
||||
|
|
@ -155,17 +154,13 @@ export function executablePath(baseDir: string, browserName: BrowserName, browse
|
|||
return path.join(targetDirectory(baseDir, browserName, browserRevision), ...relativePath);
|
||||
}
|
||||
|
||||
export async function downloadBrowserWithProgressBar(options: DownloadOptions | null): Promise<boolean> {
|
||||
if (!options) {
|
||||
logPolitely('Skipping browsers download because `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` env variable is set');
|
||||
return false;
|
||||
}
|
||||
export async function downloadBrowserWithProgressBar(options: DownloadOptions): Promise<boolean> {
|
||||
const {
|
||||
baseDir,
|
||||
browserName,
|
||||
browserRevision,
|
||||
progressBarName
|
||||
} = options;
|
||||
const progressBarName = `${browserName} v${browserRevision}`;
|
||||
assert(baseDir, '`baseDir` must be provided');
|
||||
const targetDir = targetDirectory(baseDir, browserName, browserRevision);
|
||||
if (await existsAsync(targetDir)) {
|
||||
|
|
@ -212,20 +207,11 @@ function toMegabytes(bytes: number) {
|
|||
return `${Math.round(mb * 10) / 10} Mb`;
|
||||
}
|
||||
|
||||
function logPolitely(toBeLogged: string) {
|
||||
const logLevel = process.env.npm_config_loglevel;
|
||||
const logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel || '') > -1;
|
||||
|
||||
if (!logLevelDisplay)
|
||||
console.log(toBeLogged); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
export async function canDownload(browserName: BrowserName, browserRevision: string, platform: BrowserPlatform): Promise<boolean> {
|
||||
const url = revisionURL({
|
||||
baseDir: '',
|
||||
browserName,
|
||||
browserRevision,
|
||||
progressBarName: '',
|
||||
browserRevision
|
||||
}, platform);
|
||||
let resolve: (result: boolean) => void = () => {};
|
||||
const promise = new Promise<boolean>(x => resolve = x);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,15 @@ const vm = require('vm');
|
|||
const os = require('os');
|
||||
const util = require('util');
|
||||
|
||||
async function generateProtocol(name, executablePath) {
|
||||
if (name === 'chromium')
|
||||
return generateChromiumProtocol(executablePath);
|
||||
if (name === 'firefox')
|
||||
return generateFirefoxProtocol(executablePath);
|
||||
if (name === 'webkit')
|
||||
return generateWebKitProtocol(executablePath);
|
||||
}
|
||||
|
||||
async function generateChromiumProtocol(executablePath) {
|
||||
const outputPath = path.join(__dirname, '..', '..', 'src', 'chromium', 'protocol.ts');
|
||||
const playwright = await require('../../index').chromium;
|
||||
|
|
@ -215,4 +224,4 @@ function firefoxTypeToString(type, indent=' ') {
|
|||
return type['$type'];
|
||||
}
|
||||
|
||||
module.exports = {generateChromiumProtocol, generateFirefoxProtocol, generateWebKitProtocol};
|
||||
module.exports = { generateProtocol };
|
||||
|
|
|
|||
Loading…
Reference in a new issue