@cotestdev/mcp_playwright 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/util.js ADDED
@@ -0,0 +1,397 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var util_exports = {};
30
+ __export(util_exports, {
31
+ addSuffixToFilePath: () => addSuffixToFilePath,
32
+ ansiRegex: () => ansiRegex,
33
+ createFileFiltersFromArguments: () => createFileFiltersFromArguments,
34
+ createFileMatcher: () => createFileMatcher,
35
+ createFileMatcherFromArguments: () => createFileMatcherFromArguments,
36
+ createTitleMatcher: () => createTitleMatcher,
37
+ debugTest: () => debugTest,
38
+ errorWithFile: () => errorWithFile,
39
+ expectTypes: () => expectTypes,
40
+ fileExistsAsync: () => fileExistsAsync,
41
+ fileIsModule: () => fileIsModule,
42
+ filterStackFile: () => filterStackFile,
43
+ filterStackTrace: () => filterStackTrace,
44
+ filteredStackTrace: () => filteredStackTrace,
45
+ forceRegExp: () => forceRegExp,
46
+ formatLocation: () => formatLocation,
47
+ getContainedPath: () => getContainedPath,
48
+ getPackageJsonPath: () => getPackageJsonPath,
49
+ mergeObjects: () => mergeObjects,
50
+ normalizeAndSaveAttachment: () => normalizeAndSaveAttachment,
51
+ relativeFilePath: () => relativeFilePath,
52
+ removeDirAndLogToConsole: () => removeDirAndLogToConsole,
53
+ resolveImportSpecifierAfterMapping: () => resolveImportSpecifierAfterMapping,
54
+ resolveReporterOutputPath: () => resolveReporterOutputPath,
55
+ sanitizeFilePathBeforeExtension: () => sanitizeFilePathBeforeExtension,
56
+ serializeError: () => serializeError,
57
+ stripAnsiEscapes: () => stripAnsiEscapes,
58
+ trimLongString: () => trimLongString,
59
+ windowsFilesystemFriendlyLength: () => windowsFilesystemFriendlyLength
60
+ });
61
+ module.exports = __toCommonJS(util_exports);
62
+ var import_fs = __toESM(require("fs"));
63
+ var import_path = __toESM(require("path"));
64
+ var import_url = __toESM(require("url"));
65
+ var import_util = __toESM(require("util"));
66
+ var import_utils = require("playwright-core/lib/utils");
67
+ var import_utilsBundle = require("playwright-core/lib/utilsBundle");
68
+ const PLAYWRIGHT_TEST_PATH = import_path.default.join(__dirname, "..");
69
+ const PLAYWRIGHT_CORE_PATH = import_path.default.dirname(require.resolve("playwright-core/package.json"));
70
+ function filterStackTrace(e) {
71
+ const name = e.name ? e.name + ": " : "";
72
+ const cause = e.cause instanceof Error ? filterStackTrace(e.cause) : void 0;
73
+ if (process.env.PWDEBUGIMPL)
74
+ return { message: name + e.message, stack: e.stack || "", cause };
75
+ const stackLines = (0, import_utils.stringifyStackFrames)(filteredStackTrace(e.stack?.split("\n") || []));
76
+ return {
77
+ message: name + e.message,
78
+ stack: `${name}${e.message}${stackLines.map((line) => "\n" + line).join("")}`,
79
+ cause
80
+ };
81
+ }
82
+ function filterStackFile(file) {
83
+ if (!process.env.PWDEBUGIMPL && file.startsWith(PLAYWRIGHT_TEST_PATH))
84
+ return false;
85
+ if (!process.env.PWDEBUGIMPL && file.startsWith(PLAYWRIGHT_CORE_PATH))
86
+ return false;
87
+ return true;
88
+ }
89
+ function filteredStackTrace(rawStack) {
90
+ const frames = [];
91
+ for (const line of rawStack) {
92
+ const frame = (0, import_utils.parseStackFrame)(line, import_path.default.sep, !!process.env.PWDEBUGIMPL);
93
+ if (!frame || !frame.file)
94
+ continue;
95
+ if (!filterStackFile(frame.file))
96
+ continue;
97
+ frames.push(frame);
98
+ }
99
+ return frames;
100
+ }
101
+ function serializeError(error) {
102
+ if (error instanceof Error)
103
+ return filterStackTrace(error);
104
+ return {
105
+ value: import_util.default.inspect(error)
106
+ };
107
+ }
108
+ function createFileFiltersFromArguments(args) {
109
+ return args.map((arg) => {
110
+ const match = /^(.*?):(\d+):?(\d+)?$/.exec(arg);
111
+ return {
112
+ re: forceRegExp(match ? match[1] : arg),
113
+ line: match ? parseInt(match[2], 10) : null,
114
+ column: match?.[3] ? parseInt(match[3], 10) : null
115
+ };
116
+ });
117
+ }
118
+ function createFileMatcherFromArguments(args) {
119
+ const filters = createFileFiltersFromArguments(args);
120
+ return createFileMatcher(filters.map((filter) => filter.re || filter.exact || ""));
121
+ }
122
+ function createFileMatcher(patterns) {
123
+ const reList = [];
124
+ const filePatterns = [];
125
+ for (const pattern of Array.isArray(patterns) ? patterns : [patterns]) {
126
+ if ((0, import_utils.isRegExp)(pattern)) {
127
+ reList.push(pattern);
128
+ } else {
129
+ if (!pattern.startsWith("**/"))
130
+ filePatterns.push("**/" + pattern);
131
+ else
132
+ filePatterns.push(pattern);
133
+ }
134
+ }
135
+ return (filePath) => {
136
+ for (const re of reList) {
137
+ re.lastIndex = 0;
138
+ if (re.test(filePath))
139
+ return true;
140
+ }
141
+ if (import_path.default.sep === "\\") {
142
+ const fileURL = import_url.default.pathToFileURL(filePath).href;
143
+ for (const re of reList) {
144
+ re.lastIndex = 0;
145
+ if (re.test(fileURL))
146
+ return true;
147
+ }
148
+ }
149
+ for (const pattern of filePatterns) {
150
+ if ((0, import_utilsBundle.minimatch)(filePath, pattern, { nocase: true, dot: true }))
151
+ return true;
152
+ }
153
+ return false;
154
+ };
155
+ }
156
+ function createTitleMatcher(patterns) {
157
+ const reList = Array.isArray(patterns) ? patterns : [patterns];
158
+ return (value) => {
159
+ for (const re of reList) {
160
+ re.lastIndex = 0;
161
+ if (re.test(value))
162
+ return true;
163
+ }
164
+ return false;
165
+ };
166
+ }
167
+ function mergeObjects(a, b, c) {
168
+ const result = { ...a };
169
+ for (const x of [b, c].filter(Boolean)) {
170
+ for (const [name, value] of Object.entries(x)) {
171
+ if (!Object.is(value, void 0))
172
+ result[name] = value;
173
+ }
174
+ }
175
+ return result;
176
+ }
177
+ function forceRegExp(pattern) {
178
+ const match = pattern.match(/^\/(.*)\/([gi]*)$/);
179
+ if (match)
180
+ return new RegExp(match[1], match[2]);
181
+ return new RegExp(pattern, "gi");
182
+ }
183
+ function relativeFilePath(file) {
184
+ if (!import_path.default.isAbsolute(file))
185
+ return file;
186
+ return import_path.default.relative(process.cwd(), file);
187
+ }
188
+ function formatLocation(location) {
189
+ return relativeFilePath(location.file) + ":" + location.line + ":" + location.column;
190
+ }
191
+ function errorWithFile(file, message) {
192
+ return new Error(`${relativeFilePath(file)}: ${message}`);
193
+ }
194
+ function expectTypes(receiver, types, matcherName) {
195
+ if (typeof receiver !== "object" || !types.includes(receiver.constructor.name)) {
196
+ const commaSeparated = types.slice();
197
+ const lastType = commaSeparated.pop();
198
+ const typesString = commaSeparated.length ? commaSeparated.join(", ") + " or " + lastType : lastType;
199
+ throw new Error(`${matcherName} can be only used with ${typesString} object${types.length > 1 ? "s" : ""}`);
200
+ }
201
+ }
202
+ const windowsFilesystemFriendlyLength = 60;
203
+ function trimLongString(s, length = 100) {
204
+ if (s.length <= length)
205
+ return s;
206
+ const hash = (0, import_utils.calculateSha1)(s);
207
+ const middle = `-${hash.substring(0, 5)}-`;
208
+ const start = Math.floor((length - middle.length) / 2);
209
+ const end = length - middle.length - start;
210
+ return s.substring(0, start) + middle + s.slice(-end);
211
+ }
212
+ function addSuffixToFilePath(filePath, suffix) {
213
+ const ext = import_path.default.extname(filePath);
214
+ const base = filePath.substring(0, filePath.length - ext.length);
215
+ return base + suffix + ext;
216
+ }
217
+ function sanitizeFilePathBeforeExtension(filePath, ext) {
218
+ ext ??= import_path.default.extname(filePath);
219
+ const base = filePath.substring(0, filePath.length - ext.length);
220
+ return (0, import_utils.sanitizeForFilePath)(base) + ext;
221
+ }
222
+ function getContainedPath(parentPath, subPath = "") {
223
+ const resolvedPath = import_path.default.resolve(parentPath, subPath);
224
+ if (resolvedPath === parentPath || resolvedPath.startsWith(parentPath + import_path.default.sep))
225
+ return resolvedPath;
226
+ return null;
227
+ }
228
+ const debugTest = (0, import_utilsBundle.debug)("pw:test");
229
+ const folderToPackageJsonPath = /* @__PURE__ */ new Map();
230
+ function getPackageJsonPath(folderPath) {
231
+ const cached = folderToPackageJsonPath.get(folderPath);
232
+ if (cached !== void 0)
233
+ return cached;
234
+ const packageJsonPath = import_path.default.join(folderPath, "package.json");
235
+ if (import_fs.default.existsSync(packageJsonPath)) {
236
+ folderToPackageJsonPath.set(folderPath, packageJsonPath);
237
+ return packageJsonPath;
238
+ }
239
+ const parentFolder = import_path.default.dirname(folderPath);
240
+ if (folderPath === parentFolder) {
241
+ folderToPackageJsonPath.set(folderPath, "");
242
+ return "";
243
+ }
244
+ const result = getPackageJsonPath(parentFolder);
245
+ folderToPackageJsonPath.set(folderPath, result);
246
+ return result;
247
+ }
248
+ function resolveReporterOutputPath(defaultValue, configDir, configValue) {
249
+ if (configValue)
250
+ return import_path.default.resolve(configDir, configValue);
251
+ let basePath = getPackageJsonPath(configDir);
252
+ basePath = basePath ? import_path.default.dirname(basePath) : process.cwd();
253
+ return import_path.default.resolve(basePath, defaultValue);
254
+ }
255
+ async function normalizeAndSaveAttachment(outputPath, name, options = {}) {
256
+ if (options.path === void 0 && options.body === void 0)
257
+ return { name, contentType: "text/plain" };
258
+ if ((options.path !== void 0 ? 1 : 0) + (options.body !== void 0 ? 1 : 0) !== 1)
259
+ throw new Error(`Exactly one of "path" and "body" must be specified`);
260
+ if (options.path !== void 0) {
261
+ const hash = (0, import_utils.calculateSha1)(options.path);
262
+ if (!(0, import_utils.isString)(name))
263
+ throw new Error('"name" should be string.');
264
+ const sanitizedNamePrefix = (0, import_utils.sanitizeForFilePath)(name) + "-";
265
+ const dest = import_path.default.join(outputPath, "attachments", sanitizedNamePrefix + hash + import_path.default.extname(options.path));
266
+ await import_fs.default.promises.mkdir(import_path.default.dirname(dest), { recursive: true });
267
+ await import_fs.default.promises.copyFile(options.path, dest);
268
+ const contentType = options.contentType ?? (import_utilsBundle.mime.getType(import_path.default.basename(options.path)) || "application/octet-stream");
269
+ return { name, contentType, path: dest };
270
+ } else {
271
+ const contentType = options.contentType ?? (typeof options.body === "string" ? "text/plain" : "application/octet-stream");
272
+ return { name, contentType, body: typeof options.body === "string" ? Buffer.from(options.body) : options.body };
273
+ }
274
+ }
275
+ function fileIsModule(file) {
276
+ if (file.endsWith(".mjs") || file.endsWith(".mts"))
277
+ return true;
278
+ if (file.endsWith(".cjs") || file.endsWith(".cts"))
279
+ return false;
280
+ const folder = import_path.default.dirname(file);
281
+ return folderIsModule(folder);
282
+ }
283
+ function folderIsModule(folder) {
284
+ const packageJsonPath = getPackageJsonPath(folder);
285
+ if (!packageJsonPath)
286
+ return false;
287
+ return require(packageJsonPath).type === "module";
288
+ }
289
+ const packageJsonMainFieldCache = /* @__PURE__ */ new Map();
290
+ function getMainFieldFromPackageJson(packageJsonPath) {
291
+ if (!packageJsonMainFieldCache.has(packageJsonPath)) {
292
+ let mainField;
293
+ try {
294
+ mainField = JSON.parse(import_fs.default.readFileSync(packageJsonPath, "utf8")).main;
295
+ } catch {
296
+ }
297
+ packageJsonMainFieldCache.set(packageJsonPath, mainField);
298
+ }
299
+ return packageJsonMainFieldCache.get(packageJsonPath);
300
+ }
301
+ const kExtLookups = /* @__PURE__ */ new Map([
302
+ [".js", [".jsx", ".ts", ".tsx"]],
303
+ [".jsx", [".tsx"]],
304
+ [".cjs", [".cts"]],
305
+ [".mjs", [".mts"]],
306
+ ["", [".js", ".ts", ".jsx", ".tsx", ".cjs", ".mjs", ".cts", ".mts"]]
307
+ ]);
308
+ function resolveImportSpecifierExtension(resolved) {
309
+ if (fileExists(resolved))
310
+ return resolved;
311
+ for (const [ext, others] of kExtLookups) {
312
+ if (!resolved.endsWith(ext))
313
+ continue;
314
+ for (const other of others) {
315
+ const modified = resolved.substring(0, resolved.length - ext.length) + other;
316
+ if (fileExists(modified))
317
+ return modified;
318
+ }
319
+ break;
320
+ }
321
+ }
322
+ function resolveImportSpecifierAfterMapping(resolved, afterPathMapping) {
323
+ const resolvedFile = resolveImportSpecifierExtension(resolved);
324
+ if (resolvedFile)
325
+ return resolvedFile;
326
+ if (dirExists(resolved)) {
327
+ const packageJsonPath = import_path.default.join(resolved, "package.json");
328
+ if (afterPathMapping) {
329
+ const mainField = getMainFieldFromPackageJson(packageJsonPath);
330
+ const mainFieldResolved = mainField ? resolveImportSpecifierExtension(import_path.default.resolve(resolved, mainField)) : void 0;
331
+ return mainFieldResolved || resolveImportSpecifierExtension(import_path.default.join(resolved, "index"));
332
+ }
333
+ if (fileExists(packageJsonPath))
334
+ return resolved;
335
+ const dirImport = import_path.default.join(resolved, "index");
336
+ return resolveImportSpecifierExtension(dirImport);
337
+ }
338
+ }
339
+ function fileExists(resolved) {
340
+ return import_fs.default.statSync(resolved, { throwIfNoEntry: false })?.isFile();
341
+ }
342
+ async function fileExistsAsync(resolved) {
343
+ try {
344
+ const stat = await import_fs.default.promises.stat(resolved);
345
+ return stat.isFile();
346
+ } catch {
347
+ return false;
348
+ }
349
+ }
350
+ function dirExists(resolved) {
351
+ return import_fs.default.statSync(resolved, { throwIfNoEntry: false })?.isDirectory();
352
+ }
353
+ async function removeDirAndLogToConsole(dir) {
354
+ try {
355
+ if (!import_fs.default.existsSync(dir))
356
+ return;
357
+ console.log(`Removing ${await import_fs.default.promises.realpath(dir)}`);
358
+ await import_fs.default.promises.rm(dir, { recursive: true, force: true });
359
+ } catch {
360
+ }
361
+ }
362
+ const ansiRegex = new RegExp("([\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~])))", "g");
363
+ function stripAnsiEscapes(str) {
364
+ return str.replace(ansiRegex, "");
365
+ }
366
+ // Annotate the CommonJS export names for ESM import in node:
367
+ 0 && (module.exports = {
368
+ addSuffixToFilePath,
369
+ ansiRegex,
370
+ createFileFiltersFromArguments,
371
+ createFileMatcher,
372
+ createFileMatcherFromArguments,
373
+ createTitleMatcher,
374
+ debugTest,
375
+ errorWithFile,
376
+ expectTypes,
377
+ fileExistsAsync,
378
+ fileIsModule,
379
+ filterStackFile,
380
+ filterStackTrace,
381
+ filteredStackTrace,
382
+ forceRegExp,
383
+ formatLocation,
384
+ getContainedPath,
385
+ getPackageJsonPath,
386
+ mergeObjects,
387
+ normalizeAndSaveAttachment,
388
+ relativeFilePath,
389
+ removeDirAndLogToConsole,
390
+ resolveImportSpecifierAfterMapping,
391
+ resolveReporterOutputPath,
392
+ sanitizeFilePathBeforeExtension,
393
+ serializeError,
394
+ stripAnsiEscapes,
395
+ trimLongString,
396
+ windowsFilesystemFriendlyLength
397
+ });
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var utilsBundle_exports = {};
20
+ __export(utilsBundle_exports, {
21
+ chokidar: () => chokidar,
22
+ enquirer: () => enquirer,
23
+ getEastAsianWidth: () => getEastAsianWidth,
24
+ json5: () => json5,
25
+ sourceMapSupport: () => sourceMapSupport,
26
+ stoppable: () => stoppable
27
+ });
28
+ module.exports = __toCommonJS(utilsBundle_exports);
29
+ const json5 = require("./utilsBundleImpl").json5;
30
+ const sourceMapSupport = require("./utilsBundleImpl").sourceMapSupport;
31
+ const stoppable = require("./utilsBundleImpl").stoppable;
32
+ const enquirer = require("./utilsBundleImpl").enquirer;
33
+ const chokidar = require("./utilsBundleImpl").chokidar;
34
+ const getEastAsianWidth = require("./utilsBundleImpl").getEastAsianWidth;
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ chokidar,
38
+ enquirer,
39
+ getEastAsianWidth,
40
+ json5,
41
+ sourceMapSupport,
42
+ stoppable
43
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cotestdev/mcp_playwright",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Playwright MCP (Model Context Protocol) tools for browser automation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",