chore: move last rpc files to their place (#3604)

Also update check-deps to be more user-friendly.
This commit is contained in:
Dmitry Gozman 2020-08-24 14:48:03 -07:00 committed by GitHub
parent 59a439e020
commit a099e941d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 99 additions and 95 deletions

View File

@ -16,7 +16,7 @@
const { Playwright } = require('./lib/server/playwright');
const { Electron } = require('./lib/server/electron/electron');
const { setupInProcess } = require('./lib/rpc/inprocess');
const { setupInProcess } = require('./lib/inprocess');
const path = require('path');
const playwright = new Playwright(__dirname, require(path.join(__dirname, 'browsers.json'))['browsers']);

View File

@ -15,6 +15,6 @@
*/
const { Playwright } = require('./lib/server/playwright');
const { setupInProcess } = require('./lib/rpc/inprocess');
const { setupInProcess } = require('./lib/inprocess');
module.exports = setupInProcess(new Playwright(__dirname, require('./browsers.json')['browsers']));

View File

@ -35,5 +35,5 @@ const util = require('util');
return;
}
require('../../lib/rpc/server');
require('../../lib/server');
})();

View File

@ -16,7 +16,7 @@
const { Playwright } = require('./lib/server/playwright');
const { Electron } = require('./lib/server/electron/electron');
const { setupInProcess } = require('./lib/rpc/inprocess');
const { setupInProcess } = require('./lib/inprocess');
const playwright = new Playwright(__dirname, require('./browsers.json')['browsers']);
playwright.electron = new Electron();

View File

@ -14,20 +14,20 @@
* limitations under the License.
*/
import { LaunchServerOptions } from '../client/types';
import { BrowserTypeBase } from '../server/browserType';
import { LaunchServerOptions } from './client/types';
import { BrowserTypeBase } from './server/browserType';
import * as ws from 'ws';
import { helper } from '../server/helper';
import { Browser } from '../server/browser';
import { helper } from './server/helper';
import { Browser } from './server/browser';
import { ChildProcess } from 'child_process';
import { EventEmitter } from 'ws';
import { DispatcherScope, DispatcherConnection } from './server/dispatcher';
import { BrowserTypeDispatcher } from './server/browserTypeDispatcher';
import { BrowserDispatcher } from './server/browserDispatcher';
import { BrowserContextDispatcher } from './server/browserContextDispatcher';
import { BrowserNewContextParams, BrowserContextChannel } from '../protocol/channels';
import { BrowserServerLauncher, BrowserServer } from '../client/browserType';
import { envObjectToArray } from '../client/clientHelper';
import { DispatcherScope, DispatcherConnection } from './dispatchers/dispatcher';
import { BrowserTypeDispatcher } from './dispatchers/browserTypeDispatcher';
import { BrowserDispatcher } from './dispatchers/browserDispatcher';
import { BrowserContextDispatcher } from './dispatchers/browserContextDispatcher';
import { BrowserNewContextParams, BrowserContextChannel } from './protocol/channels';
import { BrowserServerLauncher, BrowserServer } from './client/browserType';
import { envObjectToArray } from './client/clientHelper';
export class BrowserServerLauncherImpl implements BrowserServerLauncher {
private _browserType: BrowserTypeBase;

View File

@ -14,12 +14,12 @@
* limitations under the License.
*/
import { BrowserContext } from '../../server/browserContext';
import { BrowserContext } from '../server/browserContext';
import { Dispatcher, DispatcherScope, lookupDispatcher } from './dispatcher';
import { PageDispatcher, BindingCallDispatcher, WorkerDispatcher } from './pageDispatcher';
import * as channels from '../../protocol/channels';
import * as channels from '../protocol/channels';
import { RouteDispatcher, RequestDispatcher } from './networkDispatchers';
import { CRBrowserContext } from '../../server/chromium/crBrowser';
import { CRBrowserContext } from '../server/chromium/crBrowser';
import { CDPSessionDispatcher } from './cdpSessionDispatcher';
export class BrowserContextDispatcher extends Dispatcher<BrowserContext, channels.BrowserContextInitializer> implements channels.BrowserContextChannel {

View File

@ -14,12 +14,12 @@
* limitations under the License.
*/
import { Browser } from '../../server/browser';
import * as channels from '../../protocol/channels';
import { Browser } from '../server/browser';
import * as channels from '../protocol/channels';
import { BrowserContextDispatcher } from './browserContextDispatcher';
import { CDPSessionDispatcher } from './cdpSessionDispatcher';
import { Dispatcher, DispatcherScope } from './dispatcher';
import { CRBrowser } from '../../server/chromium/crBrowser';
import { CRBrowser } from '../server/chromium/crBrowser';
import { PageDispatcher } from './pageDispatcher';
export class BrowserDispatcher extends Dispatcher<Browser, channels.BrowserInitializer> implements channels.BrowserChannel {

View File

@ -14,9 +14,9 @@
* limitations under the License.
*/
import { BrowserTypeBase, BrowserType } from '../../server/browserType';
import { BrowserTypeBase, BrowserType } from '../server/browserType';
import { BrowserDispatcher } from './browserDispatcher';
import * as channels from '../../protocol/channels';
import * as channels from '../protocol/channels';
import { Dispatcher, DispatcherScope } from './dispatcher';
import { BrowserContextDispatcher } from './browserContextDispatcher';

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
import { CRSession, CRSessionEvents } from '../../server/chromium/crConnection';
import * as channels from '../../protocol/channels';
import { CRSession, CRSessionEvents } from '../server/chromium/crConnection';
import * as channels from '../protocol/channels';
import { Dispatcher, DispatcherScope } from './dispatcher';
export class CDPSessionDispatcher extends Dispatcher<CRSession, channels.CDPSessionInitializer> implements channels.CDPSessionChannel {

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
import { ConsoleMessage } from '../../server/console';
import * as channels from '../../protocol/channels';
import { ConsoleMessage } from '../server/console';
import * as channels from '../protocol/channels';
import { Dispatcher, DispatcherScope } from './dispatcher';
import { createHandle } from './elementHandlerDispatcher';

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
import { Dialog } from '../../server/dialog';
import * as channels from '../../protocol/channels';
import { Dialog } from '../server/dialog';
import * as channels from '../protocol/channels';
import { Dispatcher, DispatcherScope } from './dispatcher';
export class DialogDispatcher extends Dispatcher<Dialog, channels.DialogInitializer> implements channels.DialogChannel {

View File

@ -15,11 +15,11 @@
*/
import { EventEmitter } from 'events';
import { helper } from '../../server/helper';
import * as channels from '../../protocol/channels';
import { serializeError } from '../../protocol/serializers';
import { createScheme, Validator, ValidationError } from '../../protocol/validator';
import { assert, debugAssert } from '../../utils/utils';
import { helper } from '../server/helper';
import * as channels from '../protocol/channels';
import { serializeError } from '../protocol/serializers';
import { createScheme, Validator, ValidationError } from '../protocol/validator';
import { assert, debugAssert } from '../utils/utils';
export const dispatcherSymbol = Symbol('dispatcher');

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
import { Download } from '../../server/download';
import * as channels from '../../protocol/channels';
import { Download } from '../server/download';
import * as channels from '../protocol/channels';
import { Dispatcher, DispatcherScope } from './dispatcher';
import { StreamDispatcher } from './streamDispatcher';

View File

@ -15,8 +15,8 @@
*/
import { Dispatcher, DispatcherScope, lookupDispatcher } from './dispatcher';
import { Electron, ElectronApplication, ElectronPage } from '../../server/electron/electron';
import * as channels from '../../protocol/channels';
import { Electron, ElectronApplication, ElectronPage } from '../server/electron/electron';
import * as channels from '../protocol/channels';
import { BrowserContextDispatcher } from './browserContextDispatcher';
import { PageDispatcher } from './pageDispatcher';
import { parseArgument, serializeResult } from './jsHandleDispatcher';

View File

@ -14,9 +14,9 @@
* limitations under the License.
*/
import { ElementHandle } from '../../server/dom';
import * as js from '../../server/javascript';
import * as channels from '../../protocol/channels';
import { ElementHandle } from '../server/dom';
import * as js from '../server/javascript';
import * as channels from '../protocol/channels';
import { DispatcherScope, lookupNullableDispatcher } from './dispatcher';
import { JSHandleDispatcher, serializeResult, parseArgument } from './jsHandleDispatcher';
import { FrameDispatcher } from './frameDispatcher';

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
import { Frame, NavigationEvent } from '../../server/frames';
import * as channels from '../../protocol/channels';
import { Frame, NavigationEvent } from '../server/frames';
import * as channels from '../protocol/channels';
import { Dispatcher, DispatcherScope, lookupNullableDispatcher, existingDispatcher } from './dispatcher';
import { ElementHandleDispatcher, createHandle } from './elementHandlerDispatcher';
import { parseArgument, serializeResult } from './jsHandleDispatcher';

View File

@ -14,11 +14,11 @@
* limitations under the License.
*/
import * as js from '../../server/javascript';
import * as channels from '../../protocol/channels';
import * as js from '../server/javascript';
import * as channels from '../protocol/channels';
import { Dispatcher, DispatcherScope } from './dispatcher';
import { createHandle } from './elementHandlerDispatcher';
import { parseSerializedValue, serializeValue } from '../../protocol/serializers';
import { parseSerializedValue, serializeValue } from '../protocol/serializers';
export class JSHandleDispatcher extends Dispatcher<js.JSHandle, channels.JSHandleInitializer> implements channels.JSHandleChannel {

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
import { Request, Response, Route } from '../../server/network';
import * as channels from '../../protocol/channels';
import { Request, Response, Route } from '../server/network';
import * as channels from '../protocol/channels';
import { Dispatcher, DispatcherScope, lookupNullableDispatcher, existingDispatcher } from './dispatcher';
import { FrameDispatcher } from './frameDispatcher';

View File

@ -14,13 +14,13 @@
* limitations under the License.
*/
import { BrowserContext } from '../../server/browserContext';
import { Frame } from '../../server/frames';
import { Request } from '../../server/network';
import { Page, Worker } from '../../server/page';
import * as channels from '../../protocol/channels';
import { BrowserContext } from '../server/browserContext';
import { Frame } from '../server/frames';
import { Request } from '../server/network';
import { Page, Worker } from '../server/page';
import * as channels from '../protocol/channels';
import { Dispatcher, DispatcherScope, lookupDispatcher, lookupNullableDispatcher } from './dispatcher';
import { parseError, serializeError } from '../../protocol/serializers';
import { parseError, serializeError } from '../protocol/serializers';
import { ConsoleMessageDispatcher } from './consoleMessageDispatcher';
import { DialogDispatcher } from './dialogDispatcher';
import { DownloadDispatcher } from './downloadDispatcher';
@ -28,8 +28,8 @@ import { FrameDispatcher } from './frameDispatcher';
import { RequestDispatcher, ResponseDispatcher, RouteDispatcher } from './networkDispatchers';
import { serializeResult, parseArgument } from './jsHandleDispatcher';
import { ElementHandleDispatcher, createHandle } from './elementHandlerDispatcher';
import { FileChooser } from '../../server/fileChooser';
import { CRCoverage } from '../../server/chromium/crCoverage';
import { FileChooser } from '../server/fileChooser';
import { CRCoverage } from '../server/chromium/crCoverage';
export class PageDispatcher extends Dispatcher<Page, channels.PageInitializer> implements channels.PageChannel {
private _page: Page;

View File

@ -14,14 +14,14 @@
* limitations under the License.
*/
import { Playwright } from '../../server/playwright';
import * as channels from '../../protocol/channels';
import { Playwright } from '../server/playwright';
import * as channels from '../protocol/channels';
import { BrowserTypeDispatcher } from './browserTypeDispatcher';
import { Dispatcher, DispatcherScope } from './dispatcher';
import { SelectorsDispatcher } from './selectorsDispatcher';
import { Electron } from '../../server/electron/electron';
import { Electron } from '../server/electron/electron';
import { ElectronDispatcher } from './electronDispatcher';
import { DeviceDescriptors } from '../../server/deviceDescriptors';
import { DeviceDescriptors } from '../server/deviceDescriptors';
export class PlaywrightDispatcher extends Dispatcher<Playwright, channels.PlaywrightInitializer> implements channels.PlaywrightChannel {
constructor(scope: DispatcherScope, playwright: Playwright) {

View File

@ -15,10 +15,10 @@
*/
import { Dispatcher, DispatcherScope } from './dispatcher';
import * as channels from '../../protocol/channels';
import { Selectors } from '../../server/selectors';
import * as channels from '../protocol/channels';
import { Selectors } from '../server/selectors';
import { ElementHandleDispatcher } from './elementHandlerDispatcher';
import * as dom from '../../server/dom';
import * as dom from '../server/dom';
export class SelectorsDispatcher extends Dispatcher<Selectors, channels.SelectorsInitializer> implements channels.SelectorsChannel {
constructor(scope: DispatcherScope, selectors: Selectors) {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import * as channels from '../../protocol/channels';
import * as channels from '../protocol/channels';
import { Dispatcher, DispatcherScope } from './dispatcher';
import * as stream from 'stream';

View File

@ -14,13 +14,13 @@
* limitations under the License.
*/
import { DispatcherConnection } from './server/dispatcher';
import type { Playwright as PlaywrightImpl } from '../server/playwright';
import type { Playwright as PlaywrightAPI } from '../client/playwright';
import { PlaywrightDispatcher } from './server/playwrightDispatcher';
import { Connection } from '../client/connection';
import { DispatcherConnection } from './dispatchers/dispatcher';
import type { Playwright as PlaywrightImpl } from './server/playwright';
import type { Playwright as PlaywrightAPI } from './client/playwright';
import { PlaywrightDispatcher } from './dispatchers/playwrightDispatcher';
import { Connection } from './client/connection';
import { BrowserServerLauncherImpl } from './browserServerImpl';
import { isUnderTest } from '../utils/utils';
import { isUnderTest } from './utils/utils';
export function setupInProcess(playwright: PlaywrightImpl): PlaywrightAPI {
const clientConnection = new Connection();

View File

@ -14,12 +14,12 @@
* limitations under the License.
*/
import { Transport } from '../protocol/transport';
import { DispatcherConnection } from './server/dispatcher';
import { Playwright } from '../server/playwright';
import { PlaywrightDispatcher } from './server/playwrightDispatcher';
import { Electron } from '../server/electron/electron';
import { gracefullyCloseAll } from '../server/processLauncher';
import { Transport } from './protocol/transport';
import { DispatcherConnection } from './dispatchers/dispatcher';
import { Playwright } from './server/playwright';
import { PlaywrightDispatcher } from './dispatchers/playwrightDispatcher';
import { Electron } from './server/electron/electron';
import { gracefullyCloseAll } from './server/processLauncher';
const dispatcherConnection = new DispatcherConnection();
const transport = new Transport(process.stdout, process.stdin);

View File

@ -117,7 +117,7 @@ registerWorkerFixture('playwright', async({browserName}, test) => {
const {coverage, uninstall} = installCoverageHooks(browserName);
if (options.WIRE) {
const connection = new Connection();
const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'rpc', 'server'), [], {
const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'server'), [], {
stdio: 'pipe',
detached: true,
});

View File

@ -37,6 +37,12 @@ async function checkDeps() {
sourceFiles.filter(x => !x.fileName.includes('node_modules')).map(x => visit(x, x.fileName));
for (const error of errors)
console.log(error);
if (errors.length) {
console.log(`--------------------------------------------------------`);
console.log(`Changing the project structure or adding new components?`);
console.log(`Update DEPS in //${path.relative(root, __filename)}.`);
console.log(`--------------------------------------------------------`);
}
process.exit(errors.length ? 1 : 0);
function visit(node, fileName) {
@ -57,19 +63,15 @@ async function checkDeps() {
if (fromDirectory === toDirectory)
return true;
if (['src/rpc/server/', 'src/rpc/'].includes(fromDirectory))
return true; // Temporary.
while (!DEPS[from]) {
if (from.endsWith('/'))
from = from.substring(0, from.length - 1);
if (from.lastIndexOf('/') === -1)
break;
throw new Error(`Cannot find DEPS for ${fromDirectory}`);
from = from.substring(0, from.lastIndexOf('/') + 1);
}
const deps = DEPS[from] || [`+${fromDirectory}`];
for (const dep of deps) {
for (const dep of DEPS[from]) {
if (to === dep || toDirectory === dep)
return true;
if (dep.endsWith('**')) {
@ -84,34 +86,36 @@ async function checkDeps() {
const DEPS = {};
// No deps for code shared between node and page.
DEPS['src/server/common/'] = [];
DEPS['src/protocol/'] = ['src/utils/'];
DEPS['src/install/'] = ['src/utils/'];
// Client depends on chromium protocol for types.
DEPS['src/client/'] = ['src/utils/', 'src/protocol/', 'src/server/chromium/protocol.ts'];
DEPS['src/dispatchers/'] = ['src/utils/', 'src/protocol/', 'src/server/**'];
// Generic dependencies for server-side code.
DEPS['src/server/'] = [
'src/utils/',
'src/server/common/',
'src/server/injected/',
'src/generated/',
// TODO: remove the server->debug dependency.
// Can depend on files directly in the server directory.
'src/server/',
// Can depend on any files in these subdirectories.
'src/server/common/**',
'src/server/injected/**',
'src/server/debug/**',
];
// Strict deps for injected code.
// No dependencies for code shared between node and page.
DEPS['src/server/common/'] = [];
// Strict dependencies for injected code.
// TODO: remove the injected->types dependency.
DEPS['src/server/injected/'] = ['src/server/common/', 'src/server/types.ts'];
DEPS['src/server/debug/'] = [...DEPS['src/server/'], 'src/server/', 'src/server/debug/**'];
DEPS['src/server/electron/'] = [...DEPS['src/server/'], 'src/server/chromium/'];
DEPS['src/server/chromium/'] = [...DEPS['src/server/'], 'src/server/'];
DEPS['src/server/electron/'] = [...DEPS['src/server/'], 'src/server/', 'src/server/chromium/'];
DEPS['src/server/firefox/'] = [...DEPS['src/server/'], 'src/server/'];
DEPS['src/server/webkit/'] = [...DEPS['src/server/'], 'src/server/'];
DEPS['src/server/playwright.ts'] = [...DEPS['src/server/'], 'src/server/chromium/', 'src/server/webkit/', 'src/server/firefox/'];
DEPS['src/server.ts'] = DEPS['src/inprocess.ts'] = DEPS['src/browserServerImpl.ts'] = ['src/**'];
checkDeps();