import{__exports as e}from"../../../_virtual/ExplorerBase.mjs";import{__require as o}from"../../env-paths/index.mjs";import i from"../../../_virtual/_node_os.mjs";import t from"../../../_virtual/_node_path.mjs";import{__require as r}from"./util.mjs";var a;function n(){if(a)return e;a=1;var n=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.getExtensionDescription=e.ExplorerBase=void 0;const s=n(o()),l=n(i),f=n(t),c=r();function h(e){
/* istanbul ignore next -- @preserve */
return e?`extension "${e}"`:"files without extensions"}return e.ExplorerBase=class{#e=!1;config;loadCache;searchCache;constructor(e){this.config=e,e.cache&&(this.loadCache=new Map,this.searchCache=new Map),this.#o()}set loadingMetaConfig(e){this.#e=e}#o(){const e=this.config;for(const o of e.searchPlaces){const e=f.default.extname(o),i=this.config.loaders[e||"noExt"]??this.config.loaders.default;if(void 0===i)throw new Error(`Missing loader for ${h(o)}.`);if("function"!=typeof i)throw new Error(`Loader for ${h(o)} is not a function: Received ${typeof i}.`)}}clearLoadCache(){this.loadCache&&this.loadCache.clear()}clearSearchCache(){this.searchCache&&this.searchCache.clear()}clearCaches(){this.clearLoadCache(),this.clearSearchCache()}toCosmiconfigResult(e,o){if(null===o)return null;if(void 0===o)return{filepath:e,config:void 0,isEmpty:!0};if(this.config.applyPackagePropertyPathToConfiguration||this.#e){const e=this.config.packageProp??this.config.moduleName;o=(0,c.getPropertyByPath)(o,e)}return void 0===o?{filepath:e,config:void 0,isEmpty:!0}:{config:o,filepath:e}}validateImports(e,o,i){const t=f.default.dirname(e);for(const r of o){if("string"!=typeof r)throw new Error(`${e}: Key $import must contain a string or a list of strings`);const o=f.default.resolve(t,r);if(o===e)throw new Error(`Self-import detected in ${e}`);const a=i.indexOf(o);if(-1!==a)throw new Error(`Circular import detected:\n${[...i,o].map((e,o)=>`${o+1}. ${e}`).join("\n")} (same as ${a+1}.)`)}}getSearchPlacesForDir(e,o){return(e.isGlobalConfig?o:this.config.searchPlaces).map(o=>f.default.join(e.path,o))}getGlobalConfigDir(){return(0,s.default)(this.config.moduleName,{suffix:""}).config}*getGlobalDirs(e){const o=f.default.resolve(this.config.stopDir??l.default.homedir());yield{path:e,isGlobalConfig:!1};let i=e;for(;i!==o;){const e=f.default.dirname(i);
/* istanbul ignore if -- @preserve */if(e===i)break;yield{path:e,isGlobalConfig:!1},i=e}yield{path:this.getGlobalConfigDir(),isGlobalConfig:!0}}},e.getExtensionDescription=h,e}export{n as __require};