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

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 +16 -12
  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 +188 -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 +19 -22
  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 +405 -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,52 @@ import {
4
4
  isFileSystemPath,
5
5
  fileSystemPathToUrl,
6
6
  moveUrl,
7
- fileSystemRootUrl,
8
7
  } from "@jsenv/filesystem"
8
+ import { createDetailedMessage } from "@jsenv/logger"
9
9
 
10
10
  import { stringifyUrlSite } from "@jsenv/utils/urls/url_trace.js"
11
+ import { CONTENT_TYPE } from "@jsenv/utils/content_type/content_type.js"
12
+ import { setUrlFilename } from "@jsenv/utils/urls/url_utils.js"
11
13
 
14
+ import { createPluginController } from "../plugins/plugin_controller.js"
15
+ import { jsenvPluginUrlReferences } from "../plugins/url_references/jsenv_plugin_url_references.js"
12
16
  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"
17
+ import { RUNTIME_COMPAT } from "./compat/runtime_compat.js"
18
+ import { defaultRuntimeCompat } from "./compat/default_runtime_compat.js"
17
19
  import {
18
- createResolveError,
19
- createLoadError,
20
- createParseError,
21
- createTransformError,
20
+ createResolveUrlError,
21
+ createFetchUrlContentError,
22
+ createTransformUrlContentError,
23
+ createFinalizeUrlContentError,
22
24
  } from "./errors.js"
23
- import { createPluginController } from "./plugin_controller.js"
25
+ import { assertFetchedContentCompliance } from "./fetched_content_compliance.js"
26
+ import { isWebWorkerEntryPointReference } from "./web_workers.js"
24
27
 
25
28
  export const createKitchen = ({
26
29
  signal,
27
30
  logger,
28
31
  rootDirectoryUrl,
29
32
  urlGraph,
33
+
30
34
  plugins,
31
35
  scenario,
32
-
33
36
  sourcemaps = {
34
37
  dev: "inline", // "programmatic" and "file" also allowed
35
38
  test: "inline",
36
39
  build: "none",
37
40
  }[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
-
41
+ sourcemapsSources = {
42
+ // during dev/test, chrome is able to find the sourcemap sources
43
+ // as long as they use file:// protocol in the sourcemap files
44
+ dev: false,
45
+ test: false,
46
+ build: true,
47
+ }[scenario],
48
+ runtimeCompat = defaultRuntimeCompat,
48
49
  writeOnFileSystem = true,
49
50
  }) => {
50
51
  const pluginController = createPluginController({
51
- plugins,
52
+ plugins: [jsenvPluginUrlReferences(), ...plugins],
52
53
  scenario,
53
54
  })
54
55
  const jsenvDirectoryUrl = new URL(".jsenv/", rootDirectoryUrl).href
@@ -59,35 +60,75 @@ export const createKitchen = ({
59
60
  sourcemaps,
60
61
  urlGraph,
61
62
  scenario,
63
+ runtimeCompat,
64
+ isSupportedOnFutureClients: (feature) => {
65
+ return RUNTIME_COMPAT.isSupported(runtimeCompat, feature)
66
+ },
62
67
  }
63
68
  const createReference = ({
64
69
  data = {},
70
+ node,
65
71
  trace,
66
72
  parentUrl,
67
73
  type,
68
74
  subtype,
75
+ expectedContentType,
76
+ expectedType,
77
+ expectedSubtype,
78
+ filename,
79
+ integrity,
80
+ crossorigin,
69
81
  specifier,
82
+ baseUrl,
83
+ isOriginalPosition,
84
+ line,
85
+ column,
86
+ external = false,
70
87
  isInline = false,
88
+ injected = false,
89
+ isRessourceHint = false,
71
90
  content,
72
91
  contentType,
73
92
  }) => {
74
93
  return {
94
+ original: null,
95
+ prev: null,
96
+ next: null,
75
97
  data,
98
+ node,
76
99
  trace,
77
100
  parentUrl,
78
101
  type,
79
102
  subtype,
103
+ expectedContentType,
104
+ expectedType,
105
+ expectedSubtype,
106
+ filename,
107
+ integrity,
108
+ crossorigin,
80
109
  specifier,
110
+ baseUrl,
111
+ isOriginalPosition,
112
+ line,
113
+ column,
114
+ external,
81
115
  isInline,
116
+ injected,
117
+ isRessourceHint,
82
118
  // for inline ressources the reference contains the content
83
119
  content,
84
120
  contentType,
85
121
  }
86
122
  }
123
+ const mutateReference = (reference, newReference) => {
124
+ reference.next = newReference
125
+ newReference.prev = reference
126
+ newReference.original = reference.original || reference
127
+ }
87
128
  const resolveReference = (reference) => {
88
129
  try {
89
130
  const resolvedUrl = pluginController.callHooksUntil(
90
- "resolve",
131
+ "resolveUrl",
91
132
  reference,
92
133
  baseContext,
93
134
  )
@@ -95,15 +136,25 @@ export const createKitchen = ({
95
136
  throw new Error(`NO_RESOLVE`)
96
137
  }
97
138
  reference.url = resolvedUrl
139
+ if (reference.external) {
140
+ reference.generatedUrl = resolvedUrl
141
+ reference.generatedSpecifier = reference.specifier
142
+ return urlGraph.reuseOrCreateUrlInfo(reference.url)
143
+ }
98
144
  pluginController.callHooks(
99
- "normalize",
145
+ "normalizeUrl",
100
146
  reference,
101
147
  baseContext,
102
148
  (returnValue) => {
149
+ if (returnValue === reference.url) {
150
+ return
151
+ }
152
+ const previousReference = { ...reference }
103
153
  reference.url = returnValue
154
+ mutateReference(previousReference, reference)
104
155
  },
105
156
  )
106
- // force a last normalization regarding on url search params
157
+ // force a last normalization on url search params
107
158
  // some plugin use URLSearchParams to alter the url search params
108
159
  // which can result into "file:///file.css?css_module"
109
160
  // becoming "file:///file.css?css_module="
@@ -115,32 +166,41 @@ export const createKitchen = ({
115
166
  reference.url = reference.url.replace(/[=](?=&|$)/g, "")
116
167
  }
117
168
  const urlInfo = urlGraph.reuseOrCreateUrlInfo(reference.url)
118
- Object.assign(urlInfo.data, reference.data)
169
+ applyReferenceEffectsOnUrlInfo(reference, urlInfo, baseContext)
119
170
 
120
- // create a copy because .url will be mutated
121
- const referencedCopy = {
122
- ...reference,
123
- data: urlInfo.data,
124
- }
171
+ const referenceUrlObject = new URL(reference.url)
172
+ reference.searchParams = referenceUrlObject.searchParams
173
+ reference.generatedUrl = reference.url
174
+ // This hook must touch reference.generatedUrl, NOT reference.url
175
+ // And this is because this hook inject query params used to:
176
+ // - bypass browser cache (?v)
177
+ // - convey information (?hmr)
178
+ // But do not represent an other ressource, it is considered as
179
+ // the same ressource under the hood
125
180
  pluginController.callHooks(
126
- "transformReferencedUrl",
127
- referencedCopy,
181
+ "transformUrlSearchParams",
182
+ reference,
128
183
  baseContext,
129
184
  (returnValue) => {
130
- referencedCopy.url = returnValue
185
+ Object.keys(returnValue).forEach((key) => {
186
+ referenceUrlObject.searchParams.set(key, returnValue[key])
187
+ })
188
+ reference.generatedUrl = referenceUrlObject.href.replace(
189
+ /[=](?=&|$)/g,
190
+ "",
191
+ )
131
192
  },
132
193
  )
133
- reference.generatedUrl = referencedCopy.url
134
194
  const returnValue = pluginController.callHooksUntil(
135
- "formatReferencedUrl",
136
- referencedCopy,
195
+ "formatUrl",
196
+ reference,
137
197
  baseContext,
138
198
  )
139
199
  reference.generatedSpecifier = returnValue || reference.generatedUrl
140
- reference.generatedSpecifier = specifierFormat.encode(reference)
200
+ reference.generatedSpecifier = urlSpecifierFormat.encode(reference)
141
201
  return urlInfo
142
202
  } catch (error) {
143
- throw createResolveError({
203
+ throw createResolveUrlError({
144
204
  pluginController,
145
205
  reference,
146
206
  error,
@@ -156,8 +216,7 @@ export const createKitchen = ({
156
216
  const sourcemapReference = createReference({
157
217
  trace: `sourcemap comment placeholder for ${urlInfo.url}`,
158
218
  type: "sourcemap_comment",
159
- subtype:
160
- urlInfo.contentType === "application/javascript" ? "js" : "css",
219
+ subtype: urlInfo.contentType === "text/javascript" ? "js" : "css",
161
220
  parentUrl: urlInfo.url,
162
221
  specifier,
163
222
  })
@@ -185,69 +244,77 @@ export const createKitchen = ({
185
244
  },
186
245
  })
187
246
 
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 }) => {
247
+ const fetchUrlContent = async ({ reference, urlInfo, context }) => {
248
+ if (reference.external) {
249
+ urlInfo.external = true
250
+ return
251
+ }
197
252
  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")
253
+ const returnValue = await pluginController.callAsyncHooksUntil(
254
+ "fetchUrlContent",
255
+ urlInfo,
256
+ context,
257
+ )
258
+ if (!returnValue) {
259
+ logger.warn(
260
+ createDetailedMessage(
261
+ `no plugin has handled the url during "fetchUrlContent" hook -> consider url as external (ignore it)`,
262
+ {
263
+ "url": urlInfo.url,
264
+ "url reference trace": reference.trace,
265
+ },
266
+ ),
267
+ )
268
+ urlInfo.external = true
269
+ return
270
+ }
271
+ if (returnValue.external) {
272
+ urlInfo.external = true
273
+ return
203
274
  }
204
-
205
275
  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
276
  data,
213
- } = loadReturnValue
214
- Object.assign(urlInfo, {
215
- contentType,
277
+ type,
278
+ subtype,
279
+ contentType = "application/octet-stream",
216
280
  originalContent,
217
281
  content,
218
282
  sourcemap,
219
- })
283
+ filename,
284
+ } = returnValue
285
+ urlInfo.type =
286
+ type ||
287
+ reference.expectedType ||
288
+ inferUrlInfoType({
289
+ url: urlInfo.url,
290
+ contentType,
291
+ })
292
+ urlInfo.subtype =
293
+ subtype ||
294
+ reference.expectedSubtype ||
295
+ inferUrlInfoSubtype({
296
+ url: urlInfo.url,
297
+ type: urlInfo.type,
298
+ subtype: urlInfo.subtype,
299
+ })
300
+ urlInfo.contentType = contentType
301
+ // during build urls info are reused and load returns originalContent
302
+ urlInfo.originalContent =
303
+ originalContent === undefined ? content : originalContent
304
+ urlInfo.content = content
305
+ urlInfo.sourcemap = sourcemap
220
306
  if (data) {
221
307
  Object.assign(urlInfo.data, data)
222
308
  }
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
- }
309
+ if (filename) {
310
+ urlInfo.filename = filename
248
311
  }
312
+ assertFetchedContentCompliance({
313
+ reference,
314
+ urlInfo,
315
+ })
249
316
  } catch (error) {
250
- throw createLoadError({
317
+ throw createFetchUrlContentError({
251
318
  pluginController,
252
319
  urlInfo,
253
320
  reference,
@@ -255,9 +322,8 @@ export const createKitchen = ({
255
322
  })
256
323
  }
257
324
  urlInfo.generatedUrl = determineFileUrlForOutDirectory({
258
- rootDirectoryUrl,
259
- outDirectoryUrl: context.outDirectoryUrl,
260
- url: urlInfo.url,
325
+ urlInfo,
326
+ context,
261
327
  })
262
328
  await urlInfoTransformer.initTransformations(urlInfo, context)
263
329
  }
@@ -266,34 +332,39 @@ export const createKitchen = ({
266
332
  reference,
267
333
  urlInfo,
268
334
  outDirectoryUrl,
269
- runtimeSupport,
335
+ // during dev/test clientRuntimeCompat is a single runtime
336
+ // during build clientRuntimeCompat is runtimeCompat
337
+ clientRuntimeCompat = runtimeCompat,
270
338
  cookDuringCook = cook,
271
339
  }) => {
272
340
  const context = {
273
341
  ...baseContext,
274
342
  reference,
275
343
  outDirectoryUrl,
276
- runtimeSupport,
277
- isSupportedOnRuntime: (featureName, featureCompat) => {
278
- return isSupported({ runtimeSupport, featureName, featureCompat })
344
+ clientRuntimeCompat,
345
+ isSupportedOnCurrentClients: (feature) => {
346
+ return RUNTIME_COMPAT.isSupported(clientRuntimeCompat, feature)
279
347
  },
280
348
  cook: (params) => {
281
349
  return cookDuringCook({
282
350
  outDirectoryUrl,
283
- runtimeSupport,
351
+ clientRuntimeCompat,
284
352
  ...params,
285
353
  })
286
354
  },
287
- load: (params) => {
288
- return load({
355
+ fetchUrlContent: (params) => {
356
+ return fetchUrlContent({
289
357
  context,
290
358
  ...params,
291
359
  })
292
360
  },
293
361
  }
294
362
 
295
- // "load" hook
296
- await load({ reference, urlInfo, context })
363
+ // "fetchUrlContent" hook
364
+ await fetchUrlContent({ reference, urlInfo, context })
365
+ if (urlInfo.external) {
366
+ return
367
+ }
297
368
 
298
369
  // parsing
299
370
  const references = []
@@ -303,182 +374,146 @@ export const createKitchen = ({
303
374
  ...props,
304
375
  })
305
376
  references.push(reference)
306
- return [reference, resolveReference(reference)]
377
+ const referencedUrlInfo = resolveReference(reference)
378
+ return [reference, referencedUrlInfo]
307
379
  }
308
380
  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(),
381
+ readGeneratedSpecifier: async (reference) => {
382
+ // "formatReferencedUrl" can be async BUT this is an exception
383
+ // for most cases it will be sync. We want to favor the sync signature to keep things simpler
384
+ // The only case where it needs to be async is when
385
+ // the specifier is a `data:*` url
386
+ // in this case we'll wait for the promise returned by
387
+ // "formatReferencedUrl"
388
+ if (reference.generatedSpecifier.then) {
389
+ return reference.generatedSpecifier.then((value) => {
390
+ reference.generatedSpecifier = value
391
+ return value
326
392
  })
327
393
  }
394
+ return reference.generatedSpecifier
395
+ },
396
+ found: ({ line, column, ...rest }) => {
397
+ const trace = stringifyUrlSite(
398
+ adjustUrlSite(urlInfo, {
399
+ urlGraph,
400
+ url: urlInfo.url,
401
+ line,
402
+ column,
403
+ }),
404
+ )
405
+ // console.log(trace)
328
406
  return addReference({
329
407
  trace,
408
+ line,
409
+ column,
330
410
  ...rest,
331
411
  })
332
412
  },
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
413
+ foundInline: ({ isOriginalPosition, line, column, ...rest }) => {
414
+ const parentUrl = isOriginalPosition
415
+ ? urlInfo.url
416
+ : urlInfo.generatedUrl
417
+ const parentContent = isOriginalPosition
344
418
  ? urlInfo.originalContent
345
419
  : urlInfo.content
346
- const [inlineReference, inlineUrlInfo] = addReference({
420
+ return addReference({
347
421
  trace: stringifyUrlSite({
348
422
  url: parentUrl,
349
423
  content: parentContent,
350
424
  line,
351
425
  column,
352
426
  }),
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,
427
+ isOriginalPosition,
363
428
  line,
364
429
  column,
365
- }
366
- inlineUrlInfo.contentType = contentType
367
- inlineUrlInfo.originalContent = inlineUrlInfo.content = content
368
- return [inlineReference, inlineUrlInfo]
430
+ isInline: true,
431
+ ...rest,
432
+ })
369
433
  },
370
- updateSpecifier: (generatedSpecifier, newSpecifier, data) => {
371
- const index = references.findIndex(
372
- (ref) => ref.generatedSpecifier === generatedSpecifier,
373
- )
434
+ update: (currentReference, newReferenceParams) => {
435
+ const index = references.indexOf(currentReference)
374
436
  if (index === -1) {
375
- throw new Error(
376
- `Cannot find a reference for the following generatedSpecifier "${generatedSpecifier}"`,
377
- )
437
+ throw new Error(`reference do not exists`)
378
438
  }
379
- const referenceFound = references[index]
380
- const newReference = createReference({
381
- ...referenceFound,
382
- specifier: newSpecifier,
383
- data: {
384
- ...referenceFound.data,
385
- ...data,
386
- },
439
+ const previousReference = currentReference
440
+ const nextReference = createReference({
441
+ ...previousReference,
442
+ ...newReferenceParams,
387
443
  })
388
- references[index] = newReference
389
- newReference.data.originalReference = referenceFound
390
- const newUrlInfo = resolveReference(newReference)
391
- return [newReference, newUrlInfo]
444
+ references[index] = nextReference
445
+ mutateReference(previousReference, nextReference)
446
+ const newUrlInfo = resolveReference(nextReference)
447
+ const currentUrlInfo = context.urlGraph.getUrlInfo(currentReference.url)
448
+ if (
449
+ currentUrlInfo &&
450
+ currentUrlInfo !== newUrlInfo &&
451
+ currentUrlInfo.dependents.size === 0
452
+ ) {
453
+ delete context.urlGraph.urlInfos[currentReference.url]
454
+ }
455
+ return [nextReference, newUrlInfo]
392
456
  },
393
457
  becomesInline: (
394
458
  reference,
395
- { isOriginal, line, column, specifier, contentType, content },
459
+ { isOriginalPosition, line, column, specifier, contentType, content },
396
460
  ) => {
397
- const parentUrl = isOriginal ? urlInfo.url : urlInfo.generatedUrl
398
- const parentContent = isOriginal
461
+ const parentUrl = isOriginalPosition
462
+ ? urlInfo.url
463
+ : urlInfo.generatedUrl
464
+ const parentContent = isOriginalPosition
399
465
  ? urlInfo.originalContent
400
466
  : urlInfo.content
401
- reference.trace = stringifyUrlSite({
402
- url: parentUrl,
403
- content: parentContent,
404
- line,
405
- column,
467
+ return referenceUtils.update(reference, {
468
+ trace: stringifyUrlSite({
469
+ url: parentUrl,
470
+ content: parentContent,
471
+ line,
472
+ column,
473
+ }),
474
+ isOriginalPosition,
475
+ isInline: true,
476
+ specifier,
477
+ contentType,
478
+ content,
406
479
  })
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
480
  },
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
481
+ inject: ({ trace, ...rest }) => {
482
+ if (trace === undefined) {
483
+ const { prepareStackTrace } = Error
484
+ Error.prepareStackTrace = (error, stack) => {
485
+ Error.prepareStackTrace = prepareStackTrace
486
+ return stack
487
+ }
488
+ const { stack } = new Error()
489
+ const callerCallsite = stack[1]
490
+ const fileName = callerCallsite.getFileName()
491
+ trace = stringifyUrlSite({
492
+ url:
493
+ fileName && isFileSystemPath(fileName)
494
+ ? fileSystemPathToUrl(fileName)
495
+ : fileName,
496
+ line: callerCallsite.getLineNumber(),
497
+ column: callerCallsite.getColumnNumber(),
498
+ })
499
+ }
500
+ return addReference({
501
+ trace,
502
+ injected: true,
503
+ ...rest,
476
504
  })
477
- await urlInfoTransformer.applyIntermediateTransformations(
478
- urlInfo,
479
- replaceReturnValue,
505
+ },
506
+ findByGeneratedSpecifier: (generatedSpecifier) => {
507
+ const reference = references.find(
508
+ (ref) => ref.generatedSpecifier === generatedSpecifier,
480
509
  )
481
- }
510
+ if (!reference) {
511
+ throw new Error(
512
+ `No reference found using the following generatedSpecifier: "${generatedSpecifier}"`,
513
+ )
514
+ }
515
+ return reference
516
+ },
482
517
  }
483
518
 
484
519
  // "transform" hook
@@ -486,7 +521,7 @@ export const createKitchen = ({
486
521
  context.referenceUtils = referenceUtils
487
522
  try {
488
523
  await pluginController.callAsyncHooks(
489
- "transform",
524
+ "transformUrlContent",
490
525
  urlInfo,
491
526
  context,
492
527
  async (transformReturnValue) => {
@@ -497,7 +532,7 @@ export const createKitchen = ({
497
532
  },
498
533
  )
499
534
  } catch (error) {
500
- throw createTransformError({
535
+ throw createTransformUrlContentError({
501
536
  pluginController,
502
537
  reference,
503
538
  urlInfo,
@@ -509,15 +544,24 @@ export const createKitchen = ({
509
544
  urlGraph.updateReferences(urlInfo, references)
510
545
 
511
546
  // "finalize" hook
512
- const finalizeReturnValue = await pluginController.callHooksUntil(
513
- "finalize",
514
- urlInfo,
515
- context,
516
- )
517
- await urlInfoTransformer.applyFinalTransformations(
518
- urlInfo,
519
- finalizeReturnValue,
520
- )
547
+ try {
548
+ const finalizeReturnValue = await pluginController.callAsyncHooksUntil(
549
+ "finalizeUrlContent",
550
+ urlInfo,
551
+ context,
552
+ )
553
+ await urlInfoTransformer.applyFinalTransformations(
554
+ urlInfo,
555
+ finalizeReturnValue,
556
+ )
557
+ } catch (error) {
558
+ throw createFinalizeUrlContentError({
559
+ pluginController,
560
+ reference,
561
+ urlInfo,
562
+ error,
563
+ })
564
+ }
521
565
 
522
566
  // "cooked" hook
523
567
  pluginController.callHooks(
@@ -580,15 +624,58 @@ export const createKitchen = ({
580
624
 
581
625
  baseContext.cook = cook
582
626
 
627
+ const prepareEntryPoint = (params) => {
628
+ const entryReference = createReference(params)
629
+ const entryUrlInfo = resolveReference(entryReference)
630
+ return [entryReference, entryUrlInfo]
631
+ }
632
+
633
+ const injectReference = (params) => {
634
+ const ref = createReference(params)
635
+ const urlInfo = resolveReference(ref)
636
+ return [ref, urlInfo]
637
+ }
638
+
583
639
  return {
584
640
  pluginController,
585
641
  urlInfoTransformer,
586
642
  rootDirectoryUrl,
587
643
  jsenvDirectoryUrl,
588
- isSupported,
589
- createReference,
590
- resolveReference,
644
+ baseContext,
591
645
  cook,
646
+ prepareEntryPoint,
647
+ injectReference,
648
+ }
649
+ }
650
+
651
+ const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
652
+ Object.assign(urlInfo.data, reference.data)
653
+ if (reference.injected) {
654
+ urlInfo.data.injected = true
655
+ }
656
+ if (reference.filename) {
657
+ urlInfo.filename = reference.filename
658
+ }
659
+ if (reference.isInline) {
660
+ urlInfo.isInline = true
661
+ const parentUrlInfo = context.urlGraph.getUrlInfo(reference.parentUrl)
662
+ urlInfo.inlineUrlSite = {
663
+ url: parentUrlInfo.url,
664
+ content: reference.isOriginalPosition
665
+ ? parentUrlInfo.originalContent
666
+ : parentUrlInfo.content,
667
+ line: reference.line,
668
+ column: reference.column,
669
+ }
670
+ urlInfo.contentType = reference.contentType
671
+ urlInfo.originalContent =
672
+ urlInfo.originalContent === undefined
673
+ ? reference.content
674
+ : urlInfo.originalContent
675
+ urlInfo.content = reference.content
676
+ }
677
+ if (isWebWorkerEntryPointReference(reference)) {
678
+ urlInfo.data.isWebWorkerEntryPoint = true
592
679
  }
593
680
  }
594
681
 
@@ -626,54 +713,85 @@ const adjustUrlSite = (urlInfo, { urlGraph, url, line, column }) => {
626
713
  )
627
714
  }
628
715
 
629
- const inferUrlInfoType = ({ contentType }) => {
716
+ const inferUrlInfoType = ({ url, contentType }) => {
630
717
  if (contentType === "text/html") {
631
718
  return "html"
632
719
  }
633
720
  if (contentType === "text/css") {
634
721
  return "css"
635
722
  }
636
- if (contentType === "application/javascript") {
637
- return "js"
638
- }
639
- if (contentType === "application/json") {
640
- return "json"
723
+ if (contentType === "text/javascript") {
724
+ const urlObject = new URL(url)
725
+ if (urlObject.searchParams.has("js_classic")) {
726
+ return "js_classic"
727
+ }
728
+ return "js_module"
641
729
  }
642
730
  if (contentType === "application/importmap+json") {
643
731
  return "importmap"
644
732
  }
733
+ if (contentType === "application/manifest+json") {
734
+ return "webmanifest"
735
+ }
736
+ if (contentType === "image/svg+xml") {
737
+ return "svg"
738
+ }
739
+ if (CONTENT_TYPE.isJson(contentType)) {
740
+ return "json"
741
+ }
742
+ if (CONTENT_TYPE.isTextual(contentType)) {
743
+ return "text"
744
+ }
645
745
  return "other"
646
746
  }
647
747
 
648
- const determineFileUrlForOutDirectory = ({
649
- rootDirectoryUrl,
650
- outDirectoryUrl,
651
- url,
652
- }) => {
653
- if (!outDirectoryUrl) {
654
- return url
748
+ const inferUrlInfoSubtype = ({ type, subtype, url }) => {
749
+ if (type === "js_classic" || type === "js_module") {
750
+ const urlObject = new URL(url)
751
+ if (urlObject.searchParams.has("worker")) {
752
+ return "worker"
753
+ }
754
+ if (urlObject.searchParams.has("service_worker")) {
755
+ return "service_worker"
756
+ }
757
+ if (urlObject.searchParams.has("shared_worker")) {
758
+ return "shared_worker"
759
+ }
760
+ // if we are currently inside a worker, all deps are consider inside worker too
761
+ return subtype
762
+ }
763
+ return ""
764
+ }
765
+
766
+ const determineFileUrlForOutDirectory = ({ urlInfo, context }) => {
767
+ if (!context.outDirectoryUrl) {
768
+ return urlInfo.url
769
+ }
770
+ if (!urlInfo.url.startsWith("file:")) {
771
+ return urlInfo.url
655
772
  }
656
- if (!url.startsWith("file:")) {
657
- return url
773
+ let url = urlInfo.url
774
+ if (!urlIsInsideOf(urlInfo.url, context.rootDirectoryUrl)) {
775
+ url = `${context.rootDirectoryUrl}@fs/${url.slice("file:///".length)}`
658
776
  }
659
- if (!urlIsInsideOf(url, rootDirectoryUrl)) {
660
- url = `${rootDirectoryUrl}@fs/${url.slice(fileSystemRootUrl.length)}`
777
+ if (urlInfo.filename) {
778
+ url = setUrlFilename(url, urlInfo.filename)
661
779
  }
662
780
  return moveUrl({
663
- url: fileUrlConverter.asUrlWithoutSpecialParams(url),
664
- from: rootDirectoryUrl,
665
- to: outDirectoryUrl,
781
+ url,
782
+ from: context.rootDirectoryUrl,
783
+ to: context.outDirectoryUrl,
666
784
  preferAbsolute: true,
667
785
  })
668
786
  }
669
787
 
670
- const specifierFormat = {
788
+ const urlSpecifierFormat = {
671
789
  encode: (reference) => {
672
790
  const { generatedSpecifier } = reference
673
791
  if (generatedSpecifier.then) {
674
792
  return generatedSpecifier.then((value) => {
675
793
  reference.generatedSpecifier = value
676
- return specifierFormat.encode(reference)
794
+ return urlSpecifierFormat.encode(reference)
677
795
  })
678
796
  }
679
797
  // allow plugin to return a function to bypas default formatting
@@ -698,10 +816,11 @@ const specifierFormat = {
698
816
  },
699
817
  }
700
818
  const formatters = {
701
- js_import_export: { encode: JSON.stringify, decode: JSON.parse },
702
- js_import_meta_url_pattern: { encode: JSON.stringify, decode: JSON.parse },
819
+ "js_import_export": { encode: JSON.stringify, decode: JSON.parse },
820
+ "js_url_specifier": { encode: JSON.stringify, decode: JSON.parse },
821
+ "css_@import": { encode: JSON.stringify, code: JSON.stringify },
703
822
  // https://github.com/webpack-contrib/css-loader/pull/627/files
704
- css_url: {
823
+ "css_url": {
705
824
  encode: (url) => {
706
825
  // If url is already wrapped in quotes, remove them
707
826
  url = formatters.css_url.decode(url)