@jsenv/core 35.0.3 → 35.0.5

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 (117) hide show
  1. package/dist/html/explorer.html +107 -107
  2. package/dist/js/new_stylesheet.js +3 -0
  3. package/dist/js/s.js.map +3 -3
  4. package/package.json +2 -2
  5. package/src/build/build.js +589 -587
  6. package/src/build/build_urls_generator.js +44 -44
  7. package/src/build/graph_utils.js +14 -14
  8. package/src/build/jsenv_plugin_line_break_normalization.js +6 -6
  9. package/src/build/line_break_unix.js +11 -11
  10. package/src/build/start_build_server.js +37 -37
  11. package/src/build/version_generator.js +7 -7
  12. package/src/build/version_mappings_injection.js +23 -23
  13. package/src/dev/file_service.js +132 -132
  14. package/src/dev/start_dev_server.js +56 -56
  15. package/src/dev/user_agent.js +8 -8
  16. package/src/helpers/basic_fetch.js +24 -24
  17. package/src/helpers/command/command.js +28 -28
  18. package/src/helpers/lookup_package_directory.js +19 -16
  19. package/src/helpers/ping_server.js +17 -17
  20. package/src/helpers/require_from_jsenv.js +2 -2
  21. package/src/helpers/watch_source_files.js +9 -9
  22. package/src/helpers/web_url_converter.js +10 -10
  23. package/src/helpers/worker_reload.js +27 -27
  24. package/src/kitchen/compat/features_compatibility.js +1 -1
  25. package/src/kitchen/compat/runtime_compat.js +26 -24
  26. package/src/kitchen/errors.js +75 -75
  27. package/src/kitchen/fetched_content_compliance.js +8 -8
  28. package/src/kitchen/kitchen.js +251 -250
  29. package/src/kitchen/url_graph/sort_by_dependencies.js +17 -17
  30. package/src/kitchen/url_graph/url_graph_loader.js +30 -30
  31. package/src/kitchen/url_graph/url_graph_report.js +57 -57
  32. package/src/kitchen/url_graph/url_info_transformations.js +77 -77
  33. package/src/kitchen/url_graph.js +121 -121
  34. package/src/kitchen/url_specifier_encoding.js +21 -21
  35. package/src/kitchen/web_workers.js +5 -5
  36. package/src/main.js +3 -3
  37. package/src/plugins/autoreload/client/autoreload.js +96 -96
  38. package/src/plugins/autoreload/client/reload.js +56 -56
  39. package/src/plugins/autoreload/client/url_helpers.js +13 -13
  40. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +5 -5
  41. package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +9 -9
  42. package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +61 -60
  43. package/src/plugins/autoreload/jsenv_plugin_hmr.js +15 -15
  44. package/src/plugins/cache_control/jsenv_plugin_cache_control.js +5 -5
  45. package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +57 -57
  46. package/src/plugins/explorer/client/explorer.html +107 -107
  47. package/src/plugins/explorer/jsenv_plugin_explorer.js +20 -20
  48. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +60 -60
  49. package/src/plugins/global_scenarios/jsenv_plugin_global_scenarios.js +5 -5
  50. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +3 -3
  51. package/src/plugins/import_meta_hot/babel_plugin_metadata_import_meta_hot.js +35 -35
  52. package/src/plugins/import_meta_hot/client/import_meta_hot.js +26 -26
  53. package/src/plugins/import_meta_hot/html_hot_dependencies.js +43 -43
  54. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +44 -40
  55. package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +35 -35
  56. package/src/plugins/import_meta_url/client/import_meta_url_browser.js +21 -21
  57. package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +3 -3
  58. package/src/plugins/importmap/jsenv_plugin_importmap.js +54 -54
  59. package/src/plugins/inline_content_analysis/client/inline_content.js +3 -3
  60. package/src/plugins/inline_content_analysis/jsenv_plugin_data_urls.js +26 -26
  61. package/src/plugins/inline_content_analysis/jsenv_plugin_html_inline_content_analysis.js +47 -47
  62. package/src/plugins/inline_content_analysis/jsenv_plugin_inline_content_analysis.js +9 -9
  63. package/src/plugins/inline_content_analysis/jsenv_plugin_js_inline_content_analysis.js +101 -101
  64. package/src/plugins/inlining/jsenv_plugin_inlining.js +9 -9
  65. package/src/plugins/inlining/jsenv_plugin_inlining_as_data_url.js +11 -11
  66. package/src/plugins/inlining/jsenv_plugin_inlining_into_html.js +48 -46
  67. package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +4 -4
  68. package/src/plugins/plugin_controller.js +124 -124
  69. package/src/plugins/plugins.js +27 -27
  70. package/src/plugins/ribbon/client/ribbon.js +6 -6
  71. package/src/plugins/ribbon/jsenv_plugin_ribbon.js +15 -15
  72. package/src/plugins/server_events/client/connection_manager.js +52 -52
  73. package/src/plugins/server_events/client/event_source_connection.js +36 -36
  74. package/src/plugins/server_events/client/events_manager.js +37 -37
  75. package/src/plugins/server_events/client/server_events_client.js +7 -7
  76. package/src/plugins/server_events/client/web_socket_connection.js +39 -39
  77. package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +9 -9
  78. package/src/plugins/server_events/server_events_dispatcher.js +43 -43
  79. package/src/plugins/supervisor/client/supervisor.js +455 -450
  80. package/src/plugins/supervisor/html_supervisor_injection.js +64 -62
  81. package/src/plugins/supervisor/js_supervisor_injection.js +67 -67
  82. package/src/plugins/supervisor/jsenv_plugin_supervisor.js +54 -51
  83. package/src/plugins/transpilation/as_js_module/convert_js_classic_to_js_module.js +13 -13
  84. package/src/plugins/transpilation/as_js_module/jsenv_plugin_as_js_module.js +19 -19
  85. package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +10 -10
  86. package/src/plugins/transpilation/babel/global_this/client/global_this.js +8 -8
  87. package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +16 -16
  88. package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +36 -36
  89. package/src/plugins/transpilation/babel/helpers/babel_plugins_compatibility.js +3 -3
  90. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +24 -24
  91. package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +44 -44
  92. package/src/plugins/transpilation/babel/new_stylesheet/client/new_stylesheet.js +166 -166
  93. package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +10 -10
  94. package/src/plugins/transpilation/babel/require_babel_plugin.js +6 -6
  95. package/src/plugins/transpilation/css/jsenv_plugin_css_transpilation.js +20 -20
  96. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +62 -62
  97. package/src/plugins/transpilation/js_module_fallback/client/s.js +214 -209
  98. package/src/plugins/transpilation/js_module_fallback/convert_js_module_to_js_classic.js +45 -45
  99. package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_resolve.js +6 -6
  100. package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_url.js +17 -17
  101. package/src/plugins/transpilation/js_module_fallback/helpers-string.js +1 -1
  102. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_conversion.js +32 -32
  103. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js +17 -17
  104. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +63 -63
  105. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +15 -15
  106. package/src/plugins/transpilation/jsenv_plugin_import_meta_resolve.js +20 -20
  107. package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +23 -23
  108. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +11 -11
  109. package/src/plugins/url_analysis/css/css_urls.js +12 -12
  110. package/src/plugins/url_analysis/html/html_urls.js +85 -85
  111. package/src/plugins/url_analysis/js/js_urls.js +16 -16
  112. package/src/plugins/url_analysis/jsenv_plugin_reference_expected_types.js +16 -16
  113. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +40 -40
  114. package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +12 -12
  115. package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +35 -35
  116. package/src/plugins/url_resolution/node_esm_resolver.js +26 -26
  117. package/src/plugins/url_version/jsenv_plugin_url_version.js +11 -11
@@ -1,23 +1,23 @@
1
1
  window.__supervisor__ = (() => {
2
2
  const notImplemented = () => {
3
- throw new Error(`window.__supervisor__.setup() not called`)
4
- }
3
+ throw new Error(`window.__supervisor__.setup() not called`);
4
+ };
5
5
  const supervisor = {
6
6
  reportException: notImplemented,
7
7
  superviseScript: notImplemented,
8
8
  superviseScriptTypeModule: notImplemented,
9
9
  reloadSupervisedScript: notImplemented,
10
10
  getDocumentExecutionResult: notImplemented,
11
- }
11
+ };
12
12
 
13
- const executionResults = {}
14
- let documentExecutionStartTime
13
+ const executionResults = {};
14
+ let documentExecutionStartTime;
15
15
  try {
16
- documentExecutionStartTime = window.performance.timing.navigationStart
16
+ documentExecutionStartTime = window.performance.timing.navigationStart;
17
17
  } catch (e) {
18
- documentExecutionStartTime = Date.now()
18
+ documentExecutionStartTime = Date.now();
19
19
  }
20
- let documentExecutionEndTime
20
+ let documentExecutionEndTime;
21
21
  supervisor.setup = ({
22
22
  rootDirectoryUrl,
23
23
  scriptInfos,
@@ -27,53 +27,53 @@ window.__supervisor__ = (() => {
27
27
  errorBaseUrl,
28
28
  openInEditor,
29
29
  }) => {
30
- const executions = {}
31
- const promises = []
32
- let remainingScriptCount = scriptInfos.length
30
+ const executions = {};
31
+ const promises = [];
32
+ let remainingScriptCount = scriptInfos.length;
33
33
 
34
34
  // respect execution order
35
35
  // - wait for classic scripts to be done (non async)
36
36
  // - wait module script previous execution (non async)
37
37
  // see https://gist.github.com/jakub-g/385ee6b41085303a53ad92c7c8afd7a6#typemodule-vs-non-module-typetextjavascript-vs-script-nomodule
38
- const executionQueue = []
39
- let executing = false
38
+ const executionQueue = [];
39
+ let executing = false;
40
40
  const addToExecutionQueue = async (execution) => {
41
41
  if (execution.async) {
42
- execution.execute()
43
- return
42
+ execution.execute();
43
+ return;
44
44
  }
45
45
  if (executing) {
46
- executionQueue.push(execution)
47
- return
46
+ executionQueue.push(execution);
47
+ return;
48
48
  }
49
- execThenDequeue(execution)
50
- }
49
+ execThenDequeue(execution);
50
+ };
51
51
  const execThenDequeue = async (execution) => {
52
- executing = true
52
+ executing = true;
53
53
  // start next js module execution as soon as current js module starts to execute
54
54
  // (do not wait in case of top level await)
55
- let resolveExecutingPromise
55
+ let resolveExecutingPromise;
56
56
  const executingPromise = new Promise((resolve) => {
57
- resolveExecutingPromise = resolve
58
- })
57
+ resolveExecutingPromise = resolve;
58
+ });
59
59
  const promise = execution.execute({
60
60
  onExecuting: () => resolveExecutingPromise(),
61
- })
62
- await Promise.race([promise, executingPromise])
63
- executing = false
61
+ });
62
+ await Promise.race([promise, executingPromise]);
63
+ executing = false;
64
64
  if (executionQueue.length) {
65
- const nextExecution = executionQueue.shift()
66
- execThenDequeue(nextExecution)
65
+ const nextExecution = executionQueue.shift();
66
+ execThenDequeue(nextExecution);
67
67
  }
68
- }
68
+ };
69
69
 
70
70
  const asExecutionId = (src) => {
71
- const url = new URL(src, window.location).href
71
+ const url = new URL(src, window.location).href;
72
72
  if (url.startsWith(window.location.origin)) {
73
- return src
73
+ return src;
74
74
  }
75
- return url
76
- }
75
+ return url;
76
+ };
77
77
 
78
78
  const createExecutionController = (src, type) => {
79
79
  const result = {
@@ -82,192 +82,193 @@ window.__supervisor__ = (() => {
82
82
  coverage: null,
83
83
  exception: null,
84
84
  value: null,
85
- }
85
+ };
86
86
 
87
- let resolve
87
+ let resolve;
88
88
  const promise = new Promise((_resolve) => {
89
- resolve = _resolve
90
- })
91
- promises.push(promise)
92
- executionResults[src] = result
89
+ resolve = _resolve;
90
+ });
91
+ promises.push(promise);
92
+ executionResults[src] = result;
93
93
 
94
94
  const start = () => {
95
- result.duration = null
96
- result.coverage = null
97
- result.status = "started"
98
- result.exception = null
95
+ result.duration = null;
96
+ result.coverage = null;
97
+ result.status = "started";
98
+ result.exception = null;
99
99
  if (logs) {
100
- console.group(`[jsenv] ${src} execution started (${type})`)
100
+ console.group(`[jsenv] ${src} execution started (${type})`);
101
101
  }
102
- }
102
+ };
103
103
  const end = () => {
104
- const now = Date.now()
105
- remainingScriptCount--
106
- result.duration = now - documentExecutionStartTime
107
- result.coverage = window.__coverage__
104
+ const now = Date.now();
105
+ remainingScriptCount--;
106
+ result.duration = now - documentExecutionStartTime;
107
+ result.coverage = window.__coverage__;
108
108
  if (logs) {
109
- console.log(`execution ${result.status}`)
110
- console.groupEnd()
109
+ console.log(`execution ${result.status}`);
110
+ console.groupEnd();
111
111
  }
112
112
  if (remainingScriptCount === 0) {
113
- documentExecutionEndTime = now
113
+ documentExecutionEndTime = now;
114
114
  }
115
- resolve()
116
- }
115
+ resolve();
116
+ };
117
117
  const complete = () => {
118
- result.status = "completed"
119
- end()
120
- }
118
+ result.status = "completed";
119
+ end();
120
+ };
121
121
  const fail = (error, info) => {
122
- result.status = "failed"
123
- const exception = supervisor.createException(error, info)
124
- result.exception = exception
125
- end()
126
- }
122
+ result.status = "failed";
123
+ const exception = supervisor.createException(error, info);
124
+ result.exception = exception;
125
+ end();
126
+ };
127
127
 
128
- return { result, start, complete, fail }
129
- }
128
+ return { result, start, complete, fail };
129
+ };
130
130
 
131
131
  const prepareJsClassicRemoteExecution = (src) => {
132
- const urlObject = new URL(src, window.location)
133
- const url = urlObject.href
132
+ const urlObject = new URL(src, window.location);
133
+ const url = urlObject.href;
134
134
  const { result, start, complete, fail } = createExecutionController(
135
135
  src,
136
136
  "js_classic",
137
- )
137
+ );
138
138
 
139
- let parentNode
140
- let currentScript
141
- let nodeToReplace
142
- let currentScriptClone
139
+ let parentNode;
140
+ let currentScript;
141
+ let nodeToReplace;
142
+ let currentScriptClone;
143
143
  const init = () => {
144
- currentScript = document.currentScript
145
- parentNode = currentScript.parentNode
146
- executions[src].async = currentScript.async
147
- }
144
+ currentScript = document.currentScript;
145
+ parentNode = currentScript.parentNode;
146
+ executions[src].async = currentScript.async;
147
+ };
148
148
  const execute = async ({ isReload } = {}) => {
149
- start()
150
- currentScriptClone = prepareScriptToLoad(currentScript)
149
+ start();
150
+ currentScriptClone = prepareScriptToLoad(currentScript);
151
151
  if (isReload) {
152
- urlObject.searchParams.set("hmr", Date.now())
153
- nodeToReplace = currentScriptClone
154
- currentScriptClone.src = urlObject.href
152
+ urlObject.searchParams.set("hmr", Date.now());
153
+ nodeToReplace = currentScriptClone;
154
+ currentScriptClone.src = urlObject.href;
155
155
  } else {
156
- nodeToReplace = currentScript
157
- currentScriptClone.src = url
156
+ nodeToReplace = currentScript;
157
+ currentScriptClone.src = url;
158
158
  }
159
- const scriptLoadPromise = getScriptLoadPromise(currentScriptClone)
160
- parentNode.replaceChild(currentScriptClone, nodeToReplace)
161
- const { detectedBy, failed, error } = await scriptLoadPromise
159
+ const scriptLoadPromise = getScriptLoadPromise(currentScriptClone);
160
+ parentNode.replaceChild(currentScriptClone, nodeToReplace);
161
+ const { detectedBy, failed, error } = await scriptLoadPromise;
162
162
  if (failed) {
163
163
  if (detectedBy === "script_error_event") {
164
164
  // window.error won't be dispatched for this error
165
- reportErrorBackToBrowser(error)
165
+ reportErrorBackToBrowser(error);
166
166
  }
167
167
  fail(error, {
168
168
  message: `Error while loading script: ${urlObject.href}`,
169
169
  reportedBy: "script_error_event",
170
170
  url: urlObject.href,
171
- })
171
+ });
172
172
  if (detectedBy === "script_error_event") {
173
- supervisor.reportException(result.exception)
173
+ supervisor.reportException(result.exception);
174
174
  }
175
175
  } else {
176
- complete()
176
+ complete();
177
177
  }
178
- return result
179
- }
180
- executions[src] = { init, execute }
181
- }
178
+ return result;
179
+ };
180
+ executions[src] = { init, execute };
181
+ };
182
182
  const prepareJsClassicInlineExecution = (src) => {
183
183
  const { start, complete, fail } = createExecutionController(
184
184
  src,
185
185
  "js_classic",
186
- )
187
- const end = complete
186
+ );
187
+ const end = complete;
188
188
  const error = (e) => {
189
- reportErrorBackToBrowser(e) // supervision shallowed the error, report back to browser
190
- fail(e)
191
- }
192
- executions[src] = { isInline: true, start, end, error }
193
- }
189
+ reportErrorBackToBrowser(e); // supervision shallowed the error, report back to browser
190
+ fail(e);
191
+ };
192
+ executions[src] = { isInline: true, start, end, error };
193
+ };
194
194
 
195
195
  const isWebkitOrSafari =
196
- typeof window.webkitConvertPointFromNodeToPage === "function"
196
+ typeof window.webkitConvertPointFromNodeToPage === "function";
197
197
  // https://twitter.com/damienmaillard/status/1554752482273787906
198
198
  const prepareJsModuleExecutionWithDynamicImport = (src) => {
199
- const urlObject = new URL(src, window.location)
199
+ const urlObject = new URL(src, window.location);
200
200
  const { result, start, complete, fail } = createExecutionController(
201
201
  src,
202
202
  "js_classic",
203
- )
203
+ );
204
204
 
205
- let importFn
206
- let currentScript
205
+ let importFn;
206
+ let currentScript;
207
207
  const init = (_importFn) => {
208
- importFn = _importFn
208
+ importFn = _importFn;
209
209
  currentScript = document.querySelector(
210
210
  `script[type="module"][inlined-from-src="${src}"]`,
211
- )
212
- executions[src].async = currentScript.async
213
- }
211
+ );
212
+ executions[src].async = currentScript.async;
213
+ };
214
214
  const execute = async ({ isReload } = {}) => {
215
- start()
215
+ start();
216
216
  if (isReload) {
217
- urlObject.searchParams.set("hmr", Date.now())
217
+ urlObject.searchParams.set("hmr", Date.now());
218
218
  }
219
219
  try {
220
- const namespace = await importFn(urlObject.href)
221
- complete(namespace)
222
- return result
220
+ const namespace = await importFn(urlObject.href);
221
+ complete(namespace);
222
+ return result;
223
223
  } catch (e) {
224
224
  fail(e, {
225
225
  message: `Error while importing module: ${urlObject.href}`,
226
226
  reportedBy: "dynamic_import",
227
227
  url: urlObject.href,
228
- })
228
+ });
229
229
  if (isWebkitOrSafari) {
230
- supervisor.reportException(result.exception)
230
+ supervisor.reportException(result.exception);
231
231
  }
232
- return result
232
+ return result;
233
233
  }
234
- }
235
- executions[src] = { init, execute }
236
- }
234
+ };
235
+ executions[src] = { init, execute };
236
+ };
237
237
  const prepareJsModuleExecutionWithScriptThenDynamicImport = (src) => {
238
- const urlObject = new URL(src, window.location)
238
+ const urlObject = new URL(src, window.location);
239
239
  const { result, start, complete, fail } = createExecutionController(
240
240
  src,
241
241
  "js_module",
242
- )
242
+ );
243
243
 
244
- let importFn
245
- let currentScript
246
- let parentNode
247
- let nodeToReplace
248
- let currentScriptClone
244
+ let importFn;
245
+ let currentScript;
246
+ let parentNode;
247
+ let nodeToReplace;
248
+ let currentScriptClone;
249
249
  const init = (_importFn) => {
250
- importFn = _importFn
250
+ importFn = _importFn;
251
251
  currentScript = document.querySelector(
252
252
  `script[type="module"][inlined-from-src="${src}"]`,
253
- )
254
- parentNode = currentScript.parentNode
255
- executions[src].async = currentScript.async
256
- }
253
+ );
254
+ parentNode = currentScript.parentNode;
255
+ executions[src].async = currentScript.async;
256
+ };
257
257
  const execute = async ({ isReload, onExecuting = () => {} } = {}) => {
258
- start()
259
- currentScriptClone = prepareScriptToLoad(currentScript)
258
+ start();
259
+ currentScriptClone = prepareScriptToLoad(currentScript);
260
260
  if (isReload) {
261
- urlObject.searchParams.set("hmr", Date.now())
262
- nodeToReplace = currentScriptClone
263
- currentScriptClone.src = urlObject.href
261
+ urlObject.searchParams.set("hmr", Date.now());
262
+ nodeToReplace = currentScriptClone;
263
+ currentScriptClone.src = urlObject.href;
264
264
  } else {
265
- nodeToReplace = currentScript
266
- currentScriptClone.src = urlObject.href
265
+ nodeToReplace = currentScript;
266
+ currentScriptClone.src = urlObject.href;
267
267
  }
268
- const scriptLoadResultPromise = getScriptLoadPromise(currentScriptClone)
269
- parentNode.replaceChild(currentScriptClone, nodeToReplace)
270
- const { detectedBy, failed, error } = await scriptLoadResultPromise
268
+ const scriptLoadResultPromise =
269
+ getScriptLoadPromise(currentScriptClone);
270
+ parentNode.replaceChild(currentScriptClone, nodeToReplace);
271
+ const { detectedBy, failed, error } = await scriptLoadResultPromise;
271
272
 
272
273
  if (failed) {
273
274
  // if (detectedBy === "script_error_event") {
@@ -277,49 +278,49 @@ window.__supervisor__ = (() => {
277
278
  message: `Error while loading module: ${urlObject.href}`,
278
279
  reportedBy: "script_error_event",
279
280
  url: urlObject.href,
280
- })
281
+ });
281
282
  if (detectedBy === "script_error_event") {
282
- supervisor.reportException(result.exception)
283
+ supervisor.reportException(result.exception);
283
284
  }
284
- return result
285
+ return result;
285
286
  }
286
287
 
287
- onExecuting()
288
- result.status = "executing"
288
+ onExecuting();
289
+ result.status = "executing";
289
290
  if (logs) {
290
- console.log(`load ended`)
291
+ console.log(`load ended`);
291
292
  }
292
293
  try {
293
- const namespace = await importFn(urlObject.href)
294
- complete(namespace)
295
- return result
294
+ const namespace = await importFn(urlObject.href);
295
+ complete(namespace);
296
+ return result;
296
297
  } catch (e) {
297
298
  fail(e, {
298
299
  message: `Error while importing module: ${urlObject.href}`,
299
300
  reportedBy: "dynamic_import",
300
301
  url: urlObject.href,
301
- })
302
- return result
302
+ });
303
+ return result;
303
304
  }
304
- }
305
- executions[src] = { init, execute }
306
- }
305
+ };
306
+ executions[src] = { init, execute };
307
+ };
307
308
  const prepareJsModuleRemoteExecution = isWebkitOrSafari
308
309
  ? prepareJsModuleExecutionWithDynamicImport
309
- : prepareJsModuleExecutionWithScriptThenDynamicImport
310
+ : prepareJsModuleExecutionWithScriptThenDynamicImport;
310
311
  const prepareJsModuleInlineExecution = (src) => {
311
312
  const { start, complete, fail } = createExecutionController(
312
313
  src,
313
314
  "js_module",
314
- )
315
- const end = complete
315
+ );
316
+ const end = complete;
316
317
  const error = (e) => {
317
318
  // supervision shallowed the error, report back to browser
318
- reportErrorBackToBrowser(e)
319
- fail(e)
320
- }
321
- executions[src] = { isInline: true, start, end, error }
322
- }
319
+ reportErrorBackToBrowser(e);
320
+ fail(e);
321
+ };
322
+ executions[src] = { isInline: true, start, end, error };
323
+ };
323
324
 
324
325
  supervisor.setupReportException({
325
326
  logs,
@@ -328,82 +329,82 @@ window.__supervisor__ = (() => {
328
329
  errorOverlay,
329
330
  errorBaseUrl,
330
331
  openInEditor,
331
- })
332
+ });
332
333
 
333
334
  scriptInfos.forEach((scriptInfo) => {
334
- const { type, src, isInline } = scriptInfo
335
+ const { type, src, isInline } = scriptInfo;
335
336
  if (type === "js_module") {
336
337
  if (isInline) {
337
- prepareJsModuleInlineExecution(src)
338
+ prepareJsModuleInlineExecution(src);
338
339
  } else {
339
- prepareJsModuleRemoteExecution(src)
340
+ prepareJsModuleRemoteExecution(src);
340
341
  }
341
342
  } else if (isInline) {
342
- prepareJsClassicInlineExecution(src)
343
+ prepareJsClassicInlineExecution(src);
343
344
  } else {
344
- prepareJsClassicRemoteExecution(src)
345
+ prepareJsClassicRemoteExecution(src);
345
346
  }
346
- })
347
+ });
347
348
 
348
349
  // js classic
349
350
  supervisor.jsClassicStart = (inlineSrc) => {
350
- executions[inlineSrc].start()
351
- }
351
+ executions[inlineSrc].start();
352
+ };
352
353
  supervisor.jsClassicEnd = (inlineSrc) => {
353
- executions[inlineSrc].end()
354
- }
354
+ executions[inlineSrc].end();
355
+ };
355
356
  supervisor.jsClassicError = (inlineSrc, e) => {
356
- executions[inlineSrc].error(e)
357
- }
357
+ executions[inlineSrc].error(e);
358
+ };
358
359
  supervisor.superviseScript = (src) => {
359
- const execution = executions[asExecutionId(src)]
360
- execution.init()
361
- return addToExecutionQueue(execution)
362
- }
360
+ const execution = executions[asExecutionId(src)];
361
+ execution.init();
362
+ return addToExecutionQueue(execution);
363
+ };
363
364
  // js module
364
365
  supervisor.jsModuleStart = (inlineSrc) => {
365
- executions[inlineSrc].start()
366
- }
366
+ executions[inlineSrc].start();
367
+ };
367
368
  supervisor.jsModuleEnd = (inlineSrc) => {
368
- executions[inlineSrc].end()
369
- }
369
+ executions[inlineSrc].end();
370
+ };
370
371
  supervisor.jsModuleError = (inlineSrc, e) => {
371
- executions[inlineSrc].error(e)
372
- }
372
+ executions[inlineSrc].error(e);
373
+ };
373
374
  supervisor.superviseScriptTypeModule = (src, importFn) => {
374
- const execution = executions[asExecutionId(src)]
375
- execution.init(importFn)
376
- return addToExecutionQueue(execution)
377
- }
375
+ const execution = executions[asExecutionId(src)];
376
+ execution.init(importFn);
377
+ return addToExecutionQueue(execution);
378
+ };
378
379
 
379
380
  supervisor.reloadSupervisedScript = (src) => {
380
- const execution = executions[src]
381
+ const execution = executions[src];
381
382
  if (!execution) {
382
- throw new Error(`no execution for ${src}`)
383
+ throw new Error(`no execution for ${src}`);
383
384
  }
384
385
  if (execution.isInline) {
385
- throw new Error(`cannot reload inline script ${src}`)
386
+ throw new Error(`cannot reload inline script ${src}`);
386
387
  }
387
- return execution.execute({ isReload: true })
388
- }
388
+ return execution.execute({ isReload: true });
389
+ };
389
390
 
390
391
  supervisor.getDocumentExecutionResult = async () => {
391
- await Promise.all(promises)
392
+ await Promise.all(promises);
392
393
  return {
393
394
  startTime: documentExecutionStartTime,
394
395
  endTime: documentExecutionEndTime,
395
396
  status: "completed",
396
397
  executionResults,
397
- }
398
- }
399
- }
398
+ };
399
+ };
400
+ };
400
401
  const reportErrorBackToBrowser = (error) => {
401
402
  if (typeof window.reportError === "function") {
402
- window.reportError(error)
403
+ window.reportError(error);
403
404
  } else {
404
- console.error(error)
405
+ console.error(error);
405
406
  }
406
- }
407
+ };
407
408
 
408
409
  supervisor.setupReportException = ({
409
410
  logs,
@@ -414,9 +415,9 @@ window.__supervisor__ = (() => {
414
415
  errorBaseUrl,
415
416
  openInEditor,
416
417
  }) => {
417
- const DYNAMIC_IMPORT_FETCH_ERROR = "dynamic_import_fetch_error"
418
- const DYNAMIC_IMPORT_EXPORT_MISSING = "dynamic_import_export_missing"
419
- const DYNAMIC_IMPORT_SYNTAX_ERROR = "dynamic_import_syntax_error"
418
+ const DYNAMIC_IMPORT_FETCH_ERROR = "dynamic_import_fetch_error";
419
+ const DYNAMIC_IMPORT_EXPORT_MISSING = "dynamic_import_export_missing";
420
+ const DYNAMIC_IMPORT_SYNTAX_ERROR = "dynamic_import_syntax_error";
420
421
 
421
422
  const createException = (
422
423
  reason, // can be error, string, object
@@ -440,165 +441,165 @@ window.__supervisor__ = (() => {
440
441
  column: null,
441
442
  originalUrl: null,
442
443
  },
443
- }
444
+ };
444
445
 
445
446
  const writeBasicProperties = () => {
446
447
  if (reason === undefined) {
447
- exception.message = "undefined"
448
- return
448
+ exception.message = "undefined";
449
+ return;
449
450
  }
450
451
  if (reason === null) {
451
- exception.message = "null"
452
- return
452
+ exception.message = "null";
453
+ return;
453
454
  }
454
455
  if (typeof reason === "string") {
455
- exception.message = reason
456
- return
456
+ exception.message = reason;
457
+ return;
457
458
  }
458
459
  if (reason instanceof Error) {
459
- const error = reason
460
- let message = error.message
461
- exception.isError = true
460
+ const error = reason;
461
+ let message = error.message;
462
+ exception.isError = true;
462
463
  if (Error.captureStackTrace) {
463
464
  // stackTrace formatted by V8
464
- exception.message = message
465
- exception.stack = getErrorStackWithoutErrorMessage(error)
466
- exception.stackFormatIsV8 = true
467
- exception.stackSourcemapped = true
465
+ exception.message = message;
466
+ exception.stack = getErrorStackWithoutErrorMessage(error);
467
+ exception.stackFormatIsV8 = true;
468
+ exception.stackSourcemapped = true;
468
469
  } else {
469
- exception.message = message
470
- exception.stack = error.stack ? ` ${error.stack}` : null
471
- exception.stackFormatIsV8 = false
472
- exception.stackSourcemapped = false
470
+ exception.message = message;
471
+ exception.stack = error.stack ? ` ${error.stack}` : null;
472
+ exception.stackFormatIsV8 = false;
473
+ exception.stackSourcemapped = false;
473
474
  }
474
475
  if (error.reportedBy) {
475
- exception.reportedBy = error.reportedBy
476
+ exception.reportedBy = error.reportedBy;
476
477
  }
477
478
  if (error.url) {
478
- Object.assign(exception.site, resolveUrlSite({ url: error.url }))
479
+ Object.assign(exception.site, resolveUrlSite({ url: error.url }));
479
480
  }
480
481
  export_missing: {
481
482
  // chrome
482
483
  if (message.includes("does not provide an export named")) {
483
- exception.code = DYNAMIC_IMPORT_EXPORT_MISSING
484
- return
484
+ exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
485
+ return;
485
486
  }
486
487
  // firefox
487
488
  if (
488
489
  message.startsWith("import not found:") ||
489
490
  message.startsWith("ambiguous indirect export:")
490
491
  ) {
491
- exception.code = DYNAMIC_IMPORT_EXPORT_MISSING
492
- return
492
+ exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
493
+ return;
493
494
  }
494
495
  // safari
495
496
  if (message.startsWith("import binding name")) {
496
- exception.code = DYNAMIC_IMPORT_EXPORT_MISSING
497
- return
497
+ exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
498
+ return;
498
499
  }
499
500
  if (message.includes("Importing a module script failed")) {
500
- exception.code = DYNAMIC_IMPORT_FETCH_ERROR
501
- return
501
+ exception.code = DYNAMIC_IMPORT_FETCH_ERROR;
502
+ return;
502
503
  }
503
504
  }
504
505
  js_syntax_error: {
505
506
  if (error.name === "SyntaxError" && typeof line === "number") {
506
- exception.code = DYNAMIC_IMPORT_SYNTAX_ERROR
507
- return
507
+ exception.code = DYNAMIC_IMPORT_SYNTAX_ERROR;
508
+ return;
508
509
  }
509
510
  }
510
- return
511
+ return;
511
512
  }
512
513
  if (typeof reason === "object") {
513
514
  // happens when reason is an Event for instance
514
- exception.code = reason.code
515
- exception.message = reason.message || message
516
- exception.stack = reason.stack
515
+ exception.code = reason.code;
516
+ exception.message = reason.message || message;
517
+ exception.stack = reason.stack;
517
518
  if (reason.reportedBy) {
518
- exception.reportedBy = reason.reportedBy
519
+ exception.reportedBy = reason.reportedBy;
519
520
  }
520
521
  if (reason.url) {
521
- Object.assign(exception.site, resolveUrlSite({ url: reason.url }))
522
+ Object.assign(exception.site, resolveUrlSite({ url: reason.url }));
522
523
  }
523
- return
524
+ return;
524
525
  }
525
- exception.message = JSON.stringify(reason)
526
- }
527
- writeBasicProperties()
526
+ exception.message = JSON.stringify(reason);
527
+ };
528
+ writeBasicProperties();
528
529
 
529
530
  // first create a version of the stack with file://
530
531
  // (and use it to locate exception url+line+column)
531
532
  if (exception.stack) {
532
- exception.originalStack = exception.stack
533
+ exception.originalStack = exception.stack;
533
534
  exception.stack = replaceUrls(
534
535
  exception.originalStack,
535
536
  (serverUrlSite) => {
536
- const fileUrlSite = resolveUrlSite(serverUrlSite)
537
+ const fileUrlSite = resolveUrlSite(serverUrlSite);
537
538
  if (exception.site.url === null) {
538
- Object.assign(exception.site, fileUrlSite)
539
+ Object.assign(exception.site, fileUrlSite);
539
540
  }
540
- return stringifyUrlSite(fileUrlSite)
541
+ return stringifyUrlSite(fileUrlSite);
541
542
  },
542
- )
543
+ );
543
544
  }
544
545
  // then if it fails, use url+line+column passed
545
546
  if (exception.site.url === null && url) {
546
547
  if (typeof line === "string") {
547
- line = parseInt(line)
548
+ line = parseInt(line);
548
549
  }
549
550
  if (typeof column === "string") {
550
- column = parseInt(column)
551
+ column = parseInt(column);
551
552
  }
552
- const fileUrlSite = resolveUrlSite({ url, line, column })
553
+ const fileUrlSite = resolveUrlSite({ url, line, column });
553
554
  if (
554
555
  fileUrlSite.isInline &&
555
556
  exception.code === DYNAMIC_IMPORT_SYNTAX_ERROR
556
557
  ) {
557
558
  // syntax error on inline script need line-1 for some reason
558
- fileUrlSite.line = fileUrlSite.line - 1
559
+ fileUrlSite.line = fileUrlSite.line - 1;
559
560
  }
560
- Object.assign(exception.site, fileUrlSite)
561
+ Object.assign(exception.site, fileUrlSite);
561
562
  }
562
- exception.text = stringifyMessageAndStack(exception)
563
- return exception
564
- }
563
+ exception.text = stringifyMessageAndStack(exception);
564
+ return exception;
565
+ };
565
566
 
566
567
  const stringifyMessageAndStack = ({ message, stack }) => {
567
568
  if (message && stack) {
568
- return `${message}\n${stack}`
569
+ return `${message}\n${stack}`;
569
570
  }
570
571
  if (stack) {
571
- return stack
572
+ return stack;
572
573
  }
573
- return message
574
- }
574
+ return message;
575
+ };
575
576
 
576
577
  const stringifyUrlSite = ({ url, line, column }) => {
577
578
  if (typeof line === "number" && typeof column === "number") {
578
- return `${url}:${line}:${column}`
579
+ return `${url}:${line}:${column}`;
579
580
  }
580
581
  if (typeof line === "number") {
581
- return `${url}:${line}`
582
+ return `${url}:${line}`;
582
583
  }
583
- return url
584
- }
584
+ return url;
585
+ };
585
586
 
586
587
  const resolveUrlSite = ({ url, line, column }) => {
587
588
  const inlineUrlMatch = url.match(
588
589
  /@L([0-9]+)C([0-9]+)\-L([0-9]+)C([0-9]+)(\.[\w]+)$/,
589
- )
590
+ );
590
591
  if (inlineUrlMatch) {
591
- const htmlUrl = url.slice(0, inlineUrlMatch.index)
592
- const tagLineStart = parseInt(inlineUrlMatch[1])
593
- const tagColumnStart = parseInt(inlineUrlMatch[2])
594
- const tagLineEnd = parseInt(inlineUrlMatch[3])
595
- const tagColumnEnd = parseInt(inlineUrlMatch[4])
596
- const extension = inlineUrlMatch[5]
597
- url = htmlUrl
598
- line = tagLineStart + (typeof line === "number" ? line : 0)
599
- line = line - 1 // sauf pour les erreur de syntaxe
600
- column = tagColumnStart + (typeof column === "number" ? column : 0)
601
- const fileUrl = resolveFileUrl(url)
592
+ const htmlUrl = url.slice(0, inlineUrlMatch.index);
593
+ const tagLineStart = parseInt(inlineUrlMatch[1]);
594
+ const tagColumnStart = parseInt(inlineUrlMatch[2]);
595
+ const tagLineEnd = parseInt(inlineUrlMatch[3]);
596
+ const tagColumnEnd = parseInt(inlineUrlMatch[4]);
597
+ const extension = inlineUrlMatch[5];
598
+ url = htmlUrl;
599
+ line = tagLineStart + (typeof line === "number" ? line : 0);
600
+ line = line - 1; // sauf pour les erreur de syntaxe
601
+ column = tagColumnStart + (typeof column === "number" ? column : 0);
602
+ const fileUrl = resolveFileUrl(url);
602
603
  return {
603
604
  isInline: true,
604
605
  serverUrl: url,
@@ -606,7 +607,7 @@ window.__supervisor__ = (() => {
606
607
  url: fileUrl,
607
608
  line,
608
609
  column,
609
- }
610
+ };
610
611
  }
611
612
  return {
612
613
  isInline: false,
@@ -614,40 +615,42 @@ window.__supervisor__ = (() => {
614
615
  url: resolveFileUrl(url),
615
616
  line,
616
617
  column,
617
- }
618
- }
618
+ };
619
+ };
619
620
 
620
621
  const getErrorStackWithoutErrorMessage = (error) => {
621
- let stack = error.stack
622
- if (!stack) return ""
623
- const messageInStack = `${error.name}: ${error.message}`
622
+ let stack = error.stack;
623
+ if (!stack) return "";
624
+ const messageInStack = `${error.name}: ${error.message}`;
624
625
  if (stack.startsWith(messageInStack)) {
625
- stack = stack.slice(messageInStack.length)
626
+ stack = stack.slice(messageInStack.length);
626
627
  }
627
- const nextLineIndex = stack.indexOf("\n")
628
+ const nextLineIndex = stack.indexOf("\n");
628
629
  if (nextLineIndex > -1) {
629
- stack = stack.slice(nextLineIndex + 1)
630
+ stack = stack.slice(nextLineIndex + 1);
630
631
  }
631
- return stack
632
- }
632
+ return stack;
633
+ };
633
634
 
634
635
  const resolveFileUrl = (url) => {
635
- let urlObject = new URL(url, window.origin)
636
+ let urlObject = new URL(url, window.origin);
636
637
  if (urlObject.origin === window.origin) {
637
638
  urlObject = new URL(
638
639
  `${urlObject.pathname.slice(1)}${urlObject.search}`,
639
640
  rootDirectoryUrl,
640
- )
641
+ );
641
642
  }
642
643
  if (urlObject.href.startsWith("file:")) {
643
- const atFsIndex = urlObject.pathname.indexOf("/@fs/")
644
+ const atFsIndex = urlObject.pathname.indexOf("/@fs/");
644
645
  if (atFsIndex > -1) {
645
- const afterAtFs = urlObject.pathname.slice(atFsIndex + "/@fs/".length)
646
- return new URL(afterAtFs, "file:///").href
646
+ const afterAtFs = urlObject.pathname.slice(
647
+ atFsIndex + "/@fs/".length,
648
+ );
649
+ return new URL(afterAtFs, "file:///").href;
647
650
  }
648
651
  }
649
- return urlObject.href
650
- }
652
+ return urlObject.href;
653
+ };
651
654
 
652
655
  // `Error: yo
653
656
  // at Object.execute (http://127.0.0.1:57300/build/src/__test__/file-throw.js:9:13)
@@ -658,49 +661,49 @@ window.__supervisor__ = (() => {
658
661
  // })
659
662
  const replaceUrls = (source, replace) => {
660
663
  return source.replace(/(?:https?|ftp|file):\/\/\S+/gm, (match) => {
661
- let replacement = ""
662
- const lastChar = match[match.length - 1]
664
+ let replacement = "";
665
+ const lastChar = match[match.length - 1];
663
666
 
664
667
  // hotfix because our url regex sucks a bit
665
- const endsWithSeparationChar = lastChar === ")" || lastChar === ":"
668
+ const endsWithSeparationChar = lastChar === ")" || lastChar === ":";
666
669
  if (endsWithSeparationChar) {
667
- match = match.slice(0, -1)
670
+ match = match.slice(0, -1);
668
671
  }
669
672
 
670
- const lineAndColumnPattern = /:([0-9]+):([0-9]+)$/
671
- const lineAndColumMatch = match.match(lineAndColumnPattern)
673
+ const lineAndColumnPattern = /:([0-9]+):([0-9]+)$/;
674
+ const lineAndColumMatch = match.match(lineAndColumnPattern);
672
675
  if (lineAndColumMatch) {
673
- const lineAndColumnString = lineAndColumMatch[0]
674
- const lineString = lineAndColumMatch[1]
675
- const columnString = lineAndColumMatch[2]
676
+ const lineAndColumnString = lineAndColumMatch[0];
677
+ const lineString = lineAndColumMatch[1];
678
+ const columnString = lineAndColumMatch[2];
676
679
  replacement = replace({
677
680
  url: match.slice(0, -lineAndColumnString.length),
678
681
  line: lineString ? parseInt(lineString) : null,
679
682
  column: columnString ? parseInt(columnString) : null,
680
- })
683
+ });
681
684
  } else {
682
- const linePattern = /:([0-9]+)$/
683
- const lineMatch = match.match(linePattern)
685
+ const linePattern = /:([0-9]+)$/;
686
+ const lineMatch = match.match(linePattern);
684
687
  if (lineMatch) {
685
- const lineString = lineMatch[0]
688
+ const lineString = lineMatch[0];
686
689
  replacement = replace({
687
690
  url: match.slice(0, -lineString.length),
688
691
  line: lineString ? parseInt(lineString) : null,
689
- })
692
+ });
690
693
  } else {
691
694
  replacement = replace({
692
695
  url: match,
693
- })
696
+ });
694
697
  }
695
698
  }
696
699
  if (endsWithSeparationChar) {
697
- return `${replacement}${lastChar}`
700
+ return `${replacement}${lastChar}`;
698
701
  }
699
- return replacement
700
- })
701
- }
702
+ return replacement;
703
+ });
704
+ };
702
705
 
703
- let formatError
706
+ let formatError;
704
707
  error_formatter: {
705
708
  formatError = (exceptionInfo) => {
706
709
  const errorParts = {
@@ -709,25 +712,25 @@ window.__supervisor__ = (() => {
709
712
  text: "",
710
713
  tip: "",
711
714
  errorDetailsPromise: null,
712
- }
713
- const tips = []
714
- tips.push("Click outside to close.")
715
- errorParts.tip = tips.join(`\n <br />\n `)
715
+ };
716
+ const tips = [];
717
+ tips.push("Click outside to close.");
718
+ errorParts.tip = tips.join(`\n <br />\n `);
716
719
 
717
720
  const generateClickableText = (text) => {
718
721
  const textWithHtmlLinks = makeLinksClickable(text, {
719
722
  createLink: ({ url, line, column }) => {
720
- const urlSite = resolveUrlSite({ url, line, column })
723
+ const urlSite = resolveUrlSite({ url, line, column });
721
724
  if (errorBaseUrl) {
722
725
  if (urlSite.url.startsWith(rootDirectoryUrl)) {
723
726
  urlSite.url = `${errorBaseUrl}${urlSite.url.slice(
724
727
  rootDirectoryUrl.length,
725
- )}`
728
+ )}`;
726
729
  } else {
727
- urlSite.url = "file:///mocked_for_snapshots"
730
+ urlSite.url = "file:///mocked_for_snapshots";
728
731
  }
729
732
  }
730
- const urlWithLineAndColumn = stringifyUrlSite(urlSite)
733
+ const urlWithLineAndColumn = stringifyUrlSite(urlSite);
731
734
  return {
732
735
  href:
733
736
  urlSite.url.startsWith("file:") && openInEditor
@@ -736,11 +739,11 @@ window.__supervisor__ = (() => {
736
739
  )}')`
737
740
  : urlSite.url,
738
741
  text: urlWithLineAndColumn,
739
- }
742
+ };
740
743
  },
741
- })
742
- return textWithHtmlLinks
743
- }
744
+ });
745
+ return textWithHtmlLinks;
746
+ };
744
747
 
745
748
  errorParts.text = stringifyMessageAndStack({
746
749
  message: exceptionInfo.message
@@ -749,11 +752,11 @@ window.__supervisor__ = (() => {
749
752
  stack: exceptionInfo.stack
750
753
  ? generateClickableText(exceptionInfo.stack)
751
754
  : "",
752
- })
755
+ });
753
756
  if (exceptionInfo.site.url) {
754
757
  errorParts.errorDetailsPromise = (async () => {
755
758
  if (!serverIsJsenvDevServer) {
756
- return null
759
+ return null;
757
760
  }
758
761
  try {
759
762
  if (
@@ -766,13 +769,13 @@ window.__supervisor__ = (() => {
766
769
  ? exceptionInfo.site.originalUrl
767
770
  : exceptionInfo.site.url,
768
771
  )}`,
769
- )
772
+ );
770
773
  if (response.status !== 200) {
771
- return null
774
+ return null;
772
775
  }
773
- const causeInfo = await response.json()
776
+ const causeInfo = await response.json();
774
777
  if (!causeInfo) {
775
- return null
778
+ return null;
776
779
  }
777
780
  const causeText =
778
781
  causeInfo.code === "NOT_FOUND"
@@ -783,10 +786,10 @@ window.__supervisor__ = (() => {
783
786
  : stringifyMessageAndStack({
784
787
  message: generateClickableText(causeInfo.stack),
785
788
  stack: generateClickableText(causeInfo.codeFrame),
786
- })
789
+ });
787
790
  return {
788
791
  cause: causeText,
789
- }
792
+ };
790
793
  }
791
794
  if (exceptionInfo.site.line !== undefined) {
792
795
  const urlToFetch = new URL(
@@ -794,43 +797,43 @@ window.__supervisor__ = (() => {
794
797
  stringifyUrlSite(exceptionInfo.site),
795
798
  )}`,
796
799
  window.origin,
797
- )
800
+ );
798
801
  if (!exceptionInfo.stackSourcemapped) {
799
- urlToFetch.searchParams.set("remap", "")
802
+ urlToFetch.searchParams.set("remap", "");
800
803
  }
801
- const response = await window.fetch(urlToFetch)
804
+ const response = await window.fetch(urlToFetch);
802
805
  if (response.status !== 200) {
803
- return null
806
+ return null;
804
807
  }
805
- const codeFrame = await response.text()
808
+ const codeFrame = await response.text();
806
809
  return {
807
810
  codeFrame: generateClickableText(codeFrame),
808
- }
811
+ };
809
812
  }
810
813
  } catch (e) {
811
814
  // happens if server is closed for instance
812
- return null
815
+ return null;
813
816
  }
814
- return null
815
- })()
817
+ return null;
818
+ })();
816
819
  }
817
- return errorParts
818
- }
820
+ return errorParts;
821
+ };
819
822
 
820
823
  const makeLinksClickable = (
821
824
  string,
822
825
  { createLink = ({ url }) => url },
823
826
  ) => {
824
827
  // normalize line breaks
825
- string = string.replace(/\n/g, "\n")
826
- string = escapeHtml(string)
828
+ string = string.replace(/\n/g, "\n");
829
+ string = escapeHtml(string);
827
830
  // render links
828
831
  string = replaceUrls(string, ({ url, line, column }) => {
829
- const { href, text } = createLink({ url, line, column })
830
- return link({ href, text })
831
- })
832
- return string
833
- }
832
+ const { href, text } = createLink({ url, line, column });
833
+ return link({ href, text });
834
+ });
835
+ return string;
836
+ };
834
837
 
835
838
  const escapeHtml = (string) => {
836
839
  return string
@@ -838,15 +841,15 @@ window.__supervisor__ = (() => {
838
841
  .replace(/</g, "&lt;")
839
842
  .replace(/>/g, "&gt;")
840
843
  .replace(/"/g, "&quot;")
841
- .replace(/'/g, "&#039;")
842
- }
844
+ .replace(/'/g, "&#039;");
845
+ };
843
846
 
844
- const link = ({ href, text = href }) => `<a href="${href}">${text}</a>`
847
+ const link = ({ href, text = href }) => `<a href="${href}">${text}</a>`;
845
848
  }
846
849
 
847
- let displayErrorNotification
850
+ let displayErrorNotification;
848
851
  error_notification: {
849
- const { Notification } = window
852
+ const { Notification } = window;
850
853
  displayErrorNotification =
851
854
  typeof Notification === "function"
852
855
  ? ({ title, text, icon }) => {
@@ -855,42 +858,42 @@ window.__supervisor__ = (() => {
855
858
  lang: "en",
856
859
  body: text,
857
860
  icon,
858
- })
861
+ });
859
862
  notification.onclick = () => {
860
- window.focus()
861
- }
863
+ window.focus();
864
+ };
862
865
  }
863
866
  }
864
- : () => {}
867
+ : () => {};
865
868
  }
866
869
 
867
- const JSENV_ERROR_OVERLAY_TAGNAME = "jsenv-error-overlay"
868
- let displayJsenvErrorOverlay
870
+ const JSENV_ERROR_OVERLAY_TAGNAME = "jsenv-error-overlay";
871
+ let displayJsenvErrorOverlay;
869
872
  error_overlay: {
870
873
  displayJsenvErrorOverlay = (params) => {
871
874
  if (logs) {
872
- console.log("display jsenv error overlay", params)
875
+ console.log("display jsenv error overlay", params);
873
876
  }
874
- let jsenvErrorOverlay = new JsenvErrorOverlay(params)
877
+ let jsenvErrorOverlay = new JsenvErrorOverlay(params);
875
878
  document
876
879
  .querySelectorAll(JSENV_ERROR_OVERLAY_TAGNAME)
877
880
  .forEach((node) => {
878
- node.parentNode.removeChild(node)
879
- })
880
- document.body.appendChild(jsenvErrorOverlay)
881
+ node.parentNode.removeChild(node);
882
+ });
883
+ document.body.appendChild(jsenvErrorOverlay);
881
884
  const removeErrorOverlay = () => {
882
885
  if (jsenvErrorOverlay && jsenvErrorOverlay.parentNode) {
883
- document.body.removeChild(jsenvErrorOverlay)
884
- jsenvErrorOverlay = null
886
+ document.body.removeChild(jsenvErrorOverlay);
887
+ jsenvErrorOverlay = null;
885
888
  }
886
- }
887
- return removeErrorOverlay
888
- }
889
+ };
890
+ return removeErrorOverlay;
891
+ };
889
892
 
890
893
  class JsenvErrorOverlay extends HTMLElement {
891
894
  constructor({ theme, title, text, tip, errorDetailsPromise }) {
892
- super()
893
- this.root = this.attachShadow({ mode: "open" })
895
+ super();
896
+ this.root = this.attachShadow({ mode: "open" });
894
897
  this.root.innerHTML = `
895
898
  <style>
896
899
  ${overlayCSS}
@@ -904,50 +907,52 @@ window.__supervisor__ = (() => {
904
907
  <div class="tip">
905
908
  ${tip}
906
909
  </div>
907
- </div>`
910
+ </div>`;
908
911
  this.root.querySelector(".backdrop").onclick = () => {
909
912
  if (!this.parentNode) {
910
913
  // not in document anymore
911
- return
914
+ return;
912
915
  }
913
- this.root.querySelector(".backdrop").onclick = null
914
- this.parentNode.removeChild(this)
915
- }
916
+ this.root.querySelector(".backdrop").onclick = null;
917
+ this.parentNode.removeChild(this);
918
+ };
916
919
  if (errorDetailsPromise) {
917
920
  errorDetailsPromise.then((errorDetails) => {
918
921
  if (!errorDetails || !this.parentNode) {
919
- return
922
+ return;
920
923
  }
921
- const { codeFrame, cause } = errorDetails
924
+ const { codeFrame, cause } = errorDetails;
922
925
  if (codeFrame) {
923
- this.root.querySelector(".text").innerHTML += `\n\n${codeFrame}`
926
+ this.root.querySelector(
927
+ ".text",
928
+ ).innerHTML += `\n\n${codeFrame}`;
924
929
  }
925
930
  if (cause) {
926
- const causeIndented = prefixRemainingLines(cause, " ")
931
+ const causeIndented = prefixRemainingLines(cause, " ");
927
932
  this.root.querySelector(
928
933
  ".text",
929
- ).innerHTML += `\n [cause]: ${causeIndented}`
934
+ ).innerHTML += `\n [cause]: ${causeIndented}`;
930
935
  }
931
- })
936
+ });
932
937
  }
933
938
  }
934
939
  }
935
940
 
936
941
  const prefixRemainingLines = (text, prefix) => {
937
- const lines = text.split(/\r?\n/)
938
- const firstLine = lines.shift()
939
- let result = firstLine
940
- let i = 0
942
+ const lines = text.split(/\r?\n/);
943
+ const firstLine = lines.shift();
944
+ let result = firstLine;
945
+ let i = 0;
941
946
  while (i < lines.length) {
942
- const line = lines[i]
943
- i++
944
- result += line.length ? `\n${prefix}${line}` : `\n`
947
+ const line = lines[i];
948
+ i++;
949
+ result += line.length ? `\n${prefix}${line}` : `\n`;
945
950
  }
946
- return result
947
- }
951
+ return result;
952
+ };
948
953
 
949
954
  if (customElements && !customElements.get(JSENV_ERROR_OVERLAY_TAGNAME)) {
950
- customElements.define(JSENV_ERROR_OVERLAY_TAGNAME, JsenvErrorOverlay)
955
+ customElements.define(JSENV_ERROR_OVERLAY_TAGNAME, JsenvErrorOverlay);
951
956
  }
952
957
 
953
958
  const overlayCSS = `
@@ -1024,13 +1029,13 @@ window.__supervisor__ = (() => {
1024
1029
 
1025
1030
  pre a {
1026
1031
  color: inherit;
1027
- }`
1032
+ }`;
1028
1033
  }
1029
1034
 
1030
- supervisor.createException = createException
1035
+ supervisor.createException = createException;
1031
1036
  supervisor.reportException = (exception) => {
1032
1037
  const { theme, title, text, tip, errorDetailsPromise } =
1033
- formatError(exception)
1038
+ formatError(exception);
1034
1039
 
1035
1040
  if (errorOverlay) {
1036
1041
  const removeErrorOverlay = displayJsenvErrorOverlay({
@@ -1039,37 +1044,37 @@ window.__supervisor__ = (() => {
1039
1044
  text,
1040
1045
  tip,
1041
1046
  errorDetailsPromise,
1042
- })
1047
+ });
1043
1048
  if (window.__reloader__) {
1044
- const onchange = window.__reloader__.status.onchange
1049
+ const onchange = window.__reloader__.status.onchange;
1045
1050
  window.__reloader__.status.onchange = () => {
1046
- onchange()
1051
+ onchange();
1047
1052
  if (window.__reloader__.status.value === "reloading") {
1048
- removeErrorOverlay()
1053
+ removeErrorOverlay();
1049
1054
  }
1050
- }
1055
+ };
1051
1056
  }
1052
1057
  }
1053
1058
  if (errorNotification) {
1054
1059
  displayErrorNotification({
1055
1060
  title,
1056
1061
  text,
1057
- })
1062
+ });
1058
1063
  }
1059
- return exception
1060
- }
1064
+ return exception;
1065
+ };
1061
1066
  window.addEventListener("error", (errorEvent) => {
1062
1067
  if (!errorEvent.isTrusted) {
1063
1068
  // ignore custom error event (not sent by browser)
1064
1069
  if (logs) {
1065
- console.log("ignore non trusted error event", errorEvent)
1070
+ console.log("ignore non trusted error event", errorEvent);
1066
1071
  }
1067
- return
1072
+ return;
1068
1073
  }
1069
1074
  if (logs) {
1070
- console.log('window "error" event received', errorEvent)
1075
+ console.log('window "error" event received', errorEvent);
1071
1076
  }
1072
- const { error, message, filename, lineno, colno } = errorEvent
1077
+ const { error, message, filename, lineno, colno } = errorEvent;
1073
1078
  const exception = supervisor.createException(error || message, {
1074
1079
  // when error is reported within a worker error is null
1075
1080
  // but there is a message property on errorEvent
@@ -1077,72 +1082,72 @@ window.__supervisor__ = (() => {
1077
1082
  url: filename,
1078
1083
  line: lineno,
1079
1084
  column: colno,
1080
- })
1081
- supervisor.reportException(exception)
1082
- })
1085
+ });
1086
+ supervisor.reportException(exception);
1087
+ });
1083
1088
  window.addEventListener("unhandledrejection", (event) => {
1084
1089
  if (event.defaultPrevented) {
1085
- return
1090
+ return;
1086
1091
  }
1087
1092
  const exception = supervisor.createException(event.reason, {
1088
1093
  reportedBy: "window_unhandledrejection_event",
1089
- })
1090
- supervisor.reportException(exception)
1091
- })
1092
- }
1094
+ });
1095
+ supervisor.reportException(exception);
1096
+ });
1097
+ };
1093
1098
 
1094
1099
  const prepareScriptToLoad = (script) => {
1095
1100
  // do not use script.cloneNode()
1096
1101
  // bcause https://stackoverflow.com/questions/28771542/why-dont-clonenode-script-tags-execute
1097
- const scriptClone = document.createElement("script")
1102
+ const scriptClone = document.createElement("script");
1098
1103
  // browsers set async by default when creating script(s)
1099
1104
  // we want an exact copy to preserves how code is executed
1100
- scriptClone.async = false
1105
+ scriptClone.async = false;
1101
1106
  Array.from(script.attributes).forEach((attribute) => {
1102
- scriptClone.setAttribute(attribute.nodeName, attribute.nodeValue)
1103
- })
1104
- scriptClone.removeAttribute("jsenv-cooked-by")
1105
- scriptClone.removeAttribute("jsenv-inlined-by")
1106
- scriptClone.removeAttribute("jsenv-injected-by")
1107
- scriptClone.removeAttribute("inlined-from-src")
1108
- scriptClone.removeAttribute("original-position")
1109
- scriptClone.removeAttribute("original-src-position")
1107
+ scriptClone.setAttribute(attribute.nodeName, attribute.nodeValue);
1108
+ });
1109
+ scriptClone.removeAttribute("jsenv-cooked-by");
1110
+ scriptClone.removeAttribute("jsenv-inlined-by");
1111
+ scriptClone.removeAttribute("jsenv-injected-by");
1112
+ scriptClone.removeAttribute("inlined-from-src");
1113
+ scriptClone.removeAttribute("original-position");
1114
+ scriptClone.removeAttribute("original-src-position");
1110
1115
 
1111
- return scriptClone
1112
- }
1116
+ return scriptClone;
1117
+ };
1113
1118
 
1114
1119
  const getScriptLoadPromise = async (script) => {
1115
1120
  return new Promise((resolve) => {
1116
1121
  const windowErrorEventCallback = (errorEvent) => {
1117
1122
  if (errorEvent.filename === script.src) {
1118
- removeWindowErrorEventCallback()
1123
+ removeWindowErrorEventCallback();
1119
1124
  resolve({
1120
1125
  detectedBy: "window_error_event",
1121
1126
  failed: true,
1122
1127
  error: errorEvent,
1123
- })
1128
+ });
1124
1129
  }
1125
- }
1130
+ };
1126
1131
  const removeWindowErrorEventCallback = () => {
1127
- window.removeEventListener("error", windowErrorEventCallback)
1128
- }
1129
- window.addEventListener("error", windowErrorEventCallback)
1132
+ window.removeEventListener("error", windowErrorEventCallback);
1133
+ };
1134
+ window.addEventListener("error", windowErrorEventCallback);
1130
1135
  script.addEventListener("error", (errorEvent) => {
1131
- removeWindowErrorEventCallback()
1136
+ removeWindowErrorEventCallback();
1132
1137
  resolve({
1133
1138
  detectedBy: "script_error_event",
1134
1139
  failed: true,
1135
1140
  error: errorEvent,
1136
- })
1137
- })
1141
+ });
1142
+ });
1138
1143
  script.addEventListener("load", () => {
1139
- removeWindowErrorEventCallback()
1144
+ removeWindowErrorEventCallback();
1140
1145
  resolve({
1141
1146
  detectedBy: "script_load_event",
1142
- })
1143
- })
1144
- })
1145
- }
1147
+ });
1148
+ });
1149
+ });
1150
+ };
1146
1151
 
1147
- return supervisor
1148
- })()
1152
+ return supervisor;
1153
+ })();