import B from "../../../../../../_virtual/___vite-browser-external.js";
import { __require as de } from "./homedir.js";
import { __require as pe } from "./caller.js";
import { __require as me } from "./node-modules-paths.js";
import { __require as ge } from "./normalize-options.js";
import { __require as ke } from "../../../../is-core-module@2.9.0/node_modules/is-core-module/index.js";
var S, Q;
function qe() {
  if (Q)
    return S;
  Q = 1;
  var F = B, W = de(), s = B, X = pe(), Y = me(), b = ge(), x = ke(), ee = process.platform !== "win32" && F.realpath && typeof F.realpath.native == "function" ? F.realpath.native : F.realpath, U = W(), ne = function() {
    return [
      s.join(U, ".node_modules"),
      s.join(U, ".node_libraries")
    ];
  }, ie = function(a, c) {
    F.stat(a, function(u, i) {
      return u ? u.code === "ENOENT" || u.code === "ENOTDIR" ? c(null, !1) : c(u) : c(null, i.isFile() || i.isFIFO());
    });
  }, re = function(a, c) {
    F.stat(a, function(u, i) {
      return u ? u.code === "ENOENT" || u.code === "ENOTDIR" ? c(null, !1) : c(u) : c(null, i.isDirectory());
    });
  }, ae = function(a, c) {
    ee(a, function(u, i) {
      u && u.code !== "ENOENT" ? c(u) : c(null, u ? a : i);
    });
  }, j = function(a, c, u, i) {
    u && u.preserveSymlinks === !1 ? a(c, i) : i(null, c);
  }, te = function(a, c, u) {
    a(c, function(i, e) {
      if (i)
        u(i);
      else
        try {
          var R = JSON.parse(e);
          u(null, R);
        } catch {
          u(null);
        }
    });
  }, ue = function(a, c, u) {
    for (var i = Y(c, u, a), e = 0; e < i.length; e++)
      i[e] = s.join(i[e], a);
    return i;
  };
  return S = function(a, c, u) {
    var i = u, e = c;
    if (typeof c == "function" && (i = e, e = {}), typeof a != "string") {
      var R = new TypeError("Path must be a string.");
      return process.nextTick(function() {
        i(R);
      });
    }
    e = b(a, e);
    var I = e.isFile || ie, le = e.isDirectory || re, z = e.readFile || F.readFile, P = e.realpath || ae, L = e.readPackage || te;
    if (e.readFile && e.readPackage) {
      var oe = new TypeError("`readFile` and `readPackage` are mutually exclusive.");
      return process.nextTick(function() {
        i(oe);
      });
    }
    var H = e.packageIterator, G = e.extensions || [".js"], fe = e.includeCoreModules !== !1, J = e.basedir || s.dirname(X()), K = e.filename || J;
    e.paths = e.paths || ne();
    var se = s.resolve(J);
    j(
      P,
      se,
      e,
      function(n, t) {
        n ? i(n) : ce(t);
      }
    );
    var q;
    function ce(n) {
      if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(a))
        q = s.resolve(n, a), (a === "." || a === ".." || a.slice(-1) === "/") && (q += "/"), /\/$/.test(a) && q === n ? A(q, e.package, V) : _(q, e.package, V);
      else {
        if (fe && x(a))
          return i(null, a);
        ve(a, n, function(t, v, r) {
          if (t)
            i(t);
          else {
            if (v)
              return j(P, v, e, function(m, f) {
                m ? i(m) : i(null, f, r);
              });
            var l = new Error("Cannot find module '" + a + "' from '" + K + "'");
            l.code = "MODULE_NOT_FOUND", i(l);
          }
        });
      }
    }
    function V(n, t, v) {
      n ? i(n) : t ? i(null, t, v) : A(q, function(r, l, m) {
        if (r)
          i(r);
        else if (l)
          j(P, l, e, function(o, p) {
            o ? i(o) : i(null, p, m);
          });
        else {
          var f = new Error("Cannot find module '" + a + "' from '" + K + "'");
          f.code = "MODULE_NOT_FOUND", i(f);
        }
      });
    }
    function _(n, t, v) {
      var r = t, l = v;
      typeof r == "function" && (l = r, r = void 0);
      var m = [""].concat(G);
      f(m, n, r);
      function f(o, p, k) {
        if (o.length === 0)
          return l(null, void 0, k);
        var N = p + o[0], g = k;
        g ? d(null, g) : w(s.dirname(N), d);
        function d(y, D, h) {
          if (g = D, y)
            return l(y);
          if (h && g && e.pathFilter) {
            var E = s.relative(h, N), M = E.slice(0, E.length - o[0].length), T = e.pathFilter(g, p, M);
            if (T)
              return f(
                [""].concat(G.slice()),
                s.resolve(h, T),
                g
              );
          }
          I(N, C);
        }
        function C(y, D) {
          if (y)
            return l(y);
          if (D)
            return l(null, N, g);
          f(o.slice(1), p, g);
        }
      }
    }
    function w(n, t) {
      if (n === "" || n === "/" || process.platform === "win32" && /^\w:[/\\]*$/.test(n) || /[/\\]node_modules[/\\]*$/.test(n))
        return t(null);
      j(P, n, e, function(v, r) {
        if (v)
          return w(s.dirname(n), t);
        var l = s.join(r, "package.json");
        I(l, function(m, f) {
          if (!f)
            return w(s.dirname(n), t);
          L(z, l, function(o, p) {
            o && t(o);
            var k = p;
            k && e.packageFilter && (k = e.packageFilter(k, l)), t(null, k, n);
          });
        });
      });
    }
    function A(n, t, v) {
      var r = v, l = t;
      typeof l == "function" && (r = l, l = e.package), j(P, n, e, function(m, f) {
        if (m)
          return r(m);
        var o = s.join(f, "package.json");
        I(o, function(p, k) {
          if (p)
            return r(p);
          if (!k)
            return _(s.join(n, "index"), l, r);
          L(z, o, function(N, g) {
            if (N)
              return r(N);
            var d = g;
            if (d && e.packageFilter && (d = e.packageFilter(d, o)), d && d.main) {
              if (typeof d.main != "string") {
                var C = new TypeError("package \u201C" + d.name + "\u201D `main` must be a string");
                return C.code = "INVALID_PACKAGE_MAIN", r(C);
              }
              (d.main === "." || d.main === "./") && (d.main = "index"), _(s.resolve(n, d.main), d, function(y, D, h) {
                if (y)
                  return r(y);
                if (D)
                  return r(null, D, h);
                if (!h)
                  return _(s.join(n, "index"), h, r);
                var E = s.resolve(n, h.main);
                A(E, h, function(M, T, Z) {
                  if (M)
                    return r(M);
                  if (T)
                    return r(null, T, Z);
                  _(s.join(n, "index"), Z, r);
                });
              });
              return;
            }
            _(s.join(n, "/index"), d, r);
          });
        });
      });
    }
    function $(n, t) {
      if (t.length === 0)
        return n(null, void 0);
      var v = t[0];
      le(s.dirname(v), r);
      function r(f, o) {
        if (f)
          return n(f);
        if (!o)
          return $(n, t.slice(1));
        _(v, e.package, l);
      }
      function l(f, o, p) {
        if (f)
          return n(f);
        if (o)
          return n(null, o, p);
        A(v, e.package, m);
      }
      function m(f, o, p) {
        if (f)
          return n(f);
        if (o)
          return n(null, o, p);
        $(n, t.slice(1));
      }
    }
    function ve(n, t, v) {
      var r = function() {
        return ue(n, t, e);
      };
      $(
        v,
        H ? H(n, t, r, e) : r()
      );
    }
  }, S;
}
export {
  qe as __require
};
//# sourceMappingURL=async.js.map
