fix(yarn): download browsers to package directories (#1133)

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
This commit is contained in:
Andrey Lushnikov 2020-02-26 15:13:31 -08:00 committed by GitHub
parent 22c28b6615
commit 4ebf419259
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 69 additions and 59 deletions

View file

@ -13,26 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
const {Playwright} = require('./lib/server/playwright.js');
const { helper } = require('./lib/helper'); module.exports = new Playwright({
const api = require('./lib/api'); downloadPath: __dirname,
const packageJson = require('./package.json'); browsers: ['webkit', 'chromium', 'firefox'],
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');
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),
}

View file

@ -14,9 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
module.exports = { const {Playwright} = require('playwright-core/lib/server/playwright.js');
...require('playwright-core'),
// Keep exporting Chromium and nullify other browsers. module.exports = new Playwright({
webkit: undefined, downloadPath: __dirname,
firefox: undefined, browsers: ['chromium'],
} });

View file

@ -14,9 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
module.exports = { const {Playwright} = require('playwright-core/lib/server/playwright.js');
...require('playwright-core'),
// Keep exporting firefox and nullify other browsers. module.exports = new Playwright({
chromium: undefined, downloadPath: __dirname,
webkit: undefined, browsers: ['firefox'],
} });

View file

@ -14,9 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
module.exports = { const {Playwright} = require('playwright-core/lib/server/playwright.js');
...require('playwright-core'),
// Keep exporting webkit and nullify other browsers. module.exports = new Playwright({
chromium: undefined, downloadPath: __dirname,
firefox: undefined, browsers: ['webkit'],
} });

View file

@ -13,4 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
module.exports = require('playwright-core'); const {Playwright} = require('playwright-core/lib/server/playwright.js');
module.exports = new Playwright({
downloadPath: __dirname,
browsers: ['webkit', 'chromium', 'firefox'],
});

View file

@ -37,11 +37,11 @@ import { ConnectionTransport } from '../transport';
import { BrowserContext } from '../browserContext'; import { BrowserContext } from '../browserContext';
export class Chromium implements BrowserType { export class Chromium implements BrowserType {
private _projectRoot: string; private _downloadPath: string;
readonly _revision: string; readonly _revision: string;
constructor(projectRoot: string, preferredRevision: string) { constructor(downloadPath: string, preferredRevision: string) {
this._projectRoot = projectRoot; this._downloadPath = downloadPath;
this._revision = preferredRevision; this._revision = preferredRevision;
} }
@ -218,7 +218,7 @@ export class Chromium implements BrowserType {
}; };
const defaultOptions = { const defaultOptions = {
path: path.join(this._projectRoot, '.local-chromium'), path: path.join(this._downloadPath, '.local-chromium'),
host: 'https://storage.googleapis.com', host: 'https://storage.googleapis.com',
platform: (() => { platform: (() => {
const platform = os.platform(); const platform = os.platform();

View file

@ -38,11 +38,11 @@ import { BrowserContext } from '../browserContext';
const mkdtempAsync = platform.promisify(fs.mkdtemp); const mkdtempAsync = platform.promisify(fs.mkdtemp);
export class Firefox implements BrowserType { export class Firefox implements BrowserType {
private _projectRoot: string; private _downloadPath: string;
readonly _revision: string; readonly _revision: string;
constructor(projectRoot: string, preferredRevision: string) { constructor(downloadPath: string, preferredRevision: string) {
this._projectRoot = projectRoot; this._downloadPath = downloadPath;
this._revision = preferredRevision; this._revision = preferredRevision;
} }
@ -216,7 +216,7 @@ export class Firefox implements BrowserType {
}; };
const defaultOptions = { const defaultOptions = {
path: path.join(this._projectRoot, '.local-firefox'), path: path.join(this._downloadPath, '.local-firefox'),
host: 'https://playwright.azureedge.net', host: 'https://playwright.azureedge.net',
platform: (() => { platform: (() => {
const platform = os.platform(); const platform = os.platform();

View file

@ -15,24 +15,41 @@
*/ */
import * as types from '../types'; import * as types from '../types';
import * as api from '../api';
import { helper } from '../helper';
import { TimeoutError } from '../errors'; import { TimeoutError } from '../errors';
import { DeviceDescriptors } from '../deviceDescriptors'; import { DeviceDescriptors } from '../deviceDescriptors';
import { Chromium } from './chromium'; import { Chromium } from './chromium';
import { WebKit } from './webkit'; import { WebKit } from './webkit';
import { Firefox } from './firefox'; import { Firefox } from './firefox';
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]);
}
export class Playwright { export class Playwright {
readonly selectors = api.Selectors._instance();
readonly devices: types.Devices; readonly devices: types.Devices;
readonly errors: { TimeoutError: typeof TimeoutError }; readonly errors: { TimeoutError: typeof TimeoutError };
readonly chromium: Chromium; readonly chromium: (Chromium|undefined);
readonly firefox: Firefox; readonly firefox: (Firefox|undefined);
readonly webkit: WebKit; readonly webkit: (WebKit|undefined);
constructor(projectRoot: string, revisions: { chromium_revision: string, firefox_revision: string, webkit_revision: string }) { constructor(options: {downloadPath: string, browsers: Array<('firefox'|'webkit'|'chromium')>}) {
const {
downloadPath,
browsers,
} = options;
this.devices = DeviceDescriptors; this.devices = DeviceDescriptors;
this.errors = { TimeoutError }; this.errors = { TimeoutError };
this.chromium = new Chromium(projectRoot, revisions.chromium_revision); if (browsers.includes('chromium'))
this.firefox = new Firefox(projectRoot, revisions.firefox_revision); this.chromium = new Chromium(downloadPath, packageJSON.playwright.chromium_revision);
this.webkit = new WebKit(projectRoot, revisions.webkit_revision); if (browsers.includes('webkit'))
this.webkit = new WebKit(downloadPath, packageJSON.playwright.webkit_revision);
if (browsers.includes('firefox'))
this.firefox = new Firefox(downloadPath, packageJSON.playwright.firefox_revision);
} }
} }

View file

@ -40,11 +40,11 @@ import { Events } from '../events';
import { BrowserContext } from '../browserContext'; import { BrowserContext } from '../browserContext';
export class WebKit implements BrowserType { export class WebKit implements BrowserType {
private _projectRoot: string; private _downloadPath: string;
readonly _revision: string; readonly _revision: string;
constructor(projectRoot: string, preferredRevision: string) { constructor(downloadPath: string, preferredRevision: string) {
this._projectRoot = projectRoot; this._downloadPath = downloadPath;
this._revision = preferredRevision; this._revision = preferredRevision;
} }
@ -200,7 +200,7 @@ export class WebKit implements BrowserType {
}; };
const defaultOptions = { const defaultOptions = {
path: path.join(this._projectRoot, '.local-webkit'), path: path.join(this._downloadPath, '.local-webkit'),
host: 'https://playwright.azureedge.net', host: 'https://playwright.azureedge.net',
platform: (() => { platform: (() => {
const platform = os.platform(); const platform = os.platform();