@jsenv/core 33.0.2 → 34.0.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 +1 -4
- package/dist/js/supervisor.js +498 -290
- package/dist/jsenv.js +870 -346
- package/package.json +2 -3
- package/src/basic_fetch.js +23 -13
- package/src/build/start_build_server.js +3 -2
- package/src/dev/file_service.js +1 -1
- package/src/dev/start_dev_server.js +9 -6
- package/src/execute/execute.js +7 -18
- package/src/execute/runtimes/browsers/from_playwright.js +168 -32
- package/src/execute/runtimes/browsers/webkit.js +1 -1
- package/src/execute/web_server_param.js +68 -0
- package/src/kitchen/compat/features_compatibility.js +3 -0
- package/src/plugins/autoreload/client/reload.js +1 -4
- package/src/plugins/inline/jsenv_plugin_html_inline_content.js +30 -18
- package/src/plugins/plugins.js +1 -1
- package/src/plugins/ribbon/jsenv_plugin_ribbon.js +3 -2
- package/src/plugins/supervisor/client/supervisor.js +467 -287
- package/src/plugins/supervisor/html_supervisor_injection.js +281 -0
- package/src/plugins/supervisor/js_supervisor_injection.js +281 -0
- package/src/plugins/supervisor/jsenv_plugin_supervisor.js +48 -233
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +1 -1
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +5 -0
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +1 -1
- package/src/test/execute_steps.js +10 -18
- package/src/test/execute_test_plan.js +12 -60
- package/src/test/logs_file_execution.js +74 -28
- package/dist/js/script_type_module_supervisor.js +0 -109
- package/src/plugins/supervisor/client/script_type_module_supervisor.js +0 -98
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import wrapAnsi from "wrap-ansi"
|
|
1
2
|
import {
|
|
2
3
|
ANSI,
|
|
3
4
|
UNICODE,
|
|
@@ -41,29 +42,48 @@ export const createExecutionLog = (
|
|
|
41
42
|
timeEllapsed,
|
|
42
43
|
memoryHeap,
|
|
43
44
|
})
|
|
45
|
+
let log
|
|
44
46
|
if (completedExecutionLogAbbreviation && status === "completed") {
|
|
45
|
-
|
|
47
|
+
log = `${description}${summary}`
|
|
48
|
+
} else {
|
|
49
|
+
const { consoleCalls = [], errors = [] } = executionResult
|
|
50
|
+
const consoleOutput = formatConsoleCalls(consoleCalls)
|
|
51
|
+
const errorsOutput = formatErrors(errors)
|
|
52
|
+
log = formatExecution({
|
|
53
|
+
label: `${description}${summary}`,
|
|
54
|
+
details: {
|
|
55
|
+
file: fileRelativeUrl,
|
|
56
|
+
...(logRuntime ? { runtime: `${runtimeName}/${runtimeVersion}` } : {}),
|
|
57
|
+
...(logEachDuration
|
|
58
|
+
? {
|
|
59
|
+
duration:
|
|
60
|
+
status === "executing"
|
|
61
|
+
? msAsEllapsedTime(Date.now() - startMs)
|
|
62
|
+
: msAsDuration(endMs - startMs),
|
|
63
|
+
}
|
|
64
|
+
: {}),
|
|
65
|
+
},
|
|
66
|
+
consoleOutput,
|
|
67
|
+
errorsOutput,
|
|
68
|
+
})
|
|
46
69
|
}
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
file: fileRelativeUrl,
|
|
54
|
-
...(logRuntime ? { runtime: `${runtimeName}/${runtimeVersion}` } : {}),
|
|
55
|
-
...(logEachDuration
|
|
56
|
-
? {
|
|
57
|
-
duration:
|
|
58
|
-
status === "executing"
|
|
59
|
-
? msAsEllapsedTime(Date.now() - startMs)
|
|
60
|
-
: msAsDuration(endMs - startMs),
|
|
61
|
-
}
|
|
62
|
-
: {}),
|
|
63
|
-
},
|
|
64
|
-
consoleOutput,
|
|
65
|
-
errorsOutput,
|
|
70
|
+
|
|
71
|
+
const { columns = 80 } = process.stdout
|
|
72
|
+
log = wrapAnsi(log, columns, {
|
|
73
|
+
trim: false,
|
|
74
|
+
hard: true,
|
|
75
|
+
wordWrap: false,
|
|
66
76
|
})
|
|
77
|
+
if (endMs) {
|
|
78
|
+
if (completedExecutionLogAbbreviation) {
|
|
79
|
+
return `${log}\n`
|
|
80
|
+
}
|
|
81
|
+
if (executionIndex === counters.total - 1) {
|
|
82
|
+
return `${log}\n`
|
|
83
|
+
}
|
|
84
|
+
return `${log}\n\n`
|
|
85
|
+
}
|
|
86
|
+
return log
|
|
67
87
|
}
|
|
68
88
|
|
|
69
89
|
const formatErrors = (errors) => {
|
|
@@ -203,44 +223,70 @@ const createMixedDetails = ({ counters }) => {
|
|
|
203
223
|
const descriptionFormatters = {
|
|
204
224
|
executing: ({ index, total }) => {
|
|
205
225
|
return ANSI.color(
|
|
206
|
-
`executing ${index
|
|
226
|
+
`executing ${padNumber(index, total)} of ${total}`,
|
|
207
227
|
EXECUTION_COLORS.executing,
|
|
208
228
|
)
|
|
209
229
|
},
|
|
210
230
|
aborted: ({ index, total }) => {
|
|
211
231
|
return ANSI.color(
|
|
212
|
-
`${UNICODE.FAILURE_RAW} execution ${
|
|
232
|
+
`${UNICODE.FAILURE_RAW} execution ${padNumber(
|
|
233
|
+
index,
|
|
234
|
+
total,
|
|
235
|
+
)} of ${total} aborted`,
|
|
213
236
|
EXECUTION_COLORS.aborted,
|
|
214
237
|
)
|
|
215
238
|
},
|
|
216
239
|
timedout: ({ index, total, executionParams }) => {
|
|
217
240
|
return ANSI.color(
|
|
218
|
-
`${UNICODE.FAILURE_RAW} execution ${
|
|
219
|
-
index
|
|
220
|
-
|
|
241
|
+
`${UNICODE.FAILURE_RAW} execution ${padNumber(
|
|
242
|
+
index,
|
|
243
|
+
total,
|
|
244
|
+
)} of ${total} timeout after ${executionParams.allocatedMs}ms`,
|
|
221
245
|
EXECUTION_COLORS.timedout,
|
|
222
246
|
)
|
|
223
247
|
},
|
|
224
248
|
failed: ({ index, total }) => {
|
|
225
249
|
return ANSI.color(
|
|
226
|
-
`${UNICODE.FAILURE_RAW} execution ${
|
|
250
|
+
`${UNICODE.FAILURE_RAW} execution ${padNumber(
|
|
251
|
+
index,
|
|
252
|
+
total,
|
|
253
|
+
)} of ${total} failed`,
|
|
227
254
|
EXECUTION_COLORS.failed,
|
|
228
255
|
)
|
|
229
256
|
},
|
|
230
257
|
completed: ({ index, total }) => {
|
|
231
258
|
return ANSI.color(
|
|
232
|
-
`${UNICODE.OK_RAW} execution ${
|
|
259
|
+
`${UNICODE.OK_RAW} execution ${padNumber(
|
|
260
|
+
index,
|
|
261
|
+
total,
|
|
262
|
+
)} of ${total} completed`,
|
|
233
263
|
EXECUTION_COLORS.completed,
|
|
234
264
|
)
|
|
235
265
|
},
|
|
236
266
|
cancelled: ({ index, total }) => {
|
|
237
267
|
return ANSI.color(
|
|
238
|
-
`${UNICODE.FAILURE_RAW} execution ${
|
|
268
|
+
`${UNICODE.FAILURE_RAW} execution ${padNumber(
|
|
269
|
+
index,
|
|
270
|
+
total,
|
|
271
|
+
)} of ${total} cancelled`,
|
|
239
272
|
EXECUTION_COLORS.cancelled,
|
|
240
273
|
)
|
|
241
274
|
},
|
|
242
275
|
}
|
|
243
276
|
|
|
277
|
+
const padNumber = (index, total) => {
|
|
278
|
+
const number = index + 1
|
|
279
|
+
const numberWidth = String(number).length
|
|
280
|
+
const totalWith = String(total).length
|
|
281
|
+
let missingWidth = totalWith - numberWidth
|
|
282
|
+
let padded = ""
|
|
283
|
+
while (missingWidth--) {
|
|
284
|
+
padded += "0"
|
|
285
|
+
}
|
|
286
|
+
padded += number
|
|
287
|
+
return padded
|
|
288
|
+
}
|
|
289
|
+
|
|
244
290
|
const formatConsoleCalls = (consoleCalls) => {
|
|
245
291
|
if (consoleCalls.length === 0) {
|
|
246
292
|
return ""
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
// https://twitter.com/damienmaillard/status/1554752482273787906
|
|
2
|
-
const isWebkitOrSafari = typeof window.webkitConvertPointFromNodeToPage === "function";
|
|
3
|
-
const superviseScriptTypeModule = async ({
|
|
4
|
-
src,
|
|
5
|
-
async
|
|
6
|
-
}) => {
|
|
7
|
-
const currentScript = document.querySelector(`script[type="module"][inlined-from-src="${src}"]`);
|
|
8
|
-
const execute = isWebkitOrSafari ? createExecuteWithDynamicImport({
|
|
9
|
-
src
|
|
10
|
-
}) : createExecuteWithScript({
|
|
11
|
-
currentScript,
|
|
12
|
-
src
|
|
13
|
-
});
|
|
14
|
-
return window.__supervisor__.addExecution({
|
|
15
|
-
src,
|
|
16
|
-
async,
|
|
17
|
-
type: "js_module",
|
|
18
|
-
execute
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
const createExecuteWithScript = ({
|
|
22
|
-
currentScript,
|
|
23
|
-
src
|
|
24
|
-
}) => {
|
|
25
|
-
const parentNode = currentScript.parentNode;
|
|
26
|
-
let nodeToReplace;
|
|
27
|
-
let currentScriptClone;
|
|
28
|
-
return async ({
|
|
29
|
-
isReload
|
|
30
|
-
}) => {
|
|
31
|
-
const urlObject = new URL(src, window.location);
|
|
32
|
-
const loadPromise = new Promise((resolve, reject) => {
|
|
33
|
-
currentScriptClone = document.createElement("script");
|
|
34
|
-
// browsers set async by default when creating script(s)
|
|
35
|
-
// we want an exact copy to preserves how code is executed
|
|
36
|
-
currentScriptClone.async = false;
|
|
37
|
-
Array.from(currentScript.attributes).forEach(attribute => {
|
|
38
|
-
currentScriptClone.setAttribute(attribute.nodeName, attribute.nodeValue);
|
|
39
|
-
});
|
|
40
|
-
if (isReload) {
|
|
41
|
-
urlObject.searchParams.set("hmr", Date.now());
|
|
42
|
-
nodeToReplace = currentScriptClone;
|
|
43
|
-
currentScriptClone.src = urlObject.href;
|
|
44
|
-
} else {
|
|
45
|
-
currentScriptClone.removeAttribute("jsenv-cooked-by");
|
|
46
|
-
currentScriptClone.removeAttribute("jsenv-inlined-by");
|
|
47
|
-
currentScriptClone.removeAttribute("jsenv-injected-by");
|
|
48
|
-
currentScriptClone.removeAttribute("inlined-from-src");
|
|
49
|
-
currentScriptClone.removeAttribute("original-position");
|
|
50
|
-
currentScriptClone.removeAttribute("original-src-position");
|
|
51
|
-
nodeToReplace = currentScript;
|
|
52
|
-
currentScriptClone.src = src;
|
|
53
|
-
}
|
|
54
|
-
currentScriptClone.addEventListener("error", reject);
|
|
55
|
-
currentScriptClone.addEventListener("load", resolve);
|
|
56
|
-
parentNode.replaceChild(currentScriptClone, nodeToReplace);
|
|
57
|
-
});
|
|
58
|
-
try {
|
|
59
|
-
await loadPromise;
|
|
60
|
-
} catch (e) {
|
|
61
|
-
// eslint-disable-next-line no-throw-literal
|
|
62
|
-
throw {
|
|
63
|
-
message: `Failed to fetch module: ${urlObject.href}`,
|
|
64
|
-
reportedBy: "script_error_event",
|
|
65
|
-
url: urlObject.href,
|
|
66
|
-
// window.error won't be dispatched for this error
|
|
67
|
-
needsReport: true
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
try {
|
|
71
|
-
return {
|
|
72
|
-
executionPromise: import(urlObject.href)
|
|
73
|
-
};
|
|
74
|
-
} catch (e) {
|
|
75
|
-
e.reportedBy = "dynamic_import";
|
|
76
|
-
throw e;
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
const createExecuteWithDynamicImport = ({
|
|
81
|
-
src
|
|
82
|
-
}) => {
|
|
83
|
-
return async ({
|
|
84
|
-
isReload
|
|
85
|
-
}) => {
|
|
86
|
-
const urlObject = new URL(src, window.location);
|
|
87
|
-
if (isReload) {
|
|
88
|
-
urlObject.searchParams.set("hmr", Date.now());
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
const namespace = await import(urlObject.href);
|
|
92
|
-
return {
|
|
93
|
-
executionPromise: Promise.resolve(namespace)
|
|
94
|
-
};
|
|
95
|
-
} catch (e) {
|
|
96
|
-
e.reportedBy = "dynamic_import";
|
|
97
|
-
// dynamic import would hide the error to the browser
|
|
98
|
-
// so it must be re-reported using window.reportError
|
|
99
|
-
if (typeof window.reportError === "function") {
|
|
100
|
-
window.reportError(e);
|
|
101
|
-
} else {
|
|
102
|
-
console.error(e);
|
|
103
|
-
}
|
|
104
|
-
throw e;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export { superviseScriptTypeModule };
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// https://twitter.com/damienmaillard/status/1554752482273787906
|
|
2
|
-
const isWebkitOrSafari =
|
|
3
|
-
typeof window.webkitConvertPointFromNodeToPage === "function"
|
|
4
|
-
|
|
5
|
-
export const superviseScriptTypeModule = async ({ src, async }) => {
|
|
6
|
-
const currentScript = document.querySelector(
|
|
7
|
-
`script[type="module"][inlined-from-src="${src}"]`,
|
|
8
|
-
)
|
|
9
|
-
const execute = isWebkitOrSafari
|
|
10
|
-
? createExecuteWithDynamicImport({ src })
|
|
11
|
-
: createExecuteWithScript({ currentScript, src })
|
|
12
|
-
return window.__supervisor__.addExecution({
|
|
13
|
-
src,
|
|
14
|
-
async,
|
|
15
|
-
type: "js_module",
|
|
16
|
-
execute,
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const createExecuteWithScript = ({ currentScript, src }) => {
|
|
21
|
-
const parentNode = currentScript.parentNode
|
|
22
|
-
let nodeToReplace
|
|
23
|
-
let currentScriptClone
|
|
24
|
-
return async ({ isReload }) => {
|
|
25
|
-
const urlObject = new URL(src, window.location)
|
|
26
|
-
const loadPromise = new Promise((resolve, reject) => {
|
|
27
|
-
currentScriptClone = document.createElement("script")
|
|
28
|
-
// browsers set async by default when creating script(s)
|
|
29
|
-
// we want an exact copy to preserves how code is executed
|
|
30
|
-
currentScriptClone.async = false
|
|
31
|
-
Array.from(currentScript.attributes).forEach((attribute) => {
|
|
32
|
-
currentScriptClone.setAttribute(attribute.nodeName, attribute.nodeValue)
|
|
33
|
-
})
|
|
34
|
-
if (isReload) {
|
|
35
|
-
urlObject.searchParams.set("hmr", Date.now())
|
|
36
|
-
nodeToReplace = currentScriptClone
|
|
37
|
-
currentScriptClone.src = urlObject.href
|
|
38
|
-
} else {
|
|
39
|
-
currentScriptClone.removeAttribute("jsenv-cooked-by")
|
|
40
|
-
currentScriptClone.removeAttribute("jsenv-inlined-by")
|
|
41
|
-
currentScriptClone.removeAttribute("jsenv-injected-by")
|
|
42
|
-
currentScriptClone.removeAttribute("inlined-from-src")
|
|
43
|
-
currentScriptClone.removeAttribute("original-position")
|
|
44
|
-
currentScriptClone.removeAttribute("original-src-position")
|
|
45
|
-
nodeToReplace = currentScript
|
|
46
|
-
currentScriptClone.src = src
|
|
47
|
-
}
|
|
48
|
-
currentScriptClone.addEventListener("error", reject)
|
|
49
|
-
currentScriptClone.addEventListener("load", resolve)
|
|
50
|
-
parentNode.replaceChild(currentScriptClone, nodeToReplace)
|
|
51
|
-
})
|
|
52
|
-
try {
|
|
53
|
-
await loadPromise
|
|
54
|
-
} catch (e) {
|
|
55
|
-
// eslint-disable-next-line no-throw-literal
|
|
56
|
-
throw {
|
|
57
|
-
message: `Failed to fetch module: ${urlObject.href}`,
|
|
58
|
-
reportedBy: "script_error_event",
|
|
59
|
-
url: urlObject.href,
|
|
60
|
-
// window.error won't be dispatched for this error
|
|
61
|
-
needsReport: true,
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
return {
|
|
66
|
-
executionPromise: import(urlObject.href),
|
|
67
|
-
}
|
|
68
|
-
} catch (e) {
|
|
69
|
-
e.reportedBy = "dynamic_import"
|
|
70
|
-
throw e
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const createExecuteWithDynamicImport = ({ src }) => {
|
|
76
|
-
return async ({ isReload }) => {
|
|
77
|
-
const urlObject = new URL(src, window.location)
|
|
78
|
-
if (isReload) {
|
|
79
|
-
urlObject.searchParams.set("hmr", Date.now())
|
|
80
|
-
}
|
|
81
|
-
try {
|
|
82
|
-
const namespace = await import(urlObject.href)
|
|
83
|
-
return {
|
|
84
|
-
executionPromise: Promise.resolve(namespace),
|
|
85
|
-
}
|
|
86
|
-
} catch (e) {
|
|
87
|
-
e.reportedBy = "dynamic_import"
|
|
88
|
-
// dynamic import would hide the error to the browser
|
|
89
|
-
// so it must be re-reported using window.reportError
|
|
90
|
-
if (typeof window.reportError === "function") {
|
|
91
|
-
window.reportError(e)
|
|
92
|
-
} else {
|
|
93
|
-
console.error(e)
|
|
94
|
-
}
|
|
95
|
-
throw e
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|