@jsenv/core 27.0.0-alpha.2 → 27.0.0-alpha.22

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 (219) hide show
  1. package/main.js +4 -0
  2. package/package.json +20 -15
  3. package/readme.md +4 -12
  4. package/src/build/build.js +512 -304
  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 +83 -0
  10. package/src/build/start_build_server.js +196 -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 +56 -26
  14. package/src/execute/execute.js +23 -4
  15. package/src/execute/run.js +17 -54
  16. package/src/execute/runtimes/browsers/from_playwright.js +167 -146
  17. package/src/execute/runtimes/node/node_process.js +281 -37
  18. package/src/omega/{runtime_support/default_runtime_support.js → compat/default_runtime_compat.js} +3 -5
  19. package/src/omega/{runtime_support/features_compatibility.js → compat/features_compats.js} +66 -4
  20. package/src/omega/compat/runtime_compat.js +50 -0
  21. package/src/omega/errors.js +51 -58
  22. package/src/omega/fetched_content_compliance.js +24 -0
  23. package/src/omega/file_url_converter.js +8 -50
  24. package/src/omega/kitchen.js +409 -286
  25. package/src/omega/server/file_service.js +9 -11
  26. package/src/omega/url_graph/url_graph_load.js +14 -7
  27. package/src/omega/url_graph/url_graph_report.js +7 -5
  28. package/src/omega/url_graph.js +22 -9
  29. package/src/omega/web_workers.js +42 -0
  30. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/autoreload_preference.js +0 -0
  31. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/event_source_client.js +2 -2
  32. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/reload.js +0 -0
  33. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/url_helpers.js +0 -0
  34. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +41 -0
  35. package/src/{dev/plugins/autoreload/jsenv_plugin_autoreload.js → plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js} +27 -168
  36. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +25 -0
  37. package/src/plugins/autoreload/jsenv_plugin_hmr.js +35 -0
  38. package/src/plugins/bundling/css/bundle_css.js +21 -0
  39. package/src/plugins/bundling/js_classic_workers/bundle_js_classic_workers.js +13 -0
  40. package/src/{build/plugins/bundle_js_module/jsenv_plugin_bundle_js_module.js → plugins/bundling/js_module/bundle_js_module.js} +105 -78
  41. package/src/plugins/bundling/jsenv_plugin_bundling.js +51 -0
  42. package/src/{omega/core_plugins → plugins}/commonjs_globals/jsenv_plugin_commonjs_globals.js +48 -41
  43. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +66 -0
  44. package/src/{omega/core_plugins → plugins}/filesystem_magic/jsenv_plugin_filesystem_magic.js +7 -4
  45. package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_document.js +0 -0
  46. package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_notification.js +0 -0
  47. package/src/{omega/core_plugins → plugins}/html_supervisor/client/html_supervisor_installer.js +3 -2
  48. package/src/{omega/core_plugins → plugins}/html_supervisor/client/html_supervisor_setup.js +0 -0
  49. package/src/{omega/core_plugins → plugins}/html_supervisor/client/perf_browser.js +0 -0
  50. package/src/{omega/core_plugins → plugins}/html_supervisor/client/uneval_exception.js +0 -0
  51. package/src/{omega/core_plugins → plugins}/html_supervisor/jsenv_plugin_html_supervisor.js +38 -46
  52. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +12 -0
  53. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/babel_plugin_metadata_import_meta_hot.js +4 -5
  54. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/client/import_meta_hot.js +3 -1
  55. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/html_hot_dependencies.js +2 -2
  56. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +98 -0
  57. package/src/{omega/core_plugins → plugins}/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +41 -13
  58. package/src/plugins/import_meta_url/client/import_meta_url_browser.js +52 -0
  59. package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +9 -0
  60. package/src/{omega/core_plugins → plugins}/importmap/jsenv_plugin_importmap.js +37 -31
  61. package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +25 -0
  62. package/src/{omega/core_plugins → plugins}/inline/client/inline_content.js +0 -0
  63. package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_data_urls.js +18 -14
  64. package/src/{omega/core_plugins/inline/jsenv_plugin_js_and_css_inside_html.js → plugins/inline/jsenv_plugin_html_inline_content.js} +61 -40
  65. package/src/plugins/inline/jsenv_plugin_inline.js +36 -0
  66. package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_inline_query_param.js +6 -6
  67. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +263 -0
  68. package/src/plugins/leading_slash/jsenv_plugin_leading_slash.js +13 -0
  69. package/src/plugins/minification/css/minify_css.js +9 -0
  70. package/src/plugins/minification/html/minify_html.js +15 -0
  71. package/src/{build/plugins/minify_js/jsenv_plugin_minify_js.js → plugins/minification/js/minify_js.js} +6 -22
  72. package/src/plugins/minification/jsenv_plugin_minification.js +78 -0
  73. package/src/plugins/minification/json/minify_json.js +8 -0
  74. package/src/{omega/core_plugins → plugins}/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +15 -15
  75. package/src/{omega → plugins}/plugin_controller.js +18 -10
  76. package/src/plugins/plugins.js +73 -0
  77. package/src/plugins/transpilation/as_js_classic/client/s.js +808 -0
  78. package/src/plugins/transpilation/as_js_classic/client/s.js.md +1 -0
  79. package/src/plugins/transpilation/as_js_classic/helpers/babel_plugin_transform_import_meta_url.js +47 -0
  80. package/src/plugins/transpilation/as_js_classic/helpers/systemjs_old.js +43 -0
  81. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +191 -0
  82. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +156 -0
  83. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_top_level_await.js +37 -0
  84. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js +133 -0
  85. package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +0 -0
  86. package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/client/global_this.js +0 -0
  87. package/src/{omega/core_plugins/babel/babel_helper → plugins/transpilation/babel/helpers}/babel_plugin_babel_helpers_as_jsenv_imports.js +1 -2
  88. package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +158 -0
  89. package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugins_compatibility.js +0 -0
  90. package/src/{omega/core_plugins → plugins/transpilation}/babel/jsenv_plugin_babel.js +38 -22
  91. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +0 -0
  92. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/.eslintrc.cjs +0 -0
  93. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/new_stylesheet.js +0 -0
  94. package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +0 -0
  95. package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/client/regenerator_runtime.js +0 -0
  96. package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +18 -0
  97. package/src/{omega/core_plugins → plugins/transpilation}/import_assertions/helpers/babel_plugin_metadata_import_assertions.js +0 -0
  98. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +243 -0
  99. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +40 -0
  100. package/src/plugins/url_references/css/css_urls.js +49 -0
  101. package/src/plugins/url_references/html/html_urls.js +273 -0
  102. package/src/plugins/url_references/js/js_urls.js +170 -0
  103. package/src/plugins/url_references/jsenv_plugin_url_references.js +18 -0
  104. package/src/plugins/url_references/webmanifest/webmanifest_urls.js +17 -0
  105. package/src/{omega/core_plugins → plugins}/url_resolution/jsenv_plugin_url_resolution.js +12 -5
  106. package/src/{omega/core_plugins → plugins}/url_version/jsenv_plugin_url_version.js +8 -8
  107. package/src/test/execute_plan.js +25 -11
  108. package/src/test/execute_test_plan.js +14 -1
  109. package/src/test/logs_file_execution.js +8 -7
  110. package/src/build/plugins/minify_html/jsenv_plugin_minify_html.js +0 -30
  111. package/src/dev/plugins/autoreload/client/event_source_connection.js +0 -195
  112. package/src/dev/plugins/autoreload/sse_service.js +0 -149
  113. package/src/execute/runtimes/node/controlled_process.js +0 -316
  114. package/src/omega/core_plugins/babel/babel_helper/babel_helper_directory.js +0 -29
  115. package/src/omega/core_plugins/babel/babel_helper/client/.eslintrc.cjs +0 -24
  116. package/src/omega/core_plugins/babel/babel_helper/client/AsyncGenerator/AsyncGenerator.js +0 -81
  117. package/src/omega/core_plugins/babel/babel_helper/client/AwaitValue/AwaitValue.js +0 -3
  118. package/src/omega/core_plugins/babel/babel_helper/client/applyDecoratorDescriptor/applyDecoratorDescriptor.js +0 -33
  119. package/src/omega/core_plugins/babel/babel_helper/client/arrayLikeToArray/arrayLikeToArray.js +0 -7
  120. package/src/omega/core_plugins/babel/babel_helper/client/arrayWithHoles/arrayWithHoles.js +0 -4
  121. package/src/omega/core_plugins/babel/babel_helper/client/arrayWithoutHoles/arrayWithoutHoles.js +0 -6
  122. package/src/omega/core_plugins/babel/babel_helper/client/assertThisInitialized/assertThisInitialized.js +0 -7
  123. package/src/omega/core_plugins/babel/babel_helper/client/asyncGeneratorDelegate/asyncGeneratorDelegate.js +0 -40
  124. package/src/omega/core_plugins/babel/babel_helper/client/asyncIterator/asyncIterator.js +0 -65
  125. package/src/omega/core_plugins/babel/babel_helper/client/asyncToGenerator/asyncToGenerator.js +0 -34
  126. package/src/omega/core_plugins/babel/babel_helper/client/awaitAsyncGenerator/awaitAsyncGenerator.js +0 -5
  127. package/src/omega/core_plugins/babel/babel_helper/client/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +0 -20
  128. package/src/omega/core_plugins/babel/babel_helper/client/classApplyDescriptorGet/classApplyDescriptorGet.js +0 -6
  129. package/src/omega/core_plugins/babel/babel_helper/client/classApplyDescriptorSet/classApplyDescriptorSet.js +0 -13
  130. package/src/omega/core_plugins/babel/babel_helper/client/classCallCheck/classCallCheck.js +0 -5
  131. package/src/omega/core_plugins/babel/babel_helper/client/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +0 -5
  132. package/src/omega/core_plugins/babel/babel_helper/client/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +0 -6
  133. package/src/omega/core_plugins/babel/babel_helper/client/classExtractFieldDescriptor/classExtractFieldDescriptor.js +0 -7
  134. package/src/omega/core_plugins/babel/babel_helper/client/classNameTDZError/classNameTDZError.js +0 -4
  135. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +0 -7
  136. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldGet/classPrivateFieldGet.js +0 -7
  137. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +0 -6
  138. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +0 -5
  139. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldSet/classPrivateFieldSet.js +0 -8
  140. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateMethodGet/classPrivateMethodGet.js +0 -6
  141. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateMethodSet/classPrivateMethodSet.js +0 -3
  142. package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +0 -9
  143. package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +0 -15
  144. package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +0 -6
  145. package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +0 -3
  146. package/src/omega/core_plugins/babel/babel_helper/client/construct/construct.js +0 -16
  147. package/src/omega/core_plugins/babel/babel_helper/client/createClass/createClass.js +0 -15
  148. package/src/omega/core_plugins/babel/babel_helper/client/createForOfIteratorHelper/createForOfIteratorHelper.js +0 -60
  149. package/src/omega/core_plugins/babel/babel_helper/client/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +0 -23
  150. package/src/omega/core_plugins/babel/babel_helper/client/createRawReactElement/createRawReactElement.js +0 -50
  151. package/src/omega/core_plugins/babel/babel_helper/client/createSuper/createSuper.js +0 -22
  152. package/src/omega/core_plugins/babel/babel_helper/client/decorate/decorate.js +0 -403
  153. package/src/omega/core_plugins/babel/babel_helper/client/defaults/defaults.js +0 -11
  154. package/src/omega/core_plugins/babel/babel_helper/client/defineEnumerableProperties/defineEnumerableProperties.js +0 -23
  155. package/src/omega/core_plugins/babel/babel_helper/client/defineProperty/defineProperty.js +0 -18
  156. package/src/omega/core_plugins/babel/babel_helper/client/extends/extends.js +0 -14
  157. package/src/omega/core_plugins/babel/babel_helper/client/get/get.js +0 -19
  158. package/src/omega/core_plugins/babel/babel_helper/client/getPrototypeOf/getPrototypeOf.js +0 -4
  159. package/src/omega/core_plugins/babel/babel_helper/client/inherits/inherits.js +0 -19
  160. package/src/omega/core_plugins/babel/babel_helper/client/inheritsLoose/inheritsLoose.js +0 -7
  161. package/src/omega/core_plugins/babel/babel_helper/client/initializerDefineProperty/initializerDefineProperty.js +0 -10
  162. package/src/omega/core_plugins/babel/babel_helper/client/initializerWarningHelper/initializerWarningHelper.js +0 -6
  163. package/src/omega/core_plugins/babel/babel_helper/client/instanceof/instanceof.js +0 -6
  164. package/src/omega/core_plugins/babel/babel_helper/client/interopRequireDefault/interopRequireDefault.js +0 -3
  165. package/src/omega/core_plugins/babel/babel_helper/client/interopRequireWildcard/interopRequireWildcard.js +0 -37
  166. package/src/omega/core_plugins/babel/babel_helper/client/isNativeFunction/isNativeFunction.js +0 -4
  167. package/src/omega/core_plugins/babel/babel_helper/client/isNativeReflectConstruct/isNativeReflectConstruct.js +0 -21
  168. package/src/omega/core_plugins/babel/babel_helper/client/iterableToArray/iterableToArray.js +0 -7
  169. package/src/omega/core_plugins/babel/babel_helper/client/iterableToArrayLimit/iterableToArrayLimit.js +0 -36
  170. package/src/omega/core_plugins/babel/babel_helper/client/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +0 -10
  171. package/src/omega/core_plugins/babel/babel_helper/client/jsx/jsx.js +0 -50
  172. package/src/omega/core_plugins/babel/babel_helper/client/maybeArrayLike/maybeArrayLike.js +0 -10
  173. package/src/omega/core_plugins/babel/babel_helper/client/newArrowCheck/newArrowCheck.js +0 -5
  174. package/src/omega/core_plugins/babel/babel_helper/client/nonIterableRest/nonIterableRest.js +0 -5
  175. package/src/omega/core_plugins/babel/babel_helper/client/nonIterableSpread/nonIterableSpread.js +0 -5
  176. package/src/omega/core_plugins/babel/babel_helper/client/objectDestructuringEmpty/objectDestructuringEmpty.js +0 -3
  177. package/src/omega/core_plugins/babel/babel_helper/client/objectSpread/objectSpread.js +0 -23
  178. package/src/omega/core_plugins/babel/babel_helper/client/objectSpread2/objectSpread2.js +0 -41
  179. package/src/omega/core_plugins/babel/babel_helper/client/objectWithoutProperties/objectWithoutProperties.js +0 -19
  180. package/src/omega/core_plugins/babel/babel_helper/client/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +0 -13
  181. package/src/omega/core_plugins/babel/babel_helper/client/possibleConstructorReturn/possibleConstructorReturn.js +0 -10
  182. package/src/omega/core_plugins/babel/babel_helper/client/readOnlyError/readOnlyError.js +0 -4
  183. package/src/omega/core_plugins/babel/babel_helper/client/readme.md +0 -8
  184. package/src/omega/core_plugins/babel/babel_helper/client/set/set.js +0 -44
  185. package/src/omega/core_plugins/babel/babel_helper/client/setPrototypeOf/setPrototypeOf.js +0 -6
  186. package/src/omega/core_plugins/babel/babel_helper/client/skipFirstGeneratorNext/skipFirstGeneratorNext.js +0 -8
  187. package/src/omega/core_plugins/babel/babel_helper/client/slicedToArray/slicedToArray.js +0 -10
  188. package/src/omega/core_plugins/babel/babel_helper/client/slicedToArrayLoose/slicedToArrayLoose.js +0 -13
  189. package/src/omega/core_plugins/babel/babel_helper/client/superPropBase/superPropBase.js +0 -10
  190. package/src/omega/core_plugins/babel/babel_helper/client/taggedTemplateLiteral/taggedTemplateLiteral.js +0 -10
  191. package/src/omega/core_plugins/babel/babel_helper/client/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +0 -7
  192. package/src/omega/core_plugins/babel/babel_helper/client/tdz/tdz.js +0 -4
  193. package/src/omega/core_plugins/babel/babel_helper/client/temporalRef/temporalRef.js +0 -6
  194. package/src/omega/core_plugins/babel/babel_helper/client/temporalUndefined/temporalUndefined.js +0 -3
  195. package/src/omega/core_plugins/babel/babel_helper/client/toArray/toArray.js +0 -10
  196. package/src/omega/core_plugins/babel/babel_helper/client/toConsumableArray/toConsumableArray.js +0 -10
  197. package/src/omega/core_plugins/babel/babel_helper/client/toPrimitive/toPrimitive.js +0 -10
  198. package/src/omega/core_plugins/babel/babel_helper/client/toPropertyKey/toPropertyKey.js +0 -6
  199. package/src/omega/core_plugins/babel/babel_helper/client/typeof/typeof.js +0 -14
  200. package/src/omega/core_plugins/babel/babel_helper/client/unsupportedIterableToArray/unsupportedIterableToArray.js +0 -12
  201. package/src/omega/core_plugins/babel/babel_helper/client/wrapAsyncGenerator/wrapAsyncGenerator.js +0 -8
  202. package/src/omega/core_plugins/babel/babel_helper/client/wrapNativeSuper/wrapNativeSuper.js +0 -30
  203. package/src/omega/core_plugins/babel/babel_helper/client/wrapRegExp/wrapRegExp.js +0 -63
  204. package/src/omega/core_plugins/babel/babel_helper/client/writeOnlyError/writeOnlyError.js +0 -4
  205. package/src/omega/core_plugins/babel/helpers/babel_plugin_structure.js +0 -187
  206. package/src/omega/core_plugins/file_urls/jsenv_plugin_file_urls.js +0 -67
  207. package/src/omega/core_plugins/import_assertions/helpers/json_module.js +0 -12
  208. package/src/omega/core_plugins/import_assertions/helpers/text_module.js +0 -6
  209. package/src/omega/core_plugins/import_assertions/jsenv_plugin_import_assertions.js +0 -211
  210. package/src/omega/core_plugins/inline/jsenv_plugin_inline.js +0 -13
  211. package/src/omega/core_plugins/inline/jsenv_plugin_new_inline_content.js +0 -210
  212. package/src/omega/core_plugins/leading_slash/jsenv_plugin_leading_slash.js +0 -12
  213. package/src/omega/core_plugins.js +0 -39
  214. package/src/omega/runtime_support/runtime_support.js +0 -20
  215. package/src/omega/url_mentions/css_url_mentions.js +0 -63
  216. package/src/omega/url_mentions/html_url_mentions.js +0 -185
  217. package/src/omega/url_mentions/js_module_url_mentions.js +0 -91
  218. package/src/omega/url_mentions/parse_url_mentions.js +0 -37
  219. package/src/omega/url_mentions/worker_classic_url_mentions.js +0 -37
@@ -4,51 +4,53 @@ import {
4
4
  isFileSystemPath,
5
5
  fileSystemPathToUrl,
6
6
  moveUrl,
7
- fileSystemRootUrl,
7
+ ensureWindowsDriveLetter,
8
8
  } from "@jsenv/filesystem"
9
+ import { createDetailedMessage } from "@jsenv/logger"
9
10
 
10
11
  import { stringifyUrlSite } from "@jsenv/utils/urls/url_trace.js"
12
+ import { CONTENT_TYPE } from "@jsenv/utils/content_type/content_type.js"
13
+ import { setUrlFilename } from "@jsenv/utils/urls/url_utils.js"
11
14
 
15
+ import { createPluginController } from "../plugins/plugin_controller.js"
16
+ import { jsenvPluginUrlReferences } from "../plugins/url_references/jsenv_plugin_url_references.js"
12
17
  import { createUrlInfoTransformer } from "./url_graph/url_info_transformations.js"
13
- import { featuresCompatMap } from "./runtime_support/features_compatibility.js"
14
- import { isFeatureSupportedOnRuntimes } from "./runtime_support/runtime_support.js"
15
- import { fileUrlConverter } from "./file_url_converter.js"
16
- import { parseUrlMentions } from "./url_mentions/parse_url_mentions.js"
18
+ import { RUNTIME_COMPAT } from "./compat/runtime_compat.js"
19
+ import { defaultRuntimeCompat } from "./compat/default_runtime_compat.js"
17
20
  import {
18
- createResolveError,
19
- createLoadError,
20
- createParseError,
21
- createTransformError,
21
+ createResolveUrlError,
22
+ createFetchUrlContentError,
23
+ createTransformUrlContentError,
24
+ createFinalizeUrlContentError,
22
25
  } from "./errors.js"
23
- import { createPluginController } from "./plugin_controller.js"
26
+ import { assertFetchedContentCompliance } from "./fetched_content_compliance.js"
27
+ import { isWebWorkerEntryPointReference } from "./web_workers.js"
24
28
 
25
29
  export const createKitchen = ({
26
30
  signal,
27
31
  logger,
28
32
  rootDirectoryUrl,
29
33
  urlGraph,
34
+
30
35
  plugins,
31
36
  scenario,
32
-
33
37
  sourcemaps = {
34
38
  dev: "inline", // "programmatic" and "file" also allowed
35
39
  test: "inline",
36
40
  build: "none",
37
41
  }[scenario],
38
- // we don't need sources in sourcemap as long as the url in the
39
- // sourcemap uses file:/// (chrome will understand and read from filesystem)
40
- sourcemapsSources = false,
41
- loadInlineUrlInfos = (urlInfo) => {
42
- return {
43
- contentType: urlInfo.contentType,
44
- content: urlInfo.content,
45
- }
46
- },
47
-
42
+ sourcemapsSources = {
43
+ // during dev/test, chrome is able to find the sourcemap sources
44
+ // as long as they use file:// protocol in the sourcemap files
45
+ dev: false,
46
+ test: false,
47
+ build: true,
48
+ }[scenario],
49
+ runtimeCompat = defaultRuntimeCompat,
48
50
  writeOnFileSystem = true,
49
51
  }) => {
50
52
  const pluginController = createPluginController({
51
- plugins,
53
+ plugins: [jsenvPluginUrlReferences(), ...plugins],
52
54
  scenario,
53
55
  })
54
56
  const jsenvDirectoryUrl = new URL(".jsenv/", rootDirectoryUrl).href
@@ -59,35 +61,75 @@ export const createKitchen = ({
59
61
  sourcemaps,
60
62
  urlGraph,
61
63
  scenario,
64
+ runtimeCompat,
65
+ isSupportedOnFutureClients: (feature) => {
66
+ return RUNTIME_COMPAT.isSupported(runtimeCompat, feature)
67
+ },
62
68
  }
63
69
  const createReference = ({
64
70
  data = {},
71
+ node,
65
72
  trace,
66
73
  parentUrl,
67
74
  type,
68
75
  subtype,
76
+ expectedContentType,
77
+ expectedType,
78
+ expectedSubtype,
79
+ filename,
80
+ integrity,
81
+ crossorigin,
69
82
  specifier,
83
+ baseUrl,
84
+ isOriginalPosition,
85
+ line,
86
+ column,
87
+ external = false,
70
88
  isInline = false,
89
+ injected = false,
90
+ isRessourceHint = false,
71
91
  content,
72
92
  contentType,
73
93
  }) => {
74
94
  return {
95
+ original: null,
96
+ prev: null,
97
+ next: null,
75
98
  data,
99
+ node,
76
100
  trace,
77
101
  parentUrl,
78
102
  type,
79
103
  subtype,
104
+ expectedContentType,
105
+ expectedType,
106
+ expectedSubtype,
107
+ filename,
108
+ integrity,
109
+ crossorigin,
80
110
  specifier,
111
+ baseUrl,
112
+ isOriginalPosition,
113
+ line,
114
+ column,
115
+ external,
81
116
  isInline,
117
+ injected,
118
+ isRessourceHint,
82
119
  // for inline ressources the reference contains the content
83
120
  content,
84
121
  contentType,
85
122
  }
86
123
  }
124
+ const mutateReference = (reference, newReference) => {
125
+ reference.next = newReference
126
+ newReference.prev = reference
127
+ newReference.original = reference.original || reference
128
+ }
87
129
  const resolveReference = (reference) => {
88
130
  try {
89
131
  const resolvedUrl = pluginController.callHooksUntil(
90
- "resolve",
132
+ "resolveUrl",
91
133
  reference,
92
134
  baseContext,
93
135
  )
@@ -95,15 +137,25 @@ export const createKitchen = ({
95
137
  throw new Error(`NO_RESOLVE`)
96
138
  }
97
139
  reference.url = resolvedUrl
140
+ if (reference.external) {
141
+ reference.generatedUrl = resolvedUrl
142
+ reference.generatedSpecifier = reference.specifier
143
+ return urlGraph.reuseOrCreateUrlInfo(reference.url)
144
+ }
98
145
  pluginController.callHooks(
99
- "normalize",
146
+ "normalizeUrl",
100
147
  reference,
101
148
  baseContext,
102
149
  (returnValue) => {
150
+ if (returnValue === reference.url) {
151
+ return
152
+ }
153
+ const previousReference = { ...reference }
103
154
  reference.url = returnValue
155
+ mutateReference(previousReference, reference)
104
156
  },
105
157
  )
106
- // force a last normalization regarding on url search params
158
+ // force a last normalization on url search params
107
159
  // some plugin use URLSearchParams to alter the url search params
108
160
  // which can result into "file:///file.css?css_module"
109
161
  // becoming "file:///file.css?css_module="
@@ -115,32 +167,41 @@ export const createKitchen = ({
115
167
  reference.url = reference.url.replace(/[=](?=&|$)/g, "")
116
168
  }
117
169
  const urlInfo = urlGraph.reuseOrCreateUrlInfo(reference.url)
118
- Object.assign(urlInfo.data, reference.data)
170
+ applyReferenceEffectsOnUrlInfo(reference, urlInfo, baseContext)
119
171
 
120
- // create a copy because .url will be mutated
121
- const referencedCopy = {
122
- ...reference,
123
- data: urlInfo.data,
124
- }
172
+ const referenceUrlObject = new URL(reference.url)
173
+ reference.searchParams = referenceUrlObject.searchParams
174
+ reference.generatedUrl = reference.url
175
+ // This hook must touch reference.generatedUrl, NOT reference.url
176
+ // And this is because this hook inject query params used to:
177
+ // - bypass browser cache (?v)
178
+ // - convey information (?hmr)
179
+ // But do not represent an other ressource, it is considered as
180
+ // the same ressource under the hood
125
181
  pluginController.callHooks(
126
- "transformReferencedUrl",
127
- referencedCopy,
182
+ "transformUrlSearchParams",
183
+ reference,
128
184
  baseContext,
129
185
  (returnValue) => {
130
- referencedCopy.url = returnValue
186
+ Object.keys(returnValue).forEach((key) => {
187
+ referenceUrlObject.searchParams.set(key, returnValue[key])
188
+ })
189
+ reference.generatedUrl = referenceUrlObject.href.replace(
190
+ /[=](?=&|$)/g,
191
+ "",
192
+ )
131
193
  },
132
194
  )
133
- reference.generatedUrl = referencedCopy.url
134
195
  const returnValue = pluginController.callHooksUntil(
135
- "formatReferencedUrl",
136
- referencedCopy,
196
+ "formatUrl",
197
+ reference,
137
198
  baseContext,
138
199
  )
139
200
  reference.generatedSpecifier = returnValue || reference.generatedUrl
140
- reference.generatedSpecifier = specifierFormat.encode(reference)
201
+ reference.generatedSpecifier = urlSpecifierFormat.encode(reference)
141
202
  return urlInfo
142
203
  } catch (error) {
143
- throw createResolveError({
204
+ throw createResolveUrlError({
144
205
  pluginController,
145
206
  reference,
146
207
  error,
@@ -156,8 +217,7 @@ export const createKitchen = ({
156
217
  const sourcemapReference = createReference({
157
218
  trace: `sourcemap comment placeholder for ${urlInfo.url}`,
158
219
  type: "sourcemap_comment",
159
- subtype:
160
- urlInfo.contentType === "application/javascript" ? "js" : "css",
220
+ subtype: urlInfo.contentType === "text/javascript" ? "js" : "css",
161
221
  parentUrl: urlInfo.url,
162
222
  specifier,
163
223
  })
@@ -185,69 +245,77 @@ export const createKitchen = ({
185
245
  },
186
246
  })
187
247
 
188
- const isSupported = ({
189
- runtimeSupport,
190
- featureName,
191
- featureCompat = featuresCompatMap[featureName],
192
- }) => {
193
- return isFeatureSupportedOnRuntimes(runtimeSupport, featureCompat)
194
- }
195
-
196
- const load = async ({ reference, urlInfo, context }) => {
248
+ const fetchUrlContent = async ({ reference, urlInfo, context }) => {
249
+ if (reference.external) {
250
+ urlInfo.external = true
251
+ return
252
+ }
197
253
  try {
198
- const loadReturnValue = urlInfo.isInline
199
- ? loadInlineUrlInfos(urlInfo)
200
- : await pluginController.callAsyncHooksUntil("load", urlInfo, context)
201
- if (!loadReturnValue) {
202
- throw new Error("NO_LOAD")
254
+ const returnValue = await pluginController.callAsyncHooksUntil(
255
+ "fetchUrlContent",
256
+ urlInfo,
257
+ context,
258
+ )
259
+ if (!returnValue) {
260
+ logger.warn(
261
+ createDetailedMessage(
262
+ `no plugin has handled the url during "fetchUrlContent" hook -> consider url as external (ignore it)`,
263
+ {
264
+ "url": urlInfo.url,
265
+ "url reference trace": reference.trace,
266
+ },
267
+ ),
268
+ )
269
+ urlInfo.external = true
270
+ return
271
+ }
272
+ if (returnValue.external) {
273
+ urlInfo.external = true
274
+ return
203
275
  }
204
-
205
276
  const {
206
- contentType = "application/octet-stream",
207
- content, // can be a buffer (used for binary files) or a string
208
- sourcemap,
209
- // during build urls info are reused and load returns originalContent
210
- // that we want to keep
211
- originalContent = content,
212
277
  data,
213
- } = loadReturnValue
214
- Object.assign(urlInfo, {
215
- contentType,
278
+ type,
279
+ subtype,
280
+ contentType = "application/octet-stream",
216
281
  originalContent,
217
282
  content,
218
283
  sourcemap,
219
- })
284
+ filename,
285
+ } = returnValue
286
+ urlInfo.type =
287
+ type ||
288
+ reference.expectedType ||
289
+ inferUrlInfoType({
290
+ url: urlInfo.url,
291
+ contentType,
292
+ })
293
+ urlInfo.subtype =
294
+ subtype ||
295
+ reference.expectedSubtype ||
296
+ inferUrlInfoSubtype({
297
+ url: urlInfo.url,
298
+ type: urlInfo.type,
299
+ subtype: urlInfo.subtype,
300
+ })
301
+ urlInfo.contentType = contentType
302
+ // during build urls info are reused and load returns originalContent
303
+ urlInfo.originalContent =
304
+ originalContent === undefined ? content : originalContent
305
+ urlInfo.content = content
306
+ urlInfo.sourcemap = sourcemap
220
307
  if (data) {
221
308
  Object.assign(urlInfo.data, data)
222
309
  }
223
- if (!urlInfo.type) {
224
- const type = inferUrlInfoType(urlInfo)
225
- if (type === "js") {
226
- const urlObject = new URL(urlInfo.url)
227
- if (urlObject.searchParams.has("worker_type_classic")) {
228
- urlInfo.type = "js_classic"
229
- urlInfo.subtype = "worker"
230
- } else if (
231
- urlObject.searchParams.has("service_worker_type_classic")
232
- ) {
233
- urlInfo.type = "js_classic"
234
- urlInfo.subtype = "service_worker"
235
- } else if (urlObject.searchParams.has("js_classic")) {
236
- urlInfo.type = "js_classic"
237
- } else {
238
- urlInfo.type = "js_module"
239
- }
240
- if (urlObject.searchParams.has("worker")) {
241
- urlInfo.subtype = "worker"
242
- } else if (urlObject.searchParams.has("service_worker")) {
243
- urlInfo.subtype = "service_worker"
244
- }
245
- } else {
246
- urlInfo.type = type
247
- }
310
+ if (filename) {
311
+ urlInfo.filename = filename
248
312
  }
313
+ assertFetchedContentCompliance({
314
+ reference,
315
+ urlInfo,
316
+ })
249
317
  } catch (error) {
250
- throw createLoadError({
318
+ throw createFetchUrlContentError({
251
319
  pluginController,
252
320
  urlInfo,
253
321
  reference,
@@ -255,9 +323,8 @@ export const createKitchen = ({
255
323
  })
256
324
  }
257
325
  urlInfo.generatedUrl = determineFileUrlForOutDirectory({
258
- rootDirectoryUrl,
259
- outDirectoryUrl: context.outDirectoryUrl,
260
- url: urlInfo.url,
326
+ urlInfo,
327
+ context,
261
328
  })
262
329
  await urlInfoTransformer.initTransformations(urlInfo, context)
263
330
  }
@@ -266,34 +333,39 @@ export const createKitchen = ({
266
333
  reference,
267
334
  urlInfo,
268
335
  outDirectoryUrl,
269
- runtimeSupport,
336
+ // during dev/test clientRuntimeCompat is a single runtime
337
+ // during build clientRuntimeCompat is runtimeCompat
338
+ clientRuntimeCompat = runtimeCompat,
270
339
  cookDuringCook = cook,
271
340
  }) => {
272
341
  const context = {
273
342
  ...baseContext,
274
343
  reference,
275
344
  outDirectoryUrl,
276
- runtimeSupport,
277
- isSupportedOnRuntime: (featureName, featureCompat) => {
278
- return isSupported({ runtimeSupport, featureName, featureCompat })
345
+ clientRuntimeCompat,
346
+ isSupportedOnCurrentClients: (feature) => {
347
+ return RUNTIME_COMPAT.isSupported(clientRuntimeCompat, feature)
279
348
  },
280
349
  cook: (params) => {
281
350
  return cookDuringCook({
282
351
  outDirectoryUrl,
283
- runtimeSupport,
352
+ clientRuntimeCompat,
284
353
  ...params,
285
354
  })
286
355
  },
287
- load: (params) => {
288
- return load({
356
+ fetchUrlContent: (params) => {
357
+ return fetchUrlContent({
289
358
  context,
290
359
  ...params,
291
360
  })
292
361
  },
293
362
  }
294
363
 
295
- // "load" hook
296
- await load({ reference, urlInfo, context })
364
+ // "fetchUrlContent" hook
365
+ await fetchUrlContent({ reference, urlInfo, context })
366
+ if (urlInfo.external) {
367
+ return
368
+ }
297
369
 
298
370
  // parsing
299
371
  const references = []
@@ -303,182 +375,146 @@ export const createKitchen = ({
303
375
  ...props,
304
376
  })
305
377
  references.push(reference)
306
- return [reference, resolveReference(reference)]
378
+ const referencedUrlInfo = resolveReference(reference)
379
+ return [reference, referencedUrlInfo]
307
380
  }
308
381
  const referenceUtils = {
309
- inject: ({ trace, ...rest }) => {
310
- if (trace === undefined) {
311
- const { prepareStackTrace } = Error
312
- Error.prepareStackTrace = (error, stack) => {
313
- Error.prepareStackTrace = prepareStackTrace
314
- return stack
315
- }
316
- const { stack } = new Error()
317
- const callerCallsite = stack[1]
318
- const fileName = callerCallsite.getFileName()
319
- trace = stringifyUrlSite({
320
- url:
321
- fileName && isFileSystemPath(fileName)
322
- ? fileSystemPathToUrl(fileName)
323
- : fileName,
324
- line: callerCallsite.getLineNumber(),
325
- column: callerCallsite.getColumnNumber(),
382
+ readGeneratedSpecifier: async (reference) => {
383
+ // "formatReferencedUrl" can be async BUT this is an exception
384
+ // for most cases it will be sync. We want to favor the sync signature to keep things simpler
385
+ // The only case where it needs to be async is when
386
+ // the specifier is a `data:*` url
387
+ // in this case we'll wait for the promise returned by
388
+ // "formatReferencedUrl"
389
+ if (reference.generatedSpecifier.then) {
390
+ return reference.generatedSpecifier.then((value) => {
391
+ reference.generatedSpecifier = value
392
+ return value
326
393
  })
327
394
  }
395
+ return reference.generatedSpecifier
396
+ },
397
+ found: ({ line, column, ...rest }) => {
398
+ const trace = stringifyUrlSite(
399
+ adjustUrlSite(urlInfo, {
400
+ urlGraph,
401
+ url: urlInfo.url,
402
+ line,
403
+ column,
404
+ }),
405
+ )
406
+ // console.log(trace)
328
407
  return addReference({
329
408
  trace,
409
+ line,
410
+ column,
330
411
  ...rest,
331
412
  })
332
413
  },
333
- foundInline: ({
334
- type,
335
- isOriginal,
336
- line,
337
- column,
338
- specifier,
339
- contentType,
340
- content,
341
- }) => {
342
- const parentUrl = isOriginal ? urlInfo.url : urlInfo.generatedUrl
343
- const parentContent = isOriginal
414
+ foundInline: ({ isOriginalPosition, line, column, ...rest }) => {
415
+ const parentUrl = isOriginalPosition
416
+ ? urlInfo.url
417
+ : urlInfo.generatedUrl
418
+ const parentContent = isOriginalPosition
344
419
  ? urlInfo.originalContent
345
420
  : urlInfo.content
346
- const [inlineReference, inlineUrlInfo] = addReference({
421
+ return addReference({
347
422
  trace: stringifyUrlSite({
348
423
  url: parentUrl,
349
424
  content: parentContent,
350
425
  line,
351
426
  column,
352
427
  }),
353
- type,
354
- specifier,
355
- isInline: true,
356
- contentType,
357
- content,
358
- })
359
- inlineUrlInfo.isInline = true
360
- inlineUrlInfo.inlineUrlSite = {
361
- url: urlInfo.url,
362
- content: parentContent,
428
+ isOriginalPosition,
363
429
  line,
364
430
  column,
365
- }
366
- inlineUrlInfo.contentType = contentType
367
- inlineUrlInfo.originalContent = inlineUrlInfo.content = content
368
- return [inlineReference, inlineUrlInfo]
431
+ isInline: true,
432
+ ...rest,
433
+ })
369
434
  },
370
- updateSpecifier: (generatedSpecifier, newSpecifier, data) => {
371
- const index = references.findIndex(
372
- (ref) => ref.generatedSpecifier === generatedSpecifier,
373
- )
435
+ update: (currentReference, newReferenceParams) => {
436
+ const index = references.indexOf(currentReference)
374
437
  if (index === -1) {
375
- throw new Error(
376
- `Cannot find a reference for the following generatedSpecifier "${generatedSpecifier}"`,
377
- )
438
+ throw new Error(`reference do not exists`)
378
439
  }
379
- const referenceFound = references[index]
380
- const newReference = createReference({
381
- ...referenceFound,
382
- specifier: newSpecifier,
383
- data: {
384
- ...referenceFound.data,
385
- ...data,
386
- },
440
+ const previousReference = currentReference
441
+ const nextReference = createReference({
442
+ ...previousReference,
443
+ ...newReferenceParams,
387
444
  })
388
- references[index] = newReference
389
- newReference.data.originalReference = referenceFound
390
- const newUrlInfo = resolveReference(newReference)
391
- return [newReference, newUrlInfo]
445
+ references[index] = nextReference
446
+ mutateReference(previousReference, nextReference)
447
+ const newUrlInfo = resolveReference(nextReference)
448
+ const currentUrlInfo = context.urlGraph.getUrlInfo(currentReference.url)
449
+ if (
450
+ currentUrlInfo &&
451
+ currentUrlInfo !== newUrlInfo &&
452
+ currentUrlInfo.dependents.size === 0
453
+ ) {
454
+ delete context.urlGraph.urlInfos[currentReference.url]
455
+ }
456
+ return [nextReference, newUrlInfo]
392
457
  },
393
458
  becomesInline: (
394
459
  reference,
395
- { isOriginal, line, column, specifier, contentType, content },
460
+ { isOriginalPosition, line, column, specifier, contentType, content },
396
461
  ) => {
397
- const parentUrl = isOriginal ? urlInfo.url : urlInfo.generatedUrl
398
- const parentContent = isOriginal
462
+ const parentUrl = isOriginalPosition
463
+ ? urlInfo.url
464
+ : urlInfo.generatedUrl
465
+ const parentContent = isOriginalPosition
399
466
  ? urlInfo.originalContent
400
467
  : urlInfo.content
401
- reference.trace = stringifyUrlSite({
402
- url: parentUrl,
403
- content: parentContent,
404
- line,
405
- column,
468
+ return referenceUtils.update(reference, {
469
+ trace: stringifyUrlSite({
470
+ url: parentUrl,
471
+ content: parentContent,
472
+ line,
473
+ column,
474
+ }),
475
+ isOriginalPosition,
476
+ isInline: true,
477
+ specifier,
478
+ contentType,
479
+ content,
406
480
  })
407
- reference.isInline = true
408
- reference.specifier = specifier
409
- reference.contentType = contentType
410
- reference.content = content
411
- const inlineUrlInfo = resolveReference(reference)
412
- inlineUrlInfo.isInline = true
413
- inlineUrlInfo.inlineUrlSite = {
414
- url: urlInfo.url,
415
- content: parentContent,
416
- line,
417
- column,
418
- }
419
- inlineUrlInfo.contentType = contentType
420
- inlineUrlInfo.content = content
421
- return reference
422
481
  },
423
- }
424
-
425
- let parseResult
426
- try {
427
- parseResult = await parseUrlMentions({
428
- type: urlInfo.type,
429
- url: urlInfo.data.sourceUrl || urlInfo.url,
430
- generatedUrl: urlInfo.generatedUrl,
431
- content: urlInfo.content,
432
- })
433
- } catch (error) {
434
- throw createParseError({
435
- reference,
436
- urlInfo,
437
- error,
438
- })
439
- }
440
- if (parseResult) {
441
- Object.assign(urlInfo.data, parseResult.data)
442
- const { urlMentions, replaceUrls } = parseResult
443
- for (const urlMention of urlMentions) {
444
- const [reference] = addReference({
445
- trace: stringifyUrlSite(
446
- adjustUrlSite(urlInfo, {
447
- urlGraph,
448
- url: urlInfo.url,
449
- line: urlMention.line,
450
- column: urlMention.column,
451
- }),
452
- ),
453
- type: urlMention.type,
454
- subtype: urlMention.subtype,
455
- specifier: urlMention.specifier,
456
- })
457
- urlMention.reference = reference
458
- }
459
- if (references.length) {
460
- // "formatReferencedUrl" can be async BUT this is an exception
461
- // for most cases it will be sync. We want to favor the sync signature to keep things simpler
462
- // The only case where it needs to be async is when
463
- // the specifier is a `data:*` url
464
- // in this case we'll wait for the promise returned by
465
- // "formatReferencedUrl"
466
- await Promise.all(
467
- references.map(async (reference) => {
468
- if (reference.generatedSpecifier.then) {
469
- const value = await reference.generatedSpecifier
470
- reference.generatedSpecifier = value
471
- }
472
- }),
473
- )
474
- const replaceReturnValue = await replaceUrls((urlMention) => {
475
- return urlMention.reference.generatedSpecifier
482
+ inject: ({ trace, ...rest }) => {
483
+ if (trace === undefined) {
484
+ const { prepareStackTrace } = Error
485
+ Error.prepareStackTrace = (error, stack) => {
486
+ Error.prepareStackTrace = prepareStackTrace
487
+ return stack
488
+ }
489
+ const { stack } = new Error()
490
+ const callerCallsite = stack[1]
491
+ const fileName = callerCallsite.getFileName()
492
+ trace = stringifyUrlSite({
493
+ url:
494
+ fileName && isFileSystemPath(fileName)
495
+ ? fileSystemPathToUrl(fileName)
496
+ : fileName,
497
+ line: callerCallsite.getLineNumber(),
498
+ column: callerCallsite.getColumnNumber(),
499
+ })
500
+ }
501
+ return addReference({
502
+ trace,
503
+ injected: true,
504
+ ...rest,
476
505
  })
477
- await urlInfoTransformer.applyIntermediateTransformations(
478
- urlInfo,
479
- replaceReturnValue,
506
+ },
507
+ findByGeneratedSpecifier: (generatedSpecifier) => {
508
+ const reference = references.find(
509
+ (ref) => ref.generatedSpecifier === generatedSpecifier,
480
510
  )
481
- }
511
+ if (!reference) {
512
+ throw new Error(
513
+ `No reference found using the following generatedSpecifier: "${generatedSpecifier}"`,
514
+ )
515
+ }
516
+ return reference
517
+ },
482
518
  }
483
519
 
484
520
  // "transform" hook
@@ -486,7 +522,7 @@ export const createKitchen = ({
486
522
  context.referenceUtils = referenceUtils
487
523
  try {
488
524
  await pluginController.callAsyncHooks(
489
- "transform",
525
+ "transformUrlContent",
490
526
  urlInfo,
491
527
  context,
492
528
  async (transformReturnValue) => {
@@ -497,7 +533,7 @@ export const createKitchen = ({
497
533
  },
498
534
  )
499
535
  } catch (error) {
500
- throw createTransformError({
536
+ throw createTransformUrlContentError({
501
537
  pluginController,
502
538
  reference,
503
539
  urlInfo,
@@ -509,15 +545,24 @@ export const createKitchen = ({
509
545
  urlGraph.updateReferences(urlInfo, references)
510
546
 
511
547
  // "finalize" hook
512
- const finalizeReturnValue = await pluginController.callHooksUntil(
513
- "finalize",
514
- urlInfo,
515
- context,
516
- )
517
- await urlInfoTransformer.applyFinalTransformations(
518
- urlInfo,
519
- finalizeReturnValue,
520
- )
548
+ try {
549
+ const finalizeReturnValue = await pluginController.callAsyncHooksUntil(
550
+ "finalizeUrlContent",
551
+ urlInfo,
552
+ context,
553
+ )
554
+ await urlInfoTransformer.applyFinalTransformations(
555
+ urlInfo,
556
+ finalizeReturnValue,
557
+ )
558
+ } catch (error) {
559
+ throw createFinalizeUrlContentError({
560
+ pluginController,
561
+ reference,
562
+ urlInfo,
563
+ error,
564
+ })
565
+ }
521
566
 
522
567
  // "cooked" hook
523
568
  pluginController.callHooks(
@@ -580,15 +625,60 @@ export const createKitchen = ({
580
625
 
581
626
  baseContext.cook = cook
582
627
 
628
+ const prepareEntryPoint = (params) => {
629
+ const entryReference = createReference(params)
630
+ const entryUrlInfo = resolveReference(entryReference)
631
+ return [entryReference, entryUrlInfo]
632
+ }
633
+
634
+ const injectReference = (params) => {
635
+ const ref = createReference(params)
636
+ const urlInfo = resolveReference(ref)
637
+ return [ref, urlInfo]
638
+ }
639
+
583
640
  return {
584
641
  pluginController,
585
642
  urlInfoTransformer,
586
643
  rootDirectoryUrl,
587
644
  jsenvDirectoryUrl,
588
- isSupported,
589
- createReference,
590
- resolveReference,
645
+ baseContext,
591
646
  cook,
647
+ prepareEntryPoint,
648
+ injectReference,
649
+ }
650
+ }
651
+
652
+ const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
653
+ Object.assign(urlInfo.data, reference.data)
654
+ if (reference.injected) {
655
+ urlInfo.data.injected = true
656
+ }
657
+ if (reference.filename) {
658
+ urlInfo.filename = reference.filename
659
+ }
660
+ if (reference.isInline) {
661
+ urlInfo.isInline = true
662
+ const parentUrlInfo = context.urlGraph.getUrlInfo(reference.parentUrl)
663
+ urlInfo.inlineUrlSite = {
664
+ url: parentUrlInfo.url,
665
+ content: reference.isOriginalPosition
666
+ ? parentUrlInfo.originalContent
667
+ : parentUrlInfo.content,
668
+ line: reference.line,
669
+ column: reference.column,
670
+ }
671
+ urlInfo.contentType = reference.contentType
672
+ urlInfo.originalContent =
673
+ context === "build"
674
+ ? urlInfo.originalContent === undefined
675
+ ? reference.content
676
+ : urlInfo.originalContent
677
+ : reference.content
678
+ urlInfo.content = reference.content
679
+ }
680
+ if (isWebWorkerEntryPointReference(reference)) {
681
+ urlInfo.data.isWebWorkerEntryPoint = true
592
682
  }
593
683
  }
594
684
 
@@ -626,54 +716,86 @@ const adjustUrlSite = (urlInfo, { urlGraph, url, line, column }) => {
626
716
  )
627
717
  }
628
718
 
629
- const inferUrlInfoType = ({ contentType }) => {
719
+ const inferUrlInfoType = ({ url, contentType }) => {
630
720
  if (contentType === "text/html") {
631
721
  return "html"
632
722
  }
633
723
  if (contentType === "text/css") {
634
724
  return "css"
635
725
  }
636
- if (contentType === "application/javascript") {
637
- return "js"
638
- }
639
- if (contentType === "application/json") {
640
- return "json"
726
+ if (contentType === "text/javascript") {
727
+ const urlObject = new URL(url)
728
+ if (urlObject.searchParams.has("js_classic")) {
729
+ return "js_classic"
730
+ }
731
+ return "js_module"
641
732
  }
642
733
  if (contentType === "application/importmap+json") {
643
734
  return "importmap"
644
735
  }
736
+ if (contentType === "application/manifest+json") {
737
+ return "webmanifest"
738
+ }
739
+ if (contentType === "image/svg+xml") {
740
+ return "svg"
741
+ }
742
+ if (CONTENT_TYPE.isJson(contentType)) {
743
+ return "json"
744
+ }
745
+ if (CONTENT_TYPE.isTextual(contentType)) {
746
+ return "text"
747
+ }
645
748
  return "other"
646
749
  }
647
750
 
648
- const determineFileUrlForOutDirectory = ({
649
- rootDirectoryUrl,
650
- outDirectoryUrl,
651
- url,
652
- }) => {
653
- if (!outDirectoryUrl) {
654
- return url
751
+ const inferUrlInfoSubtype = ({ type, subtype, url }) => {
752
+ if (type === "js_classic" || type === "js_module") {
753
+ const urlObject = new URL(url)
754
+ if (urlObject.searchParams.has("worker")) {
755
+ return "worker"
756
+ }
757
+ if (urlObject.searchParams.has("service_worker")) {
758
+ return "service_worker"
759
+ }
760
+ if (urlObject.searchParams.has("shared_worker")) {
761
+ return "shared_worker"
762
+ }
763
+ // if we are currently inside a worker, all deps are consider inside worker too
764
+ return subtype
765
+ }
766
+ return ""
767
+ }
768
+
769
+ const determineFileUrlForOutDirectory = ({ urlInfo, context }) => {
770
+ if (!context.outDirectoryUrl) {
771
+ return urlInfo.url
772
+ }
773
+ if (!urlInfo.url.startsWith("file:")) {
774
+ return urlInfo.url
655
775
  }
656
- if (!url.startsWith("file:")) {
657
- return url
776
+ let url = urlInfo.url
777
+ if (!urlIsInsideOf(urlInfo.url, context.rootDirectoryUrl)) {
778
+ const fsRootUrl = ensureWindowsDriveLetter("file:///", urlInfo.url)
779
+ url = `${context.rootDirectoryUrl}@fs/${url.slice(fsRootUrl.length)}`
658
780
  }
659
- if (!urlIsInsideOf(url, rootDirectoryUrl)) {
660
- url = `${rootDirectoryUrl}@fs/${url.slice(fileSystemRootUrl.length)}`
781
+ if (urlInfo.filename) {
782
+ url = setUrlFilename(url, urlInfo.filename)
661
783
  }
662
784
  return moveUrl({
663
- url: fileUrlConverter.asUrlWithoutSpecialParams(url),
664
- from: rootDirectoryUrl,
665
- to: outDirectoryUrl,
785
+ url,
786
+ from: context.rootDirectoryUrl,
787
+ to: context.outDirectoryUrl,
666
788
  preferAbsolute: true,
667
789
  })
668
790
  }
669
791
 
670
- const specifierFormat = {
792
+ const urlSpecifierFormat = {
671
793
  encode: (reference) => {
672
794
  const { generatedSpecifier } = reference
673
795
  if (generatedSpecifier.then) {
674
796
  return generatedSpecifier.then((value) => {
675
797
  reference.generatedSpecifier = value
676
- return specifierFormat.encode(reference)
798
+ return urlSpecifierFormat.encode(reference)
677
799
  })
678
800
  }
679
801
  // allow plugin to return a function to bypas default formatting
@@ -698,10 +820,11 @@ const specifierFormat = {
698
820
  },
699
821
  }
700
822
  const formatters = {
701
- js_import_export: { encode: JSON.stringify, decode: JSON.parse },
702
- js_import_meta_url_pattern: { encode: JSON.stringify, decode: JSON.parse },
823
+ "js_import_export": { encode: JSON.stringify, decode: JSON.parse },
824
+ "js_url_specifier": { encode: JSON.stringify, decode: JSON.parse },
825
+ "css_@import": { encode: JSON.stringify, code: JSON.stringify },
703
826
  // https://github.com/webpack-contrib/css-loader/pull/627/files
704
- css_url: {
827
+ "css_url": {
705
828
  encode: (url) => {
706
829
  // If url is already wrapped in quotes, remove them
707
830
  url = formatters.css_url.decode(url)