chore: flatten supplements (#13437)

This commit is contained in:
Pavel Feldman 2022-04-08 11:52:40 -08:00 committed by GitHub
parent d65263f151
commit f0156d057e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 106 additions and 122 deletions

View File

@ -6,13 +6,11 @@
./
./injected/
./isomorphic/
./har/
./recorder/
./registry/
./supplements/
./trace/recorder/tracing.ts
[browserContext.ts]
./supplements/har/
[playwright.ts]
./android/
./chromium/

View File

@ -33,10 +33,10 @@ import path from 'path';
import fs from 'fs';
import type { CallMetadata } from './instrumentation';
import { serverSideCallMetadata, SdkObject } from './instrumentation';
import { Debugger } from './supplements/debugger';
import { Debugger } from './debugger';
import { Tracing } from './trace/recorder/tracing';
import { HarRecorder } from './supplements/har/harRecorder';
import { RecorderSupplement } from './supplements/recorderSupplement';
import { HarRecorder } from './har/harRecorder';
import { Recorder } from './recorder';
import * as consoleApiSource from '../generated/consoleApiSource';
import { BrowserContextAPIRequestContext } from './fetch';
@ -112,13 +112,13 @@ export abstract class BrowserContext extends SdkObject {
// When PWDEBUG=1, show inspector for each context.
if (debugMode() === 'inspector')
await RecorderSupplement.show(this, { pauseOnNextStatement: true });
await Recorder.show(this, { pauseOnNextStatement: true });
// When paused, show inspector.
if (contextDebugger.isPaused())
RecorderSupplement.showInspector(this);
Recorder.showInspector(this);
contextDebugger.on(Debugger.Events.PausedStateChanged, () => {
RecorderSupplement.showInspector(this);
Recorder.showInspector(this);
});
if (debugMode() === 'console')

View File

@ -15,10 +15,10 @@
*/
import { EventEmitter } from 'events';
import { debugMode, isUnderTest, monotonicTime } from '../../utils';
import type { BrowserContext } from '../browserContext';
import type { CallMetadata, InstrumentationListener, SdkObject } from '../instrumentation';
import { commandsWithTracingSnapshots, pausesBeforeInputActions } from '../../protocol/channels';
import { debugMode, isUnderTest, monotonicTime } from '../utils';
import type { BrowserContext } from './browserContext';
import type { CallMetadata, InstrumentationListener, SdkObject } from './instrumentation';
import { commandsWithTracingSnapshots, pausesBeforeInputActions } from '../protocol/channels';
const symbol = Symbol('Debugger');

View File

@ -23,7 +23,7 @@ import type * as channels from '../../protocol/channels';
import { RouteDispatcher, RequestDispatcher, ResponseDispatcher, APIRequestContextDispatcher } from './networkDispatchers';
import { CRBrowserContext } from '../chromium/crBrowser';
import { CDPSessionDispatcher } from './cdpSessionDispatcher';
import { RecorderSupplement } from '../supplements/recorderSupplement';
import { Recorder } from '../recorder';
import type { CallMetadata } from '../instrumentation';
import { ArtifactDispatcher } from './artifactDispatcher';
import type { Artifact } from '../artifact';
@ -197,7 +197,7 @@ export class BrowserContextDispatcher extends Dispatcher<BrowserContext, channel
}
async recorderSupplementEnable(params: channels.BrowserContextRecorderSupplementEnableParams): Promise<void> {
await RecorderSupplement.show(this._context, params);
await Recorder.show(this._context, params);
}
async pause(params: channels.BrowserContextPauseParams, metadata: CallMetadata) {

View File

@ -15,9 +15,9 @@
*/
import fs from 'fs';
import type { APIRequestContext } from '../../fetch';
import { Artifact } from '../../artifact';
import type { BrowserContext } from '../../browserContext';
import type { APIRequestContext } from '../fetch';
import { Artifact } from '../artifact';
import type { BrowserContext } from '../browserContext';
import type * as har from './har';
import { HarTracer } from './harTracer';

View File

@ -14,18 +14,19 @@
* limitations under the License.
*/
import { BrowserContext } from '../../browserContext';
import type { APIRequestEvent, APIRequestFinishedEvent } from '../../fetch';
import { APIRequestContext } from '../../fetch';
import { helper } from '../../helper';
import * as network from '../../network';
import { Page } from '../../page';
import { BrowserContext } from '../browserContext';
import type { APIRequestEvent, APIRequestFinishedEvent } from '../fetch';
import { APIRequestContext } from '../fetch';
import { helper } from '../helper';
import * as network from '../network';
import { Page } from '../page';
import type * as har from './har';
import { calculateSha1, monotonicTime } from '../../../utils';
import type { RegisteredListener } from '../../../utils/eventsHelper';
import { eventsHelper } from '../../../utils/eventsHelper';
import { calculateSha1, monotonicTime } from '../../utils';
import type { RegisteredListener } from '../../utils/eventsHelper';
import { eventsHelper } from '../../utils/eventsHelper';
import * as mime from 'mime';
import { ManualPromise } from '../../../utils/manualPromise';
import { ManualPromise } from '../../utils/manualPromise';
import { getPlaywrightVersion } from '../../common/userAgent';
const FALLBACK_HTTP_VERSION = 'HTTP/1.1';
@ -382,7 +383,7 @@ export class HarTracer {
version: '1.2',
creator: {
name: 'Playwright',
version: require('../../../../package.json')['version'],
version: getPlaywrightVersion(),
},
browser: {
name: context?._browser.options.name || '',

View File

@ -1,3 +1,4 @@
# Files in this folder are used in browser environment, they can only depend on isomorphic files.
[*]
../isomorphic/
../isomorphic/
../../utils/isomorphic

View File

@ -14,9 +14,9 @@
* limitations under the License.
*/
import { escapeWithQuotes } from '../../../utils/isomorphic/stringUtils';
import { type InjectedScript } from '../../injected/injectedScript';
import { generateSelector } from '../../injected/selectorGenerator';
import { escapeWithQuotes } from '../../utils/isomorphic/stringUtils';
import { type InjectedScript } from './injectedScript';
import { generateSelector } from './selectorGenerator';
function createLocator(injectedScript: InjectedScript, initial: string, options?: { hasText?: string | RegExp }) {
class Locator {

View File

@ -15,11 +15,11 @@
*/
import type * as actions from '../recorder/recorderActions';
import { type InjectedScript } from '../../injected/injectedScript';
import { generateSelector, querySelector } from '../../injected/selectorGenerator';
import type { Point } from '../../../common/types';
import { type InjectedScript } from '../injected/injectedScript';
import { generateSelector, querySelector } from '../injected/selectorGenerator';
import type { Point } from '../../common/types';
import type { UIState } from '../recorder/recorderTypes';
import { Highlight } from '../../injected/highlight';
import { Highlight } from '../injected/highlight';
declare module globalThis {

View File

@ -16,35 +16,35 @@
import * as fs from 'fs';
import type * as actions from './recorder/recorderActions';
import type * as channels from '../../protocol/channels';
import type * as channels from '../protocol/channels';
import type { ActionInContext } from './recorder/codeGenerator';
import { CodeGenerator } from './recorder/codeGenerator';
import { toClickOptions, toModifiers } from './recorder/utils';
import { Page } from '../page';
import { Frame } from '../frames';
import { BrowserContext } from '../browserContext';
import { Page } from './page';
import { Frame } from './frames';
import { BrowserContext } from './browserContext';
import { JavaLanguageGenerator } from './recorder/java';
import { JavaScriptLanguageGenerator } from './recorder/javascript';
import { CSharpLanguageGenerator } from './recorder/csharp';
import { PythonLanguageGenerator } from './recorder/python';
import * as recorderSource from '../../generated/recorderSource';
import * as consoleApiSource from '../../generated/consoleApiSource';
import * as recorderSource from '../generated/recorderSource';
import * as consoleApiSource from '../generated/consoleApiSource';
import type { IRecorderApp } from './recorder/recorderApp';
import { RecorderApp } from './recorder/recorderApp';
import type { CallMetadata, InstrumentationListener, SdkObject } from '../instrumentation';
import type { Point } from '../../common/types';
import type { CallMetadata, InstrumentationListener, SdkObject } from './instrumentation';
import type { Point } from '../common/types';
import type { CallLog, CallLogStatus, EventData, Mode, Source, UIState } from './recorder/recorderTypes';
import { createGuid, monotonicTime } from '../../utils';
import { createGuid, monotonicTime } from '../utils';
import { metadataToCallLog } from './recorder/recorderUtils';
import { Debugger } from './debugger';
import { EventEmitter } from 'events';
import { raceAgainstTimeout } from '../../utils/timeoutRunner';
import { raceAgainstTimeout } from '../utils/timeoutRunner';
type BindingSource = { frame: Frame, page: Page };
const symbol = Symbol('RecorderSupplement');
export class RecorderSupplement implements InstrumentationListener {
export class Recorder implements InstrumentationListener {
private _context: BrowserContext;
private _mode: Mode;
private _highlightedSelector = '';
@ -57,13 +57,13 @@ export class RecorderSupplement implements InstrumentationListener {
private _contextRecorder: ContextRecorder;
static showInspector(context: BrowserContext) {
RecorderSupplement.show(context, {}).catch(() => {});
Recorder.show(context, {}).catch(() => {});
}
static show(context: BrowserContext, params: channels.BrowserContextRecorderSupplementEnableParams = {}): Promise<RecorderSupplement> {
let recorderPromise = (context as any)[symbol] as Promise<RecorderSupplement>;
static show(context: BrowserContext, params: channels.BrowserContextRecorderSupplementEnableParams = {}): Promise<Recorder> {
let recorderPromise = (context as any)[symbol] as Promise<Recorder>;
if (!recorderPromise) {
const recorder = new RecorderSupplement(context, params);
const recorder = new Recorder(context, params);
recorderPromise = recorder.install().then(() => recorder);
(context as any)[symbol] = recorderPromise;
}

View File

@ -0,0 +1,9 @@
[*]
../
../registry/**
../../common/
../../protocol/
../../utils/**
[recorderApp.ts]
../chromium/crApp.ts

View File

@ -15,8 +15,8 @@
*/
import { EventEmitter } from 'events';
import type { BrowserContextOptions, LaunchOptions } from '../../../..';
import type { Frame } from '../../frames';
import type { BrowserContextOptions, LaunchOptions } from '../../..';
import type { Frame } from '../frames';
import type { LanguageGenerator, LanguageGeneratorOptions } from './language';
import type { Action, Signal, FrameDescription } from './recorderActions';

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { BrowserContextOptions } from '../../../..';
import type { BrowserContextOptions } from '../../..';
import type { LanguageGenerator, LanguageGeneratorOptions } from './language';
import { sanitizeDeviceOptions, toSignalMap } from './language';
import type { ActionInContext } from './codeGenerator';
@ -22,8 +22,8 @@ import type { Action } from './recorderActions';
import { actionTitle } from './recorderActions';
import type { MouseClickOptions } from './utils';
import { toModifiers } from './utils';
import { escapeWithQuotes } from '../../../utils/isomorphic/stringUtils';
import deviceDescriptors from '../../deviceDescriptors';
import { escapeWithQuotes } from '../../utils/isomorphic/stringUtils';
import deviceDescriptors from '../deviceDescriptors';
export class CSharpLanguageGenerator implements LanguageGenerator {
id = 'csharp';

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { BrowserContextOptions } from '../../../..';
import type { BrowserContextOptions } from '../../..';
import type { LanguageGenerator, LanguageGeneratorOptions } from './language';
import { toSignalMap } from './language';
import type { ActionInContext } from './codeGenerator';
@ -22,9 +22,9 @@ import type { Action } from './recorderActions';
import { actionTitle } from './recorderActions';
import type { MouseClickOptions } from './utils';
import { toModifiers } from './utils';
import deviceDescriptors from '../../deviceDescriptors';
import deviceDescriptors from '../deviceDescriptors';
import { JavaScriptFormatter } from './javascript';
import { escapeWithQuotes } from '../../../utils/isomorphic/stringUtils';
import { escapeWithQuotes } from '../../utils/isomorphic/stringUtils';
export class JavaLanguageGenerator implements LanguageGenerator {
id = 'java';

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { BrowserContextOptions } from '../../../..';
import type { BrowserContextOptions } from '../../..';
import type { LanguageGenerator, LanguageGeneratorOptions } from './language';
import { sanitizeDeviceOptions, toSignalMap } from './language';
import type { ActionInContext } from './codeGenerator';
@ -22,8 +22,8 @@ import type { Action } from './recorderActions';
import { actionTitle } from './recorderActions';
import type { MouseClickOptions } from './utils';
import { toModifiers } from './utils';
import deviceDescriptors from '../../deviceDescriptors';
import { escapeWithQuotes } from '../../../utils/isomorphic/stringUtils';
import deviceDescriptors from '../deviceDescriptors';
import { escapeWithQuotes } from '../../utils/isomorphic/stringUtils';
export class JavaScriptLanguageGenerator implements LanguageGenerator {
id: string;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { BrowserContextOptions, LaunchOptions } from '../../../..';
import type { BrowserContextOptions, LaunchOptions } from '../../..';
import type { ActionInContext } from './codeGenerator';
import type { Action, DialogSignal, DownloadSignal, NavigationSignal, PopupSignal } from './recorderActions';

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { BrowserContextOptions } from '../../../..';
import type { BrowserContextOptions } from '../../..';
import type { LanguageGenerator, LanguageGeneratorOptions } from './language';
import { sanitizeDeviceOptions, toSignalMap } from './language';
import type { ActionInContext } from './codeGenerator';
@ -22,8 +22,8 @@ import type { Action } from './recorderActions';
import { actionTitle } from './recorderActions';
import type { MouseClickOptions } from './utils';
import { toModifiers } from './utils';
import { escapeWithQuotes } from '../../../utils/isomorphic/stringUtils';
import deviceDescriptors from '../../deviceDescriptors';
import { escapeWithQuotes } from '../../utils/isomorphic/stringUtils';
import deviceDescriptors from '../deviceDescriptors';
export class PythonLanguageGenerator implements LanguageGenerator {
id = 'python';

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { Point } from '../../../common/types';
import type { Point } from '../../common/types';
export type ActionName =
'check' |

View File

@ -16,15 +16,15 @@
import fs from 'fs';
import path from 'path';
import type { Page } from '../../page';
import { ProgressController } from '../../progress';
import type { Page } from '../page';
import { ProgressController } from '../progress';
import { EventEmitter } from 'events';
import { serverSideCallMetadata } from '../../instrumentation';
import { serverSideCallMetadata } from '../instrumentation';
import type { CallLog, EventData, Mode, Source } from './recorderTypes';
import { isUnderTest } from '../../../utils';
import { isUnderTest } from '../../utils';
import * as mime from 'mime';
import { installAppIcon } from '../../chromium/crApp';
import { findChromiumChannel } from '../../registry';
import { installAppIcon } from '../chromium/crApp';
import { findChromiumChannel } from '../registry';
declare global {
interface Window {
@ -70,7 +70,7 @@ export class RecorderApp extends EventEmitter implements IRecorderApp {
await this._page._setServerRequestInterceptor(async route => {
if (route.request().url().startsWith('https://playwright/')) {
const uri = route.request().url().substring('https://playwright/'.length);
const file = require.resolve('../../../webpack/recorder/' + uri);
const file = require.resolve('../../webpack/recorder/' + uri);
const buffer = await fs.promises.readFile(file);
await route.fulfill({
status: 200,
@ -99,7 +99,7 @@ export class RecorderApp extends EventEmitter implements IRecorderApp {
static async open(sdkLanguage: string, headed: boolean): Promise<IRecorderApp> {
if (process.env.PW_CODEGEN_NO_INSPECTOR)
return new HeadlessRecorderApp();
const recorderPlaywright = (require('../../playwright').createPlaywright as typeof import('../../playwright').createPlaywright)('javascript', true);
const recorderPlaywright = (require('../playwright').createPlaywright as typeof import('../playwright').createPlaywright)('javascript', true);
const args = [
'--app=data:text/html,',
'--window-size=600,600',

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
import type { Point } from '../../../common/types';
import type { SerializedError } from '../../../protocol/channels';
import type { Point } from '../../common/types';
import type { SerializedError } from '../../protocol/channels';
export type Mode = 'inspecting' | 'recording' | 'none';

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { CallMetadata } from '../../instrumentation';
import type { CallMetadata } from '../instrumentation';
import type { CallLog, CallLogStatus } from './recorderTypes';
export function metadataToCallLog(metadata: CallMetadata, status: CallLogStatus): CallLog {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { Frame } from '../../frames';
import type { Frame } from '../frames';
import type * as actions from './recorderActions';
export type MouseClickOptions = Parameters<Frame['click']>[2];

View File

@ -1,10 +0,0 @@
[*]
../
../../utils/
[debugger.ts]
../../protocol/
[recorderSupplement.ts]
../../generated/
./recorder/

View File

@ -1,4 +0,0 @@
# Files in this folder are used in browser environment, they can only depend on isomorphic files.
[*]
../../injected/
../../../utils/isomorphic/

View File

@ -1,9 +0,0 @@
[*]
../../
../../registry/**
../../../common/
../../../protocol/
../../../utils/**
[recorderApp.ts]
../../chromium/crApp.ts

View File

@ -1,3 +1,3 @@
[*]
../../supplements/har/
../../har/

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { Entry as HAREntry } from '../../supplements/har/har';
import type { Entry as HAREntry } from '../../har/har';
export type ResourceSnapshot = HAREntry;

View File

@ -1,7 +1,7 @@
[*]
../../
../../har/
../../../common/
../../../protocol/
../../../utils/
../../supplements/har/
../common/

View File

@ -34,9 +34,9 @@ import type { APIRequestContext } from '../../fetch';
import type { CallMetadata, InstrumentationListener } from '../../instrumentation';
import { SdkObject } from '../../instrumentation';
import { Page } from '../../page';
import type * as har from '../../supplements/har/har';
import type { HarTracerDelegate } from '../../supplements/har/harTracer';
import { HarTracer } from '../../supplements/har/harTracer';
import type * as har from '../../har/har';
import type { HarTracerDelegate } from '../../har/harTracer';
import { HarTracer } from '../../har/harTracer';
import type { FrameSnapshot } from '../common/snapshotTypes';
import type * as trace from '../common/traceEvents';
import { VERSION } from '../common/traceEvents';

View File

@ -22,9 +22,9 @@ import { BaseSnapshotStorage } from '../../../../../trace-viewer/src/snapshotSto
import type { SnapshotterBlob, SnapshotterDelegate } from '../recorder/snapshotter';
import { Snapshotter } from '../recorder/snapshotter';
import type { ElementHandle } from '../../dom';
import type { HarTracerDelegate } from '../../supplements/har/harTracer';
import { HarTracer } from '../../supplements/har/harTracer';
import type * as har from '../../supplements/har/har';
import type { HarTracerDelegate } from '../../har/harTracer';
import { HarTracer } from '../../har/harTracer';
import type * as har from '../../har/har';
export class InMemorySnapshotter extends BaseSnapshotStorage implements SnapshotterDelegate, HarTracerDelegate {
private _blobs = new Map<string, Buffer>();

View File

@ -16,7 +16,7 @@
import './callLog.css';
import * as React from 'react';
import type { CallLog } from '@playwright-core/server/supplements/recorder/recorderTypes';
import type { CallLog } from '@playwright-core/server/recorder/recorderTypes';
import { msToString } from '@web/uiUtils';
export interface CallLogProps {

View File

@ -14,7 +14,7 @@
limitations under the License.
*/
import type { CallLog, Mode, Source } from '@playwright-core/server/supplements/recorder/recorderTypes';
import type { CallLog, Mode, Source } from '@playwright-core/server/recorder/recorderTypes';
import * as React from 'react';
import { Recorder } from './recorder';
import './recorder.css';

View File

@ -14,7 +14,7 @@
limitations under the License.
*/
import type { CallLog, Mode, Source } from '@playwright-core/server/supplements/recorder/recorderTypes';
import type { CallLog, Mode, Source } from '@playwright-core/server/recorder/recorderTypes';
import { Source as SourceView } from '@web/components/source';
import { SplitView } from '@web/components/splitView';
import { Toolbar } from '@web/components/toolbar';

View File

@ -21,7 +21,7 @@ import fs from 'fs';
import http2 from 'http2';
import type { BrowserContext, BrowserContextOptions } from 'playwright-core';
import type { AddressInfo } from 'net';
import type { Log } from '../../packages/playwright-core/src/server/supplements/har/har';
import type { Log } from '../../packages/playwright-core/src/server/har/har';
async function pageWithHar(contextFactory: (options?: BrowserContextOptions) => Promise<BrowserContext>, testInfo: any, outputPath: string = 'test.har') {
const harPath = testInfo.outputPath(outputPath);

View File

@ -17,7 +17,7 @@
import { contextTest } from '../../config/browserTest';
import type { Page } from 'playwright-core';
import * as path from 'path';
import type { Source } from '../../../packages/playwright-core/src/server/supplements/recorder/recorderTypes';
import type { Source } from '../../../packages/playwright-core/src/server/recorder/recorderTypes';
import type { CommonFixtures, TestChildProcess } from '../../config/commonFixtures';
export { expect } from '@playwright/test';

View File

@ -208,7 +208,6 @@ for (const pkg of workspace.packages()) {
'--extensions', '.ts',
'--out-dir', quotePath(path.join(pkg.path, 'lib')),
'--ignore', '"packages/playwright-core/src/server/injected/**/*"',
'--ignore', '"packages/playwright-core/src/server/supplements/injected/**/*"',
quotePath(path.join(pkg.path, 'src'))],
shell: true,
});
@ -219,7 +218,6 @@ onChanges.push({
committed: false,
inputs: [
'packages/playwright-core/src/server/injected/**',
'packages/playwright-core/src/supplements/injected/**',
'utils/generate_injected.js',
],
script: 'utils/generate_injected.js',

View File

@ -25,8 +25,8 @@ const esbuild = require('esbuild');
const injectedScripts = [
path.join(ROOT, 'packages', 'playwright-core', 'src', 'server', 'injected', 'utilityScript.ts'),
path.join(ROOT, 'packages', 'playwright-core', 'src', 'server', 'injected', 'injectedScript.ts'),
path.join(ROOT, 'packages', 'playwright-core', 'src', 'server', 'supplements', 'injected', 'consoleApi.ts'),
path.join(ROOT, 'packages', 'playwright-core', 'src', 'server', 'supplements', 'injected', 'recorder.ts'),
path.join(ROOT, 'packages', 'playwright-core', 'src', 'server', 'injected', 'consoleApi.ts'),
path.join(ROOT, 'packages', 'playwright-core', 'src', 'server', 'injected', 'recorder.ts'),
];
(async () => {