Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: export all browsers from every package #3128

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
"browsers": [
{
"name": "chromium",
"revision": "791201"
"revision": "791201",
"download": true
},
{
"name": "firefox",
"revision": "1140"
"revision": "1140",
"download": true
},
{
"name": "webkit",
"revision": "1317"
"revision": "1317",
"download": true
}
]
}
1 change: 1 addition & 0 deletions packages/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output
40 changes: 21 additions & 19 deletions packages/build_package.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ const PACKAGES = {
},
};

const cleanupPaths = [];

// 1. Parse CLI arguments
const args = process.argv.slice(2);
if (args.some(arg => arg === '--help')) {
Expand All @@ -81,10 +79,19 @@ if (args.some(arg => arg === '--help')) {
process.exit(1);
}

const packageName = args[0];
const outputPath = path.resolve(args[1]);
const packagePath = path.join(__dirname, 'output', packageName);
const package = PACKAGES[packageName];
if (!package) {
console.log(`ERROR: unknown package ${packageName}`);
process.exit(1);
}

// 2. Setup cleanup if needed
if (!args.some(arg => arg === '--no-cleanup')) {
process.on('exit', () => {
cleanupPaths.forEach(cleanupPath => rmSync(cleanupPath, {}));
rmSync(packagePath, {});
});
process.on('SIGINT', () => process.exit(2));
process.on('SIGHUP', () => process.exit(3));
Expand All @@ -99,19 +106,17 @@ if (!args.some(arg => arg === '--no-cleanup')) {
});
}

const packageName = args[0];
const outputPath = path.resolve(args[1]);
const packagePath = path.join(__dirname, packageName);
const package = PACKAGES[packageName];
if (!package) {
console.log(`ERROR: unknown package ${packageName}`);
process.exit(1);
}

(async () => {
// 3. Copy package files.
rmSync(packagePath, {});
fs.mkdirSync(packagePath, { recursive: true });
await copyToPackage(path.join(__dirname, 'common') + path.sep, packagePath + path.sep);
if (fs.existsSync(path.join(__dirname, packageName))) {
// Copy package-specific files, these can overwrite common ones.
await copyToPackage(path.join(__dirname, packageName) + path.sep, packagePath + path.sep);
}
for (const file of package.files)
await copyToPackage(file);
await copyToPackage(path.join(ROOT_PATH, file), path.join(packagePath, file));

// 4. Generate package.json
const pwInternalJSON = require(path.join(ROOT_PATH, 'package.json'));
Expand Down Expand Up @@ -144,7 +149,8 @@ if (!package) {

// 5. Generate browsers.json
const browsersJSON = require(path.join(ROOT_PATH, 'browsers.json'));
browsersJSON.browsers = browsersJSON.browsers.filter(browser => package.browsers.includes(browser.name));
for (const browser of browsersJSON.browsers)
browser.download = package.browsers.includes(browser.name);
await writeToPackage('browsers.json', JSON.stringify(browsersJSON, null, 2));

// 6. Run npm pack
Expand All @@ -163,15 +169,11 @@ if (!package) {

async function writeToPackage(fileName, content) {
const toPath = path.join(packagePath, fileName);
cleanupPaths.push(toPath);
console.error(`- generating: //${path.relative(ROOT_PATH, toPath)}`);
await writeFileAsync(toPath, content);
}

async function copyToPackage(fileOrDirectoryName) {
const fromPath = path.join(ROOT_PATH, fileOrDirectoryName);
const toPath = path.join(packagePath, fileOrDirectoryName);
cleanupPaths.push(toPath);
async function copyToPackage(fromPath, toPath) {
console.error(`- copying: //${path.relative(ROOT_PATH, fromPath)} -> //${path.relative(ROOT_PATH, toPath)}`);
await cpAsync(fromPath, toPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
import * as types from './types/types';

export * from './types/types';
export const webkit: types.BrowserType<types.WebKitBrowser>;
export const chromium: types.BrowserType<types.ChromiumBrowser>;
export const firefox: types.BrowserType<types.FirefoxBrowser>;
export const webkit: types.BrowserType<types.WebKitBrowser>;
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 3 additions & 22 deletions packages/installation-tests/esm-playwright-chromium.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,9 @@
* limitations under the License.
*/

import { chromium, selectors, devices, errors } from 'playwright-chromium';
import { chromium, firefox, webkit, selectors, devices, errors } from 'playwright-chromium';
import playwright from 'playwright-chromium';
import errorsFile from 'playwright-chromium/lib/errors.js';

if (playwright.chromium !== chromium)
process.exit(1);

if (playwright.errors !== errors)
process.exit(1);
if (errors.TimeoutError !== errorsFile.TimeoutError)
process.exit(1);

(async () => {
for (const browserType of [chromium]) {
const browser = await browserType.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.evaluate(() => navigator.userAgent);
await browser.close();
}
console.log(`esm SUCCESS`);
})().catch(err => {
console.error(err);
process.exit(1);
});
import testESM from './esm.mjs';
testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [chromium]);
25 changes: 3 additions & 22 deletions packages/installation-tests/esm-playwright-firefox.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,9 @@
* limitations under the License.
*/

import { firefox, selectors, devices, errors } from 'playwright-firefox';
import { chromium, firefox, webkit, selectors, devices, errors } from 'playwright-firefox';
dgozman marked this conversation as resolved.
Show resolved Hide resolved
import playwright from 'playwright-firefox';
import errorsFile from 'playwright-firefox/lib/errors.js';

if (playwright.firefox !== firefox)
process.exit(1);

if (playwright.errors !== errors)
process.exit(1);
if (errors.TimeoutError !== errorsFile.TimeoutError)
process.exit(1);

(async () => {
for (const browserType of [firefox]) {
const browser = await browserType.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.evaluate(() => navigator.userAgent);
await browser.close();
}
console.log(`esm SUCCESS`);
})().catch(err => {
console.error(err);
process.exit(1);
});
import testESM from './esm.mjs';
testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [firefox]);
25 changes: 3 additions & 22 deletions packages/installation-tests/esm-playwright-webkit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,9 @@
* limitations under the License.
*/

import { webkit, selectors, devices, errors } from 'playwright-webkit';
import { chromium, firefox, webkit, selectors, devices, errors } from 'playwright-webkit';
import playwright from 'playwright-webkit';
import errorsFile from 'playwright-webkit/lib/errors.js';

if (playwright.webkit !== webkit)
process.exit(1);

if (playwright.errors !== errors)
process.exit(1);
if (errors.TimeoutError !== errorsFile.TimeoutError)
process.exit(1);

(async () => {
for (const browserType of [webkit]) {
const browser = await browserType.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.evaluate(() => navigator.userAgent);
await browser.close();
}
console.log(`esm SUCCESS`);
})().catch(err => {
console.error(err);
process.exit(1);
});
import testESM from './esm.mjs';
testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [webkit]);
27 changes: 2 additions & 25 deletions packages/installation-tests/esm-playwright.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,5 @@ import { chromium, firefox, webkit, selectors, devices, errors } from 'playwrigh
import playwright from 'playwright';
import errorsFile from 'playwright/lib/errors.js';

if (playwright.chromium !== chromium)
process.exit(1);
if (playwright.firefox !== firefox)
process.exit(1);
if (playwright.webkit !== webkit)
process.exit(1);

if (playwright.errors !== errors)
process.exit(1);
if (errors.TimeoutError !== errorsFile.TimeoutError)
process.exit(1);

(async () => {
for (const browserType of [chromium, firefox, webkit]) {
const browser = await browserType.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.evaluate(() => navigator.userAgent);
await browser.close();
}
console.log(`esm SUCCESS`);
})().catch(err => {
console.error(err);
process.exit(1);
});
import testESM from './esm.mjs';
testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [chromium, firefox, webkit]);
42 changes: 42 additions & 0 deletions packages/installation-tests/esm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export default async function testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, browsers) {
if (playwright.chromium !== chromium)
process.exit(1);
if (playwright.firefox !== firefox)
process.exit(1);
if (playwright.webkit !== webkit)
process.exit(1);
if (playwright.errors !== errors)
process.exit(1);
if (errors.TimeoutError !== errorsFile.TimeoutError)
process.exit(1);

try {
for (const browserType of browsers) {
const browser = await browserType.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.evaluate(() => navigator.userAgent);
await browser.close();
}
console.log(`esm SUCCESS`);
} catch (err) {
console.error(err);
process.exit(1);
}
}
Loading