@jsenv/core 27.0.0-alpha.6 → 27.0.0-alpha.60

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/dist/event_source_client.js +545 -0
  2. package/dist/event_source_client.js.map +187 -0
  3. package/dist/html_supervisor_installer.js +1236 -0
  4. package/dist/html_supervisor_installer.js.map +337 -0
  5. package/dist/html_supervisor_setup.js +95 -0
  6. package/dist/html_supervisor_setup.js.map +57 -0
  7. package/dist/import_meta_hot.js +86 -0
  8. package/dist/import_meta_hot.js.map +42 -0
  9. package/main.js +8 -1
  10. package/package.json +30 -28
  11. package/readme.md +6 -14
  12. package/src/build/build.js +943 -555
  13. package/src/build/build_urls_generator.js +48 -23
  14. package/src/build/graph_utils.js +31 -0
  15. package/src/build/{inject_version_mappings.js → inject_global_version_mappings.js} +33 -15
  16. package/src/build/inject_service_worker_urls.js +79 -0
  17. package/src/build/resync_ressource_hints.js +68 -0
  18. package/src/build/start_build_server.js +192 -0
  19. package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +2 -2
  20. package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +3 -1
  21. package/src/dev/start_dev_server.js +136 -30
  22. package/src/execute/execute.js +31 -6
  23. package/src/execute/run.js +19 -56
  24. package/src/execute/runtimes/browsers/from_playwright.js +207 -147
  25. package/src/execute/runtimes/node/controllable_file.mjs +26 -10
  26. package/src/execute/runtimes/node/node_execution_performance.js +67 -0
  27. package/src/execute/runtimes/node/node_process.js +280 -39
  28. package/src/jsenv_root_directory_url.js +1 -0
  29. package/src/omega/{runtime_support/default_runtime_support.js → compat/default_runtime_compat.js} +3 -5
  30. package/src/omega/{runtime_support/features_compatibility.js → compat/features_compats.js} +66 -4
  31. package/src/omega/compat/runtime_compat.js +50 -0
  32. package/src/omega/errors.js +51 -58
  33. package/src/omega/fetched_content_compliance.js +24 -0
  34. package/src/omega/file_url_converter.js +8 -50
  35. package/src/omega/kitchen.js +482 -304
  36. package/src/omega/omega_server.js +2 -3
  37. package/src/omega/server/file_service.js +53 -25
  38. package/src/omega/server/user_agent.js +4 -2
  39. package/src/omega/url_graph/url_graph_load.js +22 -7
  40. package/src/omega/url_graph/url_graph_report.js +98 -48
  41. package/src/omega/url_graph/url_info_transformations.js +26 -9
  42. package/src/omega/url_graph.js +80 -16
  43. package/src/omega/web_workers.js +42 -0
  44. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/autoreload_preference.js +0 -0
  45. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/event_source_client.js +2 -2
  46. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/reload.js +0 -0
  47. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/url_helpers.js +0 -0
  48. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +46 -0
  49. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js +204 -0
  50. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +27 -0
  51. package/src/plugins/autoreload/jsenv_plugin_hmr.js +35 -0
  52. package/src/plugins/bundling/css/bundle_css.js +140 -0
  53. package/src/plugins/bundling/js_classic_workers/bundle_js_classic_workers.js +13 -0
  54. package/src/plugins/bundling/js_module/bundle_js_module.js +309 -0
  55. package/src/plugins/bundling/jsenv_plugin_bundling.js +54 -0
  56. package/src/plugins/cache_control/jsenv_plugin_cache_control.js +34 -0
  57. package/src/{omega/core_plugins → plugins}/commonjs_globals/jsenv_plugin_commonjs_globals.js +54 -41
  58. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +66 -0
  59. package/src/{omega/core_plugins → plugins}/filesystem_magic/jsenv_plugin_filesystem_magic.js +8 -5
  60. package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_document.js +0 -0
  61. package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_notification.js +0 -0
  62. package/src/plugins/html_supervisor/client/html_supervisor_installer.js +242 -0
  63. package/src/plugins/html_supervisor/client/html_supervisor_setup.js +79 -0
  64. package/src/{omega/core_plugins → plugins}/html_supervisor/client/perf_browser.js +0 -0
  65. package/src/{omega/core_plugins → plugins}/html_supervisor/client/uneval_exception.js +0 -0
  66. package/src/{omega/core_plugins → plugins}/html_supervisor/jsenv_plugin_html_supervisor.js +83 -61
  67. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +12 -0
  68. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/babel_plugin_metadata_import_meta_hot.js +4 -5
  69. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/client/import_meta_hot.js +3 -1
  70. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/html_hot_dependencies.js +2 -2
  71. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +105 -0
  72. package/src/{omega/core_plugins → plugins}/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +33 -8
  73. package/src/plugins/import_meta_url/client/import_meta_url_browser.js +52 -0
  74. package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +9 -0
  75. package/src/{omega/core_plugins → plugins}/importmap/jsenv_plugin_importmap.js +39 -33
  76. package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +67 -0
  77. package/src/{omega/core_plugins → plugins}/inline/client/inline_content.js +0 -0
  78. package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_data_urls.js +18 -14
  79. package/src/{omega/core_plugins/inline/jsenv_plugin_js_and_css_inside_html.js → plugins/inline/jsenv_plugin_html_inline_content.js} +65 -44
  80. package/src/plugins/inline/jsenv_plugin_inline.js +36 -0
  81. package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_inline_query_param.js +6 -6
  82. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +297 -0
  83. package/src/plugins/leading_slash/jsenv_plugin_leading_slash.js +13 -0
  84. package/src/plugins/minification/css/minify_css.js +9 -0
  85. package/src/plugins/minification/html/minify_html.js +15 -0
  86. package/src/{build/plugins/minify_js/jsenv_plugin_minify_js.js → plugins/minification/js/minify_js.js} +6 -22
  87. package/src/plugins/minification/jsenv_plugin_minification.js +78 -0
  88. package/src/plugins/minification/json/minify_json.js +8 -0
  89. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +146 -0
  90. package/src/{omega → plugins}/plugin_controller.js +42 -11
  91. package/src/plugins/plugins.js +92 -0
  92. package/src/plugins/transpilation/as_js_classic/client/s.js +874 -0
  93. package/src/plugins/transpilation/as_js_classic/client/s.js.md +1 -0
  94. package/src/plugins/transpilation/as_js_classic/helpers/babel_plugin_transform_import_meta_url.js +47 -0
  95. package/src/plugins/transpilation/as_js_classic/helpers/systemjs_old.js +43 -0
  96. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +199 -0
  97. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +270 -0
  98. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js +55 -0
  99. package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +0 -0
  100. package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/client/global_this.js +0 -0
  101. package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +0 -0
  102. package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_structure.js +12 -19
  103. package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugins_compatibility.js +0 -0
  104. package/src/{omega/core_plugins → plugins/transpilation}/babel/jsenv_plugin_babel.js +45 -27
  105. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +30 -6
  106. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/.eslintrc.cjs +0 -0
  107. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/new_stylesheet.js +0 -0
  108. package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +0 -0
  109. package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/client/regenerator_runtime.js +0 -0
  110. package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +18 -0
  111. package/src/plugins/transpilation/fetch_original_url_info.js +30 -0
  112. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +181 -0
  113. package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +80 -0
  114. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +44 -0
  115. package/src/plugins/url_analysis/css/css_urls.js +49 -0
  116. package/src/plugins/url_analysis/html/html_urls.js +269 -0
  117. package/src/plugins/url_analysis/js/js_urls.js +67 -0
  118. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +18 -0
  119. package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +17 -0
  120. package/src/{omega/core_plugins → plugins}/url_resolution/jsenv_plugin_url_resolution.js +12 -5
  121. package/src/plugins/url_version/jsenv_plugin_url_version.js +28 -0
  122. package/src/test/execute_plan.js +30 -18
  123. package/src/test/execute_test_plan.js +23 -8
  124. package/src/test/logs_file_execution.js +9 -8
  125. package/src/build/plugins/bundle_js_module/jsenv_plugin_bundle_js_module.js +0 -225
  126. package/src/build/plugins/minify_html/jsenv_plugin_minify_html.js +0 -30
  127. package/src/dev/plugins/autoreload/client/event_source_connection.js +0 -195
  128. package/src/dev/plugins/autoreload/jsenv_plugin_autoreload.js +0 -374
  129. package/src/dev/plugins/autoreload/sse_service.js +0 -149
  130. package/src/execute/runtimes/node/controlled_process.js +0 -316
  131. package/src/omega/core_plugins/file_urls/jsenv_plugin_file_urls.js +0 -67
  132. package/src/omega/core_plugins/html_supervisor/client/html_supervisor_installer.js +0 -168
  133. package/src/omega/core_plugins/html_supervisor/client/html_supervisor_setup.js +0 -77
  134. package/src/omega/core_plugins/import_assertions/helpers/babel_plugin_metadata_import_assertions.js +0 -98
  135. package/src/omega/core_plugins/import_assertions/helpers/json_module.js +0 -12
  136. package/src/omega/core_plugins/import_assertions/helpers/text_module.js +0 -6
  137. package/src/omega/core_plugins/import_assertions/jsenv_plugin_import_assertions.js +0 -211
  138. package/src/omega/core_plugins/inline/jsenv_plugin_inline.js +0 -13
  139. package/src/omega/core_plugins/inline/jsenv_plugin_new_inline_content.js +0 -210
  140. package/src/omega/core_plugins/leading_slash/jsenv_plugin_leading_slash.js +0 -12
  141. package/src/omega/core_plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +0 -77
  142. package/src/omega/core_plugins/url_version/jsenv_plugin_url_version.js +0 -50
  143. package/src/omega/core_plugins.js +0 -39
  144. package/src/omega/runtime_support/runtime_support.js +0 -20
  145. package/src/omega/url_graph/url_graph_sort.js +0 -29
  146. package/src/omega/url_mentions/css_url_mentions.js +0 -63
  147. package/src/omega/url_mentions/html_url_mentions.js +0 -185
  148. package/src/omega/url_mentions/js_module_url_mentions.js +0 -91
  149. package/src/omega/url_mentions/parse_url_mentions.js +0 -37
  150. package/src/omega/url_mentions/worker_classic_url_mentions.js +0 -37
@@ -0,0 +1,242 @@
1
+ import { unevalException } from "./uneval_exception.js"
2
+ import { displayErrorInDocument } from "./error_in_document.js"
3
+ import { displayErrorNotification } from "./error_in_notification.js"
4
+
5
+ const { __html_supervisor__ } = window
6
+
7
+ export const installHtmlSupervisor = ({ logs, measurePerf }) => {
8
+ const errorTransformer = null // could implement error stack remapping if needed
9
+ const scriptExecutionResults = {}
10
+ let collectCalled = false
11
+ let pendingExecutionCount = 0
12
+ let resolveScriptExecutionsPromise
13
+ const scriptExecutionsPromise = new Promise((resolve) => {
14
+ resolveScriptExecutionsPromise = resolve
15
+ })
16
+ const onExecutionStart = (name) => {
17
+ scriptExecutionResults[name] = null // ensure execution order is reflected into the object
18
+ pendingExecutionCount++
19
+ if (measurePerf) {
20
+ performance.mark(`execution_start`)
21
+ }
22
+ }
23
+ const onExecutionSettled = (name, executionResult) => {
24
+ if (measurePerf) {
25
+ performance.measure(`execution`, `execution_start`)
26
+ }
27
+ scriptExecutionResults[name] = executionResult
28
+ pendingExecutionCount--
29
+ if (pendingExecutionCount === 0 && collectCalled) {
30
+ resolveScriptExecutionsPromise()
31
+ }
32
+ }
33
+ const onExecutionError = (
34
+ executionResult,
35
+ {
36
+ currentScript,
37
+ errorExposureInNotification = false,
38
+ errorExposureInDocument = true,
39
+ },
40
+ ) => {
41
+ const error = executionResult.error
42
+ if (error && error.code === "NETWORK_FAILURE") {
43
+ if (currentScript) {
44
+ const errorEvent = new Event("error")
45
+ currentScript.dispatchEvent(errorEvent)
46
+ }
47
+ } else if (typeof error === "object") {
48
+ const globalErrorEvent = new Event("error")
49
+ globalErrorEvent.filename = error.filename
50
+ globalErrorEvent.lineno = error.line || error.lineno
51
+ globalErrorEvent.colno = error.column || error.columnno
52
+ globalErrorEvent.message = error.message
53
+ window.dispatchEvent(globalErrorEvent)
54
+ }
55
+ if (errorExposureInNotification) {
56
+ displayErrorNotification(error)
57
+ }
58
+ if (errorExposureInDocument) {
59
+ displayErrorInDocument(error)
60
+ }
61
+ executionResult.exceptionSource = unevalException(error)
62
+ delete executionResult.error
63
+ }
64
+ const getNavigationStartTime = () => {
65
+ try {
66
+ return window.performance.timing.navigationStart
67
+ } catch (e) {
68
+ return Date.now()
69
+ }
70
+ }
71
+
72
+ const performExecution = async ({
73
+ src,
74
+ type,
75
+ currentScript,
76
+ execute,
77
+ // https://developer.mozilla.org/en-US/docs/web/html/element/script
78
+ }) => {
79
+ if (logs) {
80
+ console.group(`[jsenv] loading ${type} ${src}`)
81
+ }
82
+ onExecutionStart(src)
83
+ let completed
84
+ let result
85
+ let error
86
+ try {
87
+ result = await execute()
88
+ completed = true
89
+ } catch (e) {
90
+ completed = false
91
+ error = e
92
+ }
93
+ if (completed) {
94
+ const executionResult = {
95
+ status: "completed",
96
+ namespace: result,
97
+ coverage: window.__coverage__,
98
+ }
99
+ onExecutionSettled(src, executionResult)
100
+ if (logs) {
101
+ console.log(`${type} load ended`)
102
+ console.groupEnd()
103
+ }
104
+ return
105
+ }
106
+ const executionResult = {
107
+ status: "errored",
108
+ coverage: window.__coverage__,
109
+ }
110
+ let errorExposureInConsole = true
111
+ if (error.name === "SyntaxError") {
112
+ // errorExposureInConsole = false
113
+ }
114
+ if (errorTransformer) {
115
+ try {
116
+ error = await errorTransformer(error)
117
+ } catch (e) {}
118
+ }
119
+ executionResult.error = error
120
+ onExecutionSettled(src, executionResult)
121
+ onExecutionError(executionResult, {
122
+ currentScript,
123
+ })
124
+ if (errorExposureInConsole) {
125
+ if (typeof window.reportError === "function") {
126
+ window.reportError(error)
127
+ } else {
128
+ console.error(error)
129
+ }
130
+ }
131
+ if (logs) {
132
+ console.groupEnd()
133
+ }
134
+ }
135
+
136
+ const queue = []
137
+ let previousDonePromise = null
138
+ const dequeue = () => {
139
+ const next = queue.shift()
140
+ if (next) {
141
+ __html_supervisor__.addScriptToExecute(next)
142
+ } else {
143
+ const nextDefered = deferQueue.shift()
144
+ if (nextDefered) {
145
+ __html_supervisor__.addScriptToExecute(nextDefered)
146
+ }
147
+ }
148
+ }
149
+ const deferQueue = []
150
+ let previousDeferDonePromise = null
151
+ __html_supervisor__.addScriptToExecute = async (scriptToExecute) => {
152
+ if (scriptToExecute.async) {
153
+ performExecution(scriptToExecute)
154
+ return
155
+ }
156
+ const useDeferQueue =
157
+ scriptToExecute.defer || scriptToExecute.type === "js_module"
158
+ if (useDeferQueue) {
159
+ if (document.readyState !== "interactive") {
160
+ deferQueue.push(scriptToExecute)
161
+ return
162
+ }
163
+ if (previousDonePromise) {
164
+ // defer must wait for the regular script to be done
165
+ deferQueue.push(scriptToExecute)
166
+ return
167
+ }
168
+ if (previousDeferDonePromise) {
169
+ deferQueue.push(scriptToExecute)
170
+ return
171
+ }
172
+ previousDeferDonePromise = performExecution(scriptToExecute)
173
+ await previousDeferDonePromise
174
+ previousDeferDonePromise = null
175
+ dequeue()
176
+ return
177
+ }
178
+ if (previousDonePromise) {
179
+ queue.push(scriptToExecute)
180
+ return
181
+ }
182
+ previousDonePromise = performExecution(scriptToExecute)
183
+ await previousDonePromise
184
+ previousDonePromise = null
185
+ dequeue()
186
+ }
187
+ if (
188
+ document.readyState !== "intractive" &&
189
+ document.readyState !== "complete"
190
+ ) {
191
+ document.addEventListener("readystatechange", () => {
192
+ if (document.readyState === "interactive") {
193
+ const nextDefered = deferQueue.shift()
194
+ if (nextDefered) {
195
+ __html_supervisor__.addScriptToExecute(nextDefered)
196
+ }
197
+ }
198
+ })
199
+ }
200
+
201
+ __html_supervisor__.collectScriptResults = async () => {
202
+ collectCalled = true
203
+ if (pendingExecutionCount === 0) {
204
+ resolveScriptExecutionsPromise()
205
+ } else {
206
+ await scriptExecutionsPromise
207
+ }
208
+
209
+ let status = "completed"
210
+ let exceptionSource = ""
211
+ Object.keys(scriptExecutionResults).forEach((key) => {
212
+ const scriptExecutionResult = scriptExecutionResults[key]
213
+ if (scriptExecutionResult.status === "errored") {
214
+ status = "errored"
215
+ exceptionSource = scriptExecutionResult.exceptionSource
216
+ }
217
+ })
218
+ return {
219
+ status,
220
+ ...(status === "errored" ? { exceptionSource } : {}),
221
+ startTime: getNavigationStartTime(),
222
+ endTime: Date.now(),
223
+ scriptExecutionResults,
224
+ }
225
+ }
226
+
227
+ const { scriptsToExecute } = __html_supervisor__
228
+ const copy = scriptsToExecute.slice()
229
+ scriptsToExecute.length = 0
230
+ copy.forEach((scriptToExecute) => {
231
+ __html_supervisor__.addScriptToExecute(scriptToExecute)
232
+ })
233
+ }
234
+
235
+ export const superviseScriptTypeModule = ({ src, isInline }) => {
236
+ __html_supervisor__.addScriptToExecute({
237
+ src,
238
+ type: "js_module",
239
+ isInline,
240
+ execute: () => import(new URL(src, document.location.href).href),
241
+ })
242
+ }
@@ -0,0 +1,79 @@
1
+ window.__html_supervisor__ = {
2
+ // "html_supervisor_installer.js" will implement
3
+ // - "addScriptToExecute"
4
+ // - "superviseScriptTypeModule"
5
+ // - "collectScriptResults"
6
+ // and take all executions in "scriptsToExecute" and implement their supervision
7
+ scriptsToExecute: [],
8
+ addScriptToExecute: (scriptToExecute) => {
9
+ window.__html_supervisor__.scriptsToExecute.push(scriptToExecute)
10
+ },
11
+ superviseScript: ({ src, isInline, crossorigin, integrity }) => {
12
+ window.__html_supervisor__.addScriptToExecute({
13
+ src,
14
+ type: "js_classic",
15
+ isInline,
16
+ currentScript: document.currentScript,
17
+ execute: () => {
18
+ return new Promise((resolve, reject) => {
19
+ const script = document.createElement("script")
20
+ if (crossorigin) {
21
+ script.crossorigin = crossorigin
22
+ }
23
+ if (integrity) {
24
+ script.integrity = integrity
25
+ }
26
+ script.src = src
27
+ const scriptUrl = new URL(src, window.location).href
28
+ let lastWindowErrorUrl
29
+ let lastWindowError
30
+ const windowErrorCallback = (e) => {
31
+ lastWindowErrorUrl = e.filename
32
+ lastWindowError = e.error
33
+ }
34
+ const cleanup = () => {
35
+ document.body.removeChild(script)
36
+ window.removeEventListener("error", windowErrorCallback)
37
+ }
38
+ window.addEventListener("error", windowErrorCallback)
39
+ script.addEventListener("error", () => {
40
+ cleanup()
41
+ reject(src)
42
+ })
43
+ script.addEventListener("load", () => {
44
+ cleanup()
45
+ if (lastWindowErrorUrl === scriptUrl) {
46
+ reject(lastWindowError)
47
+ } else {
48
+ resolve()
49
+ }
50
+ })
51
+ document.body.appendChild(script)
52
+ })
53
+ },
54
+ })
55
+ },
56
+ superviseScriptTypeModule: () => {
57
+ throw new Error("htmlSupervisor not installed")
58
+ },
59
+ getScriptExecutionResults: () => {
60
+ // wait for page to load before collecting script execution results
61
+ const htmlReadyPromise = new Promise((resolve) => {
62
+ if (document.readyState === "complete") {
63
+ resolve()
64
+ return
65
+ }
66
+ const loadCallback = () => {
67
+ window.removeEventListener("load", loadCallback)
68
+ resolve()
69
+ }
70
+ window.addEventListener("load", loadCallback)
71
+ })
72
+ return htmlReadyPromise.then(() => {
73
+ return window.__html_supervisor__.collectScriptResults()
74
+ })
75
+ },
76
+ collectScriptResults: () => {
77
+ throw new Error("htmlSupervisor not installed")
78
+ },
79
+ }
@@ -2,42 +2,41 @@
2
2
  * Things happening here
3
3
  * - html supervisor module injection
4
4
  * - scripts are wrapped to be supervised
5
- *
6
- * TODO:
7
- * - if ressource is referenced by ressource hint we should do sthing?
8
- * I think so when we inject ?js_classic
9
5
  */
10
6
 
11
- import { injectQueryParams } from "@jsenv/utils/urls/url_utils.js"
7
+ import { urlIsInsideOf } from "@jsenv/filesystem"
8
+
12
9
  import {
13
10
  parseHtmlString,
14
11
  stringifyHtmlAst,
15
12
  visitHtmlAst,
16
13
  getHtmlNodeAttributeByName,
17
14
  removeHtmlNodeAttributeByName,
18
- setHtmlNodeText,
19
- assignHtmlNodeAttributes,
20
15
  parseScriptNode,
21
16
  injectScriptAsEarlyAsPossible,
22
17
  createHtmlNode,
23
18
  htmlNodePosition,
24
- removeHtmlNodeText,
25
19
  getHtmlNodeTextNode,
20
+ removeHtmlNodeText,
21
+ setHtmlNodeGeneratedText,
26
22
  } from "@jsenv/utils/html_ast/html_ast.js"
27
23
  import { generateInlineContentUrl } from "@jsenv/utils/urls/inline_content_url_generator.js"
24
+ import { jsenvRootDirectoryUrl } from "@jsenv/core/src/jsenv_root_directory_url.js"
28
25
 
29
26
  export const jsenvPluginHtmlSupervisor = ({
27
+ rootDirectoryUrl,
30
28
  logs = false,
31
29
  measurePerf = false,
32
- } = {}) => {
33
- const htmlSupervisorSetupFileUrl = new URL(
34
- "./client/html_supervisor_setup.js",
35
- import.meta.url,
36
- ).href
37
- const htmlSupervisorInstallerFileUrl = new URL(
38
- "./client/html_supervisor_installer.js",
39
- import.meta.url,
40
- ).href
30
+ }) => {
31
+ const preferSourceFiles =
32
+ rootDirectoryUrl === jsenvRootDirectoryUrl ||
33
+ urlIsInsideOf(rootDirectoryUrl, jsenvRootDirectoryUrl)
34
+ const htmlSupervisorSetupFileUrl = preferSourceFiles
35
+ ? new URL("./client/html_supervisor_setup.js", import.meta.url).href
36
+ : new URL("./dist/html_supervisor_setup.js", jsenvRootDirectoryUrl).href
37
+ const htmlSupervisorInstallerFileUrl = preferSourceFiles
38
+ ? new URL("./client/html_supervisor_installer.js", import.meta.url).href
39
+ : new URL("./dist/html_supervisor_installer.js", jsenvRootDirectoryUrl).href
41
40
 
42
41
  return {
43
42
  name: "jsenv:html_supervisor",
@@ -45,7 +44,7 @@ export const jsenvPluginHtmlSupervisor = ({
45
44
  dev: true,
46
45
  test: true,
47
46
  },
48
- transform: {
47
+ transformUrlContent: {
49
48
  html: ({ url, content }, { referenceUtils }) => {
50
49
  const htmlAst = parseHtmlString(content)
51
50
  const scriptsToSupervise = []
@@ -64,27 +63,22 @@ export const jsenvPluginHtmlSupervisor = ({
64
63
  lineEnd,
65
64
  columnEnd,
66
65
  })
67
- if (scriptCategory === "classic") {
68
- inlineScriptUrl = injectQueryParams(inlineScriptUrl, {
69
- js_classic: "",
70
- })
71
- }
72
66
  const [inlineScriptReference] = referenceUtils.foundInline({
73
67
  type: "script_src",
74
- line: line - 1,
75
- column,
76
- isOriginal,
68
+ expectedType: { classic: "js_classic", module: "js_module" }[
69
+ scriptCategory
70
+ ],
71
+ isOriginalPosition: isOriginal,
72
+ specifierLine: line - 1,
73
+ specifierColumn: column,
77
74
  specifier: inlineScriptUrl,
78
- contentType: "application/javascript",
75
+ contentType: "text/javascript",
79
76
  content: textNode.value,
80
77
  })
81
- assignHtmlNodeAttributes(node, {
82
- "src": inlineScriptReference.generatedSpecifier,
83
- "src-generated-from-inline-content": "",
84
- })
85
78
  removeHtmlNodeText(node)
86
79
  scriptsToSupervise.push({
87
80
  node,
81
+ isInline: true,
88
82
  type: scriptCategory,
89
83
  src: inlineScriptReference.generatedSpecifier,
90
84
  })
@@ -105,10 +99,17 @@ export const jsenvPluginHtmlSupervisor = ({
105
99
  const crossorigin = crossoriginAttribute
106
100
  ? crossoriginAttribute.value
107
101
  : undefined
102
+ const deferAttribute = getHtmlNodeAttributeByName(node, "crossorigin")
103
+ const defer = deferAttribute ? deferAttribute.value : undefined
104
+ const asyncAttribute = getHtmlNodeAttributeByName(node, "crossorigin")
105
+ const async = asyncAttribute ? asyncAttribute.value : undefined
106
+ removeHtmlNodeAttributeByName(node, "src")
108
107
  scriptsToSupervise.push({
109
108
  node,
110
109
  type: scriptCategory,
111
110
  src: srcAttribute.value,
111
+ defer,
112
+ async,
112
113
  integrity,
113
114
  crossorigin,
114
115
  })
@@ -146,11 +147,9 @@ export const jsenvPluginHtmlSupervisor = ({
146
147
  return
147
148
  }
148
149
  })
149
- if (scriptsToSupervise.length === 0) {
150
- return null
151
- }
152
150
  const [htmlSupervisorInstallerFileReference] = referenceUtils.inject({
153
151
  type: "js_import_export",
152
+ expectedType: "js_module",
154
153
  specifier: htmlSupervisorInstallerFileUrl,
155
154
  })
156
155
  injectScriptAsEarlyAsPossible(
@@ -159,25 +158,24 @@ export const jsenvPluginHtmlSupervisor = ({
159
158
  "tagName": "script",
160
159
  "type": "module",
161
160
  "textContent": `
162
- import { installHtmlSupervisor } from ${
163
- htmlSupervisorInstallerFileReference.generatedSpecifier
164
- }
165
- installHtmlSupervisor(${JSON.stringify(
166
- {
167
- logs,
168
- measurePerf,
169
- },
170
- null,
171
- " ",
172
- )})`,
161
+ import { installHtmlSupervisor } from ${
162
+ htmlSupervisorInstallerFileReference.generatedSpecifier
163
+ }
164
+ installHtmlSupervisor(${JSON.stringify(
165
+ {
166
+ logs,
167
+ measurePerf,
168
+ },
169
+ null,
170
+ " ",
171
+ )})`,
173
172
  "injected-by": "jsenv:html_supervisor",
174
173
  }),
175
174
  )
176
175
  const [htmlSupervisorSetupFileReference] = referenceUtils.inject({
177
176
  type: "script_src",
178
- specifier: injectQueryParams(htmlSupervisorSetupFileUrl, {
179
- js_classic: "",
180
- }),
177
+ expectedType: "js_classic",
178
+ specifier: htmlSupervisorSetupFileUrl,
181
179
  })
182
180
  injectScriptAsEarlyAsPossible(
183
181
  htmlAst,
@@ -188,22 +186,32 @@ installHtmlSupervisor(${JSON.stringify(
188
186
  }),
189
187
  )
190
188
  scriptsToSupervise.forEach(
191
- ({ node, type, src, integrity, crossorigin }) => {
192
- removeHtmlNodeAttributeByName(node, "src")
193
- assignHtmlNodeAttributes(node, {
194
- "content-src": src,
195
- })
196
- setHtmlNodeText(
197
- node,
198
- generateCodeToSuperviseScript({
189
+ ({
190
+ node,
191
+ isInline,
192
+ type,
193
+ src,
194
+ defer,
195
+ async,
196
+ integrity,
197
+ crossorigin,
198
+ }) => {
199
+ setHtmlNodeGeneratedText(node, {
200
+ generatedText: generateCodeToSuperviseScript({
199
201
  type,
200
202
  src,
203
+ isInline,
204
+ defer,
205
+ async,
201
206
  integrity,
202
207
  crossorigin,
203
208
  htmlSupervisorInstallerSpecifier:
204
209
  htmlSupervisorInstallerFileReference.generatedSpecifier,
205
210
  }),
206
- )
211
+ generatedBy: "jsenv:html_supervisor",
212
+ generatedFromSrc: src,
213
+ generatedFromInlineContent: isInline,
214
+ })
207
215
  },
208
216
  )
209
217
  const htmlModified = stringifyHtmlAst(htmlAst)
@@ -220,14 +228,28 @@ installHtmlSupervisor(${JSON.stringify(
220
228
  const generateCodeToSuperviseScript = ({
221
229
  type,
222
230
  src,
231
+ isInline,
232
+ defer,
233
+ async,
223
234
  integrity,
224
235
  crossorigin,
225
236
  htmlSupervisorInstallerSpecifier,
226
237
  }) => {
227
- const paramsAsJson = JSON.stringify({ src, integrity, crossorigin })
238
+ const paramsAsJson = JSON.stringify({
239
+ src,
240
+ isInline,
241
+ defer,
242
+ async,
243
+ integrity,
244
+ crossorigin,
245
+ })
228
246
  if (type === "module") {
229
- return `import { superviseScriptTypeModule } from ${htmlSupervisorInstallerSpecifier}
230
- superviseScriptTypeModule(${paramsAsJson})`
247
+ return `
248
+ import { superviseScriptTypeModule } from ${htmlSupervisorInstallerSpecifier}
249
+ superviseScriptTypeModule(${paramsAsJson})
250
+ `
231
251
  }
232
- return `window.__html_supervisor__.superviseScript(${paramsAsJson})`
252
+ return `
253
+ window.__html_supervisor__.superviseScript(${paramsAsJson})
254
+ `
233
255
  }
@@ -0,0 +1,12 @@
1
+ export const jsenvPluginHttpUrls = () => {
2
+ return {
3
+ name: "jsenv:http_urls",
4
+ appliesDuring: "*",
5
+ fetchUrlContent: (urlInfo) => {
6
+ if (urlInfo.url.startsWith("http") || urlInfo.url.startsWith("https")) {
7
+ return { external: true }
8
+ }
9
+ return null
10
+ },
11
+ }
12
+ }
@@ -16,13 +16,12 @@ export const babelPluginMetadataImportMetaHot = () => {
16
16
  }
17
17
  }
18
18
  const collectImportMetaProperties = (programPath) => {
19
- let importMetaHotDetected = false
19
+ const importMetaHotPaths = []
20
20
  let hotDecline = false
21
21
  let hotAcceptSelf = false
22
22
  let hotAcceptDependencies = []
23
23
  programPath.traverse({
24
24
  MemberExpression(path) {
25
- if (importMetaHotDetected) return
26
25
  const { node } = path
27
26
  const { object } = node
28
27
  if (object.type !== "MetaProperty") {
@@ -35,7 +34,7 @@ const collectImportMetaProperties = (programPath) => {
35
34
  const { property } = node
36
35
  const { name } = property
37
36
  if (name === "hot") {
38
- importMetaHotDetected = true
37
+ importMetaHotPaths.push(path)
39
38
  }
40
39
  },
41
40
  CallExpression(path) {
@@ -64,7 +63,7 @@ const collectImportMetaProperties = (programPath) => {
64
63
  )
65
64
  }
66
65
  return {
67
- specifierPath: firstArgPath.get(index),
66
+ specifierPath: firstArgPath.get(String(index)),
68
67
  }
69
68
  })
70
69
  return
@@ -79,7 +78,7 @@ const collectImportMetaProperties = (programPath) => {
79
78
  },
80
79
  })
81
80
  return {
82
- importMetaHotDetected,
81
+ importMetaHotPaths,
83
82
  hotDecline,
84
83
  hotAcceptSelf,
85
84
  hotAcceptDependencies,
@@ -40,7 +40,9 @@ export const createImportMetaHot = (importMetaUrl) => {
40
40
  })
41
41
  return
42
42
  }
43
- throw new Error(`invalid call to hot.accept()`)
43
+ throw new Error(
44
+ `invalid call to import.meta.hot.accept(), received ${firstArg}`,
45
+ )
44
46
  },
45
47
  dispose: (callback) => {
46
48
  addUrlMeta(url, {
@@ -53,7 +53,7 @@ export const collectHotDataFromHtmlAst = (htmlAst) => {
53
53
  })
54
54
  visitUrlSpecifierAttribute({
55
55
  node,
56
- attributeName: "content-href",
56
+ attributeName: "generated-from-href",
57
57
  hotAccepted,
58
58
  })
59
59
  }
@@ -65,7 +65,7 @@ export const collectHotDataFromHtmlAst = (htmlAst) => {
65
65
  })
66
66
  visitUrlSpecifierAttribute({
67
67
  node,
68
- attributeName: "content-src",
68
+ attributeName: "generated-from-src",
69
69
  hotAccepted,
70
70
  })
71
71
  }