Skip to content

Commit d1c161c

Browse files
authored
chore: merge the util exports (#20110)
1 parent 736cf5c commit d1c161c

57 files changed

Lines changed: 466 additions & 345 deletions

Some content is hidden

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

packages/playwright-core/package.json

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,14 @@
2222
"./package.json": "./package.json",
2323
"./lib/grid/gridServer": "./lib/grid/gridServer.js",
2424
"./lib/outofprocess": "./lib/outofprocess.js",
25-
"./lib/utils": "./lib/utils/index.js",
2625
"./lib/image_tools/stats": "./lib/image_tools/stats.js",
2726
"./lib/image_tools/compare": "./lib/image_tools/compare.js",
2827
"./lib/image_tools/imageChannel": "./lib/image_tools/imageChannel.js",
2928
"./lib/image_tools/colorUtils": "./lib/image_tools/colorUtils.js",
30-
"./lib/common/userAgent": "./lib/common/userAgent.js",
3129
"./lib/containers/docker": "./lib/containers/docker.js",
32-
"./lib/utils/comparators": "./lib/utils/comparators.js",
33-
"./lib/utils/eventsHelper": "./lib/utils/eventsHelper.js",
34-
"./lib/utils/fileUtils": "./lib/utils/fileUtils.js",
35-
"./lib/utils/httpServer": "./lib/utils/httpServer.js",
36-
"./lib/utils/hostPlatform": "./lib/utils/hostPlatform.js",
37-
"./lib/utils/manualPromise": "./lib/utils/manualPromise.js",
38-
"./lib/utils/mimeType": "./lib/utils/mimeType.js",
39-
"./lib/utils/multimap": "./lib/utils/multimap.js",
40-
"./lib/utils/processLauncher": "./lib/utils/processLauncher.js",
41-
"./lib/utils/processLauncherCleanupEntrypoint": "./lib/utils/processLauncherCleanupEntrypoint.js",
42-
"./lib/utils/spawnAsync": "./lib/utils/spawnAsync.js",
43-
"./lib/utils/stackTrace": "./lib/utils/stackTrace.js",
44-
"./lib/utils/timeoutRunner": "./lib/utils/timeoutRunner.js",
4530
"./lib/remote/playwrightServer": "./lib/remote/playwrightServer.js",
4631
"./lib/server": "./lib/server/index.js",
32+
"./lib/utils": "./lib/utils/index.js",
4733
"./lib/utilsBundle": "./lib/utilsBundle.js",
4834
"./lib/zipBundle": "./lib/zipBundle.js",
4935
"./types/protocol": "./types/protocol.d.ts",

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import path from 'path';
1919
import * as util from 'util';
2020
import type { Serializable } from '../../types/structs';
2121
import type * as api from '../../types/types';
22-
import type { HeadersArray } from '../common/types';
22+
import type { HeadersArray, NameValue } from '../common/types';
2323
import type * as channels from '@protocol/channels';
2424
import { kBrowserOrContextClosedError } from '../common/errors';
25-
import { assert, headersObjectToArray, isFilePayload, isString, objectToArray } from '../utils';
25+
import { assert, headersObjectToArray, isString } from '../utils';
2626
import { mkdirIfNeeded } from '../utils/fileUtils';
2727
import { ChannelOwner } from './channelOwner';
2828
import { RawHeaders } from './network';
@@ -336,4 +336,17 @@ function isJsonContentType(headers?: HeadersArray): boolean {
336336
return value === 'application/json';
337337
}
338338
return false;
339-
}
339+
}
340+
341+
function objectToArray(map?: { [key: string]: any }): NameValue[] | undefined {
342+
if (!map)
343+
return undefined;
344+
const result = [];
345+
for (const [name, value] of Object.entries(map))
346+
result.push({ name, value: String(value) });
347+
return result;
348+
}
349+
350+
function isFilePayload(value: any): boolean {
351+
return typeof value === 'object' && value['name'] && value['mimeType'] && value['buffer'];
352+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { Waiter } from './waiter';
3232
import { Events } from './events';
3333
import type { LifecycleEvent, URLMatch, SelectOption, SelectOptionOptions, FilePayload, WaitForFunctionOptions, StrictOptions } from './types';
3434
import { kLifecycleEvents } from './types';
35-
import { urlMatches } from '../common/netUtils';
35+
import { urlMatches } from '../utils/network';
3636
import type * as api from '../../types/types';
3737
import type * as structs from '../../types/structs';
3838
import { debugLogger } from '../common/debugLogger';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import type { Page } from './page';
2929
import { Waiter } from './waiter';
3030
import type * as api from '../../types/types';
3131
import type { HeadersArray, URLMatch } from '../common/types';
32-
import { urlMatches } from '../common/netUtils';
32+
import { urlMatches } from '../utils/network';
3333
import { MultiMap } from '../utils/multimap';
3434
import { APIResponse } from './fetch';
3535
import type { Serializable } from '../../types/structs';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import path from 'path';
2020
import type * as structs from '../../types/structs';
2121
import type * as api from '../../types/types';
2222
import { isSafeCloseError } from '../common/errors';
23-
import { urlMatches } from '../common/netUtils';
23+
import { urlMatches } from '../utils/network';
2424
import { TimeoutSettings } from '../common/timeoutSettings';
2525
import type * as channels from '@protocol/channels';
2626
import { parseError, serializeError } from '../protocol/serializers';

packages/playwright-core/src/common/socksProxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import type { AddressInfo } from 'net';
2020
import net from 'net';
2121
import util from 'util';
2222
import { debugLogger } from './debugLogger';
23-
import { createSocket } from './netUtils';
24-
import { assert, createGuid } from '../utils';
23+
import { createSocket } from '../utils/network';
24+
import { assert, createGuid, } from '../utils';
2525

2626
const dnsLookupAsync = util.promisify(dns.lookup);
2727

packages/playwright-core/src/containers/docker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import path from 'path';
1919
import { spawnAsync } from '../utils/spawnAsync';
2020
import * as utils from '../utils';
21-
import { getPlaywrightVersion, getUserAgent } from '../common/userAgent';
21+
import { getPlaywrightVersion, getUserAgent } from '../utils/userAgent';
2222
import { urlToWSEndpoint } from '../server/dispatchers/localUtilsDispatcher';
2323
import { WebSocketTransport } from '../server/transport';
2424
import { SocksInterceptor } from '../server/socksInterceptor';

packages/playwright-core/src/grid/gridAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { debug } from '../utilsBundle';
1818
import { ws as WebSocket } from '../utilsBundle';
1919
import { fork } from 'child_process';
20-
import { getPlaywrightVersion } from '../common/userAgent';
20+
import { getPlaywrightVersion } from '../utils/userAgent';
2121

2222
export function launchGridAgent(agentId: string, gridURL: string, runId: string | undefined) {
2323
const log = debug(`pw:grid:agent:${agentId}`);

packages/playwright-core/src/grid/gridServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { URL } from 'url';
2020
import type { WebSocketServer, WebSocket, WebSocketRawData } from '../utilsBundle';
2121
import { HttpServer } from '../utils/httpServer';
2222
import { assert, createGuid } from '../utils';
23-
import { getPlaywrightVersion } from '../common/userAgent';
23+
import { getPlaywrightVersion } from '../utils/userAgent';
2424

2525
const defaultOS = 'linux';
2626

packages/playwright-core/src/server/chromium/chromium.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import fs from 'fs';
1919
import os from 'os';
2020
import path from 'path';
21+
import type stream from 'stream';
2122
import { CRBrowser } from './crBrowser';
2223
import type { Env } from '../../utils/processLauncher';
2324
import { gracefullyCloseSet } from '../../utils/processLauncher';
@@ -31,11 +32,12 @@ import type { BrowserOptions, BrowserProcess, PlaywrightOptions } from '../brows
3132
import { Browser } from '../browser';
3233
import type * as types from '../types';
3334
import type * as channels from '@protocol/channels';
34-
import type { HTTPRequestParams } from '../../common/netUtils';
35-
import { NET_DEFAULT_TIMEOUT } from '../../common/netUtils';
36-
import { fetchData } from '../../common/netUtils';
37-
import { getUserAgent } from '../../common/userAgent';
38-
import { debugMode, headersArrayToObject, streamToString, wrapInASCIIBox } from '../../utils';
35+
import type { HTTPRequestParams } from '../../utils/network';
36+
import { NET_DEFAULT_TIMEOUT } from '../../utils/network';
37+
import { fetchData } from '../../utils/network';
38+
import { getUserAgent } from '../../utils/userAgent';
39+
import { wrapInASCIIBox } from '../../utils/ascii';
40+
import { debugMode, headersArrayToObject, } from '../../utils';
3941
import { removeFolders } from '../../utils/fileUtils';
4042
import { RecentLogsCollector } from '../../common/debugLogger';
4143
import type { Progress } from '../progress';
@@ -364,3 +366,12 @@ function addProtocol(url: string) {
364366
return 'http://' + url;
365367
return url;
366368
}
369+
370+
function streamToString(stream: stream.Readable): Promise<string> {
371+
return new Promise<string>((resolve, reject) => {
372+
const chunks: Buffer[] = [];
373+
stream.on('data', chunk => chunks.push(Buffer.from(chunk)));
374+
stream.on('error', reject);
375+
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
376+
});
377+
}

0 commit comments

Comments
 (0)