const require_rolldown_runtime = require('../../../../../_virtual/rolldown_runtime.cjs');
let node_path = require("node:path");
let esbuild = require("esbuild");
let node_url = require("node:url");

//#region ../@intlayer/config/dist/esm/loadExternalFile/bundleFile.mjs
const getLoader = (extension) => {
	switch (extension) {
		case ".js": return "js";
		case ".jsx": return "jsx";
		case ".mjs": return "js";
		case ".ts": return "ts";
		case ".tsx": return "tsx";
		case ".cjs": return "js";
		case ".json": return "json";
		case ".md": return "text";
		case ".mdx": return "text";
		default: return "js";
	}
};
const getTransformationOptions = (filePath) => ({
	loader: {
		".js": "js",
		".jsx": "jsx",
		".mjs": "js",
		".ts": "ts",
		".tsx": "tsx",
		".cjs": "js",
		".json": "json",
		".md": "text",
		".mdx": "text"
	},
	format: "cjs",
	target: "node16",
	platform: "neutral",
	write: false,
	packages: "bundle",
	external: ["esbuild"],
	bundle: true,
	define: { "import.meta.url": JSON.stringify((0, node_url.pathToFileURL)(filePath).href) }
});
const bundleFile = async (code, filePath, options) => {
	return (await (0, esbuild.build)({
		stdin: {
			contents: code,
			loader: getLoader((0, node_path.extname)(filePath)),
			resolveDir: (0, node_path.dirname)(filePath),
			sourcefile: filePath
		},
		...getTransformationOptions(filePath),
		...options
	})).outputFiles?.[0].text;
};

//#endregion
exports.bundleFile = bundleFile;
exports.getLoader = getLoader;
//# sourceMappingURL=bundleFile.cjs.map