const require_rolldown_runtime = require('../../../../../../../../../../_virtual/rolldown_runtime.cjs');
const require_logger = require('../logger.cjs');
const require_getPackageJsonPath = require('../utils/getPackageJsonPath.cjs');
let node_path = require("node:path");
let node_fs = require("node:fs");

//#region ../chokidar/dist/esm/core/dist/esm/config/dist/esm/configFile/searchConfigurationFile.mjs
const EXTENSION = [
	"ts",
	"js",
	"json",
	"cjs",
	"mjs",
	""
];
const CONFIGURATION_FILE_NAME_1 = "intlayer.config";
const CONFIGURATION_FILE_NAME_2 = ".intlayerrc";
const configurationFiles = [...EXTENSION.filter((extension) => extension !== "").map((ext) => `${CONFIGURATION_FILE_NAME_1}.${ext}`), CONFIGURATION_FILE_NAME_2];
/**
* Search for the configuration file in the given path
*
* List of detected configuration files:
* - intlayer.config.ts
* - intlayer.config.js
* - intlayer.config.json
* - intlayer.config.cjs
* - intlayer.config.mjs
* - .intlayerrc
*/
const searchConfigurationFile = (startDir) => {
	let configurationFilePath;
	let numCustomConfiguration = 0;
	const { baseDir } = require_getPackageJsonPath.getPackageJsonPath(startDir);
	for (const fileName of configurationFiles) try {
		const filePath = (0, node_path.resolve)(baseDir, fileName);
		if (!(0, node_fs.existsSync)(filePath)) {} else {
			numCustomConfiguration += 1;
			if (!configurationFilePath) configurationFilePath = filePath;
		}
	} catch (error) {
		require_logger.logger(`${fileName}: ${error}`, { level: "error" });
	}
	return {
		configurationFilePath,
		numCustomConfiguration
	};
};

//#endregion
exports.searchConfigurationFile = searchConfigurationFile;
//# sourceMappingURL=searchConfigurationFile.cjs.map