@neat.is/core 0.7.7 → 0.7.8

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.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  routeSpanToProject,
3
3
  startDaemon
4
- } from "./chunk-YVZRBT4C.js";
4
+ } from "./chunk-OVRVDSUO.js";
5
5
  import {
6
6
  ProjectNameCollisionError,
7
7
  addProject,
@@ -37,7 +37,7 @@ import {
37
37
  thresholdForEdgeType,
38
38
  touchLastSeen,
39
39
  writeAtomically
40
- } from "./chunk-UI3AFJAF.js";
40
+ } from "./chunk-LN75Z624.js";
41
41
  import {
42
42
  startOtelGrpcReceiver
43
43
  } from "./chunk-4GCV46AP.js";
package/dist/neatd.cjs CHANGED
@@ -3008,6 +3008,7 @@ var ROUTER_METHODS = /* @__PURE__ */ new Set([
3008
3008
  "all"
3009
3009
  ]);
3010
3010
  var NEXT_APP_METHODS = /* @__PURE__ */ new Set(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]);
3011
+ var NET_HTTP_METHODS = /* @__PURE__ */ new Set(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]);
3011
3012
  var JS_ROUTE_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx"]);
3012
3013
  function goRouterRoutesFromSource(source, parser, framework) {
3013
3014
  const tree = parseSource2(parser, source);
@@ -3061,6 +3062,101 @@ function echoRoutesFromSource(source, parser) {
3061
3062
  function fiberRoutesFromSource(source, parser) {
3062
3063
  return goRouterRoutesFromSource(source, parser, "fiber");
3063
3064
  }
3065
+ function chiRoutesFromSource(source, parser) {
3066
+ const tree = parseSource2(parser, source);
3067
+ const out = [];
3068
+ chiWalk(tree.rootNode, "", out);
3069
+ return out;
3070
+ }
3071
+ function stripChiRegex(path70) {
3072
+ return path70.replace(/\{([^{}:]+):[^{}]*\}/g, "{$1}");
3073
+ }
3074
+ function chiWalk(node, prefix, out) {
3075
+ for (let i = 0; i < node.namedChildCount; i++) {
3076
+ const child = node.namedChild(i);
3077
+ if (child) chiHandle(child, prefix, out);
3078
+ }
3079
+ }
3080
+ function chiHandle(node, prefix, out) {
3081
+ if (node.type === "call_expression") {
3082
+ const fn = node.childForFieldName("function");
3083
+ if (fn?.type === "selector_expression") {
3084
+ const field = fn.childForFieldName("field")?.text;
3085
+ const args = node.childForFieldName("arguments");
3086
+ if (field === "Route") {
3087
+ const leaf = goStringLiteral(args?.namedChild(0));
3088
+ const closure = args?.namedChild(1);
3089
+ if (leaf !== null && closure?.type === "func_literal") {
3090
+ const body = closure.childForFieldName("body");
3091
+ if (body) chiWalk(body, prefix + leaf, out);
3092
+ }
3093
+ return;
3094
+ }
3095
+ if (field === "Group") {
3096
+ const closure = args?.namedChild(0);
3097
+ if (closure?.type === "func_literal") {
3098
+ const body = closure.childForFieldName("body");
3099
+ if (body) chiWalk(body, prefix, out);
3100
+ }
3101
+ return;
3102
+ }
3103
+ if (field === "Mount") {
3104
+ return;
3105
+ }
3106
+ if (field && ROUTER_METHODS.has(field.toLowerCase())) {
3107
+ const leaf = goStringLiteral(args?.namedChild(0));
3108
+ if (leaf !== null) {
3109
+ out.push({
3110
+ method: field.toUpperCase(),
3111
+ pathTemplate: canonicalizeTemplate(stripChiRegex(prefix + leaf)),
3112
+ line: node.startPosition.row + 1,
3113
+ framework: "chi"
3114
+ });
3115
+ }
3116
+ return;
3117
+ }
3118
+ }
3119
+ }
3120
+ chiWalk(node, prefix, out);
3121
+ }
3122
+ function netHttpRoutesFromSource(source, parser) {
3123
+ const tree = parseSource2(parser, source);
3124
+ if (!goImportsNetHttp(tree.rootNode)) return [];
3125
+ const out = [];
3126
+ walk(tree.rootNode, (node) => {
3127
+ if (node.type !== "call_expression") return;
3128
+ const fn = node.childForFieldName("function");
3129
+ if (fn?.type !== "selector_expression") return;
3130
+ const field = fn.childForFieldName("field")?.text;
3131
+ if (field !== "HandleFunc" && field !== "Handle") return;
3132
+ const leaf = goStringLiteral(node.childForFieldName("arguments")?.namedChild(0));
3133
+ if (leaf === null) return;
3134
+ const sp = leaf.indexOf(" ");
3135
+ if (sp < 0) return;
3136
+ const method = leaf.slice(0, sp);
3137
+ const rest = leaf.slice(sp + 1);
3138
+ if (!NET_HTTP_METHODS.has(method)) return;
3139
+ if (!rest.startsWith("/")) return;
3140
+ out.push({
3141
+ method,
3142
+ pathTemplate: canonicalizeTemplate(rest),
3143
+ line: node.startPosition.row + 1,
3144
+ framework: "net/http"
3145
+ });
3146
+ });
3147
+ return out;
3148
+ }
3149
+ function goImportsNetHttp(root) {
3150
+ let found = false;
3151
+ walk(root, (node) => {
3152
+ if (found || node.type !== "import_spec") return;
3153
+ for (let i = 0; i < node.namedChildCount; i++) {
3154
+ const child = node.namedChild(i);
3155
+ if (goStringLiteral(child) === "net/http") found = true;
3156
+ }
3157
+ });
3158
+ return found;
3159
+ }
3064
3160
  var FASTAPI_METHODS = /* @__PURE__ */ new Set(["get", "post", "put", "patch", "delete", "options", "head", "trace"]);
3065
3161
  var NESTJS_METHODS = /* @__PURE__ */ new Map([
3066
3162
  ["Get", "GET"],
@@ -4326,9 +4422,11 @@ async function addRoutes(graph, services) {
4326
4422
  const hasGin = deps["github.com/gin-gonic/gin"] !== void 0;
4327
4423
  const hasEcho = deps["github.com/labstack/echo/v4"] !== void 0 || deps["github.com/labstack/echo"] !== void 0;
4328
4424
  const hasFiber = deps["github.com/gofiber/fiber/v2"] !== void 0 || deps["github.com/gofiber/fiber/v3"] !== void 0;
4425
+ const hasChi = deps["github.com/go-chi/chi/v5"] !== void 0 || deps["github.com/go-chi/chi"] !== void 0;
4426
+ const isGoService = service.node.language === "go";
4329
4427
  const hasRails = deps["rails"] !== void 0;
4330
4428
  const hasLaravel = deps["laravel/framework"] !== void 0;
4331
- if (!hasExpress && !hasFastify && !hasHono && !hasNext && !hasNestjs && !hasFastapi && !hasFlask && !hasDjango && !hasGin && !hasEcho && !hasFiber && !hasRails && !hasLaravel)
4429
+ if (!hasExpress && !hasFastify && !hasHono && !hasNext && !hasNestjs && !hasFastapi && !hasFlask && !hasDjango && !hasGin && !hasEcho && !hasFiber && !hasChi && !isGoService && !hasRails && !hasLaravel)
4332
4430
  continue;
4333
4431
  const files = await loadSourceFiles(service.dir);
4334
4432
  const mountPrefixes = hasExpress ? await expressMountPrefixes(files, service.dir, await loadTsPathConfig(service.dir)) : /* @__PURE__ */ new Map();
@@ -4355,7 +4453,9 @@ async function addRoutes(graph, services) {
4355
4453
  if (hasGin) routes = ginRoutesFromSource(file.content, goParser);
4356
4454
  else if (hasEcho) routes = echoRoutesFromSource(file.content, goParser);
4357
4455
  else if (hasFiber) routes = fiberRoutesFromSource(file.content, goParser);
4456
+ else if (hasChi) routes = chiRoutesFromSource(file.content, goParser);
4358
4457
  else routes = [];
4458
+ routes = routes.concat(netHttpRoutesFromSource(file.content, goParser));
4359
4459
  } else if (isPy) {
4360
4460
  routes = hasFastapi || hasFlask ? pythonRoutesFromSource(file.content, pyParser, hasFastapi ? "fastapi" : "flask") : [];
4361
4461
  if (hasDjango) routes = routes.concat(djangoRoutesFromSource(file.content, pyParser));
@@ -5966,6 +6066,7 @@ function goFramework(deps) {
5966
6066
  if (deps["github.com/gin-gonic/gin"]) return "gin";
5967
6067
  if (deps["github.com/labstack/echo/v4"] || deps["github.com/labstack/echo"]) return "echo";
5968
6068
  if (deps["github.com/gofiber/fiber/v2"] || deps["github.com/gofiber/fiber/v3"]) return "fiber";
6069
+ if (deps["github.com/go-chi/chi/v5"] || deps["github.com/go-chi/chi"]) return "chi";
5969
6070
  return void 0;
5970
6071
  }
5971
6072
  async function discoverGoService(scanPath, dir) {