brsh 3.8.0 → 3.9.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/CHANGELOG.md +14 -0
- package/Readme.md +4 -6
- package/dist/shell.es.js +381 -147
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +11 -10
- package/dist/shell.min.js.map +1 -1
- package/dist/wbt.es.js +366 -144
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +7 -7
- package/dist/wbt.min.js.map +1 -1
- package/index.js +27 -0
- package/lib/BaseFileSystem.js +20 -0
- package/lib/BinaryContainer.js +10 -1
- package/lib/Command.js +66 -23
- package/lib/FileSystem.js +156 -5
- package/lib/InteractiveCommand.js +5 -0
- package/lib/Readme.md +1 -0
- package/lib/ScriptCommand.js +10 -0
- package/lib/TtyStream.js +12 -2
- package/lib/WasmCommand.js +139 -21
- package/package.json +1 -1
- package/test/devices-signals.test.js +173 -0
- package/test/doom.test.js +36 -0
- package/test/fixtures/nano.wasm +0 -0
- package/test/wbt.test.js +39 -0
package/dist/wbt.es.js
CHANGED
|
@@ -1079,10 +1079,24 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
1079
1079
|
super(), this.isTTY = e.isTTY !== !1, this.readable = !0, this.writable = !0, this.columns = e.columns || 80, this.rows = e.rows || 24, this.isRaw = !1, this._encoding = null, this._onWrite = e.onWrite || null;
|
|
1080
1080
|
}
|
|
1081
1081
|
write(e, t, n) {
|
|
1082
|
-
|
|
1082
|
+
if (e == null) return !0;
|
|
1083
|
+
typeof this._onWrite == "function" && this._onWrite(e), this._isPushing = !0;
|
|
1084
|
+
try {
|
|
1085
|
+
this.emit("data", this._formatChunk(e));
|
|
1086
|
+
} finally {
|
|
1087
|
+
this._isPushing = !1;
|
|
1088
|
+
}
|
|
1089
|
+
return typeof t == "function" ? t() : typeof n == "function" && n(), !0;
|
|
1083
1090
|
}
|
|
1084
1091
|
pushData(e) {
|
|
1085
|
-
e != null
|
|
1092
|
+
if (e != null) {
|
|
1093
|
+
this._isPushing = !0;
|
|
1094
|
+
try {
|
|
1095
|
+
this.emit("data", this._formatChunk(e));
|
|
1096
|
+
} finally {
|
|
1097
|
+
this._isPushing = !1;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1086
1100
|
}
|
|
1087
1101
|
_formatChunk(e) {
|
|
1088
1102
|
return this._encoding ? typeof e == "string" ? e : e instanceof Uint8Array || y !== void 0 && y.isBuffer(e) ? new TextDecoder().decode(e) : String(e) : e;
|
|
@@ -1143,11 +1157,17 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
1143
1157
|
columns: n,
|
|
1144
1158
|
rows: o,
|
|
1145
1159
|
onWrite: (e) => this.emit("stderr", e)
|
|
1146
|
-
}), this.
|
|
1160
|
+
}), this._onStdinStreamData = (e) => {
|
|
1147
1161
|
if (!this.captureInput) return;
|
|
1148
1162
|
let t = a(e);
|
|
1149
|
-
for (let e of t)
|
|
1150
|
-
|
|
1163
|
+
for (let e of t) {
|
|
1164
|
+
if (e === "^C") {
|
|
1165
|
+
this.kill("SIGINT");
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
!this.interactive && !this.stdinStream.isRaw && (e === "Enter" ? this.stdout.write("\r\n") : e === "Backspace" ? this.stdout.write("\b \b") : e.length === 1 && this.stdout.write(e)), this.onInput(e);
|
|
1169
|
+
}
|
|
1170
|
+
}, this.stdinStream.on("data", this._onStdinStreamData);
|
|
1151
1171
|
}
|
|
1152
1172
|
get name() {
|
|
1153
1173
|
return "unnamed";
|
|
@@ -1155,10 +1175,30 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
1155
1175
|
run() {
|
|
1156
1176
|
return Promise.reject("Command not implemented...");
|
|
1157
1177
|
}
|
|
1178
|
+
kill(e = "SIGINT") {
|
|
1179
|
+
let t = typeof e == "number" ? e : {
|
|
1180
|
+
SIGHUP: 129,
|
|
1181
|
+
SIGINT: 130,
|
|
1182
|
+
SIGQUIT: 131,
|
|
1183
|
+
SIGKILL: 137,
|
|
1184
|
+
SIGTERM: 143,
|
|
1185
|
+
SIGWINCH: 156
|
|
1186
|
+
}[e] || 130;
|
|
1187
|
+
this.exitCode = t, this.emit("signal", e), (e === "SIGINT" || e === "SIGTERM" || e === "SIGKILL" || e === "SIGQUIT") && (this.emit("abort"), this._abortController && this._abortController.abort());
|
|
1188
|
+
}
|
|
1158
1189
|
runCommand() {
|
|
1159
|
-
return Promise
|
|
1160
|
-
|
|
1161
|
-
|
|
1190
|
+
return new Promise((e) => {
|
|
1191
|
+
let t = !1, n = () => {
|
|
1192
|
+
t || (t = !0, e(this.result));
|
|
1193
|
+
};
|
|
1194
|
+
this.once("abort", n), Promise.resolve().then(() => this.run()).then((r) => {
|
|
1195
|
+
t || (t = !0, this.removeListener("abort", n), r && r.split(/\r?\n/).forEach((e) => this.stdOut = e), e(this.result));
|
|
1196
|
+
}).catch((r) => {
|
|
1197
|
+
if (!t) {
|
|
1198
|
+
if (t = !0, this.removeListener("abort", n), r && r.__type) throw r;
|
|
1199
|
+
r && (this.stdErr = r.message || r), this.result.getExitCode() === 0 && (this.exitCode = 127), e(this.result);
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1162
1202
|
});
|
|
1163
1203
|
}
|
|
1164
1204
|
onInput(e) {}
|
|
@@ -1197,6 +1237,9 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
1197
1237
|
onInput(e) {
|
|
1198
1238
|
this.sandbox && this.sandbox.onInput(e);
|
|
1199
1239
|
}
|
|
1240
|
+
kill(e = "SIGINT") {
|
|
1241
|
+
this.sandbox && this.sandbox.runningCommand && typeof this.sandbox.runningCommand.kill == "function" && this.sandbox.runningCommand.kill(e), this.sandbox && typeof this.sandbox.destroy == "function" && this.sandbox.destroy(130), super.kill(e);
|
|
1242
|
+
}
|
|
1200
1243
|
run() {
|
|
1201
1244
|
let e = this.context && this.context.fs || this.fs, t = e && e.isRealFilesystem ? { useRealFilesystem: !0 } : {
|
|
1202
1245
|
filesystem: e && e.getRaw() || {},
|
|
@@ -1595,7 +1638,8 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
1595
1638
|
"isRealFilesystem",
|
|
1596
1639
|
"isSymlink",
|
|
1597
1640
|
"readSymlink",
|
|
1598
|
-
"createSymlink"
|
|
1641
|
+
"createSymlink",
|
|
1642
|
+
"setTtyDevice"
|
|
1599
1643
|
]), r = class {
|
|
1600
1644
|
isReadable(e) {
|
|
1601
1645
|
let t = this.getMode(e);
|
|
@@ -1649,8 +1693,16 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
1649
1693
|
constructor(e) {
|
|
1650
1694
|
this.target = e;
|
|
1651
1695
|
}
|
|
1696
|
+
}, o = class {
|
|
1697
|
+
constructor(e, t = {}) {
|
|
1698
|
+
this.name = e, this.read = typeof t.read == "function" ? t.read : (() => ""), this.write = typeof t.write == "function" ? t.write : (() => {}), this.mode = t.mode === void 0 ? 438 : t.mode, this.isCharacterDevice = !0;
|
|
1699
|
+
}
|
|
1700
|
+
toString() {
|
|
1701
|
+
let e = this.read();
|
|
1702
|
+
return e == null ? "" : typeof e == "string" ? e : e.toString();
|
|
1703
|
+
}
|
|
1652
1704
|
};
|
|
1653
|
-
t.exports = r, t.exports.BinaryFile = i, t.exports.SymlinkRef = a;
|
|
1705
|
+
t.exports = r, t.exports.BinaryFile = i, t.exports.SymlinkRef = a, t.exports.DeviceFile = o;
|
|
1654
1706
|
}));
|
|
1655
1707
|
//#endregion
|
|
1656
1708
|
//#region node_modules/vite-plugin-node-polyfills/shims/process/dist/index.js
|
|
@@ -1760,6 +1812,9 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1760
1812
|
_exitAltScreen() {
|
|
1761
1813
|
this._inAltScreen && (this._inAltScreen = !1, this.stdinStream && this.stdinStream.setRawMode(!1), this.stdout && this.stdout.write("\x1B[?1049l\x1B[?25h"));
|
|
1762
1814
|
}
|
|
1815
|
+
kill(e = "SIGINT") {
|
|
1816
|
+
this._exitAltScreen(), super.kill(e);
|
|
1817
|
+
}
|
|
1763
1818
|
runCommand() {
|
|
1764
1819
|
return this.interactive && this._enterAltScreen(), super.runCommand().finally(() => {
|
|
1765
1820
|
this._exitAltScreen();
|
|
@@ -1768,33 +1823,34 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1768
1823
|
};
|
|
1769
1824
|
})), Y = /* @__PURE__ */ t(((e, t) => {
|
|
1770
1825
|
b(), q();
|
|
1771
|
-
var { BinaryFile: n, SymlinkRef: r } = O(),
|
|
1826
|
+
var { BinaryFile: n, SymlinkRef: r, DeviceFile: i } = O(), a = new Uint8Array([
|
|
1772
1827
|
66,
|
|
1773
1828
|
82,
|
|
1774
1829
|
70,
|
|
1775
1830
|
83
|
|
1776
|
-
]),
|
|
1777
|
-
function
|
|
1831
|
+
]), o = 2;
|
|
1832
|
+
function s(e) {
|
|
1778
1833
|
if (!e) return !1;
|
|
1779
1834
|
let t = e instanceof Uint8Array ? e : e instanceof ArrayBuffer || ArrayBuffer.isView(e) ? new Uint8Array(e.buffer || e, e.byteOffset || 0, e.byteLength) : null;
|
|
1780
|
-
return !t || t.length < 12 ? !1 : t[0] ===
|
|
1835
|
+
return !t || t.length < 12 ? !1 : t[0] === a[0] && t[1] === a[1] && t[2] === a[2] && t[3] === a[3];
|
|
1781
1836
|
}
|
|
1782
|
-
function
|
|
1783
|
-
let
|
|
1784
|
-
let t = e instanceof Uint8Array ? e : new Uint8Array(e), n =
|
|
1785
|
-
return
|
|
1786
|
-
},
|
|
1837
|
+
function c(e = {}, t = {}, n = {}) {
|
|
1838
|
+
let s = new TextEncoder(), c = [], l = 0, u = (e) => {
|
|
1839
|
+
let t = e instanceof Uint8Array ? e : new Uint8Array(e), n = l;
|
|
1840
|
+
return c.push(t), l += t.byteLength, [n, t.byteLength];
|
|
1841
|
+
}, d = {}, f = (e, t) => {
|
|
1787
1842
|
if (e == null) return null;
|
|
1788
1843
|
if (e instanceof r) return { $l: e.target };
|
|
1844
|
+
if (e instanceof i) return null;
|
|
1789
1845
|
if (e instanceof Uint8Array || y !== void 0 && y.isBuffer(e)) {
|
|
1790
|
-
let n = e instanceof Uint8Array ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength) : new Uint8Array(e), r = e.mimeType || (t.endsWith(".wasm") ? "application/wasm" : "application/octet-stream"), [i, a] =
|
|
1846
|
+
let n = e instanceof Uint8Array ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength) : new Uint8Array(e), r = e.mimeType || (t.endsWith(".wasm") ? "application/wasm" : "application/octet-stream"), [i, a] = u(n);
|
|
1791
1847
|
return { $b: [
|
|
1792
1848
|
i,
|
|
1793
1849
|
a,
|
|
1794
1850
|
r
|
|
1795
1851
|
] };
|
|
1796
1852
|
}
|
|
1797
|
-
if (typeof e == "function") return n.commandsBundle || (
|
|
1853
|
+
if (typeof e == "function") return n.commandsBundle || (d[t] = e.toString()), { $c: t };
|
|
1798
1854
|
if (typeof e == "string") {
|
|
1799
1855
|
if (e.startsWith("data:")) {
|
|
1800
1856
|
let t = e.indexOf(";"), n = e.indexOf(",", t);
|
|
@@ -1806,7 +1862,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1806
1862
|
a = new Uint8Array(e.length);
|
|
1807
1863
|
for (let t = 0; t < e.length; t++) a[t] = e.charCodeAt(t);
|
|
1808
1864
|
}
|
|
1809
|
-
let [o, s] =
|
|
1865
|
+
let [o, s] = u(a);
|
|
1810
1866
|
return { $b: [
|
|
1811
1867
|
o,
|
|
1812
1868
|
s,
|
|
@@ -1814,66 +1870,67 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1814
1870
|
] };
|
|
1815
1871
|
}
|
|
1816
1872
|
}
|
|
1817
|
-
let [t, n] =
|
|
1873
|
+
let [t, n] = u(s.encode(e));
|
|
1818
1874
|
return { $t: [t, n] };
|
|
1819
1875
|
}
|
|
1820
1876
|
if (typeof e == "object") {
|
|
1821
1877
|
let n = {};
|
|
1822
1878
|
for (let r of Object.keys(e)) {
|
|
1823
|
-
let i = `${t}/${r}`, a =
|
|
1879
|
+
let i = `${t}/${r}`, a = f(e[r], i);
|
|
1824
1880
|
a !== null && (n[r] = a);
|
|
1825
1881
|
}
|
|
1826
1882
|
return { $d: n };
|
|
1827
1883
|
}
|
|
1828
1884
|
return null;
|
|
1829
|
-
},
|
|
1830
|
-
n.commandsBundle && typeof n.commandsBundle == "string" && (
|
|
1831
|
-
let
|
|
1832
|
-
v:
|
|
1833
|
-
tree:
|
|
1885
|
+
}, p = f(e, "") || { $d: {} }, m = null;
|
|
1886
|
+
n.commandsBundle && typeof n.commandsBundle == "string" && (m = u(s.encode(n.commandsBundle)));
|
|
1887
|
+
let h = {
|
|
1888
|
+
v: o,
|
|
1889
|
+
tree: p,
|
|
1834
1890
|
permissions: Object.assign({}, t)
|
|
1835
1891
|
};
|
|
1836
|
-
|
|
1837
|
-
let
|
|
1838
|
-
|
|
1839
|
-
let
|
|
1840
|
-
|
|
1841
|
-
let
|
|
1842
|
-
for (let e of
|
|
1843
|
-
return
|
|
1892
|
+
m && (h.commandsSlice = m), Object.keys(d).length > 0 && (h.inlineCommands = d);
|
|
1893
|
+
let g = s.encode(JSON.stringify(h)), _ = 12 + g.byteLength + l, v = new Uint8Array(_);
|
|
1894
|
+
v.set(a, 0);
|
|
1895
|
+
let b = new DataView(v.buffer, v.byteOffset, v.byteLength);
|
|
1896
|
+
b.setUint32(4, o, !0), b.setUint32(8, g.byteLength, !0), v.set(g, 12);
|
|
1897
|
+
let x = 12 + g.byteLength;
|
|
1898
|
+
for (let e of c) v.set(e, x), x += e.byteLength;
|
|
1899
|
+
return v;
|
|
1844
1900
|
}
|
|
1845
|
-
function
|
|
1846
|
-
let
|
|
1847
|
-
if (!
|
|
1848
|
-
let
|
|
1849
|
-
if (
|
|
1850
|
-
let
|
|
1851
|
-
if (
|
|
1852
|
-
let
|
|
1853
|
-
if (Array.isArray(
|
|
1854
|
-
let [e, t] =
|
|
1901
|
+
function l(e, t = {}) {
|
|
1902
|
+
let a = e instanceof Uint8Array ? e : new Uint8Array(e.buffer || e, e.byteOffset || 0, e.byteLength);
|
|
1903
|
+
if (!s(a)) throw Error("Invalid BRFS binary container (missing BRFS magic header)");
|
|
1904
|
+
let c = new DataView(a.buffer, a.byteOffset, a.byteLength), l = c.getUint32(4, !0);
|
|
1905
|
+
if (l > o) throw Error(`Unsupported BRFS container version: ${l}`);
|
|
1906
|
+
let u = 12 + c.getUint32(8, !0);
|
|
1907
|
+
if (u > a.byteLength) throw Error("Corrupt BRFS binary container (header length exceeds buffer)");
|
|
1908
|
+
let d = new TextDecoder(), f = d.decode(a.subarray(12, u)), p = JSON.parse(f), m = a.subarray(u), h = Object.assign({}, t);
|
|
1909
|
+
if (Array.isArray(p.commandsSlice)) {
|
|
1910
|
+
let [e, t] = p.commandsSlice, n = d.decode(m.subarray(e, e + t));
|
|
1855
1911
|
try {
|
|
1856
1912
|
let e = Function(n)();
|
|
1857
|
-
e && typeof e == "object" && Object.assign(
|
|
1913
|
+
e && typeof e == "object" && Object.assign(h, e);
|
|
1858
1914
|
} catch {}
|
|
1859
1915
|
}
|
|
1860
|
-
let
|
|
1916
|
+
let g = (e) => {
|
|
1861
1917
|
if (!e || typeof e != "object") return e;
|
|
1862
1918
|
if ("$t" in e) {
|
|
1863
1919
|
let [t, n] = e.$t;
|
|
1864
|
-
return
|
|
1920
|
+
return d.decode(m.subarray(t, t + n));
|
|
1865
1921
|
}
|
|
1866
1922
|
if ("$b" in e) {
|
|
1867
1923
|
let [t, r, i] = e.$b;
|
|
1868
|
-
return new n(
|
|
1924
|
+
return new n(m.slice(t, t + r).buffer, i || "application/octet-stream");
|
|
1869
1925
|
}
|
|
1870
1926
|
if ("$l" in e) return new r(e.$l);
|
|
1927
|
+
if ("$dev" in e) return new i(e.$dev);
|
|
1871
1928
|
if ("$c" in e) {
|
|
1872
1929
|
let t = e.$c;
|
|
1873
|
-
if (
|
|
1874
|
-
if (
|
|
1930
|
+
if (h[t]) return h[t];
|
|
1931
|
+
if (p.inlineCommands && p.inlineCommands[t]) try {
|
|
1875
1932
|
let e = T(), n = J();
|
|
1876
|
-
return Function("Command", "InteractiveCommand", `return (${
|
|
1933
|
+
return Function("Command", "InteractiveCommand", `return (${p.inlineCommands[t]});`)(e, n);
|
|
1877
1934
|
} catch {
|
|
1878
1935
|
return null;
|
|
1879
1936
|
}
|
|
@@ -1882,7 +1939,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1882
1939
|
if ("$d" in e) {
|
|
1883
1940
|
let t = {};
|
|
1884
1941
|
for (let [n, r] of Object.entries(e.$d)) {
|
|
1885
|
-
let e =
|
|
1942
|
+
let e = g(r);
|
|
1886
1943
|
e !== null && (t[n] = e);
|
|
1887
1944
|
}
|
|
1888
1945
|
return t;
|
|
@@ -1890,16 +1947,16 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1890
1947
|
return e;
|
|
1891
1948
|
};
|
|
1892
1949
|
return {
|
|
1893
|
-
filesystem:
|
|
1894
|
-
permissions: Object.assign({},
|
|
1950
|
+
filesystem: g(p.tree) || {},
|
|
1951
|
+
permissions: Object.assign({}, p.permissions || {})
|
|
1895
1952
|
};
|
|
1896
1953
|
}
|
|
1897
|
-
function
|
|
1954
|
+
function u(e) {
|
|
1898
1955
|
if (!e) return !1;
|
|
1899
1956
|
let t = e instanceof Uint8Array ? e : e instanceof ArrayBuffer ? new Uint8Array(e) : ArrayBuffer.isView(e) ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength) : null;
|
|
1900
1957
|
return !!(t && t.byteLength >= 2 && t[0] === 31 && t[1] === 139);
|
|
1901
1958
|
}
|
|
1902
|
-
async function
|
|
1959
|
+
async function d(e) {
|
|
1903
1960
|
if (typeof DecompressionStream < "u" && typeof Response < "u") {
|
|
1904
1961
|
let t = new DecompressionStream("gzip"), n = new Blob([e]).stream().pipeThrough(t), r = await new Response(n).arrayBuffer();
|
|
1905
1962
|
return new Uint8Array(r);
|
|
@@ -1910,36 +1967,36 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1910
1967
|
}
|
|
1911
1968
|
throw Error("Gzip decompression is not supported in this environment");
|
|
1912
1969
|
}
|
|
1913
|
-
function
|
|
1914
|
-
return e ? !!(typeof e == "string" || typeof e.then == "function" || typeof e.arrayBuffer == "function" ||
|
|
1970
|
+
function f(e) {
|
|
1971
|
+
return e ? !!(typeof e == "string" || typeof e.then == "function" || typeof e.arrayBuffer == "function" || u(e)) : !1;
|
|
1915
1972
|
}
|
|
1916
|
-
async function
|
|
1973
|
+
async function p(e, t = {}) {
|
|
1917
1974
|
if (!e) return {
|
|
1918
1975
|
filesystem: {},
|
|
1919
1976
|
permissions: t
|
|
1920
1977
|
};
|
|
1921
|
-
if (typeof e.then == "function") return
|
|
1978
|
+
if (typeof e.then == "function") return p(await e, t);
|
|
1922
1979
|
if (typeof e.arrayBuffer == "function") {
|
|
1923
1980
|
let n = await e.arrayBuffer();
|
|
1924
|
-
return
|
|
1981
|
+
return p(new Uint8Array(n), t);
|
|
1925
1982
|
}
|
|
1926
1983
|
if (typeof e == "string") {
|
|
1927
1984
|
if (!/^https?:\/\//i.test(e) && K !== void 0 && typeof K.getBuiltinModule == "function" && typeof window > "u") try {
|
|
1928
1985
|
let n = K.getBuiltinModule("fs");
|
|
1929
1986
|
if (n && n.existsSync(e)) {
|
|
1930
1987
|
let r = await n.promises.readFile(e);
|
|
1931
|
-
return
|
|
1988
|
+
return p(new Uint8Array(r.buffer, r.byteOffset, r.byteLength), t);
|
|
1932
1989
|
}
|
|
1933
1990
|
} catch {}
|
|
1934
1991
|
let n = await fetch(e);
|
|
1935
1992
|
if (!n.ok) throw Error(`Failed to load filesystem from ${e}: HTTP ${n.status}`);
|
|
1936
1993
|
let r = await n.arrayBuffer();
|
|
1937
|
-
return
|
|
1994
|
+
return p(new Uint8Array(r), t);
|
|
1938
1995
|
}
|
|
1939
1996
|
if (e instanceof ArrayBuffer || ArrayBuffer.isView(e)) {
|
|
1940
1997
|
let n = e instanceof Uint8Array ? e : e instanceof ArrayBuffer ? new Uint8Array(e) : new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
|
|
1941
|
-
if (
|
|
1942
|
-
let e =
|
|
1998
|
+
if (u(n) && (n = await d(n)), s(n)) {
|
|
1999
|
+
let e = l(n);
|
|
1943
2000
|
return {
|
|
1944
2001
|
filesystem: e.filesystem,
|
|
1945
2002
|
permissions: Object.assign({}, e.permissions, t)
|
|
@@ -1966,7 +2023,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1966
2023
|
};
|
|
1967
2024
|
}
|
|
1968
2025
|
}
|
|
1969
|
-
return typeof e == "object" && e.filesystem && typeof e.permissions == "object" ?
|
|
2026
|
+
return typeof e == "object" && e.filesystem && typeof e.permissions == "object" ? f(e.filesystem) || s(e.filesystem) ? p(e.filesystem, Object.assign({}, e.permissions, t)) : {
|
|
1970
2027
|
filesystem: e.filesystem,
|
|
1971
2028
|
permissions: Object.assign({}, e.permissions, t)
|
|
1972
2029
|
} : {
|
|
@@ -1975,33 +2032,33 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1975
2032
|
};
|
|
1976
2033
|
}
|
|
1977
2034
|
t.exports = {
|
|
1978
|
-
MAGIC:
|
|
1979
|
-
FORMAT_VERSION:
|
|
1980
|
-
isBinaryContainer:
|
|
1981
|
-
isGzipBytes:
|
|
1982
|
-
isAsyncFilesystemSource:
|
|
1983
|
-
resolveFilesystemSource:
|
|
1984
|
-
serializeBinaryFilesystem:
|
|
1985
|
-
deserializeBinaryFilesystem:
|
|
2035
|
+
MAGIC: a,
|
|
2036
|
+
FORMAT_VERSION: o,
|
|
2037
|
+
isBinaryContainer: s,
|
|
2038
|
+
isGzipBytes: u,
|
|
2039
|
+
isAsyncFilesystemSource: f,
|
|
2040
|
+
resolveFilesystemSource: p,
|
|
2041
|
+
serializeBinaryFilesystem: c,
|
|
2042
|
+
deserializeBinaryFilesystem: l,
|
|
1986
2043
|
FilesystemStorage: class {
|
|
1987
2044
|
static async save(e, t = "brsh-rootfs") {
|
|
1988
|
-
let n = e.context ? e.context.fs : e, r =
|
|
2045
|
+
let n = e.context ? e.context.fs : e, r = c(n.getRaw(), n.getRawPermissions());
|
|
1989
2046
|
return typeof indexedDB < "u" && await this._idbPut(t, r), r;
|
|
1990
2047
|
}
|
|
1991
2048
|
static async load(e = "brsh-rootfs") {
|
|
1992
|
-
if (e instanceof Uint8Array || e instanceof ArrayBuffer || typeof e == "string" && (/^https?:\/\//i.test(e) || e.endsWith(".brfs"))) return
|
|
2049
|
+
if (e instanceof Uint8Array || e instanceof ArrayBuffer || typeof e == "string" && (/^https?:\/\//i.test(e) || e.endsWith(".brfs"))) return p(e);
|
|
1993
2050
|
if (typeof indexedDB < "u" && typeof e == "string") {
|
|
1994
2051
|
let t = await this._idbGet(e);
|
|
1995
|
-
if (t &&
|
|
2052
|
+
if (t && s(t)) return l(t);
|
|
1996
2053
|
}
|
|
1997
2054
|
return null;
|
|
1998
2055
|
}
|
|
1999
2056
|
static async loadOrFetch(e = "brsh-rootfs", t = {}) {
|
|
2000
|
-
return await this.load(e) ||
|
|
2057
|
+
return await this.load(e) || p(t);
|
|
2001
2058
|
}
|
|
2002
2059
|
static createAutoSave(e = "brsh-rootfs", t = null) {
|
|
2003
2060
|
return (n, r) => {
|
|
2004
|
-
let i =
|
|
2061
|
+
let i = c(n, r);
|
|
2005
2062
|
typeof indexedDB < "u" && this._idbPut(e, i).catch(() => {}), typeof t == "function" && t(i, n, r);
|
|
2006
2063
|
};
|
|
2007
2064
|
}
|
|
@@ -2039,11 +2096,11 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2039
2096
|
};
|
|
2040
2097
|
})), X = /* @__PURE__ */ t(((e, t) => {
|
|
2041
2098
|
b();
|
|
2042
|
-
var n = O(), { BinaryFile: r, SymlinkRef: i } = n;
|
|
2043
|
-
function
|
|
2099
|
+
var n = O(), { BinaryFile: r, SymlinkRef: i, DeviceFile: a } = n;
|
|
2100
|
+
function o(e) {
|
|
2044
2101
|
for (let t of Object.keys(e)) {
|
|
2045
2102
|
let n = e[t];
|
|
2046
|
-
if (typeof n == "object" && n && !(n instanceof Uint8Array) && !(n instanceof i))
|
|
2103
|
+
if (typeof n == "object" && n && !(n instanceof Uint8Array) && !(n instanceof i) && !(n instanceof a)) o(n);
|
|
2047
2104
|
else if (typeof n == "string" && n.startsWith("data:")) {
|
|
2048
2105
|
let i = n.indexOf(";"), a = n.indexOf(",", i);
|
|
2049
2106
|
if (i !== -1 && a !== -1 && n.slice(i + 1, a) === "base64") {
|
|
@@ -2068,7 +2125,43 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2068
2125
|
let { deserializeBinaryFilesystem: e } = Y(), r = e(t);
|
|
2069
2126
|
t = r.filesystem, n = Object.assign({}, r.permissions, n);
|
|
2070
2127
|
}
|
|
2071
|
-
|
|
2128
|
+
o(t), this.fileSystem = t, this.permissions = Object.assign({}, n), this.cwd = e.endsWith("/") ? e : e + "/", this._onChange = r, this._changeScheduled = !1, this._initDevices();
|
|
2129
|
+
}
|
|
2130
|
+
_initDevices() {
|
|
2131
|
+
this._devices = {};
|
|
2132
|
+
let e = this._devices;
|
|
2133
|
+
e.null = new a("null", {
|
|
2134
|
+
read: () => "",
|
|
2135
|
+
write: () => {}
|
|
2136
|
+
}), e.zero = new a("zero", {
|
|
2137
|
+
read: () => new Uint8Array(4096),
|
|
2138
|
+
write: () => {}
|
|
2139
|
+
}), e.urandom = new a("urandom", {
|
|
2140
|
+
read: () => {
|
|
2141
|
+
let e = new Uint8Array(256);
|
|
2142
|
+
if (typeof crypto < "u" && crypto.getRandomValues) crypto.getRandomValues(e);
|
|
2143
|
+
else for (let t = 0; t < e.length; t++) e[t] = Math.floor(Math.random() * 256);
|
|
2144
|
+
return e;
|
|
2145
|
+
},
|
|
2146
|
+
write: () => {}
|
|
2147
|
+
}), e.random = e.urandom, e.tty = new a("tty", {
|
|
2148
|
+
read: () => "",
|
|
2149
|
+
write: () => {}
|
|
2150
|
+
}), e.stdin = new i("/dev/tty"), e.stdout = new i("/dev/tty"), e.stderr = new i("/dev/tty");
|
|
2151
|
+
}
|
|
2152
|
+
_getDevDir() {
|
|
2153
|
+
return this._devices || this._initDevices(), this.fileSystem && this.fileSystem.dev && typeof this.fileSystem.dev == "object" && !(this.fileSystem.dev instanceof i) && !(this.fileSystem.dev instanceof Uint8Array) ? Object.assign({}, this.fileSystem.dev, this._devices) : this._devices;
|
|
2154
|
+
}
|
|
2155
|
+
_getRootOverlay() {
|
|
2156
|
+
let e = Object.assign({}, this.fileSystem);
|
|
2157
|
+
return e.dev = this._getDevDir(), e;
|
|
2158
|
+
}
|
|
2159
|
+
setTtyDevice(e = {}) {
|
|
2160
|
+
this._devices || this._initDevices(), this._devices.tty = new a("tty", {
|
|
2161
|
+
read: e.read || (() => ""),
|
|
2162
|
+
write: e.write || (() => {}),
|
|
2163
|
+
mode: 438
|
|
2164
|
+
}), this._devices.stdin = new i("/dev/tty"), this._devices.stdout = new i("/dev/tty"), this._devices.stderr = new i("/dev/tty");
|
|
2072
2165
|
}
|
|
2073
2166
|
toBinaryContainer(e = {}) {
|
|
2074
2167
|
let { serializeBinaryFilesystem: t } = Y();
|
|
@@ -2080,10 +2173,11 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2080
2173
|
}
|
|
2081
2174
|
getFileByPath(e) {
|
|
2082
2175
|
let t = this._resolveByAbsolutePath(this._pathToAbsolute(e), !0);
|
|
2083
|
-
return t == null || !this.isReadable(e) ? null : t;
|
|
2176
|
+
return t == null || !this.isReadable(e) ? null : t instanceof a ? t.read() : t;
|
|
2084
2177
|
}
|
|
2085
2178
|
_getFileRaw(e) {
|
|
2086
|
-
|
|
2179
|
+
let t = this._getFileByAbsolutePath(this._pathToAbsolute(e));
|
|
2180
|
+
return t instanceof a ? t.read() : t;
|
|
2087
2181
|
}
|
|
2088
2182
|
exists(e) {
|
|
2089
2183
|
return this._resolveByAbsolutePath(this._pathToAbsolute(e), !0) != null;
|
|
@@ -2105,13 +2199,25 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2105
2199
|
isFile: !1,
|
|
2106
2200
|
isCommand: !1,
|
|
2107
2201
|
isBinary: !1,
|
|
2108
|
-
isSymlink: !0
|
|
2202
|
+
isSymlink: !0,
|
|
2203
|
+
isDevice: !1,
|
|
2204
|
+
isCharacterDevice: !1
|
|
2205
|
+
} : t instanceof a ? {
|
|
2206
|
+
isDirectory: !1,
|
|
2207
|
+
isFile: !0,
|
|
2208
|
+
isCommand: !1,
|
|
2209
|
+
isBinary: t.read() instanceof Uint8Array,
|
|
2210
|
+
isSymlink: !1,
|
|
2211
|
+
isDevice: !0,
|
|
2212
|
+
isCharacterDevice: !0
|
|
2109
2213
|
} : {
|
|
2110
2214
|
isDirectory: t.constructor === Object,
|
|
2111
2215
|
isFile: typeof t == "string" || t instanceof Uint8Array,
|
|
2112
2216
|
isCommand: typeof t == "function",
|
|
2113
2217
|
isBinary: t instanceof Uint8Array,
|
|
2114
|
-
isSymlink: !1
|
|
2218
|
+
isSymlink: !1,
|
|
2219
|
+
isDevice: !1,
|
|
2220
|
+
isCharacterDevice: !1
|
|
2115
2221
|
};
|
|
2116
2222
|
}
|
|
2117
2223
|
_pathToAbsolute(e) {
|
|
@@ -2129,9 +2235,13 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2129
2235
|
return this._pathToAbsolute(e);
|
|
2130
2236
|
}
|
|
2131
2237
|
setFileByPath(e, t, n = !1) {
|
|
2132
|
-
let r = this._pathToAbsolute(e);
|
|
2133
|
-
if (
|
|
2238
|
+
let r = this._pathToAbsolute(e), i = this._getFileByAbsolutePath(r);
|
|
2239
|
+
if (i != null) {
|
|
2134
2240
|
if (!this.isWritable(e)) throw Error("Permission denied");
|
|
2241
|
+
if (i instanceof a) {
|
|
2242
|
+
i.write(t), this._triggerChange();
|
|
2243
|
+
return;
|
|
2244
|
+
}
|
|
2135
2245
|
} else {
|
|
2136
2246
|
let e = r.split("/");
|
|
2137
2247
|
e.pop();
|
|
@@ -2147,28 +2257,54 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2147
2257
|
_setFileByAbsolutePath(e, t, n = !0) {
|
|
2148
2258
|
let r = e.split("/");
|
|
2149
2259
|
r.shift();
|
|
2150
|
-
let
|
|
2260
|
+
let o = r.pop();
|
|
2261
|
+
if (r.length > 0 && r[0] === "dev") {
|
|
2262
|
+
let e = this._getDevDir(), i = r.slice(1);
|
|
2263
|
+
for (let t of i) {
|
|
2264
|
+
if (!Object.prototype.hasOwnProperty.call(e, t)) {
|
|
2265
|
+
if (!n) throw Error(`${t}: No such file or directory`);
|
|
2266
|
+
e[t] = {};
|
|
2267
|
+
}
|
|
2268
|
+
e = e[t];
|
|
2269
|
+
}
|
|
2270
|
+
if (e[o] instanceof a) {
|
|
2271
|
+
e[o].write(t);
|
|
2272
|
+
return;
|
|
2273
|
+
}
|
|
2274
|
+
e[o] = t;
|
|
2275
|
+
return;
|
|
2276
|
+
}
|
|
2277
|
+
if (r.length === 0 && o === "dev") throw Error("dev: File exists");
|
|
2278
|
+
let s = this.fileSystem, c = [];
|
|
2151
2279
|
for (let e of r) {
|
|
2152
|
-
if (
|
|
2280
|
+
if (c.push(e), !Object.prototype.hasOwnProperty.call(s, e)) {
|
|
2153
2281
|
if (!n) throw Error(`${e}: No such file or directory`);
|
|
2154
|
-
|
|
2282
|
+
s[e] = {};
|
|
2155
2283
|
}
|
|
2156
|
-
let t =
|
|
2284
|
+
let t = s[e];
|
|
2157
2285
|
if (t instanceof i) {
|
|
2158
|
-
let n = "/" +
|
|
2286
|
+
let n = "/" + c.slice(0, -1).join("/"), r = t.target.startsWith("/") ? this._traverseComplexAbsolutePath(t.target) : this._traverseComplexAbsolutePath(n + "/" + t.target);
|
|
2159
2287
|
if (t = this._resolveByAbsolutePath(r, !0), typeof t != "object" || !t || t instanceof i) throw Error(`${e}: Not a directory`);
|
|
2160
2288
|
}
|
|
2161
|
-
|
|
2289
|
+
s = t;
|
|
2290
|
+
}
|
|
2291
|
+
if (s[o] instanceof a) {
|
|
2292
|
+
s[o].write(t);
|
|
2293
|
+
return;
|
|
2162
2294
|
}
|
|
2163
|
-
o
|
|
2295
|
+
s[o] = t;
|
|
2164
2296
|
}
|
|
2165
2297
|
_resolveByAbsolutePath(e, t = !0, n = 0) {
|
|
2166
2298
|
if (n > 10) return null;
|
|
2167
2299
|
let r = e.split("/");
|
|
2168
|
-
r.shift(), r.length > 0 && r[r.length - 1].length < 1 && r.pop();
|
|
2300
|
+
if (r.shift(), r.length > 0 && r[r.length - 1].length < 1 && r.pop(), r.length === 0) return this._getRootOverlay();
|
|
2169
2301
|
let a = this.fileSystem, o = [];
|
|
2170
2302
|
for (let e = 0; e < r.length; e++) {
|
|
2171
2303
|
let s = r[e], c = e === r.length - 1;
|
|
2304
|
+
if (e === 0 && s === "dev") {
|
|
2305
|
+
a = this._getDevDir(), o.push(s);
|
|
2306
|
+
continue;
|
|
2307
|
+
}
|
|
2172
2308
|
if (typeof a != "object" || !a || a instanceof i || !Object.prototype.hasOwnProperty.call(a, s)) return null;
|
|
2173
2309
|
if (a = a[s], o.push(s), a instanceof i && (!c || t)) {
|
|
2174
2310
|
let e = "/" + o.slice(0, -1).join("/"), t = a.target.startsWith("/") ? this._traverseComplexAbsolutePath(a.target) : this._traverseComplexAbsolutePath(e + "/" + a.target);
|
|
@@ -2179,7 +2315,16 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2179
2315
|
}
|
|
2180
2316
|
_getFileByAbsolutePath(e) {
|
|
2181
2317
|
let t = e.split("/");
|
|
2182
|
-
|
|
2318
|
+
if (t.shift(), t.length > 0 && t[t.length - 1].length < 1 && t.pop(), t.length === 0) return this._getRootOverlay();
|
|
2319
|
+
if (t[0] === "dev") {
|
|
2320
|
+
let e = this._getDevDir();
|
|
2321
|
+
for (let n = 1; n < t.length; n++) {
|
|
2322
|
+
if (typeof e != "object" || !e || !Object.prototype.hasOwnProperty.call(e, t[n])) return null;
|
|
2323
|
+
e = e[t[n]];
|
|
2324
|
+
}
|
|
2325
|
+
return e;
|
|
2326
|
+
}
|
|
2327
|
+
return t.reduce((e, t) => typeof e != "object" || !e || !Object.prototype.hasOwnProperty.call(e, t) ? null : e[t], this.fileSystem);
|
|
2183
2328
|
}
|
|
2184
2329
|
deleteFileByPath(e) {
|
|
2185
2330
|
let t = this._pathToAbsolute(e), n = t.split("/");
|
|
@@ -2197,6 +2342,16 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2197
2342
|
t.shift(), t[t.length - 1] === "" && t.pop();
|
|
2198
2343
|
let n = t.pop();
|
|
2199
2344
|
if (!n) return;
|
|
2345
|
+
if (t.length > 0 && t[0] === "dev") {
|
|
2346
|
+
let e = this._getDevDir();
|
|
2347
|
+
for (let n = 1; n < t.length; n++) {
|
|
2348
|
+
if (!e || typeof e != "object") return;
|
|
2349
|
+
e = e[t[n]];
|
|
2350
|
+
}
|
|
2351
|
+
e && n in e && delete e[n];
|
|
2352
|
+
return;
|
|
2353
|
+
}
|
|
2354
|
+
if (t.length === 0 && n === "dev") return;
|
|
2200
2355
|
let r = this.fileSystem, a = [];
|
|
2201
2356
|
for (let e of t) {
|
|
2202
2357
|
if (a.push(e), !Object.prototype.hasOwnProperty.call(r, e)) return;
|
|
@@ -2213,7 +2368,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2213
2368
|
let t = this._pathToAbsolute(e);
|
|
2214
2369
|
if (this.permissions[t] !== void 0) return this.permissions[t];
|
|
2215
2370
|
let n = this._resolveByAbsolutePath(t, !0);
|
|
2216
|
-
return n == null ? null : n.constructor === Object ? 493 : typeof n == "function" ? 365 : 420;
|
|
2371
|
+
return n == null ? null : n instanceof a ? n.mode || 438 : n.constructor === Object ? 493 : typeof n == "function" ? 365 : 420;
|
|
2217
2372
|
}
|
|
2218
2373
|
setMode(e, t) {
|
|
2219
2374
|
let n = this._pathToAbsolute(e);
|
|
@@ -2221,7 +2376,12 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2221
2376
|
}
|
|
2222
2377
|
getSize(e) {
|
|
2223
2378
|
let t = this._pathToAbsolute(e), n = this._resolveByAbsolutePath(t, !0);
|
|
2224
|
-
|
|
2379
|
+
if (n == null) return 0;
|
|
2380
|
+
if (n instanceof a) {
|
|
2381
|
+
let e = n.read();
|
|
2382
|
+
return e instanceof Uint8Array || typeof e == "string" ? e.length : 0;
|
|
2383
|
+
}
|
|
2384
|
+
return n.constructor === Object ? JSON.stringify(n).length : n instanceof Uint8Array ? n.length : n.toString().length;
|
|
2225
2385
|
}
|
|
2226
2386
|
getRawPermissions() {
|
|
2227
2387
|
return Object.assign({}, this.permissions);
|
|
@@ -2433,15 +2593,27 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2433
2593
|
return !0;
|
|
2434
2594
|
}
|
|
2435
2595
|
get interactive() {
|
|
2436
|
-
|
|
2437
|
-
if (this._isInteractive !== void 0) return !!this._isInteractive;
|
|
2438
|
-
if (this._pkgMeta && this._pkgMeta.interactive !== void 0) return !!this._pkgMeta.interactive;
|
|
2439
|
-
let e = (this.script || this.name || "").toLowerCase();
|
|
2440
|
-
return e === "nano" || e.endsWith("/nano") || e.endsWith("nano.wasm");
|
|
2596
|
+
return (this.arguments || []).some((e) => e === "--help" || e === "-h" || e === "--version" || e === "-V" || e === "-v") ? !1 : this._isInteractive === void 0 ? !!(this._pkgMeta && (this._pkgMeta.interactive || this._pkgMeta.wasm?.interactive) || this._inspectedWasm && this._inspectedWasm.isInteractive) : !!this._isInteractive;
|
|
2441
2597
|
}
|
|
2442
2598
|
get captureInput() {
|
|
2443
2599
|
return this.interactive;
|
|
2444
2600
|
}
|
|
2601
|
+
kill(e = "SIGINT") {
|
|
2602
|
+
if (this._killed = !0, this.exitCode = 130, this._exitAltScreen(), this._asyncifyReject) {
|
|
2603
|
+
try {
|
|
2604
|
+
this._asyncifyReject(/* @__PURE__ */ Error("Interrupted by SIGINT"));
|
|
2605
|
+
} catch {}
|
|
2606
|
+
this._asyncifyReject = null;
|
|
2607
|
+
}
|
|
2608
|
+
if (this._pendingReadResolve) {
|
|
2609
|
+
let e = this._pendingReadResolve;
|
|
2610
|
+
this._pendingReadResolve = null;
|
|
2611
|
+
try {
|
|
2612
|
+
e();
|
|
2613
|
+
} catch {}
|
|
2614
|
+
}
|
|
2615
|
+
super.kill(e);
|
|
2616
|
+
}
|
|
2445
2617
|
_enterAltScreen() {
|
|
2446
2618
|
this._inAltScreen || (this._inAltScreen = !0, this.stdinStream && typeof this.stdinStream.setRawMode == "function" && this.stdinStream.setRawMode(!0), this.stdout && typeof this.stdout.write == "function" && this.stdout.write("\x1B[?1049h\x1B[2J\x1B[H"));
|
|
2447
2619
|
}
|
|
@@ -2476,7 +2648,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2476
2648
|
return n[e] ? new TextEncoder().encode(n[e]) : new TextEncoder().encode(e);
|
|
2477
2649
|
}
|
|
2478
2650
|
onInput(e) {
|
|
2479
|
-
if (!this._handlingStreamData) {
|
|
2651
|
+
if (!this._handlingStreamData && !(this.stdinStream && this.stdinStream._isPushing)) {
|
|
2480
2652
|
if (typeof this._externalKeyHandler == "function") {
|
|
2481
2653
|
this._externalKeyHandler(e);
|
|
2482
2654
|
return;
|
|
@@ -2504,22 +2676,26 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2504
2676
|
_loadBytes(e, t) {
|
|
2505
2677
|
let n = this.context && this.context.fs || this.fs;
|
|
2506
2678
|
if (!n) return Promise.reject(/* @__PURE__ */ Error(`${e}: Filesystem is not available`));
|
|
2679
|
+
let r;
|
|
2507
2680
|
if (n.isRealFilesystem && t) try {
|
|
2508
|
-
let
|
|
2509
|
-
|
|
2510
|
-
bytes:
|
|
2511
|
-
isWat: this._isWat(e,
|
|
2681
|
+
let i = t.readFileSync(n.absolutePath(e)), a = new Uint8Array(i);
|
|
2682
|
+
r = Promise.resolve({
|
|
2683
|
+
bytes: a,
|
|
2684
|
+
isWat: this._isWat(e, a)
|
|
2512
2685
|
});
|
|
2513
2686
|
} catch (t) {
|
|
2514
2687
|
return Promise.reject(/* @__PURE__ */ Error(`${e}: ${t.message}`));
|
|
2515
2688
|
}
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2689
|
+
else {
|
|
2690
|
+
let t = n.getFileByPath(e);
|
|
2691
|
+
if (t == null) return Promise.reject(/* @__PURE__ */ Error(`${e}: No such file or directory`));
|
|
2692
|
+
let i = this._contentToBytes(t);
|
|
2693
|
+
r = Promise.resolve({
|
|
2694
|
+
bytes: i,
|
|
2695
|
+
isWat: this._isWat(e, i)
|
|
2696
|
+
});
|
|
2697
|
+
}
|
|
2698
|
+
return r.then((e) => (!e.isWat && e.bytes && (this._inspectedWasm = N(e.bytes), this._inspectedWasm.isInteractive && (this._isInteractive = !0)), e));
|
|
2523
2699
|
}
|
|
2524
2700
|
_isWat(e, t) {
|
|
2525
2701
|
return e.endsWith(".wat") ? !0 : t.length > 0 && t[0] === 40;
|
|
@@ -2561,7 +2737,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2561
2737
|
1: "",
|
|
2562
2738
|
2: ""
|
|
2563
2739
|
}, n = new TextDecoder(), b = new TextEncoder(), T = null, E = null, D = !1, O = 0, k = null, A = null, j = null, M = null, F = this.stdin === void 0 || this.stdin === null || this.stdin === this.stdinStream || this.stdin && this.stdin.isTTY, I = !!(this.interactive && F), L = () => {
|
|
2564
|
-
I || !F || (I = !0, this._isInteractive = !0, t[1] &&= (this.stdout && typeof this.stdout.write == "function" && this.stdout.write(t[1]), ""), t[2] &&= (this.stderr && typeof this.stderr.write == "function" && this.stderr.write(t[2]), ""), this.stdinStream && typeof this.stdinStream.setRawMode == "function" && this.stdinStream.setRawMode(!0));
|
|
2740
|
+
I || !F || (I = !0, this._isInteractive = !0, this._enterAltScreen(), t[1] &&= (this.stdout && typeof this.stdout.write == "function" && this.stdout.write(t[1]), ""), t[2] &&= (this.stderr && typeof this.stderr.write == "function" && this.stderr.write(t[2]), ""), this.stdinStream && typeof this.stdinStream.setRawMode == "function" && this.stdinStream.setRawMode(!0));
|
|
2565
2741
|
}, R = (e, n) => {
|
|
2566
2742
|
if (I && (e === 1 || e === 2)) {
|
|
2567
2743
|
if (e === 1 && this.stdout) {
|
|
@@ -2599,7 +2775,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2599
2775
|
if (this._handlingStreamData) return;
|
|
2600
2776
|
let t = this._keyToBytes(e);
|
|
2601
2777
|
t && V(t);
|
|
2602
|
-
}, F && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", M), F && this.stdin && this.stdin !== this.stdinStream && typeof this.stdin.on == "function" && this.stdin.on("data", M);
|
|
2778
|
+
}, this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", this._onStdinStreamData), F && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", M), F && this.stdin && this.stdin !== this.stdinStream && typeof this.stdin.on == "function" && this.stdin.on("data", M);
|
|
2603
2779
|
let H = !F && typeof this.stdin == "string" ? b.encode(this.stdin) : !F && this.stdin instanceof Uint8Array ? this.stdin : !F && y !== void 0 && y.isBuffer(this.stdin) ? new Uint8Array(this.stdin) : new Uint8Array(), U = 0, W = this.context && this.context.fs ? this.context.fs : this.fs, G = this.context && this.context.fs && this.context.fs.cwd || this.fs && this.fs.cwd || this.context && typeof this.context.getVar == "function" && this.context.getVar("PWD") || W && W.cwd || "/", ee = G.length > 1 && G.endsWith("/") ? G.slice(0, -1) : G, K = 5, q = new Map([[3, {
|
|
2604
2780
|
type: "preopen",
|
|
2605
2781
|
path: "/",
|
|
@@ -2718,8 +2894,8 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2718
2894
|
}
|
|
2719
2895
|
return s.setUint32(r, e, !0), i;
|
|
2720
2896
|
}
|
|
2721
|
-
return o ? (s.setUint32(r, 0, !0), a) : (E.exports.asyncify_start_unwind(O), k = new Promise((e) => {
|
|
2722
|
-
A = e;
|
|
2897
|
+
return o ? (s.setUint32(r, 0, !0), a) : (E.exports.asyncify_start_unwind(O), k = new Promise((e, t) => {
|
|
2898
|
+
A = e, this._pendingReadResolve = e, this._asyncifyReject = t;
|
|
2723
2899
|
}), s.setUint32(r, 0, !0), i);
|
|
2724
2900
|
}
|
|
2725
2901
|
if (B.length > 0) {
|
|
@@ -2870,14 +3046,16 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2870
3046
|
path: y
|
|
2871
3047
|
}), new DataView(T.buffer).setUint32(h, e, !0), i;
|
|
2872
3048
|
}
|
|
2873
|
-
if (y === "/dev/tty") {
|
|
3049
|
+
if (y === "/dev/tty" || y === "/dev/stdin") {
|
|
2874
3050
|
L();
|
|
2875
3051
|
let e = K++;
|
|
2876
3052
|
return q.set(e, {
|
|
2877
3053
|
type: "dev_tty",
|
|
2878
|
-
path:
|
|
3054
|
+
path: y
|
|
2879
3055
|
}), new DataView(T.buffer).setUint32(h, e, !0), i;
|
|
2880
3056
|
}
|
|
3057
|
+
if (y === "/dev/stdout") return new DataView(T.buffer).setUint32(h, 1, !0), i;
|
|
3058
|
+
if (y === "/dev/stderr") return new DataView(T.buffer).setUint32(h, 2, !0), i;
|
|
2881
3059
|
let w = W.stat(g), E = w !== null;
|
|
2882
3060
|
if (c & x && c & _ && E) return s;
|
|
2883
3061
|
if (c & v) {
|
|
@@ -2910,13 +3088,12 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2910
3088
|
if (!T || !W) return o;
|
|
2911
3089
|
let c = X(e, n.decode(new Uint8Array(T.buffer, r, a)));
|
|
2912
3090
|
if (!c) return o;
|
|
2913
|
-
let l = c.replace(/\/+/g, "/").replace(/\/$/, "") || "/";
|
|
2914
|
-
if (l === "/dev/null" || l === "/dev/zero" || l === "/dev/urandom" || l === "/dev/random" || l === "/dev/tty") {
|
|
3091
|
+
let l = c.replace(/\/+/g, "/").replace(/\/$/, "") || "/", d = W.stat(c);
|
|
3092
|
+
if (l === "/dev/null" || l === "/dev/zero" || l === "/dev/urandom" || l === "/dev/random" || l === "/dev/tty" || l === "/dev/stdin" || l === "/dev/stdout" || l === "/dev/stderr" || d && (d.isDevice || d.isCharacterDevice)) {
|
|
2915
3093
|
let e = new DataView(T.buffer);
|
|
2916
3094
|
for (let t = 0; t < 64; t++) e.setUint8(s + t, 0);
|
|
2917
3095
|
return e.setUint8(s + 16, m), e.setBigUint64(s + 24, 1n, !0), i;
|
|
2918
3096
|
}
|
|
2919
|
-
let d = W.stat(c);
|
|
2920
3097
|
if (!d) return u;
|
|
2921
3098
|
let f = new DataView(T.buffer);
|
|
2922
3099
|
for (let e = 0; e < 64; e++) f.setUint8(s + e, 0);
|
|
@@ -2926,6 +3103,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2926
3103
|
if (!T || !W) return o;
|
|
2927
3104
|
let a = X(e, n.decode(new Uint8Array(T.buffer, t, r)));
|
|
2928
3105
|
if (!a) return o;
|
|
3106
|
+
if (W.exists(a)) return s;
|
|
2929
3107
|
try {
|
|
2930
3108
|
return W.setFileByPath(a, {}, !0), i;
|
|
2931
3109
|
} catch {
|
|
@@ -3074,12 +3252,14 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
3074
3252
|
}
|
|
3075
3253
|
return a.setUint32(r, o, !0), i;
|
|
3076
3254
|
}
|
|
3077
|
-
return E.exports.asyncify_start_unwind(O), k = new Promise((e) => {
|
|
3078
|
-
let
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3255
|
+
return E.exports.asyncify_start_unwind(O), k = new Promise((e, t) => {
|
|
3256
|
+
let n = null;
|
|
3257
|
+
this._asyncifyReject = t;
|
|
3258
|
+
let r = () => {
|
|
3259
|
+
n && clearTimeout(n), A = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
|
|
3260
|
+
};
|
|
3261
|
+
A = r, this._pendingReadResolve = r, s !== Infinity && (n = setTimeout(() => {
|
|
3262
|
+
A = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
|
|
3083
3263
|
}, Math.max(1, s)));
|
|
3084
3264
|
}), a.setUint32(r, 0, !0), i;
|
|
3085
3265
|
}
|
|
@@ -3162,18 +3342,39 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
3162
3342
|
let i = E.exports._start || E.exports.__wasi_command || E.exports.main || E.exports.run;
|
|
3163
3343
|
if (i) try {
|
|
3164
3344
|
let e = i();
|
|
3165
|
-
for (e && typeof e.then == "function" && (e = await e); D && typeof E.exports.asyncify_get_state == "function" && E.exports.asyncify_get_state() === 1;)
|
|
3345
|
+
for (e && typeof e.then == "function" && (e = await e); D && typeof E.exports.asyncify_get_state == "function" && E.exports.asyncify_get_state() === 1;) {
|
|
3346
|
+
if (this._killed) {
|
|
3347
|
+
this.exitCode = 130;
|
|
3348
|
+
break;
|
|
3349
|
+
}
|
|
3350
|
+
if (E.exports.asyncify_stop_unwind(), k) {
|
|
3351
|
+
try {
|
|
3352
|
+
await k;
|
|
3353
|
+
} catch {
|
|
3354
|
+
if (this._killed) {
|
|
3355
|
+
this.exitCode = 130;
|
|
3356
|
+
break;
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
k = null;
|
|
3360
|
+
}
|
|
3361
|
+
if (this._killed) {
|
|
3362
|
+
this.exitCode = 130;
|
|
3363
|
+
break;
|
|
3364
|
+
}
|
|
3365
|
+
E.exports.asyncify_start_rewind(O), e = i(), e && typeof e.then == "function" && (e = await e);
|
|
3366
|
+
}
|
|
3166
3367
|
} catch (e) {
|
|
3167
|
-
(!e || !e._wasmExit) && (this.stdErr = `${this.script}: runtime error: ${e?.message || String(e)}`, this.exitCode = 1);
|
|
3368
|
+
this._killed ? this.exitCode = 130 : (!e || !e._wasmExit) && (this.stdErr = `${this.script}: runtime error: ${e?.message || String(e)}`, this.exitCode = 1);
|
|
3168
3369
|
}
|
|
3169
3370
|
else {
|
|
3170
3371
|
let e = Object.entries(E.exports).filter(([, e]) => typeof e == "function").map(([e]) => e), t = e.length > 0 ? ` (module is a library exporting: ${e.join(", ")})` : "";
|
|
3171
3372
|
this.stdErr = `${this.script}: no CLI entry point found (expected _start, main, or run)${t}`, this.exitCode = 1;
|
|
3172
3373
|
}
|
|
3173
3374
|
} catch (e) {
|
|
3174
|
-
(!e || !e._wasmExit) && (this.stdErr = `${this.script}: ${e?.message || String(e)}`, this.exitCode = 1);
|
|
3375
|
+
this._killed ? this.exitCode = 130 : (!e || !e._wasmExit) && (this.stdErr = `${this.script}: ${e?.message || String(e)}`, this.exitCode = 1);
|
|
3175
3376
|
} finally {
|
|
3176
|
-
I && this._exitAltScreen(),
|
|
3377
|
+
I && this._exitAltScreen(), M && (this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", M), this.stdin && typeof this.stdin.off == "function" && this.stdin.off("data", M)), this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", this._onStdinStreamData), j && (this.stdout && typeof this.stdout.off == "function" && this.stdout.off("resize", j), this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("resize", j)), this._externalKeyHandler = null;
|
|
3177
3378
|
for (let e of q.values()) Z(e);
|
|
3178
3379
|
}
|
|
3179
3380
|
z();
|
|
@@ -3288,13 +3489,15 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
3288
3489
|
usage: null,
|
|
3289
3490
|
options: [],
|
|
3290
3491
|
exports: [],
|
|
3291
|
-
wasiImports: []
|
|
3492
|
+
wasiImports: [],
|
|
3493
|
+
hasAsyncify: !1,
|
|
3494
|
+
isInteractive: !1
|
|
3292
3495
|
};
|
|
3293
3496
|
if (!(e instanceof Uint8Array) || e.length < 8) return t;
|
|
3294
3497
|
try {
|
|
3295
3498
|
if (typeof WebAssembly < "u" && WebAssembly.Module) {
|
|
3296
3499
|
let n = new WebAssembly.Module(e);
|
|
3297
|
-
t.exports = WebAssembly.Module.exports(n).filter((e) => e.kind === "function").map((e) => e.name), t.wasiImports = WebAssembly.Module.imports(n).filter((e) => e.module.startsWith("wasi_")).map((e) => e.name);
|
|
3500
|
+
t.exports = WebAssembly.Module.exports(n).filter((e) => e.kind === "function").map((e) => e.name), t.wasiImports = WebAssembly.Module.imports(n).filter((e) => e.module.startsWith("wasi_")).map((e) => e.name), t.hasAsyncify = t.exports.includes("asyncify_start_unwind") && t.exports.includes("asyncify_stop_unwind"), t.exports.includes("set_terminal_size") && (t.isInteractive = !0);
|
|
3298
3501
|
}
|
|
3299
3502
|
} catch {}
|
|
3300
3503
|
try {
|
|
@@ -3304,8 +3507,10 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
3304
3507
|
i >= 32 && i <= 126 || i === 9 || i === 10 ? r += String.fromCharCode(i) : (r.length >= 4 && n.push(r), r = "");
|
|
3305
3508
|
}
|
|
3306
3509
|
r.length >= 4 && n.push(r);
|
|
3307
|
-
let i =
|
|
3308
|
-
t.
|
|
3510
|
+
let i = n.join("\n");
|
|
3511
|
+
t.isInteractive || (i.includes("/dev/tty") || i.includes("\x1B[?1049h") || i.includes("smcup") || i.includes("xterm")) && (t.isInteractive = !0);
|
|
3512
|
+
let a = M(i, !0);
|
|
3513
|
+
t.usage = a.usage, t.options = a.options;
|
|
3309
3514
|
} catch {}
|
|
3310
3515
|
return t;
|
|
3311
3516
|
}
|
|
@@ -3329,6 +3534,18 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
3329
3534
|
get requiresFilesystem() {
|
|
3330
3535
|
return !0;
|
|
3331
3536
|
}
|
|
3537
|
+
get interactive() {
|
|
3538
|
+
return this._subCommand ? this._subCommand.interactive : this._isInteractive === void 0 ? !!(e && (e.interactive || e.wasm?.interactive) || this._inspectedWasm && this._inspectedWasm.isInteractive) : !!this._isInteractive;
|
|
3539
|
+
}
|
|
3540
|
+
get captureInput() {
|
|
3541
|
+
return this.interactive;
|
|
3542
|
+
}
|
|
3543
|
+
kill(e = "SIGINT") {
|
|
3544
|
+
this._subCommand && typeof this._subCommand.kill == "function" && this._subCommand.kill(e), super.kill(e);
|
|
3545
|
+
}
|
|
3546
|
+
onInput(e) {
|
|
3547
|
+
this._subCommand && typeof this._subCommand.onInput == "function" && this._subCommand.onInput(e);
|
|
3548
|
+
}
|
|
3332
3549
|
async run() {
|
|
3333
3550
|
let n = [...this.arguments || []], r = n.includes("--help") || n.includes("-h"), a = !r && (n.includes("--version") || n.includes("-V") || n.includes("-v"));
|
|
3334
3551
|
this._inspectedWasm = null, this._persistedWasmBytes = e.wasmPath ? k(this.context && this.context.fs || this.fs, e.wasmPath) : null, r && this._persistedWasmBytes && this._persistedWasmBytes.byteLength > 0 && (this._inspectedWasm = N(this._persistedWasmBytes));
|
|
@@ -3420,7 +3637,12 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
3420
3637
|
}
|
|
3421
3638
|
async _runRawWasmBytes(t, n) {
|
|
3422
3639
|
let r = new T(i, n, this.context);
|
|
3423
|
-
r.script = i, r.arguments = n, r.context = this.context, r.fs = this.fs, r._pkgMeta = e, this.stdin !== void 0 && (r.stdin = this.stdin),
|
|
3640
|
+
r.script = i, r.arguments = n, r.context = this.context, r.fs = this.fs, r._pkgMeta = e, this.stdin !== void 0 && (r.stdin = this.stdin), this._subCommand = r;
|
|
3641
|
+
try {
|
|
3642
|
+
await r._runWasm(t);
|
|
3643
|
+
} finally {
|
|
3644
|
+
this._subCommand = null;
|
|
3645
|
+
}
|
|
3424
3646
|
for (let e of r.result.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
|
|
3425
3647
|
this.exitCode = r.result.getExitCode();
|
|
3426
3648
|
}
|