@ai-ecoverse/slicc-jsh 0.3.7 → 0.3.9
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/README.md +8 -1
- package/dist/host/main.mjs +24 -8
- package/dist/jsh.mjs +957 -305
- package/dist/meta-main.json +1 -1
- package/dist/node.mjs +957 -305
- package/package.json +2 -2
package/dist/node.mjs
CHANGED
|
@@ -1536,10 +1536,191 @@ ${e3}`;
|
|
|
1536
1536
|
}
|
|
1537
1537
|
});
|
|
1538
1538
|
|
|
1539
|
+
// src/runtime/path.mjs
|
|
1540
|
+
function normalizeArray(parts, allowAboveRoot) {
|
|
1541
|
+
const res = [];
|
|
1542
|
+
for (const part of parts) {
|
|
1543
|
+
if (part === "" || part === ".") continue;
|
|
1544
|
+
if (part === "..") {
|
|
1545
|
+
if (res.length > 0 && res[res.length - 1] !== "..") res.pop();
|
|
1546
|
+
else if (allowAboveRoot) res.push("..");
|
|
1547
|
+
} else {
|
|
1548
|
+
res.push(part);
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
return res;
|
|
1552
|
+
}
|
|
1553
|
+
function normalize(path) {
|
|
1554
|
+
if (path.length === 0) return ".";
|
|
1555
|
+
const isAbsolute = path.charCodeAt(0) === 47;
|
|
1556
|
+
const trailingSep = path.charCodeAt(path.length - 1) === 47;
|
|
1557
|
+
let out = normalizeArray(path.split("/"), !isAbsolute).join("/");
|
|
1558
|
+
if (out.length === 0 && !isAbsolute) out = ".";
|
|
1559
|
+
if (out.length > 0 && trailingSep) out += "/";
|
|
1560
|
+
return (isAbsolute ? "/" : "") + out;
|
|
1561
|
+
}
|
|
1562
|
+
function join(...parts) {
|
|
1563
|
+
const joined = parts.filter((p) => typeof p === "string" && p.length > 0).join("/");
|
|
1564
|
+
if (joined.length === 0) return ".";
|
|
1565
|
+
return normalize(joined);
|
|
1566
|
+
}
|
|
1567
|
+
function dirname(path) {
|
|
1568
|
+
if (path.length === 0) return ".";
|
|
1569
|
+
const hasRoot = path.charCodeAt(0) === 47;
|
|
1570
|
+
let end = -1;
|
|
1571
|
+
let matchedSlash = true;
|
|
1572
|
+
for (let i2 = path.length - 1; i2 >= 1; i2--) {
|
|
1573
|
+
if (path.charCodeAt(i2) === 47) {
|
|
1574
|
+
if (!matchedSlash) {
|
|
1575
|
+
end = i2;
|
|
1576
|
+
break;
|
|
1577
|
+
}
|
|
1578
|
+
} else {
|
|
1579
|
+
matchedSlash = false;
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
if (end === -1) return hasRoot ? "/" : ".";
|
|
1583
|
+
return path.slice(0, end);
|
|
1584
|
+
}
|
|
1585
|
+
function basename(path, ext) {
|
|
1586
|
+
let start = 0;
|
|
1587
|
+
let end = -1;
|
|
1588
|
+
let matchedSlash = true;
|
|
1589
|
+
for (let i2 = path.length - 1; i2 >= 0; i2--) {
|
|
1590
|
+
if (path.charCodeAt(i2) === 47) {
|
|
1591
|
+
if (!matchedSlash) {
|
|
1592
|
+
start = i2 + 1;
|
|
1593
|
+
break;
|
|
1594
|
+
}
|
|
1595
|
+
} else if (end === -1) {
|
|
1596
|
+
matchedSlash = false;
|
|
1597
|
+
end = i2 + 1;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
const base = end === -1 ? "" : path.slice(start, end);
|
|
1601
|
+
if (ext && base.endsWith(ext) && base !== ext) return base.slice(0, base.length - ext.length);
|
|
1602
|
+
return base;
|
|
1603
|
+
}
|
|
1604
|
+
function extname(path) {
|
|
1605
|
+
const base = basename(path);
|
|
1606
|
+
const dot = base.lastIndexOf(".");
|
|
1607
|
+
if (dot <= 0) return "";
|
|
1608
|
+
return base.slice(dot);
|
|
1609
|
+
}
|
|
1610
|
+
function resolve(getCwd, parts) {
|
|
1611
|
+
let resolved = "";
|
|
1612
|
+
let isAbsolute = false;
|
|
1613
|
+
for (let i2 = parts.length - 1; i2 >= -1 && !isAbsolute; i2--) {
|
|
1614
|
+
const part = i2 >= 0 ? parts[i2] : getCwd();
|
|
1615
|
+
if (typeof part !== "string" || part.length === 0) continue;
|
|
1616
|
+
resolved = resolved.length > 0 ? `${part}/${resolved}` : part;
|
|
1617
|
+
isAbsolute = part.charCodeAt(0) === 47;
|
|
1618
|
+
}
|
|
1619
|
+
const normalized = normalizeArray(resolved.split("/"), !isAbsolute).join("/");
|
|
1620
|
+
if (isAbsolute) return normalized.length > 0 ? `/${normalized}` : "/";
|
|
1621
|
+
return normalized.length > 0 ? normalized : ".";
|
|
1622
|
+
}
|
|
1623
|
+
function parse(path) {
|
|
1624
|
+
const ret = { root: "", dir: "", base: "", ext: "", name: "" };
|
|
1625
|
+
if (path.length === 0) return ret;
|
|
1626
|
+
const isAbsolute = path.charCodeAt(0) === 47;
|
|
1627
|
+
if (isAbsolute) ret.root = "/";
|
|
1628
|
+
ret.dir = dirname(path);
|
|
1629
|
+
ret.base = basename(path);
|
|
1630
|
+
ret.ext = extname(path);
|
|
1631
|
+
ret.name = ret.ext ? ret.base.slice(0, ret.base.length - ret.ext.length) : ret.base;
|
|
1632
|
+
if (ret.dir === "." && !isAbsolute) ret.dir = "";
|
|
1633
|
+
return ret;
|
|
1634
|
+
}
|
|
1635
|
+
function format(pathObject) {
|
|
1636
|
+
if (typeof pathObject === "string") return pathObject;
|
|
1637
|
+
const dir = pathObject.dir || pathObject.root || "";
|
|
1638
|
+
const base = pathObject.base || `${pathObject.name || ""}${pathObject.ext || ""}`;
|
|
1639
|
+
if (!dir) return base;
|
|
1640
|
+
if (dir === "/") return `/${base}`;
|
|
1641
|
+
return `${dir}/${base}`;
|
|
1642
|
+
}
|
|
1643
|
+
function createPath(getCwd = () => "/") {
|
|
1644
|
+
const api = {
|
|
1645
|
+
sep: "/",
|
|
1646
|
+
delimiter: ":",
|
|
1647
|
+
basename,
|
|
1648
|
+
dirname,
|
|
1649
|
+
extname,
|
|
1650
|
+
parse,
|
|
1651
|
+
format,
|
|
1652
|
+
isAbsolute: (path) => path.length > 0 && path.charCodeAt(0) === 47,
|
|
1653
|
+
join,
|
|
1654
|
+
normalize,
|
|
1655
|
+
resolve: (...parts) => resolve(getCwd, parts),
|
|
1656
|
+
relative(from, to) {
|
|
1657
|
+
const fromAbs = resolve(getCwd, [from]);
|
|
1658
|
+
const toAbs = resolve(getCwd, [to]);
|
|
1659
|
+
if (fromAbs === toAbs) return "";
|
|
1660
|
+
const fromParts = fromAbs.split("/").filter(Boolean);
|
|
1661
|
+
const toParts = toAbs.split("/").filter(Boolean);
|
|
1662
|
+
let i2 = 0;
|
|
1663
|
+
while (i2 < fromParts.length && i2 < toParts.length && fromParts[i2] === toParts[i2]) i2++;
|
|
1664
|
+
return [...fromParts.slice(i2).map(() => ".."), ...toParts.slice(i2)].join("/");
|
|
1665
|
+
}
|
|
1666
|
+
};
|
|
1667
|
+
api.posix = api;
|
|
1668
|
+
return api;
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
// src/runtime/realpath.mjs
|
|
1672
|
+
var MAX_LINKS = 40;
|
|
1673
|
+
function realpathWith(fs, path, p, fail) {
|
|
1674
|
+
let resolved = path.resolve(String(p));
|
|
1675
|
+
const knownHard = /* @__PURE__ */ new Set();
|
|
1676
|
+
let hops = 0;
|
|
1677
|
+
let current2 = "/";
|
|
1678
|
+
let pos = 1;
|
|
1679
|
+
const call = (fn, syscall, at2) => {
|
|
1680
|
+
try {
|
|
1681
|
+
return fn();
|
|
1682
|
+
} catch (err) {
|
|
1683
|
+
throw fail(err?.code || "ENOENT", syscall, at2, err);
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
while (pos < resolved.length) {
|
|
1687
|
+
const next = resolved.indexOf("/", pos);
|
|
1688
|
+
const part = next === -1 ? resolved.slice(pos) : resolved.slice(pos, next);
|
|
1689
|
+
pos = next === -1 ? resolved.length : next + 1;
|
|
1690
|
+
if (!part) continue;
|
|
1691
|
+
const previous = current2;
|
|
1692
|
+
const base = current2 === "/" ? `/${part}` : `${current2}/${part}`;
|
|
1693
|
+
current2 = base;
|
|
1694
|
+
if (knownHard.has(base)) continue;
|
|
1695
|
+
const st = call(() => fs.lstat(base), "lstat", base);
|
|
1696
|
+
if (!st.isSymbolicLink) {
|
|
1697
|
+
knownHard.add(base);
|
|
1698
|
+
continue;
|
|
1699
|
+
}
|
|
1700
|
+
if (++hops > MAX_LINKS) throw fail("ELOOP", "stat", base);
|
|
1701
|
+
call(() => fs.stat(base), "stat", base);
|
|
1702
|
+
const target = call(() => fs.readlink(base), "readlink", base);
|
|
1703
|
+
resolved = path.resolve(previous, target, resolved.slice(pos));
|
|
1704
|
+
current2 = "/";
|
|
1705
|
+
pos = 1;
|
|
1706
|
+
}
|
|
1707
|
+
return resolved;
|
|
1708
|
+
}
|
|
1709
|
+
function realMainPath(ctx, filePath, execArgv = []) {
|
|
1710
|
+
if (execArgv.includes("--preserve-symlinks-main")) return filePath;
|
|
1711
|
+
const fs = ctx?.sync?.fs;
|
|
1712
|
+
if (typeof fs?.lstat !== "function" || typeof fs?.readlink !== "function") return filePath;
|
|
1713
|
+
try {
|
|
1714
|
+
return realpathWith(fs, createPath(() => ctx.cwd), filePath, (code) => Object.assign(new Error(code), { code }));
|
|
1715
|
+
} catch {
|
|
1716
|
+
return filePath;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1539
1720
|
// package.json
|
|
1540
1721
|
var package_default = {
|
|
1541
1722
|
name: "@ai-ecoverse/slicc-jsh",
|
|
1542
|
-
version: "0.3.
|
|
1723
|
+
version: "0.3.9",
|
|
1543
1724
|
description: "Node.js-compatible runtime for slicc-kernel: the node and jsh commands (abi: js)",
|
|
1544
1725
|
type: "module",
|
|
1545
1726
|
license: "Apache-2.0",
|
|
@@ -1609,7 +1790,7 @@ var package_default = {
|
|
|
1609
1790
|
"trust:dry": "npx fledgling sync --dry-run -y --skip-publish"
|
|
1610
1791
|
},
|
|
1611
1792
|
devDependencies: {
|
|
1612
|
-
"@ai-ecoverse/slicc-kernel": "1.
|
|
1793
|
+
"@ai-ecoverse/slicc-kernel": "1.64.0",
|
|
1613
1794
|
"@ai-ecoverse/wasi-pnpm": "12.9.1-8",
|
|
1614
1795
|
"abort-controller": "3.0.0",
|
|
1615
1796
|
acorn: "8.19.0",
|
|
@@ -1751,10 +1932,21 @@ function joinChild(dir, name) {
|
|
|
1751
1932
|
if (dir === "/") return `/${name}`;
|
|
1752
1933
|
return `${dir}/${name}`;
|
|
1753
1934
|
}
|
|
1935
|
+
function skillRootOf(dir) {
|
|
1936
|
+
if (!dir) return dir;
|
|
1937
|
+
const absolute = dir.startsWith("/");
|
|
1938
|
+
const parts = dir.split("/").filter(Boolean);
|
|
1939
|
+
const at2 = parts.lastIndexOf("scripts");
|
|
1940
|
+
if (at2 < 0) return dir;
|
|
1941
|
+
const rootParts = parts.slice(0, at2);
|
|
1942
|
+
if (rootParts.length === 0) return absolute ? "/" : "";
|
|
1943
|
+
return (absolute ? "/" : "") + rootParts.join("/");
|
|
1944
|
+
}
|
|
1754
1945
|
function createSkill({ argv, fs, exec }) {
|
|
1755
1946
|
const dir = dirnameOf(argv[1] ?? "");
|
|
1756
|
-
const
|
|
1757
|
-
const
|
|
1947
|
+
const root = skillRootOf(dir);
|
|
1948
|
+
const refs = joinChild(root, "references");
|
|
1949
|
+
const assets = joinChild(root, "assets");
|
|
1758
1950
|
const configPath = joinChild(dir, ".config");
|
|
1759
1951
|
async function readConfig() {
|
|
1760
1952
|
let text;
|
|
@@ -1796,7 +1988,7 @@ function createSkill({ argv, fs, exec }) {
|
|
|
1796
1988
|
}
|
|
1797
1989
|
return stdout.replace(/\r?\n+$/, "");
|
|
1798
1990
|
}
|
|
1799
|
-
return Object.freeze({ dir, refs, assets, config, token });
|
|
1991
|
+
return Object.freeze({ dir, root, refs, assets, config, token });
|
|
1800
1992
|
}
|
|
1801
1993
|
|
|
1802
1994
|
// src/jsh/sliccy/http.mjs
|
|
@@ -2366,8 +2558,9 @@ function compiler(rt) {
|
|
|
2366
2558
|
return (...args) => fn(...args.slice(0, JSH_PARAMS.length), importFrom);
|
|
2367
2559
|
};
|
|
2368
2560
|
}
|
|
2369
|
-
async function runKernelJsh(ctx, rt,
|
|
2561
|
+
async function runKernelJsh(ctx, rt, givenFilename) {
|
|
2370
2562
|
const { process: process2, console: console2 } = rt;
|
|
2563
|
+
const filename = realMainPath(ctx, givenFilename);
|
|
2371
2564
|
let stdoutIsTTY = false;
|
|
2372
2565
|
try {
|
|
2373
2566
|
stdoutIsTTY = !!await rt.track(Promise.resolve(ctx.isatty?.(1)));
|
|
@@ -3532,7 +3725,7 @@ var {
|
|
|
3532
3725
|
// identicalSequenceRange,
|
|
3533
3726
|
inspect,
|
|
3534
3727
|
// inspectDefaultOptions,
|
|
3535
|
-
format,
|
|
3728
|
+
format: format2,
|
|
3536
3729
|
formatWithOptions,
|
|
3537
3730
|
// getStringWidth,
|
|
3538
3731
|
stripVTControlCharacters,
|
|
@@ -3623,7 +3816,7 @@ function createUtil() {
|
|
|
3623
3816
|
inspect3.defaultOptions = inspect.defaultOptions ?? { depth: 2, colors: false };
|
|
3624
3817
|
return {
|
|
3625
3818
|
inspect: inspect3,
|
|
3626
|
-
format,
|
|
3819
|
+
format: format2,
|
|
3627
3820
|
formatWithOptions,
|
|
3628
3821
|
promisify,
|
|
3629
3822
|
types,
|
|
@@ -4146,7 +4339,7 @@ var Parser = function Parser2(options, input, startPos) {
|
|
|
4146
4339
|
this.privateNameStack = [];
|
|
4147
4340
|
};
|
|
4148
4341
|
var prototypeAccessors = { inFunction: { configurable: true }, inGenerator: { configurable: true }, inAsync: { configurable: true }, canAwait: { configurable: true }, allowReturn: { configurable: true }, allowSuper: { configurable: true }, allowDirectSuper: { configurable: true }, treatFunctionsAsVar: { configurable: true }, allowNewDotTarget: { configurable: true }, allowUsing: { configurable: true }, inClassStaticBlock: { configurable: true } };
|
|
4149
|
-
Parser.prototype.parse = function
|
|
4342
|
+
Parser.prototype.parse = function parse2() {
|
|
4150
4343
|
var this$1$1 = this;
|
|
4151
4344
|
var node = this.options.program || this.startNode();
|
|
4152
4345
|
this.nextToken();
|
|
@@ -4229,7 +4422,7 @@ Parser.extend = function extend() {
|
|
|
4229
4422
|
}
|
|
4230
4423
|
return cls;
|
|
4231
4424
|
};
|
|
4232
|
-
Parser.parse = function
|
|
4425
|
+
Parser.parse = function parse3(input, options) {
|
|
4233
4426
|
return new this(options, input).parse();
|
|
4234
4427
|
};
|
|
4235
4428
|
Parser.parseExpressionAt = function parseExpressionAt(input, pos, options) {
|
|
@@ -9370,7 +9563,7 @@ Parser.acorn = {
|
|
|
9370
9563
|
lineBreakG,
|
|
9371
9564
|
nonASCIIwhitespace
|
|
9372
9565
|
};
|
|
9373
|
-
function
|
|
9566
|
+
function parse4(input, options) {
|
|
9374
9567
|
return Parser.parse(input, options);
|
|
9375
9568
|
}
|
|
9376
9569
|
|
|
@@ -9412,7 +9605,7 @@ function transformEsm(source, filename) {
|
|
|
9412
9605
|
const body = stripHashbang(source);
|
|
9413
9606
|
let ast;
|
|
9414
9607
|
try {
|
|
9415
|
-
ast =
|
|
9608
|
+
ast = parse4(body, {
|
|
9416
9609
|
ecmaVersion: "latest",
|
|
9417
9610
|
sourceType: "module",
|
|
9418
9611
|
allowAwaitOutsideFunction: true
|
|
@@ -9873,7 +10066,7 @@ function rewriteDynamicImports(source) {
|
|
|
9873
10066
|
const body = stripHashbang(source);
|
|
9874
10067
|
let ast;
|
|
9875
10068
|
try {
|
|
9876
|
-
ast =
|
|
10069
|
+
ast = parse4(body, {
|
|
9877
10070
|
ecmaVersion: "latest",
|
|
9878
10071
|
sourceType: "script",
|
|
9879
10072
|
allowAwaitOutsideFunction: false
|
|
@@ -9903,7 +10096,7 @@ function rewriteDynamicImports(source) {
|
|
|
9903
10096
|
function shouldRunAsEsm(source) {
|
|
9904
10097
|
const body = stripHashbang(source);
|
|
9905
10098
|
try {
|
|
9906
|
-
|
|
10099
|
+
parse4(body, {
|
|
9907
10100
|
ecmaVersion: "latest",
|
|
9908
10101
|
sourceType: "script",
|
|
9909
10102
|
allowAwaitOutsideFunction: false
|
|
@@ -9912,7 +10105,7 @@ function shouldRunAsEsm(source) {
|
|
|
9912
10105
|
} catch {
|
|
9913
10106
|
}
|
|
9914
10107
|
try {
|
|
9915
|
-
|
|
10108
|
+
parse4(body, {
|
|
9916
10109
|
ecmaVersion: "latest",
|
|
9917
10110
|
sourceType: "module",
|
|
9918
10111
|
allowAwaitOutsideFunction: true
|
|
@@ -9923,138 +10116,6 @@ function shouldRunAsEsm(source) {
|
|
|
9923
10116
|
}
|
|
9924
10117
|
}
|
|
9925
10118
|
|
|
9926
|
-
// src/runtime/path.mjs
|
|
9927
|
-
function normalizeArray(parts, allowAboveRoot) {
|
|
9928
|
-
const res = [];
|
|
9929
|
-
for (const part of parts) {
|
|
9930
|
-
if (part === "" || part === ".") continue;
|
|
9931
|
-
if (part === "..") {
|
|
9932
|
-
if (res.length > 0 && res[res.length - 1] !== "..") res.pop();
|
|
9933
|
-
else if (allowAboveRoot) res.push("..");
|
|
9934
|
-
} else {
|
|
9935
|
-
res.push(part);
|
|
9936
|
-
}
|
|
9937
|
-
}
|
|
9938
|
-
return res;
|
|
9939
|
-
}
|
|
9940
|
-
function normalize(path) {
|
|
9941
|
-
if (path.length === 0) return ".";
|
|
9942
|
-
const isAbsolute = path.charCodeAt(0) === 47;
|
|
9943
|
-
const trailingSep = path.charCodeAt(path.length - 1) === 47;
|
|
9944
|
-
let out = normalizeArray(path.split("/"), !isAbsolute).join("/");
|
|
9945
|
-
if (out.length === 0 && !isAbsolute) out = ".";
|
|
9946
|
-
if (out.length > 0 && trailingSep) out += "/";
|
|
9947
|
-
return (isAbsolute ? "/" : "") + out;
|
|
9948
|
-
}
|
|
9949
|
-
function join(...parts) {
|
|
9950
|
-
const joined = parts.filter((p) => typeof p === "string" && p.length > 0).join("/");
|
|
9951
|
-
if (joined.length === 0) return ".";
|
|
9952
|
-
return normalize(joined);
|
|
9953
|
-
}
|
|
9954
|
-
function dirname(path) {
|
|
9955
|
-
if (path.length === 0) return ".";
|
|
9956
|
-
const hasRoot = path.charCodeAt(0) === 47;
|
|
9957
|
-
let end = -1;
|
|
9958
|
-
let matchedSlash = true;
|
|
9959
|
-
for (let i2 = path.length - 1; i2 >= 1; i2--) {
|
|
9960
|
-
if (path.charCodeAt(i2) === 47) {
|
|
9961
|
-
if (!matchedSlash) {
|
|
9962
|
-
end = i2;
|
|
9963
|
-
break;
|
|
9964
|
-
}
|
|
9965
|
-
} else {
|
|
9966
|
-
matchedSlash = false;
|
|
9967
|
-
}
|
|
9968
|
-
}
|
|
9969
|
-
if (end === -1) return hasRoot ? "/" : ".";
|
|
9970
|
-
return path.slice(0, end);
|
|
9971
|
-
}
|
|
9972
|
-
function basename(path, ext) {
|
|
9973
|
-
let start = 0;
|
|
9974
|
-
let end = -1;
|
|
9975
|
-
let matchedSlash = true;
|
|
9976
|
-
for (let i2 = path.length - 1; i2 >= 0; i2--) {
|
|
9977
|
-
if (path.charCodeAt(i2) === 47) {
|
|
9978
|
-
if (!matchedSlash) {
|
|
9979
|
-
start = i2 + 1;
|
|
9980
|
-
break;
|
|
9981
|
-
}
|
|
9982
|
-
} else if (end === -1) {
|
|
9983
|
-
matchedSlash = false;
|
|
9984
|
-
end = i2 + 1;
|
|
9985
|
-
}
|
|
9986
|
-
}
|
|
9987
|
-
const base = end === -1 ? "" : path.slice(start, end);
|
|
9988
|
-
if (ext && base.endsWith(ext) && base !== ext) return base.slice(0, base.length - ext.length);
|
|
9989
|
-
return base;
|
|
9990
|
-
}
|
|
9991
|
-
function extname(path) {
|
|
9992
|
-
const base = basename(path);
|
|
9993
|
-
const dot = base.lastIndexOf(".");
|
|
9994
|
-
if (dot <= 0) return "";
|
|
9995
|
-
return base.slice(dot);
|
|
9996
|
-
}
|
|
9997
|
-
function resolve(getCwd, parts) {
|
|
9998
|
-
let resolved = "";
|
|
9999
|
-
let isAbsolute = false;
|
|
10000
|
-
for (let i2 = parts.length - 1; i2 >= -1 && !isAbsolute; i2--) {
|
|
10001
|
-
const part = i2 >= 0 ? parts[i2] : getCwd();
|
|
10002
|
-
if (typeof part !== "string" || part.length === 0) continue;
|
|
10003
|
-
resolved = resolved.length > 0 ? `${part}/${resolved}` : part;
|
|
10004
|
-
isAbsolute = part.charCodeAt(0) === 47;
|
|
10005
|
-
}
|
|
10006
|
-
const normalized = normalizeArray(resolved.split("/"), !isAbsolute).join("/");
|
|
10007
|
-
if (isAbsolute) return normalized.length > 0 ? `/${normalized}` : "/";
|
|
10008
|
-
return normalized.length > 0 ? normalized : ".";
|
|
10009
|
-
}
|
|
10010
|
-
function parse4(path) {
|
|
10011
|
-
const ret = { root: "", dir: "", base: "", ext: "", name: "" };
|
|
10012
|
-
if (path.length === 0) return ret;
|
|
10013
|
-
const isAbsolute = path.charCodeAt(0) === 47;
|
|
10014
|
-
if (isAbsolute) ret.root = "/";
|
|
10015
|
-
ret.dir = dirname(path);
|
|
10016
|
-
ret.base = basename(path);
|
|
10017
|
-
ret.ext = extname(path);
|
|
10018
|
-
ret.name = ret.ext ? ret.base.slice(0, ret.base.length - ret.ext.length) : ret.base;
|
|
10019
|
-
if (ret.dir === "." && !isAbsolute) ret.dir = "";
|
|
10020
|
-
return ret;
|
|
10021
|
-
}
|
|
10022
|
-
function format2(pathObject) {
|
|
10023
|
-
if (typeof pathObject === "string") return pathObject;
|
|
10024
|
-
const dir = pathObject.dir || pathObject.root || "";
|
|
10025
|
-
const base = pathObject.base || `${pathObject.name || ""}${pathObject.ext || ""}`;
|
|
10026
|
-
if (!dir) return base;
|
|
10027
|
-
if (dir === "/") return `/${base}`;
|
|
10028
|
-
return `${dir}/${base}`;
|
|
10029
|
-
}
|
|
10030
|
-
function createPath(getCwd = () => "/") {
|
|
10031
|
-
const api = {
|
|
10032
|
-
sep: "/",
|
|
10033
|
-
delimiter: ":",
|
|
10034
|
-
basename,
|
|
10035
|
-
dirname,
|
|
10036
|
-
extname,
|
|
10037
|
-
parse: parse4,
|
|
10038
|
-
format: format2,
|
|
10039
|
-
isAbsolute: (path) => path.length > 0 && path.charCodeAt(0) === 47,
|
|
10040
|
-
join,
|
|
10041
|
-
normalize,
|
|
10042
|
-
resolve: (...parts) => resolve(getCwd, parts),
|
|
10043
|
-
relative(from, to) {
|
|
10044
|
-
const fromAbs = resolve(getCwd, [from]);
|
|
10045
|
-
const toAbs = resolve(getCwd, [to]);
|
|
10046
|
-
if (fromAbs === toAbs) return "";
|
|
10047
|
-
const fromParts = fromAbs.split("/").filter(Boolean);
|
|
10048
|
-
const toParts = toAbs.split("/").filter(Boolean);
|
|
10049
|
-
let i2 = 0;
|
|
10050
|
-
while (i2 < fromParts.length && i2 < toParts.length && fromParts[i2] === toParts[i2]) i2++;
|
|
10051
|
-
return [...fromParts.slice(i2).map(() => ".."), ...toParts.slice(i2)].join("/");
|
|
10052
|
-
}
|
|
10053
|
-
};
|
|
10054
|
-
api.posix = api;
|
|
10055
|
-
return api;
|
|
10056
|
-
}
|
|
10057
|
-
|
|
10058
10119
|
// src/runtime/builtins/assert.mjs
|
|
10059
10120
|
var inspect2 = (v) => inspect(v, { compact: false, breakLength: 80, sorted: true });
|
|
10060
10121
|
var AssertionError = class extends Error {
|
|
@@ -10761,6 +10822,27 @@ function createEvents() {
|
|
|
10761
10822
|
}
|
|
10762
10823
|
|
|
10763
10824
|
// src/runtime/builtins/child-process.mjs
|
|
10825
|
+
var PROMISIFY_CUSTOM2 = /* @__PURE__ */ Symbol.for("nodejs.util.promisify.custom");
|
|
10826
|
+
function customPromiseExecFunction(orig) {
|
|
10827
|
+
return function(...args) {
|
|
10828
|
+
let resolve2;
|
|
10829
|
+
let reject;
|
|
10830
|
+
const promise = new Promise((res, rej) => {
|
|
10831
|
+
resolve2 = res;
|
|
10832
|
+
reject = rej;
|
|
10833
|
+
});
|
|
10834
|
+
promise.child = orig(...args, (err, stdout, stderr) => {
|
|
10835
|
+
if (err != null) {
|
|
10836
|
+
err.stdout = stdout;
|
|
10837
|
+
err.stderr = stderr;
|
|
10838
|
+
reject(err);
|
|
10839
|
+
} else {
|
|
10840
|
+
resolve2({ stdout, stderr });
|
|
10841
|
+
}
|
|
10842
|
+
});
|
|
10843
|
+
return promise;
|
|
10844
|
+
};
|
|
10845
|
+
}
|
|
10764
10846
|
var SIGNAL_NAMES = {
|
|
10765
10847
|
1: "SIGHUP",
|
|
10766
10848
|
2: "SIGINT",
|
|
@@ -11250,6 +11332,14 @@ function createChildProcess({ ctx, process: process2, Buffer: Buffer2, handles,
|
|
|
11250
11332
|
const cmd = String(command);
|
|
11251
11333
|
return execFile(shell, ["-c", cmd], { ...opts, shell: false, _execCmd: cmd }, cb);
|
|
11252
11334
|
}
|
|
11335
|
+
Object.defineProperty(exec, PROMISIFY_CUSTOM2, {
|
|
11336
|
+
enumerable: false,
|
|
11337
|
+
value: customPromiseExecFunction(exec)
|
|
11338
|
+
});
|
|
11339
|
+
Object.defineProperty(execFile, PROMISIFY_CUSTOM2, {
|
|
11340
|
+
enumerable: false,
|
|
11341
|
+
value: customPromiseExecFunction(execFile)
|
|
11342
|
+
});
|
|
11253
11343
|
return {
|
|
11254
11344
|
spawn,
|
|
11255
11345
|
execFile,
|
|
@@ -11273,10 +11363,375 @@ function createChildProcess({ ctx, process: process2, Buffer: Buffer2, handles,
|
|
|
11273
11363
|
};
|
|
11274
11364
|
}
|
|
11275
11365
|
|
|
11366
|
+
// src/runtime/builtins/fs-cp.mjs
|
|
11367
|
+
var ERRNO = { EEXIST: 17, ENOTDIR: 20, EISDIR: 21, EINVAL: 22 };
|
|
11368
|
+
var SYSTEM_ERROR_PREFIX = {
|
|
11369
|
+
ERR_FS_CP_DIR_TO_NON_DIR: "Cannot overwrite non-directory with directory",
|
|
11370
|
+
ERR_FS_CP_EEXIST: "Target already exists",
|
|
11371
|
+
ERR_FS_CP_EINVAL: "Invalid src or dest",
|
|
11372
|
+
ERR_FS_CP_NON_DIR_TO_DIR: "Cannot overwrite directory with non-directory",
|
|
11373
|
+
ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY: "Cannot overwrite symlink in subdirectory of self",
|
|
11374
|
+
ERR_FS_EISDIR: "Path is a directory"
|
|
11375
|
+
};
|
|
11376
|
+
function systemError(key, { message, path, code }) {
|
|
11377
|
+
const err = new Error(
|
|
11378
|
+
`${SYSTEM_ERROR_PREFIX[key]}: cp returned ${code} (${message})${path === void 0 ? "" : ` ${path}`}`
|
|
11379
|
+
);
|
|
11380
|
+
err.name = "SystemError";
|
|
11381
|
+
err.code = key;
|
|
11382
|
+
err.errno = ERRNO[code];
|
|
11383
|
+
err.syscall = "cp";
|
|
11384
|
+
if (path !== void 0) err.path = path;
|
|
11385
|
+
err.info = { code, message, path, syscall: "cp", errno: ERRNO[code] };
|
|
11386
|
+
return err;
|
|
11387
|
+
}
|
|
11388
|
+
function nativeError(code, message) {
|
|
11389
|
+
const err = new Error(message);
|
|
11390
|
+
err.code = code;
|
|
11391
|
+
return err;
|
|
11392
|
+
}
|
|
11393
|
+
function invalidFilterReturn() {
|
|
11394
|
+
const err = new TypeError(
|
|
11395
|
+
'Expected boolean to be returned from the "filter" function but got an instance of Promise.'
|
|
11396
|
+
);
|
|
11397
|
+
err.code = "ERR_INVALID_RETURN_VALUE";
|
|
11398
|
+
return err;
|
|
11399
|
+
}
|
|
11400
|
+
var isPromise = (v) => v != null && typeof v.then === "function";
|
|
11401
|
+
function createCp({ path, ops, abs, fsError, copyFileSync, mkdirpSync }) {
|
|
11402
|
+
const tryCall = (fn) => {
|
|
11403
|
+
try {
|
|
11404
|
+
return fn();
|
|
11405
|
+
} catch {
|
|
11406
|
+
return null;
|
|
11407
|
+
}
|
|
11408
|
+
};
|
|
11409
|
+
const call = (fn, syscall, pathArg, dest) => {
|
|
11410
|
+
try {
|
|
11411
|
+
return fn();
|
|
11412
|
+
} catch (err) {
|
|
11413
|
+
if (err?.syscall) throw err;
|
|
11414
|
+
throw fsError(err?.code || "EIO", syscall, pathArg, err, dest);
|
|
11415
|
+
}
|
|
11416
|
+
};
|
|
11417
|
+
const lstat = (p) => call(() => ops.lstat(abs(p)), "lstat", p);
|
|
11418
|
+
const stat = (p) => call(() => ops.stat(abs(p)), "stat", p);
|
|
11419
|
+
const readlink = (p) => call(() => ops.readlink(abs(p)), "readlink", p);
|
|
11420
|
+
const symlink = (target, p) => call(() => ops.symlink(target, abs(p)), "symlink", target, p);
|
|
11421
|
+
const unlink = (p) => call(() => ops.unlink(abs(p)), "unlink", p);
|
|
11422
|
+
const readdir = (p) => call(() => ops.readdir(abs(p)), "scandir", p);
|
|
11423
|
+
const exists = (p) => !!tryCall(() => ops.stat(abs(p)));
|
|
11424
|
+
const realpathSync = (p) => realpathWith(ops, path, p, (code, syscall, at2, err) => fsError(code, syscall, at2, err));
|
|
11425
|
+
function weaklyCanonical(p) {
|
|
11426
|
+
const parts = path.resolve(p).split("/").filter(Boolean);
|
|
11427
|
+
for (let i2 = parts.length; i2 > 0; i2--) {
|
|
11428
|
+
const prefix = `/${parts.slice(0, i2).join("/")}`;
|
|
11429
|
+
if (!exists(prefix)) continue;
|
|
11430
|
+
const real = tryCall(() => realpathSync(prefix)) ?? prefix;
|
|
11431
|
+
return path.join(real, ...parts.slice(i2));
|
|
11432
|
+
}
|
|
11433
|
+
return path.resolve(p);
|
|
11434
|
+
}
|
|
11435
|
+
const equivalent = (a, b) => {
|
|
11436
|
+
if (!exists(a) || !exists(b)) return false;
|
|
11437
|
+
return tryCall(() => realpathSync(a)) === tryCall(() => realpathSync(b));
|
|
11438
|
+
};
|
|
11439
|
+
const normalizeArray2 = (p) => path.resolve(p).split("/").filter(Boolean);
|
|
11440
|
+
const isSrcSubdir = (src, dest) => {
|
|
11441
|
+
const s = normalizeArray2(src);
|
|
11442
|
+
const d = normalizeArray2(dest);
|
|
11443
|
+
return s.every((cur, i2) => d[i2] === cur);
|
|
11444
|
+
};
|
|
11445
|
+
const withDefaults = (options = {}) => ({
|
|
11446
|
+
dereference: false,
|
|
11447
|
+
errorOnExist: false,
|
|
11448
|
+
force: true,
|
|
11449
|
+
preserveTimestamps: false,
|
|
11450
|
+
recursive: false,
|
|
11451
|
+
verbatimSymlinks: false,
|
|
11452
|
+
mode: 0,
|
|
11453
|
+
...options
|
|
11454
|
+
});
|
|
11455
|
+
function checkPathsSync(src, dest, dereference, recursive) {
|
|
11456
|
+
const srcSt = call(() => dereference ? ops.lstat(abs(src)) : ops.stat(abs(src)), dereference ? "stat" : "lstat", src);
|
|
11457
|
+
const destSt = tryCall(() => dereference ? ops.stat(abs(dest)) : ops.lstat(abs(dest)));
|
|
11458
|
+
const srcIsDir = !!srcSt.isDirectory || dereference && !!srcSt.isSymbolicLink;
|
|
11459
|
+
if (destSt) {
|
|
11460
|
+
if (equivalent(src, dest)) throw nativeError("ERR_FS_CP_EINVAL", `src and dest cannot be the same ${dest}`);
|
|
11461
|
+
const destIsDir = !!destSt.isDirectory;
|
|
11462
|
+
if (srcIsDir && !destIsDir) {
|
|
11463
|
+
throw nativeError("ERR_FS_CP_DIR_TO_NON_DIR", `Cannot overwrite non-directory ${dest} with directory ${src}`);
|
|
11464
|
+
}
|
|
11465
|
+
if (!srcIsDir && destIsDir) {
|
|
11466
|
+
throw nativeError("ERR_FS_CP_NON_DIR_TO_DIR", `Cannot overwrite directory ${dest} with non-directory ${src}`);
|
|
11467
|
+
}
|
|
11468
|
+
}
|
|
11469
|
+
const srcSlash = src.endsWith("/") ? src : `${src}/`;
|
|
11470
|
+
const subdir = () => nativeError("ERR_FS_CP_EINVAL", `Cannot copy ${srcSlash} to a subdirectory of self ${dest}`);
|
|
11471
|
+
if (srcIsDir && dest.startsWith(srcSlash)) throw subdir();
|
|
11472
|
+
if (path.dirname(src) !== path.dirname(dest) && equivalent(src, path.dirname(dest))) throw subdir();
|
|
11473
|
+
if (srcIsDir && !recursive) {
|
|
11474
|
+
throw nativeError("ERR_FS_EISDIR", `Recursive option not enabled, cannot copy a directory: ${srcSlash}`);
|
|
11475
|
+
}
|
|
11476
|
+
if (!destSt || !exists(path.dirname(dest))) tryCall(() => mkdirpSync(path.dirname(dest)));
|
|
11477
|
+
}
|
|
11478
|
+
function getStatsSync(src, dest, opts) {
|
|
11479
|
+
const srcSt = opts.dereference ? stat(src) : lstat(src);
|
|
11480
|
+
const destSt = tryCall(() => opts.dereference ? ops.stat(abs(dest)) : ops.lstat(abs(dest)));
|
|
11481
|
+
if (srcSt.isDirectory && opts.recursive) return copyDirSync(src, dest, opts, !destSt);
|
|
11482
|
+
if (srcSt.isSymbolicLink) return onLinkSync(destSt, src, dest, opts.verbatimSymlinks);
|
|
11483
|
+
if (!destSt) return copyFileSync(src, dest, opts.mode);
|
|
11484
|
+
if (opts.force) {
|
|
11485
|
+
unlink(dest);
|
|
11486
|
+
return copyFileSync(src, dest, opts.mode);
|
|
11487
|
+
}
|
|
11488
|
+
if (opts.errorOnExist) {
|
|
11489
|
+
throw systemError("ERR_FS_CP_EEXIST", { message: `${dest} already exists`, path: dest, code: "EEXIST" });
|
|
11490
|
+
}
|
|
11491
|
+
return void 0;
|
|
11492
|
+
}
|
|
11493
|
+
function copyDirSync(src, dest, opts, mkDir) {
|
|
11494
|
+
if (!opts.filter) return nativeCopyDir(src, dest, opts);
|
|
11495
|
+
if (mkDir) call(() => ops.mkdir(abs(dest)), "mkdir", dest);
|
|
11496
|
+
for (const name of readdir(src)) {
|
|
11497
|
+
const srcItem = path.join(src, name);
|
|
11498
|
+
const destItem = path.join(dest, name);
|
|
11499
|
+
const shouldCopy = opts.filter(srcItem, destItem);
|
|
11500
|
+
if (isPromise(shouldCopy)) throw invalidFilterReturn();
|
|
11501
|
+
if (shouldCopy) getStatsSync(srcItem, destItem, opts);
|
|
11502
|
+
}
|
|
11503
|
+
return void 0;
|
|
11504
|
+
}
|
|
11505
|
+
function nativeCopyDir(src, dest, opts) {
|
|
11506
|
+
call(() => mkdirpSync(dest), "cp", dest);
|
|
11507
|
+
const walk2 = (srcDir, destDir) => {
|
|
11508
|
+
for (const name of readdir(srcDir)) {
|
|
11509
|
+
const srcItem = path.join(srcDir, name);
|
|
11510
|
+
const destItem = path.join(destDir, name);
|
|
11511
|
+
const st = lstat(srcItem);
|
|
11512
|
+
if (st.isSymbolicLink) {
|
|
11513
|
+
const target = readlink(srcItem);
|
|
11514
|
+
if (opts.verbatimSymlinks) {
|
|
11515
|
+
if (tryCall(() => ops.lstat(abs(destItem)))) throw fsError("EEXIST", "cp", destDir);
|
|
11516
|
+
symlink(target, destItem);
|
|
11517
|
+
continue;
|
|
11518
|
+
}
|
|
11519
|
+
if (exists(destItem)) {
|
|
11520
|
+
const destLink = tryCall(() => ops.lstat(abs(destItem)));
|
|
11521
|
+
if (destLink?.isSymbolicLink) {
|
|
11522
|
+
unlink(destItem);
|
|
11523
|
+
} else if (!stat(destItem).isDirectory) {
|
|
11524
|
+
if (!opts.dereference || !opts.force && opts.errorOnExist) {
|
|
11525
|
+
throw fsError("EEXIST", "cp", destItem);
|
|
11526
|
+
}
|
|
11527
|
+
}
|
|
11528
|
+
} else if (tryCall(() => ops.lstat(abs(destItem)))?.isSymbolicLink) {
|
|
11529
|
+
unlink(destItem);
|
|
11530
|
+
}
|
|
11531
|
+
symlink(weaklyCanonical(path.resolve(srcDir, target)), destItem);
|
|
11532
|
+
} else if (st.isDirectory) {
|
|
11533
|
+
if (!tryCall(() => ops.lstat(abs(destItem)))) call(() => ops.mkdir(abs(destItem)), "cp", destDir);
|
|
11534
|
+
walk2(srcItem, destItem);
|
|
11535
|
+
} else {
|
|
11536
|
+
const there = tryCall(() => ops.lstat(abs(destItem)));
|
|
11537
|
+
if (there) {
|
|
11538
|
+
if (opts.force) {
|
|
11539
|
+
unlink(destItem);
|
|
11540
|
+
} else if (opts.errorOnExist) {
|
|
11541
|
+
throw nativeError(
|
|
11542
|
+
"ERR_FS_CP_EEXIST",
|
|
11543
|
+
`[ERR_FS_CP_EEXIST]: Target already exists: cp returned EEXIST (${destItem} already exists)`
|
|
11544
|
+
);
|
|
11545
|
+
} else {
|
|
11546
|
+
continue;
|
|
11547
|
+
}
|
|
11548
|
+
}
|
|
11549
|
+
copyFileSync(srcItem, destItem);
|
|
11550
|
+
}
|
|
11551
|
+
}
|
|
11552
|
+
};
|
|
11553
|
+
walk2(src, dest);
|
|
11554
|
+
}
|
|
11555
|
+
function onLinkSync(destSt, src, dest, verbatimSymlinks) {
|
|
11556
|
+
let resolvedSrc = readlink(src);
|
|
11557
|
+
if (!verbatimSymlinks && !path.isAbsolute(resolvedSrc)) resolvedSrc = path.resolve(path.dirname(src), resolvedSrc);
|
|
11558
|
+
if (!destSt) return symlink(resolvedSrc, dest);
|
|
11559
|
+
let resolvedDest;
|
|
11560
|
+
try {
|
|
11561
|
+
resolvedDest = readlink(dest);
|
|
11562
|
+
} catch (err) {
|
|
11563
|
+
if (err.code === "EINVAL" || err.code === "UNKNOWN") return symlink(resolvedSrc, dest);
|
|
11564
|
+
throw err;
|
|
11565
|
+
}
|
|
11566
|
+
if (!path.isAbsolute(resolvedDest)) resolvedDest = path.resolve(path.dirname(dest), resolvedDest);
|
|
11567
|
+
if (isSrcSubdir(resolvedSrc, resolvedDest)) {
|
|
11568
|
+
throw systemError("ERR_FS_CP_EINVAL", {
|
|
11569
|
+
message: `cannot copy ${resolvedSrc} to a subdirectory of self ${resolvedDest}`,
|
|
11570
|
+
path: dest,
|
|
11571
|
+
code: "EINVAL"
|
|
11572
|
+
});
|
|
11573
|
+
}
|
|
11574
|
+
if (tryCall(() => ops.stat(abs(dest)))?.isDirectory && isSrcSubdir(resolvedDest, resolvedSrc)) {
|
|
11575
|
+
throw systemError("ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY", {
|
|
11576
|
+
message: `cannot overwrite ${resolvedDest} with ${resolvedSrc}`,
|
|
11577
|
+
path: dest,
|
|
11578
|
+
code: "EINVAL"
|
|
11579
|
+
});
|
|
11580
|
+
}
|
|
11581
|
+
unlink(dest);
|
|
11582
|
+
return symlink(resolvedSrc, dest);
|
|
11583
|
+
}
|
|
11584
|
+
function cpSync(src, dest, options) {
|
|
11585
|
+
const opts = withDefaults(options);
|
|
11586
|
+
src = String(src);
|
|
11587
|
+
dest = String(dest);
|
|
11588
|
+
if (opts.filter) {
|
|
11589
|
+
const shouldCopy = opts.filter(src, dest);
|
|
11590
|
+
if (isPromise(shouldCopy)) throw invalidFilterReturn();
|
|
11591
|
+
if (!shouldCopy) return;
|
|
11592
|
+
}
|
|
11593
|
+
checkPathsSync(src, dest, opts.dereference, opts.recursive);
|
|
11594
|
+
getStatsSync(src, dest, opts);
|
|
11595
|
+
}
|
|
11596
|
+
const sameFile = (a, aPath, b, bPath) => {
|
|
11597
|
+
if (a?.ino && a?.dev && b?.ino && b?.dev) return a.ino === b.ino && a.dev === b.dev;
|
|
11598
|
+
return equivalent(aPath, bPath);
|
|
11599
|
+
};
|
|
11600
|
+
async function cp(src, dest, options) {
|
|
11601
|
+
const opts = withDefaults(options);
|
|
11602
|
+
src = String(src);
|
|
11603
|
+
dest = String(dest);
|
|
11604
|
+
const checked = await checkPaths(src, dest, opts);
|
|
11605
|
+
if (checked.skipped) return;
|
|
11606
|
+
checkParentPaths(src, checked.srcStat, dest);
|
|
11607
|
+
if (!exists(path.dirname(dest))) mkdirpSync(path.dirname(dest));
|
|
11608
|
+
await copyEntry(checked.destStat, src, dest, opts);
|
|
11609
|
+
}
|
|
11610
|
+
async function checkPaths(src, dest, opts) {
|
|
11611
|
+
if (opts.filter && !await opts.filter(src, dest)) return { skipped: true };
|
|
11612
|
+
const statFn = opts.dereference ? stat : lstat;
|
|
11613
|
+
const srcStat = statFn(src);
|
|
11614
|
+
let destStat = null;
|
|
11615
|
+
try {
|
|
11616
|
+
destStat = statFn(dest);
|
|
11617
|
+
} catch (err) {
|
|
11618
|
+
if (err.code !== "ENOENT") throw err;
|
|
11619
|
+
}
|
|
11620
|
+
if (destStat) {
|
|
11621
|
+
if (sameFile(srcStat, src, destStat, dest)) {
|
|
11622
|
+
throw systemError("ERR_FS_CP_EINVAL", { message: "src and dest cannot be the same", path: dest, code: "EINVAL" });
|
|
11623
|
+
}
|
|
11624
|
+
if (srcStat.isDirectory && !destStat.isDirectory) {
|
|
11625
|
+
throw systemError("ERR_FS_CP_DIR_TO_NON_DIR", {
|
|
11626
|
+
message: `cannot overwrite non-directory ${dest} with directory ${src}`,
|
|
11627
|
+
path: dest,
|
|
11628
|
+
code: "EISDIR"
|
|
11629
|
+
});
|
|
11630
|
+
}
|
|
11631
|
+
if (!srcStat.isDirectory && destStat.isDirectory) {
|
|
11632
|
+
throw systemError("ERR_FS_CP_NON_DIR_TO_DIR", {
|
|
11633
|
+
message: `cannot overwrite directory ${dest} with non-directory ${src}`,
|
|
11634
|
+
path: dest,
|
|
11635
|
+
code: "ENOTDIR"
|
|
11636
|
+
});
|
|
11637
|
+
}
|
|
11638
|
+
}
|
|
11639
|
+
if (srcStat.isDirectory && isSrcSubdir(src, dest)) {
|
|
11640
|
+
throw systemError("ERR_FS_CP_EINVAL", {
|
|
11641
|
+
message: `cannot copy ${src} to a subdirectory of self ${dest}`,
|
|
11642
|
+
path: dest,
|
|
11643
|
+
code: "EINVAL"
|
|
11644
|
+
});
|
|
11645
|
+
}
|
|
11646
|
+
return { srcStat, destStat, skipped: false };
|
|
11647
|
+
}
|
|
11648
|
+
function checkParentPaths(src, srcStat, dest) {
|
|
11649
|
+
const srcParent = path.resolve(path.dirname(src));
|
|
11650
|
+
const destParent = path.resolve(path.dirname(dest));
|
|
11651
|
+
if (destParent === srcParent || destParent === "/") return;
|
|
11652
|
+
const destStat = tryCall(() => ops.stat(destParent));
|
|
11653
|
+
if (!destStat) return;
|
|
11654
|
+
const same = sameFile(srcStat, src, destStat, destParent);
|
|
11655
|
+
if (same) {
|
|
11656
|
+
throw systemError("ERR_FS_CP_EINVAL", {
|
|
11657
|
+
message: `cannot copy ${src} to a subdirectory of self ${dest}`,
|
|
11658
|
+
path: dest,
|
|
11659
|
+
code: "EINVAL"
|
|
11660
|
+
});
|
|
11661
|
+
}
|
|
11662
|
+
checkParentPaths(src, srcStat, destParent);
|
|
11663
|
+
}
|
|
11664
|
+
async function copyEntry(destStat, src, dest, opts) {
|
|
11665
|
+
const srcStat = opts.dereference ? stat(src) : lstat(src);
|
|
11666
|
+
if (srcStat.isDirectory && opts.recursive) {
|
|
11667
|
+
if (!destStat) call(() => ops.mkdir(abs(dest)), "mkdir", dest);
|
|
11668
|
+
for (const name of readdir(src)) {
|
|
11669
|
+
const srcItem = path.join(src, name);
|
|
11670
|
+
const destItem = path.join(dest, name);
|
|
11671
|
+
const checked = await checkPaths(srcItem, destItem, opts);
|
|
11672
|
+
if (!checked.skipped) await copyEntry(checked.destStat, srcItem, destItem, opts);
|
|
11673
|
+
}
|
|
11674
|
+
return;
|
|
11675
|
+
}
|
|
11676
|
+
if (srcStat.isDirectory) {
|
|
11677
|
+
throw systemError("ERR_FS_EISDIR", { message: `${src} is a directory (not copied)`, path: src, code: "EISDIR" });
|
|
11678
|
+
}
|
|
11679
|
+
if (srcStat.isSymbolicLink) {
|
|
11680
|
+
let resolvedSrc = readlink(src);
|
|
11681
|
+
if (!opts.verbatimSymlinks && !path.isAbsolute(resolvedSrc)) {
|
|
11682
|
+
resolvedSrc = path.resolve(path.dirname(src), resolvedSrc);
|
|
11683
|
+
}
|
|
11684
|
+
if (!destStat) {
|
|
11685
|
+
symlink(resolvedSrc, dest);
|
|
11686
|
+
return;
|
|
11687
|
+
}
|
|
11688
|
+
let resolvedDest;
|
|
11689
|
+
try {
|
|
11690
|
+
resolvedDest = readlink(dest);
|
|
11691
|
+
} catch (err) {
|
|
11692
|
+
if (err.code === "EINVAL" || err.code === "UNKNOWN") {
|
|
11693
|
+
symlink(resolvedSrc, dest);
|
|
11694
|
+
return;
|
|
11695
|
+
}
|
|
11696
|
+
throw err;
|
|
11697
|
+
}
|
|
11698
|
+
if (!path.isAbsolute(resolvedDest)) resolvedDest = path.resolve(path.dirname(dest), resolvedDest);
|
|
11699
|
+
if (isSrcSubdir(resolvedSrc, resolvedDest)) {
|
|
11700
|
+
throw systemError("ERR_FS_CP_EINVAL", {
|
|
11701
|
+
message: `cannot copy ${resolvedSrc} to a subdirectory of self ${resolvedDest}`,
|
|
11702
|
+
path: dest,
|
|
11703
|
+
code: "EINVAL"
|
|
11704
|
+
});
|
|
11705
|
+
}
|
|
11706
|
+
if (tryCall(() => ops.stat(abs(src)))?.isDirectory && isSrcSubdir(resolvedDest, resolvedSrc)) {
|
|
11707
|
+
throw systemError("ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY", {
|
|
11708
|
+
message: `cannot overwrite ${resolvedDest} with ${resolvedSrc}`,
|
|
11709
|
+
path: dest,
|
|
11710
|
+
code: "EINVAL"
|
|
11711
|
+
});
|
|
11712
|
+
}
|
|
11713
|
+
unlink(dest);
|
|
11714
|
+
symlink(resolvedSrc, dest);
|
|
11715
|
+
return;
|
|
11716
|
+
}
|
|
11717
|
+
if (!destStat) {
|
|
11718
|
+
copyFileSync(src, dest, opts.mode);
|
|
11719
|
+
return;
|
|
11720
|
+
}
|
|
11721
|
+
if (opts.force) {
|
|
11722
|
+
unlink(dest);
|
|
11723
|
+
copyFileSync(src, dest, opts.mode);
|
|
11724
|
+
} else if (opts.errorOnExist) {
|
|
11725
|
+
throw systemError("ERR_FS_CP_EEXIST", { message: `${dest} already exists`, path: dest, code: "EEXIST" });
|
|
11726
|
+
}
|
|
11727
|
+
}
|
|
11728
|
+
return { cpSync, cp, realpathSync, weaklyCanonical };
|
|
11729
|
+
}
|
|
11730
|
+
|
|
11276
11731
|
// src/runtime/builtins/fs.mjs
|
|
11277
11732
|
var encoder3 = new TextEncoder();
|
|
11278
11733
|
var decoder3 = new TextDecoder();
|
|
11279
|
-
var
|
|
11734
|
+
var ERRNO2 = {
|
|
11280
11735
|
ENOENT: -2,
|
|
11281
11736
|
EEXIST: -17,
|
|
11282
11737
|
EISDIR: -21,
|
|
@@ -11288,7 +11743,9 @@ var ERRNO = {
|
|
|
11288
11743
|
ENOTEMPTY: -39,
|
|
11289
11744
|
// Linux (the shim's process.platform)
|
|
11290
11745
|
EBADF: -9,
|
|
11291
|
-
ENOTSUP: -45
|
|
11746
|
+
ENOTSUP: -45,
|
|
11747
|
+
EXDEV: -18,
|
|
11748
|
+
ELOOP: -40
|
|
11292
11749
|
};
|
|
11293
11750
|
var DESCRIPTIONS = {
|
|
11294
11751
|
ENOENT: "no such file or directory",
|
|
@@ -11301,7 +11758,9 @@ var DESCRIPTIONS = {
|
|
|
11301
11758
|
EIO: "i/o error",
|
|
11302
11759
|
ENOTEMPTY: "directory not empty",
|
|
11303
11760
|
EBADF: "bad file descriptor",
|
|
11304
|
-
ENOTSUP: "operation not supported"
|
|
11761
|
+
ENOTSUP: "operation not supported",
|
|
11762
|
+
EXDEV: "cross-device link not permitted",
|
|
11763
|
+
ELOOP: "too many symbolic links encountered"
|
|
11305
11764
|
};
|
|
11306
11765
|
function nodeFsError(code, syscall, pathArg, err, dest) {
|
|
11307
11766
|
const c = typeof code === "string" ? code : err?.code || "EIO";
|
|
@@ -11316,7 +11775,7 @@ function nodeFsError(code, syscall, pathArg, err, dest) {
|
|
|
11316
11775
|
}
|
|
11317
11776
|
const e = new Error(msg);
|
|
11318
11777
|
e.code = c;
|
|
11319
|
-
e.errno =
|
|
11778
|
+
e.errno = ERRNO2[c] ?? -1;
|
|
11320
11779
|
e.syscall = syscall;
|
|
11321
11780
|
if (pathArg !== void 0 && pathArg !== null) e.path = pathArg;
|
|
11322
11781
|
if (dest !== void 0) e.dest = dest;
|
|
@@ -11324,11 +11783,6 @@ function nodeFsError(code, syscall, pathArg, err, dest) {
|
|
|
11324
11783
|
}
|
|
11325
11784
|
var FS_READ_STREAM = /* @__PURE__ */ Symbol("fs.ReadStream");
|
|
11326
11785
|
var FS_WRITE_STREAM = /* @__PURE__ */ Symbol("fs.WriteStream");
|
|
11327
|
-
function cpInvalid(message) {
|
|
11328
|
-
const e = new Error(message);
|
|
11329
|
-
e.code = "ERR_FS_CP_EINVAL";
|
|
11330
|
-
return e;
|
|
11331
|
-
}
|
|
11332
11786
|
function rmIsDirectoryError(pathArg) {
|
|
11333
11787
|
const e = new Error(`Path is a directory: rm returned EISDIR (is a directory) ${pathArg}`);
|
|
11334
11788
|
e.name = "SystemError";
|
|
@@ -11349,15 +11803,19 @@ var S_IFMT = 61440;
|
|
|
11349
11803
|
var S_IFREG = 32768;
|
|
11350
11804
|
var S_IFDIR = 16384;
|
|
11351
11805
|
var S_IFLNK = 40960;
|
|
11806
|
+
var modeType = (mode) => {
|
|
11807
|
+
if (typeof mode === "bigint") return Number(BigInt.asUintN(32, mode) & BigInt(S_IFMT));
|
|
11808
|
+
return typeof mode === "number" ? mode & S_IFMT : -1;
|
|
11809
|
+
};
|
|
11352
11810
|
var Stats = class {
|
|
11353
11811
|
isFile() {
|
|
11354
|
-
return (this.mode
|
|
11812
|
+
return modeType(this.mode) === S_IFREG;
|
|
11355
11813
|
}
|
|
11356
11814
|
isDirectory() {
|
|
11357
|
-
return (this.mode
|
|
11815
|
+
return modeType(this.mode) === S_IFDIR;
|
|
11358
11816
|
}
|
|
11359
11817
|
isSymbolicLink() {
|
|
11360
|
-
return (this.mode
|
|
11818
|
+
return modeType(this.mode) === S_IFLNK;
|
|
11361
11819
|
}
|
|
11362
11820
|
isBlockDevice() {
|
|
11363
11821
|
return false;
|
|
@@ -11372,13 +11830,49 @@ var Stats = class {
|
|
|
11372
11830
|
return false;
|
|
11373
11831
|
}
|
|
11374
11832
|
};
|
|
11375
|
-
|
|
11833
|
+
for (const name of ["atime", "mtime", "ctime", "birthtime"]) {
|
|
11834
|
+
Object.defineProperty(Stats.prototype, name, {
|
|
11835
|
+
configurable: true,
|
|
11836
|
+
enumerable: false,
|
|
11837
|
+
get() {
|
|
11838
|
+
return new Date(Number(this[`${name}Ms`]));
|
|
11839
|
+
},
|
|
11840
|
+
set(value) {
|
|
11841
|
+
Object.defineProperty(this, name, { value, writable: true, configurable: true, enumerable: true });
|
|
11842
|
+
}
|
|
11843
|
+
});
|
|
11844
|
+
}
|
|
11845
|
+
function statView(st, bigint = false) {
|
|
11376
11846
|
const mtimeMs = st.mtimeMs ?? (st.mtime ? Number(st.mtime) : 0);
|
|
11377
11847
|
const atimeMs = st.atimeMs ?? mtimeMs;
|
|
11378
11848
|
const ctimeMs = st.ctimeMs ?? mtimeMs;
|
|
11379
11849
|
const type = st.isDirectory ? S_IFDIR : st.isSymbolicLink ? S_IFLNK : S_IFREG;
|
|
11380
11850
|
const perm = typeof st.mode === "number" ? st.mode & ~S_IFMT : st.isDirectory ? 493 : 420;
|
|
11381
11851
|
const size = st.size ?? 0;
|
|
11852
|
+
if (bigint) {
|
|
11853
|
+
const B = (v) => BigInt(Math.trunc(Number(v) || 0));
|
|
11854
|
+
const ns = (ms) => BigInt(Math.trunc(ms * 1e6));
|
|
11855
|
+
return Object.assign(new Stats(), {
|
|
11856
|
+
dev: B(st.dev),
|
|
11857
|
+
mode: B(type | perm),
|
|
11858
|
+
nlink: B(st.nlink ?? 1),
|
|
11859
|
+
uid: B(st.uid),
|
|
11860
|
+
gid: B(st.gid),
|
|
11861
|
+
rdev: 0n,
|
|
11862
|
+
blksize: 4096n,
|
|
11863
|
+
ino: B(st.ino),
|
|
11864
|
+
size: B(size),
|
|
11865
|
+
blocks: B(Math.ceil(size / 512)),
|
|
11866
|
+
atimeMs: B(atimeMs),
|
|
11867
|
+
mtimeMs: B(mtimeMs),
|
|
11868
|
+
ctimeMs: B(ctimeMs),
|
|
11869
|
+
birthtimeMs: B(ctimeMs),
|
|
11870
|
+
atimeNs: ns(atimeMs),
|
|
11871
|
+
mtimeNs: ns(mtimeMs),
|
|
11872
|
+
ctimeNs: ns(ctimeMs),
|
|
11873
|
+
birthtimeNs: ns(ctimeMs)
|
|
11874
|
+
});
|
|
11875
|
+
}
|
|
11382
11876
|
return Object.assign(new Stats(), {
|
|
11383
11877
|
dev: st.dev ?? 0,
|
|
11384
11878
|
mode: type | perm,
|
|
@@ -11393,11 +11887,7 @@ function statView(st) {
|
|
|
11393
11887
|
atimeMs,
|
|
11394
11888
|
mtimeMs,
|
|
11395
11889
|
ctimeMs,
|
|
11396
|
-
birthtimeMs: ctimeMs
|
|
11397
|
-
atime: new Date(atimeMs),
|
|
11398
|
-
mtime: new Date(mtimeMs),
|
|
11399
|
-
ctime: new Date(ctimeMs),
|
|
11400
|
-
birthtime: new Date(ctimeMs)
|
|
11890
|
+
birthtimeMs: ctimeMs
|
|
11401
11891
|
});
|
|
11402
11892
|
}
|
|
11403
11893
|
var Dirent = class {
|
|
@@ -11439,12 +11929,46 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
11439
11929
|
const wrapBuffer = (bytes) => Buffer2 ? Buffer2.from(bytes) : bytes;
|
|
11440
11930
|
const optEncoding = (options) => typeof options === "string" ? options : options?.encoding ?? null;
|
|
11441
11931
|
const optFlag = (options, fallback) => options && typeof options === "object" && options.flag || fallback;
|
|
11932
|
+
const ENCODINGS = /* @__PURE__ */ new Set([
|
|
11933
|
+
"utf8",
|
|
11934
|
+
"utf-8",
|
|
11935
|
+
"ucs2",
|
|
11936
|
+
"ucs-2",
|
|
11937
|
+
"utf16le",
|
|
11938
|
+
"utf-16le",
|
|
11939
|
+
"latin1",
|
|
11940
|
+
"binary",
|
|
11941
|
+
"base64",
|
|
11942
|
+
"base64url",
|
|
11943
|
+
"hex",
|
|
11944
|
+
"ascii",
|
|
11945
|
+
"buffer"
|
|
11946
|
+
]);
|
|
11947
|
+
const checkEncoding = (encoding) => {
|
|
11948
|
+
if (encoding == null || ENCODINGS.has(String(encoding).toLowerCase())) return;
|
|
11949
|
+
const err = new TypeError(`The argument 'encoding' is invalid encoding. Received '${encoding}'`);
|
|
11950
|
+
err.code = "ERR_INVALID_ARG_VALUE";
|
|
11951
|
+
throw err;
|
|
11952
|
+
};
|
|
11442
11953
|
const decodeAs = (bytes, encoding) => {
|
|
11443
|
-
|
|
11444
|
-
if (encoding
|
|
11445
|
-
|
|
11954
|
+
checkEncoding(encoding);
|
|
11955
|
+
if (!encoding) return wrapBuffer(bytes);
|
|
11956
|
+
const enc = String(encoding).toLowerCase();
|
|
11957
|
+
if (enc === "buffer") {
|
|
11958
|
+
const err = new TypeError("Unknown encoding: buffer");
|
|
11959
|
+
err.code = "ERR_UNKNOWN_ENCODING";
|
|
11960
|
+
throw err;
|
|
11961
|
+
}
|
|
11962
|
+
if (enc === "utf8" || enc === "utf-8") return decoder3.decode(bytes);
|
|
11963
|
+
if (enc === "ascii") {
|
|
11964
|
+
let out = "";
|
|
11965
|
+
for (let i2 = 0; i2 < bytes.length; i2++) out += String.fromCharCode(bytes[i2] & 127);
|
|
11966
|
+
return out;
|
|
11967
|
+
}
|
|
11968
|
+
return Buffer2 ? Buffer2.from(bytes).toString(enc) : decoder3.decode(bytes);
|
|
11446
11969
|
};
|
|
11447
11970
|
const encodeAs = (data2, encoding) => {
|
|
11971
|
+
checkEncoding(encoding);
|
|
11448
11972
|
if (typeof data2 === "string" && encoding && encoding !== "utf8" && encoding !== "utf-8" && Buffer2) {
|
|
11449
11973
|
const b = Buffer2.from(data2, encoding);
|
|
11450
11974
|
return new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
|
|
@@ -11615,9 +12139,17 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
11615
12139
|
}
|
|
11616
12140
|
return;
|
|
11617
12141
|
}
|
|
12142
|
+
const given = [];
|
|
12143
|
+
for (let cur2 = String(p); ; ) {
|
|
12144
|
+
given.unshift(cur2);
|
|
12145
|
+
const up = path.dirname(cur2);
|
|
12146
|
+
if (up === cur2) break;
|
|
12147
|
+
cur2 = up;
|
|
12148
|
+
}
|
|
11618
12149
|
const parts = String(target).split("/").filter(Boolean);
|
|
11619
12150
|
let cur = "";
|
|
11620
12151
|
let first;
|
|
12152
|
+
let firstAbs;
|
|
11621
12153
|
for (const part of parts) {
|
|
11622
12154
|
cur += `/${part}`;
|
|
11623
12155
|
if (syncFs.exists(cur)) {
|
|
@@ -11632,12 +12164,15 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
11632
12164
|
}
|
|
11633
12165
|
try {
|
|
11634
12166
|
syncFs.mkdir(cur);
|
|
11635
|
-
|
|
12167
|
+
firstAbs ??= cur;
|
|
11636
12168
|
} catch (err) {
|
|
11637
12169
|
if (err?.code === "EEXIST") continue;
|
|
11638
12170
|
throw nodeFsError(err?.code || "EIO", "mkdir", pathArg, err);
|
|
11639
12171
|
}
|
|
11640
12172
|
}
|
|
12173
|
+
if (firstAbs !== void 0) {
|
|
12174
|
+
first = given.find((g) => abs(g) === firstAbs) ?? firstAbs;
|
|
12175
|
+
}
|
|
11641
12176
|
return first;
|
|
11642
12177
|
}
|
|
11643
12178
|
const typeAt = (full) => {
|
|
@@ -11657,11 +12192,14 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
11657
12192
|
}
|
|
11658
12193
|
if (!ok) throw nodeFsError("ENOENT", syscall, p);
|
|
11659
12194
|
}
|
|
11660
|
-
|
|
12195
|
+
const MAX_LINK_DEPTH = 40;
|
|
12196
|
+
function readdirSync(p, options, { followLinks = true } = {}) {
|
|
11661
12197
|
const pathArg = p;
|
|
11662
12198
|
const target = abs(p);
|
|
11663
12199
|
const encoding = optEncoding(options);
|
|
12200
|
+
checkEncoding(encoding);
|
|
11664
12201
|
const asName = (name) => encoding === "buffer" ? wrapBuffer(encoder3.encode(name)) : name;
|
|
12202
|
+
const dirent = (name, type, parent) => new Dirent(asName(name), type, parent);
|
|
11665
12203
|
let names;
|
|
11666
12204
|
try {
|
|
11667
12205
|
names = syncFs.readdir(target);
|
|
@@ -11670,32 +12208,40 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
11670
12208
|
}
|
|
11671
12209
|
if (!options?.recursive) {
|
|
11672
12210
|
if (options?.withFileTypes) {
|
|
11673
|
-
return names.map((name) =>
|
|
12211
|
+
return names.map((name) => dirent(name, typeAt(path.join(target, name)), String(pathArg)));
|
|
11674
12212
|
}
|
|
11675
12213
|
return names.map(asName);
|
|
11676
12214
|
}
|
|
11677
12215
|
const out = [];
|
|
11678
|
-
const queue = [{ dir: target, rel: "", parent: String(pathArg), names }];
|
|
12216
|
+
const queue = [{ dir: target, rel: "", parent: String(pathArg), names, links: 0 }];
|
|
11679
12217
|
while (queue.length) {
|
|
11680
|
-
const { dir, rel, parent, names: entries } = queue.shift();
|
|
12218
|
+
const { dir, rel, parent, names: entries, links } = queue.shift();
|
|
11681
12219
|
for (const name of entries) {
|
|
11682
12220
|
const full = path.join(dir, name);
|
|
11683
12221
|
const type = typeAt(full);
|
|
11684
|
-
out.push(options.withFileTypes ?
|
|
11685
|
-
|
|
11686
|
-
|
|
12222
|
+
out.push(options.withFileTypes ? dirent(name, type, parent) : asName(rel ? `${rel}/${name}` : name));
|
|
12223
|
+
let descend = type === "dir";
|
|
12224
|
+
if (followLinks && type === "link" && links < MAX_LINK_DEPTH) {
|
|
11687
12225
|
try {
|
|
11688
|
-
|
|
12226
|
+
descend = !!syncFs.stat(full).isDirectory;
|
|
11689
12227
|
} catch {
|
|
11690
|
-
|
|
12228
|
+
descend = false;
|
|
11691
12229
|
}
|
|
11692
|
-
queue.push({
|
|
11693
|
-
dir: full,
|
|
11694
|
-
rel: rel ? `${rel}/${name}` : name,
|
|
11695
|
-
parent: path.join(parent, name),
|
|
11696
|
-
names: children
|
|
11697
|
-
});
|
|
11698
12230
|
}
|
|
12231
|
+
if (!descend) continue;
|
|
12232
|
+
let children;
|
|
12233
|
+
try {
|
|
12234
|
+
children = syncFs.readdir(full);
|
|
12235
|
+
} catch {
|
|
12236
|
+
continue;
|
|
12237
|
+
}
|
|
12238
|
+
queue.push({
|
|
12239
|
+
dir: full,
|
|
12240
|
+
rel: rel ? `${rel}/${name}` : name,
|
|
12241
|
+
parent: path.join(parent, name),
|
|
12242
|
+
names: children,
|
|
12243
|
+
links: links + (type === "link" ? 1 : 0)
|
|
12244
|
+
});
|
|
11699
12245
|
}
|
|
11700
12246
|
}
|
|
11701
12247
|
return out;
|
|
@@ -11703,6 +12249,7 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
11703
12249
|
const syncApi = {
|
|
11704
12250
|
readFileSync(p, options) {
|
|
11705
12251
|
const encoding = optEncoding(options);
|
|
12252
|
+
checkEncoding(encoding);
|
|
11706
12253
|
if (p === 0 || p === "0") return readStdinSync(encoding);
|
|
11707
12254
|
if (typeof p === "number") {
|
|
11708
12255
|
const ent = fdTable.get(p);
|
|
@@ -11726,13 +12273,13 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
11726
12273
|
if (st.isDirectory) {
|
|
11727
12274
|
const e = new Error("EISDIR: illegal operation on a directory, read");
|
|
11728
12275
|
e.code = "EISDIR";
|
|
11729
|
-
e.errno =
|
|
12276
|
+
e.errno = ERRNO2.EISDIR;
|
|
11730
12277
|
e.syscall = "read";
|
|
11731
12278
|
throw e;
|
|
11732
12279
|
}
|
|
11733
12280
|
return decodeAs(syncFs.readFile(target), encoding);
|
|
11734
12281
|
} catch (err) {
|
|
11735
|
-
if (err?.code && err.syscall) throw err;
|
|
12282
|
+
if (err?.code && err.syscall || String(err?.code).startsWith("ERR_")) throw err;
|
|
11736
12283
|
throw nodeFsError(err?.code || "ENOENT", "open", pathArg, err);
|
|
11737
12284
|
}
|
|
11738
12285
|
},
|
|
@@ -11750,6 +12297,23 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
11750
12297
|
const pathArg = p;
|
|
11751
12298
|
const target = abs(p);
|
|
11752
12299
|
if (flag.includes("x") && syncFs.exists(target)) throw nodeFsError("EEXIST", "open", pathArg);
|
|
12300
|
+
if (flag.startsWith("r")) {
|
|
12301
|
+
let cur;
|
|
12302
|
+
try {
|
|
12303
|
+
cur = syncFs.readFile(target);
|
|
12304
|
+
} catch (err) {
|
|
12305
|
+
throw nodeFsError(err?.code || "ENOENT", "open", pathArg, err);
|
|
12306
|
+
}
|
|
12307
|
+
const out = new Uint8Array(Math.max(cur.length, bytes.length));
|
|
12308
|
+
out.set(cur, 0);
|
|
12309
|
+
out.set(bytes, 0);
|
|
12310
|
+
try {
|
|
12311
|
+
syncFs.writeFile(target, out);
|
|
12312
|
+
} catch (err) {
|
|
12313
|
+
throw nodeFsError(err?.code || "EIO", "write", pathArg, err);
|
|
12314
|
+
}
|
|
12315
|
+
return;
|
|
12316
|
+
}
|
|
11753
12317
|
try {
|
|
11754
12318
|
syncFs.writeFile(target, bytes);
|
|
11755
12319
|
} catch (err) {
|
|
@@ -11758,6 +12322,11 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
11758
12322
|
},
|
|
11759
12323
|
appendFileSync(p, data2, options) {
|
|
11760
12324
|
const next = encodeAs(data2, optEncoding(options));
|
|
12325
|
+
const flag = optFlag(options, "a");
|
|
12326
|
+
if (!flag.includes("a")) {
|
|
12327
|
+
syncApi.writeFileSync(p, next, { flag });
|
|
12328
|
+
return;
|
|
12329
|
+
}
|
|
11761
12330
|
if (typeof p === "number") {
|
|
11762
12331
|
const ent = fdTable.get(p);
|
|
11763
12332
|
let end = null;
|
|
@@ -11805,7 +12374,7 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
11805
12374
|
statSync(p, options) {
|
|
11806
12375
|
const pathArg = p;
|
|
11807
12376
|
try {
|
|
11808
|
-
return statView(syncFs.stat(abs(p)));
|
|
12377
|
+
return statView(syncFs.stat(abs(p)), options?.bigint === true);
|
|
11809
12378
|
} catch (err) {
|
|
11810
12379
|
const code = err?.code || "ENOENT";
|
|
11811
12380
|
if (options?.throwIfNoEntry === false && (code === "ENOENT" || code === "ENOTDIR")) return void 0;
|
|
@@ -11815,27 +12384,17 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
11815
12384
|
lstatSync(p, options) {
|
|
11816
12385
|
const pathArg = p;
|
|
11817
12386
|
try {
|
|
11818
|
-
return statView(syncFs.lstat(abs(p)));
|
|
12387
|
+
return statView(syncFs.lstat(abs(p)), options?.bigint === true);
|
|
11819
12388
|
} catch (err) {
|
|
11820
12389
|
const code = err?.code || "ENOENT";
|
|
11821
12390
|
if (options?.throwIfNoEntry === false && (code === "ENOENT" || code === "ENOTDIR")) return void 0;
|
|
11822
12391
|
throw nodeFsError(code, "lstat", pathArg, err);
|
|
11823
12392
|
}
|
|
11824
12393
|
},
|
|
11825
|
-
/**
|
|
11826
|
-
|
|
11827
|
-
|
|
11828
|
-
|
|
11829
|
-
*/
|
|
11830
|
-
realpathSync(p) {
|
|
11831
|
-
const pathArg = p;
|
|
11832
|
-
const target = abs(p);
|
|
11833
|
-
try {
|
|
11834
|
-
syncFs.stat(target);
|
|
11835
|
-
return target;
|
|
11836
|
-
} catch (err) {
|
|
11837
|
-
throw nodeFsError(err?.code || "ENOENT", "realpath", pathArg, err);
|
|
11838
|
-
}
|
|
12394
|
+
/** Node's JS realpath: every symlink along the path resolved. */
|
|
12395
|
+
realpathSync(p, options) {
|
|
12396
|
+
const real = getCp().realpathSync(abs(p));
|
|
12397
|
+
return optEncoding(options) === "buffer" ? wrapBuffer(encoder3.encode(real)) : real;
|
|
11839
12398
|
},
|
|
11840
12399
|
readdirSync,
|
|
11841
12400
|
mkdirSync,
|
|
@@ -11991,11 +12550,11 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
11991
12550
|
throw nodeFsError(err?.code || "EIO", "write", ent.path, err);
|
|
11992
12551
|
}
|
|
11993
12552
|
},
|
|
11994
|
-
fstatSync(fd) {
|
|
12553
|
+
fstatSync(fd, options) {
|
|
11995
12554
|
const ent = fdTable.get(fd);
|
|
11996
12555
|
if (!ent) throw nodeFsError("EBADF", "fstat", void 0);
|
|
11997
12556
|
try {
|
|
11998
|
-
return statView(syncFs.stat(ent.path));
|
|
12557
|
+
return statView(syncFs.stat(ent.path), options?.bigint === true);
|
|
11999
12558
|
} catch (err) {
|
|
12000
12559
|
throw nodeFsError(err?.code || "EIO", "fstat", ent.path, err);
|
|
12001
12560
|
}
|
|
@@ -12026,7 +12585,7 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
12026
12585
|
try {
|
|
12027
12586
|
syncFs.symlink(target, abs(p));
|
|
12028
12587
|
} catch (err) {
|
|
12029
|
-
throw nodeFsError(err?.code || "EIO", "symlink",
|
|
12588
|
+
throw nodeFsError(err?.code || "EIO", "symlink", target, err, p);
|
|
12030
12589
|
}
|
|
12031
12590
|
},
|
|
12032
12591
|
readlinkSync(p) {
|
|
@@ -12037,6 +12596,17 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
12037
12596
|
}
|
|
12038
12597
|
},
|
|
12039
12598
|
copyFileSync(src, dest, mode = 0) {
|
|
12599
|
+
if (mode == null) mode = 0;
|
|
12600
|
+
if (typeof mode !== "number" || !Number.isInteger(mode)) {
|
|
12601
|
+
const err = new TypeError("mode must be int32 or null/undefined");
|
|
12602
|
+
err.code = "ERR_INVALID_ARG_TYPE";
|
|
12603
|
+
throw err;
|
|
12604
|
+
}
|
|
12605
|
+
if (mode < 0 || mode > 7) {
|
|
12606
|
+
const err = new RangeError("mode is out of range: >= 0 && <= 7");
|
|
12607
|
+
err.code = "ERR_OUT_OF_RANGE";
|
|
12608
|
+
throw err;
|
|
12609
|
+
}
|
|
12040
12610
|
const from = abs(src);
|
|
12041
12611
|
const to = abs(dest);
|
|
12042
12612
|
let st;
|
|
@@ -12053,42 +12623,10 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
12053
12623
|
throw nodeFsError(err?.code || "EIO", "copyfile", src, err, dest);
|
|
12054
12624
|
}
|
|
12055
12625
|
},
|
|
12056
|
-
cpSync(src, dest, options
|
|
12057
|
-
|
|
12058
|
-
const to = abs(dest);
|
|
12059
|
-
if (from === to) throw cpInvalid(`src and dest cannot be the same ${src}`);
|
|
12060
|
-
if (to.startsWith(`${from}/`)) {
|
|
12061
|
-
throw cpInvalid(`Cannot copy ${src}/ to a subdirectory of self ${dest}`);
|
|
12062
|
-
}
|
|
12063
|
-
let st;
|
|
12064
|
-
try {
|
|
12065
|
-
st = syncFs.stat(from);
|
|
12066
|
-
} catch (err) {
|
|
12067
|
-
throw nodeFsError(err?.code || "ENOENT", "cp", src, err);
|
|
12068
|
-
}
|
|
12069
|
-
if (st.isDirectory) {
|
|
12070
|
-
if (!options?.recursive) {
|
|
12071
|
-
const e = new Error(`Recursive option not enabled, cannot copy a directory: ${src}/`);
|
|
12072
|
-
e.code = "ERR_FS_EISDIR";
|
|
12073
|
-
throw e;
|
|
12074
|
-
}
|
|
12075
|
-
mkdirSync(to, { recursive: true });
|
|
12076
|
-
for (const name of syncFs.readdir(from)) {
|
|
12077
|
-
syncApi.cpSync(path.join(from, name), path.join(to, name), options);
|
|
12078
|
-
}
|
|
12079
|
-
return;
|
|
12080
|
-
}
|
|
12081
|
-
const exists = syncFs.exists(to);
|
|
12082
|
-
if (exists && options?.errorOnExist && options?.force === false) {
|
|
12083
|
-
const e = new Error(`Target already exists: cp returned EEXIST (${to} already exists)`);
|
|
12084
|
-
e.name = "SystemError";
|
|
12085
|
-
e.code = "ERR_FS_CP_EEXIST";
|
|
12086
|
-
throw e;
|
|
12087
|
-
}
|
|
12088
|
-
if (exists && options?.force === false) return;
|
|
12089
|
-
syncFs.writeFile(to, syncFs.readFile(from));
|
|
12626
|
+
cpSync(src, dest, options) {
|
|
12627
|
+
getCp().cpSync(src, dest, options);
|
|
12090
12628
|
},
|
|
12091
|
-
mkdtempSync(prefix, options) {
|
|
12629
|
+
mkdtempSync(prefix, options, { namedError = false } = {}) {
|
|
12092
12630
|
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
12093
12631
|
const bytes = new Uint8Array(6);
|
|
12094
12632
|
for (let attempt = 0; attempt < 100; attempt++) {
|
|
@@ -12096,6 +12634,14 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
12096
12634
|
const name = `${prefix}${[...bytes].map((b) => chars[b % chars.length]).join("")}`;
|
|
12097
12635
|
const target = abs(name);
|
|
12098
12636
|
if (syncFs.exists(target)) continue;
|
|
12637
|
+
const parent = path.dirname(target);
|
|
12638
|
+
let parentOk = false;
|
|
12639
|
+
try {
|
|
12640
|
+
parentOk = !!syncFs.stat(parent).isDirectory;
|
|
12641
|
+
} catch {
|
|
12642
|
+
parentOk = false;
|
|
12643
|
+
}
|
|
12644
|
+
if (!parentOk) throw nodeFsError("ENOENT", "mkdtemp", namedError ? name : `${prefix}XXXXXX`);
|
|
12099
12645
|
try {
|
|
12100
12646
|
syncFs.mkdir(target);
|
|
12101
12647
|
} catch (err) {
|
|
@@ -12156,11 +12702,51 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
12156
12702
|
fdatasyncSync(fd) {
|
|
12157
12703
|
if (fd !== 0 && fd !== 1 && fd !== 2 && !fdTable.has(fd)) throw nodeFsError("EBADF", "fdatasync", void 0);
|
|
12158
12704
|
},
|
|
12159
|
-
opendirSync(p) {
|
|
12160
|
-
|
|
12705
|
+
opendirSync(p, options) {
|
|
12706
|
+
let entries;
|
|
12707
|
+
try {
|
|
12708
|
+
entries = readdirSync(p, { withFileTypes: true, recursive: options?.recursive === true }, { followLinks: false });
|
|
12709
|
+
} catch (err) {
|
|
12710
|
+
throw nodeFsError(err?.code || "ENOENT", "opendir", void 0, err);
|
|
12711
|
+
}
|
|
12161
12712
|
return createDir(String(p), entries);
|
|
12713
|
+
},
|
|
12714
|
+
linkSync(existingPath, newPath) {
|
|
12715
|
+
try {
|
|
12716
|
+
syncFs.link(abs(existingPath), abs(newPath));
|
|
12717
|
+
} catch (err) {
|
|
12718
|
+
throw nodeFsError(err?.code || "EIO", "link", existingPath, err, newPath);
|
|
12719
|
+
}
|
|
12162
12720
|
}
|
|
12163
12721
|
};
|
|
12722
|
+
let cpImpl;
|
|
12723
|
+
function getCp() {
|
|
12724
|
+
cpImpl ??= createCp({
|
|
12725
|
+
path,
|
|
12726
|
+
abs,
|
|
12727
|
+
fsError: nodeFsError,
|
|
12728
|
+
copyFileSync: (src, dest, mode) => syncApi.copyFileSync(src, dest, mode),
|
|
12729
|
+
mkdirpSync: (p) => mkdirSync(p, { recursive: true }),
|
|
12730
|
+
ops: {
|
|
12731
|
+
lstat: (p) => syncFs.lstat(p),
|
|
12732
|
+
stat: (p) => syncFs.stat(p),
|
|
12733
|
+
readlink: (p) => syncFs.readlink(p),
|
|
12734
|
+
symlink: (target, p) => syncFs.symlink(target, p),
|
|
12735
|
+
readdir: (p) => syncFs.readdir(p),
|
|
12736
|
+
mkdir: (p) => syncFs.mkdir(p),
|
|
12737
|
+
unlink: (p) => syncFs.unlink(p)
|
|
12738
|
+
}
|
|
12739
|
+
});
|
|
12740
|
+
return cpImpl;
|
|
12741
|
+
}
|
|
12742
|
+
function realpathNative(p, options) {
|
|
12743
|
+
try {
|
|
12744
|
+
return syncApi.realpathSync(p, options);
|
|
12745
|
+
} catch (err) {
|
|
12746
|
+
throw nodeFsError(err?.code || "ENOENT", "realpath", p, err);
|
|
12747
|
+
}
|
|
12748
|
+
}
|
|
12749
|
+
syncApi.realpathSync.native = realpathNative;
|
|
12164
12750
|
function createDir(dirPath, entries) {
|
|
12165
12751
|
let closed = false;
|
|
12166
12752
|
const next = () => {
|
|
@@ -12188,13 +12774,24 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
12188
12774
|
return Promise.resolve().then(next);
|
|
12189
12775
|
},
|
|
12190
12776
|
closeSync() {
|
|
12777
|
+
if (closed) next();
|
|
12191
12778
|
closed = true;
|
|
12192
12779
|
},
|
|
12193
12780
|
close(cb) {
|
|
12781
|
+
let err = null;
|
|
12782
|
+
if (closed) {
|
|
12783
|
+
try {
|
|
12784
|
+
next();
|
|
12785
|
+
} catch (e) {
|
|
12786
|
+
err = e;
|
|
12787
|
+
}
|
|
12788
|
+
}
|
|
12194
12789
|
closed = true;
|
|
12195
|
-
if (typeof cb === "function")
|
|
12196
|
-
|
|
12197
|
-
|
|
12790
|
+
if (typeof cb === "function") {
|
|
12791
|
+
queueMicrotask(() => cb(err));
|
|
12792
|
+
return void 0;
|
|
12793
|
+
}
|
|
12794
|
+
return err ? Promise.reject(err) : Promise.resolve();
|
|
12198
12795
|
},
|
|
12199
12796
|
async *[Symbol.asyncIterator]() {
|
|
12200
12797
|
try {
|
|
@@ -12247,61 +12844,54 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
12247
12844
|
return track(
|
|
12248
12845
|
(async () => {
|
|
12249
12846
|
const encoding = optEncoding(options);
|
|
12847
|
+
checkEncoding(encoding);
|
|
12250
12848
|
try {
|
|
12251
12849
|
return decodeAs(await asyncFs.readFile(abs(p)), encoding);
|
|
12252
12850
|
} catch (err) {
|
|
12851
|
+
if (String(err?.code).startsWith("ERR_")) throw err;
|
|
12253
12852
|
throw nodeFsError(err?.code || "ENOENT", "open", p, err);
|
|
12254
12853
|
}
|
|
12255
12854
|
})()
|
|
12256
12855
|
);
|
|
12257
12856
|
},
|
|
12857
|
+
// The write happens when the call is made, as Node's open does in call
|
|
12858
|
+
// order: a later `flag: 'wx'` sees the file an earlier writeFile made.
|
|
12258
12859
|
writeFile(p, data2, options) {
|
|
12259
|
-
|
|
12260
|
-
|
|
12261
|
-
|
|
12262
|
-
|
|
12263
|
-
|
|
12264
|
-
|
|
12265
|
-
|
|
12266
|
-
|
|
12267
|
-
await asyncFs.writeFile(target, bytes);
|
|
12268
|
-
} catch (err) {
|
|
12269
|
-
throw nodeFsError(err?.code || "EIO", "open", p, err);
|
|
12270
|
-
}
|
|
12271
|
-
return void 0;
|
|
12272
|
-
})()
|
|
12273
|
-
);
|
|
12860
|
+
let result;
|
|
12861
|
+
try {
|
|
12862
|
+
syncApi.writeFileSync(p, data2, options);
|
|
12863
|
+
result = Promise.resolve();
|
|
12864
|
+
} catch (err) {
|
|
12865
|
+
result = Promise.reject(err);
|
|
12866
|
+
}
|
|
12867
|
+
return track(result);
|
|
12274
12868
|
},
|
|
12275
12869
|
appendFile(p, data2, options) {
|
|
12276
|
-
|
|
12277
|
-
|
|
12278
|
-
|
|
12279
|
-
|
|
12280
|
-
|
|
12281
|
-
|
|
12282
|
-
|
|
12283
|
-
|
|
12284
|
-
merged.set(next, prev.length);
|
|
12285
|
-
await asyncFs.writeFile(target, merged);
|
|
12286
|
-
})()
|
|
12287
|
-
);
|
|
12870
|
+
let result;
|
|
12871
|
+
try {
|
|
12872
|
+
syncApi.appendFileSync(p, data2, options);
|
|
12873
|
+
result = Promise.resolve();
|
|
12874
|
+
} catch (err) {
|
|
12875
|
+
result = Promise.reject(err);
|
|
12876
|
+
}
|
|
12877
|
+
return track(result);
|
|
12288
12878
|
},
|
|
12289
|
-
stat(p) {
|
|
12879
|
+
stat(p, options) {
|
|
12290
12880
|
return track(
|
|
12291
12881
|
(async () => {
|
|
12292
12882
|
try {
|
|
12293
|
-
return statView(await asyncFs.stat(abs(p)));
|
|
12883
|
+
return statView(await asyncFs.stat(abs(p)), options?.bigint === true);
|
|
12294
12884
|
} catch (err) {
|
|
12295
12885
|
throw nodeFsError(err?.code || "ENOENT", "stat", p, err);
|
|
12296
12886
|
}
|
|
12297
12887
|
})()
|
|
12298
12888
|
);
|
|
12299
12889
|
},
|
|
12300
|
-
lstat(p) {
|
|
12890
|
+
lstat(p, options) {
|
|
12301
12891
|
return track(
|
|
12302
12892
|
(async () => {
|
|
12303
12893
|
try {
|
|
12304
|
-
return statView(await asyncFs.lstat(abs(p)));
|
|
12894
|
+
return statView(await asyncFs.lstat(abs(p)), options?.bigint === true);
|
|
12305
12895
|
} catch (err) {
|
|
12306
12896
|
throw nodeFsError(err?.code || "ENOENT", "lstat", p, err);
|
|
12307
12897
|
}
|
|
@@ -12309,7 +12899,7 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
12309
12899
|
);
|
|
12310
12900
|
},
|
|
12311
12901
|
readdir(p, options) {
|
|
12312
|
-
return track((async () => readdirSync(p, options))());
|
|
12902
|
+
return track((async () => readdirSync(p, options, { followLinks: !options?.withFileTypes }))());
|
|
12313
12903
|
},
|
|
12314
12904
|
mkdir(p, options = {}) {
|
|
12315
12905
|
return track((async () => mkdirSync(p, options))());
|
|
@@ -12324,16 +12914,19 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
12324
12914
|
return track((async () => syncApi.copyFileSync(src, dest, mode))());
|
|
12325
12915
|
},
|
|
12326
12916
|
cp(src, dest, options) {
|
|
12327
|
-
return track((
|
|
12917
|
+
return track(getCp().cp(src, dest, options));
|
|
12918
|
+
},
|
|
12919
|
+
link(existingPath, newPath) {
|
|
12920
|
+
return track((async () => syncApi.linkSync(existingPath, newPath))());
|
|
12328
12921
|
},
|
|
12329
12922
|
mkdtemp(prefix, options) {
|
|
12330
|
-
return track((async () => syncApi.mkdtempSync(prefix, options))());
|
|
12923
|
+
return track((async () => syncApi.mkdtempSync(prefix, options, { namedError: true }))());
|
|
12331
12924
|
},
|
|
12332
12925
|
truncate(p, len) {
|
|
12333
12926
|
return track((async () => syncApi.truncateSync(p, len))());
|
|
12334
12927
|
},
|
|
12335
|
-
realpath(p) {
|
|
12336
|
-
return track((async () =>
|
|
12928
|
+
realpath(p, options) {
|
|
12929
|
+
return track((async () => realpathNative(p, options))());
|
|
12337
12930
|
},
|
|
12338
12931
|
chmod(p) {
|
|
12339
12932
|
return track((async () => syncApi.chmodSync(p))());
|
|
@@ -12353,8 +12946,8 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
12353
12946
|
lutimes(p) {
|
|
12354
12947
|
return track((async () => syncApi.lutimesSync(p))());
|
|
12355
12948
|
},
|
|
12356
|
-
opendir(p) {
|
|
12357
|
-
return track((async () => syncApi.opendirSync(p))());
|
|
12949
|
+
opendir(p, options) {
|
|
12950
|
+
return track((async () => syncApi.opendirSync(p, options))());
|
|
12358
12951
|
},
|
|
12359
12952
|
unlink(p) {
|
|
12360
12953
|
return track(
|
|
@@ -12676,7 +13269,9 @@ function createFs({ ctx, path, process: process2, Buffer: Buffer2, handles, getS
|
|
|
12676
13269
|
access: callbackify(syncApi.accessSync),
|
|
12677
13270
|
stat: callbackify(syncApi.statSync),
|
|
12678
13271
|
lstat: callbackify(syncApi.lstatSync),
|
|
12679
|
-
realpath: callbackify(syncApi.realpathSync),
|
|
13272
|
+
realpath: Object.assign(callbackify(syncApi.realpathSync), {
|
|
13273
|
+
native: callbackify(realpathNative)
|
|
13274
|
+
}),
|
|
12680
13275
|
readdir: callbackify(syncApi.readdirSync),
|
|
12681
13276
|
mkdir: callbackify(syncApi.mkdirSync, { minArgsBeforeCb: 2 }),
|
|
12682
13277
|
rmdir: callbackify(syncApi.rmdirSync),
|
|
@@ -12708,7 +13303,16 @@ ${e.stack}
|
|
|
12708
13303
|
return void 0;
|
|
12709
13304
|
},
|
|
12710
13305
|
copyFile: callbackify(syncApi.copyFileSync, { minArgsBeforeCb: 2 }),
|
|
12711
|
-
cp
|
|
13306
|
+
cp(src, dest, options, callback) {
|
|
13307
|
+
const cb = typeof options === "function" ? options : callback;
|
|
13308
|
+
const opts = typeof options === "function" ? void 0 : options;
|
|
13309
|
+
requireCallback(cb);
|
|
13310
|
+
track(getCp().cp(src, dest, opts)).then(
|
|
13311
|
+
() => cb(null),
|
|
13312
|
+
(err) => cb(err)
|
|
13313
|
+
);
|
|
13314
|
+
},
|
|
13315
|
+
link: callbackify(syncApi.linkSync, { minArgsBeforeCb: 2 }),
|
|
12712
13316
|
mkdtemp: callbackify(syncApi.mkdtempSync),
|
|
12713
13317
|
truncate: callbackify(syncApi.truncateSync),
|
|
12714
13318
|
ftruncate: callbackify(syncApi.ftruncateSync),
|
|
@@ -14628,9 +15232,17 @@ function fileURLToPath(url) {
|
|
|
14628
15232
|
}
|
|
14629
15233
|
return decodeURIComponent(parsed.pathname);
|
|
14630
15234
|
}
|
|
15235
|
+
var FILE_URL_SAFE = /[A-Za-z0-9\-._/!$&'()*+,;=:@]/;
|
|
15236
|
+
function encodeFilePath(path) {
|
|
15237
|
+
let out = "";
|
|
15238
|
+
for (const ch of path) {
|
|
15239
|
+
if (FILE_URL_SAFE.test(ch)) out += ch;
|
|
15240
|
+
else for (const b of new TextEncoder().encode(ch)) out += `%${b.toString(16).toUpperCase().padStart(2, "0")}`;
|
|
15241
|
+
}
|
|
15242
|
+
return out;
|
|
15243
|
+
}
|
|
14631
15244
|
function pathToFileURL(path) {
|
|
14632
|
-
|
|
14633
|
-
return new URL(`file://${encoded}`);
|
|
15245
|
+
return new URL(`file://${encodeFilePath(path)}`);
|
|
14634
15246
|
}
|
|
14635
15247
|
function parse5(urlStr, parseQueryString = false, slashesDenoteHost = false) {
|
|
14636
15248
|
void slashesDenoteHost;
|
|
@@ -14948,8 +15560,19 @@ function createResolver({
|
|
|
14948
15560
|
path,
|
|
14949
15561
|
readPackageJson,
|
|
14950
15562
|
conditions = REQUIRE_CONDITIONS,
|
|
14951
|
-
extensions = DEFAULT_EXTENSIONS
|
|
15563
|
+
extensions = DEFAULT_EXTENSIONS,
|
|
15564
|
+
preserveSymlinks: preserveSymlinks2 = false
|
|
14952
15565
|
} = {}) {
|
|
15566
|
+
const real = (filename) => {
|
|
15567
|
+
if (preserveSymlinks2 || typeof fs.lstat !== "function" || typeof fs.readlink !== "function") {
|
|
15568
|
+
return filename;
|
|
15569
|
+
}
|
|
15570
|
+
try {
|
|
15571
|
+
return realpathWith(fs, path, filename, (code) => Object.assign(new Error(code), { code }));
|
|
15572
|
+
} catch {
|
|
15573
|
+
return filename;
|
|
15574
|
+
}
|
|
15575
|
+
};
|
|
14953
15576
|
const tryStat = (p) => {
|
|
14954
15577
|
try {
|
|
14955
15578
|
if (!fs.exists(p)) return null;
|
|
@@ -15155,17 +15778,17 @@ function createResolver({
|
|
|
15155
15778
|
const fromDir = parentFilename.endsWith("/") || tryStat(parentFilename)?.isDirectory ? parentFilename : path.dirname(parentFilename);
|
|
15156
15779
|
if (request.startsWith("#")) {
|
|
15157
15780
|
const hit = packageImportsResolve(request, parentFilename);
|
|
15158
|
-
if (hit) return { type: "file", filename: hit };
|
|
15781
|
+
if (hit) return { type: "file", filename: real(hit) };
|
|
15159
15782
|
throw moduleNotFound(request, stack);
|
|
15160
15783
|
}
|
|
15161
15784
|
if (request.startsWith("/") || request.startsWith("./") || request.startsWith("../")) {
|
|
15162
15785
|
const abs = path.resolve(fromDir, request);
|
|
15163
15786
|
const hit = loadAsFileOrDir(abs);
|
|
15164
|
-
if (hit) return { type: "file", filename: hit };
|
|
15787
|
+
if (hit) return { type: "file", filename: real(hit) };
|
|
15165
15788
|
throw moduleNotFound(request, stack);
|
|
15166
15789
|
}
|
|
15167
15790
|
const nm = loadNodeModules(request, fromDir);
|
|
15168
|
-
if (nm) return { type: "file", filename: nm };
|
|
15791
|
+
if (nm) return { type: "file", filename: real(nm) };
|
|
15169
15792
|
throw moduleNotFound(request, stack);
|
|
15170
15793
|
}
|
|
15171
15794
|
return { resolve: resolve2, tryFile, loadAsDirectory };
|
|
@@ -15215,6 +15838,18 @@ function isBuiltinName(name) {
|
|
|
15215
15838
|
|
|
15216
15839
|
// src/runtime/cjs/loader.mjs
|
|
15217
15840
|
var decoder5 = new TextDecoder();
|
|
15841
|
+
function nodeModulePaths(dir) {
|
|
15842
|
+
const parts = dir.split("/").filter(Boolean);
|
|
15843
|
+
const out = [];
|
|
15844
|
+
for (let i2 = parts.length; i2 >= 0; i2--) {
|
|
15845
|
+
if (parts[i2 - 1] === "node_modules") continue;
|
|
15846
|
+
out.push(`/${[...parts.slice(0, i2), "node_modules"].join("/")}`);
|
|
15847
|
+
}
|
|
15848
|
+
return out;
|
|
15849
|
+
}
|
|
15850
|
+
function preserveSymlinks(process2) {
|
|
15851
|
+
return (process2?.execArgv ?? []).includes("--preserve-symlinks") || process2?.env?.NODE_PRESERVE_SYMLINKS === "1";
|
|
15852
|
+
}
|
|
15218
15853
|
function createCjs({
|
|
15219
15854
|
ctx,
|
|
15220
15855
|
process: process2,
|
|
@@ -15240,7 +15875,7 @@ function createCjs({
|
|
|
15240
15875
|
return null;
|
|
15241
15876
|
}
|
|
15242
15877
|
};
|
|
15243
|
-
const resolver = createResolver({ fs, path, readPackageJson });
|
|
15878
|
+
const resolver = createResolver({ fs, path, readPackageJson, preserveSymlinks: preserveSymlinks(process2) });
|
|
15244
15879
|
const builtins = createBuiltins({ ctx, process: process2, Buffer: Buffer2, console: console2, path, handles, timers });
|
|
15245
15880
|
const cache2 = /* @__PURE__ */ Object.create(null);
|
|
15246
15881
|
function Module(id, parent) {
|
|
@@ -15251,9 +15886,10 @@ function createCjs({
|
|
|
15251
15886
|
this.parent = parent ?? null;
|
|
15252
15887
|
this.loaded = false;
|
|
15253
15888
|
this.children = [];
|
|
15254
|
-
this.paths = [];
|
|
15889
|
+
this.paths = id.startsWith("/") ? nodeModulePaths(path.dirname(id)) : [];
|
|
15255
15890
|
}
|
|
15256
15891
|
Module._cache = cache2;
|
|
15892
|
+
Module._nodeModulePaths = (from) => nodeModulePaths(path.resolve(process2.cwd(), String(from)));
|
|
15257
15893
|
Module.builtinModules = [
|
|
15258
15894
|
"assert",
|
|
15259
15895
|
"assert/strict",
|
|
@@ -15556,6 +16192,7 @@ ${err.name}: ${err.message}`;
|
|
|
15556
16192
|
mod.filename = filename;
|
|
15557
16193
|
mod.id = filename === "[stdin]" || filename === "[eval]" ? filename : ".";
|
|
15558
16194
|
mod.path = filename.startsWith("[") ? "." : path.dirname(filename);
|
|
16195
|
+
mod.paths = nodeModulePaths(filename.startsWith("[") ? process2.cwd() : path.dirname(filename));
|
|
15559
16196
|
cache2[filename] = mod;
|
|
15560
16197
|
mainModule = setMain ? mod : void 0;
|
|
15561
16198
|
if (filename.startsWith("[")) {
|
|
@@ -15586,6 +16223,7 @@ function parseNodeArgv(argv) {
|
|
|
15586
16223
|
let print = false;
|
|
15587
16224
|
let script;
|
|
15588
16225
|
const userArgs = [];
|
|
16226
|
+
const flags = [];
|
|
15589
16227
|
let i2 = 0;
|
|
15590
16228
|
while (i2 < args.length) {
|
|
15591
16229
|
const arg = args[i2];
|
|
@@ -15633,6 +16271,11 @@ function parseNodeArgv(argv) {
|
|
|
15633
16271
|
userArgs.push(...args.slice(i2));
|
|
15634
16272
|
break;
|
|
15635
16273
|
}
|
|
16274
|
+
if (arg === "--preserve-symlinks" || arg === "--preserve-symlinks-main") {
|
|
16275
|
+
flags.push(arg);
|
|
16276
|
+
i2 += 1;
|
|
16277
|
+
continue;
|
|
16278
|
+
}
|
|
15636
16279
|
if (arg.startsWith("-")) {
|
|
15637
16280
|
if (arg === "-c" || arg === "--check") {
|
|
15638
16281
|
i2 += 1;
|
|
@@ -15651,7 +16294,7 @@ function parseNodeArgv(argv) {
|
|
|
15651
16294
|
code: evalCode,
|
|
15652
16295
|
print,
|
|
15653
16296
|
processArgv: [argv0, ...userArgs],
|
|
15654
|
-
execArgv: [flag, evalCode]
|
|
16297
|
+
execArgv: [...flags, flag, evalCode]
|
|
15655
16298
|
};
|
|
15656
16299
|
}
|
|
15657
16300
|
if (script !== void 0) {
|
|
@@ -15659,13 +16302,13 @@ function parseNodeArgv(argv) {
|
|
|
15659
16302
|
mode: "file",
|
|
15660
16303
|
script,
|
|
15661
16304
|
processArgv: [argv0, script, ...userArgs],
|
|
15662
|
-
execArgv: []
|
|
16305
|
+
execArgv: [...flags]
|
|
15663
16306
|
};
|
|
15664
16307
|
}
|
|
15665
16308
|
return {
|
|
15666
16309
|
mode: "empty",
|
|
15667
16310
|
processArgv: [argv0],
|
|
15668
|
-
execArgv: []
|
|
16311
|
+
execArgv: [...flags]
|
|
15669
16312
|
};
|
|
15670
16313
|
}
|
|
15671
16314
|
|
|
@@ -15814,8 +16457,7 @@ var IMPORT_CONDITIONS = ["slicc", "import", "node", "default"];
|
|
|
15814
16457
|
function pathToFileURL2(filename) {
|
|
15815
16458
|
if (filename.startsWith("file:")) return filename;
|
|
15816
16459
|
const p = filename.startsWith("/") ? filename : `/${filename}`;
|
|
15817
|
-
|
|
15818
|
-
return `file://${encoded}`;
|
|
16460
|
+
return `file://${encodeFilePath(p)}`;
|
|
15819
16461
|
}
|
|
15820
16462
|
function cjsToNamespace(exports) {
|
|
15821
16463
|
if (exports && typeof exports === "object" && exports.__esModule && "default" in exports) {
|
|
@@ -15866,7 +16508,8 @@ function createEsm({ ctx, process: process2, handles, builtins, cjs, trackPromis
|
|
|
15866
16508
|
path,
|
|
15867
16509
|
readPackageJson,
|
|
15868
16510
|
conditions: IMPORT_CONDITIONS,
|
|
15869
|
-
extensions: [".js", ".mjs", ".cjs", ".json"]
|
|
16511
|
+
extensions: [".js", ".mjs", ".cjs", ".json"],
|
|
16512
|
+
preserveSymlinks: preserveSymlinks(process2)
|
|
15870
16513
|
});
|
|
15871
16514
|
const cache2 = /* @__PURE__ */ new Map();
|
|
15872
16515
|
const evaluatingStack = /* @__PURE__ */ new Set();
|
|
@@ -15892,12 +16535,20 @@ function createEsm({ ctx, process: process2, handles, builtins, cjs, trackPromis
|
|
|
15892
16535
|
if (source != null && shouldRunAsEsm(source)) return true;
|
|
15893
16536
|
return false;
|
|
15894
16537
|
}
|
|
16538
|
+
function esmResolve(specifier, parentFilename) {
|
|
16539
|
+
try {
|
|
16540
|
+
return resolver.resolve(String(specifier), parentFilename, [parentFilename]);
|
|
16541
|
+
} catch (err) {
|
|
16542
|
+
if (err && err.code === "MODULE_NOT_FOUND") err.code = "ERR_MODULE_NOT_FOUND";
|
|
16543
|
+
throw err;
|
|
16544
|
+
}
|
|
16545
|
+
}
|
|
15895
16546
|
function makeImportMeta(filename) {
|
|
15896
16547
|
const url = filename.startsWith("[") ? filename : pathToFileURL2(filename);
|
|
15897
16548
|
const meta = {
|
|
15898
16549
|
url,
|
|
15899
16550
|
resolve(specifier) {
|
|
15900
|
-
const resolved =
|
|
16551
|
+
const resolved = esmResolve(specifier, filename);
|
|
15901
16552
|
if (resolved.type === "builtin") return `node:${resolved.id}`;
|
|
15902
16553
|
return pathToFileURL2(resolved.filename);
|
|
15903
16554
|
}
|
|
@@ -15909,7 +16560,7 @@ function createEsm({ ctx, process: process2, handles, builtins, cjs, trackPromis
|
|
|
15909
16560
|
return meta;
|
|
15910
16561
|
}
|
|
15911
16562
|
function resolveAndLoadSync(specifier, parentFilename) {
|
|
15912
|
-
const resolved =
|
|
16563
|
+
const resolved = esmResolve(specifier, parentFilename);
|
|
15913
16564
|
if (resolved.type === "builtin") {
|
|
15914
16565
|
return cjsToNamespace(builtins.load(resolved.id));
|
|
15915
16566
|
}
|
|
@@ -15980,7 +16631,7 @@ ${code}`
|
|
|
15980
16631
|
};
|
|
15981
16632
|
const __preload = async () => {
|
|
15982
16633
|
for (const spec of staticSpecs) {
|
|
15983
|
-
const resolved =
|
|
16634
|
+
const resolved = esmResolve(spec, filename);
|
|
15984
16635
|
if (resolved.type === "builtin") continue;
|
|
15985
16636
|
const dep = cache2.get(resolved.filename);
|
|
15986
16637
|
if (dep?.namespace) continue;
|
|
@@ -18202,13 +18853,14 @@ slicc-jsh ${NODE_SHIM_VERSION} (Node-compatible, abi: js)
|
|
|
18202
18853
|
return 1;
|
|
18203
18854
|
}
|
|
18204
18855
|
process2.argv[1] = filePath;
|
|
18856
|
+
const mainPath = realMainPath(ctx, filePath, process2.execArgv);
|
|
18205
18857
|
try {
|
|
18206
|
-
const useEsm = esm.isEsmFilename(
|
|
18858
|
+
const useEsm = esm.isEsmFilename(mainPath, source);
|
|
18207
18859
|
if (useEsm) {
|
|
18208
|
-
const result = esm.runMain(
|
|
18860
|
+
const result = esm.runMain(mainPath, source);
|
|
18209
18861
|
if (result != null && typeof result.then === "function") setEntry(result, "esm");
|
|
18210
18862
|
} else {
|
|
18211
|
-
cjs.runMain(
|
|
18863
|
+
cjs.runMain(mainPath, source);
|
|
18212
18864
|
}
|
|
18213
18865
|
nextTick.flushSync();
|
|
18214
18866
|
} catch (err) {
|