@jsenv/cli 0.3.1 → 0.3.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 (150) hide show
  1. package/package.json +1 -1
  2. package/template-node-package/package.json +2 -2
  3. package/template-web/package.json +2 -2
  4. package/template-web-components/package.json +2 -2
  5. package/template-web-preact/package.json +2 -2
  6. package/template-web-react/package.json +2 -2
  7. package/template-web/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/dist/js/inline_content.js +0 -19
  8. package/template-web/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/dist/js/new_stylesheet.js +0 -320
  9. package/template-web/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/packages/internal/js-module-fallback/dist/js/s.js +0 -553
  10. package/template-web/.jsenv/craft/app/counter.js +0 -10
  11. package/template-web/.jsenv/craft/index.html +0 -26
  12. package/template-web/.jsenv/craft/jsenv_logo.svg +0 -140
  13. package/template-web/.jsenv/craft/main.css +0 -4
  14. package/template-web/.jsenv/craft/main.css7as_css_module=.js +0 -8
  15. package/template-web/.jsenv/craft/main.js +0 -14
  16. package/template-web/.jsenv/shape/@fs/Users/dmail/Documents/dev/core/packages/internal/js-module-fallback/dist/js/s.js +0 -1
  17. package/template-web/.jsenv/shape/index.html +0 -27
  18. package/template-web/.jsenv/shape/jsenv_logo.svg +0 -91
  19. package/template-web/.jsenv/shape/main.js +0 -1
  20. package/template-web/.jsenv/shape/main.nomodule7js_module_fallback=.js +0 -1
  21. package/template-web/dist/index.html +0 -27
  22. package/template-web/dist/js/main.nomodule.js +0 -1
  23. package/template-web/dist/other/jsenv_logo.svg +0 -91
  24. package/template-web-components/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/dist/js/inline_content.js +0 -19
  25. package/template-web-components/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/dist/js/new_stylesheet.js +0 -320
  26. package/template-web-components/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/packages/independent/frontend/custom-elements-redefine/src/main.js +0 -154
  27. package/template-web-components/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/packages/internal/js-module-fallback/dist/js/s.js +0 -553
  28. package/template-web-components/.jsenv/craft/app/app_custom_element.css +0 -4
  29. package/template-web-components/.jsenv/craft/app/app_custom_element.css7as_css_module=.js +0 -8
  30. package/template-web-components/.jsenv/craft/app/app_custom_element.js +0 -15
  31. package/template-web-components/.jsenv/craft/app/counter.js +0 -10
  32. package/template-web-components/.jsenv/craft/app/custom_elements_redefine.js +0 -4
  33. package/template-web-components/.jsenv/craft/index.html +0 -26
  34. package/template-web-components/.jsenv/craft/jsenv_logo.svg +0 -140
  35. package/template-web-components/.jsenv/craft/main.js +0 -9
  36. package/template-web-components/.jsenv/shape/@fs/Users/dmail/Documents/dev/core/packages/internal/js-module-fallback/dist/js/s.js +0 -1
  37. package/template-web-components/.jsenv/shape/index.html +0 -27
  38. package/template-web-components/.jsenv/shape/jsenv_logo.svg +0 -91
  39. package/template-web-components/.jsenv/shape/main.js +0 -1
  40. package/template-web-components/.jsenv/shape/main.nomodule7js_module_fallback=.js +0 -1
  41. package/template-web-components/dist/index.html +0 -27
  42. package/template-web-components/dist/js/main.nomodule.js +0 -1
  43. package/template-web-components/dist/other/jsenv_logo.svg +0 -91
  44. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/computeKey.js +0 -38
  45. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/computeKey.js.map +0 -11
  46. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/constants.js +0 -13
  47. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/index.js +0 -210
  48. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/index.js.map +0 -11
  49. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/runtime/catchError.js +0 -17
  50. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/runtime/catchError.js.map +0 -11
  51. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/runtime/debounceRendering.js +0 -21
  52. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/runtime/debounceRendering.js.map +0 -11
  53. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/runtime/signaturesForType.js +0 -2
  54. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/runtime/unmount.js +0 -20
  55. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/runtime/unmount.js.map +0 -11
  56. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/runtime/vnode.js +0 -68
  57. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/runtime/vnode.js.map +0 -11
  58. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/core/src/runtime/vnodesForComponent.js +0 -3
  59. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/@prefresh/utils/src/index.js +0 -43
  60. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/preact/debug/dist/debug.module.js +0 -2
  61. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/preact/debug/dist/debug.module.js.map +0 -181
  62. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/preact/devtools/dist/devtools.module.js +0 -2
  63. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/preact/devtools/dist/devtools.module.js.map +0 -29
  64. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/preact/dist/preact.module.js +0 -2
  65. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/preact/dist/preact.module.js.map +0 -270
  66. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/preact/hooks/dist/hooks.module.js +0 -195
  67. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/preact/hooks/dist/hooks.module.js.map +0 -168
  68. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js +0 -2
  69. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js.map +0 -77
  70. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/packages/internal/ast/src/html/html_src_set.js +0 -18
  71. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/packages/internal/plugin-supervisor/src/client/supervisor.js +0 -1360
  72. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/packages/related/plugin-preact/src/client/preact_refresh.js +0 -36
  73. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/packages/related/plugin-preact/src/client/preact_refresh.js.map +0 -11
  74. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/src/plugins/autoreload/client/autoreload.js +0 -382
  75. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/src/plugins/autoreload/client/autoreload.js.map +0 -11
  76. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/src/plugins/import_meta_hot/client/import_meta_hot.js +0 -81
  77. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/src/plugins/ribbon/client/ribbon.js +0 -93
  78. package/template-web-preact/.jsenv/chrome@131.00/@fs/Users/dmail/Documents/dev/core/src/plugins/server_events/client/server_events_client.js +0 -461
  79. package/template-web-preact/.jsenv/chrome@131.00/app/app.css +0 -43
  80. package/template-web-preact/.jsenv/chrome@131.00/app/app.jsx +0 -95
  81. package/template-web-preact/.jsenv/chrome@131.00/app/app.jsx.map +0 -44
  82. package/template-web-preact/.jsenv/chrome@131.00/app/counter.jsx +0 -45
  83. package/template-web-preact/.jsenv/chrome@131.00/app/counter.jsx.map +0 -33
  84. package/template-web-preact/.jsenv/chrome@131.00/index.html +0 -68
  85. package/template-web-preact/.jsenv/chrome@131.00/index.html@L11C7-L15C16.js +0 -5
  86. package/template-web-preact/.jsenv/chrome@131.00/index.html@L7C5-L21C13.css +0 -10
  87. package/template-web-preact/.jsenv/chrome@131.00/main.jsx +0 -10
  88. package/template-web-preact/.jsenv/chrome@131.00/main.jsx.map +0 -24
  89. package/template-web-preact/.jsenv/chrome@131.00/preact_logo.svg +0 -6
  90. package/template-web-preact/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/dist/js/inline_content.js +0 -19
  91. package/template-web-preact/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/dist/js/new_stylesheet.js +0 -320
  92. package/template-web-preact/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/node_modules/preact/dist/preact.module.js +0 -357
  93. package/template-web-preact/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/node_modules/preact/hooks/dist/hooks.module.js +0 -198
  94. package/template-web-preact/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js +0 -93
  95. package/template-web-preact/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/packages/internal/js-module-fallback/dist/js/s.js +0 -553
  96. package/template-web-preact/.jsenv/craft/app/app.css +0 -43
  97. package/template-web-preact/.jsenv/craft/app/app.css7as_css_module=.js +0 -8
  98. package/template-web-preact/.jsenv/craft/app/app.jsx +0 -46
  99. package/template-web-preact/.jsenv/craft/app/counter.jsx +0 -17
  100. package/template-web-preact/.jsenv/craft/index.html +0 -24
  101. package/template-web-preact/.jsenv/craft/main.jsx +0 -4
  102. package/template-web-preact/.jsenv/craft/preact_logo.svg +0 -6
  103. package/template-web-preact/.jsenv/shape/@fs/Users/dmail/Documents/dev/core/packages/internal/js-module-fallback/dist/js/s.js +0 -1
  104. package/template-web-preact/.jsenv/shape/index.html +0 -28
  105. package/template-web-preact/.jsenv/shape/main.jsx +0 -1
  106. package/template-web-preact/.jsenv/shape/main.nomodule7js_module_fallback=.jsx +0 -1
  107. package/template-web-preact/.jsenv/shape/preact_logo.svg +0 -6
  108. package/template-web-preact/.jsenv/shape/vendors.js +0 -1
  109. package/template-web-preact/.jsenv/shape/vendors.nomodule7js_module_fallback=.js +0 -1
  110. package/template-web-preact/dist/index.html +0 -28
  111. package/template-web-preact/dist/js/main.nomodule.js +0 -1
  112. package/template-web-preact/dist/js/vendors.nomodule.js +0 -1
  113. package/template-web-preact/dist/other/preact_logo.svg +0 -6
  114. package/template-web-react/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/dist/js/inline_content.js +0 -19
  115. package/template-web-react/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/dist/js/new_stylesheet.js +0 -320
  116. package/template-web-react/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/node_modules/react/index.js +0 -7
  117. package/template-web-react/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/node_modules/react/jsx-runtime.js +0 -7
  118. package/template-web-react/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/node_modules/react/react/jsx-runtime7cjs_as_js_module=.jsx +0 -61
  119. package/template-web-react/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/node_modules/react/react7cjs_as_js_module=.jsx +0 -635
  120. package/template-web-react/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/node_modules/react-dom/client.js +0 -34
  121. package/template-web-react/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/node_modules/react-dom/react-dom/client7cjs_as_js_module=.jsx +0 -9847
  122. package/template-web-react/.jsenv/craft/@fs/Users/dmail/Documents/dev/core/packages/internal/js-module-fallback/dist/js/s.js +0 -553
  123. package/template-web-react/.jsenv/craft/app/app.css +0 -43
  124. package/template-web-react/.jsenv/craft/app/app.css7as_css_module=.js +0 -8
  125. package/template-web-react/.jsenv/craft/app/app.jsx +0 -46
  126. package/template-web-react/.jsenv/craft/app/counter.jsx +0 -16
  127. package/template-web-react/.jsenv/craft/cjs_to_esm/@fs/Users/dmail/Documents/dev/core/node_modules/react/index.production.js +0 -824
  128. package/template-web-react/.jsenv/craft/cjs_to_esm/@fs/Users/dmail/Documents/dev/core/node_modules/react/index.production.js__compile_info__.json +0 -26
  129. package/template-web-react/.jsenv/craft/cjs_to_esm/@fs/Users/dmail/Documents/dev/core/node_modules/react/index.production.map +0 -1
  130. package/template-web-react/.jsenv/craft/cjs_to_esm/@fs/Users/dmail/Documents/dev/core/node_modules/react/jsx-runtime.production.js +0 -69
  131. package/template-web-react/.jsenv/craft/cjs_to_esm/@fs/Users/dmail/Documents/dev/core/node_modules/react/jsx-runtime.production.js__compile_info__.json +0 -18
  132. package/template-web-react/.jsenv/craft/cjs_to_esm/@fs/Users/dmail/Documents/dev/core/node_modules/react/jsx-runtime.production.map +0 -1
  133. package/template-web-react/.jsenv/craft/cjs_to_esm/@fs/Users/dmail/Documents/dev/core/node_modules/react-dom/client.production.js +0 -16066
  134. package/template-web-react/.jsenv/craft/cjs_to_esm/@fs/Users/dmail/Documents/dev/core/node_modules/react-dom/client.production.js__compile_info__.json +0 -42
  135. package/template-web-react/.jsenv/craft/cjs_to_esm/@fs/Users/dmail/Documents/dev/core/node_modules/react-dom/client.production.map +0 -1
  136. package/template-web-react/.jsenv/craft/cjs_to_esm/__compile_context__.json +0 -3
  137. package/template-web-react/.jsenv/craft/index.html +0 -24
  138. package/template-web-react/.jsenv/craft/main.jsx +0 -10
  139. package/template-web-react/.jsenv/craft/react_logo.svg +0 -7
  140. package/template-web-react/.jsenv/shape/@fs/Users/dmail/Documents/dev/core/packages/internal/js-module-fallback/dist/js/s.js +0 -1
  141. package/template-web-react/.jsenv/shape/index.html +0 -28
  142. package/template-web-react/.jsenv/shape/main.jsx +0 -1
  143. package/template-web-react/.jsenv/shape/main.nomodule7js_module_fallback=.jsx +0 -1
  144. package/template-web-react/.jsenv/shape/react_logo.svg +0 -7
  145. package/template-web-react/.jsenv/shape/vendors.js +0 -1
  146. package/template-web-react/.jsenv/shape/vendors.nomodule7js_module_fallback=.js +0 -1
  147. package/template-web-react/dist/index.html +0 -28
  148. package/template-web-react/dist/js/main.nomodule.js +0 -1
  149. package/template-web-react/dist/js/vendors.nomodule.js +0 -1
  150. package/template-web-react/dist/other/react_logo.svg +0 -7
@@ -1,1360 +0,0 @@
1
- window.__supervisor__ = (() => {
2
- const notImplemented = () => {
3
- throw new Error(`window.__supervisor__.setup() not called`);
4
- };
5
- const supervisor = {
6
- reportException: notImplemented,
7
- superviseScript: notImplemented,
8
- superviseScriptTypeModule: notImplemented,
9
- reloadSupervisedScript: notImplemented,
10
- getDocumentExecutionResult: notImplemented,
11
- };
12
- const isWebkitOrSafari =
13
- typeof window.webkitConvertPointFromNodeToPage === "function";
14
-
15
- const executionResults = {};
16
- let documentTimingsOrigin;
17
- try {
18
- documentTimingsOrigin = window.performance.timing.navigationStart;
19
- } catch {
20
- documentTimingsOrigin = Date.now();
21
- }
22
- const documentTimings = {
23
- origin: documentTimingsOrigin,
24
- start: Date.now() - documentTimingsOrigin,
25
- end: null,
26
- };
27
-
28
- supervisor.setup = ({
29
- rootDirectoryUrl,
30
- scriptInfos,
31
- serverIsJsenvDevServer,
32
- logs,
33
- errorOverlay,
34
- errorBaseUrl,
35
- openInEditor,
36
- }) => {
37
- const executions = {};
38
- const promises = [];
39
- let remainingScriptCount = scriptInfos.length;
40
-
41
- // respect execution order
42
- // - wait for classic scripts to be done (non async)
43
- // - wait module script previous execution (non async)
44
- // see https://gist.github.com/jakub-g/385ee6b41085303a53ad92c7c8afd7a6#typemodule-vs-non-module-typetextjavascript-vs-script-nomodule
45
- const executionQueue = [];
46
- let executing = false;
47
- const addToExecutionQueue = async (execution) => {
48
- if (execution.async) {
49
- execution.execute();
50
- return;
51
- }
52
- if (executing) {
53
- executionQueue.push(execution);
54
- return;
55
- }
56
- execThenDequeue(execution);
57
- };
58
- const execThenDequeue = async (execution) => {
59
- executing = true;
60
- // start next js module execution as soon as current js module starts to execute
61
- // (do not wait in case of top level await)
62
- let resolveExecutingPromise;
63
- const executingPromise = new Promise((resolve) => {
64
- resolveExecutingPromise = resolve;
65
- });
66
- const promise = execution.execute({
67
- onExecuting: () => resolveExecutingPromise(),
68
- });
69
- await Promise.race([promise, executingPromise]);
70
- executing = false;
71
- if (executionQueue.length) {
72
- const nextExecution = executionQueue.shift();
73
- execThenDequeue(nextExecution);
74
- }
75
- };
76
-
77
- const asExecutionId = (src) => {
78
- const url = new URL(src, window.location).href;
79
- if (url.startsWith(window.location.origin)) {
80
- return src;
81
- }
82
- return url;
83
- };
84
-
85
- const createExecutionController = (src, type) => {
86
- const result = {
87
- status: "pending",
88
- coverage: null,
89
- exception: null,
90
- value: null,
91
- timings: {
92
- start: null,
93
- end: null,
94
- },
95
- };
96
-
97
- let resolve;
98
- const promise = new Promise((_resolve) => {
99
- resolve = _resolve;
100
- });
101
- promises.push(promise);
102
- executionResults[src] = result;
103
-
104
- const start = () => {
105
- result.timings.start = Date.now() - documentTimingsOrigin;
106
- result.coverage = null;
107
- result.status = "started";
108
- result.exception = null;
109
- if (logs) {
110
- console.group(`[jsenv] ${src} execution started (${type})`);
111
- }
112
- };
113
- const end = () => {
114
- remainingScriptCount--;
115
- result.timings.end = Date.now() - documentTimingsOrigin;
116
- result.coverage = window.__coverage__;
117
- if (logs) {
118
- console.log(`execution ${result.status}`);
119
- console.groupEnd();
120
- }
121
- if (remainingScriptCount === 0) {
122
- documentTimings.end = Date.now() - documentTimingsOrigin;
123
- }
124
- resolve();
125
- };
126
- const complete = () => {
127
- result.status = "completed";
128
- end();
129
- };
130
- const fail = (error, info) => {
131
- result.status = "failed";
132
- const exception = supervisor.createException(error, info);
133
- result.exception = exception;
134
- end();
135
- };
136
-
137
- return { result, start, complete, fail };
138
- };
139
-
140
- const prepareJsClassicRemoteExecution = (src) => {
141
- const urlObject = new URL(src, window.location);
142
- const url = urlObject.href;
143
- const { result, start, complete, fail } = createExecutionController(
144
- src,
145
- "js_classic",
146
- );
147
-
148
- let parentNode;
149
- let currentScript;
150
- let nodeToReplace;
151
- let currentScriptClone;
152
- const init = () => {
153
- currentScript = document.currentScript;
154
- parentNode = currentScript.parentNode;
155
- executions[src].async = currentScript.async;
156
- };
157
- const execute = async ({ isReload } = {}) => {
158
- start();
159
- currentScriptClone = prepareScriptToLoad(currentScript);
160
- if (isReload) {
161
- urlObject.searchParams.set("hot", Date.now());
162
- nodeToReplace = currentScriptClone;
163
- currentScriptClone.src = urlObject.href;
164
- } else {
165
- nodeToReplace = currentScript;
166
- currentScriptClone.src = url;
167
- }
168
- const scriptLoadPromise = getScriptLoadPromise(currentScriptClone);
169
- parentNode.replaceChild(currentScriptClone, nodeToReplace);
170
- const { detectedBy, failed, errorEvent } = await scriptLoadPromise;
171
- if (failed) {
172
- const messageDefault = `Error while loading script`;
173
- const { error, message, filename, lineno, colno } = errorEvent;
174
- if (detectedBy === "script_error_event") {
175
- // window.error won't be dispatched for this error
176
- reportErrorBackToBrowser(error || errorEvent);
177
- }
178
- fail(error || message || messageDefault, {
179
- message: messageDefault,
180
- reportedBy: "script_error_event",
181
- url: filename || urlObject.href,
182
- line: lineno,
183
- column: colno,
184
- });
185
- if (detectedBy === "script_error_event") {
186
- supervisor.reportException(result.exception);
187
- }
188
- } else {
189
- complete();
190
- }
191
- return result;
192
- };
193
- executions[src] = { init, execute };
194
- };
195
- const prepareJsClassicInlineExecution = (src) => {
196
- const { start, complete, fail } = createExecutionController(
197
- src,
198
- "js_classic",
199
- );
200
- const end = complete;
201
- const error = (e) => {
202
- reportErrorBackToBrowser(e); // supervision shallowed the error, report back to browser
203
- fail(e);
204
- };
205
- executions[src] = { isInline: true, start, end, error };
206
- };
207
-
208
- // https://twitter.com/damienmaillard/status/1554752482273787906
209
- const prepareJsModuleExecutionWithDynamicImport = (src) => {
210
- const urlObject = new URL(src, window.location);
211
- const { result, start, complete, fail } = createExecutionController(
212
- src,
213
- "js_classic",
214
- );
215
-
216
- let importFn;
217
- let currentScript;
218
- const init = (_importFn) => {
219
- importFn = _importFn;
220
- currentScript = document.querySelector(
221
- `script[type="module"][inlined-from-src="${src}"]`,
222
- );
223
- executions[src].async = currentScript.async;
224
- };
225
- const execute = async ({ isReload } = {}) => {
226
- start();
227
- if (isReload) {
228
- urlObject.searchParams.set("hot", Date.now());
229
- }
230
- try {
231
- const namespace = await importFn(urlObject.href);
232
- complete(namespace);
233
- return result;
234
- } catch (e) {
235
- fail(e, {
236
- message: `Error while importing module`,
237
- reportedBy: "dynamic_import",
238
- url: urlObject.href,
239
- });
240
- if (isWebkitOrSafari) {
241
- supervisor.reportException(result.exception);
242
- }
243
- return result;
244
- }
245
- };
246
- executions[src] = { init, execute };
247
- };
248
- const prepareJsModuleExecutionWithScriptThenDynamicImport = (src) => {
249
- const urlObject = new URL(src, window.location);
250
- const { result, start, complete, fail } = createExecutionController(
251
- src,
252
- "js_module",
253
- );
254
-
255
- let importFn;
256
- let currentScript;
257
- let parentNode;
258
- let nodeToReplace;
259
- let currentScriptClone;
260
- const init = (_importFn) => {
261
- importFn = _importFn;
262
- currentScript = document.querySelector(
263
- `script[type="module"][inlined-from-src="${src}"]`,
264
- );
265
- parentNode = currentScript.parentNode;
266
- executions[src].async = currentScript.async;
267
- };
268
- const execute = async ({ isReload, onExecuting = () => {} } = {}) => {
269
- start();
270
- currentScriptClone = prepareScriptToLoad(currentScript);
271
- if (isReload) {
272
- urlObject.searchParams.set("hot", Date.now());
273
- nodeToReplace = currentScriptClone;
274
- currentScriptClone.src = urlObject.href;
275
- } else {
276
- nodeToReplace = currentScript;
277
- currentScriptClone.src = urlObject.href;
278
- }
279
- const scriptLoadResultPromise =
280
- getScriptLoadPromise(currentScriptClone);
281
- parentNode.replaceChild(currentScriptClone, nodeToReplace);
282
- const { detectedBy, failed, errorEvent } =
283
- await scriptLoadResultPromise;
284
-
285
- if (failed) {
286
- const messageDefault = `Error while loading module`;
287
- const { error, message, filename, lineno, colno } = errorEvent;
288
- // if (detectedBy === "script_error_event") {
289
- // reportErrorBackToBrowser(error)
290
- // }
291
- fail(error || message || messageDefault, {
292
- message: messageDefault,
293
- reportedBy: "script_error_event",
294
- url: filename || urlObject.href,
295
- line: lineno,
296
- column: colno,
297
- });
298
- if (detectedBy === "script_error_event") {
299
- supervisor.reportException(result.exception);
300
- }
301
- return result;
302
- }
303
-
304
- onExecuting();
305
- result.status = "executing";
306
- if (logs) {
307
- console.log(`load ended`);
308
- }
309
- try {
310
- const namespace = await importFn(urlObject.href);
311
- complete(namespace);
312
- return result;
313
- } catch (e) {
314
- fail(e, {
315
- message: `Error while importing module: ${urlObject.href}`,
316
- reportedBy: "dynamic_import",
317
- url: urlObject.href,
318
- });
319
- return result;
320
- }
321
- };
322
- executions[src] = { init, execute };
323
- };
324
- const prepareJsModuleRemoteExecution = isWebkitOrSafari
325
- ? prepareJsModuleExecutionWithDynamicImport
326
- : prepareJsModuleExecutionWithScriptThenDynamicImport;
327
- const prepareJsModuleInlineExecution = (src) => {
328
- const { start, complete, fail } = createExecutionController(
329
- src,
330
- "js_module",
331
- );
332
- const end = complete;
333
- const error = (e) => {
334
- // supervision shallowed the error, report back to browser
335
- reportErrorBackToBrowser(e);
336
- fail(e);
337
- };
338
- executions[src] = { isInline: true, start, end, error };
339
- };
340
-
341
- supervisor.setupReportException({
342
- logs,
343
- serverIsJsenvDevServer,
344
- rootDirectoryUrl,
345
- errorOverlay,
346
- errorBaseUrl,
347
- openInEditor,
348
- });
349
-
350
- scriptInfos.forEach((scriptInfo) => {
351
- const { type, src, isInline } = scriptInfo;
352
- if (type === "js_module") {
353
- if (isInline) {
354
- prepareJsModuleInlineExecution(src);
355
- } else {
356
- prepareJsModuleRemoteExecution(src);
357
- }
358
- } else if (isInline) {
359
- prepareJsClassicInlineExecution(src);
360
- } else {
361
- prepareJsClassicRemoteExecution(src);
362
- }
363
- });
364
-
365
- // js classic
366
- supervisor.jsClassicStart = (inlineSrc) => {
367
- executions[inlineSrc].start();
368
- };
369
- supervisor.jsClassicEnd = (inlineSrc) => {
370
- executions[inlineSrc].end();
371
- };
372
- supervisor.jsClassicError = (inlineSrc, e) => {
373
- executions[inlineSrc].error(e);
374
- };
375
- supervisor.superviseScript = (src) => {
376
- const execution = executions[asExecutionId(src)];
377
- execution.init();
378
- return addToExecutionQueue(execution);
379
- };
380
- // js module
381
- supervisor.jsModuleStart = (inlineSrc) => {
382
- executions[inlineSrc].start();
383
- };
384
- supervisor.jsModuleEnd = (inlineSrc) => {
385
- executions[inlineSrc].end();
386
- };
387
- supervisor.jsModuleError = (inlineSrc, e) => {
388
- executions[inlineSrc].error(e);
389
- };
390
- supervisor.superviseScriptTypeModule = (src, importFn) => {
391
- const execution = executions[asExecutionId(src)];
392
- execution.init(importFn);
393
- return addToExecutionQueue(execution);
394
- };
395
-
396
- supervisor.reloadSupervisedScript = (src) => {
397
- const execution = executions[src];
398
- if (!execution) {
399
- throw new Error(`no execution for ${src}`);
400
- }
401
- if (execution.isInline) {
402
- throw new Error(`cannot reload inline script ${src}`);
403
- }
404
- return execution.execute({ isReload: true });
405
- };
406
-
407
- supervisor.getDocumentExecutionResult = async () => {
408
- await Promise.all(promises);
409
- return {
410
- timings: documentTimings,
411
- status: "completed",
412
- executionResults,
413
- };
414
- };
415
- };
416
- const reportErrorBackToBrowser = (error) => {
417
- if (typeof window.reportError === "function") {
418
- window.reportError(error);
419
- } else {
420
- console.error(error);
421
- }
422
- };
423
-
424
- supervisor.setupReportException = ({
425
- logs,
426
- rootDirectoryUrl,
427
- serverIsJsenvDevServer,
428
- errorNotification,
429
- errorOverlay,
430
- errorBaseUrl,
431
- openInEditor,
432
- }) => {
433
- const DYNAMIC_IMPORT_FETCH_ERROR = "dynamic_import_fetch_error";
434
- const DYNAMIC_IMPORT_EXPORT_MISSING = "dynamic_import_export_missing";
435
- const DYNAMIC_IMPORT_SYNTAX_ERROR = "dynamic_import_syntax_error";
436
-
437
- const createException = (
438
- reason, // can be error, string, object
439
- { message, reportedBy, url, line, column } = {},
440
- ) => {
441
- const exception = {
442
- runtime: "browser",
443
- reason,
444
- isException: true,
445
- isError: false, // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw
446
- reportedBy,
447
- code: null,
448
- name: null,
449
- message: null,
450
- stack: "", // the stack v8 format
451
- stackSourcemapped: null,
452
- stackOriginal: "", // the stack from runtime, not normalized to v8
453
- stackTrace: "", // the stack trace (without error name and message)
454
- stackFrames: undefined,
455
- withServerUrls: {
456
- message: "",
457
- stack: "",
458
- stackTrace: "",
459
- },
460
- meta: null,
461
- site: {
462
- ownerSite: null,
463
- isInline: null,
464
- url: null,
465
- line: null,
466
- column: null,
467
- },
468
- };
469
-
470
- const writeBasicProperties = () => {
471
- if (reason === undefined) {
472
- exception.message = "undefined";
473
- return;
474
- }
475
- if (reason === null) {
476
- exception.message = "null";
477
- return;
478
- }
479
- if (typeof reason === "string") {
480
- exception.message = reason;
481
- return;
482
- }
483
- if (typeof reason !== "object") {
484
- exception.message = JSON.stringify(reason);
485
- return;
486
- }
487
- // isError can be false when reason is an ErrorEvent for instance
488
- exception.isError = reason instanceof Error;
489
- exception.name = getErrorName(reason);
490
- exception.message = reason.message || message || "";
491
-
492
- let stackFrames;
493
- if (
494
- exception.isError &&
495
- Error.captureStackTrace &&
496
- // captureStackTrace exists on webkit but error.stack is not v8
497
- !isWebkitOrSafari
498
- ) {
499
- // stackTrace formatted by V8
500
- const { prepareStackTrace } = Error;
501
- Error.prepareStackTrace = (e, callSites) => {
502
- Error.prepareStackTrace = prepareStackTrace;
503
-
504
- const getPropertiesFromEvalOrigin = (origin) => {
505
- // Most eval() calls are in this format
506
- const topLevelEvalMatch = /^eval at [^(]+ \(.+:\d+:\d+\)$/.exec(
507
- origin,
508
- );
509
- if (topLevelEvalMatch) {
510
- const source = topLevelEvalMatch[2];
511
- const line = Number(topLevelEvalMatch[3]);
512
- const column = topLevelEvalMatch[4] - 1;
513
- return {
514
- url: source,
515
- line,
516
- column,
517
- };
518
- }
519
- // Parse nested eval() calls using recursion
520
- const nestedEvalMatch = /^eval at [^(]+ \(.+\)$/.exec(origin);
521
- if (nestedEvalMatch) {
522
- return getPropertiesFromEvalOrigin(nestedEvalMatch[2]);
523
- }
524
- return null;
525
- };
526
-
527
- stackFrames = [];
528
- for (const callSite of callSites) {
529
- const url =
530
- callSite.getFileName() || callSite.getScriptNameOrSourceURL();
531
- if (!url) {
532
- // thinks like Array.forEach can generate this
533
- const stackFrame = {
534
- raw: ` at ${String(callSite)}`,
535
- url: null,
536
- line: null,
537
- column: null,
538
- };
539
- stackFrames.push(stackFrame);
540
- continue;
541
- }
542
- const line = callSite.getLineNumber();
543
- const column = callSite.getColumnNumber();
544
- const site = resolveUrlSite({ url, line, column });
545
- const stackFrame = {
546
- raw: ` at ${String(callSite)}`,
547
- url: site.url,
548
- line: site.line,
549
- column: site.column,
550
- functionName: callSite.getFunctionName(),
551
- isNative: callSite.isNative(),
552
- isEval: callSite.isEval(),
553
- isConstructor: callSite.isConstructor(),
554
- isAsync: callSite.isAsync(),
555
- evalSite: null,
556
- };
557
- if (stackFrame.isEval) {
558
- const evalOrigin = stackFrame.getEvalOrigin();
559
- if (evalOrigin) {
560
- stackFrame.evalSite = getPropertiesFromEvalOrigin(evalOrigin);
561
- }
562
- }
563
- stackFrames.push(stackFrame);
564
- }
565
- let stackTrace = "";
566
- for (const stackFrame of stackFrames) {
567
- if (stackTrace) stackTrace += "\n";
568
- stackTrace += stackFrame.raw;
569
- }
570
- exception.stackTrace = stackTrace;
571
-
572
- let stack = "";
573
- const name = getErrorName(reason);
574
- const message = reason.message || "";
575
- stack += `${name}: ${message}`;
576
- if (stackTrace) {
577
- stack += `\n${stackTrace}`;
578
- }
579
- return stack;
580
- };
581
-
582
- exception.stackSourcemapped = true;
583
- exception.stack = reason.stack;
584
- if (stackFrames === undefined) {
585
- // Error.prepareStackTrace not trigerred
586
- // - reason is not an error
587
- // - reason.stack already get
588
- Error.prepareStackTrace = prepareStackTrace;
589
- exception.stackTrace = getErrorStackTrace(reason);
590
- } else {
591
- exception.stackFrames = stackFrames;
592
- const [firstCallFrame] = stackFrames;
593
- if (
594
- exception.site.url === null &&
595
- firstCallFrame &&
596
- firstCallFrame.url
597
- ) {
598
- Object.assign(exception.site, {
599
- url: firstCallFrame.url,
600
- line: firstCallFrame.line,
601
- column: firstCallFrame.column,
602
- });
603
- }
604
- }
605
- } else {
606
- exception.stackSourcemapped = false;
607
- exception.stackTrace = reason.stack;
608
- exception.stack = stringifyStack(exception);
609
- }
610
-
611
- if (exception.site.url === null && reason.url) {
612
- Object.assign(exception.site, resolveUrlSite({ url: reason.url }));
613
- }
614
- export_missing: {
615
- // chrome
616
- if (exception.message.includes("does not provide an export named")) {
617
- exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
618
- }
619
- // firefox
620
- if (
621
- exception.message.startsWith("import not found:") ||
622
- exception.message.startsWith("ambiguous indirect export:") ||
623
- exception.message.includes("doesn't provide an export named:")
624
- ) {
625
- exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
626
- }
627
- // safari
628
- if (exception.message.startsWith("import binding name")) {
629
- exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
630
- }
631
- if (exception.message.includes("Importing a module script failed")) {
632
- exception.code = DYNAMIC_IMPORT_FETCH_ERROR;
633
- }
634
- }
635
- js_syntax_error: {
636
- if (
637
- !exception.code &&
638
- exception.name === "SyntaxError" &&
639
- typeof line === "number"
640
- ) {
641
- exception.code = DYNAMIC_IMPORT_SYNTAX_ERROR;
642
- }
643
- }
644
- };
645
- writeBasicProperties();
646
-
647
- // then if it fails, use url+line+column passed
648
- if (exception.site.url === null && url) {
649
- if (typeof line === "string") {
650
- line = parseInt(line);
651
- }
652
- if (typeof column === "string") {
653
- column = parseInt(column);
654
- }
655
- const fileUrlSite = resolveUrlSite({ url, line, column });
656
- const decreaseLine = () => {
657
- const { ownerSite } = fileUrlSite;
658
- if (ownerSite) {
659
- if (typeof ownerSite.line === "number") {
660
- ownerSite.line = fileUrlSite.ownerSite.line - 1;
661
- }
662
- }
663
- if (typeof fileUrlSite.line === "number") {
664
- fileUrlSite.line = fileUrlSite.line - 1;
665
- }
666
- };
667
- if (fileUrlSite.isInline) {
668
- // chrome
669
- if (Error.captureStackTrace && !isWebkitOrSafari) {
670
- }
671
- // firefox and webkit
672
- else if (exception.name === "SyntaxError") {
673
- if (
674
- exception.code === DYNAMIC_IMPORT_EXPORT_MISSING ||
675
- exception.code === DYNAMIC_IMPORT_SYNTAX_ERROR
676
- ) {
677
- decreaseLine();
678
- } else {
679
- decreaseLine();
680
- decreaseLine();
681
- }
682
- } else {
683
- decreaseLine();
684
- }
685
- }
686
- Object.assign(exception.site, fileUrlSite);
687
- }
688
-
689
- exception.withServerUrls.message = exception.message;
690
- exception.withServerUrls.stackTrace = exception.stackTrace;
691
- exception.withServerUrls.stack = exception.stack;
692
- exception.message = exception.message
693
- ? replaceUrls(exception.message, (serverUrlSite) => {
694
- const fileUrlSite = resolveUrlSite(serverUrlSite);
695
- return stringifyUrlSite(fileUrlSite);
696
- })
697
- : "";
698
- exception.stackTrace = exception.stackTrace
699
- ? replaceUrls(exception.stackTrace, (serverUrlSite) => {
700
- const fileUrlSite = resolveUrlSite(serverUrlSite);
701
- if (exception.site.url === null) {
702
- Object.assign(exception.site, fileUrlSite);
703
- }
704
- return stringifyUrlSite(fileUrlSite);
705
- })
706
- : "";
707
- exception.stack = stringifyStack({
708
- name: exception.name,
709
- message: exception.message,
710
- stackTrace: exception.stackTrace,
711
- });
712
- exception.text = stringifyStack({
713
- name: exception.name,
714
- message: exception.message,
715
- stackTrace: exception.stackTrace,
716
- });
717
- return exception;
718
- };
719
-
720
- const stringifyStack = ({ codeFrame, name, message, stackTrace }) => {
721
- const parts = [];
722
- if (codeFrame) {
723
- parts.push(codeFrame);
724
- }
725
- if (name && message) {
726
- parts.push(`${name}: ${message}`);
727
- } else if (message) {
728
- parts.push(message);
729
- }
730
- if (stackTrace) {
731
- parts.push(stackTrace);
732
- }
733
- return parts.join("\n");
734
- };
735
-
736
- const stringifyUrlSite = ({ url, line, column }) => {
737
- if (typeof line === "number" && typeof column === "number") {
738
- return `${url}:${line}:${column}`;
739
- }
740
- if (typeof line === "number") {
741
- return `${url}:${line}`;
742
- }
743
- return url;
744
- };
745
-
746
- const resolveUrlSite = ({ url, line, column }) => {
747
- const inlineUrlMatch = url.match(
748
- /@L([0-9]+)C([0-9]+)-L([0-9]+)C([0-9]+)(\.\w+)$/,
749
- );
750
- if (inlineUrlMatch) {
751
- const htmlUrl = url.slice(0, inlineUrlMatch.index);
752
- const tagLineStart = parseInt(inlineUrlMatch[1]);
753
- const tagColumnStart = parseInt(inlineUrlMatch[2]);
754
- const tagLineEnd = parseInt(inlineUrlMatch[3]);
755
- const tagColumnEnd = parseInt(inlineUrlMatch[4]);
756
- const extension = inlineUrlMatch[5];
757
- url = htmlUrl;
758
- const fileUrl = resolveFileUrl(url);
759
- const ownerSiteUrl = `${fileUrl}@L${tagLineStart}C${tagColumnStart}-L${tagLineEnd}C${tagColumnEnd}${extension}`;
760
- const ownerSite = {
761
- url: ownerSiteUrl,
762
- ownerLine: tagLineStart,
763
- ownerColumn: tagColumnStart,
764
- inlineLine: typeof line === "number" ? line - 1 : undefined,
765
- inlineColumn: column,
766
- };
767
- return {
768
- ownerSite,
769
- isInline: true,
770
- serverUrl: url,
771
- url: fileUrl,
772
- line:
773
- typeof ownerSite.inlineLine === "number"
774
- ? ownerSite.ownerLine + ownerSite.inlineLine
775
- : ownerSite.ownerLine,
776
- column:
777
- typeof ownerSite.inlineColumn === "number"
778
- ? ownerSite.inlineColumn
779
- : ownerSite.ownerColumn,
780
- };
781
- }
782
- return {
783
- isInline: false,
784
- serverUrl: url,
785
- url: resolveFileUrl(url),
786
- line,
787
- column,
788
- };
789
- };
790
-
791
- const getErrorStackTrace = (error) => {
792
- let stack = error.stack;
793
- if (!stack) return "";
794
- const name = getErrorName(error);
795
- const messageInStack = `${name}: ${error.message}`;
796
- if (stack.startsWith(messageInStack)) {
797
- stack = stack.slice(messageInStack.length);
798
- }
799
- const nextLineIndex = stack.indexOf("\n");
800
- if (nextLineIndex > -1) {
801
- stack = stack.slice(nextLineIndex + 1);
802
- }
803
- return stack;
804
- };
805
-
806
- const resolveFileUrl = (url) => {
807
- let urlObject;
808
- try {
809
- urlObject = new URL(url, window.origin);
810
- } catch {
811
- return url;
812
- }
813
- if (urlObject.origin === window.origin) {
814
- urlObject = new URL(
815
- `${urlObject.pathname.slice(1)}${urlObject.search}`,
816
- rootDirectoryUrl,
817
- );
818
- }
819
- if (urlObject.href.startsWith("file:")) {
820
- const atFsIndex = urlObject.pathname.indexOf("/@fs/");
821
- if (atFsIndex > -1) {
822
- const afterAtFs = urlObject.pathname.slice(
823
- atFsIndex + "/@fs/".length,
824
- );
825
- return new URL(afterAtFs, "file:///").href;
826
- }
827
- }
828
- return urlObject.href;
829
- };
830
-
831
- // `Error: yo
832
- // at Object.execute (http://127.0.0.1:57300/build/src/__test__/file-throw.js:9:13)
833
- // at doExec (http://127.0.0.1:3000/src/__test__/file-throw.js:452:38)
834
- // at postOrderExec (http://127.0.0.1:3000/src/__test__/file-throw.js:448:16)
835
- // at http://127.0.0.1:3000/src/__test__/file-throw.js:399:18`.replace(/(?:https?|ftp|file):\/\/(.*+)$/gm, (...args) => {
836
- // debugger
837
- // })
838
- const replaceUrls = (source, replace) => {
839
- return source.replace(/(?:https?|ftp|file):\/\/\S+/g, (match) => {
840
- let replacement = "";
841
- const lastChar = match[match.length - 1];
842
-
843
- // hotfix because our url regex sucks a bit
844
- const endsWithSeparationChar = lastChar === ")" || lastChar === ":";
845
- if (endsWithSeparationChar) {
846
- match = match.slice(0, -1);
847
- }
848
-
849
- const lineAndColumnPattern = /:([0-9]+):([0-9]+)$/;
850
- const lineAndColumMatch = match.match(lineAndColumnPattern);
851
- if (lineAndColumMatch) {
852
- const lineAndColumnString = lineAndColumMatch[0];
853
- const lineString = lineAndColumMatch[1];
854
- const columnString = lineAndColumMatch[2];
855
- replacement = replace({
856
- url: match.slice(0, -lineAndColumnString.length),
857
- line: lineString ? parseInt(lineString) : null,
858
- column: columnString ? parseInt(columnString) : null,
859
- });
860
- } else {
861
- const linePattern = /:([0-9]+)$/;
862
- const lineMatch = match.match(linePattern);
863
- if (lineMatch) {
864
- const lineString = lineMatch[0];
865
- replacement = replace({
866
- url: match.slice(0, -lineString.length),
867
- line: parseInt(lineMatch[1]),
868
- });
869
- } else {
870
- replacement = replace({
871
- url: match,
872
- });
873
- }
874
- }
875
- if (endsWithSeparationChar) {
876
- return `${replacement}${lastChar}`;
877
- }
878
- return replacement;
879
- });
880
- };
881
-
882
- let displayErrorNotification;
883
- error_notification: {
884
- const { Notification } = window;
885
- displayErrorNotification =
886
- typeof Notification === "function"
887
- ? ({ title, text, icon }) => {
888
- if (Notification.permission === "granted") {
889
- const notification = new Notification(title, {
890
- lang: "en",
891
- body: text,
892
- icon,
893
- });
894
- notification.onclick = () => {
895
- window.focus();
896
- };
897
- }
898
- }
899
- : () => {};
900
- }
901
-
902
- const JSENV_ERROR_OVERLAY_TAGNAME = "jsenv-error-overlay";
903
- let displayJsenvErrorOverlay;
904
- error_overlay: {
905
- displayJsenvErrorOverlay = (params) => {
906
- if (logs) {
907
- console.log("display jsenv error overlay", params);
908
- }
909
- let jsenvErrorOverlay = new JsenvErrorOverlay(params);
910
- document
911
- .querySelectorAll(JSENV_ERROR_OVERLAY_TAGNAME)
912
- .forEach((node) => {
913
- node.parentNode.removeChild(node);
914
- });
915
-
916
- const appendIntoRespectingLineBreaksAndIndentation = (
917
- node,
918
- parentNode,
919
- { indent = 2 } = {},
920
- ) => {
921
- const indentMinusOne = " ".repeat(indent - 1);
922
- const desiredIndent = " ".repeat(indent);
923
- const previousSibling =
924
- parentNode.childNodes[parentNode.childNodes.length - 1];
925
- if (previousSibling && previousSibling.nodeName === "#text") {
926
- if (previousSibling.nodeValue === `\n${indentMinusOne}`) {
927
- previousSibling.nodeValue = `\n${desiredIndent}`;
928
- }
929
- if (previousSibling.nodeValue !== `\n${desiredIndent}`) {
930
- previousSibling.nodeValue = `\n${desiredIndent}`;
931
- }
932
- } else {
933
- parentNode.appendChild(
934
- document.createTextNode(`\n${desiredIndent}`),
935
- );
936
- }
937
- parentNode.appendChild(node);
938
- };
939
- appendIntoRespectingLineBreaksAndIndentation(
940
- jsenvErrorOverlay,
941
- document.body,
942
- );
943
- const removeErrorOverlay = () => {
944
- if (jsenvErrorOverlay && jsenvErrorOverlay.parentNode) {
945
- document.body.removeChild(jsenvErrorOverlay);
946
- jsenvErrorOverlay = null;
947
- }
948
- };
949
- return removeErrorOverlay;
950
- };
951
-
952
- class JsenvErrorOverlay extends HTMLElement {
953
- constructor(exception) {
954
- super();
955
- const root = this.attachShadow({ mode: "open" });
956
- const tips = [];
957
- tips.push("Click outside to close.");
958
- const tip = tips.join(`\n <br />\n `);
959
- root.innerHTML = `
960
- <style>
961
- ${overlayCSS}
962
- </style>
963
- <div class="backdrop"></div>
964
- <div class="overlay" data-theme="dark">
965
- <h1 class="title">
966
- An error occured
967
- </h1>
968
- <pre class="text"></pre>
969
- <div class="tip">
970
- ${tip}
971
- </div>
972
- </div>`;
973
- root.querySelector(".backdrop").onclick = () => {
974
- if (!this.parentNode) {
975
- // not in document anymore
976
- return;
977
- }
978
- root.querySelector(".backdrop").onclick = null;
979
- this.parentNode.removeChild(this);
980
- };
981
-
982
- const renderException = () => {
983
- const { cause = {} } = exception;
984
- const { trace = {} } = cause;
985
- const dataToRender =
986
- cause.code === "MODULE_NOT_FOUND" ? cause : exception;
987
- root.querySelector(".text").innerHTML = stringifyStack({
988
- codeFrame: trace.codeFrame
989
- ? generateClickableText(trace.codeFrame)
990
- : "",
991
- name: dataToRender.name,
992
- message:
993
- cause.code === "MODULE_NOT_FOUND"
994
- ? generateClickableText(dataToRender.reason)
995
- : dataToRender.message
996
- ? generateClickableText(dataToRender.message)
997
- : "",
998
- stackTrace: dataToRender.stackTrace
999
- ? generateClickableText(dataToRender.stackTrace)
1000
- : "",
1001
- });
1002
- if (cause && dataToRender === exception) {
1003
- const causeText = stringifyStack({
1004
- name: getErrorName(cause),
1005
- message: cause.reason
1006
- ? generateClickableText(cause.reason)
1007
- : cause.stack
1008
- ? generateClickableText(cause.stack)
1009
- : "",
1010
- });
1011
- if (causeText) {
1012
- const causeTextIndented = prefixRemainingLines(causeText, " ");
1013
- root.querySelector(".text").innerHTML +=
1014
- `\n [cause]: ${causeTextIndented}`;
1015
- }
1016
- }
1017
- if (
1018
- !exception.stackTrace &&
1019
- (exception.reportedBy === "script_error_event" ||
1020
- exception.reportedBy === "window_error_event" ||
1021
- exception.name === "SyntaxError" ||
1022
- exception.code === DYNAMIC_IMPORT_FETCH_ERROR ||
1023
- exception.code === DYNAMIC_IMPORT_EXPORT_MISSING ||
1024
- exception.code === DYNAMIC_IMPORT_SYNTAX_ERROR)
1025
- ) {
1026
- let traceSite = stringifyUrlSite(trace);
1027
- if (traceSite) {
1028
- root.querySelector(".text").innerHTML +=
1029
- `\n at ${generateClickableText(traceSite)}`;
1030
- }
1031
- }
1032
- };
1033
- renderException();
1034
- if (exception.site.url && serverIsJsenvDevServer) {
1035
- (async () => {
1036
- try {
1037
- if (
1038
- exception.code === DYNAMIC_IMPORT_FETCH_ERROR ||
1039
- exception.reportedBy === "script_error_event"
1040
- ) {
1041
- const errorCauseFile = exception.site.ownerSite
1042
- ? exception.site.ownerSite.url
1043
- : exception.site.url;
1044
- const errorCauseAPIUrl = `/__get_error_cause__/${encodeURIComponent(
1045
- errorCauseFile,
1046
- )}`;
1047
- const response = await window.fetch(errorCauseAPIUrl);
1048
- if (response.status !== 200) {
1049
- return;
1050
- }
1051
- const causeInfo = await response.json();
1052
- if (!causeInfo) {
1053
- return;
1054
- }
1055
- exception.cause = causeInfo;
1056
- renderException();
1057
- return;
1058
- }
1059
- if (exception.site.line !== undefined) {
1060
- const errorTraceFile = exception.site.ownerSite
1061
- ? stringifyUrlSite({
1062
- url: exception.site.ownerSite.url,
1063
- line: exception.site.ownerSite.inlineLine,
1064
- column: exception.site.ownerSite.inlineColumn,
1065
- })
1066
- : stringifyUrlSite(exception.site);
1067
- const errorTraceAPIUrl = `/__get_cause_trace__/${encodeURIComponent(
1068
- errorTraceFile,
1069
- )}`;
1070
- const urlToFetch = new URL(errorTraceAPIUrl, window.origin);
1071
- if (!exception.stackSourcemapped) {
1072
- urlToFetch.searchParams.set("remap", "");
1073
- }
1074
- const response = await window.fetch(urlToFetch);
1075
- if (response.status !== 200) {
1076
- return;
1077
- }
1078
- const causeTrace = await response.json();
1079
- exception.cause = {
1080
- trace: causeTrace,
1081
- };
1082
- renderException();
1083
- return;
1084
- }
1085
- } catch {
1086
- // happens if server is closed for instance
1087
- return;
1088
- }
1089
- })();
1090
- }
1091
- }
1092
- }
1093
- const generateClickableText = (text) => {
1094
- const textWithHtmlLinks = makeLinksClickable(text, {
1095
- createLink: ({ url, line, column }) => {
1096
- const urlSite = resolveUrlSite({ url, line, column });
1097
- if (errorBaseUrl) {
1098
- if (urlSite.url.startsWith(rootDirectoryUrl)) {
1099
- urlSite.url = `${errorBaseUrl}${urlSite.url.slice(
1100
- rootDirectoryUrl.length,
1101
- )}`;
1102
- } else {
1103
- urlSite.url = "file:///mocked_for_snapshots";
1104
- }
1105
- }
1106
- const urlWithLineAndColumn = stringifyUrlSite(urlSite);
1107
- return {
1108
- href:
1109
- urlSite.url.startsWith("file:") && openInEditor
1110
- ? `javascript:window.fetch('/__open_in_editor__/${encodeURIComponent(
1111
- urlWithLineAndColumn,
1112
- )}')`
1113
- : urlSite.url,
1114
- text: urlWithLineAndColumn,
1115
- };
1116
- },
1117
- });
1118
- return textWithHtmlLinks;
1119
- };
1120
- const makeLinksClickable = (
1121
- string,
1122
- { createLink = ({ url }) => url },
1123
- ) => {
1124
- // normalize line breaks
1125
- string = string.replace(/\r\n/g, "\n");
1126
- string = escapeHtml(string);
1127
- // render links
1128
- string = replaceUrls(string, ({ url, line, column }) => {
1129
- const { href, text } = createLink({ url, line, column });
1130
- return link({ href, text });
1131
- });
1132
- return string;
1133
- };
1134
- const prefixRemainingLines = (text, prefix) => {
1135
- const lines = text.split(/\r?\n/);
1136
- const firstLine = lines.shift();
1137
- let result = firstLine;
1138
- let i = 0;
1139
- while (i < lines.length) {
1140
- const line = lines[i];
1141
- i++;
1142
- result += line.length ? `\n${prefix}${line}` : `\n`;
1143
- }
1144
- return result;
1145
- };
1146
- const escapeHtml = (string) => {
1147
- return string
1148
- .replace(/&/g, "&amp;")
1149
- .replace(/</g, "&lt;")
1150
- .replace(/>/g, "&gt;")
1151
- .replace(/"/g, "&quot;")
1152
- .replace(/'/g, "&#039;");
1153
- };
1154
- const link = ({ href, text = href }) => `<a href="${href}">${text}</a>`;
1155
-
1156
- if (customElements && !customElements.get(JSENV_ERROR_OVERLAY_TAGNAME)) {
1157
- customElements.define(JSENV_ERROR_OVERLAY_TAGNAME, JsenvErrorOverlay);
1158
- }
1159
-
1160
- const overlayCSS = `
1161
- :host {
1162
- position: fixed;
1163
- z-index: 99999;
1164
- top: 0;
1165
- left: 0;
1166
- width: 100%;
1167
- height: 100%;
1168
- overflow-y: scroll;
1169
- margin: 0;
1170
- background: rgba(0, 0, 0, 0.66);
1171
- }
1172
-
1173
- .backdrop {
1174
- position: absolute;
1175
- left: 0;
1176
- right: 0;
1177
- top: 0;
1178
- bottom: 0;
1179
- }
1180
-
1181
- .overlay {
1182
- position: relative;
1183
- background: rgba(0, 0, 0, 0.95);
1184
- width: 800px;
1185
- margin: 30px auto;
1186
- padding: 25px 40px;
1187
- padding-top: 0;
1188
- overflow: hidden; /* for h1 margins */
1189
- border-radius: 4px 8px;
1190
- box-shadow: 0 20px 40px rgb(0 0 0 / 30%), 0 15px 12px rgb(0 0 0 / 20%);
1191
- box-sizing: border-box;
1192
- font-family: monospace;
1193
- direction: ltr;
1194
- }
1195
-
1196
- h1 {
1197
- color: red;
1198
- text-align: center;
1199
- }
1200
-
1201
- pre {
1202
- overflow: auto;
1203
- max-width: 100%;
1204
- /* padding is nice + prevents scrollbar from hiding the text behind it */
1205
- /* does not work nicely on firefox though https://bugzilla.mozilla.org/show_bug.cgi?id=748518 */
1206
- padding: 20px;
1207
- }
1208
-
1209
- .tip {
1210
- border-top: 1px solid #999;
1211
- padding-top: 12px;
1212
- }
1213
-
1214
- [data-theme="dark"] {
1215
- color: #999;
1216
- }
1217
- [data-theme="dark"] pre {
1218
- background: #111;
1219
- border: 1px solid #333;
1220
- color: #eee;
1221
- }
1222
-
1223
- [data-theme="light"] {
1224
- color: #EEEEEE;
1225
- }
1226
- [data-theme="light"] pre {
1227
- background: #1E1E1E;
1228
- border: 1px solid white;
1229
- color: #EEEEEE;
1230
- }
1231
-
1232
- pre a {
1233
- color: inherit;
1234
- }`;
1235
- }
1236
-
1237
- supervisor.createException = createException;
1238
- supervisor.reportException = (exception) => {
1239
- if (errorOverlay) {
1240
- const removeErrorOverlay = displayJsenvErrorOverlay(exception);
1241
- if (window.__reloader__) {
1242
- const onchange = window.__reloader__.status.onchange;
1243
- window.__reloader__.status.onchange = () => {
1244
- onchange();
1245
- if (window.__reloader__.status.value === "reloading") {
1246
- removeErrorOverlay();
1247
- }
1248
- };
1249
- }
1250
- }
1251
- if (errorNotification) {
1252
- displayErrorNotification({
1253
- title: "An error occured",
1254
- text: "todo",
1255
- });
1256
- }
1257
- return exception;
1258
- };
1259
- window.addEventListener("error", (errorEvent) => {
1260
- if (!errorEvent.isTrusted) {
1261
- // ignore custom error event (not sent by browser)
1262
- if (logs) {
1263
- console.log("ignore non trusted error event", errorEvent);
1264
- }
1265
- return;
1266
- }
1267
- if (logs) {
1268
- console.log('window "error" event received', errorEvent);
1269
- }
1270
- const { error, message, filename, lineno, colno } = errorEvent;
1271
- const exception = supervisor.createException(error || message, {
1272
- // when error is reported within a worker error is null
1273
- // but there is a message property on errorEvent
1274
- reportedBy: "window_error_event",
1275
- message,
1276
- url: filename,
1277
- line: lineno,
1278
- column: colno,
1279
- });
1280
- supervisor.reportException(exception);
1281
- });
1282
- window.addEventListener("unhandledrejection", (event) => {
1283
- if (event.defaultPrevented) {
1284
- return;
1285
- }
1286
- const exception = supervisor.createException(event.reason, {
1287
- reportedBy: "window_unhandledrejection_event",
1288
- });
1289
- supervisor.reportException(exception);
1290
- });
1291
- };
1292
-
1293
- const prepareScriptToLoad = (script) => {
1294
- // do not use script.cloneNode()
1295
- // bcause https://stackoverflow.com/questions/28771542/why-dont-clonenode-script-tags-execute
1296
- const scriptClone = document.createElement("script");
1297
- // browsers set async by default when creating script(s)
1298
- // we want an exact copy to preserves how code is executed
1299
- scriptClone.async = false;
1300
- Array.from(script.attributes).forEach((attribute) => {
1301
- scriptClone.setAttribute(attribute.nodeName, attribute.nodeValue);
1302
- });
1303
- scriptClone.removeAttribute("jsenv-cooked-by");
1304
- scriptClone.removeAttribute("jsenv-inlined-by");
1305
- scriptClone.removeAttribute("jsenv-injected-by");
1306
- scriptClone.removeAttribute("inlined-from-src");
1307
- scriptClone.removeAttribute("original-position");
1308
- scriptClone.removeAttribute("original-src-position");
1309
-
1310
- return scriptClone;
1311
- };
1312
-
1313
- const getScriptLoadPromise = async (script) => {
1314
- return new Promise((resolve) => {
1315
- const windowErrorEventCallback = (errorEvent) => {
1316
- if (errorEvent.filename === script.src) {
1317
- removeWindowErrorEventCallback();
1318
- resolve({
1319
- detectedBy: "window_error_event",
1320
- failed: true,
1321
- errorEvent,
1322
- });
1323
- }
1324
- };
1325
- const removeWindowErrorEventCallback = () => {
1326
- window.removeEventListener("error", windowErrorEventCallback);
1327
- };
1328
- window.addEventListener("error", windowErrorEventCallback);
1329
- script.addEventListener("error", (errorEvent) => {
1330
- removeWindowErrorEventCallback();
1331
- resolve({
1332
- detectedBy: "script_error_event",
1333
- failed: true,
1334
- errorEvent,
1335
- });
1336
- });
1337
- script.addEventListener("load", () => {
1338
- removeWindowErrorEventCallback();
1339
- resolve({
1340
- detectedBy: "script_load_event",
1341
- });
1342
- });
1343
- });
1344
- };
1345
-
1346
- const getErrorName = (value) => {
1347
- if (value.code === "MODULE_NOT_FOUND") {
1348
- return "TypeError";
1349
- }
1350
- const { constructor } = value;
1351
- if (constructor) {
1352
- if (constructor.name !== "Object") {
1353
- return constructor.name;
1354
- }
1355
- }
1356
- return value.name || "Error";
1357
- };
1358
-
1359
- return supervisor;
1360
- })();