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/shell.es.js
CHANGED
|
@@ -826,7 +826,8 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
826
826
|
"isRealFilesystem",
|
|
827
827
|
"isSymlink",
|
|
828
828
|
"readSymlink",
|
|
829
|
-
"createSymlink"
|
|
829
|
+
"createSymlink",
|
|
830
|
+
"setTtyDevice"
|
|
830
831
|
]), r = class {
|
|
831
832
|
isReadable(e) {
|
|
832
833
|
let t = this.getMode(e);
|
|
@@ -880,8 +881,16 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
880
881
|
constructor(e) {
|
|
881
882
|
this.target = e;
|
|
882
883
|
}
|
|
884
|
+
}, o = class {
|
|
885
|
+
constructor(e, t = {}) {
|
|
886
|
+
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;
|
|
887
|
+
}
|
|
888
|
+
toString() {
|
|
889
|
+
let e = this.read();
|
|
890
|
+
return e == null ? "" : typeof e == "string" ? e : e.toString();
|
|
891
|
+
}
|
|
883
892
|
};
|
|
884
|
-
t.exports = r, t.exports.BinaryFile = i, t.exports.SymlinkRef = a;
|
|
893
|
+
t.exports = r, t.exports.BinaryFile = i, t.exports.SymlinkRef = a, t.exports.DeviceFile = o;
|
|
885
894
|
}));
|
|
886
895
|
//#endregion
|
|
887
896
|
//#region node_modules/vite-plugin-node-polyfills/shims/process/dist/index.js
|
|
@@ -1240,10 +1249,24 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1240
1249
|
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;
|
|
1241
1250
|
}
|
|
1242
1251
|
write(e, t, n) {
|
|
1243
|
-
|
|
1252
|
+
if (e == null) return !0;
|
|
1253
|
+
typeof this._onWrite == "function" && this._onWrite(e), this._isPushing = !0;
|
|
1254
|
+
try {
|
|
1255
|
+
this.emit("data", this._formatChunk(e));
|
|
1256
|
+
} finally {
|
|
1257
|
+
this._isPushing = !1;
|
|
1258
|
+
}
|
|
1259
|
+
return typeof t == "function" ? t() : typeof n == "function" && n(), !0;
|
|
1244
1260
|
}
|
|
1245
1261
|
pushData(e) {
|
|
1246
|
-
e != null
|
|
1262
|
+
if (e != null) {
|
|
1263
|
+
this._isPushing = !0;
|
|
1264
|
+
try {
|
|
1265
|
+
this.emit("data", this._formatChunk(e));
|
|
1266
|
+
} finally {
|
|
1267
|
+
this._isPushing = !1;
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1247
1270
|
}
|
|
1248
1271
|
_formatChunk(e) {
|
|
1249
1272
|
return this._encoding ? typeof e == "string" ? e : e instanceof Uint8Array || y !== void 0 && y.isBuffer(e) ? new TextDecoder().decode(e) : String(e) : e;
|
|
@@ -1304,11 +1327,17 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1304
1327
|
columns: n,
|
|
1305
1328
|
rows: o,
|
|
1306
1329
|
onWrite: (e) => this.emit("stderr", e)
|
|
1307
|
-
}), this.
|
|
1330
|
+
}), this._onStdinStreamData = (e) => {
|
|
1308
1331
|
if (!this.captureInput) return;
|
|
1309
1332
|
let t = a(e);
|
|
1310
|
-
for (let e of t)
|
|
1311
|
-
|
|
1333
|
+
for (let e of t) {
|
|
1334
|
+
if (e === "^C") {
|
|
1335
|
+
this.kill("SIGINT");
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
!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);
|
|
1339
|
+
}
|
|
1340
|
+
}, this.stdinStream.on("data", this._onStdinStreamData);
|
|
1312
1341
|
}
|
|
1313
1342
|
get name() {
|
|
1314
1343
|
return "unnamed";
|
|
@@ -1316,10 +1345,30 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1316
1345
|
run() {
|
|
1317
1346
|
return Promise.reject("Command not implemented...");
|
|
1318
1347
|
}
|
|
1348
|
+
kill(e = "SIGINT") {
|
|
1349
|
+
let t = typeof e == "number" ? e : {
|
|
1350
|
+
SIGHUP: 129,
|
|
1351
|
+
SIGINT: 130,
|
|
1352
|
+
SIGQUIT: 131,
|
|
1353
|
+
SIGKILL: 137,
|
|
1354
|
+
SIGTERM: 143,
|
|
1355
|
+
SIGWINCH: 156
|
|
1356
|
+
}[e] || 130;
|
|
1357
|
+
this.exitCode = t, this.emit("signal", e), (e === "SIGINT" || e === "SIGTERM" || e === "SIGKILL" || e === "SIGQUIT") && (this.emit("abort"), this._abortController && this._abortController.abort());
|
|
1358
|
+
}
|
|
1319
1359
|
runCommand() {
|
|
1320
|
-
return Promise
|
|
1321
|
-
|
|
1322
|
-
|
|
1360
|
+
return new Promise((e) => {
|
|
1361
|
+
let t = !1, n = () => {
|
|
1362
|
+
t || (t = !0, e(this.result));
|
|
1363
|
+
};
|
|
1364
|
+
this.once("abort", n), Promise.resolve().then(() => this.run()).then((r) => {
|
|
1365
|
+
t || (t = !0, this.removeListener("abort", n), r && r.split(/\r?\n/).forEach((e) => this.stdOut = e), e(this.result));
|
|
1366
|
+
}).catch((r) => {
|
|
1367
|
+
if (!t) {
|
|
1368
|
+
if (t = !0, this.removeListener("abort", n), r && r.__type) throw r;
|
|
1369
|
+
r && (this.stdErr = r.message || r), this.result.getExitCode() === 0 && (this.exitCode = 127), e(this.result);
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1323
1372
|
});
|
|
1324
1373
|
}
|
|
1325
1374
|
onInput(e) {}
|
|
@@ -1360,6 +1409,9 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1360
1409
|
_exitAltScreen() {
|
|
1361
1410
|
this._inAltScreen && (this._inAltScreen = !1, this.stdinStream && this.stdinStream.setRawMode(!1), this.stdout && this.stdout.write("\x1B[?1049l\x1B[?25h"));
|
|
1362
1411
|
}
|
|
1412
|
+
kill(e = "SIGINT") {
|
|
1413
|
+
this._exitAltScreen(), super.kill(e);
|
|
1414
|
+
}
|
|
1363
1415
|
runCommand() {
|
|
1364
1416
|
return this.interactive && this._enterAltScreen(), super.runCommand().finally(() => {
|
|
1365
1417
|
this._exitAltScreen();
|
|
@@ -1368,33 +1420,34 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1368
1420
|
};
|
|
1369
1421
|
})), G = /* @__PURE__ */ t(((e, t) => {
|
|
1370
1422
|
b(), B();
|
|
1371
|
-
var { BinaryFile: n, SymlinkRef: r } = x(),
|
|
1423
|
+
var { BinaryFile: n, SymlinkRef: r, DeviceFile: i } = x(), a = new Uint8Array([
|
|
1372
1424
|
66,
|
|
1373
1425
|
82,
|
|
1374
1426
|
70,
|
|
1375
1427
|
83
|
|
1376
|
-
]),
|
|
1377
|
-
function
|
|
1428
|
+
]), o = 2;
|
|
1429
|
+
function s(e) {
|
|
1378
1430
|
if (!e) return !1;
|
|
1379
1431
|
let t = e instanceof Uint8Array ? e : e instanceof ArrayBuffer || ArrayBuffer.isView(e) ? new Uint8Array(e.buffer || e, e.byteOffset || 0, e.byteLength) : null;
|
|
1380
|
-
return !t || t.length < 12 ? !1 : t[0] ===
|
|
1432
|
+
return !t || t.length < 12 ? !1 : t[0] === a[0] && t[1] === a[1] && t[2] === a[2] && t[3] === a[3];
|
|
1381
1433
|
}
|
|
1382
|
-
function
|
|
1383
|
-
let
|
|
1384
|
-
let t = e instanceof Uint8Array ? e : new Uint8Array(e), n =
|
|
1385
|
-
return
|
|
1386
|
-
},
|
|
1434
|
+
function c(e = {}, t = {}, n = {}) {
|
|
1435
|
+
let s = new TextEncoder(), c = [], l = 0, u = (e) => {
|
|
1436
|
+
let t = e instanceof Uint8Array ? e : new Uint8Array(e), n = l;
|
|
1437
|
+
return c.push(t), l += t.byteLength, [n, t.byteLength];
|
|
1438
|
+
}, d = {}, f = (e, t) => {
|
|
1387
1439
|
if (e == null) return null;
|
|
1388
1440
|
if (e instanceof r) return { $l: e.target };
|
|
1441
|
+
if (e instanceof i) return null;
|
|
1389
1442
|
if (e instanceof Uint8Array || y !== void 0 && y.isBuffer(e)) {
|
|
1390
|
-
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] =
|
|
1443
|
+
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);
|
|
1391
1444
|
return { $b: [
|
|
1392
1445
|
i,
|
|
1393
1446
|
a,
|
|
1394
1447
|
r
|
|
1395
1448
|
] };
|
|
1396
1449
|
}
|
|
1397
|
-
if (typeof e == "function") return n.commandsBundle || (
|
|
1450
|
+
if (typeof e == "function") return n.commandsBundle || (d[t] = e.toString()), { $c: t };
|
|
1398
1451
|
if (typeof e == "string") {
|
|
1399
1452
|
if (e.startsWith("data:")) {
|
|
1400
1453
|
let t = e.indexOf(";"), n = e.indexOf(",", t);
|
|
@@ -1406,7 +1459,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1406
1459
|
a = new Uint8Array(e.length);
|
|
1407
1460
|
for (let t = 0; t < e.length; t++) a[t] = e.charCodeAt(t);
|
|
1408
1461
|
}
|
|
1409
|
-
let [o, s] =
|
|
1462
|
+
let [o, s] = u(a);
|
|
1410
1463
|
return { $b: [
|
|
1411
1464
|
o,
|
|
1412
1465
|
s,
|
|
@@ -1414,66 +1467,67 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1414
1467
|
] };
|
|
1415
1468
|
}
|
|
1416
1469
|
}
|
|
1417
|
-
let [t, n] =
|
|
1470
|
+
let [t, n] = u(s.encode(e));
|
|
1418
1471
|
return { $t: [t, n] };
|
|
1419
1472
|
}
|
|
1420
1473
|
if (typeof e == "object") {
|
|
1421
1474
|
let n = {};
|
|
1422
1475
|
for (let r of Object.keys(e)) {
|
|
1423
|
-
let i = `${t}/${r}`, a =
|
|
1476
|
+
let i = `${t}/${r}`, a = f(e[r], i);
|
|
1424
1477
|
a !== null && (n[r] = a);
|
|
1425
1478
|
}
|
|
1426
1479
|
return { $d: n };
|
|
1427
1480
|
}
|
|
1428
1481
|
return null;
|
|
1429
|
-
},
|
|
1430
|
-
n.commandsBundle && typeof n.commandsBundle == "string" && (
|
|
1431
|
-
let
|
|
1432
|
-
v:
|
|
1433
|
-
tree:
|
|
1482
|
+
}, p = f(e, "") || { $d: {} }, m = null;
|
|
1483
|
+
n.commandsBundle && typeof n.commandsBundle == "string" && (m = u(s.encode(n.commandsBundle)));
|
|
1484
|
+
let h = {
|
|
1485
|
+
v: o,
|
|
1486
|
+
tree: p,
|
|
1434
1487
|
permissions: Object.assign({}, t)
|
|
1435
1488
|
};
|
|
1436
|
-
|
|
1437
|
-
let
|
|
1438
|
-
|
|
1439
|
-
let
|
|
1440
|
-
|
|
1441
|
-
let
|
|
1442
|
-
for (let e of
|
|
1443
|
-
return
|
|
1444
|
-
}
|
|
1445
|
-
function
|
|
1446
|
-
let
|
|
1447
|
-
if (!
|
|
1448
|
-
let
|
|
1449
|
-
if (
|
|
1450
|
-
let
|
|
1451
|
-
if (
|
|
1452
|
-
let
|
|
1453
|
-
if (Array.isArray(
|
|
1454
|
-
let [e, t] =
|
|
1489
|
+
m && (h.commandsSlice = m), Object.keys(d).length > 0 && (h.inlineCommands = d);
|
|
1490
|
+
let g = s.encode(JSON.stringify(h)), _ = 12 + g.byteLength + l, v = new Uint8Array(_);
|
|
1491
|
+
v.set(a, 0);
|
|
1492
|
+
let b = new DataView(v.buffer, v.byteOffset, v.byteLength);
|
|
1493
|
+
b.setUint32(4, o, !0), b.setUint32(8, g.byteLength, !0), v.set(g, 12);
|
|
1494
|
+
let x = 12 + g.byteLength;
|
|
1495
|
+
for (let e of c) v.set(e, x), x += e.byteLength;
|
|
1496
|
+
return v;
|
|
1497
|
+
}
|
|
1498
|
+
function l(e, t = {}) {
|
|
1499
|
+
let a = e instanceof Uint8Array ? e : new Uint8Array(e.buffer || e, e.byteOffset || 0, e.byteLength);
|
|
1500
|
+
if (!s(a)) throw Error("Invalid BRFS binary container (missing BRFS magic header)");
|
|
1501
|
+
let c = new DataView(a.buffer, a.byteOffset, a.byteLength), l = c.getUint32(4, !0);
|
|
1502
|
+
if (l > o) throw Error(`Unsupported BRFS container version: ${l}`);
|
|
1503
|
+
let u = 12 + c.getUint32(8, !0);
|
|
1504
|
+
if (u > a.byteLength) throw Error("Corrupt BRFS binary container (header length exceeds buffer)");
|
|
1505
|
+
let d = new TextDecoder(), f = d.decode(a.subarray(12, u)), p = JSON.parse(f), m = a.subarray(u), h = Object.assign({}, t);
|
|
1506
|
+
if (Array.isArray(p.commandsSlice)) {
|
|
1507
|
+
let [e, t] = p.commandsSlice, n = d.decode(m.subarray(e, e + t));
|
|
1455
1508
|
try {
|
|
1456
1509
|
let e = Function(n)();
|
|
1457
|
-
e && typeof e == "object" && Object.assign(
|
|
1510
|
+
e && typeof e == "object" && Object.assign(h, e);
|
|
1458
1511
|
} catch {}
|
|
1459
1512
|
}
|
|
1460
|
-
let
|
|
1513
|
+
let g = (e) => {
|
|
1461
1514
|
if (!e || typeof e != "object") return e;
|
|
1462
1515
|
if ("$t" in e) {
|
|
1463
1516
|
let [t, n] = e.$t;
|
|
1464
|
-
return
|
|
1517
|
+
return d.decode(m.subarray(t, t + n));
|
|
1465
1518
|
}
|
|
1466
1519
|
if ("$b" in e) {
|
|
1467
1520
|
let [t, r, i] = e.$b;
|
|
1468
|
-
return new n(
|
|
1521
|
+
return new n(m.slice(t, t + r).buffer, i || "application/octet-stream");
|
|
1469
1522
|
}
|
|
1470
1523
|
if ("$l" in e) return new r(e.$l);
|
|
1524
|
+
if ("$dev" in e) return new i(e.$dev);
|
|
1471
1525
|
if ("$c" in e) {
|
|
1472
1526
|
let t = e.$c;
|
|
1473
|
-
if (
|
|
1474
|
-
if (
|
|
1527
|
+
if (h[t]) return h[t];
|
|
1528
|
+
if (p.inlineCommands && p.inlineCommands[t]) try {
|
|
1475
1529
|
let e = W(), n = ne();
|
|
1476
|
-
return Function("Command", "InteractiveCommand", `return (${
|
|
1530
|
+
return Function("Command", "InteractiveCommand", `return (${p.inlineCommands[t]});`)(e, n);
|
|
1477
1531
|
} catch {
|
|
1478
1532
|
return null;
|
|
1479
1533
|
}
|
|
@@ -1482,7 +1536,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1482
1536
|
if ("$d" in e) {
|
|
1483
1537
|
let t = {};
|
|
1484
1538
|
for (let [n, r] of Object.entries(e.$d)) {
|
|
1485
|
-
let e =
|
|
1539
|
+
let e = g(r);
|
|
1486
1540
|
e !== null && (t[n] = e);
|
|
1487
1541
|
}
|
|
1488
1542
|
return t;
|
|
@@ -1490,16 +1544,16 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1490
1544
|
return e;
|
|
1491
1545
|
};
|
|
1492
1546
|
return {
|
|
1493
|
-
filesystem:
|
|
1494
|
-
permissions: Object.assign({},
|
|
1547
|
+
filesystem: g(p.tree) || {},
|
|
1548
|
+
permissions: Object.assign({}, p.permissions || {})
|
|
1495
1549
|
};
|
|
1496
1550
|
}
|
|
1497
|
-
function
|
|
1551
|
+
function u(e) {
|
|
1498
1552
|
if (!e) return !1;
|
|
1499
1553
|
let t = e instanceof Uint8Array ? e : e instanceof ArrayBuffer ? new Uint8Array(e) : ArrayBuffer.isView(e) ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength) : null;
|
|
1500
1554
|
return !!(t && t.byteLength >= 2 && t[0] === 31 && t[1] === 139);
|
|
1501
1555
|
}
|
|
1502
|
-
async function
|
|
1556
|
+
async function d(e) {
|
|
1503
1557
|
if (typeof DecompressionStream < "u" && typeof Response < "u") {
|
|
1504
1558
|
let t = new DecompressionStream("gzip"), n = new Blob([e]).stream().pipeThrough(t), r = await new Response(n).arrayBuffer();
|
|
1505
1559
|
return new Uint8Array(r);
|
|
@@ -1510,36 +1564,36 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1510
1564
|
}
|
|
1511
1565
|
throw Error("Gzip decompression is not supported in this environment");
|
|
1512
1566
|
}
|
|
1513
|
-
function
|
|
1514
|
-
return e ? !!(typeof e == "string" || typeof e.then == "function" || typeof e.arrayBuffer == "function" ||
|
|
1567
|
+
function f(e) {
|
|
1568
|
+
return e ? !!(typeof e == "string" || typeof e.then == "function" || typeof e.arrayBuffer == "function" || u(e)) : !1;
|
|
1515
1569
|
}
|
|
1516
|
-
async function
|
|
1570
|
+
async function p(e, t = {}) {
|
|
1517
1571
|
if (!e) return {
|
|
1518
1572
|
filesystem: {},
|
|
1519
1573
|
permissions: t
|
|
1520
1574
|
};
|
|
1521
|
-
if (typeof e.then == "function") return
|
|
1575
|
+
if (typeof e.then == "function") return p(await e, t);
|
|
1522
1576
|
if (typeof e.arrayBuffer == "function") {
|
|
1523
1577
|
let n = await e.arrayBuffer();
|
|
1524
|
-
return
|
|
1578
|
+
return p(new Uint8Array(n), t);
|
|
1525
1579
|
}
|
|
1526
1580
|
if (typeof e == "string") {
|
|
1527
1581
|
if (!/^https?:\/\//i.test(e) && z !== void 0 && typeof z.getBuiltinModule == "function" && typeof window > "u") try {
|
|
1528
1582
|
let n = z.getBuiltinModule("fs");
|
|
1529
1583
|
if (n && n.existsSync(e)) {
|
|
1530
1584
|
let r = await n.promises.readFile(e);
|
|
1531
|
-
return
|
|
1585
|
+
return p(new Uint8Array(r.buffer, r.byteOffset, r.byteLength), t);
|
|
1532
1586
|
}
|
|
1533
1587
|
} catch {}
|
|
1534
1588
|
let n = await fetch(e);
|
|
1535
1589
|
if (!n.ok) throw Error(`Failed to load filesystem from ${e}: HTTP ${n.status}`);
|
|
1536
1590
|
let r = await n.arrayBuffer();
|
|
1537
|
-
return
|
|
1591
|
+
return p(new Uint8Array(r), t);
|
|
1538
1592
|
}
|
|
1539
1593
|
if (e instanceof ArrayBuffer || ArrayBuffer.isView(e)) {
|
|
1540
1594
|
let n = e instanceof Uint8Array ? e : e instanceof ArrayBuffer ? new Uint8Array(e) : new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
|
|
1541
|
-
if (
|
|
1542
|
-
let e =
|
|
1595
|
+
if (u(n) && (n = await d(n)), s(n)) {
|
|
1596
|
+
let e = l(n);
|
|
1543
1597
|
return {
|
|
1544
1598
|
filesystem: e.filesystem,
|
|
1545
1599
|
permissions: Object.assign({}, e.permissions, t)
|
|
@@ -1566,7 +1620,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1566
1620
|
};
|
|
1567
1621
|
}
|
|
1568
1622
|
}
|
|
1569
|
-
return typeof e == "object" && e.filesystem && typeof e.permissions == "object" ?
|
|
1623
|
+
return typeof e == "object" && e.filesystem && typeof e.permissions == "object" ? f(e.filesystem) || s(e.filesystem) ? p(e.filesystem, Object.assign({}, e.permissions, t)) : {
|
|
1570
1624
|
filesystem: e.filesystem,
|
|
1571
1625
|
permissions: Object.assign({}, e.permissions, t)
|
|
1572
1626
|
} : {
|
|
@@ -1575,33 +1629,33 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1575
1629
|
};
|
|
1576
1630
|
}
|
|
1577
1631
|
t.exports = {
|
|
1578
|
-
MAGIC:
|
|
1579
|
-
FORMAT_VERSION:
|
|
1580
|
-
isBinaryContainer:
|
|
1581
|
-
isGzipBytes:
|
|
1582
|
-
isAsyncFilesystemSource:
|
|
1583
|
-
resolveFilesystemSource:
|
|
1584
|
-
serializeBinaryFilesystem:
|
|
1585
|
-
deserializeBinaryFilesystem:
|
|
1632
|
+
MAGIC: a,
|
|
1633
|
+
FORMAT_VERSION: o,
|
|
1634
|
+
isBinaryContainer: s,
|
|
1635
|
+
isGzipBytes: u,
|
|
1636
|
+
isAsyncFilesystemSource: f,
|
|
1637
|
+
resolveFilesystemSource: p,
|
|
1638
|
+
serializeBinaryFilesystem: c,
|
|
1639
|
+
deserializeBinaryFilesystem: l,
|
|
1586
1640
|
FilesystemStorage: class {
|
|
1587
1641
|
static async save(e, t = "brsh-rootfs") {
|
|
1588
|
-
let n = e.context ? e.context.fs : e, r =
|
|
1642
|
+
let n = e.context ? e.context.fs : e, r = c(n.getRaw(), n.getRawPermissions());
|
|
1589
1643
|
return typeof indexedDB < "u" && await this._idbPut(t, r), r;
|
|
1590
1644
|
}
|
|
1591
1645
|
static async load(e = "brsh-rootfs") {
|
|
1592
|
-
if (e instanceof Uint8Array || e instanceof ArrayBuffer || typeof e == "string" && (/^https?:\/\//i.test(e) || e.endsWith(".brfs"))) return
|
|
1646
|
+
if (e instanceof Uint8Array || e instanceof ArrayBuffer || typeof e == "string" && (/^https?:\/\//i.test(e) || e.endsWith(".brfs"))) return p(e);
|
|
1593
1647
|
if (typeof indexedDB < "u" && typeof e == "string") {
|
|
1594
1648
|
let t = await this._idbGet(e);
|
|
1595
|
-
if (t &&
|
|
1649
|
+
if (t && s(t)) return l(t);
|
|
1596
1650
|
}
|
|
1597
1651
|
return null;
|
|
1598
1652
|
}
|
|
1599
1653
|
static async loadOrFetch(e = "brsh-rootfs", t = {}) {
|
|
1600
|
-
return await this.load(e) ||
|
|
1654
|
+
return await this.load(e) || p(t);
|
|
1601
1655
|
}
|
|
1602
1656
|
static createAutoSave(e = "brsh-rootfs", t = null) {
|
|
1603
1657
|
return (n, r) => {
|
|
1604
|
-
let i =
|
|
1658
|
+
let i = c(n, r);
|
|
1605
1659
|
typeof indexedDB < "u" && this._idbPut(e, i).catch(() => {}), typeof t == "function" && t(i, n, r);
|
|
1606
1660
|
};
|
|
1607
1661
|
}
|
|
@@ -1639,11 +1693,11 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1639
1693
|
};
|
|
1640
1694
|
})), K = /* @__PURE__ */ t(((e, t) => {
|
|
1641
1695
|
b();
|
|
1642
|
-
var n = x(), { BinaryFile: r, SymlinkRef: i } = n;
|
|
1643
|
-
function
|
|
1696
|
+
var n = x(), { BinaryFile: r, SymlinkRef: i, DeviceFile: a } = n;
|
|
1697
|
+
function o(e) {
|
|
1644
1698
|
for (let t of Object.keys(e)) {
|
|
1645
1699
|
let n = e[t];
|
|
1646
|
-
if (typeof n == "object" && n && !(n instanceof Uint8Array) && !(n instanceof i))
|
|
1700
|
+
if (typeof n == "object" && n && !(n instanceof Uint8Array) && !(n instanceof i) && !(n instanceof a)) o(n);
|
|
1647
1701
|
else if (typeof n == "string" && n.startsWith("data:")) {
|
|
1648
1702
|
let i = n.indexOf(";"), a = n.indexOf(",", i);
|
|
1649
1703
|
if (i !== -1 && a !== -1 && n.slice(i + 1, a) === "base64") {
|
|
@@ -1668,7 +1722,43 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1668
1722
|
let { deserializeBinaryFilesystem: e } = G(), r = e(t);
|
|
1669
1723
|
t = r.filesystem, n = Object.assign({}, r.permissions, n);
|
|
1670
1724
|
}
|
|
1671
|
-
|
|
1725
|
+
o(t), this.fileSystem = t, this.permissions = Object.assign({}, n), this.cwd = e.endsWith("/") ? e : e + "/", this._onChange = r, this._changeScheduled = !1, this._initDevices();
|
|
1726
|
+
}
|
|
1727
|
+
_initDevices() {
|
|
1728
|
+
this._devices = {};
|
|
1729
|
+
let e = this._devices;
|
|
1730
|
+
e.null = new a("null", {
|
|
1731
|
+
read: () => "",
|
|
1732
|
+
write: () => {}
|
|
1733
|
+
}), e.zero = new a("zero", {
|
|
1734
|
+
read: () => new Uint8Array(4096),
|
|
1735
|
+
write: () => {}
|
|
1736
|
+
}), e.urandom = new a("urandom", {
|
|
1737
|
+
read: () => {
|
|
1738
|
+
let e = new Uint8Array(256);
|
|
1739
|
+
if (typeof crypto < "u" && crypto.getRandomValues) crypto.getRandomValues(e);
|
|
1740
|
+
else for (let t = 0; t < e.length; t++) e[t] = Math.floor(Math.random() * 256);
|
|
1741
|
+
return e;
|
|
1742
|
+
},
|
|
1743
|
+
write: () => {}
|
|
1744
|
+
}), e.random = e.urandom, e.tty = new a("tty", {
|
|
1745
|
+
read: () => "",
|
|
1746
|
+
write: () => {}
|
|
1747
|
+
}), e.stdin = new i("/dev/tty"), e.stdout = new i("/dev/tty"), e.stderr = new i("/dev/tty");
|
|
1748
|
+
}
|
|
1749
|
+
_getDevDir() {
|
|
1750
|
+
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;
|
|
1751
|
+
}
|
|
1752
|
+
_getRootOverlay() {
|
|
1753
|
+
let e = Object.assign({}, this.fileSystem);
|
|
1754
|
+
return e.dev = this._getDevDir(), e;
|
|
1755
|
+
}
|
|
1756
|
+
setTtyDevice(e = {}) {
|
|
1757
|
+
this._devices || this._initDevices(), this._devices.tty = new a("tty", {
|
|
1758
|
+
read: e.read || (() => ""),
|
|
1759
|
+
write: e.write || (() => {}),
|
|
1760
|
+
mode: 438
|
|
1761
|
+
}), this._devices.stdin = new i("/dev/tty"), this._devices.stdout = new i("/dev/tty"), this._devices.stderr = new i("/dev/tty");
|
|
1672
1762
|
}
|
|
1673
1763
|
toBinaryContainer(e = {}) {
|
|
1674
1764
|
let { serializeBinaryFilesystem: t } = G();
|
|
@@ -1680,10 +1770,11 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1680
1770
|
}
|
|
1681
1771
|
getFileByPath(e) {
|
|
1682
1772
|
let t = this._resolveByAbsolutePath(this._pathToAbsolute(e), !0);
|
|
1683
|
-
return t == null || !this.isReadable(e) ? null : t;
|
|
1773
|
+
return t == null || !this.isReadable(e) ? null : t instanceof a ? t.read() : t;
|
|
1684
1774
|
}
|
|
1685
1775
|
_getFileRaw(e) {
|
|
1686
|
-
|
|
1776
|
+
let t = this._getFileByAbsolutePath(this._pathToAbsolute(e));
|
|
1777
|
+
return t instanceof a ? t.read() : t;
|
|
1687
1778
|
}
|
|
1688
1779
|
exists(e) {
|
|
1689
1780
|
return this._resolveByAbsolutePath(this._pathToAbsolute(e), !0) != null;
|
|
@@ -1705,13 +1796,25 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1705
1796
|
isFile: !1,
|
|
1706
1797
|
isCommand: !1,
|
|
1707
1798
|
isBinary: !1,
|
|
1708
|
-
isSymlink: !0
|
|
1799
|
+
isSymlink: !0,
|
|
1800
|
+
isDevice: !1,
|
|
1801
|
+
isCharacterDevice: !1
|
|
1802
|
+
} : t instanceof a ? {
|
|
1803
|
+
isDirectory: !1,
|
|
1804
|
+
isFile: !0,
|
|
1805
|
+
isCommand: !1,
|
|
1806
|
+
isBinary: t.read() instanceof Uint8Array,
|
|
1807
|
+
isSymlink: !1,
|
|
1808
|
+
isDevice: !0,
|
|
1809
|
+
isCharacterDevice: !0
|
|
1709
1810
|
} : {
|
|
1710
1811
|
isDirectory: t.constructor === Object,
|
|
1711
1812
|
isFile: typeof t == "string" || t instanceof Uint8Array,
|
|
1712
1813
|
isCommand: typeof t == "function",
|
|
1713
1814
|
isBinary: t instanceof Uint8Array,
|
|
1714
|
-
isSymlink: !1
|
|
1815
|
+
isSymlink: !1,
|
|
1816
|
+
isDevice: !1,
|
|
1817
|
+
isCharacterDevice: !1
|
|
1715
1818
|
};
|
|
1716
1819
|
}
|
|
1717
1820
|
_pathToAbsolute(e) {
|
|
@@ -1729,9 +1832,13 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1729
1832
|
return this._pathToAbsolute(e);
|
|
1730
1833
|
}
|
|
1731
1834
|
setFileByPath(e, t, n = !1) {
|
|
1732
|
-
let r = this._pathToAbsolute(e);
|
|
1733
|
-
if (
|
|
1835
|
+
let r = this._pathToAbsolute(e), i = this._getFileByAbsolutePath(r);
|
|
1836
|
+
if (i != null) {
|
|
1734
1837
|
if (!this.isWritable(e)) throw Error("Permission denied");
|
|
1838
|
+
if (i instanceof a) {
|
|
1839
|
+
i.write(t), this._triggerChange();
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1735
1842
|
} else {
|
|
1736
1843
|
let e = r.split("/");
|
|
1737
1844
|
e.pop();
|
|
@@ -1747,28 +1854,54 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1747
1854
|
_setFileByAbsolutePath(e, t, n = !0) {
|
|
1748
1855
|
let r = e.split("/");
|
|
1749
1856
|
r.shift();
|
|
1750
|
-
let
|
|
1857
|
+
let o = r.pop();
|
|
1858
|
+
if (r.length > 0 && r[0] === "dev") {
|
|
1859
|
+
let e = this._getDevDir(), i = r.slice(1);
|
|
1860
|
+
for (let t of i) {
|
|
1861
|
+
if (!Object.prototype.hasOwnProperty.call(e, t)) {
|
|
1862
|
+
if (!n) throw Error(`${t}: No such file or directory`);
|
|
1863
|
+
e[t] = {};
|
|
1864
|
+
}
|
|
1865
|
+
e = e[t];
|
|
1866
|
+
}
|
|
1867
|
+
if (e[o] instanceof a) {
|
|
1868
|
+
e[o].write(t);
|
|
1869
|
+
return;
|
|
1870
|
+
}
|
|
1871
|
+
e[o] = t;
|
|
1872
|
+
return;
|
|
1873
|
+
}
|
|
1874
|
+
if (r.length === 0 && o === "dev") throw Error("dev: File exists");
|
|
1875
|
+
let s = this.fileSystem, c = [];
|
|
1751
1876
|
for (let e of r) {
|
|
1752
|
-
if (
|
|
1877
|
+
if (c.push(e), !Object.prototype.hasOwnProperty.call(s, e)) {
|
|
1753
1878
|
if (!n) throw Error(`${e}: No such file or directory`);
|
|
1754
|
-
|
|
1879
|
+
s[e] = {};
|
|
1755
1880
|
}
|
|
1756
|
-
let t =
|
|
1881
|
+
let t = s[e];
|
|
1757
1882
|
if (t instanceof i) {
|
|
1758
|
-
let n = "/" +
|
|
1883
|
+
let n = "/" + c.slice(0, -1).join("/"), r = t.target.startsWith("/") ? this._traverseComplexAbsolutePath(t.target) : this._traverseComplexAbsolutePath(n + "/" + t.target);
|
|
1759
1884
|
if (t = this._resolveByAbsolutePath(r, !0), typeof t != "object" || !t || t instanceof i) throw Error(`${e}: Not a directory`);
|
|
1760
1885
|
}
|
|
1761
|
-
|
|
1886
|
+
s = t;
|
|
1762
1887
|
}
|
|
1763
|
-
o
|
|
1888
|
+
if (s[o] instanceof a) {
|
|
1889
|
+
s[o].write(t);
|
|
1890
|
+
return;
|
|
1891
|
+
}
|
|
1892
|
+
s[o] = t;
|
|
1764
1893
|
}
|
|
1765
1894
|
_resolveByAbsolutePath(e, t = !0, n = 0) {
|
|
1766
1895
|
if (n > 10) return null;
|
|
1767
1896
|
let r = e.split("/");
|
|
1768
|
-
r.shift(), r.length > 0 && r[r.length - 1].length < 1 && r.pop();
|
|
1897
|
+
if (r.shift(), r.length > 0 && r[r.length - 1].length < 1 && r.pop(), r.length === 0) return this._getRootOverlay();
|
|
1769
1898
|
let a = this.fileSystem, o = [];
|
|
1770
1899
|
for (let e = 0; e < r.length; e++) {
|
|
1771
1900
|
let s = r[e], c = e === r.length - 1;
|
|
1901
|
+
if (e === 0 && s === "dev") {
|
|
1902
|
+
a = this._getDevDir(), o.push(s);
|
|
1903
|
+
continue;
|
|
1904
|
+
}
|
|
1772
1905
|
if (typeof a != "object" || !a || a instanceof i || !Object.prototype.hasOwnProperty.call(a, s)) return null;
|
|
1773
1906
|
if (a = a[s], o.push(s), a instanceof i && (!c || t)) {
|
|
1774
1907
|
let e = "/" + o.slice(0, -1).join("/"), t = a.target.startsWith("/") ? this._traverseComplexAbsolutePath(a.target) : this._traverseComplexAbsolutePath(e + "/" + a.target);
|
|
@@ -1779,7 +1912,16 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1779
1912
|
}
|
|
1780
1913
|
_getFileByAbsolutePath(e) {
|
|
1781
1914
|
let t = e.split("/");
|
|
1782
|
-
|
|
1915
|
+
if (t.shift(), t.length > 0 && t[t.length - 1].length < 1 && t.pop(), t.length === 0) return this._getRootOverlay();
|
|
1916
|
+
if (t[0] === "dev") {
|
|
1917
|
+
let e = this._getDevDir();
|
|
1918
|
+
for (let n = 1; n < t.length; n++) {
|
|
1919
|
+
if (typeof e != "object" || !e || !Object.prototype.hasOwnProperty.call(e, t[n])) return null;
|
|
1920
|
+
e = e[t[n]];
|
|
1921
|
+
}
|
|
1922
|
+
return e;
|
|
1923
|
+
}
|
|
1924
|
+
return t.reduce((e, t) => typeof e != "object" || !e || !Object.prototype.hasOwnProperty.call(e, t) ? null : e[t], this.fileSystem);
|
|
1783
1925
|
}
|
|
1784
1926
|
deleteFileByPath(e) {
|
|
1785
1927
|
let t = this._pathToAbsolute(e), n = t.split("/");
|
|
@@ -1797,6 +1939,16 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1797
1939
|
t.shift(), t[t.length - 1] === "" && t.pop();
|
|
1798
1940
|
let n = t.pop();
|
|
1799
1941
|
if (!n) return;
|
|
1942
|
+
if (t.length > 0 && t[0] === "dev") {
|
|
1943
|
+
let e = this._getDevDir();
|
|
1944
|
+
for (let n = 1; n < t.length; n++) {
|
|
1945
|
+
if (!e || typeof e != "object") return;
|
|
1946
|
+
e = e[t[n]];
|
|
1947
|
+
}
|
|
1948
|
+
e && n in e && delete e[n];
|
|
1949
|
+
return;
|
|
1950
|
+
}
|
|
1951
|
+
if (t.length === 0 && n === "dev") return;
|
|
1800
1952
|
let r = this.fileSystem, a = [];
|
|
1801
1953
|
for (let e of t) {
|
|
1802
1954
|
if (a.push(e), !Object.prototype.hasOwnProperty.call(r, e)) return;
|
|
@@ -1813,7 +1965,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1813
1965
|
let t = this._pathToAbsolute(e);
|
|
1814
1966
|
if (this.permissions[t] !== void 0) return this.permissions[t];
|
|
1815
1967
|
let n = this._resolveByAbsolutePath(t, !0);
|
|
1816
|
-
return n == null ? null : n.constructor === Object ? 493 : typeof n == "function" ? 365 : 420;
|
|
1968
|
+
return n == null ? null : n instanceof a ? n.mode || 438 : n.constructor === Object ? 493 : typeof n == "function" ? 365 : 420;
|
|
1817
1969
|
}
|
|
1818
1970
|
setMode(e, t) {
|
|
1819
1971
|
let n = this._pathToAbsolute(e);
|
|
@@ -1821,7 +1973,12 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1821
1973
|
}
|
|
1822
1974
|
getSize(e) {
|
|
1823
1975
|
let t = this._pathToAbsolute(e), n = this._resolveByAbsolutePath(t, !0);
|
|
1824
|
-
|
|
1976
|
+
if (n == null) return 0;
|
|
1977
|
+
if (n instanceof a) {
|
|
1978
|
+
let e = n.read();
|
|
1979
|
+
return e instanceof Uint8Array || typeof e == "string" ? e.length : 0;
|
|
1980
|
+
}
|
|
1981
|
+
return n.constructor === Object ? JSON.stringify(n).length : n instanceof Uint8Array ? n.length : n.toString().length;
|
|
1825
1982
|
}
|
|
1826
1983
|
getRawPermissions() {
|
|
1827
1984
|
return Object.assign({}, this.permissions);
|
|
@@ -2309,6 +2466,9 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
2309
2466
|
onInput(e) {
|
|
2310
2467
|
this.sandbox && this.sandbox.onInput(e);
|
|
2311
2468
|
}
|
|
2469
|
+
kill(e = "SIGINT") {
|
|
2470
|
+
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);
|
|
2471
|
+
}
|
|
2312
2472
|
run() {
|
|
2313
2473
|
let e = this.context && this.context.fs || this.fs, t = e && e.isRealFilesystem ? { useRealFilesystem: !0 } : {
|
|
2314
2474
|
filesystem: e && e.getRaw() || {},
|
|
@@ -2697,15 +2857,27 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
2697
2857
|
return !0;
|
|
2698
2858
|
}
|
|
2699
2859
|
get interactive() {
|
|
2700
|
-
|
|
2701
|
-
if (this._isInteractive !== void 0) return !!this._isInteractive;
|
|
2702
|
-
if (this._pkgMeta && this._pkgMeta.interactive !== void 0) return !!this._pkgMeta.interactive;
|
|
2703
|
-
let e = (this.script || this.name || "").toLowerCase();
|
|
2704
|
-
return e === "nano" || e.endsWith("/nano") || e.endsWith("nano.wasm");
|
|
2860
|
+
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;
|
|
2705
2861
|
}
|
|
2706
2862
|
get captureInput() {
|
|
2707
2863
|
return this.interactive;
|
|
2708
2864
|
}
|
|
2865
|
+
kill(e = "SIGINT") {
|
|
2866
|
+
if (this._killed = !0, this.exitCode = 130, this._exitAltScreen(), this._asyncifyReject) {
|
|
2867
|
+
try {
|
|
2868
|
+
this._asyncifyReject(/* @__PURE__ */ Error("Interrupted by SIGINT"));
|
|
2869
|
+
} catch {}
|
|
2870
|
+
this._asyncifyReject = null;
|
|
2871
|
+
}
|
|
2872
|
+
if (this._pendingReadResolve) {
|
|
2873
|
+
let e = this._pendingReadResolve;
|
|
2874
|
+
this._pendingReadResolve = null;
|
|
2875
|
+
try {
|
|
2876
|
+
e();
|
|
2877
|
+
} catch {}
|
|
2878
|
+
}
|
|
2879
|
+
super.kill(e);
|
|
2880
|
+
}
|
|
2709
2881
|
_enterAltScreen() {
|
|
2710
2882
|
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"));
|
|
2711
2883
|
}
|
|
@@ -2740,7 +2912,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
2740
2912
|
return n[e] ? new TextEncoder().encode(n[e]) : new TextEncoder().encode(e);
|
|
2741
2913
|
}
|
|
2742
2914
|
onInput(e) {
|
|
2743
|
-
if (!this._handlingStreamData) {
|
|
2915
|
+
if (!this._handlingStreamData && !(this.stdinStream && this.stdinStream._isPushing)) {
|
|
2744
2916
|
if (typeof this._externalKeyHandler == "function") {
|
|
2745
2917
|
this._externalKeyHandler(e);
|
|
2746
2918
|
return;
|
|
@@ -2768,22 +2940,26 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
2768
2940
|
_loadBytes(e, t) {
|
|
2769
2941
|
let n = this.context && this.context.fs || this.fs;
|
|
2770
2942
|
if (!n) return Promise.reject(/* @__PURE__ */ Error(`${e}: Filesystem is not available`));
|
|
2943
|
+
let r;
|
|
2771
2944
|
if (n.isRealFilesystem && t) try {
|
|
2772
|
-
let
|
|
2773
|
-
|
|
2774
|
-
bytes:
|
|
2775
|
-
isWat: this._isWat(e,
|
|
2945
|
+
let i = t.readFileSync(n.absolutePath(e)), a = new Uint8Array(i);
|
|
2946
|
+
r = Promise.resolve({
|
|
2947
|
+
bytes: a,
|
|
2948
|
+
isWat: this._isWat(e, a)
|
|
2776
2949
|
});
|
|
2777
2950
|
} catch (t) {
|
|
2778
2951
|
return Promise.reject(/* @__PURE__ */ Error(`${e}: ${t.message}`));
|
|
2779
2952
|
}
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2953
|
+
else {
|
|
2954
|
+
let t = n.getFileByPath(e);
|
|
2955
|
+
if (t == null) return Promise.reject(/* @__PURE__ */ Error(`${e}: No such file or directory`));
|
|
2956
|
+
let i = this._contentToBytes(t);
|
|
2957
|
+
r = Promise.resolve({
|
|
2958
|
+
bytes: i,
|
|
2959
|
+
isWat: this._isWat(e, i)
|
|
2960
|
+
});
|
|
2961
|
+
}
|
|
2962
|
+
return r.then((e) => (!e.isWat && e.bytes && (this._inspectedWasm = j(e.bytes), this._inspectedWasm.isInteractive && (this._isInteractive = !0)), e));
|
|
2787
2963
|
}
|
|
2788
2964
|
_isWat(e, t) {
|
|
2789
2965
|
return e.endsWith(".wat") ? !0 : t.length > 0 && t[0] === 40;
|
|
@@ -2825,7 +3001,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
2825
3001
|
1: "",
|
|
2826
3002
|
2: ""
|
|
2827
3003
|
}, n = new TextDecoder(), b = new TextEncoder(), T = null, E = null, D = !1, O = 0, k = null, A = null, N = null, P = null, F = this.stdin === void 0 || this.stdin === null || this.stdin === this.stdinStream || this.stdin && this.stdin.isTTY, I = !!(this.interactive && F), L = () => {
|
|
2828
|
-
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));
|
|
3004
|
+
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));
|
|
2829
3005
|
}, R = (e, n) => {
|
|
2830
3006
|
if (I && (e === 1 || e === 2)) {
|
|
2831
3007
|
if (e === 1 && this.stdout) {
|
|
@@ -2863,7 +3039,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
2863
3039
|
if (this._handlingStreamData) return;
|
|
2864
3040
|
let t = this._keyToBytes(e);
|
|
2865
3041
|
t && B(t);
|
|
2866
|
-
}, F && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", P), F && this.stdin && this.stdin !== this.stdinStream && typeof this.stdin.on == "function" && this.stdin.on("data", P);
|
|
3042
|
+
}, 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", P), F && this.stdin && this.stdin !== this.stdinStream && typeof this.stdin.on == "function" && this.stdin.on("data", P);
|
|
2867
3043
|
let V = !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(), H = 0, U = this.context && this.context.fs ? this.context.fs : this.fs, te = 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") || U && U.cwd || "/", W = te.length > 1 && te.endsWith("/") ? te.slice(0, -1) : te, ne = 5, G = new Map([[3, {
|
|
2868
3044
|
type: "preopen",
|
|
2869
3045
|
path: "/",
|
|
@@ -2982,8 +3158,8 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
2982
3158
|
}
|
|
2983
3159
|
return s.setUint32(r, e, !0), i;
|
|
2984
3160
|
}
|
|
2985
|
-
return o ? (s.setUint32(r, 0, !0), a) : (E.exports.asyncify_start_unwind(O), k = new Promise((e) => {
|
|
2986
|
-
A = e;
|
|
3161
|
+
return o ? (s.setUint32(r, 0, !0), a) : (E.exports.asyncify_start_unwind(O), k = new Promise((e, t) => {
|
|
3162
|
+
A = e, this._pendingReadResolve = e, this._asyncifyReject = t;
|
|
2987
3163
|
}), s.setUint32(r, 0, !0), i);
|
|
2988
3164
|
}
|
|
2989
3165
|
if (z.length > 0) {
|
|
@@ -3134,14 +3310,16 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3134
3310
|
path: y
|
|
3135
3311
|
}), new DataView(T.buffer).setUint32(h, e, !0), i;
|
|
3136
3312
|
}
|
|
3137
|
-
if (y === "/dev/tty") {
|
|
3313
|
+
if (y === "/dev/tty" || y === "/dev/stdin") {
|
|
3138
3314
|
L();
|
|
3139
3315
|
let e = ne++;
|
|
3140
3316
|
return G.set(e, {
|
|
3141
3317
|
type: "dev_tty",
|
|
3142
|
-
path:
|
|
3318
|
+
path: y
|
|
3143
3319
|
}), new DataView(T.buffer).setUint32(h, e, !0), i;
|
|
3144
3320
|
}
|
|
3321
|
+
if (y === "/dev/stdout") return new DataView(T.buffer).setUint32(h, 1, !0), i;
|
|
3322
|
+
if (y === "/dev/stderr") return new DataView(T.buffer).setUint32(h, 2, !0), i;
|
|
3145
3323
|
let w = U.stat(g), E = w !== null;
|
|
3146
3324
|
if (c & x && c & _ && E) return s;
|
|
3147
3325
|
if (c & v) {
|
|
@@ -3174,13 +3352,12 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3174
3352
|
if (!T || !U) return o;
|
|
3175
3353
|
let c = J(e, n.decode(new Uint8Array(T.buffer, r, a)));
|
|
3176
3354
|
if (!c) return o;
|
|
3177
|
-
let l = c.replace(/\/+/g, "/").replace(/\/$/, "") || "/";
|
|
3178
|
-
if (l === "/dev/null" || l === "/dev/zero" || l === "/dev/urandom" || l === "/dev/random" || l === "/dev/tty") {
|
|
3355
|
+
let l = c.replace(/\/+/g, "/").replace(/\/$/, "") || "/", d = U.stat(c);
|
|
3356
|
+
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)) {
|
|
3179
3357
|
let e = new DataView(T.buffer);
|
|
3180
3358
|
for (let t = 0; t < 64; t++) e.setUint8(s + t, 0);
|
|
3181
3359
|
return e.setUint8(s + 16, m), e.setBigUint64(s + 24, 1n, !0), i;
|
|
3182
3360
|
}
|
|
3183
|
-
let d = U.stat(c);
|
|
3184
3361
|
if (!d) return u;
|
|
3185
3362
|
let f = new DataView(T.buffer);
|
|
3186
3363
|
for (let e = 0; e < 64; e++) f.setUint8(s + e, 0);
|
|
@@ -3190,6 +3367,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3190
3367
|
if (!T || !U) return o;
|
|
3191
3368
|
let a = J(e, n.decode(new Uint8Array(T.buffer, t, r)));
|
|
3192
3369
|
if (!a) return o;
|
|
3370
|
+
if (U.exists(a)) return s;
|
|
3193
3371
|
try {
|
|
3194
3372
|
return U.setFileByPath(a, {}, !0), i;
|
|
3195
3373
|
} catch {
|
|
@@ -3338,12 +3516,14 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3338
3516
|
}
|
|
3339
3517
|
return a.setUint32(r, o, !0), i;
|
|
3340
3518
|
}
|
|
3341
|
-
return E.exports.asyncify_start_unwind(O), k = new Promise((e) => {
|
|
3342
|
-
let
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3519
|
+
return E.exports.asyncify_start_unwind(O), k = new Promise((e, t) => {
|
|
3520
|
+
let n = null;
|
|
3521
|
+
this._asyncifyReject = t;
|
|
3522
|
+
let r = () => {
|
|
3523
|
+
n && clearTimeout(n), A = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
|
|
3524
|
+
};
|
|
3525
|
+
A = r, this._pendingReadResolve = r, s !== Infinity && (n = setTimeout(() => {
|
|
3526
|
+
A = null, this._pendingReadResolve = null, this._asyncifyReject = null, e();
|
|
3347
3527
|
}, Math.max(1, s)));
|
|
3348
3528
|
}), a.setUint32(r, 0, !0), i;
|
|
3349
3529
|
}
|
|
@@ -3426,18 +3606,39 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3426
3606
|
let i = E.exports._start || E.exports.__wasi_command || E.exports.main || E.exports.run;
|
|
3427
3607
|
if (i) try {
|
|
3428
3608
|
let e = i();
|
|
3429
|
-
for (e && typeof e.then == "function" && (e = await e); D && typeof E.exports.asyncify_get_state == "function" && E.exports.asyncify_get_state() === 1;)
|
|
3609
|
+
for (e && typeof e.then == "function" && (e = await e); D && typeof E.exports.asyncify_get_state == "function" && E.exports.asyncify_get_state() === 1;) {
|
|
3610
|
+
if (this._killed) {
|
|
3611
|
+
this.exitCode = 130;
|
|
3612
|
+
break;
|
|
3613
|
+
}
|
|
3614
|
+
if (E.exports.asyncify_stop_unwind(), k) {
|
|
3615
|
+
try {
|
|
3616
|
+
await k;
|
|
3617
|
+
} catch {
|
|
3618
|
+
if (this._killed) {
|
|
3619
|
+
this.exitCode = 130;
|
|
3620
|
+
break;
|
|
3621
|
+
}
|
|
3622
|
+
}
|
|
3623
|
+
k = null;
|
|
3624
|
+
}
|
|
3625
|
+
if (this._killed) {
|
|
3626
|
+
this.exitCode = 130;
|
|
3627
|
+
break;
|
|
3628
|
+
}
|
|
3629
|
+
E.exports.asyncify_start_rewind(O), e = i(), e && typeof e.then == "function" && (e = await e);
|
|
3630
|
+
}
|
|
3430
3631
|
} catch (e) {
|
|
3431
|
-
(!e || !e._wasmExit) && (this.stdErr = `${this.script}: runtime error: ${e?.message || String(e)}`, this.exitCode = 1);
|
|
3632
|
+
this._killed ? this.exitCode = 130 : (!e || !e._wasmExit) && (this.stdErr = `${this.script}: runtime error: ${e?.message || String(e)}`, this.exitCode = 1);
|
|
3432
3633
|
}
|
|
3433
3634
|
else {
|
|
3434
3635
|
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(", ")})` : "";
|
|
3435
3636
|
this.stdErr = `${this.script}: no CLI entry point found (expected _start, main, or run)${t}`, this.exitCode = 1;
|
|
3436
3637
|
}
|
|
3437
3638
|
} catch (e) {
|
|
3438
|
-
(!e || !e._wasmExit) && (this.stdErr = `${this.script}: ${e?.message || String(e)}`, this.exitCode = 1);
|
|
3639
|
+
this._killed ? this.exitCode = 130 : (!e || !e._wasmExit) && (this.stdErr = `${this.script}: ${e?.message || String(e)}`, this.exitCode = 1);
|
|
3439
3640
|
} finally {
|
|
3440
|
-
I && this._exitAltScreen(),
|
|
3641
|
+
I && this._exitAltScreen(), P && (this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("data", P), this.stdin && typeof this.stdin.off == "function" && this.stdin.off("data", P)), this._onStdinStreamData && this.stdinStream && typeof this.stdinStream.on == "function" && this.stdinStream.on("data", this._onStdinStreamData), N && (this.stdout && typeof this.stdout.off == "function" && this.stdout.off("resize", N), this.stdinStream && typeof this.stdinStream.off == "function" && this.stdinStream.off("resize", N)), this._externalKeyHandler = null;
|
|
3441
3642
|
for (let e of G.values()) Y(e);
|
|
3442
3643
|
}
|
|
3443
3644
|
ee();
|
|
@@ -3552,13 +3753,15 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3552
3753
|
usage: null,
|
|
3553
3754
|
options: [],
|
|
3554
3755
|
exports: [],
|
|
3555
|
-
wasiImports: []
|
|
3756
|
+
wasiImports: [],
|
|
3757
|
+
hasAsyncify: !1,
|
|
3758
|
+
isInteractive: !1
|
|
3556
3759
|
};
|
|
3557
3760
|
if (!(e instanceof Uint8Array) || e.length < 8) return t;
|
|
3558
3761
|
try {
|
|
3559
3762
|
if (typeof WebAssembly < "u" && WebAssembly.Module) {
|
|
3560
3763
|
let n = new WebAssembly.Module(e);
|
|
3561
|
-
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);
|
|
3764
|
+
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);
|
|
3562
3765
|
}
|
|
3563
3766
|
} catch {}
|
|
3564
3767
|
try {
|
|
@@ -3568,8 +3771,10 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3568
3771
|
i >= 32 && i <= 126 || i === 9 || i === 10 ? r += String.fromCharCode(i) : (r.length >= 4 && n.push(r), r = "");
|
|
3569
3772
|
}
|
|
3570
3773
|
r.length >= 4 && n.push(r);
|
|
3571
|
-
let i =
|
|
3572
|
-
t.
|
|
3774
|
+
let i = n.join("\n");
|
|
3775
|
+
t.isInteractive || (i.includes("/dev/tty") || i.includes("\x1B[?1049h") || i.includes("smcup") || i.includes("xterm")) && (t.isInteractive = !0);
|
|
3776
|
+
let a = A(i, !0);
|
|
3777
|
+
t.usage = a.usage, t.options = a.options;
|
|
3573
3778
|
} catch {}
|
|
3574
3779
|
return t;
|
|
3575
3780
|
}
|
|
@@ -3593,6 +3798,18 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3593
3798
|
get requiresFilesystem() {
|
|
3594
3799
|
return !0;
|
|
3595
3800
|
}
|
|
3801
|
+
get interactive() {
|
|
3802
|
+
return this._subCommand ? this._subCommand.interactive : this._isInteractive === void 0 ? !!(e && (e.interactive || e.wasm?.interactive) || this._inspectedWasm && this._inspectedWasm.isInteractive) : !!this._isInteractive;
|
|
3803
|
+
}
|
|
3804
|
+
get captureInput() {
|
|
3805
|
+
return this.interactive;
|
|
3806
|
+
}
|
|
3807
|
+
kill(e = "SIGINT") {
|
|
3808
|
+
this._subCommand && typeof this._subCommand.kill == "function" && this._subCommand.kill(e), super.kill(e);
|
|
3809
|
+
}
|
|
3810
|
+
onInput(e) {
|
|
3811
|
+
this._subCommand && typeof this._subCommand.onInput == "function" && this._subCommand.onInput(e);
|
|
3812
|
+
}
|
|
3596
3813
|
async run() {
|
|
3597
3814
|
let n = [...this.arguments || []], r = n.includes("--help") || n.includes("-h"), a = !r && (n.includes("--version") || n.includes("-V") || n.includes("-v"));
|
|
3598
3815
|
this._inspectedWasm = null, this._persistedWasmBytes = e.wasmPath ? D(this.context && this.context.fs || this.fs, e.wasmPath) : null, r && this._persistedWasmBytes && this._persistedWasmBytes.byteLength > 0 && (this._inspectedWasm = j(this._persistedWasmBytes));
|
|
@@ -3684,7 +3901,12 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3684
3901
|
}
|
|
3685
3902
|
async _runRawWasmBytes(t, n) {
|
|
3686
3903
|
let r = new T(i, n, this.context);
|
|
3687
|
-
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),
|
|
3904
|
+
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;
|
|
3905
|
+
try {
|
|
3906
|
+
await r._runWasm(t);
|
|
3907
|
+
} finally {
|
|
3908
|
+
this._subCommand = null;
|
|
3909
|
+
}
|
|
3688
3910
|
for (let e of r.result.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
|
|
3689
3911
|
this.exitCode = r.result.getExitCode();
|
|
3690
3912
|
}
|
|
@@ -8051,6 +8273,10 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
8051
8273
|
let e = this.context.fs.exists(this.context.getVar("PATH"));
|
|
8052
8274
|
this._loadDefaultCommands(), this._loadBuiltinCommands(e), this.ready = Promise.resolve(this), s ? this._initializing = !1 : (this._initializing = !0, setTimeout(() => this._init(), 0));
|
|
8053
8275
|
}
|
|
8276
|
+
this.context.fs && typeof this.context.fs.setTtyDevice == "function" && this.context.fs.setTtyDevice({
|
|
8277
|
+
write: (e) => this.stdout.write(e),
|
|
8278
|
+
read: () => ""
|
|
8279
|
+
});
|
|
8054
8280
|
}
|
|
8055
8281
|
async _initAsyncFilesystem(t, n, r) {
|
|
8056
8282
|
let i = this.context.getVar("PATH") || "/bin", a = () => {
|
|
@@ -8070,7 +8296,10 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
8070
8296
|
let u = this.context.fs.exists(i);
|
|
8071
8297
|
this._loadDefaultCommands(), this._loadBuiltinCommands(u);
|
|
8072
8298
|
for (let e of c) this.context.setCommand(e);
|
|
8073
|
-
this.context.setCwd(r), this.context._onFsChange = l, l && this.context.fs && (this.context.fs._onChange = () => l(this.context.fs.getRaw(), this.context.fs.getRawPermissions()))
|
|
8299
|
+
this.context.setCwd(r), this.context._onFsChange = l, l && this.context.fs && (this.context.fs._onChange = () => l(this.context.fs.getRaw(), this.context.fs.getRawPermissions())), this.context.fs && typeof this.context.fs.setTtyDevice == "function" && this.context.fs.setTtyDevice({
|
|
8300
|
+
write: (e) => this.stdout.write(e),
|
|
8301
|
+
read: () => ""
|
|
8302
|
+
});
|
|
8074
8303
|
} catch (e) {
|
|
8075
8304
|
this.emit("stdErr", e.message || String(e));
|
|
8076
8305
|
} finally {
|
|
@@ -8569,7 +8798,12 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
8569
8798
|
_handleStdinData(e) {
|
|
8570
8799
|
let t = typeof e == "string" ? e : e instanceof Uint8Array || y !== void 0 && y.isBuffer(e) ? new TextDecoder().decode(e) : String(e ?? "");
|
|
8571
8800
|
if (this.runningCommand) {
|
|
8572
|
-
let t = this.runningCommand
|
|
8801
|
+
let t = this.runningCommand;
|
|
8802
|
+
if ((typeof e == "string" && e === "" || e instanceof Uint8Array && e.length === 1 && e[0] === 3 || y !== void 0 && y.isBuffer(e) && e.length === 1 && e[0] === 3) && (!t.stdinStream || !t.stdinStream.isRaw)) {
|
|
8803
|
+
typeof t.kill == "function" && t.kill("SIGINT"), !t.interactive && !t._inAltScreen && this.stdout.write("^C\r\n");
|
|
8804
|
+
return;
|
|
8805
|
+
}
|
|
8806
|
+
let n = t.stdinStream && t.stdinStream.listenerCount("data") > 1;
|
|
8573
8807
|
if (t.captureInput || t.interactive || t._inAltScreen || n) {
|
|
8574
8808
|
t.stdinStream.pushData(e);
|
|
8575
8809
|
return;
|