tidewave 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,7 +28,7 @@ var __export = (target, all) => {
28
28
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
29
29
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
30
30
 
31
- // node_modules/connect/node_modules/ms/index.js
31
+ // node_modules/connect/node_modules/debug/node_modules/ms/index.js
32
32
  var require_ms = __commonJS((exports, module) => {
33
33
  var s = 1000;
34
34
  var m = s * 60;
@@ -444,7 +444,423 @@ var require_src = __commonJS((exports, module) => {
444
444
  }
445
445
  });
446
446
 
447
- // node_modules/connect/node_modules/encodeurl/index.js
447
+ // node_modules/finalhandler/node_modules/debug/node_modules/ms/index.js
448
+ var require_ms2 = __commonJS((exports, module) => {
449
+ var s = 1000;
450
+ var m = s * 60;
451
+ var h = m * 60;
452
+ var d = h * 24;
453
+ var y = d * 365.25;
454
+ module.exports = function(val, options) {
455
+ options = options || {};
456
+ var type = typeof val;
457
+ if (type === "string" && val.length > 0) {
458
+ return parse(val);
459
+ } else if (type === "number" && isNaN(val) === false) {
460
+ return options.long ? fmtLong(val) : fmtShort(val);
461
+ }
462
+ throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(val));
463
+ };
464
+ function parse(str) {
465
+ str = String(str);
466
+ if (str.length > 100) {
467
+ return;
468
+ }
469
+ var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
470
+ if (!match) {
471
+ return;
472
+ }
473
+ var n = parseFloat(match[1]);
474
+ var type = (match[2] || "ms").toLowerCase();
475
+ switch (type) {
476
+ case "years":
477
+ case "year":
478
+ case "yrs":
479
+ case "yr":
480
+ case "y":
481
+ return n * y;
482
+ case "days":
483
+ case "day":
484
+ case "d":
485
+ return n * d;
486
+ case "hours":
487
+ case "hour":
488
+ case "hrs":
489
+ case "hr":
490
+ case "h":
491
+ return n * h;
492
+ case "minutes":
493
+ case "minute":
494
+ case "mins":
495
+ case "min":
496
+ case "m":
497
+ return n * m;
498
+ case "seconds":
499
+ case "second":
500
+ case "secs":
501
+ case "sec":
502
+ case "s":
503
+ return n * s;
504
+ case "milliseconds":
505
+ case "millisecond":
506
+ case "msecs":
507
+ case "msec":
508
+ case "ms":
509
+ return n;
510
+ default:
511
+ return;
512
+ }
513
+ }
514
+ function fmtShort(ms) {
515
+ if (ms >= d) {
516
+ return Math.round(ms / d) + "d";
517
+ }
518
+ if (ms >= h) {
519
+ return Math.round(ms / h) + "h";
520
+ }
521
+ if (ms >= m) {
522
+ return Math.round(ms / m) + "m";
523
+ }
524
+ if (ms >= s) {
525
+ return Math.round(ms / s) + "s";
526
+ }
527
+ return ms + "ms";
528
+ }
529
+ function fmtLong(ms) {
530
+ return plural(ms, d, "day") || plural(ms, h, "hour") || plural(ms, m, "minute") || plural(ms, s, "second") || ms + " ms";
531
+ }
532
+ function plural(ms, n, name) {
533
+ if (ms < n) {
534
+ return;
535
+ }
536
+ if (ms < n * 1.5) {
537
+ return Math.floor(ms / n) + " " + name;
538
+ }
539
+ return Math.ceil(ms / n) + " " + name + "s";
540
+ }
541
+ });
542
+
543
+ // node_modules/finalhandler/node_modules/debug/src/debug.js
544
+ var require_debug2 = __commonJS((exports, module) => {
545
+ exports = module.exports = createDebug.debug = createDebug["default"] = createDebug;
546
+ exports.coerce = coerce;
547
+ exports.disable = disable;
548
+ exports.enable = enable;
549
+ exports.enabled = enabled;
550
+ exports.humanize = require_ms2();
551
+ exports.names = [];
552
+ exports.skips = [];
553
+ exports.formatters = {};
554
+ var prevTime;
555
+ function selectColor(namespace) {
556
+ var hash = 0, i;
557
+ for (i in namespace) {
558
+ hash = (hash << 5) - hash + namespace.charCodeAt(i);
559
+ hash |= 0;
560
+ }
561
+ return exports.colors[Math.abs(hash) % exports.colors.length];
562
+ }
563
+ function createDebug(namespace) {
564
+ function debug() {
565
+ if (!debug.enabled)
566
+ return;
567
+ var self = debug;
568
+ var curr = +new Date;
569
+ var ms = curr - (prevTime || curr);
570
+ self.diff = ms;
571
+ self.prev = prevTime;
572
+ self.curr = curr;
573
+ prevTime = curr;
574
+ var args = new Array(arguments.length);
575
+ for (var i = 0;i < args.length; i++) {
576
+ args[i] = arguments[i];
577
+ }
578
+ args[0] = exports.coerce(args[0]);
579
+ if (typeof args[0] !== "string") {
580
+ args.unshift("%O");
581
+ }
582
+ var index = 0;
583
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
584
+ if (match === "%%")
585
+ return match;
586
+ index++;
587
+ var formatter = exports.formatters[format];
588
+ if (typeof formatter === "function") {
589
+ var val = args[index];
590
+ match = formatter.call(self, val);
591
+ args.splice(index, 1);
592
+ index--;
593
+ }
594
+ return match;
595
+ });
596
+ exports.formatArgs.call(self, args);
597
+ var logFn = debug.log || exports.log || console.log.bind(console);
598
+ logFn.apply(self, args);
599
+ }
600
+ debug.namespace = namespace;
601
+ debug.enabled = exports.enabled(namespace);
602
+ debug.useColors = exports.useColors();
603
+ debug.color = selectColor(namespace);
604
+ if (typeof exports.init === "function") {
605
+ exports.init(debug);
606
+ }
607
+ return debug;
608
+ }
609
+ function enable(namespaces) {
610
+ exports.save(namespaces);
611
+ exports.names = [];
612
+ exports.skips = [];
613
+ var split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
614
+ var len = split.length;
615
+ for (var i = 0;i < len; i++) {
616
+ if (!split[i])
617
+ continue;
618
+ namespaces = split[i].replace(/\*/g, ".*?");
619
+ if (namespaces[0] === "-") {
620
+ exports.skips.push(new RegExp("^" + namespaces.substr(1) + "$"));
621
+ } else {
622
+ exports.names.push(new RegExp("^" + namespaces + "$"));
623
+ }
624
+ }
625
+ }
626
+ function disable() {
627
+ exports.enable("");
628
+ }
629
+ function enabled(name) {
630
+ var i, len;
631
+ for (i = 0, len = exports.skips.length;i < len; i++) {
632
+ if (exports.skips[i].test(name)) {
633
+ return false;
634
+ }
635
+ }
636
+ for (i = 0, len = exports.names.length;i < len; i++) {
637
+ if (exports.names[i].test(name)) {
638
+ return true;
639
+ }
640
+ }
641
+ return false;
642
+ }
643
+ function coerce(val) {
644
+ if (val instanceof Error)
645
+ return val.stack || val.message;
646
+ return val;
647
+ }
648
+ });
649
+
650
+ // node_modules/finalhandler/node_modules/debug/src/browser.js
651
+ var require_browser2 = __commonJS((exports, module) => {
652
+ exports = module.exports = require_debug2();
653
+ exports.log = log;
654
+ exports.formatArgs = formatArgs;
655
+ exports.save = save;
656
+ exports.load = load;
657
+ exports.useColors = useColors;
658
+ exports.storage = typeof chrome != "undefined" && typeof chrome.storage != "undefined" ? chrome.storage.local : localstorage();
659
+ exports.colors = [
660
+ "lightseagreen",
661
+ "forestgreen",
662
+ "goldenrod",
663
+ "dodgerblue",
664
+ "darkorchid",
665
+ "crimson"
666
+ ];
667
+ function useColors() {
668
+ if (typeof window !== "undefined" && window.process && window.process.type === "renderer") {
669
+ return true;
670
+ }
671
+ return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
672
+ }
673
+ exports.formatters.j = function(v) {
674
+ try {
675
+ return JSON.stringify(v);
676
+ } catch (err) {
677
+ return "[UnexpectedJSONParseError]: " + err.message;
678
+ }
679
+ };
680
+ function formatArgs(args) {
681
+ var useColors2 = this.useColors;
682
+ args[0] = (useColors2 ? "%c" : "") + this.namespace + (useColors2 ? " %c" : " ") + args[0] + (useColors2 ? "%c " : " ") + "+" + exports.humanize(this.diff);
683
+ if (!useColors2)
684
+ return;
685
+ var c = "color: " + this.color;
686
+ args.splice(1, 0, c, "color: inherit");
687
+ var index = 0;
688
+ var lastC = 0;
689
+ args[0].replace(/%[a-zA-Z%]/g, function(match) {
690
+ if (match === "%%")
691
+ return;
692
+ index++;
693
+ if (match === "%c") {
694
+ lastC = index;
695
+ }
696
+ });
697
+ args.splice(lastC, 0, c);
698
+ }
699
+ function log() {
700
+ return typeof console === "object" && console.log && Function.prototype.apply.call(console.log, console, arguments);
701
+ }
702
+ function save(namespaces) {
703
+ try {
704
+ if (namespaces == null) {
705
+ exports.storage.removeItem("debug");
706
+ } else {
707
+ exports.storage.debug = namespaces;
708
+ }
709
+ } catch (e) {}
710
+ }
711
+ function load() {
712
+ var r;
713
+ try {
714
+ r = exports.storage.debug;
715
+ } catch (e) {}
716
+ if (!r && typeof process !== "undefined" && "env" in process) {
717
+ r = process.env.DEBUG;
718
+ }
719
+ return r;
720
+ }
721
+ exports.enable(load());
722
+ function localstorage() {
723
+ try {
724
+ return window.localStorage;
725
+ } catch (e) {}
726
+ }
727
+ });
728
+
729
+ // node_modules/finalhandler/node_modules/debug/src/node.js
730
+ var require_node2 = __commonJS((exports, module) => {
731
+ var tty = __require("tty");
732
+ var util = __require("util");
733
+ exports = module.exports = require_debug2();
734
+ exports.init = init;
735
+ exports.log = log;
736
+ exports.formatArgs = formatArgs;
737
+ exports.save = save;
738
+ exports.load = load;
739
+ exports.useColors = useColors;
740
+ exports.colors = [6, 2, 3, 4, 5, 1];
741
+ exports.inspectOpts = Object.keys(process.env).filter(function(key) {
742
+ return /^debug_/i.test(key);
743
+ }).reduce(function(obj, key) {
744
+ var prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, function(_, k) {
745
+ return k.toUpperCase();
746
+ });
747
+ var val = process.env[key];
748
+ if (/^(yes|on|true|enabled)$/i.test(val))
749
+ val = true;
750
+ else if (/^(no|off|false|disabled)$/i.test(val))
751
+ val = false;
752
+ else if (val === "null")
753
+ val = null;
754
+ else
755
+ val = Number(val);
756
+ obj[prop] = val;
757
+ return obj;
758
+ }, {});
759
+ var fd = parseInt(process.env.DEBUG_FD, 10) || 2;
760
+ if (fd !== 1 && fd !== 2) {
761
+ util.deprecate(function() {}, "except for stderr(2) and stdout(1), any other usage of DEBUG_FD is deprecated. Override debug.log if you want to use a different log function (https://git.io/debug_fd)")();
762
+ }
763
+ var stream = fd === 1 ? process.stdout : fd === 2 ? process.stderr : createWritableStdioStream(fd);
764
+ function useColors() {
765
+ return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(fd);
766
+ }
767
+ exports.formatters.o = function(v) {
768
+ this.inspectOpts.colors = this.useColors;
769
+ return util.inspect(v, this.inspectOpts).split(`
770
+ `).map(function(str) {
771
+ return str.trim();
772
+ }).join(" ");
773
+ };
774
+ exports.formatters.O = function(v) {
775
+ this.inspectOpts.colors = this.useColors;
776
+ return util.inspect(v, this.inspectOpts);
777
+ };
778
+ function formatArgs(args) {
779
+ var name = this.namespace;
780
+ var useColors2 = this.useColors;
781
+ if (useColors2) {
782
+ var c = this.color;
783
+ var prefix = " \x1B[3" + c + ";1m" + name + " " + "\x1B[0m";
784
+ args[0] = prefix + args[0].split(`
785
+ `).join(`
786
+ ` + prefix);
787
+ args.push("\x1B[3" + c + "m+" + exports.humanize(this.diff) + "\x1B[0m");
788
+ } else {
789
+ args[0] = new Date().toUTCString() + " " + name + " " + args[0];
790
+ }
791
+ }
792
+ function log() {
793
+ return stream.write(util.format.apply(util, arguments) + `
794
+ `);
795
+ }
796
+ function save(namespaces) {
797
+ if (namespaces == null) {
798
+ delete process.env.DEBUG;
799
+ } else {
800
+ process.env.DEBUG = namespaces;
801
+ }
802
+ }
803
+ function load() {
804
+ return process.env.DEBUG;
805
+ }
806
+ function createWritableStdioStream(fd2) {
807
+ var stream2;
808
+ var tty_wrap = process.binding("tty_wrap");
809
+ switch (tty_wrap.guessHandleType(fd2)) {
810
+ case "TTY":
811
+ stream2 = new tty.WriteStream(fd2);
812
+ stream2._type = "tty";
813
+ if (stream2._handle && stream2._handle.unref) {
814
+ stream2._handle.unref();
815
+ }
816
+ break;
817
+ case "FILE":
818
+ var fs = __require("fs");
819
+ stream2 = new fs.SyncWriteStream(fd2, { autoClose: false });
820
+ stream2._type = "fs";
821
+ break;
822
+ case "PIPE":
823
+ case "TCP":
824
+ var net = __require("net");
825
+ stream2 = new net.Socket({
826
+ fd: fd2,
827
+ readable: false,
828
+ writable: true
829
+ });
830
+ stream2.readable = false;
831
+ stream2.read = null;
832
+ stream2._type = "pipe";
833
+ if (stream2._handle && stream2._handle.unref) {
834
+ stream2._handle.unref();
835
+ }
836
+ break;
837
+ default:
838
+ throw new Error("Implement me. Unknown stream file type!");
839
+ }
840
+ stream2.fd = fd2;
841
+ stream2._isStdio = true;
842
+ return stream2;
843
+ }
844
+ function init(debug) {
845
+ debug.inspectOpts = {};
846
+ var keys = Object.keys(exports.inspectOpts);
847
+ for (var i = 0;i < keys.length; i++) {
848
+ debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
849
+ }
850
+ }
851
+ exports.enable(load());
852
+ });
853
+
854
+ // node_modules/finalhandler/node_modules/debug/src/index.js
855
+ var require_src2 = __commonJS((exports, module) => {
856
+ if (typeof process !== "undefined" && process.type === "renderer") {
857
+ module.exports = require_browser2();
858
+ } else {
859
+ module.exports = require_node2();
860
+ }
861
+ });
862
+
863
+ // node_modules/finalhandler/node_modules/encodeurl/index.js
448
864
  var require_encodeurl = __commonJS((exports, module) => {
449
865
  /*!
450
866
  * encodeurl
@@ -569,7 +985,7 @@ var require_ee_first = __commonJS((exports, module) => {
569
985
  }
570
986
  });
571
987
 
572
- // node_modules/connect/node_modules/on-finished/index.js
988
+ // node_modules/finalhandler/node_modules/on-finished/index.js
573
989
  var require_on_finished = __commonJS((exports, module) => {
574
990
  /*!
575
991
  * on-finished
@@ -744,7 +1160,7 @@ var require_parseurl = __commonJS((exports, module) => {
744
1160
  }
745
1161
  });
746
1162
 
747
- // node_modules/connect/node_modules/statuses/codes.json
1163
+ // node_modules/finalhandler/node_modules/statuses/codes.json
748
1164
  var require_codes = __commonJS((exports, module) => {
749
1165
  module.exports = {
750
1166
  "100": "Continue",
@@ -814,7 +1230,7 @@ var require_codes = __commonJS((exports, module) => {
814
1230
  };
815
1231
  });
816
1232
 
817
- // node_modules/connect/node_modules/statuses/index.js
1233
+ // node_modules/finalhandler/node_modules/statuses/index.js
818
1234
  var require_statuses = __commonJS((exports, module) => {
819
1235
  /*!
820
1236
  * statuses
@@ -919,14 +1335,14 @@ var require_unpipe = __commonJS((exports, module) => {
919
1335
  }
920
1336
  });
921
1337
 
922
- // node_modules/connect/node_modules/finalhandler/index.js
1338
+ // node_modules/finalhandler/index.js
923
1339
  var require_finalhandler = __commonJS((exports, module) => {
924
1340
  /*!
925
1341
  * finalhandler
926
1342
  * Copyright(c) 2014-2017 Douglas Christopher Wilson
927
1343
  * MIT Licensed
928
1344
  */
929
- var debug = require_src()("finalhandler");
1345
+ var debug = require_src2()("finalhandler");
930
1346
  var encodeUrl = require_encodeurl();
931
1347
  var escapeHtml = require_escape_html();
932
1348
  var onFinished = require_on_finished();
@@ -19721,7 +20137,7 @@ Defaults to 30000 (30 seconds).`),
19721
20137
  });
19722
20138
 
19723
20139
  // package.json
19724
- var name = "tidewave", version = "0.5.0", package_default;
20140
+ var name = "tidewave", version = "0.5.2", package_default;
19725
20141
  var init_package = __esm(() => {
19726
20142
  package_default = {
19727
20143
  name,
@@ -19779,7 +20195,7 @@ var init_package = __esm(() => {
19779
20195
  ],
19780
20196
  scripts: {
19781
20197
  dist: "bun run clean && bun run build:js && bun run build:types",
19782
- "build:js": "bun build --outdir dist --root src --external commander --external chalk --external typescript --external child_process --external module --external @opentelemetry/api --external @opentelemetry/api-logs --external @opentelemetry/core --external @opentelemetry/resources --external @opentelemetry/sdk-logs --external @opentelemetry/sdk-trace-base --external @opentelemetry/sdk-trace-node --external @opentelemetry/semantic-conventions src/next-js/handler.ts src/next-js/instrumentation.ts src/vite-plugin.ts src/evaluation/eval_worker.ts src/cli/index.ts --target node",
20198
+ "build:js": "bun build --outdir dist --root src --external typescript --external child_process --external module --external @opentelemetry/api --external @opentelemetry/sdk-logs --external @opentelemetry/sdk-trace-base src/next-js/handler.ts src/next-js/instrumentation.ts src/vite-plugin.ts src/evaluation/eval_worker.ts src/cli/index.ts --target node",
19783
20199
  "build:types": "tsc -p tsconfig.declarations.json",
19784
20200
  dev: "bun run src/cli/index.ts",
19785
20201
  test: "bun test",
@@ -19792,23 +20208,16 @@ var init_package = __esm(() => {
19792
20208
  },
19793
20209
  dependencies: {
19794
20210
  "@modelcontextprotocol/sdk": "^1.17.4",
19795
- "@opentelemetry/api": "^1.9.0",
19796
- "@opentelemetry/api-logs": "^0.206.0",
19797
- "@opentelemetry/core": "^2.1.0",
19798
- "@opentelemetry/resources": "^2.1.0",
19799
- "@opentelemetry/sdk-logs": "^0.206.0",
19800
- "@opentelemetry/sdk-trace-base": "^2.1.0",
19801
- "@opentelemetry/sdk-trace-node": "^2.1.0",
19802
- "@opentelemetry/semantic-conventions": "^1.37.0",
19803
20211
  "body-parser": "^2.2.0",
19804
- chalk: "^5.3.0",
19805
- commander: "^12.1.0",
19806
20212
  connect: "^3.7.0",
19807
20213
  typescript: "^5",
19808
20214
  zod: "3.25.76"
19809
20215
  },
19810
20216
  devDependencies: {
19811
20217
  "@eslint/js": "^9.16.0",
20218
+ "@opentelemetry/api": "^1.9.0",
20219
+ "@opentelemetry/sdk-logs": "^0.206.0",
20220
+ "@opentelemetry/sdk-trace-base": "^2.1.0",
19812
20221
  "@types/body-parser": "^1.19.6",
19813
20222
  "@types/bun": "latest",
19814
20223
  "@types/connect": "^3.4.38",
@@ -19818,6 +20227,8 @@ var init_package = __esm(() => {
19818
20227
  "@vercel/otel": "^2.0.1",
19819
20228
  "@vitest/ui": "^3.2.4",
19820
20229
  "bun-types": "latest",
20230
+ chalk: "^5.3.0",
20231
+ commander: "^12.1.0",
19821
20232
  eslint: "^9.16.0",
19822
20233
  globals: "^15.14.0",
19823
20234
  next: "^15.5.3",
@@ -19839,6 +20250,8 @@ var init_package = __esm(() => {
19839
20250
  });
19840
20251
 
19841
20252
  // src/core.ts
20253
+ import path from "path";
20254
+ import fs from "fs/promises";
19842
20255
  function isResolveError(result) {
19843
20256
  return result != null && "success" in result && result.success === false;
19844
20257
  }
@@ -19863,10 +20276,25 @@ function createExtractError(code, message, details) {
19863
20276
  }
19864
20277
  };
19865
20278
  }
20279
+ async function getProjectName(defaultName = "app") {
20280
+ if (typeof process === "undefined" || !process.cwd) {
20281
+ return defaultName;
20282
+ }
20283
+ const rootDir = process.cwd();
20284
+ const packageJsonPath = path.join(rootDir, "package.json");
20285
+ try {
20286
+ const packageJson = await fs.readFile(packageJsonPath, "utf8");
20287
+ const { name: name2 } = JSON.parse(packageJson);
20288
+ return name2 || defaultName;
20289
+ } catch {
20290
+ return defaultName;
20291
+ }
20292
+ }
20293
+ var init_core = () => {};
19866
20294
 
19867
20295
  // src/resolution/module-resolver.ts
19868
20296
  import ts from "typescript";
19869
- import path from "node:path";
20297
+ import path2 from "node:path";
19870
20298
  function loadTsConfig(prefix) {
19871
20299
  const projectPath = prefix || process.cwd();
19872
20300
  const configPath = ts.findConfigFile(projectPath, ts.sys.fileExists, "tsconfig.json");
@@ -19886,7 +20314,7 @@ function loadTsConfig(prefix) {
19886
20314
  if (configPath) {
19887
20315
  const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
19888
20316
  if (configFile.config) {
19889
- const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
20317
+ const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path2.dirname(configPath));
19890
20318
  compilerOptions = { ...compilerOptions, ...parsedConfig.options };
19891
20319
  rootNames = parsedConfig.fileNames;
19892
20320
  }
@@ -19898,7 +20326,7 @@ function loadTsConfig(prefix) {
19898
20326
  }
19899
20327
  function resolveModule(moduleName, compilerOptions) {
19900
20328
  if (moduleName.startsWith("./") || moduleName.startsWith("../") || moduleName.includes(".") && !moduleName.includes("/")) {
19901
- const absolutePath = path.resolve(moduleName);
20329
+ const absolutePath = path2.resolve(moduleName);
19902
20330
  if (ts.sys.fileExists(absolutePath)) {
19903
20331
  const dedicatedProgram = ts.createProgram([absolutePath], compilerOptions);
19904
20332
  const sourceFile = dedicatedProgram.getSourceFile(absolutePath);
@@ -19907,7 +20335,7 @@ function resolveModule(moduleName, compilerOptions) {
19907
20335
  }
19908
20336
  }
19909
20337
  }
19910
- const moduleResolver = ts.resolveModuleName(moduleName, path.resolve("./index.ts"), compilerOptions, ts.sys);
20338
+ const moduleResolver = ts.resolveModuleName(moduleName, path2.resolve("./index.ts"), compilerOptions, ts.sys);
19911
20339
  if (moduleResolver.resolvedModule) {
19912
20340
  const { resolvedFileName } = moduleResolver.resolvedModule;
19913
20341
  const dedicatedProgram = ts.createProgram([resolvedFileName], compilerOptions);
@@ -19967,11 +20395,13 @@ function resolveNodeBuiltin(moduleName, compilerOptions) {
19967
20395
  }
19968
20396
  return resolveError(moduleName, process.cwd());
19969
20397
  }
19970
- var init_module_resolver = () => {};
20398
+ var init_module_resolver = __esm(() => {
20399
+ init_core();
20400
+ });
19971
20401
 
19972
20402
  // src/resolution/utils.ts
19973
20403
  import ts2 from "typescript";
19974
- import path2 from "node:path";
20404
+ import path3 from "node:path";
19975
20405
  function getLocation(symbol) {
19976
20406
  if (symbol.valueDeclaration) {
19977
20407
  const sourceFile = symbol.valueDeclaration.getSourceFile();
@@ -19979,7 +20409,7 @@ function getLocation(symbol) {
19979
20409
  let { fileName } = sourceFile;
19980
20410
  const cwd = process.cwd();
19981
20411
  if (fileName.startsWith(cwd)) {
19982
- fileName = path2.relative(cwd, fileName);
20412
+ fileName = path3.relative(cwd, fileName);
19983
20413
  }
19984
20414
  return `${fileName}:${line + 1}:${character + 1}`;
19985
20415
  }
@@ -19992,7 +20422,7 @@ function getLocation(symbol) {
19992
20422
  let fileName = sourceFile?.fileName;
19993
20423
  const cwd = process.cwd();
19994
20424
  if (fileName?.startsWith(cwd)) {
19995
- fileName = path2.relative(cwd, fileName);
20425
+ fileName = path3.relative(cwd, fileName);
19996
20426
  }
19997
20427
  return `${fileName}:${line + 1}:${character + 1}`;
19998
20428
  }
@@ -20339,13 +20769,14 @@ function getSymbolInfo(checker, symbol, member, isStatic) {
20339
20769
  };
20340
20770
  }
20341
20771
  var init_symbol_finder = __esm(() => {
20772
+ init_core();
20342
20773
  init_utils();
20343
20774
  init_formatters();
20344
20775
  });
20345
20776
 
20346
20777
  // src/resolution/index.ts
20347
20778
  import ts5 from "typescript";
20348
- import path3 from "node:path";
20779
+ import path4 from "node:path";
20349
20780
  function parseModulePath(modulePath) {
20350
20781
  let module;
20351
20782
  let symbolPath;
@@ -20550,12 +20981,12 @@ async function getSourceLocation(reference) {
20550
20981
  }
20551
20982
  const moduleName = reference;
20552
20983
  if (moduleName.startsWith("./") || moduleName.startsWith("../")) {
20553
- const absolutePath = path3.resolve(moduleName);
20984
+ const absolutePath = path4.resolve(moduleName);
20554
20985
  if (ts5.sys.fileExists(absolutePath)) {
20555
20986
  const cwd = process.cwd();
20556
20987
  let finalPath;
20557
20988
  if (absolutePath.startsWith(cwd)) {
20558
- const relativePath = path3.relative(cwd, absolutePath);
20989
+ const relativePath = path4.relative(cwd, absolutePath);
20559
20990
  finalPath = relativePath.startsWith("..") ? absolutePath : relativePath;
20560
20991
  } else {
20561
20992
  finalPath = absolutePath;
@@ -20564,13 +20995,13 @@ async function getSourceLocation(reference) {
20564
20995
  }
20565
20996
  }
20566
20997
  const config = loadTsConfig(options.prefix);
20567
- const moduleResolver = ts5.resolveModuleName(moduleName, path3.resolve("./index.ts"), config.options, ts5.sys);
20998
+ const moduleResolver = ts5.resolveModuleName(moduleName, path4.resolve("./index.ts"), config.options, ts5.sys);
20568
20999
  if (moduleResolver.resolvedModule) {
20569
21000
  const { resolvedFileName } = moduleResolver.resolvedModule;
20570
21001
  const cwd = process.cwd();
20571
21002
  let finalPath;
20572
21003
  if (resolvedFileName.startsWith(cwd)) {
20573
- const relativePath = path3.relative(cwd, resolvedFileName);
21004
+ const relativePath = path4.relative(cwd, resolvedFileName);
20574
21005
  finalPath = relativePath.startsWith("..") ? resolvedFileName : relativePath;
20575
21006
  } else {
20576
21007
  finalPath = resolvedFileName;
@@ -20580,6 +21011,7 @@ async function getSourceLocation(reference) {
20580
21011
  return resolveError(moduleName, process.cwd());
20581
21012
  }
20582
21013
  var init_resolution = __esm(() => {
21014
+ init_core();
20583
21015
  init_module_resolver();
20584
21016
  init_symbol_finder();
20585
21017
  init_formatters();
@@ -20807,9 +21239,9 @@ async function handleGetSourcePath({ reference }) {
20807
21239
  isError: true
20808
21240
  };
20809
21241
  }
20810
- const { path: path4, format } = sourceResult;
21242
+ const { path: path5, format } = sourceResult;
20811
21243
  return {
20812
- content: [{ type: "text", text: `${path4}(${format})` }],
21244
+ content: [{ type: "text", text: `${path5}(${format})` }],
20813
21245
  isError: false
20814
21246
  };
20815
21247
  }
@@ -20869,6 +21301,7 @@ var init_mcp2 = __esm(() => {
20869
21301
  init_mcp();
20870
21302
  init_tools();
20871
21303
  init_package();
21304
+ init_core();
20872
21305
  init_src();
20873
21306
  init_circular_buffer();
20874
21307
  ({
@@ -21025,8 +21458,93 @@ var init_shell = __esm(() => {
21025
21458
  init_http();
21026
21459
  });
21027
21460
 
21461
+ // src/http/handlers/html.ts
21462
+ function createHandleHtml(config) {
21463
+ return async function handleHtml(req, res, next) {
21464
+ const url = req.url || "/";
21465
+ const [pathname] = url.split("?");
21466
+ if (pathname !== "" && pathname !== "/" && pathname !== "/tidewave") {
21467
+ return next();
21468
+ }
21469
+ try {
21470
+ const clientUrl = config.clientUrl || "https://tidewave.ai";
21471
+ const tidewaveConfig = {
21472
+ project_name: config.projectName || "app",
21473
+ framework_type: config.framework || "unknown",
21474
+ tidewave_version: package_default.version,
21475
+ team: config.team || {}
21476
+ };
21477
+ res.statusCode = 200;
21478
+ res.setHeader("Content-Type", "text/html");
21479
+ res.end(`
21480
+ <html>
21481
+ <head>
21482
+ <meta charset="UTF-8" />
21483
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
21484
+ <meta name="tidewave:config" content="${escapeHtml(JSON.stringify(tidewaveConfig))}" />
21485
+ <script type="module" src="${clientUrl}/tc/tc.js"></script>
21486
+ </head>
21487
+ <body></body>
21488
+ </html>
21489
+ `);
21490
+ } catch (err) {
21491
+ console.error(`[Tidewave] Failed to serve HTML: ${err}`);
21492
+ if (!res.headersSent) {
21493
+ res.statusCode = 500;
21494
+ res.setHeader("Content-Type", "text/html");
21495
+ res.end("<html><body>Internal server error</body></html>");
21496
+ }
21497
+ next(err);
21498
+ }
21499
+ };
21500
+ }
21501
+ function escapeHtml(text) {
21502
+ const map2 = {
21503
+ "&": "&amp;",
21504
+ "<": "&lt;",
21505
+ ">": "&gt;",
21506
+ '"': "&quot;",
21507
+ "'": "&#039;"
21508
+ };
21509
+ return text.replace(/[&<>"']/g, (match) => map2[match]);
21510
+ }
21511
+ var init_html = __esm(() => {
21512
+ init_package();
21513
+ });
21514
+
21515
+ // src/http/handlers/config.ts
21516
+ function createHandleConfig(config) {
21517
+ return async function handleConfig(_req, res, next) {
21518
+ try {
21519
+ const tidewaveConfig = {
21520
+ project_name: config.projectName || "app",
21521
+ framework_type: config.framework || "unknown",
21522
+ tidewave_version: package_default.version,
21523
+ team: config.team || {}
21524
+ };
21525
+ res.statusCode = 200;
21526
+ res.setHeader("Content-Type", "application/json");
21527
+ res.end(JSON.stringify(tidewaveConfig));
21528
+ } catch (err) {
21529
+ console.error(`[Tidewave] Failed to serve config: ${err}`);
21530
+ if (!res.headersSent) {
21531
+ res.statusCode = 500;
21532
+ res.setHeader("Content-Type", "application/json");
21533
+ res.end(JSON.stringify({
21534
+ error: "Internal server error",
21535
+ message: err instanceof Error ? err.message : String(err)
21536
+ }));
21537
+ }
21538
+ next(err);
21539
+ }
21540
+ };
21541
+ }
21542
+ var init_config = __esm(() => {
21543
+ init_package();
21544
+ });
21545
+
21028
21546
  // node_modules/ms/index.js
21029
- var require_ms2 = __commonJS((exports, module) => {
21547
+ var require_ms3 = __commonJS((exports, module) => {
21030
21548
  var s = 1000;
21031
21549
  var m = s * 60;
21032
21550
  var h = m * 60;
@@ -21144,7 +21662,7 @@ var require_common = __commonJS((exports, module) => {
21144
21662
  createDebug.disable = disable;
21145
21663
  createDebug.enable = enable;
21146
21664
  createDebug.enabled = enabled;
21147
- createDebug.humanize = require_ms2();
21665
+ createDebug.humanize = require_ms3();
21148
21666
  createDebug.destroy = destroy;
21149
21667
  Object.keys(env).forEach((key) => {
21150
21668
  createDebug[key] = env[key];
@@ -21311,7 +21829,7 @@ var require_common = __commonJS((exports, module) => {
21311
21829
  });
21312
21830
 
21313
21831
  // node_modules/debug/src/browser.js
21314
- var require_browser2 = __commonJS((exports, module) => {
21832
+ var require_browser3 = __commonJS((exports, module) => {
21315
21833
  exports.formatArgs = formatArgs;
21316
21834
  exports.save = save;
21317
21835
  exports.load = load;
@@ -21580,7 +22098,7 @@ var require_supports_color = __commonJS((exports, module) => {
21580
22098
  });
21581
22099
 
21582
22100
  // node_modules/debug/src/node.js
21583
- var require_node2 = __commonJS((exports, module) => {
22101
+ var require_node3 = __commonJS((exports, module) => {
21584
22102
  var tty = __require("tty");
21585
22103
  var util3 = __require("util");
21586
22104
  exports.init = init;
@@ -21751,11 +22269,11 @@ var require_node2 = __commonJS((exports, module) => {
21751
22269
  });
21752
22270
 
21753
22271
  // node_modules/debug/src/index.js
21754
- var require_src2 = __commonJS((exports, module) => {
22272
+ var require_src3 = __commonJS((exports, module) => {
21755
22273
  if (typeof process === "undefined" || process.type === "renderer" || false || process.__nwjs) {
21756
- module.exports = require_browser2();
22274
+ module.exports = require_browser3();
21757
22275
  } else {
21758
- module.exports = require_node2();
22276
+ module.exports = require_node3();
21759
22277
  }
21760
22278
  });
21761
22279
 
@@ -31452,11 +31970,11 @@ var require_mime_types = __commonJS((exports) => {
31452
31970
  }
31453
31971
  return exts[0];
31454
31972
  }
31455
- function lookup(path4) {
31456
- if (!path4 || typeof path4 !== "string") {
31973
+ function lookup(path5) {
31974
+ if (!path5 || typeof path5 !== "string") {
31457
31975
  return false;
31458
31976
  }
31459
- var extension2 = extname("x." + path4).toLowerCase().slice(1);
31977
+ var extension2 = extname("x." + path5).toLowerCase().slice(1);
31460
31978
  if (!extension2) {
31461
31979
  return false;
31462
31980
  }
@@ -31717,7 +32235,7 @@ var require_json = __commonJS((exports, module) => {
31717
32235
  * MIT Licensed
31718
32236
  */
31719
32237
  var createError = require_http_errors();
31720
- var debug = require_src2()("body-parser:json");
32238
+ var debug = require_src3()("body-parser:json");
31721
32239
  var isFinished = require_on_finished2().isFinished;
31722
32240
  var read = require_read();
31723
32241
  var typeis = require_type_is();
@@ -31834,7 +32352,7 @@ var require_raw = __commonJS((exports, module) => {
31834
32352
  * Copyright(c) 2014-2015 Douglas Christopher Wilson
31835
32353
  * MIT Licensed
31836
32354
  */
31837
- var debug = require_src2()("body-parser:raw");
32355
+ var debug = require_src3()("body-parser:raw");
31838
32356
  var isFinished = require_on_finished2().isFinished;
31839
32357
  var read = require_read();
31840
32358
  var typeis = require_type_is();
@@ -31882,7 +32400,7 @@ var require_text = __commonJS((exports, module) => {
31882
32400
  * Copyright(c) 2014-2015 Douglas Christopher Wilson
31883
32401
  * MIT Licensed
31884
32402
  */
31885
- var debug = require_src2()("body-parser:text");
32403
+ var debug = require_src3()("body-parser:text");
31886
32404
  var isFinished = require_on_finished2().isFinished;
31887
32405
  var read = require_read();
31888
32406
  var typeis = require_type_is();
@@ -34112,7 +34630,7 @@ var require_urlencoded = __commonJS((exports, module) => {
34112
34630
  * MIT Licensed
34113
34631
  */
34114
34632
  var createError = require_http_errors();
34115
- var debug = require_src2()("body-parser:urlencoded");
34633
+ var debug = require_src3()("body-parser:urlencoded");
34116
34634
  var isFinished = require_on_finished2().isFinished;
34117
34635
  var read = require_read();
34118
34636
  var typeis = require_type_is();
@@ -34257,18 +34775,27 @@ var exports_http = {};
34257
34775
  __export(exports_http, {
34258
34776
  serve: () => serve,
34259
34777
  methodNotAllowed: () => methodNotAllowed,
34778
+ getHandlers: () => getHandlers,
34260
34779
  configureServer: () => configureServer,
34261
34780
  checkSecurity: () => checkSecurity,
34262
- HANDLERS: () => HANDLERS,
34263
34781
  ENDPOINT: () => ENDPOINT
34264
34782
  });
34265
34783
  import http from "node:http";
34784
+ function getHandlers(config) {
34785
+ return {
34786
+ "": createHandleHtml(config),
34787
+ config: createHandleConfig(config),
34788
+ mcp: handleMcp,
34789
+ shell: handleShell
34790
+ };
34791
+ }
34266
34792
  function configureServer(server = import_connect.default(), config = DEFAULT_OPTIONS) {
34267
34793
  const securityChecker = checkSecurity(config);
34268
34794
  server.use(`${ENDPOINT}`, securityChecker);
34269
34795
  server.use(`${ENDPOINT}`, import_body_parser.default.json());
34270
- for (const [path4, handler] of Object.entries(HANDLERS)) {
34271
- server.use(ENDPOINT + "/" + path4, handler);
34796
+ const handlers = getHandlers(config);
34797
+ for (const [path5, handler] of Object.entries(handlers)) {
34798
+ server.use(ENDPOINT + "/" + path5, handler);
34272
34799
  }
34273
34800
  return server;
34274
34801
  }
@@ -34290,11 +34817,13 @@ function methodNotAllowed(res) {
34290
34817
  res.end();
34291
34818
  return;
34292
34819
  }
34293
- var import_connect, import_body_parser, ENDPOINT = "/tidewave", DEFAULT_PORT = 5001, DEFAULT_OPTIONS, HANDLERS;
34820
+ var import_connect, import_body_parser, ENDPOINT = "/tidewave", DEFAULT_PORT = 5001, DEFAULT_OPTIONS;
34294
34821
  var init_http = __esm(() => {
34295
34822
  import_connect = __toESM(require_connect(), 1);
34296
34823
  init_mcp3();
34297
34824
  init_shell();
34825
+ init_html();
34826
+ init_config();
34298
34827
  import_body_parser = __toESM(require_body_parser(), 1);
34299
34828
  DEFAULT_OPTIONS = {
34300
34829
  allowRemoteAccess: false,
@@ -34302,10 +34831,6 @@ var init_http = __esm(() => {
34302
34831
  port: 5001,
34303
34832
  host: "localhost"
34304
34833
  };
34305
- HANDLERS = {
34306
- mcp: handleMcp,
34307
- shell: handleShell
34308
- };
34309
34834
  });
34310
34835
 
34311
34836
  // src/logger/tidewave-span-processor.ts
@@ -34327,8 +34852,8 @@ class TidewaveSpanProcessor {
34327
34852
  const httpUrl = span.attributes["http.url"];
34328
34853
  const httpTarget = span.attributes["http.target"];
34329
34854
  const httpStatusCode = span.attributes["http.status_code"];
34330
- const path4 = route || httpTarget || httpUrl || "unknown";
34331
- if (typeof path4 === "string" && path4.startsWith("/tidewave")) {
34855
+ const path5 = route || httpTarget || httpUrl || "unknown";
34856
+ if (typeof path5 === "string" && path5.startsWith("/tidewave")) {
34332
34857
  return;
34333
34858
  }
34334
34859
  const durationMs = this.calculateDuration(span);
@@ -34337,7 +34862,7 @@ class TidewaveSpanProcessor {
34337
34862
  if (spanType === "BaseServer.handleRequest") {
34338
34863
  const method = httpMethod || "UNKNOWN";
34339
34864
  const status = httpStatusCode || "unknown";
34340
- message = `${method} ${path4} ${status} ${durationMs.toFixed(2)}ms`;
34865
+ message = `${method} ${path5} ${status} ${durationMs.toFixed(2)}ms`;
34341
34866
  if (typeof httpStatusCode === "number") {
34342
34867
  if (httpStatusCode >= 500)
34343
34868
  severity = "ERROR";
@@ -34469,9 +34994,7 @@ var init_instrumentation = __esm(() => {
34469
34994
  // src/next-js/handler.ts
34470
34995
  init_http();
34471
34996
  var import_body_parser2 = __toESM(require_body_parser(), 1);
34472
- init_package();
34473
- import path4 from "path";
34474
- import fs from "fs/promises";
34997
+ init_core();
34475
34998
  var DEFAULT_CONFIG = {};
34476
34999
  function connectWrapper(fn) {
34477
35000
  return (req, res, next) => new Promise((resolve, reject) => {
@@ -34486,6 +35009,8 @@ async function tidewaveHandler(config = DEFAULT_CONFIG) {
34486
35009
  if (process.env["NEXT_RUNTIME"] !== "edge") {
34487
35010
  await Promise.resolve().then(() => (init_instrumentation(), exports_instrumentation));
34488
35011
  }
35012
+ config.framework = "nextjs";
35013
+ config.projectName = config.projectName || await getProjectName("next_app");
34489
35014
  return async function handler(req, res) {
34490
35015
  const origin = req.headers.host;
34491
35016
  const url = new URL(req.url ?? "", `http://${origin}`);
@@ -34503,70 +35028,14 @@ async function tidewaveHandler(config = DEFAULT_CONFIG) {
34503
35028
  const securityMiddleware = checkSecurity(config);
34504
35029
  await connectWrapper(securityMiddleware)(req, res, next);
34505
35030
  await connectWrapper(import_body_parser2.default.json())(req, res, next);
34506
- if (req.method === "GET" && endpoint === undefined) {
34507
- return await respondTidewaveHTML(res, config);
34508
- }
34509
- if (req.method === "GET" && endpoint === "config") {
34510
- return await respondTidewaveConfigJSON(res, config);
34511
- }
34512
- if (req.method !== "POST") {
34513
- return methodNotAllowed(res);
34514
- }
34515
- const { HANDLERS: HANDLERS2 } = await Promise.resolve().then(() => (init_http(), exports_http));
34516
- const handler = HANDLERS2[endpoint || ""];
35031
+ const { getHandlers: getHandlers2 } = await Promise.resolve().then(() => (init_http(), exports_http));
35032
+ const handlers = getHandlers2(config);
35033
+ const handler = handlers[endpoint || ""];
34517
35034
  if (handler)
34518
35035
  return await connectWrapper(handler)(req, res, next);
34519
35036
  return res.status(404).json({ message: `Route not found: ${req.method} ${req.url}` });
34520
35037
  };
34521
35038
  }
34522
- async function respondTidewaveHTML(res, config) {
34523
- const clientUrl = config.clientUrl || "https://tidewave.ai";
34524
- const tidewaveConfig = await tidewaveConfigJSON(config);
34525
- res.status(200).setHeader("Content-Type", "text/html").end(`
34526
- <html>
34527
- <head>
34528
- <meta charset="UTF-8" />
34529
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
34530
- <meta name="tidewave:config" content="${escapeHtml(JSON.stringify(tidewaveConfig))}" />
34531
- <script type="module" src="${clientUrl}/tc/tc.js"></script>
34532
- </head>
34533
- <body></body>
34534
- </html>
34535
- `);
34536
- }
34537
- async function respondTidewaveConfigJSON(res, config) {
34538
- const tidewaveConfig = await tidewaveConfigJSON(config);
34539
- res.status(200).json(tidewaveConfig);
34540
- }
34541
- async function tidewaveConfigJSON(config) {
34542
- return {
34543
- project_name: await getProjectName(),
34544
- framework_type: "nextjs",
34545
- tidewave_version: package_default.version,
34546
- team: config.team || {}
34547
- };
34548
- }
34549
- async function getProjectName() {
34550
- const rootDir = process.cwd();
34551
- const packageJsonPath = path4.join(rootDir, "package.json");
34552
- try {
34553
- const packageJson = await fs.readFile(packageJsonPath, "utf8");
34554
- const { name: name2 } = JSON.parse(packageJson);
34555
- return name2 || "next_app";
34556
- } catch {
34557
- return "next_app";
34558
- }
34559
- }
34560
- function escapeHtml(text) {
34561
- const map2 = {
34562
- "&": "&amp;",
34563
- "<": "&lt;",
34564
- ">": "&gt;",
34565
- '"': "&quot;",
34566
- "'": "&#039;"
34567
- };
34568
- return text.replace(/[&<>"']/g, (match) => map2[match]);
34569
- }
34570
35039
  export {
34571
35040
  tidewaveHandler
34572
35041
  };