@stablyai/internal-playwright 0.1.0

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.
Files changed (297) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +168 -0
  4. package/ThirdPartyNotices.txt +6277 -0
  5. package/cli.js +19 -0
  6. package/index.d.ts +17 -0
  7. package/index.js +17 -0
  8. package/index.mjs +18 -0
  9. package/jsx-runtime.js +42 -0
  10. package/jsx-runtime.mjs +21 -0
  11. package/lib/agents/generateAgents.js +265 -0
  12. package/lib/agents/generator.md +102 -0
  13. package/lib/agents/healer.md +78 -0
  14. package/lib/agents/planner.md +135 -0
  15. package/lib/cli.js +274 -0
  16. package/lib/common/config.js +274 -0
  17. package/lib/common/config.js.map +7 -0
  18. package/lib/common/configLoader.js +377 -0
  19. package/lib/common/configLoader.js.map +7 -0
  20. package/lib/common/esmLoaderHost.js +102 -0
  21. package/lib/common/esmLoaderHost.js.map +7 -0
  22. package/lib/common/expectBundle.js +52 -0
  23. package/lib/common/expectBundle.js.map +7 -0
  24. package/lib/common/expectBundleImpl.js +389 -0
  25. package/lib/common/expectBundleImpl.js.map +7 -0
  26. package/lib/common/fixtures.js +302 -0
  27. package/lib/common/fixtures.js.map +7 -0
  28. package/lib/common/globals.js +58 -0
  29. package/lib/common/globals.js.map +7 -0
  30. package/lib/common/ipc.js +60 -0
  31. package/lib/common/ipc.js.map +7 -0
  32. package/lib/common/poolBuilder.js +85 -0
  33. package/lib/common/poolBuilder.js.map +7 -0
  34. package/lib/common/process.js +104 -0
  35. package/lib/common/process.js.map +7 -0
  36. package/lib/common/suiteUtils.js +140 -0
  37. package/lib/common/suiteUtils.js.map +7 -0
  38. package/lib/common/test.js +321 -0
  39. package/lib/common/test.js.map +7 -0
  40. package/lib/common/testLoader.js +100 -0
  41. package/lib/common/testLoader.js.map +7 -0
  42. package/lib/common/testType.js +310 -0
  43. package/lib/common/testType.js.map +7 -0
  44. package/lib/fsWatcher.js +67 -0
  45. package/lib/fsWatcher.js.map +7 -0
  46. package/lib/index.js +696 -0
  47. package/lib/index.js.map +7 -0
  48. package/lib/internalsForTest.js +42 -0
  49. package/lib/internalsForTest.js.map +7 -0
  50. package/lib/isomorphic/events.js +77 -0
  51. package/lib/isomorphic/events.js.map +7 -0
  52. package/lib/isomorphic/folders.js +30 -0
  53. package/lib/isomorphic/folders.js.map +7 -0
  54. package/lib/isomorphic/stringInternPool.js +69 -0
  55. package/lib/isomorphic/stringInternPool.js.map +7 -0
  56. package/lib/isomorphic/teleReceiver.js +507 -0
  57. package/lib/isomorphic/teleReceiver.js.map +7 -0
  58. package/lib/isomorphic/teleSuiteUpdater.js +137 -0
  59. package/lib/isomorphic/teleSuiteUpdater.js.map +7 -0
  60. package/lib/isomorphic/testServerConnection.js +211 -0
  61. package/lib/isomorphic/testServerConnection.js.map +7 -0
  62. package/lib/isomorphic/testServerInterface.js +16 -0
  63. package/lib/isomorphic/testServerInterface.js.map +7 -0
  64. package/lib/isomorphic/testTree.js +334 -0
  65. package/lib/isomorphic/testTree.js.map +7 -0
  66. package/lib/isomorphic/types.d.js +16 -0
  67. package/lib/isomorphic/types.d.js.map +7 -0
  68. package/lib/loader/loaderMain.js +59 -0
  69. package/lib/loader/loaderMain.js.map +7 -0
  70. package/lib/matchers/expect.js +325 -0
  71. package/lib/matchers/expect.js.map +7 -0
  72. package/lib/matchers/matcherHint.js +87 -0
  73. package/lib/matchers/matcherHint.js.map +7 -0
  74. package/lib/matchers/matchers.js +366 -0
  75. package/lib/matchers/matchers.js.map +7 -0
  76. package/lib/matchers/toBeTruthy.js +73 -0
  77. package/lib/matchers/toBeTruthy.js.map +7 -0
  78. package/lib/matchers/toEqual.js +99 -0
  79. package/lib/matchers/toEqual.js.map +7 -0
  80. package/lib/matchers/toHaveURL.js +102 -0
  81. package/lib/matchers/toHaveURL.js.map +7 -0
  82. package/lib/matchers/toMatchAriaSnapshot.js +159 -0
  83. package/lib/matchers/toMatchAriaSnapshot.js.map +7 -0
  84. package/lib/matchers/toMatchSnapshot.js +359 -0
  85. package/lib/matchers/toMatchSnapshot.js.map +7 -0
  86. package/lib/matchers/toMatchText.js +99 -0
  87. package/lib/matchers/toMatchText.js.map +7 -0
  88. package/lib/mcp/browser/actions.d.js +16 -0
  89. package/lib/mcp/browser/backend.js +93 -0
  90. package/lib/mcp/browser/backend.js.map +7 -0
  91. package/lib/mcp/browser/browserContextFactory.js +296 -0
  92. package/lib/mcp/browser/browserServerBackend.js +76 -0
  93. package/lib/mcp/browser/codegen.js +66 -0
  94. package/lib/mcp/browser/config.js +385 -0
  95. package/lib/mcp/browser/context.js +287 -0
  96. package/lib/mcp/browser/response.js +228 -0
  97. package/lib/mcp/browser/sessionLog.js +160 -0
  98. package/lib/mcp/browser/tab.js +277 -0
  99. package/lib/mcp/browser/tool.js +30 -0
  100. package/lib/mcp/browser/tool.js.map +7 -0
  101. package/lib/mcp/browser/tools/common.js +63 -0
  102. package/lib/mcp/browser/tools/console.js +44 -0
  103. package/lib/mcp/browser/tools/dialogs.js +60 -0
  104. package/lib/mcp/browser/tools/evaluate.js +70 -0
  105. package/lib/mcp/browser/tools/files.js +58 -0
  106. package/lib/mcp/browser/tools/form.js +74 -0
  107. package/lib/mcp/browser/tools/install.js +69 -0
  108. package/lib/mcp/browser/tools/keyboard.js +85 -0
  109. package/lib/mcp/browser/tools/mouse.js +107 -0
  110. package/lib/mcp/browser/tools/navigate.js +62 -0
  111. package/lib/mcp/browser/tools/network.js +54 -0
  112. package/lib/mcp/browser/tools/pdf.js +59 -0
  113. package/lib/mcp/browser/tools/screenshot.js +88 -0
  114. package/lib/mcp/browser/tools/snapshot.js +182 -0
  115. package/lib/mcp/browser/tools/tabs.js +67 -0
  116. package/lib/mcp/browser/tools/tool.js +49 -0
  117. package/lib/mcp/browser/tools/tracing.js +74 -0
  118. package/lib/mcp/browser/tools/utils.js +100 -0
  119. package/lib/mcp/browser/tools/verify.js +154 -0
  120. package/lib/mcp/browser/tools/wait.js +63 -0
  121. package/lib/mcp/browser/tools.js +80 -0
  122. package/lib/mcp/browser/tools.js.map +7 -0
  123. package/lib/mcp/browser/watchdog.js +44 -0
  124. package/lib/mcp/config.d.js +16 -0
  125. package/lib/mcp/extension/cdpRelay.js +351 -0
  126. package/lib/mcp/extension/extensionContextFactory.js +75 -0
  127. package/lib/mcp/extension/protocol.js +28 -0
  128. package/lib/mcp/index.js +61 -0
  129. package/lib/mcp/log.js +35 -0
  130. package/lib/mcp/program.js +96 -0
  131. package/lib/mcp/sdk/bundle.js +81 -0
  132. package/lib/mcp/sdk/bundle.js.map +7 -0
  133. package/lib/mcp/sdk/call.js +49 -0
  134. package/lib/mcp/sdk/call.js.map +7 -0
  135. package/lib/mcp/sdk/exports.js +32 -0
  136. package/lib/mcp/sdk/exports.js.map +7 -0
  137. package/lib/mcp/sdk/http.js +187 -0
  138. package/lib/mcp/sdk/http.js.map +7 -0
  139. package/lib/mcp/sdk/inProcessTransport.js +71 -0
  140. package/lib/mcp/sdk/inProcessTransport.js.map +7 -0
  141. package/lib/mcp/sdk/mdb.js +206 -0
  142. package/lib/mcp/sdk/mdb.js.map +7 -0
  143. package/lib/mcp/sdk/proxyBackend.js +128 -0
  144. package/lib/mcp/sdk/proxyBackend.js.map +7 -0
  145. package/lib/mcp/sdk/server.js +189 -0
  146. package/lib/mcp/sdk/server.js.map +7 -0
  147. package/lib/mcp/sdk/tool.js +51 -0
  148. package/lib/mcp/sdk/tool.js.map +7 -0
  149. package/lib/mcp/test/backend.js +67 -0
  150. package/lib/mcp/test/backend.js.map +7 -0
  151. package/lib/mcp/test/browserBackend.js +98 -0
  152. package/lib/mcp/test/context.js +48 -0
  153. package/lib/mcp/test/context.js.map +7 -0
  154. package/lib/mcp/test/generatorTools.js +122 -0
  155. package/lib/mcp/test/plannerTools.js +46 -0
  156. package/lib/mcp/test/seed.js +72 -0
  157. package/lib/mcp/test/streams.js +39 -0
  158. package/lib/mcp/test/streams.js.map +7 -0
  159. package/lib/mcp/test/testBackend.js +97 -0
  160. package/lib/mcp/test/testContext.js +176 -0
  161. package/lib/mcp/test/testTool.js +30 -0
  162. package/lib/mcp/test/testTools.js +115 -0
  163. package/lib/mcp/test/tool.js +30 -0
  164. package/lib/mcp/test/tool.js.map +7 -0
  165. package/lib/mcp/test/tools.js +150 -0
  166. package/lib/mcp/test/tools.js.map +7 -0
  167. package/lib/mcp/vscode/host.js +187 -0
  168. package/lib/mcp/vscode/main.js +77 -0
  169. package/lib/mcpBundleImpl.js +41 -0
  170. package/lib/mcpBundleImpl.js.map +7 -0
  171. package/lib/plugins/gitCommitInfoPlugin.js +198 -0
  172. package/lib/plugins/gitCommitInfoPlugin.js.map +7 -0
  173. package/lib/plugins/index.js +28 -0
  174. package/lib/plugins/index.js.map +7 -0
  175. package/lib/plugins/webServerPlugin.js +209 -0
  176. package/lib/plugins/webServerPlugin.js.map +7 -0
  177. package/lib/program.js +412 -0
  178. package/lib/program.js.map +7 -0
  179. package/lib/reporters/base.js +609 -0
  180. package/lib/reporters/base.js.map +7 -0
  181. package/lib/reporters/blob.js +135 -0
  182. package/lib/reporters/blob.js.map +7 -0
  183. package/lib/reporters/dot.js +82 -0
  184. package/lib/reporters/dot.js.map +7 -0
  185. package/lib/reporters/empty.js +32 -0
  186. package/lib/reporters/empty.js.map +7 -0
  187. package/lib/reporters/github.js +128 -0
  188. package/lib/reporters/github.js.map +7 -0
  189. package/lib/reporters/html.js +644 -0
  190. package/lib/reporters/html.js.map +7 -0
  191. package/lib/reporters/internalReporter.js +130 -0
  192. package/lib/reporters/internalReporter.js.map +7 -0
  193. package/lib/reporters/json.js +254 -0
  194. package/lib/reporters/json.js.map +7 -0
  195. package/lib/reporters/junit.js +230 -0
  196. package/lib/reporters/junit.js.map +7 -0
  197. package/lib/reporters/line.js +113 -0
  198. package/lib/reporters/line.js.map +7 -0
  199. package/lib/reporters/list.js +235 -0
  200. package/lib/reporters/list.js.map +7 -0
  201. package/lib/reporters/listModeReporter.js +69 -0
  202. package/lib/reporters/listModeReporter.js.map +7 -0
  203. package/lib/reporters/markdown.js +144 -0
  204. package/lib/reporters/markdown.js.map +7 -0
  205. package/lib/reporters/merge.js +535 -0
  206. package/lib/reporters/merge.js.map +7 -0
  207. package/lib/reporters/multiplexer.js +104 -0
  208. package/lib/reporters/multiplexer.js.map +7 -0
  209. package/lib/reporters/reporterV2.js +102 -0
  210. package/lib/reporters/reporterV2.js.map +7 -0
  211. package/lib/reporters/teleEmitter.js +297 -0
  212. package/lib/reporters/teleEmitter.js.map +7 -0
  213. package/lib/reporters/versions/blobV1.js +16 -0
  214. package/lib/reporters/versions/blobV1.js.map +7 -0
  215. package/lib/runner/dispatcher.js +491 -0
  216. package/lib/runner/dispatcher.js.map +7 -0
  217. package/lib/runner/failureTracker.js +72 -0
  218. package/lib/runner/failureTracker.js.map +7 -0
  219. package/lib/runner/lastRun.js +77 -0
  220. package/lib/runner/lastRun.js.map +7 -0
  221. package/lib/runner/loadUtils.js +333 -0
  222. package/lib/runner/loadUtils.js.map +7 -0
  223. package/lib/runner/loaderHost.js +89 -0
  224. package/lib/runner/loaderHost.js.map +7 -0
  225. package/lib/runner/processHost.js +161 -0
  226. package/lib/runner/processHost.js.map +7 -0
  227. package/lib/runner/projectUtils.js +241 -0
  228. package/lib/runner/projectUtils.js.map +7 -0
  229. package/lib/runner/rebase.js +189 -0
  230. package/lib/runner/rebase.js.map +7 -0
  231. package/lib/runner/reporters.js +137 -0
  232. package/lib/runner/reporters.js.map +7 -0
  233. package/lib/runner/runner.js +173 -0
  234. package/lib/runner/sigIntWatcher.js +96 -0
  235. package/lib/runner/sigIntWatcher.js.map +7 -0
  236. package/lib/runner/taskRunner.js +127 -0
  237. package/lib/runner/taskRunner.js.map +7 -0
  238. package/lib/runner/tasks.js +410 -0
  239. package/lib/runner/tasks.js.map +7 -0
  240. package/lib/runner/testGroups.js +117 -0
  241. package/lib/runner/testGroups.js.map +7 -0
  242. package/lib/runner/testRunner.js +390 -0
  243. package/lib/runner/testRunner.js.map +7 -0
  244. package/lib/runner/testServer.js +264 -0
  245. package/lib/runner/testServer.js.map +7 -0
  246. package/lib/runner/uiMode.js +271 -0
  247. package/lib/runner/uiModeReporter.js +30 -0
  248. package/lib/runner/uiModeReporter.js.map +7 -0
  249. package/lib/runner/vcs.js +72 -0
  250. package/lib/runner/vcs.js.map +7 -0
  251. package/lib/runner/watchMode.js +395 -0
  252. package/lib/runner/watchMode.js.map +7 -0
  253. package/lib/runner/workerHost.js +95 -0
  254. package/lib/runner/workerHost.js.map +7 -0
  255. package/lib/store.js +98 -0
  256. package/lib/third_party/pirates.js +62 -0
  257. package/lib/third_party/pirates.js.map +7 -0
  258. package/lib/third_party/tsconfig-loader.js +103 -0
  259. package/lib/third_party/tsconfig-loader.js.map +7 -0
  260. package/lib/transform/babelBundle.js +43 -0
  261. package/lib/transform/babelBundle.js.map +7 -0
  262. package/lib/transform/babelBundleImpl.js +461 -0
  263. package/lib/transform/babelBundleImpl.js.map +7 -0
  264. package/lib/transform/compilationCache.js +272 -0
  265. package/lib/transform/compilationCache.js.map +7 -0
  266. package/lib/transform/esmLoader.js +104 -0
  267. package/lib/transform/esmLoader.js.map +7 -0
  268. package/lib/transform/esmUtils.js +32 -0
  269. package/lib/transform/portTransport.js +67 -0
  270. package/lib/transform/portTransport.js.map +7 -0
  271. package/lib/transform/transform.js +293 -0
  272. package/lib/transform/transform.js.map +7 -0
  273. package/lib/util.js +403 -0
  274. package/lib/util.js.map +7 -0
  275. package/lib/utilsBundle.js +43 -0
  276. package/lib/utilsBundle.js.map +7 -0
  277. package/lib/utilsBundleImpl.js +100 -0
  278. package/lib/utilsBundleImpl.js.map +7 -0
  279. package/lib/worker/fixtureRunner.js +258 -0
  280. package/lib/worker/fixtureRunner.js.map +7 -0
  281. package/lib/worker/stepContext.js +34 -0
  282. package/lib/worker/testInfo.js +508 -0
  283. package/lib/worker/testInfo.js.map +7 -0
  284. package/lib/worker/testTracing.js +344 -0
  285. package/lib/worker/testTracing.js.map +7 -0
  286. package/lib/worker/timeoutManager.js +174 -0
  287. package/lib/worker/timeoutManager.js.map +7 -0
  288. package/lib/worker/util.js +31 -0
  289. package/lib/worker/util.js.map +7 -0
  290. package/lib/worker/workerMain.js +520 -0
  291. package/lib/worker/workerMain.js.map +7 -0
  292. package/package.json +74 -0
  293. package/test.d.ts +18 -0
  294. package/test.js +24 -0
  295. package/test.mjs +33 -0
  296. package/types/test.d.ts +10217 -0
  297. package/types/testReporter.d.ts +816 -0
@@ -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,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/transform/compilationCache.ts"],
4
+ "sourcesContent": ["/**\n * Copyright (c) Microsoft Corporation.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from 'fs';\nimport os from 'os';\nimport path from 'path';\n\nimport { isWorkerProcess } from '../common/globals';\nimport { sourceMapSupport } from '../utilsBundle';\n\nexport type MemoryCache = {\n codePath: string;\n sourceMapPath: string;\n dataPath: string;\n moduleUrl?: string;\n};\n\nexport type SerializedCompilationCache = {\n sourceMaps: [string, string][],\n memoryCache: [string, MemoryCache][],\n fileDependencies: [string, string[]][],\n externalDependencies: [string, string[]][],\n};\n\n// Assumptions for the compilation cache:\n// - Files in the temp directory we work with can disappear at any moment, either some of them or all together.\n// - Multiple workers can be trying to read from the compilation cache at the same time.\n// - There is a single invocation of the test runner at a time.\n//\n// Therefore, we implement the following logic:\n// - Never assume that file is present, always try to read it to determine whether it's actually present.\n// - Never write to the cache from worker processes to avoid \"multiple writers\" races.\n// - Since we perform all static imports in the runner beforehand, most of the time\n// workers should be able to read from the cache.\n// - For workers-only dynamic imports or some cache problems, we will re-transpile files in\n// each worker anew.\n\nexport const cacheDir = process.env.PWTEST_CACHE_DIR || (() => {\n if (process.platform === 'win32')\n return path.join(os.tmpdir(), `playwright-transform-cache`);\n // Use `geteuid()` instead of more natural `os.userInfo().username`\n // since `os.userInfo()` is not always available.\n // Note: `process.geteuid()` is not available on windows.\n // See https://github.com/microsoft/playwright/issues/22721\n return path.join(os.tmpdir(), `playwright-transform-cache-` + process.geteuid?.());\n})();\n\nconst sourceMaps: Map<string, string> = new Map();\nconst memoryCache = new Map<string, MemoryCache>();\n// Dependencies resolved by the loader.\nconst fileDependencies = new Map<string, Set<string>>();\n// Dependencies resolved by the external bundler.\nconst externalDependencies = new Map<string, Set<string>>();\n\nexport function installSourceMapSupport() {\n Error.stackTraceLimit = 200;\n\n sourceMapSupport.install({\n environment: 'node',\n handleUncaughtExceptions: false,\n retrieveSourceMap(source) {\n if (!sourceMaps.has(source))\n return null;\n const sourceMapPath = sourceMaps.get(source)!;\n try {\n return {\n map: JSON.parse(fs.readFileSync(sourceMapPath, 'utf-8')),\n url: source,\n };\n } catch {\n return null;\n }\n }\n });\n}\n\nfunction _innerAddToCompilationCacheAndSerialize(filename: string, entry: MemoryCache) {\n sourceMaps.set(entry.moduleUrl || filename, entry.sourceMapPath);\n memoryCache.set(filename, entry);\n return {\n sourceMaps: [[entry.moduleUrl || filename, entry.sourceMapPath]],\n memoryCache: [[filename, entry]],\n fileDependencies: [],\n externalDependencies: [],\n };\n}\n\ntype CompilationCacheLookupResult = {\n serializedCache?: any;\n cachedCode?: string;\n addToCache?: (code: string, map: any | undefined | null, data: Map<string, any>) => { serializedCache?: any };\n};\n\nexport function getFromCompilationCache(filename: string, hash: string, moduleUrl?: string): CompilationCacheLookupResult {\n // First check the memory cache by filename, this cache will always work in the worker,\n // because we just compiled this file in the loader.\n const cache = memoryCache.get(filename);\n if (cache?.codePath) {\n try {\n return { cachedCode: fs.readFileSync(cache.codePath, 'utf-8') };\n } catch {\n // Not able to read the file - fall through.\n }\n }\n\n // Then do the disk cache, this cache works between the Playwright Test runs.\n const cachePath = calculateCachePath(filename, hash);\n const codePath = cachePath + '.js';\n const sourceMapPath = cachePath + '.map';\n const dataPath = cachePath + '.data';\n try {\n const cachedCode = fs.readFileSync(codePath, 'utf8');\n const serializedCache = _innerAddToCompilationCacheAndSerialize(filename, { codePath, sourceMapPath, dataPath, moduleUrl });\n return { cachedCode, serializedCache };\n } catch {\n }\n\n return {\n addToCache: (code: string, map: any | undefined | null, data: Map<string, any>) => {\n if (isWorkerProcess())\n return {};\n fs.mkdirSync(path.dirname(cachePath), { recursive: true });\n if (map)\n fs.writeFileSync(sourceMapPath, JSON.stringify(map), 'utf8');\n if (data.size)\n fs.writeFileSync(dataPath, JSON.stringify(Object.fromEntries(data.entries()), undefined, 2), 'utf8');\n fs.writeFileSync(codePath, code, 'utf8');\n const serializedCache = _innerAddToCompilationCacheAndSerialize(filename, { codePath, sourceMapPath, dataPath, moduleUrl });\n return { serializedCache };\n }\n };\n}\n\nexport function serializeCompilationCache(): SerializedCompilationCache {\n return {\n sourceMaps: [...sourceMaps.entries()],\n memoryCache: [...memoryCache.entries()],\n fileDependencies: [...fileDependencies.entries()].map(([filename, deps]) => ([filename, [...deps]])),\n externalDependencies: [...externalDependencies.entries()].map(([filename, deps]) => ([filename, [...deps]])),\n };\n}\n\nexport function addToCompilationCache(payload: SerializedCompilationCache) {\n for (const entry of payload.sourceMaps)\n sourceMaps.set(entry[0], entry[1]);\n for (const entry of payload.memoryCache)\n memoryCache.set(entry[0], entry[1]);\n for (const entry of payload.fileDependencies) {\n const existing = fileDependencies.get(entry[0]) || [];\n fileDependencies.set(entry[0], new Set([...entry[1], ...existing]));\n }\n for (const entry of payload.externalDependencies) {\n const existing = externalDependencies.get(entry[0]) || [];\n externalDependencies.set(entry[0], new Set([...entry[1], ...existing]));\n }\n}\n\nfunction calculateCachePath(filePath: string, hash: string): string {\n const fileName = path.basename(filePath, path.extname(filePath)).replace(/\\W/g, '') + '_' + hash;\n return path.join(cacheDir, hash[0] + hash[1], fileName);\n}\n\n// Since ESM and CJS collect dependencies differently,\n// we go via the global state to collect them.\nlet depsCollector: Set<string> | undefined;\n\nexport function startCollectingFileDeps() {\n depsCollector = new Set();\n}\n\nexport function stopCollectingFileDeps(filename: string) {\n if (!depsCollector)\n return;\n depsCollector.delete(filename);\n for (const dep of depsCollector) {\n if (belongsToNodeModules(dep))\n depsCollector.delete(dep);\n }\n fileDependencies.set(filename, depsCollector);\n depsCollector = undefined;\n}\n\nexport function currentFileDepsCollector(): Set<string> | undefined {\n return depsCollector;\n}\n\nexport function setExternalDependencies(filename: string, deps: string[]) {\n const depsSet = new Set(deps.filter(dep => !belongsToNodeModules(dep) && dep !== filename));\n externalDependencies.set(filename, depsSet);\n}\n\nexport function fileDependenciesForTest() {\n return fileDependencies;\n}\n\nexport function collectAffectedTestFiles(changedFile: string, testFileCollector: Set<string>) {\n const isTestFile = (file: string) => fileDependencies.has(file);\n\n if (isTestFile(changedFile))\n testFileCollector.add(changedFile);\n\n for (const [testFile, deps] of fileDependencies) {\n if (deps.has(changedFile))\n testFileCollector.add(testFile);\n }\n\n for (const [importingFile, depsOfImportingFile] of externalDependencies) {\n if (depsOfImportingFile.has(changedFile)) {\n if (isTestFile(importingFile))\n testFileCollector.add(importingFile);\n\n for (const [testFile, depsOfTestFile] of fileDependencies) {\n if (depsOfTestFile.has(importingFile))\n testFileCollector.add(testFile);\n }\n }\n }\n}\n\nexport function affectedTestFiles(changes: string[]): string[] {\n const result = new Set<string>();\n for (const change of changes)\n collectAffectedTestFiles(change, result);\n return [...result];\n}\n\nexport function internalDependenciesForTestFile(filename: string): Set<string> | undefined{\n return fileDependencies.get(filename);\n}\n\nexport function dependenciesForTestFile(filename: string): Set<string> {\n const result = new Set<string>();\n for (const testDependency of fileDependencies.get(filename) || []) {\n result.add(testDependency);\n for (const externalDependency of externalDependencies.get(testDependency) || [])\n result.add(externalDependency);\n }\n for (const dep of externalDependencies.get(filename) || [])\n result.add(dep);\n return result;\n}\n\n// This is only used in the dev mode, specifically excluding\n// files from packages/playwright*. In production mode, node_modules covers\n// that.\nconst kPlaywrightInternalPrefix = path.resolve(__dirname, '../../../playwright');\n\nexport function belongsToNodeModules(file: string) {\n if (file.includes(`${path.sep}node_modules${path.sep}`))\n return true;\n if (file.startsWith(kPlaywrightInternalPrefix) && (file.endsWith('.js') || file.endsWith('.mjs')))\n return true;\n return false;\n}\n\nexport async function getUserData(pluginName: string): Promise<Map<string, any>> {\n const result = new Map<string, any>();\n for (const [fileName, cache] of memoryCache) {\n if (!cache.dataPath)\n continue;\n if (!fs.existsSync(cache.dataPath))\n continue;\n const data = JSON.parse(await fs.promises.readFile(cache.dataPath, 'utf8'));\n if (data[pluginName])\n result.set(fileName, data[pluginName]);\n }\n return result;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,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E,WAAO,IAAI,cAAc;AACzB,eAAW,sBAAsB,qBAAqB,IAAI,cAAc,KAAK,CAAC;AAC5E,aAAO,IAAI,kBAAkB;AAAA,EACjC;AACA,aAAW,OAAO,qBAAqB,IAAI,QAAQ,KAAK,CAAC;AACvD,WAAO,IAAI,GAAG;AAChB,SAAO;AACT;AAKA,MAAM,4BAA4B,YAAAA,QAAK,QAAQ,WAAW,qBAAqB;AAExE,SAAS,qBAAqB,MAAc;AACjD,MAAI,KAAK,SAAS,GAAG,YAAAA,QAAK,GAAG,eAAe,YAAAA,QAAK,GAAG,EAAE;AACpD,WAAO;AACT,MAAI,KAAK,WAAW,yBAAyB,MAAM,KAAK,SAAS,KAAK,KAAK,KAAK,SAAS,MAAM;AAC7F,WAAO;AACT,SAAO;AACT;AAEA,eAAsB,YAAY,YAA+C;AAC/E,QAAM,SAAS,oBAAI,IAAiB;AACpC,aAAW,CAAC,UAAU,KAAK,KAAK,aAAa;AAC3C,QAAI,CAAC,MAAM;AACT;AACF,QAAI,CAAC,UAAAE,QAAG,WAAW,MAAM,QAAQ;AAC/B;AACF,UAAM,OAAO,KAAK,MAAM,MAAM,UAAAA,QAAG,SAAS,SAAS,MAAM,UAAU,MAAM,CAAC;AAC1E,QAAI,KAAK,UAAU;AACjB,aAAO,IAAI,UAAU,KAAK,UAAU,CAAC;AAAA,EACzC;AACA,SAAO;AACT;",
6
+ "names": ["path", "os", "fs"]
7
+ }
@@ -0,0 +1,104 @@
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
+ async function resolve(specifier, context, defaultResolve) {
31
+ if (context.parentURL && context.parentURL.startsWith("file://")) {
32
+ const filename = import_url.default.fileURLToPath(context.parentURL);
33
+ const resolved = (0, import_transform.resolveHook)(filename, specifier);
34
+ if (resolved !== void 0)
35
+ specifier = import_url.default.pathToFileURL(resolved).toString();
36
+ }
37
+ const result = await defaultResolve(specifier, context, defaultResolve);
38
+ if (result?.url && result.url.startsWith("file://"))
39
+ (0, import_compilationCache.currentFileDepsCollector)()?.add(import_url.default.fileURLToPath(result.url));
40
+ return result;
41
+ }
42
+ const kSupportedFormats = /* @__PURE__ */ new Map([
43
+ ["commonjs", "commonjs"],
44
+ ["module", "module"],
45
+ ["commonjs-typescript", "commonjs"],
46
+ ["module-typescript", "module"],
47
+ [null, null],
48
+ [void 0, void 0]
49
+ ]);
50
+ async function load(moduleUrl, context, defaultLoad) {
51
+ if (!kSupportedFormats.has(context.format))
52
+ return defaultLoad(moduleUrl, context, defaultLoad);
53
+ if (!moduleUrl.startsWith("file://"))
54
+ return defaultLoad(moduleUrl, context, defaultLoad);
55
+ const filename = import_url.default.fileURLToPath(moduleUrl);
56
+ if (!(0, import_transform.shouldTransform)(filename))
57
+ return defaultLoad(moduleUrl, context, defaultLoad);
58
+ const code = import_fs.default.readFileSync(filename, "utf-8");
59
+ const transformed = (0, import_transform.transformHook)(code, filename, moduleUrl);
60
+ if (transformed.serializedCache) {
61
+ if (legacyWaitForSourceMaps)
62
+ await transport?.send("pushToCompilationCache", { cache: transformed.serializedCache });
63
+ else
64
+ transport?.post("pushToCompilationCache", { cache: transformed.serializedCache });
65
+ }
66
+ return {
67
+ format: kSupportedFormats.get(context.format) || ((0, import_util.fileIsModule)(filename) ? "module" : "commonjs"),
68
+ source: transformed.code,
69
+ shortCircuit: true
70
+ };
71
+ }
72
+ let transport;
73
+ let legacyWaitForSourceMaps = false;
74
+ function initialize(data) {
75
+ transport = createTransport(data?.port);
76
+ legacyWaitForSourceMaps = !!process.env.PLAYWRIGHT_WAIT_FOR_SOURCE_MAPS;
77
+ }
78
+ function createTransport(port) {
79
+ return new import_portTransport.PortTransport(port, async (method, params) => {
80
+ if (method === "setSingleTSConfig") {
81
+ (0, import_transform.setSingleTSConfig)(params.tsconfig);
82
+ return;
83
+ }
84
+ if (method === "setTransformConfig") {
85
+ (0, import_transform.setTransformConfig)(params.config);
86
+ return;
87
+ }
88
+ if (method === "addToCompilationCache") {
89
+ (0, import_compilationCache.addToCompilationCache)(params.cache);
90
+ return;
91
+ }
92
+ if (method === "getCompilationCache")
93
+ return { cache: (0, import_compilationCache.serializeCompilationCache)() };
94
+ if (method === "startCollectingFileDeps") {
95
+ (0, import_compilationCache.startCollectingFileDeps)();
96
+ return;
97
+ }
98
+ if (method === "stopCollectingFileDeps") {
99
+ (0, import_compilationCache.stopCollectingFileDeps)(params.file);
100
+ return;
101
+ }
102
+ });
103
+ }
104
+ module.exports = { initialize, load, resolve };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/transform/esmLoader.ts"],
4
+ "sourcesContent": ["/**\n * Copyright (c) Microsoft Corporation.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from 'fs';\nimport url from 'url';\n\nimport { addToCompilationCache, currentFileDepsCollector, serializeCompilationCache, startCollectingFileDeps, stopCollectingFileDeps } from './compilationCache';\nimport { PortTransport } from './portTransport';\nimport { resolveHook, setSingleTSConfig, setTransformConfig, shouldTransform, transformHook } from './transform';\nimport { fileIsModule } from '../util';\n\n// Node < 18.6: defaultResolve takes 3 arguments.\n// Node >= 18.6: nextResolve from the chain takes 2 arguments.\nasync function resolve(specifier: string, context: { parentURL?: string }, defaultResolve: Function) {\n if (context.parentURL && context.parentURL.startsWith('file://')) {\n const filename = url.fileURLToPath(context.parentURL);\n const resolved = resolveHook(filename, specifier);\n if (resolved !== undefined)\n specifier = url.pathToFileURL(resolved).toString();\n }\n const result = await defaultResolve(specifier, context, defaultResolve);\n // Note: we collect dependencies here that will be sent to the main thread\n // (and optionally runner process) after the loading finishes.\n if (result?.url && result.url.startsWith('file://'))\n currentFileDepsCollector()?.add(url.fileURLToPath(result.url));\n\n return result;\n}\n\n// non-js files have undefined\n// some js files have null\n// {module/commonjs}-typescript are changed to {module,commonjs} because we handle typescript ourselves\nconst kSupportedFormats = new Map([\n ['commonjs', 'commonjs'],\n ['module', 'module'],\n ['commonjs-typescript', 'commonjs'],\n ['module-typescript', 'module'],\n [null, null],\n [undefined, undefined]\n]);\n\n// Node < 18.6: defaultLoad takes 3 arguments.\n// Node >= 18.6: nextLoad from the chain takes 2 arguments.\nasync function load(moduleUrl: string, context: { format?: string }, defaultLoad: Function) {\n // Bail out for wasm, json, etc.\n if (!kSupportedFormats.has(context.format))\n return defaultLoad(moduleUrl, context, defaultLoad);\n\n // Bail for built-in modules.\n if (!moduleUrl.startsWith('file://'))\n return defaultLoad(moduleUrl, context, defaultLoad);\n\n const filename = url.fileURLToPath(moduleUrl);\n // Bail for node_modules.\n if (!shouldTransform(filename))\n return defaultLoad(moduleUrl, context, defaultLoad);\n\n const code = fs.readFileSync(filename, 'utf-8');\n const transformed = transformHook(code, filename, moduleUrl);\n\n // Flush the source maps to the main thread, so that errors during import() are source-mapped.\n if (transformed.serializedCache) {\n if (legacyWaitForSourceMaps)\n await transport?.send('pushToCompilationCache', { cache: transformed.serializedCache });\n else\n transport?.post('pushToCompilationCache', { cache: transformed.serializedCache });\n }\n\n // Output format is required, so we determine it manually when unknown.\n // shortCircuit is required by Node >= 18.6 to designate no more loaders should be called.\n return {\n format: kSupportedFormats.get(context.format) || (fileIsModule(filename) ? 'module' : 'commonjs'),\n source: transformed.code,\n shortCircuit: true,\n };\n}\n\nlet transport: PortTransport | undefined;\nlet legacyWaitForSourceMaps = false;\n\nfunction initialize(data: { port: MessagePort }) {\n transport = createTransport(data?.port);\n legacyWaitForSourceMaps = !!process.env.PLAYWRIGHT_WAIT_FOR_SOURCE_MAPS;\n}\n\nfunction createTransport(port: MessagePort) {\n return new PortTransport(port, async (method, params) => {\n if (method === 'setSingleTSConfig') {\n setSingleTSConfig(params.tsconfig);\n return;\n }\n\n if (method === 'setTransformConfig') {\n setTransformConfig(params.config);\n return;\n }\n\n if (method === 'addToCompilationCache') {\n addToCompilationCache(params.cache);\n return;\n }\n\n if (method === 'getCompilationCache')\n return { cache: serializeCompilationCache() };\n\n if (method === 'startCollectingFileDeps') {\n startCollectingFileDeps();\n return;\n }\n\n if (method === 'stopCollectingFileDeps') {\n stopCollectingFileDeps(params.file);\n return;\n }\n });\n}\n\n\nmodule.exports = { initialize, load, resolve };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAgBA,gBAAe;AACf,iBAAgB;AAEhB,8BAA4I;AAC5I,2BAA8B;AAC9B,uBAAmG;AACnG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AA0B,EAAE,OAAO,YAAY,gBAAgB,CAAC;AAAA,EACpF;AAIA,SAAO;AAAA,IACL,QAAQ,kBAAkB,IAAI,QAAQ,MAAM,UAAM,0BAAa,QAAQ,IAAI,WAAW;AAAA,IACtF,QAAQ,YAAY;AAAA,IACpB,cAAc;AAAA,EAChB;AACF;AAEA,IAAI;AACJ,IAAI,0BAA0B;AAE9B,SAAS,WAAW,MAA6B;AAC/C,cAAY,gBAAgB,MAAM,IAAI;AACtC,4BAA0B,CAAC,CAAC,QAAQ,IAAI;AAC1C;AAEA,SAAS,gBAAgB,MAAmB;AAC1C,SAAO,IAAI,mCAAc,MAAM,OAAO,QAAQ,WAAW;AACvD,QAAI,WAAW,qBAAqB;AAClC,8CAAkB,OAAO,QAAQ;AACjC;AAAA,IACF;AAEA,QAAI,WAAW,sBAAsB;AACnC,+CAAmB,OAAO,MAAM;AAChC;AAAA,IACF;AAEA,QAAI,WAAW,yBAAyB;AACtC,yDAAsB,OAAO,KAAK;AAClC;AAAA,IACF;AAEA,QAAI,WAAW;AACb,aAAO,EAAE,WAAO,mDAA0B,EAAE;AAE9C,QAAI,WAAW,2BAA2B;AACxC,2DAAwB;AACxB;AAAA,IACF;AAEA,QAAI,WAAW,0BAA0B;AACvC,0DAAuB,OAAO,IAAI;AAClC;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAGA,OAAO,UAAU,EAAE,YAAY,MAAM,QAAQ;",
6
+ "names": ["url", "fs"]
7
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.execArgvWithExperimentalLoaderOptions = execArgvWithExperimentalLoaderOptions;
7
+ exports.execArgvWithoutExperimentalLoaderOptions = execArgvWithoutExperimentalLoaderOptions;
8
+ var _url = _interopRequireDefault(require("url"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ /**
11
+ * Copyright (c) Microsoft Corporation.
12
+ *
13
+ * Licensed under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License.
15
+ * You may obtain a copy of the License at
16
+ *
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+
26
+ const kExperimentalLoaderOptions = ['--no-warnings', `--experimental-loader=${_url.default.pathToFileURL(require.resolve('playwright/lib/transform/esmLoader')).toString()}`];
27
+ function execArgvWithExperimentalLoaderOptions() {
28
+ return [...process.execArgv, ...kExperimentalLoaderOptions];
29
+ }
30
+ function execArgvWithoutExperimentalLoaderOptions() {
31
+ return process.execArgv.filter(arg => !kExperimentalLoaderOptions.includes(arg));
32
+ }
@@ -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
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/transform/portTransport.ts"],
4
+ "sourcesContent": ["/**\n * Copyright (c) Microsoft Corporation.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport class PortTransport {\n private _lastId = 0;\n private _port: MessagePort;\n private _callbacks = new Map<number, (result: any) => void>();\n\n constructor(port: MessagePort, handler: (method: string, params: any) => Promise<any>) {\n this._port = port;\n port.addEventListener('message', async event => {\n const message = event.data;\n const { id, ackId, method, params, result } = message;\n\n if (ackId) {\n const callback = this._callbacks.get(ackId);\n this._callbacks.delete(ackId);\n this._resetRef();\n callback?.(result);\n return;\n }\n\n const handlerResult = await handler(method, params);\n if (id)\n this._port.postMessage({ ackId: id, result: handlerResult });\n });\n // Make sure to unref **after** adding a 'message' event listener.\n // https://nodejs.org/api/worker_threads.html#portref\n this._resetRef();\n }\n\n post(method: string, params: any) {\n this._port.postMessage({ method, params });\n }\n\n async send(method: string, params: any) {\n return await new Promise<any>(f => {\n const id = ++this._lastId;\n this._callbacks.set(id, f);\n this._resetRef();\n this._port.postMessage({ id, method, params });\n });\n }\n\n private _resetRef() {\n if (this._callbacks.size) {\n // When we are waiting for a response, ref the port to prevent this process from exiting.\n (this._port as any).ref();\n } else {\n // When we are not waiting for a response, unref the port to prevent this process\n // from hanging forever.\n (this._port as any).unref();\n }\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBO,MAAM,cAAc;AAAA,EAKzB,YAAY,MAAmB,SAAwD;AAJvF,SAAQ,UAAU;AAElB,SAAQ,aAAa,oBAAI,IAAmC;AAG1D,SAAK,QAAQ;AACb,SAAK,iBAAiB,WAAW,OAAM,UAAS;AAC9C,YAAM,UAAU,MAAM;AACtB,YAAM,EAAE,IAAI,OAAO,QAAQ,QAAQ,OAAO,IAAI;AAE9C,UAAI,OAAO;AACT,cAAM,WAAW,KAAK,WAAW,IAAI,KAAK;AAC1C,aAAK,WAAW,OAAO,KAAK;AAC5B,aAAK,UAAU;AACf,mBAAW,MAAM;AACjB;AAAA,MACF;AAEA,YAAM,gBAAgB,MAAM,QAAQ,QAAQ,MAAM;AAClD,UAAI;AACF,aAAK,MAAM,YAAY,EAAE,OAAO,IAAI,QAAQ,cAAc,CAAC;AAAA,IAC/D,CAAC;AAGD,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,KAAK,QAAgB,QAAa;AAChC,SAAK,MAAM,YAAY,EAAE,QAAQ,OAAO,CAAC;AAAA,EAC3C;AAAA,EAEA,MAAM,KAAK,QAAgB,QAAa;AACtC,WAAO,MAAM,IAAI,QAAa,OAAK;AACjC,YAAM,KAAK,EAAE,KAAK;AAClB,WAAK,WAAW,IAAI,IAAI,CAAC;AACzB,WAAK,UAAU;AACf,WAAK,MAAM,YAAY,EAAE,IAAI,QAAQ,OAAO,CAAC;AAAA,IAC/C,CAAC;AAAA,EACH;AAAA,EAEQ,YAAY;AAClB,QAAI,KAAK,WAAW,MAAM;AAExB,MAAC,KAAK,MAAc,IAAI;AAAA,IAC1B,OAAO;AAGL,MAAC,KAAK,MAAc,MAAM;AAAA,IAC5B;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }