// node_modules/tsup/assets/esm_shims.js
import path from "path";
import { fileURLToPath } from "url";
var getFilename = () => fileURLToPath(import.meta.url);
var getDirname = () => path.dirname(getFilename());
var __dirname = /* @__PURE__ */ getDirname();

// src/index.ts
import nodeGypBuild from "node-gyp-build";
import { join } from "path";

// src/stack_path.ts
import { dirname } from "path";
function getCallerDirname() {
  const e = new Error();
  if (e.stack == null) {
    Error.captureStackTrace(e);
  }
  return dirname(extractCallerPath(e.stack));
}
var patterns = process.platform === "win32" ? [
  // Standard: "at functionName (C:\path\file.js:1:1)"
  /\bat\s.+?\((?<path>[A-Z]:\\.+):\d+:\d+\)$/,
  // direct: "at C:\path\file.js:1:1"
  /\bat\s(?<path>[A-Z]:\\.+):\d+:\d+$/,
  // UNC: "at functionName (\\server\share\path\file.js:1:1)"
  /\bat\s.+?\((?<path>\\\\.+):\d+:\d+\)$/,
  // direct: "at \\server\share\path\file.js:1:1"
  /\bat\s(?<path>\\\\.+):\d+:\d+$/
] : [
  // Standard: "at functionName (/path/file.js:1:1)"
  /\bat\s.+?\((?<path>\/.+?):\d+:\d+\)$/,
  // Anonymous or direct: "at /path/file.js:1:1"
  /\bat\s(.+[^/]\s)?(?<path>\/.+?):\d+:\d+$/
];
var MaybeUrlRE = /^[a-z]{2,5}:\/\//i;
function extractCallerPath(stack) {
  const frames = stack.split("\n").filter(Boolean);
  const callerFrame = frames.findIndex(
    (frame) => frame.includes("getCallerDirname")
  );
  if (callerFrame === -1) {
    throw new Error("Invalid stack trace format: missing caller frame");
  }
  for (let i = callerFrame + 1; i < frames.length; i++) {
    const frame = frames[i];
    for (const pattern of patterns) {
      const g = frame?.trim().match(pattern)?.groups;
      if (g != null && g["path"]) {
        const path2 = g["path"];
        if (MaybeUrlRE.test(path2)) {
          try {
            return new URL(path2).pathname;
          } catch {
          }
        }
        return path2;
      }
    }
  }
  throw new Error("Invalid stack trace format: no parsable frames");
}

// src/dirname.ts
function _dirname() {
  try {
    if (typeof __dirname !== "undefined") return __dirname;
  } catch {
  }
  return getCallerDirname();
}

// src/index.ts
var binding = nodeGypBuild(join(_dirname(), ".."));
if (binding.DatabaseSync && typeof Symbol.dispose !== "undefined") {
  binding.DatabaseSync.prototype[Symbol.dispose] = function() {
    try {
      this.close();
    } catch {
    }
  };
}
if (binding.StatementSync && typeof Symbol.dispose !== "undefined") {
  binding.StatementSync.prototype[Symbol.dispose] = function() {
    try {
      this.finalize();
    } catch {
    }
  };
}
var DatabaseSync = binding.DatabaseSync;
var StatementSync = binding.StatementSync;
var Session = binding.Session;
var constants = binding.constants;
var index_default = binding;
export {
  DatabaseSync,
  Session,
  StatementSync,
  constants,
  index_default as default
};
//# sourceMappingURL=index.mjs.map