import { __name } from './chunk-6AXVLTU5.js';
import 'esbuild';
import { createRequire } from 'module';

createRequire(import.meta.url) ;

// ../../node_modules/.pnpm/bundle-require@5.1.0_esbuild@0.25.2/node_modules/bundle-require/dist/index.js
var tsconfigPathsToRegExp = /* @__PURE__ */ __name((paths) => {
  return Object.keys(paths || {}).map((key) => {
    return new RegExp(`^${key.replace(/\*/, ".*")}$`);
  });
}, "tsconfigPathsToRegExp");
var match = /* @__PURE__ */ __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__ */ __name((log, 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");

export { externalPlugin };
//# sourceMappingURL=chunk-OV4QUJV2.js.map
//# sourceMappingURL=chunk-OV4QUJV2.js.map