@jsenv/core 36.0.2 → 36.1.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/jsenv_core.js +149 -879
- package/package.json +4 -4
- package/src/build/build.js +29 -40
- package/src/dev/file_service.js +18 -3
- package/src/dev/start_dev_server.js +2 -0
- package/src/kitchen/kitchen.js +65 -12
- package/src/kitchen/url_graph/url_graph_report.js +9 -5
- package/src/kitchen/url_graph.js +0 -1
- package/src/plugins/plugin_controller.js +15 -7
- package/src/plugins/plugins.js +2 -1
- package/src/plugins/protocol_file/jsenv_plugin_protocol_file.js +44 -39
- package/src/plugins/protocol_http/jsenv_plugin_protocol_http.js +4 -3
- package/src/plugins/reference_analysis/jsenv_plugin_reference_analysis.js +0 -88
- package/dist/js/supervisor.js +0 -1175
- package/src/helpers/basic_fetch.js +0 -53
- package/src/helpers/ping_server.js +0 -30
- package/src/plugins/supervisor/client/supervisor.js +0 -1153
- package/src/plugins/supervisor/html_supervisor_injection.js +0 -281
- package/src/plugins/supervisor/js_supervisor_injection.js +0 -283
- package/src/plugins/supervisor/jsenv_plugin_supervisor.js +0 -218
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* This plugin provides a way for jsenv to know when js execution is done
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
import { getOriginalPosition } from "@jsenv/sourcemap";
|
|
7
|
-
import { stringifyUrlSite } from "@jsenv/urls";
|
|
8
|
-
|
|
9
|
-
import { injectSupervisorIntoHTML } from "./html_supervisor_injection.js";
|
|
10
|
-
import { requireFromJsenv } from "@jsenv/core/src/helpers/require_from_jsenv.js";
|
|
11
|
-
|
|
12
|
-
export const supervisorFileUrl = new URL(
|
|
13
|
-
"./client/supervisor.js",
|
|
14
|
-
import.meta.url,
|
|
15
|
-
).href;
|
|
16
|
-
|
|
17
|
-
export const jsenvPluginSupervisor = ({
|
|
18
|
-
logs = false,
|
|
19
|
-
measurePerf = false,
|
|
20
|
-
errorOverlay = true,
|
|
21
|
-
openInEditor = true,
|
|
22
|
-
errorBaseUrl,
|
|
23
|
-
}) => {
|
|
24
|
-
return {
|
|
25
|
-
name: "jsenv:supervisor",
|
|
26
|
-
appliesDuring: "dev",
|
|
27
|
-
serve: async (request, context) => {
|
|
28
|
-
if (request.pathname.startsWith("/__get_code_frame__/")) {
|
|
29
|
-
const { pathname, searchParams } = new URL(request.url);
|
|
30
|
-
let urlWithLineAndColumn = pathname.slice(
|
|
31
|
-
"/__get_code_frame__/".length,
|
|
32
|
-
);
|
|
33
|
-
urlWithLineAndColumn = decodeURIComponent(urlWithLineAndColumn);
|
|
34
|
-
const match = urlWithLineAndColumn.match(/:([0-9]+):([0-9]+)$/);
|
|
35
|
-
if (!match) {
|
|
36
|
-
return {
|
|
37
|
-
status: 400,
|
|
38
|
-
body: "Missing line and column in url",
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
const file = urlWithLineAndColumn.slice(0, match.index);
|
|
42
|
-
let line = parseInt(match[1]);
|
|
43
|
-
let column = parseInt(match[2]);
|
|
44
|
-
const urlInfo = context.urlGraph.getUrlInfo(file);
|
|
45
|
-
if (!urlInfo) {
|
|
46
|
-
return {
|
|
47
|
-
status: 204,
|
|
48
|
-
headers: {
|
|
49
|
-
"cache-control": "no-store",
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
const remap = searchParams.has("remap");
|
|
54
|
-
if (remap) {
|
|
55
|
-
const sourcemap = urlInfo.sourcemap;
|
|
56
|
-
if (sourcemap) {
|
|
57
|
-
const original = getOriginalPosition({
|
|
58
|
-
sourcemap,
|
|
59
|
-
url: file,
|
|
60
|
-
line,
|
|
61
|
-
column,
|
|
62
|
-
});
|
|
63
|
-
if (original.line !== null) {
|
|
64
|
-
line = original.line;
|
|
65
|
-
if (original.column !== null) {
|
|
66
|
-
column = original.column;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const codeFrame = stringifyUrlSite({
|
|
72
|
-
url: file,
|
|
73
|
-
line,
|
|
74
|
-
column,
|
|
75
|
-
content: urlInfo.originalContent,
|
|
76
|
-
});
|
|
77
|
-
return {
|
|
78
|
-
status: 200,
|
|
79
|
-
headers: {
|
|
80
|
-
"cache-control": "no-store",
|
|
81
|
-
"content-type": "text/plain",
|
|
82
|
-
"content-length": Buffer.byteLength(codeFrame),
|
|
83
|
-
},
|
|
84
|
-
body: codeFrame,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
if (request.pathname.startsWith("/__get_error_cause__/")) {
|
|
88
|
-
let file = request.pathname.slice("/__get_error_cause__/".length);
|
|
89
|
-
file = decodeURIComponent(file);
|
|
90
|
-
if (!file) {
|
|
91
|
-
return {
|
|
92
|
-
status: 400,
|
|
93
|
-
body: "Missing file in url",
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
const getErrorCauseInfo = () => {
|
|
97
|
-
const urlInfo = context.urlGraph.getUrlInfo(file);
|
|
98
|
-
if (!urlInfo) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
const { error } = urlInfo;
|
|
102
|
-
if (error) {
|
|
103
|
-
return error;
|
|
104
|
-
}
|
|
105
|
-
// search in direct dependencies (404 or 500)
|
|
106
|
-
const { dependencies } = urlInfo;
|
|
107
|
-
for (const dependencyUrl of dependencies) {
|
|
108
|
-
const dependencyUrlInfo =
|
|
109
|
-
context.urlGraph.getUrlInfo(dependencyUrl);
|
|
110
|
-
if (dependencyUrlInfo.error) {
|
|
111
|
-
return dependencyUrlInfo.error;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return null;
|
|
115
|
-
};
|
|
116
|
-
const causeInfo = getErrorCauseInfo();
|
|
117
|
-
const body = JSON.stringify(
|
|
118
|
-
causeInfo
|
|
119
|
-
? {
|
|
120
|
-
code: causeInfo.code,
|
|
121
|
-
message: causeInfo.message,
|
|
122
|
-
reason: causeInfo.reason,
|
|
123
|
-
stack: errorBaseUrl
|
|
124
|
-
? `stack mocked for snapshot`
|
|
125
|
-
: causeInfo.stack,
|
|
126
|
-
codeFrame: causeInfo.traceMessage,
|
|
127
|
-
}
|
|
128
|
-
: null,
|
|
129
|
-
null,
|
|
130
|
-
" ",
|
|
131
|
-
);
|
|
132
|
-
return {
|
|
133
|
-
status: 200,
|
|
134
|
-
headers: {
|
|
135
|
-
"cache-control": "no-store",
|
|
136
|
-
"content-type": "application/json",
|
|
137
|
-
"content-length": Buffer.byteLength(body),
|
|
138
|
-
},
|
|
139
|
-
body,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
if (request.pathname.startsWith("/__open_in_editor__/")) {
|
|
143
|
-
let file = request.pathname.slice("/__open_in_editor__/".length);
|
|
144
|
-
file = decodeURIComponent(file);
|
|
145
|
-
if (!file) {
|
|
146
|
-
return {
|
|
147
|
-
status: 400,
|
|
148
|
-
body: "Missing file in url",
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
const launch = requireFromJsenv("launch-editor");
|
|
152
|
-
launch(fileURLToPath(file), () => {
|
|
153
|
-
// ignore error for now
|
|
154
|
-
});
|
|
155
|
-
return {
|
|
156
|
-
status: 200,
|
|
157
|
-
headers: {
|
|
158
|
-
"cache-control": "no-store",
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
return null;
|
|
163
|
-
},
|
|
164
|
-
transformUrlContent: {
|
|
165
|
-
html: ({ url, content }, context) => {
|
|
166
|
-
const [supervisorFileReference] = context.referenceUtils.inject({
|
|
167
|
-
type: "script",
|
|
168
|
-
expectedType: "js_classic",
|
|
169
|
-
specifier: supervisorFileUrl,
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
return injectSupervisorIntoHTML(
|
|
173
|
-
{
|
|
174
|
-
content,
|
|
175
|
-
url,
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
supervisorScriptSrc: supervisorFileReference.generatedSpecifier,
|
|
179
|
-
supervisorOptions: {
|
|
180
|
-
errorBaseUrl,
|
|
181
|
-
logs,
|
|
182
|
-
measurePerf,
|
|
183
|
-
errorOverlay,
|
|
184
|
-
openInEditor,
|
|
185
|
-
},
|
|
186
|
-
webServer: {
|
|
187
|
-
rootDirectoryUrl: context.rootDirectoryUrl,
|
|
188
|
-
isJsenvDevServer: true,
|
|
189
|
-
},
|
|
190
|
-
inlineAsRemote: true,
|
|
191
|
-
generateInlineScriptSrc: ({
|
|
192
|
-
type,
|
|
193
|
-
textContent,
|
|
194
|
-
inlineScriptUrl,
|
|
195
|
-
isOriginal,
|
|
196
|
-
line,
|
|
197
|
-
column,
|
|
198
|
-
}) => {
|
|
199
|
-
const [inlineScriptReference] =
|
|
200
|
-
context.referenceUtils.foundInline({
|
|
201
|
-
type: "script",
|
|
202
|
-
subtype: "inline",
|
|
203
|
-
expectedType: type,
|
|
204
|
-
isOriginalPosition: isOriginal,
|
|
205
|
-
specifierLine: line - 1,
|
|
206
|
-
specifierColumn: column,
|
|
207
|
-
specifier: inlineScriptUrl,
|
|
208
|
-
contentType: "text/javascript",
|
|
209
|
-
content: textContent,
|
|
210
|
-
});
|
|
211
|
-
return inlineScriptReference.generatedSpecifier;
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
|
-
);
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
};
|
|
218
|
-
};
|