@jsenv/core 27.0.0-alpha.64 → 27.0.0-alpha.67

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 (151) 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 +13450 -0
  102. package/dist/other/jsenv.png +0 -0
  103. package/dist/s.js.map +59 -62
  104. package/package.json +16 -12
  105. package/src/build/build.js +169 -68
  106. package/src/build/build_urls_generator.js +18 -2
  107. package/src/build/inject_service_worker_urls.js +1 -1
  108. package/src/build/resync_ressource_hints.js +56 -9
  109. package/src/dev/plugins/explorer/client/explorer.html +1 -1
  110. package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +1 -1
  111. package/src/dev/start_dev_server.js +17 -3
  112. package/src/execute/execute.js +3 -0
  113. package/src/omega/errors.js +12 -9
  114. package/src/omega/kitchen.js +252 -217
  115. package/src/omega/server/file_service.js +1 -1
  116. package/src/omega/url_graph/url_graph_report.js +2 -2
  117. package/src/omega/url_graph/url_info_transformations.js +10 -5
  118. package/src/omega/url_graph.js +3 -2
  119. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +5 -10
  120. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +1 -3
  121. package/src/plugins/bundling/js_module/bundle_js_module.js +66 -24
  122. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +185 -53
  123. package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +9 -13
  124. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +6 -6
  125. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +5 -10
  126. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +2 -2
  127. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +12 -2
  128. package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +12 -0
  129. package/src/plugins/plugin_controller.js +17 -3
  130. package/src/plugins/plugins.js +16 -19
  131. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +17 -19
  132. package/src/plugins/transpilation/as_js_classic/{jsenv_plugin_script_type_module_as_classic.js → jsenv_plugin_as_js_classic_html.js} +0 -0
  133. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +9 -4
  134. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +1 -2
  135. package/src/plugins/url_analysis/css/css_urls.js +1 -1
  136. package/src/plugins/url_analysis/html/html_urls.js +4 -1
  137. package/src/plugins/url_analysis/js/js_urls.js +3 -2
  138. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +94 -1
  139. package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +3 -0
  140. package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +0 -3
  141. package/src/test/execute_plan.js +3 -1
  142. package/dist/event_source_client.js.map +0 -188
  143. package/dist/html_supervisor_installer.js +0 -1236
  144. package/dist/html_supervisor_installer.js.map +0 -337
  145. package/dist/html_supervisor_setup.js +0 -95
  146. package/dist/html_supervisor_setup.js.map +0 -57
  147. package/dist/import_meta_hot.js.map +0 -42
  148. package/src/jsenv_root_directory_url.js +0 -1
  149. package/src/omega/compat/default_runtime_compat.js +0 -11
  150. package/src/plugins/filesystem_magic/jsenv_plugin_filesystem_magic.js +0 -61
  151. package/src/plugins/transpilation/babel/new_stylesheet/client/.eslintrc.cjs +0 -24
@@ -26,6 +26,7 @@ import {
26
26
  asUrlUntilPathname,
27
27
  normalizeUrl,
28
28
  asUrlWithoutSearch,
29
+ ensurePathnameTrailingSlash,
29
30
  } from "@jsenv/utils/urls/url_utils.js"
30
31
  import { createVersionGenerator } from "@jsenv/utils/versioning/version_generator.js"
31
32
  import { generateSourcemapUrl } from "@jsenv/utils/sourcemap/sourcemap_utils.js"
@@ -35,10 +36,10 @@ import {
35
36
  } from "@jsenv/utils/html_ast/html_ast.js"
36
37
  import { sortByDependencies } from "@jsenv/utils/graph/sort_by_dependencies.js"
37
38
 
39
+ import { createUrlGraph } from "../omega/url_graph.js"
38
40
  import { jsenvPluginUrlAnalysis } from "../plugins/url_analysis/jsenv_plugin_url_analysis.js"
39
41
  import { jsenvPluginInline } from "../plugins/inline/jsenv_plugin_inline.js"
40
42
  import { jsenvPluginAsJsClassic } from "../plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js"
41
- import { createUrlGraph } from "../omega/url_graph.js"
42
43
  import { getCorePlugins } from "../plugins/plugins.js"
43
44
  import { createKitchen } from "../omega/kitchen.js"
44
45
  import { loadUrlGraph } from "../omega/url_graph/url_graph_load.js"
@@ -87,13 +88,28 @@ export const build = async ({
87
88
  rootDirectoryUrl,
88
89
  buildDirectoryUrl,
89
90
  entryPoints = {},
91
+ baseUrl = "/",
90
92
 
93
+ // default runtimeCompat corresponds to dynamic import
94
+ // (meaning we can keep <script type="module">)
95
+ runtimeCompat = {
96
+ // android: "8",
97
+ chrome: "63",
98
+ edge: "79",
99
+ firefox: "67",
100
+ ios: "11.3",
101
+ opera: "50",
102
+ safari: "11.3",
103
+ samsung: "8.2",
104
+ },
91
105
  plugins = [],
92
106
  sourcemaps = false,
107
+ sourcemapsSourcesContent,
108
+ urlAnalysis = {},
93
109
  nodeEsmResolution,
94
110
  fileSystemMagicResolution,
111
+ directoryReferenceAllowed,
95
112
  injectedGlobals,
96
- runtimeCompat,
97
113
  transpilation = {},
98
114
  bundling = true,
99
115
  minification = true,
@@ -113,7 +129,6 @@ export const build = async ({
113
129
  buildDirectoryClean = true,
114
130
  writeOnFileSystem = true,
115
131
  writeGeneratedFiles = false,
116
- baseUrl = "/",
117
132
  assetManifest = true,
118
133
  assetManifestFileRelativeUrl = "asset-manifest.json",
119
134
  }) => {
@@ -161,6 +176,7 @@ build ${entryPointKeys.length} entry points`)
161
176
  disabled: infoLogsAreDisabled,
162
177
  })
163
178
  let urlCount = 0
179
+ const prebuildRedirections = new Map()
164
180
  const rawGraphKitchen = createKitchen({
165
181
  signal,
166
182
  logger,
@@ -168,6 +184,7 @@ build ${entryPointKeys.length} entry points`)
168
184
  urlGraph: rawGraph,
169
185
  scenario: "build",
170
186
  sourcemaps,
187
+ sourcemapsSourcesContent,
171
188
  runtimeCompat,
172
189
  writeGeneratedFiles,
173
190
  plugins: [
@@ -180,13 +197,33 @@ build ${entryPointKeys.length} entry points`)
180
197
  prebuildTask.setRightText(urlCount)
181
198
  },
182
199
  },
200
+ {
201
+ appliesDuring: "build",
202
+ fetchUrlContent: (urlInfo, context) => {
203
+ if (context.reference.original) {
204
+ prebuildRedirections.set(
205
+ context.reference.original.url,
206
+ context.reference.url,
207
+ )
208
+ }
209
+ },
210
+ formatUrl: (reference) => {
211
+ if (!reference.shouldHandle) {
212
+ return `ignore:${reference.specifier}`
213
+ }
214
+ return null
215
+ },
216
+ },
183
217
  ...getCorePlugins({
184
218
  rootDirectoryUrl,
185
219
  urlGraph: rawGraph,
186
220
  scenario: "build",
221
+ runtimeCompat,
187
222
 
223
+ urlAnalysis,
188
224
  nodeEsmResolution,
189
225
  fileSystemMagicResolution,
226
+ directoryReferenceAllowed,
190
227
  injectedGlobals,
191
228
  transpilation: {
192
229
  ...transpilation,
@@ -229,8 +266,8 @@ build ${entryPointKeys.length} entry points`)
229
266
  buildDirectoryUrl,
230
267
  })
231
268
  const rawUrls = {}
269
+ const bundleRedirections = {}
232
270
  const buildUrls = {}
233
- const rawUrlRedirections = {}
234
271
  const bundleUrlInfos = {}
235
272
  const bundlers = {}
236
273
  rawGraphKitchen.pluginController.plugins.forEach((plugin) => {
@@ -320,7 +357,7 @@ build ${entryPointKeys.length} entry points`)
320
357
  })
321
358
  }
322
359
  })
323
- const bundleUrlRedirections = {}
360
+ const bundleInternalRedirections = {}
324
361
  await Object.keys(bundlers).reduce(async (previous, type) => {
325
362
  await previous
326
363
  const bundler = bundlers[type]
@@ -352,6 +389,10 @@ build ${entryPointKeys.length} entry points`)
352
389
  type,
353
390
  subtype: rawUrlInfo ? rawUrlInfo.subtype : undefined,
354
391
  filename: rawUrlInfo ? rawUrlInfo.filename : undefined,
392
+ originalUrl: rawUrlInfo ? rawUrlInfo.originalUrl : undefined,
393
+ originalContent: rawUrlInfo
394
+ ? rawUrlInfo.originalContent
395
+ : undefined,
355
396
  ...bundlerGeneratedUrlInfo,
356
397
  data: {
357
398
  ...(rawUrlInfo ? rawUrlInfo.data : {}),
@@ -362,7 +403,7 @@ build ${entryPointKeys.length} entry points`)
362
403
  const buildUrl = buildUrlsGenerator.generate(url, {
363
404
  urlInfo: bundleUrlInfo,
364
405
  })
365
- rawUrlRedirections[url] = buildUrl
406
+ bundleRedirections[url] = buildUrl
366
407
  rawUrls[buildUrl] = url
367
408
  bundleUrlInfos[buildUrl] = bundleUrlInfo
368
409
  if (buildUrl.includes("?")) {
@@ -373,7 +414,9 @@ build ${entryPointKeys.length} entry points`)
373
414
  bundlerGeneratedUrlInfo.data.bundleRelativeUrl,
374
415
  buildDirectoryUrl,
375
416
  ).href
376
- bundleUrlRedirections[urlForBundler] = buildUrl
417
+ if (urlForBundler !== buildUrl) {
418
+ bundleInternalRedirections[urlForBundler] = buildUrl
419
+ }
377
420
  }
378
421
  })
379
422
  } catch (e) {
@@ -383,7 +426,11 @@ build ${entryPointKeys.length} entry points`)
383
426
  bundleTask.done()
384
427
  }, Promise.resolve())
385
428
 
386
- const buildUrlRedirections = {}
429
+ const urlAnalysisPlugin = jsenvPluginUrlAnalysis({
430
+ rootDirectoryUrl,
431
+ ...urlAnalysis,
432
+ })
433
+ const postBuildRedirections = {}
387
434
  const finalGraph = createUrlGraph()
388
435
  const optimizeUrlContentHooks =
389
436
  rawGraphKitchen.pluginController.addHook("optimizeUrlContent")
@@ -393,38 +440,63 @@ build ${entryPointKeys.length} entry points`)
393
440
  urlGraph: finalGraph,
394
441
  scenario: "build",
395
442
  sourcemaps,
443
+ sourcemapsSourcesContent,
396
444
  sourcemapsRelativeSources: !versioning,
397
445
  runtimeCompat,
398
446
  writeGeneratedFiles,
399
447
  plugins: [
400
- jsenvPluginUrlAnalysis(),
401
- jsenvPluginAsJsClassic({
402
- rootDirectoryUrl,
403
- systemJsInjection: true,
404
- }),
405
- jsenvPluginInline({
406
- fetchInlineUrls: false,
407
- }),
448
+ urlAnalysisPlugin,
449
+ jsenvPluginAsJsClassic({ systemJsInjection: true }),
450
+ jsenvPluginInline({ fetchInlineUrls: false }),
408
451
  {
409
452
  name: "jsenv:postbuild",
410
- appliesDuring: { build: true },
453
+ appliesDuring: "build",
411
454
  resolveUrl: (reference) => {
412
- if (reference.specifier[0] === "#") {
413
- reference.external = true
455
+ const performInternalRedirections = (url) => {
456
+ const prebuildRedirection = prebuildRedirections.get(url)
457
+ if (prebuildRedirection) {
458
+ logger.debug(
459
+ `\nprebuild redirection\n${url} ->\n${prebuildRedirection}\n`,
460
+ )
461
+ url = prebuildRedirection
462
+ }
463
+ const bundleRedirection = bundleRedirections[url]
464
+ if (bundleRedirection) {
465
+ logger.debug(
466
+ `\nbundler redirection\n${url} ->\n${bundleRedirection}\n`,
467
+ )
468
+ url = bundleRedirection
469
+ }
470
+ const bundleInternalRedirection = bundleInternalRedirections[url]
471
+ if (bundleInternalRedirection) {
472
+ logger.debug(
473
+ `\nbundler internal redirection\n${url} ->\n${bundleInternalRedirection}\n`,
474
+ )
475
+ url = bundleInternalRedirection
476
+ }
477
+ return url
414
478
  }
415
- const urlBeforePotentialRedirect =
416
- reference.specifier[0] === "/"
417
- ? new URL(reference.specifier.slice(1), buildDirectoryUrl).href
418
- : new URL(reference.specifier, reference.parentUrl).href
419
- const url =
420
- rawUrlRedirections[urlBeforePotentialRedirect] ||
421
- urlBeforePotentialRedirect
422
- const urlRedirectedByBundle = bundleUrlRedirections[url]
423
- if (urlRedirectedByBundle) {
424
- return urlRedirectedByBundle
479
+
480
+ if (reference.type === "filesystem") {
481
+ const parentRawUrl = rawUrls[reference.parentUrl]
482
+ const baseUrl = ensurePathnameTrailingSlash(parentRawUrl)
483
+ return performInternalRedirections(
484
+ new URL(reference.specifier, baseUrl).href,
485
+ )
425
486
  }
426
- return url
487
+ if (reference.specifier[0] === "/") {
488
+ return performInternalRedirections(
489
+ new URL(reference.specifier.slice(1), buildDirectoryUrl).href,
490
+ )
491
+ }
492
+ return performInternalRedirections(
493
+ new URL(
494
+ reference.specifier,
495
+ reference.baseUrl || reference.parentUrl,
496
+ ).href,
497
+ )
427
498
  },
499
+ // redirecting urls into the build directory
428
500
  redirectUrl: (reference) => {
429
501
  if (!reference.url.startsWith("file:")) {
430
502
  return null
@@ -434,11 +506,6 @@ build ${entryPointKeys.length} entry points`)
434
506
  if (rawUrl) {
435
507
  return reference.url
436
508
  }
437
- // from rollup or postcss
438
- const bundleUrlInfo = bundleUrlInfos[reference.url]
439
- if (bundleUrlInfo) {
440
- return reference.url
441
- }
442
509
  // from "js_module_as_js_classic":
443
510
  // - injecting "?as_js_classic" for the first time
444
511
  // - injecting "?as_js_classic" because the parentUrl has it
@@ -454,9 +521,8 @@ build ${entryPointKeys.length} entry points`)
454
521
  }
455
522
  let rawUrl
456
523
  if (urlIsInsideOf(reference.url, buildDirectoryUrl)) {
457
- // rawUrl = rawUrls[reference.url] || reference.url
458
524
  const originalBuildUrl =
459
- buildUrlRedirections[referenceOriginalUrl]
525
+ postBuildRedirections[referenceOriginalUrl]
460
526
  rawUrl = originalBuildUrl
461
527
  ? rawUrls[originalBuildUrl]
462
528
  : reference.url
@@ -478,7 +544,7 @@ build ${entryPointKeys.length} entry points`)
478
544
  filename: reference.filename,
479
545
  },
480
546
  })
481
- buildUrlRedirections[originalBuildUrl] = buildUrl
547
+ postBuildRedirections[originalBuildUrl] = buildUrl
482
548
  rawUrls[buildUrl] = rawUrl
483
549
  return buildUrl
484
550
  }
@@ -522,15 +588,17 @@ build ${entryPointKeys.length} entry points`)
522
588
  return buildUrl
523
589
  }
524
590
  const rawUrlInfo = rawGraph.getUrlInfo(reference.url)
591
+ const parentUrlInfo = finalGraph.getUrlInfo(reference.parentUrl)
525
592
  // files from root directory but not given to rollup nor postcss
526
593
  if (rawUrlInfo) {
527
594
  const buildUrl = buildUrlsGenerator.generate(reference.url, {
528
595
  urlInfo: rawUrlInfo,
596
+ parentUrlInfo,
529
597
  })
598
+ rawUrls[buildUrl] = rawUrlInfo.url
530
599
  if (buildUrl.includes("?")) {
531
600
  rawUrls[asUrlWithoutSearch(buildUrl)] = rawUrlInfo.url
532
601
  }
533
- rawUrls[buildUrl] = rawUrlInfo.url
534
602
  return buildUrl
535
603
  }
536
604
  if (reference.type === "sourcemap_comment") {
@@ -550,6 +618,9 @@ build ${entryPointKeys.length} entry points`)
550
618
  },
551
619
  formatUrl: (reference) => {
552
620
  if (!reference.generatedUrl.startsWith("file:")) {
621
+ if (!versioning && reference.generatedUrl.startsWith("ignore:")) {
622
+ return reference.generatedUrl.slice("ignore:".length)
623
+ }
553
624
  return null
554
625
  }
555
626
  if (!urlIsInsideOf(reference.generatedUrl, buildDirectoryUrl)) {
@@ -557,6 +628,10 @@ build ${entryPointKeys.length} entry points`)
557
628
  `urls should be inside build directory at this stage, found "${reference.url}"`,
558
629
  )
559
630
  }
631
+ if (reference.isRessourceHint) {
632
+ // return the raw url, we will resync at the end
633
+ return rawUrls[reference.url]
634
+ }
560
635
  // remove eventual search params and hash
561
636
  const urlUntilPathname = asUrlUntilPathname(reference.generatedUrl)
562
637
  let specifier
@@ -582,23 +657,18 @@ build ${entryPointKeys.length} entry points`)
582
657
  return specifier
583
658
  },
584
659
  fetchUrlContent: async (finalUrlInfo, context) => {
585
- if (!finalUrlInfo.url.startsWith("file:")) {
586
- return { external: true }
587
- }
588
660
  const fromBundleOrRawGraph = (url) => {
589
661
  const bundleUrlInfo = bundleUrlInfos[url]
590
662
  if (bundleUrlInfo) {
663
+ logger.debug(`fetching from bundle ${url}`)
591
664
  return bundleUrlInfo
592
665
  }
593
666
  const rawUrl = rawUrls[url] || url
594
667
  const rawUrlInfo = rawGraph.getUrlInfo(rawUrl)
595
668
  if (!rawUrlInfo) {
596
- const originalBuildUrl = buildUrlRedirections[url]
597
- if (originalBuildUrl) {
598
- return fromBundleOrRawGraph(originalBuildUrl)
599
- }
600
669
  throw new Error(`Cannot find url`)
601
670
  }
671
+ logger.debug(`fetching from raw graph ${url}`)
602
672
  if (rawUrlInfo.isInline) {
603
673
  // Inline content, such as <script> inside html, is transformed during the previous phase.
604
674
  // If we read the inline content it would be considered as the original content.
@@ -638,7 +708,7 @@ build ${entryPointKeys.length} entry points`)
638
708
  },
639
709
  {
640
710
  name: "jsenv:optimize",
641
- appliesDuring: { build: true },
711
+ appliesDuring: "build",
642
712
  finalizeUrlContent: async (urlInfo, context) => {
643
713
  if (optimizeUrlContentHooks.length) {
644
714
  await rawGraphKitchen.pluginController.callAsyncHooks(
@@ -699,9 +769,11 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
699
769
  baseUrl,
700
770
  postBuildEntryUrls,
701
771
  sourcemaps,
772
+ sourcemapsSourcesContent,
702
773
  runtimeCompat,
703
774
  writeGeneratedFiles,
704
775
  rawGraph,
776
+ urlAnalysisPlugin,
705
777
  finalGraph,
706
778
  finalGraphKitchen,
707
779
  lineBreakNormalization,
@@ -709,10 +781,10 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
709
781
  })
710
782
  }
711
783
  GRAPH.forEach(finalGraph, (urlInfo) => {
712
- if (!urlInfo.url.startsWith("file:")) {
784
+ if (!urlInfo.shouldHandle) {
713
785
  return
714
786
  }
715
- if (urlInfo.external) {
787
+ if (!urlInfo.url.startsWith("file:")) {
716
788
  return
717
789
  }
718
790
  if (urlInfo.type === "html") {
@@ -734,10 +806,11 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
734
806
  urlInfo.data.buildUrlSpecifier = buildUrlSpecifier
735
807
  })
736
808
  await resyncRessourceHints({
809
+ logger,
737
810
  finalGraphKitchen,
738
811
  finalGraph,
739
812
  rawUrls,
740
- buildUrls,
813
+ postBuildRedirections,
741
814
  })
742
815
  buildOperation.throwIfAborted()
743
816
  const cleanupActions = []
@@ -767,10 +840,13 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
767
840
  const buildFileContents = {}
768
841
  const buildInlineContents = {}
769
842
  GRAPH.forEach(finalGraph, (urlInfo) => {
770
- if (urlInfo.external) {
843
+ if (!urlInfo.shouldHandle) {
771
844
  return
772
845
  }
773
- if (urlInfo.url.startsWith("data:")) {
846
+ if (!urlInfo.url.startsWith("file:")) {
847
+ return
848
+ }
849
+ if (urlInfo.type === "directory") {
774
850
  return
775
851
  }
776
852
  const buildRelativeUrl = urlToRelativeUrl(
@@ -901,9 +977,11 @@ const applyUrlVersioning = async ({
901
977
  baseUrl,
902
978
  postBuildEntryUrls,
903
979
  sourcemaps,
980
+ sourcemapsSourcesContent,
904
981
  runtimeCompat,
905
982
  writeGeneratedFiles,
906
983
  rawGraph,
984
+ urlAnalysisPlugin,
907
985
  finalGraph,
908
986
  finalGraphKitchen,
909
987
  lineBreakNormalization,
@@ -925,7 +1003,7 @@ const applyUrlVersioning = async ({
925
1003
  // ignore:
926
1004
  // - inline files:
927
1005
  // they are already taken into account in the file where they appear
928
- // - external files
1006
+ // - ignored files:
929
1007
  // we don't know their content
930
1008
  // - unused files without reference
931
1009
  // File updated such as style.css -> style.css.js or file.js->file.es5.js
@@ -935,7 +1013,7 @@ const applyUrlVersioning = async ({
935
1013
  if (urlInfo.isInline) {
936
1014
  return
937
1015
  }
938
- if (urlInfo.external) {
1016
+ if (!urlInfo.shouldHandle) {
939
1017
  return
940
1018
  }
941
1019
  if (!urlInfo.data.isEntryPoint && urlInfo.dependents.size === 0) {
@@ -958,8 +1036,8 @@ const applyUrlVersioning = async ({
958
1036
  lineBreakNormalization,
959
1037
  })
960
1038
  urlInfo.dependencies.forEach((dependencyUrl) => {
961
- // this dependency is inline (data:) or remote (http://, https://)
962
- if (!dependencyUrl.startsWith("file:")) {
1039
+ // this dependency is inline
1040
+ if (dependencyUrl.startsWith("data:")) {
963
1041
  return
964
1042
  }
965
1043
  const dependencyUrlInfo = finalGraph.getUrlInfo(dependencyUrl)
@@ -967,7 +1045,7 @@ const applyUrlVersioning = async ({
967
1045
  // this content is part of the file, no need to take into account twice
968
1046
  dependencyUrlInfo.isInline ||
969
1047
  // this dependency content is not known
970
- dependencyUrlInfo.external
1048
+ !dependencyUrlInfo.shouldHandle
971
1049
  ) {
972
1050
  return
973
1051
  }
@@ -1005,11 +1083,12 @@ const applyUrlVersioning = async ({
1005
1083
  urlGraph: finalGraph,
1006
1084
  scenario: "build",
1007
1085
  sourcemaps,
1086
+ sourcemapsSourcesContent,
1008
1087
  sourcemapsRelativeSources: true,
1009
1088
  runtimeCompat,
1010
1089
  writeGeneratedFiles,
1011
1090
  plugins: [
1012
- jsenvPluginUrlAnalysis(),
1091
+ urlAnalysisPlugin,
1013
1092
  jsenvPluginInline({
1014
1093
  fetchInlineUrls: false,
1015
1094
  analyzeConvertedScripts: true, // to be able to version their urls
@@ -1019,18 +1098,44 @@ const applyUrlVersioning = async ({
1019
1098
  name: "jsenv:versioning",
1020
1099
  appliesDuring: { build: true },
1021
1100
  resolveUrl: (reference) => {
1022
- if (reference.specifier[0] === "#") {
1023
- reference.external = true
1024
- }
1025
1101
  const buildUrl = buildUrls[reference.specifier]
1026
1102
  if (buildUrl) {
1027
1103
  return buildUrl
1028
1104
  }
1029
- const url = new URL(reference.specifier, reference.parentUrl).href
1105
+ const urlObject = new URL(
1106
+ reference.specifier,
1107
+ reference.baseUrl || reference.parentUrl,
1108
+ )
1109
+ const url = urlObject.href
1110
+ // during versioning we revisit the deps
1111
+ // but the code used to enforce trailing slash on directories
1112
+ // is not applied because "jsenv:file_url_resolution" is not used
1113
+ // so here we search if the url with a trailing slash exists
1114
+ if (
1115
+ reference.type === "filesystem" &&
1116
+ !urlObject.pathname.endsWith("/")
1117
+ ) {
1118
+ const urlWithTrailingSlash = `${url}/`
1119
+ const specifier = Object.keys(buildUrls).find(
1120
+ (key) => buildUrls[key] === urlWithTrailingSlash,
1121
+ )
1122
+ if (specifier) {
1123
+ return urlWithTrailingSlash
1124
+ }
1125
+ }
1030
1126
  return url
1031
1127
  },
1032
1128
  formatUrl: (reference) => {
1033
- if (reference.isInline) {
1129
+ if (!reference.shouldHandle) {
1130
+ if (reference.generatedUrl.startsWith("ignore:")) {
1131
+ return reference.generatedUrl.slice("ignore:".length)
1132
+ }
1133
+ return null
1134
+ }
1135
+ if (reference.isInline || reference.url.startsWith("data:")) {
1136
+ return null
1137
+ }
1138
+ if (reference.isRessourceHint) {
1034
1139
  return null
1035
1140
  }
1036
1141
  // specifier comes from "normalize" hook done a bit earlier in this file
@@ -1039,8 +1144,7 @@ const applyUrlVersioning = async ({
1039
1144
  if (!canUseVersionedUrl(referencedUrlInfo)) {
1040
1145
  return reference.specifier
1041
1146
  }
1042
- // data:* urls and so on
1043
- if (!referencedUrlInfo.url.startsWith("file:")) {
1147
+ if (!referencedUrlInfo.shouldHandle) {
1044
1148
  return null
1045
1149
  }
1046
1150
  const versionedUrl = referencedUrlInfo.data.versionedUrl
@@ -1077,9 +1181,6 @@ const applyUrlVersioning = async ({
1077
1181
  return versionedSpecifier
1078
1182
  },
1079
1183
  fetchUrlContent: (versionedUrlInfo) => {
1080
- if (!versionedUrlInfo.url.startsWith("file:")) {
1081
- return { external: true }
1082
- }
1083
1184
  if (versionedUrlInfo.isInline) {
1084
1185
  const rawUrlInfo = rawGraph.getUrlInfo(
1085
1186
  rawUrls[versionedUrlInfo.url],
@@ -1,4 +1,4 @@
1
- import { urlToFilename } from "@jsenv/filesystem"
1
+ import { urlToFilename, urlToRelativeUrl } from "@jsenv/filesystem"
2
2
 
3
3
  import { memoizeByFirstArgument } from "@jsenv/utils/memoize/memoize_by_first_argument.js"
4
4
 
@@ -17,6 +17,7 @@ export const createBuilUrlsGenerator = ({ buildDirectoryUrl }) => {
17
17
 
18
18
  const generate = memoizeByFirstArgument((url, { urlInfo, parentUrlInfo }) => {
19
19
  const directoryPath = determineDirectoryPath({
20
+ buildDirectoryUrl,
20
21
  urlInfo,
21
22
  parentUrlInfo,
22
23
  })
@@ -69,9 +70,24 @@ const splitFileExtension = (filename) => {
69
70
  return [filename.slice(0, dotLastIndex), filename.slice(dotLastIndex)]
70
71
  }
71
72
 
72
- const determineDirectoryPath = ({ urlInfo, parentUrlInfo }) => {
73
+ const determineDirectoryPath = ({
74
+ buildDirectoryUrl,
75
+ urlInfo,
76
+ parentUrlInfo,
77
+ }) => {
78
+ if (urlInfo.type === "directory") {
79
+ return ""
80
+ }
81
+ if (parentUrlInfo && parentUrlInfo.type === "directory") {
82
+ const parentDirectoryPath = urlToRelativeUrl(
83
+ parentUrlInfo.url,
84
+ buildDirectoryUrl,
85
+ )
86
+ return parentDirectoryPath
87
+ }
73
88
  if (urlInfo.isInline) {
74
89
  const parentDirectoryPath = determineDirectoryPath({
90
+ buildDirectoryUrl,
75
91
  urlInfo: parentUrlInfo,
76
92
  })
77
93
  return parentDirectoryPath
@@ -22,7 +22,7 @@ export const injectServiceWorkerUrls = async ({
22
22
  }
23
23
  const serviceWorkerUrls = {}
24
24
  GRAPH.forEach(finalGraph, (urlInfo) => {
25
- if (urlInfo.isInline || urlInfo.external) {
25
+ if (urlInfo.isInline || !urlInfo.shouldHandle) {
26
26
  return
27
27
  }
28
28
  if (!urlInfo.url.startsWith("file:")) {
@@ -16,9 +16,11 @@ import {
16
16
  import { GRAPH } from "./graph_utils.js"
17
17
 
18
18
  export const resyncRessourceHints = async ({
19
+ logger,
19
20
  finalGraphKitchen,
20
21
  finalGraph,
21
- buildUrls,
22
+ rawUrls,
23
+ postBuildRedirections,
22
24
  }) => {
23
25
  const ressourceHintActions = []
24
26
  GRAPH.forEach(finalGraph, (urlInfo) => {
@@ -29,20 +31,62 @@ export const resyncRessourceHints = async ({
29
31
  const htmlAst = parseHtmlString(urlInfo.content, {
30
32
  storeOriginalPositions: false,
31
33
  })
34
+ const actions = []
32
35
  const visitLinkWithHref = (linkNode, hrefAttribute) => {
33
36
  const href = hrefAttribute.value
34
37
  if (!href || href.startsWith("data:")) {
35
38
  return
36
39
  }
37
- const buildUrl = buildUrls[href]
40
+ const relAttribute = getHtmlNodeAttributeByName(linkNode, "rel")
41
+ const rel = relAttribute ? relAttribute.value : undefined
42
+ const isRessourceHint = [
43
+ "preconnect",
44
+ "dns-prefetch",
45
+ "prefetch",
46
+ "preload",
47
+ "modulepreload",
48
+ ].includes(rel)
49
+ if (!isRessourceHint) {
50
+ return
51
+ }
52
+
53
+ let buildUrl
54
+ for (const key of Object.keys(rawUrls)) {
55
+ if (rawUrls[key] === href) {
56
+ buildUrl = key
57
+ break
58
+ }
59
+ }
60
+ if (!buildUrl) {
61
+ logger.warn(`remove ressource hint because cannot find "${href}"`)
62
+ actions.push(() => {
63
+ removeHtmlNode(linkNode)
64
+ })
65
+ return
66
+ }
67
+ buildUrl = postBuildRedirections[buildUrl] || buildUrl
38
68
  const urlInfo = finalGraph.getUrlInfo(buildUrl)
39
69
  if (!urlInfo) {
70
+ logger.warn(
71
+ `remove ressource hint because cannot find "${buildUrl}" in the graph`,
72
+ )
73
+ actions.push(() => {
74
+ removeHtmlNode(linkNode)
75
+ })
40
76
  return
41
77
  }
42
78
  if (urlInfo.dependents.size === 0) {
43
- removeHtmlNode(linkNode)
79
+ logger.info(
80
+ `remove ressource hint because "${href}" not used anymore`,
81
+ )
82
+ actions.push(() => {
83
+ removeHtmlNode(linkNode)
84
+ })
44
85
  return
45
86
  }
87
+ actions.push(() => {
88
+ hrefAttribute.value = urlInfo.data.buildUrlSpecifier
89
+ })
46
90
  }
47
91
  visitHtmlAst(htmlAst, (node) => {
48
92
  if (node.nodeName !== "link") {
@@ -54,12 +98,15 @@ export const resyncRessourceHints = async ({
54
98
  }
55
99
  visitLinkWithHref(node, hrefAttribute)
56
100
  })
57
- await finalGraphKitchen.urlInfoTransformer.applyFinalTransformations(
58
- urlInfo,
59
- {
60
- content: stringifyHtmlAst(htmlAst),
61
- },
62
- )
101
+ if (actions.length) {
102
+ actions.forEach((action) => action())
103
+ await finalGraphKitchen.urlInfoTransformer.applyFinalTransformations(
104
+ urlInfo,
105
+ {
106
+ content: stringifyHtmlAst(htmlAst),
107
+ },
108
+ )
109
+ }
63
110
  })
64
111
  })
65
112
  await Promise.all(