brsh 2.7.0 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/Readme.md +33 -16
- package/bin/brsh-shell.js +15 -1
- package/dist/shell.es.js +243 -109
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +7 -7
- package/dist/shell.min.js.map +1 -1
- package/dist/terminal.cjs.js +101 -0
- package/dist/terminal.cjs.js.map +1 -0
- package/dist/terminal.es.js +290 -8107
- package/dist/terminal.es.js.map +1 -1
- package/dist/terminal.min.js +4 -32
- package/dist/terminal.min.js.map +1 -1
- package/dist/wbt.es.js +1619 -6133
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +6 -20
- package/dist/wbt.min.js.map +1 -1
- package/index.js +29 -0
- package/lib/BaseFileSystem.js +40 -0
- package/lib/BinaryContainer.js +1 -1
- package/lib/FileSystem.js +1 -38
- package/lib/NodeFileSystem.js +4 -2
- package/lib/Terminal.js +45 -10
- package/lib/WasmCommand.js +168 -18
- package/lib/local/curl.js +60 -2
- package/lib/wbt/index.js +297 -64
- package/lib/wbt/packages/wllama.js +1061 -0
- package/lib/wbt/registry.js +31 -19
- package/package.json +3 -2
- package/test/curl.test.js +166 -0
- package/test/terminal.test.js +113 -0
- package/test/wasm-cli.test.js +127 -0
- package/test/wbt.test.js +342 -232
- package/vite.config.terminal.js +16 -12
- package/vitest.config.js +6 -0
- package/lib/wbt/daemon.js +0 -264
- package/lib/wbt/packages/pglite.js +0 -590
package/dist/shell.es.js
CHANGED
|
@@ -807,6 +807,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
807
807
|
}
|
|
808
808
|
})(u), y = u.Buffer, u.Blob, u.BlobOptions, u.Buffer, u.File, u.FileOptions, u.INSPECT_MAX_BYTES, u.SlowBuffer, u.TranscodeEncoding, u.atob, u.btoa, u.constants, u.isAscii, u.isUtf8, u.kMaxLength, u.kStringMaxLength, u.resolveObjectURL, u.transcode;
|
|
809
809
|
})), x = /* @__PURE__ */ t(((e, t) => {
|
|
810
|
+
b();
|
|
810
811
|
var n = new Set([
|
|
811
812
|
"getFileByPath",
|
|
812
813
|
"setFileByPath",
|
|
@@ -825,8 +826,7 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
825
826
|
"isSymlink",
|
|
826
827
|
"readSymlink",
|
|
827
828
|
"createSymlink"
|
|
828
|
-
])
|
|
829
|
-
t.exports = class {
|
|
829
|
+
]), r = class {
|
|
830
830
|
isReadable(e) {
|
|
831
831
|
let t = this.getMode(e);
|
|
832
832
|
return t === null ? !1 : (t & 256) != 0;
|
|
@@ -860,7 +860,27 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
860
860
|
this._changeScheduled = !1, typeof this._onChange == "function" && this._onChange(this.getRaw(), this.getRawPermissions());
|
|
861
861
|
}));
|
|
862
862
|
}
|
|
863
|
+
}, i = class extends Uint8Array {
|
|
864
|
+
constructor(e, t) {
|
|
865
|
+
super(e), Object.defineProperty(this, "mimeType", {
|
|
866
|
+
value: t,
|
|
867
|
+
enumerable: !1,
|
|
868
|
+
configurable: !1,
|
|
869
|
+
writable: !1
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
toString() {
|
|
873
|
+
if (y !== void 0) return `data:${this.mimeType};base64,${y.from(this).toString("base64")}`;
|
|
874
|
+
let e = "", t = 8192;
|
|
875
|
+
for (let n = 0; n < this.length; n += t) e += String.fromCharCode(...this.subarray(n, n + t));
|
|
876
|
+
return `data:${this.mimeType};base64,${btoa(e)}`;
|
|
877
|
+
}
|
|
878
|
+
}, a = class {
|
|
879
|
+
constructor(e) {
|
|
880
|
+
this.target = e;
|
|
881
|
+
}
|
|
863
882
|
};
|
|
883
|
+
t.exports = r, t.exports.BinaryFile = i, t.exports.SymlinkRef = a;
|
|
864
884
|
}));
|
|
865
885
|
//#endregion
|
|
866
886
|
//#region node_modules/vite-plugin-node-polyfills/shims/process/dist/index.js
|
|
@@ -1204,7 +1224,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1204
1224
|
};
|
|
1205
1225
|
})), re = /* @__PURE__ */ t(((e, t) => {
|
|
1206
1226
|
b(), B();
|
|
1207
|
-
var { BinaryFile: n, SymlinkRef: r } =
|
|
1227
|
+
var { BinaryFile: n, SymlinkRef: r } = x(), i = new Uint8Array([
|
|
1208
1228
|
66,
|
|
1209
1229
|
82,
|
|
1210
1230
|
70,
|
|
@@ -1475,26 +1495,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1475
1495
|
};
|
|
1476
1496
|
})), ie = /* @__PURE__ */ t(((e, t) => {
|
|
1477
1497
|
b();
|
|
1478
|
-
var n = x(), r
|
|
1479
|
-
constructor(e, t) {
|
|
1480
|
-
super(e), Object.defineProperty(this, "mimeType", {
|
|
1481
|
-
value: t,
|
|
1482
|
-
enumerable: !1,
|
|
1483
|
-
configurable: !1,
|
|
1484
|
-
writable: !1
|
|
1485
|
-
});
|
|
1486
|
-
}
|
|
1487
|
-
toString() {
|
|
1488
|
-
if (y !== void 0) return `data:${this.mimeType};base64,${y.from(this).toString("base64")}`;
|
|
1489
|
-
let e = "", t = 8192;
|
|
1490
|
-
for (let n = 0; n < this.length; n += t) e += String.fromCharCode(...this.subarray(n, n + t));
|
|
1491
|
-
return `data:${this.mimeType};base64,${btoa(e)}`;
|
|
1492
|
-
}
|
|
1493
|
-
}, i = class {
|
|
1494
|
-
constructor(e) {
|
|
1495
|
-
this.target = e;
|
|
1496
|
-
}
|
|
1497
|
-
};
|
|
1498
|
+
var n = x(), { BinaryFile: r, SymlinkRef: i } = n;
|
|
1498
1499
|
function a(e) {
|
|
1499
1500
|
for (let t of Object.keys(e)) {
|
|
1500
1501
|
let n = e[t];
|
|
@@ -1972,7 +1973,9 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
1972
1973
|
}
|
|
1973
1974
|
setMode(e, t) {
|
|
1974
1975
|
let r = this.absolutePath(e);
|
|
1975
|
-
this._virtualFiles[r] === void 0
|
|
1976
|
+
if (this._virtualFiles[r] === void 0) try {
|
|
1977
|
+
n.chmodSync(r, t), this._triggerChange();
|
|
1978
|
+
} catch {}
|
|
1976
1979
|
}
|
|
1977
1980
|
getSize(e) {
|
|
1978
1981
|
let t = this.absolutePath(e);
|
|
@@ -2960,9 +2963,7 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
2960
2963
|
if (e.isRealFilesystem) try {
|
|
2961
2964
|
let n = W();
|
|
2962
2965
|
return new Uint8Array(n.readFileSync(e.absolutePath(t)));
|
|
2963
|
-
} catch {
|
|
2964
|
-
return null;
|
|
2965
|
-
}
|
|
2966
|
+
} catch {}
|
|
2966
2967
|
let n = e.getFileByPath(t);
|
|
2967
2968
|
if (n == null) return null;
|
|
2968
2969
|
if (n instanceof Uint8Array || y !== void 0 && y.isBuffer(n)) return new Uint8Array(n.buffer, n.byteOffset, n.byteLength);
|
|
@@ -2985,15 +2986,23 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
2985
2986
|
return null;
|
|
2986
2987
|
}
|
|
2987
2988
|
function E(e, t, n, i = "application/octet-stream") {
|
|
2988
|
-
let a = n instanceof Uint8Array ? n : new Uint8Array(n);
|
|
2989
|
-
|
|
2989
|
+
let a = n instanceof Uint8Array ? n : new Uint8Array(n), o = new Uint8Array(a.byteLength);
|
|
2990
|
+
o.set(a);
|
|
2991
|
+
let s = new r(o.buffer, i);
|
|
2992
|
+
if (e.isRealFilesystem) try {
|
|
2990
2993
|
let n = W(), r = ae(), i = e.absolutePath(t);
|
|
2991
2994
|
n.mkdirSync(r.dirname(i), { recursive: !0 }), n.writeFileSync(i, y.from(a.buffer, a.byteOffset, a.byteLength));
|
|
2992
2995
|
return;
|
|
2996
|
+
} catch {
|
|
2997
|
+
if (typeof e._setFileRaw == "function") {
|
|
2998
|
+
e._setFileRaw(t, s, !0);
|
|
2999
|
+
return;
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
if (typeof e._setFileRaw == "function" && t.startsWith("/var/lib/wbt/")) {
|
|
3003
|
+
e._setFileRaw(t, s, !0);
|
|
3004
|
+
return;
|
|
2993
3005
|
}
|
|
2994
|
-
let o = new Uint8Array(a.byteLength);
|
|
2995
|
-
o.set(a);
|
|
2996
|
-
let s = new r(o.buffer, i);
|
|
2997
3006
|
e.setFileByPath(t, s, !0);
|
|
2998
3007
|
}
|
|
2999
3008
|
async function D(e, t, n = null) {
|
|
@@ -3014,6 +3023,12 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3014
3023
|
t
|
|
3015
3024
|
);
|
|
3016
3025
|
} catch (n) {
|
|
3026
|
+
if (!/^https?:\/\/esm\.sh\//i.test(t)) try {
|
|
3027
|
+
return await import(
|
|
3028
|
+
/* @vite-ignore */
|
|
3029
|
+
`https://esm.sh/${e}`
|
|
3030
|
+
);
|
|
3031
|
+
} catch {}
|
|
3017
3032
|
throw Error(`Failed to load WASM package '${e}' from ${t}: ${n.message || n}`);
|
|
3018
3033
|
}
|
|
3019
3034
|
throw Error(`Package '${e}' could not be loaded`);
|
|
@@ -3024,8 +3039,11 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3024
3039
|
options: []
|
|
3025
3040
|
};
|
|
3026
3041
|
if (!e || typeof e != "string") return n;
|
|
3027
|
-
let r = e.split(/\r?\n/).map((e) => e.trim()).filter(Boolean), i = /* @__PURE__ */ new Set();
|
|
3028
|
-
for (let e
|
|
3042
|
+
let r = e.split(/\r?\n/).map((e) => e.trim()).filter(Boolean), i = /* @__PURE__ */ new Set(), a = t ? r.findIndex((e) => /^usage:\s*(.+)/i.test(e)) : -1, o = a >= 0 ? a : 0;
|
|
3043
|
+
for (let e = o; e < r.length; e++) {
|
|
3044
|
+
let a = r[e];
|
|
3045
|
+
!n.usage && /^usage:\s*(.+)/i.test(a) ? n.usage = a.replace(/^usage:\s*/i, "").trim() : /^(?:-[a-zA-Z0-9?]|--[a-zA-Z0-9][-a-zA-Z0-9]*)(?:\s|,|=|<|\[|$)/.test(a) && a.length <= 120 && !/^(?:-[hHvV],\s*)?--(?:help|version)\b/i.test(a) && (!t || /^(?:-[a-zA-Z?]|--[a-zA-Z][a-zA-Z0-9-]*)(?:,\s*--?[a-zA-Z0-9-]+)?(?:\s+[<\[a-zA-Z0-9_.->\]]+)*(?:\s+[A-Za-z`'"(][A-Za-z0-9 ,.;:()'"`/<>\[\]=+$\t_-]*|)$/.test(a)) && (i.has(a) || (i.add(a), n.options.push(a)));
|
|
3046
|
+
}
|
|
3029
3047
|
if (t && n.options.length === 0) {
|
|
3030
3048
|
let t = e.match(/--[a-z][a-z0-9-]{1,24}/g) || [];
|
|
3031
3049
|
for (let e of Array.from(new Set(t)).slice(0, 12)) e !== "--help" && e !== "--version" && n.options.push(e);
|
|
@@ -3059,12 +3077,12 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3059
3077
|
return t;
|
|
3060
3078
|
}
|
|
3061
3079
|
function A(e, t = {}, n = null) {
|
|
3062
|
-
let r = t.name || e, i = t.version || "wasm", a = t.description || "WebAssembly binary", o = t && typeof t.repl == "object" ? t.repl : t.repl ? {} : null, s = n && n.usage || t.usage, c = o ? `${e} [options] ${o.evalFlag ? `[${o.evalFlag} <code>] ` : ""}[file] [args...]` : `${e} [options] [args...]`,
|
|
3063
|
-
t.details &&
|
|
3064
|
-
let
|
|
3065
|
-
if (
|
|
3066
|
-
else o && (o.evalFlag &&
|
|
3067
|
-
return
|
|
3080
|
+
let r = t.name || e, i = t.version || "wasm", a = t.description || "WebAssembly binary", o = t && typeof t.repl == "object" ? t.repl : t.repl ? {} : null, s = n && n.usage || t.usage, c = s ? s.replace(/%s/g, e) : null, l = o ? `${e} [options] ${o.evalFlag ? `[${o.evalFlag} <code>] ` : ""}[file] [args...]` : `${e} [options] [args...]`, u = [`${e} (${r} ${i} wasm) — ${a}`, `Usage: ${c || l}`];
|
|
3081
|
+
t.details && u.push("", t.details), u.push("", "Options:");
|
|
3082
|
+
let d = n && n.options && n.options.length > 0 ? n.options : Array.isArray(t.options) ? t.options : [];
|
|
3083
|
+
if (d.length > 0) for (let e of d) u.push(` ${e}`);
|
|
3084
|
+
else o && (o.evalFlag && u.push(` ${o.evalFlag.padEnd(20)}Evaluate inline code and print result`), u.push(` (no arguments) Start interactive ${e} REPL shell`));
|
|
3085
|
+
return u.push(" -h, --help Show this help message and exit"), u.push(" -V, --version Show WebAssembly binary version and exit"), n && n.exports && n.exports.length > 0 && u.push("", `WASM Exports: ${n.exports.join(", ")}`), Array.isArray(t.aliases) && t.aliases.length > 0 && u.push("", `Aliases: ${t.aliases.join(", ")}`), (t.homepage || t.cdnUrl || t.wasmUrl) && u.push(`Source: ${t.homepage || t.cdnUrl || t.wasmUrl}`), u;
|
|
3068
3086
|
}
|
|
3069
3087
|
function j(e, t = {}, n = null) {
|
|
3070
3088
|
let r = K(), i = (n || e.bin || e.name).toLowerCase();
|
|
@@ -3080,25 +3098,46 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3080
3098
|
}
|
|
3081
3099
|
async run() {
|
|
3082
3100
|
let n = [...this.arguments || []], r = n.includes("--help") || n.includes("-h"), a = !r && (n.includes("--version") || n.includes("-V") || n.includes("-v"));
|
|
3083
|
-
this._inspectedWasm = null;
|
|
3101
|
+
this._inspectedWasm = null, this._persistedWasmBytes = e.wasmPath ? T(this.context && this.context.fs || this.fs, e.wasmPath) : null, r && this._persistedWasmBytes && this._persistedWasmBytes.byteLength > 0 && (this._inspectedWasm = k(this._persistedWasmBytes));
|
|
3084
3102
|
try {
|
|
3085
|
-
if (e.type === "wasm" && e.wasmUrl && !t.moduleLoader) {
|
|
3086
|
-
let t = await this._fetchWasmBytes(e.wasmUrl);
|
|
3103
|
+
if (e.type === "wasm" && (this._persistedWasmBytes || e.wasmUrl) && !t.moduleLoader) {
|
|
3104
|
+
let t = this._persistedWasmBytes || await this._fetchWasmBytes(e.wasmUrl);
|
|
3087
3105
|
r && (this._inspectedWasm = k(t)), await this._runRawWasmBytes(t, n);
|
|
3088
3106
|
} else {
|
|
3089
|
-
let o = e.cdnUrl || e.wasmUrl || `https://esm.sh/${e.name}`, s =
|
|
3090
|
-
if (
|
|
3091
|
-
let
|
|
3107
|
+
let o = e.cdnUrl || e.wasmUrl || `https://esm.sh/${e.name}`, s = typeof globalThis.fetch == "function" ? globalThis.fetch : null;
|
|
3108
|
+
if (s && this._persistedWasmBytes && this._persistedWasmBytes.byteLength > 0 && typeof Response < "u") {
|
|
3109
|
+
let t = this._persistedWasmBytes, n = e.wasmUrl || "";
|
|
3110
|
+
globalThis.fetch = async (e, r) => {
|
|
3111
|
+
let i = typeof e == "string" ? e : e && e.url ? e.url : "";
|
|
3112
|
+
return i && (i === n || !/^https?:\/\//i.test(i) && /\.wasm(\?.*)?$/i.test(i)) ? new Response(t, {
|
|
3113
|
+
status: 200,
|
|
3114
|
+
headers: { "Content-Type": "application/wasm" }
|
|
3115
|
+
}) : s(e, r);
|
|
3116
|
+
};
|
|
3117
|
+
}
|
|
3118
|
+
let c, l;
|
|
3119
|
+
try {
|
|
3120
|
+
c = await D(e.name, o, t.moduleLoader), l = c && c.default !== void 0 ? c.default : c, l && typeof l.then == "function" && (l = await l);
|
|
3121
|
+
} finally {
|
|
3122
|
+
s && (globalThis.fetch = s);
|
|
3123
|
+
}
|
|
3124
|
+
if (l instanceof Uint8Array || l instanceof ArrayBuffer) {
|
|
3125
|
+
let e = l instanceof Uint8Array ? l : new Uint8Array(l);
|
|
3092
3126
|
r && (this._inspectedWasm = k(e)), await this._runRawWasmBytes(e, n);
|
|
3093
|
-
} else if (
|
|
3094
|
-
let e =
|
|
3127
|
+
} else if (l && (l.wasmBytes instanceof Uint8Array || l.wasm instanceof Uint8Array)) {
|
|
3128
|
+
let e = l.wasmBytes || l.wasm;
|
|
3095
3129
|
r && (this._inspectedWasm = k(e)), await this._runRawWasmBytes(e, n);
|
|
3096
|
-
} else if (typeof
|
|
3097
|
-
else if (
|
|
3098
|
-
|
|
3099
|
-
let t =
|
|
3100
|
-
if (typeof t == "function") await this._invokeCliFunction(t.bind(
|
|
3101
|
-
else if (
|
|
3130
|
+
} else if (typeof l == "function") await this._runFunctionOrEmscripten(l, n, r);
|
|
3131
|
+
else if (l && typeof l == "object") {
|
|
3132
|
+
l.ready && await l.ready, r && (l.HEAPU8 instanceof Uint8Array || l.wasmBinary instanceof Uint8Array) && (this._inspectedWasm = k(l.wasmBinary || l.HEAPU8));
|
|
3133
|
+
let t = l.main || l.run || l.callMain || l.exec;
|
|
3134
|
+
if (typeof t == "function") await this._invokeCliFunction(t.bind(l), n);
|
|
3135
|
+
else if (l.promised || typeof l.raw == "function" || typeof l.json == "function") {
|
|
3136
|
+
let e = l.promised ? await l.promised : l, t = n.filter((e) => e.startsWith("-")), i = n.filter((e) => !e.startsWith("-")), o = i.shift() || ".", s = this._createIoBridge(n, [], []), c = i.length > 0 ? s.readFile(i[0]) || "" : s.stdin || (r || a ? "{}" : ""), u = typeof e.raw == "function" ? e.raw(c, o, t) : !r && !a ? JSON.stringify(e.json(JSON.parse(c || "null"), o)) : null;
|
|
3137
|
+
u != null && String(u).replace(/\r?\n$/, "").split(/\r?\n/).forEach((e) => {
|
|
3138
|
+
this.stdOut = e;
|
|
3139
|
+
});
|
|
3140
|
+
} else if (!r && !a) {
|
|
3102
3141
|
this.stdErr = `${i}: unsupported WASM module format for '${e.name}'`, this.exitCode = 1;
|
|
3103
3142
|
return;
|
|
3104
3143
|
}
|
|
@@ -3145,18 +3184,20 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3145
3184
|
for (let e of r.result.getStdOutput()) e.type === "out" ? this.stdOut = e.string : e.type === "err" && (this.stdErr = e.string);
|
|
3146
3185
|
this.exitCode = r.result.getExitCode();
|
|
3147
3186
|
}
|
|
3148
|
-
_createIoBridge(
|
|
3149
|
-
let
|
|
3187
|
+
_createIoBridge(t, n, r) {
|
|
3188
|
+
let a = (e) => ({ write(t) {
|
|
3150
3189
|
(t instanceof Uint8Array ? new TextDecoder().decode(t) : String(t ?? "")).replace(/\r?\n$/, "").split(/\r?\n/).forEach((t) => e.push(t));
|
|
3151
3190
|
} });
|
|
3152
3191
|
return {
|
|
3153
3192
|
binName: i,
|
|
3154
|
-
args:
|
|
3193
|
+
args: t,
|
|
3155
3194
|
stdin: this.stdin !== void 0 && this.stdin !== null ? String(this.stdin) : "",
|
|
3156
3195
|
fs: this.fs,
|
|
3157
3196
|
context: this.context,
|
|
3158
|
-
|
|
3159
|
-
|
|
3197
|
+
wasmPath: e.wasmPath || null,
|
|
3198
|
+
wasmBytes: this._persistedWasmBytes || null,
|
|
3199
|
+
stdout: Object.assign((e) => n.push(String(e)), a(n)),
|
|
3200
|
+
stderr: Object.assign((e) => r.push(String(e)), a(r)),
|
|
3160
3201
|
readFile: (e, t) => {
|
|
3161
3202
|
if (!this.fs) return null;
|
|
3162
3203
|
let n = t && t !== "." && !e.startsWith("/") ? `${t.replace(/\/+$/, "")}/${e}` : e, r = this.fs.getFileByPath(n) ?? this.fs.getFileByPath(e);
|
|
@@ -3181,48 +3222,86 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
3181
3222
|
}
|
|
3182
3223
|
};
|
|
3183
3224
|
}
|
|
3184
|
-
async _runFunctionOrEmscripten(
|
|
3185
|
-
let
|
|
3186
|
-
arguments:
|
|
3225
|
+
async _runFunctionOrEmscripten(t, n, r = !1) {
|
|
3226
|
+
let i = [], a = [], o = new TextEncoder().encode(this.stdin || ""), s = 0, c = /* @__PURE__ */ new Set(), l = {
|
|
3227
|
+
arguments: n,
|
|
3187
3228
|
noInitialRun: !0,
|
|
3229
|
+
...this._persistedWasmBytes && this._persistedWasmBytes.byteLength > 0 ? { wasmBinary: this._persistedWasmBytes } : {},
|
|
3230
|
+
...e.wasmUrl ? { locateFile: (t) => t.endsWith(".wasm") ? e.wasmUrl : t } : {},
|
|
3188
3231
|
print: (e) => {
|
|
3189
|
-
|
|
3232
|
+
i.push(String(e));
|
|
3190
3233
|
},
|
|
3191
3234
|
printErr: (e) => {
|
|
3192
|
-
|
|
3235
|
+
a.push(String(e));
|
|
3193
3236
|
},
|
|
3194
|
-
stdin: () =>
|
|
3237
|
+
stdin: () => s < o.length ? o[s++] : null,
|
|
3195
3238
|
preRun: [(e) => {
|
|
3196
|
-
e && e.FS && (
|
|
3239
|
+
e && e.FS && (c = this._syncBrshToEmscriptenFs(e.FS, n));
|
|
3197
3240
|
}]
|
|
3198
|
-
},
|
|
3241
|
+
}, u = this._createIoBridge(n, i, a), d;
|
|
3199
3242
|
try {
|
|
3200
|
-
|
|
3243
|
+
d = t.prototype && t.prototype.constructor === t && Object.getOwnPropertyNames(t.prototype).length > 1 ? new t(l, u) : await t(l, u);
|
|
3201
3244
|
} catch (e) {
|
|
3202
3245
|
if (e && typeof e.status == "number") this.exitCode = e.status;
|
|
3203
3246
|
else throw e;
|
|
3204
3247
|
}
|
|
3205
|
-
if (
|
|
3206
|
-
|
|
3248
|
+
if (d && typeof d == "object") if (r && (d.wasmBinary instanceof Uint8Array || d.HEAPU8 instanceof Uint8Array) && (this._inspectedWasm = k(d.wasmBinary || d.HEAPU8)), typeof d.callMain == "function") {
|
|
3249
|
+
d.FS && c.size === 0 && (c = this._syncBrshToEmscriptenFs(d.FS, n));
|
|
3207
3250
|
try {
|
|
3208
|
-
let e = await
|
|
3251
|
+
let e = await d.callMain(n);
|
|
3209
3252
|
typeof e == "number" && e !== 0 && (this.exitCode = e);
|
|
3210
3253
|
} catch (e) {
|
|
3211
|
-
e && typeof e.status == "number" ? this.exitCode = e.status : (
|
|
3254
|
+
e && typeof e.status == "number" ? this.exitCode = e.status : (a.push(e.message || String(e)), this.exitCode = 1);
|
|
3212
3255
|
}
|
|
3213
|
-
|
|
3214
|
-
} else if (typeof
|
|
3215
|
-
else if (typeof
|
|
3216
|
-
let e = (
|
|
3217
|
-
await this._invokeCliFunction(e,
|
|
3218
|
-
} else typeof u.stdout == "string" &&
|
|
3219
|
-
else typeof
|
|
3220
|
-
|
|
3256
|
+
d.FS && this._syncEmscriptenFsToBrsh(d.FS, n, c);
|
|
3257
|
+
} else if (typeof d.exec == "function" && typeof d.writeFile == "function") await this._runVirtualFsInstance(d, n, i, a);
|
|
3258
|
+
else if (typeof d.main == "function" || typeof d.run == "function") {
|
|
3259
|
+
let e = (d.main || d.run).bind(d);
|
|
3260
|
+
await this._invokeCliFunction(e, n, i, a);
|
|
3261
|
+
} else !r && !isVersion && typeof d.Database == "function" ? this._runSqlJsDatabase(d, n, u, i) : (typeof d.stdout == "string" && d.stdout && d.stdout.replace(/\r?\n$/, "").split(/\r?\n/).forEach((e) => i.push(e)), typeof d.stderr == "string" && d.stderr && d.stderr.replace(/\r?\n$/, "").split(/\r?\n/).forEach((e) => a.push(e)), d.error && a.length === 0 && (a.push(d.error.message || String(d.error)), this.exitCode = 1), typeof d.exitCode == "number" && (this.exitCode = d.exitCode));
|
|
3262
|
+
else typeof d == "string" ? d.replace(/\r?\n$/, "").split(/\r?\n/).forEach((e) => i.push(e)) : typeof d == "number" && (this.exitCode = d);
|
|
3263
|
+
i.forEach((e) => {
|
|
3221
3264
|
this.stdOut = e;
|
|
3222
|
-
}),
|
|
3265
|
+
}), a.forEach((e) => {
|
|
3223
3266
|
this.stdErr = e;
|
|
3224
3267
|
});
|
|
3225
3268
|
}
|
|
3269
|
+
_runSqlJsDatabase(e, t, n, r) {
|
|
3270
|
+
let i = "list", a = ":memory:", o = null, s = [];
|
|
3271
|
+
for (let e = 0; e < t.length; e++) {
|
|
3272
|
+
let n = t[e];
|
|
3273
|
+
n === "-table" || n === "--table" || n === "-box" ? i = "table" : n === "-csv" || n === "--csv" ? i = "csv" : n === "-cmd" && e + 1 < t.length ? o = t[++e] : n.startsWith("-") || s.push(n);
|
|
3274
|
+
}
|
|
3275
|
+
if (s.length === 1 ? /^\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|DROP|PRAGMA|WITH|BEGIN|EXPLAIN|\.)\b/i.test(s[0]) ? o = s[0] : a = s[0] : s.length >= 2 && (a = s[0], o = s.slice(1).join(" ")), !o && n.stdin && n.stdin.trim() && (o = n.stdin.trim()), !o) return;
|
|
3276
|
+
let c = a === ":memory:" ? null : n.readBytes(a), l = c && c.byteLength > 0 ? new e.Database(c) : new e.Database();
|
|
3277
|
+
try {
|
|
3278
|
+
if (o.trim() === ".tables") {
|
|
3279
|
+
let e = l.exec("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name"), t = e[0] && e[0].values ? e[0].values.map((e) => e[0]) : [];
|
|
3280
|
+
t.length > 0 && r.push(t.join(" "));
|
|
3281
|
+
} else {
|
|
3282
|
+
let e = l.exec(o);
|
|
3283
|
+
for (let t of e) {
|
|
3284
|
+
let e = (t.columns || []).map(String), n = t.values || [];
|
|
3285
|
+
if (i === "table" && e.length > 0) {
|
|
3286
|
+
let t = e.map((e) => e.length), i = n.map((n) => e.map((e, r) => {
|
|
3287
|
+
let i = n[r] == null ? "NULL" : String(n[r]);
|
|
3288
|
+
return i.length > t[r] && (t[r] = i.length), i;
|
|
3289
|
+
}));
|
|
3290
|
+
r.push(e.map((e, n) => " " + e.padEnd(t[n]) + " ").join("|")), r.push(t.map((e) => "-".repeat(e + 2)).join("+")), i.forEach((e) => r.push(e.map((e, n) => " " + e.padEnd(t[n]) + " ").join("|")));
|
|
3291
|
+
} else if (i === "csv") {
|
|
3292
|
+
let t = (e) => {
|
|
3293
|
+
let t = e == null ? "" : String(e);
|
|
3294
|
+
return /[",\r\n]/.test(t) ? "\"" + t.replace(/"/g, "\"\"") + "\"" : t;
|
|
3295
|
+
};
|
|
3296
|
+
e.length > 0 && r.push(e.map(t).join(",")), n.forEach((n) => r.push(e.map((e, r) => t(n[r])).join(",")));
|
|
3297
|
+
} else n.forEach((t) => r.push(e.map((e, n) => t[n] == null ? "" : String(t[n])).join("|")));
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
a !== ":memory:" && n.writeFile(a, l.export());
|
|
3301
|
+
} finally {
|
|
3302
|
+
l.close();
|
|
3303
|
+
}
|
|
3304
|
+
}
|
|
3226
3305
|
async _runVirtualFsInstance(t, n, r, i) {
|
|
3227
3306
|
typeof t.on == "function" && t.on("log", ({ message: e }) => {
|
|
3228
3307
|
e && r.push(e);
|
|
@@ -5157,6 +5236,9 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
5157
5236
|
};
|
|
5158
5237
|
})), Be = /* @__PURE__ */ t(((e, t) => {
|
|
5159
5238
|
var n = K();
|
|
5239
|
+
function r(e) {
|
|
5240
|
+
return e >= 1048576 ? (e / 1048576).toFixed(1) + " MB" : e >= 1024 ? (e / 1024).toFixed(1) + " KB" : e + " B";
|
|
5241
|
+
}
|
|
5160
5242
|
t.exports = class extends n {
|
|
5161
5243
|
static get name() {
|
|
5162
5244
|
return "curl";
|
|
@@ -5165,75 +5247,108 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
5165
5247
|
return !0;
|
|
5166
5248
|
}
|
|
5167
5249
|
run() {
|
|
5168
|
-
let e = [...this.arguments], t = null, n = {},
|
|
5169
|
-
for (;
|
|
5170
|
-
let
|
|
5171
|
-
switch (
|
|
5250
|
+
let e = [...this.arguments], t = null, n = {}, i = null, a = !1, o = !1, s = null, c = null, l = 0;
|
|
5251
|
+
for (; l < e.length;) {
|
|
5252
|
+
let r = e[l];
|
|
5253
|
+
switch (r) {
|
|
5172
5254
|
case "-X":
|
|
5173
5255
|
case "--request":
|
|
5174
|
-
t = e[++
|
|
5256
|
+
t = e[++l];
|
|
5175
5257
|
break;
|
|
5176
5258
|
case "-H":
|
|
5177
5259
|
case "--header": {
|
|
5178
|
-
let t = e[++
|
|
5260
|
+
let t = e[++l] || "", r = t.indexOf(":");
|
|
5179
5261
|
r > 0 && (n[t.slice(0, r).trim()] = t.slice(r + 1).trim());
|
|
5180
5262
|
break;
|
|
5181
5263
|
}
|
|
5182
5264
|
case "-d":
|
|
5183
5265
|
case "--data":
|
|
5184
5266
|
case "--data-raw":
|
|
5185
|
-
|
|
5267
|
+
i = e[++l], t ||= "POST";
|
|
5186
5268
|
break;
|
|
5187
5269
|
case "-u":
|
|
5188
5270
|
case "--user": {
|
|
5189
|
-
let t = e[++
|
|
5271
|
+
let t = e[++l] || "";
|
|
5190
5272
|
n.Authorization = "Basic " + btoa(t);
|
|
5191
5273
|
break;
|
|
5192
5274
|
}
|
|
5193
5275
|
case "-o":
|
|
5194
5276
|
case "--output":
|
|
5195
|
-
|
|
5277
|
+
s = e[++l];
|
|
5196
5278
|
break;
|
|
5197
5279
|
case "-i":
|
|
5198
5280
|
case "--include":
|
|
5199
|
-
|
|
5281
|
+
a = !0;
|
|
5200
5282
|
break;
|
|
5201
5283
|
case "-s":
|
|
5202
5284
|
case "--silent":
|
|
5203
|
-
|
|
5285
|
+
o = !0;
|
|
5204
5286
|
break;
|
|
5287
|
+
case "-#":
|
|
5288
|
+
case "--progress-bar": break;
|
|
5205
5289
|
case "-L":
|
|
5206
5290
|
case "--location": break;
|
|
5207
|
-
default:
|
|
5291
|
+
default: r.startsWith("-") ? o || (this.stdErr = `curl: unknown option '${r}'`) : c = r;
|
|
5208
5292
|
}
|
|
5209
|
-
|
|
5293
|
+
l++;
|
|
5210
5294
|
}
|
|
5211
|
-
if (!
|
|
5212
|
-
if (!/^https?:\/\//i.test(
|
|
5213
|
-
let
|
|
5295
|
+
if (!c) return this.stdErr = "curl: no URL specified", this.exitCode = 1, Promise.resolve();
|
|
5296
|
+
if (!/^https?:\/\//i.test(c)) return this.stdErr = `curl: unsupported protocol in URL: ${c}`, this.exitCode = 1, Promise.resolve();
|
|
5297
|
+
let u = {
|
|
5214
5298
|
method: t || "GET",
|
|
5215
5299
|
headers: n
|
|
5216
5300
|
};
|
|
5217
|
-
return
|
|
5218
|
-
|
|
5301
|
+
return i !== null && (u.body = i), fetch(c, u).then(async (e) => {
|
|
5302
|
+
a && (this.stdOut = `HTTP/1.1 ${e.status} ${e.statusText}`, e.headers.forEach((e, t) => {
|
|
5219
5303
|
this.stdOut = `${t}: ${e}`;
|
|
5220
5304
|
}), this.stdOut = "");
|
|
5221
|
-
let t =
|
|
5222
|
-
if (
|
|
5223
|
-
|
|
5305
|
+
let t = null, n = Number(e.headers.get("content-length") || 0);
|
|
5306
|
+
if (e.body && typeof e.body.getReader == "function") {
|
|
5307
|
+
let i = e.body.getReader(), a = [], c = 0;
|
|
5308
|
+
for (;;) {
|
|
5309
|
+
let { done: e, value: t } = await i.read();
|
|
5310
|
+
if (e) break;
|
|
5311
|
+
if (a.push(t), c += t.length, s && !o) {
|
|
5312
|
+
if (n > 0) {
|
|
5313
|
+
let e = Math.min(100, Math.floor(c / n * 100)), t = Math.min(20, Math.round(c / n * 20)), i = "=".repeat(Math.max(0, t - 1)) + (t > 0 ? ">" : "") + " ".repeat(Math.max(0, 20 - t));
|
|
5314
|
+
this.stdOut = `\r[${i}] ${e}% (${r(c)} / ${r(n)})`;
|
|
5315
|
+
} else this.stdOut = `\rDownloading: ${r(c)}`;
|
|
5316
|
+
this.flush();
|
|
5317
|
+
}
|
|
5318
|
+
}
|
|
5319
|
+
t = new Uint8Array(c);
|
|
5320
|
+
let l = 0;
|
|
5321
|
+
for (let e of a) t.set(e, l), l += e.length;
|
|
5322
|
+
if (s && !o && c > 0) {
|
|
5323
|
+
let e = n || c;
|
|
5324
|
+
this.stdOut = `\r[${"=".repeat(20)}] 100% (${r(c)} / ${r(e)})`, this.flush();
|
|
5325
|
+
}
|
|
5326
|
+
} else {
|
|
5327
|
+
let n = await e.arrayBuffer();
|
|
5328
|
+
t = new Uint8Array(n);
|
|
5329
|
+
}
|
|
5330
|
+
if (s) try {
|
|
5331
|
+
let n = e.headers.get("content-type") || "";
|
|
5332
|
+
if (/^text\/|application\/(json|javascript|xml|x-sh)/i.test(n)) {
|
|
5333
|
+
let e = new TextDecoder().decode(t);
|
|
5334
|
+
this.fs.setFileByPath(s, e, !0);
|
|
5335
|
+
} else {
|
|
5336
|
+
let { BinaryFile: e } = ie(), r = e ? new e(t.buffer, n || "application/octet-stream") : t;
|
|
5337
|
+
this.fs.setFileByPath(s, r, !0);
|
|
5338
|
+
}
|
|
5224
5339
|
} catch (e) {
|
|
5225
|
-
this.stdErr = `curl: cannot write to '${
|
|
5340
|
+
this.stdErr = `curl: cannot write to '${s}': ${e.message}`, this.exitCode = 1;
|
|
5226
5341
|
}
|
|
5227
|
-
else t.split(/\r?\n/).forEach((e) => {
|
|
5342
|
+
else new TextDecoder().decode(t).split(/\r?\n/).forEach((e) => {
|
|
5228
5343
|
this.stdOut = e;
|
|
5229
5344
|
});
|
|
5230
5345
|
e.ok || (this.exitCode = 22);
|
|
5231
5346
|
}).catch((e) => {
|
|
5232
|
-
if (!
|
|
5347
|
+
if (!o) {
|
|
5233
5348
|
let t = e && e.message ? e.message : String(e);
|
|
5234
5349
|
if (e instanceof TypeError && /failed to fetch|networkerror|load failed|fetch is aborted/i.test(t)) {
|
|
5235
|
-
let e = /^https:\/\//i.test(
|
|
5236
|
-
!e && t ? this.stdErr = "curl: (35) Mixed content blocked — the page is served over HTTPS but the target URL is HTTP. Browsers block insecure requests from secure pages." : (this.stdErr = `curl: (6) Network request failed — this is likely a CORS error. The server at ${
|
|
5350
|
+
let e = /^https:\/\//i.test(c), t = typeof location < "u" && location.protocol === "https:";
|
|
5351
|
+
!e && t ? this.stdErr = "curl: (35) Mixed content blocked — the page is served over HTTPS but the target URL is HTTP. Browsers block insecure requests from secure pages." : (this.stdErr = `curl: (6) Network request failed — this is likely a CORS error. The server at ${c} did not include the required 'Access-Control-Allow-Origin' response header. You can only fetch cross-origin resources that explicitly allow it.`, this.stdErr = " Hint: try a public CORS proxy, or ensure the server sends 'Access-Control-Allow-Origin: *'.");
|
|
5237
5352
|
} else this.stdErr = `curl: (6) Could not connect: ${t}`;
|
|
5238
5353
|
}
|
|
5239
5354
|
this.exitCode = 6;
|
|
@@ -7711,7 +7826,11 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
7711
7826
|
let t = this.context.getCommand(e), r = e;
|
|
7712
7827
|
if (!t && !e.endsWith(".wasm") && (t = this.context.getCommand(`${e}.wasm`), t && (r = `${e}.wasm`)), !t) throw Error(`${e}: Command not found`);
|
|
7713
7828
|
let i = `${this.path}/${r}`;
|
|
7714
|
-
|
|
7829
|
+
if (this._isWasmFile(i, t)) {
|
|
7830
|
+
if (!this.context.fs.isExecutable(i)) throw Error(`${e}: permission denied`);
|
|
7831
|
+
return o.bind(null, i);
|
|
7832
|
+
}
|
|
7833
|
+
return typeof t == "string" && t.startsWith("#!") ? a.bind(this, t) : t;
|
|
7715
7834
|
}
|
|
7716
7835
|
async _parseCommandLine(t) {
|
|
7717
7836
|
let n = e._splitCommand(t);
|
|
@@ -7838,8 +7957,23 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
7838
7957
|
static _escapeRegExp(e) {
|
|
7839
7958
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
7840
7959
|
}
|
|
7960
|
+
static async create(t = {}) {
|
|
7961
|
+
let { filesystem: n, permissions: r, ...i } = t;
|
|
7962
|
+
if (p(n) || n && typeof n == "object" && p(n.filesystem)) {
|
|
7963
|
+
let e = await m(n, r);
|
|
7964
|
+
n = e.filesystem, r = e.permissions;
|
|
7965
|
+
}
|
|
7966
|
+
let a = new e(Object.assign({}, i, {
|
|
7967
|
+
filesystem: n,
|
|
7968
|
+
permissions: r
|
|
7969
|
+
}));
|
|
7970
|
+
return await a.ready, a;
|
|
7971
|
+
}
|
|
7972
|
+
static async fromContainer(t, n = {}) {
|
|
7973
|
+
return e.create(Object.assign({}, n, { filesystem: t }));
|
|
7974
|
+
}
|
|
7841
7975
|
};
|
|
7842
|
-
_.STATUS_READY = "READY", _.STATUS_WORKING = "WORKING", _.STATUS_DESTROYED = "DESTROYED", _.Command = s, _.InteractiveCommand = c, _.WasmCommand = o, _.ReplCommand = or(), _.FS = f, _.BinaryContainer = re(), _.Storage = _.BinaryContainer.FilesystemStorage, globalThis.shell = _, t.exports = _;
|
|
7976
|
+
_.STATUS_READY = "READY", _.STATUS_WORKING = "WORKING", _.STATUS_DESTROYED = "DESTROYED", _.Command = s, _.InteractiveCommand = c, _.WasmCommand = o, _.createWasmCommand = o.createGenericWasmCommand || o.createCommand, _.ReplCommand = or(), _.FS = f, _.BinaryContainer = re(), _.Storage = _.BinaryContainer.FilesystemStorage, globalThis.shell = _, globalThis.Shell = _, t.exports = _;
|
|
7843
7977
|
}));
|
|
7844
7978
|
//#endregion
|
|
7845
7979
|
export default sr();
|