@jsenv/core 40.6.2 → 40.7.1

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 (36) hide show
  1. package/dist/build/browserslist_index/browserslist_index.js +62 -48
  2. package/dist/build/build.js +412 -185
  3. package/dist/build/jsenv_core_packages.js +103 -105
  4. package/dist/client/directory_listing/js/directory_listing.js +41 -26
  5. package/dist/client/ribbon/ribbon.js +40 -37
  6. package/dist/jsenv_core.js +4 -0
  7. package/dist/start_build_server/jsenv_core_packages.js +29 -29
  8. package/dist/start_dev_server/jsenv_core_packages.js +103 -105
  9. package/dist/start_dev_server/start_dev_server.js +412 -182
  10. package/package.json +21 -12
  11. package/src/build/build.js +9 -9
  12. package/src/build/build_specifier_manager.js +3 -3
  13. package/src/build/build_urls_generator.js +2 -2
  14. package/src/dev/start_dev_server.js +11 -8
  15. package/src/helpers/web_url_converter.js +2 -2
  16. package/src/kitchen/errors.js +1 -1
  17. package/src/kitchen/kitchen.js +2 -0
  18. package/src/kitchen/out_directory_url.js +2 -2
  19. package/src/kitchen/url_graph/url_graph.js +1 -0
  20. package/src/kitchen/url_graph/url_info_injections.js +172 -0
  21. package/src/kitchen/url_graph/url_info_transformations.js +28 -7
  22. package/src/main.js +1 -1
  23. package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +2 -2
  24. package/src/plugins/chrome_devtools_json/jsenv_plugin_chrome_devtools_json.js +1 -0
  25. package/src/plugins/global_scenarios/jsenv_plugin_global_scenarios.js +4 -9
  26. package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +2 -0
  27. package/src/plugins/injections/jsenv_plugin_injections.js +51 -85
  28. package/src/plugins/plugin_controller.js +28 -7
  29. package/src/plugins/plugins.js +3 -1
  30. package/src/plugins/protocol_file/client/directory_listing.jsx +42 -23
  31. package/src/plugins/protocol_file/file_and_server_urls_converter.js +2 -5
  32. package/src/plugins/protocol_file/jsenv_plugin_directory_listing.js +65 -49
  33. package/src/plugins/protocol_file/jsenv_plugin_fs_redirection.js +36 -3
  34. package/src/plugins/protocol_file/jsenv_plugin_protocol_file.js +3 -0
  35. package/src/plugins/ribbon/client/ribbon.js +40 -37
  36. package/src/plugins/injections/internal/inject_globals.js +0 -52
@@ -5,79 +5,6 @@ import { extname } from "node:path";
5
5
  import crypto, { createHash } from "node:crypto";
6
6
  import { pathToFileURL, fileURLToPath } from "node:url";
7
7
 
8
- const isFileSystemPath = (value) => {
9
- if (typeof value !== "string") {
10
- throw new TypeError(
11
- `isFileSystemPath first arg must be a string, got ${value}`,
12
- );
13
- }
14
- if (value[0] === "/") {
15
- return true;
16
- }
17
- return startsWithWindowsDriveLetter(value);
18
- };
19
-
20
- const startsWithWindowsDriveLetter = (string) => {
21
- const firstChar = string[0];
22
- if (!/[a-zA-Z]/.test(firstChar)) return false;
23
-
24
- const secondChar = string[1];
25
- if (secondChar !== ":") return false;
26
-
27
- return true;
28
- };
29
-
30
- const fileSystemPathToUrl = (value) => {
31
- if (!isFileSystemPath(value)) {
32
- throw new Error(`value must be a filesystem path, got ${value}`);
33
- }
34
- return String(pathToFileURL(value));
35
- };
36
-
37
- const getCallerPosition = () => {
38
- const { prepareStackTrace } = Error;
39
- Error.prepareStackTrace = (error, stack) => {
40
- Error.prepareStackTrace = prepareStackTrace;
41
- return stack;
42
- };
43
- const { stack } = new Error();
44
- const callerCallsite = stack[2];
45
- const fileName = callerCallsite.getFileName();
46
- return {
47
- url:
48
- fileName && isFileSystemPath(fileName)
49
- ? fileSystemPathToUrl(fileName)
50
- : fileName,
51
- line: callerCallsite.getLineNumber(),
52
- column: callerCallsite.getColumnNumber(),
53
- };
54
- };
55
-
56
- const urlToFileSystemPath = (url) => {
57
- const urlObject = new URL(url);
58
- let { origin, pathname, hash } = urlObject;
59
- if (urlObject.protocol === "file:") {
60
- origin = "file://";
61
- }
62
- pathname = pathname
63
- .split("/")
64
- .map((part) => {
65
- return part.replace(/%(?![0-9A-F][0-9A-F])/g, "%25");
66
- })
67
- .join("/");
68
- if (hash) {
69
- pathname += `%23${encodeURIComponent(hash.slice(1))}`;
70
- }
71
- const urlString = `${origin}${pathname}`;
72
- const fileSystemPath = fileURLToPath(urlString);
73
- if (fileSystemPath[fileSystemPath.length - 1] === "/") {
74
- // remove trailing / so that nodejs path becomes predictable otherwise it logs
75
- // the trailing slash on linux but does not on windows
76
- return fileSystemPath.slice(0, -1);
77
- }
78
- return fileSystemPath;
79
- };
80
-
81
8
  /*
82
9
  * data:[<mediatype>][;base64],<data>
83
10
  * https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs#syntax
@@ -1379,35 +1306,33 @@ const urlToExtension$1 = (url) => {
1379
1306
  return pathnameToExtension$1(pathname);
1380
1307
  };
1381
1308
 
1382
- const urlToOrigin$1 = (url) => {
1383
- const urlString = String(url);
1384
- if (urlString.startsWith("file://")) {
1385
- return `file://`;
1386
- }
1387
- return new URL(urlString).origin;
1388
- };
1389
-
1390
- const setUrlExtension = (url, extension) => {
1391
- const origin = urlToOrigin$1(url);
1392
- const currentExtension = urlToExtension$1(url);
1393
- if (typeof extension === "function") {
1394
- extension = extension(currentExtension);
1395
- }
1396
- const resource = urlToResource(url);
1397
- const [pathname, search] = resource.split("?");
1398
- const pathnameWithoutExtension = currentExtension
1399
- ? pathname.slice(0, -currentExtension.length)
1400
- : pathname;
1401
- let newPathname;
1402
- if (pathnameWithoutExtension.endsWith("/")) {
1403
- newPathname = pathnameWithoutExtension.slice(0, -1);
1404
- newPathname += extension;
1405
- newPathname += "/";
1406
- } else {
1407
- newPathname = pathnameWithoutExtension;
1408
- newPathname += extension;
1409
- }
1410
- return `${origin}${newPathname}${search ? `?${search}` : ""}`;
1309
+ const setUrlExtension = (
1310
+ url,
1311
+ extension,
1312
+ { trailingSlash = "preserve" } = {},
1313
+ ) => {
1314
+ return transformUrlPathname(url, (pathname) => {
1315
+ const currentExtension = urlToExtension$1(url);
1316
+ if (typeof extension === "function") {
1317
+ extension = extension(currentExtension);
1318
+ }
1319
+ const pathnameWithoutExtension = currentExtension
1320
+ ? pathname.slice(0, -currentExtension.length)
1321
+ : pathname;
1322
+
1323
+ if (pathnameWithoutExtension.endsWith("/")) {
1324
+ let pathnameWithExtension;
1325
+ pathnameWithExtension = pathnameWithoutExtension.slice(0, -1);
1326
+ pathnameWithExtension += extension;
1327
+ if (trailingSlash === "preserve") {
1328
+ pathnameWithExtension += "/";
1329
+ }
1330
+ return pathnameWithExtension;
1331
+ }
1332
+ let pathnameWithExtension = pathnameWithoutExtension;
1333
+ pathnameWithExtension += extension;
1334
+ return pathnameWithExtension;
1335
+ });
1411
1336
  };
1412
1337
 
1413
1338
  const setUrlFilename = (url, filename) => {
@@ -1655,6 +1580,28 @@ const moveUrl = ({ url, from, to, preferRelative }) => {
1655
1580
  return absoluteUrl;
1656
1581
  };
1657
1582
 
1583
+ const isFileSystemPath = (value) => {
1584
+ if (typeof value !== "string") {
1585
+ throw new TypeError(
1586
+ `isFileSystemPath first arg must be a string, got ${value}`,
1587
+ );
1588
+ }
1589
+ if (value[0] === "/") {
1590
+ return true;
1591
+ }
1592
+ return startsWithWindowsDriveLetter(value);
1593
+ };
1594
+
1595
+ const startsWithWindowsDriveLetter = (string) => {
1596
+ const firstChar = string[0];
1597
+ if (!/[a-zA-Z]/.test(firstChar)) return false;
1598
+
1599
+ const secondChar = string[1];
1600
+ if (secondChar !== ":") return false;
1601
+
1602
+ return true;
1603
+ };
1604
+
1658
1605
  const resolveUrl$1 = (specifier, baseUrl) => {
1659
1606
  if (typeof baseUrl === "undefined") {
1660
1607
  throw new TypeError(`baseUrl missing to resolve ${specifier}`);
@@ -1662,7 +1609,7 @@ const resolveUrl$1 = (specifier, baseUrl) => {
1662
1609
  return String(new URL(specifier, baseUrl));
1663
1610
  };
1664
1611
 
1665
- const urlIsInsideOf = (url, otherUrl) => {
1612
+ const urlIsOrIsInsideOf = (url, otherUrl) => {
1666
1613
  const urlObject = new URL(url);
1667
1614
  const otherUrlObject = new URL(otherUrl);
1668
1615
 
@@ -1673,13 +1620,64 @@ const urlIsInsideOf = (url, otherUrl) => {
1673
1620
  const urlPathname = urlObject.pathname;
1674
1621
  const otherUrlPathname = otherUrlObject.pathname;
1675
1622
  if (urlPathname === otherUrlPathname) {
1676
- return false;
1623
+ return true;
1677
1624
  }
1678
1625
 
1679
1626
  const isInside = urlPathname.startsWith(otherUrlPathname);
1680
1627
  return isInside;
1681
1628
  };
1682
1629
 
1630
+ const fileSystemPathToUrl = (value) => {
1631
+ if (!isFileSystemPath(value)) {
1632
+ throw new Error(`value must be a filesystem path, got ${value}`);
1633
+ }
1634
+ return String(pathToFileURL(value));
1635
+ };
1636
+
1637
+ const getCallerPosition = () => {
1638
+ const { prepareStackTrace } = Error;
1639
+ Error.prepareStackTrace = (error, stack) => {
1640
+ Error.prepareStackTrace = prepareStackTrace;
1641
+ return stack;
1642
+ };
1643
+ const { stack } = new Error();
1644
+ const callerCallsite = stack[2];
1645
+ const fileName = callerCallsite.getFileName();
1646
+ return {
1647
+ url:
1648
+ fileName && isFileSystemPath(fileName)
1649
+ ? fileSystemPathToUrl(fileName)
1650
+ : fileName,
1651
+ line: callerCallsite.getLineNumber(),
1652
+ column: callerCallsite.getColumnNumber(),
1653
+ };
1654
+ };
1655
+
1656
+ const urlToFileSystemPath = (url) => {
1657
+ const urlObject = new URL(url);
1658
+ let { origin, pathname, hash } = urlObject;
1659
+ if (urlObject.protocol === "file:") {
1660
+ origin = "file://";
1661
+ }
1662
+ pathname = pathname
1663
+ .split("/")
1664
+ .map((part) => {
1665
+ return part.replace(/%(?![0-9A-F][0-9A-F])/g, "%25");
1666
+ })
1667
+ .join("/");
1668
+ if (hash) {
1669
+ pathname += `%23${encodeURIComponent(hash.slice(1))}`;
1670
+ }
1671
+ const urlString = `${origin}${pathname}`;
1672
+ const fileSystemPath = fileURLToPath(urlString);
1673
+ if (fileSystemPath[fileSystemPath.length - 1] === "/") {
1674
+ // remove trailing / so that nodejs path becomes predictable otherwise it logs
1675
+ // the trailing slash on linux but does not on windows
1676
+ return fileSystemPath.slice(0, -1);
1677
+ }
1678
+ return fileSystemPath;
1679
+ };
1680
+
1683
1681
  const validateDirectoryUrl = (value) => {
1684
1682
  let urlString;
1685
1683
 
@@ -6257,4 +6255,4 @@ const memoizeByFirstArgument = (compute) => {
6257
6255
  return fnWithMemoization;
6258
6256
  };
6259
6257
 
6260
- export { ANSI, CONTENT_TYPE, DATA_URL, JS_QUOTES, RUNTIME_COMPAT, URL_META, applyFileSystemMagicResolution, applyNodeEsmResolution, asSpecifierWithoutSearch, asUrlWithoutSearch, assertAndNormalizeDirectoryUrl, bufferToEtag, compareFileUrls, composeTwoImportMaps, createDetailedMessage$1 as createDetailedMessage, createLogger, createTaskLog, defaultLookupPackageScope, defaultReadPackageJson, ensurePathnameTrailingSlash, ensureWindowsDriveLetter, errorToHTML, formatError, generateContentFrame, getCallerPosition, getExtensionsToTry, injectQueryParamsIntoSpecifier, isFileSystemPath, isSpecifierForNodeBuiltin, lookupPackageDirectory, memoizeByFirstArgument, moveUrl, normalizeImportMap, normalizeUrl, readCustomConditionsFromProcessArgs, readEntryStatSync, readPackageAtOrNull, registerDirectoryLifecycle, resolveImport, setUrlBasename, setUrlExtension, setUrlFilename, stringifyUrlSite, urlIsInsideOf, urlToBasename, urlToExtension$1 as urlToExtension, urlToFileSystemPath, urlToFilename$1 as urlToFilename, urlToPathname$1 as urlToPathname, urlToRelativeUrl, validateResponseIntegrity, writeFileSync };
6258
+ export { ANSI, CONTENT_TYPE, DATA_URL, JS_QUOTES, RUNTIME_COMPAT, URL_META, applyFileSystemMagicResolution, applyNodeEsmResolution, asSpecifierWithoutSearch, asUrlWithoutSearch, assertAndNormalizeDirectoryUrl, bufferToEtag, compareFileUrls, composeTwoImportMaps, createDetailedMessage$1 as createDetailedMessage, createLogger, createTaskLog, defaultLookupPackageScope, defaultReadPackageJson, ensurePathnameTrailingSlash, ensureWindowsDriveLetter, errorToHTML, formatError, generateContentFrame, getCallerPosition, getExtensionsToTry, injectQueryParamsIntoSpecifier, isFileSystemPath, isSpecifierForNodeBuiltin, lookupPackageDirectory, memoizeByFirstArgument, moveUrl, normalizeImportMap, normalizeUrl, readCustomConditionsFromProcessArgs, readEntryStatSync, readPackageAtOrNull, registerDirectoryLifecycle, resolveImport, setUrlBasename, setUrlExtension, setUrlFilename, stringifyUrlSite, urlIsOrIsInsideOf, urlToBasename, urlToExtension$1 as urlToExtension, urlToFileSystemPath, urlToFilename$1 as urlToFilename, urlToPathname$1 as urlToPathname, urlToRelativeUrl, validateResponseIntegrity, writeFileSync };