const require_rolldown_runtime = require('../../../../../../../../../../../../../../_virtual/rolldown_runtime.cjs');
const require_logger = require('../logger.cjs');
const require_ESMxCJSHelpers = require('../utils/ESMxCJSHelpers.cjs');
const require_parseFileContent = require('./parseFileContent.cjs');
const require_transpileTSToMJS = require('./transpileTSToMJS.cjs');
let node_path = require("node:path");
let node_fs_promises = require("node:fs/promises");
let node_fs = require("node:fs");

//#region ../@intlayer/webpack/dist/esm/chokidar/dist/esm/remote-dictionaries-entry/dist/esm/config/dist/esm/loadExternalFile/loadExternalFile.mjs
/**
* Load the content declaration from the given path
*
* Accepts JSON, JS, MJS and TS files as configuration
*/
const loadExternalFileSync = (filePath, options) => {
	const fileExtension = (0, node_path.extname)(filePath);
	const safeProjectRequire = options?.projectRequire ?? require_ESMxCJSHelpers.getProjectRequire();
	try {
		if (fileExtension === "json") {
			delete safeProjectRequire.cache[safeProjectRequire.resolve(filePath)];
			return safeProjectRequire(filePath);
		}
		const moduleResultString = require_transpileTSToMJS.transpileTSToMJSSync((0, node_fs.readFileSync)(filePath, "utf-8"), filePath);
		if (!moduleResultString) {
			require_logger.logger("File could not be loaded.", { level: "error" });
			return;
		}
		const fileContent = require_parseFileContent.parseFileContent(moduleResultString, {
			projectRequire: options?.projectRequire,
			envVarOptions: options?.envVarOptions,
			additionalEnvVars: options?.additionalEnvVars,
			mocks: options?.mocks,
			aliases: options?.aliases
		});
		if (typeof fileContent === "undefined") {
			require_logger.logger(`File file could not be loaded. Path : ${filePath}`);
			return;
		}
		return fileContent;
	} catch (error) {
		require_logger.logger([`Error: ${error.message} - `, JSON.stringify(error.stack, null, 2)], { level: "error" });
	}
};

//#endregion
exports.loadExternalFileSync = loadExternalFileSync;
//# sourceMappingURL=loadExternalFile.cjs.map