import { __exports as a } from "../../../../../../_virtual/ExplorerBase.js";
import p from "../../../../../../_virtual/___vite-browser-external.js";
import { __require as g } from "./loaders.js";
import { __require as m } from "./getPropertyByPath.js";
var c;
function _() {
  if (c)
    return a;
  c = 1, Object.defineProperty(a, "__esModule", {
    value: !0
  }), a.getExtensionDescription = s, a.ExplorerBase = void 0;
  var i = f(p), l = g(), u = m();
  function f(t) {
    return t && t.__esModule ? t : { default: t };
  }
  class h {
    constructor(e) {
      e.cache === !0 && (this.loadCache = /* @__PURE__ */ new Map(), this.searchCache = /* @__PURE__ */ new Map()), this.config = e, this.validateConfig();
    }
    clearLoadCache() {
      this.loadCache && this.loadCache.clear();
    }
    clearSearchCache() {
      this.searchCache && this.searchCache.clear();
    }
    clearCaches() {
      this.clearLoadCache(), this.clearSearchCache();
    }
    validateConfig() {
      const e = this.config;
      e.searchPlaces.forEach((r) => {
        const o = i.default.extname(r) || "noExt", n = e.loaders[o];
        if (!n)
          throw new Error(`No loader specified for ${s(r)}, so searchPlaces item "${r}" is invalid`);
        if (typeof n != "function")
          throw new Error(`loader for ${s(r)} is not a function (type provided: "${typeof n}"), so searchPlaces item "${r}" is invalid`);
      });
    }
    shouldSearchStopWithResult(e) {
      return !(e === null || e.isEmpty && this.config.ignoreEmptySearchPlaces);
    }
    nextDirectoryToSearch(e, r) {
      if (this.shouldSearchStopWithResult(r))
        return null;
      const o = d(e);
      return o === e || e === this.config.stopDir ? null : o;
    }
    loadPackageProp(e, r) {
      const o = l.loaders.loadJson(e, r);
      return (0, u.getPropertyByPath)(o, this.config.packageProp) || null;
    }
    getLoaderEntryForFile(e) {
      if (i.default.basename(e) === "package.json")
        return this.loadPackageProp.bind(this);
      const r = i.default.extname(e) || "noExt", o = this.config.loaders[r];
      if (!o)
        throw new Error(`No loader specified for ${s(e)}`);
      return o;
    }
    loadedContentToCosmiconfigResult(e, r) {
      return r === null ? null : r === void 0 ? {
        filepath: e,
        config: void 0,
        isEmpty: !0
      } : {
        config: r,
        filepath: e
      };
    }
    validateFilePath(e) {
      if (!e)
        throw new Error("load must pass a non-empty string");
    }
  }
  a.ExplorerBase = h;
  function d(t) {
    return i.default.dirname(t);
  }
  function s(t) {
    const e = i.default.extname(t);
    return e ? `extension "${e}"` : "files without extensions";
  }
  return a;
}
export {
  _ as __require
};
//# sourceMappingURL=ExplorerBase.js.map
