'use strict';

var chunkAF3E2D32_cjs = require('./chunk-AF3E2D32.cjs');
require('esbuild');
var module$1 = require('module');

var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-ULD5XAAD.cjs', document.baseURI).href))) ;

// ../../node_modules/.pnpm/bundle-require@5.1.0_esbuild@0.24.2/node_modules/bundle-require/dist/index.js
var tsconfigPathsToRegExp = /* @__PURE__ */ chunkAF3E2D32_cjs.__name((paths) => {
  return Object.keys(paths || {}).map((key) => {
    return new RegExp(`^${key.replace(/\*/, ".*")}$`);
  });
}, "tsconfigPathsToRegExp");
var match = /* @__PURE__ */ chunkAF3E2D32_cjs.__name((id, patterns) => {
  if (!patterns) return false;
  return patterns.some((p) => {
    if (p instanceof RegExp) {
      return p.test(id);
    }
    return id === p || id.startsWith(p + "/");
  });
}, "match");

// src/helpers/esbuild/external-plugin.ts
var NON_NODE_MODULE_REGEX = /^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/;
var externalPlugin = /* @__PURE__ */ chunkAF3E2D32_cjs.__name((options = {}, tsconfigResolvePaths = {}) => {
  return {
    name: "storm-stack:external",
    setup(build2) {
      const external = options.external ?? [];
      const noExternal = options.noExternal ?? [];
      const skipNodeModulesBundle = options.skipNodeModulesBundle ?? false;
      if (skipNodeModulesBundle) {
        const resolvePatterns = tsconfigPathsToRegExp(tsconfigResolvePaths);
        build2.onResolve({
          filter: /.*/
        }, (args) => {
          if (match(args.path, resolvePatterns) || args.path.startsWith("internal:") || args.path.startsWith("virtual:") || args.path.startsWith("storm:")) {
            return;
          }
          if (match(args.path, noExternal)) {
            return;
          }
          if (match(args.path, external)) {
            return {
              external: true
            };
          }
          if (!NON_NODE_MODULE_REGEX.test(args.path)) {
            return {
              path: args.path,
              external: true
            };
          }
          return;
        });
      } else {
        build2.onResolve({
          filter: /.*/
        }, (args) => {
          if (match(args.path, noExternal)) {
            return;
          }
          if (match(args.path, external)) {
            return {
              external: true
            };
          }
          return;
        });
      }
    }
  };
}, "externalPlugin");

exports.externalPlugin = externalPlugin;
//# sourceMappingURL=chunk-ULD5XAAD.cjs.map
//# sourceMappingURL=chunk-ULD5XAAD.cjs.map