@jsenv/core 27.0.0-alpha.8 → 27.0.0-alpha.82

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 (254) hide show
  1. package/dist/babel_helpers/AsyncGenerator/AsyncGenerator.js +95 -0
  2. package/dist/babel_helpers/AwaitValue/AwaitValue.js +3 -0
  3. package/dist/babel_helpers/applyDecoratorDescriptor/applyDecoratorDescriptor.js +29 -0
  4. package/dist/babel_helpers/applyDecs/applyDecs.js +756 -0
  5. package/dist/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +9 -0
  6. package/dist/babel_helpers/arrayWithHoles/arrayWithHoles.js +4 -0
  7. package/dist/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +5 -0
  8. package/dist/babel_helpers/assertThisInitialized/assertThisInitialized.js +8 -0
  9. package/dist/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +52 -0
  10. package/dist/babel_helpers/asyncIterator/asyncIterator.js +78 -0
  11. package/dist/babel_helpers/asyncToGenerator/asyncToGenerator.js +39 -0
  12. package/dist/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +4 -0
  13. package/dist/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +24 -0
  14. package/dist/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +7 -0
  15. package/dist/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +14 -0
  16. package/dist/babel_helpers/classCallCheck/classCallCheck.js +5 -0
  17. package/dist/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -0
  18. package/dist/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -0
  19. package/dist/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +8 -0
  20. package/dist/babel_helpers/classNameTDZError/classNameTDZError.js +4 -0
  21. package/dist/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +6 -0
  22. package/dist/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +6 -0
  23. package/dist/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +7 -0
  24. package/dist/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -0
  25. package/dist/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +7 -0
  26. package/dist/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +7 -0
  27. package/dist/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +3 -0
  28. package/dist/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +8 -0
  29. package/dist/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +9 -0
  30. package/dist/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +5 -0
  31. package/dist/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -0
  32. package/dist/babel_helpers/construct/construct.js +15 -0
  33. package/dist/babel_helpers/createClass/createClass.js +18 -0
  34. package/dist/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +63 -0
  35. package/dist/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +22 -0
  36. package/dist/babel_helpers/createRawReactElement/createRawReactElement.js +50 -0
  37. package/dist/babel_helpers/createSuper/createSuper.js +22 -0
  38. package/dist/babel_helpers/decorate/decorate.js +622 -0
  39. package/dist/babel_helpers/defaults/defaults.js +14 -0
  40. package/dist/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +26 -0
  41. package/dist/babel_helpers/defineProperty/defineProperty.js +19 -0
  42. package/dist/babel_helpers/extends/extends.js +16 -0
  43. package/dist/babel_helpers/get/get.js +21 -0
  44. package/dist/babel_helpers/getPrototypeOf/getPrototypeOf.js +2 -0
  45. package/dist/babel_helpers/identity/identity.js +3 -0
  46. package/dist/babel_helpers/inherits/inherits.js +21 -0
  47. package/dist/babel_helpers/inheritsLoose/inheritsLoose.js +6 -0
  48. package/dist/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +10 -0
  49. package/dist/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +3 -0
  50. package/dist/babel_helpers/instanceof/instanceof.js +7 -0
  51. package/dist/babel_helpers/interopRequireDefault/interopRequireDefault.js +5 -0
  52. package/dist/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +49 -0
  53. package/dist/babel_helpers/isNativeFunction/isNativeFunction.js +4 -0
  54. package/dist/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -0
  55. package/dist/babel_helpers/iterableToArray/iterableToArray.js +3 -0
  56. package/dist/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +38 -0
  57. package/dist/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +13 -0
  58. package/dist/babel_helpers/jsx/jsx.js +49 -0
  59. package/dist/babel_helpers/maybeArrayLike/maybeArrayLike.js +10 -0
  60. package/dist/babel_helpers/newArrowCheck/newArrowCheck.js +5 -0
  61. package/dist/babel_helpers/nonIterableRest/nonIterableRest.js +3 -0
  62. package/dist/babel_helpers/nonIterableSpread/nonIterableSpread.js +3 -0
  63. package/dist/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -0
  64. package/dist/babel_helpers/objectSpread/objectSpread.js +22 -0
  65. package/dist/babel_helpers/objectSpread2/objectSpread2.js +41 -0
  66. package/dist/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +20 -0
  67. package/dist/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +15 -0
  68. package/dist/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +10 -0
  69. package/dist/babel_helpers/readOnlyError/readOnlyError.js +4 -0
  70. package/dist/babel_helpers/set/set.js +51 -0
  71. package/dist/babel_helpers/setPrototypeOf/setPrototypeOf.js +5 -0
  72. package/dist/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -0
  73. package/dist/babel_helpers/slicedToArray/slicedToArray.js +5 -0
  74. package/dist/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +7 -0
  75. package/dist/babel_helpers/superPropBase/superPropBase.js +10 -0
  76. package/dist/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +11 -0
  77. package/dist/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +8 -0
  78. package/dist/babel_helpers/tdz/tdz.js +4 -0
  79. package/dist/babel_helpers/temporalRef/temporalRef.js +5 -0
  80. package/dist/babel_helpers/temporalUndefined/temporalUndefined.js +3 -0
  81. package/dist/babel_helpers/toArray/toArray.js +5 -0
  82. package/dist/babel_helpers/toConsumableArray/toConsumableArray.js +5 -0
  83. package/dist/babel_helpers/toPrimitive/toPrimitive.js +14 -0
  84. package/dist/babel_helpers/toPropertyKey/toPropertyKey.js +5 -0
  85. package/dist/babel_helpers/typeof/typeof.js +7 -0
  86. package/dist/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +10 -0
  87. package/dist/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +7 -0
  88. package/dist/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +35 -0
  89. package/dist/babel_helpers/wrapRegExp/wrapRegExp.js +67 -0
  90. package/dist/babel_helpers/writeOnlyError/writeOnlyError.js +4 -0
  91. package/dist/html/explorer.html +557 -0
  92. package/dist/js/controllable_file.mjs +227 -0
  93. package/dist/js/event_source_client.js +324 -0
  94. package/dist/js/global_this.js +32 -0
  95. package/dist/js/html_supervisor_installer.js +522 -0
  96. package/dist/js/html_supervisor_setup.js +82 -0
  97. package/dist/js/import_meta_hot.js +84 -0
  98. package/dist/js/inline_content.js +8 -0
  99. package/dist/js/new_stylesheet.js +409 -0
  100. package/dist/js/regenerator_runtime.js +721 -0
  101. package/dist/js/s.js +429 -0
  102. package/dist/main.js +13422 -0
  103. package/dist/other/jsenv.png +0 -0
  104. package/dist/s.js +626 -0
  105. package/dist/s.js.map +204 -0
  106. package/package.json +57 -51
  107. package/readme.md +6 -14
  108. package/src/build/build.js +1074 -563
  109. package/src/build/build_urls_generator.js +65 -24
  110. package/src/build/graph_utils.js +31 -0
  111. package/src/build/{inject_version_mappings.js → inject_global_version_mappings.js} +49 -18
  112. package/src/build/inject_service_worker_urls.js +79 -0
  113. package/src/build/resync_ressource_hints.js +115 -0
  114. package/src/build/start_build_server.js +210 -0
  115. package/src/dev/plugins/explorer/client/explorer.html +1 -1
  116. package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +9 -13
  117. package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +3 -1
  118. package/src/dev/start_dev_server.js +165 -38
  119. package/src/execute/execute.js +35 -8
  120. package/src/execute/run.js +21 -57
  121. package/src/execute/runtimes/browsers/from_playwright.js +220 -150
  122. package/src/execute/runtimes/node/child_exec_options.js +1 -1
  123. package/src/execute/runtimes/node/controllable_file.mjs +26 -10
  124. package/src/execute/runtimes/node/kill_process_tree.js +2 -4
  125. package/src/execute/runtimes/node/node_execution_performance.js +67 -0
  126. package/src/execute/runtimes/node/node_process.js +288 -39
  127. package/src/main.js +27 -0
  128. package/src/omega/{runtime_support/features_compatibility.js → compat/features_compats.js} +30 -7
  129. package/src/omega/{runtime_support/runtime_support.js → compat/runtime_compat.js} +14 -16
  130. package/src/omega/errors.js +63 -67
  131. package/src/omega/fetched_content_compliance.js +24 -0
  132. package/src/omega/file_url_converter.js +9 -51
  133. package/src/omega/kitchen.js +605 -467
  134. package/src/omega/omega_server.js +2 -3
  135. package/src/omega/server/file_service.js +88 -41
  136. package/src/omega/server/user_agent.js +5 -6
  137. package/src/omega/url_graph/url_graph_load.js +31 -23
  138. package/src/omega/url_graph/url_graph_report.js +94 -51
  139. package/src/omega/url_graph/url_info_transformations.js +37 -17
  140. package/src/omega/url_graph.js +88 -19
  141. package/src/omega/url_specifier_encoding.js +59 -0
  142. package/src/omega/web_workers.js +42 -0
  143. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/autoreload_preference.js +0 -0
  144. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/event_source_client.js +19 -12
  145. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/reload.js +0 -0
  146. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/url_helpers.js +0 -0
  147. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +41 -0
  148. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js +204 -0
  149. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +25 -0
  150. package/src/plugins/autoreload/jsenv_plugin_hmr.js +35 -0
  151. package/src/plugins/bundling/css/bundle_css.js +140 -0
  152. package/src/plugins/bundling/js_classic_workers/bundle_js_classic_workers.js +13 -0
  153. package/src/plugins/bundling/js_module/bundle_js_module.js +343 -0
  154. package/src/plugins/bundling/jsenv_plugin_bundling.js +54 -0
  155. package/src/plugins/cache_control/jsenv_plugin_cache_control.js +34 -0
  156. package/src/{omega/core_plugins → plugins}/commonjs_globals/jsenv_plugin_commonjs_globals.js +54 -41
  157. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +183 -0
  158. package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_document.js +0 -0
  159. package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_notification.js +0 -0
  160. package/src/plugins/html_supervisor/client/html_supervisor_installer.js +254 -0
  161. package/src/plugins/html_supervisor/client/html_supervisor_setup.js +82 -0
  162. package/src/{omega/core_plugins → plugins}/html_supervisor/client/perf_browser.js +0 -0
  163. package/src/{omega/core_plugins → plugins}/html_supervisor/client/uneval_exception.js +0 -0
  164. package/src/{omega/core_plugins → plugins}/html_supervisor/jsenv_plugin_html_supervisor.js +73 -55
  165. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +12 -0
  166. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/babel_plugin_metadata_import_meta_hot.js +4 -5
  167. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/client/import_meta_hot.js +3 -1
  168. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/html_hot_dependencies.js +7 -4
  169. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +100 -0
  170. package/src/{omega/core_plugins → plugins}/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +33 -8
  171. package/src/plugins/import_meta_url/client/import_meta_url_browser.js +52 -0
  172. package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +9 -0
  173. package/src/{omega/core_plugins → plugins}/importmap/jsenv_plugin_importmap.js +40 -36
  174. package/src/plugins/inject_globals/inject_globals.js +57 -0
  175. package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +24 -0
  176. package/src/{omega/core_plugins → plugins}/inline/client/inline_content.js +0 -0
  177. package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_data_urls.js +22 -21
  178. package/src/plugins/inline/jsenv_plugin_html_inline_content.js +161 -0
  179. package/src/plugins/inline/jsenv_plugin_inline.js +36 -0
  180. package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_inline_query_param.js +8 -11
  181. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +294 -0
  182. package/src/plugins/leading_slash/jsenv_plugin_leading_slash.js +13 -0
  183. package/src/plugins/minification/css/minify_css.js +9 -0
  184. package/src/plugins/minification/html/minify_html.js +13 -0
  185. package/src/{build/plugins/minify_js/jsenv_plugin_minify_js.js → plugins/minification/js/minify_js.js} +6 -22
  186. package/src/plugins/minification/jsenv_plugin_minification.js +78 -0
  187. package/src/plugins/minification/json/minify_json.js +8 -0
  188. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +162 -0
  189. package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +12 -0
  190. package/src/{omega → plugins}/plugin_controller.js +57 -12
  191. package/src/plugins/plugins.js +89 -0
  192. package/src/plugins/transpilation/as_js_classic/client/s.js +429 -0
  193. package/src/plugins/transpilation/as_js_classic/helpers/babel_plugin_transform_import_meta_url.js +47 -0
  194. package/src/plugins/transpilation/as_js_classic/helpers/systemjs_old.js +43 -0
  195. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +211 -0
  196. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +304 -0
  197. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_workers.js +55 -0
  198. package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +0 -0
  199. package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/client/global_this.js +0 -0
  200. package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +0 -0
  201. package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_structure.js +14 -17
  202. package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugins_compatibility.js +0 -0
  203. package/src/{omega/core_plugins → plugins/transpilation}/babel/jsenv_plugin_babel.js +39 -32
  204. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +30 -6
  205. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/new_stylesheet.js +0 -0
  206. package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +0 -0
  207. package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/client/regenerator_runtime.js +0 -0
  208. package/src/plugins/transpilation/babel/require_babel_plugin.js +8 -0
  209. package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +18 -0
  210. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +184 -0
  211. package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +79 -0
  212. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +46 -0
  213. package/src/plugins/url_analysis/css/css_urls.js +49 -0
  214. package/src/plugins/url_analysis/html/html_urls.js +272 -0
  215. package/src/plugins/url_analysis/js/js_urls.js +68 -0
  216. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +103 -0
  217. package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +20 -0
  218. package/src/{omega/core_plugins → plugins}/url_resolution/jsenv_plugin_url_resolution.js +9 -5
  219. package/src/plugins/url_version/jsenv_plugin_url_version.js +28 -0
  220. package/src/require_from_jsenv.js +3 -0
  221. package/src/test/execute_plan.js +85 -44
  222. package/src/test/execute_test_plan.js +37 -25
  223. package/src/test/execution_steps.js +2 -5
  224. package/src/test/logs_file_execution.js +56 -49
  225. package/main.js +0 -19
  226. package/src/build/plugins/bundle_js_module/jsenv_plugin_bundle_js_module.js +0 -227
  227. package/src/build/plugins/minify_html/jsenv_plugin_minify_html.js +0 -30
  228. package/src/dev/plugins/autoreload/client/event_source_connection.js +0 -195
  229. package/src/dev/plugins/autoreload/jsenv_plugin_autoreload.js +0 -374
  230. package/src/dev/plugins/autoreload/sse_service.js +0 -149
  231. package/src/execute/runtimes/node/controlled_process.js +0 -316
  232. package/src/omega/core_plugins/babel/new_stylesheet/client/.eslintrc.cjs +0 -24
  233. package/src/omega/core_plugins/file_urls/jsenv_plugin_file_urls.js +0 -67
  234. package/src/omega/core_plugins/filesystem_magic/jsenv_plugin_filesystem_magic.js +0 -58
  235. package/src/omega/core_plugins/html_supervisor/client/html_supervisor_installer.js +0 -168
  236. package/src/omega/core_plugins/html_supervisor/client/html_supervisor_setup.js +0 -77
  237. package/src/omega/core_plugins/import_assertions/helpers/babel_plugin_metadata_import_assertions.js +0 -98
  238. package/src/omega/core_plugins/import_assertions/helpers/json_module.js +0 -12
  239. package/src/omega/core_plugins/import_assertions/helpers/text_module.js +0 -6
  240. package/src/omega/core_plugins/import_assertions/jsenv_plugin_import_assertions.js +0 -211
  241. package/src/omega/core_plugins/inline/jsenv_plugin_inline.js +0 -13
  242. package/src/omega/core_plugins/inline/jsenv_plugin_js_and_css_inside_html.js +0 -142
  243. package/src/omega/core_plugins/inline/jsenv_plugin_new_inline_content.js +0 -207
  244. package/src/omega/core_plugins/leading_slash/jsenv_plugin_leading_slash.js +0 -12
  245. package/src/omega/core_plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +0 -77
  246. package/src/omega/core_plugins/url_version/jsenv_plugin_url_version.js +0 -50
  247. package/src/omega/core_plugins.js +0 -39
  248. package/src/omega/runtime_support/default_runtime_support.js +0 -13
  249. package/src/omega/url_graph/url_graph_sort.js +0 -29
  250. package/src/omega/url_mentions/css_url_mentions.js +0 -63
  251. package/src/omega/url_mentions/html_url_mentions.js +0 -185
  252. package/src/omega/url_mentions/js_module_url_mentions.js +0 -91
  253. package/src/omega/url_mentions/parse_url_mentions.js +0 -37
  254. package/src/omega/url_mentions/worker_classic_url_mentions.js +0 -37
@@ -0,0 +1,227 @@
1
+ import v8 from "node:v8";
2
+ import { uneval } from "@jsenv/uneval";
3
+ import { performance, PerformanceObserver } from "node:perf_hooks";
4
+
5
+ const startObservingPerformances = () => {
6
+ const measureEntries = []; // https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html
7
+
8
+ const perfObserver = new PerformanceObserver(( // https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html#perf_hooks_class_performanceobserverentrylist
9
+ list) => {
10
+ const perfMeasureEntries = list.getEntriesByType("measure");
11
+ measureEntries.push(...perfMeasureEntries);
12
+ });
13
+ perfObserver.observe({
14
+ entryTypes: ["measure"]
15
+ });
16
+ return async () => {
17
+ // wait for node to call the performance observer
18
+ await new Promise(resolve => {
19
+ setTimeout(resolve);
20
+ });
21
+ performance.clearMarks();
22
+ perfObserver.disconnect();
23
+ return { ...readNodePerformance(),
24
+ measures: measuresFromMeasureEntries(measureEntries)
25
+ };
26
+ };
27
+ };
28
+
29
+ const readNodePerformance = () => {
30
+ const nodePerformance = {
31
+ nodeTiming: asPlainObject(performance.nodeTiming),
32
+ timeOrigin: performance.timeOrigin,
33
+ eventLoopUtilization: performance.eventLoopUtilization()
34
+ };
35
+ return nodePerformance;
36
+ }; // remove getters that cannot be stringified
37
+
38
+
39
+ const asPlainObject = objectWithGetters => {
40
+ const objectWithoutGetters = {};
41
+ Object.keys(objectWithGetters).forEach(key => {
42
+ objectWithoutGetters[key] = objectWithGetters[key];
43
+ });
44
+ return objectWithoutGetters;
45
+ };
46
+
47
+ const measuresFromMeasureEntries = measureEntries => {
48
+ const measures = {}; // Sort to ensure measures order is predictable
49
+ // It seems to be already predictable on Node 16+ but
50
+ // it's not the case on Node 14.
51
+
52
+ measureEntries.sort((a, b) => {
53
+ return a.startTime - b.startTime;
54
+ });
55
+ measureEntries.forEach(( // https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html#perf_hooks_class_performanceentry
56
+ perfMeasureEntry) => {
57
+ measures[perfMeasureEntry.name] = perfMeasureEntry.duration;
58
+ });
59
+ return measures;
60
+ };
61
+
62
+ const ACTIONS_AVAILABLE = {
63
+ "execute-using-dynamic-import": async ({
64
+ fileUrl,
65
+ collectPerformance
66
+ }) => {
67
+ const getNamespace = async () => {
68
+ const namespace = await import(fileUrl);
69
+ const namespaceResolved = {};
70
+ await Promise.all([...Object.keys(namespace).map(async key => {
71
+ const value = await namespace[key];
72
+ namespaceResolved[key] = value;
73
+ })]);
74
+ return namespaceResolved;
75
+ };
76
+
77
+ if (collectPerformance) {
78
+ const getPerformance = startObservingPerformances();
79
+ const namespace = await getNamespace();
80
+ const performance = await getPerformance();
81
+ return {
82
+ namespace,
83
+ performance
84
+ };
85
+ }
86
+
87
+ const namespace = await getNamespace();
88
+ return {
89
+ namespace
90
+ };
91
+ },
92
+ "execute-using-require": async ({
93
+ fileUrl
94
+ }) => {
95
+ const {
96
+ createRequire
97
+ } = await import("module");
98
+ const {
99
+ fileURLToPath
100
+ } = await import("url");
101
+ const filePath = fileURLToPath(fileUrl);
102
+
103
+ const require = createRequire(fileUrl); // eslint-disable-next-line import/no-dynamic-require
104
+
105
+
106
+ const namespace = require(filePath);
107
+
108
+ const namespaceResolved = {};
109
+ await Promise.all([...Object.keys(namespace).map(async key => {
110
+ const value = await namespace[key];
111
+ namespaceResolved[key] = value;
112
+ })]);
113
+ return namespaceResolved;
114
+ }
115
+ };
116
+ const ACTION_REQUEST_EVENT_NAME = "action";
117
+ const ACTION_RESPONSE_EVENT_NAME = "action-result";
118
+ const ACTION_RESPONSE_STATUS_FAILED = "action-failed";
119
+ const ACTION_RESPONSE_STATUS_COMPLETED = "action-completed";
120
+
121
+ const sendActionFailed = error => {
122
+ if (error.hasOwnProperty("toString")) {
123
+ delete error.toString;
124
+ }
125
+
126
+ sendToParent(ACTION_RESPONSE_EVENT_NAME, // process.send algorithm does not send non enumerable values
127
+ // so use @jsenv/uneval
128
+ uneval({
129
+ status: ACTION_RESPONSE_STATUS_FAILED,
130
+ value: error
131
+ }, {
132
+ ignoreSymbols: true
133
+ }));
134
+ };
135
+
136
+ const sendActionCompleted = value => {
137
+ sendToParent(ACTION_RESPONSE_EVENT_NAME, // here we use JSON.stringify because we should not
138
+ // have non enumerable value (unlike there is on Error objects)
139
+ // otherwise uneval is quite slow to turn a giant object
140
+ // into a string (and value can be giant when using coverage)
141
+ JSON.stringify({
142
+ status: ACTION_RESPONSE_STATUS_COMPLETED,
143
+ value
144
+ }));
145
+ };
146
+
147
+ const sendToParent = (type, data) => {
148
+ // https://nodejs.org/api/process.html#process_process_connected
149
+ // not connected anymore, cannot communicate with parent
150
+ if (!process.connected) {
151
+ return;
152
+ } // this can keep process alive longer than expected
153
+ // when source is a long string.
154
+ // It means node process may stay alive longer than expected
155
+ // the time to send the data to the parent.
156
+
157
+
158
+ process.send({
159
+ type,
160
+ data
161
+ });
162
+ };
163
+
164
+ const onceProcessMessage = (type, callback) => {
165
+ const listener = event => {
166
+ if (event.type === type) {
167
+ // commenting line below keep this process alive
168
+ removeListener(); // eslint-disable-next-line no-eval
169
+
170
+ callback(eval(`(${event.data})`));
171
+ }
172
+ };
173
+
174
+ const removeListener = () => {
175
+ process.removeListener("message", listener);
176
+ };
177
+
178
+ process.on("message", listener);
179
+ return removeListener;
180
+ };
181
+
182
+ const removeActionRequestListener = onceProcessMessage(ACTION_REQUEST_EVENT_NAME, async ({
183
+ actionType,
184
+ actionParams
185
+ }) => {
186
+ const action = ACTIONS_AVAILABLE[actionType];
187
+
188
+ if (!action) {
189
+ sendActionFailed(new Error(`unknown action ${actionType}`));
190
+ return;
191
+ }
192
+
193
+ let value;
194
+ let failed = false;
195
+
196
+ try {
197
+ value = await action(actionParams);
198
+ } catch (e) {
199
+ failed = true;
200
+ value = e;
201
+ }
202
+
203
+ if (process.env.NODE_V8_COVERAGE) {
204
+ v8.takeCoverage(); // if (actionParams.stopCoverageAfterExecution) {
205
+ // v8.stopCoverage()
206
+ // }
207
+ } // setTimeout(() => {}, 100)
208
+
209
+
210
+ if (failed) {
211
+ sendActionFailed(value);
212
+ } else {
213
+ sendActionCompleted(value);
214
+ } // removeActionRequestListener()
215
+
216
+
217
+ if (actionParams.exitAfterAction) {
218
+ removeActionRequestListener(); // for some reason this fixes v8 coverage directory sometimes empty on Ubuntu
219
+ // process.exit()
220
+ }
221
+ }); // remove listener to process.on('message')
222
+ // which is sufficient to let child process die
223
+ // assuming nothing else keeps it alive
224
+ // process.once("SIGTERM", removeActionRequestListener)
225
+ // process.once("SIGINT", removeActionRequestListener)
226
+
227
+ setTimeout(() => sendToParent("ready"));
@@ -0,0 +1,324 @@
1
+ import { createEventSourceConnection } from "@jsenv/utils/event_source/event_source.js";
2
+ import { urlHotMetas } from "./import_meta_hot.js";
3
+ import { htmlAttributeSrcSet } from "@jsenv/utils/html_ast/html_attribute_src_set.js";
4
+
5
+ const isAutoreloadEnabled = () => {
6
+ const value = window.localStorage.getItem("autoreload");
7
+
8
+ if (value === "0") {
9
+ return false;
10
+ }
11
+
12
+ return true;
13
+ };
14
+ const setAutoreloadPreference = value => {
15
+ window.localStorage.setItem("autoreload", value ? "1" : "0");
16
+ };
17
+
18
+ const compareTwoUrlPaths = (url, otherUrl) => {
19
+ if (url === otherUrl) {
20
+ return true;
21
+ }
22
+
23
+ const urlObject = new URL(url);
24
+ const otherUrlObject = new URL(otherUrl);
25
+ return urlObject.origin === otherUrlObject.origin && urlObject.pathname === otherUrlObject.pathname;
26
+ };
27
+ const injectQuery = (url, query) => {
28
+ const urlObject = new URL(url);
29
+ const {
30
+ searchParams
31
+ } = urlObject;
32
+ Object.keys(query).forEach(key => {
33
+ searchParams.set(key, query[key]);
34
+ });
35
+ return String(urlObject);
36
+ };
37
+
38
+ const reloadHtmlPage = () => {
39
+ window.location.reload(true);
40
+ }; // This function can consider everything as hot reloadable:
41
+ // - no need to check [hot-accept]and [hot-decline] attributes for instance
42
+ // This is because if something should full reload, we receive "full_reload"
43
+ // from server and this function is not called
44
+
45
+ const reloadDOMNodesUsingUrl = urlToReload => {
46
+ const mutations = [];
47
+
48
+ const shouldReloadUrl = urlCandidate => {
49
+ return compareTwoUrlPaths(urlCandidate, urlToReload);
50
+ };
51
+
52
+ const visitNodeAttributeAsUrl = (node, attributeName) => {
53
+ let attribute = node[attributeName];
54
+
55
+ if (!attribute) {
56
+ return;
57
+ }
58
+
59
+ if (SVGAnimatedString && attribute instanceof SVGAnimatedString) {
60
+ attribute = attribute.animVal;
61
+ }
62
+
63
+ if (!shouldReloadUrl(attribute)) {
64
+ return;
65
+ }
66
+
67
+ mutations.push(() => {
68
+ node[attributeName] = injectQuery(attribute, {
69
+ hmr: Date.now()
70
+ });
71
+ });
72
+ };
73
+
74
+ Array.from(document.querySelectorAll(`link[rel="stylesheet"]`)).forEach(link => {
75
+ visitNodeAttributeAsUrl(link, "href");
76
+ });
77
+ Array.from(document.querySelectorAll(`link[rel="icon"]`)).forEach(link => {
78
+ visitNodeAttributeAsUrl(link, "href");
79
+ });
80
+ Array.from(document.querySelector("script")).forEach(script => {
81
+ visitNodeAttributeAsUrl(script, "src");
82
+ }); // There is no real need to update a.href because the ressource will be fetched when clicked.
83
+ // But in a scenario where the ressource was already visited and is in browser cache, adding
84
+ // the dynamic query param ensure the cache is invalidated
85
+
86
+ Array.from(document.querySelectorAll("a")).forEach(a => {
87
+ visitNodeAttributeAsUrl(a, "href");
88
+ }); // About iframes:
89
+ // - By default iframe itself and everything inside trigger a parent page full-reload
90
+ // - Adding [hot-accept] on the iframe means parent page won't reload when iframe full/hot reload
91
+ // In that case and if there is code in the iframe and parent doing post message communication:
92
+ // you must put import.meta.hot.decline() for code involved in communication.
93
+ // (both in parent and iframe)
94
+
95
+ Array.from(document.querySelectorAll("img")).forEach(img => {
96
+ visitNodeAttributeAsUrl(img, "src");
97
+ const srcset = img.srcset;
98
+
99
+ if (srcset) {
100
+ const srcCandidates = htmlAttributeSrcSet.parse(srcset);
101
+ srcCandidates.forEach(srcCandidate => {
102
+ const url = new URL(srcCandidate.specifier, `${window.location.href}`);
103
+
104
+ if (shouldReloadUrl(url)) {
105
+ srcCandidate.specifier = injectQuery(url, {
106
+ hmr: Date.now()
107
+ });
108
+ }
109
+ });
110
+ mutations.push(() => {
111
+ img.srcset = htmlAttributeSrcSet.stringify(srcCandidates);
112
+ });
113
+ }
114
+ });
115
+ Array.from(document.querySelectorAll("source")).forEach(source => {
116
+ visitNodeAttributeAsUrl(source, "src");
117
+ }); // svg image tag
118
+
119
+ Array.from(document.querySelectorAll("image")).forEach(image => {
120
+ visitNodeAttributeAsUrl(image, "href");
121
+ }); // svg use
122
+
123
+ Array.from(document.querySelectorAll("use")).forEach(use => {
124
+ visitNodeAttributeAsUrl(use, "href");
125
+ });
126
+ mutations.forEach(mutation => {
127
+ mutation();
128
+ });
129
+ };
130
+ const reloadJsImport = async url => {
131
+ const urlWithHmr = injectQuery(url, {
132
+ hmr: Date.now()
133
+ });
134
+ const namespace = await import(urlWithHmr);
135
+ return namespace;
136
+ };
137
+
138
+ const reloadMessages = [];
139
+ const reloadMessagesSignal = {
140
+ onchange: () => {}
141
+ };
142
+ let pendingCallbacks = [];
143
+ let running = false;
144
+
145
+ const addToHotQueue = async callback => {
146
+ pendingCallbacks.push(callback);
147
+ dequeue();
148
+ };
149
+
150
+ const dequeue = async () => {
151
+ if (running) {
152
+ return;
153
+ }
154
+
155
+ const callbacks = pendingCallbacks.slice();
156
+ pendingCallbacks = [];
157
+ running = true;
158
+
159
+ try {
160
+ await callbacks.reduce(async (previous, callback) => {
161
+ await previous;
162
+ await callback();
163
+ }, Promise.resolve());
164
+ } finally {
165
+ running = false;
166
+
167
+ if (pendingCallbacks.length) {
168
+ dequeue();
169
+ }
170
+ }
171
+ };
172
+
173
+ const applyReloadMessageEffects = async () => {
174
+ const someEffectIsFullReload = reloadMessages.some(reloadMessage => reloadMessage.type === "full");
175
+
176
+ if (someEffectIsFullReload) {
177
+ reloadHtmlPage();
178
+ return;
179
+ }
180
+
181
+ const onApplied = reloadMessage => {
182
+ const index = reloadMessages.indexOf(reloadMessage);
183
+ reloadMessages.splice(index, 1);
184
+ reloadMessagesSignal.onchange();
185
+ };
186
+
187
+ const setReloadMessagePromise = (reloadMessage, promise) => {
188
+ reloadMessage.status = "pending";
189
+ promise.then(() => {
190
+ onApplied(reloadMessage);
191
+ }, e => {
192
+ // TODO: reuse error display from html supervisor
193
+ console.error(e);
194
+ console.error(`[hmr] Failed to reload after ${reloadMessage.reason}.
195
+ This could be due to syntax errors or importing non-existent modules (see errors above)`);
196
+ reloadMessage.status = "failed";
197
+ reloadMessagesSignal.onchange();
198
+ });
199
+ };
200
+
201
+ reloadMessages.forEach(reloadMessage => {
202
+ if (reloadMessage.type === "hot") {
203
+ const promise = addToHotQueue(() => {
204
+ return applyHotReload(reloadMessage);
205
+ });
206
+ setReloadMessagePromise(reloadMessage, promise);
207
+ } else {
208
+ setReloadMessagePromise(reloadMessage, Promise.resolve());
209
+ }
210
+ });
211
+ reloadMessagesSignal.onchange(); // reload status is "pending"
212
+ };
213
+
214
+ const applyHotReload = async ({
215
+ hotInstructions
216
+ }) => {
217
+ await hotInstructions.reduce(async (previous, {
218
+ type,
219
+ boundary,
220
+ acceptedBy
221
+ }) => {
222
+ await previous;
223
+ const urlToFetch = new URL(boundary, `${window.location.origin}/`).href;
224
+ const urlHotMeta = urlHotMetas[urlToFetch]; // TODO: we should return when there is no url hot meta because
225
+ // it means code was not executed (code splitting with dynamic import)
226
+ // if (!urlHotMeta) {return }
227
+
228
+ if (type === "prune") {
229
+ console.groupCollapsed(`[jsenv] prune: ${boundary} (inside ${acceptedBy})`);
230
+ } else if (acceptedBy === boundary) {
231
+ console.groupCollapsed(`[jsenv] hot reloading: ${boundary}`);
232
+ } else {
233
+ console.groupCollapsed(`[jsenv] hot reloading: ${acceptedBy} inside ${boundary}`);
234
+ }
235
+
236
+ if (urlHotMeta && urlHotMeta.disposeCallback) {
237
+ console.log(`call dispose callback`);
238
+ await urlHotMeta.disposeCallback();
239
+ }
240
+
241
+ if (type === "prune") {
242
+ delete urlHotMetas[urlToFetch];
243
+ console.log(`cleanup pruned url`);
244
+ console.groupEnd();
245
+ return null;
246
+ }
247
+
248
+ if (type === "js_module") {
249
+ console.log(`importing js module`);
250
+ const namespace = await reloadJsImport(urlToFetch);
251
+
252
+ if (urlHotMeta && urlHotMeta.acceptCallback) {
253
+ await urlHotMeta.acceptCallback(namespace);
254
+ }
255
+
256
+ console.log(`js module import done`);
257
+ console.groupEnd();
258
+ return namespace;
259
+ }
260
+
261
+ if (type === "html") {
262
+ if (!compareTwoUrlPaths(urlToFetch, window.location.href)) {
263
+ // we are not in that HTML page
264
+ return null;
265
+ }
266
+
267
+ console.log(`reloading url`);
268
+ const urlToReload = new URL(acceptedBy, `${window.location.origin}/`).href;
269
+ reloadDOMNodesUsingUrl(urlToReload);
270
+ console.log(`url reloaded`);
271
+ console.groupEnd();
272
+ return null;
273
+ }
274
+
275
+ console.warn(`unknown update type: "${type}"`);
276
+ return null;
277
+ }, Promise.resolve());
278
+ };
279
+
280
+ const addReloadMessage = reloadMessage => {
281
+ reloadMessages.push(reloadMessage);
282
+
283
+ if (isAutoreloadEnabled()) {
284
+ applyReloadMessageEffects();
285
+ } else {
286
+ reloadMessagesSignal.onchange();
287
+ }
288
+ };
289
+
290
+ const eventsourceConnection = createEventSourceConnection(document.location.href, {
291
+ reload: ({
292
+ data
293
+ }) => {
294
+ const reloadMessage = JSON.parse(data);
295
+ addReloadMessage(reloadMessage);
296
+ }
297
+ }, {
298
+ retryMaxAttempt: Infinity,
299
+ retryAllocatedMs: 20 * 1000
300
+ });
301
+ const {
302
+ status,
303
+ connect,
304
+ disconnect
305
+ } = eventsourceConnection;
306
+ connect();
307
+ window.__jsenv_event_source_client__ = {
308
+ status,
309
+ connect,
310
+ disconnect,
311
+ isAutoreloadEnabled,
312
+ setAutoreloadPreference,
313
+ urlHotMetas,
314
+ reloadMessages,
315
+ reloadMessagesSignal,
316
+ applyReloadMessageEffects,
317
+ addReloadMessage
318
+ }; // const findHotMetaUrl = (originalFileRelativeUrl) => {
319
+ // return Object.keys(urlHotMetas).find((compileUrl) => {
320
+ // return (
321
+ // parseCompiledUrl(compileUrl).fileRelativeUrl === originalFileRelativeUrl
322
+ // )
323
+ // })
324
+ // }
@@ -0,0 +1,32 @@
1
+ // https://mathiasbynens.be/notes/globalthis
2
+
3
+ /* eslint-disable no-redeclare */
4
+
5
+ /* global globalThis */
6
+ let globalObject;
7
+
8
+ if (typeof globalThis === "object") {
9
+ globalObject = globalThis;
10
+ } else {
11
+ if (undefined) {
12
+ globalObject = undefined;
13
+ } else {
14
+ // eslint-disable-next-line no-extend-native
15
+ Object.defineProperty(Object.prototype, "__global__", {
16
+ get() {
17
+ return this;
18
+ },
19
+
20
+ configurable: true
21
+ }); // eslint-disable-next-line no-undef
22
+
23
+ globalObject = __global__;
24
+ delete Object.prototype.__global__;
25
+ }
26
+
27
+ globalObject.globalThis = globalObject;
28
+ }
29
+
30
+ var globalObject$1 = globalObject;
31
+
32
+ export { globalObject$1 as default };