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/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
@@ -1321,7 +1330,13 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1321
1330
  }), this._onStdinStreamData = (e) => {
1322
1331
  if (!this.captureInput) return;
1323
1332
  let t = a(e);
1324
- for (let e of t) !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);
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
+ }
1325
1340
  }, this.stdinStream.on("data", this._onStdinStreamData);
1326
1341
  }
1327
1342
  get name() {
@@ -1330,10 +1345,30 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1330
1345
  run() {
1331
1346
  return Promise.reject("Command not implemented...");
1332
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
+ }
1333
1359
  runCommand() {
1334
- return Promise.resolve().then(() => this.run()).then((e) => (e && e.split(/\r?\n/).forEach((e) => this.stdOut = e), this.result)).catch((e) => {
1335
- if (e && e.__type) throw e;
1336
- return e && (this.stdErr = e.message || e), this.exitCode = 127, this.result;
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
+ });
1337
1372
  });
1338
1373
  }
1339
1374
  onInput(e) {}
@@ -1374,6 +1409,9 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1374
1409
  _exitAltScreen() {
1375
1410
  this._inAltScreen && (this._inAltScreen = !1, this.stdinStream && this.stdinStream.setRawMode(!1), this.stdout && this.stdout.write("\x1B[?1049l\x1B[?25h"));
1376
1411
  }
1412
+ kill(e = "SIGINT") {
1413
+ this._exitAltScreen(), super.kill(e);
1414
+ }
1377
1415
  runCommand() {
1378
1416
  return this.interactive && this._enterAltScreen(), super.runCommand().finally(() => {
1379
1417
  this._exitAltScreen();
@@ -1382,33 +1420,34 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1382
1420
  };
1383
1421
  })), G = /* @__PURE__ */ t(((e, t) => {
1384
1422
  b(), B();
1385
- var { BinaryFile: n, SymlinkRef: r } = x(), i = new Uint8Array([
1423
+ var { BinaryFile: n, SymlinkRef: r, DeviceFile: i } = x(), a = new Uint8Array([
1386
1424
  66,
1387
1425
  82,
1388
1426
  70,
1389
1427
  83
1390
- ]), a = 2;
1391
- function o(e) {
1428
+ ]), o = 2;
1429
+ function s(e) {
1392
1430
  if (!e) return !1;
1393
1431
  let t = e instanceof Uint8Array ? e : e instanceof ArrayBuffer || ArrayBuffer.isView(e) ? new Uint8Array(e.buffer || e, e.byteOffset || 0, e.byteLength) : null;
1394
- return !t || t.length < 12 ? !1 : t[0] === i[0] && t[1] === i[1] && t[2] === i[2] && t[3] === i[3];
1432
+ return !t || t.length < 12 ? !1 : t[0] === a[0] && t[1] === a[1] && t[2] === a[2] && t[3] === a[3];
1395
1433
  }
1396
- function s(e = {}, t = {}, n = {}) {
1397
- let o = new TextEncoder(), s = [], c = 0, l = (e) => {
1398
- let t = e instanceof Uint8Array ? e : new Uint8Array(e), n = c;
1399
- return s.push(t), c += t.byteLength, [n, t.byteLength];
1400
- }, u = {}, d = (e, t) => {
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) => {
1401
1439
  if (e == null) return null;
1402
1440
  if (e instanceof r) return { $l: e.target };
1441
+ if (e instanceof i) return null;
1403
1442
  if (e instanceof Uint8Array || y !== void 0 && y.isBuffer(e)) {
1404
- 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] = l(n);
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);
1405
1444
  return { $b: [
1406
1445
  i,
1407
1446
  a,
1408
1447
  r
1409
1448
  ] };
1410
1449
  }
1411
- if (typeof e == "function") return n.commandsBundle || (u[t] = e.toString()), { $c: t };
1450
+ if (typeof e == "function") return n.commandsBundle || (d[t] = e.toString()), { $c: t };
1412
1451
  if (typeof e == "string") {
1413
1452
  if (e.startsWith("data:")) {
1414
1453
  let t = e.indexOf(";"), n = e.indexOf(",", t);
@@ -1420,7 +1459,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1420
1459
  a = new Uint8Array(e.length);
1421
1460
  for (let t = 0; t < e.length; t++) a[t] = e.charCodeAt(t);
1422
1461
  }
1423
- let [o, s] = l(a);
1462
+ let [o, s] = u(a);
1424
1463
  return { $b: [
1425
1464
  o,
1426
1465
  s,
@@ -1428,66 +1467,67 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1428
1467
  ] };
1429
1468
  }
1430
1469
  }
1431
- let [t, n] = l(o.encode(e));
1470
+ let [t, n] = u(s.encode(e));
1432
1471
  return { $t: [t, n] };
1433
1472
  }
1434
1473
  if (typeof e == "object") {
1435
1474
  let n = {};
1436
1475
  for (let r of Object.keys(e)) {
1437
- let i = `${t}/${r}`, a = d(e[r], i);
1476
+ let i = `${t}/${r}`, a = f(e[r], i);
1438
1477
  a !== null && (n[r] = a);
1439
1478
  }
1440
1479
  return { $d: n };
1441
1480
  }
1442
1481
  return null;
1443
- }, f = d(e, "") || { $d: {} }, p = null;
1444
- n.commandsBundle && typeof n.commandsBundle == "string" && (p = l(o.encode(n.commandsBundle)));
1445
- let m = {
1446
- v: a,
1447
- tree: f,
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,
1448
1487
  permissions: Object.assign({}, t)
1449
1488
  };
1450
- p && (m.commandsSlice = p), Object.keys(u).length > 0 && (m.inlineCommands = u);
1451
- let h = o.encode(JSON.stringify(m)), g = 12 + h.byteLength + c, _ = new Uint8Array(g);
1452
- _.set(i, 0);
1453
- let v = new DataView(_.buffer, _.byteOffset, _.byteLength);
1454
- v.setUint32(4, a, !0), v.setUint32(8, h.byteLength, !0), _.set(h, 12);
1455
- let b = 12 + h.byteLength;
1456
- for (let e of s) _.set(e, b), b += e.byteLength;
1457
- return _;
1458
- }
1459
- function c(e, t = {}) {
1460
- let i = e instanceof Uint8Array ? e : new Uint8Array(e.buffer || e, e.byteOffset || 0, e.byteLength);
1461
- if (!o(i)) throw Error("Invalid BRFS binary container (missing BRFS magic header)");
1462
- let s = new DataView(i.buffer, i.byteOffset, i.byteLength), c = s.getUint32(4, !0);
1463
- if (c > a) throw Error(`Unsupported BRFS container version: ${c}`);
1464
- let l = 12 + s.getUint32(8, !0);
1465
- if (l > i.byteLength) throw Error("Corrupt BRFS binary container (header length exceeds buffer)");
1466
- let u = new TextDecoder(), d = u.decode(i.subarray(12, l)), f = JSON.parse(d), p = i.subarray(l), m = Object.assign({}, t);
1467
- if (Array.isArray(f.commandsSlice)) {
1468
- let [e, t] = f.commandsSlice, n = u.decode(p.subarray(e, 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));
1469
1508
  try {
1470
1509
  let e = Function(n)();
1471
- e && typeof e == "object" && Object.assign(m, e);
1510
+ e && typeof e == "object" && Object.assign(h, e);
1472
1511
  } catch {}
1473
1512
  }
1474
- let h = (e) => {
1513
+ let g = (e) => {
1475
1514
  if (!e || typeof e != "object") return e;
1476
1515
  if ("$t" in e) {
1477
1516
  let [t, n] = e.$t;
1478
- return u.decode(p.subarray(t, t + n));
1517
+ return d.decode(m.subarray(t, t + n));
1479
1518
  }
1480
1519
  if ("$b" in e) {
1481
1520
  let [t, r, i] = e.$b;
1482
- return new n(p.slice(t, t + r).buffer, i || "application/octet-stream");
1521
+ return new n(m.slice(t, t + r).buffer, i || "application/octet-stream");
1483
1522
  }
1484
1523
  if ("$l" in e) return new r(e.$l);
1524
+ if ("$dev" in e) return new i(e.$dev);
1485
1525
  if ("$c" in e) {
1486
1526
  let t = e.$c;
1487
- if (m[t]) return m[t];
1488
- if (f.inlineCommands && f.inlineCommands[t]) try {
1527
+ if (h[t]) return h[t];
1528
+ if (p.inlineCommands && p.inlineCommands[t]) try {
1489
1529
  let e = W(), n = ne();
1490
- return Function("Command", "InteractiveCommand", `return (${f.inlineCommands[t]});`)(e, n);
1530
+ return Function("Command", "InteractiveCommand", `return (${p.inlineCommands[t]});`)(e, n);
1491
1531
  } catch {
1492
1532
  return null;
1493
1533
  }
@@ -1496,7 +1536,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1496
1536
  if ("$d" in e) {
1497
1537
  let t = {};
1498
1538
  for (let [n, r] of Object.entries(e.$d)) {
1499
- let e = h(r);
1539
+ let e = g(r);
1500
1540
  e !== null && (t[n] = e);
1501
1541
  }
1502
1542
  return t;
@@ -1504,16 +1544,16 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1504
1544
  return e;
1505
1545
  };
1506
1546
  return {
1507
- filesystem: h(f.tree) || {},
1508
- permissions: Object.assign({}, f.permissions || {})
1547
+ filesystem: g(p.tree) || {},
1548
+ permissions: Object.assign({}, p.permissions || {})
1509
1549
  };
1510
1550
  }
1511
- function l(e) {
1551
+ function u(e) {
1512
1552
  if (!e) return !1;
1513
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;
1514
1554
  return !!(t && t.byteLength >= 2 && t[0] === 31 && t[1] === 139);
1515
1555
  }
1516
- async function u(e) {
1556
+ async function d(e) {
1517
1557
  if (typeof DecompressionStream < "u" && typeof Response < "u") {
1518
1558
  let t = new DecompressionStream("gzip"), n = new Blob([e]).stream().pipeThrough(t), r = await new Response(n).arrayBuffer();
1519
1559
  return new Uint8Array(r);
@@ -1524,36 +1564,36 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1524
1564
  }
1525
1565
  throw Error("Gzip decompression is not supported in this environment");
1526
1566
  }
1527
- function d(e) {
1528
- return e ? !!(typeof e == "string" || typeof e.then == "function" || typeof e.arrayBuffer == "function" || l(e)) : !1;
1567
+ function f(e) {
1568
+ return e ? !!(typeof e == "string" || typeof e.then == "function" || typeof e.arrayBuffer == "function" || u(e)) : !1;
1529
1569
  }
1530
- async function f(e, t = {}) {
1570
+ async function p(e, t = {}) {
1531
1571
  if (!e) return {
1532
1572
  filesystem: {},
1533
1573
  permissions: t
1534
1574
  };
1535
- if (typeof e.then == "function") return f(await e, t);
1575
+ if (typeof e.then == "function") return p(await e, t);
1536
1576
  if (typeof e.arrayBuffer == "function") {
1537
1577
  let n = await e.arrayBuffer();
1538
- return f(new Uint8Array(n), t);
1578
+ return p(new Uint8Array(n), t);
1539
1579
  }
1540
1580
  if (typeof e == "string") {
1541
1581
  if (!/^https?:\/\//i.test(e) && z !== void 0 && typeof z.getBuiltinModule == "function" && typeof window > "u") try {
1542
1582
  let n = z.getBuiltinModule("fs");
1543
1583
  if (n && n.existsSync(e)) {
1544
1584
  let r = await n.promises.readFile(e);
1545
- return f(new Uint8Array(r.buffer, r.byteOffset, r.byteLength), t);
1585
+ return p(new Uint8Array(r.buffer, r.byteOffset, r.byteLength), t);
1546
1586
  }
1547
1587
  } catch {}
1548
1588
  let n = await fetch(e);
1549
1589
  if (!n.ok) throw Error(`Failed to load filesystem from ${e}: HTTP ${n.status}`);
1550
1590
  let r = await n.arrayBuffer();
1551
- return f(new Uint8Array(r), t);
1591
+ return p(new Uint8Array(r), t);
1552
1592
  }
1553
1593
  if (e instanceof ArrayBuffer || ArrayBuffer.isView(e)) {
1554
1594
  let n = e instanceof Uint8Array ? e : e instanceof ArrayBuffer ? new Uint8Array(e) : new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
1555
- if (l(n) && (n = await u(n)), o(n)) {
1556
- let e = c(n);
1595
+ if (u(n) && (n = await d(n)), s(n)) {
1596
+ let e = l(n);
1557
1597
  return {
1558
1598
  filesystem: e.filesystem,
1559
1599
  permissions: Object.assign({}, e.permissions, t)
@@ -1580,7 +1620,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1580
1620
  };
1581
1621
  }
1582
1622
  }
1583
- return typeof e == "object" && e.filesystem && typeof e.permissions == "object" ? d(e.filesystem) || o(e.filesystem) ? f(e.filesystem, Object.assign({}, e.permissions, t)) : {
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)) : {
1584
1624
  filesystem: e.filesystem,
1585
1625
  permissions: Object.assign({}, e.permissions, t)
1586
1626
  } : {
@@ -1589,33 +1629,33 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1589
1629
  };
1590
1630
  }
1591
1631
  t.exports = {
1592
- MAGIC: i,
1593
- FORMAT_VERSION: a,
1594
- isBinaryContainer: o,
1595
- isGzipBytes: l,
1596
- isAsyncFilesystemSource: d,
1597
- resolveFilesystemSource: f,
1598
- serializeBinaryFilesystem: s,
1599
- deserializeBinaryFilesystem: c,
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,
1600
1640
  FilesystemStorage: class {
1601
1641
  static async save(e, t = "brsh-rootfs") {
1602
- let n = e.context ? e.context.fs : e, r = s(n.getRaw(), n.getRawPermissions());
1642
+ let n = e.context ? e.context.fs : e, r = c(n.getRaw(), n.getRawPermissions());
1603
1643
  return typeof indexedDB < "u" && await this._idbPut(t, r), r;
1604
1644
  }
1605
1645
  static async load(e = "brsh-rootfs") {
1606
- if (e instanceof Uint8Array || e instanceof ArrayBuffer || typeof e == "string" && (/^https?:\/\//i.test(e) || e.endsWith(".brfs"))) return f(e);
1646
+ if (e instanceof Uint8Array || e instanceof ArrayBuffer || typeof e == "string" && (/^https?:\/\//i.test(e) || e.endsWith(".brfs"))) return p(e);
1607
1647
  if (typeof indexedDB < "u" && typeof e == "string") {
1608
1648
  let t = await this._idbGet(e);
1609
- if (t && o(t)) return c(t);
1649
+ if (t && s(t)) return l(t);
1610
1650
  }
1611
1651
  return null;
1612
1652
  }
1613
1653
  static async loadOrFetch(e = "brsh-rootfs", t = {}) {
1614
- return await this.load(e) || f(t);
1654
+ return await this.load(e) || p(t);
1615
1655
  }
1616
1656
  static createAutoSave(e = "brsh-rootfs", t = null) {
1617
1657
  return (n, r) => {
1618
- let i = s(n, r);
1658
+ let i = c(n, r);
1619
1659
  typeof indexedDB < "u" && this._idbPut(e, i).catch(() => {}), typeof t == "function" && t(i, n, r);
1620
1660
  };
1621
1661
  }
@@ -1653,11 +1693,11 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1653
1693
  };
1654
1694
  })), K = /* @__PURE__ */ t(((e, t) => {
1655
1695
  b();
1656
- var n = x(), { BinaryFile: r, SymlinkRef: i } = n;
1657
- function a(e) {
1696
+ var n = x(), { BinaryFile: r, SymlinkRef: i, DeviceFile: a } = n;
1697
+ function o(e) {
1658
1698
  for (let t of Object.keys(e)) {
1659
1699
  let n = e[t];
1660
- if (typeof n == "object" && n && !(n instanceof Uint8Array) && !(n instanceof i)) a(n);
1700
+ if (typeof n == "object" && n && !(n instanceof Uint8Array) && !(n instanceof i) && !(n instanceof a)) o(n);
1661
1701
  else if (typeof n == "string" && n.startsWith("data:")) {
1662
1702
  let i = n.indexOf(";"), a = n.indexOf(",", i);
1663
1703
  if (i !== -1 && a !== -1 && n.slice(i + 1, a) === "base64") {
@@ -1682,7 +1722,43 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1682
1722
  let { deserializeBinaryFilesystem: e } = G(), r = e(t);
1683
1723
  t = r.filesystem, n = Object.assign({}, r.permissions, n);
1684
1724
  }
1685
- a(t), this.fileSystem = t, this.permissions = Object.assign({}, n), this.cwd = e.endsWith("/") ? e : e + "/", this._onChange = r, this._changeScheduled = !1;
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");
1686
1762
  }
1687
1763
  toBinaryContainer(e = {}) {
1688
1764
  let { serializeBinaryFilesystem: t } = G();
@@ -1694,10 +1770,11 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1694
1770
  }
1695
1771
  getFileByPath(e) {
1696
1772
  let t = this._resolveByAbsolutePath(this._pathToAbsolute(e), !0);
1697
- return t == null || !this.isReadable(e) ? null : t;
1773
+ return t == null || !this.isReadable(e) ? null : t instanceof a ? t.read() : t;
1698
1774
  }
1699
1775
  _getFileRaw(e) {
1700
- return this._getFileByAbsolutePath(this._pathToAbsolute(e));
1776
+ let t = this._getFileByAbsolutePath(this._pathToAbsolute(e));
1777
+ return t instanceof a ? t.read() : t;
1701
1778
  }
1702
1779
  exists(e) {
1703
1780
  return this._resolveByAbsolutePath(this._pathToAbsolute(e), !0) != null;
@@ -1719,13 +1796,25 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1719
1796
  isFile: !1,
1720
1797
  isCommand: !1,
1721
1798
  isBinary: !1,
1722
- 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
1723
1810
  } : {
1724
1811
  isDirectory: t.constructor === Object,
1725
1812
  isFile: typeof t == "string" || t instanceof Uint8Array,
1726
1813
  isCommand: typeof t == "function",
1727
1814
  isBinary: t instanceof Uint8Array,
1728
- isSymlink: !1
1815
+ isSymlink: !1,
1816
+ isDevice: !1,
1817
+ isCharacterDevice: !1
1729
1818
  };
1730
1819
  }
1731
1820
  _pathToAbsolute(e) {
@@ -1743,9 +1832,13 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1743
1832
  return this._pathToAbsolute(e);
1744
1833
  }
1745
1834
  setFileByPath(e, t, n = !1) {
1746
- let r = this._pathToAbsolute(e);
1747
- if (this._getFileByAbsolutePath(r) != null) {
1835
+ let r = this._pathToAbsolute(e), i = this._getFileByAbsolutePath(r);
1836
+ if (i != null) {
1748
1837
  if (!this.isWritable(e)) throw Error("Permission denied");
1838
+ if (i instanceof a) {
1839
+ i.write(t), this._triggerChange();
1840
+ return;
1841
+ }
1749
1842
  } else {
1750
1843
  let e = r.split("/");
1751
1844
  e.pop();
@@ -1761,28 +1854,54 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1761
1854
  _setFileByAbsolutePath(e, t, n = !0) {
1762
1855
  let r = e.split("/");
1763
1856
  r.shift();
1764
- let a = r.pop(), o = this.fileSystem, s = [];
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 = [];
1765
1876
  for (let e of r) {
1766
- if (s.push(e), !Object.prototype.hasOwnProperty.call(o, e)) {
1877
+ if (c.push(e), !Object.prototype.hasOwnProperty.call(s, e)) {
1767
1878
  if (!n) throw Error(`${e}: No such file or directory`);
1768
- o[e] = {};
1879
+ s[e] = {};
1769
1880
  }
1770
- let t = o[e];
1881
+ let t = s[e];
1771
1882
  if (t instanceof i) {
1772
- let n = "/" + s.slice(0, -1).join("/"), r = t.target.startsWith("/") ? this._traverseComplexAbsolutePath(t.target) : this._traverseComplexAbsolutePath(n + "/" + t.target);
1883
+ let n = "/" + c.slice(0, -1).join("/"), r = t.target.startsWith("/") ? this._traverseComplexAbsolutePath(t.target) : this._traverseComplexAbsolutePath(n + "/" + t.target);
1773
1884
  if (t = this._resolveByAbsolutePath(r, !0), typeof t != "object" || !t || t instanceof i) throw Error(`${e}: Not a directory`);
1774
1885
  }
1775
- o = t;
1886
+ s = t;
1887
+ }
1888
+ if (s[o] instanceof a) {
1889
+ s[o].write(t);
1890
+ return;
1776
1891
  }
1777
- o[a] = t;
1892
+ s[o] = t;
1778
1893
  }
1779
1894
  _resolveByAbsolutePath(e, t = !0, n = 0) {
1780
1895
  if (n > 10) return null;
1781
1896
  let r = e.split("/");
1782
- 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();
1783
1898
  let a = this.fileSystem, o = [];
1784
1899
  for (let e = 0; e < r.length; e++) {
1785
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
+ }
1786
1905
  if (typeof a != "object" || !a || a instanceof i || !Object.prototype.hasOwnProperty.call(a, s)) return null;
1787
1906
  if (a = a[s], o.push(s), a instanceof i && (!c || t)) {
1788
1907
  let e = "/" + o.slice(0, -1).join("/"), t = a.target.startsWith("/") ? this._traverseComplexAbsolutePath(a.target) : this._traverseComplexAbsolutePath(e + "/" + a.target);
@@ -1793,7 +1912,16 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1793
1912
  }
1794
1913
  _getFileByAbsolutePath(e) {
1795
1914
  let t = e.split("/");
1796
- return t.shift(), t[t.length - 1].length < 1 && t.pop(), t.reduce((e, t) => typeof e != "object" || !e || !Object.prototype.hasOwnProperty.call(e, t) ? null : e[t], this.fileSystem);
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);
1797
1925
  }
1798
1926
  deleteFileByPath(e) {
1799
1927
  let t = this._pathToAbsolute(e), n = t.split("/");
@@ -1811,6 +1939,16 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1811
1939
  t.shift(), t[t.length - 1] === "" && t.pop();
1812
1940
  let n = t.pop();
1813
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;
1814
1952
  let r = this.fileSystem, a = [];
1815
1953
  for (let e of t) {
1816
1954
  if (a.push(e), !Object.prototype.hasOwnProperty.call(r, e)) return;
@@ -1827,7 +1965,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1827
1965
  let t = this._pathToAbsolute(e);
1828
1966
  if (this.permissions[t] !== void 0) return this.permissions[t];
1829
1967
  let n = this._resolveByAbsolutePath(t, !0);
1830
- 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;
1831
1969
  }
1832
1970
  setMode(e, t) {
1833
1971
  let n = this._pathToAbsolute(e);
@@ -1835,7 +1973,12 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
1835
1973
  }
1836
1974
  getSize(e) {
1837
1975
  let t = this._pathToAbsolute(e), n = this._resolveByAbsolutePath(t, !0);
1838
- return n == null ? 0 : n.constructor === Object ? JSON.stringify(n).length : n instanceof Uint8Array ? n.length : n.toString().length;
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;
1839
1982
  }
1840
1983
  getRawPermissions() {
1841
1984
  return Object.assign({}, this.permissions);
@@ -2323,6 +2466,9 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
2323
2466
  onInput(e) {
2324
2467
  this.sandbox && this.sandbox.onInput(e);
2325
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
+ }
2326
2472
  run() {
2327
2473
  let e = this.context && this.context.fs || this.fs, t = e && e.isRealFilesystem ? { useRealFilesystem: !0 } : {
2328
2474
  filesystem: e && e.getRaw() || {},
@@ -2711,15 +2857,27 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
2711
2857
  return !0;
2712
2858
  }
2713
2859
  get interactive() {
2714
- if ((this.arguments || []).some((e) => e === "--help" || e === "-h" || e === "--version" || e === "-V" || e === "-v")) return !1;
2715
- if (this._isInteractive !== void 0) return !!this._isInteractive;
2716
- if (this._pkgMeta && this._pkgMeta.interactive !== void 0) return !!this._pkgMeta.interactive;
2717
- let e = (this.script || this.name || "").toLowerCase();
2718
- 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;
2719
2861
  }
2720
2862
  get captureInput() {
2721
2863
  return this.interactive;
2722
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
+ }
2723
2881
  _enterAltScreen() {
2724
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"));
2725
2883
  }
@@ -2782,22 +2940,26 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
2782
2940
  _loadBytes(e, t) {
2783
2941
  let n = this.context && this.context.fs || this.fs;
2784
2942
  if (!n) return Promise.reject(/* @__PURE__ */ Error(`${e}: Filesystem is not available`));
2943
+ let r;
2785
2944
  if (n.isRealFilesystem && t) try {
2786
- let r = t.readFileSync(n.absolutePath(e)), i = new Uint8Array(r);
2787
- return Promise.resolve({
2788
- bytes: i,
2789
- isWat: this._isWat(e, i)
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)
2790
2949
  });
2791
2950
  } catch (t) {
2792
2951
  return Promise.reject(/* @__PURE__ */ Error(`${e}: ${t.message}`));
2793
2952
  }
2794
- let r = n.getFileByPath(e);
2795
- if (r == null) return Promise.reject(/* @__PURE__ */ Error(`${e}: No such file or directory`));
2796
- let i = this._contentToBytes(r);
2797
- return Promise.resolve({
2798
- bytes: i,
2799
- isWat: this._isWat(e, i)
2800
- });
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));
2801
2963
  }
2802
2964
  _isWat(e, t) {
2803
2965
  return e.endsWith(".wat") ? !0 : t.length > 0 && t[0] === 40;
@@ -2839,7 +3001,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
2839
3001
  1: "",
2840
3002
  2: ""
2841
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 = () => {
2842
- 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));
2843
3005
  }, R = (e, n) => {
2844
3006
  if (I && (e === 1 || e === 2)) {
2845
3007
  if (e === 1 && this.stdout) {
@@ -2996,8 +3158,8 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
2996
3158
  }
2997
3159
  return s.setUint32(r, e, !0), i;
2998
3160
  }
2999
- return o ? (s.setUint32(r, 0, !0), a) : (E.exports.asyncify_start_unwind(O), k = new Promise((e) => {
3000
- 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;
3001
3163
  }), s.setUint32(r, 0, !0), i);
3002
3164
  }
3003
3165
  if (z.length > 0) {
@@ -3148,14 +3310,16 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
3148
3310
  path: y
3149
3311
  }), new DataView(T.buffer).setUint32(h, e, !0), i;
3150
3312
  }
3151
- if (y === "/dev/tty") {
3313
+ if (y === "/dev/tty" || y === "/dev/stdin") {
3152
3314
  L();
3153
3315
  let e = ne++;
3154
3316
  return G.set(e, {
3155
3317
  type: "dev_tty",
3156
- path: "/dev/tty"
3318
+ path: y
3157
3319
  }), new DataView(T.buffer).setUint32(h, e, !0), i;
3158
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;
3159
3323
  let w = U.stat(g), E = w !== null;
3160
3324
  if (c & x && c & _ && E) return s;
3161
3325
  if (c & v) {
@@ -3188,13 +3352,12 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
3188
3352
  if (!T || !U) return o;
3189
3353
  let c = J(e, n.decode(new Uint8Array(T.buffer, r, a)));
3190
3354
  if (!c) return o;
3191
- let l = c.replace(/\/+/g, "/").replace(/\/$/, "") || "/";
3192
- 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)) {
3193
3357
  let e = new DataView(T.buffer);
3194
3358
  for (let t = 0; t < 64; t++) e.setUint8(s + t, 0);
3195
3359
  return e.setUint8(s + 16, m), e.setBigUint64(s + 24, 1n, !0), i;
3196
3360
  }
3197
- let d = U.stat(c);
3198
3361
  if (!d) return u;
3199
3362
  let f = new DataView(T.buffer);
3200
3363
  for (let e = 0; e < 64; e++) f.setUint8(s + e, 0);
@@ -3204,6 +3367,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
3204
3367
  if (!T || !U) return o;
3205
3368
  let a = J(e, n.decode(new Uint8Array(T.buffer, t, r)));
3206
3369
  if (!a) return o;
3370
+ if (U.exists(a)) return s;
3207
3371
  try {
3208
3372
  return U.setFileByPath(a, {}, !0), i;
3209
3373
  } catch {
@@ -3352,12 +3516,14 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
3352
3516
  }
3353
3517
  return a.setUint32(r, o, !0), i;
3354
3518
  }
3355
- return E.exports.asyncify_start_unwind(O), k = new Promise((e) => {
3356
- let t = null;
3357
- A = () => {
3358
- t && clearTimeout(t), A = null, e();
3359
- }, s !== Infinity && (t = setTimeout(() => {
3360
- A = null, e();
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();
3361
3527
  }, Math.max(1, s)));
3362
3528
  }), a.setUint32(r, 0, !0), i;
3363
3529
  }
@@ -3440,16 +3606,37 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
3440
3606
  let i = E.exports._start || E.exports.__wasi_command || E.exports.main || E.exports.run;
3441
3607
  if (i) try {
3442
3608
  let e = i();
3443
- for (e && typeof e.then == "function" && (e = await e); D && typeof E.exports.asyncify_get_state == "function" && E.exports.asyncify_get_state() === 1;) E.exports.asyncify_stop_unwind(), k &&= (await k, null), E.exports.asyncify_start_rewind(O), e = i(), e && typeof e.then == "function" && (e = await e);
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
+ }
3444
3631
  } catch (e) {
3445
- (!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);
3446
3633
  }
3447
3634
  else {
3448
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(", ")})` : "";
3449
3636
  this.stdErr = `${this.script}: no CLI entry point found (expected _start, main, or run)${t}`, this.exitCode = 1;
3450
3637
  }
3451
3638
  } catch (e) {
3452
- (!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);
3453
3640
  } finally {
3454
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;
3455
3642
  for (let e of G.values()) Y(e);
@@ -3566,13 +3753,15 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
3566
3753
  usage: null,
3567
3754
  options: [],
3568
3755
  exports: [],
3569
- wasiImports: []
3756
+ wasiImports: [],
3757
+ hasAsyncify: !1,
3758
+ isInteractive: !1
3570
3759
  };
3571
3760
  if (!(e instanceof Uint8Array) || e.length < 8) return t;
3572
3761
  try {
3573
3762
  if (typeof WebAssembly < "u" && WebAssembly.Module) {
3574
3763
  let n = new WebAssembly.Module(e);
3575
- 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);
3576
3765
  }
3577
3766
  } catch {}
3578
3767
  try {
@@ -3582,8 +3771,10 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
3582
3771
  i >= 32 && i <= 126 || i === 9 || i === 10 ? r += String.fromCharCode(i) : (r.length >= 4 && n.push(r), r = "");
3583
3772
  }
3584
3773
  r.length >= 4 && n.push(r);
3585
- let i = A(n.join("\n"), !0);
3586
- t.usage = i.usage, t.options = i.options;
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;
3587
3778
  } catch {}
3588
3779
  return t;
3589
3780
  }
@@ -3607,6 +3798,18 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
3607
3798
  get requiresFilesystem() {
3608
3799
  return !0;
3609
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
+ }
3610
3813
  async run() {
3611
3814
  let n = [...this.arguments || []], r = n.includes("--help") || n.includes("-h"), a = !r && (n.includes("--version") || n.includes("-V") || n.includes("-v"));
3612
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));
@@ -3698,7 +3901,12 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
3698
3901
  }
3699
3902
  async _runRawWasmBytes(t, n) {
3700
3903
  let r = new T(i, n, this.context);
3701
- 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), await r._runWasm(t);
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
+ }
3702
3910
  for (let e of r.result.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
3703
3911
  this.exitCode = r.result.getExitCode();
3704
3912
  }
@@ -8065,6 +8273,10 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
8065
8273
  let e = this.context.fs.exists(this.context.getVar("PATH"));
8066
8274
  this._loadDefaultCommands(), this._loadBuiltinCommands(e), this.ready = Promise.resolve(this), s ? this._initializing = !1 : (this._initializing = !0, setTimeout(() => this._init(), 0));
8067
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
+ });
8068
8280
  }
8069
8281
  async _initAsyncFilesystem(t, n, r) {
8070
8282
  let i = this.context.getVar("PATH") || "/bin", a = () => {
@@ -8084,7 +8296,10 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
8084
8296
  let u = this.context.fs.exists(i);
8085
8297
  this._loadDefaultCommands(), this._loadBuiltinCommands(u);
8086
8298
  for (let e of c) this.context.setCommand(e);
8087
- 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
+ });
8088
8303
  } catch (e) {
8089
8304
  this.emit("stdErr", e.message || String(e));
8090
8305
  } finally {
@@ -8583,7 +8798,12 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
8583
8798
  _handleStdinData(e) {
8584
8799
  let t = typeof e == "string" ? e : e instanceof Uint8Array || y !== void 0 && y.isBuffer(e) ? new TextDecoder().decode(e) : String(e ?? "");
8585
8800
  if (this.runningCommand) {
8586
- let t = this.runningCommand, n = t.stdinStream && t.stdinStream.listenerCount("data") > 1;
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;
8587
8807
  if (t.captureInput || t.interactive || t._inAltScreen || n) {
8588
8808
  t.stdinStream.pushData(e);
8589
8809
  return;