@jsenv/core 25.6.2 → 27.0.0-alpha.0

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 (476) hide show
  1. package/main.js +18 -20
  2. package/package.json +38 -73
  3. package/readme.md +32 -44
  4. package/src/build/build.js +737 -0
  5. package/src/build/build_urls_generator.js +64 -0
  6. package/src/build/inject_version_mappings.js +62 -0
  7. package/src/build/plugins/bundle_js_module/jsenv_plugin_bundle_js_module.js +225 -0
  8. package/src/build/plugins/minify_html/jsenv_plugin_minify_html.js +30 -0
  9. package/src/build/plugins/minify_js/jsenv_plugin_minify_js.js +47 -0
  10. package/src/dev/plugins/autoreload/babel_plugin_metadata_import_meta_hot.js +98 -0
  11. package/src/dev/plugins/autoreload/client/autoreload_preference.js +11 -0
  12. package/src/dev/plugins/autoreload/client/event_source_client.js +186 -0
  13. package/src/{internal/dev_server/event_source_client → dev/plugins/autoreload/client}/event_source_connection.js +21 -25
  14. package/src/dev/plugins/autoreload/client/import_meta_hot.js +80 -0
  15. package/src/dev/plugins/autoreload/client/reload.js +101 -0
  16. package/src/dev/plugins/autoreload/client/url_helpers.js +20 -0
  17. package/src/dev/plugins/autoreload/html_hot_dependencies.js +156 -0
  18. package/src/dev/plugins/autoreload/jsenv_plugin_autoreload.js +374 -0
  19. package/src/dev/plugins/autoreload/sse_service.js +149 -0
  20. package/src/dev/plugins/explorer/client/explorer.html +607 -0
  21. package/src/{internal → dev/plugins/explorer/client}/jsenv.png +0 -0
  22. package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +74 -0
  23. package/src/{internal/dev_server/toolbar/animation/toolbar.animation.js → dev/plugins/toolbar/client/animation/toolbar_animation.js} +0 -0
  24. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/eventsource/eventsource.css +2 -2
  25. package/src/dev/plugins/toolbar/client/eventsource/toolbar_eventsource.js +57 -0
  26. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/execution/execution.css +0 -0
  27. package/src/dev/plugins/toolbar/client/execution/toolbar_execution.js +88 -0
  28. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/focus/focus.css +0 -0
  29. package/src/{internal/dev_server/toolbar/focus/toolbar.focus.js → dev/plugins/toolbar/client/focus/toolbar_focus.js} +0 -0
  30. package/src/{internal/dev_server/toolbar/jsenv-logo.svg → dev/plugins/toolbar/client/jsenv_logo.svg} +1 -1
  31. package/src/{internal/dev_server/toolbar/notification/toolbar.notification.js → dev/plugins/toolbar/client/notification/toolbar_notification.js} +0 -0
  32. package/src/{internal/dev_server/toolbar/responsive/overflow-menu.css → dev/plugins/toolbar/client/responsive/overflow_menu.css} +0 -0
  33. package/src/{internal/dev_server/toolbar/responsive/toolbar.responsive.js → dev/plugins/toolbar/client/responsive/toolbar_responsive.js} +0 -0
  34. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/settings/settings.css +0 -0
  35. package/src/{internal/dev_server/toolbar/settings/toolbar.settings.js → dev/plugins/toolbar/client/settings/toolbar_settings.js} +1 -0
  36. package/src/{internal/dev_server/toolbar/theme/jsenv-theme.css → dev/plugins/toolbar/client/theme/jsenv_theme.css} +1 -15
  37. package/src/{internal/dev_server/toolbar/theme/light-theme.css → dev/plugins/toolbar/client/theme/light_theme.css} +0 -17
  38. package/src/{internal/dev_server/toolbar/theme/toolbar.theme.js → dev/plugins/toolbar/client/theme/toolbar_theme.js} +0 -0
  39. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/toolbar.html +42 -201
  40. package/src/{internal/dev_server/toolbar/toolbar.injector.js → dev/plugins/toolbar/client/toolbar_injector.js} +10 -29
  41. package/src/{internal/dev_server/toolbar/toolbar.main.css → dev/plugins/toolbar/client/toolbar_main.css} +2 -26
  42. package/src/{internal/dev_server/toolbar/toolbar.main.js → dev/plugins/toolbar/client/toolbar_main.js} +18 -64
  43. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/tooltip/tooltip.css +1 -1
  44. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/tooltip/tooltip.js +0 -0
  45. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/util/animation.js +0 -0
  46. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/util/dom.js +0 -0
  47. package/src/{internal/browser_utils/fetchUsingXHR.js → dev/plugins/toolbar/client/util/fetch_using_xhr.js} +0 -2
  48. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/util/fetching.js +2 -4
  49. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/util/iframe_to_parent_href.js +0 -0
  50. package/src/{internal/dev_server/toolbar/util/jsenvLogger.js → dev/plugins/toolbar/client/util/jsenv_logger.js} +0 -0
  51. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/util/preferences.js +0 -0
  52. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/util/responsive.js +0 -0
  53. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/util/util.js +0 -0
  54. package/src/{internal/dev_server/toolbar → dev/plugins/toolbar/client}/variant/variant.js +0 -0
  55. package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +62 -0
  56. package/src/dev/start_dev_server.js +105 -0
  57. package/src/execute/execute.js +132 -0
  58. package/src/execute/run.js +208 -0
  59. package/src/execute/runtimes/browsers/chromium.js +8 -0
  60. package/src/execute/runtimes/browsers/firefox.js +7 -0
  61. package/src/execute/runtimes/browsers/from_playwright.js +464 -0
  62. package/src/execute/runtimes/browsers/webkit.js +24 -0
  63. package/src/{internal/node_launcher/createChildProcessOptions.js → execute/runtimes/node/child_exec_options.js} +25 -36
  64. package/src/{internal/node_runtime/nodeControllableFile.mjs → execute/runtimes/node/controllable_file.mjs} +1 -18
  65. package/src/{internal/node_launcher/createControllableNodeProcess.js → execute/runtimes/node/controlled_process.js} +128 -150
  66. package/src/execute/runtimes/node/exec_options.js +44 -0
  67. package/src/{internal/node_launcher → execute/runtimes/node}/kill_process_tree.js +4 -2
  68. package/src/execute/runtimes/node/node_process.js +92 -0
  69. package/src/execute/runtimes/node/node_worker_thread.js +28 -0
  70. package/src/omega/core_plugins/babel/babel_helper/babel_helper_directory.js +29 -0
  71. package/src/{internal/compiling/js-compilation-service → omega/core_plugins/babel/babel_helper}/babel_plugin_babel_helpers_as_jsenv_imports.js +16 -19
  72. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/.eslintrc.cjs +0 -0
  73. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/AsyncGenerator/AsyncGenerator.js +0 -0
  74. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/AwaitValue/AwaitValue.js +0 -0
  75. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/applyDecoratorDescriptor/applyDecoratorDescriptor.js +0 -0
  76. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/arrayLikeToArray/arrayLikeToArray.js +0 -0
  77. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/arrayWithHoles/arrayWithHoles.js +0 -0
  78. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/arrayWithoutHoles/arrayWithoutHoles.js +0 -0
  79. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/assertThisInitialized/assertThisInitialized.js +0 -0
  80. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/asyncGeneratorDelegate/asyncGeneratorDelegate.js +0 -0
  81. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/asyncIterator/asyncIterator.js +0 -0
  82. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/asyncToGenerator/asyncToGenerator.js +0 -0
  83. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/awaitAsyncGenerator/awaitAsyncGenerator.js +0 -0
  84. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +0 -0
  85. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classApplyDescriptorGet/classApplyDescriptorGet.js +0 -0
  86. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classApplyDescriptorSet/classApplyDescriptorSet.js +0 -0
  87. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classCallCheck/classCallCheck.js +0 -0
  88. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +0 -0
  89. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +0 -0
  90. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classExtractFieldDescriptor/classExtractFieldDescriptor.js +0 -0
  91. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classNameTDZError/classNameTDZError.js +0 -0
  92. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +0 -0
  93. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classPrivateFieldGet/classPrivateFieldGet.js +0 -0
  94. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +0 -0
  95. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +0 -0
  96. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classPrivateFieldSet/classPrivateFieldSet.js +0 -0
  97. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classPrivateMethodGet/classPrivateMethodGet.js +0 -0
  98. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classPrivateMethodSet/classPrivateMethodSet.js +0 -0
  99. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +0 -0
  100. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +0 -0
  101. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +0 -0
  102. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +0 -0
  103. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/construct/construct.js +0 -0
  104. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/createClass/createClass.js +0 -0
  105. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/createForOfIteratorHelper/createForOfIteratorHelper.js +0 -0
  106. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +0 -0
  107. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/createRawReactElement/createRawReactElement.js +0 -0
  108. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/createSuper/createSuper.js +0 -0
  109. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/decorate/decorate.js +0 -0
  110. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/defaults/defaults.js +0 -0
  111. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/defineEnumerableProperties/defineEnumerableProperties.js +0 -0
  112. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/defineProperty/defineProperty.js +0 -0
  113. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/extends/extends.js +0 -0
  114. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/get/get.js +0 -0
  115. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/getPrototypeOf/getPrototypeOf.js +0 -0
  116. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/inherits/inherits.js +0 -0
  117. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/inheritsLoose/inheritsLoose.js +0 -0
  118. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/initializerDefineProperty/initializerDefineProperty.js +0 -0
  119. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/initializerWarningHelper/initializerWarningHelper.js +0 -0
  120. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/instanceof/instanceof.js +0 -0
  121. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/interopRequireDefault/interopRequireDefault.js +0 -0
  122. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/interopRequireWildcard/interopRequireWildcard.js +0 -0
  123. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/isNativeFunction/isNativeFunction.js +0 -0
  124. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/isNativeReflectConstruct/isNativeReflectConstruct.js +0 -0
  125. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/iterableToArray/iterableToArray.js +0 -0
  126. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/iterableToArrayLimit/iterableToArrayLimit.js +0 -0
  127. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +0 -0
  128. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/jsx/jsx.js +0 -0
  129. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/maybeArrayLike/maybeArrayLike.js +0 -0
  130. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/newArrowCheck/newArrowCheck.js +0 -0
  131. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/nonIterableRest/nonIterableRest.js +0 -0
  132. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/nonIterableSpread/nonIterableSpread.js +0 -0
  133. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/objectDestructuringEmpty/objectDestructuringEmpty.js +0 -0
  134. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/objectSpread/objectSpread.js +0 -0
  135. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/objectSpread2/objectSpread2.js +0 -0
  136. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/objectWithoutProperties/objectWithoutProperties.js +0 -0
  137. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +0 -0
  138. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/possibleConstructorReturn/possibleConstructorReturn.js +0 -0
  139. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/readOnlyError/readOnlyError.js +0 -0
  140. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/readme.md +0 -0
  141. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/set/set.js +0 -0
  142. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/setPrototypeOf/setPrototypeOf.js +0 -0
  143. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/skipFirstGeneratorNext/skipFirstGeneratorNext.js +0 -0
  144. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/slicedToArray/slicedToArray.js +0 -0
  145. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/slicedToArrayLoose/slicedToArrayLoose.js +0 -0
  146. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/superPropBase/superPropBase.js +0 -0
  147. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/taggedTemplateLiteral/taggedTemplateLiteral.js +0 -0
  148. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +0 -0
  149. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/tdz/tdz.js +0 -0
  150. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/temporalRef/temporalRef.js +0 -0
  151. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/temporalUndefined/temporalUndefined.js +0 -0
  152. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/toArray/toArray.js +0 -0
  153. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/toConsumableArray/toConsumableArray.js +0 -0
  154. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/toPrimitive/toPrimitive.js +0 -0
  155. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/toPropertyKey/toPropertyKey.js +0 -0
  156. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/typeof/typeof.js +0 -0
  157. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/unsupportedIterableToArray/unsupportedIterableToArray.js +0 -0
  158. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/wrapAsyncGenerator/wrapAsyncGenerator.js +0 -0
  159. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/wrapNativeSuper/wrapNativeSuper.js +0 -0
  160. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/wrapRegExp/wrapRegExp.js +0 -0
  161. package/{helpers/babel → src/omega/core_plugins/babel/babel_helper/client}/writeOnlyError/writeOnlyError.js +0 -0
  162. package/src/omega/core_plugins/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +35 -0
  163. package/{helpers/global-this/global-this.js → src/omega/core_plugins/babel/global_this/client/global_this.js} +0 -0
  164. package/src/omega/core_plugins/babel/helpers/babel_plugin_structure.js +187 -0
  165. package/src/{internal/features → omega/core_plugins/babel/helpers}/babel_plugins_compatibility.js +1 -24
  166. package/src/omega/core_plugins/babel/jsenv_plugin_babel.js +97 -0
  167. package/src/omega/core_plugins/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +117 -0
  168. package/src/omega/core_plugins/babel/new_stylesheet/client/.eslintrc.cjs +24 -0
  169. package/{helpers/new_stylesheet → src/omega/core_plugins/babel/new_stylesheet/client}/new_stylesheet.js +0 -0
  170. package/src/omega/core_plugins/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +34 -0
  171. package/{helpers/regenerator-runtime/regenerator-runtime.js → src/omega/core_plugins/babel/regenerator_runtime/client/regenerator_runtime.js} +0 -0
  172. package/src/omega/core_plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +169 -0
  173. package/src/omega/core_plugins/file_urls/jsenv_plugin_file_urls.js +67 -0
  174. package/src/omega/core_plugins/filesystem_magic/jsenv_plugin_filesystem_magic.js +58 -0
  175. package/src/{internal/browser_runtime/displayErrorInDocument.js → omega/core_plugins/html_supervisor/client/error_in_document.js} +10 -18
  176. package/src/{internal/browser_runtime/displayErrorNotification.js → omega/core_plugins/html_supervisor/client/error_in_notification.js} +0 -1
  177. package/src/omega/core_plugins/html_supervisor/client/html_supervisor_installer.js +168 -0
  178. package/src/omega/core_plugins/html_supervisor/client/html_supervisor_setup.js +77 -0
  179. package/src/{internal → omega/core_plugins/html_supervisor/client}/perf_browser.js +0 -2
  180. package/src/{internal/unevalException.js → omega/core_plugins/html_supervisor/client/uneval_exception.js} +1 -1
  181. package/src/omega/core_plugins/html_supervisor/jsenv_plugin_html_supervisor.js +233 -0
  182. package/src/omega/core_plugins/import_assertions/helpers/babel_plugin_metadata_import_assertions.js +98 -0
  183. package/src/{internal/building → omega/core_plugins/import_assertions/helpers}/json_module.js +3 -2
  184. package/src/omega/core_plugins/import_assertions/helpers/text_module.js +6 -0
  185. package/src/omega/core_plugins/import_assertions/jsenv_plugin_import_assertions.js +211 -0
  186. package/src/omega/core_plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +80 -0
  187. package/src/omega/core_plugins/importmap/jsenv_plugin_importmap.js +212 -0
  188. package/src/omega/core_plugins/inline/client/inline_content.js +6 -0
  189. package/src/omega/core_plugins/inline/jsenv_plugin_data_urls.js +70 -0
  190. package/src/omega/core_plugins/inline/jsenv_plugin_inline.js +13 -0
  191. package/src/omega/core_plugins/inline/jsenv_plugin_inline_query_param.js +42 -0
  192. package/src/omega/core_plugins/inline/jsenv_plugin_js_and_css_inside_html.js +142 -0
  193. package/src/omega/core_plugins/inline/jsenv_plugin_new_inline_content.js +210 -0
  194. package/src/omega/core_plugins/leading_slash/jsenv_plugin_leading_slash.js +12 -0
  195. package/src/omega/core_plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +77 -0
  196. package/src/omega/core_plugins/url_resolution/jsenv_plugin_url_resolution.js +28 -0
  197. package/src/omega/core_plugins/url_version/jsenv_plugin_url_version.js +50 -0
  198. package/src/omega/core_plugins.js +39 -0
  199. package/src/omega/errors.js +168 -0
  200. package/src/omega/file_url_converter.js +63 -0
  201. package/src/omega/kitchen.js +777 -0
  202. package/src/omega/omega_server.js +129 -0
  203. package/src/omega/plugin_controller.js +240 -0
  204. package/src/omega/runtime_support/default_runtime_support.js +13 -0
  205. package/src/omega/runtime_support/features_compatibility.js +91 -0
  206. package/src/omega/runtime_support/runtime_support.js +20 -0
  207. package/src/omega/server/file_service.js +155 -0
  208. package/src/omega/server/user_agent.js +22 -0
  209. package/src/omega/url_graph/url_graph_load.js +68 -0
  210. package/src/omega/url_graph/url_graph_report.js +151 -0
  211. package/src/omega/url_graph/url_graph_sort.js +29 -0
  212. package/src/omega/url_graph/url_info_transformations.js +161 -0
  213. package/src/omega/url_graph.js +132 -0
  214. package/src/omega/url_mentions/css_url_mentions.js +63 -0
  215. package/src/omega/url_mentions/html_url_mentions.js +185 -0
  216. package/src/omega/url_mentions/js_module_url_mentions.js +91 -0
  217. package/src/omega/url_mentions/parse_url_mentions.js +37 -0
  218. package/src/omega/url_mentions/worker_classic_url_mentions.js +37 -0
  219. package/src/{internal/executing/executePlan.js → test/execute_plan.js} +159 -213
  220. package/src/{executeTestPlan.js → test/execute_test_plan.js} +36 -84
  221. package/src/{internal/executing → test}/execution_colors.js +0 -0
  222. package/src/{internal/executing/generateFileExecutionSteps.js → test/execution_steps.js} +25 -4
  223. package/src/{internal/executing → test}/gc.js +0 -0
  224. package/src/test/logs_file_execution.js +223 -0
  225. package/dist/browser_runtime/asset-manifest.json +0 -4
  226. package/dist/browser_runtime/browser_runtime_c81cd9af.js +0 -5300
  227. package/dist/browser_runtime/browser_runtime_c81cd9af.js.map +0 -1089
  228. package/dist/build_manifest.js +0 -12
  229. package/dist/compile_proxy/asset-manifest.json +0 -4
  230. package/dist/compile_proxy/compile_proxy.html__inline__20_c05fdc30.js.map +0 -343
  231. package/dist/compile_proxy/compile_proxy_93ec4247.html +0 -2247
  232. package/dist/event_source_client/asset-manifest.json +0 -4
  233. package/dist/event_source_client/event_source_client_69f48287.js +0 -354
  234. package/dist/event_source_client/event_source_client_69f48287.js.map +0 -128
  235. package/dist/redirector/asset-manifest.json +0 -4
  236. package/dist/redirector/redirector.html__inline__12_20421b23.js.map +0 -349
  237. package/dist/redirector/redirector_ddc79416.html +0 -2292
  238. package/dist/toolbar/asset-manifest.json +0 -13
  239. package/dist/toolbar/assets/compilation.css_7421bd55.map +0 -12
  240. package/dist/toolbar/assets/eventsource.css_c0c71e7b.map +0 -12
  241. package/dist/toolbar/assets/execution.css_f3377c10.map +0 -12
  242. package/dist/toolbar/assets/focus.css_896f3e45.map +0 -12
  243. package/dist/toolbar/assets/light-theme.css_72a60fa3.map +0 -12
  244. package/dist/toolbar/assets/overflow-menu.css_2859d519.map +0 -12
  245. package/dist/toolbar/assets/settings.css_942b5a9e.map +0 -12
  246. package/dist/toolbar/assets/toolbar.main.css_b7d8bec1.map +0 -28
  247. package/dist/toolbar/assets/tooltip.css_a94a8bdd.map +0 -12
  248. package/dist/toolbar/toolbar.main_7d7783d3.js.map +0 -776
  249. package/dist/toolbar/toolbar_d6045dd0.html +0 -4978
  250. package/dist/toolbar_injector/asset-manifest.json +0 -5
  251. package/dist/toolbar_injector/assets/jsenv-logo_188b9ca6.svg +0 -95
  252. package/dist/toolbar_injector/toolbar_injector_c8c214dd.js +0 -977
  253. package/dist/toolbar_injector/toolbar_injector_c8c214dd.js.map +0 -294
  254. package/helpers/import-meta/import-meta-url-commonjs.js +0 -9
  255. package/helpers/import-meta/import-meta-url-global.js +0 -54
  256. package/src/buildProject.js +0 -336
  257. package/src/commonJsToJavaScriptModule.js +0 -180
  258. package/src/dev_server.js +0 -295
  259. package/src/execute.js +0 -184
  260. package/src/importUsingChildProcess.js +0 -68
  261. package/src/internal/argUtils.js +0 -12
  262. package/src/internal/babel_plugin_replace_expressions.js +0 -101
  263. package/src/internal/browser_detection/browser_detection.js +0 -68
  264. package/src/internal/browser_detection/detectAndroid.js +0 -13
  265. package/src/internal/browser_detection/detectChrome.js +0 -28
  266. package/src/internal/browser_detection/detectEdge.js +0 -13
  267. package/src/internal/browser_detection/detectElectron.js +0 -1
  268. package/src/internal/browser_detection/detectFirefox.js +0 -17
  269. package/src/internal/browser_detection/detectIOS.js +0 -19
  270. package/src/internal/browser_detection/detectInternetExplorer.js +0 -14
  271. package/src/internal/browser_detection/detectOpera.js +0 -27
  272. package/src/internal/browser_detection/detectSafari.js +0 -13
  273. package/src/internal/browser_detection/user_agent_data.js +0 -26
  274. package/src/internal/browser_detection/util.js +0 -13
  275. package/src/internal/browser_launcher/browser_runtime_profile.js +0 -81
  276. package/src/internal/browser_launcher/executeHtmlFile.js +0 -354
  277. package/src/internal/browser_launcher/from_playwright.js +0 -320
  278. package/src/internal/browser_launcher/trackPageToNotify.js +0 -77
  279. package/src/internal/browser_runtime/browser_runtime.js +0 -224
  280. package/src/internal/browser_runtime/browser_system.js +0 -218
  281. package/src/internal/browser_runtime/createBrowserRuntime.js +0 -146
  282. package/src/internal/browser_runtime/evalSource.js +0 -11
  283. package/src/internal/browser_runtime/makeNamespaceTransferable.js +0 -90
  284. package/src/internal/browser_utils/fetchAndEvalUsingFetch.js +0 -29
  285. package/src/internal/browser_utils/fetchAndEvalUsingScript.js +0 -49
  286. package/src/internal/browser_utils/fetchJson.js +0 -7
  287. package/src/internal/browser_utils/fetch_browser.js +0 -34
  288. package/src/internal/building/buildToCompilationResult.js +0 -183
  289. package/src/internal/building/buildUsingRollup.js +0 -359
  290. package/src/internal/building/build_logs.js +0 -133
  291. package/src/internal/building/build_stats.js +0 -100
  292. package/src/internal/building/build_url_generator.js +0 -153
  293. package/src/internal/building/css/applyPostCss.js +0 -55
  294. package/src/internal/building/css/moveCssUrls.js +0 -44
  295. package/src/internal/building/css/parseCssRessource.js +0 -259
  296. package/src/internal/building/css/parseCssUrls.js +0 -38
  297. package/src/internal/building/css/postcss_plugin_url_visitor.js +0 -244
  298. package/src/internal/building/css/replaceCssUrls.js +0 -67
  299. package/src/internal/building/css_module.js +0 -43
  300. package/src/internal/building/es_to_system.js +0 -34
  301. package/src/internal/building/html/htmlScan.js +0 -70
  302. package/src/internal/building/html/minifyHtml.js +0 -7
  303. package/src/internal/building/html/parseHtmlRessource.js +0 -814
  304. package/src/internal/building/import_references.js +0 -80
  305. package/src/internal/building/importmap/parseImportmapRessource.js +0 -28
  306. package/src/internal/building/js/babel_plugin_inline_worker_imports.js +0 -96
  307. package/src/internal/building/js/minifyJs.js +0 -33
  308. package/src/internal/building/js/parseJsRessource.js +0 -121
  309. package/src/internal/building/js/transform_worker.js +0 -55
  310. package/src/internal/building/json/parseJsonRessource.js +0 -11
  311. package/src/internal/building/parseRessource.js +0 -207
  312. package/src/internal/building/parsing.utils.js +0 -29
  313. package/src/internal/building/resolve_import_url_helper.js +0 -12
  314. package/src/internal/building/ressource_builder.js +0 -1097
  315. package/src/internal/building/ressource_builder_util.js +0 -194
  316. package/src/internal/building/rollup_plugin_jsenv.js +0 -1963
  317. package/src/internal/building/sortObjectByPathnames.js +0 -10
  318. package/src/internal/building/sourcemap_loader.js +0 -73
  319. package/src/internal/building/svg/parseSvgRessource.js +0 -111
  320. package/src/internal/building/url_fetcher.js +0 -85
  321. package/src/internal/building/url_loader.js +0 -127
  322. package/src/internal/building/url_trace.js +0 -229
  323. package/src/internal/building/url_versioning.js +0 -65
  324. package/src/internal/building/webmanifest/parseWebmanifestRessource.js +0 -48
  325. package/src/internal/compiling/babel_parse_error.js +0 -9
  326. package/src/internal/compiling/babel_plugin_global_this_as_jsenv_import.js +0 -34
  327. package/src/internal/compiling/babel_plugin_import_assertions.js +0 -120
  328. package/src/internal/compiling/babel_plugin_import_metadata.js +0 -18
  329. package/src/internal/compiling/babel_plugin_import_visitor.js +0 -84
  330. package/src/internal/compiling/babel_plugin_new_stylesheet_as_jsenv_import.js +0 -113
  331. package/src/internal/compiling/babel_plugin_proxy_external_imports.js +0 -31
  332. package/src/internal/compiling/babel_plugin_transform_import_meta.js +0 -134
  333. package/src/internal/compiling/babel_plugins.js +0 -37
  334. package/src/internal/compiling/compileFile.js +0 -271
  335. package/src/internal/compiling/compileHtml.js +0 -544
  336. package/src/internal/compiling/createCompiledFileService.js +0 -263
  337. package/src/internal/compiling/html_source_file_service.js +0 -453
  338. package/src/internal/compiling/js-compilation-service/ansiToHTML.js +0 -9
  339. package/src/internal/compiling/js-compilation-service/babelHelper.js +0 -145
  340. package/src/internal/compiling/js-compilation-service/babel_plugin_regenerator_runtime_as_jsenv_import.js +0 -48
  341. package/src/internal/compiling/js-compilation-service/babel_plugin_systemjs_prepend.js +0 -23
  342. package/src/internal/compiling/js-compilation-service/generateBabelHelper.js +0 -36
  343. package/src/internal/compiling/js-compilation-service/transformJs.js +0 -196
  344. package/src/internal/compiling/jsenvCompilerForHtml.js +0 -674
  345. package/src/internal/compiling/jsenvCompilerForImportmap.js +0 -28
  346. package/src/internal/compiling/jsenvCompilerForJavaScript.js +0 -61
  347. package/src/internal/compiling/jsenv_directory/comparison_utils.js +0 -27
  348. package/src/internal/compiling/jsenv_directory/compile_asset.js +0 -24
  349. package/src/internal/compiling/jsenv_directory/compile_context.js +0 -60
  350. package/src/internal/compiling/jsenv_directory/compile_profile.js +0 -217
  351. package/src/internal/compiling/jsenv_directory/file_lock_registry.js +0 -24
  352. package/src/internal/compiling/jsenv_directory/file_lock_registry.test.js +0 -47
  353. package/src/internal/compiling/jsenv_directory/fs-optimized-for-cache.js +0 -57
  354. package/src/internal/compiling/jsenv_directory/getOrGenerateCompiledFile.js +0 -269
  355. package/src/internal/compiling/jsenv_directory/jsenv_directory.js +0 -174
  356. package/src/internal/compiling/jsenv_directory/updateMeta.js +0 -150
  357. package/src/internal/compiling/jsenv_directory/validateCache.js +0 -264
  358. package/src/internal/compiling/load_babel_plugin_map_from_file.js +0 -49
  359. package/src/internal/compiling/rollup_plugin_commonjs_named_exports.js +0 -187
  360. package/src/internal/compiling/sse_service/sse_service.js +0 -369
  361. package/src/internal/compiling/startCompileServer.js +0 -518
  362. package/src/internal/compiling/transformResultToCompilationResult.js +0 -242
  363. package/src/internal/dataUrl.utils.js +0 -55
  364. package/src/internal/dev_server/event_source_client/event_source_client.js +0 -63
  365. package/src/internal/dev_server/event_source_client/file_changes.js +0 -82
  366. package/src/internal/dev_server/event_source_client/livereload_preference.js +0 -13
  367. package/src/internal/dev_server/exploring/exploring.css +0 -237
  368. package/src/internal/dev_server/exploring/exploring.html +0 -79
  369. package/src/internal/dev_server/exploring/exploring.js +0 -243
  370. package/src/internal/dev_server/exploring/fetchExploringJson.js +0 -19
  371. package/src/internal/dev_server/toolbar/compilation/compilation.css +0 -23
  372. package/src/internal/dev_server/toolbar/compilation/toolbar.compilation.js +0 -201
  373. package/src/internal/dev_server/toolbar/eventsource/toolbar.eventsource.js +0 -83
  374. package/src/internal/dev_server/toolbar/execution/toolbar.execution.js +0 -91
  375. package/src/internal/error-stack-remapping/getOriginalCallsites.js +0 -217
  376. package/src/internal/error-stack-remapping/installBrowserErrorStackRemapping.js +0 -45
  377. package/src/internal/error-stack-remapping/installErrorStackRemapping.js +0 -141
  378. package/src/internal/error-stack-remapping/installNodeErrorStackRemapping.js +0 -20
  379. package/src/internal/error-stack-remapping/remapCallSite.js +0 -314
  380. package/src/internal/error-stack-remapping/stackToString.js +0 -9
  381. package/src/internal/escapeRegexpSpecialCharacters.js +0 -34
  382. package/src/internal/escapeTemplateStringSpecialCharacters.js +0 -20
  383. package/src/internal/executing/coverage/babel_plugin_instrument.js +0 -90
  384. package/src/internal/executing/coverage/reportToCoverage.js +0 -198
  385. package/src/internal/executing/coverage_missing/createEmptyCoverage.js +0 -6
  386. package/src/internal/executing/coverage_missing/list_files_not_covered.js +0 -20
  387. package/src/internal/executing/coverage_missing/missing_coverage.js +0 -46
  388. package/src/internal/executing/coverage_missing/relativeUrlToEmptyCoverage.js +0 -63
  389. package/src/internal/executing/coverage_reporter/coverage_reporter_html_directory.js +0 -36
  390. package/src/internal/executing/coverage_reporter/coverage_reporter_json_file.js +0 -22
  391. package/src/internal/executing/coverage_reporter/coverage_reporter_text_log.js +0 -19
  392. package/src/internal/executing/coverage_reporter/istanbulCoverageMapFromCoverage.js +0 -16
  393. package/src/internal/executing/coverage_utils/file_by_file_coverage.js +0 -28
  394. package/src/internal/executing/coverage_utils/istanbul_coverage_composition.js +0 -28
  395. package/src/internal/executing/coverage_utils/v8_and_istanbul.js +0 -38
  396. package/src/internal/executing/coverage_utils/v8_coverage_composition.js +0 -23
  397. package/src/internal/executing/coverage_utils/v8_coverage_from_directory.js +0 -86
  398. package/src/internal/executing/coverage_utils/v8_coverage_to_istanbul.js +0 -100
  399. package/src/internal/executing/createSummaryLog.js +0 -143
  400. package/src/internal/executing/executionIsPassed.js +0 -2
  401. package/src/internal/executing/executionLogs.js +0 -159
  402. package/src/internal/executing/generateExecutionSteps.js +0 -29
  403. package/src/internal/executing/launchAndExecute.js +0 -458
  404. package/src/internal/features/browser_feature_detection/browser_feature_detect_dynamic_import.js +0 -20
  405. package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_css.js +0 -23
  406. package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_json.js +0 -25
  407. package/src/internal/features/browser_feature_detection/browser_feature_detect_importmap.js +0 -37
  408. package/src/internal/features/browser_feature_detection/browser_feature_detect_new_stylesheet.js +0 -9
  409. package/src/internal/features/browser_feature_detection/browser_feature_detect_top_level_await.js +0 -14
  410. package/src/internal/features/browser_feature_detection/browser_feature_detection.js +0 -89
  411. package/src/internal/features/browser_feature_detection/compile_proxy.html +0 -27
  412. package/src/internal/features/browser_feature_detection/execute_with_script_module.js +0 -24
  413. package/src/internal/features/features_compat_from_runtime.js +0 -38
  414. package/src/internal/features/features_compat_from_runtime_support.js +0 -31
  415. package/src/internal/features/features_compatibility.js +0 -37
  416. package/src/internal/features/node_feature_detection/feature_detect_dynamic_import.mjs +0 -5
  417. package/src/internal/features/node_feature_detection/feature_detect_top_level_await.mjs +0 -1
  418. package/src/internal/features/node_feature_detection/node_feature_detect_dynamic_import.js +0 -5
  419. package/src/internal/features/node_feature_detection/node_feature_detect_top_level_await.js +0 -16
  420. package/src/internal/features/node_feature_detection/node_feature_detection.js +0 -66
  421. package/src/internal/fetchUrl.js +0 -28
  422. package/src/internal/filePathUtils.js +0 -19
  423. package/src/internal/import-resolution/default-extension.js +0 -40
  424. package/src/internal/import-resolution/import-resolver-importmap.js +0 -64
  425. package/src/internal/import-resolution/import-resolver-node.js +0 -254
  426. package/src/internal/import-resolution/importmap_default.js +0 -37
  427. package/src/internal/jsenvCoreDirectoryUrl.js +0 -11
  428. package/src/internal/jsenvInternalFiles.js +0 -36
  429. package/src/internal/jsenv_builds.js +0 -19
  430. package/src/internal/jsenv_remote_directory.js +0 -156
  431. package/src/internal/logs/byte.js +0 -10
  432. package/src/internal/logs/byteAsFileSize.js +0 -9
  433. package/src/internal/logs/msAsDuration.js +0 -12
  434. package/src/internal/memoize.js +0 -24
  435. package/src/internal/node_launcher/node_runtime_report.js +0 -77
  436. package/src/internal/node_launcher/processOptions.js +0 -46
  437. package/src/internal/node_runtime/evalSource.js +0 -6
  438. package/src/internal/node_runtime/fetchSource.js +0 -8
  439. package/src/internal/node_runtime/node_execution_dynamic_import.js +0 -74
  440. package/src/internal/node_runtime/node_execution_performance.js +0 -67
  441. package/src/internal/node_runtime/node_execution_systemjs.js +0 -125
  442. package/src/internal/node_runtime/node_system.js +0 -191
  443. package/src/internal/origin_directory_converter.js +0 -62
  444. package/src/internal/perf_node.js +0 -13
  445. package/src/internal/promise_race.js +0 -19
  446. package/src/internal/redirector/redirector.html +0 -40
  447. package/src/internal/require.js +0 -3
  448. package/src/internal/response_validation.js +0 -130
  449. package/src/internal/runtime/module-registration.js +0 -207
  450. package/src/internal/runtime/s.js +0 -864
  451. package/src/internal/runtime/s.js.md +0 -1
  452. package/src/internal/runtime/valueInstall.js +0 -14
  453. package/src/internal/runtime_support/jsenv_runtime_support.js +0 -15
  454. package/src/internal/runtime_support/runtime_support.js +0 -70
  455. package/src/internal/semantic_versioning/findHighestVersion.js +0 -12
  456. package/src/internal/semantic_versioning/findLowestVersion.js +0 -12
  457. package/src/internal/semantic_versioning/index.js +0 -5
  458. package/src/internal/semantic_versioning/valueToVersion.js +0 -44
  459. package/src/internal/semantic_versioning/versionCompare.js +0 -32
  460. package/src/internal/semantic_versioning/versionIsAbove.js +0 -5
  461. package/src/internal/semantic_versioning/versionIsBelow.js +0 -5
  462. package/src/internal/semantic_versioning/versionIsEqual.js +0 -3
  463. package/src/internal/sourceMappingURLUtils.js +0 -112
  464. package/src/internal/url_conversion.js +0 -313
  465. package/src/internal/url_utils.js +0 -33
  466. package/src/internal/url_utils.test.js +0 -39
  467. package/src/jsenvCoverageConfig.js +0 -7
  468. package/src/jsenvExplorableConfig.js +0 -9
  469. package/src/jsenvRuntimeSupportDuringDev.js +0 -12
  470. package/src/jsenvServiceWorkerFinalizer.js +0 -55
  471. package/src/jsonToJavaScriptModule.js +0 -12
  472. package/src/launchBrowser.js +0 -43
  473. package/src/launchNode.js +0 -227
  474. package/src/playwright_browser_versions.js +0 -5
  475. package/src/requireUsingChildProcess.js +0 -67
  476. package/src/textToJavaScriptModule.js +0 -14
@@ -1,1963 +0,0 @@
1
- import path from "node:path"
2
- import MagicString from "magic-string"
3
- import { composeTwoImportMaps, normalizeImportMap } from "@jsenv/importmap"
4
- import { isSpecifierForNodeCoreModule } from "@jsenv/importmap/src/isSpecifierForNodeCoreModule.js"
5
- import { createDetailedMessage, loggerToLogLevel } from "@jsenv/logger"
6
- import {
7
- fileSystemPathToUrl,
8
- resolveUrl,
9
- urlToRelativeUrl,
10
- resolveDirectoryUrl,
11
- comparePathnames,
12
- urlIsInsideOf,
13
- normalizeStructuredMetaMap,
14
- urlToMeta,
15
- urlToBasename,
16
- urlToFilename,
17
- readFile,
18
- urlToFileSystemPath,
19
- } from "@jsenv/filesystem"
20
- import { UNICODE } from "@jsenv/log"
21
-
22
- import { require } from "@jsenv/core/src/internal/require.js"
23
- import { convertJsonTextToJavascriptModule } from "@jsenv/core/src/internal/building/json_module.js"
24
- import { convertCssTextToJavascriptModule } from "@jsenv/core/src/internal/building/css_module.js"
25
- import { transformJs } from "@jsenv/core/src/internal/compiling/js-compilation-service/transformJs.js"
26
- import { createUrlConverter } from "@jsenv/core/src/internal/url_conversion.js"
27
- import { createUrlFetcher } from "@jsenv/core/src/internal/building/url_fetcher.js"
28
- import { createUrlLoader } from "@jsenv/core/src/internal/building/url_loader.js"
29
- import { stringifyUrlTrace } from "@jsenv/core/src/internal/building/url_trace.js"
30
- import { sortObjectByPathnames } from "@jsenv/core/src/internal/building/sortObjectByPathnames.js"
31
- import { jsenvHelpersDirectoryInfo } from "@jsenv/core/src/internal/jsenvInternalFiles.js"
32
- import { createImportResolverForNode } from "@jsenv/core/src/internal/import-resolution/import-resolver-node.js"
33
- import { createImportResolverForImportmap } from "@jsenv/core/src/internal/import-resolution/import-resolver-importmap.js"
34
- import { getDefaultImportmap } from "@jsenv/core/src/internal/import-resolution/importmap_default.js"
35
- import { createJsenvRemoteDirectory } from "@jsenv/core/src/internal/jsenv_remote_directory.js"
36
- import { setUrlSearchParamsDescriptor } from "@jsenv/core/src/internal/url_utils.js"
37
- import { shakeBabelPluginMap } from "@jsenv/core/src/internal/compiling/jsenv_directory/compile_profile.js"
38
-
39
- import {
40
- formatBuildStartLog,
41
- formatUseImportMapFromHtml,
42
- formatImportmapOutsideCompileDirectory,
43
- formatRessourceHintNeverUsedWarning,
44
- formatBuildDoneInfo,
45
- } from "./build_logs.js"
46
- import { importMapsFromHtml } from "./html/htmlScan.js"
47
- import { parseRessource } from "./parseRessource.js"
48
- import {
49
- createRessourceBuilder,
50
- referenceToCodeForRollup,
51
- } from "./ressource_builder.js"
52
- import { createBuildUrlGenerator } from "./build_url_generator.js"
53
- import { visitImportReferences } from "./import_references.js"
54
- import { esToSystem } from "./es_to_system.js"
55
- import { createBuildStats } from "./build_stats.js"
56
-
57
- export const createRollupPlugins = async ({
58
- buildOperation,
59
- logger,
60
-
61
- projectDirectoryUrl,
62
- entryPoints,
63
- buildDirectoryUrl,
64
-
65
- urlMappings,
66
- importResolutionMethod,
67
- importMapFileRelativeUrl,
68
- importDefaultExtension,
69
- externalImportSpecifiers,
70
- importPaths,
71
- preservedUrls,
72
- serviceWorkerFinalizer,
73
-
74
- format,
75
- systemJsUrl,
76
- globals,
77
- preservedDynamicImports,
78
-
79
- node,
80
- compileServer,
81
- compileProfile,
82
- compileId,
83
-
84
- urlVersioning,
85
- lineBreakNormalization,
86
- jsConcatenation,
87
- cssConcatenation,
88
- useImportMapToMaximizeCacheReuse,
89
-
90
- minify,
91
- minifyJsOptions,
92
- minifyCssOptions,
93
- minifyHtmlOptions,
94
- }) => {
95
- const compileServerOrigin = compileServer.origin
96
- // For now the compilation is forced during build because this plugin
97
- // was coded assuming build always requires to be compiled.
98
- // Ideally jsenv should also be able to build a project using source files
99
- // and in that case compileProfile and compileId are null
100
- // the babel plugin map is useless (we can just fetch the source file directly)
101
- const jsenvDirectoryRelativeUrl = compileServer.jsenvDirectoryRelativeUrl
102
- const compileDirectoryRelativeUrl = `${jsenvDirectoryRelativeUrl}${compileId}/`
103
- const babelPluginMap = shakeBabelPluginMap({
104
- babelPluginMap: compileServer.babelPluginMap,
105
- compileProfile,
106
- })
107
- const importAssertionsSupport = {
108
- json:
109
- format === "esmodule" &&
110
- compileProfile &&
111
- !compileProfile.missingFeatures["import_assertion_type_json"],
112
- css:
113
- format === "esmodule" &&
114
- compileProfile &&
115
- !compileProfile.missingFeatures["import_assertion_type_css"],
116
- }
117
-
118
- const jsenvRemoteDirectory = createJsenvRemoteDirectory({
119
- projectDirectoryUrl,
120
- jsenvDirectoryRelativeUrl,
121
- preservedUrls,
122
- })
123
-
124
- const urlImporterMap = {}
125
- const inlineModuleScripts = {}
126
- const jsModulesFromEntry = {}
127
- const buildFileContents = {}
128
- const buildInlineFileContents = {}
129
- let buildStats = {}
130
- const buildStartMs = Date.now()
131
-
132
- const serviceWorkerUrls = []
133
- const classicServiceWorkerUrls = []
134
-
135
- let lastErrorMessage
136
- const storeLatestJsenvPluginError = (error) => {
137
- lastErrorMessage = error.message
138
- }
139
-
140
- const extension = path.extname(entryPoints[Object.keys(entryPoints)[0]])
141
- const outputExtension = extension === ".html" ? ".js" : extension
142
-
143
- const entryPointUrls = {}
144
- Object.keys(entryPoints).forEach((key) => {
145
- const url = resolveUrl(key, projectDirectoryUrl)
146
- entryPointUrls[url] = entryPoints[key]
147
- })
148
-
149
- let ressourceBuilder
150
- let importResolver
151
- let rollupEmitFile = () => {}
152
- let rollupSetAssetSource = () => {}
153
- let _rollupGetModuleInfo = () => {}
154
- const rollupGetModuleInfo = (id) => _rollupGetModuleInfo(id)
155
-
156
- const {
157
- compileServerOriginForRollup,
158
- asRollupUrl,
159
- asProjectUrl,
160
- asServerUrl,
161
- asCompiledServerUrl,
162
- asOriginalUrl,
163
- asOriginalServerUrl,
164
- applyUrlMappings,
165
- } = createUrlConverter({
166
- projectDirectoryUrl,
167
- compileServerOrigin,
168
- compileDirectoryRelativeUrl,
169
- urlMappings,
170
- })
171
-
172
- const buildUrlGenerator = createBuildUrlGenerator({
173
- entryPointUrls,
174
- asOriginalUrl,
175
- lineBreakNormalization,
176
- })
177
-
178
- const urlFetcher = createUrlFetcher({
179
- jsenvRemoteDirectory,
180
- asOriginalUrl,
181
- asProjectUrl,
182
- applyUrlMappings,
183
- urlImporterMap,
184
- beforeThrowingResponseValidationError: (error) => {
185
- storeLatestJsenvPluginError(error)
186
- },
187
- })
188
-
189
- const urlCustomLoaders = {}
190
- const urlLoader = createUrlLoader({
191
- urlCustomLoaders,
192
- allowJson: acceptsJsonContentType({ node, format }),
193
- urlImporterMap,
194
-
195
- asProjectUrl,
196
- asOriginalUrl,
197
-
198
- urlFetcher,
199
- })
200
-
201
- const urlMetaGetter = createUrlMetaGetter({
202
- projectDirectoryUrl,
203
- jsenvRemoteDirectory,
204
- preservedUrls,
205
- })
206
-
207
- // Object mapping project relative urls to build relative urls
208
- let buildMappings = {}
209
- // Object mapping ressource names to build relative urls
210
- let ressourceMappings = {}
211
-
212
- const ressourcesReferencedByJs = []
213
- const createImportMapForFilesUsedInJs = () => {
214
- const topLevelMappings = {}
215
- ressourcesReferencedByJs.sort(comparePathnames).forEach((ressourceName) => {
216
- const buildRelativeUrl = ressourceMappings[ressourceName]
217
- if (
218
- ressourceName &&
219
- buildRelativeUrl &&
220
- ressourceName !== buildRelativeUrl
221
- ) {
222
- topLevelMappings[`./${ressourceName}`] = `./${buildRelativeUrl}`
223
- }
224
- })
225
- return {
226
- imports: topLevelMappings,
227
- }
228
- }
229
-
230
- let rollupBuild
231
-
232
- const EMPTY_CHUNK_URL = resolveUrl("__empty__", projectDirectoryUrl)
233
-
234
- const compileDirectoryUrl = resolveDirectoryUrl(
235
- compileDirectoryRelativeUrl,
236
- projectDirectoryUrl,
237
- )
238
- const compileDirectoryServerUrl = resolveDirectoryUrl(
239
- compileDirectoryRelativeUrl,
240
- compileServerOrigin,
241
- )
242
-
243
- const emitAsset = ({ fileName, source }) => {
244
- return rollupEmitFile({
245
- type: "asset",
246
- source,
247
- fileName,
248
- })
249
- }
250
- // rollup expects an input option, if we provide only an html file
251
- // without any script type module in it, we won't emit "chunk" and rollup will throw.
252
- // It is valid to build an html not referencing any js (rare but valid)
253
- // In that case jsenv emits an empty chunk and discards rollup warning about it
254
- // This chunk is later ignored in "generateBundle" hook
255
- let atleastOneChunkEmitted = false
256
- const emitChunk = (chunk) => {
257
- atleastOneChunkEmitted = true
258
- return rollupEmitFile({
259
- type: "chunk",
260
- ...chunk,
261
- })
262
- }
263
- const setAssetSource = (rollupReferenceId, assetSource) => {
264
- return rollupSetAssetSource(rollupReferenceId, assetSource)
265
- }
266
-
267
- let onBundleEnd = () => {}
268
- let minifyJs
269
- let minifyHtml
270
-
271
- const rollupPlugins = []
272
- // When format is systemjs, rollup add async/await
273
- // that might be unsupported by the runtime.
274
- // in that case we have to transform the rollup output
275
- if (babelPluginMap["transform-async-to-promises"] && format === "systemjs") {
276
- rollupPlugins.push({
277
- name: "jsenv_fix_async_await",
278
- async renderChunk(code, chunk) {
279
- let map = chunk.map
280
- const result = await transformJs({
281
- projectDirectoryUrl,
282
- jsenvRemoteDirectory,
283
- url: chunk.facadeModuleId
284
- ? asOriginalUrl(chunk.facadeModuleId)
285
- : resolveUrl(chunk.fileName, buildDirectoryUrl),
286
- code,
287
- babelPluginMap: {
288
- "transform-async-to-promises":
289
- babelPluginMap["transform-async-to-promises"],
290
- },
291
- // pass undefined when format is "systemjs" to avoid
292
- // re-wrapping the code in systemjs format
293
- moduleOutFormat: undefined,
294
- babelHelpersInjectionAsImport: false,
295
- transformGenerator: false,
296
- })
297
- code = result.code
298
- map = result.map
299
- return {
300
- code,
301
- map,
302
- }
303
- },
304
- })
305
- }
306
- if (format === "global") {
307
- const globalsForRollup = {}
308
- Object.keys(globals).forEach((key) => {
309
- if (key.startsWith("./")) {
310
- const keyAsUrl = resolveUrl(key, projectDirectoryUrl)
311
- const keyAsPath = urlToFileSystemPath(keyAsUrl)
312
- globalsForRollup[keyAsPath] = globals[key]
313
- } else {
314
- globalsForRollup[key] = globals[key]
315
- }
316
- })
317
- const ESIIFE = require("es-iife")
318
- const globalNameFromChunkInfo = (chunkInfo) => {
319
- const originalUrl = asOriginalUrl(chunkInfo.facadeModuleId)
320
- const originalPath = urlToFileSystemPath(originalUrl)
321
- const nameFromGlobals = globalsForRollup[originalPath]
322
- return nameFromGlobals || path.parse(chunkInfo.fileName).name
323
- }
324
- const structuredMetaMap = normalizeStructuredMetaMap(
325
- { preserved: preservedDynamicImports },
326
- projectDirectoryUrl,
327
- )
328
- const isPreservedDynamicImport = (url) => {
329
- const meta = urlToMeta({ url, structuredMetaMap })
330
- return Boolean(meta.preserved)
331
- }
332
- rollupPlugins.push({
333
- async transform(code, id) {
334
- const serverUrl = asServerUrl(id)
335
- const originalUrl = asOriginalUrl(id)
336
- if (isPreservedDynamicImport(originalUrl)) {
337
- return null
338
- }
339
- const jsRessource = ressourceBuilder.findRessource((ressource) => {
340
- return ressource.url === serverUrl
341
- })
342
- if (!jsRessource || !jsRessource.isEntryPoint) {
343
- return null
344
- }
345
- let map = null
346
- const ast = this.parse(code, {
347
- // used to know node line and column
348
- locations: true,
349
- })
350
- let useDynamicImport = false
351
- const { walk } = await import("estree-walker")
352
- walk(ast, {
353
- enter: (node) => {
354
- if (node.type === "ImportExpression") {
355
- useDynamicImport = true
356
- }
357
- },
358
- })
359
- if (!useDynamicImport) {
360
- return null
361
- }
362
- const magicString = new MagicString(code)
363
- magicString.prepend(`import "@jsenv/core/src/internal/runtime/s.js";`)
364
- code = magicString.toString()
365
- map = magicString.generateMap({ hires: true })
366
- return { code, map }
367
- },
368
-
369
- outputOptions: (outputOptions) => {
370
- outputOptions.globals = globalsForRollup
371
- outputOptions.format = "esm"
372
- },
373
- resolveImportMeta: (property, { chunkId }) => {
374
- if (property === "url") {
375
- return `(document.currentScript && document.currentScript.src || new URL("${chunkId}", document.baseURI).href);`
376
- }
377
- return undefined
378
- },
379
- renderDynamicImport: ({ moduleId }) => {
380
- const originalUrl = asOriginalUrl(moduleId)
381
- if (isPreservedDynamicImport(originalUrl)) {
382
- return null
383
- }
384
- return {
385
- left: "System.import(",
386
- right: ")",
387
- }
388
- },
389
- async renderChunk(code, chunkInfo) {
390
- const serverUrl = asServerUrl(chunkInfo.facadeModuleId)
391
- const jsRessource = ressourceBuilder.findRessource(
392
- (ressource) => ressource.url === serverUrl,
393
- )
394
- if (jsRessource.isEntryPoint) {
395
- const name = globalNameFromChunkInfo(chunkInfo)
396
- const out = ESIIFE.transform({
397
- code,
398
- parse: this.parse,
399
- name,
400
- sourcemap: true,
401
- resolveGlobal: (specifier) => {
402
- const url = resolveUrl(specifier, chunkInfo.facadeModuleId)
403
- const globalName = urlToBasename(url)
404
- return globalName
405
- },
406
- strict: true,
407
- })
408
- code = out.code
409
- const map = out.map
410
- return {
411
- code,
412
- map,
413
- }
414
- }
415
- return esToSystem({
416
- code,
417
- url: serverUrl,
418
- map: chunkInfo.map,
419
- })
420
- },
421
- })
422
- }
423
- if (minify) {
424
- const methodHooks = {
425
- minifyJs: async (...args) => {
426
- const { minifyJs } = await import("./js/minifyJs.js")
427
- return minifyJs(...args)
428
- },
429
- minifyHtml: async (...args) => {
430
- const { minifyHtml } = await import("./html/minifyHtml.js")
431
- return minifyHtml(...args)
432
- },
433
- }
434
- minifyJs = async ({ url, code, map, ...rest }) => {
435
- const result = await methodHooks.minifyJs({
436
- url,
437
- code,
438
- map,
439
- ...minifyJsOptions,
440
- ...rest,
441
- })
442
- return {
443
- code: result.code,
444
- map: result.map,
445
- }
446
- }
447
- minifyHtml = async (html) => {
448
- return methodHooks.minifyHtml(html, minifyHtmlOptions)
449
- }
450
- rollupPlugins.push({
451
- name: "jsenv_minifier",
452
- async renderChunk(code, chunk) {
453
- let map = chunk.map
454
- const result = await minifyJs({
455
- url: chunk.facadeModuleId
456
- ? asOriginalUrl(chunk.facadeModuleId)
457
- : resolveUrl(chunk.fileName, buildDirectoryUrl),
458
- code,
459
- map,
460
- module: format === "esmodule",
461
- ...(format === "global" ? { toplevel: false } : { toplevel: true }),
462
- })
463
- code = result.code
464
- map = result.map
465
- return {
466
- code,
467
- map,
468
- }
469
- },
470
- })
471
- }
472
- rollupPlugins.unshift({
473
- name: "jsenv",
474
-
475
- async buildStart() {
476
- logger.info(formatBuildStartLog({ entryPoints }))
477
-
478
- const entryPointsPrepared = await prepareEntryPoints(entryPoints, {
479
- logger,
480
- projectDirectoryUrl,
481
- buildDirectoryUrl,
482
- compileServerOrigin,
483
- urlFetcher,
484
- })
485
- const htmlEntryPoints = entryPointsPrepared.filter(
486
- (entryPointPrepared) => {
487
- return entryPointPrepared.entryContentType === "text/html"
488
- },
489
- )
490
- const htmlEntryPointCount = htmlEntryPoints.length
491
- if (node && htmlEntryPointCount > 0) {
492
- logger.warn(
493
- `WARNING: Found an HTML entry point and "node" is part of "runtimeSupport", it's not supposed to happen`,
494
- )
495
- }
496
- if (htmlEntryPointCount > 1) {
497
- const error = new Error(
498
- `Cannot handle more than one html entry point, got ${htmlEntryPointCount}`,
499
- )
500
- storeLatestJsenvPluginError(error)
501
- throw error
502
- }
503
-
504
- if (typeof useImportMapToMaximizeCacheReuse === "undefined") {
505
- useImportMapToMaximizeCacheReuse =
506
- htmlEntryPointCount > 0 &&
507
- // node has no importmap concept, let's use the versionned url in that case
508
- !node
509
- }
510
-
511
- // https://github.com/easesu/rollup-plugin-html-input/blob/master/index.js
512
- // https://rollupjs.org/guide/en/#thisemitfileemittedfile-emittedchunk--emittedasset--string
513
- rollupEmitFile = (...args) => this.emitFile(...args)
514
- rollupSetAssetSource = (...args) => this.setAssetSource(...args)
515
- _rollupGetModuleInfo = (id) => this.getModuleInfo(id)
516
-
517
- let importMapInfoFromHtml = null
518
- if (htmlEntryPointCount === 1) {
519
- const htmlEntryPoint = htmlEntryPoints[0]
520
- const htmlSource = String(htmlEntryPoint.entryBuffer)
521
-
522
- const importMaps = importMapsFromHtml(htmlSource)
523
- const importMapCount = importMaps.length
524
- if (importMapCount > 1) {
525
- const error = new Error(`Many importmap found in html file`)
526
- storeLatestJsenvPluginError(error)
527
- throw error
528
- }
529
-
530
- if (importMapCount === 1) {
531
- const htmlUrl = resolveUrl(
532
- htmlEntryPoint.entryProjectRelativeUrl,
533
- projectDirectoryUrl,
534
- )
535
- importMapInfoFromHtml = {
536
- ...importMaps[0],
537
- htmlUrl,
538
- htmlSource,
539
- }
540
- }
541
- }
542
-
543
- if (importResolutionMethod === "node") {
544
- importResolver = await createImportResolverForNode({
545
- projectDirectoryUrl,
546
- compileServerOrigin,
547
- compileDirectoryRelativeUrl,
548
- importDefaultExtension,
549
- })
550
- } else {
551
- let importMap
552
- let importMapUrl
553
- let fetchImportMap
554
- if (importMapInfoFromHtml) {
555
- logger.debug(formatUseImportMapFromHtml(importMapInfoFromHtml))
556
-
557
- if (importMapInfoFromHtml.type === "remote") {
558
- importMapUrl = resolveUrl(
559
- importMapInfoFromHtml.src,
560
- asCompiledServerUrl(importMapInfoFromHtml.htmlUrl),
561
- )
562
- importMapUrl = applyUrlMappings(importMapUrl)
563
- if (!urlIsInsideOf(importMapUrl, compileDirectoryServerUrl)) {
564
- logger.warn(
565
- formatImportmapOutsideCompileDirectory({
566
- importMapInfo: importMapInfoFromHtml,
567
- compileDirectoryUrl,
568
- }),
569
- )
570
- }
571
- fetchImportMap = () => {
572
- return fetchImportMapFromUrl(
573
- importMapUrl,
574
- importMapInfoFromHtml.htmlUrl,
575
- )
576
- }
577
- } else {
578
- const firstHtmlEntryPoint = htmlEntryPoints[0]
579
- const htmlProjectRelativeUrl =
580
- firstHtmlEntryPoint.entryProjectRelativeUrl
581
- const htmlCompiledUrl = resolveUrl(
582
- htmlProjectRelativeUrl,
583
- compileDirectoryServerUrl,
584
- )
585
- importMapUrl = htmlCompiledUrl
586
- fetchImportMap = () => {
587
- const importmapFileUrl = asProjectUrl(importMapUrl)
588
- const jsenvImportmap = getDefaultImportmap(importmapFileUrl, {
589
- projectDirectoryUrl,
590
- compileDirectoryUrl,
591
- })
592
- const htmlImportmap = JSON.parse(importMapInfoFromHtml.text)
593
- const importmap = composeTwoImportMaps(
594
- jsenvImportmap,
595
- htmlImportmap,
596
- )
597
- const importmapNormalized = normalizeImportMap(
598
- importmap,
599
- importMapUrl,
600
- )
601
- return importmapNormalized
602
- }
603
- }
604
- } else if (importMapFileRelativeUrl) {
605
- importMapUrl = resolveUrl(
606
- importMapFileRelativeUrl,
607
- compileDirectoryServerUrl,
608
- )
609
- fetchImportMap = () => {
610
- return fetchImportMapFromUrl(
611
- importMapUrl,
612
- "importMapFileRelativeUrl parameter",
613
- )
614
- }
615
- } else {
616
- // there is no importmap, it's fine, it's not mandatory
617
- fetchImportMap = () => {
618
- const firstEntryPoint = htmlEntryPoints[0] || entryPointsPrepared[0]
619
- const { entryProjectRelativeUrl } = firstEntryPoint
620
- const entryCompileUrl = resolveUrl(
621
- entryProjectRelativeUrl,
622
- compileDirectoryUrl,
623
- )
624
- const jsenvImportmap = getDefaultImportmap(entryCompileUrl, {
625
- projectDirectoryUrl,
626
- compileDirectoryUrl,
627
- })
628
- const entryCompileServerUrl = resolveUrl(
629
- entryProjectRelativeUrl,
630
- compileDirectoryServerUrl,
631
- )
632
- const importmapNormalized = normalizeImportMap(
633
- jsenvImportmap,
634
- entryCompileServerUrl,
635
- )
636
- return importmapNormalized
637
- }
638
- }
639
-
640
- try {
641
- importMap = await fetchImportMap()
642
- } catch (e) {
643
- storeLatestJsenvPluginError(e)
644
- throw e
645
- }
646
- importResolver = await createImportResolverForImportmap({
647
- compileServerOrigin,
648
- compileDirectoryRelativeUrl,
649
- importMap,
650
- importMapUrl,
651
- importDefaultExtension,
652
- onBareSpecifierError: (error) => {
653
- storeLatestJsenvPluginError(error)
654
- },
655
- })
656
- }
657
-
658
- ressourceBuilder = createRessourceBuilder(
659
- {
660
- urlFetcher,
661
- urlLoader,
662
- parseRessource: async (ressource, notifiers) => {
663
- return parseRessource(ressource, notifiers, {
664
- format,
665
- systemJsUrl,
666
- projectDirectoryUrl,
667
- jsenvRemoteDirectory,
668
- asProjectUrl,
669
- asOriginalUrl,
670
- asOriginalServerUrl,
671
- ressourceHintNeverUsedCallback: (linkInfo) => {
672
- logger.warn(formatRessourceHintNeverUsedWarning(linkInfo))
673
- },
674
- useImportMapToMaximizeCacheReuse,
675
- createImportMapForFilesUsedInJs,
676
- minify,
677
- minifyJs,
678
- minifyHtml,
679
- minifyCssOptions,
680
- cssConcatenation,
681
- })
682
- },
683
- },
684
- {
685
- logLevel: loggerToLogLevel(logger),
686
- format,
687
- // projectDirectoryUrl,
688
- compileServerOrigin,
689
- buildDirectoryUrl,
690
-
691
- asOriginalServerUrl,
692
- urlToCompiledServerUrl: (url) => {
693
- return asCompiledServerUrl(url)
694
- },
695
- urlToHumanUrl: (
696
- url,
697
- { showCompiledHint = false, preferRelativeUrls = false } = {},
698
- ) => {
699
- if (
700
- !url.startsWith("http:") &&
701
- !url.startsWith("https:") &&
702
- !url.startsWith("file:")
703
- ) {
704
- return url
705
- }
706
- const originalUrl = asOriginalUrl(url)
707
- const isCompiled = urlIsInsideOf(url, compileServerOrigin)
708
- const originalRelativeUrl = urlToRelativeUrl(
709
- originalUrl,
710
- projectDirectoryUrl,
711
- )
712
- if (showCompiledHint && isCompiled) {
713
- if (preferRelativeUrls) {
714
- return `${originalRelativeUrl}[compiled]`
715
- }
716
- return `${originalUrl}[compiled]`
717
- }
718
- if (preferRelativeUrls) {
719
- return originalRelativeUrl
720
- }
721
- return originalUrl
722
- },
723
- resolveRessourceUrl: ({
724
- ressourceSpecifier,
725
- isJsModule,
726
- // isRessourceHint,
727
- ressourceImporter,
728
- }) => {
729
- const getRessourceUrl = () => {
730
- // Entry point is not a JS module and references a js module (html referencing js)
731
- if (
732
- ressourceImporter.isEntryPoint &&
733
- !ressourceImporter.isJsModule &&
734
- isJsModule
735
- ) {
736
- const importerCompiledUrl = asCompiledServerUrl(
737
- ressourceImporter.url,
738
- )
739
- const jsModuleUrl = resolveUrl(
740
- ressourceSpecifier,
741
- importerCompiledUrl,
742
- )
743
- return jsModuleUrl
744
- }
745
- // Entry point (likely html, unlikely css) is referecing a ressource
746
- // In this situation:
747
- // - when importmap is referenced: parse the original importmap ressource
748
- // - other ressource: force compilation (because the HTML url is the original url)
749
- if (
750
- ressourceImporter.isEntryPoint &&
751
- !ressourceImporter.isJsModule
752
- ) {
753
- if (ressourceSpecifier.endsWith(".importmap")) {
754
- const importmapUrl = resolveUrl(
755
- ressourceSpecifier,
756
- ressourceImporter.url,
757
- )
758
- return importmapUrl
759
- }
760
- const importerCompiled = asCompiledServerUrl(
761
- ressourceImporter.url,
762
- )
763
- const ressourceCompiledUrl = resolveUrl(
764
- ressourceSpecifier,
765
- importerCompiled,
766
- )
767
- return ressourceCompiledUrl
768
- }
769
- const ressourceCompiledUrl = resolveUrl(
770
- ressourceSpecifier,
771
- ressourceImporter.url,
772
- )
773
- return ressourceCompiledUrl
774
- }
775
- const ressourceUrl = getRessourceUrl()
776
- const resolutionResult = { url: ressourceUrl }
777
- const ressourceOriginalUrl =
778
- asOriginalUrl(ressourceUrl) || ressourceUrl
779
-
780
- if (!urlIsInsideOf(ressourceUrl, compileServerOrigin)) {
781
- resolutionResult.isCrossOrigin = true
782
- }
783
-
784
- const urlMeta = urlMetaGetter(ressourceOriginalUrl)
785
- if (urlMeta.preserve) {
786
- resolutionResult.isExternal = true
787
- } else if (jsenvRemoteDirectory.isRemoteUrl(ressourceOriginalUrl)) {
788
- const fileUrl =
789
- jsenvRemoteDirectory.fileUrlFromRemoteUrl(ressourceOriginalUrl)
790
- const compiledFileUrl = asCompiledServerUrl(fileUrl)
791
- resolutionResult.url = compiledFileUrl
792
- }
793
- const { searchParams } = new URL(ressourceUrl)
794
- if (searchParams.has("module")) {
795
- resolutionResult.isJsModule = true
796
- } else if (searchParams.has("worker")) {
797
- resolutionResult.isWorker = true
798
- resolutionResult.isJsModule = true
799
- } else if (searchParams.has("service_worker")) {
800
- resolutionResult.isServiceWorker = true
801
- resolutionResult.isJsModule = true
802
- serviceWorkerUrls.push(ressourceOriginalUrl)
803
- } else if (searchParams.has("worker_type_classic")) {
804
- resolutionResult.isWorker = true
805
- } else if (searchParams.has("service_worker_type_classic")) {
806
- resolutionResult.isServiceWorker = true
807
- classicServiceWorkerUrls.push(ressourceOriginalUrl)
808
- }
809
- return resolutionResult
810
- },
811
- onJsModule: ({ ressource, jsModuleUrl, jsModuleIsInline }) => {
812
- // we want to emit chunk only when ressource is referenced by something else than rollup
813
- if (
814
- jsConcatenation &&
815
- ressource.references.every((ref) => ref.fromRollup)
816
- ) {
817
- return null
818
- }
819
- if (ressource.isEntryPoint) {
820
- } else {
821
- const importerUrl = resolveUrl(
822
- entryPointsPrepared[0].entryProjectRelativeUrl,
823
- compileDirectoryServerUrl,
824
- )
825
- urlImporterMap[jsModuleUrl] = {
826
- url: importerUrl,
827
- line: undefined,
828
- column: undefined,
829
- }
830
- jsModulesFromEntry[asRollupUrl(jsModuleUrl)] = true
831
- if (jsModuleIsInline) {
832
- inlineModuleScripts[jsModuleUrl] = ressource
833
- urlCustomLoaders[jsModuleUrl] = async () => {
834
- const url = asOriginalUrl(jsModuleUrl) // transformJs expect a file:// url
835
- let code = String(ressource.bufferBeforeBuild)
836
- const transformResult = await transformJs({
837
- projectDirectoryUrl,
838
- jsenvRemoteDirectory,
839
- url,
840
- babelPluginMap,
841
- // moduleOutFormat: format // we are compiling for rollup output must be "esmodule"
842
- // we compile for rollup, let top level await untouched
843
- // it will be converted, if needed, during "renderChunk" hook
844
- topLevelAwait: "ignore",
845
- // if we put babel helpers, rollup might try to share them and a file
846
- // might try to import from an inline script resulting in 404.
847
- babelHelpersInjectionAsImport: false,
848
- code,
849
- })
850
- return {
851
- code: transformResult.code,
852
- map: transformResult.map,
853
- }
854
- }
855
- }
856
- }
857
- const fileName = ressource.buildRelativeUrlWithoutHash
858
- const name = urlToBasename(resolveUrl(fileName, "file://"))
859
- const rollupReferenceId = emitChunk({
860
- id: jsModuleUrl,
861
- name,
862
- ...(useImportMapToMaximizeCacheReuse && !ressource.isInline
863
- ? { fileName }
864
- : {}),
865
- })
866
- return {
867
- rollupReferenceId,
868
- fileName:
869
- useImportMapToMaximizeCacheReuse && !ressource.isInline
870
- ? fileName
871
- : name,
872
- }
873
- },
874
- onAsset: ({ ressource }) => {
875
- const fileName = ressource.buildRelativeUrlWithoutHash
876
- const rollupReferenceId = emitAsset({
877
- fileName,
878
- })
879
- return {
880
- rollupReferenceId,
881
- fileName,
882
- }
883
- },
884
- onAssetSourceUpdated: ({ ressource }) => {
885
- setAssetSource(
886
- ressource.rollupReferenceId,
887
- ressource.bufferAfterBuild,
888
- )
889
- },
890
- buildUrlGenerator,
891
- },
892
- )
893
-
894
- await Promise.all(
895
- entryPointsPrepared.map(
896
- async ({
897
- entryContentType,
898
- entryProjectRelativeUrl,
899
- entryBuffer,
900
- }) => {
901
- if (entryContentType === "application/javascript") {
902
- await ressourceBuilder.createReferenceForEntryPoint({
903
- entryContentType,
904
- entryUrl: resolveUrl(
905
- entryProjectRelativeUrl,
906
- compileDirectoryServerUrl,
907
- ),
908
- })
909
- return
910
- }
911
-
912
- if (
913
- entryContentType !== "text/html" &&
914
- entryContentType !== "text/css"
915
- ) {
916
- logger.warn(
917
- `Unusual content type for entry point, got "${entryContentType}" for ${entryProjectRelativeUrl}`,
918
- )
919
- }
920
- const entryUrl =
921
- entryContentType === "text/html"
922
- ? resolveUrl(entryProjectRelativeUrl, compileServerOrigin)
923
- : resolveUrl(entryProjectRelativeUrl, compileDirectoryServerUrl)
924
- await ressourceBuilder.createReferenceForEntryPoint({
925
- entryContentType,
926
- entryUrl,
927
- entryBuffer,
928
- })
929
- },
930
- ),
931
- )
932
-
933
- if (!atleastOneChunkEmitted) {
934
- emitChunk({
935
- id: EMPTY_CHUNK_URL,
936
- fileName: "__empty__",
937
- })
938
- }
939
- },
940
-
941
- async resolveId(specifier, importer, { custom = {} } = {}) {
942
- if (specifier === EMPTY_CHUNK_URL) {
943
- return specifier
944
- }
945
-
946
- let importerUrl
947
- if (importer === undefined) {
948
- if (specifier.endsWith(".html")) {
949
- importerUrl = compileServerOrigin
950
- } else {
951
- importerUrl = compileDirectoryServerUrl
952
- }
953
- } else {
954
- importerUrl = asServerUrl(importer)
955
- }
956
-
957
- const { importAssertionInfo } = custom
958
- const onExternal = ({ specifier, reason }) => {
959
- logger.debug(`${specifier} marked as external (reason: ${reason})`)
960
- }
961
-
962
- if (node && isSpecifierForNodeCoreModule(specifier)) {
963
- onExternal({
964
- specifier,
965
- reason: `node builtin module`,
966
- })
967
- return false
968
- }
969
-
970
- if (externalImportSpecifiers.includes(specifier)) {
971
- onExternal({
972
- specifier,
973
- reason: `declared in "externalImportSpecifiers"`,
974
- })
975
- return { id: specifier, external: true }
976
- }
977
-
978
- if (inlineModuleScripts.hasOwnProperty(specifier)) {
979
- return asRollupUrl(specifier)
980
- }
981
-
982
- const specifierUrl = await importResolver.resolveImport(
983
- specifier,
984
- importerUrl,
985
- )
986
- const existingImporter = urlImporterMap[specifierUrl]
987
- if (!existingImporter) {
988
- urlImporterMap[specifierUrl] = importAssertionInfo
989
- ? {
990
- url: importerUrl,
991
- column: importAssertionInfo.column,
992
- line: importAssertionInfo.line,
993
- }
994
- : {
995
- url: importerUrl,
996
- // rollup do not expose a way to know line and column for the static or dynamic import
997
- // referencing that file
998
- column: undefined,
999
- line: undefined,
1000
- }
1001
- }
1002
- // keep external url intact
1003
- const specifierProjectUrl = asProjectUrl(specifierUrl)
1004
- if (!specifierProjectUrl) {
1005
- onExternal({
1006
- specifier,
1007
- reason: `outside project directory`,
1008
- })
1009
- return { id: specifier, external: true }
1010
- }
1011
- const specifierOriginalUrl = asOriginalUrl(specifierProjectUrl)
1012
- const urlMeta = urlMetaGetter(specifierOriginalUrl)
1013
- if (urlMeta.preserve) {
1014
- if (urlMeta.remote) {
1015
- specifier =
1016
- jsenvRemoteDirectory.remoteUrlFromFileUrl(specifierOriginalUrl)
1017
- }
1018
- onExternal({
1019
- specifier,
1020
- reason: `matches "preservedUrls"`,
1021
- })
1022
- return { id: specifier, external: true }
1023
- }
1024
- // const rollupId = urlToRollupId(importUrl, { projectDirectoryUrl, compileServerOrigin })
1025
- // logger.debug(`${specifier} imported by ${importer} resolved to ${importUrl}`)
1026
- const specifierRollupUrl = asRollupUrl(specifierUrl)
1027
- return specifierRollupUrl
1028
- },
1029
-
1030
- resolveFileUrl: ({ referenceId, fileName }) => {
1031
- ressourcesReferencedByJs.push(fileName)
1032
- const getAssetRelativeUrl = () => {
1033
- const ressource = ressourceBuilder.findRessource((ressource) => {
1034
- return ressource.rollupReferenceId === referenceId
1035
- })
1036
- ressource.buildRelativeUrlWithoutHash = fileName
1037
- if (ressource.isJsModule) {
1038
- return fileName
1039
- }
1040
- const buildRelativeUrl = ressource.buildRelativeUrl
1041
- return buildRelativeUrl
1042
- }
1043
- if (format === "esmodule") {
1044
- if (!node && useImportMapToMaximizeCacheReuse && urlVersioning) {
1045
- return `window.__resolveImportUrl__("./${fileName}", import.meta.url)`
1046
- }
1047
- return `new URL("${getAssetRelativeUrl()}", import.meta.url)`
1048
- }
1049
- if (format === "systemjs") {
1050
- return `new URL(System.resolve("./${fileName}", module.meta.url))`
1051
- }
1052
- if (format === "global") {
1053
- return `new URL("${getAssetRelativeUrl()}", document.currentScript && document.currentScript.src || document.baseURI)`
1054
- }
1055
- if (format === "commonjs") {
1056
- return `new URL("${getAssetRelativeUrl()}", "file:///" + __filename.replace(/\\/g, "/"))`
1057
- }
1058
- return null
1059
- },
1060
-
1061
- // https://rollupjs.org/guide/en#resolvedynamicimport
1062
- // resolveDynamicImport: (specifier, importer) => {
1063
-
1064
- // },
1065
-
1066
- async load(rollupUrl) {
1067
- if (rollupUrl === EMPTY_CHUNK_URL) {
1068
- return ""
1069
- }
1070
- let url = asServerUrl(rollupUrl)
1071
- // Jsenv helpers are injected as import statements to provide code like babel helpers
1072
- // For now we just compute the information that the target file is a jsenv helper
1073
- // without doing anything special with "targetIsJsenvHelperFile" information
1074
- const projectUrl = asProjectUrl(rollupUrl)
1075
- const originalUrl = asOriginalUrl(rollupUrl)
1076
- const isJsenvHelperFile = urlIsInsideOf(
1077
- originalUrl,
1078
- jsenvHelpersDirectoryInfo.url,
1079
- )
1080
- // const isEntryPoint = entryPointUrls[originalUrl]
1081
- const loadResult = await buildOperation.withSignal((signal) => {
1082
- let urlToLoad
1083
- const jsModuleRessource = ressourceBuilder.findRessource(
1084
- (ressource) => ressource.url === url,
1085
- )
1086
- if (
1087
- jsModuleRessource &&
1088
- jsModuleRessource.firstStrongReference &&
1089
- jsModuleRessource.firstStrongReference.integrity
1090
- ) {
1091
- urlToLoad = setUrlSearchParamsDescriptor(url, {
1092
- integrity: jsModuleRessource.firstStrongReference.integrity,
1093
- })
1094
- urlImporterMap[urlToLoad] = urlImporterMap[url]
1095
- } else {
1096
- urlToLoad = url
1097
- }
1098
- return urlLoader.loadUrl(urlToLoad, {
1099
- signal,
1100
- logger,
1101
- })
1102
- })
1103
- // if (loadResult.url) url = loadResult.url
1104
- const code = loadResult.code
1105
- const map = loadResult.map
1106
- if (jsenvRemoteDirectory.isFileUrlForRemoteUrl(originalUrl)) {
1107
- map.sources.forEach((source, index) => {
1108
- if (jsenvRemoteDirectory.isRemoteUrl(source)) {
1109
- const sourceFileUrl =
1110
- jsenvRemoteDirectory.fileUrlFromRemoteUrl(source)
1111
- const sourceRelativeUrl = urlToRelativeUrl(
1112
- sourceFileUrl,
1113
- projectUrl,
1114
- )
1115
- map.sources[index] = sourceRelativeUrl
1116
- }
1117
- })
1118
- }
1119
- const importer = urlImporterMap[url]
1120
- // Inform ressource builder that this js module exists
1121
- // It can only be a js module and happens when:
1122
- // - entry point (html) references js
1123
- // - js is referenced by static or dynamic imports
1124
- // For import assertions, the imported ressource (css,json,...)
1125
- // is already converted to a js module
1126
- ressourceBuilder.createReferenceFoundByRollup({
1127
- contentTypeExpected: "application/javascript",
1128
- referenceLabel: "static or dynamic import",
1129
- referenceUrl: importer.url,
1130
- referenceColumn: importer.column,
1131
- referenceLine: importer.line,
1132
- ressourceSpecifier: url,
1133
- isJsenvHelperFile,
1134
- contentType: "application/javascript",
1135
- isJsModule: true,
1136
- bufferBeforeBuild: Buffer.from(code),
1137
- })
1138
- return {
1139
- code,
1140
- map,
1141
- }
1142
- },
1143
-
1144
- async transform(code, id) {
1145
- let map = null
1146
- // we should try/catch here?
1147
- // because this.parse might fail
1148
- const ast = this.parse(code, {
1149
- // used to know node line and column
1150
- locations: true,
1151
- })
1152
- // const moduleInfo = this.getModuleInfo(id)
1153
- const url = asServerUrl(id)
1154
- const mutations = []
1155
- await visitImportReferences({
1156
- ast,
1157
- onReferenceWithImportMetaUrlPattern: async ({ importNode }) => {
1158
- const specifier = importNode.arguments[0].value
1159
- const { line, column } = importNode.loc.start
1160
- const { id } = normalizeRollupResolveReturnValue(
1161
- await this.resolve(specifier, url),
1162
- )
1163
- const ressourceUrl = asServerUrl(id)
1164
- const reference = ressourceBuilder.createReferenceFoundInJsModule({
1165
- referenceLabel: "URL + import.meta.url",
1166
- jsUrl: url,
1167
- jsLine: line,
1168
- jsColumn: column,
1169
- ressourceSpecifier: ressourceUrl,
1170
- })
1171
- if (!reference) {
1172
- return
1173
- }
1174
- if (!reference.ressource.isJsModule) {
1175
- // so that ressource.buildRelativeUrl is known during "resolveFileUrl" hook`
1176
- await reference.ressource.getReadyPromise()
1177
- }
1178
- mutations.push((magicString) => {
1179
- magicString.overwrite(
1180
- importNode.start,
1181
- importNode.end,
1182
- referenceToCodeForRollup(reference),
1183
- )
1184
- })
1185
- },
1186
- onReferenceWithImportAssertion: async ({
1187
- importNode,
1188
- typePropertyNode,
1189
- assertions,
1190
- }) => {
1191
- const { source } = importNode
1192
- const importSpecifier = source.value
1193
- const { line, column } = importNode.loc.start
1194
- // "type" is dynamic on dynamic import such as
1195
- // import("./data.json", {
1196
- // assert: {
1197
- // type: true ? "json" : "css"
1198
- // }
1199
- // })
1200
- if (typePropertyNode) {
1201
- const typePropertyValue = typePropertyNode.value
1202
- if (typePropertyValue.type !== "Literal") {
1203
- if (importAssertionSupportedByRuntime) {
1204
- return // keep untouched
1205
- }
1206
- throw new Error(
1207
- createDetailedMessage(
1208
- `Dynamic "type" not supported for dynamic import assertion`,
1209
- {
1210
- "import assertion trace": stringifyUrlTrace(
1211
- urlLoader.createUrlTrace({ url, line, column }),
1212
- ),
1213
- },
1214
- ),
1215
- )
1216
- }
1217
- assertions = {
1218
- type: typePropertyValue.value,
1219
- }
1220
- }
1221
- const { type } = assertions
1222
- // "specifier" is dynamic on dynamic import such as
1223
- // import(true ? "./a.json" : "b.json", {
1224
- // assert: {
1225
- // type: "json"
1226
- // }
1227
- // })
1228
- const importAssertionSupportedByRuntime =
1229
- importAssertionsSupport[type]
1230
- if (source.type !== "Literal") {
1231
- if (importAssertionSupportedByRuntime) {
1232
- return // keep untouched
1233
- }
1234
- throw new Error(
1235
- createDetailedMessage(
1236
- `Dynamic specifier not supported for dynamic import assertion`,
1237
- {
1238
- "import assertion trace": stringifyUrlTrace(
1239
- urlLoader.createUrlTrace({ url, line, column }),
1240
- ),
1241
- },
1242
- ),
1243
- )
1244
- }
1245
- // There is no strategy for css import assertion on Node.js
1246
- if (type === "css" && node) {
1247
- throw new Error(
1248
- createDetailedMessage(
1249
- `{ type: "css" } is not supported when "node" is part of "runtimeSupport"`,
1250
- {
1251
- "import assertion trace": stringifyUrlTrace(
1252
- urlLoader.createUrlTrace({ url, line, column }),
1253
- ),
1254
- },
1255
- ),
1256
- )
1257
- }
1258
-
1259
- const { id, external } = normalizeRollupResolveReturnValue(
1260
- await this.resolve(importSpecifier, url, {
1261
- custom: {
1262
- importAssertionInfo: {
1263
- line,
1264
- column,
1265
- type,
1266
- supportedByRuntime: importAssertionSupportedByRuntime,
1267
- },
1268
- },
1269
- }),
1270
- )
1271
- // remove import
1272
- let ressourceUrl = asServerUrl(id)
1273
- // lod the asset without ?import_type in it
1274
- ressourceUrl = ressourceUrl.replace(`?import_type=${type}`, "")
1275
- const fileReference = ressourceBuilder.createReferenceFoundInJsModule(
1276
- {
1277
- referenceLabel: `${type} import assertion`,
1278
- // If all references to a ressource are only import assertions
1279
- // the file referenced do not need to be written on filesystem
1280
- // as it was converted to a js file
1281
- // We pass "isImportAssertion: true" for this purpose
1282
- isImportAssertion: true,
1283
- jsUrl: url,
1284
- jsLine: line,
1285
- jsColumn: column,
1286
- ressourceSpecifier: ressourceUrl,
1287
- contentTypeExpected:
1288
- type === "css" ? "text/css" : "application/json",
1289
- },
1290
- )
1291
- // reference can be null for cross origin urls
1292
- if (!fileReference) {
1293
- return
1294
- }
1295
- if (external && !importAssertionSupportedByRuntime) {
1296
- throw new Error(
1297
- createDetailedMessage(
1298
- `import assertion ressource cannot be external when runtime do not support import assertions`,
1299
- {
1300
- "import assertion trace": stringifyUrlTrace(
1301
- urlLoader.createUrlTrace({ url, line, column }),
1302
- ),
1303
- },
1304
- ),
1305
- )
1306
- }
1307
-
1308
- // await fileReference.ressource.getReadyPromise()
1309
- // once the file is ready, we know its buildRelativeUrl
1310
- // we can update either to the fileName or buildRelativeUrl
1311
- // should be use the rollup reference id?
1312
- const ressourceUrlAsJsModule = resolveUrl(
1313
- `${urlToBasename(
1314
- ressourceUrl,
1315
- )}${outputExtension}?import_type=${type}`,
1316
- ressourceUrl,
1317
- )
1318
- const jsUrl = url
1319
- urlCustomLoaders[ressourceUrlAsJsModule] = async () => {
1320
- let code
1321
- let map
1322
-
1323
- if (type === "json") {
1324
- await fileReference.ressource.getReadyPromise()
1325
- code = String(fileReference.ressource.bufferAfterBuild)
1326
- const jsModuleConversionResult =
1327
- await convertJsonTextToJavascriptModule({
1328
- code,
1329
- map,
1330
- })
1331
- code = jsModuleConversionResult.code
1332
- map = jsModuleConversionResult.map
1333
- } else if (type === "css") {
1334
- await fileReference.ressource.getReadyPromise()
1335
- const cssBuildUrl = resolveUrl(
1336
- fileReference.ressource.buildRelativeUrl,
1337
- buildDirectoryUrl,
1338
- )
1339
- const jsBuildUrl = resolveUrl(
1340
- urlToFilename(jsUrl),
1341
- buildDirectoryUrl,
1342
- )
1343
- code = String(fileReference.ressource.bufferAfterBuild)
1344
- const sourcemapReference =
1345
- fileReference.ressource.dependencies.find((dependency) => {
1346
- return dependency.ressource.isSourcemap
1347
- })
1348
- if (sourcemapReference) {
1349
- // because css is ready, it's sourcemap is also ready
1350
- // we can read directly sourcemapReference.ressource.bufferAfterBuild
1351
- map = JSON.parse(sourcemapReference.ressource.bufferAfterBuild)
1352
- }
1353
- const jsModuleConversionResult =
1354
- await convertCssTextToJavascriptModule({
1355
- cssUrl: cssBuildUrl,
1356
- jsUrl: jsBuildUrl,
1357
- code,
1358
- map,
1359
- })
1360
- code = jsModuleConversionResult.code
1361
- map = jsModuleConversionResult.map
1362
- }
1363
-
1364
- return { code, map }
1365
- }
1366
-
1367
- mutations.push((magicString) => {
1368
- magicString.overwrite(
1369
- importNode.source.start,
1370
- importNode.source.end,
1371
- `"${ressourceUrlAsJsModule}"`,
1372
- )
1373
- if (typePropertyNode) {
1374
- magicString.remove(typePropertyNode.start, typePropertyNode.end)
1375
- }
1376
- })
1377
- },
1378
- })
1379
- if (mutations.length > 0) {
1380
- const magicString = new MagicString(code)
1381
- mutations.forEach((mutation) => {
1382
- mutation(magicString)
1383
- })
1384
- code = magicString.toString()
1385
- map = magicString.generateMap({ hires: true })
1386
- }
1387
- return { code, map }
1388
- },
1389
-
1390
- // resolveImportMeta: () => {}
1391
- outputOptions: (outputOptions) => {
1392
- outputOptions.paths = (id) => {
1393
- const mapping = importPaths[id]
1394
- if (mapping) {
1395
- return mapping
1396
- }
1397
- if (format === "commonjs") {
1398
- if (id.startsWith("node:")) {
1399
- return id.slice("node:".length)
1400
- }
1401
- }
1402
- return id
1403
- }
1404
- // outputOptions.assetFileNames = () => {
1405
- // return `assets/[name]_[hash][extname]`
1406
- // }
1407
- outputOptions.entryFileNames = () => {
1408
- if (useImportMapToMaximizeCacheReuse) {
1409
- return `[name]${outputExtension}`
1410
- }
1411
- return entryPoints
1412
- }
1413
- outputOptions.chunkFileNames = (chunkInfo) => {
1414
- // maybe we should find ressource from ressource builder and return
1415
- // the buildRelativeUrlPattern?
1416
-
1417
- // const originalUrl = asOriginalUrl(chunkInfo.facadeModuleId)
1418
- // const basename = urlToBasename(originalUrl)
1419
- if (useImportMapToMaximizeCacheReuse) {
1420
- return `[name]${outputExtension}`
1421
- }
1422
- if (chunkInfo.isEntry) {
1423
- const originalUrl = asOriginalUrl(chunkInfo.facadeModuleId)
1424
- const entryPointPattern = entryPointUrls[originalUrl]
1425
- if (entryPointPattern) {
1426
- return entryPointPattern
1427
- }
1428
- }
1429
- return urlVersioning
1430
- ? `[name]_[hash]${outputExtension}`
1431
- : `[name]${outputExtension}`
1432
- }
1433
-
1434
- const getStringAfter = (string, substring) => {
1435
- const index = string.indexOf(substring)
1436
- if (index === -1) return ""
1437
- return string.slice(index + substring.length)
1438
- }
1439
-
1440
- // rollup does not expects to have http dependency in the mix: fix them
1441
- outputOptions.sourcemapPathTransform = (relativePath, sourcemapPath) => {
1442
- const sourcemapUrl = fileSystemPathToUrl(sourcemapPath)
1443
- // here relativePath contains a protocol
1444
- // because rollup don't work with url but with filesystem paths
1445
- // let fix it below
1446
- const sourceRollupUrlRaw = resolveUrl(relativePath, sourcemapUrl)
1447
- const afterOrigin =
1448
- getStringAfter(sourceRollupUrlRaw, "http:/jsenv.com") ||
1449
- getStringAfter(sourceRollupUrlRaw, "https:/jsenv.com")
1450
- const sourceRollupUrl = afterOrigin
1451
- ? `${compileServerOriginForRollup}${afterOrigin}`
1452
- : sourceRollupUrlRaw
1453
-
1454
- const sourceServerUrl = asServerUrl(sourceRollupUrl)
1455
- const sourceUrl =
1456
- urlFetcher.getUrlBeforeRedirection(sourceServerUrl) || sourceServerUrl
1457
- const sourceProjectUrl = asProjectUrl(sourceUrl)
1458
-
1459
- if (jsenvRemoteDirectory.isFileUrlForRemoteUrl(sourceProjectUrl)) {
1460
- const remoteUrl =
1461
- jsenvRemoteDirectory.remoteUrlFromFileUrl(sourceProjectUrl)
1462
- return remoteUrl
1463
- }
1464
- if (sourceProjectUrl) {
1465
- relativePath = urlToRelativeUrl(sourceProjectUrl, sourcemapUrl)
1466
- return relativePath
1467
- }
1468
- return sourceUrl
1469
- }
1470
- return outputOptions
1471
- },
1472
-
1473
- async renderChunk(code, chunk) {
1474
- const { facadeModuleId } = chunk
1475
- if (!facadeModuleId) {
1476
- // happens for inline module scripts for instance
1477
- return null
1478
- }
1479
- const url = asOriginalUrl(facadeModuleId)
1480
- const { searchParams } = new URL(url)
1481
- if (
1482
- format === "systemjs" &&
1483
- (searchParams.has("worker") || searchParams.has("service_worker"))
1484
- ) {
1485
- const magicString = new MagicString(code)
1486
- const systemjsCode = await readFile(
1487
- new URL("../runtime/s.js", import.meta.url),
1488
- )
1489
- magicString.prepend(systemjsCode)
1490
- code = magicString.toString()
1491
- const map = magicString.generateMap({ hires: true })
1492
- return {
1493
- code,
1494
- map,
1495
- }
1496
- }
1497
- return null
1498
- },
1499
-
1500
- async generateBundle(outputOptions, rollupResult) {
1501
- // it's important to do this to emit late asset
1502
- rollupEmitFile = (...args) => this.emitFile(...args)
1503
- rollupSetAssetSource = (...args) => this.setAssetSource(...args)
1504
- // To keep in mind: rollupResult object can be mutated by late asset emission
1505
- // however late chunk (js module) emission is not possible
1506
- // as rollup rightfully prevent late js emission
1507
- Object.keys(rollupResult).forEach((fileName) => {
1508
- const rollupFileInfo = rollupResult[fileName]
1509
- // there is 3 types of file: "placeholder", "asset", "chunk"
1510
- if (rollupFileInfo.type === "chunk") {
1511
- const { facadeModuleId } = rollupFileInfo
1512
- if (facadeModuleId === EMPTY_CHUNK_URL) {
1513
- delete rollupResult[fileName]
1514
- return
1515
- }
1516
- if (facadeModuleId) {
1517
- rollupFileInfo.url = asServerUrl(facadeModuleId)
1518
- } else {
1519
- const sourcePath =
1520
- rollupFileInfo.map.sources[rollupFileInfo.map.sources.length - 1]
1521
- const fileBuildUrl = resolveUrl(fileName, buildDirectoryUrl)
1522
- const originalProjectUrl = resolveUrl(sourcePath, fileBuildUrl)
1523
- rollupFileInfo.url = asCompiledServerUrl(originalProjectUrl, {
1524
- projectDirectoryUrl,
1525
- compileServerOrigin,
1526
- compileDirectoryRelativeUrl,
1527
- })
1528
- }
1529
-
1530
- if (
1531
- rollupFileInfo.url in inlineModuleScripts &&
1532
- format === "systemjs"
1533
- ) {
1534
- const code = rollupFileInfo.code
1535
- const systemRegisterIndex = code.indexOf("System.register([")
1536
- const magicString = new MagicString(code)
1537
- magicString.overwrite(
1538
- systemRegisterIndex,
1539
- systemRegisterIndex + "System.register([".length,
1540
- `System.register("${fileName}", [`,
1541
- )
1542
- rollupFileInfo.code = magicString.toString()
1543
- }
1544
-
1545
- const jsRessource = ressourceBuilder.findRessource((ressource) => {
1546
- return ressource.url === rollupFileInfo.url
1547
- })
1548
- if (
1549
- isReferencedByJs({
1550
- rollupFileInfo,
1551
- jsConcatenation,
1552
- jsRessource,
1553
- })
1554
- ) {
1555
- ressourcesReferencedByJs.push(fileName)
1556
- }
1557
- }
1558
- })
1559
-
1560
- // malheureusement rollup ne permet pas de savoir lorsqu'un chunk
1561
- // a fini d'etre résolu (parsing des imports statiques et dynamiques recursivement)
1562
- // donc lorsque le build se termine on va indiquer
1563
- // aux assets faisant référence a ces chunk js qu'ils sont terminés
1564
- // et donc les assets peuvent connaitre le nom du chunk
1565
- // et mettre a jour leur dépendance vers ce fichier js
1566
- const { jsRessources } = ressourceBuilder.rollupBuildEnd({
1567
- rollupResult,
1568
- useImportMapToMaximizeCacheReuse,
1569
- })
1570
- Object.keys(jsRessources).forEach((ressourceUrl) => {
1571
- const jsRessource = jsRessources[ressourceUrl]
1572
- if (jsRessource.isInline) {
1573
- buildInlineFileContents[jsRessource.buildRelativeUrl] =
1574
- jsRessource.bufferAfterBuild
1575
- // if (format === "systemjs") {
1576
- // ressourcesReferencedByJs.push(jsRessource.fileName)
1577
- // }
1578
- } else {
1579
- const originalProjectUrl = asOriginalUrl(ressourceUrl)
1580
- if (jsenvRemoteDirectory.isFileUrlForRemoteUrl(originalProjectUrl)) {
1581
- const remoteUrl =
1582
- jsenvRemoteDirectory.remoteUrlFromFileUrl(originalProjectUrl)
1583
- buildMappings[remoteUrl] = jsRessource.buildRelativeUrl
1584
- } else {
1585
- const originalProjectRelativeUrl = urlToRelativeUrl(
1586
- originalProjectUrl,
1587
- projectDirectoryUrl,
1588
- )
1589
- buildMappings[originalProjectRelativeUrl] =
1590
- jsRessource.buildRelativeUrl
1591
- }
1592
- }
1593
- ressourceMappings[jsRessource.buildRelativeUrlWithoutHash] =
1594
- jsRessource.buildRelativeUrl
1595
- })
1596
- // wait for asset build relative urls
1597
- // to ensure the importmap will contain remappings for them
1598
- // (not sure this is required anymore)
1599
- await Promise.all(
1600
- ressourcesReferencedByJs.map(async (ressourceFileName) => {
1601
- const ressource = ressourceBuilder.findRessource((ressource) => {
1602
- return ressource.buildRelativeUrlWithoutHash === ressourceFileName
1603
- })
1604
- if (ressource && !ressource.isJsModule) {
1605
- await ressource.getReadyPromise()
1606
- ressourceMappings[ressource.buildRelativeUrlWithoutHash] =
1607
- ressource.buildRelativeUrl
1608
- }
1609
- }),
1610
- )
1611
- // wait html files to be emitted
1612
- await ressourceBuilder.getAllEntryPointsEmittedPromise()
1613
- onBundleEnd()
1614
-
1615
- const jsModuleBuild = {}
1616
- const assetBuild = {}
1617
- Object.keys(rollupResult).forEach((fileName) => {
1618
- const rollupFileInfo = rollupResult[fileName]
1619
-
1620
- if (rollupFileInfo.type === "chunk") {
1621
- const jsRessource = ressourceBuilder.findRessource((ressource) => {
1622
- return ressource.url === rollupFileInfo.url
1623
- })
1624
- jsModuleBuild[jsRessource.buildRelativeUrl] = rollupFileInfo
1625
- return
1626
- }
1627
-
1628
- if (rollupFileInfo.type === "asset") {
1629
- const assetRessource = ressourceBuilder.findRessource(
1630
- (ressource) =>
1631
- // happens for import.meta.url pattern
1632
- ressource.buildRelativeUrlWithoutHash === fileName ||
1633
- // happens for sourcemap
1634
- ressource.relativeUrl === fileName,
1635
- )
1636
- // ignore potential useless assets which happens when:
1637
- // - sourcemap re-emitted
1638
- // - importmap re-emitted to have buildRelativeUrlMap
1639
- if (assetRessource.shouldBeIgnored) {
1640
- return
1641
- }
1642
- // Ignore file only referenced by import assertions
1643
- // - if file is referenced by import assertion and html or import meta url
1644
- // then source file is duplicated. If concatenation is disabled
1645
- // and import assertions are supported, the file is still converted to js module
1646
- const isReferencedOnlyByImportAssertions =
1647
- assetRessource.references.every((reference) => {
1648
- return reference.isImportAssertion
1649
- })
1650
- if (isReferencedOnlyByImportAssertions) {
1651
- return
1652
- }
1653
- const buildRelativeUrl = assetRessource.buildRelativeUrl
1654
- if (assetRessource.isInline) {
1655
- buildInlineFileContents[buildRelativeUrl] = rollupFileInfo.source
1656
- return
1657
- }
1658
- // in case sourcemap is mutated, we must not trust rollup but the asset builder source instead
1659
- rollupFileInfo.source = assetRessource.bufferAfterBuild
1660
- assetBuild[buildRelativeUrl] = rollupFileInfo
1661
- ressourceMappings[assetRessource.buildRelativeUrlWithoutHash] =
1662
- buildRelativeUrl
1663
- if (assetRessource.bufferBeforeBuild) {
1664
- const originalProjectUrl = asOriginalUrl(assetRessource.url)
1665
- const originalProjectRelativeUrl = urlToRelativeUrl(
1666
- originalProjectUrl,
1667
- projectDirectoryUrl,
1668
- )
1669
- buildMappings[originalProjectRelativeUrl] = buildRelativeUrl
1670
- }
1671
- return
1672
- }
1673
- })
1674
- rollupBuild = {
1675
- ...jsModuleBuild,
1676
- ...assetBuild,
1677
- }
1678
- rollupBuild = sortObjectByPathnames(rollupBuild)
1679
- // fill "buildFileContents", "buildInlineFilesContents"
1680
- // and update "buildMappings"
1681
- // in case some ressource where inlined by ressourceBuilder.rollupBuildEnd
1682
- Object.keys(rollupBuild).forEach((buildRelativeUrl) => {
1683
- const rollupFileInfo = rollupBuild[buildRelativeUrl]
1684
- const ressource = ressourceBuilder.findRessource((ressource) => {
1685
- if (ressource.buildRelativeUrl === buildRelativeUrl) {
1686
- return true
1687
- }
1688
- if (ressource.url === rollupFileInfo.url) {
1689
- return true
1690
- }
1691
- return false
1692
- })
1693
- if (ressource.isInline) {
1694
- if (ressource.isJsModule) {
1695
- delete jsModuleBuild[buildRelativeUrl]
1696
- } else {
1697
- delete assetBuild[buildRelativeUrl]
1698
- }
1699
- const originalProjectUrl = asOriginalUrl(ressource.url)
1700
- const originalRelativeUrl = urlToRelativeUrl(
1701
- originalProjectUrl,
1702
- projectDirectoryUrl,
1703
- )
1704
- delete buildMappings[originalRelativeUrl]
1705
- buildInlineFileContents[ressource.buildRelativeUrl] =
1706
- ressource.bufferAfterBuild
1707
- } else {
1708
- buildFileContents[ressource.buildRelativeUrl] =
1709
- ressource.bufferAfterBuild
1710
- }
1711
- })
1712
-
1713
- ressourceMappings = sortObjectByPathnames(ressourceMappings)
1714
- buildMappings = sortObjectByPathnames(buildMappings)
1715
- await visitServiceWorkers({
1716
- projectDirectoryUrl,
1717
- serviceWorkerFinalizer,
1718
- serviceWorkerUrls,
1719
- classicServiceWorkerUrls,
1720
- buildMappings,
1721
- ressourceMappings,
1722
- buildFileContents,
1723
- lineBreakNormalization,
1724
- })
1725
- const buildDuration = Date.now() - buildStartMs
1726
- buildStats = createBuildStats({
1727
- buildFileContents,
1728
- ressourceBuilder,
1729
- buildDuration,
1730
- })
1731
- logger.info(
1732
- formatBuildDoneInfo({
1733
- buildStats,
1734
- buildDirectoryRelativeUrl: urlToRelativeUrl(
1735
- buildDirectoryUrl,
1736
- projectDirectoryUrl,
1737
- ),
1738
- }),
1739
- )
1740
- },
1741
- })
1742
-
1743
- const fetchImportMapFromUrl = async (importMapUrl, importer) => {
1744
- const importMapResponse = await urlFetcher.fetchUrl(importMapUrl, {
1745
- urlTrace: importer,
1746
- contentTypeExpected: "application/importmap+json",
1747
- })
1748
- const importMap = await importMapResponse.json()
1749
- const importMapNormalized = normalizeImportMap(
1750
- importMap,
1751
- importMapResponse.url,
1752
- )
1753
- return importMapNormalized
1754
- }
1755
-
1756
- return {
1757
- rollupPlugins,
1758
- getLastErrorMessage: () => lastErrorMessage,
1759
- getResult: async () => {
1760
- return {
1761
- rollupBuild,
1762
- urlResponseBodyMap: urlLoader.getUrlResponseBodyMap(),
1763
- buildMappings,
1764
- ressourceMappings,
1765
- // Object mapping build relative urls without hash to build relative urls
1766
- buildManifest: createBuildManifest({
1767
- buildFileContents,
1768
- }),
1769
- buildImportMap: createImportMapForFilesUsedInJs(),
1770
- buildFileContents,
1771
- buildInlineFileContents,
1772
- buildStats,
1773
- }
1774
- },
1775
- asOriginalUrl,
1776
- asProjectUrl,
1777
- rollupGetModuleInfo,
1778
- }
1779
- }
1780
-
1781
- const createBuildManifest = ({ buildFileContents }) => {
1782
- const buildManifest = {}
1783
- Object.keys(buildFileContents).forEach((buildRelativeUrl) => {
1784
- const relativeUrlWithoutHash = asFileNameWithoutHash(buildRelativeUrl)
1785
- buildManifest[relativeUrlWithoutHash] = buildRelativeUrl
1786
- })
1787
- return buildManifest
1788
- }
1789
-
1790
- const asFileNameWithoutHash = (fileName) => {
1791
- return fileName.replace(/_[a-z0-9]{8,}(\..*?)?$/, (_, afterHash = "") => {
1792
- return afterHash
1793
- })
1794
- }
1795
-
1796
- const prepareEntryPoints = async (
1797
- entryPoints,
1798
- {
1799
- logger,
1800
- projectDirectoryUrl,
1801
- buildDirectoryUrl,
1802
- compileServerOrigin,
1803
- urlFetcher,
1804
- },
1805
- ) => {
1806
- const entryFileRelativeUrls = Object.keys(entryPoints)
1807
- const entryPointsPrepared = []
1808
- await entryFileRelativeUrls.reduce(async (previous, entryFileRelativeUrl) => {
1809
- await previous
1810
-
1811
- const entryProjectUrl = resolveUrl(
1812
- entryFileRelativeUrl,
1813
- projectDirectoryUrl,
1814
- )
1815
- const entryBuildUrl = resolveUrl(
1816
- entryPoints[entryFileRelativeUrl],
1817
- buildDirectoryUrl,
1818
- )
1819
- const entryProjectRelativeUrl = urlToRelativeUrl(
1820
- entryProjectUrl,
1821
- projectDirectoryUrl,
1822
- )
1823
- const entryBuildRelativeUrl = urlToRelativeUrl(
1824
- entryBuildUrl,
1825
- buildDirectoryUrl,
1826
- )
1827
- logger.debug(`${UNICODE.INFO} load entry point ${entryProjectRelativeUrl}`)
1828
- const entryServerUrl = resolveUrl(
1829
- entryProjectRelativeUrl,
1830
- compileServerOrigin,
1831
- )
1832
- const entryResponse = await urlFetcher.fetchUrl(entryServerUrl, {
1833
- urlTrace: `entryPoints`,
1834
- })
1835
- const entryContentType = entryResponse.headers["content-type"]
1836
- const isHtml = entryContentType === "text/html"
1837
- entryPointsPrepared.push({
1838
- entryContentType:
1839
- entryContentType === "text/javascript"
1840
- ? "application/javascript"
1841
- : entryContentType,
1842
- entryProjectRelativeUrl,
1843
- entryBuildRelativeUrl,
1844
- ...(isHtml
1845
- ? { entryBuffer: Buffer.from(await entryResponse.arrayBuffer()) }
1846
- : {}),
1847
- })
1848
- }, Promise.resolve())
1849
-
1850
- return entryPointsPrepared
1851
- }
1852
-
1853
- const normalizeRollupResolveReturnValue = (resolveReturnValue) => {
1854
- if (resolveReturnValue === null) {
1855
- return { id: null, external: true }
1856
- }
1857
- if (typeof resolveReturnValue === "string") {
1858
- return { id: resolveReturnValue, external: false }
1859
- }
1860
-
1861
- return resolveReturnValue
1862
- }
1863
-
1864
- const createUrlMetaGetter = ({
1865
- projectDirectoryUrl,
1866
- jsenvRemoteDirectory,
1867
- preservedUrls,
1868
- }) => {
1869
- const preservedFileUrls = {}
1870
- const remoteFileUrls = {}
1871
- Object.keys(preservedUrls).forEach((pattern) => {
1872
- if (jsenvRemoteDirectory.isRemoteUrl(pattern)) {
1873
- const fileUrlPattern = jsenvRemoteDirectory.fileUrlFromRemoteUrl(pattern)
1874
- preservedFileUrls[fileUrlPattern] = preservedUrls[pattern]
1875
- remoteFileUrls[fileUrlPattern] = true
1876
- }
1877
- })
1878
- const structuredMetaMap = normalizeStructuredMetaMap(
1879
- {
1880
- preserve: {
1881
- ...preservedUrls,
1882
- ...preservedFileUrls,
1883
- },
1884
- remote: remoteFileUrls,
1885
- },
1886
- projectDirectoryUrl,
1887
- )
1888
- return (url) => {
1889
- const meta = urlToMeta({
1890
- url,
1891
- structuredMetaMap,
1892
- })
1893
- return meta
1894
- }
1895
- }
1896
-
1897
- const acceptsJsonContentType = ({ node, format }) => {
1898
- if (!node) {
1899
- return false
1900
- }
1901
- if (format === "commonjs") {
1902
- return true
1903
- }
1904
- if (process.execArgv.includes("--experimental-json-modules")) {
1905
- return true
1906
- }
1907
- return false
1908
- }
1909
-
1910
- const isReferencedByJs = ({ rollupFileInfo, jsConcatenation, jsRessource }) => {
1911
- if (rollupFileInfo.isDynamicEntry) {
1912
- return true
1913
- }
1914
- if (!jsConcatenation && rollupFileInfo.isEntry) {
1915
- return true
1916
- }
1917
- if (
1918
- jsRessource &&
1919
- jsRessource.references.some((ref) => ref.isRessourceHint)
1920
- ) {
1921
- return true
1922
- }
1923
- return false
1924
- }
1925
-
1926
- const visitServiceWorkers = async ({
1927
- projectDirectoryUrl,
1928
- serviceWorkerUrls,
1929
- classicServiceWorkerUrls,
1930
- serviceWorkerFinalizer,
1931
- buildMappings,
1932
- buildFileContents,
1933
- lineBreakNormalization,
1934
- }) => {
1935
- const allServiceWorkerUrls = [
1936
- ...serviceWorkerUrls,
1937
- ...classicServiceWorkerUrls,
1938
- ]
1939
- await Promise.all(
1940
- allServiceWorkerUrls.map(async (serviceWorkerUrl) => {
1941
- const serviceWorkerRelativeUrl = urlToRelativeUrl(
1942
- serviceWorkerUrl,
1943
- projectDirectoryUrl,
1944
- )
1945
- const serviceWorkerBuildRelativeUrl =
1946
- buildMappings[serviceWorkerRelativeUrl]
1947
- if (!serviceWorkerBuildRelativeUrl) {
1948
- throw new Error(
1949
- `"${serviceWorkerRelativeUrl}" service worker file missing in the build`,
1950
- )
1951
- }
1952
- if (serviceWorkerFinalizer) {
1953
- let code = buildFileContents[serviceWorkerBuildRelativeUrl]
1954
- code = await serviceWorkerFinalizer(code, {
1955
- serviceWorkerBuildRelativeUrl,
1956
- buildFileContents,
1957
- lineBreakNormalization,
1958
- })
1959
- buildFileContents[serviceWorkerBuildRelativeUrl] = code
1960
- }
1961
- }),
1962
- )
1963
- }