@jsenv/test 3.7.5 → 3.7.6

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 (2) hide show
  1. package/dist/jsenv_test.js +54 -54
  2. package/package.json +2 -2
@@ -527,60 +527,6 @@ const SIGINT_CALLBACK = {
527
527
  },
528
528
  };
529
529
 
530
- const isFileSystemPath = (value) => {
531
- if (typeof value !== "string") {
532
- throw new TypeError(
533
- `isFileSystemPath first arg must be a string, got ${value}`,
534
- );
535
- }
536
- if (value[0] === "/") {
537
- return true;
538
- }
539
- return startsWithWindowsDriveLetter(value);
540
- };
541
-
542
- const startsWithWindowsDriveLetter = (string) => {
543
- const firstChar = string[0];
544
- if (!/[a-zA-Z]/.test(firstChar)) return false;
545
-
546
- const secondChar = string[1];
547
- if (secondChar !== ":") return false;
548
-
549
- return true;
550
- };
551
-
552
- const fileSystemPathToUrl = (value) => {
553
- if (!isFileSystemPath(value)) {
554
- throw new Error(`value must be a filesystem path, got ${value}`);
555
- }
556
- return String(pathToFileURL(value));
557
- };
558
-
559
- const urlToFileSystemPath = (url) => {
560
- const urlObject = new URL(url);
561
- let { origin, pathname, hash } = urlObject;
562
- if (urlObject.protocol === "file:") {
563
- origin = "file://";
564
- }
565
- pathname = pathname
566
- .split("/")
567
- .map((part) => {
568
- return part.replace(/%(?![0-9A-F][0-9A-F])/g, "%25");
569
- })
570
- .join("/");
571
- if (hash) {
572
- pathname += `%23${encodeURIComponent(hash.slice(1))}`;
573
- }
574
- const urlString = `${origin}${pathname}`;
575
- const fileSystemPath = fileURLToPath(urlString);
576
- if (fileSystemPath[fileSystemPath.length - 1] === "/") {
577
- // remove trailing / so that nodejs path becomes predictable otherwise it logs
578
- // the trailing slash on linux but does not on windows
579
- return fileSystemPath.slice(0, -1);
580
- }
581
- return fileSystemPath;
582
- };
583
-
584
530
  const createDetailedMessage = (message, details = {}) => {
585
531
  let text = `${message}`;
586
532
  const namedSectionsText = renderNamedSections(details);
@@ -1869,6 +1815,28 @@ const moveUrl = ({ url, from, to, preferRelative }) => {
1869
1815
  return absoluteUrl;
1870
1816
  };
1871
1817
 
1818
+ const isFileSystemPath = (value) => {
1819
+ if (typeof value !== "string") {
1820
+ throw new TypeError(
1821
+ `isFileSystemPath first arg must be a string, got ${value}`,
1822
+ );
1823
+ }
1824
+ if (value[0] === "/") {
1825
+ return true;
1826
+ }
1827
+ return startsWithWindowsDriveLetter(value);
1828
+ };
1829
+
1830
+ const startsWithWindowsDriveLetter = (string) => {
1831
+ const firstChar = string[0];
1832
+ if (!/[a-zA-Z]/.test(firstChar)) return false;
1833
+
1834
+ const secondChar = string[1];
1835
+ if (secondChar !== ":") return false;
1836
+
1837
+ return true;
1838
+ };
1839
+
1872
1840
  const resolveUrl = (specifier, baseUrl) => {
1873
1841
  if (typeof baseUrl === "undefined") {
1874
1842
  throw new TypeError(`baseUrl missing to resolve ${specifier}`);
@@ -1894,6 +1862,38 @@ const urlIsInsideOf = (url, otherUrl) => {
1894
1862
  return isInside;
1895
1863
  };
1896
1864
 
1865
+ const fileSystemPathToUrl = (value) => {
1866
+ if (!isFileSystemPath(value)) {
1867
+ throw new Error(`value must be a filesystem path, got ${value}`);
1868
+ }
1869
+ return String(pathToFileURL(value));
1870
+ };
1871
+
1872
+ const urlToFileSystemPath = (url) => {
1873
+ const urlObject = new URL(url);
1874
+ let { origin, pathname, hash } = urlObject;
1875
+ if (urlObject.protocol === "file:") {
1876
+ origin = "file://";
1877
+ }
1878
+ pathname = pathname
1879
+ .split("/")
1880
+ .map((part) => {
1881
+ return part.replace(/%(?![0-9A-F][0-9A-F])/g, "%25");
1882
+ })
1883
+ .join("/");
1884
+ if (hash) {
1885
+ pathname += `%23${encodeURIComponent(hash.slice(1))}`;
1886
+ }
1887
+ const urlString = `${origin}${pathname}`;
1888
+ const fileSystemPath = fileURLToPath(urlString);
1889
+ if (fileSystemPath[fileSystemPath.length - 1] === "/") {
1890
+ // remove trailing / so that nodejs path becomes predictable otherwise it logs
1891
+ // the trailing slash on linux but does not on windows
1892
+ return fileSystemPath.slice(0, -1);
1893
+ }
1894
+ return fileSystemPath;
1895
+ };
1896
+
1897
1897
  const validateDirectoryUrl = (value) => {
1898
1898
  let urlString;
1899
1899
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/test",
3
- "version": "3.7.5",
3
+ "version": "3.7.6",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -46,7 +46,7 @@
46
46
  "dependencies": {
47
47
  "@c88/v8-coverage": "0.1.1",
48
48
  "@jsenv/ast": "6.7.3",
49
- "@jsenv/plugin-supervisor": "1.7.1",
49
+ "@jsenv/plugin-supervisor": "1.7.2",
50
50
  "@jsenv/sourcemap": "1.3.8",
51
51
  "he": "1.2.0",
52
52
  "istanbul-lib-coverage": "3.2.2",