@jsenv/plugin-supervisor 1.3.9 → 1.4.1
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/js/supervisor.js +309 -256
- package/dist/jsenv_plugin_supervisor.js +137 -153
- package/package.json +4 -4
- package/src/client/supervisor.js +332 -263
- package/src/html_supervisor.js +14 -3
- package/src/js_supervisor.js +11 -10
- package/src/jsenv_plugin_supervisor.js +17 -10
package/src/html_supervisor.js
CHANGED
|
@@ -78,6 +78,7 @@ export const injectSupervisorIntoHTML = async (
|
|
|
78
78
|
generateInlineScriptSrc = ({ inlineScriptUrl }) =>
|
|
79
79
|
urlToRelativeUrl(inlineScriptUrl, webServer.rootDirectoryUrl),
|
|
80
80
|
inlineAsRemote,
|
|
81
|
+
sourcemaps = "inline",
|
|
81
82
|
},
|
|
82
83
|
) => {
|
|
83
84
|
const htmlAst = parseHtml({ html: content, url });
|
|
@@ -113,7 +114,10 @@ export const injectSupervisorIntoHTML = async (
|
|
|
113
114
|
});
|
|
114
115
|
if (inlineAsRemote) {
|
|
115
116
|
// prefere la version src
|
|
116
|
-
scriptInfos.push({
|
|
117
|
+
scriptInfos.push({
|
|
118
|
+
type,
|
|
119
|
+
src: inlineScriptSrc,
|
|
120
|
+
});
|
|
117
121
|
const remoteJsSupervised = generateCodeToSuperviseScriptWithSrc({
|
|
118
122
|
type,
|
|
119
123
|
src: inlineScriptSrc,
|
|
@@ -129,7 +133,11 @@ export const injectSupervisorIntoHTML = async (
|
|
|
129
133
|
});
|
|
130
134
|
});
|
|
131
135
|
} else {
|
|
132
|
-
scriptInfos.push({
|
|
136
|
+
scriptInfos.push({
|
|
137
|
+
type,
|
|
138
|
+
src: inlineScriptSrc,
|
|
139
|
+
isInline: true,
|
|
140
|
+
});
|
|
133
141
|
actions.push(async () => {
|
|
134
142
|
try {
|
|
135
143
|
const inlineJsSupervised = await injectSupervisorIntoJs({
|
|
@@ -138,6 +146,7 @@ export const injectSupervisorIntoHTML = async (
|
|
|
138
146
|
url: inlineScriptUrl,
|
|
139
147
|
type,
|
|
140
148
|
inlineSrc: inlineScriptSrc,
|
|
149
|
+
sourcemaps,
|
|
141
150
|
});
|
|
142
151
|
mutations.push(() => {
|
|
143
152
|
setHtmlNodeText(scriptNode, inlineJsSupervised, {
|
|
@@ -228,7 +237,9 @@ export const injectSupervisorIntoHTML = async (
|
|
|
228
237
|
htmlAst,
|
|
229
238
|
createHtmlNode({
|
|
230
239
|
tagName: "script",
|
|
231
|
-
textContent: `window.__supervisor__.setup({
|
|
240
|
+
textContent: `window.__supervisor__.setup({
|
|
241
|
+
${setupParamsSource}
|
|
242
|
+
});`,
|
|
232
243
|
}),
|
|
233
244
|
"jsenv:supervisor",
|
|
234
245
|
);
|
package/src/js_supervisor.js
CHANGED
|
@@ -36,16 +36,15 @@
|
|
|
36
36
|
* and create a variable named "undefined"
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
|
-
import { urlToRelativeUrl } from "@jsenv/urls";
|
|
40
39
|
import { applyBabelPlugins } from "@jsenv/ast";
|
|
41
40
|
import { SOURCEMAP, generateSourcemapDataUrl } from "@jsenv/sourcemap";
|
|
42
41
|
|
|
43
42
|
export const injectSupervisorIntoJs = async ({
|
|
44
|
-
webServer,
|
|
45
43
|
content,
|
|
46
44
|
url,
|
|
47
45
|
type,
|
|
48
46
|
inlineSrc,
|
|
47
|
+
sourcemaps,
|
|
49
48
|
}) => {
|
|
50
49
|
const babelPluginJsSupervisor =
|
|
51
50
|
type === "js_module"
|
|
@@ -58,15 +57,17 @@ export const injectSupervisorIntoJs = async ({
|
|
|
58
57
|
inputUrl: url,
|
|
59
58
|
});
|
|
60
59
|
let code = result.code;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
if (sourcemaps === "inline") {
|
|
61
|
+
const map = result.map;
|
|
62
|
+
const sourcemapDataUrl = generateSourcemapDataUrl(map);
|
|
63
|
+
code = SOURCEMAP.writeComment({
|
|
64
|
+
contentType: "text/javascript",
|
|
65
|
+
content: code,
|
|
66
|
+
specifier: sourcemapDataUrl,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
68
69
|
code = `${code}
|
|
69
|
-
//# sourceURL=${
|
|
70
|
+
//# sourceURL=${inlineSrc}`;
|
|
70
71
|
return code;
|
|
71
72
|
};
|
|
72
73
|
|
|
@@ -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 {
|
|
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("/
|
|
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
|
-
"/
|
|
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
|
|
70
|
+
const causeTrace = {
|
|
71
71
|
url: file,
|
|
72
72
|
line,
|
|
73
73
|
column,
|
|
74
|
-
|
|
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": "
|
|
81
|
-
"content-length": Buffer.byteLength(
|
|
86
|
+
"content-type": "application/json",
|
|
87
|
+
"content-length": Buffer.byteLength(causeTraceJson),
|
|
82
88
|
},
|
|
83
|
-
body:
|
|
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
|
-
|
|
132
|
+
trace: causeInfo.trace,
|
|
127
133
|
}
|
|
128
134
|
: null,
|
|
129
135
|
null,
|
|
@@ -216,6 +222,7 @@ export const jsenvPluginSupervisor = ({
|
|
|
216
222
|
});
|
|
217
223
|
return inlineScriptReference.generatedSpecifier;
|
|
218
224
|
},
|
|
225
|
+
sourcemaps: htmlUrlInfo.kitchen.context.sourcemaps,
|
|
219
226
|
},
|
|
220
227
|
);
|
|
221
228
|
},
|