Skip to content

Commit

Permalink
fix(yarn): download browsers to package directories
Browse files Browse the repository at this point in the history
This patch makes it so all our packages, like `playwright` and
browser-specific flavors, download browsers to their
directories rather then using directory of `playwright-core`.

This way yarn@1 caches are not busted: they didn't expect that directory
content might change after packages's explicit install step
is failed, there's that was what we were doing.

Fixes #1085
  • Loading branch information
aslushnikov committed Feb 26, 2020
1 parent 4ab8801 commit 4049f9d
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 40 deletions.
25 changes: 4 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,8 @@
* limitations under the License.
*/

const { helper } = require('./lib/helper');
const api = require('./lib/api');
const packageJson = require('./package.json');
const { DeviceDescriptors } = require('./lib/deviceDescriptors');
const { TimeoutError } = require('./lib/errors');
const { Chromium } = require('./lib/server/chromium');
const { Firefox } = require('./lib/server/firefox');
const { WebKit } = require('./lib/server/webkit');
module.exports = require('./lib/playwright.js').exportAPI({
downloadPath: __dirname,
browsers: ['webkit', 'chromium', 'firefox'],
});

for (const className in api) {
if (typeof api[className] === 'function')
helper.installApiHooks(className[0].toLowerCase() + className.substring(1), api[className]);
}

module.exports = {
devices: DeviceDescriptors,
errors: { TimeoutError },
selectors: api.Selectors._instance(),
chromium: new Chromium(__dirname, packageJson.playwright.chromium_revision),
firefox: new Firefox(__dirname, packageJson.playwright.firefox_revision),
webkit: new WebKit(__dirname, packageJson.playwright.webkit_revision),
}
10 changes: 4 additions & 6 deletions packages/playwright-chromium/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* limitations under the License.
*/

module.exports = {
...require('playwright-core'),
// Keep exporting Chromium and nullify other browsers.
webkit: undefined,
firefox: undefined,
}
module.exports = require('playwright-core/lib/playwright.js').exportAPI({
downloadPath: __dirname,
browsers: ['chromium'],
});
10 changes: 4 additions & 6 deletions packages/playwright-firefox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* limitations under the License.
*/

module.exports = {
...require('playwright-core'),
// Keep exporting firefox and nullify other browsers.
chromium: undefined,
webkit: undefined,
}
module.exports = require('playwright-core').exportAPI({
downloadPath: __dirname,
browsers: ['firefox'],
});
10 changes: 4 additions & 6 deletions packages/playwright-webkit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* limitations under the License.
*/

module.exports = {
...require('playwright-core'),
// Keep exporting webkit and nullify other browsers.
chromium: undefined,
firefox: undefined,
}
module.exports = require('playwright-core').exportAPI({
downloadPath: __dirname,
browsers: ['webkit'],
});
5 changes: 4 additions & 1 deletion packages/playwright/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
module.exports = require('playwright-core');
module.exports = require('playwright-core/lib/playwright.js').exportAPI({
downloadPath: __dirname,
browsers: ['webkit', 'chromium', 'firefox'],
});
62 changes: 62 additions & 0 deletions src/playwright.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* 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.
*/

import { helper } from './helper';
import * as api from './api';

import { DeviceDescriptors } from './deviceDescriptors';
import { TimeoutError } from './errors';
import { Chromium } from './server/chromium';
import { Firefox } from './server/firefox';
import { WebKit } from './server/webkit';

const packageJson = require('../package.json');

for (const className in api) {
if (typeof (api as any)[className] === 'function')
helper.installApiHooks(className[0].toLowerCase() + className.substring(1), (api as any)[className]);
}

type API = {
devices: typeof DeviceDescriptors,
errors: { TimeoutError: typeof TimeoutError },
chromium?: Chromium,
firefox?: Firefox,
webkit?: WebKit,
selectors: api.Selectors,
};

export function exportAPI(options: {downloadPath: string, browsers: Array<('firefox'|'webkit'|'chromium')>}): API {
const {
downloadPath = __dirname,
browsers = ['webkit', 'chromium', 'firefox'],
} = options;

const result: API = {
devices: DeviceDescriptors,
errors: { TimeoutError },
selectors: api.Selectors._instance(),
};

if (browsers.includes('webkit'))
result.webkit = new WebKit(downloadPath, packageJson.playwright.webkit_revision);
if (browsers.includes('chromium'))
result.chromium = new Chromium(downloadPath, packageJson.playwright.chromium_revision);
if (browsers.includes('firefox'))
result.firefox = new Firefox(downloadPath, packageJson.playwright.firefox_revision);
return result;
}

0 comments on commit 4049f9d

Please sign in to comment.