@jsenv/core 27.0.0-alpha.3 → 27.0.0-alpha.30

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 (222) hide show
  1. package/main.js +4 -0
  2. package/package.json +17 -14
  3. package/readme.md +4 -12
  4. package/src/build/build.js +527 -307
  5. package/src/build/build_urls_generator.js +33 -21
  6. package/src/build/graph_utils.js +31 -0
  7. package/src/build/{inject_version_mappings.js → inject_global_version_mappings.js} +33 -15
  8. package/src/build/inject_service_worker_urls.js +79 -0
  9. package/src/build/resync_ressource_hints.js +68 -0
  10. package/src/build/start_build_server.js +201 -0
  11. package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +2 -2
  12. package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +3 -1
  13. package/src/dev/start_dev_server.js +58 -26
  14. package/src/execute/execute.js +30 -4
  15. package/src/execute/run.js +19 -56
  16. package/src/execute/runtimes/browsers/from_playwright.js +201 -147
  17. package/src/execute/runtimes/node/controllable_file.mjs +26 -10
  18. package/src/execute/runtimes/node/node_execution_performance.js +67 -0
  19. package/src/execute/runtimes/node/node_process.js +280 -39
  20. package/src/omega/{runtime_support/default_runtime_support.js → compat/default_runtime_compat.js} +3 -5
  21. package/src/omega/{runtime_support/features_compatibility.js → compat/features_compats.js} +66 -4
  22. package/src/omega/compat/runtime_compat.js +50 -0
  23. package/src/omega/errors.js +51 -58
  24. package/src/omega/fetched_content_compliance.js +24 -0
  25. package/src/omega/file_url_converter.js +8 -50
  26. package/src/omega/kitchen.js +409 -286
  27. package/src/omega/server/file_service.js +9 -11
  28. package/src/omega/url_graph/url_graph_load.js +14 -7
  29. package/src/omega/url_graph/url_graph_report.js +17 -15
  30. package/src/omega/url_graph.js +32 -10
  31. package/src/omega/web_workers.js +42 -0
  32. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/autoreload_preference.js +0 -0
  33. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/event_source_client.js +2 -2
  34. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/reload.js +0 -0
  35. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/url_helpers.js +0 -0
  36. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +41 -0
  37. package/src/{dev/plugins/autoreload/jsenv_plugin_autoreload.js → plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js} +27 -168
  38. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +25 -0
  39. package/src/plugins/autoreload/jsenv_plugin_hmr.js +35 -0
  40. package/src/plugins/bundling/css/bundle_css.js +21 -0
  41. package/src/plugins/bundling/js_classic_workers/bundle_js_classic_workers.js +13 -0
  42. package/src/{build/plugins/bundle_js_module/jsenv_plugin_bundle_js_module.js → plugins/bundling/js_module/bundle_js_module.js} +108 -78
  43. package/src/plugins/bundling/jsenv_plugin_bundling.js +51 -0
  44. package/src/{omega/core_plugins → plugins}/commonjs_globals/jsenv_plugin_commonjs_globals.js +48 -41
  45. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +66 -0
  46. package/src/{omega/core_plugins → plugins}/filesystem_magic/jsenv_plugin_filesystem_magic.js +7 -4
  47. package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_document.js +0 -0
  48. package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_notification.js +0 -0
  49. package/src/{omega/core_plugins → plugins}/html_supervisor/client/html_supervisor_installer.js +3 -2
  50. package/src/{omega/core_plugins → plugins}/html_supervisor/client/html_supervisor_setup.js +0 -0
  51. package/src/{omega/core_plugins → plugins}/html_supervisor/client/perf_browser.js +0 -0
  52. package/src/{omega/core_plugins → plugins}/html_supervisor/client/uneval_exception.js +0 -0
  53. package/src/{omega/core_plugins → plugins}/html_supervisor/jsenv_plugin_html_supervisor.js +38 -46
  54. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +12 -0
  55. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/babel_plugin_metadata_import_meta_hot.js +4 -5
  56. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/client/import_meta_hot.js +3 -1
  57. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/html_hot_dependencies.js +2 -2
  58. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +98 -0
  59. package/src/{omega/core_plugins → plugins}/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +26 -8
  60. package/src/plugins/import_meta_url/client/import_meta_url_browser.js +52 -0
  61. package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +9 -0
  62. package/src/{omega/core_plugins → plugins}/importmap/jsenv_plugin_importmap.js +37 -31
  63. package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +25 -0
  64. package/src/{omega/core_plugins → plugins}/inline/client/inline_content.js +0 -0
  65. package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_data_urls.js +18 -14
  66. package/src/{omega/core_plugins/inline/jsenv_plugin_js_and_css_inside_html.js → plugins/inline/jsenv_plugin_html_inline_content.js} +61 -40
  67. package/src/plugins/inline/jsenv_plugin_inline.js +36 -0
  68. package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_inline_query_param.js +6 -6
  69. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +263 -0
  70. package/src/plugins/leading_slash/jsenv_plugin_leading_slash.js +13 -0
  71. package/src/plugins/minification/css/minify_css.js +9 -0
  72. package/src/plugins/minification/html/minify_html.js +15 -0
  73. package/src/{build/plugins/minify_js/jsenv_plugin_minify_js.js → plugins/minification/js/minify_js.js} +6 -22
  74. package/src/plugins/minification/jsenv_plugin_minification.js +78 -0
  75. package/src/plugins/minification/json/minify_json.js +8 -0
  76. package/src/{omega/core_plugins → plugins}/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +15 -15
  77. package/src/{omega → plugins}/plugin_controller.js +18 -10
  78. package/src/plugins/plugins.js +73 -0
  79. package/src/plugins/transpilation/as_js_classic/client/s.js +808 -0
  80. package/src/plugins/transpilation/as_js_classic/client/s.js.md +1 -0
  81. package/src/plugins/transpilation/as_js_classic/helpers/babel_plugin_transform_import_meta_url.js +47 -0
  82. package/src/plugins/transpilation/as_js_classic/helpers/systemjs_old.js +43 -0
  83. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +183 -0
  84. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +256 -0
  85. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js +139 -0
  86. package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +0 -0
  87. package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/client/global_this.js +0 -0
  88. package/src/{omega/core_plugins/babel/babel_helper → plugins/transpilation/babel/helpers}/babel_plugin_babel_helpers_as_jsenv_imports.js +1 -2
  89. package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +161 -0
  90. package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugins_compatibility.js +0 -0
  91. package/src/{omega/core_plugins → plugins/transpilation}/babel/jsenv_plugin_babel.js +38 -22
  92. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +31 -6
  93. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/.eslintrc.cjs +0 -0
  94. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/new_stylesheet.js +0 -0
  95. package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +0 -0
  96. package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/client/regenerator_runtime.js +0 -0
  97. package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +18 -0
  98. package/src/plugins/transpilation/fetch_original_url_info.js +30 -0
  99. package/src/{omega/core_plugins → plugins/transpilation}/import_assertions/helpers/babel_plugin_metadata_import_assertions.js +0 -0
  100. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +225 -0
  101. package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +37 -0
  102. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +44 -0
  103. package/src/plugins/url_references/css/css_urls.js +49 -0
  104. package/src/plugins/url_references/html/html_urls.js +273 -0
  105. package/src/plugins/url_references/js/js_urls.js +163 -0
  106. package/src/plugins/url_references/jsenv_plugin_url_references.js +18 -0
  107. package/src/plugins/url_references/webmanifest/webmanifest_urls.js +17 -0
  108. package/src/{omega/core_plugins → plugins}/url_resolution/jsenv_plugin_url_resolution.js +12 -5
  109. package/src/{omega/core_plugins → plugins}/url_version/jsenv_plugin_url_version.js +8 -8
  110. package/src/test/execute_plan.js +25 -11
  111. package/src/test/execute_test_plan.js +14 -1
  112. package/src/test/logs_file_execution.js +8 -7
  113. package/src/build/plugins/minify_html/jsenv_plugin_minify_html.js +0 -30
  114. package/src/dev/plugins/autoreload/client/event_source_connection.js +0 -195
  115. package/src/dev/plugins/autoreload/sse_service.js +0 -149
  116. package/src/execute/runtimes/node/controlled_process.js +0 -316
  117. package/src/omega/core_plugins/babel/babel_helper/babel_helper_directory.js +0 -29
  118. package/src/omega/core_plugins/babel/babel_helper/client/.eslintrc.cjs +0 -24
  119. package/src/omega/core_plugins/babel/babel_helper/client/AsyncGenerator/AsyncGenerator.js +0 -81
  120. package/src/omega/core_plugins/babel/babel_helper/client/AwaitValue/AwaitValue.js +0 -3
  121. package/src/omega/core_plugins/babel/babel_helper/client/applyDecoratorDescriptor/applyDecoratorDescriptor.js +0 -33
  122. package/src/omega/core_plugins/babel/babel_helper/client/arrayLikeToArray/arrayLikeToArray.js +0 -7
  123. package/src/omega/core_plugins/babel/babel_helper/client/arrayWithHoles/arrayWithHoles.js +0 -4
  124. package/src/omega/core_plugins/babel/babel_helper/client/arrayWithoutHoles/arrayWithoutHoles.js +0 -6
  125. package/src/omega/core_plugins/babel/babel_helper/client/assertThisInitialized/assertThisInitialized.js +0 -7
  126. package/src/omega/core_plugins/babel/babel_helper/client/asyncGeneratorDelegate/asyncGeneratorDelegate.js +0 -40
  127. package/src/omega/core_plugins/babel/babel_helper/client/asyncIterator/asyncIterator.js +0 -65
  128. package/src/omega/core_plugins/babel/babel_helper/client/asyncToGenerator/asyncToGenerator.js +0 -34
  129. package/src/omega/core_plugins/babel/babel_helper/client/awaitAsyncGenerator/awaitAsyncGenerator.js +0 -5
  130. package/src/omega/core_plugins/babel/babel_helper/client/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +0 -20
  131. package/src/omega/core_plugins/babel/babel_helper/client/classApplyDescriptorGet/classApplyDescriptorGet.js +0 -6
  132. package/src/omega/core_plugins/babel/babel_helper/client/classApplyDescriptorSet/classApplyDescriptorSet.js +0 -13
  133. package/src/omega/core_plugins/babel/babel_helper/client/classCallCheck/classCallCheck.js +0 -5
  134. package/src/omega/core_plugins/babel/babel_helper/client/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +0 -5
  135. package/src/omega/core_plugins/babel/babel_helper/client/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +0 -6
  136. package/src/omega/core_plugins/babel/babel_helper/client/classExtractFieldDescriptor/classExtractFieldDescriptor.js +0 -7
  137. package/src/omega/core_plugins/babel/babel_helper/client/classNameTDZError/classNameTDZError.js +0 -4
  138. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +0 -7
  139. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldGet/classPrivateFieldGet.js +0 -7
  140. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +0 -6
  141. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +0 -5
  142. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldSet/classPrivateFieldSet.js +0 -8
  143. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateMethodGet/classPrivateMethodGet.js +0 -6
  144. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateMethodSet/classPrivateMethodSet.js +0 -3
  145. package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +0 -9
  146. package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +0 -15
  147. package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +0 -6
  148. package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +0 -3
  149. package/src/omega/core_plugins/babel/babel_helper/client/construct/construct.js +0 -16
  150. package/src/omega/core_plugins/babel/babel_helper/client/createClass/createClass.js +0 -15
  151. package/src/omega/core_plugins/babel/babel_helper/client/createForOfIteratorHelper/createForOfIteratorHelper.js +0 -60
  152. package/src/omega/core_plugins/babel/babel_helper/client/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +0 -23
  153. package/src/omega/core_plugins/babel/babel_helper/client/createRawReactElement/createRawReactElement.js +0 -50
  154. package/src/omega/core_plugins/babel/babel_helper/client/createSuper/createSuper.js +0 -22
  155. package/src/omega/core_plugins/babel/babel_helper/client/decorate/decorate.js +0 -403
  156. package/src/omega/core_plugins/babel/babel_helper/client/defaults/defaults.js +0 -11
  157. package/src/omega/core_plugins/babel/babel_helper/client/defineEnumerableProperties/defineEnumerableProperties.js +0 -23
  158. package/src/omega/core_plugins/babel/babel_helper/client/defineProperty/defineProperty.js +0 -18
  159. package/src/omega/core_plugins/babel/babel_helper/client/extends/extends.js +0 -14
  160. package/src/omega/core_plugins/babel/babel_helper/client/get/get.js +0 -19
  161. package/src/omega/core_plugins/babel/babel_helper/client/getPrototypeOf/getPrototypeOf.js +0 -4
  162. package/src/omega/core_plugins/babel/babel_helper/client/inherits/inherits.js +0 -19
  163. package/src/omega/core_plugins/babel/babel_helper/client/inheritsLoose/inheritsLoose.js +0 -7
  164. package/src/omega/core_plugins/babel/babel_helper/client/initializerDefineProperty/initializerDefineProperty.js +0 -10
  165. package/src/omega/core_plugins/babel/babel_helper/client/initializerWarningHelper/initializerWarningHelper.js +0 -6
  166. package/src/omega/core_plugins/babel/babel_helper/client/instanceof/instanceof.js +0 -6
  167. package/src/omega/core_plugins/babel/babel_helper/client/interopRequireDefault/interopRequireDefault.js +0 -3
  168. package/src/omega/core_plugins/babel/babel_helper/client/interopRequireWildcard/interopRequireWildcard.js +0 -37
  169. package/src/omega/core_plugins/babel/babel_helper/client/isNativeFunction/isNativeFunction.js +0 -4
  170. package/src/omega/core_plugins/babel/babel_helper/client/isNativeReflectConstruct/isNativeReflectConstruct.js +0 -21
  171. package/src/omega/core_plugins/babel/babel_helper/client/iterableToArray/iterableToArray.js +0 -7
  172. package/src/omega/core_plugins/babel/babel_helper/client/iterableToArrayLimit/iterableToArrayLimit.js +0 -36
  173. package/src/omega/core_plugins/babel/babel_helper/client/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +0 -10
  174. package/src/omega/core_plugins/babel/babel_helper/client/jsx/jsx.js +0 -50
  175. package/src/omega/core_plugins/babel/babel_helper/client/maybeArrayLike/maybeArrayLike.js +0 -10
  176. package/src/omega/core_plugins/babel/babel_helper/client/newArrowCheck/newArrowCheck.js +0 -5
  177. package/src/omega/core_plugins/babel/babel_helper/client/nonIterableRest/nonIterableRest.js +0 -5
  178. package/src/omega/core_plugins/babel/babel_helper/client/nonIterableSpread/nonIterableSpread.js +0 -5
  179. package/src/omega/core_plugins/babel/babel_helper/client/objectDestructuringEmpty/objectDestructuringEmpty.js +0 -3
  180. package/src/omega/core_plugins/babel/babel_helper/client/objectSpread/objectSpread.js +0 -23
  181. package/src/omega/core_plugins/babel/babel_helper/client/objectSpread2/objectSpread2.js +0 -41
  182. package/src/omega/core_plugins/babel/babel_helper/client/objectWithoutProperties/objectWithoutProperties.js +0 -19
  183. package/src/omega/core_plugins/babel/babel_helper/client/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +0 -13
  184. package/src/omega/core_plugins/babel/babel_helper/client/possibleConstructorReturn/possibleConstructorReturn.js +0 -10
  185. package/src/omega/core_plugins/babel/babel_helper/client/readOnlyError/readOnlyError.js +0 -4
  186. package/src/omega/core_plugins/babel/babel_helper/client/readme.md +0 -8
  187. package/src/omega/core_plugins/babel/babel_helper/client/set/set.js +0 -44
  188. package/src/omega/core_plugins/babel/babel_helper/client/setPrototypeOf/setPrototypeOf.js +0 -6
  189. package/src/omega/core_plugins/babel/babel_helper/client/skipFirstGeneratorNext/skipFirstGeneratorNext.js +0 -8
  190. package/src/omega/core_plugins/babel/babel_helper/client/slicedToArray/slicedToArray.js +0 -10
  191. package/src/omega/core_plugins/babel/babel_helper/client/slicedToArrayLoose/slicedToArrayLoose.js +0 -13
  192. package/src/omega/core_plugins/babel/babel_helper/client/superPropBase/superPropBase.js +0 -10
  193. package/src/omega/core_plugins/babel/babel_helper/client/taggedTemplateLiteral/taggedTemplateLiteral.js +0 -10
  194. package/src/omega/core_plugins/babel/babel_helper/client/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +0 -7
  195. package/src/omega/core_plugins/babel/babel_helper/client/tdz/tdz.js +0 -4
  196. package/src/omega/core_plugins/babel/babel_helper/client/temporalRef/temporalRef.js +0 -6
  197. package/src/omega/core_plugins/babel/babel_helper/client/temporalUndefined/temporalUndefined.js +0 -3
  198. package/src/omega/core_plugins/babel/babel_helper/client/toArray/toArray.js +0 -10
  199. package/src/omega/core_plugins/babel/babel_helper/client/toConsumableArray/toConsumableArray.js +0 -10
  200. package/src/omega/core_plugins/babel/babel_helper/client/toPrimitive/toPrimitive.js +0 -10
  201. package/src/omega/core_plugins/babel/babel_helper/client/toPropertyKey/toPropertyKey.js +0 -6
  202. package/src/omega/core_plugins/babel/babel_helper/client/typeof/typeof.js +0 -14
  203. package/src/omega/core_plugins/babel/babel_helper/client/unsupportedIterableToArray/unsupportedIterableToArray.js +0 -12
  204. package/src/omega/core_plugins/babel/babel_helper/client/wrapAsyncGenerator/wrapAsyncGenerator.js +0 -8
  205. package/src/omega/core_plugins/babel/babel_helper/client/wrapNativeSuper/wrapNativeSuper.js +0 -30
  206. package/src/omega/core_plugins/babel/babel_helper/client/wrapRegExp/wrapRegExp.js +0 -63
  207. package/src/omega/core_plugins/babel/babel_helper/client/writeOnlyError/writeOnlyError.js +0 -4
  208. package/src/omega/core_plugins/babel/helpers/babel_plugin_structure.js +0 -187
  209. package/src/omega/core_plugins/file_urls/jsenv_plugin_file_urls.js +0 -67
  210. package/src/omega/core_plugins/import_assertions/helpers/json_module.js +0 -12
  211. package/src/omega/core_plugins/import_assertions/helpers/text_module.js +0 -6
  212. package/src/omega/core_plugins/import_assertions/jsenv_plugin_import_assertions.js +0 -211
  213. package/src/omega/core_plugins/inline/jsenv_plugin_inline.js +0 -13
  214. package/src/omega/core_plugins/inline/jsenv_plugin_new_inline_content.js +0 -210
  215. package/src/omega/core_plugins/leading_slash/jsenv_plugin_leading_slash.js +0 -12
  216. package/src/omega/core_plugins.js +0 -39
  217. package/src/omega/runtime_support/runtime_support.js +0 -20
  218. package/src/omega/url_mentions/css_url_mentions.js +0 -63
  219. package/src/omega/url_mentions/html_url_mentions.js +0 -185
  220. package/src/omega/url_mentions/js_module_url_mentions.js +0 -91
  221. package/src/omega/url_mentions/parse_url_mentions.js +0 -37
  222. package/src/omega/url_mentions/worker_classic_url_mentions.js +0 -37
@@ -4,23 +4,22 @@ import { memoizeByUrl } from "@jsenv/utils/memoize/memoize_by_url.js"
4
4
 
5
5
  export const createBuilUrlsGenerator = ({ buildDirectoryUrl }) => {
6
6
  const cache = {}
7
- const generate = memoizeByUrl((url, urlInfo, parentUrlInfo) => {
8
- const directoryPath = determineDirectoryPath(urlInfo, parentUrlInfo)
9
- let name = urlToFilename(url)
10
- const { searchParams } = new URL(url)
11
- if (
12
- searchParams.has("css_module") ||
13
- searchParams.has("json_module") ||
14
- searchParams.has("text_module")
15
- ) {
16
- name = `${name}.js`
17
- }
7
+ const generate = memoizeByUrl((url, { urlInfo, parentUrlInfo }) => {
8
+ const directoryPath = determineDirectoryPath({
9
+ urlInfo,
10
+ parentUrlInfo,
11
+ })
18
12
  let names = cache[directoryPath]
19
13
  if (!names) {
20
14
  names = []
21
15
  cache[directoryPath] = names
22
16
  }
23
-
17
+ const urlObject = new URL(url)
18
+ let { search, hash } = urlObject
19
+ let name = urlInfo
20
+ ? urlInfo.filename || urlToFilename(url)
21
+ : urlToFilename(url)
22
+ const [basename, extension] = splitFileExtension(name)
24
23
  let nameCandidate = name
25
24
  let integer = 1
26
25
  // eslint-disable-next-line no-constant-condition
@@ -30,9 +29,9 @@ export const createBuilUrlsGenerator = ({ buildDirectoryUrl }) => {
30
29
  break
31
30
  }
32
31
  integer++
33
- nameCandidate = `${name}${integer}`
32
+ nameCandidate = `${basename}${integer}${extension}`
34
33
  }
35
- return `${buildDirectoryUrl}${directoryPath}${nameCandidate}`
34
+ return `${buildDirectoryUrl}${directoryPath}${nameCandidate}${search}${hash}`
36
35
  })
37
36
 
38
37
  return {
@@ -40,12 +39,25 @@ export const createBuilUrlsGenerator = ({ buildDirectoryUrl }) => {
40
39
  }
41
40
  }
42
41
 
43
- const determineDirectoryPath = (urlInfo, parentUrlInfo) => {
42
+ const splitFileExtension = (filename) => {
43
+ const dotLastIndex = filename.lastIndexOf(".")
44
+ if (dotLastIndex === -1) {
45
+ return [filename, ""]
46
+ }
47
+ return [filename.slice(0, dotLastIndex), filename.slice(dotLastIndex)]
48
+ }
49
+
50
+ const determineDirectoryPath = ({ urlInfo, parentUrlInfo }) => {
44
51
  if (urlInfo.isInline) {
45
- const parentDirectoryPath = determineDirectoryPath(parentUrlInfo)
52
+ const parentDirectoryPath = determineDirectoryPath({
53
+ urlInfo: parentUrlInfo,
54
+ })
46
55
  return parentDirectoryPath
47
56
  }
48
- if (urlInfo.data.isEntryPoint) {
57
+ if (urlInfo.data.isEntryPoint || urlInfo.data.isWebWorkerEntryPoint) {
58
+ return ""
59
+ }
60
+ if (urlInfo.type === "importmap") {
49
61
  return ""
50
62
  }
51
63
  if (urlInfo.type === "html") {
@@ -55,10 +67,10 @@ const determineDirectoryPath = (urlInfo, parentUrlInfo) => {
55
67
  return "css/"
56
68
  }
57
69
  if (urlInfo.type === "js_module" || urlInfo.type === "js_classic") {
58
- if (urlInfo.subtype === "service_worker") {
59
- return ""
60
- }
61
70
  return "js/"
62
71
  }
63
- return "assets/"
72
+ if (urlInfo.type === "json") {
73
+ return "json/"
74
+ }
75
+ return "other/"
64
76
  }
@@ -0,0 +1,31 @@
1
+ export const GRAPH = {
2
+ map: (graph, callback) => {
3
+ return Object.keys(graph.urlInfos).map((url) => {
4
+ return callback(graph.urlInfos[url])
5
+ })
6
+ },
7
+
8
+ forEach: (graph, callback) => {
9
+ Object.keys(graph.urlInfos).forEach((url) => {
10
+ callback(graph.urlInfos[url], url)
11
+ })
12
+ },
13
+
14
+ filter: (graph, callback) => {
15
+ const urlInfos = []
16
+ Object.keys(graph.urlInfos).forEach((url) => {
17
+ const urlInfo = graph.urlInfos[url]
18
+ if (callback(urlInfo)) {
19
+ urlInfos.push(urlInfo)
20
+ }
21
+ })
22
+ return urlInfos
23
+ },
24
+
25
+ find: (graph, callback) => {
26
+ const urlFound = Object.keys(graph.urlInfos).find((url) => {
27
+ return callback(graph.urlInfos[url])
28
+ })
29
+ return graph.urlInfos[urlFound]
30
+ },
31
+ }
@@ -8,10 +8,27 @@ import {
8
8
  } from "@jsenv/utils/html_ast/html_ast.js"
9
9
  import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
10
10
 
11
- export const injectVersionMappings = async (
12
- urlInfo,
13
- { kitchen, versionMappings },
14
- ) => {
11
+ import { GRAPH } from "./graph_utils.js"
12
+
13
+ export const injectGlobalVersionMapping = async ({
14
+ finalGraphKitchen,
15
+ finalGraph,
16
+ versionMappings,
17
+ }) => {
18
+ await Promise.all(
19
+ GRAPH.map(finalGraph, async (urlInfo) => {
20
+ if (urlInfo.data.isEntryPoint || urlInfo.data.isWebWorkerEntryPoint) {
21
+ await injectVersionMappings({
22
+ urlInfo,
23
+ kitchen: finalGraphKitchen,
24
+ versionMappings,
25
+ })
26
+ }
27
+ }),
28
+ )
29
+ }
30
+
31
+ const injectVersionMappings = async ({ urlInfo, kitchen, versionMappings }) => {
15
32
  const injector = injectors[urlInfo.type]
16
33
  if (injector) {
17
34
  const { content, sourcemap } = injector(urlInfo, { versionMappings })
@@ -22,6 +39,12 @@ export const injectVersionMappings = async (
22
39
  }
23
40
  }
24
41
 
42
+ const jsInjector = (urlInfo, { versionMappings }) => {
43
+ const magicSource = createMagicSource(urlInfo.content)
44
+ magicSource.prepend(generateClientCodeForVersionMappings(versionMappings))
45
+ return magicSource.toContentAndSourcemap()
46
+ }
47
+
25
48
  const injectors = {
26
49
  html: (urlInfo, { versionMappings }) => {
27
50
  // ideally we would inject an importmap but browser support is too low
@@ -39,24 +62,19 @@ const injectors = {
39
62
  }),
40
63
  )
41
64
  return {
42
- content: stringifyHtmlAst(htmlAst, {
43
- removeOriginalPositionAttributes: true,
44
- }),
65
+ content: stringifyHtmlAst(htmlAst),
45
66
  }
46
67
  },
47
- js_module: (urlInfo, { versionMappings }) => {
48
- const magicSource = createMagicSource(urlInfo.content)
49
- magicSource.prepend(generateClientCodeForVersionMappings(versionMappings))
50
- return magicSource.toContentAndSourcemap()
51
- },
68
+ js_classic: jsInjector,
69
+ js_module: jsInjector,
52
70
  }
53
71
 
54
72
  const generateClientCodeForVersionMappings = (versionMappings) => {
55
73
  return `
56
- var __versionMappings__ = ${JSON.stringify(versionMappings, null, " ")}
57
- var __envGlobal__ = typeof self === 'undefined' ? global : self
74
+ var __versionMappings__ = ${JSON.stringify(versionMappings, null, " ")};
75
+ var __envGlobal__ = typeof self === 'undefined' ? global : self;
58
76
  __envGlobal__.__v__ = function (specifier) {
59
77
  return __versionMappings__[specifier] || specifier
60
- }
78
+ };
61
79
  `
62
80
  }
@@ -0,0 +1,79 @@
1
+ import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
2
+ import { createVersionGenerator } from "@jsenv/utils/versioning/version_generator.js"
3
+
4
+ import { GRAPH } from "./graph_utils.js"
5
+
6
+ export const injectServiceWorkerUrls = async ({
7
+ finalGraph,
8
+ finalGraphKitchen,
9
+ lineBreakNormalization,
10
+ }) => {
11
+ const serviceWorkerEntryUrlInfos = GRAPH.filter(
12
+ finalGraph,
13
+ (finalUrlInfo) => {
14
+ return (
15
+ finalUrlInfo.subtype === "service_worker" &&
16
+ finalUrlInfo.data.isWebWorkerEntryPoint
17
+ )
18
+ },
19
+ )
20
+ if (serviceWorkerEntryUrlInfos.length === 0) {
21
+ return
22
+ }
23
+ const serviceWorkerUrls = {}
24
+ GRAPH.forEach(finalGraph, (urlInfo) => {
25
+ if (urlInfo.isInline || urlInfo.external) {
26
+ return
27
+ }
28
+ if (!urlInfo.url.startsWith("file:")) {
29
+ return
30
+ }
31
+ if (urlInfo.data.buildUrlIsVersioned) {
32
+ serviceWorkerUrls[urlInfo.data.buildUrlSpecifier] = {
33
+ versioned: true,
34
+ }
35
+ return
36
+ }
37
+ if (!urlInfo.data.version) {
38
+ // when url is not versioned we compute a "version" for that url anyway
39
+ // so that service worker source still changes and navigator
40
+ // detect there is a change
41
+ const versionGenerator = createVersionGenerator()
42
+ versionGenerator.augmentWithContent({
43
+ content: urlInfo.content,
44
+ contentType: urlInfo.contentType,
45
+ lineBreakNormalization,
46
+ })
47
+ const version = versionGenerator.generate()
48
+ urlInfo.data.version = version
49
+ }
50
+ serviceWorkerUrls[urlInfo.data.buildUrlSpecifier] = {
51
+ versioned: false,
52
+ version: urlInfo.data.version,
53
+ }
54
+ })
55
+ await Promise.all(
56
+ serviceWorkerEntryUrlInfos.map(async (serviceWorkerEntryUrlInfo) => {
57
+ const magicSource = createMagicSource(serviceWorkerEntryUrlInfo.content)
58
+ const urlsWithoutSelf = {
59
+ ...serviceWorkerUrls,
60
+ }
61
+ delete urlsWithoutSelf[serviceWorkerEntryUrlInfo.data.buildUrlSpecifier]
62
+ magicSource.prepend(generateClientCode(urlsWithoutSelf))
63
+ const { content, sourcemap } = magicSource.toContentAndSourcemap()
64
+ await finalGraphKitchen.urlInfoTransformer.applyFinalTransformations(
65
+ serviceWorkerEntryUrlInfo,
66
+ {
67
+ content,
68
+ sourcemap,
69
+ },
70
+ )
71
+ }),
72
+ )
73
+ }
74
+
75
+ const generateClientCode = (serviceWorkerUrls) => {
76
+ return `
77
+ self.serviceWorkerUrls = ${JSON.stringify(serviceWorkerUrls, null, " ")};
78
+ `
79
+ }
@@ -0,0 +1,68 @@
1
+ /*
2
+ * Update <link rel="preload"> and friends after build (once we know everything)
3
+ *
4
+ * - Used to remove ressource hint targeting an url that is no longer used:
5
+ * - Happens because of import assertions transpilation (file is inlined into JS)
6
+ */
7
+
8
+ import {
9
+ parseHtmlString,
10
+ visitHtmlAst,
11
+ stringifyHtmlAst,
12
+ getHtmlNodeAttributeByName,
13
+ removeHtmlNode,
14
+ } from "@jsenv/utils/html_ast/html_ast.js"
15
+
16
+ import { GRAPH } from "./graph_utils.js"
17
+
18
+ export const resyncRessourceHints = async ({
19
+ finalGraphKitchen,
20
+ finalGraph,
21
+ buildUrls,
22
+ }) => {
23
+ const ressourceHintActions = []
24
+ GRAPH.forEach(finalGraph, (urlInfo) => {
25
+ if (urlInfo.type !== "html") {
26
+ return
27
+ }
28
+ ressourceHintActions.push(async () => {
29
+ const htmlAst = parseHtmlString(urlInfo.content, {
30
+ storeOriginalPositions: false,
31
+ })
32
+ const visitLinkWithHref = (linkNode, hrefAttribute) => {
33
+ const href = hrefAttribute.value
34
+ if (!href || href.startsWith("data:")) {
35
+ return
36
+ }
37
+ const buildUrl = buildUrls[href]
38
+ const urlInfo = finalGraph.getUrlInfo(buildUrl)
39
+ if (!urlInfo) {
40
+ return
41
+ }
42
+ if (urlInfo.dependents.size === 0) {
43
+ removeHtmlNode(linkNode)
44
+ return
45
+ }
46
+ }
47
+ visitHtmlAst(htmlAst, (node) => {
48
+ if (node.nodeName !== "link") {
49
+ return
50
+ }
51
+ const hrefAttribute = getHtmlNodeAttributeByName(node, "href")
52
+ if (!hrefAttribute) {
53
+ return
54
+ }
55
+ visitLinkWithHref(node, hrefAttribute)
56
+ })
57
+ await finalGraphKitchen.urlInfoTransformer.applyFinalTransformations(
58
+ urlInfo,
59
+ {
60
+ content: stringifyHtmlAst(htmlAst),
61
+ },
62
+ )
63
+ })
64
+ })
65
+ await Promise.all(
66
+ ressourceHintActions.map((ressourceHintAction) => ressourceHintAction()),
67
+ )
68
+ }
@@ -0,0 +1,201 @@
1
+ /*
2
+ * startBuildServer is mean to interact with the build files;
3
+ * files that will be deployed to production server(s).
4
+ * We want to be as close as possible from the production in order to:
5
+ * - run lighthouse
6
+ * - run an automated test tool such as cypress, playwright
7
+ * - see exactly how build file behaves (debug, measure perf, etc)
8
+ * For these reasons "startBuildServer" must be as close as possible from a static file server.
9
+ * It is not meant to provide a nice developper experience: this is the role "startDevServer".
10
+ *
11
+ * Conclusion:
12
+ * "startBuildServer" must be as close as possible from a static file server because
13
+ * we want to be in the user shoes and we should not alter build files.
14
+ */
15
+
16
+ import {
17
+ jsenvAccessControlAllowedHeaders,
18
+ startServer,
19
+ pluginServerTiming,
20
+ pluginRequestWaitingCheck,
21
+ pluginCORS,
22
+ fetchFileSystem,
23
+ } from "@jsenv/server"
24
+ import { createLogger } from "@jsenv/logger"
25
+ import { Abort } from "@jsenv/abort"
26
+
27
+ import { initProcessAutorestart } from "@jsenv/utils/file_watcher/process_auto_restart.js"
28
+ import { createTaskLog } from "@jsenv/utils/logs/task_log.js"
29
+ import { watchFiles } from "@jsenv/utils/file_watcher/file_watcher.js"
30
+ import { executeCommand } from "@jsenv/utils/command/command.js"
31
+
32
+ export const startBuildServer = async ({
33
+ signal = new AbortController().signal,
34
+ handleSIGINT = true,
35
+ logLevel,
36
+ buildCommandLogLevel = "warn",
37
+ protocol = "http",
38
+ http2,
39
+ certificate,
40
+ privateKey,
41
+ listenAnyIp,
42
+ ip,
43
+ port = 9779,
44
+
45
+ rootDirectoryUrl,
46
+ buildDirectoryUrl,
47
+ buildCommand,
48
+ mainBuildFile,
49
+ watchedFilePatterns,
50
+ cooldownBetweenFileEvents,
51
+ autorestart,
52
+ }) => {
53
+ const autorestartProcess = await initProcessAutorestart({
54
+ signal,
55
+ handleSIGINT,
56
+ ...(autorestart
57
+ ? {
58
+ enabled: true,
59
+ logLevel: autorestart.logLevel,
60
+ urlToRestart: autorestart.url,
61
+ urlsToWatch: [
62
+ ...(autorestart.urlsToWatch || []),
63
+ new URL("package.json", rootDirectoryUrl),
64
+ new URL("jsenv.config.mjs", rootDirectoryUrl),
65
+ ],
66
+ }
67
+ : {
68
+ enabled: false,
69
+ }),
70
+ })
71
+ if (autorestartProcess.isPrimary) {
72
+ return {
73
+ origin: `${protocol}://127.0.0.1:${port}`,
74
+ stop: () => {
75
+ autorestartProcess.stop()
76
+ },
77
+ }
78
+ }
79
+ signal = autorestartProcess.signal
80
+ const logger = createLogger({ logLevel })
81
+
82
+ let buildPromise
83
+ let buildAbortController
84
+ const runBuild = async () => {
85
+ buildAbortController = new AbortController()
86
+ const buildOperation = Abort.startOperation()
87
+ buildOperation.addAbortSignal(signal)
88
+ buildOperation.addAbortSignal(buildAbortController.signal)
89
+ const buildTask = createTaskLog(logger, `execute build command`)
90
+ buildPromise = executeCommand(buildCommand, {
91
+ cwd: rootDirectoryUrl,
92
+ logLevel: buildCommandLogLevel,
93
+ signal: buildOperation.signal,
94
+ })
95
+ try {
96
+ await buildPromise
97
+ buildTask.done()
98
+ } catch (e) {
99
+ if (e.code === "ABORT_ERR") {
100
+ buildTask.fail(`execute build command aborted`)
101
+ } else {
102
+ buildTask.fail()
103
+ throw e
104
+ }
105
+ }
106
+ }
107
+
108
+ const startServerTask = createTaskLog(logger, "start build server")
109
+ const server = await startServer({
110
+ signal,
111
+ stopOnExit: false,
112
+ stopOnSIGINT: false,
113
+ stopOnInternalError: false,
114
+ keepProcessAlive: true,
115
+ logLevel,
116
+ startLog: false,
117
+
118
+ protocol,
119
+ http2,
120
+ certificate,
121
+ privateKey,
122
+ listenAnyIp,
123
+ ip,
124
+ port,
125
+ plugins: {
126
+ ...pluginCORS({
127
+ accessControlAllowRequestOrigin: true,
128
+ accessControlAllowRequestMethod: true,
129
+ accessControlAllowRequestHeaders: true,
130
+ accessControlAllowedRequestHeaders: [
131
+ ...jsenvAccessControlAllowedHeaders,
132
+ "x-jsenv-execution-id",
133
+ ],
134
+ accessControlAllowCredentials: true,
135
+ }),
136
+ ...pluginServerTiming(),
137
+ ...pluginRequestWaitingCheck({
138
+ requestWaitingMs: 60 * 1000,
139
+ }),
140
+ },
141
+ sendErrorDetails: true,
142
+ requestToResponse: async (request) => {
143
+ await buildPromise
144
+ const urlIsVersioned = new URL(
145
+ request.ressource,
146
+ request.origin,
147
+ ).searchParams.has("v")
148
+ if (mainBuildFile && request.ressource === "/") {
149
+ request = {
150
+ ...request,
151
+ ressource: `/${mainBuildFile}`,
152
+ }
153
+ }
154
+ return fetchFileSystem(
155
+ new URL(request.ressource.slice(1), buildDirectoryUrl),
156
+ {
157
+ headers: request.headers,
158
+ cacheControl: urlIsVersioned
159
+ ? `private,max-age=${SECONDS_IN_30_DAYS},immutable`
160
+ : "private,max-age=0,must-revalidate",
161
+ etagEnabled: true,
162
+ compressionEnabled: !request.pathname.endsWith(".mp4"),
163
+ rootDirectoryUrl: buildDirectoryUrl,
164
+ canReadDirectory: true,
165
+ },
166
+ )
167
+ },
168
+ })
169
+ startServerTask.done()
170
+ logger.info(``)
171
+ Object.keys(server.origins).forEach((key) => {
172
+ logger.info(`- ${server.origins[key]}`)
173
+ })
174
+ logger.info(``)
175
+
176
+ const unregisterDirectoryLifecyle = watchFiles({
177
+ rootDirectoryUrl,
178
+ watchedFilePatterns,
179
+ cooldownBetweenFileEvents,
180
+ fileChangeCallback: ({ url, event }) => {
181
+ buildAbortController.abort()
182
+ // setTimeout is to ensure the abortController.abort() above
183
+ // is properly taken into account so that logs about abort comes first
184
+ // then logs about re-running the build happens
185
+ setTimeout(() => {
186
+ logger.info(`${url.slice(rootDirectoryUrl.length)} ${event} -> rebuild`)
187
+ runBuild()
188
+ })
189
+ },
190
+ })
191
+ signal.addEventListener("abort", () => {
192
+ unregisterDirectoryLifecyle()
193
+ })
194
+ runBuild()
195
+ return {
196
+ origin: server.origin,
197
+ stop: () => server.stop(),
198
+ }
199
+ }
200
+
201
+ const SECONDS_IN_30_DAYS = 60 * 60 * 24 * 30
@@ -1,8 +1,8 @@
1
1
  import { readFileSync } from "node:fs"
2
- import { urlToContentType } from "@jsenv/server"
3
2
  import { collectFiles, normalizeStructuredMetaMap } from "@jsenv/filesystem"
4
3
 
5
4
  import { DataUrl } from "@jsenv/utils/urls/data_url.js"
5
+ import { CONTENT_TYPE } from "@jsenv/utils/content_type/content_type.js"
6
6
 
7
7
  export const jsenvPluginExplorer = ({ groups }) => {
8
8
  const htmlClientFileUrl = new URL("./client/explorer.html", import.meta.url)
@@ -43,7 +43,7 @@ export const jsenvPluginExplorer = ({ groups }) => {
43
43
  html = html.replace(
44
44
  "FAVICON_HREF",
45
45
  DataUrl.stringify({
46
- contentType: urlToContentType(faviconClientFileUrl),
46
+ contentType: CONTENT_TYPE.fromUrlExtension(faviconClientFileUrl),
47
47
  base64Flag: true,
48
48
  data: readFileSync(new URL(faviconClientFileUrl)).toString("base64"),
49
49
  }),
@@ -20,7 +20,7 @@ export const jsenvPluginToolbar = ({ logs = false } = {}) => {
20
20
  appliesDuring: {
21
21
  dev: true,
22
22
  },
23
- transform: {
23
+ transformUrlContent: {
24
24
  html: ({ url, content }, { referenceUtils }) => {
25
25
  if (url === toolbarHtmlClientFileUrl) {
26
26
  return null
@@ -28,10 +28,12 @@ export const jsenvPluginToolbar = ({ logs = false } = {}) => {
28
28
  const htmlAst = parseHtmlString(content)
29
29
  const [toolbarInjectorReference] = referenceUtils.inject({
30
30
  type: "js_import_export",
31
+ expectedType: "js_module",
31
32
  specifier: toolbarInjectorClientFileUrl,
32
33
  })
33
34
  const [toolbarClientFileReference] = referenceUtils.inject({
34
35
  type: "iframe_src",
36
+ expectedType: "html",
35
37
  specifier: toolbarHtmlClientFileUrl,
36
38
  })
37
39
  injectScriptAsEarlyAsPossible(