First Commit
This commit is contained in:
43
node_modules/playwright/lib/transform/babelBundle.js
generated
vendored
Normal file
43
node_modules/playwright/lib/transform/babelBundle.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
"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,
|
||||
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;
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
babelParse,
|
||||
babelTransform,
|
||||
codeFrameColumns,
|
||||
declare,
|
||||
traverse,
|
||||
types
|
||||
});
|
461
node_modules/playwright/lib/transform/babelBundleImpl.js
generated
vendored
Normal file
461
node_modules/playwright/lib/transform/babelBundleImpl.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
255
node_modules/playwright/lib/transform/compilationCache.js
generated
vendored
Normal file
255
node_modules/playwright/lib/transform/compilationCache.js
generated
vendored
Normal file
@@ -0,0 +1,255 @@
|
||||
"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_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 (!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, hash, moduleUrl) {
|
||||
const cache = memoryCache.get(filename);
|
||||
if (cache?.codePath) {
|
||||
try {
|
||||
return { cachedCode: import_fs.default.readFileSync(cache.codePath, "utf-8") };
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
const cachePath = calculateCachePath(filename, hash);
|
||||
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 {};
|
||||
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 calculateCachePath(filePath, hash) {
|
||||
const fileName = import_path.default.basename(filePath, import_path.default.extname(filePath)).replace(/\W/g, "") + "_" + hash;
|
||||
return import_path.default.join(cacheDir, hash[0] + hash[1], fileName);
|
||||
}
|
||||
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
|
||||
});
|
104
node_modules/playwright/lib/transform/esmLoader.js
generated
vendored
Normal file
104
node_modules/playwright/lib/transform/esmLoader.js
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
"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");
|
||||
async function resolve(specifier, context, defaultResolve) {
|
||||
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));
|
||||
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(moduleUrl, context, defaultLoad) {
|
||||
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) {
|
||||
if (legacyWaitForSourceMaps)
|
||||
await transport?.send("pushToCompilationCache", { cache: transformed.serializedCache });
|
||||
else
|
||||
transport?.post("pushToCompilationCache", { cache: transformed.serializedCache });
|
||||
}
|
||||
return {
|
||||
format: kSupportedFormats.get(context.format) || ((0, import_util.fileIsModule)(filename) ? "module" : "commonjs"),
|
||||
source: transformed.code,
|
||||
shortCircuit: true
|
||||
};
|
||||
}
|
||||
let transport;
|
||||
let legacyWaitForSourceMaps = false;
|
||||
function initialize(data) {
|
||||
transport = createTransport(data?.port);
|
||||
legacyWaitForSourceMaps = !!process.env.PLAYWRIGHT_WAIT_FOR_SOURCE_MAPS;
|
||||
}
|
||||
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 };
|
67
node_modules/playwright/lib/transform/portTransport.js
generated
vendored
Normal file
67
node_modules/playwright/lib/transform/portTransport.js
generated
vendored
Normal 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
|
||||
});
|
293
node_modules/playwright/lib/transform/transform.js
generated
vendored
Normal file
293
node_modules/playwright/lib/transform/transform.js
generated
vendored
Normal file
@@ -0,0 +1,293 @@
|
||||
"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");
|
||||
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) {
|
||||
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);
|
||||
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);
|
||||
const esmImport = () => eval(`import(${JSON.stringify(import_url.default.pathToFileURL(file))})`);
|
||||
if (isModule) {
|
||||
return await esmImport().finally(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
});
|
||||
}
|
||||
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"]);
|
||||
}
|
||||
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 fileName = frame.getFileName();
|
||||
const file2 = fileName && fileName.startsWith("file://") ? import_url.default.fileURLToPath(fileName) : fileName;
|
||||
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("../");
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
requireOrImport,
|
||||
resolveHook,
|
||||
setSingleTSConfig,
|
||||
setTransformConfig,
|
||||
setTransformData,
|
||||
shouldTransform,
|
||||
singleTSConfig,
|
||||
transformConfig,
|
||||
transformHook,
|
||||
wrapFunctionWithLocation
|
||||
});
|
Reference in New Issue
Block a user