"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); // src/index.ts var src_exports = {}; __export(src_exports, { default: () => src_default }); module.exports = __toCommonJS(src_exports); // src/require/index.ts var import_path = require("path"); var import_url = require("url"); function interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } async function requireOrImportModule(filePath, applyInteropRequireDefault = true) { if (!(0, import_path.isAbsolute)(filePath) && filePath[0] === ".") { throw new Error( `Jest: requireOrImportModule path must be absolute, was "${filePath}"` ); } try { const requiredModule = require(filePath); if (!applyInteropRequireDefault) { return requiredModule; } return interopRequireDefault(requiredModule).default; } catch (error) { try { const moduleUrl = (0, import_url.pathToFileURL)(filePath); const importedModule = await import( /* webpackIgnore: true */ moduleUrl.href ); if (!applyInteropRequireDefault) { return importedModule; } if (!importedModule.default) { throw new Error( `Jest: Failed to load ESM at ${filePath} - did you use a default export?` ); } return importedModule.default; } catch (innerError) { if (innerError.message === "Not supported") { throw new Error( `Jest: Your version of Node does not support dynamic import - please enable it or use a .cjs file extension for file ${filePath}` ); } throw innerError; } } } // src/transformer.ts var requireTransformer = (path, config) => { const transformer = require(path).default || require(path); if (!transformer.process && !transformer.processAsync) { if (transformer.createTransformer) { return transformer.createTransformer(config || {}); } return null; } return transformer; }; var importTransformer = async (path, config) => { const transformer = await requireOrImportModule(path); if (!transformer.process && !transformer.processAsync) { if (transformer.createTransformer) { return transformer.createTransformer(config || {}); } return null; } return transformer; }; var flatTransformers = (transformers) => { const containers = []; for (let transformer of transformers) { let transformerModule; if (typeof transformer === "string") { transformerModule = requireTransformer(transformer, {}); if (!transformerModule) { console.error(`cant load ${transformer} as a transformer, so skip it`); break; } } else if (Array.isArray(transformer)) { transformerModule = { ...requireTransformer(transformer[0], transformer[1]), transformerConfig: transformer[1] }; } containers.push(transformerModule); } return containers; }; var flatAsyncTransformers = async (transformers) => { const containers = []; for (let transformer of transformers) { let transformerModule; if (typeof transformer === "string") { transformerModule = await importTransformer(transformer, {}); if (!transformerModule) { console.error(`cant load ${transformer} as a transformer, so skip it`); break; } } else if (Array.isArray(transformer)) { transformerModule = { ...await importTransformer(transformer[0], transformer[1]), transformerConfig: transformer[1] }; } containers.push(transformerModule); } return containers; }; var createTransformer = () => { let flattenTransformers = null; const getFlattenTransformers = (options) => { if (flattenTransformers) { return flattenTransformers; } return flatTransformers(options.transformerConfig.transformers); }; const getFlattenAsyncTransformers = (options) => { if (flattenTransformers) { return flattenTransformers; } return flatAsyncTransformers(options.transformerConfig.transformers); }; const constructOptions = (options, config) => { return { ...options, transformerConfig: config }; }; return { canInstrument: true, getCacheKey: (sourceText, sourcePath, options) => { const transformers = getFlattenTransformers(options); return transformers.reduce((res, transformer) => { return res + transformer.getCacheKey?.( sourceText, sourcePath, constructOptions(options, transformer.transformerConfig) ) || ""; }, ""); }, process: (sourceText, sourcePath, options) => { const transformers = getFlattenTransformers(options); return transformers.reduce( (res, transformer) => { return transformer.process?.( res.code ? res.code : res, sourcePath, constructOptions(options, transformer.transformerConfig) ); }, { code: sourceText } ); }, getCacheKeyAsync: async (sourceText, sourcePath, options) => { const transformers = await getFlattenAsyncTransformers(options); let res = ""; for (let transformer of transformers) { res += await transformer.getCacheKeyAsync?.( sourceText, sourcePath, constructOptions(options, transformer.transformerConfig) ) || ""; } return res; }, processAsync: async (sourceText, sourcePath, options) => { const transformers = await getFlattenAsyncTransformers(options); let res = { code: sourceText }; for (let transformer of transformers) { res = await (transformer.processAsync || transformer.process)?.( res.code ? res.code : res, sourcePath, constructOptions(options, transformer.transformerConfig) ); } return res; } }; }; var transformer_default = createTransformer(); // src/index.ts var src_default = transformer_default;