@jsenv/core 28.0.2 → 28.1.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.
- package/dist/controllable_child_process.mjs +1 -2
- package/dist/controllable_worker_thread.mjs +1 -2
- package/dist/js/autoreload.js +25 -9
- package/dist/js/execute_using_dynamic_import.js +804 -1
- package/dist/js/script_type_module_supervisor.js +122 -0
- package/dist/js/supervisor.js +915 -0
- package/dist/main.js +432 -492
- package/package.json +13 -13
- package/readme.md +1 -1
- package/src/build/inject_global_version_mappings.js +3 -3
- package/src/dev/start_dev_server.js +2 -2
- package/src/execute/execute.js +1 -1
- package/src/execute/run.js +26 -38
- package/src/execute/runtimes/browsers/from_playwright.js +51 -77
- package/src/execute/runtimes/node/node_child_process.js +36 -36
- package/src/execute/runtimes/node/node_worker_thread.js +36 -36
- package/src/omega/kitchen.js +12 -9
- package/src/omega/omega_server.js +2 -2
- package/src/omega/server/file_service.js +2 -2
- package/src/omega/url_graph/url_info_transformations.js +8 -1
- package/src/plugins/autoreload/client/reload.js +20 -7
- package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +4 -4
- package/src/plugins/import_meta_hot/html_hot_dependencies.js +2 -2
- package/src/plugins/importmap/jsenv_plugin_importmap.js +5 -3
- package/src/plugins/inject_globals/inject_globals.js +3 -3
- package/src/plugins/inline/jsenv_plugin_data_urls.js +1 -1
- package/src/plugins/inline/jsenv_plugin_html_inline_content.js +10 -5
- package/src/plugins/plugins.js +5 -5
- package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +4 -4
- package/src/plugins/supervisor/client/script_type_module_supervisor.js +99 -0
- package/src/plugins/supervisor/client/supervisor.js +915 -0
- package/src/plugins/{html_supervisor/jsenv_plugin_html_supervisor.js → supervisor/jsenv_plugin_supervisor.js} +128 -102
- package/src/plugins/toolbar/client/execution/toolbar_execution.js +1 -1
- package/src/plugins/toolbar/jsenv_plugin_toolbar.js +4 -4
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +7 -5
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +5 -4
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +13 -7
- package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +6 -4
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +4 -2
- package/src/plugins/url_analysis/html/html_urls.js +11 -10
- package/src/test/coverage/babel_plugin_instrument.js +1 -35
- package/src/test/coverage/empty_coverage_factory.js +1 -1
- package/src/test/execute_plan.js +7 -3
- package/src/test/execute_test_plan.js +2 -1
- package/src/test/logs_file_execution.js +49 -8
- package/dist/js/html_supervisor_installer.js +0 -1091
- package/dist/js/html_supervisor_setup.js +0 -89
- package/dist/js/uneval.js +0 -804
- package/src/plugins/html_supervisor/client/error_formatter.js +0 -426
- package/src/plugins/html_supervisor/client/error_in_notification.js +0 -21
- package/src/plugins/html_supervisor/client/error_overlay.js +0 -191
- package/src/plugins/html_supervisor/client/html_supervisor_installer.js +0 -315
- package/src/plugins/html_supervisor/client/html_supervisor_setup.js +0 -89
- package/src/plugins/html_supervisor/client/perf_browser.js +0 -17
- package/src/plugins/html_supervisor/client/uneval_exception.js +0 -8
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
import { unevalException } from "./uneval_exception.js"
|
|
2
|
-
import { displayErrorInDocument } from "./error_overlay.js"
|
|
3
|
-
import { displayErrorNotification } from "./error_in_notification.js"
|
|
4
|
-
|
|
5
|
-
const { __html_supervisor__ } = window
|
|
6
|
-
|
|
7
|
-
const supervisedScripts = []
|
|
8
|
-
|
|
9
|
-
export const installHtmlSupervisor = ({
|
|
10
|
-
rootDirectoryUrl,
|
|
11
|
-
logs,
|
|
12
|
-
measurePerf,
|
|
13
|
-
errorOverlay,
|
|
14
|
-
errorBaseUrl,
|
|
15
|
-
openInEditor,
|
|
16
|
-
}) => {
|
|
17
|
-
const errorTransformer = null // could implement error stack remapping if needed
|
|
18
|
-
const scriptExecutionResults = {}
|
|
19
|
-
let collectCalled = false
|
|
20
|
-
let pendingExecutionCount = 0
|
|
21
|
-
let resolveScriptExecutionsPromise
|
|
22
|
-
const scriptExecutionsPromise = new Promise((resolve) => {
|
|
23
|
-
resolveScriptExecutionsPromise = resolve
|
|
24
|
-
})
|
|
25
|
-
const onExecutionStart = (name) => {
|
|
26
|
-
scriptExecutionResults[name] = null // ensure execution order is reflected into the object
|
|
27
|
-
pendingExecutionCount++
|
|
28
|
-
if (measurePerf) {
|
|
29
|
-
performance.mark(`execution_start`)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const onExecutionSettled = (name, executionResult) => {
|
|
33
|
-
if (measurePerf) {
|
|
34
|
-
performance.measure(`execution`, `execution_start`)
|
|
35
|
-
}
|
|
36
|
-
scriptExecutionResults[name] = executionResult
|
|
37
|
-
pendingExecutionCount--
|
|
38
|
-
if (pendingExecutionCount === 0 && collectCalled) {
|
|
39
|
-
resolveScriptExecutionsPromise()
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const onExecutionError = (
|
|
43
|
-
executionResult,
|
|
44
|
-
{ currentScript, errorExposureInNotification = false },
|
|
45
|
-
) => {
|
|
46
|
-
const error = executionResult.error
|
|
47
|
-
if (error && error.code === "NETWORK_FAILURE") {
|
|
48
|
-
if (currentScript) {
|
|
49
|
-
const currentScriptErrorEvent = new Event("error")
|
|
50
|
-
currentScript.dispatchEvent(currentScriptErrorEvent)
|
|
51
|
-
}
|
|
52
|
-
} else if (typeof error === "object") {
|
|
53
|
-
const globalErrorEvent = new Event("error")
|
|
54
|
-
globalErrorEvent.filename = error.filename
|
|
55
|
-
globalErrorEvent.lineno = error.line || error.lineno
|
|
56
|
-
globalErrorEvent.colno = error.column || error.columnno
|
|
57
|
-
globalErrorEvent.message = error.message
|
|
58
|
-
window.dispatchEvent(globalErrorEvent)
|
|
59
|
-
}
|
|
60
|
-
if (errorExposureInNotification) {
|
|
61
|
-
displayErrorNotification(error)
|
|
62
|
-
}
|
|
63
|
-
executionResult.exceptionSource = unevalException(error)
|
|
64
|
-
delete executionResult.error
|
|
65
|
-
}
|
|
66
|
-
const getNavigationStartTime = () => {
|
|
67
|
-
try {
|
|
68
|
-
return window.performance.timing.navigationStart
|
|
69
|
-
} catch (e) {
|
|
70
|
-
return Date.now()
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const performExecution = async (
|
|
75
|
-
{
|
|
76
|
-
src,
|
|
77
|
-
type,
|
|
78
|
-
currentScript,
|
|
79
|
-
execute,
|
|
80
|
-
// https://developer.mozilla.org/en-US/docs/web/html/element/script
|
|
81
|
-
},
|
|
82
|
-
{ reload = false } = {},
|
|
83
|
-
) => {
|
|
84
|
-
if (logs) {
|
|
85
|
-
console.group(`[jsenv] loading ${type} ${src}`)
|
|
86
|
-
}
|
|
87
|
-
onExecutionStart(src)
|
|
88
|
-
let completed
|
|
89
|
-
let result
|
|
90
|
-
let error
|
|
91
|
-
const urlObject = new URL(src, window.location)
|
|
92
|
-
if (reload) {
|
|
93
|
-
urlObject.searchParams.set("hmr", Date.now())
|
|
94
|
-
}
|
|
95
|
-
__html_supervisor__.currentExecution = {
|
|
96
|
-
type: type === "module" ? "dynamic_import" : "script_injection",
|
|
97
|
-
url: urlObject.href,
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
result = await execute(urlObject.href)
|
|
101
|
-
completed = true
|
|
102
|
-
} catch (e) {
|
|
103
|
-
completed = false
|
|
104
|
-
error = e
|
|
105
|
-
}
|
|
106
|
-
if (completed) {
|
|
107
|
-
const executionResult = {
|
|
108
|
-
status: "completed",
|
|
109
|
-
namespace: result,
|
|
110
|
-
coverage: window.__coverage__,
|
|
111
|
-
}
|
|
112
|
-
onExecutionSettled(src, executionResult)
|
|
113
|
-
if (logs) {
|
|
114
|
-
console.log(`${type} load ended`)
|
|
115
|
-
console.groupEnd()
|
|
116
|
-
}
|
|
117
|
-
__html_supervisor__.currentExecution = null
|
|
118
|
-
return
|
|
119
|
-
}
|
|
120
|
-
const executionResult = {
|
|
121
|
-
status: "errored",
|
|
122
|
-
coverage: window.__coverage__,
|
|
123
|
-
}
|
|
124
|
-
let errorExposureInConsole = true
|
|
125
|
-
if (error.name === "SyntaxError") {
|
|
126
|
-
// errorExposureInConsole = false
|
|
127
|
-
}
|
|
128
|
-
if (errorTransformer) {
|
|
129
|
-
try {
|
|
130
|
-
error = await errorTransformer(error)
|
|
131
|
-
} catch (e) {}
|
|
132
|
-
}
|
|
133
|
-
executionResult.error = error
|
|
134
|
-
onExecutionSettled(src, executionResult)
|
|
135
|
-
onExecutionError(executionResult, { currentScript })
|
|
136
|
-
if (errorExposureInConsole) {
|
|
137
|
-
if (typeof window.reportError === "function") {
|
|
138
|
-
window.reportError(error)
|
|
139
|
-
} else {
|
|
140
|
-
console.error(error)
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (logs) {
|
|
144
|
-
console.groupEnd()
|
|
145
|
-
}
|
|
146
|
-
__html_supervisor__.currentExecution = null
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const classicExecutionQueue = createExecutionQueue(performExecution)
|
|
150
|
-
const deferedExecutionQueue = createExecutionQueue(performExecution)
|
|
151
|
-
deferedExecutionQueue.waitFor(
|
|
152
|
-
new Promise((resolve) => {
|
|
153
|
-
if (
|
|
154
|
-
document.readyState === "interactive" ||
|
|
155
|
-
document.readyState === "complete"
|
|
156
|
-
) {
|
|
157
|
-
resolve()
|
|
158
|
-
} else {
|
|
159
|
-
document.addEventListener("readystatechange", () => {
|
|
160
|
-
if (document.readyState === "interactive") {
|
|
161
|
-
resolve()
|
|
162
|
-
}
|
|
163
|
-
})
|
|
164
|
-
}
|
|
165
|
-
}),
|
|
166
|
-
)
|
|
167
|
-
__html_supervisor__.addScriptToExecute = async (scriptToExecute) => {
|
|
168
|
-
if (!supervisedScripts.includes(scriptToExecute)) {
|
|
169
|
-
supervisedScripts.push(scriptToExecute)
|
|
170
|
-
scriptToExecute.reload = () => {
|
|
171
|
-
return performExecution(scriptToExecute, { reload: true })
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (scriptToExecute.async) {
|
|
176
|
-
performExecution(scriptToExecute)
|
|
177
|
-
return
|
|
178
|
-
}
|
|
179
|
-
const useDeferQueue =
|
|
180
|
-
scriptToExecute.defer || scriptToExecute.type === "module"
|
|
181
|
-
if (useDeferQueue) {
|
|
182
|
-
const classicExecutionPromise = classicExecutionQueue.getPromise()
|
|
183
|
-
if (classicExecutionPromise) {
|
|
184
|
-
deferedExecutionQueue.waitFor(classicExecutionPromise)
|
|
185
|
-
}
|
|
186
|
-
deferedExecutionQueue.executeAsap(scriptToExecute)
|
|
187
|
-
} else {
|
|
188
|
-
classicExecutionQueue.executeAsap(scriptToExecute)
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
__html_supervisor__.collectScriptResults = async () => {
|
|
193
|
-
collectCalled = true
|
|
194
|
-
if (pendingExecutionCount === 0) {
|
|
195
|
-
resolveScriptExecutionsPromise()
|
|
196
|
-
} else {
|
|
197
|
-
await scriptExecutionsPromise
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
let status = "completed"
|
|
201
|
-
let exceptionSource = ""
|
|
202
|
-
Object.keys(scriptExecutionResults).forEach((key) => {
|
|
203
|
-
const scriptExecutionResult = scriptExecutionResults[key]
|
|
204
|
-
if (scriptExecutionResult.status === "errored") {
|
|
205
|
-
status = "errored"
|
|
206
|
-
exceptionSource = scriptExecutionResult.exceptionSource
|
|
207
|
-
}
|
|
208
|
-
})
|
|
209
|
-
return {
|
|
210
|
-
status,
|
|
211
|
-
...(status === "errored" ? { exceptionSource } : {}),
|
|
212
|
-
startTime: getNavigationStartTime(),
|
|
213
|
-
endTime: Date.now(),
|
|
214
|
-
scriptExecutionResults,
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const { scriptsToExecute } = __html_supervisor__
|
|
219
|
-
const copy = scriptsToExecute.slice()
|
|
220
|
-
scriptsToExecute.length = 0
|
|
221
|
-
copy.forEach((scriptToExecute) => {
|
|
222
|
-
__html_supervisor__.addScriptToExecute(scriptToExecute)
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
if (errorOverlay) {
|
|
226
|
-
const onErrorReportedByBrowser = (error, { url, line, column }) => {
|
|
227
|
-
displayErrorInDocument(error, {
|
|
228
|
-
rootDirectoryUrl,
|
|
229
|
-
errorBaseUrl,
|
|
230
|
-
openInEditor,
|
|
231
|
-
url,
|
|
232
|
-
line,
|
|
233
|
-
column,
|
|
234
|
-
})
|
|
235
|
-
}
|
|
236
|
-
window.addEventListener("error", (errorEvent) => {
|
|
237
|
-
if (!errorEvent.isTrusted) {
|
|
238
|
-
// ignore custom error event (not sent by browser)
|
|
239
|
-
return
|
|
240
|
-
}
|
|
241
|
-
const { error, filename, lineno, colno } = errorEvent
|
|
242
|
-
onErrorReportedByBrowser(error, {
|
|
243
|
-
url: filename,
|
|
244
|
-
line: lineno,
|
|
245
|
-
column: colno,
|
|
246
|
-
})
|
|
247
|
-
})
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
__html_supervisor__.reloadSupervisedScript = ({ type, src }) => {
|
|
252
|
-
const supervisedScript = supervisedScripts.find(
|
|
253
|
-
(supervisedScriptCandidate) => {
|
|
254
|
-
if (type && supervisedScriptCandidate.type !== type) {
|
|
255
|
-
return false
|
|
256
|
-
}
|
|
257
|
-
if (supervisedScriptCandidate.src !== src) {
|
|
258
|
-
return false
|
|
259
|
-
}
|
|
260
|
-
return true
|
|
261
|
-
},
|
|
262
|
-
)
|
|
263
|
-
if (supervisedScript) {
|
|
264
|
-
supervisedScript.reload()
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export const superviseScriptTypeModule = ({ src, isInline }) => {
|
|
269
|
-
__html_supervisor__.addScriptToExecute({
|
|
270
|
-
src,
|
|
271
|
-
type: "module",
|
|
272
|
-
isInline,
|
|
273
|
-
execute: (url) => import(url),
|
|
274
|
-
})
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const createExecutionQueue = (execute) => {
|
|
278
|
-
const scripts = []
|
|
279
|
-
|
|
280
|
-
let promiseToWait = null
|
|
281
|
-
const waitFor = async (promise) => {
|
|
282
|
-
promiseToWait = promise
|
|
283
|
-
promiseToWait.then(
|
|
284
|
-
() => {
|
|
285
|
-
promiseToWait = null
|
|
286
|
-
dequeue()
|
|
287
|
-
},
|
|
288
|
-
() => {
|
|
289
|
-
promiseToWait = null
|
|
290
|
-
dequeue()
|
|
291
|
-
},
|
|
292
|
-
)
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
const executeAsap = async (script) => {
|
|
296
|
-
if (promiseToWait) {
|
|
297
|
-
scripts.push(script)
|
|
298
|
-
return
|
|
299
|
-
}
|
|
300
|
-
waitFor(execute(script))
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const dequeue = () => {
|
|
304
|
-
const scriptWaiting = scripts.shift()
|
|
305
|
-
if (scriptWaiting) {
|
|
306
|
-
__html_supervisor__.addScriptToExecute(scriptWaiting)
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return {
|
|
311
|
-
waitFor,
|
|
312
|
-
executeAsap,
|
|
313
|
-
getPromise: () => promiseToWait,
|
|
314
|
-
}
|
|
315
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
window.__html_supervisor__ = {
|
|
2
|
-
// "html_supervisor_installer.js" will implement
|
|
3
|
-
// - "addScriptToExecute"
|
|
4
|
-
// - "superviseScriptTypeModule"
|
|
5
|
-
// - "collectScriptResults"
|
|
6
|
-
// and take all executions in "scriptsToExecute" and implement their supervision
|
|
7
|
-
scriptsToExecute: [],
|
|
8
|
-
addScriptToExecute: (scriptToExecute) => {
|
|
9
|
-
window.__html_supervisor__.scriptsToExecute.push(scriptToExecute)
|
|
10
|
-
},
|
|
11
|
-
superviseScript: ({ src, isInline, crossorigin, integrity }) => {
|
|
12
|
-
const { currentScript } = document
|
|
13
|
-
window.__html_supervisor__.addScriptToExecute({
|
|
14
|
-
src,
|
|
15
|
-
type: "js_classic",
|
|
16
|
-
isInline,
|
|
17
|
-
currentScript,
|
|
18
|
-
execute: (url) => {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
const script = document.createElement("script")
|
|
21
|
-
if (crossorigin) {
|
|
22
|
-
script.crossorigin = crossorigin
|
|
23
|
-
}
|
|
24
|
-
if (integrity) {
|
|
25
|
-
script.integrity = integrity
|
|
26
|
-
}
|
|
27
|
-
script.src = url
|
|
28
|
-
let lastWindowErrorUrl
|
|
29
|
-
let lastWindowError
|
|
30
|
-
const windowErrorCallback = (e) => {
|
|
31
|
-
lastWindowErrorUrl = e.filename
|
|
32
|
-
lastWindowError = e.error
|
|
33
|
-
}
|
|
34
|
-
const cleanup = () => {
|
|
35
|
-
// the execution of the script itself can remove script from the page
|
|
36
|
-
if (script.parentNode) {
|
|
37
|
-
script.parentNode.removeChild(script)
|
|
38
|
-
}
|
|
39
|
-
window.removeEventListener("error", windowErrorCallback)
|
|
40
|
-
}
|
|
41
|
-
window.addEventListener("error", windowErrorCallback)
|
|
42
|
-
script.addEventListener("error", () => {
|
|
43
|
-
cleanup()
|
|
44
|
-
reject(src)
|
|
45
|
-
})
|
|
46
|
-
script.addEventListener("load", () => {
|
|
47
|
-
cleanup()
|
|
48
|
-
if (lastWindowErrorUrl === url) {
|
|
49
|
-
reject(lastWindowError)
|
|
50
|
-
} else {
|
|
51
|
-
resolve()
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
if (currentScript) {
|
|
55
|
-
currentScript.parentNode.insertBefore(
|
|
56
|
-
script,
|
|
57
|
-
currentScript.nextSibling,
|
|
58
|
-
)
|
|
59
|
-
} else {
|
|
60
|
-
document.body.appendChild(script)
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
},
|
|
64
|
-
})
|
|
65
|
-
},
|
|
66
|
-
superviseScriptTypeModule: () => {
|
|
67
|
-
throw new Error("htmlSupervisor not installed")
|
|
68
|
-
},
|
|
69
|
-
getScriptExecutionResults: () => {
|
|
70
|
-
// wait for page to load before collecting script execution results
|
|
71
|
-
const htmlReadyPromise = new Promise((resolve) => {
|
|
72
|
-
if (document.readyState === "complete") {
|
|
73
|
-
resolve()
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
const loadCallback = () => {
|
|
77
|
-
window.removeEventListener("load", loadCallback)
|
|
78
|
-
resolve()
|
|
79
|
-
}
|
|
80
|
-
window.addEventListener("load", loadCallback)
|
|
81
|
-
})
|
|
82
|
-
return htmlReadyPromise.then(() => {
|
|
83
|
-
return window.__html_supervisor__.collectScriptResults()
|
|
84
|
-
})
|
|
85
|
-
},
|
|
86
|
-
collectScriptResults: () => {
|
|
87
|
-
throw new Error("htmlSupervisor not installed")
|
|
88
|
-
},
|
|
89
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const { performance } = window
|
|
2
|
-
|
|
3
|
-
export const measureAsyncFnPerf = performance
|
|
4
|
-
? async (fn, name) => {
|
|
5
|
-
const perfMarkStartName = `${name}_start`
|
|
6
|
-
|
|
7
|
-
performance.mark(perfMarkStartName)
|
|
8
|
-
try {
|
|
9
|
-
const value = await fn()
|
|
10
|
-
return value
|
|
11
|
-
} finally {
|
|
12
|
-
performance.measure(name, perfMarkStartName)
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
: async (fn) => {
|
|
16
|
-
return fn()
|
|
17
|
-
}
|