"use strict";const s=require("node:fs"),c=require("node:path"),d=require("lodash.merge"),i=require("ini"),jiti=require("jiti"),jsoncEslintParser=require("jsonc-eslint-parser"),tomlEslintParser=require("toml-eslint-parser"),yamlEslintParser=require("yaml-eslint-parser");function _interopDefaultCompat(n){return n&&typeof n=="object"&&"default"in n?n.default:n}const s__default=_interopDefaultCompat(s),c__default=_interopDefaultCompat(c),d__default=_interopDefaultCompat(d),i__default=_interopDefaultCompat(i);function iniLoader(n,r){return i__default.parse(r)}function u(){switch(process.platform){case"win32":return"Windows";case"linux":return"Linux";case"darwin":return"Mac";default:return"UNKNOWN"}}function e(n=process.cwd(),r={}){const t=n.split("/"),a=jiti.createJiti(n,{interopDefault:!0,...r});return u()==="Windows"?a(`${t[t.length-1]}`):a(`./${t[t.length-1]}`)}function loadConf(n,r={}){const{jiti:t=!0,jitiOptions:a}=r,l=function(){try{return t?n?e(n,a):{}:n?require(n):{}}catch{return e(n,a)}}();return l.default??l}function jsLoader(n,r,t={}){return loadConf(n,t)}function jsonLoader(n,r){const t=jsoncEslintParser.parseJSON(r);return jsoncEslintParser.getStaticJSONValue(t)}function tomlLoader(n,r){const t=tomlEslintParser.parseTOML(r);return tomlEslintParser.getStaticTOMLValue(t)}function yamlLoader(n,r){const t=yamlEslintParser.parseYAML(r);return yamlEslintParser.getStaticYAMLValue(t)}function findConfigFile(n,r,t=[]){const a=[...t,`.${n}rc`,`.${n}rc.json`,`.${n}rc.json5`,`.${n}rc.jsonc`,`.${n}rc.yaml`,`.${n}rc.yml`,`.${n}rc.toml`,`.${n}rc.ini`,`.${n}rc.js`,`.${n}rc.ts`,`.${n}rc.cjs`,`.${n}rc.mjs`,`.config/${n}rc`,`.config/${n}rc.json`,`.config/${n}rc.json5`,`.config/${n}rc.jsonc`,`.config/${n}rc.yaml`,`.config/${n}rc.yml`,`.config/${n}rc.toml`,`.config/${n}rc.ini`,`.config/${n}rc.js`,`.config/${n}rc.ts`,`.config/${n}rc.cjs`,`.config/${n}rc.mjs`,`${n}.config.js`,`${n}.config.ts`,`${n}.config.cjs`,`${n}.config.mjs`];for(const l of a){const $=c__default.resolve(r,l);if(s__default.existsSync($))return $}return null}let o="";const h=()=>o;function E(n="autoconf",r={}){const{searchPlaces:t=[],default:a={},cwd:l=process.cwd(),mustExist:$=!1,jsOption:y}=r,g={".yml":yamlLoader,".yaml":yamlLoader,".ini":iniLoader,".toml":tomlLoader,".json":jsonLoader,".json5":jsonLoader,".jsonc":jsonLoader,".js":jsLoader,".ts":jsLoader,".cjs":jsLoader,".mjs":jsLoader,...r.loaders||{}},x=c__default.resolve(l,"package.json");o=findConfigFile(n,l,t);let j="",f,m;try{if(o){const p=c__default.extname(o),L=c__default.basename(o);new RegExp(`^(.?${n}rc)$`).test(L)?(j=s__default.readFileSync(o,"utf-8"),m=g[".json"]):g[p]&&(j=s__default.readFileSync(o,"utf-8"),m=g[p])}else s__default.existsSync(x)&&(j=s__default.readFileSync(x,"utf-8"),f=g[".json"](o,j)[n]);if(j&&m&&(f=m(o,j,y),typeof f=="function"))return d__default(a,f,{default:f});if($&&!o&&!f)return null;if(f)return d__default(a,f);console.log("READ_CONF:ERROR: \x1B[31;1mCan't find config file\x1B[0m")}catch(p){console.log(`READ_CONF:CATCH:ERROR: \x1B[31;1m${p}\x1B[0m`)}}exports.merge=d__default,exports.getConfigPath=h,exports.iniLoader=iniLoader,exports.jsLoader=jsLoader,exports.jsonLoader=jsonLoader,exports.loadConf=loadConf,exports.readConfig=E,exports.tomlLoader=tomlLoader,exports.yamlLoader=yamlLoader;