const require_chunk = require("./chunk-D6vf50IK.cjs");
let _apm_js_collab_code_transformer = require("@apm-js-collab/code-transformer");
let path = require("path");
let fs = require("fs");
let module_details_from_path = require("module-details-from-path");
module_details_from_path = require_chunk.__toESM(module_details_from_path, 1);
//#region node_modules/es-module-lexer/dist/lexer.js
var ImportType;
(function(A) {
	A[A.Static = 1] = "Static", A[A.Dynamic = 2] = "Dynamic", A[A.ImportMeta = 3] = "ImportMeta", A[A.StaticSourcePhase = 4] = "StaticSourcePhase", A[A.DynamicSourcePhase = 5] = "DynamicSourcePhase", A[A.StaticDeferPhase = 6] = "StaticDeferPhase", A[A.DynamicDeferPhase = 7] = "DynamicDeferPhase";
})(ImportType || (ImportType = {}));
var A = 1 === new Uint8Array(new Uint16Array([1]).buffer)[0];
function parse(E, g = "@") {
	if (!C) return init.then((() => parse(E)));
	const I = E.length + 1, o = (C.__heap_base.value || C.__heap_base) + 4 * I - C.memory.buffer.byteLength;
	o > 0 && C.memory.grow(Math.ceil(o / 65536));
	const D = C.sa(I - 1);
	if ((A ? B : Q)(E, new Uint16Array(C.memory.buffer, D, I)), !C.parse()) throw Object.assign(/* @__PURE__ */ new Error(`Parse error ${g}:${E.slice(0, C.e()).split("\n").length}:${C.e() - E.lastIndexOf("\n", C.e() - 1)}`), { idx: C.e() });
	const K = [], k = [];
	for (; C.ri();) {
		const A = C.is(), Q = C.ie(), B = C.it(), g = C.ai(), I = C.id(), o = C.ss(), D = C.se();
		let k;
		C.ip() && (k = w(E.slice(-1 === I ? A - 1 : A, -1 === I ? Q + 1 : Q)));
		const i = [];
		for (C.rsa(); C.ra();) {
			const A = C.aks(), Q = C.ake(), B = C.avs(), g = C.ave();
			i.push([N(E.slice(A, Q)), N(E.slice(B, g))]);
		}
		K.push({
			n: k,
			t: B,
			s: A,
			e: Q,
			ss: o,
			se: D,
			d: I,
			a: g,
			at: i.length > 0 ? i : null
		});
	}
	for (; C.re();) {
		const A = C.es(), Q = C.ee(), B = C.els(), g = C.ele(), I = N(E.slice(A, Q)), o = B < 0 ? void 0 : N(E.slice(B, g));
		k.push({
			s: A,
			e: Q,
			ls: B,
			le: g,
			n: I,
			ln: o
		});
	}
	function w(A) {
		try {
			return (0, eval)(A);
		} catch (A) {}
	}
	function N(A) {
		if (!A) return A;
		const Q = A[0];
		return ("\"" === Q || "'" === Q) && w(A) || A;
	}
	return [
		K,
		k,
		!!C.f(),
		!!C.ms()
	];
}
function Q(A, Q) {
	const B = A.length;
	let C = 0;
	for (; C < B;) {
		const B = A.charCodeAt(C);
		Q[C++] = (255 & B) << 8 | B >>> 8;
	}
}
function B(A, Q) {
	const B = A.length;
	let C = 0;
	for (; C < B;) Q[C] = A.charCodeAt(C++);
}
var C;
var E = () => {
	return A = "[encoded data, 13248 characters]", "undefined" != typeof Buffer ? Buffer.from(A, "base64") : Uint8Array.from(atob(A), ((A) => A.charCodeAt(0)));
	var A;
};
var init = WebAssembly.compile(E()).then(WebAssembly.instantiate).then((({ exports: A }) => {
	C = A;
}));
var initSync = () => {
	if (C) return;
	const A = new WebAssembly.Module(E());
	C = new WebAssembly.Instance(A).exports;
};
//#endregion
//#region src/core.ts
var moduleDetailsFromPath = module_details_from_path.default || module_details_from_path;
var COMMENT_USE_STRICT_REGEX = /^(?:\s*|\/\*(?:.|\r|\n)*?\*\/|\/\/.*[\n\r])*(?:"[^"]*";|'[^']*';)?/;
function stripQueryAndHashFromPath(path$1) {
	return path$1.split("?")[0].split("#")[0];
}
/**
* Checks if a file is a JavaScript file based on its extension.
* Handles query strings and hashes in the filename.
*/
function isJsFile(fileName) {
	const cleanFileName = stripQueryAndHashFromPath(fileName);
	return [
		".js",
		".mjs",
		".cjs"
	].some((ext) => cleanFileName.endsWith(ext));
}
/**
* Checks if a chunk contains only import/export statements and no substantial code.
*
* In Vite MPA (multi-page application) mode, HTML entry points create "facade" chunks
* that only contain import statements to load shared modules. These should not have
* Sentry code injected. However, in SPA mode, the main bundle also has an HTML facade
* but contains substantial application code that SHOULD have debug IDs injected.
*
* @ref https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829
* @ref https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/839
*/
function containsOnlyImports(code) {
	return code.replace(/^\s*import\s+(?:'[^'\n]*'|"[^"\n]*"|`[^`\n]*`)[\s;]*$/gm, "").replace(/^\s*import\b[^'"`\n]*\bfrom\s+(?:'[^'\n]*'|"[^"\n]*"|`[^`\n]*`)[\s;]*$/gm, "").replace(/^\s*export\b[^'"`\n]*\bfrom\s+(?:'[^'\n]*'|"[^"\n]*"|`[^`\n]*`)[\s;]*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "").replace(/["']use strict["']\s*;?/g, "").trim().length === 0;
}
/**
* Checks if a chunk should be skipped for code injection
*
* This is necessary to handle Vite's MPA (multi-page application) mode where
* HTML entry points create "facade" chunks that should not contain injected code.
* See: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829
*
* However, in SPA mode, the main bundle also has an HTML facade but contains
* substantial application code. We should NOT skip injection for these bundles.
*
* @param code - The chunk's code content
* @param facadeModuleId - The facade module ID (if any) - HTML files create facade chunks
* @returns true if the chunk should be skipped
*/
function shouldSkipCodeInjection(code, facadeModuleId) {
	if (code.trim().length === 0) return true;
	if (facadeModuleId && stripQueryAndHashFromPath(facadeModuleId).endsWith(".html")) return containsOnlyImports(code);
	return false;
}
function getModuleVersion(basedir) {
	try {
		const packageJsonPath = (0, path.join)(basedir, "package.json");
		const packageJson = JSON.parse((0, fs.readFileSync)(packageJsonPath, "utf8"));
		if (packageJson.version) return packageJson.version;
	} catch (_) {}
}
function detectModuleType(id, code) {
	const ext = (0, path.extname)(id);
	if (ext === ".mjs" || ext === ".ts" || ext === ".tsx") return "esm";
	if (ext === ".cjs") return "cjs";
	if (ext === ".js") try {
		initSync();
		const [imports, exports] = parse(code);
		return imports.length > 0 || exports.length > 0 ? "esm" : "cjs";
	} catch (_) {}
	return "unknown";
}
/**
* Build a reusable code transformer from plugin options. The returned
* `transform` function returns `null` for files that should not be modified.
* Call `dispose` when the bundler tears the plugin down.
*/
function createCodeTransformer(options) {
	const matcher = (0, _apm_js_collab_code_transformer.create)(options.instrumentations, options.dcModule ?? null);
	const transformedModules = /* @__PURE__ */ new Set();
	const failedModules = /* @__PURE__ */ new Set();
	const getCodeToInject = () => {
		if (!options.injectDiagnostics) return;
		const diagnostics = {
			transformedModules: Array.from(transformedModules),
			failedModules: Array.from(failedModules)
		};
		return options.injectDiagnostics(diagnostics);
	};
	const transform = (code, id, inputSourceMap) => {
		const moduleDetails = moduleDetailsFromPath(id);
		if (!moduleDetails) return null;
		const moduleVersion = getModuleVersion(moduleDetails.basedir);
		if (!moduleVersion) {
			console.warn(`No 'package.json' version found for module ${moduleDetails.name} at ${moduleDetails.basedir}. Skipping transformation.`);
			return null;
		}
		const transformer = matcher.getTransformer(moduleDetails.name, moduleVersion, moduleDetails.path);
		if (!transformer) return null;
		const moduleType = detectModuleType(id, code);
		if (moduleType === "unknown") {
			failedModules.add(moduleDetails.name);
			return null;
		}
		try {
			const result = transformer.transform(code, moduleType, inputSourceMap ?? null);
			transformedModules.add(transformer.moduleName);
			return {
				code: result.code,
				map: result.map
			};
		} catch (error) {
			console.warn(`Code transformation failed for '${id}'`, error);
			failedModules.add(moduleDetails.name);
			return null;
		}
	};
	return {
		transform,
		getCodeToInject
	};
}
//#endregion
Object.defineProperty(exports, "COMMENT_USE_STRICT_REGEX", {
	enumerable: true,
	get: function() {
		return COMMENT_USE_STRICT_REGEX;
	}
});
Object.defineProperty(exports, "createCodeTransformer", {
	enumerable: true,
	get: function() {
		return createCodeTransformer;
	}
});
Object.defineProperty(exports, "isJsFile", {
	enumerable: true,
	get: function() {
		return isJsFile;
	}
});
Object.defineProperty(exports, "shouldSkipCodeInjection", {
	enumerable: true,
	get: function() {
		return shouldSkipCodeInjection;
	}
});

//# sourceMappingURL=core-BOrUDYbE.cjs.map