Skip to content

Commit 3d760b6

Browse files
authored
chore: move debug, env and user agent from utils/ (#34766)
1 parent 6951e6a commit 3d760b6

File tree

86 files changed

+248
-182
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+248
-182
lines changed

packages/playwright-core/src/DEPS.list

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
**
99

1010
[inprocess.ts]
11+
common/
1112
utils/
13+
server/utils
1214

1315
[outofprocess.ts]
1416
client/
17+
common/
1518
protocol/
1619
utils/
1720
utils/isomorphic

packages/playwright-core/src/client/android.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { ChannelOwner } from './channelOwner';
2121
import { TargetClosedError, isTargetClosedError } from './errors';
2222
import { Events } from './events';
2323
import { Waiter } from './waiter';
24-
import { TimeoutSettings } from '../common/timeoutSettings';
24+
import { TimeoutSettings } from '../utils/isomorphic/timeoutSettings';
2525
import { isRegExp, isString } from '../utils/isomorphic/rtti';
2626
import { monotonicTime } from '../utils/isomorphic/time';
2727
import { raceAgainstDeadline } from '../utils/isomorphic/timeoutRunner';
@@ -30,7 +30,7 @@ import type { Page } from './page';
3030
import type * as types from './types';
3131
import type * as api from '../../types/types';
3232
import type { AndroidServerLauncherImpl } from '../androidServerImpl';
33-
import type { Platform } from '../utils/platform';
33+
import type { Platform } from '../common/platform';
3434
import type * as channels from '@protocol/channels';
3535

3636
type Direction = 'down' | 'up' | 'left' | 'right';

packages/playwright-core/src/client/artifact.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { ChannelOwner } from './channelOwner';
1818
import { Stream } from './stream';
19-
import { mkdirIfNeeded } from '../utils/fileUtils';
19+
import { mkdirIfNeeded } from '../common/fileUtils';
2020

2121
import type * as channels from '@protocol/channels';
2222
import type { Readable } from 'stream';

packages/playwright-core/src/client/browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { CDPSession } from './cdpSession';
2020
import { ChannelOwner } from './channelOwner';
2121
import { isTargetClosedError } from './errors';
2222
import { Events } from './events';
23-
import { mkdirIfNeeded } from '../utils/fileUtils';
23+
import { mkdirIfNeeded } from '../common/fileUtils';
2424

2525
import type { BrowserType } from './browserType';
2626
import type { Page } from './page';

packages/playwright-core/src/client/browserContext.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import { Tracing } from './tracing';
3434
import { Waiter } from './waiter';
3535
import { WebError } from './webError';
3636
import { Worker } from './worker';
37-
import { TimeoutSettings } from '../common/timeoutSettings';
38-
import { mkdirIfNeeded } from '../utils/fileUtils';
37+
import { TimeoutSettings } from '../utils/isomorphic/timeoutSettings';
38+
import { mkdirIfNeeded } from '../common/fileUtils';
3939
import { headersObjectToArray } from '../utils/isomorphic/headers';
4040
import { urlMatchesEqual } from '../utils/isomorphic/urlMatch';
4141
import { isRegExp, isString } from '../utils/isomorphic/rtti';
@@ -46,7 +46,7 @@ import type { BrowserContextOptions, Headers, LaunchOptions, StorageState, WaitF
4646
import type * as structs from '../../types/structs';
4747
import type * as api from '../../types/types';
4848
import type { URLMatch } from '../utils/isomorphic/urlMatch';
49-
import type { Platform } from '../utils/platform';
49+
import type { Platform } from '../common/platform';
5050
import type * as channels from '@protocol/channels';
5151

5252
export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel> implements api.BrowserContext {

packages/playwright-core/src/client/browserType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { BrowserContext, prepareBrowserContextParams } from './browserContext';
2121
import { ChannelOwner } from './channelOwner';
2222
import { envObjectToArray } from './clientHelper';
2323
import { Events } from './events';
24-
import { assert } from '../utils/debug';
24+
import { assert } from '../utils/isomorphic/debug';
2525
import { headersObjectToArray } from '../utils/isomorphic/headers';
2626
import { monotonicTime } from '../utils/isomorphic/time';
2727
import { raceAgainstDeadline } from '../utils/isomorphic/timeoutRunner';

packages/playwright-core/src/client/channelOwner.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616

1717
import { EventEmitter } from './eventEmitter';
1818
import { ValidationError, maybeFindValidator } from '../protocol/validator';
19-
import { isUnderTest } from '../utils/debug';
20-
import { debugLogger } from '../utils/debugLogger';
19+
import { isUnderTest } from '../utils/isomorphic/debug';
2120
import { captureLibraryStackTrace, stringifyStackFrames } from '../utils/isomorphic/stackTrace';
2221
import { zones } from '../utils/zones';
2322

2423
import type { ClientInstrumentation } from './clientInstrumentation';
2524
import type { Connection } from './connection';
2625
import type { Logger } from './types';
2726
import type { ValidatorContext } from '../protocol/validator';
28-
import type { Platform } from '../utils/platform';
27+
import type { Platform } from '../common/platform';
2928
import type * as channels from '@protocol/channels';
3029

3130
type Listener = (...args: any[]) => void;
@@ -158,7 +157,7 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
158157
apiZone.params = params;
159158
apiZone.reported = true;
160159
this._instrumentation.onApiCallBegin(apiZone);
161-
logApiCall(this._logger, `=> ${apiZone.apiName} started`);
160+
logApiCall(this._platform, this._logger, `=> ${apiZone.apiName} started`);
162161
return await this._connection.sendMessageToServer(this, prop, validatedParams, apiZone.apiName, apiZone.frames, apiZone.stepId);
163162
}
164163
// Since this api call is either internal, or has already been reported/traced once,
@@ -189,7 +188,7 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
189188
try {
190189
const result = await zones.run('apiZone', apiZone, async () => await func(apiZone));
191190
if (!isInternal) {
192-
logApiCall(logger, `<= ${apiZone.apiName} succeeded`);
191+
logApiCall(this._platform, logger, `<= ${apiZone.apiName} succeeded`);
193192
this._instrumentation.onApiCallEnd(apiZone);
194193
}
195194
return result;
@@ -204,7 +203,7 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
204203
e.stack = '';
205204
if (!isInternal) {
206205
apiZone.error = e;
207-
logApiCall(logger, `<= ${apiZone.apiName} failed`);
206+
logApiCall(this._platform, logger, `<= ${apiZone.apiName} failed`);
208207
this._instrumentation.onApiCallEnd(apiZone);
209208
}
210209
throw e;
@@ -227,10 +226,10 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
227226
}
228227
}
229228

230-
function logApiCall(logger: Logger | undefined, message: string) {
229+
function logApiCall(platform: Platform, logger: Logger | undefined, message: string) {
231230
if (logger && logger.isEnabled('api', 'info'))
232231
logger.log('api', 'info', message, [], { color: 'cyan' });
233-
debugLogger.log('api', message);
232+
platform.log('api', message);
234233
}
235234

236235
function tChannelImplToWire(names: '*' | string[], arg: any, path: string, context: ValidatorContext) {

packages/playwright-core/src/client/clientHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import { isString } from '../utils/isomorphic/rtti';
1919

2020
import type * as types from './types';
21-
import type { Platform } from '../utils/platform';
21+
import type { Platform } from '../common/platform';
2222

2323
export function envObjectToArray(env: types.Env): { name: string, value: string }[] {
2424
const result: { name: string, value: string }[] = [];

packages/playwright-core/src/client/connection.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@ import { Tracing } from './tracing';
4242
import { Worker } from './worker';
4343
import { WritableStream } from './writableStream';
4444
import { ValidationError, findValidator } from '../protocol/validator';
45-
import { debugLogger } from '../utils/debugLogger';
4645
import { formatCallLog, rewriteErrorMessage } from '../utils/isomorphic/stackTrace';
4746
import { zones } from '../utils/zones';
4847

4948
import type { ClientInstrumentation } from './clientInstrumentation';
5049
import type { HeadersArray } from './types';
5150
import type { ValidatorContext } from '../protocol/validator';
52-
import type { Platform } from '../utils/platform';
51+
import type { Platform } from '../common/platform';
5352
import type * as channels from '@protocol/channels';
5453

5554
class Root extends ChannelOwner<channels.RootChannel> {
@@ -139,9 +138,9 @@ export class Connection extends EventEmitter {
139138
const type = object._type;
140139
const id = ++this._lastId;
141140
const message = { id, guid, method, params };
142-
if (debugLogger.isEnabled('channel')) {
141+
if (this.platform.isLogEnabled('channel')) {
143142
// Do not include metadata in debug logs to avoid noise.
144-
debugLogger.log('channel', 'SEND> ' + JSON.stringify(message));
143+
this.platform.log('channel', 'SEND> ' + JSON.stringify(message));
145144
}
146145
const location = frames[0] ? { file: frames[0].file, line: frames[0].line, column: frames[0].column } : undefined;
147146
const metadata: channels.Metadata = { apiName, location, internal: !apiName, stepId };
@@ -159,8 +158,8 @@ export class Connection extends EventEmitter {
159158

160159
const { id, guid, method, params, result, error, log } = message as any;
161160
if (id) {
162-
if (debugLogger.isEnabled('channel'))
163-
debugLogger.log('channel', '<RECV ' + JSON.stringify(message));
161+
if (this.platform.isLogEnabled('channel'))
162+
this.platform.log('channel', '<RECV ' + JSON.stringify(message));
164163
const callback = this._callbacks.get(id);
165164
if (!callback)
166165
throw new Error(`Cannot find command to respond: ${id}`);
@@ -176,8 +175,8 @@ export class Connection extends EventEmitter {
176175
return;
177176
}
178177

179-
if (debugLogger.isEnabled('channel'))
180-
debugLogger.log('channel', '<EVENT ' + JSON.stringify(message));
178+
if (this.platform.isLogEnabled('channel'))
179+
this.platform.log('channel', '<EVENT ' + JSON.stringify(message));
181180
if (method === '__create__') {
182181
this._createRemoteObject(guid, params.type, params.guid, params.initializer);
183182
return;

packages/playwright-core/src/client/consoleMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { JSHandle } from './jsHandle';
1818
import { Page } from './page';
1919

2020
import type * as api from '../../types/types';
21-
import type { Platform } from '../utils/platform';
21+
import type { Platform } from '../common/platform';
2222
import type * as channels from '@protocol/channels';
2323

2424
type ConsoleMessageLocation = channels.BrowserContextConsoleEvent['location'];

0 commit comments

Comments
 (0)