Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move crypto to server/util/ #34759

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/playwright-core/src/androidServerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { PlaywrightServer } from './remote/playwrightServer';
import { createPlaywright } from './server/playwright';
import { createGuid } from './utils';
import { createGuid } from './server/utils/crypto';
import { ws } from './utilsBundle';

import type { BrowserServer } from './client/browserType';
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/browserServerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { PlaywrightServer } from './remote/playwrightServer';
import { helper } from './server/helper';
import { serverSideCallMetadata } from './server/instrumentation';
import { createPlaywright } from './server/playwright';
import { createGuid } from './utils';
import { createGuid } from './server/utils/crypto';
import { rewriteErrorMessage } from './utils/stackTrace';
import { ws } from './utilsBundle';

Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/localUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class LocalUtils extends ChannelOwner<channels.LocalUtilsChannel> {
}

async harOpen(params: channels.LocalUtilsHarOpenParams): Promise<channels.LocalUtilsHarOpenResult> {
return await localUtils.harOpen(this._harBackends, params);
return await localUtils.harOpen(this._platform, this._harBackends, params);
}

async harLookup(params: channels.LocalUtilsHarLookupParams): Promise<channels.LocalUtilsHarLookupResult> {
Expand Down
3 changes: 1 addition & 2 deletions packages/playwright-core/src/client/waiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import { TimeoutError } from './errors';
import { createGuid } from '../utils/crypto';
import { rewriteErrorMessage } from '../utils/stackTrace';
import { zones } from '../utils/zones';

Expand All @@ -35,7 +34,7 @@ export class Waiter {
private _savedZone: Zone;

constructor(channelOwner: ChannelOwner<channels.EventTargetChannel>, event: string) {
this._waitId = createGuid();
this._waitId = channelOwner._platform.createGuid();
this._channelOwner = channelOwner;
this._savedZone = zones.current().without('apiZone');

Expand Down
5 changes: 4 additions & 1 deletion packages/playwright-core/src/server/android/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import * as path from 'path';

import { TimeoutSettings } from '../../common/timeoutSettings';
import { PipeTransport } from '../../utils/pipeTransport';
import { createGuid, getPackageManagerExecCommand, isUnderTest, makeWaitForNextTask } from '../../utils';
import { createGuid } from '../utils/crypto';
import { isUnderTest } from '../../utils/debug';
import { getPackageManagerExecCommand } from '../../utils/env';
import { makeWaitForNextTask } from '../../utils/task';
import { RecentLogsCollector } from '../../utils/debugLogger';
import { debug } from '../../utilsBundle';
import { wsReceiver, wsSender } from '../../utilsBundle';
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-core/src/server/android/backendAdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import { EventEmitter } from 'events';
import * as net from 'net';

import { assert, createGuid } from '../../utils';
import { assert } from '../../utils/debug';
import { createGuid } from '../utils/crypto';
import { debug } from '../../utilsBundle';

import type { Backend, DeviceBackend, SocketBackend } from './android';
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-core/src/server/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import * as fs from 'fs';
import * as path from 'path';

import { TimeoutSettings } from '../common/timeoutSettings';
import { createGuid, debugMode } from '../utils';
import { createGuid } from './utils/crypto';
import { debugMode } from '../utils/debug';
import { Clock } from './clock';
import { Debugger } from './debugger';
import { BrowserContextAPIRequestContext } from './fetch';
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-core/src/server/chromium/crBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

import * as path from 'path';

import { assert, createGuid } from '../../utils';
import { assert } from '../../utils/debug';
import { createGuid } from '../utils/crypto';
import { Artifact } from '../artifact';
import { Browser } from '../browser';
import { BrowserContext, assertBrowserContextIsNotOwned, verifyGeolocation } from '../browserContext';
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-core/src/server/chromium/crPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

import * as path from 'path';

import { assert, createGuid } from '../../utils';
import { assert } from '../../utils/debug';
import { createGuid } from '../utils/crypto';
import { eventsHelper } from '../../utils/eventsHelper';
import { rewriteErrorMessage } from '../../utils/stackTrace';
import * as dialog from '../dialog';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import { Recorder } from '../recorder';
import { TracingDispatcher } from './tracingDispatcher';
import { WebSocketRouteDispatcher } from './webSocketRouteDispatcher';
import { WritableStreamDispatcher } from './writableStreamDispatcher';
import { createGuid, urlMatches } from '../../utils';
import { createGuid } from '../utils/crypto';
import { urlMatches } from '../../utils/isomorphic/urlMatch';
import { RecorderApp } from '../recorder/recorderApp';

import type { Artifact } from '../artifact';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { Dispatcher } from './dispatcher';
import { createGuid } from '../../utils';
import { createGuid } from '../utils/crypto';

import type { LocalUtilsDispatcher } from './localUtilsDispatcher';
import type * as channels from '@protocol/channels';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class LocalUtilsDispatcher extends Dispatcher<{ guid: string }, channels.
}

async harOpen(params: channels.LocalUtilsHarOpenParams, metadata: CallMetadata): Promise<channels.LocalUtilsHarOpenResult> {
return await localUtils.harOpen(this._harBackends, params);
return await localUtils.harOpen(nodePlatform, this._harBackends, params);
}

async harLookup(params: channels.LocalUtilsHarLookupParams, metadata: CallMetadata): Promise<channels.LocalUtilsHarLookupResult> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import { RequestDispatcher } from './networkDispatchers';
import { ResponseDispatcher } from './networkDispatchers';
import { RouteDispatcher, WebSocketDispatcher } from './networkDispatchers';
import { WebSocketRouteDispatcher } from './webSocketRouteDispatcher';
import { createGuid, urlMatches } from '../../utils';
import { createGuid } from '../utils/crypto';
import { urlMatches } from '../../utils/isomorphic/urlMatch';

import type { Artifact } from '../artifact';
import type { BrowserContext } from '../browserContext';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { ElectronDispatcher } from './electronDispatcher';
import { LocalUtilsDispatcher } from './localUtilsDispatcher';
import { APIRequestContextDispatcher } from './networkDispatchers';
import { SelectorsDispatcher } from './selectorsDispatcher';
import { createGuid } from '../../utils';
import { createGuid } from '../utils/crypto';
import { eventsHelper } from '../../utils/eventsHelper';

import type { RootDispatcher } from './dispatcher';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/

import { Dispatcher } from './dispatcher';
import { ManualPromise, createGuid } from '../../utils';
import { ManualPromise } from '../../utils/isomorphic/manualPromise';
import { createGuid } from '../utils/crypto';

import type { ArtifactDispatcher } from './artifactDispatcher';
import type * as channels from '@protocol/channels';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { Page } from '../page';
import { Dispatcher, existingDispatcher } from './dispatcher';
import { PageDispatcher } from './pageDispatcher';
import * as webSocketMockSource from '../../generated/webSocketMockSource';
import { createGuid, urlMatches } from '../../utils';
import { createGuid } from '../utils/crypto';
import { urlMatches } from '../../utils/isomorphic/urlMatch';
import { eventsHelper } from '../../utils/eventsHelper';

import type { BrowserContextDispatcher } from './browserContextDispatcher';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as fs from 'fs';

import { Dispatcher } from './dispatcher';
import { createGuid } from '../../utils';
import { createGuid } from '../utils/crypto';

import type { BrowserContextDispatcher } from './browserContextDispatcher';
import type * as channels from '@protocol/channels';
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-core/src/server/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import * as url from 'url';
import * as zlib from 'zlib';

import { TimeoutSettings } from '../common/timeoutSettings';
import { assert, constructURLBasedOnBaseURL, createGuid, eventsHelper, monotonicTime } from '../utils';
import { assert, constructURLBasedOnBaseURL, eventsHelper, monotonicTime } from '../utils';
import { createGuid } from './utils/crypto';
import { getUserAgent } from '../utils/userAgent';
import { HttpsProxyAgent, SocksProxyAgent } from '../utilsBundle';
import { BrowserContext, verifyClientCertificates } from './browserContext';
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/har/harRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as path from 'path';

import { Artifact } from '../artifact';
import { HarTracer } from './harTracer';
import { createGuid } from '../../utils';
import { createGuid } from '../utils/crypto';
import { ManualPromise } from '../../utils/isomorphic/manualPromise';
import { yazl } from '../../zipBundle';

Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { EventEmitter } from 'events';

import { createGuid } from '../utils';
import { createGuid } from './utils/crypto';

import type { Browser } from './browser';
import type { BrowserContext } from './browserContext';
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-core/src/server/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import * as js from './javascript';
import { ProgressController } from './progress';
import { Screenshotter, validateScreenshotOptions } from './screenshotter';
import { TimeoutSettings } from '../common/timeoutSettings';
import { LongStandingScope, assert, compressCallLog, createGuid, trimStringWithEllipsis } from '../utils';
import { LongStandingScope, assert, compressCallLog, trimStringWithEllipsis } from '../utils';
import { createGuid } from './utils/crypto';
import { asLocator } from '../utils';
import { getComparator } from './utils/comparators';
import { debugLogger } from '../utils/debugLogger';
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { createGuid } from '../utils';
import { createGuid } from './utils/crypto';
import { InvalidSelectorError, parseSelector, stringifySelector, visitAllSelectorParts } from '../utils/isomorphic/selectorParser';

import type { ParsedSelector } from '../utils/isomorphic/selectorParser';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
../../../protocol/
../../../utils/
../../../utilsBundle.ts
../../../utils/isomorphic/
../../../zipBundle.ts
../../dispatchers/dispatcher.ts
../../utils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/

import { frameSnapshotStreamer } from './snapshotterInjected';
import { calculateSha1, createGuid, monotonicTime } from '../../../utils';
import { monotonicTime } from '../../../utils/isomorphic/time';
import { calculateSha1, createGuid } from '../../utils/crypto';
import { debugLogger } from '../../../utils/debugLogger';
import { eventsHelper } from '../../../utils/eventsHelper';
import { mime } from '../../../utilsBundle';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import * as path from 'path';

import { Snapshotter } from './snapshotter';
import { commandsWithTracingSnapshots } from '../../../protocol/debug';
import { assert, createGuid, eventsHelper, monotonicTime } from '../../../utils';
import { assert } from '../../../utils/debug';
import { monotonicTime } from '../../../utils/isomorphic/time';
import { eventsHelper } from '../../../utils/eventsHelper';
import { createGuid } from '../../utils/crypto';
import { Artifact } from '../../artifact';
import { BrowserContext } from '../../browserContext';
import { Dispatcher } from '../../dispatchers/dispatcher';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import * as crypto from 'crypto';

import { assert } from './debug';
import { assert } from '../../utils/debug';

export function createGuid(): string {
return crypto.randomBytes(16).toString('hex');
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/utils/httpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as fs from 'fs';
import * as path from 'path';

import { mime, wsServer } from '../../utilsBundle';
import { createGuid } from '../../utils/crypto';
import { createGuid } from './crypto';
import { assert } from '../../utils/debug';
import { ManualPromise } from '../../utils/isomorphic/manualPromise';
import { createHttpServer } from './network';
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-core/src/server/utils/socksProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import EventEmitter from 'events';
import * as net from 'net';

import { assert, createGuid, } from '../../utils';
import { assert } from '../../utils/debug';
import { createGuid } from './crypto';
import { debugLogger } from '../../utils/debugLogger';
import { createSocket } from './happyEyeballs';

Expand Down
4 changes: 3 additions & 1 deletion packages/playwright-core/src/server/webkit/wkPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import * as path from 'path';

import { assert, createGuid, debugAssert, headersArrayToObject } from '../../utils';
import { assert, debugAssert } from '../../utils';
import { headersArrayToObject } from '../../utils/isomorphic/headers';
import { createGuid } from '../utils/crypto';
import { eventsHelper } from '../../utils/eventsHelper';
import { hostPlatform } from '../../utils/hostPlatform';
import { splitErrorMessage } from '../../utils/stackTrace';
Expand Down
18 changes: 9 additions & 9 deletions packages/playwright-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,39 @@
* limitations under the License.
*/

export * from './utils/isomorphic/manualPromise';
export * from './utils/isomorphic/locatorGenerators';
export * from './utils/isomorphic/manualPromise';
export * from './utils/isomorphic/mimeType';
export * from './utils/isomorphic/stringUtils';
export * from './utils/isomorphic/urlMatch';
export * from './utils/isomorphic/multimap';
export * from './utils/isomorphic/rtti';
export * from './utils/isomorphic/stringUtils';
export * from './utils/isomorphic/time';
export * from './utils/isomorphic/timeoutRunner';
export * from './utils/isomorphic/urlMatch';

export * from './utils/crypto';
export * from './utils/debug';
export * from './utils/debugLogger';
export * from './utils/env';
export * from './utils/eventsHelper';
export * from './utils/expectUtils';
export * from './utils/isomorphic/headers';
export * from './utils/hostPlatform';
export * from './utils/platform';
export * from './utils/isomorphic/headers';
export * from './utils/isomorphic/semaphore';
export * from './utils/platform';
export * from './utils/stackTrace';
export * from './utils/task';
export * from './utils/userAgent';
export * from './utils/zipFile';
export * from './utils/zones';

export * from './server/utils/socksProxy';
export * from './server/utils/processLauncher';
export * from './server/utils/ascii';
export * from './server/utils/comparators';
export * from './server/utils/crypto';
export * from './server/utils/fileUtils';
export * from './server/utils/httpServer';
export * from './server/utils/network';
export * from './server/utils/processLauncher';
export * from './server/utils/profiler';
export * from './server/utils/wsServer';
export * from './server/utils/socksProxy';
export * from './server/utils/spawnAsync';
export * from './server/utils/wsServer';
14 changes: 7 additions & 7 deletions packages/playwright-core/src/utils/harBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
* limitations under the License.
*/

import * as fs from 'fs';
import * as path from 'path';

import { createGuid } from './crypto';
import { ZipFile } from './zipFile';

import type { HeadersArray } from '../common/types';
import type * as har from '@trace/har';
import type { Platform } from './platform';

const redirectStatus = [301, 302, 303, 307, 308];

export class HarBackend {
readonly id = createGuid();
readonly id: string;
private _harFile: har.HARFile;
private _zipFile: ZipFile | null;
private _baseDir: string | null;
private _platform: Platform;

constructor(harFile: har.HARFile, baseDir: string | null, zipFile: ZipFile | null) {
constructor(platform: Platform, harFile: har.HARFile, baseDir: string | null, zipFile: ZipFile | null) {
this._platform = platform;
this.id = platform.createGuid();
this._harFile = harFile;
this._baseDir = baseDir;
this._zipFile = zipFile;
Expand Down Expand Up @@ -79,7 +79,7 @@ export class HarBackend {
if (this._zipFile)
buffer = await this._zipFile.read(file);
else
buffer = await fs.promises.readFile(path.resolve(this._baseDir!, file));
buffer = await this._platform.fs().promises.readFile(this._platform.path().resolve(this._baseDir!, file));
} else {
buffer = Buffer.from(content.text || '', content.encoding === 'base64' ? 'base64' : 'utf-8');
}
Expand Down
Loading
Loading