Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: remove debug cli dep (#38978)

Pavel Feldman25bfb220a8fb
diff --git a/packages/playwright/src/mcp/terminal/DEPS.list b/packages/playwright/src/mcp/terminal/DEPS.list
index 18c7c0e142..c83f31a2da 100644
--- a/packages/playwright/src/mcp/terminal/DEPS.list
+++ b/packages/playwright/src/mcp/terminal/DEPS.list
@@ -3,4 +3,12 @@
../cli/socketConnection.ts
[cli.ts]
+"strict"
+./program.ts
+
+[program.ts]
+"strict"
./socketConnection.ts
+
+[socketConnection.ts]
+"strict"
diff --git a/packages/playwright/src/mcp/terminal/program.ts b/packages/playwright/src/mcp/terminal/program.ts
index 3b6c0347f0..0f621001c0 100644
--- a/packages/playwright/src/mcp/terminal/program.ts
+++ b/packages/playwright/src/mcp/terminal/program.ts
@@ -24,7 +24,6 @@ import fs from 'fs';
import net from 'net';
import os from 'os';
import path from 'path';
-import { debug } from 'playwright-core/lib/utilsBundle';
import { SocketConnection } from './socketConnection';
import type { Section } from '../browser/response';
@@ -35,8 +34,6 @@ export type StructuredResponse = {
sections: Section[];
};
-const debugCli = debug('pw:cli');
-
class Session {
readonly name: string;
private _connection: SocketConnection;
@@ -201,10 +198,8 @@ class SessionManager {
private async _connect(sessionName: string): Promise<Session> {
const socketPath = this._daemonSocketPath(sessionName);
- debugCli(`Connecting to daemon at ${socketPath}`);
if (await this._canConnect(sessionName)) {
- debugCli(`Socket file exists, attempting to connect...`);
try {
return await this._connectToSocket(sessionName, socketPath);
} catch (e) {
@@ -217,7 +212,6 @@ class SessionManager {
await fs.promises.mkdir(daemonProfilesDir, { recursive: true });
const userDataDir = path.resolve(daemonProfilesDir, `ud-${sessionName}`);
const cliPath = path.join(__dirname, '../../../cli.js');
- debugCli(`Will launch daemon process: ${cliPath}`);
const configFile = resolveConfigFile(this._options.config);
const configArg = configFile !== undefined ? [`--config=${configFile}`] : [];
const headedArg = this._options.headed ? [`--daemon-headed`] : [];
@@ -259,7 +253,6 @@ class SessionManager {
} catch (e) {
if (e.code !== 'ENOENT')
throw e;
- debugCli(`Retrying to connect to daemon at ${socketPath} (${i + 1}/${maxRetries})`);
}
}
@@ -277,7 +270,6 @@ class SessionManager {
private async _connectToSocket(sessionName: string, socketPath: string): Promise<Session> {
const socket = await new Promise<net.Socket>((resolve, reject) => {
const socket = net.createConnection(socketPath, () => {
- debugCli(`Connected to daemon at ${socketPath}`);
resolve(socket);
});
socket.on('error', reject);
diff --git a/packages/playwright/src/mcp/terminal/socketConnection.ts b/packages/playwright/src/mcp/terminal/socketConnection.ts
index 135d88ec99..ff86662644 100644
--- a/packages/playwright/src/mcp/terminal/socketConnection.ts
+++ b/packages/playwright/src/mcp/terminal/socketConnection.ts
@@ -16,10 +16,6 @@
import net from 'net';
-import { debug } from 'playwright-core/lib/utilsBundle';
-
-const daemonDebug = debug('pw:daemon');
-
export class SocketConnection {
private _socket: net.Socket;
private _pendingBuffers: Buffer[] = [];
@@ -33,7 +29,9 @@ export class SocketConnection {
socket.on('close', () => {
this.onclose?.();
});
- socket.on('error', e => daemonDebug(`error: ${e.message}`));
+
+ // eslint-disable-next-line no-console
+ socket.on('error', e => console.error(`error: ${e.message}`));
}
async send(message: any) {
@@ -76,7 +74,8 @@ export class SocketConnection {
try {
this.onmessage?.(JSON.parse(message));
} catch (e) {
- daemonDebug('failed to dispatch message', e);
+ // eslint-disable-next-line no-console
+ console.error('failed to dispatch message', e);
}
}
}
diff --git a/utils/check_deps.js b/utils/check_deps.js
index 5c39fb374b..9ba0e23265 100644
--- a/utils/check_deps.js
+++ b/utils/check_deps.js
@@ -150,6 +150,9 @@ async function innerCheckDeps(root) {
if (!allowImport(fileName, importPath, mergedDeps))
errors.push(`Disallowed import ${path.relative(root, importPath)} in ${path.relative(root, fileName)}`);
return;
+ } else {
+ if (mergedDeps.includes('"strict"') && !builtins.has(node.moduleSpecifier.text))
+ errors.push(`Disallowed import ${node.moduleSpecifier.text} in ${path.relative(root, fileName)}`);
}
const fullStart = node.getFullStart();
@@ -193,6 +196,8 @@ async function innerCheckDeps(root) {
}
if (line === '***')
group.push('***');
+ else if (line === '"strict"')
+ group.push('"strict"');
else if (line.startsWith('@'))
group.push(line.replace(/@([\w-]+)\/(.*)/, (_, arg1, arg2) => packages.get(arg1) + arg2));
else
@@ -205,13 +210,17 @@ async function innerCheckDeps(root) {
}
function allowImport(from, to, mergedDeps) {
+ const strict = mergedDeps.includes('"strict"');
const fromDirectory = path.dirname(from);
const toDirectory = isDirectory(to) ? to : path.dirname(to);
if (to === toDirectory)
to = path.join(to, 'index.ts');
- if (fromDirectory === toDirectory)
+ if (!strict && fromDirectory === toDirectory)
return true;
+ if (strict)
+ return mergedDeps.includes(to) && calculateDeps(to).includes('"strict"');
+
for (const dep of mergedDeps) {
if (dep === '***')
return true;