@lifo-sh/core 0.1.0 → 0.2.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/README.md +65 -0
- package/dist/{archive-D220So0m.js → archive-nRHWNwjH.js} +1 -1
- package/dist/{awk-rMPdpM91.js → awk-CchAsBzt.js} +1 -1
- package/dist/{basename-C33A_Zse.js → basename-C2v8jn7p.js} +1 -1
- package/dist/{cat-Crmqa4-2.js → cat-B2exoWlk.js} +1 -1
- package/dist/{chmod-CcGyvoCX.js → chmod-CQS63aP7.js} +1 -1
- package/dist/{chown-CErsnGQX.js → chown-rgGwZwu9.js} +1 -1
- package/dist/{cp-CpjwiLUF.js → cp-C8mNek36.js} +1 -1
- package/dist/{cut-GfN8py4j.js → cut-BZez9bS1.js} +1 -1
- package/dist/{diff-2wbVWmCT.js → diff-tWPvmikU.js} +1 -1
- package/dist/{dirname-C5L53RA2.js → dirname-BY_Gu5i2.js} +1 -1
- package/dist/{du-B0shJpEL.js → du-D25egSeK.js} +1 -1
- package/dist/{file-C2epVYvH.js → file-BPs1dqg5.js} +1 -1
- package/dist/{find-DA-rpvsC.js → find-CRUAXbhO.js} +1 -1
- package/dist/{grep-Bynq2w2E.js → grep-B9pTCSNY.js} +1 -1
- package/dist/{gunzip-B9b1Vph1.js → gunzip-BYlJhPf7.js} +2 -2
- package/dist/{gzip-CkXnPp5J.js → gzip-DgE-9PzE.js} +2 -2
- package/dist/{head-DZJVLF1k.js → head-DzP_T5Wx.js} +1 -1
- package/dist/{index-Be1wosKt.js → index-DccAPaZF.js} +861 -879
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -12
- package/dist/{ls-CSeazevv.js → ls-BiT10kLm.js} +1 -1
- package/dist/{mkdir-B7p8krsP.js → mkdir-DgzJ2JLj.js} +1 -1
- package/dist/{mktemp-88Nhvd7h.js → mktemp-Sh5DWxvc.js} +1 -1
- package/dist/{mv-DRVvz9oK.js → mv-Kp6DjQ8n.js} +1 -1
- package/dist/{nl-G2vK3rR3.js → nl-DBLFdpfC.js} +1 -1
- package/dist/{realpath-C-kisl-F.js → realpath-BOeYN6nD.js} +1 -1
- package/dist/{rev-9puwegeh.js → rev-CWRUIXWp.js} +1 -1
- package/dist/{rm-BXSq9iqP.js → rm-DA2w3xTR.js} +1 -1
- package/dist/{rmdir-CWgZ6q8D.js → rmdir-BiGbNDOT.js} +1 -1
- package/dist/sandbox/HeadlessTerminal.d.ts +2 -1
- package/dist/sandbox/HeadlessTerminal.d.ts.map +1 -1
- package/dist/sandbox/Sandbox.d.ts.map +1 -1
- package/dist/sandbox/types.d.ts +3 -2
- package/dist/sandbox/types.d.ts.map +1 -1
- package/dist/{sed-BRxd2DlZ.js → sed-ClWZ06zX.js} +1 -1
- package/dist/shell/Shell.d.ts +2 -2
- package/dist/shell/Shell.d.ts.map +1 -1
- package/dist/{sort-B7K83hAD.js → sort-CSzSGTdB.js} +1 -1
- package/dist/{stat-C0qs7xMV.js → stat-D0i1gTKB.js} +1 -1
- package/dist/{tail-CYBTYnn3.js → tail-tcIJLQnB.js} +1 -1
- package/dist/{tar-mMS7gfb-.js → tar-DkyzTzmT.js} +2 -2
- package/dist/{tee-B8bXFHbI.js → tee-RqoZ3qG-.js} +1 -1
- package/dist/terminal/ITerminal.d.ts +10 -0
- package/dist/terminal/ITerminal.d.ts.map +1 -0
- package/dist/{touch-CdAHKfLv.js → touch-k2NomRzL.js} +1 -1
- package/dist/{tree-BiWLXiUu.js → tree-B_j2_PsZ.js} +1 -1
- package/dist/{uniq-BZMOwoCc.js → uniq-hzJnHQOm.js} +1 -1
- package/dist/{unzip-DP4I991d.js → unzip-FwYCTDEZ.js} +2 -2
- package/dist/{wc-CpE5K4ZI.js → wc-Jp7nOops.js} +1 -1
- package/dist/{wget-DIPI0-I3.js → wget-2NAABIHc.js} +1 -1
- package/dist/{zip-B_gQ6LXC.js → zip--0ncHv0q.js} +2 -2
- package/package.json +35 -11
- package/dist/terminal/Terminal.d.ts +0 -13
- package/dist/terminal/Terminal.d.ts.map +0 -1
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { Terminal as Pt } from "@xterm/xterm";
|
|
5
|
-
import { FitAddon as Tt } from "@xterm/addon-fit";
|
|
6
|
-
import { WebglAddon as At } from "@xterm/addon-webgl";
|
|
1
|
+
var Lt = Object.defineProperty;
|
|
2
|
+
var Pt = (r, e, t) => e in r ? Lt(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var u = (r, e, t) => Pt(r, typeof e != "symbol" ? e + "" : e, t);
|
|
7
4
|
function W(r) {
|
|
8
5
|
if (r === "") return ".";
|
|
9
6
|
const e = r.startsWith("/"), t = r.split("/"), s = [];
|
|
@@ -37,14 +34,14 @@ function Q(r) {
|
|
|
37
34
|
const e = K(r), t = e.lastIndexOf(".");
|
|
38
35
|
return t <= 0 ? "" : e.slice(t);
|
|
39
36
|
}
|
|
40
|
-
const
|
|
37
|
+
const Tt = new TextEncoder(), _t = new TextDecoder();
|
|
41
38
|
function ee(r) {
|
|
42
|
-
return
|
|
39
|
+
return Tt.encode(r);
|
|
43
40
|
}
|
|
44
|
-
function
|
|
45
|
-
return
|
|
41
|
+
function Rt(r) {
|
|
42
|
+
return _t.decode(r);
|
|
46
43
|
}
|
|
47
|
-
function
|
|
44
|
+
function xr(...r) {
|
|
48
45
|
const e = r.reduce((i, n) => i + n.length, 0), t = new Uint8Array(e);
|
|
49
46
|
let s = 0;
|
|
50
47
|
for (const i of r)
|
|
@@ -62,15 +59,15 @@ const C = {
|
|
|
62
59
|
class k extends Error {
|
|
63
60
|
constructor(t, s) {
|
|
64
61
|
super(`${t}: ${s}`);
|
|
65
|
-
|
|
62
|
+
u(this, "code");
|
|
66
63
|
this.code = t, this.name = "VFSError";
|
|
67
64
|
}
|
|
68
65
|
}
|
|
69
|
-
class
|
|
66
|
+
class At {
|
|
70
67
|
constructor() {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
u(this, "root");
|
|
69
|
+
u(this, "virtualProviders", /* @__PURE__ */ new Map());
|
|
70
|
+
u(this, "onChange");
|
|
74
71
|
this.root = this.createNode("directory", "");
|
|
75
72
|
}
|
|
76
73
|
registerProvider(e, t) {
|
|
@@ -139,7 +136,7 @@ class It {
|
|
|
139
136
|
}
|
|
140
137
|
readFileString(e) {
|
|
141
138
|
const t = this.getProvider(e);
|
|
142
|
-
return t ? t.provider.readFileString(t.subpath) :
|
|
139
|
+
return t ? t.provider.readFileString(t.subpath) : Rt(this.readFile(e));
|
|
143
140
|
}
|
|
144
141
|
writeFile(e, t) {
|
|
145
142
|
var c;
|
|
@@ -241,13 +238,13 @@ class It {
|
|
|
241
238
|
if (t != null && t.recursive) {
|
|
242
239
|
const l = this.toAbsolute(e).split("/").filter(Boolean);
|
|
243
240
|
let f = this.root;
|
|
244
|
-
for (const
|
|
245
|
-
let
|
|
246
|
-
if (!
|
|
247
|
-
|
|
248
|
-
else if (
|
|
249
|
-
throw new k(C.ENOTDIR, `'${
|
|
250
|
-
f =
|
|
241
|
+
for (const h of l) {
|
|
242
|
+
let p = f.children.get(h);
|
|
243
|
+
if (!p)
|
|
244
|
+
p = this.createNode("directory", h), f.children.set(h, p);
|
|
245
|
+
else if (p.type !== "directory")
|
|
246
|
+
throw new k(C.ENOTDIR, `'${h}': not a directory`);
|
|
247
|
+
f = p;
|
|
251
248
|
}
|
|
252
249
|
(o = this.onChange) == null || o.call(this);
|
|
253
250
|
return;
|
|
@@ -320,9 +317,9 @@ class It {
|
|
|
320
317
|
this.rmdir(s);
|
|
321
318
|
}
|
|
322
319
|
}
|
|
323
|
-
class
|
|
320
|
+
class Ft {
|
|
324
321
|
constructor() {
|
|
325
|
-
|
|
322
|
+
u(this, "generators", /* @__PURE__ */ new Map());
|
|
326
323
|
this.generators.set("cpuinfo", () => {
|
|
327
324
|
const e = typeof navigator < "u" ? navigator.hardwareConcurrency ?? 1 : 1, t = [];
|
|
328
325
|
for (let s = 0; s < e; s++)
|
|
@@ -415,9 +412,9 @@ class Nt {
|
|
|
415
412
|
}
|
|
416
413
|
}
|
|
417
414
|
const re = ["null", "zero", "random", "urandom", "clipboard"];
|
|
418
|
-
class
|
|
415
|
+
class It {
|
|
419
416
|
constructor() {
|
|
420
|
-
|
|
417
|
+
u(this, "clipboardCache", "");
|
|
421
418
|
}
|
|
422
419
|
readFile(e) {
|
|
423
420
|
switch (e.startsWith("/") ? e.slice(1) : e) {
|
|
@@ -484,23 +481,23 @@ class Bt {
|
|
|
484
481
|
throw new k(C.ENOTDIR, `'/dev${e}': not a directory`);
|
|
485
482
|
}
|
|
486
483
|
}
|
|
487
|
-
const
|
|
488
|
-
function
|
|
484
|
+
const Nt = ["proc", "dev"];
|
|
485
|
+
function Bt(r) {
|
|
489
486
|
let e = "";
|
|
490
487
|
for (let t = 0; t < r.length; t++)
|
|
491
488
|
e += String.fromCharCode(r[t]);
|
|
492
489
|
return btoa(e);
|
|
493
490
|
}
|
|
494
|
-
function
|
|
491
|
+
function zt(r) {
|
|
495
492
|
const e = atob(r), t = new Uint8Array(e.length);
|
|
496
493
|
for (let s = 0; s < e.length; s++)
|
|
497
494
|
t[s] = e.charCodeAt(s);
|
|
498
495
|
return t;
|
|
499
496
|
}
|
|
500
|
-
function
|
|
501
|
-
return
|
|
497
|
+
function jt(r) {
|
|
498
|
+
return Ue(r, !0);
|
|
502
499
|
}
|
|
503
|
-
function
|
|
500
|
+
function Ue(r, e) {
|
|
504
501
|
if (r.type === "file") {
|
|
505
502
|
const i = {
|
|
506
503
|
t: "f",
|
|
@@ -509,11 +506,11 @@ function He(r, e) {
|
|
|
509
506
|
mt: r.mtime,
|
|
510
507
|
m: r.mode
|
|
511
508
|
};
|
|
512
|
-
return r.data.length > 0 && (i.d =
|
|
509
|
+
return r.data.length > 0 && (i.d = Bt(r.data)), i;
|
|
513
510
|
}
|
|
514
511
|
const t = [];
|
|
515
512
|
for (const [i, n] of r.children)
|
|
516
|
-
e &&
|
|
513
|
+
e && Nt.includes(i) || t.push(Ue(n, !1));
|
|
517
514
|
const s = {
|
|
518
515
|
t: "d",
|
|
519
516
|
n: r.name,
|
|
@@ -523,36 +520,36 @@ function He(r, e) {
|
|
|
523
520
|
};
|
|
524
521
|
return t.length > 0 && (s.c = t), s;
|
|
525
522
|
}
|
|
526
|
-
function
|
|
527
|
-
return
|
|
523
|
+
function Dt(r) {
|
|
524
|
+
return He(r);
|
|
528
525
|
}
|
|
529
|
-
function
|
|
526
|
+
function He(r) {
|
|
530
527
|
const e = /* @__PURE__ */ new Map();
|
|
531
528
|
if (r.t === "d" && r.c)
|
|
532
529
|
for (const t of r.c) {
|
|
533
|
-
const s =
|
|
530
|
+
const s = He(t);
|
|
534
531
|
e.set(s.name, s);
|
|
535
532
|
}
|
|
536
533
|
return {
|
|
537
534
|
type: r.t === "f" ? "file" : "directory",
|
|
538
535
|
name: r.n,
|
|
539
|
-
data: r.d ?
|
|
536
|
+
data: r.d ? zt(r.d) : new Uint8Array(0),
|
|
540
537
|
children: e,
|
|
541
538
|
ctime: r.ct,
|
|
542
539
|
mtime: r.mt,
|
|
543
540
|
mode: r.m
|
|
544
541
|
};
|
|
545
542
|
}
|
|
546
|
-
const
|
|
547
|
-
class
|
|
543
|
+
const Ot = "lifo", V = "filesystem", $e = "root", Mt = 1e3;
|
|
544
|
+
class Wt {
|
|
548
545
|
constructor() {
|
|
549
|
-
|
|
550
|
-
|
|
546
|
+
u(this, "db", null);
|
|
547
|
+
u(this, "timer", null);
|
|
551
548
|
}
|
|
552
549
|
async open() {
|
|
553
550
|
if (!(typeof indexedDB > "u"))
|
|
554
551
|
return new Promise((e) => {
|
|
555
|
-
const t = indexedDB.open(
|
|
552
|
+
const t = indexedDB.open(Ot, 1);
|
|
556
553
|
t.onupgradeneeded = () => {
|
|
557
554
|
const s = t.result;
|
|
558
555
|
s.objectStoreNames.contains(V) || s.createObjectStore(V);
|
|
@@ -570,7 +567,7 @@ class Ut {
|
|
|
570
567
|
i.onsuccess = () => {
|
|
571
568
|
if (i.result)
|
|
572
569
|
try {
|
|
573
|
-
const n =
|
|
570
|
+
const n = Dt(i.result);
|
|
574
571
|
e(n);
|
|
575
572
|
} catch {
|
|
576
573
|
e(null);
|
|
@@ -585,7 +582,7 @@ class Ut {
|
|
|
585
582
|
}
|
|
586
583
|
async save(e) {
|
|
587
584
|
if (!this.db) return;
|
|
588
|
-
const t =
|
|
585
|
+
const t = jt(e);
|
|
589
586
|
return new Promise((s) => {
|
|
590
587
|
try {
|
|
591
588
|
const i = this.db.transaction(V, "readwrite");
|
|
@@ -599,10 +596,10 @@ class Ut {
|
|
|
599
596
|
this.timer && clearTimeout(this.timer), this.timer = setTimeout(() => {
|
|
600
597
|
this.save(e).catch(() => {
|
|
601
598
|
}), this.timer = null;
|
|
602
|
-
},
|
|
599
|
+
}, Mt);
|
|
603
600
|
}
|
|
604
601
|
}
|
|
605
|
-
function
|
|
602
|
+
function qt(r) {
|
|
606
603
|
const e = "/home/user/examples", t = [
|
|
607
604
|
e,
|
|
608
605
|
`${e}/scripts`,
|
|
@@ -614,10 +611,10 @@ function Ht(r) {
|
|
|
614
611
|
r.mkdir(s, { recursive: !0 });
|
|
615
612
|
} catch {
|
|
616
613
|
}
|
|
617
|
-
for (const [s, i] of Object.entries(
|
|
614
|
+
for (const [s, i] of Object.entries(Ut))
|
|
618
615
|
r.exists(`${e}/${s}`) || r.writeFile(`${e}/${s}`, i);
|
|
619
616
|
}
|
|
620
|
-
const
|
|
617
|
+
const Ut = {
|
|
621
618
|
// ─── README ───
|
|
622
619
|
"README.txt": `Lifo Examples
|
|
623
620
|
==================
|
|
@@ -1270,6 +1267,63 @@ console.log("\\nAdmin users:");
|
|
|
1270
1267
|
for (const user of data.users.filter(u => u.role === "admin")) {
|
|
1271
1268
|
console.log(\` \${user.name} (active: \${user.active})\`);
|
|
1272
1269
|
}
|
|
1270
|
+
`,
|
|
1271
|
+
"node/http-server.js": `// Run with: node examples/node/http-server.js
|
|
1272
|
+
// Then in another terminal: curl localhost:3000
|
|
1273
|
+
// Or run: node examples/node/http-client.js
|
|
1274
|
+
|
|
1275
|
+
const http = require("http");
|
|
1276
|
+
|
|
1277
|
+
const server = http.createServer((req, res) => {
|
|
1278
|
+
const body = JSON.stringify({
|
|
1279
|
+
message: "Hello from Lifo!",
|
|
1280
|
+
method: req.method,
|
|
1281
|
+
url: req.url,
|
|
1282
|
+
time: new Date().toISOString(),
|
|
1283
|
+
}, null, 2);
|
|
1284
|
+
|
|
1285
|
+
res.writeHead(200, {
|
|
1286
|
+
"Content-Type": "application/json",
|
|
1287
|
+
"Content-Length": Buffer.byteLength(body),
|
|
1288
|
+
});
|
|
1289
|
+
res.end(body);
|
|
1290
|
+
});
|
|
1291
|
+
|
|
1292
|
+
server.listen(3000, () => {
|
|
1293
|
+
console.log("Server running on http://localhost:3000");
|
|
1294
|
+
console.log("Try: curl localhost:3000");
|
|
1295
|
+
console.log("Press Ctrl+C to stop");
|
|
1296
|
+
});
|
|
1297
|
+
`,
|
|
1298
|
+
"node/http-client.js": `// Run with: node examples/node/http-client.js
|
|
1299
|
+
// Make sure http-server.js is running first!
|
|
1300
|
+
|
|
1301
|
+
const http = require("http");
|
|
1302
|
+
|
|
1303
|
+
function request(path) {
|
|
1304
|
+
return new Promise((resolve, reject) => {
|
|
1305
|
+
http.get("http://localhost:3000" + path, (res) => {
|
|
1306
|
+
let data = "";
|
|
1307
|
+
res.on("data", (chunk) => data += chunk);
|
|
1308
|
+
res.on("end", () => {
|
|
1309
|
+
console.log("GET " + path);
|
|
1310
|
+
console.log("Status:", res.statusCode);
|
|
1311
|
+
console.log("Response:", data);
|
|
1312
|
+
console.log();
|
|
1313
|
+
resolve(data);
|
|
1314
|
+
});
|
|
1315
|
+
});
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
async function main() {
|
|
1320
|
+
await request("/");
|
|
1321
|
+
await request("/api/users");
|
|
1322
|
+
await request("/health");
|
|
1323
|
+
console.log("Done!");
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
main();
|
|
1273
1327
|
`,
|
|
1274
1328
|
// ─── Text processing cheatsheet ───
|
|
1275
1329
|
"scripts/11-text-processing.sh": `#!/bin/sh
|
|
@@ -1377,7 +1431,7 @@ tree /home/user -L 2
|
|
|
1377
1431
|
|
|
1378
1432
|
echo "Done."
|
|
1379
1433
|
`
|
|
1380
|
-
},
|
|
1434
|
+
}, Ht = `\x1B[1;36m
|
|
1381
1435
|
_ _ __
|
|
1382
1436
|
| | (_)/ _| ___
|
|
1383
1437
|
| | | | |_ / _ \\
|
|
@@ -1387,9 +1441,9 @@ echo "Done."
|
|
|
1387
1441
|
\x1B[2mA Linux-like OS running natively in your browser.\x1B[0m
|
|
1388
1442
|
\x1B[2mType 'help' or try: ls, cd, cat, mkdir, touch\x1B[0m
|
|
1389
1443
|
\x1B[2mExplore examples: ls ~/examples/scripts\x1B[0m
|
|
1390
|
-
`,
|
|
1444
|
+
`, Vt = `export PATH=/usr/bin:/bin
|
|
1391
1445
|
export EDITOR=nano
|
|
1392
|
-
`,
|
|
1446
|
+
`, Gt = `# Aliases
|
|
1393
1447
|
alias ll='ls -la'
|
|
1394
1448
|
alias la='ls -a'
|
|
1395
1449
|
alias l='ls -1'
|
|
@@ -1397,12 +1451,12 @@ alias ..='cd ..'
|
|
|
1397
1451
|
alias cls='clear'
|
|
1398
1452
|
alias h='history'
|
|
1399
1453
|
`;
|
|
1400
|
-
class
|
|
1454
|
+
class Zt {
|
|
1401
1455
|
constructor() {
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
this.vfs = new
|
|
1456
|
+
u(this, "vfs");
|
|
1457
|
+
u(this, "portRegistry", /* @__PURE__ */ new Map());
|
|
1458
|
+
u(this, "persistence");
|
|
1459
|
+
this.vfs = new At(), this.persistence = new Wt();
|
|
1406
1460
|
}
|
|
1407
1461
|
async boot(e) {
|
|
1408
1462
|
const t = (e == null ? void 0 : e.persist) ?? !0;
|
|
@@ -1411,7 +1465,7 @@ class Yt {
|
|
|
1411
1465
|
const s = await this.persistence.load();
|
|
1412
1466
|
s && this.vfs.loadFromSerialized(s);
|
|
1413
1467
|
}
|
|
1414
|
-
this.initFilesystem(), this.vfs.registerProvider("/proc", new
|
|
1468
|
+
this.initFilesystem(), this.vfs.registerProvider("/proc", new Ft()), this.vfs.registerProvider("/dev", new It()), t && (this.vfs.onChange = () => {
|
|
1415
1469
|
this.persistence.scheduleSave(this.vfs.getRoot());
|
|
1416
1470
|
});
|
|
1417
1471
|
}
|
|
@@ -1435,8 +1489,8 @@ class Yt {
|
|
|
1435
1489
|
this.vfs.mkdir(t, { recursive: !0 });
|
|
1436
1490
|
} catch {
|
|
1437
1491
|
}
|
|
1438
|
-
this.vfs.writeFile("/etc/motd",
|
|
1439
|
-
`), this.vfs.exists("/etc/profile") || this.vfs.writeFile("/etc/profile",
|
|
1492
|
+
this.vfs.writeFile("/etc/motd", Ht), this.vfs.writeFile("/etc/hostname", `lifo
|
|
1493
|
+
`), this.vfs.exists("/etc/profile") || this.vfs.writeFile("/etc/profile", Vt), this.vfs.exists("/home/user/.bashrc") || this.vfs.writeFile("/home/user/.bashrc", Gt), qt(this.vfs);
|
|
1440
1494
|
}
|
|
1441
1495
|
getDefaultEnv() {
|
|
1442
1496
|
return {
|
|
@@ -1450,30 +1504,30 @@ class Yt {
|
|
|
1450
1504
|
};
|
|
1451
1505
|
}
|
|
1452
1506
|
}
|
|
1453
|
-
const z = "\x1B[0m", Y = "\x1B[1m",
|
|
1454
|
-
function
|
|
1455
|
-
return
|
|
1507
|
+
const z = "\x1B[0m", Y = "\x1B[1m", Jt = "\x1B[2m", Sr = "\x1B[3m", kr = "\x1B[4m", Yt = "\x1B[31m", oe = "\x1B[32m", Xt = "\x1B[33m", ae = "\x1B[34m", Qt = "\x1B[35m", Kt = "\x1B[36m", Er = "\x1B[37m", Cr = "\x1B[91m", Lr = "\x1B[92m", Pr = "\x1B[93m", Tr = "\x1B[94m", _r = "\x1B[95m", Rr = "\x1B[96m";
|
|
1508
|
+
function Ar(r) {
|
|
1509
|
+
return Yt + r + z;
|
|
1456
1510
|
}
|
|
1457
|
-
function
|
|
1511
|
+
function Fr(r) {
|
|
1458
1512
|
return oe + r + z;
|
|
1459
1513
|
}
|
|
1460
|
-
function
|
|
1461
|
-
return
|
|
1514
|
+
function Ir(r) {
|
|
1515
|
+
return Xt + r + z;
|
|
1462
1516
|
}
|
|
1463
|
-
function
|
|
1517
|
+
function Nr(r) {
|
|
1464
1518
|
return ae + r + z;
|
|
1465
1519
|
}
|
|
1466
|
-
function
|
|
1467
|
-
return
|
|
1520
|
+
function Br(r) {
|
|
1521
|
+
return Qt + r + z;
|
|
1468
1522
|
}
|
|
1469
|
-
function
|
|
1470
|
-
return
|
|
1523
|
+
function zr(r) {
|
|
1524
|
+
return Kt + r + z;
|
|
1471
1525
|
}
|
|
1472
|
-
function
|
|
1526
|
+
function jr(r) {
|
|
1473
1527
|
return Y + r + z;
|
|
1474
1528
|
}
|
|
1475
|
-
function
|
|
1476
|
-
return
|
|
1529
|
+
function Dr(r) {
|
|
1530
|
+
return Jt + r + z;
|
|
1477
1531
|
}
|
|
1478
1532
|
var g = /* @__PURE__ */ ((r) => (r[r.Word = 0] = "Word", r[r.Pipe = 1] = "Pipe", r[r.And = 2] = "And", r[r.Or = 3] = "Or", r[r.Semi = 4] = "Semi", r[r.Amp = 5] = "Amp", r[r.RedirectOut = 6] = "RedirectOut", r[r.RedirectAppend = 7] = "RedirectAppend", r[r.RedirectIn = 8] = "RedirectIn", r[r.RedirectErr = 9] = "RedirectErr", r[r.RedirectErrAppend = 10] = "RedirectErrAppend", r[r.RedirectAll = 11] = "RedirectAll", r[r.DoubleSemi = 12] = "DoubleSemi", r[r.LParen = 13] = "LParen", r[r.RParen = 14] = "RParen", r[r.Newline = 15] = "Newline", r[r.EOF = 16] = "EOF", r))(g || {});
|
|
1479
1533
|
function xe(r) {
|
|
@@ -1496,12 +1550,12 @@ function xe(r) {
|
|
|
1496
1550
|
t++;
|
|
1497
1551
|
continue;
|
|
1498
1552
|
}
|
|
1499
|
-
const s =
|
|
1553
|
+
const s = es(r, t);
|
|
1500
1554
|
if (s) {
|
|
1501
1555
|
e.push(s.token), t = s.end;
|
|
1502
1556
|
continue;
|
|
1503
1557
|
}
|
|
1504
|
-
const i =
|
|
1558
|
+
const i = rs(r, t);
|
|
1505
1559
|
if (i) {
|
|
1506
1560
|
e.push(i.token), t = i.end;
|
|
1507
1561
|
continue;
|
|
@@ -1510,19 +1564,19 @@ function xe(r) {
|
|
|
1510
1564
|
}
|
|
1511
1565
|
return e.push({ kind: g.EOF, value: "", pos: t }), e;
|
|
1512
1566
|
}
|
|
1513
|
-
function
|
|
1567
|
+
function es(r, e) {
|
|
1514
1568
|
const t = r[e], s = r[e + 1];
|
|
1515
|
-
return t === "&" && s === ">" ? { token: { kind: g.RedirectAll, value: "&>", pos: e }, end: e + 2 } : t === "&" && s === "&" ? { token: { kind: g.And, value: "&&", pos: e }, end: e + 2 } : t === "&" ? { token: { kind: g.Amp, value: "&", pos: e }, end: e + 1 } : t === "|" && s === "|" ? { token: { kind: g.Or, value: "||", pos: e }, end: e + 2 } : t === "|" ? { token: { kind: g.Pipe, value: "|", pos: e }, end: e + 1 } : t === "2" && s === ">" && r[e + 2] === ">" ? { token: { kind: g.RedirectErrAppend, value: "2>>", pos: e }, end: e + 3 } : t === "2" && s === ">" ? e > 0 && !
|
|
1569
|
+
return t === "&" && s === ">" ? { token: { kind: g.RedirectAll, value: "&>", pos: e }, end: e + 2 } : t === "&" && s === "&" ? { token: { kind: g.And, value: "&&", pos: e }, end: e + 2 } : t === "&" ? { token: { kind: g.Amp, value: "&", pos: e }, end: e + 1 } : t === "|" && s === "|" ? { token: { kind: g.Or, value: "||", pos: e }, end: e + 2 } : t === "|" ? { token: { kind: g.Pipe, value: "|", pos: e }, end: e + 1 } : t === "2" && s === ">" && r[e + 2] === ">" ? { token: { kind: g.RedirectErrAppend, value: "2>>", pos: e }, end: e + 3 } : t === "2" && s === ">" ? e > 0 && !ts(r[e - 1]) ? null : { token: { kind: g.RedirectErr, value: "2>", pos: e }, end: e + 2 } : t === ">" && s === ">" ? { token: { kind: g.RedirectAppend, value: ">>", pos: e }, end: e + 2 } : t === ">" ? { token: { kind: g.RedirectOut, value: ">", pos: e }, end: e + 1 } : t === "<" ? { token: { kind: g.RedirectIn, value: "<", pos: e }, end: e + 1 } : t === ";" && s === ";" ? { token: { kind: g.DoubleSemi, value: ";;", pos: e }, end: e + 2 } : t === ";" ? { token: { kind: g.Semi, value: ";", pos: e }, end: e + 1 } : t === "(" ? { token: { kind: g.LParen, value: "(", pos: e }, end: e + 1 } : t === ")" ? { token: { kind: g.RParen, value: ")", pos: e }, end: e + 1 } : null;
|
|
1516
1570
|
}
|
|
1517
|
-
function
|
|
1571
|
+
function ts(r) {
|
|
1518
1572
|
return r === " " || r === " " || r === "|" || r === "&" || r === ";" || r === ">" || r === "<" || r === `
|
|
1519
1573
|
` || r === "(" || r === ")";
|
|
1520
1574
|
}
|
|
1521
|
-
function
|
|
1575
|
+
function ss(r) {
|
|
1522
1576
|
return r === " " || r === " " || r === "|" || r === "&" || r === ";" || r === ">" || r === "<" || r === "#" || r === `
|
|
1523
1577
|
` || r === "(" || r === ")";
|
|
1524
1578
|
}
|
|
1525
|
-
function
|
|
1579
|
+
function rs(r, e) {
|
|
1526
1580
|
const t = [];
|
|
1527
1581
|
let s = e, i = "", n = !1;
|
|
1528
1582
|
for (; s < r.length; ) {
|
|
@@ -1574,7 +1628,7 @@ function ns(r, e) {
|
|
|
1574
1628
|
continue;
|
|
1575
1629
|
}
|
|
1576
1630
|
}
|
|
1577
|
-
if (
|
|
1631
|
+
if (ss(a) || a === ">" || a === "<")
|
|
1578
1632
|
break;
|
|
1579
1633
|
i += a, s++, n = !0;
|
|
1580
1634
|
}
|
|
@@ -1623,9 +1677,9 @@ class ke extends Error {
|
|
|
1623
1677
|
}
|
|
1624
1678
|
}
|
|
1625
1679
|
function Ee(r) {
|
|
1626
|
-
return new
|
|
1680
|
+
return new ns(r).parseScript();
|
|
1627
1681
|
}
|
|
1628
|
-
const
|
|
1682
|
+
const is = /* @__PURE__ */ new Set([
|
|
1629
1683
|
"if",
|
|
1630
1684
|
"then",
|
|
1631
1685
|
"else",
|
|
@@ -1640,10 +1694,10 @@ const os = /* @__PURE__ */ new Set([
|
|
|
1640
1694
|
"case",
|
|
1641
1695
|
"esac"
|
|
1642
1696
|
]);
|
|
1643
|
-
class
|
|
1697
|
+
class ns {
|
|
1644
1698
|
constructor(e) {
|
|
1645
|
-
|
|
1646
|
-
|
|
1699
|
+
u(this, "tokens");
|
|
1700
|
+
u(this, "pos", 0);
|
|
1647
1701
|
this.tokens = e;
|
|
1648
1702
|
}
|
|
1649
1703
|
peek() {
|
|
@@ -1731,7 +1785,7 @@ class as {
|
|
|
1731
1785
|
}
|
|
1732
1786
|
if (this.peekAt(1).kind === g.LParen && this.peekAt(2).kind === g.RParen) {
|
|
1733
1787
|
const t = e.value;
|
|
1734
|
-
if (!
|
|
1788
|
+
if (!is.has(t))
|
|
1735
1789
|
return this.parseFunctionDef();
|
|
1736
1790
|
}
|
|
1737
1791
|
}
|
|
@@ -1869,13 +1923,13 @@ class as {
|
|
|
1869
1923
|
const a = i.value.slice(0, o), c = i.value.slice(o + 1), l = [];
|
|
1870
1924
|
if (i.parts) {
|
|
1871
1925
|
let f = 0;
|
|
1872
|
-
for (const
|
|
1873
|
-
const
|
|
1874
|
-
if (
|
|
1875
|
-
f =
|
|
1926
|
+
for (const h of i.parts) {
|
|
1927
|
+
const p = f + h.text.length;
|
|
1928
|
+
if (p <= o + 1) {
|
|
1929
|
+
f = p;
|
|
1876
1930
|
continue;
|
|
1877
1931
|
}
|
|
1878
|
-
f < o + 1 ? l.push({ text:
|
|
1932
|
+
f < o + 1 ? l.push({ text: h.text.slice(o + 1 - f), quoted: h.quoted }) : l.push(h), f = p;
|
|
1879
1933
|
}
|
|
1880
1934
|
}
|
|
1881
1935
|
l.length === 0 && l.push({ text: c, quoted: "none" }), e.push({ name: a, value: l });
|
|
@@ -1899,7 +1953,7 @@ function M(r, e) {
|
|
|
1899
1953
|
let t = 0, s = 0, i = -1, n = -1;
|
|
1900
1954
|
for (; s < e.length; ) {
|
|
1901
1955
|
if (t < r.length && r[t] === "[") {
|
|
1902
|
-
const o =
|
|
1956
|
+
const o = os(r, t, e[s]);
|
|
1903
1957
|
if (o.matched) {
|
|
1904
1958
|
t = o.end, s++;
|
|
1905
1959
|
continue;
|
|
@@ -1932,7 +1986,7 @@ function M(r, e) {
|
|
|
1932
1986
|
t++;
|
|
1933
1987
|
return t === r.length;
|
|
1934
1988
|
}
|
|
1935
|
-
function
|
|
1989
|
+
function os(r, e, t) {
|
|
1936
1990
|
let s = e + 1, i = !1;
|
|
1937
1991
|
s < r.length && (r[s] === "!" || r[s] === "^") && (i = !0, s++);
|
|
1938
1992
|
let n = !1;
|
|
@@ -1941,7 +1995,7 @@ function cs(r, e, t) {
|
|
|
1941
1995
|
s + 2 < r.length && r[s + 1] === "-" && r[s + 2] !== "]" ? (t >= r[s] && t <= r[s + 2] && (n = !0), s += 3) : (t === r[s] && (n = !0), s++);
|
|
1942
1996
|
return s < r.length && r[s] === "]" && s++, { matched: i ? !n : n, end: s };
|
|
1943
1997
|
}
|
|
1944
|
-
function
|
|
1998
|
+
function as(r, e, t) {
|
|
1945
1999
|
if (!Ce(r))
|
|
1946
2000
|
return [r];
|
|
1947
2001
|
const i = (r.startsWith("/") ? r : I(e, r)).split("/").filter(Boolean), n = r.startsWith("/");
|
|
@@ -1951,18 +2005,18 @@ function ls(r, e, t) {
|
|
|
1951
2005
|
if (Ce(c))
|
|
1952
2006
|
for (const f of o)
|
|
1953
2007
|
try {
|
|
1954
|
-
const
|
|
1955
|
-
for (const
|
|
1956
|
-
if (M(c,
|
|
1957
|
-
const y = f === "/" ? `/${
|
|
2008
|
+
const h = t.readdir(f);
|
|
2009
|
+
for (const p of h)
|
|
2010
|
+
if (M(c, p.name)) {
|
|
2011
|
+
const y = f === "/" ? `/${p.name}` : `${f}/${p.name}`;
|
|
1958
2012
|
l.push(y);
|
|
1959
2013
|
}
|
|
1960
2014
|
} catch {
|
|
1961
2015
|
}
|
|
1962
2016
|
else
|
|
1963
2017
|
for (const f of o) {
|
|
1964
|
-
const
|
|
1965
|
-
t.exists(
|
|
2018
|
+
const h = f === "/" ? `/${c}` : `${f}/${c}`;
|
|
2019
|
+
t.exists(h) && l.push(h);
|
|
1966
2020
|
}
|
|
1967
2021
|
o = l;
|
|
1968
2022
|
}
|
|
@@ -1983,9 +2037,9 @@ function Ce(r) {
|
|
|
1983
2037
|
async function Le(r, e) {
|
|
1984
2038
|
const t = [];
|
|
1985
2039
|
for (const s of r) {
|
|
1986
|
-
const i = await
|
|
1987
|
-
if (
|
|
1988
|
-
const n =
|
|
2040
|
+
const i = await Ve(s, e);
|
|
2041
|
+
if (ds(s)) {
|
|
2042
|
+
const n = as(i, e.cwd, e.vfs);
|
|
1989
2043
|
t.push(...n);
|
|
1990
2044
|
} else
|
|
1991
2045
|
t.push(i);
|
|
@@ -1993,9 +2047,9 @@ async function Le(r, e) {
|
|
|
1993
2047
|
return t;
|
|
1994
2048
|
}
|
|
1995
2049
|
async function J(r, e) {
|
|
1996
|
-
return
|
|
2050
|
+
return Ve(r, e);
|
|
1997
2051
|
}
|
|
1998
|
-
async function
|
|
2052
|
+
async function Ve(r, e) {
|
|
1999
2053
|
let t = "";
|
|
2000
2054
|
for (const s of r)
|
|
2001
2055
|
switch (s.quoted) {
|
|
@@ -2021,13 +2075,13 @@ async function Pe(r, e) {
|
|
|
2021
2075
|
let t = "", s = 0;
|
|
2022
2076
|
for (; s < r.length; )
|
|
2023
2077
|
if (r[s] === "$") {
|
|
2024
|
-
const i = await
|
|
2078
|
+
const i = await cs(r, s, e);
|
|
2025
2079
|
t += i.value, s = i.end;
|
|
2026
2080
|
} else
|
|
2027
2081
|
t += r[s], s++;
|
|
2028
2082
|
return t;
|
|
2029
2083
|
}
|
|
2030
|
-
async function
|
|
2084
|
+
async function cs(r, e, t) {
|
|
2031
2085
|
const s = r[e + 1];
|
|
2032
2086
|
if (s === void 0)
|
|
2033
2087
|
return { value: "$", end: e + 1 };
|
|
@@ -2050,7 +2104,7 @@ async function hs(r, e, t) {
|
|
|
2050
2104
|
n += 2;
|
|
2051
2105
|
} else
|
|
2052
2106
|
n++;
|
|
2053
|
-
const o = r.slice(e + 3, n - 2), a =
|
|
2107
|
+
const o = r.slice(e + 3, n - 2), a = fs(o, t.env);
|
|
2054
2108
|
return { value: String(a), end: n };
|
|
2055
2109
|
}
|
|
2056
2110
|
if (s === "(") {
|
|
@@ -2066,7 +2120,7 @@ async function hs(r, e, t) {
|
|
|
2066
2120
|
for (; i < r.length && n > 0; )
|
|
2067
2121
|
r[i] === "{" ? n++ : r[i] === "}" && n--, i++;
|
|
2068
2122
|
const o = r.slice(e + 2, i - 1);
|
|
2069
|
-
return { value:
|
|
2123
|
+
return { value: ls(o, t), end: i };
|
|
2070
2124
|
}
|
|
2071
2125
|
if (/[0-9]/.test(s))
|
|
2072
2126
|
return { value: t.env[s] ?? "", end: e + 2 };
|
|
@@ -2079,7 +2133,7 @@ async function hs(r, e, t) {
|
|
|
2079
2133
|
}
|
|
2080
2134
|
return { value: "$", end: e + 1 };
|
|
2081
2135
|
}
|
|
2082
|
-
function
|
|
2136
|
+
function ls(r, e) {
|
|
2083
2137
|
if (r.startsWith("#") && /^#[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)) {
|
|
2084
2138
|
const t = r.slice(1), s = e.env[t] ?? "";
|
|
2085
2139
|
return String(s.length);
|
|
@@ -2129,14 +2183,14 @@ function us(r, e) {
|
|
|
2129
2183
|
const t = r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\/\/([^/]*)\/(.*)$/s);
|
|
2130
2184
|
if (t) {
|
|
2131
2185
|
const s = e.env[t[1]] ?? "", i = t[2], n = t[3];
|
|
2132
|
-
return
|
|
2186
|
+
return us(s, i, n);
|
|
2133
2187
|
}
|
|
2134
2188
|
}
|
|
2135
2189
|
{
|
|
2136
2190
|
const t = r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\/([^/]*)\/(.*)$/s);
|
|
2137
2191
|
if (t) {
|
|
2138
2192
|
const s = e.env[t[1]] ?? "", i = t[2], n = t[3];
|
|
2139
|
-
return
|
|
2193
|
+
return hs(s, i, n);
|
|
2140
2194
|
}
|
|
2141
2195
|
}
|
|
2142
2196
|
{
|
|
@@ -2181,14 +2235,14 @@ function us(r, e) {
|
|
|
2181
2235
|
}
|
|
2182
2236
|
return e.env[r] ?? "";
|
|
2183
2237
|
}
|
|
2184
|
-
function
|
|
2238
|
+
function hs(r, e, t) {
|
|
2185
2239
|
for (let s = 0; s < r.length; s++)
|
|
2186
2240
|
for (let i = s + 1; i <= r.length; i++)
|
|
2187
2241
|
if (M(e, r.slice(s, i)))
|
|
2188
2242
|
return r.slice(0, s) + t + r.slice(i);
|
|
2189
2243
|
return r;
|
|
2190
2244
|
}
|
|
2191
|
-
function
|
|
2245
|
+
function us(r, e, t) {
|
|
2192
2246
|
let s = "", i = 0;
|
|
2193
2247
|
for (; i < r.length; ) {
|
|
2194
2248
|
let n = !1;
|
|
@@ -2201,20 +2255,20 @@ function fs(r, e, t) {
|
|
|
2201
2255
|
}
|
|
2202
2256
|
return s;
|
|
2203
2257
|
}
|
|
2204
|
-
function
|
|
2258
|
+
function ds(r, e) {
|
|
2205
2259
|
for (const t of r)
|
|
2206
2260
|
if (t.quoted === "none" && (t.text.includes("*") || t.text.includes("?") || t.text.includes("[")))
|
|
2207
2261
|
return !0;
|
|
2208
2262
|
return !1;
|
|
2209
2263
|
}
|
|
2210
|
-
function
|
|
2211
|
-
return new
|
|
2264
|
+
function fs(r, e) {
|
|
2265
|
+
return new ms(r.trim(), e).parseExpression();
|
|
2212
2266
|
}
|
|
2213
|
-
class
|
|
2267
|
+
class ms {
|
|
2214
2268
|
constructor(e, t) {
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2269
|
+
u(this, "expr");
|
|
2270
|
+
u(this, "pos", 0);
|
|
2271
|
+
u(this, "env");
|
|
2218
2272
|
this.expr = e, this.env = t;
|
|
2219
2273
|
}
|
|
2220
2274
|
skipSpaces() {
|
|
@@ -2477,12 +2531,12 @@ class gs {
|
|
|
2477
2531
|
return isNaN(s) ? 0 : s;
|
|
2478
2532
|
}
|
|
2479
2533
|
}
|
|
2480
|
-
class
|
|
2534
|
+
class ps {
|
|
2481
2535
|
constructor() {
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2536
|
+
u(this, "buffer", []);
|
|
2537
|
+
u(this, "closed", !1);
|
|
2538
|
+
u(this, "waiting", null);
|
|
2539
|
+
u(this, "writer", {
|
|
2486
2540
|
write: (e) => {
|
|
2487
2541
|
if (this.waiting) {
|
|
2488
2542
|
const t = this.waiting;
|
|
@@ -2491,7 +2545,7 @@ class ws {
|
|
|
2491
2545
|
this.buffer.push(e);
|
|
2492
2546
|
}
|
|
2493
2547
|
});
|
|
2494
|
-
|
|
2548
|
+
u(this, "reader", {
|
|
2495
2549
|
read: () => this.read(),
|
|
2496
2550
|
readAll: () => this.readAll()
|
|
2497
2551
|
});
|
|
@@ -2532,11 +2586,11 @@ class ie {
|
|
|
2532
2586
|
this.exitCode = e;
|
|
2533
2587
|
}
|
|
2534
2588
|
}
|
|
2535
|
-
class
|
|
2589
|
+
class gs {
|
|
2536
2590
|
constructor(e) {
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2591
|
+
u(this, "config");
|
|
2592
|
+
u(this, "lastExitCode", 0);
|
|
2593
|
+
u(this, "functions", /* @__PURE__ */ new Map());
|
|
2540
2594
|
this.config = e;
|
|
2541
2595
|
}
|
|
2542
2596
|
getLastExitCode() {
|
|
@@ -2592,11 +2646,11 @@ class ys {
|
|
|
2592
2646
|
const a = o > 0 ? s[o - 1].reader : void 0;
|
|
2593
2647
|
let c;
|
|
2594
2648
|
if (o < e.length - 1) {
|
|
2595
|
-
const
|
|
2596
|
-
s.push(
|
|
2649
|
+
const p = new ps();
|
|
2650
|
+
s.push(p), c = p.writer;
|
|
2597
2651
|
}
|
|
2598
|
-
const l = e[o], f = o === 0 ? t : void 0,
|
|
2599
|
-
i.push(
|
|
2652
|
+
const l = e[o], f = o === 0 ? t : void 0, h = this.executeCommand(l, a, c, f).then((p) => (o < e.length - 1 && s[o].close(), p));
|
|
2653
|
+
i.push(h);
|
|
2600
2654
|
}
|
|
2601
2655
|
const n = await Promise.all(i);
|
|
2602
2656
|
return n[n.length - 1];
|
|
@@ -2716,7 +2770,7 @@ class ys {
|
|
|
2716
2770
|
return s;
|
|
2717
2771
|
}
|
|
2718
2772
|
async executeSimpleCommand(e, t, s, i) {
|
|
2719
|
-
var
|
|
2773
|
+
var _, L;
|
|
2720
2774
|
const n = this.createExpandContext(), o = await Le(e.words, n);
|
|
2721
2775
|
if (o.length === 0 && e.assignments.length > 0) {
|
|
2722
2776
|
for (const S of e.assignments) {
|
|
@@ -2740,31 +2794,31 @@ class ys {
|
|
|
2740
2794
|
const w = await J(S.value, n);
|
|
2741
2795
|
f[S.name] = this.config.env[S.name], this.config.env[S.name] = w;
|
|
2742
2796
|
}
|
|
2743
|
-
let
|
|
2797
|
+
let h = s ?? this.config.defaultStdout ?? {
|
|
2744
2798
|
write: (S) => this.config.writeToTerminal(S)
|
|
2745
|
-
},
|
|
2799
|
+
}, p = this.config.defaultStderr ?? {
|
|
2746
2800
|
write: (S) => this.config.writeToTerminal(S)
|
|
2747
2801
|
}, y = t;
|
|
2748
2802
|
for (const S of e.redirections) {
|
|
2749
2803
|
const w = await J(S.target, n), $ = I(this.config.getCwd(), w);
|
|
2750
2804
|
switch (S.operator) {
|
|
2751
2805
|
case ">":
|
|
2752
|
-
this.config.vfs.writeFile($, ""),
|
|
2806
|
+
this.config.vfs.writeFile($, ""), h = this.createFileWriter($);
|
|
2753
2807
|
break;
|
|
2754
2808
|
case ">>":
|
|
2755
|
-
this.config.vfs.exists($) || this.config.vfs.writeFile($, ""),
|
|
2809
|
+
this.config.vfs.exists($) || this.config.vfs.writeFile($, ""), h = this.createFileAppender($);
|
|
2756
2810
|
break;
|
|
2757
2811
|
case "<":
|
|
2758
2812
|
y = this.createFileReader($);
|
|
2759
2813
|
break;
|
|
2760
2814
|
case "2>":
|
|
2761
|
-
this.config.vfs.writeFile($, ""),
|
|
2815
|
+
this.config.vfs.writeFile($, ""), p = this.createFileWriter($);
|
|
2762
2816
|
break;
|
|
2763
2817
|
case "2>>":
|
|
2764
|
-
this.config.vfs.exists($) || this.config.vfs.writeFile($, ""),
|
|
2818
|
+
this.config.vfs.exists($) || this.config.vfs.writeFile($, ""), p = this.createFileAppender($);
|
|
2765
2819
|
break;
|
|
2766
2820
|
case "&>":
|
|
2767
|
-
this.config.vfs.writeFile($, ""),
|
|
2821
|
+
this.config.vfs.writeFile($, ""), h = this.createFileWriter($), p = h;
|
|
2768
2822
|
break;
|
|
2769
2823
|
}
|
|
2770
2824
|
}
|
|
@@ -2789,27 +2843,27 @@ class ys {
|
|
|
2789
2843
|
else {
|
|
2790
2844
|
const w = this.config.builtins.get(a);
|
|
2791
2845
|
if (w)
|
|
2792
|
-
E = await w(c,
|
|
2846
|
+
E = await w(c, h, p, y);
|
|
2793
2847
|
else {
|
|
2794
2848
|
const $ = await this.config.registry.resolve(a);
|
|
2795
2849
|
if (!$)
|
|
2796
2850
|
this.config.writeToTerminal(`${a}: command not found
|
|
2797
2851
|
`), E = 127;
|
|
2798
2852
|
else {
|
|
2799
|
-
const x = ((
|
|
2853
|
+
const x = ((L = (_ = this.config).getAbortSignal) == null ? void 0 : L.call(_)) ?? new AbortController().signal, R = {
|
|
2800
2854
|
args: c,
|
|
2801
2855
|
env: { ...this.config.env },
|
|
2802
2856
|
cwd: this.config.getCwd(),
|
|
2803
2857
|
vfs: this.config.vfs,
|
|
2804
|
-
stdout:
|
|
2805
|
-
stderr:
|
|
2858
|
+
stdout: h,
|
|
2859
|
+
stderr: p,
|
|
2806
2860
|
signal: x,
|
|
2807
2861
|
stdin: y
|
|
2808
2862
|
};
|
|
2809
2863
|
try {
|
|
2810
|
-
E = await $(
|
|
2811
|
-
} catch (
|
|
2812
|
-
|
|
2864
|
+
E = await $(R);
|
|
2865
|
+
} catch (P) {
|
|
2866
|
+
P instanceof Error && P.name === "AbortError" ? E = 130 : (p.write(`${a}: ${P instanceof Error ? P.message : String(P)}
|
|
2813
2867
|
`), E = 1);
|
|
2814
2868
|
}
|
|
2815
2869
|
}
|
|
@@ -2889,11 +2943,11 @@ class ys {
|
|
|
2889
2943
|
};
|
|
2890
2944
|
}
|
|
2891
2945
|
}
|
|
2892
|
-
const Te = "/home/user/.bash_history",
|
|
2893
|
-
class
|
|
2946
|
+
const Te = "/home/user/.bash_history", _e = 1e3;
|
|
2947
|
+
class ws {
|
|
2894
2948
|
constructor(e) {
|
|
2895
|
-
|
|
2896
|
-
|
|
2949
|
+
u(this, "entries", []);
|
|
2950
|
+
u(this, "vfs");
|
|
2897
2951
|
this.vfs = e;
|
|
2898
2952
|
}
|
|
2899
2953
|
load() {
|
|
@@ -2915,7 +2969,7 @@ class vs {
|
|
|
2915
2969
|
}
|
|
2916
2970
|
add(e) {
|
|
2917
2971
|
const t = e.trim();
|
|
2918
|
-
t && (this.entries.length > 0 && this.entries[this.entries.length - 1] === t || (this.entries.push(t), this.entries.length >
|
|
2972
|
+
t && (this.entries.length > 0 && this.entries[this.entries.length - 1] === t || (this.entries.push(t), this.entries.length > _e && (this.entries = this.entries.slice(-_e)), this.save()));
|
|
2919
2973
|
}
|
|
2920
2974
|
/**
|
|
2921
2975
|
* Expand history references:
|
|
@@ -2959,10 +3013,10 @@ class vs {
|
|
|
2959
3013
|
return this.entries.length;
|
|
2960
3014
|
}
|
|
2961
3015
|
}
|
|
2962
|
-
class
|
|
3016
|
+
class ys {
|
|
2963
3017
|
constructor() {
|
|
2964
|
-
|
|
2965
|
-
|
|
3018
|
+
u(this, "jobs", /* @__PURE__ */ new Map());
|
|
3019
|
+
u(this, "nextId", 1);
|
|
2966
3020
|
}
|
|
2967
3021
|
add(e, t, s) {
|
|
2968
3022
|
const i = this.nextId++, n = {
|
|
@@ -3000,25 +3054,25 @@ class bs {
|
|
|
3000
3054
|
return e;
|
|
3001
3055
|
}
|
|
3002
3056
|
}
|
|
3003
|
-
function
|
|
3004
|
-
const { line: e, cursorPos: t } = r, s = e.slice(0, t), { word: i, start: n } =
|
|
3057
|
+
function vs(r) {
|
|
3058
|
+
const { line: e, cursorPos: t } = r, s = e.slice(0, t), { word: i, start: n } = bs(s), o = $s(s, i);
|
|
3005
3059
|
let a;
|
|
3006
3060
|
switch (o) {
|
|
3007
3061
|
case "command":
|
|
3008
|
-
a =
|
|
3062
|
+
a = xs(i, r);
|
|
3009
3063
|
break;
|
|
3010
3064
|
case "directory":
|
|
3011
|
-
a =
|
|
3065
|
+
a = ks(i, r);
|
|
3012
3066
|
break;
|
|
3013
3067
|
case "variable":
|
|
3014
|
-
a =
|
|
3068
|
+
a = Es(i.slice(1), r);
|
|
3015
3069
|
break;
|
|
3016
3070
|
case "file":
|
|
3017
3071
|
default:
|
|
3018
|
-
a =
|
|
3072
|
+
a = Ss(i, r);
|
|
3019
3073
|
break;
|
|
3020
3074
|
}
|
|
3021
|
-
const c =
|
|
3075
|
+
const c = Cs(a);
|
|
3022
3076
|
return {
|
|
3023
3077
|
replacementStart: n,
|
|
3024
3078
|
replacementEnd: t,
|
|
@@ -3026,14 +3080,14 @@ function $s(r) {
|
|
|
3026
3080
|
commonPrefix: c
|
|
3027
3081
|
};
|
|
3028
3082
|
}
|
|
3029
|
-
function
|
|
3083
|
+
function bs(r) {
|
|
3030
3084
|
let e = r.length - 1;
|
|
3031
3085
|
for (; e >= 0 && r[e] !== " " && r[e] !== " " && r[e] !== "|" && r[e] !== ";" && r[e] !== "&" && r[e] !== ">" && r[e] !== "<"; )
|
|
3032
3086
|
e--;
|
|
3033
3087
|
const t = e + 1;
|
|
3034
3088
|
return { word: r.slice(t), start: t };
|
|
3035
3089
|
}
|
|
3036
|
-
function
|
|
3090
|
+
function $s(r, e) {
|
|
3037
3091
|
if (e.startsWith("$"))
|
|
3038
3092
|
return "variable";
|
|
3039
3093
|
const t = r.slice(0, r.length - e.length).trimEnd();
|
|
@@ -3042,23 +3096,23 @@ function Ss(r, e) {
|
|
|
3042
3096
|
if (t === "" || t.endsWith("|") || t.endsWith("&&") || t.endsWith("||") || t.endsWith(";"))
|
|
3043
3097
|
return "command";
|
|
3044
3098
|
const s = t.split(/\s+/).filter(Boolean);
|
|
3045
|
-
return s.length > 0 && s[s.length - 1] === "cd" &&
|
|
3099
|
+
return s.length > 0 && s[s.length - 1] === "cd" && Re(t) === "cd" || Re(t) === "cd" ? "directory" : "file";
|
|
3046
3100
|
}
|
|
3047
|
-
function
|
|
3101
|
+
function Re(r) {
|
|
3048
3102
|
const e = r.split(/\|{1,2}|&&|;/), s = e[e.length - 1].trim().split(/\s+/).filter(Boolean);
|
|
3049
3103
|
return s.length > 0 ? s[0] : null;
|
|
3050
3104
|
}
|
|
3051
|
-
function
|
|
3105
|
+
function xs(r, e) {
|
|
3052
3106
|
const t = [...e.builtinNames, ...e.registry.list()], s = [...new Set(t)].sort();
|
|
3053
3107
|
return r ? s.filter((i) => i.startsWith(r)) : s;
|
|
3054
3108
|
}
|
|
3055
|
-
function
|
|
3056
|
-
return
|
|
3109
|
+
function Ss(r, e) {
|
|
3110
|
+
return Ge(r, e, !1);
|
|
3057
3111
|
}
|
|
3058
|
-
function
|
|
3059
|
-
return
|
|
3112
|
+
function ks(r, e) {
|
|
3113
|
+
return Ge(r, e, !0);
|
|
3060
3114
|
}
|
|
3061
|
-
function
|
|
3115
|
+
function Ge(r, e, t) {
|
|
3062
3116
|
let s = r, i = "";
|
|
3063
3117
|
r.startsWith("~/") ? (s = (e.env.HOME ?? "/home/user") + r.slice(1), i = "~/") : r === "~" && (s = e.env.HOME ?? "/home/user", i = "~");
|
|
3064
3118
|
let n, o;
|
|
@@ -3070,17 +3124,17 @@ function Ze(r, e, t) {
|
|
|
3070
3124
|
try {
|
|
3071
3125
|
let c = e.vfs.readdir(n).filter((l) => l.name.startsWith(o) && (o.startsWith(".") || !l.name.startsWith(".")));
|
|
3072
3126
|
return t && (c = c.filter((l) => l.type === "directory")), c.map((l) => {
|
|
3073
|
-
const f = r.includes("/") ? r.slice(0, r.lastIndexOf("/") + 1) : "",
|
|
3074
|
-
return i && f.startsWith(i), f + l.name +
|
|
3127
|
+
const f = r.includes("/") ? r.slice(0, r.lastIndexOf("/") + 1) : "", h = l.type === "directory" ? "/" : "";
|
|
3128
|
+
return i && f.startsWith(i), f + l.name + h;
|
|
3075
3129
|
}).sort();
|
|
3076
3130
|
} catch {
|
|
3077
3131
|
return [];
|
|
3078
3132
|
}
|
|
3079
3133
|
}
|
|
3080
|
-
function
|
|
3134
|
+
function Es(r, e) {
|
|
3081
3135
|
return Object.keys(e.env).filter((t) => t.startsWith(r)).map((t) => "$" + t).sort();
|
|
3082
3136
|
}
|
|
3083
|
-
function
|
|
3137
|
+
function Cs(r) {
|
|
3084
3138
|
if (r.length === 0) return "";
|
|
3085
3139
|
if (r.length === 1) return r[0];
|
|
3086
3140
|
let e = r[0];
|
|
@@ -3092,11 +3146,11 @@ function Ps(r) {
|
|
|
3092
3146
|
}
|
|
3093
3147
|
return e;
|
|
3094
3148
|
}
|
|
3095
|
-
function
|
|
3149
|
+
function Ae(r, e, t) {
|
|
3096
3150
|
if (r.length > 0 && r[r.length - 1] === "]" && (r = r.slice(0, -1)), r.length === 0)
|
|
3097
3151
|
return 1;
|
|
3098
3152
|
try {
|
|
3099
|
-
const s =
|
|
3153
|
+
const s = Ze(r, 0, e);
|
|
3100
3154
|
return s.pos !== r.length ? (t.write(`test: too many arguments
|
|
3101
3155
|
`), 2) : s.value ? 0 : 1;
|
|
3102
3156
|
} catch (s) {
|
|
@@ -3104,10 +3158,10 @@ function Re(r, e, t) {
|
|
|
3104
3158
|
`), 2;
|
|
3105
3159
|
}
|
|
3106
3160
|
}
|
|
3107
|
-
function
|
|
3108
|
-
return
|
|
3161
|
+
function Ze(r, e, t) {
|
|
3162
|
+
return Ls(r, e, t);
|
|
3109
3163
|
}
|
|
3110
|
-
function
|
|
3164
|
+
function Ls(r, e, t) {
|
|
3111
3165
|
let s = Fe(r, e, t);
|
|
3112
3166
|
for (; s.pos < r.length && r[s.pos] === "-o"; ) {
|
|
3113
3167
|
const i = Fe(r, s.pos + 1, t);
|
|
@@ -3132,7 +3186,7 @@ function ce(r, e, t) {
|
|
|
3132
3186
|
return { value: !i.value, pos: i.pos };
|
|
3133
3187
|
}
|
|
3134
3188
|
if (s === "(") {
|
|
3135
|
-
const i =
|
|
3189
|
+
const i = Ze(r, e + 1, t);
|
|
3136
3190
|
if (i.pos >= r.length || r[i.pos] !== ")")
|
|
3137
3191
|
throw new Error("missing )");
|
|
3138
3192
|
return { value: i.value, pos: i.pos + 1 };
|
|
@@ -3142,7 +3196,7 @@ function ce(r, e, t) {
|
|
|
3142
3196
|
if (s === "-n" && e + 1 < r.length)
|
|
3143
3197
|
return { value: r[e + 1].length > 0, pos: e + 2 };
|
|
3144
3198
|
if (s.startsWith("-") && s.length === 2 && e + 1 < r.length) {
|
|
3145
|
-
const i = s[1], n = r[e + 1], o =
|
|
3199
|
+
const i = s[1], n = r[e + 1], o = Ps(i, n, t);
|
|
3146
3200
|
if (o !== null)
|
|
3147
3201
|
return { value: o, pos: e + 2 };
|
|
3148
3202
|
}
|
|
@@ -3173,7 +3227,7 @@ function ce(r, e, t) {
|
|
|
3173
3227
|
}
|
|
3174
3228
|
return { value: s.length > 0, pos: e + 1 };
|
|
3175
3229
|
}
|
|
3176
|
-
function
|
|
3230
|
+
function Ps(r, e, t) {
|
|
3177
3231
|
switch (r) {
|
|
3178
3232
|
case "e":
|
|
3179
3233
|
return t.exists(e);
|
|
@@ -3216,10 +3270,10 @@ function N(r) {
|
|
|
3216
3270
|
}
|
|
3217
3271
|
class Ie {
|
|
3218
3272
|
constructor() {
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3273
|
+
u(this, "buffer", []);
|
|
3274
|
+
u(this, "closed", !1);
|
|
3275
|
+
u(this, "resolver", null);
|
|
3276
|
+
u(this, "_waiting", !1);
|
|
3223
3277
|
}
|
|
3224
3278
|
/** True when a command has called read() and is waiting for input. */
|
|
3225
3279
|
get isWaiting() {
|
|
@@ -3258,37 +3312,37 @@ class Ie {
|
|
|
3258
3312
|
return e.join("");
|
|
3259
3313
|
}
|
|
3260
3314
|
}
|
|
3261
|
-
class
|
|
3315
|
+
class Ts {
|
|
3262
3316
|
constructor(e, t, s, i) {
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3317
|
+
u(this, "terminal");
|
|
3318
|
+
u(this, "vfs");
|
|
3319
|
+
u(this, "registry");
|
|
3320
|
+
u(this, "cwd");
|
|
3321
|
+
u(this, "env");
|
|
3268
3322
|
// Alias map
|
|
3269
|
-
|
|
3323
|
+
u(this, "aliases", /* @__PURE__ */ new Map());
|
|
3270
3324
|
// Line editing state
|
|
3271
|
-
|
|
3272
|
-
|
|
3325
|
+
u(this, "lineBuffer", "");
|
|
3326
|
+
u(this, "cursorPos", 0);
|
|
3273
3327
|
// History (legacy array kept for backward compat with tests)
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3328
|
+
u(this, "history", []);
|
|
3329
|
+
u(this, "historyIndex", -1);
|
|
3330
|
+
u(this, "savedLine", "");
|
|
3277
3331
|
// Running command
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3332
|
+
u(this, "running", !1);
|
|
3333
|
+
u(this, "abortController", null);
|
|
3334
|
+
u(this, "terminalStdin", null);
|
|
3335
|
+
u(this, "stdinLineBuffer", "");
|
|
3336
|
+
u(this, "stdinCursorPos", 0);
|
|
3283
3337
|
// New Sprint 2 components
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3338
|
+
u(this, "interpreter");
|
|
3339
|
+
u(this, "interpreterConfig");
|
|
3340
|
+
u(this, "historyManager");
|
|
3341
|
+
u(this, "jobTable");
|
|
3342
|
+
u(this, "builtins");
|
|
3289
3343
|
// Tab completion state
|
|
3290
|
-
|
|
3291
|
-
this.terminal = e, this.vfs = t, this.registry = s, this.cwd = i.HOME ?? "/home/user", this.env = { ...i }, this.builtins = /* @__PURE__ */ new Map(), this.registerBuiltins(), this.jobTable = new
|
|
3344
|
+
u(this, "tabCount", 0);
|
|
3345
|
+
this.terminal = e, this.vfs = t, this.registry = s, this.cwd = i.HOME ?? "/home/user", this.env = { ...i }, this.builtins = /* @__PURE__ */ new Map(), this.registerBuiltins(), this.jobTable = new ys(), this.historyManager = new ws(t), this.historyManager.load(), this.interpreterConfig = {
|
|
3292
3346
|
env: this.env,
|
|
3293
3347
|
getCwd: () => this.cwd,
|
|
3294
3348
|
setCwd: (n) => {
|
|
@@ -3304,10 +3358,10 @@ class _s {
|
|
|
3304
3358
|
var n;
|
|
3305
3359
|
return ((n = this.abortController) == null ? void 0 : n.signal) ?? new AbortController().signal;
|
|
3306
3360
|
}
|
|
3307
|
-
}, this.interpreter = new
|
|
3361
|
+
}, this.interpreter = new gs(this.interpreterConfig);
|
|
3308
3362
|
}
|
|
3309
3363
|
registerBuiltins() {
|
|
3310
|
-
this.builtins.set("cd", (e, t, s) => this.builtinCd(e, s)), this.builtins.set("pwd", (e, t) => this.builtinPwd(t)), this.builtins.set("echo", (e, t) => this.builtinEcho(e, t)), this.builtins.set("clear", () => this.builtinClear()), this.builtins.set("export", (e) => this.builtinExport(e)), this.builtins.set("exit", (e, t) => this.builtinExit(t)), this.builtins.set("true", () => Promise.resolve(0)), this.builtins.set("false", () => Promise.resolve(1)), this.builtins.set("jobs", (e, t) => this.builtinJobs(t)), this.builtins.set("fg", (e, t, s) => this.builtinFg(e, t, s)), this.builtins.set("bg", (e, t, s) => this.builtinBg(e, t, s)), this.builtins.set("history", (e, t) => this.builtinHistory(t)), this.builtins.set("source", (e, t, s) => this.builtinSource(e, s)), this.builtins.set(".", (e, t, s) => this.builtinSource(e, s)), this.builtins.set("alias", (e, t) => this.builtinAlias(e, t)), this.builtins.set("unalias", (e, t, s) => this.builtinUnalias(e, s)), this.builtins.set("test", (e, t, s) => Promise.resolve(
|
|
3364
|
+
this.builtins.set("cd", (e, t, s) => this.builtinCd(e, s)), this.builtins.set("pwd", (e, t) => this.builtinPwd(t)), this.builtins.set("echo", (e, t) => this.builtinEcho(e, t)), this.builtins.set("clear", () => this.builtinClear()), this.builtins.set("export", (e) => this.builtinExport(e)), this.builtins.set("exit", (e, t) => this.builtinExit(t)), this.builtins.set("true", () => Promise.resolve(0)), this.builtins.set("false", () => Promise.resolve(1)), this.builtins.set("jobs", (e, t) => this.builtinJobs(t)), this.builtins.set("fg", (e, t, s) => this.builtinFg(e, t, s)), this.builtins.set("bg", (e, t, s) => this.builtinBg(e, t, s)), this.builtins.set("history", (e, t) => this.builtinHistory(t)), this.builtins.set("source", (e, t, s) => this.builtinSource(e, s)), this.builtins.set(".", (e, t, s) => this.builtinSource(e, s)), this.builtins.set("alias", (e, t) => this.builtinAlias(e, t)), this.builtins.set("unalias", (e, t, s) => this.builtinUnalias(e, s)), this.builtins.set("test", (e, t, s) => Promise.resolve(Ae(e, this.vfs, s))), this.builtins.set("[", (e, t, s) => Promise.resolve(Ae(e, this.vfs, s)));
|
|
3311
3365
|
}
|
|
3312
3366
|
getJobTable() {
|
|
3313
3367
|
return this.jobTable;
|
|
@@ -3334,27 +3388,27 @@ class _s {
|
|
|
3334
3388
|
async execute(e, t) {
|
|
3335
3389
|
let s = "", i = "";
|
|
3336
3390
|
const n = {
|
|
3337
|
-
write: (
|
|
3391
|
+
write: (p) => {
|
|
3338
3392
|
var y;
|
|
3339
|
-
s +=
|
|
3393
|
+
s += p, (y = t == null ? void 0 : t.onStdout) == null || y.call(t, p);
|
|
3340
3394
|
}
|
|
3341
3395
|
}, o = {
|
|
3342
|
-
write: (
|
|
3396
|
+
write: (p) => {
|
|
3343
3397
|
var y;
|
|
3344
|
-
i +=
|
|
3398
|
+
i += p, (y = t == null ? void 0 : t.onStderr) == null || y.call(t, p);
|
|
3345
3399
|
}
|
|
3346
3400
|
}, a = this.interpreterConfig.defaultStdout, c = this.interpreterConfig.defaultStderr, l = this.interpreterConfig.writeToTerminal, f = t != null && t.cwd ? this.cwd : void 0;
|
|
3347
|
-
this.interpreterConfig.defaultStdout = n, this.interpreterConfig.defaultStderr = o, this.interpreterConfig.writeToTerminal = (
|
|
3401
|
+
this.interpreterConfig.defaultStdout = n, this.interpreterConfig.defaultStderr = o, this.interpreterConfig.writeToTerminal = (p) => {
|
|
3348
3402
|
var y;
|
|
3349
|
-
i +=
|
|
3403
|
+
i += p, (y = t == null ? void 0 : t.onStderr) == null || y.call(t, p);
|
|
3350
3404
|
}, t != null && t.cwd && (this.cwd = t.cwd), t != null && t.env && Object.assign(this.env, t.env);
|
|
3351
|
-
let
|
|
3352
|
-
(t == null ? void 0 : t.stdin) !== void 0 && (
|
|
3405
|
+
let h;
|
|
3406
|
+
(t == null ? void 0 : t.stdin) !== void 0 && (h = new Ie(), h.feed(t.stdin), h.close());
|
|
3353
3407
|
try {
|
|
3354
|
-
const
|
|
3355
|
-
return { stdout: s, stderr: i, exitCode:
|
|
3356
|
-
} catch (
|
|
3357
|
-
const y =
|
|
3408
|
+
const p = await this.interpreter.executeLine(e, h);
|
|
3409
|
+
return { stdout: s, stderr: i, exitCode: p };
|
|
3410
|
+
} catch (p) {
|
|
3411
|
+
const y = p instanceof Error ? p.message : String(p);
|
|
3358
3412
|
return i += y + `
|
|
3359
3413
|
`, { stdout: s, stderr: i, exitCode: 1 };
|
|
3360
3414
|
} finally {
|
|
@@ -3466,7 +3520,7 @@ class _s {
|
|
|
3466
3520
|
vfs: this.vfs,
|
|
3467
3521
|
registry: this.registry,
|
|
3468
3522
|
builtinNames: [...this.builtins.keys()]
|
|
3469
|
-
}, t =
|
|
3523
|
+
}, t = vs(e), s = this.lineBuffer.slice(t.replacementStart, t.replacementEnd);
|
|
3470
3524
|
if (t.completions.length === 0) {
|
|
3471
3525
|
this.terminal.write("\x07");
|
|
3472
3526
|
return;
|
|
@@ -3759,10 +3813,10 @@ class _s {
|
|
|
3759
3813
|
return s.length > 0 && t.push(s), t;
|
|
3760
3814
|
}
|
|
3761
3815
|
}
|
|
3762
|
-
class
|
|
3816
|
+
class _s {
|
|
3763
3817
|
constructor() {
|
|
3764
|
-
|
|
3765
|
-
|
|
3818
|
+
u(this, "commands", /* @__PURE__ */ new Map());
|
|
3819
|
+
u(this, "lazy", /* @__PURE__ */ new Map());
|
|
3766
3820
|
}
|
|
3767
3821
|
register(e, t) {
|
|
3768
3822
|
this.commands.set(e, t);
|
|
@@ -3783,12 +3837,12 @@ class Rs {
|
|
|
3783
3837
|
return [.../* @__PURE__ */ new Set([...this.commands.keys(), ...this.lazy.keys()])].sort();
|
|
3784
3838
|
}
|
|
3785
3839
|
}
|
|
3786
|
-
function
|
|
3787
|
-
const r = new
|
|
3788
|
-
return r.registerLazy("ls", () => import("./ls-
|
|
3840
|
+
function Rs() {
|
|
3841
|
+
const r = new _s();
|
|
3842
|
+
return r.registerLazy("ls", () => import("./ls-BiT10kLm.js")), r.registerLazy("cat", () => import("./cat-B2exoWlk.js")), r.registerLazy("mkdir", () => import("./mkdir-DgzJ2JLj.js")), r.registerLazy("rm", () => import("./rm-DA2w3xTR.js")), r.registerLazy("cp", () => import("./cp-C8mNek36.js")), r.registerLazy("mv", () => import("./mv-Kp6DjQ8n.js")), r.registerLazy("touch", () => import("./touch-k2NomRzL.js")), r.registerLazy("find", () => import("./find-CRUAXbhO.js")), r.registerLazy("tree", () => import("./tree-B_j2_PsZ.js")), r.registerLazy("stat", () => import("./stat-D0i1gTKB.js")), r.registerLazy("ln", () => import("./ln-Bf3f3jVA.js")), r.registerLazy("du", () => import("./du-D25egSeK.js")), r.registerLazy("df", () => import("./df-CeZb4WOr.js")), r.registerLazy("chmod", () => import("./chmod-CQS63aP7.js")), r.registerLazy("file", () => import("./file-BPs1dqg5.js")), r.registerLazy("grep", () => import("./grep-B9pTCSNY.js")), r.registerLazy("head", () => import("./head-DzP_T5Wx.js")), r.registerLazy("tail", () => import("./tail-tcIJLQnB.js")), r.registerLazy("wc", () => import("./wc-Jp7nOops.js")), r.registerLazy("sort", () => import("./sort-CSzSGTdB.js")), r.registerLazy("uniq", () => import("./uniq-hzJnHQOm.js")), r.registerLazy("cut", () => import("./cut-BZez9bS1.js")), r.registerLazy("tr", () => import("./tr-DsCiwSIu.js")), r.registerLazy("sed", () => import("./sed-ClWZ06zX.js")), r.registerLazy("awk", () => import("./awk-CchAsBzt.js")), r.registerLazy("tee", () => import("./tee-RqoZ3qG-.js")), r.registerLazy("xargs", () => import("./xargs-DfbCRFFd.js")), r.registerLazy("yes", () => import("./yes-DXEyHHD2.js")), r.registerLazy("printf", () => import("./printf-Cc2o7KZx.js")), r.registerLazy("env", () => import("./env-DXzvDKsN.js")), r.registerLazy("uname", () => import("./uname-BCn8HlJD.js")), r.registerLazy("date", () => import("./date-C8NB8v8G.js")), r.registerLazy("sleep", () => import("./sleep-B4C3fZiR.js")), r.registerLazy("uptime", () => import("./uptime-CgBJegqU.js")), r.registerLazy("whoami", () => import("./whoami-B1237V5e.js")), r.registerLazy("hostname", () => import("./hostname-BxU2S3nT.js")), r.registerLazy("free", () => import("./free-DAxE4b2U.js")), r.registerLazy("which", () => import("./which-D3u0cwyh.js")), r.registerLazy("curl", () => Promise.resolve().then(() => dr)), r.registerLazy("wget", () => import("./wget-2NAABIHc.js")), r.registerLazy("ping", () => import("./ping-DtVEwwda.js")), r.registerLazy("dig", () => import("./dig-BEJ8Ky96.js")), r.registerLazy("tar", () => import("./tar-DkyzTzmT.js")), r.registerLazy("gzip", () => import("./gzip-DgE-9PzE.js")), r.registerLazy("gunzip", () => import("./gunzip-BYlJhPf7.js")), r.registerLazy("zip", () => import("./zip--0ncHv0q.js")), r.registerLazy("unzip", () => import("./unzip-FwYCTDEZ.js")), r.registerLazy("node", () => Promise.resolve().then(() => ge)), r.registerLazy("rmdir", () => import("./rmdir-BiGbNDOT.js")), r.registerLazy("realpath", () => import("./realpath-BOeYN6nD.js")), r.registerLazy("basename", () => import("./basename-C2v8jn7p.js")), r.registerLazy("dirname", () => import("./dirname-BY_Gu5i2.js")), r.registerLazy("mktemp", () => import("./mktemp-Sh5DWxvc.js")), r.registerLazy("chown", () => import("./chown-rgGwZwu9.js")), r.registerLazy("diff", () => import("./diff-tWPvmikU.js")), r.registerLazy("nl", () => import("./nl-DBLFdpfC.js")), r.registerLazy("rev", () => import("./rev-CWRUIXWp.js")), r.registerLazy("cal", () => import("./cal-DPULSAhj.js")), r.registerLazy("bc", () => import("./bc-BYiKVTNg.js")), r.registerLazy("man", () => import("./man-CJ5pI0_W.js")), r;
|
|
3789
3843
|
}
|
|
3790
|
-
const
|
|
3791
|
-
class
|
|
3844
|
+
const As = "/usr/share/pkg", ne = "/usr/share/pkg/node_modules", Ne = "/usr/share/pkg/packages.json";
|
|
3845
|
+
class Fs {
|
|
3792
3846
|
constructor(e) {
|
|
3793
3847
|
this.vfs = e;
|
|
3794
3848
|
}
|
|
@@ -3806,7 +3860,7 @@ class Ns {
|
|
|
3806
3860
|
}
|
|
3807
3861
|
ensureDirs() {
|
|
3808
3862
|
try {
|
|
3809
|
-
this.vfs.mkdir(
|
|
3863
|
+
this.vfs.mkdir(As, { recursive: !0 });
|
|
3810
3864
|
} catch {
|
|
3811
3865
|
}
|
|
3812
3866
|
try {
|
|
@@ -3861,9 +3915,9 @@ class Ns {
|
|
|
3861
3915
|
return this.readMetadata().packages[e] || null;
|
|
3862
3916
|
}
|
|
3863
3917
|
}
|
|
3864
|
-
function
|
|
3918
|
+
function Is(r) {
|
|
3865
3919
|
return async (t) => {
|
|
3866
|
-
const s = t.args[0], i = new
|
|
3920
|
+
const s = t.args[0], i = new Fs(t.vfs);
|
|
3867
3921
|
if (!s || s === "--help")
|
|
3868
3922
|
return t.stdout.write(`Usage: pkg <command> [args]
|
|
3869
3923
|
|
|
@@ -3885,7 +3939,7 @@ function Bs(r) {
|
|
|
3885
3939
|
`);
|
|
3886
3940
|
const a = await i.install(n, o);
|
|
3887
3941
|
t.stdout.write(`Installed ${a.name} (${a.size} bytes)
|
|
3888
|
-
`),
|
|
3942
|
+
`), Ns(r, t, a.name), t.stdout.write(`Command '${a.name}' is now available
|
|
3889
3943
|
`);
|
|
3890
3944
|
} catch (a) {
|
|
3891
3945
|
return t.stderr.write(`pkg: install failed: ${a instanceof Error ? a.message : String(a)}
|
|
@@ -3938,7 +3992,7 @@ function Bs(r) {
|
|
|
3938
3992
|
}
|
|
3939
3993
|
};
|
|
3940
3994
|
}
|
|
3941
|
-
function
|
|
3995
|
+
function Ns(r, e, t) {
|
|
3942
3996
|
const s = `/usr/share/pkg/node_modules/${t}/index.js`;
|
|
3943
3997
|
r.registerLazy(
|
|
3944
3998
|
t,
|
|
@@ -3950,7 +4004,7 @@ function zs(r, e, t) {
|
|
|
3950
4004
|
}))
|
|
3951
4005
|
);
|
|
3952
4006
|
}
|
|
3953
|
-
function
|
|
4007
|
+
function Bs(r) {
|
|
3954
4008
|
return async (e) => {
|
|
3955
4009
|
e.stdout.write(` PID TTY TIME CMD
|
|
3956
4010
|
`), e.stdout.write(` 1 tty1 00:00:00 sh
|
|
@@ -3966,13 +4020,13 @@ function js(r) {
|
|
|
3966
4020
|
`), 0;
|
|
3967
4021
|
};
|
|
3968
4022
|
}
|
|
3969
|
-
function
|
|
4023
|
+
function zs(r) {
|
|
3970
4024
|
return async (e) => {
|
|
3971
|
-
const t = /* @__PURE__ */ new Date(), s = String(t.getHours()).padStart(2, "0"), i = String(t.getMinutes()).padStart(2, "0"), n = String(t.getSeconds()).padStart(2, "0"), o = typeof performance < "u" ? performance.now() : 0, a = Math.floor(o / 6e4), c = typeof navigator < "u" && navigator.hardwareConcurrency || 1, l = typeof performance < "u" ? performance.memory : void 0, f = l ? Math.round(l.jsHeapSizeLimit / (1024 * 1024)) : 256,
|
|
4025
|
+
const t = /* @__PURE__ */ new Date(), s = String(t.getHours()).padStart(2, "0"), i = String(t.getMinutes()).padStart(2, "0"), n = String(t.getSeconds()).padStart(2, "0"), o = typeof performance < "u" ? performance.now() : 0, a = Math.floor(o / 6e4), c = typeof navigator < "u" && navigator.hardwareConcurrency || 1, l = typeof performance < "u" ? performance.memory : void 0, f = l ? Math.round(l.jsHeapSizeLimit / (1024 * 1024)) : 256, h = l ? Math.round(l.usedJSHeapSize / (1024 * 1024)) : 16, p = f - h, y = r.list(), E = y.filter((w) => w.status === "running").length, _ = y.filter((w) => w.status === "stopped").length, L = y.length + 2;
|
|
3972
4026
|
e.stdout.write(`top - ${s}:${i}:${n} up ${a} min, 1 user
|
|
3973
|
-
`), e.stdout.write(`Tasks: ${String(
|
|
4027
|
+
`), e.stdout.write(`Tasks: ${String(L).padStart(3, " ")} total, ${String(E + 2).padStart(3, " ")} running, ${String(_).padStart(3, " ")} stopped
|
|
3974
4028
|
`), e.stdout.write(`%Cpu(s): ${c} cores
|
|
3975
|
-
`), e.stdout.write(`MiB Mem: ${String(f).padStart(7, " ")} total ${String(
|
|
4029
|
+
`), e.stdout.write(`MiB Mem: ${String(f).padStart(7, " ")} total ${String(h).padStart(7, " ")} used ${String(p).padStart(7, " ")} free
|
|
3976
4030
|
`), e.stdout.write(`
|
|
3977
4031
|
`), e.stdout.write(` PID CMD STATUS
|
|
3978
4032
|
`), e.stdout.write(` 1 sh running
|
|
@@ -3987,7 +4041,7 @@ function Ds(r) {
|
|
|
3987
4041
|
`), 0;
|
|
3988
4042
|
};
|
|
3989
4043
|
}
|
|
3990
|
-
const
|
|
4044
|
+
const js = {
|
|
3991
4045
|
HUP: 1,
|
|
3992
4046
|
INT: 2,
|
|
3993
4047
|
QUIT: 3,
|
|
@@ -4011,7 +4065,7 @@ const Os = {
|
|
|
4011
4065
|
19: "STOP",
|
|
4012
4066
|
18: "CONT"
|
|
4013
4067
|
};
|
|
4014
|
-
function
|
|
4068
|
+
function Ds(r) {
|
|
4015
4069
|
return async (e) => {
|
|
4016
4070
|
const t = e.args;
|
|
4017
4071
|
if (t.length === 0)
|
|
@@ -4029,7 +4083,7 @@ function Ms(r) {
|
|
|
4029
4083
|
s = 1;
|
|
4030
4084
|
const o = parseInt(n, 10);
|
|
4031
4085
|
if (!(!isNaN(o) && Be[o])) {
|
|
4032
|
-
if (
|
|
4086
|
+
if (js[n.toUpperCase()] === void 0) return e.stderr.write(`kill: invalid signal: ${n}
|
|
4033
4087
|
`), 1;
|
|
4034
4088
|
}
|
|
4035
4089
|
}
|
|
@@ -4071,7 +4125,7 @@ function Ms(r) {
|
|
|
4071
4125
|
return i;
|
|
4072
4126
|
};
|
|
4073
4127
|
}
|
|
4074
|
-
function
|
|
4128
|
+
function Os(r) {
|
|
4075
4129
|
return async (e) => {
|
|
4076
4130
|
let t = 2, s = 0;
|
|
4077
4131
|
if (e.args[0] === "-n" && e.args.length > 1) {
|
|
@@ -4090,8 +4144,8 @@ function Ws(r) {
|
|
|
4090
4144
|
|
|
4091
4145
|
`);
|
|
4092
4146
|
const l = [], f = {
|
|
4093
|
-
write(
|
|
4094
|
-
l.push(
|
|
4147
|
+
write(h) {
|
|
4148
|
+
l.push(h);
|
|
4095
4149
|
}
|
|
4096
4150
|
};
|
|
4097
4151
|
await a({
|
|
@@ -4118,7 +4172,7 @@ function Ws(r) {
|
|
|
4118
4172
|
});
|
|
4119
4173
|
};
|
|
4120
4174
|
}
|
|
4121
|
-
const
|
|
4175
|
+
const Ms = [
|
|
4122
4176
|
"cd",
|
|
4123
4177
|
"pwd",
|
|
4124
4178
|
"echo",
|
|
@@ -4135,8 +4189,8 @@ const qs = [
|
|
|
4135
4189
|
".",
|
|
4136
4190
|
"alias",
|
|
4137
4191
|
"unalias"
|
|
4138
|
-
],
|
|
4139
|
-
"Shell builtins":
|
|
4192
|
+
], Ws = {
|
|
4193
|
+
"Shell builtins": Ms,
|
|
4140
4194
|
"File system": [
|
|
4141
4195
|
"ls",
|
|
4142
4196
|
"cat",
|
|
@@ -4199,13 +4253,13 @@ const qs = [
|
|
|
4199
4253
|
Archive: ["tar", "gzip", "gunzip", "zip", "unzip"],
|
|
4200
4254
|
"Node.js": ["node", "pkg"]
|
|
4201
4255
|
};
|
|
4202
|
-
function
|
|
4256
|
+
function qs(r) {
|
|
4203
4257
|
return async (e) => {
|
|
4204
4258
|
e.stdout.write(`Lifo Commands
|
|
4205
4259
|
`), e.stdout.write(`==================
|
|
4206
4260
|
|
|
4207
4261
|
`);
|
|
4208
|
-
for (const [t, s] of Object.entries(
|
|
4262
|
+
for (const [t, s] of Object.entries(Ws)) {
|
|
4209
4263
|
e.stdout.write(`${t}:
|
|
4210
4264
|
`);
|
|
4211
4265
|
const i = 6;
|
|
@@ -4221,233 +4275,7 @@ function Hs(r) {
|
|
|
4221
4275
|
`), 0;
|
|
4222
4276
|
};
|
|
4223
4277
|
}
|
|
4224
|
-
|
|
4225
|
-
function Zs(r, e) {
|
|
4226
|
-
let t;
|
|
4227
|
-
try {
|
|
4228
|
-
const s = r.readFileString(Vs);
|
|
4229
|
-
t = JSON.parse(s);
|
|
4230
|
-
} catch {
|
|
4231
|
-
return;
|
|
4232
|
-
}
|
|
4233
|
-
for (const s of Object.keys(t.packages)) {
|
|
4234
|
-
const i = `${Gs}/${s}/index.js`;
|
|
4235
|
-
r.exists(i) && e.registerLazy(
|
|
4236
|
-
s,
|
|
4237
|
-
() => Promise.resolve().then(() => ge).then((n) => ({
|
|
4238
|
-
default: ((o) => n.default({
|
|
4239
|
-
...o,
|
|
4240
|
-
args: [i, ...o.args]
|
|
4241
|
-
}))
|
|
4242
|
-
}))
|
|
4243
|
-
);
|
|
4244
|
-
}
|
|
4245
|
-
}
|
|
4246
|
-
class Js {
|
|
4247
|
-
constructor(e, t) {
|
|
4248
|
-
this.vfs = e, this.getCwd = t;
|
|
4249
|
-
}
|
|
4250
|
-
resolvePath(e) {
|
|
4251
|
-
return I(this.getCwd(), e);
|
|
4252
|
-
}
|
|
4253
|
-
readFile(e, t) {
|
|
4254
|
-
const s = this.resolvePath(e);
|
|
4255
|
-
return t === null ? Promise.resolve(this.vfs.readFile(s)) : Promise.resolve(this.vfs.readFileString(s));
|
|
4256
|
-
}
|
|
4257
|
-
async writeFile(e, t) {
|
|
4258
|
-
const s = this.resolvePath(e);
|
|
4259
|
-
this.vfs.writeFile(s, t);
|
|
4260
|
-
}
|
|
4261
|
-
async readdir(e) {
|
|
4262
|
-
const t = this.resolvePath(e);
|
|
4263
|
-
return this.vfs.readdir(t);
|
|
4264
|
-
}
|
|
4265
|
-
async stat(e) {
|
|
4266
|
-
const t = this.resolvePath(e), s = this.vfs.stat(t);
|
|
4267
|
-
return { type: s.type, size: s.size, mtime: s.mtime };
|
|
4268
|
-
}
|
|
4269
|
-
async mkdir(e, t) {
|
|
4270
|
-
const s = this.resolvePath(e);
|
|
4271
|
-
this.vfs.mkdir(s, t);
|
|
4272
|
-
}
|
|
4273
|
-
async rm(e, t) {
|
|
4274
|
-
const s = this.resolvePath(e);
|
|
4275
|
-
this.vfs.stat(s).type === "directory" ? t != null && t.recursive ? this.vfs.rmdirRecursive(s) : this.vfs.rmdir(s) : this.vfs.unlink(s);
|
|
4276
|
-
}
|
|
4277
|
-
async exists(e) {
|
|
4278
|
-
const t = this.resolvePath(e);
|
|
4279
|
-
return this.vfs.exists(t);
|
|
4280
|
-
}
|
|
4281
|
-
async rename(e, t) {
|
|
4282
|
-
const s = this.resolvePath(e), i = this.resolvePath(t);
|
|
4283
|
-
this.vfs.rename(s, i);
|
|
4284
|
-
}
|
|
4285
|
-
async cp(e, t) {
|
|
4286
|
-
const s = this.resolvePath(e), i = this.resolvePath(t);
|
|
4287
|
-
this.vfs.copyFile(s, i);
|
|
4288
|
-
}
|
|
4289
|
-
async writeFiles(e) {
|
|
4290
|
-
for (const { path: t, content: s } of e)
|
|
4291
|
-
await this.writeFile(t, s);
|
|
4292
|
-
}
|
|
4293
|
-
}
|
|
4294
|
-
class Ys {
|
|
4295
|
-
constructor(e, t) {
|
|
4296
|
-
h(this, "queue", Promise.resolve());
|
|
4297
|
-
this.shell = e, this.registry = t;
|
|
4298
|
-
}
|
|
4299
|
-
run(e, t) {
|
|
4300
|
-
return new Promise((i, n) => {
|
|
4301
|
-
this.queue = this.queue.then(async () => {
|
|
4302
|
-
try {
|
|
4303
|
-
const o = await this.executeWithOptions(e, t);
|
|
4304
|
-
i(o);
|
|
4305
|
-
} catch (o) {
|
|
4306
|
-
n(o);
|
|
4307
|
-
}
|
|
4308
|
-
});
|
|
4309
|
-
});
|
|
4310
|
-
}
|
|
4311
|
-
register(e, t) {
|
|
4312
|
-
this.registry.register(e, t);
|
|
4313
|
-
}
|
|
4314
|
-
async executeWithOptions(e, t) {
|
|
4315
|
-
let s, i;
|
|
4316
|
-
if (t != null && t.timeout || t != null && t.signal) {
|
|
4317
|
-
if (s = new AbortController(), t.signal) {
|
|
4318
|
-
if (t.signal.aborted)
|
|
4319
|
-
return { stdout: "", stderr: "", exitCode: 130 };
|
|
4320
|
-
t.signal.addEventListener("abort", () => s.abort(), { once: !0 });
|
|
4321
|
-
}
|
|
4322
|
-
t.timeout && (i = setTimeout(() => s.abort(), t.timeout));
|
|
4323
|
-
}
|
|
4324
|
-
try {
|
|
4325
|
-
return await this.shell.execute(e, {
|
|
4326
|
-
cwd: t == null ? void 0 : t.cwd,
|
|
4327
|
-
env: t == null ? void 0 : t.env,
|
|
4328
|
-
onStdout: t == null ? void 0 : t.onStdout,
|
|
4329
|
-
onStderr: t == null ? void 0 : t.onStderr,
|
|
4330
|
-
stdin: t == null ? void 0 : t.stdin
|
|
4331
|
-
});
|
|
4332
|
-
} finally {
|
|
4333
|
-
i !== void 0 && clearTimeout(i);
|
|
4334
|
-
}
|
|
4335
|
-
}
|
|
4336
|
-
}
|
|
4337
|
-
class Xs {
|
|
4338
|
-
constructor() {
|
|
4339
|
-
h(this, "dataCallback", null);
|
|
4340
|
-
}
|
|
4341
|
-
write(e) {
|
|
4342
|
-
}
|
|
4343
|
-
writeln(e) {
|
|
4344
|
-
}
|
|
4345
|
-
onData(e) {
|
|
4346
|
-
this.dataCallback = e;
|
|
4347
|
-
}
|
|
4348
|
-
get cols() {
|
|
4349
|
-
return 80;
|
|
4350
|
-
}
|
|
4351
|
-
get rows() {
|
|
4352
|
-
return 24;
|
|
4353
|
-
}
|
|
4354
|
-
focus() {
|
|
4355
|
-
}
|
|
4356
|
-
clear() {
|
|
4357
|
-
}
|
|
4358
|
-
/** Send data as if typed on keyboard (used internally for stdin) */
|
|
4359
|
-
sendData(e) {
|
|
4360
|
-
var t;
|
|
4361
|
-
(t = this.dataCallback) == null || t.call(this, e);
|
|
4362
|
-
}
|
|
4363
|
-
}
|
|
4364
|
-
class Ye {
|
|
4365
|
-
constructor(e, t, s, i, n) {
|
|
4366
|
-
/** Programmatic command execution */
|
|
4367
|
-
h(this, "commands");
|
|
4368
|
-
/** Filesystem operations */
|
|
4369
|
-
h(this, "fs");
|
|
4370
|
-
/** Environment variables */
|
|
4371
|
-
h(this, "env");
|
|
4372
|
-
// Power-user escape hatches
|
|
4373
|
-
h(this, "kernel");
|
|
4374
|
-
h(this, "shell");
|
|
4375
|
-
h(this, "_destroyed", !1);
|
|
4376
|
-
this.kernel = e, this.shell = t, this.commands = s, this.fs = i, this.env = n;
|
|
4377
|
-
}
|
|
4378
|
-
/** Current working directory */
|
|
4379
|
-
get cwd() {
|
|
4380
|
-
return this.shell.getCwd();
|
|
4381
|
-
}
|
|
4382
|
-
set cwd(e) {
|
|
4383
|
-
this.shell.setCwd(e);
|
|
4384
|
-
}
|
|
4385
|
-
/**
|
|
4386
|
-
* Create a new Sandbox instance.
|
|
4387
|
-
* Orchestrates all boot steps: Kernel, VFS, Registry, Shell, config sourcing.
|
|
4388
|
-
*/
|
|
4389
|
-
static async create(e) {
|
|
4390
|
-
const t = new Yt();
|
|
4391
|
-
await t.boot({ persist: (e == null ? void 0 : e.persist) ?? !1 });
|
|
4392
|
-
const s = Fs();
|
|
4393
|
-
if (s.register("pkg", Bs(s)), Zs(t.vfs, s), e != null && e.files)
|
|
4394
|
-
for (const [m, y] of Object.entries(e.files))
|
|
4395
|
-
Ks(t.vfs, m), t.vfs.writeFile(m, y);
|
|
4396
|
-
const n = { ...t.getDefaultEnv(), ...e == null ? void 0 : e.env };
|
|
4397
|
-
e != null && e.cwd && (n.PWD = e.cwd);
|
|
4398
|
-
let o;
|
|
4399
|
-
if (e != null && e.terminal) {
|
|
4400
|
-
const { Terminal: m } = await Promise.resolve().then(() => Ue), y = Qs(e.terminal), E = new m(y);
|
|
4401
|
-
o = E;
|
|
4402
|
-
const A = t.vfs.readFileString("/etc/motd");
|
|
4403
|
-
E.write(A.replace(/\r\n/g, `
|
|
4404
|
-
`).replace(/\n/g, `\r
|
|
4405
|
-
`));
|
|
4406
|
-
} else
|
|
4407
|
-
o = new Xs();
|
|
4408
|
-
const a = new _s(o, t.vfs, s, n), c = a.getJobTable();
|
|
4409
|
-
s.register("ps", js(c)), s.register("top", Ds(c)), s.register("kill", Ms(c)), s.register("watch", Ws(s)), s.register("help", Hs()), await a.sourceFile("/etc/profile"), await a.sourceFile(n.HOME + "/.bashrc"), e != null && e.cwd && a.setCwd(e.cwd), e != null && e.terminal && (a.start(), o.focus());
|
|
4410
|
-
const l = () => a.getCwd(), f = new Js(t.vfs, l), u = new Ys(a, s);
|
|
4411
|
-
return new Ye(t, a, u, f, n);
|
|
4412
|
-
}
|
|
4413
|
-
/**
|
|
4414
|
-
* Attach a headless sandbox to a DOM element, enabling visual mode.
|
|
4415
|
-
*/
|
|
4416
|
-
async attach(e) {
|
|
4417
|
-
if (this._destroyed) throw new Error("Sandbox is destroyed");
|
|
4418
|
-
const { Terminal: t } = await Promise.resolve().then(() => Ue), s = new t(e), i = this.kernel.vfs.readFileString("/etc/motd");
|
|
4419
|
-
s.write(i.replace(/\r\n/g, `
|
|
4420
|
-
`).replace(/\n/g, `\r
|
|
4421
|
-
`)), s.focus();
|
|
4422
|
-
}
|
|
4423
|
-
/**
|
|
4424
|
-
* Detach from visual mode.
|
|
4425
|
-
*/
|
|
4426
|
-
detach() {
|
|
4427
|
-
}
|
|
4428
|
-
/**
|
|
4429
|
-
* Destroy the sandbox, releasing all resources.
|
|
4430
|
-
*/
|
|
4431
|
-
destroy() {
|
|
4432
|
-
this._destroyed = !0;
|
|
4433
|
-
}
|
|
4434
|
-
}
|
|
4435
|
-
function Qs(r) {
|
|
4436
|
-
if (typeof r == "string") {
|
|
4437
|
-
const e = document.querySelector(r);
|
|
4438
|
-
if (!e) throw new Error(`Sandbox: element not found: ${r}`);
|
|
4439
|
-
return e;
|
|
4440
|
-
}
|
|
4441
|
-
return r;
|
|
4442
|
-
}
|
|
4443
|
-
function Ks(r, e) {
|
|
4444
|
-
const t = e.split("/").filter(Boolean);
|
|
4445
|
-
t.pop();
|
|
4446
|
-
let s = "";
|
|
4447
|
-
for (const i of t)
|
|
4448
|
-
s += "/" + i, r.exists(s) || r.mkdir(s, { recursive: !0 });
|
|
4449
|
-
}
|
|
4450
|
-
function er(r) {
|
|
4278
|
+
function Us(r) {
|
|
4451
4279
|
const e = r.type === "file", t = r.type === "directory";
|
|
4452
4280
|
return {
|
|
4453
4281
|
dev: 0,
|
|
@@ -4477,7 +4305,7 @@ function er(r) {
|
|
|
4477
4305
|
isSocket: () => !1
|
|
4478
4306
|
};
|
|
4479
4307
|
}
|
|
4480
|
-
function
|
|
4308
|
+
function Hs(r, e, t) {
|
|
4481
4309
|
const s = new Error(r.message);
|
|
4482
4310
|
return s.code = r.code, s.errno = -2, s.syscall = e, s.path = t, s.name = "Error", s;
|
|
4483
4311
|
}
|
|
@@ -4486,105 +4314,105 @@ function F(r, e) {
|
|
|
4486
4314
|
return I(r, t);
|
|
4487
4315
|
}
|
|
4488
4316
|
function ze(r, e) {
|
|
4489
|
-
function t(
|
|
4490
|
-
const v = typeof d == "string" ? d : d == null ? void 0 : d.encoding, b = F(e,
|
|
4317
|
+
function t(m, d) {
|
|
4318
|
+
const v = typeof d == "string" ? d : d == null ? void 0 : d.encoding, b = F(e, m);
|
|
4491
4319
|
return v ? r.readFileString(b) : r.readFile(b);
|
|
4492
4320
|
}
|
|
4493
|
-
function s(
|
|
4494
|
-
const b = F(e,
|
|
4321
|
+
function s(m, d, v) {
|
|
4322
|
+
const b = F(e, m);
|
|
4495
4323
|
r.writeFile(b, d);
|
|
4496
4324
|
}
|
|
4497
|
-
function i(
|
|
4498
|
-
const v = F(e,
|
|
4325
|
+
function i(m, d) {
|
|
4326
|
+
const v = F(e, m);
|
|
4499
4327
|
r.appendFile(v, d);
|
|
4500
4328
|
}
|
|
4501
|
-
function n(
|
|
4502
|
-
const d = F(e,
|
|
4329
|
+
function n(m) {
|
|
4330
|
+
const d = F(e, m);
|
|
4503
4331
|
return r.exists(d);
|
|
4504
4332
|
}
|
|
4505
|
-
function o(
|
|
4506
|
-
const d = F(e,
|
|
4507
|
-
return
|
|
4333
|
+
function o(m) {
|
|
4334
|
+
const d = F(e, m);
|
|
4335
|
+
return Us(r.stat(d));
|
|
4508
4336
|
}
|
|
4509
|
-
function a(
|
|
4510
|
-
return o(
|
|
4337
|
+
function a(m) {
|
|
4338
|
+
return o(m);
|
|
4511
4339
|
}
|
|
4512
|
-
function c(
|
|
4513
|
-
const v = F(e,
|
|
4340
|
+
function c(m, d) {
|
|
4341
|
+
const v = F(e, m), b = typeof d == "number" ? {} : d;
|
|
4514
4342
|
r.mkdir(v, { recursive: b == null ? void 0 : b.recursive });
|
|
4515
4343
|
}
|
|
4516
|
-
function l(
|
|
4517
|
-
const v = F(e,
|
|
4344
|
+
function l(m, d) {
|
|
4345
|
+
const v = F(e, m);
|
|
4518
4346
|
return r.readdir(v).map((T) => T.name);
|
|
4519
4347
|
}
|
|
4520
|
-
function f(
|
|
4521
|
-
const d = F(e,
|
|
4348
|
+
function f(m) {
|
|
4349
|
+
const d = F(e, m);
|
|
4522
4350
|
r.unlink(d);
|
|
4523
4351
|
}
|
|
4524
|
-
function
|
|
4525
|
-
const v = F(e,
|
|
4352
|
+
function h(m, d) {
|
|
4353
|
+
const v = F(e, m);
|
|
4526
4354
|
d != null && d.recursive ? r.rmdirRecursive(v) : r.rmdir(v);
|
|
4527
4355
|
}
|
|
4528
|
-
function m
|
|
4529
|
-
const v = F(e,
|
|
4356
|
+
function p(m, d) {
|
|
4357
|
+
const v = F(e, m), b = F(e, d);
|
|
4530
4358
|
r.rename(v, b);
|
|
4531
4359
|
}
|
|
4532
|
-
function y(
|
|
4533
|
-
const v = F(e,
|
|
4360
|
+
function y(m, d) {
|
|
4361
|
+
const v = F(e, m), b = F(e, d);
|
|
4534
4362
|
r.copyFile(v, b);
|
|
4535
4363
|
}
|
|
4536
|
-
function E(
|
|
4364
|
+
function E(m, d) {
|
|
4537
4365
|
}
|
|
4538
|
-
function
|
|
4539
|
-
const v = F(e,
|
|
4366
|
+
function _(m, d) {
|
|
4367
|
+
const v = F(e, m);
|
|
4540
4368
|
if (!r.exists(v)) {
|
|
4541
4369
|
const b = new Error(`ENOENT: no such file or directory, access '${v}'`);
|
|
4542
4370
|
throw b.code = "ENOENT", b.errno = -2, b.syscall = "access", b.path = v, b;
|
|
4543
4371
|
}
|
|
4544
4372
|
}
|
|
4545
|
-
function
|
|
4373
|
+
function L(m, d) {
|
|
4546
4374
|
queueMicrotask(() => {
|
|
4547
4375
|
try {
|
|
4548
|
-
const v =
|
|
4376
|
+
const v = m();
|
|
4549
4377
|
d(null, v);
|
|
4550
4378
|
} catch (v) {
|
|
4551
4379
|
if (v instanceof k)
|
|
4552
|
-
d(
|
|
4380
|
+
d(Hs(v, "", ""));
|
|
4553
4381
|
else
|
|
4554
4382
|
throw v;
|
|
4555
4383
|
}
|
|
4556
4384
|
});
|
|
4557
4385
|
}
|
|
4558
|
-
function S(
|
|
4386
|
+
function S(m, d, v) {
|
|
4559
4387
|
const b = typeof d == "function" ? d : v, T = typeof d == "function" ? void 0 : d;
|
|
4560
|
-
|
|
4388
|
+
L(() => t(m, T), b);
|
|
4561
4389
|
}
|
|
4562
|
-
function w(
|
|
4563
|
-
|
|
4390
|
+
function w(m, d, v, b) {
|
|
4391
|
+
L(() => s(m, d), typeof v == "function" ? v : b);
|
|
4564
4392
|
}
|
|
4565
|
-
function $(
|
|
4566
|
-
|
|
4393
|
+
function $(m, d) {
|
|
4394
|
+
L(() => o(m), d);
|
|
4567
4395
|
}
|
|
4568
|
-
function x(
|
|
4396
|
+
function x(m, d, v) {
|
|
4569
4397
|
const b = typeof d == "function" ? d : v, T = typeof d == "function" ? void 0 : d;
|
|
4570
|
-
|
|
4398
|
+
L(() => c(m, T), b);
|
|
4571
4399
|
}
|
|
4572
|
-
function
|
|
4573
|
-
|
|
4400
|
+
function R(m, d, v) {
|
|
4401
|
+
L(() => l(m), typeof d == "function" ? d : v);
|
|
4574
4402
|
}
|
|
4575
|
-
function
|
|
4576
|
-
|
|
4403
|
+
function P(m, d) {
|
|
4404
|
+
L(() => f(m), d);
|
|
4577
4405
|
}
|
|
4578
|
-
function j(
|
|
4579
|
-
|
|
4406
|
+
function j(m, d, v) {
|
|
4407
|
+
L(() => p(m, d), v);
|
|
4580
4408
|
}
|
|
4581
|
-
function U(
|
|
4409
|
+
function U(m, d, v) {
|
|
4582
4410
|
const b = typeof d == "function" ? d : v, T = typeof d == "function" ? void 0 : d;
|
|
4583
|
-
|
|
4411
|
+
L(() => _(m, T), b);
|
|
4584
4412
|
}
|
|
4585
|
-
function H(
|
|
4413
|
+
function H(m, d) {
|
|
4586
4414
|
queueMicrotask(() => {
|
|
4587
|
-
d(n(
|
|
4415
|
+
d(n(m));
|
|
4588
4416
|
});
|
|
4589
4417
|
}
|
|
4590
4418
|
return {
|
|
@@ -4598,39 +4426,39 @@ function ze(r, e) {
|
|
|
4598
4426
|
mkdirSync: c,
|
|
4599
4427
|
readdirSync: l,
|
|
4600
4428
|
unlinkSync: f,
|
|
4601
|
-
rmdirSync:
|
|
4602
|
-
renameSync:
|
|
4429
|
+
rmdirSync: h,
|
|
4430
|
+
renameSync: p,
|
|
4603
4431
|
copyFileSync: y,
|
|
4604
4432
|
chmodSync: E,
|
|
4605
|
-
accessSync:
|
|
4433
|
+
accessSync: _,
|
|
4606
4434
|
// Callback
|
|
4607
4435
|
readFile: S,
|
|
4608
4436
|
writeFile: w,
|
|
4609
4437
|
stat: $,
|
|
4610
4438
|
mkdir: x,
|
|
4611
|
-
readdir:
|
|
4612
|
-
unlink:
|
|
4439
|
+
readdir: R,
|
|
4440
|
+
unlink: P,
|
|
4613
4441
|
rename: j,
|
|
4614
4442
|
access: U,
|
|
4615
4443
|
exists: H,
|
|
4616
4444
|
// Promises
|
|
4617
4445
|
promises: {
|
|
4618
|
-
readFile: async (
|
|
4619
|
-
writeFile: async (
|
|
4620
|
-
appendFile: async (
|
|
4621
|
-
stat: async (
|
|
4622
|
-
lstat: async (
|
|
4623
|
-
mkdir: async (
|
|
4624
|
-
c(
|
|
4446
|
+
readFile: async (m, d) => t(m, d),
|
|
4447
|
+
writeFile: async (m, d) => s(m, d),
|
|
4448
|
+
appendFile: async (m, d) => i(m, d),
|
|
4449
|
+
stat: async (m) => o(m),
|
|
4450
|
+
lstat: async (m) => a(m),
|
|
4451
|
+
mkdir: async (m, d) => {
|
|
4452
|
+
c(m, d);
|
|
4625
4453
|
},
|
|
4626
|
-
readdir: async (
|
|
4627
|
-
unlink: async (
|
|
4628
|
-
rmdir: async (
|
|
4629
|
-
rename: async (
|
|
4630
|
-
copyFile: async (
|
|
4631
|
-
access: async (
|
|
4632
|
-
rm: async (
|
|
4633
|
-
const v = F(e,
|
|
4454
|
+
readdir: async (m) => l(m),
|
|
4455
|
+
unlink: async (m) => f(m),
|
|
4456
|
+
rmdir: async (m, d) => h(m, d),
|
|
4457
|
+
rename: async (m, d) => p(m, d),
|
|
4458
|
+
copyFile: async (m, d) => y(m, d),
|
|
4459
|
+
access: async (m, d) => _(m),
|
|
4460
|
+
rm: async (m, d) => {
|
|
4461
|
+
const v = F(e, m);
|
|
4634
4462
|
try {
|
|
4635
4463
|
r.stat(v).type === "directory" ? d != null && d.recursive ? r.rmdirRecursive(v) : r.rmdir(v) : r.unlink(v);
|
|
4636
4464
|
} catch (b) {
|
|
@@ -4648,7 +4476,7 @@ function ze(r, e) {
|
|
|
4648
4476
|
}
|
|
4649
4477
|
};
|
|
4650
4478
|
}
|
|
4651
|
-
function
|
|
4479
|
+
function Je(r, e) {
|
|
4652
4480
|
const t = W(r).split("/").filter(Boolean), s = W(e).split("/").filter(Boolean);
|
|
4653
4481
|
let i = 0;
|
|
4654
4482
|
for (; i < t.length && i < s.length && t[i] === s[i]; )
|
|
@@ -4656,15 +4484,15 @@ function Xe(r, e) {
|
|
|
4656
4484
|
const n = t.length - i, o = s.slice(i);
|
|
4657
4485
|
return [...Array(n).fill(".."), ...o].join("/") || ".";
|
|
4658
4486
|
}
|
|
4659
|
-
function
|
|
4487
|
+
function Ye(r) {
|
|
4660
4488
|
const e = se(r) ? "/" : "", t = G(r), s = K(r), i = Q(r), n = i ? s.slice(0, -i.length) : s;
|
|
4661
4489
|
return { root: e, dir: t, base: s, ext: i, name: n };
|
|
4662
4490
|
}
|
|
4663
|
-
function
|
|
4491
|
+
function Xe(r) {
|
|
4664
4492
|
const e = r.dir || r.root || "", t = r.base || (r.name || "") + (r.ext || "");
|
|
4665
4493
|
return e ? e.endsWith("/") ? e + t : e + "/" + t : t;
|
|
4666
4494
|
}
|
|
4667
|
-
const
|
|
4495
|
+
const Qe = "/", Ke = ":", Vs = {
|
|
4668
4496
|
normalize: W,
|
|
4669
4497
|
isAbsolute: se,
|
|
4670
4498
|
join: ue,
|
|
@@ -4672,12 +4500,12 @@ const et = "/", tt = ":", sr = {
|
|
|
4672
4500
|
dirname: G,
|
|
4673
4501
|
basename: K,
|
|
4674
4502
|
extname: Q,
|
|
4675
|
-
relative:
|
|
4676
|
-
parse:
|
|
4677
|
-
format:
|
|
4678
|
-
sep:
|
|
4679
|
-
delimiter:
|
|
4680
|
-
},
|
|
4503
|
+
relative: Je,
|
|
4504
|
+
parse: Ye,
|
|
4505
|
+
format: Xe,
|
|
4506
|
+
sep: Qe,
|
|
4507
|
+
delimiter: Ke
|
|
4508
|
+
}, Gs = {
|
|
4681
4509
|
normalize: W,
|
|
4682
4510
|
isAbsolute: se,
|
|
4683
4511
|
join: ue,
|
|
@@ -4685,14 +4513,14 @@ const et = "/", tt = ":", sr = {
|
|
|
4685
4513
|
dirname: G,
|
|
4686
4514
|
basename: K,
|
|
4687
4515
|
extname: Q,
|
|
4688
|
-
relative:
|
|
4689
|
-
parse:
|
|
4690
|
-
format:
|
|
4691
|
-
sep:
|
|
4692
|
-
delimiter:
|
|
4693
|
-
posix:
|
|
4516
|
+
relative: Je,
|
|
4517
|
+
parse: Ye,
|
|
4518
|
+
format: Xe,
|
|
4519
|
+
sep: Qe,
|
|
4520
|
+
delimiter: Ke,
|
|
4521
|
+
posix: Vs
|
|
4694
4522
|
};
|
|
4695
|
-
function
|
|
4523
|
+
function Zs(r) {
|
|
4696
4524
|
return {
|
|
4697
4525
|
arch: () => "wasm",
|
|
4698
4526
|
platform: () => "lifo",
|
|
@@ -4736,10 +4564,10 @@ function ir(r) {
|
|
|
4736
4564
|
}
|
|
4737
4565
|
};
|
|
4738
4566
|
}
|
|
4739
|
-
class
|
|
4567
|
+
class et extends Error {
|
|
4740
4568
|
constructor(t) {
|
|
4741
4569
|
super(`process.exit(${t})`);
|
|
4742
|
-
|
|
4570
|
+
u(this, "exitCode");
|
|
4743
4571
|
this.name = "ProcessExitError", this.exitCode = t;
|
|
4744
4572
|
}
|
|
4745
4573
|
}
|
|
@@ -4754,7 +4582,7 @@ function le(r) {
|
|
|
4754
4582
|
throw new Error("process.chdir() is not supported in Lifo");
|
|
4755
4583
|
},
|
|
4756
4584
|
exit: (t = 0) => {
|
|
4757
|
-
throw new
|
|
4585
|
+
throw new et(t);
|
|
4758
4586
|
},
|
|
4759
4587
|
stdout: {
|
|
4760
4588
|
write: (t) => (r.stdout.write(t), !0),
|
|
@@ -4815,8 +4643,8 @@ function le(r) {
|
|
|
4815
4643
|
}
|
|
4816
4644
|
class q {
|
|
4817
4645
|
constructor() {
|
|
4818
|
-
|
|
4819
|
-
|
|
4646
|
+
u(this, "_events", /* @__PURE__ */ new Map());
|
|
4647
|
+
u(this, "_maxListeners", 10);
|
|
4820
4648
|
}
|
|
4821
4649
|
on(e, t) {
|
|
4822
4650
|
let s = this._events.get(e);
|
|
@@ -4874,47 +4702,47 @@ class q {
|
|
|
4874
4702
|
return s || (s = [], this._events.set(e, s)), s.unshift(t), this;
|
|
4875
4703
|
}
|
|
4876
4704
|
}
|
|
4877
|
-
const je = new TextEncoder(),
|
|
4878
|
-
class
|
|
4705
|
+
const je = new TextEncoder(), Js = new TextDecoder();
|
|
4706
|
+
class A extends Uint8Array {
|
|
4879
4707
|
// Use overloaded signatures to satisfy Uint8Array's static from
|
|
4880
4708
|
static from(e, t, s) {
|
|
4881
4709
|
if (typeof e == "string") {
|
|
4882
4710
|
const o = t;
|
|
4883
4711
|
if (o === "base64") {
|
|
4884
|
-
const l = atob(e), f = new
|
|
4885
|
-
for (let
|
|
4712
|
+
const l = atob(e), f = new A(l.length);
|
|
4713
|
+
for (let h = 0; h < l.length; h++) f[h] = l.charCodeAt(h);
|
|
4886
4714
|
return f;
|
|
4887
4715
|
}
|
|
4888
4716
|
if (o === "hex") {
|
|
4889
|
-
const l = new
|
|
4717
|
+
const l = new A(e.length / 2);
|
|
4890
4718
|
for (let f = 0; f < e.length; f += 2)
|
|
4891
4719
|
l[f / 2] = parseInt(e.substring(f, f + 2), 16);
|
|
4892
4720
|
return l;
|
|
4893
4721
|
}
|
|
4894
|
-
const a = je.encode(e), c = new
|
|
4722
|
+
const a = je.encode(e), c = new A(a.length);
|
|
4895
4723
|
return c.set(a), c;
|
|
4896
4724
|
}
|
|
4897
4725
|
if (e instanceof ArrayBuffer) {
|
|
4898
|
-
const o = new
|
|
4726
|
+
const o = new A(e.byteLength);
|
|
4899
4727
|
return o.set(new Uint8Array(e)), o;
|
|
4900
4728
|
}
|
|
4901
4729
|
if (e instanceof Uint8Array) {
|
|
4902
|
-
const o = new
|
|
4730
|
+
const o = new A(e.length);
|
|
4903
4731
|
return o.set(e), o;
|
|
4904
4732
|
}
|
|
4905
|
-
const i = e, n = new
|
|
4733
|
+
const i = e, n = new A(i.length);
|
|
4906
4734
|
for (let o = 0; o < i.length; o++) n[o] = i[o];
|
|
4907
4735
|
return n;
|
|
4908
4736
|
}
|
|
4909
4737
|
static alloc(e, t) {
|
|
4910
|
-
const s = new
|
|
4738
|
+
const s = new A(e);
|
|
4911
4739
|
return t !== void 0 && s.fill(t), s;
|
|
4912
4740
|
}
|
|
4913
4741
|
static isBuffer(e) {
|
|
4914
|
-
return e instanceof
|
|
4742
|
+
return e instanceof A;
|
|
4915
4743
|
}
|
|
4916
4744
|
static concat(e, t) {
|
|
4917
|
-
const s = t ?? e.reduce((o, a) => o + a.length, 0), i =
|
|
4745
|
+
const s = t ?? e.reduce((o, a) => o + a.length, 0), i = A.alloc(s);
|
|
4918
4746
|
let n = 0;
|
|
4919
4747
|
for (const o of e) {
|
|
4920
4748
|
const a = o.subarray(0, Math.min(o.length, s - n));
|
|
@@ -4933,7 +4761,7 @@ class R extends Uint8Array {
|
|
|
4933
4761
|
for (let s = 0; s < this.length; s++) t += this[s].toString(16).padStart(2, "0");
|
|
4934
4762
|
return t;
|
|
4935
4763
|
}
|
|
4936
|
-
return
|
|
4764
|
+
return Js.decode(this);
|
|
4937
4765
|
}
|
|
4938
4766
|
write(e, t, s, i) {
|
|
4939
4767
|
const n = je.encode(e), o = t ?? 0, a = s ?? this.length - o, c = Math.min(n.length, a);
|
|
@@ -4954,7 +4782,7 @@ class R extends Uint8Array {
|
|
|
4954
4782
|
}
|
|
4955
4783
|
slice(e, t) {
|
|
4956
4784
|
const s = super.slice(e, t);
|
|
4957
|
-
return
|
|
4785
|
+
return A.from(s);
|
|
4958
4786
|
}
|
|
4959
4787
|
}
|
|
4960
4788
|
function B(r, ...e) {
|
|
@@ -5012,45 +4840,45 @@ function he(r, e) {
|
|
|
5012
4840
|
}
|
|
5013
4841
|
return String(r);
|
|
5014
4842
|
}
|
|
5015
|
-
function
|
|
4843
|
+
function tt(r) {
|
|
5016
4844
|
return (...e) => new Promise((t, s) => {
|
|
5017
4845
|
r(...e, (i, n) => {
|
|
5018
4846
|
i ? s(i) : t(n);
|
|
5019
4847
|
});
|
|
5020
4848
|
});
|
|
5021
4849
|
}
|
|
5022
|
-
function
|
|
4850
|
+
function st(r, e) {
|
|
5023
4851
|
Object.setPrototypeOf(r.prototype, e.prototype);
|
|
5024
4852
|
}
|
|
5025
|
-
function
|
|
4853
|
+
function rt(r, e) {
|
|
5026
4854
|
let t = !1;
|
|
5027
4855
|
return ((...s) => (t || (console.warn(`DeprecationWarning: ${e}`), t = !0), r(...s)));
|
|
5028
4856
|
}
|
|
5029
|
-
function
|
|
4857
|
+
function it() {
|
|
5030
4858
|
return {
|
|
5031
4859
|
isDate: (r) => r instanceof Date,
|
|
5032
4860
|
isRegExp: (r) => r instanceof RegExp,
|
|
5033
4861
|
isArray: Array.isArray
|
|
5034
4862
|
};
|
|
5035
4863
|
}
|
|
5036
|
-
const
|
|
4864
|
+
const Ys = { format: B, inspect: X, promisify: tt, inherits: st, deprecate: rt, types: it }, Xs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5037
4865
|
__proto__: null,
|
|
5038
|
-
default:
|
|
5039
|
-
deprecate:
|
|
4866
|
+
default: Ys,
|
|
4867
|
+
deprecate: rt,
|
|
5040
4868
|
format: B,
|
|
5041
|
-
inherits:
|
|
4869
|
+
inherits: st,
|
|
5042
4870
|
inspect: X,
|
|
5043
|
-
promisify:
|
|
5044
|
-
types:
|
|
4871
|
+
promisify: tt,
|
|
4872
|
+
types: it
|
|
5045
4873
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
5046
4874
|
class te extends q {
|
|
5047
4875
|
constructor(t, s, i) {
|
|
5048
4876
|
super();
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
4877
|
+
u(this, "statusCode");
|
|
4878
|
+
u(this, "statusMessage");
|
|
4879
|
+
u(this, "headers");
|
|
4880
|
+
u(this, "method");
|
|
4881
|
+
u(this, "url");
|
|
5054
4882
|
this.statusCode = t, this.statusMessage = s, this.headers = i;
|
|
5055
4883
|
}
|
|
5056
4884
|
setEncoding(t) {
|
|
@@ -5060,10 +4888,10 @@ class te extends q {
|
|
|
5060
4888
|
class De extends q {
|
|
5061
4889
|
constructor(t, s, i) {
|
|
5062
4890
|
super();
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
4891
|
+
u(this, "options");
|
|
4892
|
+
u(this, "body", "");
|
|
4893
|
+
u(this, "aborted", !1);
|
|
4894
|
+
u(this, "portRegistry");
|
|
5067
4895
|
this.options = t, this.portRegistry = i, s && this.on("response", s), queueMicrotask(() => this.execute());
|
|
5068
4896
|
}
|
|
5069
4897
|
write(t) {
|
|
@@ -5093,12 +4921,12 @@ class De extends q {
|
|
|
5093
4921
|
};
|
|
5094
4922
|
try {
|
|
5095
4923
|
c(l, f);
|
|
5096
|
-
const
|
|
5097
|
-
this.emit("response",
|
|
5098
|
-
|
|
4924
|
+
const h = new te(f.statusCode, "OK", f.headers);
|
|
4925
|
+
this.emit("response", h), queueMicrotask(() => {
|
|
4926
|
+
h.emit("data", f.body), h.emit("end");
|
|
5099
4927
|
});
|
|
5100
|
-
} catch (
|
|
5101
|
-
this.emit("error",
|
|
4928
|
+
} catch (h) {
|
|
4929
|
+
this.emit("error", h);
|
|
5102
4930
|
}
|
|
5103
4931
|
return;
|
|
5104
4932
|
}
|
|
@@ -5110,13 +4938,13 @@ class De extends q {
|
|
|
5110
4938
|
headers: this.options.headers,
|
|
5111
4939
|
body: this.options.method !== "GET" && this.body ? this.body : void 0
|
|
5112
4940
|
}), l = {};
|
|
5113
|
-
c.headers.forEach((
|
|
5114
|
-
l[y] =
|
|
4941
|
+
c.headers.forEach((p, y) => {
|
|
4942
|
+
l[y] = p;
|
|
5115
4943
|
});
|
|
5116
4944
|
const f = new te(c.status, c.statusText, l);
|
|
5117
4945
|
this.emit("response", f);
|
|
5118
|
-
const
|
|
5119
|
-
f.emit("data",
|
|
4946
|
+
const h = await c.text();
|
|
4947
|
+
f.emit("data", h), f.emit("end");
|
|
5120
4948
|
} catch (c) {
|
|
5121
4949
|
this.emit("error", c);
|
|
5122
4950
|
}
|
|
@@ -5125,12 +4953,12 @@ class De extends q {
|
|
|
5125
4953
|
return s && this.on("timeout", s), this;
|
|
5126
4954
|
}
|
|
5127
4955
|
}
|
|
5128
|
-
class
|
|
4956
|
+
class nt {
|
|
5129
4957
|
constructor(e) {
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
4958
|
+
u(this, "statusCode", 200);
|
|
4959
|
+
u(this, "_headers", {});
|
|
4960
|
+
u(this, "_body", "");
|
|
4961
|
+
u(this, "_vRes");
|
|
5134
4962
|
this._vRes = e;
|
|
5135
4963
|
}
|
|
5136
4964
|
writeHead(e, t) {
|
|
@@ -5149,15 +4977,15 @@ class at {
|
|
|
5149
4977
|
e && (this._body += e), this._vRes.statusCode = this.statusCode, this._vRes.headers = { ...this._headers }, this._vRes.body = this._body;
|
|
5150
4978
|
}
|
|
5151
4979
|
}
|
|
5152
|
-
const
|
|
4980
|
+
const ot = Symbol.for("lifo.http.activeServers");
|
|
5153
4981
|
class Oe extends q {
|
|
5154
4982
|
constructor(t, s, i) {
|
|
5155
4983
|
super();
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
4984
|
+
u(this, "portRegistry");
|
|
4985
|
+
u(this, "_port", null);
|
|
4986
|
+
u(this, "_closeResolve", null);
|
|
4987
|
+
u(this, "_promise", null);
|
|
4988
|
+
u(this, "_activeServers");
|
|
5161
4989
|
this.portRegistry = t, this._activeServers = s, i && this.on("request", i);
|
|
5162
4990
|
}
|
|
5163
4991
|
listen(t, ...s) {
|
|
@@ -5173,7 +5001,7 @@ class Oe extends q {
|
|
|
5173
5001
|
const n = (o, a) => {
|
|
5174
5002
|
const c = new te(0, "", o.headers);
|
|
5175
5003
|
c.method = o.method, c.url = o.url;
|
|
5176
|
-
const l = new
|
|
5004
|
+
const l = new nt(a);
|
|
5177
5005
|
this.emit("request", c, l);
|
|
5178
5006
|
};
|
|
5179
5007
|
return this.portRegistry.set(t, n), this._activeServers.push(this), i && queueMicrotask(i), this;
|
|
@@ -5195,11 +5023,11 @@ function Me(r) {
|
|
|
5195
5023
|
function t(o, a, c) {
|
|
5196
5024
|
let l, f;
|
|
5197
5025
|
if (typeof o == "string") {
|
|
5198
|
-
const
|
|
5026
|
+
const h = new URL(o);
|
|
5199
5027
|
l = {
|
|
5200
|
-
hostname:
|
|
5201
|
-
port:
|
|
5202
|
-
path:
|
|
5028
|
+
hostname: h.hostname,
|
|
5029
|
+
port: h.port,
|
|
5030
|
+
path: h.pathname + h.search,
|
|
5203
5031
|
method: "GET"
|
|
5204
5032
|
}, typeof a == "function" ? f = a : (l = { ...l, ...a }, f = c);
|
|
5205
5033
|
} else
|
|
@@ -5222,26 +5050,26 @@ function Me(r) {
|
|
|
5222
5050
|
IncomingMessage: te,
|
|
5223
5051
|
ClientRequest: De,
|
|
5224
5052
|
Server: Oe,
|
|
5225
|
-
ServerResponse:
|
|
5226
|
-
[
|
|
5053
|
+
ServerResponse: nt,
|
|
5054
|
+
[ot]: e
|
|
5227
5055
|
};
|
|
5228
5056
|
}
|
|
5229
|
-
function
|
|
5057
|
+
function Qs(r) {
|
|
5230
5058
|
function e(n, o, a) {
|
|
5231
5059
|
const c = typeof o == "function" ? o : a, l = new q();
|
|
5232
5060
|
if (!r)
|
|
5233
5061
|
return queueMicrotask(() => {
|
|
5234
|
-
const
|
|
5235
|
-
c && c(
|
|
5062
|
+
const h = new Error("child_process.exec() requires shell interpreter");
|
|
5063
|
+
c && c(h, "", ""), l.emit("error", h);
|
|
5236
5064
|
}), l;
|
|
5237
5065
|
const f = r;
|
|
5238
5066
|
return queueMicrotask(async () => {
|
|
5239
5067
|
try {
|
|
5240
|
-
const
|
|
5241
|
-
c && c(null,
|
|
5242
|
-
} catch (
|
|
5243
|
-
const
|
|
5244
|
-
c && c(
|
|
5068
|
+
const h = await f(n);
|
|
5069
|
+
c && c(null, h, ""), l.emit("close", 0);
|
|
5070
|
+
} catch (h) {
|
|
5071
|
+
const p = h instanceof Error ? h : new Error(String(h));
|
|
5072
|
+
c && c(p, "", p.message), l.emit("close", 1);
|
|
5245
5073
|
}
|
|
5246
5074
|
}), l;
|
|
5247
5075
|
}
|
|
@@ -5259,9 +5087,9 @@ function cr(r) {
|
|
|
5259
5087
|
class de extends q {
|
|
5260
5088
|
constructor() {
|
|
5261
5089
|
super(...arguments);
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5090
|
+
u(this, "_buffer", []);
|
|
5091
|
+
u(this, "_ended", !1);
|
|
5092
|
+
u(this, "readable", !0);
|
|
5265
5093
|
}
|
|
5266
5094
|
push(t) {
|
|
5267
5095
|
t === null ? (this._ended = !0, this.readable = !1, this.emit("end")) : (this._buffer.push(t), this.emit("data", t));
|
|
@@ -5285,11 +5113,11 @@ class de extends q {
|
|
|
5285
5113
|
return this;
|
|
5286
5114
|
}
|
|
5287
5115
|
}
|
|
5288
|
-
class
|
|
5116
|
+
class at extends q {
|
|
5289
5117
|
constructor() {
|
|
5290
5118
|
super(...arguments);
|
|
5291
|
-
|
|
5292
|
-
|
|
5119
|
+
u(this, "_ended", !1);
|
|
5120
|
+
u(this, "writable", !0);
|
|
5293
5121
|
}
|
|
5294
5122
|
write(t, s, i) {
|
|
5295
5123
|
return this._ended ? !1 : (this.emit("data", t), i && i(), !0);
|
|
@@ -5304,8 +5132,8 @@ class lt extends q {
|
|
|
5304
5132
|
class fe extends de {
|
|
5305
5133
|
constructor() {
|
|
5306
5134
|
super(...arguments);
|
|
5307
|
-
|
|
5308
|
-
|
|
5135
|
+
u(this, "writable", !0);
|
|
5136
|
+
u(this, "_writableEnded", !1);
|
|
5309
5137
|
}
|
|
5310
5138
|
write(t, s, i) {
|
|
5311
5139
|
return this._writableEnded ? !1 : (this.emit("data", t), i && i(), !0);
|
|
@@ -5314,17 +5142,17 @@ class fe extends de {
|
|
|
5314
5142
|
t && this.write(t), this._writableEnded = !0, this.writable = !1, this.emit("finish");
|
|
5315
5143
|
}
|
|
5316
5144
|
}
|
|
5317
|
-
class
|
|
5145
|
+
class ct extends fe {
|
|
5318
5146
|
}
|
|
5319
|
-
const
|
|
5147
|
+
const Ks = { Readable: de, Writable: at, Duplex: fe, PassThrough: ct }, er = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5320
5148
|
__proto__: null,
|
|
5321
5149
|
Duplex: fe,
|
|
5322
|
-
PassThrough:
|
|
5150
|
+
PassThrough: ct,
|
|
5323
5151
|
Readable: de,
|
|
5324
|
-
Writable:
|
|
5325
|
-
default:
|
|
5326
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
5327
|
-
function
|
|
5152
|
+
Writable: at,
|
|
5153
|
+
default: Ks
|
|
5154
|
+
}, Symbol.toStringTag, { value: "Module" })), tr = globalThis.URL, sr = globalThis.URLSearchParams;
|
|
5155
|
+
function lt(r) {
|
|
5328
5156
|
try {
|
|
5329
5157
|
const e = new URL(r);
|
|
5330
5158
|
return {
|
|
@@ -5354,53 +5182,53 @@ function ut(r) {
|
|
|
5354
5182
|
};
|
|
5355
5183
|
}
|
|
5356
5184
|
}
|
|
5357
|
-
function
|
|
5185
|
+
function ht(r) {
|
|
5358
5186
|
let e = "";
|
|
5359
5187
|
return r.protocol && (e += r.protocol + "//"), r.hostname && (e += r.hostname), r.port && (e += ":" + r.port), r.pathname && (e += r.pathname), r.search && (e += r.search), r.hash && (e += r.hash), e;
|
|
5360
5188
|
}
|
|
5361
|
-
function
|
|
5189
|
+
function ut(r, e) {
|
|
5362
5190
|
return new URL(e, r).href;
|
|
5363
5191
|
}
|
|
5364
|
-
const
|
|
5192
|
+
const rr = { URL, URLSearchParams, parse: lt, format: ht, resolve: ut }, ir = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5365
5193
|
__proto__: null,
|
|
5366
|
-
URL:
|
|
5367
|
-
URLSearchParams:
|
|
5368
|
-
default:
|
|
5369
|
-
format:
|
|
5370
|
-
parse:
|
|
5371
|
-
resolve:
|
|
5372
|
-
}, Symbol.toStringTag, { value: "Module" })), me = globalThis.setTimeout,
|
|
5373
|
-
function
|
|
5194
|
+
URL: tr,
|
|
5195
|
+
URLSearchParams: sr,
|
|
5196
|
+
default: rr,
|
|
5197
|
+
format: ht,
|
|
5198
|
+
parse: lt,
|
|
5199
|
+
resolve: ut
|
|
5200
|
+
}, Symbol.toStringTag, { value: "Module" })), me = globalThis.setTimeout, dt = globalThis.setInterval, pe = globalThis.clearTimeout, ft = globalThis.clearInterval;
|
|
5201
|
+
function mt(r, ...e) {
|
|
5374
5202
|
return me(() => r(...e), 0);
|
|
5375
5203
|
}
|
|
5376
|
-
function
|
|
5204
|
+
function pt(r) {
|
|
5377
5205
|
pe(r);
|
|
5378
5206
|
}
|
|
5379
|
-
const
|
|
5207
|
+
const nr = {
|
|
5380
5208
|
setTimeout: me,
|
|
5381
|
-
setInterval:
|
|
5209
|
+
setInterval: dt,
|
|
5382
5210
|
clearTimeout: pe,
|
|
5383
|
-
clearInterval:
|
|
5384
|
-
setImmediate:
|
|
5385
|
-
clearImmediate:
|
|
5386
|
-
},
|
|
5211
|
+
clearInterval: ft,
|
|
5212
|
+
setImmediate: mt,
|
|
5213
|
+
clearImmediate: pt
|
|
5214
|
+
}, or = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5387
5215
|
__proto__: null,
|
|
5388
|
-
_clearInterval:
|
|
5216
|
+
_clearInterval: ft,
|
|
5389
5217
|
_clearTimeout: pe,
|
|
5390
|
-
_setInterval:
|
|
5218
|
+
_setInterval: dt,
|
|
5391
5219
|
_setTimeout: me,
|
|
5392
|
-
clearImmediate:
|
|
5393
|
-
default:
|
|
5394
|
-
setImmediate:
|
|
5220
|
+
clearImmediate: pt,
|
|
5221
|
+
default: nr,
|
|
5222
|
+
setImmediate: mt
|
|
5395
5223
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
5396
|
-
function
|
|
5397
|
-
const e =
|
|
5224
|
+
function gt(r) {
|
|
5225
|
+
const e = A.alloc(r);
|
|
5398
5226
|
return crypto.getRandomValues(e), e;
|
|
5399
5227
|
}
|
|
5400
|
-
function
|
|
5228
|
+
function wt() {
|
|
5401
5229
|
return crypto.randomUUID();
|
|
5402
5230
|
}
|
|
5403
|
-
function
|
|
5231
|
+
function yt(r) {
|
|
5404
5232
|
const t = {
|
|
5405
5233
|
sha1: "SHA-1",
|
|
5406
5234
|
"sha-1": "SHA-1",
|
|
@@ -5425,30 +5253,30 @@ function bt(r) {
|
|
|
5425
5253
|
let a = 0;
|
|
5426
5254
|
for (const f of s)
|
|
5427
5255
|
o.set(f, a), a += f.length;
|
|
5428
|
-
const c = await crypto.subtle.digest(t, o), l =
|
|
5256
|
+
const c = await crypto.subtle.digest(t, o), l = A.from(c);
|
|
5429
5257
|
return i === "hex" ? l.toString("hex") : i === "base64" ? l.toString("base64") : l;
|
|
5430
5258
|
}
|
|
5431
5259
|
};
|
|
5432
5260
|
}
|
|
5433
|
-
function
|
|
5261
|
+
function vt(r, e) {
|
|
5434
5262
|
e === void 0 && (e = r, r = 0);
|
|
5435
5263
|
const t = e - r, s = new Uint32Array(1);
|
|
5436
5264
|
return crypto.getRandomValues(s), r + s[0] % t;
|
|
5437
5265
|
}
|
|
5438
|
-
const
|
|
5266
|
+
const ar = { randomBytes: gt, randomUUID: wt, createHash: yt, randomInt: vt }, cr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5439
5267
|
__proto__: null,
|
|
5440
|
-
createHash:
|
|
5441
|
-
default:
|
|
5442
|
-
randomBytes:
|
|
5443
|
-
randomInt:
|
|
5444
|
-
randomUUID:
|
|
5268
|
+
createHash: yt,
|
|
5269
|
+
default: ar,
|
|
5270
|
+
randomBytes: gt,
|
|
5271
|
+
randomInt: vt,
|
|
5272
|
+
randomUUID: wt
|
|
5445
5273
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
5446
5274
|
function We(r) {
|
|
5447
5275
|
return {
|
|
5448
5276
|
fs: () => ze(r.vfs, r.cwd),
|
|
5449
5277
|
"fs/promises": () => ze(r.vfs, r.cwd).promises,
|
|
5450
|
-
path: () =>
|
|
5451
|
-
os: () =>
|
|
5278
|
+
path: () => Gs,
|
|
5279
|
+
os: () => Zs(r.env),
|
|
5452
5280
|
process: () => le({
|
|
5453
5281
|
argv: r.argv,
|
|
5454
5282
|
env: r.env,
|
|
@@ -5457,15 +5285,15 @@ function We(r) {
|
|
|
5457
5285
|
stderr: r.stderr
|
|
5458
5286
|
}),
|
|
5459
5287
|
events: () => ({ EventEmitter: q, default: q }),
|
|
5460
|
-
buffer: () => ({ Buffer:
|
|
5461
|
-
util: () =>
|
|
5288
|
+
buffer: () => ({ Buffer: A }),
|
|
5289
|
+
util: () => Xs,
|
|
5462
5290
|
http: () => Me(r.portRegistry),
|
|
5463
5291
|
https: () => Me(r.portRegistry),
|
|
5464
|
-
child_process: () =>
|
|
5465
|
-
stream: () =>
|
|
5466
|
-
url: () =>
|
|
5467
|
-
timers: () =>
|
|
5468
|
-
crypto: () =>
|
|
5292
|
+
child_process: () => Qs(r.executeCapture),
|
|
5293
|
+
stream: () => er,
|
|
5294
|
+
url: () => ir,
|
|
5295
|
+
timers: () => or,
|
|
5296
|
+
crypto: () => cr,
|
|
5469
5297
|
querystring: () => ({
|
|
5470
5298
|
parse: (e) => Object.fromEntries(new URLSearchParams(e)),
|
|
5471
5299
|
stringify: (e) => new URLSearchParams(e).toString(),
|
|
@@ -5574,11 +5402,11 @@ function qe(r, e) {
|
|
|
5574
5402
|
}
|
|
5575
5403
|
};
|
|
5576
5404
|
}
|
|
5577
|
-
const
|
|
5578
|
-
function
|
|
5405
|
+
const lr = "v20.0.0";
|
|
5406
|
+
function bt(r) {
|
|
5579
5407
|
return async (e) => {
|
|
5580
5408
|
if (e.args.length > 0 && (e.args[0] === "-v" || e.args[0] === "--version"))
|
|
5581
|
-
return e.stdout.write(
|
|
5409
|
+
return e.stdout.write(lr + `
|
|
5582
5410
|
`), 0;
|
|
5583
5411
|
if (e.args.length > 0 && e.args[0] === "--help")
|
|
5584
5412
|
return e.stdout.write(`Usage: node [-e code] [script.js] [args...]
|
|
@@ -5635,13 +5463,13 @@ function xt(r) {
|
|
|
5635
5463
|
if (w.startsWith("./") || w.startsWith("../") || w.startsWith("/")) {
|
|
5636
5464
|
const x = f(w, n);
|
|
5637
5465
|
if (x) {
|
|
5638
|
-
const
|
|
5639
|
-
if (
|
|
5466
|
+
const R = c.get(x.path);
|
|
5467
|
+
if (R) return R;
|
|
5640
5468
|
if (x.path.endsWith(".json")) {
|
|
5641
5469
|
const U = e.vfs.readFileString(x.path), H = JSON.parse(U);
|
|
5642
5470
|
return c.set(x.path, H), H;
|
|
5643
5471
|
}
|
|
5644
|
-
const
|
|
5472
|
+
const P = e.vfs.readFileString(x.path), j = h(P, x.path);
|
|
5645
5473
|
return c.set(x.path, j), j;
|
|
5646
5474
|
}
|
|
5647
5475
|
throw new Error(`Cannot find module '${w}'`);
|
|
@@ -5650,8 +5478,8 @@ function xt(r) {
|
|
|
5650
5478
|
if (e.vfs.exists($)) {
|
|
5651
5479
|
const x = c.get($);
|
|
5652
5480
|
if (x) return x;
|
|
5653
|
-
const
|
|
5654
|
-
return c.set($,
|
|
5481
|
+
const R = e.vfs.readFileString($), P = h(R, $);
|
|
5482
|
+
return c.set($, P), P;
|
|
5655
5483
|
}
|
|
5656
5484
|
throw new Error(`Cannot find module '${w}'`);
|
|
5657
5485
|
}
|
|
@@ -5660,14 +5488,14 @@ function xt(r) {
|
|
|
5660
5488
|
if (e.vfs.exists(x))
|
|
5661
5489
|
try {
|
|
5662
5490
|
if (e.vfs.stat(x).type === "file") return { path: x };
|
|
5663
|
-
const
|
|
5664
|
-
if (e.vfs.exists(
|
|
5491
|
+
const P = ue(x, "index.js");
|
|
5492
|
+
if (e.vfs.exists(P)) return { path: P };
|
|
5665
5493
|
} catch {
|
|
5666
5494
|
}
|
|
5667
5495
|
return !Q(x) && e.vfs.exists(x + ".js") ? { path: x + ".js" } : !Q(x) && e.vfs.exists(x + ".json") ? { path: x + ".json" } : null;
|
|
5668
5496
|
}
|
|
5669
|
-
function
|
|
5670
|
-
const x = G($),
|
|
5497
|
+
function h(w, $) {
|
|
5498
|
+
const x = G($), R = { exports: {} }, P = R.exports, j = { ...o }, U = We(j), H = le({
|
|
5671
5499
|
argv: o.argv,
|
|
5672
5500
|
env: o.env,
|
|
5673
5501
|
cwd: o.cwd,
|
|
@@ -5687,65 +5515,65 @@ function xt(r) {
|
|
|
5687
5515
|
const Z = c.get(T.path);
|
|
5688
5516
|
if (Z) return Z;
|
|
5689
5517
|
if (T.path.endsWith(".json")) {
|
|
5690
|
-
const
|
|
5518
|
+
const Ct = e.vfs.readFileString(T.path), be = JSON.parse(Ct);
|
|
5691
5519
|
return c.set(T.path, be), be;
|
|
5692
5520
|
}
|
|
5693
|
-
const
|
|
5521
|
+
const Et = e.vfs.readFileString(T.path), ve = h(Et, T.path);
|
|
5694
5522
|
return c.set(T.path, ve), ve;
|
|
5695
5523
|
}
|
|
5696
5524
|
throw new Error(`Cannot find module '${b}'`);
|
|
5697
5525
|
}
|
|
5698
5526
|
return l(b);
|
|
5699
5527
|
}
|
|
5700
|
-
const
|
|
5528
|
+
const m = `(function(exports, require, module, __filename, __dirname, console, process, Buffer, setTimeout, setInterval, clearTimeout, clearInterval, global) {
|
|
5701
5529
|
${w}
|
|
5702
|
-
})`, d = new Function("return " +
|
|
5530
|
+
})`, d = new Function("return " + m)(), v = {};
|
|
5703
5531
|
return d(
|
|
5704
|
-
|
|
5532
|
+
P,
|
|
5705
5533
|
ye,
|
|
5706
|
-
|
|
5534
|
+
R,
|
|
5707
5535
|
$,
|
|
5708
5536
|
x,
|
|
5709
5537
|
we,
|
|
5710
5538
|
H,
|
|
5711
|
-
|
|
5539
|
+
A,
|
|
5712
5540
|
globalThis.setTimeout,
|
|
5713
5541
|
globalThis.setInterval,
|
|
5714
5542
|
globalThis.clearTimeout,
|
|
5715
5543
|
globalThis.clearInterval,
|
|
5716
5544
|
v
|
|
5717
|
-
),
|
|
5545
|
+
), R.exports;
|
|
5718
5546
|
}
|
|
5719
|
-
const
|
|
5547
|
+
const p = le({
|
|
5720
5548
|
argv: o.argv,
|
|
5721
5549
|
env: o.env,
|
|
5722
5550
|
cwd: o.cwd,
|
|
5723
5551
|
stdout: e.stdout,
|
|
5724
5552
|
stderr: e.stderr
|
|
5725
|
-
}), y = qe(e.stdout, e.stderr), E = { exports: {} },
|
|
5553
|
+
}), y = qe(e.stdout, e.stderr), E = { exports: {} }, _ = E.exports, L = {}, S = `(function(exports, require, module, __filename, __dirname, console, process, Buffer, setTimeout, setInterval, clearTimeout, clearInterval, global) {
|
|
5726
5554
|
${t}
|
|
5727
5555
|
})`;
|
|
5728
5556
|
try {
|
|
5729
5557
|
new Function("return " + S)()(
|
|
5730
|
-
|
|
5558
|
+
_,
|
|
5731
5559
|
l,
|
|
5732
5560
|
E,
|
|
5733
5561
|
s,
|
|
5734
5562
|
n,
|
|
5735
5563
|
y,
|
|
5736
|
-
|
|
5737
|
-
|
|
5564
|
+
p,
|
|
5565
|
+
A,
|
|
5738
5566
|
globalThis.setTimeout,
|
|
5739
5567
|
globalThis.setInterval,
|
|
5740
5568
|
globalThis.clearTimeout,
|
|
5741
5569
|
globalThis.clearInterval,
|
|
5742
|
-
|
|
5570
|
+
L
|
|
5743
5571
|
);
|
|
5744
|
-
const $ = c.get("http"), x = $ == null ? void 0 : $[
|
|
5572
|
+
const $ = c.get("http"), x = $ == null ? void 0 : $[ot];
|
|
5745
5573
|
if (x && x.length > 0) {
|
|
5746
|
-
const
|
|
5747
|
-
if (
|
|
5748
|
-
const
|
|
5574
|
+
const R = x.map((P) => P.getPromise()).filter((P) => P !== null);
|
|
5575
|
+
if (R.length > 0) {
|
|
5576
|
+
const P = new Promise((j) => {
|
|
5749
5577
|
if (e.signal.aborted) {
|
|
5750
5578
|
j();
|
|
5751
5579
|
return;
|
|
@@ -5753,8 +5581,8 @@ ${t}
|
|
|
5753
5581
|
e.signal.addEventListener("abort", () => j(), { once: !0 });
|
|
5754
5582
|
});
|
|
5755
5583
|
if (await Promise.race([
|
|
5756
|
-
Promise.all(
|
|
5757
|
-
|
|
5584
|
+
Promise.all(R),
|
|
5585
|
+
P
|
|
5758
5586
|
]), e.signal.aborted)
|
|
5759
5587
|
for (const j of [...x])
|
|
5760
5588
|
j.close();
|
|
@@ -5762,42 +5590,42 @@ ${t}
|
|
|
5762
5590
|
}
|
|
5763
5591
|
return 0;
|
|
5764
5592
|
} catch (w) {
|
|
5765
|
-
return w instanceof
|
|
5593
|
+
return w instanceof et ? w.exitCode : (w instanceof Error ? e.stderr.write(`${w.stack || w.message}
|
|
5766
5594
|
`) : e.stderr.write(`${String(w)}
|
|
5767
5595
|
`), 1);
|
|
5768
5596
|
}
|
|
5769
5597
|
};
|
|
5770
5598
|
}
|
|
5771
|
-
function
|
|
5772
|
-
return
|
|
5599
|
+
function $t(r) {
|
|
5600
|
+
return bt(r);
|
|
5773
5601
|
}
|
|
5774
|
-
const
|
|
5602
|
+
const hr = bt(), ge = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5775
5603
|
__proto__: null,
|
|
5776
|
-
createNodeCommand:
|
|
5777
|
-
default:
|
|
5604
|
+
createNodeCommand: $t,
|
|
5605
|
+
default: hr
|
|
5778
5606
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
5779
|
-
function
|
|
5607
|
+
function xt(r) {
|
|
5780
5608
|
return async (e) => {
|
|
5781
5609
|
let t = "GET";
|
|
5782
5610
|
const s = {};
|
|
5783
5611
|
let i, n, o = !1, a = !1, c = !1, l;
|
|
5784
5612
|
const f = e.args;
|
|
5785
|
-
for (let
|
|
5786
|
-
const
|
|
5787
|
-
switch (
|
|
5613
|
+
for (let h = 0; h < f.length; h++) {
|
|
5614
|
+
const p = f[h];
|
|
5615
|
+
switch (p) {
|
|
5788
5616
|
case "-X":
|
|
5789
|
-
t = f[++
|
|
5617
|
+
t = f[++h] ?? "GET";
|
|
5790
5618
|
break;
|
|
5791
5619
|
case "-H": {
|
|
5792
|
-
const y = f[++
|
|
5620
|
+
const y = f[++h] ?? "", E = y.indexOf(":");
|
|
5793
5621
|
E !== -1 && (s[y.slice(0, E).trim()] = y.slice(E + 1).trim());
|
|
5794
5622
|
break;
|
|
5795
5623
|
}
|
|
5796
5624
|
case "-d":
|
|
5797
|
-
i = f[++
|
|
5625
|
+
i = f[++h] ?? "", t === "GET" && (t = "POST");
|
|
5798
5626
|
break;
|
|
5799
5627
|
case "-o":
|
|
5800
|
-
n = f[++
|
|
5628
|
+
n = f[++h] ?? "";
|
|
5801
5629
|
break;
|
|
5802
5630
|
case "-s":
|
|
5803
5631
|
case "--silent":
|
|
@@ -5812,7 +5640,7 @@ function St(r) {
|
|
|
5812
5640
|
c = !0, t = "HEAD";
|
|
5813
5641
|
break;
|
|
5814
5642
|
default:
|
|
5815
|
-
|
|
5643
|
+
p.startsWith("-") || (l = p);
|
|
5816
5644
|
break;
|
|
5817
5645
|
}
|
|
5818
5646
|
}
|
|
@@ -5822,27 +5650,27 @@ function St(r) {
|
|
|
5822
5650
|
`), 1;
|
|
5823
5651
|
if (!l.startsWith("http://") && !l.startsWith("https://") && (l = "https://" + l), r)
|
|
5824
5652
|
try {
|
|
5825
|
-
const
|
|
5826
|
-
if ((
|
|
5827
|
-
const E = r.get(y),
|
|
5653
|
+
const h = new URL(l), p = h.hostname, y = h.port ? Number(h.port) : h.protocol === "http:" ? 80 : 443;
|
|
5654
|
+
if ((p === "localhost" || p === "127.0.0.1") && r.has(y)) {
|
|
5655
|
+
const E = r.get(y), _ = {
|
|
5828
5656
|
method: t,
|
|
5829
|
-
url:
|
|
5657
|
+
url: h.pathname + h.search,
|
|
5830
5658
|
headers: s,
|
|
5831
5659
|
body: i || ""
|
|
5832
|
-
},
|
|
5660
|
+
}, L = {
|
|
5833
5661
|
statusCode: 200,
|
|
5834
5662
|
headers: {},
|
|
5835
5663
|
body: ""
|
|
5836
5664
|
};
|
|
5837
|
-
if (E(
|
|
5838
|
-
e.stdout.write(`HTTP/${
|
|
5665
|
+
if (E(_, L), c) {
|
|
5666
|
+
e.stdout.write(`HTTP/${L.statusCode} OK
|
|
5839
5667
|
`);
|
|
5840
|
-
for (const [w, $] of Object.entries(
|
|
5668
|
+
for (const [w, $] of Object.entries(L.headers))
|
|
5841
5669
|
e.stdout.write(`${w}: ${$}
|
|
5842
5670
|
`);
|
|
5843
5671
|
return 0;
|
|
5844
5672
|
}
|
|
5845
|
-
const S =
|
|
5673
|
+
const S = L.body;
|
|
5846
5674
|
if (n) {
|
|
5847
5675
|
const w = I(e.cwd, n);
|
|
5848
5676
|
e.vfs.writeFile(w, S), o || (e.stderr.write(` % Total % Received
|
|
@@ -5852,25 +5680,25 @@ function St(r) {
|
|
|
5852
5680
|
e.stdout.write(S), S.endsWith(`
|
|
5853
5681
|
`) || e.stdout.write(`
|
|
5854
5682
|
`);
|
|
5855
|
-
return
|
|
5683
|
+
return L.statusCode >= 200 && L.statusCode < 400 ? 0 : 22;
|
|
5856
5684
|
}
|
|
5857
5685
|
} catch {
|
|
5858
5686
|
}
|
|
5859
5687
|
try {
|
|
5860
|
-
const
|
|
5688
|
+
const h = {
|
|
5861
5689
|
method: t,
|
|
5862
5690
|
headers: Object.keys(s).length > 0 ? s : void 0,
|
|
5863
5691
|
body: i,
|
|
5864
5692
|
redirect: a ? "follow" : "manual",
|
|
5865
5693
|
signal: e.signal
|
|
5866
|
-
},
|
|
5694
|
+
}, p = await fetch(l, h);
|
|
5867
5695
|
if (c)
|
|
5868
|
-
return e.stdout.write(`HTTP/${
|
|
5869
|
-
`),
|
|
5870
|
-
e.stdout.write(`${
|
|
5696
|
+
return e.stdout.write(`HTTP/${p.status} ${p.statusText}
|
|
5697
|
+
`), p.headers.forEach((E, _) => {
|
|
5698
|
+
e.stdout.write(`${_}: ${E}
|
|
5871
5699
|
`);
|
|
5872
5700
|
}), 0;
|
|
5873
|
-
const y = await
|
|
5701
|
+
const y = await p.text();
|
|
5874
5702
|
if (n) {
|
|
5875
5703
|
const E = I(e.cwd, n);
|
|
5876
5704
|
e.vfs.writeFile(E, y), o || (e.stderr.write(` % Total % Received
|
|
@@ -5880,149 +5708,303 @@ function St(r) {
|
|
|
5880
5708
|
e.stdout.write(y), y.endsWith(`
|
|
5881
5709
|
`) || e.stdout.write(`
|
|
5882
5710
|
`);
|
|
5883
|
-
return
|
|
5884
|
-
} catch (
|
|
5885
|
-
const
|
|
5886
|
-
return
|
|
5711
|
+
return p.ok ? 0 : 22;
|
|
5712
|
+
} catch (h) {
|
|
5713
|
+
const p = h instanceof Error ? h.message : String(h);
|
|
5714
|
+
return p.includes("Failed to fetch") || p.includes("NetworkError") || p.includes("CORS") ? (e.stderr.write(`curl: (7) Failed to connect to ${l}
|
|
5887
5715
|
`), e.stderr.write(`Note: This may be a CORS restriction. The target server must allow cross-origin requests.
|
|
5888
|
-
`)) : e.stderr.write(`curl: ${
|
|
5716
|
+
`)) : e.stderr.write(`curl: ${p}
|
|
5889
5717
|
`), 7;
|
|
5890
5718
|
}
|
|
5891
5719
|
};
|
|
5892
5720
|
}
|
|
5893
|
-
function
|
|
5894
|
-
return
|
|
5721
|
+
function St(r) {
|
|
5722
|
+
return xt(r);
|
|
5895
5723
|
}
|
|
5896
|
-
const
|
|
5724
|
+
const ur = xt(), dr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5897
5725
|
__proto__: null,
|
|
5898
|
-
createCurlCommand:
|
|
5899
|
-
default:
|
|
5900
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
this.
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5726
|
+
createCurlCommand: St,
|
|
5727
|
+
default: ur
|
|
5728
|
+
}, Symbol.toStringTag, { value: "Module" })), fr = "/usr/share/pkg/packages.json", mr = "/usr/share/pkg/node_modules";
|
|
5729
|
+
function pr(r, e) {
|
|
5730
|
+
let t;
|
|
5731
|
+
try {
|
|
5732
|
+
const s = r.readFileString(fr);
|
|
5733
|
+
t = JSON.parse(s);
|
|
5734
|
+
} catch {
|
|
5735
|
+
return;
|
|
5736
|
+
}
|
|
5737
|
+
for (const s of Object.keys(t.packages)) {
|
|
5738
|
+
const i = `${mr}/${s}/index.js`;
|
|
5739
|
+
r.exists(i) && e.registerLazy(
|
|
5740
|
+
s,
|
|
5741
|
+
() => Promise.resolve().then(() => ge).then((n) => ({
|
|
5742
|
+
default: ((o) => n.default({
|
|
5743
|
+
...o,
|
|
5744
|
+
args: [i, ...o.args]
|
|
5745
|
+
}))
|
|
5746
|
+
}))
|
|
5747
|
+
);
|
|
5748
|
+
}
|
|
5749
|
+
}
|
|
5750
|
+
class gr {
|
|
5751
|
+
constructor(e, t) {
|
|
5752
|
+
this.vfs = e, this.getCwd = t;
|
|
5753
|
+
}
|
|
5754
|
+
resolvePath(e) {
|
|
5755
|
+
return I(this.getCwd(), e);
|
|
5756
|
+
}
|
|
5757
|
+
readFile(e, t) {
|
|
5758
|
+
const s = this.resolvePath(e);
|
|
5759
|
+
return t === null ? Promise.resolve(this.vfs.readFile(s)) : Promise.resolve(this.vfs.readFileString(s));
|
|
5760
|
+
}
|
|
5761
|
+
async writeFile(e, t) {
|
|
5762
|
+
const s = this.resolvePath(e);
|
|
5763
|
+
this.vfs.writeFile(s, t);
|
|
5764
|
+
}
|
|
5765
|
+
async readdir(e) {
|
|
5766
|
+
const t = this.resolvePath(e);
|
|
5767
|
+
return this.vfs.readdir(t);
|
|
5768
|
+
}
|
|
5769
|
+
async stat(e) {
|
|
5770
|
+
const t = this.resolvePath(e), s = this.vfs.stat(t);
|
|
5771
|
+
return { type: s.type, size: s.size, mtime: s.mtime };
|
|
5772
|
+
}
|
|
5773
|
+
async mkdir(e, t) {
|
|
5774
|
+
const s = this.resolvePath(e);
|
|
5775
|
+
this.vfs.mkdir(s, t);
|
|
5776
|
+
}
|
|
5777
|
+
async rm(e, t) {
|
|
5778
|
+
const s = this.resolvePath(e);
|
|
5779
|
+
this.vfs.stat(s).type === "directory" ? t != null && t.recursive ? this.vfs.rmdirRecursive(s) : this.vfs.rmdir(s) : this.vfs.unlink(s);
|
|
5780
|
+
}
|
|
5781
|
+
async exists(e) {
|
|
5782
|
+
const t = this.resolvePath(e);
|
|
5783
|
+
return this.vfs.exists(t);
|
|
5784
|
+
}
|
|
5785
|
+
async rename(e, t) {
|
|
5786
|
+
const s = this.resolvePath(e), i = this.resolvePath(t);
|
|
5787
|
+
this.vfs.rename(s, i);
|
|
5788
|
+
}
|
|
5789
|
+
async cp(e, t) {
|
|
5790
|
+
const s = this.resolvePath(e), i = this.resolvePath(t);
|
|
5791
|
+
this.vfs.copyFile(s, i);
|
|
5792
|
+
}
|
|
5793
|
+
async writeFiles(e) {
|
|
5794
|
+
for (const { path: t, content: s } of e)
|
|
5795
|
+
await this.writeFile(t, s);
|
|
5796
|
+
}
|
|
5797
|
+
}
|
|
5798
|
+
class wr {
|
|
5799
|
+
constructor(e, t) {
|
|
5800
|
+
u(this, "queue", Promise.resolve());
|
|
5801
|
+
this.shell = e, this.registry = t;
|
|
5802
|
+
}
|
|
5803
|
+
run(e, t) {
|
|
5804
|
+
return new Promise((i, n) => {
|
|
5805
|
+
this.queue = this.queue.then(async () => {
|
|
5806
|
+
try {
|
|
5807
|
+
const o = await this.executeWithOptions(e, t);
|
|
5808
|
+
i(o);
|
|
5809
|
+
} catch (o) {
|
|
5810
|
+
n(o);
|
|
5811
|
+
}
|
|
5812
|
+
});
|
|
5813
|
+
});
|
|
5814
|
+
}
|
|
5815
|
+
register(e, t) {
|
|
5816
|
+
this.registry.register(e, t);
|
|
5817
|
+
}
|
|
5818
|
+
async executeWithOptions(e, t) {
|
|
5819
|
+
let s, i;
|
|
5820
|
+
if (t != null && t.timeout || t != null && t.signal) {
|
|
5821
|
+
if (s = new AbortController(), t.signal) {
|
|
5822
|
+
if (t.signal.aborted)
|
|
5823
|
+
return { stdout: "", stderr: "", exitCode: 130 };
|
|
5824
|
+
t.signal.addEventListener("abort", () => s.abort(), { once: !0 });
|
|
5825
|
+
}
|
|
5826
|
+
t.timeout && (i = setTimeout(() => s.abort(), t.timeout));
|
|
5827
|
+
}
|
|
5936
5828
|
try {
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5829
|
+
return await this.shell.execute(e, {
|
|
5830
|
+
cwd: t == null ? void 0 : t.cwd,
|
|
5831
|
+
env: t == null ? void 0 : t.env,
|
|
5832
|
+
onStdout: t == null ? void 0 : t.onStdout,
|
|
5833
|
+
onStderr: t == null ? void 0 : t.onStderr,
|
|
5834
|
+
stdin: t == null ? void 0 : t.stdin
|
|
5835
|
+
});
|
|
5836
|
+
} finally {
|
|
5837
|
+
i !== void 0 && clearTimeout(i);
|
|
5940
5838
|
}
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5839
|
+
}
|
|
5840
|
+
}
|
|
5841
|
+
class yr {
|
|
5842
|
+
constructor() {
|
|
5843
|
+
u(this, "dataCallback", null);
|
|
5944
5844
|
}
|
|
5945
5845
|
write(e) {
|
|
5946
|
-
this.xterm.write(e);
|
|
5947
5846
|
}
|
|
5948
5847
|
writeln(e) {
|
|
5949
|
-
this.xterm.writeln(e);
|
|
5950
5848
|
}
|
|
5951
5849
|
onData(e) {
|
|
5952
|
-
this.
|
|
5850
|
+
this.dataCallback = e;
|
|
5953
5851
|
}
|
|
5954
5852
|
get cols() {
|
|
5955
|
-
return
|
|
5853
|
+
return 80;
|
|
5956
5854
|
}
|
|
5957
5855
|
get rows() {
|
|
5958
|
-
return
|
|
5856
|
+
return 24;
|
|
5959
5857
|
}
|
|
5960
5858
|
focus() {
|
|
5961
|
-
this.xterm.focus();
|
|
5962
5859
|
}
|
|
5963
5860
|
clear() {
|
|
5964
|
-
|
|
5861
|
+
}
|
|
5862
|
+
/** Send data as if typed on keyboard (used internally for stdin) */
|
|
5863
|
+
sendData(e) {
|
|
5864
|
+
var t;
|
|
5865
|
+
(t = this.dataCallback) == null || t.call(this, e);
|
|
5965
5866
|
}
|
|
5966
5867
|
}
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5868
|
+
class kt {
|
|
5869
|
+
constructor(e, t, s, i, n) {
|
|
5870
|
+
/** Programmatic command execution */
|
|
5871
|
+
u(this, "commands");
|
|
5872
|
+
/** Filesystem operations */
|
|
5873
|
+
u(this, "fs");
|
|
5874
|
+
/** Environment variables */
|
|
5875
|
+
u(this, "env");
|
|
5876
|
+
// Power-user escape hatches
|
|
5877
|
+
u(this, "kernel");
|
|
5878
|
+
u(this, "shell");
|
|
5879
|
+
u(this, "_destroyed", !1);
|
|
5880
|
+
this.kernel = e, this.shell = t, this.commands = s, this.fs = i, this.env = n;
|
|
5881
|
+
}
|
|
5882
|
+
/** Current working directory */
|
|
5883
|
+
get cwd() {
|
|
5884
|
+
return this.shell.getCwd();
|
|
5885
|
+
}
|
|
5886
|
+
set cwd(e) {
|
|
5887
|
+
this.shell.setCwd(e);
|
|
5888
|
+
}
|
|
5889
|
+
/**
|
|
5890
|
+
* Create a new Sandbox instance.
|
|
5891
|
+
* Orchestrates all boot steps: Kernel, VFS, Registry, Shell, config sourcing.
|
|
5892
|
+
*/
|
|
5893
|
+
static async create(e) {
|
|
5894
|
+
const t = new Zt();
|
|
5895
|
+
await t.boot({ persist: (e == null ? void 0 : e.persist) ?? !1 });
|
|
5896
|
+
const s = Rs();
|
|
5897
|
+
if (s.register("pkg", Is(s)), pr(t.vfs, s), e != null && e.files)
|
|
5898
|
+
for (const [y, E] of Object.entries(e.files))
|
|
5899
|
+
br(t.vfs, y), t.vfs.writeFile(y, E);
|
|
5900
|
+
const n = { ...t.getDefaultEnv(), ...e == null ? void 0 : e.env };
|
|
5901
|
+
e != null && e.cwd && (n.PWD = e.cwd);
|
|
5902
|
+
let o, a = !1;
|
|
5903
|
+
if (typeof (e == null ? void 0 : e.terminal) == "string" || typeof HTMLElement < "u" && (e == null ? void 0 : e.terminal) instanceof HTMLElement) {
|
|
5904
|
+
const { Terminal: y } = await import("@lifo-sh/ui"), E = vr(e.terminal), _ = new y(E);
|
|
5905
|
+
o = _, a = !0;
|
|
5906
|
+
const L = t.vfs.readFileString("/etc/motd");
|
|
5907
|
+
_.write(L.replace(/\r\n/g, `
|
|
5908
|
+
`).replace(/\n/g, `\r
|
|
5909
|
+
`));
|
|
5910
|
+
} else e != null && e.terminal && typeof e.terminal == "object" ? (o = e.terminal, a = !0) : o = new yr();
|
|
5911
|
+
const c = new Ts(o, t.vfs, s, n), l = c.getJobTable();
|
|
5912
|
+
s.register("ps", Bs(l)), s.register("top", zs(l)), s.register("kill", Ds(l)), s.register("watch", Os(s)), s.register("help", qs()), s.register("node", $t(t.portRegistry)), s.register("curl", St(t.portRegistry)), await c.sourceFile("/etc/profile"), await c.sourceFile(n.HOME + "/.bashrc"), e != null && e.cwd && c.setCwd(e.cwd), a && (c.start(), o.focus());
|
|
5913
|
+
const f = () => c.getCwd(), h = new gr(t.vfs, f), p = new wr(c, s);
|
|
5914
|
+
return new kt(t, c, p, h, n);
|
|
5915
|
+
}
|
|
5916
|
+
/**
|
|
5917
|
+
* Attach a headless sandbox to a DOM element, enabling visual mode.
|
|
5918
|
+
*/
|
|
5919
|
+
async attach(e) {
|
|
5920
|
+
if (this._destroyed) throw new Error("Sandbox is destroyed");
|
|
5921
|
+
const { Terminal: t } = await import("@lifo-sh/ui"), s = new t(e), i = this.kernel.vfs.readFileString("/etc/motd");
|
|
5922
|
+
s.write(i.replace(/\r\n/g, `
|
|
5923
|
+
`).replace(/\n/g, `\r
|
|
5924
|
+
`)), s.focus();
|
|
5925
|
+
}
|
|
5926
|
+
/**
|
|
5927
|
+
* Detach from visual mode.
|
|
5928
|
+
*/
|
|
5929
|
+
detach() {
|
|
5930
|
+
}
|
|
5931
|
+
/**
|
|
5932
|
+
* Destroy the sandbox, releasing all resources.
|
|
5933
|
+
*/
|
|
5934
|
+
destroy() {
|
|
5935
|
+
this._destroyed = !0;
|
|
5936
|
+
}
|
|
5937
|
+
}
|
|
5938
|
+
function vr(r) {
|
|
5939
|
+
if (typeof r == "string") {
|
|
5940
|
+
const e = document.querySelector(r);
|
|
5941
|
+
if (!e) throw new Error(`Sandbox: element not found: ${r}`);
|
|
5942
|
+
return e;
|
|
5943
|
+
}
|
|
5944
|
+
return r;
|
|
5945
|
+
}
|
|
5946
|
+
function br(r, e) {
|
|
5947
|
+
const t = e.split("/").filter(Boolean);
|
|
5948
|
+
t.pop();
|
|
5949
|
+
let s = "";
|
|
5950
|
+
for (const i of t)
|
|
5951
|
+
s += "/" + i, r.exists(s) || r.mkdir(s, { recursive: !0 });
|
|
5952
|
+
}
|
|
5971
5953
|
export {
|
|
5972
|
-
|
|
5954
|
+
Br as $,
|
|
5973
5955
|
We as A,
|
|
5974
5956
|
Y as B,
|
|
5975
|
-
|
|
5976
|
-
|
|
5957
|
+
Kt as C,
|
|
5958
|
+
Jt as D,
|
|
5977
5959
|
C as E,
|
|
5978
|
-
|
|
5960
|
+
$t as F,
|
|
5979
5961
|
oe as G,
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5962
|
+
yr as H,
|
|
5963
|
+
Sr as I,
|
|
5964
|
+
ys as J,
|
|
5965
|
+
Zt as K,
|
|
5966
|
+
Is as L,
|
|
5967
|
+
Qt as M,
|
|
5968
|
+
Bs as N,
|
|
5969
|
+
zs as O,
|
|
5970
|
+
Fs as P,
|
|
5971
|
+
Os as Q,
|
|
5990
5972
|
z as R,
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5973
|
+
kt as S,
|
|
5974
|
+
zr as T,
|
|
5975
|
+
kr as U,
|
|
5994
5976
|
k as V,
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
5977
|
+
Er as W,
|
|
5978
|
+
Dr as X,
|
|
5979
|
+
Xt as Y,
|
|
5980
|
+
Fr as Z,
|
|
5981
|
+
pr as _,
|
|
6000
5982
|
ae as a,
|
|
6001
|
-
|
|
6002
|
-
|
|
5983
|
+
Ar as a0,
|
|
5984
|
+
Ir as a1,
|
|
6003
5985
|
K as b,
|
|
6004
|
-
|
|
5986
|
+
xr as c,
|
|
6005
5987
|
G as d,
|
|
6006
5988
|
Q as e,
|
|
6007
5989
|
ee as f,
|
|
6008
5990
|
M as g,
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
5991
|
+
Rt as h,
|
|
5992
|
+
Tr as i,
|
|
5993
|
+
Rr as j,
|
|
5994
|
+
Lr as k,
|
|
5995
|
+
_r as l,
|
|
5996
|
+
Cr as m,
|
|
5997
|
+
Pr as n,
|
|
5998
|
+
_s as o,
|
|
5999
|
+
et as p,
|
|
6000
|
+
Yt as q,
|
|
6019
6001
|
I as r,
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6002
|
+
Ts as s,
|
|
6003
|
+
At as t,
|
|
6004
|
+
Nr as u,
|
|
6005
|
+
jr as v,
|
|
6006
|
+
St as w,
|
|
6007
|
+
Rs as x,
|
|
6008
|
+
qs as y,
|
|
6009
|
+
Ds as z
|
|
6028
6010
|
};
|