@timber-js/app 0.2.0-alpha.86 → 0.2.0-alpha.87

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
@@ -361,6 +361,35 @@ function formatRscDebugContext(components) {
361
361
  return lines.join("\n");
362
362
  }
363
363
  /**
364
+ * Dynamically compute the line offset that Vite's module runner adds
365
+ * when wrapping modules in an async function.
366
+ *
367
+ * Vite's `calculateOffsetOnce()` uses the same technique: create a new
368
+ * AsyncFunction, throw from line 1, and check where the engine reports
369
+ * the error. The difference between the reported line and 1 is the offset.
370
+ *
371
+ * This is engine-dependent (currently 2 on Node 18-22) and could change
372
+ * in future Node.js or V8 versions. Computing it at runtime ensures we
373
+ * always match the actual behavior.
374
+ */
375
+ var _cachedOffset = null;
376
+ function calculateModuleRunnerOffset() {
377
+ if (_cachedOffset !== null) return _cachedOffset;
378
+ try {
379
+ const AsyncFunction = async function() {}.constructor;
380
+ const src = new AsyncFunction("BODY").toString();
381
+ const bodyIndex = src.indexOf("BODY");
382
+ if (bodyIndex === -1) {
383
+ _cachedOffset = 2;
384
+ return _cachedOffset;
385
+ }
386
+ _cachedOffset = (src.slice(0, bodyIndex).match(/\n/g) || []).length;
387
+ } catch {
388
+ _cachedOffset = 2;
389
+ }
390
+ return _cachedOffset;
391
+ }
392
+ /**
364
393
  * Phases where the error originated in the RSC environment.
365
394
  * These use `server.environments.rsc.moduleGraph` for source-mapping.
366
395
  */
@@ -420,7 +449,8 @@ function rewriteStacktrace(stack, moduleGraph) {
420
449
  if (!id) return input;
421
450
  const rawSourceMap = moduleGraph.getModuleById(id)?.transformResult?.map;
422
451
  if (!rawSourceMap) return input;
423
- const origLine = Number(lineStr) - 2;
452
+ const OFFSET = calculateModuleRunnerOffset();
453
+ const origLine = Number(lineStr) - OFFSET;
424
454
  const origCol = Number(colStr) - 1;
425
455
  if (origLine <= 0 || origCol < 0) return input;
426
456
  let pos;