brsh 3.8.1 → 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 +7 -0
- package/Readme.md +4 -6
- package/dist/shell.es.js +360 -140
- 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 +345 -137
- 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 +63 -21
- 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/WasmCommand.js +129 -20
- 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/dist/wbt.es.js
CHANGED
|
@@ -1160,7 +1160,13 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
1160
1160
|
}), this._onStdinStreamData = (e) => {
|
|
1161
1161
|
if (!this.captureInput) return;
|
|
1162
1162
|
let t = a(e);
|
|
1163
|
-
for (let e of t)
|
|
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
|
+
}
|
|
1164
1170
|
}, this.stdinStream.on("data", this._onStdinStreamData);
|
|
1165
1171
|
}
|
|
1166
1172
|
get name() {
|
|
@@ -1169,10 +1175,30 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
1169
1175
|
run() {
|
|
1170
1176
|
return Promise.reject("Command not implemented...");
|
|
1171
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
|
+
}
|
|
1172
1189
|
runCommand() {
|
|
1173
|
-
return Promise
|
|
1174
|
-
|
|
1175
|
-
|
|
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
|
+
});
|
|
1176
1202
|
});
|
|
1177
1203
|
}
|
|
1178
1204
|
onInput(e) {}
|
|
@@ -1211,6 +1237,9 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
1211
1237
|
onInput(e) {
|
|
1212
1238
|
this.sandbox && this.sandbox.onInput(e);
|
|
1213
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
|
+
}
|
|
1214
1243
|
run() {
|
|
1215
1244
|
let e = this.context && this.context.fs || this.fs, t = e && e.isRealFilesystem ? { useRealFilesystem: !0 } : {
|
|
1216
1245
|
filesystem: e && e.getRaw() || {},
|
|
@@ -1609,7 +1638,8 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
1609
1638
|
"isRealFilesystem",
|
|
1610
1639
|
"isSymlink",
|
|
1611
1640
|
"readSymlink",
|
|
1612
|
-
"createSymlink"
|
|
1641
|
+
"createSymlink",
|
|
1642
|
+
"setTtyDevice"
|
|
1613
1643
|
]), r = class {
|
|
1614
1644
|
isReadable(e) {
|
|
1615
1645
|
let t = this.getMode(e);
|
|
@@ -1663,8 +1693,16 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
1663
1693
|
constructor(e) {
|
|
1664
1694
|
this.target = e;
|
|
1665
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
|
+
}
|
|
1666
1704
|
};
|
|
1667
|
-
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;
|
|
1668
1706
|
}));
|
|
1669
1707
|
//#endregion
|
|
1670
1708
|
//#region node_modules/vite-plugin-node-polyfills/shims/process/dist/index.js
|
|
@@ -1774,6 +1812,9 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1774
1812
|
_exitAltScreen() {
|
|
1775
1813
|
this._inAltScreen && (this._inAltScreen = !1, this.stdinStream && this.stdinStream.setRawMode(!1), this.stdout && this.stdout.write("\x1B[?1049l\x1B[?25h"));
|
|
1776
1814
|
}
|
|
1815
|
+
kill(e = "SIGINT") {
|
|
1816
|
+
this._exitAltScreen(), super.kill(e);
|
|
1817
|
+
}
|
|
1777
1818
|
runCommand() {
|
|
1778
1819
|
return this.interactive && this._enterAltScreen(), super.runCommand().finally(() => {
|
|
1779
1820
|
this._exitAltScreen();
|
|
@@ -1782,33 +1823,34 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1782
1823
|
};
|
|
1783
1824
|
})), Y = /* @__PURE__ */ t(((e, t) => {
|
|
1784
1825
|
b(), q();
|
|
1785
|
-
var { BinaryFile: n, SymlinkRef: r } = O(),
|
|
1826
|
+
var { BinaryFile: n, SymlinkRef: r, DeviceFile: i } = O(), a = new Uint8Array([
|
|
1786
1827
|
66,
|
|
1787
1828
|
82,
|
|
1788
1829
|
70,
|
|
1789
1830
|
83
|
|
1790
|
-
]),
|
|
1791
|
-
function
|
|
1831
|
+
]), o = 2;
|
|
1832
|
+
function s(e) {
|
|
1792
1833
|
if (!e) return !1;
|
|
1793
1834
|
let t = e instanceof Uint8Array ? e : e instanceof ArrayBuffer || ArrayBuffer.isView(e) ? new Uint8Array(e.buffer || e, e.byteOffset || 0, e.byteLength) : null;
|
|
1794
|
-
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];
|
|
1795
1836
|
}
|
|
1796
|
-
function
|
|
1797
|
-
let
|
|
1798
|
-
let t = e instanceof Uint8Array ? e : new Uint8Array(e), n =
|
|
1799
|
-
return
|
|
1800
|
-
},
|
|
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) => {
|
|
1801
1842
|
if (e == null) return null;
|
|
1802
1843
|
if (e instanceof r) return { $l: e.target };
|
|
1844
|
+
if (e instanceof i) return null;
|
|
1803
1845
|
if (e instanceof Uint8Array || y !== void 0 && y.isBuffer(e)) {
|
|
1804
|
-
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);
|
|
1805
1847
|
return { $b: [
|
|
1806
1848
|
i,
|
|
1807
1849
|
a,
|
|
1808
1850
|
r
|
|
1809
1851
|
] };
|
|
1810
1852
|
}
|
|
1811
|
-
if (typeof e == "function") return n.commandsBundle || (
|
|
1853
|
+
if (typeof e == "function") return n.commandsBundle || (d[t] = e.toString()), { $c: t };
|
|
1812
1854
|
if (typeof e == "string") {
|
|
1813
1855
|
if (e.startsWith("data:")) {
|
|
1814
1856
|
let t = e.indexOf(";"), n = e.indexOf(",", t);
|
|
@@ -1820,7 +1862,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1820
1862
|
a = new Uint8Array(e.length);
|
|
1821
1863
|
for (let t = 0; t < e.length; t++) a[t] = e.charCodeAt(t);
|
|
1822
1864
|
}
|
|
1823
|
-
let [o, s] =
|
|
1865
|
+
let [o, s] = u(a);
|
|
1824
1866
|
return { $b: [
|
|
1825
1867
|
o,
|
|
1826
1868
|
s,
|
|
@@ -1828,66 +1870,67 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1828
1870
|
] };
|
|
1829
1871
|
}
|
|
1830
1872
|
}
|
|
1831
|
-
let [t, n] =
|
|
1873
|
+
let [t, n] = u(s.encode(e));
|
|
1832
1874
|
return { $t: [t, n] };
|
|
1833
1875
|
}
|
|
1834
1876
|
if (typeof e == "object") {
|
|
1835
1877
|
let n = {};
|
|
1836
1878
|
for (let r of Object.keys(e)) {
|
|
1837
|
-
let i = `${t}/${r}`, a =
|
|
1879
|
+
let i = `${t}/${r}`, a = f(e[r], i);
|
|
1838
1880
|
a !== null && (n[r] = a);
|
|
1839
1881
|
}
|
|
1840
1882
|
return { $d: n };
|
|
1841
1883
|
}
|
|
1842
1884
|
return null;
|
|
1843
|
-
},
|
|
1844
|
-
n.commandsBundle && typeof n.commandsBundle == "string" && (
|
|
1845
|
-
let
|
|
1846
|
-
v:
|
|
1847
|
-
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,
|
|
1848
1890
|
permissions: Object.assign({}, t)
|
|
1849
1891
|
};
|
|
1850
|
-
|
|
1851
|
-
let
|
|
1852
|
-
|
|
1853
|
-
let
|
|
1854
|
-
|
|
1855
|
-
let
|
|
1856
|
-
for (let e of
|
|
1857
|
-
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;
|
|
1858
1900
|
}
|
|
1859
|
-
function
|
|
1860
|
-
let
|
|
1861
|
-
if (!
|
|
1862
|
-
let
|
|
1863
|
-
if (
|
|
1864
|
-
let
|
|
1865
|
-
if (
|
|
1866
|
-
let
|
|
1867
|
-
if (Array.isArray(
|
|
1868
|
-
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));
|
|
1869
1911
|
try {
|
|
1870
1912
|
let e = Function(n)();
|
|
1871
|
-
e && typeof e == "object" && Object.assign(
|
|
1913
|
+
e && typeof e == "object" && Object.assign(h, e);
|
|
1872
1914
|
} catch {}
|
|
1873
1915
|
}
|
|
1874
|
-
let
|
|
1916
|
+
let g = (e) => {
|
|
1875
1917
|
if (!e || typeof e != "object") return e;
|
|
1876
1918
|
if ("$t" in e) {
|
|
1877
1919
|
let [t, n] = e.$t;
|
|
1878
|
-
return
|
|
1920
|
+
return d.decode(m.subarray(t, t + n));
|
|
1879
1921
|
}
|
|
1880
1922
|
if ("$b" in e) {
|
|
1881
1923
|
let [t, r, i] = e.$b;
|
|
1882
|
-
return new n(
|
|
1924
|
+
return new n(m.slice(t, t + r).buffer, i || "application/octet-stream");
|
|
1883
1925
|
}
|
|
1884
1926
|
if ("$l" in e) return new r(e.$l);
|
|
1927
|
+
if ("$dev" in e) return new i(e.$dev);
|
|
1885
1928
|
if ("$c" in e) {
|
|
1886
1929
|
let t = e.$c;
|
|
1887
|
-
if (
|
|
1888
|
-
if (
|
|
1930
|
+
if (h[t]) return h[t];
|
|
1931
|
+
if (p.inlineCommands && p.inlineCommands[t]) try {
|
|
1889
1932
|
let e = T(), n = J();
|
|
1890
|
-
return Function("Command", "InteractiveCommand", `return (${
|
|
1933
|
+
return Function("Command", "InteractiveCommand", `return (${p.inlineCommands[t]});`)(e, n);
|
|
1891
1934
|
} catch {
|
|
1892
1935
|
return null;
|
|
1893
1936
|
}
|
|
@@ -1896,7 +1939,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1896
1939
|
if ("$d" in e) {
|
|
1897
1940
|
let t = {};
|
|
1898
1941
|
for (let [n, r] of Object.entries(e.$d)) {
|
|
1899
|
-
let e =
|
|
1942
|
+
let e = g(r);
|
|
1900
1943
|
e !== null && (t[n] = e);
|
|
1901
1944
|
}
|
|
1902
1945
|
return t;
|
|
@@ -1904,16 +1947,16 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1904
1947
|
return e;
|
|
1905
1948
|
};
|
|
1906
1949
|
return {
|
|
1907
|
-
filesystem:
|
|
1908
|
-
permissions: Object.assign({},
|
|
1950
|
+
filesystem: g(p.tree) || {},
|
|
1951
|
+
permissions: Object.assign({}, p.permissions || {})
|
|
1909
1952
|
};
|
|
1910
1953
|
}
|
|
1911
|
-
function
|
|
1954
|
+
function u(e) {
|
|
1912
1955
|
if (!e) return !1;
|
|
1913
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;
|
|
1914
1957
|
return !!(t && t.byteLength >= 2 && t[0] === 31 && t[1] === 139);
|
|
1915
1958
|
}
|
|
1916
|
-
async function
|
|
1959
|
+
async function d(e) {
|
|
1917
1960
|
if (typeof DecompressionStream < "u" && typeof Response < "u") {
|
|
1918
1961
|
let t = new DecompressionStream("gzip"), n = new Blob([e]).stream().pipeThrough(t), r = await new Response(n).arrayBuffer();
|
|
1919
1962
|
return new Uint8Array(r);
|
|
@@ -1924,36 +1967,36 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1924
1967
|
}
|
|
1925
1968
|
throw Error("Gzip decompression is not supported in this environment");
|
|
1926
1969
|
}
|
|
1927
|
-
function
|
|
1928
|
-
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;
|
|
1929
1972
|
}
|
|
1930
|
-
async function
|
|
1973
|
+
async function p(e, t = {}) {
|
|
1931
1974
|
if (!e) return {
|
|
1932
1975
|
filesystem: {},
|
|
1933
1976
|
permissions: t
|
|
1934
1977
|
};
|
|
1935
|
-
if (typeof e.then == "function") return
|
|
1978
|
+
if (typeof e.then == "function") return p(await e, t);
|
|
1936
1979
|
if (typeof e.arrayBuffer == "function") {
|
|
1937
1980
|
let n = await e.arrayBuffer();
|
|
1938
|
-
return
|
|
1981
|
+
return p(new Uint8Array(n), t);
|
|
1939
1982
|
}
|
|
1940
1983
|
if (typeof e == "string") {
|
|
1941
1984
|
if (!/^https?:\/\//i.test(e) && K !== void 0 && typeof K.getBuiltinModule == "function" && typeof window > "u") try {
|
|
1942
1985
|
let n = K.getBuiltinModule("fs");
|
|
1943
1986
|
if (n && n.existsSync(e)) {
|
|
1944
1987
|
let r = await n.promises.readFile(e);
|
|
1945
|
-
return
|
|
1988
|
+
return p(new Uint8Array(r.buffer, r.byteOffset, r.byteLength), t);
|
|
1946
1989
|
}
|
|
1947
1990
|
} catch {}
|
|
1948
1991
|
let n = await fetch(e);
|
|
1949
1992
|
if (!n.ok) throw Error(`Failed to load filesystem from ${e}: HTTP ${n.status}`);
|
|
1950
1993
|
let r = await n.arrayBuffer();
|
|
1951
|
-
return
|
|
1994
|
+
return p(new Uint8Array(r), t);
|
|
1952
1995
|
}
|
|
1953
1996
|
if (e instanceof ArrayBuffer || ArrayBuffer.isView(e)) {
|
|
1954
1997
|
let n = e instanceof Uint8Array ? e : e instanceof ArrayBuffer ? new Uint8Array(e) : new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
|
|
1955
|
-
if (
|
|
1956
|
-
let e =
|
|
1998
|
+
if (u(n) && (n = await d(n)), s(n)) {
|
|
1999
|
+
let e = l(n);
|
|
1957
2000
|
return {
|
|
1958
2001
|
filesystem: e.filesystem,
|
|
1959
2002
|
permissions: Object.assign({}, e.permissions, t)
|
|
@@ -1980,7 +2023,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1980
2023
|
};
|
|
1981
2024
|
}
|
|
1982
2025
|
}
|
|
1983
|
-
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)) : {
|
|
1984
2027
|
filesystem: e.filesystem,
|
|
1985
2028
|
permissions: Object.assign({}, e.permissions, t)
|
|
1986
2029
|
} : {
|
|
@@ -1989,33 +2032,33 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
1989
2032
|
};
|
|
1990
2033
|
}
|
|
1991
2034
|
t.exports = {
|
|
1992
|
-
MAGIC:
|
|
1993
|
-
FORMAT_VERSION:
|
|
1994
|
-
isBinaryContainer:
|
|
1995
|
-
isGzipBytes:
|
|
1996
|
-
isAsyncFilesystemSource:
|
|
1997
|
-
resolveFilesystemSource:
|
|
1998
|
-
serializeBinaryFilesystem:
|
|
1999
|
-
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,
|
|
2000
2043
|
FilesystemStorage: class {
|
|
2001
2044
|
static async save(e, t = "brsh-rootfs") {
|
|
2002
|
-
let n = e.context ? e.context.fs : e, r =
|
|
2045
|
+
let n = e.context ? e.context.fs : e, r = c(n.getRaw(), n.getRawPermissions());
|
|
2003
2046
|
return typeof indexedDB < "u" && await this._idbPut(t, r), r;
|
|
2004
2047
|
}
|
|
2005
2048
|
static async load(e = "brsh-rootfs") {
|
|
2006
|
-
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);
|
|
2007
2050
|
if (typeof indexedDB < "u" && typeof e == "string") {
|
|
2008
2051
|
let t = await this._idbGet(e);
|
|
2009
|
-
if (t &&
|
|
2052
|
+
if (t && s(t)) return l(t);
|
|
2010
2053
|
}
|
|
2011
2054
|
return null;
|
|
2012
2055
|
}
|
|
2013
2056
|
static async loadOrFetch(e = "brsh-rootfs", t = {}) {
|
|
2014
|
-
return await this.load(e) ||
|
|
2057
|
+
return await this.load(e) || p(t);
|
|
2015
2058
|
}
|
|
2016
2059
|
static createAutoSave(e = "brsh-rootfs", t = null) {
|
|
2017
2060
|
return (n, r) => {
|
|
2018
|
-
let i =
|
|
2061
|
+
let i = c(n, r);
|
|
2019
2062
|
typeof indexedDB < "u" && this._idbPut(e, i).catch(() => {}), typeof t == "function" && t(i, n, r);
|
|
2020
2063
|
};
|
|
2021
2064
|
}
|
|
@@ -2053,11 +2096,11 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2053
2096
|
};
|
|
2054
2097
|
})), X = /* @__PURE__ */ t(((e, t) => {
|
|
2055
2098
|
b();
|
|
2056
|
-
var n = O(), { BinaryFile: r, SymlinkRef: i } = n;
|
|
2057
|
-
function
|
|
2099
|
+
var n = O(), { BinaryFile: r, SymlinkRef: i, DeviceFile: a } = n;
|
|
2100
|
+
function o(e) {
|
|
2058
2101
|
for (let t of Object.keys(e)) {
|
|
2059
2102
|
let n = e[t];
|
|
2060
|
-
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);
|
|
2061
2104
|
else if (typeof n == "string" && n.startsWith("data:")) {
|
|
2062
2105
|
let i = n.indexOf(";"), a = n.indexOf(",", i);
|
|
2063
2106
|
if (i !== -1 && a !== -1 && n.slice(i + 1, a) === "base64") {
|
|
@@ -2082,7 +2125,43 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2082
2125
|
let { deserializeBinaryFilesystem: e } = Y(), r = e(t);
|
|
2083
2126
|
t = r.filesystem, n = Object.assign({}, r.permissions, n);
|
|
2084
2127
|
}
|
|
2085
|
-
|
|
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");
|
|
2086
2165
|
}
|
|
2087
2166
|
toBinaryContainer(e = {}) {
|
|
2088
2167
|
let { serializeBinaryFilesystem: t } = Y();
|
|
@@ -2094,10 +2173,11 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2094
2173
|
}
|
|
2095
2174
|
getFileByPath(e) {
|
|
2096
2175
|
let t = this._resolveByAbsolutePath(this._pathToAbsolute(e), !0);
|
|
2097
|
-
return t == null || !this.isReadable(e) ? null : t;
|
|
2176
|
+
return t == null || !this.isReadable(e) ? null : t instanceof a ? t.read() : t;
|
|
2098
2177
|
}
|
|
2099
2178
|
_getFileRaw(e) {
|
|
2100
|
-
|
|
2179
|
+
let t = this._getFileByAbsolutePath(this._pathToAbsolute(e));
|
|
2180
|
+
return t instanceof a ? t.read() : t;
|
|
2101
2181
|
}
|
|
2102
2182
|
exists(e) {
|
|
2103
2183
|
return this._resolveByAbsolutePath(this._pathToAbsolute(e), !0) != null;
|
|
@@ -2119,13 +2199,25 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2119
2199
|
isFile: !1,
|
|
2120
2200
|
isCommand: !1,
|
|
2121
2201
|
isBinary: !1,
|
|
2122
|
-
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
|
|
2123
2213
|
} : {
|
|
2124
2214
|
isDirectory: t.constructor === Object,
|
|
2125
2215
|
isFile: typeof t == "string" || t instanceof Uint8Array,
|
|
2126
2216
|
isCommand: typeof t == "function",
|
|
2127
2217
|
isBinary: t instanceof Uint8Array,
|
|
2128
|
-
isSymlink: !1
|
|
2218
|
+
isSymlink: !1,
|
|
2219
|
+
isDevice: !1,
|
|
2220
|
+
isCharacterDevice: !1
|
|
2129
2221
|
};
|
|
2130
2222
|
}
|
|
2131
2223
|
_pathToAbsolute(e) {
|
|
@@ -2143,9 +2235,13 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2143
2235
|
return this._pathToAbsolute(e);
|
|
2144
2236
|
}
|
|
2145
2237
|
setFileByPath(e, t, n = !1) {
|
|
2146
|
-
let r = this._pathToAbsolute(e);
|
|
2147
|
-
if (
|
|
2238
|
+
let r = this._pathToAbsolute(e), i = this._getFileByAbsolutePath(r);
|
|
2239
|
+
if (i != null) {
|
|
2148
2240
|
if (!this.isWritable(e)) throw Error("Permission denied");
|
|
2241
|
+
if (i instanceof a) {
|
|
2242
|
+
i.write(t), this._triggerChange();
|
|
2243
|
+
return;
|
|
2244
|
+
}
|
|
2149
2245
|
} else {
|
|
2150
2246
|
let e = r.split("/");
|
|
2151
2247
|
e.pop();
|
|
@@ -2161,28 +2257,54 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2161
2257
|
_setFileByAbsolutePath(e, t, n = !0) {
|
|
2162
2258
|
let r = e.split("/");
|
|
2163
2259
|
r.shift();
|
|
2164
|
-
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 = [];
|
|
2165
2279
|
for (let e of r) {
|
|
2166
|
-
if (
|
|
2280
|
+
if (c.push(e), !Object.prototype.hasOwnProperty.call(s, e)) {
|
|
2167
2281
|
if (!n) throw Error(`${e}: No such file or directory`);
|
|
2168
|
-
|
|
2282
|
+
s[e] = {};
|
|
2169
2283
|
}
|
|
2170
|
-
let t =
|
|
2284
|
+
let t = s[e];
|
|
2171
2285
|
if (t instanceof i) {
|
|
2172
|
-
let n = "/" +
|
|
2286
|
+
let n = "/" + c.slice(0, -1).join("/"), r = t.target.startsWith("/") ? this._traverseComplexAbsolutePath(t.target) : this._traverseComplexAbsolutePath(n + "/" + t.target);
|
|
2173
2287
|
if (t = this._resolveByAbsolutePath(r, !0), typeof t != "object" || !t || t instanceof i) throw Error(`${e}: Not a directory`);
|
|
2174
2288
|
}
|
|
2175
|
-
|
|
2289
|
+
s = t;
|
|
2176
2290
|
}
|
|
2177
|
-
o
|
|
2291
|
+
if (s[o] instanceof a) {
|
|
2292
|
+
s[o].write(t);
|
|
2293
|
+
return;
|
|
2294
|
+
}
|
|
2295
|
+
s[o] = t;
|
|
2178
2296
|
}
|
|
2179
2297
|
_resolveByAbsolutePath(e, t = !0, n = 0) {
|
|
2180
2298
|
if (n > 10) return null;
|
|
2181
2299
|
let r = e.split("/");
|
|
2182
|
-
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();
|
|
2183
2301
|
let a = this.fileSystem, o = [];
|
|
2184
2302
|
for (let e = 0; e < r.length; e++) {
|
|
2185
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
|
+
}
|
|
2186
2308
|
if (typeof a != "object" || !a || a instanceof i || !Object.prototype.hasOwnProperty.call(a, s)) return null;
|
|
2187
2309
|
if (a = a[s], o.push(s), a instanceof i && (!c || t)) {
|
|
2188
2310
|
let e = "/" + o.slice(0, -1).join("/"), t = a.target.startsWith("/") ? this._traverseComplexAbsolutePath(a.target) : this._traverseComplexAbsolutePath(e + "/" + a.target);
|
|
@@ -2193,7 +2315,16 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2193
2315
|
}
|
|
2194
2316
|
_getFileByAbsolutePath(e) {
|
|
2195
2317
|
let t = e.split("/");
|
|
2196
|
-
|
|
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);
|
|
2197
2328
|
}
|
|
2198
2329
|
deleteFileByPath(e) {
|
|
2199
2330
|
let t = this._pathToAbsolute(e), n = t.split("/");
|
|
@@ -2211,6 +2342,16 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2211
2342
|
t.shift(), t[t.length - 1] === "" && t.pop();
|
|
2212
2343
|
let n = t.pop();
|
|
2213
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;
|
|
2214
2355
|
let r = this.fileSystem, a = [];
|
|
2215
2356
|
for (let e of t) {
|
|
2216
2357
|
if (a.push(e), !Object.prototype.hasOwnProperty.call(r, e)) return;
|
|
@@ -2227,7 +2368,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2227
2368
|
let t = this._pathToAbsolute(e);
|
|
2228
2369
|
if (this.permissions[t] !== void 0) return this.permissions[t];
|
|
2229
2370
|
let n = this._resolveByAbsolutePath(t, !0);
|
|
2230
|
-
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;
|
|
2231
2372
|
}
|
|
2232
2373
|
setMode(e, t) {
|
|
2233
2374
|
let n = this._pathToAbsolute(e);
|
|
@@ -2235,7 +2376,12 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2235
2376
|
}
|
|
2236
2377
|
getSize(e) {
|
|
2237
2378
|
let t = this._pathToAbsolute(e), n = this._resolveByAbsolutePath(t, !0);
|
|
2238
|
-
|
|
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;
|
|
2239
2385
|
}
|
|
2240
2386
|
getRawPermissions() {
|
|
2241
2387
|
return Object.assign({}, this.permissions);
|
|
@@ -2447,15 +2593,27 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2447
2593
|
return !0;
|
|
2448
2594
|
}
|
|
2449
2595
|
get interactive() {
|
|
2450
|
-
|
|
2451
|
-
if (this._isInteractive !== void 0) return !!this._isInteractive;
|
|
2452
|
-
if (this._pkgMeta && this._pkgMeta.interactive !== void 0) return !!this._pkgMeta.interactive;
|
|
2453
|
-
let e = (this.script || this.name || "").toLowerCase();
|
|
2454
|
-
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;
|
|
2455
2597
|
}
|
|
2456
2598
|
get captureInput() {
|
|
2457
2599
|
return this.interactive;
|
|
2458
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
|
+
}
|
|
2459
2617
|
_enterAltScreen() {
|
|
2460
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"));
|
|
2461
2619
|
}
|
|
@@ -2518,22 +2676,26 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2518
2676
|
_loadBytes(e, t) {
|
|
2519
2677
|
let n = this.context && this.context.fs || this.fs;
|
|
2520
2678
|
if (!n) return Promise.reject(/* @__PURE__ */ Error(`${e}: Filesystem is not available`));
|
|
2679
|
+
let r;
|
|
2521
2680
|
if (n.isRealFilesystem && t) try {
|
|
2522
|
-
let
|
|
2523
|
-
|
|
2524
|
-
bytes:
|
|
2525
|
-
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)
|
|
2526
2685
|
});
|
|
2527
2686
|
} catch (t) {
|
|
2528
2687
|
return Promise.reject(/* @__PURE__ */ Error(`${e}: ${t.message}`));
|
|
2529
2688
|
}
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
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));
|
|
2537
2699
|
}
|
|
2538
2700
|
_isWat(e, t) {
|
|
2539
2701
|
return e.endsWith(".wat") ? !0 : t.length > 0 && t[0] === 40;
|
|
@@ -2575,7 +2737,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2575
2737
|
1: "",
|
|
2576
2738
|
2: ""
|
|
2577
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 = () => {
|
|
2578
|
-
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));
|
|
2579
2741
|
}, R = (e, n) => {
|
|
2580
2742
|
if (I && (e === 1 || e === 2)) {
|
|
2581
2743
|
if (e === 1 && this.stdout) {
|
|
@@ -2732,8 +2894,8 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2732
2894
|
}
|
|
2733
2895
|
return s.setUint32(r, e, !0), i;
|
|
2734
2896
|
}
|
|
2735
|
-
return o ? (s.setUint32(r, 0, !0), a) : (E.exports.asyncify_start_unwind(O), k = new Promise((e) => {
|
|
2736
|
-
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;
|
|
2737
2899
|
}), s.setUint32(r, 0, !0), i);
|
|
2738
2900
|
}
|
|
2739
2901
|
if (B.length > 0) {
|
|
@@ -2884,14 +3046,16 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2884
3046
|
path: y
|
|
2885
3047
|
}), new DataView(T.buffer).setUint32(h, e, !0), i;
|
|
2886
3048
|
}
|
|
2887
|
-
if (y === "/dev/tty") {
|
|
3049
|
+
if (y === "/dev/tty" || y === "/dev/stdin") {
|
|
2888
3050
|
L();
|
|
2889
3051
|
let e = K++;
|
|
2890
3052
|
return q.set(e, {
|
|
2891
3053
|
type: "dev_tty",
|
|
2892
|
-
path:
|
|
3054
|
+
path: y
|
|
2893
3055
|
}), new DataView(T.buffer).setUint32(h, e, !0), i;
|
|
2894
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;
|
|
2895
3059
|
let w = W.stat(g), E = w !== null;
|
|
2896
3060
|
if (c & x && c & _ && E) return s;
|
|
2897
3061
|
if (c & v) {
|
|
@@ -2924,13 +3088,12 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2924
3088
|
if (!T || !W) return o;
|
|
2925
3089
|
let c = X(e, n.decode(new Uint8Array(T.buffer, r, a)));
|
|
2926
3090
|
if (!c) return o;
|
|
2927
|
-
let l = c.replace(/\/+/g, "/").replace(/\/$/, "") || "/";
|
|
2928
|
-
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)) {
|
|
2929
3093
|
let e = new DataView(T.buffer);
|
|
2930
3094
|
for (let t = 0; t < 64; t++) e.setUint8(s + t, 0);
|
|
2931
3095
|
return e.setUint8(s + 16, m), e.setBigUint64(s + 24, 1n, !0), i;
|
|
2932
3096
|
}
|
|
2933
|
-
let d = W.stat(c);
|
|
2934
3097
|
if (!d) return u;
|
|
2935
3098
|
let f = new DataView(T.buffer);
|
|
2936
3099
|
for (let e = 0; e < 64; e++) f.setUint8(s + e, 0);
|
|
@@ -2940,6 +3103,7 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
2940
3103
|
if (!T || !W) return o;
|
|
2941
3104
|
let a = X(e, n.decode(new Uint8Array(T.buffer, t, r)));
|
|
2942
3105
|
if (!a) return o;
|
|
3106
|
+
if (W.exists(a)) return s;
|
|
2943
3107
|
try {
|
|
2944
3108
|
return W.setFileByPath(a, {}, !0), i;
|
|
2945
3109
|
} catch {
|
|
@@ -3088,12 +3252,14 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
3088
3252
|
}
|
|
3089
3253
|
return a.setUint32(r, o, !0), i;
|
|
3090
3254
|
}
|
|
3091
|
-
return E.exports.asyncify_start_unwind(O), k = new Promise((e) => {
|
|
3092
|
-
let
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
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();
|
|
3097
3263
|
}, Math.max(1, s)));
|
|
3098
3264
|
}), a.setUint32(r, 0, !0), i;
|
|
3099
3265
|
}
|
|
@@ -3176,16 +3342,37 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
3176
3342
|
let i = E.exports._start || E.exports.__wasi_command || E.exports.main || E.exports.run;
|
|
3177
3343
|
if (i) try {
|
|
3178
3344
|
let e = i();
|
|
3179
|
-
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
|
+
}
|
|
3180
3367
|
} catch (e) {
|
|
3181
|
-
(!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);
|
|
3182
3369
|
}
|
|
3183
3370
|
else {
|
|
3184
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(", ")})` : "";
|
|
3185
3372
|
this.stdErr = `${this.script}: no CLI entry point found (expected _start, main, or run)${t}`, this.exitCode = 1;
|
|
3186
3373
|
}
|
|
3187
3374
|
} catch (e) {
|
|
3188
|
-
(!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);
|
|
3189
3376
|
} finally {
|
|
3190
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;
|
|
3191
3378
|
for (let e of q.values()) Z(e);
|
|
@@ -3302,13 +3489,15 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
3302
3489
|
usage: null,
|
|
3303
3490
|
options: [],
|
|
3304
3491
|
exports: [],
|
|
3305
|
-
wasiImports: []
|
|
3492
|
+
wasiImports: [],
|
|
3493
|
+
hasAsyncify: !1,
|
|
3494
|
+
isInteractive: !1
|
|
3306
3495
|
};
|
|
3307
3496
|
if (!(e instanceof Uint8Array) || e.length < 8) return t;
|
|
3308
3497
|
try {
|
|
3309
3498
|
if (typeof WebAssembly < "u" && WebAssembly.Module) {
|
|
3310
3499
|
let n = new WebAssembly.Module(e);
|
|
3311
|
-
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);
|
|
3312
3501
|
}
|
|
3313
3502
|
} catch {}
|
|
3314
3503
|
try {
|
|
@@ -3318,8 +3507,10 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
3318
3507
|
i >= 32 && i <= 126 || i === 9 || i === 10 ? r += String.fromCharCode(i) : (r.length >= 4 && n.push(r), r = "");
|
|
3319
3508
|
}
|
|
3320
3509
|
r.length >= 4 && n.push(r);
|
|
3321
|
-
let i =
|
|
3322
|
-
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;
|
|
3323
3514
|
} catch {}
|
|
3324
3515
|
return t;
|
|
3325
3516
|
}
|
|
@@ -3343,6 +3534,18 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
3343
3534
|
get requiresFilesystem() {
|
|
3344
3535
|
return !0;
|
|
3345
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
|
+
}
|
|
3346
3549
|
async run() {
|
|
3347
3550
|
let n = [...this.arguments || []], r = n.includes("--help") || n.includes("-h"), a = !r && (n.includes("--version") || n.includes("-V") || n.includes("-v"));
|
|
3348
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));
|
|
@@ -3434,7 +3637,12 @@ var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
|
3434
3637
|
}
|
|
3435
3638
|
async _runRawWasmBytes(t, n) {
|
|
3436
3639
|
let r = new T(i, n, this.context);
|
|
3437
|
-
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
|
+
}
|
|
3438
3646
|
for (let e of r.result.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
|
|
3439
3647
|
this.exitCode = r.result.getExitCode();
|
|
3440
3648
|
}
|