diff --git a/cli.js b/cli.js index 95d4dbd..bbda09e 100755 --- a/cli.js +++ b/cli.js @@ -15,4 +15,4 @@ * limitations under the License. */ -require('./lib/program'); +import './lib/program.js'; diff --git a/eslint.config.mjs b/eslint.config.mjs index 3ab4df5..5d015d1 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -33,6 +33,7 @@ const plugins = { }; export const baseRules = { + "import/extensions": ["error", "ignorePackages", {ts: "always"}], "@typescript-eslint/no-floating-promises": "error", "@typescript-eslint/no-unused-vars": [ 2, diff --git a/index.js b/index.js index faf60b5..61f7c07 100755 --- a/index.js +++ b/index.js @@ -15,5 +15,5 @@ * limitations under the License. */ -const { createServer } = require('./lib/index'); -module.exports = { createServer }; +import { createServer } from './lib/index'; +export default { createServer }; diff --git a/package-lock.json b/package-lock.json index f17e1a1..9d5c019 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "zod-to-json-schema": "^3.24.4" }, "bin": { - "mcp-server-playwright": "cli.js" + "mcp-server-playwright": "cli.mjs" }, "devDependencies": { "@eslint/eslintrc": "^3.2.0", diff --git a/package.json b/package.json index 92f442a..76368ce 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "@playwright/mcp", "version": "0.0.18", "description": "Playwright Tools for MCP", + "type": "module", "repository": { "type": "git", "url": "git+https://github.com/microsoft/playwright-mcp.git" diff --git a/src/config.ts b/src/config.ts index 0d4ad7a..590c9df 100644 --- a/src/config.ts +++ b/src/config.ts @@ -20,9 +20,9 @@ import os from 'os'; import path from 'path'; import { devices } from 'playwright'; -import { sanitizeForFilePath } from './tools/utils'; +import { sanitizeForFilePath } from './tools/utils.js'; -import type { Config, ToolCapability } from '../config'; +import type { Config, ToolCapability } from '../config.js'; import type { BrowserContextOptions, LaunchOptions } from 'playwright'; export type CLIOptions = { diff --git a/src/context.ts b/src/context.ts index ba54885..0dd42d3 100644 --- a/src/context.ts +++ b/src/context.ts @@ -16,13 +16,13 @@ import * as playwright from 'playwright'; -import { waitForCompletion } from './tools/utils'; -import { ManualPromise } from './manualPromise'; -import { Tab } from './tab'; +import { waitForCompletion } from './tools/utils.js'; +import { ManualPromise } from './manualPromise.js'; +import { Tab } from './tab.js'; -import type { ImageContent, TextContent } from '@modelcontextprotocol/sdk/types'; -import type { ModalState, Tool, ToolActionResult } from './tools/tool'; -import type { Config } from '../config'; +import type { ImageContent, TextContent } from '@modelcontextprotocol/sdk/types.js'; +import type { ModalState, Tool, ToolActionResult } from './tools/tool.js'; +import type { Config } from '../config.js'; type PendingAction = { dialogShown: ManualPromise; diff --git a/src/index.ts b/src/index.ts index 3dfe1ca..1b45d6b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,22 +14,22 @@ * limitations under the License. */ -import { createServerWithTools } from './server'; -import common from './tools/common'; -import console from './tools/console'; -import dialogs from './tools/dialogs'; -import files from './tools/files'; -import install from './tools/install'; -import keyboard from './tools/keyboard'; -import navigate from './tools/navigate'; -import network from './tools/network'; -import pdf from './tools/pdf'; -import snapshot from './tools/snapshot'; -import tabs from './tools/tabs'; -import screen from './tools/screen'; +import { createServerWithTools } from './server.js'; +import common from './tools/common.js'; +import console from './tools/console.js'; +import dialogs from './tools/dialogs.js'; +import files from './tools/files.js'; +import install from './tools/install.js'; +import keyboard from './tools/keyboard.js'; +import navigate from './tools/navigate.js'; +import network from './tools/network.js'; +import pdf from './tools/pdf.js'; +import snapshot from './tools/snapshot.js'; +import tabs from './tools/tabs.js'; +import screen from './tools/screen.js'; -import type { Tool } from './tools/tool'; -import type { Config } from '../config'; +import type { Tool } from './tools/tool.js'; +import type { Config } from '../config.js'; import type { Server } from '@modelcontextprotocol/sdk/server/index.js'; const snapshotTools: Tool[] = [ @@ -60,7 +60,7 @@ const screenshotTools: Tool[] = [ ...tabs(false), ]; -const packageJSON = require('../package.json'); +import packageJSON from '../package.json' with { type: 'json' }; export async function createServer(config: Config = {}): Promise { const allTools = config.vision ? screenshotTools : snapshotTools; diff --git a/src/program.ts b/src/program.ts index c97fcfe..928d01a 100644 --- a/src/program.ts +++ b/src/program.ts @@ -16,14 +16,14 @@ import { program } from 'commander'; -import { createServer } from './index'; -import { ServerList } from './server'; +import { createServer } from './index.js'; +import { ServerList } from './server.js'; -import { startHttpTransport, startStdioTransport } from './transport'; +import { startHttpTransport, startStdioTransport } from './transport.js'; -import { resolveConfig } from './config'; +import { resolveConfig } from './config.js'; -const packageJSON = require('../package.json'); +import packageJSON from '../package.json' with { type: 'json' }; program .version('Version ' + packageJSON.version) diff --git a/src/resources/resource.ts b/src/resources/resource.ts index d9b19e4..abe0e5b 100644 --- a/src/resources/resource.ts +++ b/src/resources/resource.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import type { Context } from '../context'; +import type { Context } from '../context.js'; export type ResourceSchema = { uri: string; diff --git a/src/server.ts b/src/server.ts index 0c9e58e..5e7da17 100644 --- a/src/server.ts +++ b/src/server.ts @@ -18,10 +18,10 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js'; import { zodToJsonSchema } from 'zod-to-json-schema'; -import { Context } from './context'; +import { Context } from './context.js'; -import type { Tool } from './tools/tool'; -import type { Config } from '../config'; +import type { Tool } from './tools/tool.js'; +import type { Config } from '../config.js'; type MCPServerOptions = { name: string; diff --git a/src/tab.ts b/src/tab.ts index 1ea9cfe..69c27c2 100644 --- a/src/tab.ts +++ b/src/tab.ts @@ -16,9 +16,9 @@ import * as playwright from 'playwright'; -import { PageSnapshot } from './pageSnapshot'; +import { PageSnapshot } from './pageSnapshot.js'; -import type { Context } from './context'; +import type { Context } from './context.js'; export class Tab { readonly context: Context; diff --git a/src/tools/common.ts b/src/tools/common.ts index 269fc0b..a615f0d 100644 --- a/src/tools/common.ts +++ b/src/tools/common.ts @@ -15,7 +15,7 @@ */ import { z } from 'zod'; -import { defineTool, type ToolFactory } from './tool'; +import { defineTool, type ToolFactory } from './tool.js'; const wait: ToolFactory = captureSnapshot => defineTool({ capability: 'wait', diff --git a/src/tools/console.ts b/src/tools/console.ts index 8bec34c..b0c58f5 100644 --- a/src/tools/console.ts +++ b/src/tools/console.ts @@ -15,7 +15,7 @@ */ import { z } from 'zod'; -import { defineTool } from './tool'; +import { defineTool } from './tool.js'; const console = defineTool({ capability: 'core', diff --git a/src/tools/dialogs.ts b/src/tools/dialogs.ts index b9cfffc..62105cc 100644 --- a/src/tools/dialogs.ts +++ b/src/tools/dialogs.ts @@ -15,7 +15,7 @@ */ import { z } from 'zod'; -import { defineTool, type ToolFactory } from './tool'; +import { defineTool, type ToolFactory } from './tool.js'; const handleDialog: ToolFactory = captureSnapshot => defineTool({ capability: 'core', diff --git a/src/tools/files.ts b/src/tools/files.ts index 4c733a3..4ab6d3f 100644 --- a/src/tools/files.ts +++ b/src/tools/files.ts @@ -15,7 +15,7 @@ */ import { z } from 'zod'; -import { defineTool, type ToolFactory } from './tool'; +import { defineTool, type ToolFactory } from './tool.js'; const uploadFile: ToolFactory = captureSnapshot => defineTool({ capability: 'files', diff --git a/src/tools/install.ts b/src/tools/install.ts index 11c9ca6..d6f876a 100644 --- a/src/tools/install.ts +++ b/src/tools/install.ts @@ -18,7 +18,7 @@ import { fork } from 'child_process'; import path from 'path'; import { z } from 'zod'; -import { defineTool } from './tool'; +import { defineTool } from './tool.js'; const install = defineTool({ capability: 'install', diff --git a/src/tools/keyboard.ts b/src/tools/keyboard.ts index 68cb32c..0527cbf 100644 --- a/src/tools/keyboard.ts +++ b/src/tools/keyboard.ts @@ -15,7 +15,7 @@ */ import { z } from 'zod'; -import { defineTool, type ToolFactory } from './tool'; +import { defineTool, type ToolFactory } from './tool.js'; const pressKey: ToolFactory = captureSnapshot => defineTool({ capability: 'core', diff --git a/src/tools/navigate.ts b/src/tools/navigate.ts index e424a11..1279418 100644 --- a/src/tools/navigate.ts +++ b/src/tools/navigate.ts @@ -15,7 +15,7 @@ */ import { z } from 'zod'; -import { defineTool, type ToolFactory } from './tool'; +import { defineTool, type ToolFactory } from './tool.js'; const navigate: ToolFactory = captureSnapshot => defineTool({ capability: 'core', diff --git a/src/tools/network.ts b/src/tools/network.ts index 604eeff..e9499e2 100644 --- a/src/tools/network.ts +++ b/src/tools/network.ts @@ -15,7 +15,7 @@ */ import { z } from 'zod'; -import { defineTool } from './tool'; +import { defineTool } from './tool.js'; import type * as playwright from 'playwright'; diff --git a/src/tools/pdf.ts b/src/tools/pdf.ts index 52cccbf..122ea88 100644 --- a/src/tools/pdf.ts +++ b/src/tools/pdf.ts @@ -15,10 +15,10 @@ */ import { z } from 'zod'; -import { defineTool } from './tool'; +import { defineTool } from './tool.js'; -import * as javascript from '../javascript'; -import { outputFile } from '../config'; +import * as javascript from '../javascript.js'; +import { outputFile } from '../config.js'; const pdf = defineTool({ capability: 'pdf', diff --git a/src/tools/screen.ts b/src/tools/screen.ts index 7e906b9..88ca40c 100644 --- a/src/tools/screen.ts +++ b/src/tools/screen.ts @@ -15,9 +15,9 @@ */ import { z } from 'zod'; -import { defineTool } from './tool'; +import { defineTool } from './tool.js'; -import * as javascript from '../javascript'; +import * as javascript from '../javascript.js'; const elementSchema = z.object({ element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'), diff --git a/src/tools/snapshot.ts b/src/tools/snapshot.ts index 9571c2a..b0a4bd1 100644 --- a/src/tools/snapshot.ts +++ b/src/tools/snapshot.ts @@ -16,9 +16,9 @@ import { z } from 'zod'; -import { defineTool } from './tool'; -import * as javascript from '../javascript'; -import { outputFile } from '../config'; +import { defineTool } from './tool.js'; +import * as javascript from '../javascript.js'; +import { outputFile } from '../config.js'; import type * as playwright from 'playwright'; diff --git a/src/tools/tabs.ts b/src/tools/tabs.ts index 2be1ac4..f2226da 100644 --- a/src/tools/tabs.ts +++ b/src/tools/tabs.ts @@ -15,7 +15,7 @@ */ import { z } from 'zod'; -import { defineTool, type ToolFactory } from './tool'; +import { defineTool, type ToolFactory } from './tool.js'; const listTabs = defineTool({ capability: 'tabs', diff --git a/src/tools/tool.ts b/src/tools/tool.ts index 7caebcb..84e9bce 100644 --- a/src/tools/tool.ts +++ b/src/tools/tool.ts @@ -14,11 +14,11 @@ * limitations under the License. */ -import type { ImageContent, TextContent } from '@modelcontextprotocol/sdk/types'; +import type { ImageContent, TextContent } from '@modelcontextprotocol/sdk/types.js'; import type { z } from 'zod'; -import type { Context } from '../context'; +import type { Context } from '../context.js'; import type * as playwright from 'playwright'; -import type { ToolCapability } from '../../config'; +import type { ToolCapability } from '../../config.js'; export type ToolSchema = { name: string; diff --git a/src/tools/utils.ts b/src/tools/utils.ts index 88150c3..5142bad 100644 --- a/src/tools/utils.ts +++ b/src/tools/utils.ts @@ -15,7 +15,7 @@ */ import type * as playwright from 'playwright'; -import type { Context } from '../context'; +import type { Context } from '../context.js'; export async function waitForCompletion(context: Context, page: playwright.Page, callback: () => Promise): Promise { const requests = new Set(); diff --git a/src/transport.ts b/src/transport.ts index b21db06..266dcf1 100644 --- a/src/transport.ts +++ b/src/transport.ts @@ -18,7 +18,7 @@ import http from 'node:http'; import assert from 'node:assert'; import crypto from 'node:crypto'; -import { ServerList } from './server'; +import { ServerList } from './server.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js'; import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'; diff --git a/tests/capabilities.spec.ts b/tests/capabilities.spec.ts index 389f107..5952d09 100644 --- a/tests/capabilities.spec.ts +++ b/tests/capabilities.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; test('test snapshot tool list', async ({ client }) => { const { tools } = await client.listTools(); diff --git a/tests/cdp.spec.ts b/tests/cdp.spec.ts index c12baf4..7e6d29f 100644 --- a/tests/cdp.spec.ts +++ b/tests/cdp.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; test('cdp server', async ({ cdpEndpoint, startClient }) => { const client = await startClient({ args: [`--cdp-endpoint=${cdpEndpoint}`] }); diff --git a/tests/console.spec.ts b/tests/console.spec.ts index f5f617a..a5db3c1 100644 --- a/tests/console.spec.ts +++ b/tests/console.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; test('browser_console_messages', async ({ client }) => { await client.callTool({ diff --git a/tests/core.spec.ts b/tests/core.spec.ts index 44ab50f..bce5788 100644 --- a/tests/core.spec.ts +++ b/tests/core.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; test('browser_navigate', async ({ client }) => { expect(await client.callTool({ diff --git a/tests/device.spec.ts b/tests/device.spec.ts index 31860bb..8b3c708 100644 --- a/tests/device.spec.ts +++ b/tests/device.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; test('browser_take_screenshot (viewport)', async ({ startClient, server }) => { const client = await startClient({ diff --git a/tests/dialogs.spec.ts b/tests/dialogs.spec.ts index ac9fefb..cb48f33 100644 --- a/tests/dialogs.spec.ts +++ b/tests/dialogs.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; // https://github.com/microsoft/playwright/issues/35663 test.skip(({ mcpBrowser, mcpHeadless }) => mcpBrowser === 'webkit' && mcpHeadless); diff --git a/tests/files.spec.ts b/tests/files.spec.ts index 468f5ff..2672307 100644 --- a/tests/files.spec.ts +++ b/tests/files.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; import fs from 'fs/promises'; test('browser_file_upload', async ({ client }) => { diff --git a/tests/fixtures.ts b/tests/fixtures.ts index adfda76..dcc1481 100644 --- a/tests/fixtures.ts +++ b/tests/fixtures.ts @@ -15,6 +15,7 @@ */ import fs from 'fs'; +import url from 'url'; import path from 'path'; import { chromium } from 'playwright'; @@ -22,7 +23,7 @@ import { test as baseTest, expect as baseExpect } from '@playwright/test'; import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'; import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { spawn } from 'child_process'; -import { TestServer } from './testserver'; +import { TestServer } from './testserver/index.ts'; import type { Config } from '../config'; @@ -69,9 +70,11 @@ export const test = baseTest.extend({ await fs.promises.writeFile(configFile, JSON.stringify(options.config, null, 2)); args.push(`--config=${configFile}`); } + // NOTE: Can be removed when we drop Node.js 18 support and changed to import.meta.filename. + const __filename = url.fileURLToPath(import.meta.url); const transport = new StdioClientTransport({ command: 'node', - args: [path.join(__dirname, '../cli.js'), ...args], + args: [path.join(path.dirname(__filename), '../cli.js'), ...args], }); client = new Client({ name: 'test', version: '1.0.0' }); await client.connect(transport); diff --git a/tests/headed.spec.ts b/tests/headed.spec.ts index 04954c1..82f4a97 100644 --- a/tests/headed.spec.ts +++ b/tests/headed.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; for (const mcpHeadless of [false, true]) { test.describe(`mcpHeadless: ${mcpHeadless}`, () => { diff --git a/tests/iframes.spec.ts b/tests/iframes.spec.ts index 3b55f1b..47245be 100644 --- a/tests/iframes.spec.ts +++ b/tests/iframes.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; test('stitched aria frames', async ({ client }) => { expect(await client.callTool({ diff --git a/tests/launch.spec.ts b/tests/launch.spec.ts index dd78725..bfca616 100644 --- a/tests/launch.spec.ts +++ b/tests/launch.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; test('test reopen browser', async ({ client }) => { await client.callTool({ diff --git a/tests/network.spec.ts b/tests/network.spec.ts index 45c3280..3e67cec 100644 --- a/tests/network.spec.ts +++ b/tests/network.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; test('browser_network_requests', async ({ client, server }) => { server.route('/', (req, res) => { diff --git a/tests/pdf.spec.ts b/tests/pdf.spec.ts index da53e0f..549ae7e 100644 --- a/tests/pdf.spec.ts +++ b/tests/pdf.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; test('save as pdf unavailable', async ({ startClient }) => { const client = await startClient({ args: ['--caps="no-pdf"'] }); diff --git a/tests/screenshot.spec.ts b/tests/screenshot.spec.ts index 0e59837..a6af1c3 100644 --- a/tests/screenshot.spec.ts +++ b/tests/screenshot.spec.ts @@ -16,7 +16,7 @@ import fs from 'fs'; -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; test('browser_take_screenshot (viewport)', async ({ client }) => { expect(await client.callTool({ diff --git a/tests/sse.spec.ts b/tests/sse.spec.ts index eaacd15..84845e7 100644 --- a/tests/sse.spec.ts +++ b/tests/sse.spec.ts @@ -14,14 +14,18 @@ * limitations under the License. */ +import url from 'node:url'; import { spawn } from 'node:child_process'; import path from 'node:path'; -import { test as baseTest } from './fixtures'; +import { test as baseTest } from './fixtures.js'; import { expect } from 'playwright/test'; +// NOTE: Can be removed when we drop Node.js 18 support and changed to import.meta.filename. +const __filename = url.fileURLToPath(import.meta.url); + const test = baseTest.extend<{ serverEndpoint: string }>({ serverEndpoint: async ({}, use) => { - const cp = spawn('node', [path.join(__dirname, '../cli.js'), '--port', '0'], { stdio: 'pipe' }); + const cp = spawn('node', [path.join(path.dirname(__filename), '../cli.js'), '--port', '0'], { stdio: 'pipe' }); try { let stdout = ''; const url = await new Promise(resolve => cp.stdout?.on('data', data => { diff --git a/tests/tabs.spec.ts b/tests/tabs.spec.ts index 5336169..12beed3 100644 --- a/tests/tabs.spec.ts +++ b/tests/tabs.spec.ts @@ -16,7 +16,7 @@ import { chromium } from 'playwright'; -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; import type { Client } from '@modelcontextprotocol/sdk/client/index.js'; diff --git a/tests/testserver/index.ts b/tests/testserver/index.ts index a1d60ec..a4f1e02 100644 --- a/tests/testserver/index.ts +++ b/tests/testserver/index.ts @@ -16,13 +16,18 @@ */ import fs from 'fs'; +import url from 'node:url'; import http from 'http'; import https from 'https'; import path from 'path'; +import debug from 'debug'; const fulfillSymbol = Symbol('fulfil callback'); const rejectSymbol = Symbol('reject callback'); +// NOTE: Can be removed when we drop Node.js 18 support and changed to import.meta.filename. +const __filename = url.fileURLToPath(import.meta.url); + export class TestServer { private _server: http.Server; readonly debugServer: any; @@ -42,8 +47,8 @@ export class TestServer { static async createHTTPS(port: number): Promise { const server = new TestServer(port, { - key: await fs.promises.readFile(path.join(__dirname, 'key.pem')), - cert: await fs.promises.readFile(path.join(__dirname, 'cert.pem')), + key: await fs.promises.readFile(path.join(path.dirname(__filename), 'key.pem')), + cert: await fs.promises.readFile(path.join(path.dirname(__filename), 'cert.pem')), passphrase: 'aaaa', }); await new Promise(x => server._server.once('listening', x)); @@ -56,7 +61,7 @@ export class TestServer { else this._server = http.createServer(this._onRequest.bind(this)); this._server.listen(port); - this.debugServer = require('debug')('pw:testserver'); + this.debugServer = debug('pw:testserver'); const cross_origin = '127.0.0.1'; const same_origin = 'localhost'; diff --git a/tests/webdriver.spec.ts b/tests/webdriver.spec.ts index fca04a9..faf5fdc 100644 --- a/tests/webdriver.spec.ts +++ b/tests/webdriver.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './fixtures'; +import { test, expect } from './fixtures.js'; test('do not falsely advertise user agent as a test driver', async ({ client, server, mcpBrowser }) => { test.skip(mcpBrowser === 'firefox'); diff --git a/tsconfig.json b/tsconfig.json index 7bc09d3..df8a76c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,10 +3,12 @@ "target": "ESNext", "skipLibCheck": true, "esModuleInterop": true, - "moduleResolution": "node", + "moduleResolution": "nodenext", "strict": true, - "module": "CommonJS", - "outDir": "./lib" + "module": "NodeNext", + "rootDir": "src", + "outDir": "./lib", + "resolveJsonModule": true }, "include": [ "src", diff --git a/utils/update-readme.js b/utils/update-readme.js index 31d1120..93513df 100644 --- a/utils/update-readme.js +++ b/utils/update-readme.js @@ -16,21 +16,22 @@ */ // @ts-check -const fs = require('node:fs'); -const path = require('node:path'); -const zodToJsonSchema = require('zod-to-json-schema').default; +import fs from 'node:fs' +import path from 'node:path' +import url from 'node:url' +import zodToJsonSchema from 'zod-to-json-schema' -const commonTools = require('../lib/tools/common').default; -const consoleTools = require('../lib/tools/console').default; -const dialogsTools = require('../lib/tools/dialogs').default; -const filesTools = require('../lib/tools/files').default; -const installTools = require('../lib/tools/install').default; -const keyboardTools = require('../lib/tools/keyboard').default; -const navigateTools = require('../lib/tools/navigate').default; -const pdfTools = require('../lib/tools/pdf').default; -const snapshotTools = require('../lib/tools/snapshot').default; -const tabsTools = require('../lib/tools/tabs').default; -const screenTools = require('../lib/tools/screen').default; +import commonTools from '../lib/tools/common.js'; +import consoleTools from '../lib/tools/console.js'; +import dialogsTools from '../lib/tools/dialogs.js'; +import filesTools from '../lib/tools/files.js'; +import installTools from '../lib/tools/install.js'; +import keyboardTools from '../lib/tools/keyboard.js'; +import navigateTools from '../lib/tools/navigate.js'; +import pdfTools from '../lib/tools/pdf.js'; +import snapshotTools from '../lib/tools/snapshot.js'; +import tabsTools from '../lib/tools/tabs.js'; +import screenTools from '../lib/tools/screen.js'; // Category definitions for tools const categories = { @@ -63,6 +64,9 @@ const categories = { ], }; +// NOTE: Can be removed when we drop Node.js 18 support and changed to import.meta.filename. +const __filename = url.fileURLToPath(import.meta.url); + const kStartMarker = ``; const kEndMarker = ``; @@ -152,7 +156,7 @@ async function updateReadme() { } } - const readmePath = path.join(__dirname, '..', 'README.md'); + const readmePath = path.join(path.dirname(__filename), '..', 'README.md'); const readmeContent = await fs.promises.readFile(readmePath, 'utf-8'); const startMarker = readmeContent.indexOf(kStartMarker); const endMarker = readmeContent.indexOf(kEndMarker);