@jsenv/core 27.4.0 → 27.5.0
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/autoreload.js +359 -0
- package/dist/js/execute_using_dynamic_import.js +1 -1
- package/dist/js/html_supervisor_installer.js +221 -73
- package/dist/js/html_supervisor_setup.js +3 -4
- package/dist/js/new_stylesheet.js +26 -58
- package/dist/js/server_events_client.js +307 -0
- package/dist/main.js +7483 -7281
- package/package.json +11 -10
- package/{README.md → readme.md} +8 -9
- package/src/build/build.js +12 -16
- package/src/build/start_build_server.js +24 -28
- package/src/dev/start_dev_server.js +30 -94
- package/src/execute/execute.js +17 -35
- package/src/omega/errors.js +20 -18
- package/src/omega/kitchen.js +7 -6
- package/src/omega/omega_server.js +96 -127
- package/src/omega/server/file_service.js +247 -46
- package/src/omega/url_graph.js +33 -20
- package/src/plugins/autoreload/client/autoreload.js +201 -0
- package/src/plugins/autoreload/{dev_sse/client → client}/autoreload_preference.js +0 -0
- package/src/plugins/autoreload/{dev_sse/client → client}/reload.js +29 -10
- package/src/plugins/autoreload/{dev_sse/client → client}/url_helpers.js +0 -0
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +4 -4
- package/src/plugins/autoreload/{dev_sse/jsenv_plugin_dev_sse_client.js → jsenv_plugin_autoreload_client.js} +8 -8
- package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +196 -0
- package/src/{dev/plugins → plugins}/explorer/client/explorer.html +0 -0
- package/src/{dev/plugins → plugins}/explorer/client/jsenv.png +0 -0
- package/src/{dev/plugins → plugins}/explorer/jsenv_plugin_explorer.js +1 -3
- package/src/plugins/html_supervisor/client/{error_in_document.js → error_overlay.js} +73 -17
- package/src/plugins/html_supervisor/client/html_supervisor_installer.js +127 -54
- package/src/plugins/html_supervisor/client/html_supervisor_setup.js +3 -4
- package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +19 -12
- package/src/plugins/inline/jsenv_plugin_html_inline_content.js +97 -117
- package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +66 -58
- package/src/plugins/plugin_controller.js +102 -67
- package/src/plugins/plugins.js +10 -8
- package/src/{helpers/event_source/event_source.js → plugins/server_events/client/event_source_connection.js} +102 -31
- package/src/plugins/server_events/client/server_events_client.js +17 -0
- package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +48 -0
- package/src/plugins/server_events/server_events_dispatcher.js +69 -0
- package/src/{dev/plugins → plugins}/toolbar/client/animation/toolbar_animation.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/eventsource/eventsource.css +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/eventsource/toolbar_eventsource.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/execution/execution.css +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/execution/toolbar_execution.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/focus/focus.css +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/focus/toolbar_focus.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/jsenv_logo.svg +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/notification/toolbar_notification.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/responsive/overflow_menu.css +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/responsive/toolbar_responsive.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/settings/settings.css +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/settings/toolbar_settings.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/theme/jsenv_theme.css +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/theme/light_theme.css +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/theme/toolbar_theme.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/toolbar.html +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/toolbar_injector.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/toolbar_main.css +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/toolbar_main.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/tooltip/tooltip.css +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/tooltip/tooltip.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/util/animation.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/util/dom.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/util/fetch_using_xhr.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/util/fetching.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/util/iframe_to_parent_href.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/util/jsenv_logger.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/util/preferences.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/util/responsive.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/util/util.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/client/variant/variant.js +0 -0
- package/src/{dev/plugins → plugins}/toolbar/jsenv_plugin_toolbar.js +0 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +4 -3
- package/src/plugins/transpilation/babel/new_stylesheet/client/new_stylesheet.js +25 -55
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +44 -24
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +6 -1
- package/src/plugins/url_analysis/html/html_urls.js +8 -8
- package/src/test/execute_plan.js +36 -54
- package/src/test/execute_test_plan.js +2 -2
- package/dist/js/event_source_client.js +0 -549
- package/src/helpers/event_source/sse_service.js +0 -53
- package/src/plugins/autoreload/dev_sse/client/event_source_client.js +0 -193
- package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js +0 -192
|
@@ -2,36 +2,72 @@ const JSENV_ERROR_OVERLAY_TAGNAME = "jsenv-error-overlay"
|
|
|
2
2
|
|
|
3
3
|
export const displayErrorInDocument = (
|
|
4
4
|
error,
|
|
5
|
-
{
|
|
5
|
+
{
|
|
6
|
+
rootDirectoryUrl,
|
|
7
|
+
openInEditor,
|
|
8
|
+
url,
|
|
9
|
+
line,
|
|
10
|
+
column,
|
|
11
|
+
reportedBy,
|
|
12
|
+
requestedRessource,
|
|
13
|
+
},
|
|
6
14
|
) => {
|
|
7
15
|
document.querySelectorAll(JSENV_ERROR_OVERLAY_TAGNAME).forEach((node) => {
|
|
8
16
|
node.parentNode.removeChild(node)
|
|
9
17
|
})
|
|
10
|
-
const { theme, title, message, stack } = errorToHTML(error, {
|
|
18
|
+
const { theme, title, message, stack, tip } = errorToHTML(error, {
|
|
11
19
|
url,
|
|
12
20
|
line,
|
|
13
21
|
column,
|
|
22
|
+
reportedBy,
|
|
23
|
+
requestedRessource,
|
|
14
24
|
})
|
|
15
|
-
|
|
25
|
+
let jsenvErrorOverlay = new JsenvErrorOverlay({
|
|
16
26
|
theme,
|
|
17
27
|
title,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
rootDirectoryUrl,
|
|
21
|
-
})}`
|
|
22
|
-
: replaceLinks(message, { rootDirectoryUrl }),
|
|
28
|
+
text: createErrorText({ rootDirectoryUrl, openInEditor, message, stack }),
|
|
29
|
+
tip,
|
|
23
30
|
})
|
|
24
31
|
document.body.appendChild(jsenvErrorOverlay)
|
|
32
|
+
const removeErrorOverlay = () => {
|
|
33
|
+
if (jsenvErrorOverlay && jsenvErrorOverlay.parentNode) {
|
|
34
|
+
document.body.removeChild(jsenvErrorOverlay)
|
|
35
|
+
jsenvErrorOverlay = null
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (window.__reloader__) {
|
|
39
|
+
window.__reloader__.onstatuschange = () => {
|
|
40
|
+
if (window.__reloader__.status === "reloading") {
|
|
41
|
+
removeErrorOverlay()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return removeErrorOverlay
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const createErrorText = ({
|
|
49
|
+
rootDirectoryUrl,
|
|
50
|
+
openInEditor,
|
|
51
|
+
message,
|
|
52
|
+
stack,
|
|
53
|
+
}) => {
|
|
54
|
+
if (message && stack) {
|
|
55
|
+
return `${replaceLinks(message, {
|
|
56
|
+
rootDirectoryUrl,
|
|
57
|
+
openInEditor,
|
|
58
|
+
})}\n${replaceLinks(stack, { rootDirectoryUrl, openInEditor })}`
|
|
59
|
+
}
|
|
60
|
+
if (stack) {
|
|
61
|
+
return replaceLinks(stack, { rootDirectoryUrl, openInEditor })
|
|
62
|
+
}
|
|
63
|
+
return replaceLinks(message, { rootDirectoryUrl, openInEditor })
|
|
25
64
|
}
|
|
26
65
|
|
|
27
66
|
class JsenvErrorOverlay extends HTMLElement {
|
|
28
|
-
constructor({ title,
|
|
67
|
+
constructor({ theme, title, text, tip }) {
|
|
29
68
|
super()
|
|
30
69
|
this.root = this.attachShadow({ mode: "open" })
|
|
31
70
|
this.root.innerHTML = overlayHtml
|
|
32
|
-
this.root.querySelector(".overlay").setAttribute("data-theme", theme)
|
|
33
|
-
this.root.querySelector(".title").innerHTML = title
|
|
34
|
-
this.root.querySelector(".stack").innerHTML = stack
|
|
35
71
|
this.root.querySelector(".backdrop").onclick = () => {
|
|
36
72
|
if (!this.parentNode) {
|
|
37
73
|
// not in document anymore
|
|
@@ -40,6 +76,10 @@ class JsenvErrorOverlay extends HTMLElement {
|
|
|
40
76
|
this.root.querySelector(".backdrop").onclick = null
|
|
41
77
|
this.parentNode.removeChild(this)
|
|
42
78
|
}
|
|
79
|
+
this.root.querySelector(".overlay").setAttribute("data-theme", theme)
|
|
80
|
+
this.root.querySelector(".title").innerHTML = title
|
|
81
|
+
this.root.querySelector(".text").innerHTML = text
|
|
82
|
+
this.root.querySelector(".tip").innerHTML = tip
|
|
43
83
|
}
|
|
44
84
|
}
|
|
45
85
|
|
|
@@ -127,8 +167,8 @@ pre a {
|
|
|
127
167
|
<div class="backdrop"></div>
|
|
128
168
|
<div class="overlay">
|
|
129
169
|
<h1 class="title"></h1>
|
|
130
|
-
<pre class="
|
|
131
|
-
<div class="tip"
|
|
170
|
+
<pre class="text"></pre>
|
|
171
|
+
<div class="tip"></div>
|
|
132
172
|
</div>
|
|
133
173
|
`
|
|
134
174
|
|
|
@@ -197,13 +237,17 @@ const getErrorStackWithoutErrorMessage = (error) => {
|
|
|
197
237
|
return stack
|
|
198
238
|
}
|
|
199
239
|
|
|
200
|
-
const errorToHTML = (
|
|
240
|
+
const errorToHTML = (
|
|
241
|
+
error,
|
|
242
|
+
{ url, line, column, reportedBy, requestedRessource },
|
|
243
|
+
) => {
|
|
201
244
|
let { message, stack } = parseErrorInfo(error)
|
|
202
245
|
if (url) {
|
|
203
246
|
if (!stack || (error && error.name === "SyntaxError")) {
|
|
204
247
|
stack = ` at ${appendLineAndColumn(url, { line, column })}`
|
|
205
248
|
}
|
|
206
249
|
}
|
|
250
|
+
let tip = formatTip({ reportedBy, requestedRessource })
|
|
207
251
|
return {
|
|
208
252
|
theme:
|
|
209
253
|
error && error.cause && error.cause.code === "PARSE_ERROR"
|
|
@@ -212,10 +256,20 @@ const errorToHTML = (error, { url, line, column }) => {
|
|
|
212
256
|
title: "An error occured",
|
|
213
257
|
message,
|
|
214
258
|
stack,
|
|
259
|
+
tip: `${tip}
|
|
260
|
+
<br />
|
|
261
|
+
Click outside to close.`,
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const formatTip = ({ reportedBy, requestedRessource }) => {
|
|
266
|
+
if (reportedBy === "browser") {
|
|
267
|
+
return `Reported by the browser while executing <code>${window.location.pathname}${window.location.search}</code>.`
|
|
215
268
|
}
|
|
269
|
+
return `Reported by the server while serving <code>${requestedRessource}</code>`
|
|
216
270
|
}
|
|
217
271
|
|
|
218
|
-
const replaceLinks = (string, { rootDirectoryUrl }) => {
|
|
272
|
+
const replaceLinks = (string, { rootDirectoryUrl, openInEditor }) => {
|
|
219
273
|
// normalize line breaks
|
|
220
274
|
string = string.replace(/\n/g, "\n")
|
|
221
275
|
string = escapeHtml(string)
|
|
@@ -240,7 +294,9 @@ const replaceLinks = (string, { rootDirectoryUrl }) => {
|
|
|
240
294
|
column,
|
|
241
295
|
})
|
|
242
296
|
return link({
|
|
243
|
-
href:
|
|
297
|
+
href: openInEditor
|
|
298
|
+
? `javascript:window.fetch('/__open_in_editor__/${fileUrl}')`
|
|
299
|
+
: fileUrl,
|
|
244
300
|
text: fileUrl,
|
|
245
301
|
})
|
|
246
302
|
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { unevalException } from "./uneval_exception.js"
|
|
2
|
-
import { displayErrorInDocument } from "./
|
|
2
|
+
import { displayErrorInDocument } from "./error_overlay.js"
|
|
3
3
|
import { displayErrorNotification } from "./error_in_notification.js"
|
|
4
4
|
|
|
5
5
|
const { __html_supervisor__ } = window
|
|
6
6
|
|
|
7
|
+
const supervisedScripts = []
|
|
8
|
+
|
|
7
9
|
export const installHtmlSupervisor = ({
|
|
10
|
+
rootDirectoryUrl,
|
|
8
11
|
logs,
|
|
9
12
|
measurePerf,
|
|
10
|
-
|
|
13
|
+
errorOverlay,
|
|
14
|
+
openInEditor,
|
|
11
15
|
}) => {
|
|
12
16
|
const errorTransformer = null // could implement error stack remapping if needed
|
|
13
17
|
const scriptExecutionResults = {}
|
|
@@ -36,11 +40,7 @@ export const installHtmlSupervisor = ({
|
|
|
36
40
|
}
|
|
37
41
|
const onExecutionError = (
|
|
38
42
|
executionResult,
|
|
39
|
-
{
|
|
40
|
-
currentScript,
|
|
41
|
-
errorExposureInNotification = false,
|
|
42
|
-
errorExposureInDocument = false,
|
|
43
|
-
},
|
|
43
|
+
{ currentScript, errorExposureInNotification = false },
|
|
44
44
|
) => {
|
|
45
45
|
const error = executionResult.error
|
|
46
46
|
if (error && error.code === "NETWORK_FAILURE") {
|
|
@@ -59,9 +59,6 @@ export const installHtmlSupervisor = ({
|
|
|
59
59
|
if (errorExposureInNotification) {
|
|
60
60
|
displayErrorNotification(error)
|
|
61
61
|
}
|
|
62
|
-
if (errorExposureInDocument) {
|
|
63
|
-
displayErrorInDocument(error, { rootDirectoryUrl })
|
|
64
|
-
}
|
|
65
62
|
executionResult.exceptionSource = unevalException(error)
|
|
66
63
|
delete executionResult.error
|
|
67
64
|
}
|
|
@@ -73,13 +70,16 @@ export const installHtmlSupervisor = ({
|
|
|
73
70
|
}
|
|
74
71
|
}
|
|
75
72
|
|
|
76
|
-
const performExecution = async (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
73
|
+
const performExecution = async (
|
|
74
|
+
{
|
|
75
|
+
src,
|
|
76
|
+
type,
|
|
77
|
+
currentScript,
|
|
78
|
+
execute,
|
|
79
|
+
// https://developer.mozilla.org/en-US/docs/web/html/element/script
|
|
80
|
+
},
|
|
81
|
+
{ reload = false } = {},
|
|
82
|
+
) => {
|
|
83
83
|
if (logs) {
|
|
84
84
|
console.group(`[jsenv] loading ${type} ${src}`)
|
|
85
85
|
}
|
|
@@ -88,7 +88,11 @@ export const installHtmlSupervisor = ({
|
|
|
88
88
|
let result
|
|
89
89
|
let error
|
|
90
90
|
try {
|
|
91
|
-
|
|
91
|
+
const urlObject = new URL(src, window.location)
|
|
92
|
+
if (reload) {
|
|
93
|
+
urlObject.searchParams.set("hmr", Date.now())
|
|
94
|
+
}
|
|
95
|
+
result = await execute(urlObject.href)
|
|
92
96
|
completed = true
|
|
93
97
|
} catch (e) {
|
|
94
98
|
completed = false
|
|
@@ -156,12 +160,19 @@ export const installHtmlSupervisor = ({
|
|
|
156
160
|
}),
|
|
157
161
|
)
|
|
158
162
|
__html_supervisor__.addScriptToExecute = async (scriptToExecute) => {
|
|
163
|
+
if (!supervisedScripts.includes(scriptToExecute)) {
|
|
164
|
+
supervisedScripts.push(scriptToExecute)
|
|
165
|
+
scriptToExecute.reload = () => {
|
|
166
|
+
return performExecution(scriptToExecute, { reload: true })
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
159
170
|
if (scriptToExecute.async) {
|
|
160
171
|
performExecution(scriptToExecute)
|
|
161
172
|
return
|
|
162
173
|
}
|
|
163
174
|
const useDeferQueue =
|
|
164
|
-
scriptToExecute.defer || scriptToExecute.type === "
|
|
175
|
+
scriptToExecute.defer || scriptToExecute.type === "module"
|
|
165
176
|
if (useDeferQueue) {
|
|
166
177
|
// defer must wait for classic script to be done
|
|
167
178
|
const classicExecutionPromise = classicExecutionQueue.getPromise()
|
|
@@ -207,51 +218,113 @@ export const installHtmlSupervisor = ({
|
|
|
207
218
|
__html_supervisor__.addScriptToExecute(scriptToExecute)
|
|
208
219
|
})
|
|
209
220
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
+
if (errorOverlay) {
|
|
222
|
+
window.addEventListener("error", (errorEvent) => {
|
|
223
|
+
if (!errorEvent.isTrusted) {
|
|
224
|
+
// ignore custom error event (not sent by browser)
|
|
225
|
+
return
|
|
226
|
+
}
|
|
227
|
+
const { error } = errorEvent
|
|
228
|
+
displayErrorInDocument(error, {
|
|
229
|
+
rootDirectoryUrl,
|
|
230
|
+
openInEditor,
|
|
231
|
+
url: errorEvent.filename,
|
|
232
|
+
line: errorEvent.lineno,
|
|
233
|
+
column: errorEvent.colno,
|
|
234
|
+
reportedBy: "browser",
|
|
235
|
+
})
|
|
221
236
|
})
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
{
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
237
|
+
if (window.__server_events__) {
|
|
238
|
+
const isExecuting = () => {
|
|
239
|
+
if (pendingExecutionCount > 0) {
|
|
240
|
+
return true
|
|
241
|
+
}
|
|
242
|
+
if (
|
|
243
|
+
document.readyState === "loading" ||
|
|
244
|
+
document.readyState === "interactive"
|
|
245
|
+
) {
|
|
246
|
+
return true
|
|
247
|
+
}
|
|
248
|
+
if (window.__reloader__ && window.__reloader__.status === "reloading") {
|
|
249
|
+
return true
|
|
250
|
+
}
|
|
251
|
+
return false
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
window.__server_events__.addEventCallbacks({
|
|
255
|
+
error_while_serving_file: (serverErrorEvent) => {
|
|
256
|
+
if (!isExecuting()) {
|
|
257
|
+
return
|
|
258
|
+
}
|
|
259
|
+
const {
|
|
260
|
+
message,
|
|
261
|
+
stack,
|
|
262
|
+
traceUrl,
|
|
263
|
+
traceLine,
|
|
264
|
+
traceColumn,
|
|
265
|
+
traceMessage,
|
|
266
|
+
requestedRessource,
|
|
267
|
+
isFaviconAutoRequest,
|
|
268
|
+
} = JSON.parse(serverErrorEvent.data)
|
|
269
|
+
if (isFaviconAutoRequest) {
|
|
270
|
+
return
|
|
271
|
+
}
|
|
272
|
+
// setTimeout is to ensure the error
|
|
273
|
+
// dispatched on window by browser is displayed first,
|
|
274
|
+
// then the server error replaces it (because it contains more information)
|
|
275
|
+
setTimeout(() => {
|
|
276
|
+
displayErrorInDocument(
|
|
277
|
+
{
|
|
278
|
+
message,
|
|
279
|
+
stack:
|
|
280
|
+
stack && traceMessage
|
|
281
|
+
? `${stack}\n\n${traceMessage}`
|
|
282
|
+
: stack
|
|
283
|
+
? stack
|
|
284
|
+
: traceMessage
|
|
285
|
+
? `\n${traceMessage}`
|
|
286
|
+
: "",
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
rootDirectoryUrl,
|
|
290
|
+
openInEditor,
|
|
291
|
+
url: traceUrl,
|
|
292
|
+
line: traceLine,
|
|
293
|
+
column: traceColumn,
|
|
294
|
+
reportedBy: "server",
|
|
295
|
+
requestedRessource,
|
|
296
|
+
},
|
|
297
|
+
)
|
|
298
|
+
}, 10)
|
|
238
299
|
},
|
|
239
|
-
)
|
|
300
|
+
})
|
|
240
301
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
__html_supervisor__.reloadSupervisedScript = ({ type, src }) => {
|
|
306
|
+
const supervisedScript = supervisedScripts.find(
|
|
307
|
+
(supervisedScriptCandidate) => {
|
|
308
|
+
if (type && supervisedScriptCandidate.type !== type) {
|
|
309
|
+
return false
|
|
310
|
+
}
|
|
311
|
+
if (supervisedScriptCandidate.src !== src) {
|
|
312
|
+
return false
|
|
313
|
+
}
|
|
314
|
+
return true
|
|
315
|
+
},
|
|
316
|
+
)
|
|
317
|
+
if (supervisedScript) {
|
|
318
|
+
supervisedScript.reload()
|
|
246
319
|
}
|
|
247
320
|
}
|
|
248
321
|
|
|
249
322
|
export const superviseScriptTypeModule = ({ src, isInline }) => {
|
|
250
323
|
__html_supervisor__.addScriptToExecute({
|
|
251
324
|
src,
|
|
252
|
-
type: "
|
|
325
|
+
type: "module",
|
|
253
326
|
isInline,
|
|
254
|
-
execute: () => import(
|
|
327
|
+
execute: (url) => import(url),
|
|
255
328
|
})
|
|
256
329
|
}
|
|
257
330
|
|
|
@@ -14,7 +14,7 @@ window.__html_supervisor__ = {
|
|
|
14
14
|
type: "js_classic",
|
|
15
15
|
isInline,
|
|
16
16
|
currentScript: document.currentScript,
|
|
17
|
-
execute: () => {
|
|
17
|
+
execute: (url) => {
|
|
18
18
|
return new Promise((resolve, reject) => {
|
|
19
19
|
const script = document.createElement("script")
|
|
20
20
|
if (crossorigin) {
|
|
@@ -23,8 +23,7 @@ window.__html_supervisor__ = {
|
|
|
23
23
|
if (integrity) {
|
|
24
24
|
script.integrity = integrity
|
|
25
25
|
}
|
|
26
|
-
script.src =
|
|
27
|
-
const scriptUrl = new URL(src, window.location).href
|
|
26
|
+
script.src = url
|
|
28
27
|
let lastWindowErrorUrl
|
|
29
28
|
let lastWindowError
|
|
30
29
|
const windowErrorCallback = (e) => {
|
|
@@ -45,7 +44,7 @@ window.__html_supervisor__ = {
|
|
|
45
44
|
})
|
|
46
45
|
script.addEventListener("load", () => {
|
|
47
46
|
cleanup()
|
|
48
|
-
if (lastWindowErrorUrl ===
|
|
47
|
+
if (lastWindowErrorUrl === url) {
|
|
49
48
|
reject(lastWindowError)
|
|
50
49
|
} else {
|
|
51
50
|
resolve()
|
|
@@ -26,6 +26,8 @@ import { requireFromJsenv } from "@jsenv/core/src/require_from_jsenv.js"
|
|
|
26
26
|
export const jsenvPluginHtmlSupervisor = ({
|
|
27
27
|
logs = false,
|
|
28
28
|
measurePerf = false,
|
|
29
|
+
errorOverlay = true,
|
|
30
|
+
openInEditor = true,
|
|
29
31
|
}) => {
|
|
30
32
|
const htmlSupervisorSetupFileUrl = new URL(
|
|
31
33
|
"./client/html_supervisor_setup.js?js_classic",
|
|
@@ -68,14 +70,14 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
68
70
|
const scriptsToSupervise = []
|
|
69
71
|
|
|
70
72
|
const handleInlineScript = (node, htmlNodeText) => {
|
|
71
|
-
const
|
|
73
|
+
const { type, extension } = analyzeScriptNode(node)
|
|
72
74
|
const { line, column, lineEnd, columnEnd, isOriginal } =
|
|
73
75
|
getHtmlNodePosition(node, {
|
|
74
76
|
preferOriginal: true,
|
|
75
77
|
})
|
|
76
78
|
let inlineScriptUrl = generateInlineContentUrl({
|
|
77
79
|
url,
|
|
78
|
-
extension: ".js",
|
|
80
|
+
extension: extension || ".js",
|
|
79
81
|
line,
|
|
80
82
|
column,
|
|
81
83
|
lineEnd,
|
|
@@ -83,9 +85,7 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
83
85
|
})
|
|
84
86
|
const [inlineScriptReference] = context.referenceUtils.foundInline({
|
|
85
87
|
type: "script_src",
|
|
86
|
-
expectedType:
|
|
87
|
-
scriptCategory
|
|
88
|
-
],
|
|
88
|
+
expectedType: type,
|
|
89
89
|
isOriginalPosition: isOriginal,
|
|
90
90
|
specifierLine: line - 1,
|
|
91
91
|
specifierColumn: column,
|
|
@@ -94,15 +94,20 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
94
94
|
content: htmlNodeText,
|
|
95
95
|
})
|
|
96
96
|
removeHtmlNodeText(node)
|
|
97
|
+
if (extension) {
|
|
98
|
+
setHtmlNodeAttributes(node, {
|
|
99
|
+
type: type === "js_module" ? "module" : undefined,
|
|
100
|
+
})
|
|
101
|
+
}
|
|
97
102
|
scriptsToSupervise.push({
|
|
98
103
|
node,
|
|
99
104
|
isInline: true,
|
|
100
|
-
type
|
|
105
|
+
type,
|
|
101
106
|
src: inlineScriptReference.generatedSpecifier,
|
|
102
107
|
})
|
|
103
108
|
}
|
|
104
109
|
const handleScriptWithSrc = (node, src) => {
|
|
105
|
-
const
|
|
110
|
+
const { type } = analyzeScriptNode(node)
|
|
106
111
|
const integrity = getHtmlNodeAttribute(node, "integrity")
|
|
107
112
|
const crossorigin =
|
|
108
113
|
getHtmlNodeAttribute(node, "crossorigin") !== undefined
|
|
@@ -113,7 +118,7 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
113
118
|
})
|
|
114
119
|
scriptsToSupervise.push({
|
|
115
120
|
node,
|
|
116
|
-
type
|
|
121
|
+
type,
|
|
117
122
|
src,
|
|
118
123
|
defer,
|
|
119
124
|
async,
|
|
@@ -123,8 +128,8 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
123
128
|
}
|
|
124
129
|
visitHtmlNodes(htmlAst, {
|
|
125
130
|
script: (node) => {
|
|
126
|
-
const
|
|
127
|
-
if (
|
|
131
|
+
const { type } = analyzeScriptNode(node)
|
|
132
|
+
if (type !== "js_classic" && type !== "js_module") {
|
|
128
133
|
return
|
|
129
134
|
}
|
|
130
135
|
const injectedBy = getHtmlNodeAttribute(node, "injected-by")
|
|
@@ -167,9 +172,11 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
167
172
|
}
|
|
168
173
|
installHtmlSupervisor(${JSON.stringify(
|
|
169
174
|
{
|
|
175
|
+
rootDirectoryUrl: context.rootDirectoryUrl,
|
|
170
176
|
logs,
|
|
171
177
|
measurePerf,
|
|
172
|
-
|
|
178
|
+
errorOverlay,
|
|
179
|
+
openInEditor,
|
|
173
180
|
},
|
|
174
181
|
null,
|
|
175
182
|
" ",
|
|
@@ -252,7 +259,7 @@ const generateCodeToSuperviseScript = ({
|
|
|
252
259
|
integrity,
|
|
253
260
|
crossorigin,
|
|
254
261
|
})
|
|
255
|
-
if (type === "
|
|
262
|
+
if (type === "js_module") {
|
|
256
263
|
return `
|
|
257
264
|
import { superviseScriptTypeModule } from ${htmlSupervisorInstallerSpecifier}
|
|
258
265
|
superviseScriptTypeModule(${paramsAsJson})
|