chore: align lint w/ playwright (#729)

This commit is contained in:
Pavel Feldman 2025-07-21 17:07:13 -07:00 committed by GitHub
parent eeeab4f042
commit f1826b96b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 46 additions and 19 deletions

View File

@ -192,6 +192,31 @@ const languageOptions = {
}
};
const importOrderRules = {
"import/order": [
2,
{
groups: [
"builtin",
"external",
"internal",
["parent", "sibling"],
"index",
"type",
],
},
],
"import/consistent-type-specifier-style": [2, "prefer-top-level"],
};
const noFloatingPromisesRules = {
"@typescript-eslint/no-floating-promises": "error",
};
const noBooleanCompareRules = {
"@typescript-eslint/no-unnecessary-boolean-literal-compare": 2,
};
export default [
{
ignores: ["**/*.js"],
@ -200,6 +225,11 @@ export default [
files: ["**/*.ts", "**/*.tsx"],
plugins,
languageOptions,
rules: baseRules,
rules: {
...baseRules,
...importOrderRules,
...noFloatingPromisesRules,
...noBooleanCompareRules,
},
},
];

View File

@ -18,10 +18,9 @@ import fs from 'fs';
import os from 'os';
import path from 'path';
import { devices } from 'playwright';
import { sanitizeForFilePath } from './tools/utils.js';
import type { Config, ToolCapability } from '../config.js';
import type { BrowserContextOptions, LaunchOptions } from 'playwright';
import { sanitizeForFilePath } from './tools/utils.js';
export type CLIOptions = {
allowedOrigins?: string[];

View File

@ -22,15 +22,15 @@
* - /extension/guid - Extension connection for chrome.debugger forwarding
*/
import http from 'http';
import { promisify } from 'util';
import { exec } from 'child_process';
import { WebSocket, WebSocketServer } from 'ws';
import type websocket from 'ws';
import http from 'node:http';
import debug from 'debug';
import { promisify } from 'node:util';
import { exec } from 'node:child_process';
import * as playwright from 'playwright';
import { httpAddressToString, startHttpServer } from '../transport.js';
import { BrowserContextFactory } from '../browserContextFactory.js';
import { Browser, chromium, type BrowserContext } from 'playwright';
import type websocket from 'ws';
const debugLogger = debug('pw:mcp:relay');
@ -284,13 +284,13 @@ export class CDPRelayServer {
class ExtensionContextFactory implements BrowserContextFactory {
private _relay: CDPRelayServer;
private _browserPromise: Promise<Browser> | undefined;
private _browserPromise: Promise<playwright.Browser> | undefined;
constructor(relay: CDPRelayServer) {
this._relay = relay;
}
async createContext(clientInfo: { name: string, version: string }): Promise<{ browserContext: BrowserContext, close: () => Promise<void> }> {
async createContext(clientInfo: { name: string, version: string }): Promise<{ browserContext: playwright.BrowserContext, close: () => Promise<void> }> {
// First call will establish the connection to the extension.
if (!this._browserPromise)
this._browserPromise = this._obtainBrowser(clientInfo);
@ -301,9 +301,9 @@ class ExtensionContextFactory implements BrowserContextFactory {
};
}
private async _obtainBrowser(clientInfo: { name: string, version: string }): Promise<Browser> {
private async _obtainBrowser(clientInfo: { name: string, version: string }): Promise<playwright.Browser> {
await this._relay.ensureExtensionConnectionForMCPContext(clientInfo);
return await chromium.connectOverCDP(this._relay.cdpEndpoint());
return await playwright.chromium.connectOverCDP(this._relay.cdpEndpoint());
}
}

View File

@ -15,10 +15,9 @@
*/
import { createConnection as createConnectionImpl } from './connection.js';
import type { Connection } from '../index.js';
import { resolveConfig } from './config.js';
import { contextFactory } from './browserContextFactory.js';
import type { Connection } from '../index.js';
import type { Config } from '../config.js';
import type { BrowserContext } from 'playwright';
import type { BrowserContextFactory } from './browserContextFactory.js';

View File

@ -16,11 +16,10 @@
import { fork } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';
import { z } from 'zod';
import { defineTool } from './tool.js';
import { fileURLToPath } from 'node:url';
const install = defineTool({
capability: 'core-install',

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
import { test, expect } from './fixtures.js';
import fs from 'fs/promises';
import { test, expect } from './fixtures.js';
test('browser_file_upload', async ({ client, server }, testInfo) => {
server.setContent('/', `

View File

@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import child_process from 'child_process';
import fs from 'fs/promises';
import { test, expect } from './fixtures.js';
import fs from 'node:fs/promises';
import child_process from 'node:child_process';
test('library can be used from CommonJS', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright-mcp/issues/456' } }, async ({}, testInfo) => {
const file = testInfo.outputPath('main.cjs');