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