@cotestdev/mcp_playwright 0.0.16 → 0.0.17
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/common/config.js +281 -0
- package/lib/common/configLoader.js +344 -0
- package/lib/common/esmLoaderHost.js +104 -0
- package/lib/common/expectBundle.js +43 -0
- package/lib/common/expectBundleImpl.js +407 -0
- package/lib/common/fixtures.js +302 -0
- package/lib/common/globals.js +58 -0
- package/lib/common/ipc.js +60 -0
- package/lib/common/poolBuilder.js +85 -0
- package/lib/common/process.js +132 -0
- package/lib/common/suiteUtils.js +140 -0
- package/lib/common/test.js +322 -0
- package/lib/common/testLoader.js +101 -0
- package/lib/common/testType.js +298 -0
- package/lib/common/validators.js +68 -0
- package/lib/mcp/browser/tools/common.js +1 -1
- package/lib/mcp/browser/tools/console.js +1 -1
- package/lib/mcp/browser/tools/dialogs.js +1 -1
- package/lib/mcp/browser/tools/evaluate.js +1 -1
- package/lib/mcp/browser/tools/files.js +1 -1
- package/lib/mcp/browser/tools/form.js +1 -1
- package/lib/mcp/browser/tools/install.js +1 -1
- package/lib/mcp/browser/tools/keyboard.js +1 -1
- package/lib/mcp/browser/tools/mouse.js +1 -1
- package/lib/mcp/browser/tools/navigate.js +1 -1
- package/lib/mcp/browser/tools/network.js +1 -1
- package/lib/mcp/browser/tools/pdf.js +1 -1
- package/lib/mcp/browser/tools/runCode.js +1 -1
- package/lib/mcp/browser/tools/screenshot.js +1 -1
- package/lib/mcp/browser/tools/script.js +1 -1
- package/lib/mcp/browser/tools/snapshot.js +1 -1
- package/lib/mcp/browser/tools/tabs.js +1 -1
- package/lib/mcp/browser/tools/tracing.js +1 -1
- package/lib/mcp/browser/tools/verify.js +1 -1
- package/lib/mcp/browser/tools/wait.js +1 -1
- package/lib/mcp/index.js +1 -1
- package/lib/mcp/sdk/http.js +1 -1
- package/lib/mcp/sdk/server.js +1 -1
- package/lib/mcp/sdk/tool.js +1 -1
- package/lib/mcp/test/generatorTools.js +1 -1
- package/lib/mcp/test/plannerTools.js +1 -1
- package/lib/mcp/test/seed.js +1 -1
- package/lib/mcp/test/testBackend.js +1 -1
- package/lib/mcp/test/testContext.js +4 -4
- package/lib/mcp/test/testTools.js +2 -2
- package/lib/mcp/vscode/host.js +1 -1
- package/lib/third_party/pirates.js +62 -0
- package/lib/third_party/tsconfig-loader.js +103 -0
- package/lib/transform/babelBundle.js +43 -0
- package/lib/transform/babelBundleImpl.js +461 -0
- package/lib/transform/babelHighlightUtils.js +63 -0
- package/lib/transform/compilationCache.js +272 -0
- package/lib/transform/esmLoader.js +103 -0
- package/lib/transform/portTransport.js +67 -0
- package/lib/transform/transform.js +296 -0
- package/lib/utilsBundleImpl/index.js +218 -0
- package/package.json +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
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 babelHighlightUtils_exports = {};
|
|
30
|
+
__export(babelHighlightUtils_exports, {
|
|
31
|
+
findTestEndLocation: () => findTestEndLocation
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(babelHighlightUtils_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_babelBundle = require("./babelBundle");
|
|
36
|
+
function containsLocation(range, location) {
|
|
37
|
+
if (location.line < range.start.line || location.line > range.end.line)
|
|
38
|
+
return false;
|
|
39
|
+
if (location.line === range.start.line && location.column < range.start.column)
|
|
40
|
+
return false;
|
|
41
|
+
if (location.line === range.end.line && location.column > range.end.column)
|
|
42
|
+
return false;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
function findTestEndLocation(text, testStartLocation) {
|
|
46
|
+
const ast = (0, import_babelBundle.babelParse)(text, import_path.default.basename(testStartLocation.file), false);
|
|
47
|
+
let result;
|
|
48
|
+
(0, import_babelBundle.traverse)(ast, {
|
|
49
|
+
enter(path2) {
|
|
50
|
+
if (import_babelBundle.types.isCallExpression(path2.node) && path2.node.loc && containsLocation(path2.node.loc, testStartLocation)) {
|
|
51
|
+
const callNode = path2.node;
|
|
52
|
+
const funcNode = callNode.arguments[callNode.arguments.length - 1];
|
|
53
|
+
if (callNode.arguments.length >= 2 && import_babelBundle.types.isFunction(funcNode) && funcNode.body.loc)
|
|
54
|
+
result = { file: testStartLocation.file, ...funcNode.body.loc.end };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
findTestEndLocation
|
|
63
|
+
});
|
|
@@ -0,0 +1,272 @@
|
|
|
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 compilationCache_exports = {};
|
|
30
|
+
__export(compilationCache_exports, {
|
|
31
|
+
addToCompilationCache: () => addToCompilationCache,
|
|
32
|
+
affectedTestFiles: () => affectedTestFiles,
|
|
33
|
+
belongsToNodeModules: () => belongsToNodeModules,
|
|
34
|
+
cacheDir: () => cacheDir,
|
|
35
|
+
collectAffectedTestFiles: () => collectAffectedTestFiles,
|
|
36
|
+
currentFileDepsCollector: () => currentFileDepsCollector,
|
|
37
|
+
dependenciesForTestFile: () => dependenciesForTestFile,
|
|
38
|
+
fileDependenciesForTest: () => fileDependenciesForTest,
|
|
39
|
+
getFromCompilationCache: () => getFromCompilationCache,
|
|
40
|
+
getUserData: () => getUserData,
|
|
41
|
+
installSourceMapSupport: () => installSourceMapSupport,
|
|
42
|
+
internalDependenciesForTestFile: () => internalDependenciesForTestFile,
|
|
43
|
+
serializeCompilationCache: () => serializeCompilationCache,
|
|
44
|
+
setExternalDependencies: () => setExternalDependencies,
|
|
45
|
+
startCollectingFileDeps: () => startCollectingFileDeps,
|
|
46
|
+
stopCollectingFileDeps: () => stopCollectingFileDeps
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(compilationCache_exports);
|
|
49
|
+
var import_fs = __toESM(require("fs"));
|
|
50
|
+
var import_os = __toESM(require("os"));
|
|
51
|
+
var import_path = __toESM(require("path"));
|
|
52
|
+
var import_utils = require("playwright-core/lib/utils");
|
|
53
|
+
var import_globals = require("../common/globals");
|
|
54
|
+
var import_utilsBundle = require("../utilsBundle");
|
|
55
|
+
const cacheDir = process.env.PWTEST_CACHE_DIR || (() => {
|
|
56
|
+
if (process.platform === "win32")
|
|
57
|
+
return import_path.default.join(import_os.default.tmpdir(), `playwright-transform-cache`);
|
|
58
|
+
return import_path.default.join(import_os.default.tmpdir(), `playwright-transform-cache-` + process.geteuid?.());
|
|
59
|
+
})();
|
|
60
|
+
const sourceMaps = /* @__PURE__ */ new Map();
|
|
61
|
+
const memoryCache = /* @__PURE__ */ new Map();
|
|
62
|
+
const fileDependencies = /* @__PURE__ */ new Map();
|
|
63
|
+
const externalDependencies = /* @__PURE__ */ new Map();
|
|
64
|
+
function installSourceMapSupport() {
|
|
65
|
+
Error.stackTraceLimit = 200;
|
|
66
|
+
import_utilsBundle.sourceMapSupport.install({
|
|
67
|
+
environment: "node",
|
|
68
|
+
handleUncaughtExceptions: false,
|
|
69
|
+
retrieveSourceMap(source) {
|
|
70
|
+
if (!sourceMaps.has(source))
|
|
71
|
+
return null;
|
|
72
|
+
const sourceMapPath = sourceMaps.get(source);
|
|
73
|
+
try {
|
|
74
|
+
return {
|
|
75
|
+
map: JSON.parse(import_fs.default.readFileSync(sourceMapPath, "utf-8")),
|
|
76
|
+
url: source
|
|
77
|
+
};
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function _innerAddToCompilationCacheAndSerialize(filename, entry) {
|
|
85
|
+
sourceMaps.set(entry.moduleUrl || filename, entry.sourceMapPath);
|
|
86
|
+
memoryCache.set(filename, entry);
|
|
87
|
+
return {
|
|
88
|
+
sourceMaps: [[entry.moduleUrl || filename, entry.sourceMapPath]],
|
|
89
|
+
memoryCache: [[filename, entry]],
|
|
90
|
+
fileDependencies: [],
|
|
91
|
+
externalDependencies: []
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function getFromCompilationCache(filename, contentHash, moduleUrl) {
|
|
95
|
+
const cache = memoryCache.get(filename);
|
|
96
|
+
if (cache?.codePath) {
|
|
97
|
+
try {
|
|
98
|
+
return { cachedCode: import_fs.default.readFileSync(cache.codePath, "utf-8") };
|
|
99
|
+
} catch {
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const filePathHash = calculateFilePathHash(filename);
|
|
103
|
+
const hashPrefix = filePathHash + "_" + contentHash.substring(0, 7);
|
|
104
|
+
const cacheFolderName = filePathHash.substring(0, 2);
|
|
105
|
+
const cachePath = calculateCachePath(filename, cacheFolderName, hashPrefix);
|
|
106
|
+
const codePath = cachePath + ".js";
|
|
107
|
+
const sourceMapPath = cachePath + ".map";
|
|
108
|
+
const dataPath = cachePath + ".data";
|
|
109
|
+
try {
|
|
110
|
+
const cachedCode = import_fs.default.readFileSync(codePath, "utf8");
|
|
111
|
+
const serializedCache = _innerAddToCompilationCacheAndSerialize(filename, { codePath, sourceMapPath, dataPath, moduleUrl });
|
|
112
|
+
return { cachedCode, serializedCache };
|
|
113
|
+
} catch {
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
addToCache: (code, map, data) => {
|
|
117
|
+
if ((0, import_globals.isWorkerProcess)())
|
|
118
|
+
return {};
|
|
119
|
+
clearOldCacheEntries(cacheFolderName, filePathHash);
|
|
120
|
+
import_fs.default.mkdirSync(import_path.default.dirname(cachePath), { recursive: true });
|
|
121
|
+
if (map)
|
|
122
|
+
import_fs.default.writeFileSync(sourceMapPath, JSON.stringify(map), "utf8");
|
|
123
|
+
if (data.size)
|
|
124
|
+
import_fs.default.writeFileSync(dataPath, JSON.stringify(Object.fromEntries(data.entries()), void 0, 2), "utf8");
|
|
125
|
+
import_fs.default.writeFileSync(codePath, code, "utf8");
|
|
126
|
+
const serializedCache = _innerAddToCompilationCacheAndSerialize(filename, { codePath, sourceMapPath, dataPath, moduleUrl });
|
|
127
|
+
return { serializedCache };
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function serializeCompilationCache() {
|
|
132
|
+
return {
|
|
133
|
+
sourceMaps: [...sourceMaps.entries()],
|
|
134
|
+
memoryCache: [...memoryCache.entries()],
|
|
135
|
+
fileDependencies: [...fileDependencies.entries()].map(([filename, deps]) => [filename, [...deps]]),
|
|
136
|
+
externalDependencies: [...externalDependencies.entries()].map(([filename, deps]) => [filename, [...deps]])
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function addToCompilationCache(payload) {
|
|
140
|
+
for (const entry of payload.sourceMaps)
|
|
141
|
+
sourceMaps.set(entry[0], entry[1]);
|
|
142
|
+
for (const entry of payload.memoryCache)
|
|
143
|
+
memoryCache.set(entry[0], entry[1]);
|
|
144
|
+
for (const entry of payload.fileDependencies) {
|
|
145
|
+
const existing = fileDependencies.get(entry[0]) || [];
|
|
146
|
+
fileDependencies.set(entry[0], /* @__PURE__ */ new Set([...entry[1], ...existing]));
|
|
147
|
+
}
|
|
148
|
+
for (const entry of payload.externalDependencies) {
|
|
149
|
+
const existing = externalDependencies.get(entry[0]) || [];
|
|
150
|
+
externalDependencies.set(entry[0], /* @__PURE__ */ new Set([...entry[1], ...existing]));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function calculateFilePathHash(filePath) {
|
|
154
|
+
return (0, import_utils.calculateSha1)(filePath).substring(0, 10);
|
|
155
|
+
}
|
|
156
|
+
function calculateCachePath(filePath, cacheFolderName, hashPrefix) {
|
|
157
|
+
const fileName = hashPrefix + "_" + import_path.default.basename(filePath, import_path.default.extname(filePath)).replace(/\W/g, "");
|
|
158
|
+
return import_path.default.join(cacheDir, cacheFolderName, fileName);
|
|
159
|
+
}
|
|
160
|
+
function clearOldCacheEntries(cacheFolderName, filePathHash) {
|
|
161
|
+
const cachePath = import_path.default.join(cacheDir, cacheFolderName);
|
|
162
|
+
try {
|
|
163
|
+
const cachedRelevantFiles = import_fs.default.readdirSync(cachePath).filter((file) => file.startsWith(filePathHash));
|
|
164
|
+
for (const file of cachedRelevantFiles)
|
|
165
|
+
import_fs.default.rmSync(import_path.default.join(cachePath, file), { force: true });
|
|
166
|
+
} catch {
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
let depsCollector;
|
|
170
|
+
function startCollectingFileDeps() {
|
|
171
|
+
depsCollector = /* @__PURE__ */ new Set();
|
|
172
|
+
}
|
|
173
|
+
function stopCollectingFileDeps(filename) {
|
|
174
|
+
if (!depsCollector)
|
|
175
|
+
return;
|
|
176
|
+
depsCollector.delete(filename);
|
|
177
|
+
for (const dep of depsCollector) {
|
|
178
|
+
if (belongsToNodeModules(dep))
|
|
179
|
+
depsCollector.delete(dep);
|
|
180
|
+
}
|
|
181
|
+
fileDependencies.set(filename, depsCollector);
|
|
182
|
+
depsCollector = void 0;
|
|
183
|
+
}
|
|
184
|
+
function currentFileDepsCollector() {
|
|
185
|
+
return depsCollector;
|
|
186
|
+
}
|
|
187
|
+
function setExternalDependencies(filename, deps) {
|
|
188
|
+
const depsSet = new Set(deps.filter((dep) => !belongsToNodeModules(dep) && dep !== filename));
|
|
189
|
+
externalDependencies.set(filename, depsSet);
|
|
190
|
+
}
|
|
191
|
+
function fileDependenciesForTest() {
|
|
192
|
+
return fileDependencies;
|
|
193
|
+
}
|
|
194
|
+
function collectAffectedTestFiles(changedFile, testFileCollector) {
|
|
195
|
+
const isTestFile = (file) => fileDependencies.has(file);
|
|
196
|
+
if (isTestFile(changedFile))
|
|
197
|
+
testFileCollector.add(changedFile);
|
|
198
|
+
for (const [testFile, deps] of fileDependencies) {
|
|
199
|
+
if (deps.has(changedFile))
|
|
200
|
+
testFileCollector.add(testFile);
|
|
201
|
+
}
|
|
202
|
+
for (const [importingFile, depsOfImportingFile] of externalDependencies) {
|
|
203
|
+
if (depsOfImportingFile.has(changedFile)) {
|
|
204
|
+
if (isTestFile(importingFile))
|
|
205
|
+
testFileCollector.add(importingFile);
|
|
206
|
+
for (const [testFile, depsOfTestFile] of fileDependencies) {
|
|
207
|
+
if (depsOfTestFile.has(importingFile))
|
|
208
|
+
testFileCollector.add(testFile);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function affectedTestFiles(changes) {
|
|
214
|
+
const result = /* @__PURE__ */ new Set();
|
|
215
|
+
for (const change of changes)
|
|
216
|
+
collectAffectedTestFiles(change, result);
|
|
217
|
+
return [...result];
|
|
218
|
+
}
|
|
219
|
+
function internalDependenciesForTestFile(filename) {
|
|
220
|
+
return fileDependencies.get(filename);
|
|
221
|
+
}
|
|
222
|
+
function dependenciesForTestFile(filename) {
|
|
223
|
+
const result = /* @__PURE__ */ new Set();
|
|
224
|
+
for (const testDependency of fileDependencies.get(filename) || []) {
|
|
225
|
+
result.add(testDependency);
|
|
226
|
+
for (const externalDependency of externalDependencies.get(testDependency) || [])
|
|
227
|
+
result.add(externalDependency);
|
|
228
|
+
}
|
|
229
|
+
for (const dep of externalDependencies.get(filename) || [])
|
|
230
|
+
result.add(dep);
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
const kPlaywrightInternalPrefix = import_path.default.resolve(__dirname, "../../../playwright");
|
|
234
|
+
function belongsToNodeModules(file) {
|
|
235
|
+
if (file.includes(`${import_path.default.sep}node_modules${import_path.default.sep}`))
|
|
236
|
+
return true;
|
|
237
|
+
if (file.startsWith(kPlaywrightInternalPrefix) && (file.endsWith(".js") || file.endsWith(".mjs")))
|
|
238
|
+
return true;
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
async function getUserData(pluginName) {
|
|
242
|
+
const result = /* @__PURE__ */ new Map();
|
|
243
|
+
for (const [fileName, cache] of memoryCache) {
|
|
244
|
+
if (!cache.dataPath)
|
|
245
|
+
continue;
|
|
246
|
+
if (!import_fs.default.existsSync(cache.dataPath))
|
|
247
|
+
continue;
|
|
248
|
+
const data = JSON.parse(await import_fs.default.promises.readFile(cache.dataPath, "utf8"));
|
|
249
|
+
if (data[pluginName])
|
|
250
|
+
result.set(fileName, data[pluginName]);
|
|
251
|
+
}
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
255
|
+
0 && (module.exports = {
|
|
256
|
+
addToCompilationCache,
|
|
257
|
+
affectedTestFiles,
|
|
258
|
+
belongsToNodeModules,
|
|
259
|
+
cacheDir,
|
|
260
|
+
collectAffectedTestFiles,
|
|
261
|
+
currentFileDepsCollector,
|
|
262
|
+
dependenciesForTestFile,
|
|
263
|
+
fileDependenciesForTest,
|
|
264
|
+
getFromCompilationCache,
|
|
265
|
+
getUserData,
|
|
266
|
+
installSourceMapSupport,
|
|
267
|
+
internalDependenciesForTestFile,
|
|
268
|
+
serializeCompilationCache,
|
|
269
|
+
setExternalDependencies,
|
|
270
|
+
startCollectingFileDeps,
|
|
271
|
+
stopCollectingFileDeps
|
|
272
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
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 import_fs = __toESM(require("fs"));
|
|
25
|
+
var import_url = __toESM(require("url"));
|
|
26
|
+
var import_compilationCache = require("./compilationCache");
|
|
27
|
+
var import_portTransport = require("./portTransport");
|
|
28
|
+
var import_transform = require("./transform");
|
|
29
|
+
var import_util = require("../util");
|
|
30
|
+
const esmPreflightExtension = ".esm.preflight";
|
|
31
|
+
async function resolve(originalSpecifier, context, defaultResolve) {
|
|
32
|
+
let specifier = originalSpecifier.replace(esmPreflightExtension, "");
|
|
33
|
+
if (context.parentURL && context.parentURL.startsWith("file://")) {
|
|
34
|
+
const filename = import_url.default.fileURLToPath(context.parentURL);
|
|
35
|
+
const resolved = (0, import_transform.resolveHook)(filename, specifier);
|
|
36
|
+
if (resolved !== void 0)
|
|
37
|
+
specifier = import_url.default.pathToFileURL(resolved).toString();
|
|
38
|
+
}
|
|
39
|
+
const result = await defaultResolve(specifier, context, defaultResolve);
|
|
40
|
+
if (result?.url && result.url.startsWith("file://"))
|
|
41
|
+
(0, import_compilationCache.currentFileDepsCollector)()?.add(import_url.default.fileURLToPath(result.url));
|
|
42
|
+
if (originalSpecifier.endsWith(esmPreflightExtension))
|
|
43
|
+
result.url = result.url + esmPreflightExtension;
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
const kSupportedFormats = /* @__PURE__ */ new Map([
|
|
47
|
+
["commonjs", "commonjs"],
|
|
48
|
+
["module", "module"],
|
|
49
|
+
["commonjs-typescript", "commonjs"],
|
|
50
|
+
["module-typescript", "module"],
|
|
51
|
+
[null, null],
|
|
52
|
+
[void 0, void 0]
|
|
53
|
+
]);
|
|
54
|
+
async function load(originalModuleUrl, context, defaultLoad) {
|
|
55
|
+
const moduleUrl = originalModuleUrl.replace(esmPreflightExtension, "");
|
|
56
|
+
if (!kSupportedFormats.has(context.format))
|
|
57
|
+
return defaultLoad(moduleUrl, context, defaultLoad);
|
|
58
|
+
if (!moduleUrl.startsWith("file://"))
|
|
59
|
+
return defaultLoad(moduleUrl, context, defaultLoad);
|
|
60
|
+
const filename = import_url.default.fileURLToPath(moduleUrl);
|
|
61
|
+
if (!(0, import_transform.shouldTransform)(filename))
|
|
62
|
+
return defaultLoad(moduleUrl, context, defaultLoad);
|
|
63
|
+
const code = import_fs.default.readFileSync(filename, "utf-8");
|
|
64
|
+
const transformed = (0, import_transform.transformHook)(code, filename, moduleUrl);
|
|
65
|
+
if (transformed.serializedCache)
|
|
66
|
+
transport?.post("pushToCompilationCache", { cache: transformed.serializedCache });
|
|
67
|
+
return {
|
|
68
|
+
format: kSupportedFormats.get(context.format) || ((0, import_util.fileIsModule)(filename) ? "module" : "commonjs"),
|
|
69
|
+
source: originalModuleUrl.endsWith(esmPreflightExtension) ? `void 0;` : transformed.code,
|
|
70
|
+
shortCircuit: true
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
let transport;
|
|
74
|
+
function initialize(data) {
|
|
75
|
+
transport = createTransport(data?.port);
|
|
76
|
+
}
|
|
77
|
+
function createTransport(port) {
|
|
78
|
+
return new import_portTransport.PortTransport(port, async (method, params) => {
|
|
79
|
+
if (method === "setSingleTSConfig") {
|
|
80
|
+
(0, import_transform.setSingleTSConfig)(params.tsconfig);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (method === "setTransformConfig") {
|
|
84
|
+
(0, import_transform.setTransformConfig)(params.config);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (method === "addToCompilationCache") {
|
|
88
|
+
(0, import_compilationCache.addToCompilationCache)(params.cache);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (method === "getCompilationCache")
|
|
92
|
+
return { cache: (0, import_compilationCache.serializeCompilationCache)() };
|
|
93
|
+
if (method === "startCollectingFileDeps") {
|
|
94
|
+
(0, import_compilationCache.startCollectingFileDeps)();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (method === "stopCollectingFileDeps") {
|
|
98
|
+
(0, import_compilationCache.stopCollectingFileDeps)(params.file);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
module.exports = { initialize, load, resolve };
|
|
@@ -0,0 +1,67 @@
|
|
|
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 portTransport_exports = {};
|
|
20
|
+
__export(portTransport_exports, {
|
|
21
|
+
PortTransport: () => PortTransport
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(portTransport_exports);
|
|
24
|
+
class PortTransport {
|
|
25
|
+
constructor(port, handler) {
|
|
26
|
+
this._lastId = 0;
|
|
27
|
+
this._callbacks = /* @__PURE__ */ new Map();
|
|
28
|
+
this._port = port;
|
|
29
|
+
port.addEventListener("message", async (event) => {
|
|
30
|
+
const message = event.data;
|
|
31
|
+
const { id, ackId, method, params, result } = message;
|
|
32
|
+
if (ackId) {
|
|
33
|
+
const callback = this._callbacks.get(ackId);
|
|
34
|
+
this._callbacks.delete(ackId);
|
|
35
|
+
this._resetRef();
|
|
36
|
+
callback?.(result);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const handlerResult = await handler(method, params);
|
|
40
|
+
if (id)
|
|
41
|
+
this._port.postMessage({ ackId: id, result: handlerResult });
|
|
42
|
+
});
|
|
43
|
+
this._resetRef();
|
|
44
|
+
}
|
|
45
|
+
post(method, params) {
|
|
46
|
+
this._port.postMessage({ method, params });
|
|
47
|
+
}
|
|
48
|
+
async send(method, params) {
|
|
49
|
+
return await new Promise((f) => {
|
|
50
|
+
const id = ++this._lastId;
|
|
51
|
+
this._callbacks.set(id, f);
|
|
52
|
+
this._resetRef();
|
|
53
|
+
this._port.postMessage({ id, method, params });
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
_resetRef() {
|
|
57
|
+
if (this._callbacks.size) {
|
|
58
|
+
this._port.ref();
|
|
59
|
+
} else {
|
|
60
|
+
this._port.unref();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
PortTransport
|
|
67
|
+
});
|