@cotestdev/mcp_playwright 0.0.10 → 0.0.12
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/mcp/cli.js +8 -1
- package/lib/mcp/config.d.js +16 -0
- package/lib/mcp/index.js +61 -0
- package/lib/mcp/log.js +35 -0
- package/lib/mcp/test/browserBackend.js +92 -0
- package/lib/mcp/test/streams.js +41 -0
- package/lib/mcp/test/testBackend.js +79 -0
- package/lib/mcp/test/testContext.js +50 -0
- package/lib/mcp/test/testTool.js +30 -0
- package/lib/mcp/test/testTools.js +194 -0
- package/lib/mcp/vscode/host.js +187 -0
- package/lib/mcp/vscode/main.js +77 -0
- package/lib/util.js +397 -0
- package/lib/utilsBundle.js +43 -0
- package/package.json +1 -1
package/lib/mcp/cli.js
CHANGED
|
@@ -15,5 +15,12 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
const { program } = require('
|
|
18
|
+
const { program } = require('playwright-core/lib/cli/program');
|
|
19
|
+
const { decorateCommand } = require('./program');
|
|
20
|
+
const packageJSON = require('../../package.json');
|
|
21
|
+
|
|
22
|
+
const command = program.command('run-mcp-server');
|
|
23
|
+
command.description('Interact with the browser over MCP');
|
|
24
|
+
decorateCommand(command, packageJSON.version);
|
|
25
|
+
|
|
19
26
|
program.parse(process.argv);
|
|
@@ -0,0 +1,16 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var config_d_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(config_d_exports);
|
package/lib/mcp/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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 mcp_exports = {};
|
|
30
|
+
__export(mcp_exports, {
|
|
31
|
+
createConnection: () => createConnection
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(mcp_exports);
|
|
34
|
+
var import_browserServerBackend = require("./browser/browserServerBackend");
|
|
35
|
+
var import_config = require("./browser/config");
|
|
36
|
+
var import_browserContextFactory = require("./browser/browserContextFactory");
|
|
37
|
+
var mcpServer = __toESM(require("./sdk/server"));
|
|
38
|
+
const packageJSON = require("../../package.json");
|
|
39
|
+
async function createConnection(userConfig = {}, contextGetter) {
|
|
40
|
+
const config = await (0, import_config.resolveConfig)(userConfig);
|
|
41
|
+
const factory = contextGetter ? new SimpleBrowserContextFactory(contextGetter) : (0, import_browserContextFactory.contextFactory)(config);
|
|
42
|
+
return mcpServer.createServer("Playwright", packageJSON.version, new import_browserServerBackend.BrowserServerBackend(config, factory), false);
|
|
43
|
+
}
|
|
44
|
+
class SimpleBrowserContextFactory {
|
|
45
|
+
constructor(contextGetter) {
|
|
46
|
+
this.name = "custom";
|
|
47
|
+
this.description = "Connect to a browser using a custom context getter";
|
|
48
|
+
this._contextGetter = contextGetter;
|
|
49
|
+
}
|
|
50
|
+
async createContext() {
|
|
51
|
+
const browserContext = await this._contextGetter();
|
|
52
|
+
return {
|
|
53
|
+
browserContext,
|
|
54
|
+
close: () => browserContext.close()
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
createConnection
|
|
61
|
+
});
|
package/lib/mcp/log.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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 log_exports = {};
|
|
20
|
+
__export(log_exports, {
|
|
21
|
+
logUnhandledError: () => logUnhandledError,
|
|
22
|
+
testDebug: () => testDebug
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(log_exports);
|
|
25
|
+
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
|
|
26
|
+
const errorsDebug = (0, import_utilsBundle.debug)("pw:mcp:errors");
|
|
27
|
+
function logUnhandledError(error) {
|
|
28
|
+
errorsDebug(error);
|
|
29
|
+
}
|
|
30
|
+
const testDebug = (0, import_utilsBundle.debug)("pw:mcp:test");
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
logUnhandledError,
|
|
34
|
+
testDebug
|
|
35
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
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 browserBackend_exports = {};
|
|
30
|
+
__export(browserBackend_exports, {
|
|
31
|
+
runBrowserBackendAtEnd: () => runBrowserBackendAtEnd,
|
|
32
|
+
runBrowserBackendOnError: () => runBrowserBackendOnError
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(browserBackend_exports);
|
|
35
|
+
var mcp = __toESM(require("../sdk/exports"));
|
|
36
|
+
var import_globals = require("../../common/globals");
|
|
37
|
+
var import_util = require("../../util");
|
|
38
|
+
var import_config = require("../browser/config");
|
|
39
|
+
var import_browserServerBackend = require("../browser/browserServerBackend");
|
|
40
|
+
async function runBrowserBackendOnError(page, message) {
|
|
41
|
+
const testInfo = (0, import_globals.currentTestInfo)();
|
|
42
|
+
if (!testInfo || !testInfo._pauseOnError())
|
|
43
|
+
return;
|
|
44
|
+
const config = {
|
|
45
|
+
...import_config.defaultConfig,
|
|
46
|
+
capabilities: ["testing"]
|
|
47
|
+
};
|
|
48
|
+
const snapshot = await page._snapshotForAI();
|
|
49
|
+
const introMessage = `### Paused on error:
|
|
50
|
+
${(0, import_util.stripAnsiEscapes)(message())}
|
|
51
|
+
|
|
52
|
+
### Current page snapshot:
|
|
53
|
+
${snapshot}
|
|
54
|
+
|
|
55
|
+
### Task
|
|
56
|
+
Try recovering from the error prior to continuing`;
|
|
57
|
+
await mcp.runOnPauseBackendLoop(new import_browserServerBackend.BrowserServerBackend(config, identityFactory(page.context())), introMessage);
|
|
58
|
+
}
|
|
59
|
+
async function runBrowserBackendAtEnd(context) {
|
|
60
|
+
const testInfo = (0, import_globals.currentTestInfo)();
|
|
61
|
+
if (!testInfo || !testInfo._pauseAtEnd())
|
|
62
|
+
return;
|
|
63
|
+
const page = context.pages()[0];
|
|
64
|
+
if (!page)
|
|
65
|
+
return;
|
|
66
|
+
const snapshot = await page._snapshotForAI();
|
|
67
|
+
const introMessage = `### Paused at end of test. ready for interaction
|
|
68
|
+
|
|
69
|
+
### Current page snapshot:
|
|
70
|
+
${snapshot}`;
|
|
71
|
+
const config = {
|
|
72
|
+
...import_config.defaultConfig,
|
|
73
|
+
capabilities: ["testing"]
|
|
74
|
+
};
|
|
75
|
+
await mcp.runOnPauseBackendLoop(new import_browserServerBackend.BrowserServerBackend(config, identityFactory(context)), introMessage);
|
|
76
|
+
}
|
|
77
|
+
function identityFactory(browserContext) {
|
|
78
|
+
return {
|
|
79
|
+
createContext: async (clientInfo, abortSignal, toolName) => {
|
|
80
|
+
return {
|
|
81
|
+
browserContext,
|
|
82
|
+
close: async () => {
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
runBrowserBackendAtEnd,
|
|
91
|
+
runBrowserBackendOnError
|
|
92
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
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 streams_exports = {};
|
|
20
|
+
__export(streams_exports, {
|
|
21
|
+
StringWriteStream: () => StringWriteStream
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(streams_exports);
|
|
24
|
+
var import_stream = require("stream");
|
|
25
|
+
class StringWriteStream extends import_stream.Writable {
|
|
26
|
+
constructor() {
|
|
27
|
+
super(...arguments);
|
|
28
|
+
this._chunks = [];
|
|
29
|
+
}
|
|
30
|
+
_write(chunk, encoding, callback) {
|
|
31
|
+
this._chunks.push(chunk.toString());
|
|
32
|
+
callback();
|
|
33
|
+
}
|
|
34
|
+
content() {
|
|
35
|
+
return this._chunks.join("");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
StringWriteStream
|
|
41
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
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 testBackend_exports = {};
|
|
30
|
+
__export(testBackend_exports, {
|
|
31
|
+
TestServerBackend: () => TestServerBackend
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(testBackend_exports);
|
|
34
|
+
var mcp = __toESM(require("../sdk/exports"));
|
|
35
|
+
var import_testContext = require("./testContext");
|
|
36
|
+
var import_testTools = require("./testTools.js");
|
|
37
|
+
var import_tools = require("../browser/tools");
|
|
38
|
+
var import_configLoader = require("../../common/configLoader");
|
|
39
|
+
class TestServerBackend {
|
|
40
|
+
constructor(configOption, options) {
|
|
41
|
+
this.name = "Playwright";
|
|
42
|
+
this.version = "0.0.1";
|
|
43
|
+
this._tools = [import_testTools.listTests, import_testTools.runTests, import_testTools.debugTest, import_testTools.setupPage];
|
|
44
|
+
this._context = new import_testContext.TestContext(options);
|
|
45
|
+
this._configOption = configOption;
|
|
46
|
+
}
|
|
47
|
+
async initialize(server, clientInfo) {
|
|
48
|
+
if (this._configOption) {
|
|
49
|
+
this._context.setConfigLocation((0, import_configLoader.resolveConfigLocation)(this._configOption));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const rootPath = mcp.firstRootPath(clientInfo);
|
|
53
|
+
if (rootPath) {
|
|
54
|
+
this._context.setConfigLocation((0, import_configLoader.resolveConfigLocation)(rootPath));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
throw new Error("No config option or MCP root path provided");
|
|
58
|
+
}
|
|
59
|
+
async listTools() {
|
|
60
|
+
return [
|
|
61
|
+
...this._tools.map((tool) => mcp.toMcpTool(tool.schema)),
|
|
62
|
+
...import_tools.browserTools.map((tool) => mcp.toMcpTool(tool.schema))
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
async callTool(name, args) {
|
|
66
|
+
const tool = this._tools.find((tool2) => tool2.schema.name === name);
|
|
67
|
+
if (!tool)
|
|
68
|
+
throw new Error(`Tool not found: ${name}. Available tools: ${this._tools.map((tool2) => tool2.schema.name).join(", ")}`);
|
|
69
|
+
const parsedArguments = tool.schema.inputSchema.parse(args || {});
|
|
70
|
+
return await tool.handle(this._context, parsedArguments);
|
|
71
|
+
}
|
|
72
|
+
serverClosed() {
|
|
73
|
+
void this._context.close();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
TestServerBackend
|
|
79
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
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 testContext_exports = {};
|
|
20
|
+
__export(testContext_exports, {
|
|
21
|
+
TestContext: () => TestContext
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(testContext_exports);
|
|
24
|
+
var import_testRunner = require("../../runner/testRunner");
|
|
25
|
+
class TestContext {
|
|
26
|
+
constructor(options) {
|
|
27
|
+
this.options = options;
|
|
28
|
+
}
|
|
29
|
+
setConfigLocation(configLocation) {
|
|
30
|
+
this.configLocation = configLocation;
|
|
31
|
+
}
|
|
32
|
+
async createTestRunner() {
|
|
33
|
+
if (this._testRunner)
|
|
34
|
+
await this._testRunner.stopTests();
|
|
35
|
+
const testRunner = new import_testRunner.TestRunner(this.configLocation, {});
|
|
36
|
+
await testRunner.initialize({});
|
|
37
|
+
this._testRunner = testRunner;
|
|
38
|
+
testRunner.on(import_testRunner.TestRunnerEvent.TestFilesChanged, (testFiles) => {
|
|
39
|
+
this._testRunner?.emit(import_testRunner.TestRunnerEvent.TestFilesChanged, testFiles);
|
|
40
|
+
});
|
|
41
|
+
this._testRunner = testRunner;
|
|
42
|
+
return testRunner;
|
|
43
|
+
}
|
|
44
|
+
async close() {
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
TestContext
|
|
50
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
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 testTool_exports = {};
|
|
20
|
+
__export(testTool_exports, {
|
|
21
|
+
defineTestTool: () => defineTestTool
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(testTool_exports);
|
|
24
|
+
function defineTestTool(tool) {
|
|
25
|
+
return tool;
|
|
26
|
+
}
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
defineTestTool
|
|
30
|
+
});
|
|
@@ -0,0 +1,194 @@
|
|
|
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 testTools_exports = {};
|
|
30
|
+
__export(testTools_exports, {
|
|
31
|
+
debugTest: () => debugTest,
|
|
32
|
+
listTests: () => listTests,
|
|
33
|
+
runTests: () => runTests,
|
|
34
|
+
setupPage: () => setupPage
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(testTools_exports);
|
|
37
|
+
var import_fs = __toESM(require("fs"));
|
|
38
|
+
var import_path = __toESM(require("path"));
|
|
39
|
+
var import_utils = require("playwright-core/lib/utils");
|
|
40
|
+
var import_bundle = require("../sdk/bundle");
|
|
41
|
+
var import_base = require("../../reporters/base");
|
|
42
|
+
var import_list = __toESM(require("../../reporters/list"));
|
|
43
|
+
var import_listModeReporter = __toESM(require("../../reporters/listModeReporter"));
|
|
44
|
+
var import_projectUtils = require("../../runner/projectUtils");
|
|
45
|
+
var import_testTool = require("./testTool");
|
|
46
|
+
var import_streams = require("./streams");
|
|
47
|
+
const listTests = (0, import_testTool.defineTestTool)({
|
|
48
|
+
schema: {
|
|
49
|
+
name: "test_list",
|
|
50
|
+
title: "List tests",
|
|
51
|
+
description: "List tests",
|
|
52
|
+
inputSchema: import_bundle.z.object({}),
|
|
53
|
+
type: "readOnly"
|
|
54
|
+
},
|
|
55
|
+
handle: async (context) => {
|
|
56
|
+
const { screen, stream } = createScreen();
|
|
57
|
+
const reporter = new import_listModeReporter.default({ screen, includeTestId: true });
|
|
58
|
+
const testRunner = await context.createTestRunner();
|
|
59
|
+
await testRunner.listTests(reporter, {});
|
|
60
|
+
return {
|
|
61
|
+
content: [{ type: "text", text: stream.content() }]
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
const runTests = (0, import_testTool.defineTestTool)({
|
|
66
|
+
schema: {
|
|
67
|
+
name: "test_run",
|
|
68
|
+
title: "Run tests",
|
|
69
|
+
description: "Run tests",
|
|
70
|
+
inputSchema: import_bundle.z.object({
|
|
71
|
+
locations: import_bundle.z.array(import_bundle.z.string()).optional().describe('Folder, file or location to run: "test/e2e" or "test/e2e/file.spec.ts" or "test/e2e/file.spec.ts:20"'),
|
|
72
|
+
projects: import_bundle.z.array(import_bundle.z.string()).optional().describe('Projects to run, projects from playwright.config.ts, by default runs all projects. Running with "chromium" is a good start')
|
|
73
|
+
}),
|
|
74
|
+
type: "readOnly"
|
|
75
|
+
},
|
|
76
|
+
handle: async (context, params) => {
|
|
77
|
+
const { screen, stream } = createScreen();
|
|
78
|
+
const configDir = context.configLocation.configDir;
|
|
79
|
+
const reporter = new import_list.default({ configDir, screen, includeTestId: true });
|
|
80
|
+
const testRunner = await context.createTestRunner();
|
|
81
|
+
await testRunner.runTests(reporter, {
|
|
82
|
+
locations: params.locations,
|
|
83
|
+
projects: params.projects,
|
|
84
|
+
disableConfigReporters: true
|
|
85
|
+
});
|
|
86
|
+
const text = stream.content();
|
|
87
|
+
return {
|
|
88
|
+
content: [
|
|
89
|
+
{ type: "text", text }
|
|
90
|
+
]
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
const debugTest = (0, import_testTool.defineTestTool)({
|
|
95
|
+
schema: {
|
|
96
|
+
name: "test_debug",
|
|
97
|
+
title: "Debug single test",
|
|
98
|
+
description: "Debug single test",
|
|
99
|
+
inputSchema: import_bundle.z.object({
|
|
100
|
+
test: import_bundle.z.object({
|
|
101
|
+
id: import_bundle.z.string().describe("Test ID to debug."),
|
|
102
|
+
title: import_bundle.z.string().describe("Human readable test title for granting permission to debug the test.")
|
|
103
|
+
})
|
|
104
|
+
}),
|
|
105
|
+
type: "readOnly"
|
|
106
|
+
},
|
|
107
|
+
handle: async (context, params) => {
|
|
108
|
+
const { screen, stream } = createScreen();
|
|
109
|
+
const configDir = context.configLocation.configDir;
|
|
110
|
+
const reporter = new import_list.default({ configDir, screen });
|
|
111
|
+
const testRunner = await context.createTestRunner();
|
|
112
|
+
const result = await testRunner.runTests(reporter, {
|
|
113
|
+
headed: !context.options?.headless,
|
|
114
|
+
testIds: [params.test.id],
|
|
115
|
+
// For automatic recovery
|
|
116
|
+
timeout: 0,
|
|
117
|
+
workers: 1,
|
|
118
|
+
pauseOnError: true,
|
|
119
|
+
disableConfigReporters: true
|
|
120
|
+
});
|
|
121
|
+
const text = stream.content();
|
|
122
|
+
return {
|
|
123
|
+
content: [
|
|
124
|
+
{ type: "text", text }
|
|
125
|
+
],
|
|
126
|
+
isError: result.status !== "passed"
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
const setupPage = (0, import_testTool.defineTestTool)({
|
|
131
|
+
schema: {
|
|
132
|
+
name: "test_setup_page",
|
|
133
|
+
title: "Setup page",
|
|
134
|
+
description: "Setup the page for test",
|
|
135
|
+
inputSchema: import_bundle.z.object({
|
|
136
|
+
project: import_bundle.z.string().optional().describe('Project to use for setup. For example: "chromium", if no project is provided uses the first project in the config.'),
|
|
137
|
+
testLocation: import_bundle.z.string().optional().describe('Location of the seed test to use for setup. For example: "test/seed/default.spec.ts:20".')
|
|
138
|
+
}),
|
|
139
|
+
type: "readOnly"
|
|
140
|
+
},
|
|
141
|
+
handle: async (context, params) => {
|
|
142
|
+
const { screen, stream } = createScreen();
|
|
143
|
+
const configDir = context.configLocation.configDir;
|
|
144
|
+
const reporter = new import_list.default({ configDir, screen });
|
|
145
|
+
const testRunner = await context.createTestRunner();
|
|
146
|
+
let testLocation = params.testLocation;
|
|
147
|
+
if (!testLocation) {
|
|
148
|
+
testLocation = "default.seed.spec.ts";
|
|
149
|
+
const config = await testRunner.loadConfig();
|
|
150
|
+
const project = params.project ? config.projects.find((p) => p.project.name === params.project) : (0, import_projectUtils.findTopLevelProjects)(config)[0];
|
|
151
|
+
const testDir = project?.project.testDir || configDir;
|
|
152
|
+
const seedFile = import_path.default.join(testDir, testLocation);
|
|
153
|
+
if (!import_fs.default.existsSync(seedFile)) {
|
|
154
|
+
await import_fs.default.promises.mkdir(import_path.default.dirname(seedFile), { recursive: true });
|
|
155
|
+
await import_fs.default.promises.writeFile(seedFile, `import { test, expect } from '@playwright/test';
|
|
156
|
+
|
|
157
|
+
test('seed', async ({ page }) => {});
|
|
158
|
+
`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const result = await testRunner.runTests(reporter, {
|
|
162
|
+
headed: !context.options?.headless,
|
|
163
|
+
locations: [testLocation],
|
|
164
|
+
projects: params.project ? [params.project] : void 0,
|
|
165
|
+
timeout: 0,
|
|
166
|
+
workers: 1,
|
|
167
|
+
pauseAtEnd: true,
|
|
168
|
+
disableConfigReporters: true
|
|
169
|
+
});
|
|
170
|
+
const text = stream.content();
|
|
171
|
+
return {
|
|
172
|
+
content: [{ type: "text", text }],
|
|
173
|
+
isError: result.status !== "passed"
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
function createScreen() {
|
|
178
|
+
const stream = new import_streams.StringWriteStream();
|
|
179
|
+
const screen = {
|
|
180
|
+
...import_base.terminalScreen,
|
|
181
|
+
isTTY: false,
|
|
182
|
+
colors: import_utils.noColors,
|
|
183
|
+
stdout: stream,
|
|
184
|
+
stderr: stream
|
|
185
|
+
};
|
|
186
|
+
return { screen, stream };
|
|
187
|
+
}
|
|
188
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
189
|
+
0 && (module.exports = {
|
|
190
|
+
debugTest,
|
|
191
|
+
listTests,
|
|
192
|
+
runTests,
|
|
193
|
+
setupPage
|
|
194
|
+
});
|
|
@@ -0,0 +1,187 @@
|
|
|
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 host_exports = {};
|
|
30
|
+
__export(host_exports, {
|
|
31
|
+
runVSCodeTools: () => runVSCodeTools
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(host_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var mcpBundle = __toESM(require("../sdk/bundle"));
|
|
36
|
+
var mcpServer = __toESM(require("../sdk/server"));
|
|
37
|
+
var import_log = require("../log");
|
|
38
|
+
var import_browserServerBackend = require("../browser/browserServerBackend");
|
|
39
|
+
var import_browserContextFactory = require("../browser/browserContextFactory");
|
|
40
|
+
const packageJSON = require("../../../package.json");
|
|
41
|
+
const { z, zodToJsonSchema } = mcpBundle;
|
|
42
|
+
const contextSwitchOptions = z.object({
|
|
43
|
+
connectionString: z.string().optional().describe("The connection string to use to connect to the browser"),
|
|
44
|
+
lib: z.string().optional().describe("The library to use for the connection"),
|
|
45
|
+
debugController: z.boolean().optional().describe("Enable the debug controller")
|
|
46
|
+
});
|
|
47
|
+
class VSCodeProxyBackend {
|
|
48
|
+
constructor(_config, _defaultTransportFactory) {
|
|
49
|
+
this._config = _config;
|
|
50
|
+
this._defaultTransportFactory = _defaultTransportFactory;
|
|
51
|
+
this.name = "Playwright MCP Client Switcher";
|
|
52
|
+
this.version = packageJSON.version;
|
|
53
|
+
this._contextSwitchTool = this._defineContextSwitchTool();
|
|
54
|
+
}
|
|
55
|
+
async initialize(server, clientInfo) {
|
|
56
|
+
this._clientInfo = clientInfo;
|
|
57
|
+
const transport = await this._defaultTransportFactory(this);
|
|
58
|
+
await this._setCurrentClient(transport);
|
|
59
|
+
}
|
|
60
|
+
async listTools() {
|
|
61
|
+
const response = await this._currentClient.listTools();
|
|
62
|
+
return [
|
|
63
|
+
...response.tools,
|
|
64
|
+
this._contextSwitchTool
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
async callTool(name, args) {
|
|
68
|
+
if (name === this._contextSwitchTool.name)
|
|
69
|
+
return this._callContextSwitchTool(args);
|
|
70
|
+
return await this._currentClient.callTool({
|
|
71
|
+
name,
|
|
72
|
+
arguments: args
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
serverClosed(server) {
|
|
76
|
+
void this._currentClient?.close().catch(import_log.logUnhandledError);
|
|
77
|
+
}
|
|
78
|
+
onContext(context) {
|
|
79
|
+
this._context = context;
|
|
80
|
+
context.on("close", () => {
|
|
81
|
+
this._context = void 0;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async _getDebugControllerURL() {
|
|
85
|
+
if (!this._context)
|
|
86
|
+
return;
|
|
87
|
+
const browser = this._context.browser();
|
|
88
|
+
if (!browser || !browser._launchServer)
|
|
89
|
+
return;
|
|
90
|
+
if (this._browser !== browser)
|
|
91
|
+
this._browserServer = void 0;
|
|
92
|
+
if (!this._browserServer)
|
|
93
|
+
this._browserServer = await browser._launchServer({ _debugController: true });
|
|
94
|
+
const url = new URL(this._browserServer.wsEndpoint());
|
|
95
|
+
url.searchParams.set("debug-controller", "1");
|
|
96
|
+
return url.toString();
|
|
97
|
+
}
|
|
98
|
+
async _callContextSwitchTool(params) {
|
|
99
|
+
if (params.debugController) {
|
|
100
|
+
const url = await this._getDebugControllerURL();
|
|
101
|
+
const lines = [`### Result`];
|
|
102
|
+
if (url) {
|
|
103
|
+
lines.push(`URL: ${url}`);
|
|
104
|
+
lines.push(`Version: ${packageJSON.version}`);
|
|
105
|
+
} else {
|
|
106
|
+
lines.push(`No open browsers.`);
|
|
107
|
+
}
|
|
108
|
+
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
109
|
+
}
|
|
110
|
+
if (!params.connectionString || !params.lib) {
|
|
111
|
+
const transport = await this._defaultTransportFactory(this);
|
|
112
|
+
await this._setCurrentClient(transport);
|
|
113
|
+
return {
|
|
114
|
+
content: [{ type: "text", text: "### Result\nSuccessfully disconnected.\n" }]
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
await this._setCurrentClient(
|
|
118
|
+
new mcpBundle.StdioClientTransport({
|
|
119
|
+
command: process.execPath,
|
|
120
|
+
cwd: process.cwd(),
|
|
121
|
+
args: [
|
|
122
|
+
import_path.default.join(__dirname, "main.js"),
|
|
123
|
+
JSON.stringify(this._config),
|
|
124
|
+
params.connectionString,
|
|
125
|
+
params.lib
|
|
126
|
+
]
|
|
127
|
+
})
|
|
128
|
+
);
|
|
129
|
+
return {
|
|
130
|
+
content: [{ type: "text", text: "### Result\nSuccessfully connected.\n" }]
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
_defineContextSwitchTool() {
|
|
134
|
+
return {
|
|
135
|
+
name: "browser_connect",
|
|
136
|
+
description: "Do not call, this tool is used in the integration with the Playwright VS Code Extension and meant for programmatic usage only.",
|
|
137
|
+
inputSchema: zodToJsonSchema(contextSwitchOptions, { strictUnions: true }),
|
|
138
|
+
annotations: {
|
|
139
|
+
title: "Connect to a browser running in VS Code.",
|
|
140
|
+
readOnlyHint: true,
|
|
141
|
+
openWorldHint: false
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async _setCurrentClient(transport) {
|
|
146
|
+
await this._currentClient?.close();
|
|
147
|
+
this._currentClient = void 0;
|
|
148
|
+
const client = new mcpBundle.Client({ name: this._clientInfo.name, version: this._clientInfo.version });
|
|
149
|
+
client.registerCapabilities({
|
|
150
|
+
roots: {
|
|
151
|
+
listRoots: true
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
client.setRequestHandler(mcpBundle.ListRootsRequestSchema, () => ({ roots: this._clientInfo.roots }));
|
|
155
|
+
client.setRequestHandler(mcpBundle.PingRequestSchema, () => ({}));
|
|
156
|
+
await client.connect(transport);
|
|
157
|
+
this._currentClient = client;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async function runVSCodeTools(config) {
|
|
161
|
+
const serverBackendFactory = {
|
|
162
|
+
name: "Playwright w/ vscode",
|
|
163
|
+
nameInConfig: "playwright-vscode",
|
|
164
|
+
version: packageJSON.version,
|
|
165
|
+
create: () => new VSCodeProxyBackend(
|
|
166
|
+
config,
|
|
167
|
+
(delegate) => mcpServer.wrapInProcess(
|
|
168
|
+
new import_browserServerBackend.BrowserServerBackend(
|
|
169
|
+
config,
|
|
170
|
+
{
|
|
171
|
+
async createContext(clientInfo, abortSignal, toolName) {
|
|
172
|
+
const context = await (0, import_browserContextFactory.contextFactory)(config).createContext(clientInfo, abortSignal, toolName);
|
|
173
|
+
delegate.onContext(context.browserContext);
|
|
174
|
+
return context;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
)
|
|
179
|
+
)
|
|
180
|
+
};
|
|
181
|
+
await mcpServer.start(serverBackendFactory, config.server);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
185
|
+
0 && (module.exports = {
|
|
186
|
+
runVSCodeTools
|
|
187
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var mcpBundle = __toESM(require("../sdk/bundle"));
|
|
25
|
+
var mcpServer = __toESM(require("../sdk/server"));
|
|
26
|
+
var import_browserServerBackend = require("../browser/browserServerBackend");
|
|
27
|
+
class VSCodeBrowserContextFactory {
|
|
28
|
+
constructor(_config, _playwright, _connectionString) {
|
|
29
|
+
this._config = _config;
|
|
30
|
+
this._playwright = _playwright;
|
|
31
|
+
this._connectionString = _connectionString;
|
|
32
|
+
this.name = "vscode";
|
|
33
|
+
this.description = "Connect to a browser running in the Playwright VS Code extension";
|
|
34
|
+
}
|
|
35
|
+
async createContext(clientInfo, abortSignal) {
|
|
36
|
+
let launchOptions = this._config.browser.launchOptions;
|
|
37
|
+
if (this._config.browser.userDataDir) {
|
|
38
|
+
launchOptions = {
|
|
39
|
+
...launchOptions,
|
|
40
|
+
...this._config.browser.contextOptions,
|
|
41
|
+
userDataDir: this._config.browser.userDataDir
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const connectionString = new URL(this._connectionString);
|
|
45
|
+
connectionString.searchParams.set("launch-options", JSON.stringify(launchOptions));
|
|
46
|
+
const browserType = this._playwright.chromium;
|
|
47
|
+
const browser = await browserType.connect(connectionString.toString());
|
|
48
|
+
const context = browser.contexts()[0] ?? await browser.newContext(this._config.browser.contextOptions);
|
|
49
|
+
return {
|
|
50
|
+
browserContext: context,
|
|
51
|
+
close: async () => {
|
|
52
|
+
await browser.close();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function main(config, connectionString, lib) {
|
|
58
|
+
const playwright = await import(lib).then((mod) => mod.default ?? mod);
|
|
59
|
+
const factory = new VSCodeBrowserContextFactory(config, playwright, connectionString);
|
|
60
|
+
await mcpServer.connect(
|
|
61
|
+
{
|
|
62
|
+
name: "Playwright MCP",
|
|
63
|
+
nameInConfig: "playwright-vscode",
|
|
64
|
+
create: () => new import_browserServerBackend.BrowserServerBackend(config, factory),
|
|
65
|
+
version: "unused"
|
|
66
|
+
},
|
|
67
|
+
new mcpBundle.StdioServerTransport(),
|
|
68
|
+
false
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
void (async () => {
|
|
72
|
+
await main(
|
|
73
|
+
JSON.parse(process.argv[2]),
|
|
74
|
+
process.argv[3],
|
|
75
|
+
process.argv[4]
|
|
76
|
+
);
|
|
77
|
+
})();
|
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
|
+
});
|