Skip to content

Commit 4ebf419

Browse files
authored
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
1 parent 22c28b6 commit 4ebf419

File tree

9 files changed

+69
-59
lines changed

9 files changed

+69
-59
lines changed

index.js

+5-21
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
const {Playwright} = require('./lib/server/playwright.js');
1617

17-
const { helper } = require('./lib/helper');
18-
const api = require('./lib/api');
19-
const packageJson = require('./package.json');
20-
const { DeviceDescriptors } = require('./lib/deviceDescriptors');
21-
const { TimeoutError } = require('./lib/errors');
22-
const { Chromium } = require('./lib/server/chromium');
23-
const { Firefox } = require('./lib/server/firefox');
24-
const { WebKit } = require('./lib/server/webkit');
18+
module.exports = new Playwright({
19+
downloadPath: __dirname,
20+
browsers: ['webkit', 'chromium', 'firefox'],
21+
});
2522

26-
for (const className in api) {
27-
if (typeof api[className] === 'function')
28-
helper.installApiHooks(className[0].toLowerCase() + className.substring(1), api[className]);
29-
}
30-
31-
module.exports = {
32-
devices: DeviceDescriptors,
33-
errors: { TimeoutError },
34-
selectors: api.Selectors._instance(),
35-
chromium: new Chromium(__dirname, packageJson.playwright.chromium_revision),
36-
firefox: new Firefox(__dirname, packageJson.playwright.firefox_revision),
37-
webkit: new WebKit(__dirname, packageJson.playwright.webkit_revision),
38-
}

packages/playwright-chromium/index.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
module.exports = {
18-
...require('playwright-core'),
19-
// Keep exporting Chromium and nullify other browsers.
20-
webkit: undefined,
21-
firefox: undefined,
22-
}
17+
const {Playwright} = require('playwright-core/lib/server/playwright.js');
18+
19+
module.exports = new Playwright({
20+
downloadPath: __dirname,
21+
browsers: ['chromium'],
22+
});
23+

packages/playwright-firefox/index.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
module.exports = {
18-
...require('playwright-core'),
19-
// Keep exporting firefox and nullify other browsers.
20-
chromium: undefined,
21-
webkit: undefined,
22-
}
17+
const {Playwright} = require('playwright-core/lib/server/playwright.js');
18+
19+
module.exports = new Playwright({
20+
downloadPath: __dirname,
21+
browsers: ['firefox'],
22+
});
23+

packages/playwright-webkit/index.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
module.exports = {
18-
...require('playwright-core'),
19-
// Keep exporting webkit and nullify other browsers.
20-
chromium: undefined,
21-
firefox: undefined,
22-
}
17+
const {Playwright} = require('playwright-core/lib/server/playwright.js');
18+
19+
module.exports = new Playwright({
20+
downloadPath: __dirname,
21+
browsers: ['webkit'],
22+
});
23+

packages/playwright/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
module.exports = require('playwright-core');
16+
const {Playwright} = require('playwright-core/lib/server/playwright.js');
17+
18+
module.exports = new Playwright({
19+
downloadPath: __dirname,
20+
browsers: ['webkit', 'chromium', 'firefox'],
21+
});
22+

src/server/chromium.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ import { ConnectionTransport } from '../transport';
3737
import { BrowserContext } from '../browserContext';
3838

3939
export class Chromium implements BrowserType {
40-
private _projectRoot: string;
40+
private _downloadPath: string;
4141
readonly _revision: string;
4242

43-
constructor(projectRoot: string, preferredRevision: string) {
44-
this._projectRoot = projectRoot;
43+
constructor(downloadPath: string, preferredRevision: string) {
44+
this._downloadPath = downloadPath;
4545
this._revision = preferredRevision;
4646
}
4747

@@ -218,7 +218,7 @@ export class Chromium implements BrowserType {
218218
};
219219

220220
const defaultOptions = {
221-
path: path.join(this._projectRoot, '.local-chromium'),
221+
path: path.join(this._downloadPath, '.local-chromium'),
222222
host: 'https://storage.googleapis.com',
223223
platform: (() => {
224224
const platform = os.platform();

src/server/firefox.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ import { BrowserContext } from '../browserContext';
3838
const mkdtempAsync = platform.promisify(fs.mkdtemp);
3939

4040
export class Firefox implements BrowserType {
41-
private _projectRoot: string;
41+
private _downloadPath: string;
4242
readonly _revision: string;
4343

44-
constructor(projectRoot: string, preferredRevision: string) {
45-
this._projectRoot = projectRoot;
44+
constructor(downloadPath: string, preferredRevision: string) {
45+
this._downloadPath = downloadPath;
4646
this._revision = preferredRevision;
4747
}
4848

@@ -216,7 +216,7 @@ export class Firefox implements BrowserType {
216216
};
217217

218218
const defaultOptions = {
219-
path: path.join(this._projectRoot, '.local-firefox'),
219+
path: path.join(this._downloadPath, '.local-firefox'),
220220
host: 'https://playwright.azureedge.net',
221221
platform: (() => {
222222
const platform = os.platform();

src/server/playwright.ts

+24-7
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,41 @@
1515
*/
1616

1717
import * as types from '../types';
18+
import * as api from '../api';
19+
import { helper } from '../helper';
1820
import { TimeoutError } from '../errors';
1921
import { DeviceDescriptors } from '../deviceDescriptors';
2022
import { Chromium } from './chromium';
2123
import { WebKit } from './webkit';
2224
import { Firefox } from './firefox';
2325

26+
const packageJSON = require('../../package.json');
27+
28+
for (const className in api) {
29+
if (typeof (api as any)[className] === 'function')
30+
helper.installApiHooks(className[0].toLowerCase() + className.substring(1), (api as any)[className]);
31+
}
32+
2433
export class Playwright {
34+
readonly selectors = api.Selectors._instance();
2535
readonly devices: types.Devices;
2636
readonly errors: { TimeoutError: typeof TimeoutError };
27-
readonly chromium: Chromium;
28-
readonly firefox: Firefox;
29-
readonly webkit: WebKit;
37+
readonly chromium: (Chromium|undefined);
38+
readonly firefox: (Firefox|undefined);
39+
readonly webkit: (WebKit|undefined);
3040

31-
constructor(projectRoot: string, revisions: { chromium_revision: string, firefox_revision: string, webkit_revision: string }) {
41+
constructor(options: {downloadPath: string, browsers: Array<('firefox'|'webkit'|'chromium')>}) {
42+
const {
43+
downloadPath,
44+
browsers,
45+
} = options;
3246
this.devices = DeviceDescriptors;
3347
this.errors = { TimeoutError };
34-
this.chromium = new Chromium(projectRoot, revisions.chromium_revision);
35-
this.firefox = new Firefox(projectRoot, revisions.firefox_revision);
36-
this.webkit = new WebKit(projectRoot, revisions.webkit_revision);
48+
if (browsers.includes('chromium'))
49+
this.chromium = new Chromium(downloadPath, packageJSON.playwright.chromium_revision);
50+
if (browsers.includes('webkit'))
51+
this.webkit = new WebKit(downloadPath, packageJSON.playwright.webkit_revision);
52+
if (browsers.includes('firefox'))
53+
this.firefox = new Firefox(downloadPath, packageJSON.playwright.firefox_revision);
3754
}
3855
}

src/server/webkit.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ import { Events } from '../events';
4040
import { BrowserContext } from '../browserContext';
4141

4242
export class WebKit implements BrowserType {
43-
private _projectRoot: string;
43+
private _downloadPath: string;
4444
readonly _revision: string;
4545

46-
constructor(projectRoot: string, preferredRevision: string) {
47-
this._projectRoot = projectRoot;
46+
constructor(downloadPath: string, preferredRevision: string) {
47+
this._downloadPath = downloadPath;
4848
this._revision = preferredRevision;
4949
}
5050

@@ -200,7 +200,7 @@ export class WebKit implements BrowserType {
200200
};
201201

202202
const defaultOptions = {
203-
path: path.join(this._projectRoot, '.local-webkit'),
203+
path: path.join(this._downloadPath, '.local-webkit'),
204204
host: 'https://playwright.azureedge.net',
205205
platform: (() => {
206206
const platform = os.platform();

0 commit comments

Comments
 (0)