brsh 2.8.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 +7 -0
- package/dist/shell.es.js +160 -81
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +4 -4
- package/dist/shell.min.js.map +1 -1
- package/dist/wbt.es.js +1584 -623
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +6 -6
- package/dist/wbt.min.js.map +1 -1
- 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/WasmCommand.js +168 -18
- package/lib/wbt/index.js +270 -14
- package/lib/wbt/packages/wllama.js +12 -2
- package/lib/wbt/registry.js +11 -2
- package/package.json +1 -1
- package/test/wbt.test.js +24 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [2.8.1](https://github.com/eliotstocker/Brsh-JS/compare/v2.8.0...v2.8.1) (2026-11-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **wbt:** eagerly pull and persist .wasm binaries on install, upgrade jq-web@0.6.2, and fix browser bundling ([#29](https://github.com/eliotstocker/Brsh-JS/issues/29)) ([e713798](https://github.com/eliotstocker/Brsh-JS/commit/e713798656926a8b2afce9571a853ffc928099c1))
|
|
7
|
+
|
|
1
8
|
# [2.8.0](https://github.com/eliotstocker/Brsh-JS/compare/v2.7.0...v2.8.0) (2026-11-08)
|
|
2
9
|
|
|
3
10
|
|
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);
|