@jsenv/core 27.0.0-alpha.63 → 27.0.0-alpha.66

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 (170) hide show
  1. package/dist/babel_helpers/AsyncGenerator/AsyncGenerator.js +95 -0
  2. package/dist/babel_helpers/AwaitValue/AwaitValue.js +3 -0
  3. package/dist/babel_helpers/applyDecoratorDescriptor/applyDecoratorDescriptor.js +29 -0
  4. package/dist/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +9 -0
  5. package/dist/babel_helpers/arrayWithHoles/arrayWithHoles.js +4 -0
  6. package/dist/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +5 -0
  7. package/dist/babel_helpers/assertThisInitialized/assertThisInitialized.js +8 -0
  8. package/dist/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +52 -0
  9. package/dist/babel_helpers/asyncIterator/asyncIterator.js +78 -0
  10. package/dist/babel_helpers/asyncToGenerator/asyncToGenerator.js +39 -0
  11. package/dist/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +4 -0
  12. package/dist/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +24 -0
  13. package/dist/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +7 -0
  14. package/dist/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +14 -0
  15. package/dist/babel_helpers/classCallCheck/classCallCheck.js +5 -0
  16. package/dist/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -0
  17. package/dist/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -0
  18. package/dist/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +8 -0
  19. package/dist/babel_helpers/classNameTDZError/classNameTDZError.js +4 -0
  20. package/dist/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +6 -0
  21. package/dist/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +6 -0
  22. package/dist/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +7 -0
  23. package/dist/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -0
  24. package/dist/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +7 -0
  25. package/dist/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +7 -0
  26. package/dist/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +3 -0
  27. package/dist/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +8 -0
  28. package/dist/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +9 -0
  29. package/dist/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +5 -0
  30. package/dist/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -0
  31. package/dist/babel_helpers/construct/construct.js +15 -0
  32. package/dist/babel_helpers/createClass/createClass.js +18 -0
  33. package/dist/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +63 -0
  34. package/dist/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +22 -0
  35. package/dist/babel_helpers/createRawReactElement/createRawReactElement.js +50 -0
  36. package/dist/babel_helpers/createSuper/createSuper.js +22 -0
  37. package/dist/babel_helpers/decorate/decorate.js +622 -0
  38. package/dist/babel_helpers/defaults/defaults.js +14 -0
  39. package/dist/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +26 -0
  40. package/dist/babel_helpers/defineProperty/defineProperty.js +19 -0
  41. package/dist/babel_helpers/extends/extends.js +16 -0
  42. package/dist/babel_helpers/get/get.js +21 -0
  43. package/dist/babel_helpers/getPrototypeOf/getPrototypeOf.js +2 -0
  44. package/dist/babel_helpers/inherits/inherits.js +21 -0
  45. package/dist/babel_helpers/inheritsLoose/inheritsLoose.js +6 -0
  46. package/dist/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +10 -0
  47. package/dist/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +3 -0
  48. package/dist/babel_helpers/instanceof/instanceof.js +7 -0
  49. package/dist/babel_helpers/interopRequireDefault/interopRequireDefault.js +5 -0
  50. package/dist/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +49 -0
  51. package/dist/babel_helpers/isNativeFunction/isNativeFunction.js +4 -0
  52. package/dist/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -0
  53. package/dist/babel_helpers/iterableToArray/iterableToArray.js +3 -0
  54. package/dist/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +38 -0
  55. package/dist/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +13 -0
  56. package/dist/babel_helpers/jsx/jsx.js +49 -0
  57. package/dist/babel_helpers/maybeArrayLike/maybeArrayLike.js +10 -0
  58. package/dist/babel_helpers/newArrowCheck/newArrowCheck.js +5 -0
  59. package/dist/babel_helpers/nonIterableRest/nonIterableRest.js +3 -0
  60. package/dist/babel_helpers/nonIterableSpread/nonIterableSpread.js +3 -0
  61. package/dist/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -0
  62. package/dist/babel_helpers/objectSpread/objectSpread.js +22 -0
  63. package/dist/babel_helpers/objectSpread2/objectSpread2.js +41 -0
  64. package/dist/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +20 -0
  65. package/dist/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +15 -0
  66. package/dist/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +10 -0
  67. package/dist/babel_helpers/readOnlyError/readOnlyError.js +4 -0
  68. package/dist/babel_helpers/readme.md +8 -0
  69. package/dist/babel_helpers/set/set.js +51 -0
  70. package/dist/babel_helpers/setPrototypeOf/setPrototypeOf.js +5 -0
  71. package/dist/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -0
  72. package/dist/babel_helpers/slicedToArray/slicedToArray.js +5 -0
  73. package/dist/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +7 -0
  74. package/dist/babel_helpers/superPropBase/superPropBase.js +10 -0
  75. package/dist/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +11 -0
  76. package/dist/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +8 -0
  77. package/dist/babel_helpers/tdz/tdz.js +4 -0
  78. package/dist/babel_helpers/temporalRef/temporalRef.js +5 -0
  79. package/dist/babel_helpers/temporalUndefined/temporalUndefined.js +3 -0
  80. package/dist/babel_helpers/toArray/toArray.js +5 -0
  81. package/dist/babel_helpers/toConsumableArray/toConsumableArray.js +5 -0
  82. package/dist/babel_helpers/toPrimitive/toPrimitive.js +14 -0
  83. package/dist/babel_helpers/toPropertyKey/toPropertyKey.js +5 -0
  84. package/dist/babel_helpers/typeof/typeof.js +7 -0
  85. package/dist/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +10 -0
  86. package/dist/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +7 -0
  87. package/dist/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +35 -0
  88. package/dist/babel_helpers/wrapRegExp/wrapRegExp.js +67 -0
  89. package/dist/babel_helpers/writeOnlyError/writeOnlyError.js +4 -0
  90. package/dist/html/explorer.html +557 -0
  91. package/dist/js/controllable_file.mjs +227 -0
  92. package/dist/{event_source_client.js → js/event_source_client.js} +19 -244
  93. package/dist/js/global_this.js +32 -0
  94. package/dist/js/html_supervisor_installer.js +522 -0
  95. package/dist/js/html_supervisor_setup.js +79 -0
  96. package/dist/{import_meta_hot.js → js/import_meta_hot.js} +1 -3
  97. package/dist/js/inline_content.js +8 -0
  98. package/dist/js/new_stylesheet.js +409 -0
  99. package/dist/js/regenerator_runtime.js +721 -0
  100. package/dist/js/s.js +429 -0
  101. package/dist/main.js +13383 -0
  102. package/dist/other/jsenv.png +0 -0
  103. package/main.js +1 -0
  104. package/package.json +18 -14
  105. package/src/build/build.js +175 -69
  106. package/src/build/build_urls_generator.js +18 -2
  107. package/src/build/inject_global_version_mappings.js +18 -5
  108. package/src/build/inject_service_worker_urls.js +1 -1
  109. package/src/build/resync_ressource_hints.js +56 -9
  110. package/src/build/start_build_server.js +38 -29
  111. package/src/dev/plugins/explorer/client/explorer.html +1 -1
  112. package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +1 -1
  113. package/src/dev/start_dev_server.js +18 -4
  114. package/src/execute/execute.js +3 -0
  115. package/src/execute/runtimes/browsers/from_playwright.js +10 -0
  116. package/src/execute/runtimes/node/node_process.js +8 -0
  117. package/src/omega/errors.js +10 -7
  118. package/src/omega/kitchen.js +251 -340
  119. package/src/omega/server/file_service.js +34 -17
  120. package/src/omega/url_graph/url_graph_load.js +10 -17
  121. package/src/omega/url_graph/url_graph_report.js +2 -2
  122. package/src/omega/url_graph/url_info_transformations.js +1 -4
  123. package/src/omega/url_graph.js +7 -3
  124. package/src/omega/url_specifier_encoding.js +59 -0
  125. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +5 -10
  126. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +1 -3
  127. package/src/plugins/bundling/js_module/bundle_js_module.js +66 -24
  128. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +178 -53
  129. package/src/plugins/html_supervisor/client/html_supervisor_installer.js +1 -1
  130. package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +9 -13
  131. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +6 -6
  132. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +5 -10
  133. package/src/plugins/importmap/jsenv_plugin_importmap.js +2 -4
  134. package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +51 -42
  135. package/src/plugins/inline/jsenv_plugin_data_urls.js +1 -4
  136. package/src/plugins/inline/jsenv_plugin_html_inline_content.js +3 -5
  137. package/src/plugins/inline/jsenv_plugin_inline_query_param.js +1 -4
  138. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +1 -4
  139. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +16 -2
  140. package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +12 -0
  141. package/src/plugins/plugin_controller.js +17 -3
  142. package/src/plugins/plugins.js +15 -15
  143. package/src/plugins/transpilation/as_js_classic/client/s.js +362 -807
  144. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +20 -10
  145. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +302 -0
  146. package/src/plugins/transpilation/as_js_classic/{jsenv_plugin_workers_type_module_as_classic.js → jsenv_plugin_as_js_classic_workers.js} +2 -2
  147. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +5 -2
  148. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +1 -2
  149. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +2 -0
  150. package/src/plugins/url_analysis/html/html_urls.js +3 -0
  151. package/src/plugins/url_analysis/js/js_urls.js +2 -1
  152. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +94 -1
  153. package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +3 -0
  154. package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +0 -3
  155. package/src/test/execute_plan.js +34 -13
  156. package/src/test/execute_test_plan.js +2 -0
  157. package/src/test/logs_file_execution.js +47 -38
  158. package/dist/event_source_client.js.map +0 -188
  159. package/dist/html_supervisor_installer.js +0 -1236
  160. package/dist/html_supervisor_installer.js.map +0 -337
  161. package/dist/html_supervisor_setup.js +0 -95
  162. package/dist/html_supervisor_setup.js.map +0 -57
  163. package/dist/import_meta_hot.js.map +0 -42
  164. package/src/jsenv_root_directory_url.js +0 -1
  165. package/src/omega/compat/default_runtime_compat.js +0 -11
  166. package/src/plugins/filesystem_magic/jsenv_plugin_filesystem_magic.js +0 -61
  167. package/src/plugins/transpilation/as_js_classic/client/s.js.md +0 -1
  168. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +0 -270
  169. package/src/plugins/transpilation/babel/new_stylesheet/client/.eslintrc.cjs +0 -24
  170. package/src/plugins/transpilation/fetch_original_url_info.js +0 -30
@@ -12,9 +12,9 @@ import { CONTENT_TYPE } from "@jsenv/utils/content_type/content_type.js"
12
12
  import { normalizeUrl, setUrlFilename } from "@jsenv/utils/urls/url_utils.js"
13
13
 
14
14
  import { createPluginController } from "../plugins/plugin_controller.js"
15
+ import { urlSpecifierEncoding } from "./url_specifier_encoding.js"
15
16
  import { createUrlInfoTransformer } from "./url_graph/url_info_transformations.js"
16
17
  import { RUNTIME_COMPAT } from "./compat/runtime_compat.js"
17
- import { defaultRuntimeCompat } from "./compat/default_runtime_compat.js"
18
18
  import {
19
19
  createResolveUrlError,
20
20
  createFetchUrlContentError,
@@ -45,7 +45,7 @@ export const createKitchen = ({
45
45
  build: true,
46
46
  }[scenario],
47
47
  sourcemapsRelativeSources,
48
- runtimeCompat = defaultRuntimeCompat,
48
+ runtimeCompat,
49
49
  writeGeneratedFiles,
50
50
  }) => {
51
51
  const pluginController = createPluginController({
@@ -53,7 +53,7 @@ export const createKitchen = ({
53
53
  scenario,
54
54
  })
55
55
  const jsenvDirectoryUrl = new URL(".jsenv/", rootDirectoryUrl).href
56
- const baseContext = {
56
+ const kitchenContext = {
57
57
  signal,
58
58
  logger,
59
59
  rootDirectoryUrl,
@@ -85,7 +85,7 @@ export const createKitchen = ({
85
85
  specifierColumn,
86
86
  baseUrl,
87
87
  isOriginalPosition,
88
- external = false,
88
+ shouldHandle,
89
89
  isInline = false,
90
90
  injected = false,
91
91
  isRessourceHint = false,
@@ -121,7 +121,7 @@ export const createKitchen = ({
121
121
  specifierColumn,
122
122
  baseUrl,
123
123
  isOriginalPosition,
124
- external,
124
+ shouldHandle,
125
125
  isInline,
126
126
  injected,
127
127
  isRessourceHint,
@@ -144,22 +144,17 @@ export const createKitchen = ({
144
144
  let resolvedUrl = pluginController.callHooksUntil(
145
145
  "resolveUrl",
146
146
  reference,
147
- baseContext,
147
+ kitchenContext,
148
148
  )
149
149
  if (!resolvedUrl) {
150
150
  throw new Error(`NO_RESOLVE`)
151
151
  }
152
152
  resolvedUrl = normalizeUrl(resolvedUrl)
153
153
  reference.url = resolvedUrl
154
- if (reference.external) {
155
- reference.generatedUrl = resolvedUrl
156
- reference.generatedSpecifier = reference.specifier
157
- return urlGraph.reuseOrCreateUrlInfo(reference.url)
158
- }
159
154
  pluginController.callHooks(
160
155
  "redirectUrl",
161
156
  reference,
162
- baseContext,
157
+ kitchenContext,
163
158
  (returnValue) => {
164
159
  const normalizedReturnValue = normalizeUrl(returnValue)
165
160
  if (normalizedReturnValue === reference.url) {
@@ -172,7 +167,7 @@ export const createKitchen = ({
172
167
  )
173
168
 
174
169
  const urlInfo = urlGraph.reuseOrCreateUrlInfo(reference.url)
175
- applyReferenceEffectsOnUrlInfo(reference, urlInfo, baseContext)
170
+ applyReferenceEffectsOnUrlInfo(reference, urlInfo, kitchenContext)
176
171
 
177
172
  const referenceUrlObject = new URL(reference.url)
178
173
  reference.searchParams = referenceUrlObject.searchParams
@@ -186,7 +181,7 @@ export const createKitchen = ({
186
181
  pluginController.callHooks(
187
182
  "transformUrlSearchParams",
188
183
  reference,
189
- baseContext,
184
+ kitchenContext,
190
185
  (returnValue) => {
191
186
  Object.keys(returnValue).forEach((key) => {
192
187
  referenceUrlObject.searchParams.set(key, returnValue[key])
@@ -197,10 +192,10 @@ export const createKitchen = ({
197
192
  const returnValue = pluginController.callHooksUntil(
198
193
  "formatUrl",
199
194
  reference,
200
- baseContext,
195
+ kitchenContext,
201
196
  )
202
197
  reference.generatedSpecifier = returnValue || reference.generatedUrl
203
- reference.generatedSpecifier = urlSpecifierFormat.encode(reference)
198
+ reference.generatedSpecifier = urlSpecifierEncoding.encode(reference)
204
199
  return urlInfo
205
200
  } catch (error) {
206
201
  throw createResolveUrlError({
@@ -210,7 +205,7 @@ export const createKitchen = ({
210
205
  })
211
206
  }
212
207
  }
213
- baseContext.resolveReference = resolveReference
208
+ kitchenContext.resolveReference = resolveReference
214
209
  const urlInfoTransformer = createUrlInfoTransformer({
215
210
  logger,
216
211
  urlGraph,
@@ -257,11 +252,7 @@ export const createKitchen = ({
257
252
  },
258
253
  })
259
254
 
260
- const fetchUrlContent = async ({ reference, urlInfo, context }) => {
261
- if (reference.external) {
262
- urlInfo.external = true
263
- return
264
- }
255
+ const fetchUrlContent = async (urlInfo, { reference, context }) => {
265
256
  try {
266
257
  const fetchUrlContentReturnValue =
267
258
  await pluginController.callAsyncHooksUntil(
@@ -272,18 +263,13 @@ export const createKitchen = ({
272
263
  if (!fetchUrlContentReturnValue) {
273
264
  logger.warn(
274
265
  createDetailedMessage(
275
- `no plugin has handled the url during "fetchUrlContent" hook -> consider url as external (ignore it)`,
266
+ `no plugin has handled url during "fetchUrlContent" hook -> url will be ignored`,
276
267
  {
277
268
  "url": urlInfo.url,
278
269
  "url reference trace": reference.trace,
279
270
  },
280
271
  ),
281
272
  )
282
- urlInfo.external = true
283
- return
284
- }
285
- if (fetchUrlContentReturnValue.external) {
286
- urlInfo.external = true
287
273
  return
288
274
  }
289
275
  const {
@@ -342,238 +328,231 @@ export const createKitchen = ({
342
328
  await urlInfoTransformer.initTransformations(urlInfo, context)
343
329
  }
344
330
 
345
- const _cook = async ({
346
- reference,
347
- urlInfo,
348
- outDirectoryUrl,
331
+ const _cook = async (urlInfo, dishContext) => {
349
332
  // during dev/test clientRuntimeCompat is a single runtime
350
333
  // during build clientRuntimeCompat is runtimeCompat
351
- clientRuntimeCompat = runtimeCompat,
352
- cookDuringCook = cook,
353
- }) => {
354
- baseContext.isSupportedOnCurrentClients = (feature) => {
334
+ const { clientRuntimeCompat = runtimeCompat } = dishContext
335
+ kitchenContext.isSupportedOnCurrentClients = (feature) => {
355
336
  return RUNTIME_COMPAT.isSupported(clientRuntimeCompat, feature)
356
337
  }
357
338
  const context = {
358
- ...baseContext,
359
- reference,
360
- outDirectoryUrl,
339
+ ...kitchenContext,
340
+ ...dishContext,
361
341
  clientRuntimeCompat,
362
- cook: (params) => {
363
- return cookDuringCook({
364
- outDirectoryUrl,
365
- clientRuntimeCompat,
366
- ...params,
367
- })
368
- },
369
- fetchUrlContent: (params) => {
370
- return fetchUrlContent({
371
- context,
372
- ...params,
373
- })
374
- },
375
342
  }
376
-
377
- // "fetchUrlContent" hook
378
- await fetchUrlContent({ reference, urlInfo, context })
379
- if (urlInfo.external) {
380
- return
381
- }
382
-
383
- // parsing
384
- const references = []
385
- const addReference = (props) => {
386
- const reference = createReference({
387
- parentUrl: urlInfo.url,
388
- ...props,
343
+ const { cookDuringCook = cook } = dishContext
344
+ context.cook = (urlInfo, nestedDishContext) => {
345
+ return cookDuringCook(urlInfo, {
346
+ outDirectoryUrl: dishContext.outDirectoryUrl,
347
+ clientRuntimeCompat: dishContext.clientRuntimeCompat,
348
+ ...nestedDishContext,
389
349
  })
390
- references.push(reference)
391
- const referencedUrlInfo = resolveReference(reference)
392
- return [reference, referencedUrlInfo]
393
350
  }
394
- const referenceUtils = {
395
- readGeneratedSpecifier: async (reference) => {
396
- // "formatReferencedUrl" can be async BUT this is an exception
397
- // for most cases it will be sync. We want to favor the sync signature to keep things simpler
398
- // The only case where it needs to be async is when
399
- // the specifier is a `data:*` url
400
- // in this case we'll wait for the promise returned by
401
- // "formatReferencedUrl"
402
- if (reference.generatedSpecifier.then) {
403
- return reference.generatedSpecifier.then((value) => {
404
- reference.generatedSpecifier = value
405
- return value
406
- })
407
- }
408
- return reference.generatedSpecifier
409
- },
410
- found: ({ specifierLine, specifierColumn, ...rest }) => {
411
- const trace = stringifyUrlSite(
412
- adjustUrlSite(urlInfo, {
413
- urlGraph,
414
- url: urlInfo.url,
415
- line: specifierLine,
416
- column: specifierColumn,
417
- }),
418
- )
419
- // console.log(trace)
420
- return addReference({
421
- trace,
422
- specifierLine,
423
- specifierColumn,
424
- ...rest,
425
- })
426
- },
427
- foundInline: ({ isOriginalPosition, line, column, ...rest }) => {
428
- const parentUrl = isOriginalPosition
429
- ? urlInfo.url
430
- : urlInfo.generatedUrl
431
- const parentContent = isOriginalPosition
432
- ? urlInfo.originalContent
433
- : urlInfo.content
434
- return addReference({
435
- trace: stringifyUrlSite({
436
- url: parentUrl,
437
- content: parentContent,
438
- line,
439
- column,
440
- }),
441
- isOriginalPosition,
442
- line,
443
- column,
444
- isInline: true,
445
- ...rest,
446
- })
447
- },
448
- update: (currentReference, newReferenceParams) => {
449
- const index = references.indexOf(currentReference)
450
- if (index === -1) {
451
- throw new Error(`reference do not exists`)
452
- }
453
- const previousReference = currentReference
454
- const nextReference = createReference({
455
- ...previousReference,
456
- ...newReferenceParams,
351
+ context.fetchUrlContent = (urlInfo, { reference }) => {
352
+ return fetchUrlContent(urlInfo, { reference, context })
353
+ }
354
+
355
+ if (urlInfo.shouldHandle) {
356
+ // "fetchUrlContent" hook
357
+ await fetchUrlContent(urlInfo, { reference: context.reference, context })
358
+
359
+ // parsing
360
+ const references = []
361
+ const addReference = (props) => {
362
+ const reference = createReference({
363
+ parentUrl: urlInfo.url,
364
+ ...props,
457
365
  })
458
- references[index] = nextReference
459
- mutateReference(previousReference, nextReference)
460
- const newUrlInfo = resolveReference(nextReference)
461
- const currentUrlInfo = context.urlGraph.getUrlInfo(currentReference.url)
462
- if (
463
- currentUrlInfo &&
464
- currentUrlInfo !== newUrlInfo &&
465
- currentUrlInfo.dependents.size === 0
466
- ) {
467
- context.urlGraph.deleteUrlInfo(currentReference.url)
468
- }
469
- return [nextReference, newUrlInfo]
470
- },
471
- becomesInline: (
472
- reference,
473
- {
474
- isOriginalPosition,
475
- specifier,
476
- specifierLine,
477
- specifierColumn,
478
- contentType,
479
- content,
366
+ references.push(reference)
367
+ const referencedUrlInfo = resolveReference(reference)
368
+ return [reference, referencedUrlInfo]
369
+ }
370
+ const referenceUtils = {
371
+ readGeneratedSpecifier: async (reference) => {
372
+ // "formatReferencedUrl" can be async BUT this is an exception
373
+ // for most cases it will be sync. We want to favor the sync signature to keep things simpler
374
+ // The only case where it needs to be async is when
375
+ // the specifier is a `data:*` url
376
+ // in this case we'll wait for the promise returned by
377
+ // "formatReferencedUrl"
378
+ if (reference.generatedSpecifier.then) {
379
+ return reference.generatedSpecifier.then((value) => {
380
+ reference.generatedSpecifier = value
381
+ return value
382
+ })
383
+ }
384
+ return reference.generatedSpecifier
480
385
  },
481
- ) => {
482
- const parentUrl = isOriginalPosition
483
- ? urlInfo.url
484
- : urlInfo.generatedUrl
485
- const parentContent = isOriginalPosition
486
- ? urlInfo.originalContent
487
- : urlInfo.content
488
- return referenceUtils.update(reference, {
489
- trace: stringifyUrlSite({
490
- url: parentUrl,
491
- content: parentContent,
492
- line: specifierLine,
493
- column: specifierColumn,
494
- }),
495
- isOriginalPosition,
496
- isInline: true,
497
- specifier,
498
- specifierLine,
499
- specifierColumn,
500
- contentType,
501
- content,
502
- })
503
- },
504
- inject: ({ trace, ...rest }) => {
505
- if (trace === undefined) {
506
- const { url, line, column } = getCallerPosition()
507
- trace = stringifyUrlSite({
508
- url,
386
+ found: ({ trace, ...rest }) => {
387
+ if (trace === undefined) {
388
+ trace = stringifyUrlSite(
389
+ adjustUrlSite(urlInfo, {
390
+ urlGraph,
391
+ url: urlInfo.url,
392
+ line: rest.specifierLine,
393
+ column: rest.specifierColumn,
394
+ }),
395
+ )
396
+ }
397
+ // console.log(trace)
398
+ return addReference({
399
+ trace,
400
+ ...rest,
401
+ })
402
+ },
403
+ foundInline: ({ isOriginalPosition, line, column, ...rest }) => {
404
+ const parentUrl = isOriginalPosition
405
+ ? urlInfo.url
406
+ : urlInfo.generatedUrl
407
+ const parentContent = isOriginalPosition
408
+ ? urlInfo.originalContent
409
+ : urlInfo.content
410
+ return addReference({
411
+ trace: stringifyUrlSite({
412
+ url: parentUrl,
413
+ content: parentContent,
414
+ line,
415
+ column,
416
+ }),
417
+ isOriginalPosition,
509
418
  line,
510
419
  column,
420
+ isInline: true,
421
+ ...rest,
511
422
  })
512
- }
513
- return addReference({
514
- trace,
515
- injected: true,
516
- ...rest,
517
- })
518
- },
519
- findByGeneratedSpecifier: (generatedSpecifier) => {
520
- const reference = references.find(
521
- (ref) => ref.generatedSpecifier === generatedSpecifier,
522
- )
523
- if (!reference) {
524
- throw new Error(
525
- `No reference found using the following generatedSpecifier: "${generatedSpecifier}"`,
423
+ },
424
+ update: (currentReference, newReferenceParams) => {
425
+ const index = references.indexOf(currentReference)
426
+ if (index === -1) {
427
+ throw new Error(`reference do not exists`)
428
+ }
429
+ const previousReference = currentReference
430
+ const nextReference = createReference({
431
+ ...previousReference,
432
+ ...newReferenceParams,
433
+ })
434
+ references[index] = nextReference
435
+ mutateReference(previousReference, nextReference)
436
+ const newUrlInfo = resolveReference(nextReference)
437
+ const currentUrlInfo = context.urlGraph.getUrlInfo(
438
+ currentReference.url,
526
439
  )
527
- }
528
- return reference
529
- },
530
- }
531
-
532
- // "transform" hook
533
- urlInfo.references = references
534
- context.referenceUtils = referenceUtils
535
- try {
536
- await pluginController.callAsyncHooks(
537
- "transformUrlContent",
538
- urlInfo,
539
- context,
540
- async (transformReturnValue) => {
541
- await urlInfoTransformer.applyIntermediateTransformations(
542
- urlInfo,
543
- transformReturnValue,
440
+ if (
441
+ currentUrlInfo &&
442
+ currentUrlInfo !== newUrlInfo &&
443
+ currentUrlInfo.dependents.size === 0
444
+ ) {
445
+ context.urlGraph.deleteUrlInfo(currentReference.url)
446
+ }
447
+ return [nextReference, newUrlInfo]
448
+ },
449
+ becomesInline: (
450
+ reference,
451
+ {
452
+ isOriginalPosition,
453
+ specifier,
454
+ specifierLine,
455
+ specifierColumn,
456
+ contentType,
457
+ content,
458
+ },
459
+ ) => {
460
+ const parentUrl = isOriginalPosition
461
+ ? urlInfo.url
462
+ : urlInfo.generatedUrl
463
+ const parentContent = isOriginalPosition
464
+ ? urlInfo.originalContent
465
+ : urlInfo.content
466
+ return referenceUtils.update(reference, {
467
+ trace: stringifyUrlSite({
468
+ url: parentUrl,
469
+ content: parentContent,
470
+ line: specifierLine,
471
+ column: specifierColumn,
472
+ }),
473
+ isOriginalPosition,
474
+ isInline: true,
475
+ specifier,
476
+ specifierLine,
477
+ specifierColumn,
478
+ contentType,
479
+ content,
480
+ })
481
+ },
482
+ inject: ({ trace, ...rest }) => {
483
+ if (trace === undefined) {
484
+ const { url, line, column } = getCallerPosition()
485
+ trace = stringifyUrlSite({
486
+ url,
487
+ line,
488
+ column,
489
+ })
490
+ }
491
+ return addReference({
492
+ trace,
493
+ injected: true,
494
+ ...rest,
495
+ })
496
+ },
497
+ findByGeneratedSpecifier: (generatedSpecifier) => {
498
+ const reference = references.find(
499
+ (ref) => ref.generatedSpecifier === generatedSpecifier,
544
500
  )
501
+ if (!reference) {
502
+ throw new Error(
503
+ `No reference found using the following generatedSpecifier: "${generatedSpecifier}"`,
504
+ )
505
+ }
506
+ return reference
545
507
  },
546
- )
547
- } catch (error) {
548
- throw createTransformUrlContentError({
549
- pluginController,
550
- reference,
551
- urlInfo,
552
- error,
553
- })
554
- }
555
- // after "transform" all references from originalContent
556
- // and the one injected by plugin are known
557
- urlGraph.updateReferences(urlInfo, references)
508
+ }
558
509
 
559
- // "finalize" hook
560
- try {
561
- const finalizeReturnValue = await pluginController.callAsyncHooksUntil(
562
- "finalizeUrlContent",
563
- urlInfo,
564
- context,
565
- )
566
- await urlInfoTransformer.applyFinalTransformations(
567
- urlInfo,
568
- finalizeReturnValue,
569
- )
570
- } catch (error) {
571
- throw createFinalizeUrlContentError({
572
- pluginController,
573
- reference,
574
- urlInfo,
575
- error,
576
- })
510
+ // "transform" hook
511
+ urlInfo.references = references
512
+ context.referenceUtils = referenceUtils
513
+ try {
514
+ await pluginController.callAsyncHooks(
515
+ "transformUrlContent",
516
+ urlInfo,
517
+ context,
518
+ async (transformReturnValue) => {
519
+ await urlInfoTransformer.applyIntermediateTransformations(
520
+ urlInfo,
521
+ transformReturnValue,
522
+ )
523
+ },
524
+ )
525
+ } catch (error) {
526
+ throw createTransformUrlContentError({
527
+ pluginController,
528
+ reference: context.reference,
529
+ urlInfo,
530
+ error,
531
+ })
532
+ }
533
+ // after "transform" all references from originalContent
534
+ // and the one injected by plugin are known
535
+ urlGraph.updateReferences(urlInfo, references)
536
+
537
+ // "finalize" hook
538
+ try {
539
+ const finalizeReturnValue = await pluginController.callAsyncHooksUntil(
540
+ "finalizeUrlContent",
541
+ urlInfo,
542
+ context,
543
+ )
544
+ await urlInfoTransformer.applyFinalTransformations(
545
+ urlInfo,
546
+ finalizeReturnValue,
547
+ )
548
+ } catch (error) {
549
+ throw createFinalizeUrlContentError({
550
+ pluginController,
551
+ reference: context.reference,
552
+ urlInfo,
553
+ error,
554
+ })
555
+ }
577
556
  }
578
557
 
579
558
  // "cooked" hook
@@ -598,44 +577,34 @@ export const createKitchen = ({
598
577
  },
599
578
  )
600
579
  }
601
- const cook = memoizeCook(async ({ urlInfo, outDirectoryUrl, ...rest }) => {
602
- outDirectoryUrl = outDirectoryUrl ? String(outDirectoryUrl) : undefined
603
-
604
- const writeFiles = ({ gotError }) => {
605
- if (!writeGeneratedFiles || !outDirectoryUrl) {
606
- return
607
- }
608
- const { generatedUrl } = urlInfo
609
- // writing result inside ".jsenv" directory (debug purposes)
610
- if (!generatedUrl || !generatedUrl.startsWith("file:")) {
611
- return
612
- }
613
- // use writeSync to avoid concurrency on writing the file
614
- const write = gotError ? writeFileSync : writeFileSync
615
- write(new URL(generatedUrl), urlInfo.content)
616
- const { sourcemapGeneratedUrl, sourcemap } = urlInfo
617
- if (sourcemapGeneratedUrl && sourcemap) {
618
- write(
619
- new URL(sourcemapGeneratedUrl),
620
- JSON.stringify(sourcemap, null, " "),
621
- )
622
- }
580
+ const cook = memoizeCook(async (urlInfo, context) => {
581
+ if (!writeGeneratedFiles || !context.outDirectoryUrl) {
582
+ await _cook(urlInfo, context)
583
+ return
623
584
  }
624
-
585
+ // writing result inside ".jsenv" directory (debug purposes)
625
586
  try {
626
- await _cook({
627
- urlInfo,
628
- outDirectoryUrl,
629
- ...rest,
630
- })
631
- writeFiles({ gotError: false })
632
- } catch (e) {
633
- writeFiles({ gotError: true })
634
- throw e
587
+ await _cook(urlInfo, context)
588
+ } finally {
589
+ const { generatedUrl } = urlInfo
590
+ if (generatedUrl && generatedUrl.startsWith("file:")) {
591
+ if (urlInfo.type === "directory") {
592
+ // no need to write the directory
593
+ } else {
594
+ writeFileSync(new URL(generatedUrl), urlInfo.content)
595
+ const { sourcemapGeneratedUrl, sourcemap } = urlInfo
596
+ if (sourcemapGeneratedUrl && sourcemap) {
597
+ writeFileSync(
598
+ new URL(sourcemapGeneratedUrl),
599
+ JSON.stringify(sourcemap, null, " "),
600
+ )
601
+ }
602
+ }
603
+ }
635
604
  }
636
605
  })
637
-
638
- baseContext.cook = cook
606
+ kitchenContext.fetchUrlContent = fetchUrlContent
607
+ kitchenContext.cook = cook
639
608
 
640
609
  const prepareEntryPoint = (params) => {
641
610
  const entryReference = createReference(params)
@@ -654,7 +623,7 @@ export const createKitchen = ({
654
623
  urlInfoTransformer,
655
624
  rootDirectoryUrl,
656
625
  jsenvDirectoryUrl,
657
- baseContext,
626
+ kitchenContext,
658
627
  cook,
659
628
  prepareEntryPoint,
660
629
  injectReference,
@@ -663,8 +632,7 @@ export const createKitchen = ({
663
632
 
664
633
  const memoizeCook = (cook) => {
665
634
  const pendingDishes = new Map()
666
- return async (params) => {
667
- const { urlInfo } = params
635
+ return async (urlInfo, context) => {
668
636
  const { url, modifiedTimestamp } = urlInfo
669
637
  const pendingDish = pendingDishes.get(url)
670
638
  if (pendingDish) {
@@ -679,7 +647,7 @@ const memoizeCook = (cook) => {
679
647
  pendingDishes.delete(url)
680
648
  }
681
649
  const timestamp = Date.now()
682
- const promise = cook(params)
650
+ const promise = cook(urlInfo, context)
683
651
  pendingDishes.set(url, {
684
652
  timestamp,
685
653
  promise,
@@ -693,6 +661,9 @@ const memoizeCook = (cook) => {
693
661
  }
694
662
 
695
663
  const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
664
+ if (reference.shouldHandle) {
665
+ urlInfo.shouldHandle = true
666
+ }
696
667
  Object.assign(urlInfo.data, reference.data)
697
668
  Object.assign(urlInfo.timing, reference.timing)
698
669
  if (reference.injected) {
@@ -833,66 +804,6 @@ const determineFileUrlForOutDirectory = ({ urlInfo, context }) => {
833
804
  })
834
805
  }
835
806
 
836
- const urlSpecifierFormat = {
837
- encode: (reference) => {
838
- const { generatedSpecifier } = reference
839
- if (generatedSpecifier.then) {
840
- return generatedSpecifier.then((value) => {
841
- reference.generatedSpecifier = value
842
- return urlSpecifierFormat.encode(reference)
843
- })
844
- }
845
- // allow plugin to return a function to bypas default formatting
846
- // (which is to use JSON.stringify when url is referenced inside js)
847
- if (typeof generatedSpecifier === "function") {
848
- return generatedSpecifier()
849
- }
850
- const formatter = formatters[reference.type]
851
- const value = formatter
852
- ? formatter.encode(generatedSpecifier)
853
- : generatedSpecifier
854
- if (reference.escape) {
855
- return reference.escape(value)
856
- }
857
- return value
858
- },
859
- decode: (reference) => {
860
- const formatter = formatters[reference.type]
861
- return formatter
862
- ? formatter.decode(reference.generatedSpecifier)
863
- : reference.generatedSpecifier
864
- },
865
- }
866
- const formatters = {
867
- "js_import_export": { encode: JSON.stringify, decode: JSON.parse },
868
- "js_url_specifier": { encode: JSON.stringify, decode: JSON.parse },
869
- "css_@import": { encode: JSON.stringify, code: JSON.stringify },
870
- // https://github.com/webpack-contrib/css-loader/pull/627/files
871
- "css_url": {
872
- encode: (url) => {
873
- // If url is already wrapped in quotes, remove them
874
- url = formatters.css_url.decode(url)
875
- // Should url be wrapped?
876
- // See https://drafts.csswg.org/css-values-3/#urls
877
- if (/["'() \t\n]/.test(url)) {
878
- return `"${url.replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`
879
- }
880
- return url
881
- },
882
- decode: (url) => {
883
- const firstChar = url[0]
884
- const lastChar = url[url.length - 1]
885
- if (firstChar === `"` && lastChar === `"`) {
886
- return url.slice(1, -1)
887
- }
888
- if (firstChar === `'` && lastChar === `'`) {
889
- return url.slice(1, -1)
890
- }
891
- return url
892
- },
893
- },
894
- }
895
-
896
807
  // import { getOriginalPosition } from "@jsenv/core/src/utils/sourcemap/original_position.js"
897
808
  // const getUrlSite = async (
898
809
  // urlInfo,