@jsenv/core 35.0.3 → 35.0.5

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 (117) hide show
  1. package/dist/html/explorer.html +107 -107
  2. package/dist/js/new_stylesheet.js +3 -0
  3. package/dist/js/s.js.map +3 -3
  4. package/package.json +2 -2
  5. package/src/build/build.js +589 -587
  6. package/src/build/build_urls_generator.js +44 -44
  7. package/src/build/graph_utils.js +14 -14
  8. package/src/build/jsenv_plugin_line_break_normalization.js +6 -6
  9. package/src/build/line_break_unix.js +11 -11
  10. package/src/build/start_build_server.js +37 -37
  11. package/src/build/version_generator.js +7 -7
  12. package/src/build/version_mappings_injection.js +23 -23
  13. package/src/dev/file_service.js +132 -132
  14. package/src/dev/start_dev_server.js +56 -56
  15. package/src/dev/user_agent.js +8 -8
  16. package/src/helpers/basic_fetch.js +24 -24
  17. package/src/helpers/command/command.js +28 -28
  18. package/src/helpers/lookup_package_directory.js +19 -16
  19. package/src/helpers/ping_server.js +17 -17
  20. package/src/helpers/require_from_jsenv.js +2 -2
  21. package/src/helpers/watch_source_files.js +9 -9
  22. package/src/helpers/web_url_converter.js +10 -10
  23. package/src/helpers/worker_reload.js +27 -27
  24. package/src/kitchen/compat/features_compatibility.js +1 -1
  25. package/src/kitchen/compat/runtime_compat.js +26 -24
  26. package/src/kitchen/errors.js +75 -75
  27. package/src/kitchen/fetched_content_compliance.js +8 -8
  28. package/src/kitchen/kitchen.js +251 -250
  29. package/src/kitchen/url_graph/sort_by_dependencies.js +17 -17
  30. package/src/kitchen/url_graph/url_graph_loader.js +30 -30
  31. package/src/kitchen/url_graph/url_graph_report.js +57 -57
  32. package/src/kitchen/url_graph/url_info_transformations.js +77 -77
  33. package/src/kitchen/url_graph.js +121 -121
  34. package/src/kitchen/url_specifier_encoding.js +21 -21
  35. package/src/kitchen/web_workers.js +5 -5
  36. package/src/main.js +3 -3
  37. package/src/plugins/autoreload/client/autoreload.js +96 -96
  38. package/src/plugins/autoreload/client/reload.js +56 -56
  39. package/src/plugins/autoreload/client/url_helpers.js +13 -13
  40. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +5 -5
  41. package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +9 -9
  42. package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +61 -60
  43. package/src/plugins/autoreload/jsenv_plugin_hmr.js +15 -15
  44. package/src/plugins/cache_control/jsenv_plugin_cache_control.js +5 -5
  45. package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +57 -57
  46. package/src/plugins/explorer/client/explorer.html +107 -107
  47. package/src/plugins/explorer/jsenv_plugin_explorer.js +20 -20
  48. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +60 -60
  49. package/src/plugins/global_scenarios/jsenv_plugin_global_scenarios.js +5 -5
  50. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +3 -3
  51. package/src/plugins/import_meta_hot/babel_plugin_metadata_import_meta_hot.js +35 -35
  52. package/src/plugins/import_meta_hot/client/import_meta_hot.js +26 -26
  53. package/src/plugins/import_meta_hot/html_hot_dependencies.js +43 -43
  54. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +44 -40
  55. package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +35 -35
  56. package/src/plugins/import_meta_url/client/import_meta_url_browser.js +21 -21
  57. package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +3 -3
  58. package/src/plugins/importmap/jsenv_plugin_importmap.js +54 -54
  59. package/src/plugins/inline_content_analysis/client/inline_content.js +3 -3
  60. package/src/plugins/inline_content_analysis/jsenv_plugin_data_urls.js +26 -26
  61. package/src/plugins/inline_content_analysis/jsenv_plugin_html_inline_content_analysis.js +47 -47
  62. package/src/plugins/inline_content_analysis/jsenv_plugin_inline_content_analysis.js +9 -9
  63. package/src/plugins/inline_content_analysis/jsenv_plugin_js_inline_content_analysis.js +101 -101
  64. package/src/plugins/inlining/jsenv_plugin_inlining.js +9 -9
  65. package/src/plugins/inlining/jsenv_plugin_inlining_as_data_url.js +11 -11
  66. package/src/plugins/inlining/jsenv_plugin_inlining_into_html.js +48 -46
  67. package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +4 -4
  68. package/src/plugins/plugin_controller.js +124 -124
  69. package/src/plugins/plugins.js +27 -27
  70. package/src/plugins/ribbon/client/ribbon.js +6 -6
  71. package/src/plugins/ribbon/jsenv_plugin_ribbon.js +15 -15
  72. package/src/plugins/server_events/client/connection_manager.js +52 -52
  73. package/src/plugins/server_events/client/event_source_connection.js +36 -36
  74. package/src/plugins/server_events/client/events_manager.js +37 -37
  75. package/src/plugins/server_events/client/server_events_client.js +7 -7
  76. package/src/plugins/server_events/client/web_socket_connection.js +39 -39
  77. package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +9 -9
  78. package/src/plugins/server_events/server_events_dispatcher.js +43 -43
  79. package/src/plugins/supervisor/client/supervisor.js +455 -450
  80. package/src/plugins/supervisor/html_supervisor_injection.js +64 -62
  81. package/src/plugins/supervisor/js_supervisor_injection.js +67 -67
  82. package/src/plugins/supervisor/jsenv_plugin_supervisor.js +54 -51
  83. package/src/plugins/transpilation/as_js_module/convert_js_classic_to_js_module.js +13 -13
  84. package/src/plugins/transpilation/as_js_module/jsenv_plugin_as_js_module.js +19 -19
  85. package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +10 -10
  86. package/src/plugins/transpilation/babel/global_this/client/global_this.js +8 -8
  87. package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +16 -16
  88. package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +36 -36
  89. package/src/plugins/transpilation/babel/helpers/babel_plugins_compatibility.js +3 -3
  90. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +24 -24
  91. package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +44 -44
  92. package/src/plugins/transpilation/babel/new_stylesheet/client/new_stylesheet.js +166 -166
  93. package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +10 -10
  94. package/src/plugins/transpilation/babel/require_babel_plugin.js +6 -6
  95. package/src/plugins/transpilation/css/jsenv_plugin_css_transpilation.js +20 -20
  96. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +62 -62
  97. package/src/plugins/transpilation/js_module_fallback/client/s.js +214 -209
  98. package/src/plugins/transpilation/js_module_fallback/convert_js_module_to_js_classic.js +45 -45
  99. package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_resolve.js +6 -6
  100. package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_url.js +17 -17
  101. package/src/plugins/transpilation/js_module_fallback/helpers-string.js +1 -1
  102. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_conversion.js +32 -32
  103. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js +17 -17
  104. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +63 -63
  105. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +15 -15
  106. package/src/plugins/transpilation/jsenv_plugin_import_meta_resolve.js +20 -20
  107. package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +23 -23
  108. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +11 -11
  109. package/src/plugins/url_analysis/css/css_urls.js +12 -12
  110. package/src/plugins/url_analysis/html/html_urls.js +85 -85
  111. package/src/plugins/url_analysis/js/js_urls.js +16 -16
  112. package/src/plugins/url_analysis/jsenv_plugin_reference_expected_types.js +16 -16
  113. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +40 -40
  114. package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +12 -12
  115. package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +35 -35
  116. package/src/plugins/url_resolution/node_esm_resolver.js +26 -26
  117. package/src/plugins/url_version/jsenv_plugin_url_version.js +11 -11
@@ -368,7 +368,7 @@
368
368
  </div>
369
369
  <script no-supervisor>
370
370
  // eslint-disable-next-line no-undef
371
- const { rootDirectoryUrl, groups, files } = SERVER_PARAMS
371
+ const { rootDirectoryUrl, groups, files } = SERVER_PARAMS;
372
372
 
373
373
  const groupPreference = {
374
374
  has: () => localStorage.hasOwnProperty("explorer_active_group"),
@@ -378,30 +378,30 @@
378
378
  : undefined,
379
379
  set: (value) =>
380
380
  localStorage.setItem("explorer_active_group", JSON.stringify(value)),
381
- }
381
+ };
382
382
  const directoryNameFromUrl = (directoryUrl) => {
383
383
  const slashLastIndex = directoryUrl.lastIndexOf(
384
384
  "/",
385
385
  // ignore last slash
386
386
  directoryUrl.length - 2,
387
- )
388
- if (slashLastIndex === -1) return ""
389
- return directoryUrl.slice(slashLastIndex + 1)
390
- }
387
+ );
388
+ if (slashLastIndex === -1) return "";
389
+ return directoryUrl.slice(slashLastIndex + 1);
390
+ };
391
391
  const urlToVisitFromRelativeUrl = (relativeUrl) => {
392
- return `${window.origin}/${relativeUrl}`
393
- }
392
+ return `${window.origin}/${relativeUrl}`;
393
+ };
394
394
 
395
395
  const fileListElement = document
396
396
  .querySelector(`[data-page="file-list"]`)
397
- .cloneNode(true)
398
- const directoryName = directoryNameFromUrl(rootDirectoryUrl)
399
- const span = fileListElement.querySelector("#directory_relative_url")
400
- span.title = rootDirectoryUrl
401
- span.textContent = directoryName
402
-
403
- const h4 = fileListElement.querySelector("h4")
404
- const ul = fileListElement.querySelector("ul")
397
+ .cloneNode(true);
398
+ const directoryName = directoryNameFromUrl(rootDirectoryUrl);
399
+ const span = fileListElement.querySelector("#directory_relative_url");
400
+ span.title = rootDirectoryUrl;
401
+ span.textContent = directoryName;
402
+
403
+ const h4 = fileListElement.querySelector("h4");
404
+ const ul = fileListElement.querySelector("ul");
405
405
  ul.innerHTML = files
406
406
  .map(
407
407
  (file) =>
@@ -415,10 +415,10 @@
415
415
  </a>
416
416
  </li>`,
417
417
  )
418
- .join("")
418
+ .join("");
419
419
 
420
- const groupFieldset = fileListElement.querySelector("#filter-group-set")
421
- const groupNames = Object.keys(groups)
420
+ const groupFieldset = fileListElement.querySelector("#filter-group-set");
421
+ const groupNames = Object.keys(groups);
422
422
  groupFieldset.innerHTML = groupNames
423
423
  .map(
424
424
  (key) => `<label data-contains-hidden-input class="item">
@@ -426,45 +426,45 @@
426
426
  <span>${key}</span>
427
427
  </label>`,
428
428
  )
429
- .join("")
429
+ .join("");
430
430
 
431
- const groupFromLocalStorage = groupPreference.get()
431
+ const groupFromLocalStorage = groupPreference.get();
432
432
  const currentGroup =
433
433
  groupFromLocalStorage && groupNames.includes(groupFromLocalStorage)
434
434
  ? groupFromLocalStorage
435
- : groupNames[0]
435
+ : groupNames[0];
436
436
  Array.from(groupFieldset.querySelectorAll("input")).forEach(
437
437
  (inputRadio) => {
438
- inputRadio.checked = inputRadio.value === currentGroup
438
+ inputRadio.checked = inputRadio.value === currentGroup;
439
439
  inputRadio.onchange = () => {
440
440
  if (inputRadio.checked) {
441
- groupPreference.set(inputRadio.value)
442
- enableGroup(inputRadio.value)
441
+ groupPreference.set(inputRadio.value);
442
+ enableGroup(inputRadio.value);
443
443
  }
444
- }
444
+ };
445
445
  },
446
- )
446
+ );
447
447
 
448
448
  const enableGroup = (groupName) => {
449
- const arrayOfElementToShow = []
450
- const arrayOfElementToHide = []
449
+ const arrayOfElementToShow = [];
450
+ const arrayOfElementToHide = [];
451
451
  files.forEach((file) => {
452
452
  const fileLink = fileListElement.querySelector(
453
453
  `a[data-relative-url="${file.relativeUrl}"]`,
454
- )
455
- const fileLi = fileLink.parentNode
454
+ );
455
+ const fileLi = fileLink.parentNode;
456
456
  if (file.meta[groupName]) {
457
- arrayOfElementToShow.push(fileLi)
457
+ arrayOfElementToShow.push(fileLi);
458
458
  } else {
459
- arrayOfElementToHide.push(fileLi)
459
+ arrayOfElementToHide.push(fileLi);
460
460
  }
461
- })
461
+ });
462
462
  arrayOfElementToShow.forEach((element) => {
463
- element.removeAttribute("data-force-hide")
464
- })
463
+ element.removeAttribute("data-force-hide");
464
+ });
465
465
  arrayOfElementToHide.forEach((element) => {
466
- element.setAttribute("data-force-hide", "")
467
- })
466
+ element.setAttribute("data-force-hide", "");
467
+ });
468
468
 
469
469
  h4.innerHTML =
470
470
  arrayOfElementToShow.length === 0
@@ -474,65 +474,65 @@
474
474
  null,
475
475
  " ",
476
476
  )}</pre>`
477
- : `${arrayOfElementToShow.length} files found. Click on the one you want to execute`
478
- }
479
- enableGroup(currentGroup)
477
+ : `${arrayOfElementToShow.length} files found. Click on the one you want to execute`;
478
+ };
479
+ enableGroup(currentGroup);
480
480
 
481
- document.querySelector("main").appendChild(fileListElement)
481
+ document.querySelector("main").appendChild(fileListElement);
482
482
  </script>
483
483
  <script no-supervisor>
484
484
  // make menu scrollable
485
485
  const getMenuWrapperSize = () => {
486
486
  return document.querySelector(".menu-wrapper").getBoundingClientRect()
487
- .width
488
- }
487
+ .width;
488
+ };
489
489
  const getMenuSize = () => {
490
- return document.querySelector(".menu").getBoundingClientRect().width
491
- }
490
+ return document.querySelector(".menu").getBoundingClientRect().width;
491
+ };
492
492
  const getMenuPosition = () => {
493
- return document.querySelector(".menu-wrapper").scrollLeft
494
- }
493
+ return document.querySelector(".menu-wrapper").scrollLeft;
494
+ };
495
495
 
496
- let menuWrapperSize = getMenuWrapperSize()
497
- let menuSize = getMenuSize()
498
- const menuVisibleSize = menuWrapperSize
499
- let menuInvisibleSize = menuSize - menuVisibleSize
500
- const scrollDuration = 300
501
- const leftPaddle = document.querySelector(".left-paddle")
502
- const rightPaddle = document.querySelector(".right-paddle")
496
+ let menuWrapperSize = getMenuWrapperSize();
497
+ let menuSize = getMenuSize();
498
+ const menuVisibleSize = menuWrapperSize;
499
+ let menuInvisibleSize = menuSize - menuVisibleSize;
500
+ const scrollDuration = 300;
501
+ const leftPaddle = document.querySelector(".left-paddle");
502
+ const rightPaddle = document.querySelector(".right-paddle");
503
503
 
504
504
  const handleMenuScroll = () => {
505
- menuInvisibleSize = menuSize - menuWrapperSize
506
- const menuPosition = getMenuPosition()
507
- const menuEndOffset = menuInvisibleSize
505
+ menuInvisibleSize = menuSize - menuWrapperSize;
506
+ const menuPosition = getMenuPosition();
507
+ const menuEndOffset = menuInvisibleSize;
508
508
  // show & hide the paddles, depending on scroll position
509
509
  if (menuPosition <= 0 && menuEndOffset <= 0) {
510
510
  // hide both paddles if the window is large enough to display all tabs
511
- leftPaddle.classList.add("hidden")
512
- rightPaddle.classList.add("hidden")
511
+ leftPaddle.classList.add("hidden");
512
+ rightPaddle.classList.add("hidden");
513
513
  } else if (menuPosition <= 0) {
514
- leftPaddle.classList.add("hidden")
515
- rightPaddle.classList.remove("hidden")
514
+ leftPaddle.classList.add("hidden");
515
+ rightPaddle.classList.remove("hidden");
516
516
  } else if (menuPosition < Math.floor(menuEndOffset)) {
517
517
  // show both paddles in the middle
518
- leftPaddle.classList.remove("hidden")
519
- rightPaddle.classList.remove("hidden")
518
+ leftPaddle.classList.remove("hidden");
519
+ rightPaddle.classList.remove("hidden");
520
520
  } else if (menuPosition >= Math.floor(menuEndOffset)) {
521
- leftPaddle.classList.remove("hidden")
522
- rightPaddle.classList.add("hidden")
521
+ leftPaddle.classList.remove("hidden");
522
+ rightPaddle.classList.add("hidden");
523
523
  }
524
- }
525
- handleMenuScroll()
524
+ };
525
+ handleMenuScroll();
526
526
 
527
527
  window.onresize = () => {
528
- menuWrapperSize = getMenuWrapperSize()
529
- menuSize = getMenuSize()
530
- handleMenuScroll()
531
- }
528
+ menuWrapperSize = getMenuWrapperSize();
529
+ menuSize = getMenuSize();
530
+ handleMenuScroll();
531
+ };
532
532
  // finally, what happens when we are actually scrolling the menu
533
533
  document.querySelector(".menu-wrapper").onscroll = () => {
534
- handleMenuScroll()
535
- }
534
+ handleMenuScroll();
535
+ };
536
536
 
537
537
  const startJavaScriptAnimation = ({
538
538
  duration = 300,
@@ -541,68 +541,68 @@
541
541
  onCancel = () => {},
542
542
  onComplete = () => {},
543
543
  }) => {
544
- duration = parseInt(duration, 10)
545
- const startMs = performance.now()
546
- let currentRequestAnimationFrameId
547
- let done = false
548
- let rawProgress = 0
549
- let progress = 0
544
+ duration = parseInt(duration, 10);
545
+ const startMs = performance.now();
546
+ let currentRequestAnimationFrameId;
547
+ let done = false;
548
+ let rawProgress = 0;
549
+ let progress = 0;
550
550
  const handler = () => {
551
- currentRequestAnimationFrameId = null
552
- const nowMs = performance.now()
553
- rawProgress = Math.min((nowMs - startMs) / duration, 1)
554
- progress = timingFunction(rawProgress)
555
- done = rawProgress === 1
551
+ currentRequestAnimationFrameId = null;
552
+ const nowMs = performance.now();
553
+ rawProgress = Math.min((nowMs - startMs) / duration, 1);
554
+ progress = timingFunction(rawProgress);
555
+ done = rawProgress === 1;
556
556
  onProgress({
557
557
  done,
558
558
  rawProgress,
559
559
  progress,
560
- })
560
+ });
561
561
  if (done) {
562
- onComplete()
562
+ onComplete();
563
563
  } else {
564
564
  currentRequestAnimationFrameId =
565
- window.requestAnimationFrame(handler)
565
+ window.requestAnimationFrame(handler);
566
566
  }
567
- }
568
- handler()
567
+ };
568
+ handler();
569
569
  const stop = () => {
570
570
  if (currentRequestAnimationFrameId) {
571
- window.cancelAnimationFrame(currentRequestAnimationFrameId)
572
- currentRequestAnimationFrameId = null
571
+ window.cancelAnimationFrame(currentRequestAnimationFrameId);
572
+ currentRequestAnimationFrameId = null;
573
573
  }
574
574
  if (!done) {
575
- done = true
575
+ done = true;
576
576
  onCancel({
577
577
  rawProgress,
578
578
  progress,
579
- })
579
+ });
580
580
  }
581
- }
582
- return stop
583
- }
581
+ };
582
+ return stop;
583
+ };
584
584
  rightPaddle.onclick = () => {
585
- const scrollStart = document.querySelector(".menu-wrapper").scrollLeft
586
- const scrollEnd = scrollStart + menuWrapperSize
585
+ const scrollStart = document.querySelector(".menu-wrapper").scrollLeft;
586
+ const scrollEnd = scrollStart + menuWrapperSize;
587
587
  startJavaScriptAnimation({
588
588
  duration: scrollDuration,
589
589
  onProgress: ({ progress }) => {
590
590
  document.querySelector(".menu-wrapper").scrollLeft =
591
- scrollStart + (scrollEnd - scrollStart) * progress
591
+ scrollStart + (scrollEnd - scrollStart) * progress;
592
592
  },
593
- })
594
- }
593
+ });
594
+ };
595
595
  leftPaddle.onclick = () => {
596
- const scrollStart = document.querySelector(".menu-wrapper").scrollLeft
597
- const scrollEnd = scrollStart - menuWrapperSize
596
+ const scrollStart = document.querySelector(".menu-wrapper").scrollLeft;
597
+ const scrollEnd = scrollStart - menuWrapperSize;
598
598
  startJavaScriptAnimation({
599
599
  duration: scrollDuration,
600
600
  onProgress: ({ progress }) => {
601
601
  document.querySelector(".menu-wrapper").scrollLeft =
602
- scrollStart + (scrollEnd - scrollStart) * progress
602
+ scrollStart + (scrollEnd - scrollStart) * progress;
603
603
  },
604
- })
605
- }
604
+ });
605
+ };
606
606
  </script>
607
607
  </body>
608
608
  </html>
@@ -1,11 +1,11 @@
1
- import { readFileSync } from "node:fs"
2
- import { DATA_URL } from "@jsenv/urls"
3
- import { collectFiles } from "@jsenv/filesystem"
4
- import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"
1
+ import { readFileSync } from "node:fs";
2
+ import { DATA_URL } from "@jsenv/urls";
3
+ import { collectFiles } from "@jsenv/filesystem";
4
+ import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js";
5
5
 
6
6
  export const explorerHtmlFileUrl = String(
7
7
  new URL("./client/explorer.html", import.meta.url),
8
- )
8
+ );
9
9
 
10
10
  export const jsenvPluginExplorer = ({
11
11
  groups = {
@@ -18,7 +18,7 @@ export const jsenvPluginExplorer = ({
18
18
  },
19
19
  },
20
20
  }) => {
21
- const faviconClientFileUrl = new URL("./client/jsenv.png", import.meta.url)
21
+ const faviconClientFileUrl = new URL("./client/jsenv.png", import.meta.url);
22
22
 
23
23
  return {
24
24
  name: "jsenv:explorer",
@@ -26,9 +26,9 @@ export const jsenvPluginExplorer = ({
26
26
  transformUrlContent: {
27
27
  html: async (urlInfo, context) => {
28
28
  if (urlInfo.url !== explorerHtmlFileUrl) {
29
- return null
29
+ return null;
30
30
  }
31
- let html = urlInfo.content
31
+ let html = urlInfo.content;
32
32
  if (html.includes("ignore:FAVICON_HREF")) {
33
33
  html = html.replace(
34
34
  "ignore:FAVICON_HREF",
@@ -39,29 +39,29 @@ export const jsenvPluginExplorer = ({
39
39
  "base64",
40
40
  ),
41
41
  }),
42
- )
42
+ );
43
43
  }
44
44
  if (html.includes("SERVER_PARAMS")) {
45
- const associationsForExplorable = {}
45
+ const associationsForExplorable = {};
46
46
  Object.keys(groups).forEach((groupName) => {
47
- const groupConfig = groups[groupName]
47
+ const groupConfig = groups[groupName];
48
48
  associationsForExplorable[groupName] = {
49
49
  "**/.jsenv/": false, // avoid visting .jsenv directory in jsenv itself
50
50
  ...groupConfig,
51
- }
52
- })
51
+ };
52
+ });
53
53
  const matchingFileResultArray = await collectFiles({
54
54
  directoryUrl: context.rootDirectoryUrl,
55
55
  associations: associationsForExplorable,
56
56
  predicate: (meta) =>
57
57
  Object.keys(meta).some((group) => Boolean(meta[group])),
58
- })
58
+ });
59
59
  const files = matchingFileResultArray.map(
60
60
  ({ relativeUrl, meta }) => ({
61
61
  relativeUrl,
62
62
  meta,
63
63
  }),
64
- )
64
+ );
65
65
 
66
66
  html = html.replace(
67
67
  "SERVER_PARAMS",
@@ -74,13 +74,13 @@ export const jsenvPluginExplorer = ({
74
74
  null,
75
75
  " ",
76
76
  ),
77
- )
77
+ );
78
78
  Object.assign(urlInfo.headers, {
79
79
  "cache-control": "no-store",
80
- })
80
+ });
81
81
  }
82
- return html
82
+ return html;
83
83
  },
84
84
  },
85
- }
86
- }
85
+ };
86
+ };
@@ -1,16 +1,16 @@
1
- import { readFileSync, readdirSync, realpathSync, statSync } from "node:fs"
2
- import { pathToFileURL } from "node:url"
1
+ import { readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
2
+ import { pathToFileURL } from "node:url";
3
3
  import {
4
4
  urlIsInsideOf,
5
5
  urlToRelativeUrl,
6
6
  urlToFilename,
7
7
  ensurePathnameTrailingSlash,
8
- } from "@jsenv/urls"
8
+ } from "@jsenv/urls";
9
9
  import {
10
10
  applyFileSystemMagicResolution,
11
11
  getExtensionsToTry,
12
- } from "@jsenv/node-esm-resolution"
13
- import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"
12
+ } from "@jsenv/node-esm-resolution";
13
+ import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js";
14
14
 
15
15
  export const jsenvPluginFileUrls = ({
16
16
  magicExtensions = ["inherit", ".js"],
@@ -25,38 +25,38 @@ export const jsenvPluginFileUrls = ({
25
25
  redirectUrl: (reference) => {
26
26
  // http, https, data, about, ...
27
27
  if (!reference.url.startsWith("file:")) {
28
- return null
28
+ return null;
29
29
  }
30
30
  if (reference.isInline) {
31
- return null
31
+ return null;
32
32
  }
33
- const urlObject = new URL(reference.url)
34
- let stat
33
+ const urlObject = new URL(reference.url);
34
+ let stat;
35
35
  try {
36
- stat = statSync(urlObject)
36
+ stat = statSync(urlObject);
37
37
  } catch (e) {
38
38
  if (e.code === "ENOENT") {
39
- stat = null
39
+ stat = null;
40
40
  } else {
41
- throw e
41
+ throw e;
42
42
  }
43
43
  }
44
- const { search, hash } = urlObject
45
- let { pathname } = urlObject
46
- const pathnameUsesTrailingSlash = pathname.endsWith("/")
47
- urlObject.search = ""
48
- urlObject.hash = ""
44
+ const { search, hash } = urlObject;
45
+ let { pathname } = urlObject;
46
+ const pathnameUsesTrailingSlash = pathname.endsWith("/");
47
+ urlObject.search = "";
48
+ urlObject.hash = "";
49
49
  // force trailing slash on directories
50
50
  if (stat && stat.isDirectory() && !pathnameUsesTrailingSlash) {
51
- urlObject.pathname = `${pathname}/`
51
+ urlObject.pathname = `${pathname}/`;
52
52
  }
53
53
  // otherwise remove trailing slash if any
54
54
  if (stat && !stat.isDirectory() && pathnameUsesTrailingSlash) {
55
55
  // a warning here? (because it's strange to reference a file with a trailing slash)
56
- urlObject.pathname = pathname.slice(0, -1)
56
+ urlObject.pathname = pathname.slice(0, -1);
57
57
  }
58
58
 
59
- let url = urlObject.href
59
+ let url = urlObject.href;
60
60
  const shouldPreserve =
61
61
  stat &&
62
62
  stat.isDirectory() &&
@@ -65,13 +65,13 @@ export const jsenvPluginFileUrls = ({
65
65
  // ignore root file url
66
66
  reference.url === "file:///" ||
67
67
  (reference.subtype === "new_url_first_arg" &&
68
- reference.specifier === "./"))
68
+ reference.specifier === "./"));
69
69
 
70
70
  if (shouldPreserve) {
71
- reference.shouldHandle = false
71
+ reference.shouldHandle = false;
72
72
  } else {
73
73
  const shouldApplyDilesystemMagicResolution =
74
- reference.type === "js_import"
74
+ reference.type === "js_import";
75
75
  if (shouldApplyDilesystemMagicResolution) {
76
76
  const filesystemResolution = applyFileSystemMagicResolution(url, {
77
77
  fileStat: stat,
@@ -80,10 +80,10 @@ export const jsenvPluginFileUrls = ({
80
80
  magicExtensions,
81
81
  reference.parentUrl,
82
82
  ),
83
- })
83
+ });
84
84
  if (filesystemResolution.stat) {
85
- stat = filesystemResolution.stat
86
- url = filesystemResolution.url
85
+ stat = filesystemResolution.stat;
86
+ url = filesystemResolution.url;
87
87
  }
88
88
  }
89
89
  if (stat && stat.isDirectory()) {
@@ -91,21 +91,21 @@ export const jsenvPluginFileUrls = ({
91
91
  reference.type === "filesystem" ||
92
92
  (typeof directoryReferenceAllowed === "function" &&
93
93
  directoryReferenceAllowed(reference)) ||
94
- directoryReferenceAllowed
94
+ directoryReferenceAllowed;
95
95
  if (!directoryAllowed) {
96
- const error = new Error("Reference leads to a directory")
97
- error.code = "DIRECTORY_REFERENCE_NOT_ALLOWED"
98
- throw error
96
+ const error = new Error("Reference leads to a directory");
97
+ error.code = "DIRECTORY_REFERENCE_NOT_ALLOWED";
98
+ throw error;
99
99
  }
100
100
  }
101
101
  }
102
- reference.leadsToADirectory = stat && stat.isDirectory()
102
+ reference.leadsToADirectory = stat && stat.isDirectory();
103
103
  if (stat) {
104
- const urlRaw = preserveSymlinks ? url : resolveSymlink(url)
105
- const resolvedUrl = `${urlRaw}${search}${hash}`
106
- return resolvedUrl
104
+ const urlRaw = preserveSymlinks ? url : resolveSymlink(url);
105
+ const resolvedUrl = `${urlRaw}${search}${hash}`;
106
+ return resolvedUrl;
107
107
  }
108
- return null
108
+ return null;
109
109
  },
110
110
  },
111
111
  {
@@ -113,13 +113,13 @@ export const jsenvPluginFileUrls = ({
113
113
  appliesDuring: "*",
114
114
  resolveUrl: {
115
115
  filesystem: (reference, context) => {
116
- const { parentUrl } = reference
117
- const parentUrlInfo = context.urlGraph.getUrlInfo(parentUrl)
116
+ const { parentUrl } = reference;
117
+ const parentUrlInfo = context.urlGraph.getUrlInfo(parentUrl);
118
118
  const baseUrl =
119
119
  parentUrlInfo && parentUrlInfo.type === "directory"
120
120
  ? ensurePathnameTrailingSlash(parentUrl)
121
- : parentUrl
122
- return new URL(reference.specifier, baseUrl).href
121
+ : parentUrl;
122
+ return new URL(reference.specifier, baseUrl).href;
123
123
  },
124
124
  },
125
125
  },
@@ -131,22 +131,22 @@ export const jsenvPluginFileUrls = ({
131
131
  appliesDuring: "dev",
132
132
  resolveUrl: (reference) => {
133
133
  if (reference.specifier.startsWith("/@fs/")) {
134
- const fsRootRelativeUrl = reference.specifier.slice("/@fs/".length)
135
- return `file:///${fsRootRelativeUrl}`
134
+ const fsRootRelativeUrl = reference.specifier.slice("/@fs/".length);
135
+ return `file:///${fsRootRelativeUrl}`;
136
136
  }
137
- return null
137
+ return null;
138
138
  },
139
139
  formatUrl: (reference, context) => {
140
140
  if (!reference.generatedUrl.startsWith("file:")) {
141
- return null
141
+ return null;
142
142
  }
143
143
  if (urlIsInsideOf(reference.generatedUrl, context.rootDirectoryUrl)) {
144
144
  return `/${urlToRelativeUrl(
145
145
  reference.generatedUrl,
146
146
  context.rootDirectoryUrl,
147
- )}`
147
+ )}`;
148
148
  }
149
- return `/@fs/${reference.generatedUrl.slice("file:///".length)}`
149
+ return `/@fs/${reference.generatedUrl.slice("file:///".length)}`;
150
150
  },
151
151
  },
152
152
  {
@@ -154,40 +154,40 @@ export const jsenvPluginFileUrls = ({
154
154
  appliesDuring: "*",
155
155
  fetchUrlContent: (urlInfo, context) => {
156
156
  if (!urlInfo.url.startsWith("file:")) {
157
- return null
157
+ return null;
158
158
  }
159
- const urlObject = new URL(urlInfo.url)
159
+ const urlObject = new URL(urlInfo.url);
160
160
  if (context.reference.leadsToADirectory) {
161
- const directoryEntries = readdirSync(urlObject)
162
- let filename
161
+ const directoryEntries = readdirSync(urlObject);
162
+ let filename;
163
163
  if (context.reference.type === "filesystem") {
164
164
  const parentUrlInfo = context.urlGraph.getUrlInfo(
165
165
  context.reference.parentUrl,
166
- )
167
- filename = `${parentUrlInfo.filename}${context.reference.specifier}/`
166
+ );
167
+ filename = `${parentUrlInfo.filename}${context.reference.specifier}/`;
168
168
  } else {
169
- filename = `${urlToFilename(urlInfo.url)}/`
169
+ filename = `${urlToFilename(urlInfo.url)}/`;
170
170
  }
171
171
  return {
172
172
  type: "directory",
173
173
  contentType: "application/json",
174
174
  content: JSON.stringify(directoryEntries, null, " "),
175
175
  filename,
176
- }
176
+ };
177
177
  }
178
- const fileBuffer = readFileSync(urlObject)
179
- const contentType = CONTENT_TYPE.fromUrlExtension(urlInfo.url)
178
+ const fileBuffer = readFileSync(urlObject);
179
+ const contentType = CONTENT_TYPE.fromUrlExtension(urlInfo.url);
180
180
  return {
181
181
  content: CONTENT_TYPE.isTextual(contentType)
182
182
  ? String(fileBuffer)
183
183
  : fileBuffer,
184
184
  contentType,
185
- }
185
+ };
186
186
  },
187
187
  },
188
- ]
189
- }
188
+ ];
189
+ };
190
190
 
191
191
  const resolveSymlink = (fileUrl) => {
192
- return pathToFileURL(realpathSync(new URL(fileUrl))).href
193
- }
192
+ return pathToFileURL(realpathSync(new URL(fileUrl))).href;
193
+ };