@jsenv/core 40.6.1 → 40.7.0
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.
- package/dist/build/browserslist_index/browserslist_index.js +1 -0
- package/dist/build/build.js +335 -135
- package/dist/build/jsenv_core_node_modules.js +3 -4
- package/dist/build/jsenv_core_packages.js +100 -102
- package/dist/jsenv_core.js +4 -0
- package/dist/start_build_server/jsenv_core_node_modules.js +3 -4
- package/dist/start_build_server/jsenv_core_packages.js +29 -29
- package/dist/start_dev_server/jsenv_core_node_modules.js +3 -4
- package/dist/start_dev_server/jsenv_core_packages.js +100 -102
- package/dist/start_dev_server/start_dev_server.js +338 -136
- package/package.json +10 -11
- package/src/dev/start_dev_server.js +3 -1
- package/src/kitchen/kitchen.js +2 -0
- package/src/kitchen/url_graph/url_graph.js +1 -0
- package/src/kitchen/url_graph/url_info_injections.js +172 -0
- package/src/kitchen/url_graph/url_info_transformations.js +28 -7
- package/src/main.js +1 -1
- package/src/plugins/global_scenarios/jsenv_plugin_global_scenarios.js +4 -9
- package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +2 -0
- package/src/plugins/injections/jsenv_plugin_injections.js +51 -85
- package/src/plugins/plugin_controller.js +3 -0
- package/src/plugins/plugins.js +3 -1
- package/src/plugins/protocol_file/jsenv_plugin_directory_listing.js +23 -22
- package/src/plugins/protocol_file/jsenv_plugin_fs_redirection.js +41 -3
- package/src/plugins/protocol_file/jsenv_plugin_protocol_file.js +2 -0
- package/src/plugins/injections/internal/inject_globals.js +0 -52
|
@@ -516,79 +516,6 @@ const SIGINT_CALLBACK = {
|
|
|
516
516
|
},
|
|
517
517
|
};
|
|
518
518
|
|
|
519
|
-
const isFileSystemPath = (value) => {
|
|
520
|
-
if (typeof value !== "string") {
|
|
521
|
-
throw new TypeError(
|
|
522
|
-
`isFileSystemPath first arg must be a string, got ${value}`,
|
|
523
|
-
);
|
|
524
|
-
}
|
|
525
|
-
if (value[0] === "/") {
|
|
526
|
-
return true;
|
|
527
|
-
}
|
|
528
|
-
return startsWithWindowsDriveLetter(value);
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
const startsWithWindowsDriveLetter = (string) => {
|
|
532
|
-
const firstChar = string[0];
|
|
533
|
-
if (!/[a-zA-Z]/.test(firstChar)) return false;
|
|
534
|
-
|
|
535
|
-
const secondChar = string[1];
|
|
536
|
-
if (secondChar !== ":") return false;
|
|
537
|
-
|
|
538
|
-
return true;
|
|
539
|
-
};
|
|
540
|
-
|
|
541
|
-
const fileSystemPathToUrl = (value) => {
|
|
542
|
-
if (!isFileSystemPath(value)) {
|
|
543
|
-
throw new Error(`value must be a filesystem path, got ${value}`);
|
|
544
|
-
}
|
|
545
|
-
return String(pathToFileURL(value));
|
|
546
|
-
};
|
|
547
|
-
|
|
548
|
-
const getCallerPosition = () => {
|
|
549
|
-
const { prepareStackTrace } = Error;
|
|
550
|
-
Error.prepareStackTrace = (error, stack) => {
|
|
551
|
-
Error.prepareStackTrace = prepareStackTrace;
|
|
552
|
-
return stack;
|
|
553
|
-
};
|
|
554
|
-
const { stack } = new Error();
|
|
555
|
-
const callerCallsite = stack[2];
|
|
556
|
-
const fileName = callerCallsite.getFileName();
|
|
557
|
-
return {
|
|
558
|
-
url:
|
|
559
|
-
fileName && isFileSystemPath(fileName)
|
|
560
|
-
? fileSystemPathToUrl(fileName)
|
|
561
|
-
: fileName,
|
|
562
|
-
line: callerCallsite.getLineNumber(),
|
|
563
|
-
column: callerCallsite.getColumnNumber(),
|
|
564
|
-
};
|
|
565
|
-
};
|
|
566
|
-
|
|
567
|
-
const urlToFileSystemPath = (url) => {
|
|
568
|
-
const urlObject = new URL(url);
|
|
569
|
-
let { origin, pathname, hash } = urlObject;
|
|
570
|
-
if (urlObject.protocol === "file:") {
|
|
571
|
-
origin = "file://";
|
|
572
|
-
}
|
|
573
|
-
pathname = pathname
|
|
574
|
-
.split("/")
|
|
575
|
-
.map((part) => {
|
|
576
|
-
return part.replace(/%(?![0-9A-F][0-9A-F])/g, "%25");
|
|
577
|
-
})
|
|
578
|
-
.join("/");
|
|
579
|
-
if (hash) {
|
|
580
|
-
pathname += `%23${encodeURIComponent(hash.slice(1))}`;
|
|
581
|
-
}
|
|
582
|
-
const urlString = `${origin}${pathname}`;
|
|
583
|
-
const fileSystemPath = fileURLToPath(urlString);
|
|
584
|
-
if (fileSystemPath[fileSystemPath.length - 1] === "/") {
|
|
585
|
-
// remove trailing / so that nodejs path becomes predictable otherwise it logs
|
|
586
|
-
// the trailing slash on linux but does not on windows
|
|
587
|
-
return fileSystemPath.slice(0, -1);
|
|
588
|
-
}
|
|
589
|
-
return fileSystemPath;
|
|
590
|
-
};
|
|
591
|
-
|
|
592
519
|
/*
|
|
593
520
|
* data:[<mediatype>][;base64],<data>
|
|
594
521
|
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs#syntax
|
|
@@ -2012,35 +1939,33 @@ const urlToExtension$1 = (url) => {
|
|
|
2012
1939
|
return pathnameToExtension$1(pathname);
|
|
2013
1940
|
};
|
|
2014
1941
|
|
|
2015
|
-
const
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
return
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
}
|
|
2043
|
-
return `${origin}${newPathname}${search ? `?${search}` : ""}`;
|
|
1942
|
+
const setUrlExtension = (
|
|
1943
|
+
url,
|
|
1944
|
+
extension,
|
|
1945
|
+
{ trailingSlash = "preserve" } = {},
|
|
1946
|
+
) => {
|
|
1947
|
+
return transformUrlPathname(url, (pathname) => {
|
|
1948
|
+
const currentExtension = urlToExtension$1(url);
|
|
1949
|
+
if (typeof extension === "function") {
|
|
1950
|
+
extension = extension(currentExtension);
|
|
1951
|
+
}
|
|
1952
|
+
const pathnameWithoutExtension = currentExtension
|
|
1953
|
+
? pathname.slice(0, -currentExtension.length)
|
|
1954
|
+
: pathname;
|
|
1955
|
+
|
|
1956
|
+
if (pathnameWithoutExtension.endsWith("/")) {
|
|
1957
|
+
let pathnameWithExtension;
|
|
1958
|
+
pathnameWithExtension = pathnameWithoutExtension.slice(0, -1);
|
|
1959
|
+
pathnameWithExtension += extension;
|
|
1960
|
+
if (trailingSlash === "preserve") {
|
|
1961
|
+
pathnameWithExtension += "/";
|
|
1962
|
+
}
|
|
1963
|
+
return pathnameWithExtension;
|
|
1964
|
+
}
|
|
1965
|
+
let pathnameWithExtension = pathnameWithoutExtension;
|
|
1966
|
+
pathnameWithExtension += extension;
|
|
1967
|
+
return pathnameWithExtension;
|
|
1968
|
+
});
|
|
2044
1969
|
};
|
|
2045
1970
|
|
|
2046
1971
|
const setUrlFilename = (url, filename) => {
|
|
@@ -2350,6 +2275,28 @@ const moveUrl = ({ url, from, to, preferRelative }) => {
|
|
|
2350
2275
|
return absoluteUrl;
|
|
2351
2276
|
};
|
|
2352
2277
|
|
|
2278
|
+
const isFileSystemPath = (value) => {
|
|
2279
|
+
if (typeof value !== "string") {
|
|
2280
|
+
throw new TypeError(
|
|
2281
|
+
`isFileSystemPath first arg must be a string, got ${value}`,
|
|
2282
|
+
);
|
|
2283
|
+
}
|
|
2284
|
+
if (value[0] === "/") {
|
|
2285
|
+
return true;
|
|
2286
|
+
}
|
|
2287
|
+
return startsWithWindowsDriveLetter(value);
|
|
2288
|
+
};
|
|
2289
|
+
|
|
2290
|
+
const startsWithWindowsDriveLetter = (string) => {
|
|
2291
|
+
const firstChar = string[0];
|
|
2292
|
+
if (!/[a-zA-Z]/.test(firstChar)) return false;
|
|
2293
|
+
|
|
2294
|
+
const secondChar = string[1];
|
|
2295
|
+
if (secondChar !== ":") return false;
|
|
2296
|
+
|
|
2297
|
+
return true;
|
|
2298
|
+
};
|
|
2299
|
+
|
|
2353
2300
|
const resolveUrl$1 = (specifier, baseUrl) => {
|
|
2354
2301
|
if (typeof baseUrl === "undefined") {
|
|
2355
2302
|
throw new TypeError(`baseUrl missing to resolve ${specifier}`);
|
|
@@ -2375,6 +2322,57 @@ const urlIsInsideOf = (url, otherUrl) => {
|
|
|
2375
2322
|
return isInside;
|
|
2376
2323
|
};
|
|
2377
2324
|
|
|
2325
|
+
const fileSystemPathToUrl = (value) => {
|
|
2326
|
+
if (!isFileSystemPath(value)) {
|
|
2327
|
+
throw new Error(`value must be a filesystem path, got ${value}`);
|
|
2328
|
+
}
|
|
2329
|
+
return String(pathToFileURL(value));
|
|
2330
|
+
};
|
|
2331
|
+
|
|
2332
|
+
const getCallerPosition = () => {
|
|
2333
|
+
const { prepareStackTrace } = Error;
|
|
2334
|
+
Error.prepareStackTrace = (error, stack) => {
|
|
2335
|
+
Error.prepareStackTrace = prepareStackTrace;
|
|
2336
|
+
return stack;
|
|
2337
|
+
};
|
|
2338
|
+
const { stack } = new Error();
|
|
2339
|
+
const callerCallsite = stack[2];
|
|
2340
|
+
const fileName = callerCallsite.getFileName();
|
|
2341
|
+
return {
|
|
2342
|
+
url:
|
|
2343
|
+
fileName && isFileSystemPath(fileName)
|
|
2344
|
+
? fileSystemPathToUrl(fileName)
|
|
2345
|
+
: fileName,
|
|
2346
|
+
line: callerCallsite.getLineNumber(),
|
|
2347
|
+
column: callerCallsite.getColumnNumber(),
|
|
2348
|
+
};
|
|
2349
|
+
};
|
|
2350
|
+
|
|
2351
|
+
const urlToFileSystemPath = (url) => {
|
|
2352
|
+
const urlObject = new URL(url);
|
|
2353
|
+
let { origin, pathname, hash } = urlObject;
|
|
2354
|
+
if (urlObject.protocol === "file:") {
|
|
2355
|
+
origin = "file://";
|
|
2356
|
+
}
|
|
2357
|
+
pathname = pathname
|
|
2358
|
+
.split("/")
|
|
2359
|
+
.map((part) => {
|
|
2360
|
+
return part.replace(/%(?![0-9A-F][0-9A-F])/g, "%25");
|
|
2361
|
+
})
|
|
2362
|
+
.join("/");
|
|
2363
|
+
if (hash) {
|
|
2364
|
+
pathname += `%23${encodeURIComponent(hash.slice(1))}`;
|
|
2365
|
+
}
|
|
2366
|
+
const urlString = `${origin}${pathname}`;
|
|
2367
|
+
const fileSystemPath = fileURLToPath(urlString);
|
|
2368
|
+
if (fileSystemPath[fileSystemPath.length - 1] === "/") {
|
|
2369
|
+
// remove trailing / so that nodejs path becomes predictable otherwise it logs
|
|
2370
|
+
// the trailing slash on linux but does not on windows
|
|
2371
|
+
return fileSystemPath.slice(0, -1);
|
|
2372
|
+
}
|
|
2373
|
+
return fileSystemPath;
|
|
2374
|
+
};
|
|
2375
|
+
|
|
2378
2376
|
const validateDirectoryUrl = (value) => {
|
|
2379
2377
|
let urlString;
|
|
2380
2378
|
|
package/dist/jsenv_core.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import "@jsenv/ast";
|
|
1
2
|
import "@jsenv/sourcemap";
|
|
2
3
|
|
|
3
4
|
const injectionSymbol = Symbol.for("jsenv_injection");
|
|
4
5
|
const INJECTIONS = {
|
|
6
|
+
global: (value) => {
|
|
7
|
+
return { [injectionSymbol]: "global", value };
|
|
8
|
+
},
|
|
5
9
|
optional: (value) => {
|
|
6
10
|
return { [injectionSymbol]: "optional", value };
|
|
7
11
|
},
|
|
@@ -211,10 +211,9 @@ function isUnicodeSupported() {
|
|
|
211
211
|
|| env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
const r = String.raw
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
const emojiRegex = () => new RegExp(r`[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[${sTags}]{2}[\u{E0030}-\u{E0039}${sTags}]{1,3}\u{E007F}|${seq}(?:\u200D${seq})*`, 'gu');
|
|
214
|
+
const r = String.raw,
|
|
215
|
+
e = r`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`;
|
|
216
|
+
const emojiRegex = () => new RegExp(r`\p{RI}{2}|(?)${e}(?:\u200D${e})*`, 'gu');
|
|
218
217
|
|
|
219
218
|
// Generated code.
|
|
220
219
|
|
|
@@ -511,35 +511,6 @@ const SIGINT_CALLBACK = {
|
|
|
511
511
|
},
|
|
512
512
|
};
|
|
513
513
|
|
|
514
|
-
const isFileSystemPath = (value) => {
|
|
515
|
-
if (typeof value !== "string") {
|
|
516
|
-
throw new TypeError(
|
|
517
|
-
`isFileSystemPath first arg must be a string, got ${value}`,
|
|
518
|
-
);
|
|
519
|
-
}
|
|
520
|
-
if (value[0] === "/") {
|
|
521
|
-
return true;
|
|
522
|
-
}
|
|
523
|
-
return startsWithWindowsDriveLetter(value);
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
const startsWithWindowsDriveLetter = (string) => {
|
|
527
|
-
const firstChar = string[0];
|
|
528
|
-
if (!/[a-zA-Z]/.test(firstChar)) return false;
|
|
529
|
-
|
|
530
|
-
const secondChar = string[1];
|
|
531
|
-
if (secondChar !== ":") return false;
|
|
532
|
-
|
|
533
|
-
return true;
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
const fileSystemPathToUrl = (value) => {
|
|
537
|
-
if (!isFileSystemPath(value)) {
|
|
538
|
-
throw new Error(`value must be a filesystem path, got ${value}`);
|
|
539
|
-
}
|
|
540
|
-
return String(pathToFileURL(value));
|
|
541
|
-
};
|
|
542
|
-
|
|
543
514
|
// https://github.com/Marak/colors.js/blob/master/lib/styles.js
|
|
544
515
|
// https://stackoverflow.com/a/75985833/2634179
|
|
545
516
|
const RESET = "\x1b[0m";
|
|
@@ -1491,6 +1462,35 @@ const ensurePathnameTrailingSlash = (url) => {
|
|
|
1491
1462
|
});
|
|
1492
1463
|
};
|
|
1493
1464
|
|
|
1465
|
+
const isFileSystemPath = (value) => {
|
|
1466
|
+
if (typeof value !== "string") {
|
|
1467
|
+
throw new TypeError(
|
|
1468
|
+
`isFileSystemPath first arg must be a string, got ${value}`,
|
|
1469
|
+
);
|
|
1470
|
+
}
|
|
1471
|
+
if (value[0] === "/") {
|
|
1472
|
+
return true;
|
|
1473
|
+
}
|
|
1474
|
+
return startsWithWindowsDriveLetter(value);
|
|
1475
|
+
};
|
|
1476
|
+
|
|
1477
|
+
const startsWithWindowsDriveLetter = (string) => {
|
|
1478
|
+
const firstChar = string[0];
|
|
1479
|
+
if (!/[a-zA-Z]/.test(firstChar)) return false;
|
|
1480
|
+
|
|
1481
|
+
const secondChar = string[1];
|
|
1482
|
+
if (secondChar !== ":") return false;
|
|
1483
|
+
|
|
1484
|
+
return true;
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
const fileSystemPathToUrl = (value) => {
|
|
1488
|
+
if (!isFileSystemPath(value)) {
|
|
1489
|
+
throw new Error(`value must be a filesystem path, got ${value}`);
|
|
1490
|
+
}
|
|
1491
|
+
return String(pathToFileURL(value));
|
|
1492
|
+
};
|
|
1493
|
+
|
|
1494
1494
|
const validateDirectoryUrl = (value) => {
|
|
1495
1495
|
let urlString;
|
|
1496
1496
|
|
|
@@ -211,10 +211,9 @@ function isUnicodeSupported() {
|
|
|
211
211
|
|| env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
const r = String.raw
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
const emojiRegex = () => new RegExp(r`[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[${sTags}]{2}[\u{E0030}-\u{E0039}${sTags}]{1,3}\u{E007F}|${seq}(?:\u200D${seq})*`, 'gu');
|
|
214
|
+
const r = String.raw,
|
|
215
|
+
e = r`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`;
|
|
216
|
+
const emojiRegex = () => new RegExp(r`\p{RI}{2}|(?)${e}(?:\u200D${e})*`, 'gu');
|
|
218
217
|
|
|
219
218
|
// Generated code.
|
|
220
219
|
|
|
@@ -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
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
return
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
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}`);
|
|
@@ -1680,6 +1627,57 @@ const urlIsInsideOf = (url, otherUrl) => {
|
|
|
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
|
|