feat(auth): implement user authentication system

This commit is contained in:
J.A.R.V.I.S. 2026-03-19 23:10:50 +00:00
parent 4847ab793a
commit 25cea4fbe8
12051 changed files with 1462377 additions and 0 deletions

View file

@ -0,0 +1,46 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var babelBundle_exports = {};
__export(babelBundle_exports, {
babelParse: () => babelParse,
babelTransform: () => babelTransform,
codeFrameColumns: () => codeFrameColumns,
declare: () => declare,
genMapping: () => genMapping,
traverse: () => traverse,
types: () => types
});
module.exports = __toCommonJS(babelBundle_exports);
const codeFrameColumns = require("./babelBundleImpl").codeFrameColumns;
const declare = require("./babelBundleImpl").declare;
const types = require("./babelBundleImpl").types;
const traverse = require("./babelBundleImpl").traverse;
const babelTransform = require("./babelBundleImpl").babelTransform;
const babelParse = require("./babelBundleImpl").babelParse;
const genMapping = require("./babelBundleImpl").genMapping;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
babelParse,
babelTransform,
codeFrameColumns,
declare,
genMapping,
traverse,
types
});

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,274 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var compilationCache_exports = {};
__export(compilationCache_exports, {
addToCompilationCache: () => addToCompilationCache,
affectedTestFiles: () => affectedTestFiles,
belongsToNodeModules: () => belongsToNodeModules,
cacheDir: () => cacheDir,
collectAffectedTestFiles: () => collectAffectedTestFiles,
currentFileDepsCollector: () => currentFileDepsCollector,
dependenciesForTestFile: () => dependenciesForTestFile,
fileDependenciesForTest: () => fileDependenciesForTest,
getFromCompilationCache: () => getFromCompilationCache,
getUserData: () => getUserData,
installSourceMapSupport: () => installSourceMapSupport,
internalDependenciesForTestFile: () => internalDependenciesForTestFile,
serializeCompilationCache: () => serializeCompilationCache,
setExternalDependencies: () => setExternalDependencies,
startCollectingFileDeps: () => startCollectingFileDeps,
stopCollectingFileDeps: () => stopCollectingFileDeps
});
module.exports = __toCommonJS(compilationCache_exports);
var import_fs = __toESM(require("fs"));
var import_os = __toESM(require("os"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_globals = require("../common/globals");
var import_utilsBundle = require("../utilsBundle");
const cacheDir = process.env.PWTEST_CACHE_DIR || (() => {
if (process.platform === "win32")
return import_path.default.join(import_os.default.tmpdir(), `playwright-transform-cache`);
return import_path.default.join(import_os.default.tmpdir(), `playwright-transform-cache-` + process.geteuid?.());
})();
const sourceMaps = /* @__PURE__ */ new Map();
const memoryCache = /* @__PURE__ */ new Map();
const fileDependencies = /* @__PURE__ */ new Map();
const externalDependencies = /* @__PURE__ */ new Map();
function installSourceMapSupport() {
Error.stackTraceLimit = 200;
import_utilsBundle.sourceMapSupport.install({
environment: "node",
handleUncaughtExceptions: false,
retrieveSourceMap(source) {
if (source.startsWith("file://") && !sourceMaps.has(source))
source = source.substring("file://".length);
if (!sourceMaps.has(source))
return null;
const sourceMapPath = sourceMaps.get(source);
try {
return {
map: JSON.parse(import_fs.default.readFileSync(sourceMapPath, "utf-8")),
url: source
};
} catch {
return null;
}
}
});
}
function _innerAddToCompilationCacheAndSerialize(filename, entry) {
sourceMaps.set(entry.moduleUrl || filename, entry.sourceMapPath);
memoryCache.set(filename, entry);
return {
sourceMaps: [[entry.moduleUrl || filename, entry.sourceMapPath]],
memoryCache: [[filename, entry]],
fileDependencies: [],
externalDependencies: []
};
}
function getFromCompilationCache(filename, contentHash, moduleUrl) {
const cache = memoryCache.get(filename);
if (cache?.codePath) {
try {
return { cachedCode: import_fs.default.readFileSync(cache.codePath, "utf-8") };
} catch {
}
}
const filePathHash = calculateFilePathHash(filename);
const hashPrefix = filePathHash + "_" + contentHash.substring(0, 7);
const cacheFolderName = filePathHash.substring(0, 2);
const cachePath = calculateCachePath(filename, cacheFolderName, hashPrefix);
const codePath = cachePath + ".js";
const sourceMapPath = cachePath + ".map";
const dataPath = cachePath + ".data";
try {
const cachedCode = import_fs.default.readFileSync(codePath, "utf8");
const serializedCache = _innerAddToCompilationCacheAndSerialize(filename, { codePath, sourceMapPath, dataPath, moduleUrl });
return { cachedCode, serializedCache };
} catch {
}
return {
addToCache: (code, map, data) => {
if ((0, import_globals.isWorkerProcess)())
return {};
clearOldCacheEntries(cacheFolderName, filePathHash);
import_fs.default.mkdirSync(import_path.default.dirname(cachePath), { recursive: true });
if (map)
import_fs.default.writeFileSync(sourceMapPath, JSON.stringify(map), "utf8");
if (data.size)
import_fs.default.writeFileSync(dataPath, JSON.stringify(Object.fromEntries(data.entries()), void 0, 2), "utf8");
import_fs.default.writeFileSync(codePath, code, "utf8");
const serializedCache = _innerAddToCompilationCacheAndSerialize(filename, { codePath, sourceMapPath, dataPath, moduleUrl });
return { serializedCache };
}
};
}
function serializeCompilationCache() {
return {
sourceMaps: [...sourceMaps.entries()],
memoryCache: [...memoryCache.entries()],
fileDependencies: [...fileDependencies.entries()].map(([filename, deps]) => [filename, [...deps]]),
externalDependencies: [...externalDependencies.entries()].map(([filename, deps]) => [filename, [...deps]])
};
}
function addToCompilationCache(payload) {
for (const entry of payload.sourceMaps)
sourceMaps.set(entry[0], entry[1]);
for (const entry of payload.memoryCache)
memoryCache.set(entry[0], entry[1]);
for (const entry of payload.fileDependencies) {
const existing = fileDependencies.get(entry[0]) || [];
fileDependencies.set(entry[0], /* @__PURE__ */ new Set([...entry[1], ...existing]));
}
for (const entry of payload.externalDependencies) {
const existing = externalDependencies.get(entry[0]) || [];
externalDependencies.set(entry[0], /* @__PURE__ */ new Set([...entry[1], ...existing]));
}
}
function calculateFilePathHash(filePath) {
return (0, import_utils.calculateSha1)(filePath).substring(0, 10);
}
function calculateCachePath(filePath, cacheFolderName, hashPrefix) {
const fileName = hashPrefix + "_" + import_path.default.basename(filePath, import_path.default.extname(filePath)).replace(/\W/g, "");
return import_path.default.join(cacheDir, cacheFolderName, fileName);
}
function clearOldCacheEntries(cacheFolderName, filePathHash) {
const cachePath = import_path.default.join(cacheDir, cacheFolderName);
try {
const cachedRelevantFiles = import_fs.default.readdirSync(cachePath).filter((file) => file.startsWith(filePathHash));
for (const file of cachedRelevantFiles)
import_fs.default.rmSync(import_path.default.join(cachePath, file), { force: true });
} catch {
}
}
let depsCollector;
function startCollectingFileDeps() {
depsCollector = /* @__PURE__ */ new Set();
}
function stopCollectingFileDeps(filename) {
if (!depsCollector)
return;
depsCollector.delete(filename);
for (const dep of depsCollector) {
if (belongsToNodeModules(dep))
depsCollector.delete(dep);
}
fileDependencies.set(filename, depsCollector);
depsCollector = void 0;
}
function currentFileDepsCollector() {
return depsCollector;
}
function setExternalDependencies(filename, deps) {
const depsSet = new Set(deps.filter((dep) => !belongsToNodeModules(dep) && dep !== filename));
externalDependencies.set(filename, depsSet);
}
function fileDependenciesForTest() {
return fileDependencies;
}
function collectAffectedTestFiles(changedFile, testFileCollector) {
const isTestFile = (file) => fileDependencies.has(file);
if (isTestFile(changedFile))
testFileCollector.add(changedFile);
for (const [testFile, deps] of fileDependencies) {
if (deps.has(changedFile))
testFileCollector.add(testFile);
}
for (const [importingFile, depsOfImportingFile] of externalDependencies) {
if (depsOfImportingFile.has(changedFile)) {
if (isTestFile(importingFile))
testFileCollector.add(importingFile);
for (const [testFile, depsOfTestFile] of fileDependencies) {
if (depsOfTestFile.has(importingFile))
testFileCollector.add(testFile);
}
}
}
}
function affectedTestFiles(changes) {
const result = /* @__PURE__ */ new Set();
for (const change of changes)
collectAffectedTestFiles(change, result);
return [...result];
}
function internalDependenciesForTestFile(filename) {
return fileDependencies.get(filename);
}
function dependenciesForTestFile(filename) {
const result = /* @__PURE__ */ new Set();
for (const testDependency of fileDependencies.get(filename) || []) {
result.add(testDependency);
for (const externalDependency of externalDependencies.get(testDependency) || [])
result.add(externalDependency);
}
for (const dep of externalDependencies.get(filename) || [])
result.add(dep);
return result;
}
const kPlaywrightInternalPrefix = import_path.default.resolve(__dirname, "../../../playwright");
function belongsToNodeModules(file) {
if (file.includes(`${import_path.default.sep}node_modules${import_path.default.sep}`))
return true;
if (file.startsWith(kPlaywrightInternalPrefix) && (file.endsWith(".js") || file.endsWith(".mjs")))
return true;
return false;
}
async function getUserData(pluginName) {
const result = /* @__PURE__ */ new Map();
for (const [fileName, cache] of memoryCache) {
if (!cache.dataPath)
continue;
if (!import_fs.default.existsSync(cache.dataPath))
continue;
const data = JSON.parse(await import_fs.default.promises.readFile(cache.dataPath, "utf8"));
if (data[pluginName])
result.set(fileName, data[pluginName]);
}
return result;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
addToCompilationCache,
affectedTestFiles,
belongsToNodeModules,
cacheDir,
collectAffectedTestFiles,
currentFileDepsCollector,
dependenciesForTestFile,
fileDependenciesForTest,
getFromCompilationCache,
getUserData,
installSourceMapSupport,
internalDependenciesForTestFile,
serializeCompilationCache,
setExternalDependencies,
startCollectingFileDeps,
stopCollectingFileDeps
});

View file

@ -0,0 +1,103 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var import_fs = __toESM(require("fs"));
var import_url = __toESM(require("url"));
var import_compilationCache = require("./compilationCache");
var import_portTransport = require("./portTransport");
var import_transform = require("./transform");
var import_util = require("../util");
const esmPreflightExtension = ".esm.preflight";
async function resolve(originalSpecifier, context, defaultResolve) {
let specifier = originalSpecifier.replace(esmPreflightExtension, "");
if (context.parentURL && context.parentURL.startsWith("file://")) {
const filename = import_url.default.fileURLToPath(context.parentURL);
const resolved = (0, import_transform.resolveHook)(filename, specifier);
if (resolved !== void 0)
specifier = import_url.default.pathToFileURL(resolved).toString();
}
const result = await defaultResolve(specifier, context, defaultResolve);
if (result?.url && result.url.startsWith("file://"))
(0, import_compilationCache.currentFileDepsCollector)()?.add(import_url.default.fileURLToPath(result.url));
if (originalSpecifier.endsWith(esmPreflightExtension))
result.url = result.url + esmPreflightExtension;
return result;
}
const kSupportedFormats = /* @__PURE__ */ new Map([
["commonjs", "commonjs"],
["module", "module"],
["commonjs-typescript", "commonjs"],
["module-typescript", "module"],
[null, null],
[void 0, void 0]
]);
async function load(originalModuleUrl, context, defaultLoad) {
const moduleUrl = originalModuleUrl.replace(esmPreflightExtension, "");
if (!kSupportedFormats.has(context.format))
return defaultLoad(moduleUrl, context, defaultLoad);
if (!moduleUrl.startsWith("file://"))
return defaultLoad(moduleUrl, context, defaultLoad);
const filename = import_url.default.fileURLToPath(moduleUrl);
if (!(0, import_transform.shouldTransform)(filename))
return defaultLoad(moduleUrl, context, defaultLoad);
const code = import_fs.default.readFileSync(filename, "utf-8");
const transformed = (0, import_transform.transformHook)(code, filename, moduleUrl);
if (transformed.serializedCache)
transport?.post("pushToCompilationCache", { cache: transformed.serializedCache });
return {
format: kSupportedFormats.get(context.format) || ((0, import_util.fileIsModule)(filename) ? "module" : "commonjs"),
source: originalModuleUrl.endsWith(esmPreflightExtension) ? `void 0;` : transformed.code,
shortCircuit: true
};
}
let transport;
function initialize(data) {
transport = createTransport(data?.port);
}
function createTransport(port) {
return new import_portTransport.PortTransport(port, async (method, params) => {
if (method === "setSingleTSConfig") {
(0, import_transform.setSingleTSConfig)(params.tsconfig);
return;
}
if (method === "setTransformConfig") {
(0, import_transform.setTransformConfig)(params.config);
return;
}
if (method === "addToCompilationCache") {
(0, import_compilationCache.addToCompilationCache)(params.cache);
return;
}
if (method === "getCompilationCache")
return { cache: (0, import_compilationCache.serializeCompilationCache)() };
if (method === "startCollectingFileDeps") {
(0, import_compilationCache.startCollectingFileDeps)();
return;
}
if (method === "stopCollectingFileDeps") {
(0, import_compilationCache.stopCollectingFileDeps)(params.file);
return;
}
});
}
module.exports = { initialize, load, resolve };

221
backend/node_modules/playwright/lib/transform/md.js generated vendored Normal file
View file

@ -0,0 +1,221 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var md_exports = {};
__export(md_exports, {
transformMDToTS: () => transformMDToTS
});
module.exports = __toCommonJS(md_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_utilsBundle = require("../utilsBundle");
var import_babelBundle = require("./babelBundle");
function transformMDToTS(code, filename) {
const parsed = parseSpec(code, filename);
let fixtures = resolveFixtures(filename, parsed.props.find((prop) => prop[0] === "fixtures")?.[1]);
const seed = parsed.props.find((prop) => prop[0] === "seed")?.[1];
if (seed) {
const seedFile = import_path.default.resolve(import_path.default.dirname(filename), seed.text);
const seedContents = import_fs.default.readFileSync(seedFile, "utf-8");
const parsedSeed = parseSpec(seedContents, seedFile);
if (parsedSeed.tests.length !== 1)
throw new Error(`while parsing ${seedFile}: seed file must contain exactly one test`);
if (parsedSeed.tests[0].props.length)
throw new Error(`while parsing ${seedFile}: seed test must not have properties`);
for (const test of parsed.tests)
test.lines = parsedSeed.tests[0].lines.concat(test.lines);
const seedFixtures = resolveFixtures(seedFile, parsedSeed.props.find((prop) => prop[0] === "fixtures")?.[1]);
if (seedFixtures && fixtures)
throw new Error(`while parsing ${filename}: either seed or test can specify fixtures, but not both`);
fixtures ??= seedFixtures;
}
const map = new import_babelBundle.genMapping.GenMapping({});
const lines = [];
const addLine = (line) => {
lines.push(line.text);
if (line.source) {
import_babelBundle.genMapping.addMapping(map, {
generated: { line: lines.length, column: 0 },
source: line.source.filename,
original: { line: line.source.line, column: line.source.column - 1 }
});
}
};
if (fixtures)
addLine({ text: `import { test, expect } from ${escapeString(import_path.default.relative(import_path.default.dirname(filename), fixtures.text))};`, source: fixtures.source });
else
addLine({ text: `import { test, expect } from '@playwright/test';` });
addLine({ text: `test.describe(${escapeString(parsed.describe.text)}, () => {`, source: parsed.describe.source });
for (const test of parsed.tests) {
const tags = [];
const annotations = [];
for (const [key, value] of test.props) {
if (key === "tag") {
tags.push(...value.text.split(" ").map((s) => s.trim()).filter((s) => !!s));
} else if (key === "annotation") {
if (!value.text.includes("="))
throw new Error(`while parsing ${filename}: annotation must be in format "type=description", found "${value}"`);
const [type, description] = value.text.split("=").map((s) => s.trim());
annotations.push({ type, description });
}
}
let props = "";
if (tags.length || annotations.length) {
props = "{ ";
if (tags.length)
props += `tag: [${tags.map((tag) => escapeString(tag)).join(", ")}], `;
if (annotations.length)
props += `annotation: [${annotations.map((a) => `{ type: ${escapeString(a.type)}, description: ${escapeString(a.description)} }`).join(", ")}], `;
props += "}, ";
}
addLine({ text: ` test(${escapeString(test.title.text)}, ${props}async ({ page, agent }) => {`, source: test.title.source });
for (const line of test.lines)
addLine({ text: " " + line.text, source: line.source });
addLine({ text: ` });`, source: test.title.source });
}
addLine({ text: `});`, source: parsed.describe.source });
addLine({ text: `` });
const encodedMap = import_babelBundle.genMapping.toEncodedMap(map);
const result = lines.join("\n");
return { code: result, map: encodedMap };
}
function resolveFixtures(filename, prop) {
if (!prop)
return;
return { text: import_path.default.resolve(import_path.default.dirname(filename), prop.text), source: prop.source };
}
function escapeString(s) {
return `'` + s.replace(/\n/g, " ").replace(/'/g, `\\'`) + `'`;
}
function parsingError(filename, node, message) {
const position = node?.position?.start ? ` at ${node.position.start.line}:${node.position.start.column}` : "";
return new Error(`while parsing ${filename}${position}: ${message}`);
}
function asText(filename, node, errorMessage, skipChild) {
let children = node.children.filter((child) => child !== skipChild);
while (children.length === 1 && children[0].type === "paragraph")
children = children[0].children;
if (children.length !== 1 || children[0].type !== "text")
throw parsingError(filename, node, errorMessage);
return { text: children[0].value, source: node.position ? { filename, line: node.position.start.line, column: node.position.start.column } : void 0 };
}
function parseSpec(content, filename) {
const root = (0, import_utilsBundle.parseMarkdown)(content);
const props = [];
const children = [...root.children];
const describeNode = children[0];
children.shift();
if (describeNode?.type !== "heading" || describeNode.depth !== 2)
throw parsingError(filename, describeNode, `describe title must be ##`);
const describe = asText(filename, describeNode, `describe title must be ##`);
if (children[0]?.type === "list") {
parseProps(filename, children[0], props);
children.shift();
}
const tests = [];
while (children.length) {
let nextIndex = children.findIndex((n, i) => i > 0 && n.type === "heading" && n.depth === 3);
if (nextIndex === -1)
nextIndex = children.length;
const testNodes = children.splice(0, nextIndex);
tests.push(parseTest(filename, testNodes));
}
return { describe, tests, props };
}
function parseProp(filename, node, props) {
const propText = asText(filename, node, `property must be a list item without children`);
const match = propText.text.match(/^([^:]+):(.*)$/);
if (!match)
throw parsingError(filename, node, `property must be in format "key: value"`);
props.push([match[1].trim(), { text: match[2].trim(), source: propText.source }]);
}
function parseProps(filename, node, props) {
for (const prop of node.children || []) {
if (prop.type !== "listItem")
throw parsingError(filename, prop, `property must be a list item without children`);
parseProp(filename, prop, props);
}
}
function parseTest(filename, nodes) {
const titleNode = nodes[0];
nodes.shift();
if (titleNode.type !== "heading" || titleNode.depth !== 3)
throw parsingError(filename, titleNode, `test title must be ###`);
const title = asText(filename, titleNode, `test title must be ###`);
const props = [];
let handlingProps = true;
const lines = [];
const visit = (node, indent) => {
if (node.type === "list") {
for (const child of node.children)
visit(child, indent);
return;
}
if (node.type === "listItem") {
const listItem = node;
const lastChild = listItem.children[listItem.children.length - 1];
if (lastChild?.type === "code") {
handlingProps = false;
const { text, source } = asText(filename, listItem, `code step must be a list item with a single code block`, lastChild);
lines.push({ text: `${indent}await test.step(${escapeString(text)}, async () => {`, source });
for (const [index, code] of lastChild.value.split("\n").entries())
lines.push({ text: indent + " " + code, source: lastChild.position ? { filename, line: lastChild.position.start.line + 1 + index, column: lastChild.position.start.column } : void 0 });
lines.push({ text: `${indent}});`, source });
} else {
const { text, source } = asText(filename, listItem, `step must contain a single instruction`, lastChild?.type === "list" ? lastChild : void 0);
let isGroup = false;
if (handlingProps && lastChild?.type !== "list" && ["tag:", "annotation:"].some((prefix) => text.startsWith(prefix))) {
parseProp(filename, listItem, props);
} else if (text.startsWith("group:")) {
isGroup = true;
lines.push({ text: `${indent}await test.step(${escapeString(text.substring("group:".length).trim())}, async () => {`, source });
} else if (text.startsWith("expect:")) {
handlingProps = false;
const assertion = text.substring("expect:".length).trim();
lines.push({ text: `${indent}await agent.expect(${escapeString(assertion)});`, source });
} else if (!text.startsWith("//")) {
handlingProps = false;
lines.push({ text: `${indent}await agent.perform(${escapeString(text)});`, source });
}
if (lastChild?.type === "list")
visit(lastChild, indent + (isGroup ? " " : ""));
if (isGroup)
lines.push({ text: `${indent}});`, source });
}
} else {
throw parsingError(filename, node, `test step must be a markdown list item`);
}
};
for (const node of nodes)
visit(node, "");
return { title, lines, props };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
transformMDToTS
});

View file

@ -0,0 +1,67 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var portTransport_exports = {};
__export(portTransport_exports, {
PortTransport: () => PortTransport
});
module.exports = __toCommonJS(portTransport_exports);
class PortTransport {
constructor(port, handler) {
this._lastId = 0;
this._callbacks = /* @__PURE__ */ new Map();
this._port = port;
port.addEventListener("message", async (event) => {
const message = event.data;
const { id, ackId, method, params, result } = message;
if (ackId) {
const callback = this._callbacks.get(ackId);
this._callbacks.delete(ackId);
this._resetRef();
callback?.(result);
return;
}
const handlerResult = await handler(method, params);
if (id)
this._port.postMessage({ ackId: id, result: handlerResult });
});
this._resetRef();
}
post(method, params) {
this._port.postMessage({ method, params });
}
async send(method, params) {
return await new Promise((f) => {
const id = ++this._lastId;
this._callbacks.set(id, f);
this._resetRef();
this._port.postMessage({ id, method, params });
});
}
_resetRef() {
if (this._callbacks.size) {
this._port.ref();
} else {
this._port.unref();
}
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PortTransport
});

View file

@ -0,0 +1,303 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var transform_exports = {};
__export(transform_exports, {
requireOrImport: () => requireOrImport,
resolveHook: () => resolveHook,
setSingleTSConfig: () => setSingleTSConfig,
setTransformConfig: () => setTransformConfig,
setTransformData: () => setTransformData,
shouldTransform: () => shouldTransform,
singleTSConfig: () => singleTSConfig,
transformConfig: () => transformConfig,
transformHook: () => transformHook,
wrapFunctionWithLocation: () => wrapFunctionWithLocation
});
module.exports = __toCommonJS(transform_exports);
var import_fs = __toESM(require("fs"));
var import_module = __toESM(require("module"));
var import_path = __toESM(require("path"));
var import_url = __toESM(require("url"));
var import_crypto = __toESM(require("crypto"));
var import_tsconfig_loader = require("../third_party/tsconfig-loader");
var import_util = require("../util");
var import_utilsBundle = require("../utilsBundle");
var import_compilationCache = require("./compilationCache");
var import_pirates = require("../third_party/pirates");
var import_md = require("./md");
const version = require("../../package.json").version;
const cachedTSConfigs = /* @__PURE__ */ new Map();
let _transformConfig = {
babelPlugins: [],
external: []
};
let _externalMatcher = () => false;
function setTransformConfig(config) {
_transformConfig = config;
_externalMatcher = (0, import_util.createFileMatcher)(_transformConfig.external);
}
function transformConfig() {
return _transformConfig;
}
let _singleTSConfigPath;
let _singleTSConfig;
function setSingleTSConfig(value) {
_singleTSConfigPath = value;
}
function singleTSConfig() {
return _singleTSConfigPath;
}
function validateTsConfig(tsconfig) {
const pathsBase = tsconfig.absoluteBaseUrl ?? tsconfig.paths?.pathsBasePath;
const pathsFallback = tsconfig.absoluteBaseUrl ? [{ key: "*", values: ["*"] }] : [];
return {
allowJs: !!tsconfig.allowJs,
pathsBase,
paths: Object.entries(tsconfig.paths?.mapping || {}).map(([key, values]) => ({ key, values })).concat(pathsFallback)
};
}
function loadAndValidateTsconfigsForFile(file2) {
if (_singleTSConfigPath && !_singleTSConfig)
_singleTSConfig = (0, import_tsconfig_loader.loadTsConfig)(_singleTSConfigPath).map(validateTsConfig);
if (_singleTSConfig)
return _singleTSConfig;
return loadAndValidateTsconfigsForFolder(import_path.default.dirname(file2));
}
function loadAndValidateTsconfigsForFolder(folder) {
const foldersWithConfig = [];
let currentFolder = import_path.default.resolve(folder);
let result2;
while (true) {
const cached = cachedTSConfigs.get(currentFolder);
if (cached) {
result2 = cached;
break;
}
foldersWithConfig.push(currentFolder);
for (const name of ["tsconfig.json", "jsconfig.json"]) {
const configPath = import_path.default.join(currentFolder, name);
if (import_fs.default.existsSync(configPath)) {
const loaded = (0, import_tsconfig_loader.loadTsConfig)(configPath);
result2 = loaded.map(validateTsConfig);
break;
}
}
if (result2)
break;
const parentFolder = import_path.default.resolve(currentFolder, "../");
if (currentFolder === parentFolder)
break;
currentFolder = parentFolder;
}
result2 = result2 || [];
for (const folder2 of foldersWithConfig)
cachedTSConfigs.set(folder2, result2);
return result2;
}
const pathSeparator = process.platform === "win32" ? ";" : ":";
const builtins = new Set(import_module.default.builtinModules);
function resolveHook(filename, specifier) {
if (specifier.startsWith("node:") || builtins.has(specifier))
return;
if (!shouldTransform(filename))
return;
if (isRelativeSpecifier(specifier))
return (0, import_util.resolveImportSpecifierAfterMapping)(import_path.default.resolve(import_path.default.dirname(filename), specifier), false);
const isTypeScript = filename.endsWith(".ts") || filename.endsWith(".tsx");
const tsconfigs = loadAndValidateTsconfigsForFile(filename);
for (const tsconfig of tsconfigs) {
if (!isTypeScript && !tsconfig.allowJs)
continue;
let longestPrefixLength = -1;
let pathMatchedByLongestPrefix;
for (const { key, values } of tsconfig.paths) {
let matchedPartOfSpecifier = specifier;
const [keyPrefix, keySuffix] = key.split("*");
if (key.includes("*")) {
if (keyPrefix) {
if (!specifier.startsWith(keyPrefix))
continue;
matchedPartOfSpecifier = matchedPartOfSpecifier.substring(keyPrefix.length, matchedPartOfSpecifier.length);
}
if (keySuffix) {
if (!specifier.endsWith(keySuffix))
continue;
matchedPartOfSpecifier = matchedPartOfSpecifier.substring(0, matchedPartOfSpecifier.length - keySuffix.length);
}
} else {
if (specifier !== key)
continue;
matchedPartOfSpecifier = specifier;
}
if (keyPrefix.length <= longestPrefixLength)
continue;
for (const value of values) {
let candidate = value;
if (value.includes("*"))
candidate = candidate.replace("*", matchedPartOfSpecifier);
candidate = import_path.default.resolve(tsconfig.pathsBase, candidate);
const existing = (0, import_util.resolveImportSpecifierAfterMapping)(candidate, true);
if (existing) {
longestPrefixLength = keyPrefix.length;
pathMatchedByLongestPrefix = existing;
}
}
}
if (pathMatchedByLongestPrefix)
return pathMatchedByLongestPrefix;
}
if (import_path.default.isAbsolute(specifier)) {
return (0, import_util.resolveImportSpecifierAfterMapping)(specifier, false);
}
}
function shouldTransform(filename) {
if (_externalMatcher(filename))
return false;
return !(0, import_compilationCache.belongsToNodeModules)(filename);
}
let transformData;
function setTransformData(pluginName, value) {
transformData.set(pluginName, value);
}
function transformHook(originalCode, filename, moduleUrl) {
let inputSourceMap;
if (filename.endsWith(".md") && false) {
const transformed = transformMDToTS(originalCode, filename);
originalCode = transformed.code;
inputSourceMap = transformed.map;
}
const hasPreprocessor = process.env.PW_TEST_SOURCE_TRANSFORM && process.env.PW_TEST_SOURCE_TRANSFORM_SCOPE && process.env.PW_TEST_SOURCE_TRANSFORM_SCOPE.split(pathSeparator).some((f) => filename.startsWith(f));
const pluginsPrologue = _transformConfig.babelPlugins;
const pluginsEpilogue = hasPreprocessor ? [[process.env.PW_TEST_SOURCE_TRANSFORM]] : [];
const hash = calculateHash(originalCode, filename, !!moduleUrl, pluginsPrologue, pluginsEpilogue);
const { cachedCode, addToCache, serializedCache } = (0, import_compilationCache.getFromCompilationCache)(filename, hash, moduleUrl);
if (cachedCode !== void 0)
return { code: cachedCode, serializedCache };
process.env.BROWSERSLIST_IGNORE_OLD_DATA = "true";
const { babelTransform } = require("./babelBundle");
transformData = /* @__PURE__ */ new Map();
const babelResult = babelTransform(originalCode, filename, !!moduleUrl, pluginsPrologue, pluginsEpilogue, inputSourceMap);
if (!babelResult?.code)
return { code: originalCode, serializedCache };
const { code, map } = babelResult;
const added = addToCache(code, map, transformData);
return { code, serializedCache: added.serializedCache };
}
function calculateHash(content, filePath, isModule2, pluginsPrologue, pluginsEpilogue) {
const hash = import_crypto.default.createHash("sha1").update(isModule2 ? "esm" : "no_esm").update(content).update(filePath).update(version).update(pluginsPrologue.map((p) => p[0]).join(",")).update(pluginsEpilogue.map((p) => p[0]).join(",")).digest("hex");
return hash;
}
async function requireOrImport(file) {
installTransformIfNeeded();
const isModule = (0, import_util.fileIsModule)(file);
if (isModule) {
const fileName = import_url.default.pathToFileURL(file);
const esmImport = () => eval(`import(${JSON.stringify(fileName)})`);
await eval(`import(${JSON.stringify(fileName + ".esm.preflight")})`).finally(nextTask);
return await esmImport().finally(nextTask);
}
const result = require(file);
const depsCollector = (0, import_compilationCache.currentFileDepsCollector)();
if (depsCollector) {
const module2 = require.cache[file];
if (module2)
collectCJSDependencies(module2, depsCollector);
}
return result;
}
let transformInstalled = false;
function installTransformIfNeeded() {
if (transformInstalled)
return;
transformInstalled = true;
(0, import_compilationCache.installSourceMapSupport)();
const originalResolveFilename = import_module.default._resolveFilename;
function resolveFilename(specifier, parent, ...rest) {
if (parent) {
const resolved = resolveHook(parent.filename, specifier);
if (resolved !== void 0)
specifier = resolved;
}
return originalResolveFilename.call(this, specifier, parent, ...rest);
}
import_module.default._resolveFilename = resolveFilename;
(0, import_pirates.addHook)((code, filename) => {
return transformHook(code, filename).code;
}, shouldTransform, [".ts", ".tsx", ".js", ".jsx", ".mjs", ".mts", ".cjs", ".cts", ".md"]);
}
const collectCJSDependencies = (module2, dependencies) => {
module2.children.forEach((child) => {
if (!(0, import_compilationCache.belongsToNodeModules)(child.filename) && !dependencies.has(child.filename)) {
dependencies.add(child.filename);
collectCJSDependencies(child, dependencies);
}
});
};
function wrapFunctionWithLocation(func) {
return (...args) => {
const oldPrepareStackTrace = Error.prepareStackTrace;
Error.prepareStackTrace = (error, stackFrames) => {
const frame = import_utilsBundle.sourceMapSupport.wrapCallSite(stackFrames[1]);
const fileName2 = frame.getFileName();
const file2 = fileName2 && fileName2.startsWith("file://") ? import_url.default.fileURLToPath(fileName2) : fileName2;
return {
file: file2,
line: frame.getLineNumber(),
column: frame.getColumnNumber()
};
};
const oldStackTraceLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 2;
const obj = {};
Error.captureStackTrace(obj);
const location = obj.stack;
Error.stackTraceLimit = oldStackTraceLimit;
Error.prepareStackTrace = oldPrepareStackTrace;
return func(location, ...args);
};
}
function isRelativeSpecifier(specifier) {
return specifier === "." || specifier === ".." || specifier.startsWith("./") || specifier.startsWith("../");
}
async function nextTask() {
return new Promise((resolve) => setTimeout(resolve, 0));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
requireOrImport,
resolveHook,
setSingleTSConfig,
setTransformConfig,
setTransformData,
shouldTransform,
singleTSConfig,
transformConfig,
transformHook,
wrapFunctionWithLocation
});