@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.
Files changed (55) hide show
  1. package/dist/controllable_child_process.mjs +1 -2
  2. package/dist/controllable_worker_thread.mjs +1 -2
  3. package/dist/js/autoreload.js +25 -9
  4. package/dist/js/execute_using_dynamic_import.js +804 -1
  5. package/dist/js/script_type_module_supervisor.js +122 -0
  6. package/dist/js/supervisor.js +915 -0
  7. package/dist/main.js +432 -492
  8. package/package.json +13 -13
  9. package/readme.md +1 -1
  10. package/src/build/inject_global_version_mappings.js +3 -3
  11. package/src/dev/start_dev_server.js +2 -2
  12. package/src/execute/execute.js +1 -1
  13. package/src/execute/run.js +26 -38
  14. package/src/execute/runtimes/browsers/from_playwright.js +51 -77
  15. package/src/execute/runtimes/node/node_child_process.js +36 -36
  16. package/src/execute/runtimes/node/node_worker_thread.js +36 -36
  17. package/src/omega/kitchen.js +12 -9
  18. package/src/omega/omega_server.js +2 -2
  19. package/src/omega/server/file_service.js +2 -2
  20. package/src/omega/url_graph/url_info_transformations.js +8 -1
  21. package/src/plugins/autoreload/client/reload.js +20 -7
  22. package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +4 -4
  23. package/src/plugins/import_meta_hot/html_hot_dependencies.js +2 -2
  24. package/src/plugins/importmap/jsenv_plugin_importmap.js +5 -3
  25. package/src/plugins/inject_globals/inject_globals.js +3 -3
  26. package/src/plugins/inline/jsenv_plugin_data_urls.js +1 -1
  27. package/src/plugins/inline/jsenv_plugin_html_inline_content.js +10 -5
  28. package/src/plugins/plugins.js +5 -5
  29. package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +4 -4
  30. package/src/plugins/supervisor/client/script_type_module_supervisor.js +99 -0
  31. package/src/plugins/supervisor/client/supervisor.js +915 -0
  32. package/src/plugins/{html_supervisor/jsenv_plugin_html_supervisor.js → supervisor/jsenv_plugin_supervisor.js} +128 -102
  33. package/src/plugins/toolbar/client/execution/toolbar_execution.js +1 -1
  34. package/src/plugins/toolbar/jsenv_plugin_toolbar.js +4 -4
  35. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +7 -5
  36. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +5 -4
  37. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +13 -7
  38. package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +6 -4
  39. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +4 -2
  40. package/src/plugins/url_analysis/html/html_urls.js +11 -10
  41. package/src/test/coverage/babel_plugin_instrument.js +1 -35
  42. package/src/test/coverage/empty_coverage_factory.js +1 -1
  43. package/src/test/execute_plan.js +7 -3
  44. package/src/test/execute_test_plan.js +2 -1
  45. package/src/test/logs_file_execution.js +49 -8
  46. package/dist/js/html_supervisor_installer.js +0 -1091
  47. package/dist/js/html_supervisor_setup.js +0 -89
  48. package/dist/js/uneval.js +0 -804
  49. package/src/plugins/html_supervisor/client/error_formatter.js +0 -426
  50. package/src/plugins/html_supervisor/client/error_in_notification.js +0 -21
  51. package/src/plugins/html_supervisor/client/error_overlay.js +0 -191
  52. package/src/plugins/html_supervisor/client/html_supervisor_installer.js +0 -315
  53. package/src/plugins/html_supervisor/client/html_supervisor_setup.js +0 -89
  54. package/src/plugins/html_supervisor/client/perf_browser.js +0 -17
  55. package/src/plugins/html_supervisor/client/uneval_exception.js +0 -8
@@ -0,0 +1,122 @@
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
+
15
+ if (!async) {
16
+ await window.__supervisor__.getPreviousExecutionDonePromise();
17
+ }
18
+
19
+ const execution = window.__supervisor__.createExecution({
20
+ src,
21
+ async,
22
+ type: "js_module",
23
+ execute
24
+ });
25
+
26
+ return execution.start();
27
+ };
28
+
29
+ const createExecuteWithScript = ({
30
+ currentScript,
31
+ src
32
+ }) => {
33
+ const parentNode = currentScript.parentNode;
34
+ let nodeToReplace;
35
+ let currentScriptClone;
36
+ return async ({
37
+ isReload
38
+ }) => {
39
+ const urlObject = new URL(src, window.location);
40
+ const loadPromise = new Promise((resolve, reject) => {
41
+ currentScriptClone = document.createElement("script"); // browsers set async by default when creating script(s)
42
+ // we want an exact copy to preserves how code is executed
43
+
44
+ currentScriptClone.async = false;
45
+ Array.from(currentScript.attributes).forEach(attribute => {
46
+ currentScriptClone.setAttribute(attribute.nodeName, attribute.nodeValue);
47
+ });
48
+
49
+ if (isReload) {
50
+ urlObject.searchParams.set("hmr", Date.now());
51
+ nodeToReplace = currentScriptClone;
52
+ currentScriptClone.src = urlObject.href;
53
+ } else {
54
+ currentScriptClone.removeAttribute("jsenv-plugin-owner");
55
+ currentScriptClone.removeAttribute("jsenv-plugin-action");
56
+ currentScriptClone.removeAttribute("inlined-from-src");
57
+ currentScriptClone.removeAttribute("original-position");
58
+ currentScriptClone.removeAttribute("original-src-position");
59
+ nodeToReplace = currentScript;
60
+ currentScriptClone.src = src;
61
+ }
62
+
63
+ currentScriptClone.addEventListener("error", reject);
64
+ currentScriptClone.addEventListener("load", resolve);
65
+ parentNode.replaceChild(currentScriptClone, nodeToReplace);
66
+ });
67
+
68
+ try {
69
+ await loadPromise;
70
+ } catch (e) {
71
+ // eslint-disable-next-line no-throw-literal
72
+ throw {
73
+ message: `Failed to fetch module: ${urlObject.href}`,
74
+ reportedBy: "script_error_event",
75
+ url: urlObject.href,
76
+ // window.error won't be dispatched for this error
77
+ needsReport: true
78
+ };
79
+ } // do not resolve right away, wait for top level execution
80
+
81
+
82
+ try {
83
+ const namespace = await import(urlObject.href);
84
+ return namespace;
85
+ } catch (e) {
86
+ e.reportedBy = "dynamic_import";
87
+ throw e;
88
+ }
89
+ };
90
+ };
91
+
92
+ const createExecuteWithDynamicImport = ({
93
+ src
94
+ }) => {
95
+ return async ({
96
+ isReload
97
+ }) => {
98
+ const urlObject = new URL(src, window.location);
99
+
100
+ if (isReload) {
101
+ urlObject.searchParams.set("hmr", Date.now());
102
+ }
103
+
104
+ try {
105
+ const namespace = await import(urlObject.href);
106
+ return namespace;
107
+ } catch (e) {
108
+ e.reportedBy = "dynamic_import"; // dynamic import would hide the error to the browser
109
+ // so it must be re-reported using window.reportError
110
+
111
+ if (typeof window.reportError === "function") {
112
+ window.reportError(e);
113
+ } else {
114
+ console.error(e);
115
+ }
116
+
117
+ throw e;
118
+ }
119
+ };
120
+ };
121
+
122
+ export { superviseScriptTypeModule };