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

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 (146) hide show
  1. package/dist/html/explorer.html +557 -0
  2. package/dist/js/controllable_file.mjs +227 -0
  3. package/dist/{event_source_client.js → js/event_source_client.js} +19 -244
  4. package/dist/js/global_this.js +32 -0
  5. package/dist/js/html_supervisor_installer.js +522 -0
  6. package/dist/js/html_supervisor_setup.js +79 -0
  7. package/dist/{import_meta_hot.js → js/import_meta_hot.js} +1 -3
  8. package/dist/js/inline_content.js +8 -0
  9. package/dist/js/new_stylesheet.js +409 -0
  10. package/dist/js/regenerator_runtime.js +721 -0
  11. package/dist/js/s.js +429 -0
  12. package/dist/main.js +13362 -0
  13. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/AsyncGenerator/AsyncGenerator.js +95 -0
  14. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/AwaitValue/AwaitValue.js +3 -0
  15. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/applyDecoratorDescriptor/applyDecoratorDescriptor.js +29 -0
  16. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +9 -0
  17. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/arrayWithHoles/arrayWithHoles.js +4 -0
  18. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +5 -0
  19. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/assertThisInitialized/assertThisInitialized.js +8 -0
  20. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +52 -0
  21. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/asyncIterator/asyncIterator.js +78 -0
  22. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/asyncToGenerator/asyncToGenerator.js +39 -0
  23. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +4 -0
  24. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +24 -0
  25. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +7 -0
  26. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +14 -0
  27. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classCallCheck/classCallCheck.js +5 -0
  28. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -0
  29. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -0
  30. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +8 -0
  31. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classNameTDZError/classNameTDZError.js +4 -0
  32. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +6 -0
  33. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +6 -0
  34. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +7 -0
  35. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -0
  36. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +7 -0
  37. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +7 -0
  38. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +3 -0
  39. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +8 -0
  40. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +9 -0
  41. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +5 -0
  42. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -0
  43. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/construct/construct.js +15 -0
  44. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createClass/createClass.js +18 -0
  45. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +63 -0
  46. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +22 -0
  47. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createRawReactElement/createRawReactElement.js +50 -0
  48. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/createSuper/createSuper.js +22 -0
  49. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/decorate/decorate.js +622 -0
  50. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/defaults/defaults.js +14 -0
  51. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +26 -0
  52. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/defineProperty/defineProperty.js +19 -0
  53. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/extends/extends.js +16 -0
  54. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/get/get.js +21 -0
  55. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/getPrototypeOf/getPrototypeOf.js +2 -0
  56. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/inherits/inherits.js +21 -0
  57. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/inheritsLoose/inheritsLoose.js +6 -0
  58. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +10 -0
  59. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +3 -0
  60. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/instanceof/instanceof.js +7 -0
  61. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/interopRequireDefault/interopRequireDefault.js +5 -0
  62. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +49 -0
  63. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/isNativeFunction/isNativeFunction.js +4 -0
  64. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -0
  65. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/iterableToArray/iterableToArray.js +3 -0
  66. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +38 -0
  67. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +13 -0
  68. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/jsx/jsx.js +49 -0
  69. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/maybeArrayLike/maybeArrayLike.js +10 -0
  70. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/newArrowCheck/newArrowCheck.js +5 -0
  71. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/nonIterableRest/nonIterableRest.js +3 -0
  72. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/nonIterableSpread/nonIterableSpread.js +3 -0
  73. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -0
  74. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectSpread/objectSpread.js +22 -0
  75. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectSpread2/objectSpread2.js +41 -0
  76. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +20 -0
  77. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +15 -0
  78. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +10 -0
  79. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/readOnlyError/readOnlyError.js +4 -0
  80. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/readme.md +8 -0
  81. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/set/set.js +51 -0
  82. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/setPrototypeOf/setPrototypeOf.js +5 -0
  83. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -0
  84. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/slicedToArray/slicedToArray.js +5 -0
  85. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +7 -0
  86. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/superPropBase/superPropBase.js +10 -0
  87. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +11 -0
  88. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +8 -0
  89. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/tdz/tdz.js +4 -0
  90. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/temporalRef/temporalRef.js +5 -0
  91. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/temporalUndefined/temporalUndefined.js +3 -0
  92. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/toArray/toArray.js +5 -0
  93. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/toConsumableArray/toConsumableArray.js +5 -0
  94. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/toPrimitive/toPrimitive.js +14 -0
  95. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/toPropertyKey/toPropertyKey.js +5 -0
  96. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/typeof/typeof.js +7 -0
  97. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +10 -0
  98. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +7 -0
  99. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +35 -0
  100. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/wrapRegExp/wrapRegExp.js +67 -0
  101. package/dist/node_modules/@jsenv/babel-plugins/src/babel_helpers/writeOnlyError/writeOnlyError.js +4 -0
  102. package/dist/other/jsenv.png +0 -0
  103. package/package.json +15 -11
  104. package/src/build/build.js +152 -67
  105. package/src/build/build_urls_generator.js +18 -2
  106. package/src/build/inject_service_worker_urls.js +1 -1
  107. package/src/build/resync_ressource_hints.js +56 -9
  108. package/src/dev/plugins/explorer/client/explorer.html +1 -1
  109. package/src/dev/start_dev_server.js +17 -3
  110. package/src/execute/execute.js +3 -0
  111. package/src/omega/errors.js +10 -7
  112. package/src/omega/kitchen.js +209 -216
  113. package/src/omega/url_graph/url_graph_report.js +2 -2
  114. package/src/omega/url_graph.js +1 -1
  115. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +5 -10
  116. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +1 -3
  117. package/src/plugins/bundling/js_module/bundle_js_module.js +66 -24
  118. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +171 -53
  119. package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +9 -13
  120. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +6 -6
  121. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +5 -10
  122. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +12 -2
  123. package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +12 -0
  124. package/src/plugins/plugin_controller.js +17 -3
  125. package/src/plugins/plugins.js +16 -19
  126. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +7 -13
  127. package/src/plugins/transpilation/as_js_classic/{jsenv_plugin_script_type_module_as_classic.js → jsenv_plugin_as_js_classic_html.js} +0 -0
  128. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +1 -2
  129. package/src/plugins/url_analysis/html/html_urls.js +3 -0
  130. package/src/plugins/url_analysis/js/js_urls.js +2 -1
  131. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +87 -1
  132. package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +3 -0
  133. package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +0 -3
  134. package/src/test/execute_plan.js +2 -0
  135. package/dist/event_source_client.js.map +0 -188
  136. package/dist/html_supervisor_installer.js +0 -1236
  137. package/dist/html_supervisor_installer.js.map +0 -337
  138. package/dist/html_supervisor_setup.js +0 -95
  139. package/dist/html_supervisor_setup.js.map +0 -57
  140. package/dist/import_meta_hot.js.map +0 -42
  141. package/dist/s.js +0 -626
  142. package/dist/s.js.map +0 -207
  143. package/src/jsenv_root_directory_url.js +0 -1
  144. package/src/omega/compat/default_runtime_compat.js +0 -11
  145. package/src/plugins/filesystem_magic/jsenv_plugin_filesystem_magic.js +0 -61
  146. 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,27 @@ 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
+ urlAnalysis = {},
93
108
  nodeEsmResolution,
94
109
  fileSystemMagicResolution,
110
+ directoryReferenceAllowed,
95
111
  injectedGlobals,
96
- runtimeCompat,
97
112
  transpilation = {},
98
113
  bundling = true,
99
114
  minification = true,
@@ -113,7 +128,6 @@ export const build = async ({
113
128
  buildDirectoryClean = true,
114
129
  writeOnFileSystem = true,
115
130
  writeGeneratedFiles = false,
116
- baseUrl = "/",
117
131
  assetManifest = true,
118
132
  assetManifestFileRelativeUrl = "asset-manifest.json",
119
133
  }) => {
@@ -161,6 +175,7 @@ build ${entryPointKeys.length} entry points`)
161
175
  disabled: infoLogsAreDisabled,
162
176
  })
163
177
  let urlCount = 0
178
+ const prebuildRedirections = new Map()
164
179
  const rawGraphKitchen = createKitchen({
165
180
  signal,
166
181
  logger,
@@ -180,13 +195,33 @@ build ${entryPointKeys.length} entry points`)
180
195
  prebuildTask.setRightText(urlCount)
181
196
  },
182
197
  },
198
+ {
199
+ appliesDuring: "build",
200
+ fetchUrlContent: (urlInfo, context) => {
201
+ if (context.reference.original) {
202
+ prebuildRedirections.set(
203
+ context.reference.original.url,
204
+ context.reference.url,
205
+ )
206
+ }
207
+ },
208
+ formatUrl: (reference) => {
209
+ if (!reference.shouldHandle) {
210
+ return `ignore:${reference.specifier}`
211
+ }
212
+ return null
213
+ },
214
+ },
183
215
  ...getCorePlugins({
184
216
  rootDirectoryUrl,
185
217
  urlGraph: rawGraph,
186
218
  scenario: "build",
219
+ runtimeCompat,
187
220
 
221
+ urlAnalysis,
188
222
  nodeEsmResolution,
189
223
  fileSystemMagicResolution,
224
+ directoryReferenceAllowed,
190
225
  injectedGlobals,
191
226
  transpilation: {
192
227
  ...transpilation,
@@ -229,8 +264,8 @@ build ${entryPointKeys.length} entry points`)
229
264
  buildDirectoryUrl,
230
265
  })
231
266
  const rawUrls = {}
267
+ const bundleRedirections = {}
232
268
  const buildUrls = {}
233
- const rawUrlRedirections = {}
234
269
  const bundleUrlInfos = {}
235
270
  const bundlers = {}
236
271
  rawGraphKitchen.pluginController.plugins.forEach((plugin) => {
@@ -320,7 +355,7 @@ build ${entryPointKeys.length} entry points`)
320
355
  })
321
356
  }
322
357
  })
323
- const bundleUrlRedirections = {}
358
+ const bundleInternalRedirections = {}
324
359
  await Object.keys(bundlers).reduce(async (previous, type) => {
325
360
  await previous
326
361
  const bundler = bundlers[type]
@@ -362,7 +397,7 @@ build ${entryPointKeys.length} entry points`)
362
397
  const buildUrl = buildUrlsGenerator.generate(url, {
363
398
  urlInfo: bundleUrlInfo,
364
399
  })
365
- rawUrlRedirections[url] = buildUrl
400
+ bundleRedirections[url] = buildUrl
366
401
  rawUrls[buildUrl] = url
367
402
  bundleUrlInfos[buildUrl] = bundleUrlInfo
368
403
  if (buildUrl.includes("?")) {
@@ -373,7 +408,9 @@ build ${entryPointKeys.length} entry points`)
373
408
  bundlerGeneratedUrlInfo.data.bundleRelativeUrl,
374
409
  buildDirectoryUrl,
375
410
  ).href
376
- bundleUrlRedirections[urlForBundler] = buildUrl
411
+ if (urlForBundler !== buildUrl) {
412
+ bundleInternalRedirections[urlForBundler] = buildUrl
413
+ }
377
414
  }
378
415
  })
379
416
  } catch (e) {
@@ -383,7 +420,11 @@ build ${entryPointKeys.length} entry points`)
383
420
  bundleTask.done()
384
421
  }, Promise.resolve())
385
422
 
386
- const buildUrlRedirections = {}
423
+ const urlAnalysisPlugin = jsenvPluginUrlAnalysis({
424
+ rootDirectoryUrl,
425
+ ...urlAnalysis,
426
+ })
427
+ const postBuildRedirections = {}
387
428
  const finalGraph = createUrlGraph()
388
429
  const optimizeUrlContentHooks =
389
430
  rawGraphKitchen.pluginController.addHook("optimizeUrlContent")
@@ -397,34 +438,58 @@ build ${entryPointKeys.length} entry points`)
397
438
  runtimeCompat,
398
439
  writeGeneratedFiles,
399
440
  plugins: [
400
- jsenvPluginUrlAnalysis(),
401
- jsenvPluginAsJsClassic({
402
- rootDirectoryUrl,
403
- systemJsInjection: true,
404
- }),
405
- jsenvPluginInline({
406
- fetchInlineUrls: false,
407
- }),
441
+ urlAnalysisPlugin,
442
+ jsenvPluginAsJsClassic({ systemJsInjection: true }),
443
+ jsenvPluginInline({ fetchInlineUrls: false }),
408
444
  {
409
445
  name: "jsenv:postbuild",
410
- appliesDuring: { build: true },
446
+ appliesDuring: "build",
411
447
  resolveUrl: (reference) => {
412
- if (reference.specifier[0] === "#") {
413
- reference.external = true
448
+ const performInternalRedirections = (url) => {
449
+ const prebuildRedirection = prebuildRedirections.get(url)
450
+ if (prebuildRedirection) {
451
+ logger.debug(
452
+ `\nprebuild redirection\n${url} ->\n${prebuildRedirection}\n`,
453
+ )
454
+ url = prebuildRedirection
455
+ }
456
+ const bundleRedirection = bundleRedirections[url]
457
+ if (bundleRedirection) {
458
+ logger.debug(
459
+ `\nbundler redirection\n${url} ->\n${bundleRedirection}\n`,
460
+ )
461
+ url = bundleRedirection
462
+ }
463
+ const bundleInternalRedirection = bundleInternalRedirections[url]
464
+ if (bundleInternalRedirection) {
465
+ logger.debug(
466
+ `\nbundler internal redirection\n${url} ->\n${bundleInternalRedirection}\n`,
467
+ )
468
+ url = bundleInternalRedirection
469
+ }
470
+ return url
471
+ }
472
+
473
+ if (reference.type === "filesystem") {
474
+ const parentRawUrl = rawUrls[reference.parentUrl]
475
+ const baseUrl = ensurePathnameTrailingSlash(parentRawUrl)
476
+ return performInternalRedirections(
477
+ new URL(reference.specifier, baseUrl).href,
478
+ )
414
479
  }
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
480
+ if (reference.specifier[0] === "/") {
481
+ return performInternalRedirections(
482
+ new URL(reference.specifier.slice(1), buildDirectoryUrl).href,
483
+ )
425
484
  }
426
- return url
485
+ return performInternalRedirections(
486
+ new URL(
487
+ reference.specifier,
488
+ reference.baseUrl || reference.parentUrl,
489
+ ).href,
490
+ )
427
491
  },
492
+ // redirecting urls into the build directory
428
493
  redirectUrl: (reference) => {
429
494
  if (!reference.url.startsWith("file:")) {
430
495
  return null
@@ -434,11 +499,6 @@ build ${entryPointKeys.length} entry points`)
434
499
  if (rawUrl) {
435
500
  return reference.url
436
501
  }
437
- // from rollup or postcss
438
- const bundleUrlInfo = bundleUrlInfos[reference.url]
439
- if (bundleUrlInfo) {
440
- return reference.url
441
- }
442
502
  // from "js_module_as_js_classic":
443
503
  // - injecting "?as_js_classic" for the first time
444
504
  // - injecting "?as_js_classic" because the parentUrl has it
@@ -454,9 +514,8 @@ build ${entryPointKeys.length} entry points`)
454
514
  }
455
515
  let rawUrl
456
516
  if (urlIsInsideOf(reference.url, buildDirectoryUrl)) {
457
- // rawUrl = rawUrls[reference.url] || reference.url
458
517
  const originalBuildUrl =
459
- buildUrlRedirections[referenceOriginalUrl]
518
+ postBuildRedirections[referenceOriginalUrl]
460
519
  rawUrl = originalBuildUrl
461
520
  ? rawUrls[originalBuildUrl]
462
521
  : reference.url
@@ -478,7 +537,7 @@ build ${entryPointKeys.length} entry points`)
478
537
  filename: reference.filename,
479
538
  },
480
539
  })
481
- buildUrlRedirections[originalBuildUrl] = buildUrl
540
+ postBuildRedirections[originalBuildUrl] = buildUrl
482
541
  rawUrls[buildUrl] = rawUrl
483
542
  return buildUrl
484
543
  }
@@ -522,10 +581,12 @@ build ${entryPointKeys.length} entry points`)
522
581
  return buildUrl
523
582
  }
524
583
  const rawUrlInfo = rawGraph.getUrlInfo(reference.url)
584
+ const parentUrlInfo = finalGraph.getUrlInfo(reference.parentUrl)
525
585
  // files from root directory but not given to rollup nor postcss
526
586
  if (rawUrlInfo) {
527
587
  const buildUrl = buildUrlsGenerator.generate(reference.url, {
528
588
  urlInfo: rawUrlInfo,
589
+ parentUrlInfo,
529
590
  })
530
591
  if (buildUrl.includes("?")) {
531
592
  rawUrls[asUrlWithoutSearch(buildUrl)] = rawUrlInfo.url
@@ -550,6 +611,9 @@ build ${entryPointKeys.length} entry points`)
550
611
  },
551
612
  formatUrl: (reference) => {
552
613
  if (!reference.generatedUrl.startsWith("file:")) {
614
+ if (!versioning && reference.generatedUrl.startsWith("ignore:")) {
615
+ return reference.generatedUrl.slice("ignore:".length)
616
+ }
553
617
  return null
554
618
  }
555
619
  if (!urlIsInsideOf(reference.generatedUrl, buildDirectoryUrl)) {
@@ -557,6 +621,10 @@ build ${entryPointKeys.length} entry points`)
557
621
  `urls should be inside build directory at this stage, found "${reference.url}"`,
558
622
  )
559
623
  }
624
+ if (reference.isRessourceHint) {
625
+ // return the raw url, we will resync at the end
626
+ return rawUrls[reference.url]
627
+ }
560
628
  // remove eventual search params and hash
561
629
  const urlUntilPathname = asUrlUntilPathname(reference.generatedUrl)
562
630
  let specifier
@@ -582,23 +650,18 @@ build ${entryPointKeys.length} entry points`)
582
650
  return specifier
583
651
  },
584
652
  fetchUrlContent: async (finalUrlInfo, context) => {
585
- if (!finalUrlInfo.url.startsWith("file:")) {
586
- return { external: true }
587
- }
588
653
  const fromBundleOrRawGraph = (url) => {
589
654
  const bundleUrlInfo = bundleUrlInfos[url]
590
655
  if (bundleUrlInfo) {
656
+ logger.debug(`fetching from bundle ${url}`)
591
657
  return bundleUrlInfo
592
658
  }
593
659
  const rawUrl = rawUrls[url] || url
594
660
  const rawUrlInfo = rawGraph.getUrlInfo(rawUrl)
595
661
  if (!rawUrlInfo) {
596
- const originalBuildUrl = buildUrlRedirections[url]
597
- if (originalBuildUrl) {
598
- return fromBundleOrRawGraph(originalBuildUrl)
599
- }
600
662
  throw new Error(`Cannot find url`)
601
663
  }
664
+ logger.debug(`fetching from raw graph ${url}`)
602
665
  if (rawUrlInfo.isInline) {
603
666
  // Inline content, such as <script> inside html, is transformed during the previous phase.
604
667
  // If we read the inline content it would be considered as the original content.
@@ -638,7 +701,7 @@ build ${entryPointKeys.length} entry points`)
638
701
  },
639
702
  {
640
703
  name: "jsenv:optimize",
641
- appliesDuring: { build: true },
704
+ appliesDuring: "build",
642
705
  finalizeUrlContent: async (urlInfo, context) => {
643
706
  if (optimizeUrlContentHooks.length) {
644
707
  await rawGraphKitchen.pluginController.callAsyncHooks(
@@ -702,6 +765,7 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
702
765
  runtimeCompat,
703
766
  writeGeneratedFiles,
704
767
  rawGraph,
768
+ urlAnalysisPlugin,
705
769
  finalGraph,
706
770
  finalGraphKitchen,
707
771
  lineBreakNormalization,
@@ -709,10 +773,10 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
709
773
  })
710
774
  }
711
775
  GRAPH.forEach(finalGraph, (urlInfo) => {
712
- if (!urlInfo.url.startsWith("file:")) {
776
+ if (!urlInfo.shouldHandle) {
713
777
  return
714
778
  }
715
- if (urlInfo.external) {
779
+ if (!urlInfo.url.startsWith("file:")) {
716
780
  return
717
781
  }
718
782
  if (urlInfo.type === "html") {
@@ -734,10 +798,11 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
734
798
  urlInfo.data.buildUrlSpecifier = buildUrlSpecifier
735
799
  })
736
800
  await resyncRessourceHints({
801
+ logger,
737
802
  finalGraphKitchen,
738
803
  finalGraph,
739
804
  rawUrls,
740
- buildUrls,
805
+ postBuildRedirections,
741
806
  })
742
807
  buildOperation.throwIfAborted()
743
808
  const cleanupActions = []
@@ -767,10 +832,13 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
767
832
  const buildFileContents = {}
768
833
  const buildInlineContents = {}
769
834
  GRAPH.forEach(finalGraph, (urlInfo) => {
770
- if (urlInfo.external) {
835
+ if (!urlInfo.shouldHandle) {
836
+ return
837
+ }
838
+ if (!urlInfo.url.startsWith("file:")) {
771
839
  return
772
840
  }
773
- if (urlInfo.url.startsWith("data:")) {
841
+ if (urlInfo.type === "directory") {
774
842
  return
775
843
  }
776
844
  const buildRelativeUrl = urlToRelativeUrl(
@@ -904,6 +972,7 @@ const applyUrlVersioning = async ({
904
972
  runtimeCompat,
905
973
  writeGeneratedFiles,
906
974
  rawGraph,
975
+ urlAnalysisPlugin,
907
976
  finalGraph,
908
977
  finalGraphKitchen,
909
978
  lineBreakNormalization,
@@ -925,7 +994,7 @@ const applyUrlVersioning = async ({
925
994
  // ignore:
926
995
  // - inline files:
927
996
  // they are already taken into account in the file where they appear
928
- // - external files
997
+ // - ignored files:
929
998
  // we don't know their content
930
999
  // - unused files without reference
931
1000
  // File updated such as style.css -> style.css.js or file.js->file.es5.js
@@ -935,7 +1004,7 @@ const applyUrlVersioning = async ({
935
1004
  if (urlInfo.isInline) {
936
1005
  return
937
1006
  }
938
- if (urlInfo.external) {
1007
+ if (!urlInfo.shouldHandle) {
939
1008
  return
940
1009
  }
941
1010
  if (!urlInfo.data.isEntryPoint && urlInfo.dependents.size === 0) {
@@ -958,8 +1027,8 @@ const applyUrlVersioning = async ({
958
1027
  lineBreakNormalization,
959
1028
  })
960
1029
  urlInfo.dependencies.forEach((dependencyUrl) => {
961
- // this dependency is inline (data:) or remote (http://, https://)
962
- if (!dependencyUrl.startsWith("file:")) {
1030
+ // this dependency is inline
1031
+ if (dependencyUrl.startsWith("data:")) {
963
1032
  return
964
1033
  }
965
1034
  const dependencyUrlInfo = finalGraph.getUrlInfo(dependencyUrl)
@@ -967,7 +1036,7 @@ const applyUrlVersioning = async ({
967
1036
  // this content is part of the file, no need to take into account twice
968
1037
  dependencyUrlInfo.isInline ||
969
1038
  // this dependency content is not known
970
- dependencyUrlInfo.external
1039
+ !dependencyUrlInfo.shouldHandle
971
1040
  ) {
972
1041
  return
973
1042
  }
@@ -1009,7 +1078,7 @@ const applyUrlVersioning = async ({
1009
1078
  runtimeCompat,
1010
1079
  writeGeneratedFiles,
1011
1080
  plugins: [
1012
- jsenvPluginUrlAnalysis(),
1081
+ urlAnalysisPlugin,
1013
1082
  jsenvPluginInline({
1014
1083
  fetchInlineUrls: false,
1015
1084
  analyzeConvertedScripts: true, // to be able to version their urls
@@ -1019,18 +1088,38 @@ const applyUrlVersioning = async ({
1019
1088
  name: "jsenv:versioning",
1020
1089
  appliesDuring: { build: true },
1021
1090
  resolveUrl: (reference) => {
1022
- if (reference.specifier[0] === "#") {
1023
- reference.external = true
1024
- }
1025
1091
  const buildUrl = buildUrls[reference.specifier]
1026
1092
  if (buildUrl) {
1027
1093
  return buildUrl
1028
1094
  }
1029
- const url = new URL(reference.specifier, reference.parentUrl).href
1095
+ const urlObject = new URL(
1096
+ reference.specifier,
1097
+ reference.baseUrl || reference.parentUrl,
1098
+ )
1099
+ const url = urlObject.href
1100
+ // during versioning we revisit the deps
1101
+ // but the code used to enforce trailing slash on directories
1102
+ // is not applied because "jsenv:file_url_resolution" is not used
1103
+ // so here we search if the url with a trailing slash exists
1104
+ if (
1105
+ reference.type === "filesystem" &&
1106
+ !urlObject.pathname.endsWith("/")
1107
+ ) {
1108
+ const urlWithTrailingSlash = `${url}/`
1109
+ const specifier = Object.keys(buildUrls).find(
1110
+ (key) => buildUrls[key] === urlWithTrailingSlash,
1111
+ )
1112
+ if (specifier) {
1113
+ return urlWithTrailingSlash
1114
+ }
1115
+ }
1030
1116
  return url
1031
1117
  },
1032
1118
  formatUrl: (reference) => {
1033
- if (reference.isInline) {
1119
+ if (reference.isInline || reference.url.startsWith("data:")) {
1120
+ return null
1121
+ }
1122
+ if (reference.isRessourceHint) {
1034
1123
  return null
1035
1124
  }
1036
1125
  // specifier comes from "normalize" hook done a bit earlier in this file
@@ -1039,8 +1128,7 @@ const applyUrlVersioning = async ({
1039
1128
  if (!canUseVersionedUrl(referencedUrlInfo)) {
1040
1129
  return reference.specifier
1041
1130
  }
1042
- // data:* urls and so on
1043
- if (!referencedUrlInfo.url.startsWith("file:")) {
1131
+ if (!referencedUrlInfo.shouldHandle) {
1044
1132
  return null
1045
1133
  }
1046
1134
  const versionedUrl = referencedUrlInfo.data.versionedUrl
@@ -1077,9 +1165,6 @@ const applyUrlVersioning = async ({
1077
1165
  return versionedSpecifier
1078
1166
  },
1079
1167
  fetchUrlContent: (versionedUrlInfo) => {
1080
- if (!versionedUrlInfo.url.startsWith("file:")) {
1081
- return { external: true }
1082
- }
1083
1168
  if (versionedUrlInfo.isInline) {
1084
1169
  const rawUrlInfo = rawGraph.getUrlInfo(
1085
1170
  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.warn(
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(
@@ -4,7 +4,7 @@
4
4
  <title>Exploring</title>
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <meta charset="utf-8" />
7
- <link rel="icon" href="FAVICON_HREF" />
7
+ <link rel="icon" href="./jsenv.png" />
8
8
  <style>
9
9
  button:focus,
10
10
  a:focus,