Skip to content

Commit 17e953c

Browse files
authored
chore: make generate_types not depend on the source (#5040)
The only dependency is a list of devices that we can turn into a js file.
1 parent 1fc02e8 commit 17e953c

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

docs/src/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ $ python -m playwright wk example.com
9595
```
9696

9797
### Emulate devices
98-
`open` can emulate mobile and tablet devices ([see all devices](https://github.com/microsoft/playwright/blob/master/src/server/deviceDescriptors.ts)).
98+
`open` can emulate mobile and tablet devices from the [`playwright.devices`](https://playwright.dev/docs/api/class-playwright#playwrightdevices) list.
9999

100100
```sh js
101101
# Emulate iPhone 11.

src/dispatchers/playwrightDispatcher.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
*/
1616

1717
import * as channels from '../protocol/channels';
18-
import { DeviceDescriptors } from '../server/deviceDescriptors';
1918
import { Playwright } from '../server/playwright';
2019
import { AndroidDispatcher } from './androidDispatcher';
2120
import { BrowserTypeDispatcher } from './browserTypeDispatcher';
2221
import { Dispatcher, DispatcherScope } from './dispatcher';
2322
import { ElectronDispatcher } from './electronDispatcher';
2423
import { SelectorsDispatcher } from './selectorsDispatcher';
24+
import * as types from '../server/types';
2525

2626
export class PlaywrightDispatcher extends Dispatcher<Playwright, channels.PlaywrightInitializer> implements channels.PlaywrightChannel {
2727
constructor(scope: DispatcherScope, playwright: Playwright) {
28-
const deviceDescriptors = Object.entries(DeviceDescriptors)
28+
const descriptors = require('../server/deviceDescriptors') as types.Devices;
29+
const deviceDescriptors = Object.entries(descriptors)
2930
.map(([name, descriptor]) => ({ name, descriptor }));
3031
super(scope, playwright, 'Playwright', {
3132
chromium: new BrowserTypeDispatcher(scope, playwright.chromium),

src/server/deviceDescriptors.ts renamed to src/server/deviceDescriptors.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as types from './types';
19-
20-
export const DeviceDescriptors: types.Devices = {
18+
/**
19+
* @type {import('./types').Devices}
20+
*/
21+
module.exports = {
2122
'Blackberry PlayBook': {
2223
'userAgent': 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML like Gecko) Version/7.2.1.0 Safari/536.2+',
2324
'viewport': {

test/launcher.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ it('should require top-level Errors', async ({}) => {
2323
});
2424

2525
it('should require top-level DeviceDescriptors', async ({playwright}) => {
26-
const Devices = require('../lib/server/deviceDescriptors.js').DeviceDescriptors;
26+
const Devices = require('../lib/server/deviceDescriptors.js');
2727
expect(Devices['iPhone 6']).toBeTruthy();
2828
expect(Devices['iPhone 6']).toEqual(playwright.devices['iPhone 6']);
2929
});

utils/generate_types/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//@ts-check
1818
const path = require('path');
1919
const os = require('os');
20-
const {devices} = require('../..');
20+
const devices = require('../../src/server/deviceDescriptors');
2121
const Documentation = require('../doclint/documentation');
2222
const PROJECT_DIR = path.join(__dirname, '..', '..');
2323
const fs = require('fs');

0 commit comments

Comments
 (0)