import { __exports as n } from "../../../../../../_virtual/Explorer.js";
import C from "../../../../../../_virtual/___vite-browser-external.js";
import { __require as x } from "./ExplorerBase.js";
import { __require as R } from "./readFile.js";
import { __require as F } from "./cacheWrapper.js";
import { __require as q } from "./getDirectory.js";
var y;
function b() {
  if (y)
    return n;
  y = 1, Object.defineProperty(n, "__esModule", {
    value: !0
  }), n.Explorer = void 0;
  var c = w(C), m = x(), u = R(), f = F(), p = q();
  function w(o) {
    return o && o.__esModule ? o : { default: o };
  }
  function _(o) {
    var r;
    if (typeof Symbol < "u" && (Symbol.asyncIterator && (r = o[Symbol.asyncIterator], r != null) || Symbol.iterator && (r = o[Symbol.iterator], r != null)))
      return r.call(o);
    throw new TypeError("Object is not async iterable");
  }
  class v extends m.ExplorerBase {
    constructor(r) {
      super(r);
    }
    async search(r = process.cwd()) {
      const e = await (0, p.getDirectory)(r);
      return await this.searchFromDirectory(e);
    }
    async searchFromDirectory(r) {
      const e = c.default.resolve(process.cwd(), r), t = async () => {
        const a = await this.searchDirectory(e), s = this.nextDirectoryToSearch(e, a);
        return s ? this.searchFromDirectory(s) : await this.config.transform(a);
      };
      return this.searchCache ? (0, f.cacheWrapper)(this.searchCache, e, t) : t();
    }
    async searchDirectory(r) {
      var e = !0, t = !1, a;
      try {
        for (var s = _(this.config.searchPlaces), i, h; i = await s.next(), e = i.done, h = await i.value, !e; e = !0) {
          const l = h, d = await this.loadSearchPlace(r, l);
          if (this.shouldSearchStopWithResult(d) === !0)
            return d;
        }
      } catch (l) {
        t = !0, a = l;
      } finally {
        try {
          !e && s.return != null && await s.return();
        } finally {
          if (t)
            throw a;
        }
      }
      return null;
    }
    async loadSearchPlace(r, e) {
      const t = c.default.join(r, e), a = await (0, u.readFile)(t);
      return await this.createCosmiconfigResult(t, a);
    }
    async loadFileContent(r, e) {
      return e === null ? null : e.trim() === "" ? void 0 : await this.getLoaderEntryForFile(r)(r, e);
    }
    async createCosmiconfigResult(r, e) {
      const t = await this.loadFileContent(r, e);
      return this.loadedContentToCosmiconfigResult(r, t);
    }
    async load(r) {
      this.validateFilePath(r);
      const e = c.default.resolve(process.cwd(), r), t = async () => {
        const a = await (0, u.readFile)(e, {
          throwNotFound: !0
        }), s = await this.createCosmiconfigResult(e, a);
        return await this.config.transform(s);
      };
      return this.loadCache ? (0, f.cacheWrapper)(this.loadCache, e, t) : t();
    }
  }
  return n.Explorer = v, n;
}
export {
  b as __require
};
//# sourceMappingURL=Explorer.js.map
