From 73e53b21df2d2ea6e91f1ac8f8f0861cdca68c0c Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Sun, 23 Aug 2020 20:25:59 -0700 Subject: [PATCH] chore: move injected and debug to src/server (#3591) --- packages/common/.npmignore | 4 ++-- src/browserContext.ts | 2 +- src/dom.ts | 4 ++-- src/javascript.ts | 2 +- src/server/chromium/crConnection.ts | 10 +--------- src/{ => server}/debug/debugController.ts | 10 +++++----- src/{ => server}/debug/injected/consoleApi.ts | 2 +- src/{ => server}/debug/injected/debugScript.ts | 2 +- .../debug/injected/debugScript.webpack.config.js | 4 ++-- src/{ => server}/debug/injected/html.ts | 0 src/server/firefox/ffConnection.ts | 10 +--------- src/{ => server}/injected/README.md | 0 src/{ => server}/injected/attributeSelectorEngine.ts | 0 src/{ => server}/injected/cssSelectorEngine.ts | 0 src/{ => server}/injected/injectedScript.ts | 6 +++--- .../injected/injectedScript.webpack.config.js | 4 ++-- src/{ => server}/injected/selectorEngine.ts | 0 src/{ => server}/injected/textSelectorEngine.ts | 0 src/{ => server}/injected/utilityScript.ts | 2 +- .../injected/utilityScript.webpack.config.js | 4 ++-- .../injected/webpack-inline-source-plugin.js | 0 src/{ => server}/injected/xpathSelectorEngine.ts | 0 src/server/webkit/wkConnection.ts | 10 +--------- utils/check_deps.js | 3 +++ utils/runWebpack.js | 6 +++--- 25 files changed, 32 insertions(+), 53 deletions(-) rename src/{ => server}/debug/debugController.ts (84%) rename src/{ => server}/debug/injected/consoleApi.ts (97%) rename src/{ => server}/debug/injected/debugScript.ts (93%) rename src/{ => server}/debug/injected/debugScript.webpack.config.js (86%) rename src/{ => server}/debug/injected/html.ts (100%) rename src/{ => server}/injected/README.md (100%) rename src/{ => server}/injected/attributeSelectorEngine.ts (100%) rename src/{ => server}/injected/cssSelectorEngine.ts (100%) rename src/{ => server}/injected/injectedScript.ts (99%) rename src/{ => server}/injected/injectedScript.webpack.config.js (87%) rename src/{ => server}/injected/selectorEngine.ts (100%) rename src/{ => server}/injected/textSelectorEngine.ts (100%) rename src/{ => server}/injected/utilityScript.ts (98%) rename src/{ => server}/injected/utilityScript.webpack.config.js (87%) rename src/{ => server}/injected/webpack-inline-source-plugin.js (100%) rename src/{ => server}/injected/xpathSelectorEngine.ts (100%) diff --git a/packages/common/.npmignore b/packages/common/.npmignore index 2b3d1f3193..72e9faf9a8 100644 --- a/packages/common/.npmignore +++ b/packages/common/.npmignore @@ -9,8 +9,8 @@ # Include sources from lib, but not map files. !lib/**/*.js # Exclude injected files. A preprocessed version of these is included via lib/generated. -# See src/injected/README.md. -lib/injected/ +# See src/server/injected/README.md. +lib/server/injected/ # Include Windows dependency checker executable. !bin/PrintDeps.exe # Include generated types and entrypoint. diff --git a/src/browserContext.ts b/src/browserContext.ts index 7d4944f1e3..44d69d7c52 100644 --- a/src/browserContext.ts +++ b/src/browserContext.ts @@ -27,7 +27,7 @@ import { Download } from './download'; import { Browser } from './browser'; import { EventEmitter } from 'events'; import { Progress } from './progress'; -import { DebugController } from './debug/debugController'; +import { DebugController } from './server/debug/debugController'; import { isDebugMode } from './utils/utils'; export class Screencast { diff --git a/src/dom.ts b/src/dom.ts index e7bf07044d..44c0b4fa6c 100644 --- a/src/dom.ts +++ b/src/dom.ts @@ -16,7 +16,7 @@ import * as frames from './frames'; import { assert } from './utils/utils'; -import InjectedScript from './injected/injectedScript'; +import type InjectedScript from './server/injected/injectedScript'; import * as injectedScriptSource from './generated/injectedScriptSource'; import * as debugScriptSource from './generated/debugScriptSource'; import * as js from './javascript'; @@ -24,7 +24,7 @@ import { Page } from './page'; import { selectors, SelectorInfo } from './selectors'; import * as types from './types'; import { Progress } from './progress'; -import DebugScript from './debug/injected/debugScript'; +import type DebugScript from './server/debug/injected/debugScript'; import { FatalDOMError, RetargetableDOMError } from './common/domErrors'; export class FrameExecutionContext extends js.ExecutionContext { diff --git a/src/javascript.ts b/src/javascript.ts index 48bd64c964..85a94f7995 100644 --- a/src/javascript.ts +++ b/src/javascript.ts @@ -18,7 +18,7 @@ import * as dom from './dom'; import * as utilityScriptSource from './generated/utilityScriptSource'; import * as sourceMap from './utils/sourceMap'; import { serializeAsCallArgument } from './common/utilityScriptSerializers'; -import UtilityScript from './injected/utilityScript'; +import type UtilityScript from './server/injected/utilityScript'; type ObjectId = string; export type RemoteObject = { diff --git a/src/server/chromium/crConnection.ts b/src/server/chromium/crConnection.ts index 8b6c162e32..32506a6142 100644 --- a/src/server/chromium/crConnection.ts +++ b/src/server/chromium/crConnection.ts @@ -60,7 +60,7 @@ export class CRConnection extends EventEmitter { if (sessionId) message.sessionId = sessionId; if (debugLogger.isEnabled('protocol')) - debugLogger.log('protocol', 'SEND ► ' + rewriteInjectedScriptEvaluationLog(message)); + debugLogger.log('protocol', 'SEND ► ' + JSON.stringify(message)); this._transport.send(message); return id; } @@ -209,11 +209,3 @@ function createProtocolError(error: Error, method: string, protocolError: { mess message += ` ${protocolError.data}`; return rewriteErrorMessage(error, message); } - -function rewriteInjectedScriptEvaluationLog(message: ProtocolRequest): string { - // Injected script is very long and clutters protocol logs. - // To increase development velocity, we skip replace it with short description in the log. - if (message.method === 'Runtime.evaluate' && message.params && message.params.expression && message.params.expression.includes('src/injected/injected.ts')) - return `{"id":${message.id} [evaluate injected script]}`; - return JSON.stringify(message); -} diff --git a/src/debug/debugController.ts b/src/server/debug/debugController.ts similarity index 84% rename from src/debug/debugController.ts rename to src/server/debug/debugController.ts index d18af7707f..eeb17e97b6 100644 --- a/src/debug/debugController.ts +++ b/src/server/debug/debugController.ts @@ -14,11 +14,11 @@ * limitations under the License. */ -import { BrowserContext } from '../browserContext'; -import * as frames from '../frames'; -import * as js from '../javascript'; -import { Page } from '../page'; -import DebugScript from './injected/debugScript'; +import { BrowserContext } from '../../browserContext'; +import * as frames from '../../frames'; +import * as js from '../../javascript'; +import { Page } from '../../page'; +import type DebugScript from './injected/debugScript'; export class DebugController { constructor(context: BrowserContext) { diff --git a/src/debug/injected/consoleApi.ts b/src/server/debug/injected/consoleApi.ts similarity index 97% rename from src/debug/injected/consoleApi.ts rename to src/server/debug/injected/consoleApi.ts index 6290eb0876..d2f1682d27 100644 --- a/src/debug/injected/consoleApi.ts +++ b/src/server/debug/injected/consoleApi.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ParsedSelector, parseSelector } from '../../common/selectorParser'; +import { ParsedSelector, parseSelector } from '../../../common/selectorParser'; import type InjectedScript from '../../injected/injectedScript'; import { html } from './html'; diff --git a/src/debug/injected/debugScript.ts b/src/server/debug/injected/debugScript.ts similarity index 93% rename from src/debug/injected/debugScript.ts rename to src/server/debug/injected/debugScript.ts index cbc9699cee..a30f44b2be 100644 --- a/src/debug/injected/debugScript.ts +++ b/src/server/debug/injected/debugScript.ts @@ -15,7 +15,7 @@ */ import { ConsoleAPI } from './consoleApi'; -import InjectedScript from '../../injected/injectedScript'; +import type InjectedScript from '../../injected/injectedScript'; export default class DebugScript { consoleAPI: ConsoleAPI | undefined; diff --git a/src/debug/injected/debugScript.webpack.config.js b/src/server/debug/injected/debugScript.webpack.config.js similarity index 86% rename from src/debug/injected/debugScript.webpack.config.js rename to src/server/debug/injected/debugScript.webpack.config.js index 690b64a857..a63aa7701f 100644 --- a/src/debug/injected/debugScript.webpack.config.js +++ b/src/server/debug/injected/debugScript.webpack.config.js @@ -38,9 +38,9 @@ module.exports = { output: { libraryTarget: 'var', filename: 'debugScriptSource.js', - path: path.resolve(__dirname, '../../../lib/injected/packed') + path: path.resolve(__dirname, '../../../../lib/server/injected/packed') }, plugins: [ - new InlineSource(path.join(__dirname, '..', '..', 'generated', 'debugScriptSource.ts')), + new InlineSource(path.join(__dirname, '..', '..', '..', 'generated', 'debugScriptSource.ts')), ] }; diff --git a/src/debug/injected/html.ts b/src/server/debug/injected/html.ts similarity index 100% rename from src/debug/injected/html.ts rename to src/server/debug/injected/html.ts diff --git a/src/server/firefox/ffConnection.ts b/src/server/firefox/ffConnection.ts index f19433b195..e3d355a1c8 100644 --- a/src/server/firefox/ffConnection.ts +++ b/src/server/firefox/ffConnection.ts @@ -78,7 +78,7 @@ export class FFConnection extends EventEmitter { _rawSend(message: ProtocolRequest) { if (debugLogger.isEnabled('protocol')) - debugLogger.log('protocol', 'SEND ► ' + rewriteInjectedScriptEvaluationLog(message)); + debugLogger.log('protocol', 'SEND ► ' + JSON.stringify(message)); this._transport.send(message); } @@ -217,11 +217,3 @@ function createProtocolError(error: Error, method: string, protocolError: { mess message += ` ${protocolError.data}`; return rewriteErrorMessage(error, message); } - -function rewriteInjectedScriptEvaluationLog(message: ProtocolRequest): string { - // Injected script is very long and clutters protocol logs. - // To increase development velocity, we skip replace it with short description in the log. - if (message.method === 'Runtime.evaluate' && message.params && message.params.expression && message.params.expression.includes('src/injected/injected.ts')) - return `{"id":${message.id} [evaluate injected script]}`; - return JSON.stringify(message); -} diff --git a/src/injected/README.md b/src/server/injected/README.md similarity index 100% rename from src/injected/README.md rename to src/server/injected/README.md diff --git a/src/injected/attributeSelectorEngine.ts b/src/server/injected/attributeSelectorEngine.ts similarity index 100% rename from src/injected/attributeSelectorEngine.ts rename to src/server/injected/attributeSelectorEngine.ts diff --git a/src/injected/cssSelectorEngine.ts b/src/server/injected/cssSelectorEngine.ts similarity index 100% rename from src/injected/cssSelectorEngine.ts rename to src/server/injected/cssSelectorEngine.ts diff --git a/src/injected/injectedScript.ts b/src/server/injected/injectedScript.ts similarity index 99% rename from src/injected/injectedScript.ts rename to src/server/injected/injectedScript.ts index 772778dc37..6e770a86d5 100644 --- a/src/injected/injectedScript.ts +++ b/src/server/injected/injectedScript.ts @@ -14,14 +14,14 @@ * limitations under the License. */ -import * as types from '../types'; +import type * as types from '../../types'; import { createAttributeEngine } from './attributeSelectorEngine'; import { createCSSEngine } from './cssSelectorEngine'; import { SelectorEngine, SelectorRoot } from './selectorEngine'; import { createTextSelector } from './textSelectorEngine'; import { XPathEngine } from './xpathSelectorEngine'; -import { ParsedSelector } from '../common/selectorParser'; -import { FatalDOMError } from '../common/domErrors'; +import { ParsedSelector } from '../../common/selectorParser'; +import { FatalDOMError } from '../../common/domErrors'; type Predicate = (progress: types.InjectedScriptProgress, continuePolling: symbol) => T | symbol; diff --git a/src/injected/injectedScript.webpack.config.js b/src/server/injected/injectedScript.webpack.config.js similarity index 87% rename from src/injected/injectedScript.webpack.config.js rename to src/server/injected/injectedScript.webpack.config.js index c1cd15cf75..221e2e5a85 100644 --- a/src/injected/injectedScript.webpack.config.js +++ b/src/server/injected/injectedScript.webpack.config.js @@ -37,9 +37,9 @@ module.exports = { }, output: { filename: 'injectedScriptSource.js', - path: path.resolve(__dirname, '../../lib/injected/packed') + path: path.resolve(__dirname, '../../../lib/server/injected/packed') }, plugins: [ - new InlineSource(path.join(__dirname, '..', 'generated', 'injectedScriptSource.ts')), + new InlineSource(path.join(__dirname, '..', '..', 'generated', 'injectedScriptSource.ts')), ] }; diff --git a/src/injected/selectorEngine.ts b/src/server/injected/selectorEngine.ts similarity index 100% rename from src/injected/selectorEngine.ts rename to src/server/injected/selectorEngine.ts diff --git a/src/injected/textSelectorEngine.ts b/src/server/injected/textSelectorEngine.ts similarity index 100% rename from src/injected/textSelectorEngine.ts rename to src/server/injected/textSelectorEngine.ts diff --git a/src/injected/utilityScript.ts b/src/server/injected/utilityScript.ts similarity index 98% rename from src/injected/utilityScript.ts rename to src/server/injected/utilityScript.ts index d04951ea27..bf2e5b6430 100644 --- a/src/injected/utilityScript.ts +++ b/src/server/injected/utilityScript.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { serializeAsCallArgument, parseEvaluationResultValue } from '../common/utilityScriptSerializers'; +import { serializeAsCallArgument, parseEvaluationResultValue } from '../../common/utilityScriptSerializers'; export default class UtilityScript { evaluate(returnByValue: boolean, expression: string) { diff --git a/src/injected/utilityScript.webpack.config.js b/src/server/injected/utilityScript.webpack.config.js similarity index 87% rename from src/injected/utilityScript.webpack.config.js rename to src/server/injected/utilityScript.webpack.config.js index 41159620be..f20cfec99d 100644 --- a/src/injected/utilityScript.webpack.config.js +++ b/src/server/injected/utilityScript.webpack.config.js @@ -38,9 +38,9 @@ module.exports = { output: { libraryTarget: 'var', filename: 'utilityScriptSource.js', - path: path.resolve(__dirname, '../../lib/injected/packed') + path: path.resolve(__dirname, '../../../lib/server/injected/packed') }, plugins: [ - new InlineSource(path.join(__dirname, '..', 'generated', 'utilityScriptSource.ts')), + new InlineSource(path.join(__dirname, '..', '..', 'generated', 'utilityScriptSource.ts')), ] }; diff --git a/src/injected/webpack-inline-source-plugin.js b/src/server/injected/webpack-inline-source-plugin.js similarity index 100% rename from src/injected/webpack-inline-source-plugin.js rename to src/server/injected/webpack-inline-source-plugin.js diff --git a/src/injected/xpathSelectorEngine.ts b/src/server/injected/xpathSelectorEngine.ts similarity index 100% rename from src/injected/xpathSelectorEngine.ts rename to src/server/injected/xpathSelectorEngine.ts diff --git a/src/server/webkit/wkConnection.ts b/src/server/webkit/wkConnection.ts index 8225e88d3e..d193c6fe3a 100644 --- a/src/server/webkit/wkConnection.ts +++ b/src/server/webkit/wkConnection.ts @@ -54,7 +54,7 @@ export class WKConnection { rawSend(message: ProtocolRequest) { if (debugLogger.isEnabled('protocol')) - debugLogger.log('protocol', 'SEND ► ' + rewriteInjectedScriptEvaluationLog(message)); + debugLogger.log('protocol', 'SEND ► ' + JSON.stringify(message)); this._transport.send(message); } @@ -181,11 +181,3 @@ export function createProtocolError(error: Error, method: string, protocolError: export function isSwappedOutError(e: Error) { return e.message.includes('Target was swapped out.'); } - -function rewriteInjectedScriptEvaluationLog(message: any): string { - // Injected script is very long and clutters protocol logs. - // To increase development velocity, we skip replace it with short description in the log. - if (message.params && message.params.message && message.params.message.includes('Runtime.evaluate') && message.params.message.includes('src/injected/injected.ts')) - return `{"id":${message.id},"method":"${message.method}","params":{"message":[evaluate injected script],"targetId":"${message.params.targetId}"},"pageProxyId":${message.pageProxyId}}`; - return JSON.stringify(message); -} diff --git a/utils/check_deps.js b/utils/check_deps.js index 06a8bcb909..c061d9c8b6 100644 --- a/utils/check_deps.js +++ b/utils/check_deps.js @@ -74,6 +74,9 @@ const DEPS = new Map([ ['src/common/', ['src/common/']], ['src/protocol/', ['src/protocol/', 'src/utils/']], ['src/install/', ['src/install/', 'src/utils/']], + ['src/server/debug/', ['src/server/debug/', 'src/common/', 'src/server/injected/', 'src/', 'src/server/debug/injected/']], + // TODO: reverse the injected->types dependency. + ['src/server/injected/', ['src/server/injected/', 'src/common/', 'src/types.ts']], ['src/server/chromium/', ['src/server/chromium/', 'src/utils/', 'src/', 'src/common/', 'src/server/']], ['src/server/electron/', ['src/server/electron/', 'src/server/chromium/', 'src/utils/', 'src/', 'src/server/']], ['src/server/firefox/', ['src/server/firefox/', 'src/utils/', 'src/', 'src/common/', 'src/server/']], diff --git a/utils/runWebpack.js b/utils/runWebpack.js index cd3b7ac056..56e3b3b219 100644 --- a/utils/runWebpack.js +++ b/utils/runWebpack.js @@ -18,9 +18,9 @@ const child_process = require('child_process'); const path = require('path'); const files = [ - path.join('src', 'injected', 'injectedScript.webpack.config.js'), - path.join('src', 'injected', 'utilityScript.webpack.config.js'), - path.join('src', 'debug', 'injected', 'debugScript.webpack.config.js'), + path.join('src', 'server', 'injected', 'injectedScript.webpack.config.js'), + path.join('src', 'server', 'injected', 'utilityScript.webpack.config.js'), + path.join('src', 'server', 'debug', 'injected', 'debugScript.webpack.config.js'), ]; function runOne(runner, file) {