function getRuntimeRequire() {
  if (typeof __non_webpack_require__ === "function") {
    return __non_webpack_require__;
  }

  return require;
}

function loadSwift() {
  if (globalThis.SwiftLoaded) return;

  const runtimeRequire = getRuntimeRequire();

  if (
    typeof NSBundle !== "undefined" &&
    NSBundle.mainBundle?.bundleIdentifier
  ) {
    const mainBundle = NSBundle.mainBundle;
    const resourcePath = mainBundle.resourcePath;
    if (resourcePath) {
      const nodeFilePath = resourcePath + "/libSwiftBridge.node";
      module.exports = runtimeRequire(nodeFilePath);
      globalThis.SwiftLoaded = true;
      return;
    }
  }

  module.exports = runtimeRequire(__dirname + "/dist/libSwiftBridge.node");
  globalThis.SwiftLoaded = true;
}

loadSwift();
