@neat.is/core 0.3.5 → 0.3.6

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-KCEZSFU2.js";
4
+ } from "./chunk-YHQYHFI3.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-BUB3ASD5.js";
40
+ } from "./chunk-ZU2RQRCN.js";
41
41
  import {
42
42
  startOtelGrpcReceiver
43
43
  } from "./chunk-G3PDTGOW.js";
package/dist/neatd.cjs CHANGED
@@ -371,6 +371,7 @@ var init_otel = __esm({
371
371
  init_cjs_shims();
372
372
  var import_node_fs22 = require("fs");
373
373
  var import_node_path38 = __toESM(require("path"), 1);
374
+ var import_node_module = require("module");
374
375
 
375
376
  // src/daemon.ts
376
377
  init_cjs_shims();
@@ -1585,7 +1586,7 @@ function buildErrorEventForReceiver(span) {
1585
1586
  service: span.service,
1586
1587
  traceId: span.traceId,
1587
1588
  spanId: span.spanId,
1588
- errorMessage: span.exception?.message ?? span.name ?? "unknown error",
1589
+ errorMessage: span.exception?.message ?? "unknown error",
1589
1590
  ...span.exception?.type ? { exceptionType: span.exception.type } : {},
1590
1591
  ...span.exception?.stacktrace ? { exceptionStacktrace: span.exception.stacktrace } : {},
1591
1592
  ...Object.keys(attrs).length > 0 ? { attributes: attrs } : {},
@@ -1677,7 +1678,7 @@ async function handleSpan(ctx, span) {
1677
1678
  service: span.service,
1678
1679
  traceId: span.traceId,
1679
1680
  spanId: span.spanId,
1680
- errorMessage: span.exception?.message ?? span.name ?? "unknown error",
1681
+ errorMessage: span.exception?.message ?? "unknown error",
1681
1682
  ...span.exception?.type ? { exceptionType: span.exception.type } : {},
1682
1683
  ...span.exception?.stacktrace ? { exceptionStacktrace: span.exception.stacktrace } : {},
1683
1684
  ...Object.keys(attrs).length > 0 ? { attributes: attrs } : {},
@@ -5389,7 +5390,83 @@ async function spawnWebUI(restPort) {
5389
5390
  return { child, port, stop };
5390
5391
  }
5391
5392
 
5393
+ // src/version-skew.ts
5394
+ init_cjs_shims();
5395
+ var import_promises = require("timers/promises");
5396
+ var NPM_REGISTRY_URL = "https://registry.npmjs.org/neat.is/latest";
5397
+ var DEFAULT_TIMEOUT_MS = 2e3;
5398
+ async function fetchRegistryVersion(url, timeoutMs, fetchImpl) {
5399
+ const controller = new AbortController();
5400
+ let timedOut = false;
5401
+ const timer = (0, import_promises.setTimeout)(timeoutMs).then(() => {
5402
+ timedOut = true;
5403
+ controller.abort();
5404
+ });
5405
+ try {
5406
+ const res = await Promise.race([
5407
+ fetchImpl(url, { signal: controller.signal, headers: { accept: "application/json" } }),
5408
+ timer.then(() => null)
5409
+ ]);
5410
+ if (timedOut || !res) return null;
5411
+ if (!res.ok) return null;
5412
+ const body = await res.json();
5413
+ if (typeof body.version !== "string" || body.version.length === 0) return null;
5414
+ return body.version;
5415
+ } catch {
5416
+ return null;
5417
+ } finally {
5418
+ if (!timedOut) controller.abort();
5419
+ }
5420
+ }
5421
+ function isLocalBehind(local, remote) {
5422
+ if (local === remote) return false;
5423
+ const parse10 = (v) => {
5424
+ const core = v.split(/[-+]/)[0] ?? v;
5425
+ return core.split(".").map((s) => {
5426
+ const n = Number.parseInt(s, 10);
5427
+ return Number.isFinite(n) ? n : 0;
5428
+ });
5429
+ };
5430
+ const a = parse10(local);
5431
+ const b = parse10(remote);
5432
+ const len = Math.max(a.length, b.length);
5433
+ for (let i = 0; i < len; i++) {
5434
+ const av = a[i] ?? 0;
5435
+ const bv = b[i] ?? 0;
5436
+ if (av < bv) return true;
5437
+ if (av > bv) return false;
5438
+ }
5439
+ return false;
5440
+ }
5441
+ async function checkVersionSkew(opts) {
5442
+ const url = opts.registryUrl ?? NPM_REGISTRY_URL;
5443
+ const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
5444
+ const fetchImpl = opts.fetchImpl ?? fetch;
5445
+ const warn = opts.warn ?? ((m) => console.warn(m));
5446
+ const remote = await fetchRegistryVersion(url, timeoutMs, fetchImpl);
5447
+ if (!remote) return { remoteVersion: null, skewed: false, warned: false };
5448
+ if (!isLocalBehind(opts.localVersion, remote)) {
5449
+ return { remoteVersion: remote, skewed: false, warned: false };
5450
+ }
5451
+ warn(
5452
+ `[neatd] running neat.is@${opts.localVersion} but neat.is@${remote} is on npm \u2014 run \`npm install -g neat.is@latest\` to update`
5453
+ );
5454
+ return { remoteVersion: remote, skewed: true, warned: true };
5455
+ }
5456
+
5392
5457
  // src/neatd.ts
5458
+ function localVersion() {
5459
+ if (process.env.NEAT_LOCAL_VERSION && process.env.NEAT_LOCAL_VERSION.length > 0) {
5460
+ return process.env.NEAT_LOCAL_VERSION;
5461
+ }
5462
+ try {
5463
+ const req2 = (0, import_node_module.createRequire)(importMetaUrl);
5464
+ const pkg = req2("../package.json");
5465
+ return typeof pkg.version === "string" ? pkg.version : "0.0.0";
5466
+ } catch {
5467
+ return "0.0.0";
5468
+ }
5469
+ }
5393
5470
  function neatHome2() {
5394
5471
  if (process.env.NEAT_HOME && process.env.NEAT_HOME.length > 0) {
5395
5472
  return import_node_path38.default.resolve(process.env.NEAT_HOME);
@@ -5419,6 +5496,10 @@ async function cmdStart() {
5419
5496
  console.log(`neatd: registry at ${registryPath()}`);
5420
5497
  if (handle.restAddress) console.log(`neatd: REST \u2192 ${handle.restAddress}`);
5421
5498
  if (handle.otlpAddress) console.log(`neatd: OTLP \u2192 ${handle.otlpAddress}`);
5499
+ if (process.env.NEAT_DISABLE_VERSION_CHECK !== "1") {
5500
+ void checkVersionSkew({ localVersion: localVersion() }).catch(() => {
5501
+ });
5502
+ }
5422
5503
  const skipWeb = process.env.NEAT_WEB_DISABLED === "1";
5423
5504
  let web = null;
5424
5505
  if (!skipWeb) {