@jsenv/plugin-supervisor 1.4.0 → 1.4.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.
@@ -6,7 +6,7 @@
6
6
  import { createRequire } from "node:module";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { getOriginalPosition } from "@jsenv/sourcemap";
9
- import { stringifyUrlSite } from "@jsenv/urls";
9
+ import { inspectFileContent } from "@jsenv/inspect";
10
10
 
11
11
  import {
12
12
  supervisorFileUrl,
@@ -24,10 +24,10 @@ export const jsenvPluginSupervisor = ({
24
24
  name: "jsenv:supervisor",
25
25
  appliesDuring: "dev",
26
26
  serve: async (serveInfo) => {
27
- if (serveInfo.request.pathname.startsWith("/__get_code_frame__/")) {
27
+ if (serveInfo.request.pathname.startsWith("/__get_cause_trace__/")) {
28
28
  const { pathname, searchParams } = new URL(serveInfo.request.url);
29
29
  let urlWithLineAndColumn = pathname.slice(
30
- "/__get_code_frame__/".length,
30
+ "/__get_cause_trace__/".length,
31
31
  );
32
32
  urlWithLineAndColumn = decodeURIComponent(urlWithLineAndColumn);
33
33
  const match = urlWithLineAndColumn.match(/:([0-9]+):([0-9]+)$/);
@@ -67,20 +67,26 @@ export const jsenvPluginSupervisor = ({
67
67
  }
68
68
  }
69
69
  }
70
- const codeFrame = stringifyUrlSite({
70
+ const causeTrace = {
71
71
  url: file,
72
72
  line,
73
73
  column,
74
- content: urlInfo.originalContent,
75
- });
74
+ codeFrame: inspectFileContent({
75
+ line,
76
+ column,
77
+ content: urlInfo.originalContent,
78
+ }),
79
+ };
80
+ const causeTraceJson = JSON.stringify(causeTrace, null, " ");
81
+
76
82
  return {
77
83
  status: 200,
78
84
  headers: {
79
85
  "cache-control": "no-store",
80
- "content-type": "text/plain",
81
- "content-length": Buffer.byteLength(codeFrame),
86
+ "content-type": "application/json",
87
+ "content-length": Buffer.byteLength(causeTraceJson),
82
88
  },
83
- body: codeFrame,
89
+ body: causeTraceJson,
84
90
  };
85
91
  }
86
92
  if (serveInfo.request.pathname.startsWith("/__get_error_cause__/")) {
@@ -123,7 +129,7 @@ export const jsenvPluginSupervisor = ({
123
129
  stack: errorBaseUrl
124
130
  ? `stack mocked for snapshot`
125
131
  : causeInfo.stack,
126
- codeFrame: causeInfo.traceMessage,
132
+ trace: causeInfo.trace,
127
133
  }
128
134
  : null,
129
135
  null,