sandboxedjs 0.1.25 → 0.1.27
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 +42 -11
- package/dist/index.cjs +1769 -459
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +68 -12
- package/dist/index.d.ts +68 -12
- package/dist/index.js +1765 -452
- package/dist/index.js.map +1 -1
- package/package.json +2 -5
package/dist/index.cjs
CHANGED
|
@@ -2,44 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var index_js = require('buffer/index.js');
|
|
6
6
|
var pako = require('pako');
|
|
7
7
|
var sha256 = require('@noble/hashes/sha256');
|
|
8
8
|
var sha512 = require('@noble/hashes/sha512');
|
|
9
9
|
var sha1 = require('@noble/hashes/sha1');
|
|
10
10
|
var semver = require('semver');
|
|
11
11
|
var acorn = require('acorn');
|
|
12
|
-
var
|
|
12
|
+
var EventEmitter4 = require('events/events.js');
|
|
13
13
|
var jsx = require('acorn-jsx');
|
|
14
14
|
var resolve_exports = require('resolve.exports');
|
|
15
15
|
var pathModule = require('path-browserify');
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var assertModule = require('assert');
|
|
19
|
-
var processShim = require('process');
|
|
20
|
-
var zlibModule = require('browserify-zlib');
|
|
16
|
+
var streamModule4 = require('stream-browserify');
|
|
17
|
+
var processShim = require('process/browser.js');
|
|
21
18
|
var querystringModule = require('querystring-es3');
|
|
22
|
-
var stringDecoderModule = require('string_decoder');
|
|
19
|
+
var stringDecoderModule = require('string_decoder/lib/string_decoder.js');
|
|
23
20
|
var timersModule = require('timers-browserify');
|
|
24
|
-
var
|
|
25
|
-
var legacy = require('@noble/hashes/legacy');
|
|
21
|
+
var legacyUrl = require('url/url.js');
|
|
22
|
+
var legacy$1 = require('@noble/hashes/legacy');
|
|
26
23
|
var hmac = require('@noble/hashes/hmac');
|
|
27
24
|
|
|
28
25
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
29
26
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
30
27
|
|
|
31
|
-
var
|
|
28
|
+
var EventEmitter4__default = /*#__PURE__*/_interopDefault(EventEmitter4);
|
|
32
29
|
var jsx__default = /*#__PURE__*/_interopDefault(jsx);
|
|
33
30
|
var pathModule__default = /*#__PURE__*/_interopDefault(pathModule);
|
|
34
|
-
var
|
|
35
|
-
var utilModule__default = /*#__PURE__*/_interopDefault(utilModule);
|
|
36
|
-
var assertModule__default = /*#__PURE__*/_interopDefault(assertModule);
|
|
31
|
+
var streamModule4__default = /*#__PURE__*/_interopDefault(streamModule4);
|
|
37
32
|
var processShim__default = /*#__PURE__*/_interopDefault(processShim);
|
|
38
|
-
var zlibModule__default = /*#__PURE__*/_interopDefault(zlibModule);
|
|
39
33
|
var querystringModule__default = /*#__PURE__*/_interopDefault(querystringModule);
|
|
40
34
|
var stringDecoderModule__default = /*#__PURE__*/_interopDefault(stringDecoderModule);
|
|
41
35
|
var timersModule__default = /*#__PURE__*/_interopDefault(timersModule);
|
|
42
|
-
var
|
|
36
|
+
var legacyUrl__default = /*#__PURE__*/_interopDefault(legacyUrl);
|
|
43
37
|
|
|
44
38
|
var __defProp = Object.defineProperty;
|
|
45
39
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -249,7 +243,7 @@ function join(...parts) {
|
|
|
249
243
|
const joined = parts.filter((p) => p !== "").join("/");
|
|
250
244
|
return joined === "" ? "." : normalize(joined);
|
|
251
245
|
}
|
|
252
|
-
function resolve(
|
|
246
|
+
function resolve(base2, ...parts) {
|
|
253
247
|
let resolved = "";
|
|
254
248
|
let absolute = false;
|
|
255
249
|
for (let i = parts.length - 1; i >= 0 && !absolute; i--) {
|
|
@@ -259,7 +253,7 @@ function resolve(base, ...parts) {
|
|
|
259
253
|
absolute = isAbsolute(part);
|
|
260
254
|
}
|
|
261
255
|
if (!absolute) {
|
|
262
|
-
resolved = resolved === "" ?
|
|
256
|
+
resolved = resolved === "" ? base2 : `${base2}/${resolved}`;
|
|
263
257
|
}
|
|
264
258
|
const norm = normalize(resolved);
|
|
265
259
|
return isAbsolute(norm) ? stripTrailing(norm) : stripTrailing(normalize(`/${norm}`));
|
|
@@ -279,14 +273,14 @@ function basename(p, ext) {
|
|
|
279
273
|
const norm = stripTrailing(normalize(p));
|
|
280
274
|
if (norm === "/") return "/";
|
|
281
275
|
const idx = norm.lastIndexOf("/");
|
|
282
|
-
let
|
|
283
|
-
if (ext &&
|
|
284
|
-
return
|
|
276
|
+
let base2 = idx < 0 ? norm : norm.slice(idx + 1);
|
|
277
|
+
if (ext && base2 !== ext && base2.endsWith(ext)) base2 = base2.slice(0, -ext.length);
|
|
278
|
+
return base2;
|
|
285
279
|
}
|
|
286
280
|
function extname(p) {
|
|
287
|
-
const
|
|
288
|
-
const idx =
|
|
289
|
-
return idx <= 0 ? "" :
|
|
281
|
+
const base2 = basename(p);
|
|
282
|
+
const idx = base2.lastIndexOf(".");
|
|
283
|
+
return idx <= 0 ? "" : base2.slice(idx);
|
|
290
284
|
}
|
|
291
285
|
function relative(from, to) {
|
|
292
286
|
const a = segments(normalize(from));
|
|
@@ -1056,9 +1050,9 @@ function tokenize(src) {
|
|
|
1056
1050
|
const rest = src.slice(i);
|
|
1057
1051
|
const baseMatch = /^(\d+)#([0-9a-zA-Z@_]+)/.exec(rest);
|
|
1058
1052
|
if (baseMatch) {
|
|
1059
|
-
const
|
|
1060
|
-
if (
|
|
1061
|
-
out.push({ kind: "num", value: baseMatch[0], num: parseInBase(baseMatch[2],
|
|
1053
|
+
const base2 = Number(baseMatch[1]);
|
|
1054
|
+
if (base2 < 2 || base2 > 64) throw new exports.ArithError(`invalid arithmetic base (error token is "${baseMatch[1]}")`);
|
|
1055
|
+
out.push({ kind: "num", value: baseMatch[0], num: parseInBase(baseMatch[2], base2) });
|
|
1062
1056
|
i += baseMatch[0].length;
|
|
1063
1057
|
continue;
|
|
1064
1058
|
}
|
|
@@ -1105,17 +1099,17 @@ function tokenize(src) {
|
|
|
1105
1099
|
out.push({ kind: "eof", value: "" });
|
|
1106
1100
|
return out;
|
|
1107
1101
|
}
|
|
1108
|
-
function parseInBase(text2,
|
|
1102
|
+
function parseInBase(text2, base2) {
|
|
1109
1103
|
let value = 0;
|
|
1110
1104
|
for (const ch of text2) {
|
|
1111
1105
|
let digit;
|
|
1112
|
-
if (
|
|
1106
|
+
if (base2 <= 36) {
|
|
1113
1107
|
digit = DIGITS.toLowerCase().indexOf(ch.toLowerCase());
|
|
1114
1108
|
} else {
|
|
1115
1109
|
digit = DIGITS.indexOf(ch);
|
|
1116
1110
|
}
|
|
1117
|
-
if (digit < 0 || digit >=
|
|
1118
|
-
value = value *
|
|
1111
|
+
if (digit < 0 || digit >= base2) throw new exports.ArithError(`value too great for base (error token is "${text2}")`);
|
|
1112
|
+
value = value * base2 + digit;
|
|
1119
1113
|
}
|
|
1120
1114
|
return value;
|
|
1121
1115
|
}
|
|
@@ -1350,12 +1344,12 @@ var init_arith = __esm({
|
|
|
1350
1344
|
}
|
|
1351
1345
|
}
|
|
1352
1346
|
power() {
|
|
1353
|
-
const
|
|
1347
|
+
const base2 = this.unary();
|
|
1354
1348
|
if (this.eat("**")) {
|
|
1355
1349
|
const exp = this.power();
|
|
1356
|
-
return Math.trunc(Math.pow(
|
|
1350
|
+
return Math.trunc(Math.pow(base2, exp));
|
|
1357
1351
|
}
|
|
1358
|
-
return
|
|
1352
|
+
return base2;
|
|
1359
1353
|
}
|
|
1360
1354
|
unary() {
|
|
1361
1355
|
if (this.eat("+")) return this.unary();
|
|
@@ -2184,18 +2178,18 @@ async function pathnameExpand(field, ctx) {
|
|
|
2184
2178
|
if (ctx.noglob) return [literal];
|
|
2185
2179
|
const pattern = field.map((f) => f.glob ? f.text : escapeGlob(f.text)).join("");
|
|
2186
2180
|
if (!hasMagic(pattern, ctx.extglob !== false)) return [literal];
|
|
2187
|
-
const
|
|
2181
|
+
const matches3 = glob(ctx.vfs, pattern, {
|
|
2188
2182
|
cwd: ctx.cwd,
|
|
2189
2183
|
cred: ctx.cred,
|
|
2190
2184
|
dot: ctx.dotglob ?? false,
|
|
2191
2185
|
extglob: ctx.extglob !== false
|
|
2192
2186
|
});
|
|
2193
|
-
if (
|
|
2187
|
+
if (matches3.length === 0) {
|
|
2194
2188
|
if (ctx.failglob) throw new ExpansionError(`no match: ${literal}`);
|
|
2195
2189
|
if (ctx.nullglob) return [];
|
|
2196
2190
|
return [literal];
|
|
2197
2191
|
}
|
|
2198
|
-
return
|
|
2192
|
+
return matches3;
|
|
2199
2193
|
}
|
|
2200
2194
|
function matchesPattern(value, pattern, extglob = true) {
|
|
2201
2195
|
return fnmatch(pattern, value, { pathname: false, dot: true, extglob });
|
|
@@ -2609,12 +2603,12 @@ function decodeEscapes(input, opts = {}) {
|
|
|
2609
2603
|
}
|
|
2610
2604
|
return { text: out, stopped: false };
|
|
2611
2605
|
}
|
|
2612
|
-
function formatPrintf(
|
|
2606
|
+
function formatPrintf(format3, args) {
|
|
2613
2607
|
let out = "";
|
|
2614
2608
|
let argIndex = 0;
|
|
2615
2609
|
let consumedAny = false;
|
|
2616
2610
|
do {
|
|
2617
|
-
const pass = formatOnce(
|
|
2611
|
+
const pass = formatOnce(format3, args, argIndex);
|
|
2618
2612
|
out += pass.text;
|
|
2619
2613
|
if (pass.stopped) return out;
|
|
2620
2614
|
consumedAny = pass.nextIndex > argIndex;
|
|
@@ -2623,17 +2617,17 @@ function formatPrintf(format, args) {
|
|
|
2623
2617
|
} while (argIndex < args.length && consumedAny);
|
|
2624
2618
|
return out;
|
|
2625
2619
|
}
|
|
2626
|
-
function formatOnce(
|
|
2620
|
+
function formatOnce(format3, args, startIndex) {
|
|
2627
2621
|
let out = "";
|
|
2628
2622
|
let i = 0;
|
|
2629
2623
|
let argIndex = startIndex;
|
|
2630
2624
|
let hasConversions = false;
|
|
2631
2625
|
const nextArg = () => args[argIndex++] ?? "";
|
|
2632
|
-
while (i <
|
|
2633
|
-
const c =
|
|
2626
|
+
while (i < format3.length) {
|
|
2627
|
+
const c = format3[i];
|
|
2634
2628
|
if (c === "\\") {
|
|
2635
|
-
decodeEscapes(
|
|
2636
|
-
const single = decodeSingleEscape(
|
|
2629
|
+
decodeEscapes(format3.slice(i, i + 12), { stopAtC: true });
|
|
2630
|
+
const single = decodeSingleEscape(format3, i);
|
|
2637
2631
|
if (single.stopped) return { text: out, nextIndex: argIndex, hasConversions, stopped: true };
|
|
2638
2632
|
out += single.text;
|
|
2639
2633
|
i = single.next;
|
|
@@ -2644,12 +2638,12 @@ function formatOnce(format, args, startIndex) {
|
|
|
2644
2638
|
i++;
|
|
2645
2639
|
continue;
|
|
2646
2640
|
}
|
|
2647
|
-
if (
|
|
2641
|
+
if (format3[i + 1] === "%") {
|
|
2648
2642
|
out += "%";
|
|
2649
2643
|
i += 2;
|
|
2650
2644
|
continue;
|
|
2651
2645
|
}
|
|
2652
|
-
const spec = /^%([-+ #0']*)(\*|\d+)?(?:\.(\*|\d+))?([diouxXeEfgGaAcsbq])/.exec(
|
|
2646
|
+
const spec = /^%([-+ #0']*)(\*|\d+)?(?:\.(\*|\d+))?([diouxXeEfgGaAcsbq])/.exec(format3.slice(i));
|
|
2653
2647
|
if (!spec) {
|
|
2654
2648
|
out += c;
|
|
2655
2649
|
i++;
|
|
@@ -2859,13 +2853,13 @@ function builtinPrintf({ argv, io }) {
|
|
|
2859
2853
|
varName = args[1];
|
|
2860
2854
|
start2 = 2;
|
|
2861
2855
|
}
|
|
2862
|
-
const
|
|
2863
|
-
if (
|
|
2856
|
+
const format3 = args[start2];
|
|
2857
|
+
if (format3 === void 0) {
|
|
2864
2858
|
io.stderr.write("printf: usage: printf [-v var] format [arguments]\n");
|
|
2865
2859
|
return 2;
|
|
2866
2860
|
}
|
|
2867
2861
|
try {
|
|
2868
|
-
const text2 = formatPrintf(
|
|
2862
|
+
const text2 = formatPrintf(format3, args.slice(start2 + 1));
|
|
2869
2863
|
if (varName) return 0;
|
|
2870
2864
|
io.stdout.write(text2);
|
|
2871
2865
|
return 0;
|
|
@@ -3613,10 +3607,10 @@ function builtinType({ shell, argv, io }) {
|
|
|
3613
3607
|
}
|
|
3614
3608
|
async function builtinCommand({ shell, argv, io }) {
|
|
3615
3609
|
const args = argv.slice(1);
|
|
3616
|
-
const
|
|
3610
|
+
const describe2 = args.includes("-v") || args.includes("-V");
|
|
3617
3611
|
const verbose = args.includes("-V");
|
|
3618
3612
|
const rest = args.filter((a) => a !== "-v" && a !== "-V" && a !== "-p");
|
|
3619
|
-
if (
|
|
3613
|
+
if (describe2) {
|
|
3620
3614
|
let status = 0;
|
|
3621
3615
|
for (const name of rest) {
|
|
3622
3616
|
if (isBuiltinName(name)) {
|
|
@@ -3855,13 +3849,13 @@ function builtinDirs({ shell, argv, io }) {
|
|
|
3855
3849
|
}
|
|
3856
3850
|
const entries = [shell.cwd, ...shell.dirStack];
|
|
3857
3851
|
const home = shell.vars.get("HOME");
|
|
3858
|
-
const
|
|
3852
|
+
const render2 = (p) => home && p.startsWith(home) ? "~" + p.slice(home.length) : p;
|
|
3859
3853
|
if (argv.includes("-v")) {
|
|
3860
|
-
entries.forEach((entry, idx) => io.stdout.write(`${String(idx).padStart(2)} ${
|
|
3854
|
+
entries.forEach((entry, idx) => io.stdout.write(`${String(idx).padStart(2)} ${render2(entry)}
|
|
3861
3855
|
`));
|
|
3862
3856
|
return 0;
|
|
3863
3857
|
}
|
|
3864
|
-
io.stdout.write(entries.map(
|
|
3858
|
+
io.stdout.write(entries.map(render2).join(" ") + "\n");
|
|
3865
3859
|
return 0;
|
|
3866
3860
|
}
|
|
3867
3861
|
function builtinPushd({ shell, argv, io }) {
|
|
@@ -4470,12 +4464,12 @@ var Vfs = class {
|
|
|
4470
4464
|
writeFile(abs, data, opts = {}) {
|
|
4471
4465
|
const cred = opts.privileged ? void 0 : opts.cred;
|
|
4472
4466
|
const real = this.resolvePath(abs, { cred });
|
|
4473
|
-
const
|
|
4467
|
+
const bytes2 = typeof data === "string" ? encoder.encode(data) : data;
|
|
4474
4468
|
const virt = this.lookupVirtual(real);
|
|
4475
4469
|
if (virt) {
|
|
4476
4470
|
if (!virt.write) throw new exports.SysError("EACCES", "write", real);
|
|
4477
4471
|
this.require(this.statFromVirtual(real, virt), W_OK, cred, "open", real);
|
|
4478
|
-
virt.write(
|
|
4472
|
+
virt.write(bytes2, opts.append ?? false);
|
|
4479
4473
|
return;
|
|
4480
4474
|
}
|
|
4481
4475
|
if (this.isUnderProvider(real)) throw new exports.SysError("ENOENT", "open", real);
|
|
@@ -4490,8 +4484,8 @@ var Vfs = class {
|
|
|
4490
4484
|
this.require(pst, W_OK | X_OK, cred, "open", real);
|
|
4491
4485
|
}
|
|
4492
4486
|
try {
|
|
4493
|
-
if (opts.append && existing) this.volume.appendFileSync(real,
|
|
4494
|
-
else this.volume.writeFileSync(real,
|
|
4487
|
+
if (opts.append && existing) this.volume.appendFileSync(real, bytes2);
|
|
4488
|
+
else this.volume.writeFileSync(real, bytes2);
|
|
4495
4489
|
} catch (e) {
|
|
4496
4490
|
throw toSysError(e, "open", real);
|
|
4497
4491
|
}
|
|
@@ -4743,7 +4737,7 @@ var Vfs = class {
|
|
|
4743
4737
|
usage(abs = "/") {
|
|
4744
4738
|
let files = 0;
|
|
4745
4739
|
let dirs = 0;
|
|
4746
|
-
let
|
|
4740
|
+
let bytes2 = 0;
|
|
4747
4741
|
for (const p of this.walk(abs)) {
|
|
4748
4742
|
let st = null;
|
|
4749
4743
|
try {
|
|
@@ -4754,10 +4748,10 @@ var Vfs = class {
|
|
|
4754
4748
|
if (st.isDirectory()) dirs++;
|
|
4755
4749
|
else {
|
|
4756
4750
|
files++;
|
|
4757
|
-
|
|
4751
|
+
bytes2 += st.size;
|
|
4758
4752
|
}
|
|
4759
4753
|
}
|
|
4760
|
-
return { files, dirs, bytes };
|
|
4754
|
+
return { files, dirs, bytes: bytes2 };
|
|
4761
4755
|
}
|
|
4762
4756
|
};
|
|
4763
4757
|
|
|
@@ -4794,6 +4788,14 @@ var Pipe = class _Pipe {
|
|
|
4794
4788
|
isTTY = false;
|
|
4795
4789
|
/** Set on pipes owned by an outside caller, who may never call `end()`. */
|
|
4796
4790
|
interactive = false;
|
|
4791
|
+
/**
|
|
4792
|
+
* Set while the running program has put the terminal in raw mode.
|
|
4793
|
+
*
|
|
4794
|
+
* A program in raw mode draws its own input — a prompt library redraws the
|
|
4795
|
+
* whole line on every keystroke — so the terminal must stop echoing, or
|
|
4796
|
+
* every character appears twice.
|
|
4797
|
+
*/
|
|
4798
|
+
rawMode = false;
|
|
4797
4799
|
columns;
|
|
4798
4800
|
rows;
|
|
4799
4801
|
get closed() {
|
|
@@ -4808,10 +4810,10 @@ var Pipe = class _Pipe {
|
|
|
4808
4810
|
write(data) {
|
|
4809
4811
|
if (this.readerClosed) throw new exports.SysError("EPIPE", "write");
|
|
4810
4812
|
if (this.writerClosed) return;
|
|
4811
|
-
const
|
|
4812
|
-
if (
|
|
4813
|
-
this.chunks.push(
|
|
4814
|
-
this.buffered +=
|
|
4813
|
+
const bytes2 = toBytes(data);
|
|
4814
|
+
if (bytes2.length === 0) return;
|
|
4815
|
+
this.chunks.push(bytes2);
|
|
4816
|
+
this.buffered += bytes2.length;
|
|
4815
4817
|
this.wake();
|
|
4816
4818
|
}
|
|
4817
4819
|
end() {
|
|
@@ -4940,11 +4942,11 @@ var BufferSink = class {
|
|
|
4940
4942
|
}
|
|
4941
4943
|
write(data) {
|
|
4942
4944
|
if (this._closed) return;
|
|
4943
|
-
const
|
|
4944
|
-
if (
|
|
4945
|
-
this.chunks.push(
|
|
4946
|
-
this.total +=
|
|
4947
|
-
this.onWrite?.(
|
|
4945
|
+
const bytes2 = toBytes(data);
|
|
4946
|
+
if (bytes2.length === 0) return;
|
|
4947
|
+
this.chunks.push(bytes2);
|
|
4948
|
+
this.total += bytes2.length;
|
|
4949
|
+
this.onWrite?.(bytes2);
|
|
4948
4950
|
}
|
|
4949
4951
|
end() {
|
|
4950
4952
|
this._closed = true;
|
|
@@ -5573,9 +5575,9 @@ function parseSize(spec) {
|
|
|
5573
5575
|
const value = Number(m[1]);
|
|
5574
5576
|
const unit = (m[2] ?? "").toLowerCase();
|
|
5575
5577
|
const binary = m[3] !== "" || unit === "";
|
|
5576
|
-
const
|
|
5578
|
+
const base2 = binary ? 1024 : 1e3;
|
|
5577
5579
|
const exp = { "": 0, k: 1, m: 2, g: 3, t: 4, p: 5 }[unit] ?? 0;
|
|
5578
|
-
return Math.round(value * Math.pow(
|
|
5580
|
+
return Math.round(value * Math.pow(base2, exp));
|
|
5579
5581
|
}
|
|
5580
5582
|
|
|
5581
5583
|
// src/kernel/command.ts
|
|
@@ -6821,7 +6823,7 @@ var NetworkStack = class {
|
|
|
6821
6823
|
}
|
|
6822
6824
|
return [...out.values()].sort((a, b) => a.port - b.port);
|
|
6823
6825
|
}
|
|
6824
|
-
/** Ports
|
|
6826
|
+
/** Ports the pod's proxy has registered for this instance. */
|
|
6825
6827
|
knownPodPorts() {
|
|
6826
6828
|
try {
|
|
6827
6829
|
return this.pod.proxy.activePorts(this.pod.instanceId) ?? [];
|
|
@@ -6887,22 +6889,22 @@ var NetworkStack = class {
|
|
|
6887
6889
|
`;
|
|
6888
6890
|
return out;
|
|
6889
6891
|
}
|
|
6890
|
-
countTx(
|
|
6892
|
+
countTx(bytes2, iface = "eth0") {
|
|
6891
6893
|
const i = this.interface(iface);
|
|
6892
6894
|
if (!i) return;
|
|
6893
|
-
i.txBytes +=
|
|
6894
|
-
i.txPackets += Math.max(1, Math.ceil(
|
|
6895
|
+
i.txBytes += bytes2;
|
|
6896
|
+
i.txPackets += Math.max(1, Math.ceil(bytes2 / 1400));
|
|
6895
6897
|
}
|
|
6896
|
-
countRx(
|
|
6898
|
+
countRx(bytes2, iface = "eth0") {
|
|
6897
6899
|
const i = this.interface(iface);
|
|
6898
6900
|
if (!i) return;
|
|
6899
|
-
i.rxBytes +=
|
|
6900
|
-
i.rxPackets += Math.max(1, Math.ceil(
|
|
6901
|
+
i.rxBytes += bytes2;
|
|
6902
|
+
i.rxPackets += Math.max(1, Math.ceil(bytes2 / 1400));
|
|
6901
6903
|
}
|
|
6902
6904
|
};
|
|
6903
6905
|
function randomMac() {
|
|
6904
|
-
const
|
|
6905
|
-
return
|
|
6906
|
+
const bytes2 = [2, 66, 172, 17, 0, 2];
|
|
6907
|
+
return bytes2.map((b) => b.toString(16).padStart(2, "0")).join(":");
|
|
6906
6908
|
}
|
|
6907
6909
|
function hexIp(ip2) {
|
|
6908
6910
|
return ip2.split(".").reverse().map((o) => Number(o).toString(16).padStart(2, "0").toUpperCase()).join("");
|
|
@@ -7191,7 +7193,7 @@ var Lexer = class _Lexer {
|
|
|
7191
7193
|
const stripTabs = opToken.value === "<<-";
|
|
7192
7194
|
const rawTag = tagToken.value;
|
|
7193
7195
|
const quoted = /['"\\]/.test(rawTag);
|
|
7194
|
-
const
|
|
7196
|
+
const tag2 = rawTag.replace(/['"\\]/g, "");
|
|
7195
7197
|
const lines = [];
|
|
7196
7198
|
let found = false;
|
|
7197
7199
|
while (this.pos < this.src.length) {
|
|
@@ -7200,7 +7202,7 @@ var Lexer = class _Lexer {
|
|
|
7200
7202
|
const rawLine = this.src.slice(this.pos, eol);
|
|
7201
7203
|
this.pos = eol + 1;
|
|
7202
7204
|
const compare = stripTabs ? rawLine.replace(/^\t+/, "") : rawLine;
|
|
7203
|
-
if (compare ===
|
|
7205
|
+
if (compare === tag2) {
|
|
7204
7206
|
found = true;
|
|
7205
7207
|
break;
|
|
7206
7208
|
}
|
|
@@ -7208,9 +7210,9 @@ var Lexer = class _Lexer {
|
|
|
7208
7210
|
if (eol >= this.src.length) break;
|
|
7209
7211
|
}
|
|
7210
7212
|
if (!found) {
|
|
7211
|
-
throw new IncompleteInputError(`here-document delimited by end-of-file (wanted \`${
|
|
7213
|
+
throw new IncompleteInputError(`here-document delimited by end-of-file (wanted \`${tag2}')`, opToken.pos);
|
|
7212
7214
|
}
|
|
7213
|
-
opToken.heredoc = { tag, stripTabs, quoted, body: lines.length ? lines.join("\n") + "\n" : "" };
|
|
7215
|
+
opToken.heredoc = { tag: tag2, stripTabs, quoted, body: lines.length ? lines.join("\n") + "\n" : "" };
|
|
7214
7216
|
}
|
|
7215
7217
|
}
|
|
7216
7218
|
};
|
|
@@ -8777,16 +8779,16 @@ sys ${fmt2(Math.floor(ms * 0.2))}
|
|
|
8777
8779
|
function splitAliasWords(text2) {
|
|
8778
8780
|
const out = [];
|
|
8779
8781
|
let current = "";
|
|
8780
|
-
let
|
|
8782
|
+
let quote3 = null;
|
|
8781
8783
|
for (let i = 0; i < text2.length; i++) {
|
|
8782
8784
|
const c = text2[i];
|
|
8783
|
-
if (
|
|
8784
|
-
if (c ===
|
|
8785
|
+
if (quote3) {
|
|
8786
|
+
if (c === quote3) quote3 = null;
|
|
8785
8787
|
else current += c;
|
|
8786
8788
|
continue;
|
|
8787
8789
|
}
|
|
8788
8790
|
if (c === "'" || c === '"') {
|
|
8789
|
-
|
|
8791
|
+
quote3 = c;
|
|
8790
8792
|
continue;
|
|
8791
8793
|
}
|
|
8792
8794
|
if (c === " " || c === " ") {
|
|
@@ -8940,11 +8942,11 @@ var decoder3 = new TextDecoder();
|
|
|
8940
8942
|
async function readInputs(ctx, operands, opts = {}) {
|
|
8941
8943
|
const stdinName = opts.stdinName ?? "-";
|
|
8942
8944
|
if (operands.length === 0) {
|
|
8943
|
-
const
|
|
8944
|
-
return { sources: [{ name: stdinName, bytes }], ok: true };
|
|
8945
|
+
const bytes2 = await ctx.stdin.readAll();
|
|
8946
|
+
return { sources: [{ name: stdinName, bytes: bytes2 }], ok: true };
|
|
8945
8947
|
}
|
|
8946
8948
|
const sources = [];
|
|
8947
|
-
let
|
|
8949
|
+
let ok2 = true;
|
|
8948
8950
|
for (const operand of operands) {
|
|
8949
8951
|
if (operand === "-") {
|
|
8950
8952
|
sources.push({ name: stdinName, bytes: await ctx.stdin.readAll() });
|
|
@@ -8955,19 +8957,19 @@ async function readInputs(ctx, operands, opts = {}) {
|
|
|
8955
8957
|
const st = ctx.vfs.stat(abs, { cred: ctx.cred });
|
|
8956
8958
|
if (st.isDirectory()) {
|
|
8957
8959
|
ctx.warn(`${operand}: Is a directory`);
|
|
8958
|
-
|
|
8960
|
+
ok2 = false;
|
|
8959
8961
|
continue;
|
|
8960
8962
|
}
|
|
8961
8963
|
sources.push({ name: operand, bytes: ctx.vfs.readFile(abs, ctx.cred) });
|
|
8962
8964
|
} catch (e) {
|
|
8963
8965
|
ctx.reportError(e, operand);
|
|
8964
|
-
|
|
8966
|
+
ok2 = false;
|
|
8965
8967
|
}
|
|
8966
8968
|
}
|
|
8967
|
-
return { sources, ok };
|
|
8969
|
+
return { sources, ok: ok2 };
|
|
8968
8970
|
}
|
|
8969
|
-
function splitLines(
|
|
8970
|
-
const text2 = decoder3.decode(
|
|
8971
|
+
function splitLines(bytes2) {
|
|
8972
|
+
const text2 = decoder3.decode(bytes2);
|
|
8971
8973
|
if (text2 === "") return { lines: [], trailingNewline: true };
|
|
8972
8974
|
const trailingNewline = text2.endsWith("\n");
|
|
8973
8975
|
const body = trailingNewline ? text2.slice(0, -1) : text2;
|
|
@@ -8979,14 +8981,14 @@ function joinLines(lines, trailingNewline = true) {
|
|
|
8979
8981
|
}
|
|
8980
8982
|
var SI_UNITS = ["", "k", "M", "G", "T", "P", "E"];
|
|
8981
8983
|
var IEC_UNITS = ["", "K", "M", "G", "T", "P", "E"];
|
|
8982
|
-
function humanSize(
|
|
8983
|
-
const
|
|
8984
|
+
function humanSize(bytes2, opts = {}) {
|
|
8985
|
+
const base2 = opts.si ? 1e3 : 1024;
|
|
8984
8986
|
const units = opts.si ? SI_UNITS : IEC_UNITS;
|
|
8985
|
-
if (
|
|
8986
|
-
let value =
|
|
8987
|
+
if (bytes2 < base2) return String(bytes2);
|
|
8988
|
+
let value = bytes2;
|
|
8987
8989
|
let unit = 0;
|
|
8988
|
-
while (value >=
|
|
8989
|
-
value /=
|
|
8990
|
+
while (value >= base2 && unit < units.length - 1) {
|
|
8991
|
+
value /= base2;
|
|
8990
8992
|
unit++;
|
|
8991
8993
|
}
|
|
8992
8994
|
const rounded = value < 10 ? Math.ceil(value * 10) / 10 : Math.ceil(value);
|
|
@@ -9273,7 +9275,7 @@ var cat = defineCommand({
|
|
|
9273
9275
|
let lineNumber = 1;
|
|
9274
9276
|
let lastWasBlank = false;
|
|
9275
9277
|
for (const operand of operands) {
|
|
9276
|
-
let
|
|
9278
|
+
let bytes2;
|
|
9277
9279
|
if (operand === "-") {
|
|
9278
9280
|
if (plain) {
|
|
9279
9281
|
for (; ; ) {
|
|
@@ -9284,7 +9286,7 @@ var cat = defineCommand({
|
|
|
9284
9286
|
}
|
|
9285
9287
|
continue;
|
|
9286
9288
|
}
|
|
9287
|
-
|
|
9289
|
+
bytes2 = await ctx.stdin.readAll();
|
|
9288
9290
|
} else {
|
|
9289
9291
|
try {
|
|
9290
9292
|
const abs = ctx.path(operand);
|
|
@@ -9294,17 +9296,17 @@ var cat = defineCommand({
|
|
|
9294
9296
|
status = 1;
|
|
9295
9297
|
continue;
|
|
9296
9298
|
}
|
|
9297
|
-
|
|
9299
|
+
bytes2 = ctx.vfs.readFile(abs, ctx.cred);
|
|
9298
9300
|
} catch (e) {
|
|
9299
9301
|
status = ctx.reportError(e, operand);
|
|
9300
9302
|
continue;
|
|
9301
9303
|
}
|
|
9302
9304
|
}
|
|
9303
9305
|
if (plain) {
|
|
9304
|
-
ctx.write(
|
|
9306
|
+
ctx.write(bytes2);
|
|
9305
9307
|
continue;
|
|
9306
9308
|
}
|
|
9307
|
-
const text2 = new TextDecoder().decode(
|
|
9309
|
+
const text2 = new TextDecoder().decode(bytes2);
|
|
9308
9310
|
const hadTrailing = text2.endsWith("\n");
|
|
9309
9311
|
const parts = (hadTrailing ? text2.slice(0, -1) : text2).split("\n");
|
|
9310
9312
|
for (const raw of parts) {
|
|
@@ -9894,9 +9896,9 @@ var stat = defineCommand({
|
|
|
9894
9896
|
try {
|
|
9895
9897
|
const abs = ctx.path(operand);
|
|
9896
9898
|
const st = args.has("dereference") ? ctx.vfs.stat(abs, { cred: ctx.cred }) : ctx.vfs.lstat(abs);
|
|
9897
|
-
const
|
|
9898
|
-
if (
|
|
9899
|
-
ctx.write(expandStatFormat(
|
|
9899
|
+
const format3 = args.str("format") ?? args.str("printf");
|
|
9900
|
+
if (format3) {
|
|
9901
|
+
ctx.write(expandStatFormat(format3, abs, st, ctx) + (args.str("printf") ? "" : "\n"));
|
|
9900
9902
|
continue;
|
|
9901
9903
|
}
|
|
9902
9904
|
if (args.has("terse")) {
|
|
@@ -9928,8 +9930,8 @@ var stat = defineCommand({
|
|
|
9928
9930
|
function isoTime(ms) {
|
|
9929
9931
|
return new Date(ms).toISOString().replace("T", " ").replace("Z", " +0000");
|
|
9930
9932
|
}
|
|
9931
|
-
function expandStatFormat(
|
|
9932
|
-
return
|
|
9933
|
+
function expandStatFormat(format3, path, st, ctx) {
|
|
9934
|
+
return format3.replace(/%(.)/g, (_, ch) => {
|
|
9933
9935
|
switch (ch) {
|
|
9934
9936
|
case "n":
|
|
9935
9937
|
return path;
|
|
@@ -9988,7 +9990,7 @@ var du = defineCommand({
|
|
|
9988
9990
|
const operands = args.positional.length ? args.positional : ["."];
|
|
9989
9991
|
const maxDepth = args.num("max-depth", args.has("summarize") ? 0 : Infinity);
|
|
9990
9992
|
const asBytes = args.has("bytes");
|
|
9991
|
-
const
|
|
9993
|
+
const render2 = (value) => args.has("human-readable") ? humanSize(value) : String(asBytes ? value : Math.max(1, Math.ceil(value / 1024)));
|
|
9992
9994
|
let total = 0;
|
|
9993
9995
|
let status = 0;
|
|
9994
9996
|
const walk = (abs, depth) => {
|
|
@@ -10000,20 +10002,20 @@ var du = defineCommand({
|
|
|
10000
10002
|
return 0;
|
|
10001
10003
|
}
|
|
10002
10004
|
if (!st.isDirectory()) {
|
|
10003
|
-
if (args.has("all") && depth <= maxDepth) ctx.line(`${
|
|
10005
|
+
if (args.has("all") && depth <= maxDepth) ctx.line(`${render2(st.size)} ${abs}`);
|
|
10004
10006
|
return st.size;
|
|
10005
10007
|
}
|
|
10006
10008
|
let sum = 4096;
|
|
10007
10009
|
for (const name of safeReaddir(ctx, abs)) {
|
|
10008
10010
|
sum += walk(join(abs, name), depth + 1);
|
|
10009
10011
|
}
|
|
10010
|
-
if (depth <= maxDepth) ctx.line(`${
|
|
10012
|
+
if (depth <= maxDepth) ctx.line(`${render2(sum)} ${abs}`);
|
|
10011
10013
|
return sum;
|
|
10012
10014
|
};
|
|
10013
10015
|
for (const operand of operands) {
|
|
10014
10016
|
total += walk(ctx.path(operand), 0);
|
|
10015
10017
|
}
|
|
10016
|
-
if (args.has("total")) ctx.line(`${
|
|
10018
|
+
if (args.has("total")) ctx.line(`${render2(total)} total`);
|
|
10017
10019
|
return status;
|
|
10018
10020
|
}
|
|
10019
10021
|
});
|
|
@@ -10048,8 +10050,8 @@ var df = defineCommand({
|
|
|
10048
10050
|
ctx.warn(`${operand}: No such file or directory`);
|
|
10049
10051
|
continue;
|
|
10050
10052
|
}
|
|
10051
|
-
const
|
|
10052
|
-
if (
|
|
10053
|
+
const match2 = mounts.filter((m) => contains(m.mountpoint, abs)).sort((a, b) => b.mountpoint.length - a.mountpoint.length)[0];
|
|
10054
|
+
if (match2) selected.set(match2.mountpoint, match2);
|
|
10053
10055
|
}
|
|
10054
10056
|
mounts = [...selected.values()];
|
|
10055
10057
|
}
|
|
@@ -10158,15 +10160,15 @@ function describeFile(ctx, abs, st, mime) {
|
|
|
10158
10160
|
}
|
|
10159
10161
|
if (st.isCharacterDevice()) return mime ? "inode/chardevice" : "character special";
|
|
10160
10162
|
if (st.size === 0) return mime ? "inode/x-empty" : "empty";
|
|
10161
|
-
const
|
|
10162
|
-
const magic = [...
|
|
10163
|
+
const bytes2 = ctx.vfs.readFile(abs, ctx.cred).subarray(0, 512);
|
|
10164
|
+
const magic = [...bytes2.subarray(0, 4)];
|
|
10163
10165
|
if (magic[0] === 127 && magic[1] === 69 && magic[2] === 76 && magic[3] === 70) {
|
|
10164
10166
|
return mime ? "application/x-executable" : "ELF 64-bit LSB executable, x86-64";
|
|
10165
10167
|
}
|
|
10166
10168
|
if (magic[0] === 31 && magic[1] === 139) return mime ? "application/gzip" : "gzip compressed data";
|
|
10167
10169
|
if (magic[0] === 80 && magic[1] === 75) return mime ? "application/zip" : "Zip archive data";
|
|
10168
10170
|
if (magic[0] === 137 && magic[1] === 80) return mime ? "image/png" : "PNG image data";
|
|
10169
|
-
const text2 = new TextDecoder().decode(
|
|
10171
|
+
const text2 = new TextDecoder().decode(bytes2);
|
|
10170
10172
|
const printable = [...text2].every((c) => c === "\n" || c === " " || c === "\r" || c >= " " && c <= "~" || c.charCodeAt(0) > 127);
|
|
10171
10173
|
if (!printable) return mime ? "application/octet-stream" : "data";
|
|
10172
10174
|
if (text2.startsWith("#!")) {
|
|
@@ -10239,10 +10241,10 @@ var printfCmd = defineCommand({
|
|
|
10239
10241
|
summary: "format and print data",
|
|
10240
10242
|
usage: "printf FORMAT [ARGUMENT]...",
|
|
10241
10243
|
run(ctx) {
|
|
10242
|
-
const
|
|
10243
|
-
if (
|
|
10244
|
+
const format3 = ctx.args[0];
|
|
10245
|
+
if (format3 === void 0) return ctx.fail("usage: printf FORMAT [ARGUMENT]...", 2);
|
|
10244
10246
|
try {
|
|
10245
|
-
ctx.write(formatPrintf(
|
|
10247
|
+
ctx.write(formatPrintf(format3, ctx.args.slice(1)));
|
|
10246
10248
|
return 0;
|
|
10247
10249
|
} catch (e) {
|
|
10248
10250
|
return ctx.fail(e instanceof Error ? e.message : String(e));
|
|
@@ -10338,13 +10340,13 @@ var seq = defineCommand({
|
|
|
10338
10340
|
}
|
|
10339
10341
|
if (increment === 0) return ctx.fail("zero increment", 1);
|
|
10340
10342
|
const separator = args.str("separator", "\n");
|
|
10341
|
-
const
|
|
10343
|
+
const format3 = args.str("format");
|
|
10342
10344
|
const values = [];
|
|
10343
10345
|
if (increment > 0) for (let v = first; v <= last + 1e-9; v += increment) values.push(v);
|
|
10344
10346
|
else for (let v = first; v >= last - 1e-9; v += increment) values.push(v);
|
|
10345
10347
|
const rendered = values.map((v) => {
|
|
10346
10348
|
const text2 = Number.isInteger(v) ? String(v) : String(Number(v.toFixed(10)));
|
|
10347
|
-
return
|
|
10349
|
+
return format3 ? formatPrintf(format3, [String(v)]) : text2;
|
|
10348
10350
|
});
|
|
10349
10351
|
const width = args.has("equal-width") ? Math.max(0, ...rendered.map((r) => r.length)) : 0;
|
|
10350
10352
|
const out = rendered.map((r) => width ? r.padStart(width, "0") : r);
|
|
@@ -10662,9 +10664,9 @@ var date = defineCommand({
|
|
|
10662
10664
|
return 0;
|
|
10663
10665
|
}
|
|
10664
10666
|
});
|
|
10665
|
-
function strftime(
|
|
10667
|
+
function strftime(format3, d) {
|
|
10666
10668
|
const pad2 = (n, w = 2, c = "0") => String(n).padStart(w, c);
|
|
10667
|
-
return
|
|
10669
|
+
return format3.replace(/%([-_0^#]?)(\d*)([a-zA-Z%])/g, (_, flag, width, ch) => {
|
|
10668
10670
|
const value = (() => {
|
|
10669
10671
|
switch (ch) {
|
|
10670
10672
|
case "Y":
|
|
@@ -10882,13 +10884,13 @@ var killall = defineCommand({
|
|
|
10882
10884
|
const signal = signalArg ? normalizeSignal(signalArg.slice(1)) ?? "SIGTERM" : "SIGTERM";
|
|
10883
10885
|
let status = 0;
|
|
10884
10886
|
for (const name of args) {
|
|
10885
|
-
const
|
|
10886
|
-
if (
|
|
10887
|
+
const matches3 = ctx.kernel.procs.list({ comm: name });
|
|
10888
|
+
if (matches3.length === 0) {
|
|
10887
10889
|
ctx.warn(`${name}: no process found`);
|
|
10888
10890
|
status = 1;
|
|
10889
10891
|
continue;
|
|
10890
10892
|
}
|
|
10891
|
-
for (const proc of
|
|
10893
|
+
for (const proc of matches3) proc.deliver(signal);
|
|
10892
10894
|
}
|
|
10893
10895
|
return status;
|
|
10894
10896
|
}
|
|
@@ -10902,13 +10904,13 @@ var pgrep = defineCommand({
|
|
|
10902
10904
|
const pattern = args.positional[0];
|
|
10903
10905
|
if (pattern === void 0) return ctx.fail("no matching criteria specified", 2);
|
|
10904
10906
|
const re = new RegExp(pattern);
|
|
10905
|
-
const
|
|
10906
|
-
for (const proc of
|
|
10907
|
+
const matches3 = ctx.kernel.procs.list().filter((p) => re.test(args.has("f") ? p.cmdline : p.comm));
|
|
10908
|
+
for (const proc of matches3) {
|
|
10907
10909
|
if (args.has("a")) ctx.line(`${proc.pid} ${proc.cmdline}`);
|
|
10908
10910
|
else if (args.has("l")) ctx.line(`${proc.pid} ${proc.comm}`);
|
|
10909
10911
|
else ctx.line(String(proc.pid));
|
|
10910
10912
|
}
|
|
10911
|
-
return
|
|
10913
|
+
return matches3.length ? 0 : 1;
|
|
10912
10914
|
}
|
|
10913
10915
|
});
|
|
10914
10916
|
var top = defineCommand({
|
|
@@ -11440,7 +11442,7 @@ var BRACKET_CLASSES = {
|
|
|
11440
11442
|
function translateBracket(text2) {
|
|
11441
11443
|
return text2.replace(/\[:([a-z]+):\]/g, (_, name) => BRACKET_CLASSES[name] ?? "");
|
|
11442
11444
|
}
|
|
11443
|
-
function applyReplacement(replacement,
|
|
11445
|
+
function applyReplacement(replacement, match2) {
|
|
11444
11446
|
let out = "";
|
|
11445
11447
|
let caseMode = null;
|
|
11446
11448
|
let oneShot = null;
|
|
@@ -11457,7 +11459,7 @@ function applyReplacement(replacement, match) {
|
|
|
11457
11459
|
for (let i = 0; i < replacement.length; i++) {
|
|
11458
11460
|
const c = replacement[i];
|
|
11459
11461
|
if (c === "&") {
|
|
11460
|
-
emit(
|
|
11462
|
+
emit(match2[0]);
|
|
11461
11463
|
continue;
|
|
11462
11464
|
}
|
|
11463
11465
|
if (c !== "\\") {
|
|
@@ -11467,7 +11469,7 @@ function applyReplacement(replacement, match) {
|
|
|
11467
11469
|
const next = replacement[++i];
|
|
11468
11470
|
if (next === void 0) break;
|
|
11469
11471
|
if (/\d/.test(next)) {
|
|
11470
|
-
emit(
|
|
11472
|
+
emit(match2[Number(next)] ?? "");
|
|
11471
11473
|
continue;
|
|
11472
11474
|
}
|
|
11473
11475
|
switch (next) {
|
|
@@ -11545,8 +11547,8 @@ async function runSed(ctx) {
|
|
|
11545
11547
|
const inPlace = args.present("in-place");
|
|
11546
11548
|
const suffix = args.str("in-place") ?? "";
|
|
11547
11549
|
const suppress = args.has("quiet") || args.has("silent");
|
|
11548
|
-
const { sources, ok } = await readInputs(ctx, operands);
|
|
11549
|
-
let status =
|
|
11550
|
+
const { sources, ok: ok2 } = await readInputs(ctx, operands);
|
|
11551
|
+
let status = ok2 ? 0 : 1;
|
|
11550
11552
|
for (const source of sources) {
|
|
11551
11553
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
11552
11554
|
const state = {
|
|
@@ -11759,17 +11761,17 @@ function substitute2(input, regex, replacement, global, occurrence) {
|
|
|
11759
11761
|
let last = 0;
|
|
11760
11762
|
let count = 0;
|
|
11761
11763
|
let changed = false;
|
|
11762
|
-
let
|
|
11763
|
-
while ((
|
|
11764
|
+
let match2;
|
|
11765
|
+
while ((match2 = re.exec(input)) !== null) {
|
|
11764
11766
|
count++;
|
|
11765
11767
|
const wanted = occurrence > 0 ? count >= occurrence && (global || count === occurrence) : true;
|
|
11766
11768
|
if (wanted) {
|
|
11767
|
-
out += input.slice(last,
|
|
11768
|
-
last =
|
|
11769
|
+
out += input.slice(last, match2.index) + applyReplacement(replacement, match2);
|
|
11770
|
+
last = match2.index + match2[0].length;
|
|
11769
11771
|
changed = true;
|
|
11770
11772
|
if (!global) break;
|
|
11771
11773
|
}
|
|
11772
|
-
if (
|
|
11774
|
+
if (match2[0] === "") re.lastIndex++;
|
|
11773
11775
|
}
|
|
11774
11776
|
out += input.slice(last);
|
|
11775
11777
|
return { text: out, changed };
|
|
@@ -12424,12 +12426,12 @@ var AwkParser = class {
|
|
|
12424
12426
|
return this.parsePower(noGt);
|
|
12425
12427
|
}
|
|
12426
12428
|
parsePower(noGt) {
|
|
12427
|
-
const
|
|
12429
|
+
const base2 = this.parsePostfix(noGt);
|
|
12428
12430
|
if (this.isOp("^") || this.isOp("**")) {
|
|
12429
12431
|
this.i++;
|
|
12430
|
-
return { t: "binary", op: "^", left:
|
|
12432
|
+
return { t: "binary", op: "^", left: base2, right: this.parseUnary(noGt) };
|
|
12431
12433
|
}
|
|
12432
|
-
return
|
|
12434
|
+
return base2;
|
|
12433
12435
|
}
|
|
12434
12436
|
parsePostfix(noGt) {
|
|
12435
12437
|
if (this.isOp("++") || this.isOp("--")) {
|
|
@@ -12723,11 +12725,11 @@ var Interpreter = class {
|
|
|
12723
12725
|
toStrRaw(v) {
|
|
12724
12726
|
return v === void 0 ? "%.6g" : v.isNum ? String(v.num) : v.str;
|
|
12725
12727
|
}
|
|
12726
|
-
numToStr(n,
|
|
12728
|
+
numToStr(n, format3) {
|
|
12727
12729
|
if (Number.isInteger(n) && Math.abs(n) < 1e16) return String(n);
|
|
12728
12730
|
if (!Number.isFinite(n)) return n > 0 ? "inf" : Number.isNaN(n) ? "nan" : "-inf";
|
|
12729
12731
|
try {
|
|
12730
|
-
return formatPrintf(
|
|
12732
|
+
return formatPrintf(format3, [String(n)]);
|
|
12731
12733
|
} catch {
|
|
12732
12734
|
return String(n);
|
|
12733
12735
|
}
|
|
@@ -13033,9 +13035,9 @@ var Interpreter = class {
|
|
|
13033
13035
|
let count = 0;
|
|
13034
13036
|
const result = subject.replace(re, (...groups) => {
|
|
13035
13037
|
count++;
|
|
13036
|
-
const
|
|
13038
|
+
const match2 = groups[0];
|
|
13037
13039
|
return replacement.replace(/\\?&|\\\\/g, (token) => {
|
|
13038
|
-
if (token === "&") return
|
|
13040
|
+
if (token === "&") return match2;
|
|
13039
13041
|
if (token === "\\&") return "&";
|
|
13040
13042
|
return "\\";
|
|
13041
13043
|
});
|
|
@@ -13057,9 +13059,9 @@ var Interpreter = class {
|
|
|
13057
13059
|
return Value.fromNumber(m.index + 1);
|
|
13058
13060
|
}
|
|
13059
13061
|
case "sprintf": {
|
|
13060
|
-
const
|
|
13062
|
+
const format3 = str(0);
|
|
13061
13063
|
const rest = args.slice(1).map((a) => this.outputStr(this.evaluate(a)));
|
|
13062
|
-
return Value.fromString(formatPrintf(
|
|
13064
|
+
return Value.fromString(formatPrintf(format3, rest));
|
|
13063
13065
|
}
|
|
13064
13066
|
case "sin":
|
|
13065
13067
|
return Value.fromNumber(Math.sin(num(0)));
|
|
@@ -13206,12 +13208,12 @@ var Interpreter = class {
|
|
|
13206
13208
|
}
|
|
13207
13209
|
case "printf": {
|
|
13208
13210
|
if (stmt.args.length === 0) throw new AwkError("printf: no format supplied");
|
|
13209
|
-
const
|
|
13211
|
+
const format3 = this.toStr(this.evaluate(stmt.args[0]));
|
|
13210
13212
|
const rest = stmt.args.slice(1).map((a) => {
|
|
13211
13213
|
const v = this.evaluate(a);
|
|
13212
13214
|
return v.isNum ? String(v.num) : v.str;
|
|
13213
13215
|
});
|
|
13214
|
-
this.emit(formatPrintf(
|
|
13216
|
+
this.emit(formatPrintf(format3, rest), stmt.redirect);
|
|
13215
13217
|
return;
|
|
13216
13218
|
}
|
|
13217
13219
|
case "if":
|
|
@@ -13511,8 +13513,8 @@ async function runAwk(ctx) {
|
|
|
13511
13513
|
continue;
|
|
13512
13514
|
}
|
|
13513
13515
|
try {
|
|
13514
|
-
const
|
|
13515
|
-
inputs.push({ name: operand, lines: splitLines(
|
|
13516
|
+
const bytes2 = ctx.vfs.readFile(ctx.path(operand), ctx.cred);
|
|
13517
|
+
inputs.push({ name: operand, lines: splitLines(bytes2).lines });
|
|
13516
13518
|
} catch (e) {
|
|
13517
13519
|
ctx.reportError(e, operand);
|
|
13518
13520
|
return 2;
|
|
@@ -13567,7 +13569,7 @@ var head = defineCommand({
|
|
|
13567
13569
|
],
|
|
13568
13570
|
{ numericShortcut: "lines" }
|
|
13569
13571
|
);
|
|
13570
|
-
const { sources, ok } = await readInputs(ctx, args.positional, { stdinName: "standard input" });
|
|
13572
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional, { stdinName: "standard input" });
|
|
13571
13573
|
const showHeaders = (sources.length > 1 || args.has("verbose")) && !args.has("quiet");
|
|
13572
13574
|
sources.forEach((source, index) => {
|
|
13573
13575
|
if (showHeaders) {
|
|
@@ -13585,7 +13587,7 @@ var head = defineCommand({
|
|
|
13585
13587
|
const kept = count.fromEnd ? lines.slice(0, Math.max(0, lines.length - count.value)) : lines.slice(0, count.value);
|
|
13586
13588
|
ctx.write(joinLines(kept, trailingNewline || kept.length < lines.length));
|
|
13587
13589
|
});
|
|
13588
|
-
return
|
|
13590
|
+
return ok2 ? 0 : 1;
|
|
13589
13591
|
}
|
|
13590
13592
|
});
|
|
13591
13593
|
function parseCount(spec) {
|
|
@@ -13614,7 +13616,7 @@ var tail = defineCommand({
|
|
|
13614
13616
|
],
|
|
13615
13617
|
{ numericShortcut: "lines" }
|
|
13616
13618
|
);
|
|
13617
|
-
const { sources, ok } = await readInputs(ctx, args.positional, { stdinName: "standard input" });
|
|
13619
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional, { stdinName: "standard input" });
|
|
13618
13620
|
const showHeaders = (sources.length > 1 || args.has("verbose")) && !args.has("quiet");
|
|
13619
13621
|
sources.forEach((source, index) => {
|
|
13620
13622
|
if (showHeaders) {
|
|
@@ -13638,7 +13640,7 @@ var tail = defineCommand({
|
|
|
13638
13640
|
if (args.has("follow") && args.positional.length > 0) {
|
|
13639
13641
|
await followFiles(ctx, args.positional, Number(args.str("sleep-interval", "1")) * 1e3);
|
|
13640
13642
|
}
|
|
13641
|
-
return
|
|
13643
|
+
return ok2 ? 0 : 1;
|
|
13642
13644
|
}
|
|
13643
13645
|
});
|
|
13644
13646
|
async function followFiles(ctx, paths, intervalMs) {
|
|
@@ -13655,12 +13657,12 @@ async function followFiles(ctx, paths, intervalMs) {
|
|
|
13655
13657
|
if (ctx.signal.aborted) break;
|
|
13656
13658
|
for (const path of paths) {
|
|
13657
13659
|
try {
|
|
13658
|
-
const
|
|
13660
|
+
const bytes2 = ctx.vfs.readFile(ctx.path(path), ctx.cred);
|
|
13659
13661
|
const previous = offsets.get(path) ?? 0;
|
|
13660
|
-
if (
|
|
13661
|
-
ctx.write(
|
|
13662
|
-
offsets.set(path,
|
|
13663
|
-
} else if (
|
|
13662
|
+
if (bytes2.length > previous) {
|
|
13663
|
+
ctx.write(bytes2.subarray(previous));
|
|
13664
|
+
offsets.set(path, bytes2.length);
|
|
13665
|
+
} else if (bytes2.length < previous) {
|
|
13664
13666
|
offsets.set(path, 0);
|
|
13665
13667
|
}
|
|
13666
13668
|
} catch {
|
|
@@ -13681,7 +13683,7 @@ var wc = defineCommand({
|
|
|
13681
13683
|
{ short: "w", long: "words" },
|
|
13682
13684
|
{ short: "L", long: "max-line-length" }
|
|
13683
13685
|
]);
|
|
13684
|
-
const { sources, ok } = await readInputs(ctx, args.positional, { stdinName: "" });
|
|
13686
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional, { stdinName: "" });
|
|
13685
13687
|
const anyFlag = args.has("bytes") || args.has("chars") || args.has("lines") || args.has("words") || args.has("max-line-length");
|
|
13686
13688
|
const totals = { lines: 0, words: 0, bytes: 0, chars: 0, maxLine: 0 };
|
|
13687
13689
|
const rows = [];
|
|
@@ -13719,7 +13721,7 @@ var wc = defineCommand({
|
|
|
13719
13721
|
}
|
|
13720
13722
|
ctx.line(parts.join(" ") + (row.name ? ` ${row.name}` : ""));
|
|
13721
13723
|
}
|
|
13722
|
-
return
|
|
13724
|
+
return ok2 ? 0 : 1;
|
|
13723
13725
|
}
|
|
13724
13726
|
});
|
|
13725
13727
|
var sort = defineCommand({
|
|
@@ -13745,7 +13747,7 @@ var sort = defineCommand({
|
|
|
13745
13747
|
{ short: "z", long: "zero-terminated" },
|
|
13746
13748
|
{ short: "o", long: "output", arg: true }
|
|
13747
13749
|
]);
|
|
13748
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
13750
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
13749
13751
|
const all = [];
|
|
13750
13752
|
for (const source of sources) all.push(...splitLines(source.bytes).lines);
|
|
13751
13753
|
const separator = args.str("field-separator");
|
|
@@ -13809,7 +13811,7 @@ var sort = defineCommand({
|
|
|
13809
13811
|
const target = args.str("output");
|
|
13810
13812
|
if (target) ctx.vfs.writeFile(ctx.path(target), output, { cred: ctx.cred });
|
|
13811
13813
|
else ctx.write(output);
|
|
13812
|
-
return
|
|
13814
|
+
return ok2 ? 0 : 1;
|
|
13813
13815
|
}
|
|
13814
13816
|
});
|
|
13815
13817
|
var uniq = defineCommand({
|
|
@@ -13829,7 +13831,7 @@ var uniq = defineCommand({
|
|
|
13829
13831
|
{ short: "w", long: "check-chars", arg: true }
|
|
13830
13832
|
]);
|
|
13831
13833
|
const [input, output] = args.positional;
|
|
13832
|
-
const { sources, ok } = await readInputs(ctx, input ? [input] : []);
|
|
13834
|
+
const { sources, ok: ok2 } = await readInputs(ctx, input ? [input] : []);
|
|
13833
13835
|
const lines = sources.flatMap((s) => splitLines(s.bytes).lines);
|
|
13834
13836
|
const key = (line) => {
|
|
13835
13837
|
let value = line;
|
|
@@ -13861,7 +13863,7 @@ var uniq = defineCommand({
|
|
|
13861
13863
|
const text2 = joinLines(out, true);
|
|
13862
13864
|
if (output) ctx.vfs.writeFile(ctx.path(output), text2, { cred: ctx.cred });
|
|
13863
13865
|
else ctx.write(text2);
|
|
13864
|
-
return
|
|
13866
|
+
return ok2 ? 0 : 1;
|
|
13865
13867
|
}
|
|
13866
13868
|
});
|
|
13867
13869
|
var cut = defineCommand({
|
|
@@ -13885,7 +13887,7 @@ var cut = defineCommand({
|
|
|
13885
13887
|
const delimiter = args.str("delimiter", " ");
|
|
13886
13888
|
const outputDelimiter = args.str("output-delimiter", delimiter);
|
|
13887
13889
|
const byField = args.has("fields");
|
|
13888
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
13890
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
13889
13891
|
for (const source of sources) {
|
|
13890
13892
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
13891
13893
|
const out = lines.flatMap((line) => {
|
|
@@ -13900,7 +13902,7 @@ var cut = defineCommand({
|
|
|
13900
13902
|
});
|
|
13901
13903
|
ctx.write(joinLines(out, trailingNewline));
|
|
13902
13904
|
}
|
|
13903
|
-
return
|
|
13905
|
+
return ok2 ? 0 : 1;
|
|
13904
13906
|
}
|
|
13905
13907
|
});
|
|
13906
13908
|
function parseRanges(spec) {
|
|
@@ -13934,13 +13936,13 @@ var paste = defineCommand({
|
|
|
13934
13936
|
{ short: "s", long: "serial" }
|
|
13935
13937
|
]);
|
|
13936
13938
|
const delimiters = [...args.str("delimiters") || " "];
|
|
13937
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
13939
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
13938
13940
|
const columns = sources.map((s) => splitLines(s.bytes).lines);
|
|
13939
13941
|
if (args.has("serial")) {
|
|
13940
13942
|
for (const column2 of columns) {
|
|
13941
13943
|
ctx.line(column2.map((line, idx) => idx === 0 ? line : delimiters[(idx - 1) % delimiters.length] + line).join(""));
|
|
13942
13944
|
}
|
|
13943
|
-
return
|
|
13945
|
+
return ok2 ? 0 : 1;
|
|
13944
13946
|
}
|
|
13945
13947
|
const rows = Math.max(0, ...columns.map((c) => c.length));
|
|
13946
13948
|
for (let r = 0; r < rows; r++) {
|
|
@@ -13951,7 +13953,7 @@ var paste = defineCommand({
|
|
|
13951
13953
|
});
|
|
13952
13954
|
ctx.line(line);
|
|
13953
13955
|
}
|
|
13954
|
-
return
|
|
13956
|
+
return ok2 ? 0 : 1;
|
|
13955
13957
|
}
|
|
13956
13958
|
});
|
|
13957
13959
|
var tr = defineCommand({
|
|
@@ -14043,14 +14045,14 @@ var tee = defineCommand({
|
|
|
14043
14045
|
{ short: "a", long: "append" },
|
|
14044
14046
|
{ short: "i", long: "ignore-interrupts" }
|
|
14045
14047
|
]);
|
|
14046
|
-
const
|
|
14047
|
-
ctx.write(
|
|
14048
|
+
const bytes2 = await ctx.stdin.readAll();
|
|
14049
|
+
ctx.write(bytes2);
|
|
14048
14050
|
let status = 0;
|
|
14049
14051
|
for (const target of args.positional) {
|
|
14050
14052
|
try {
|
|
14051
14053
|
const abs = ctx.path(target);
|
|
14052
|
-
if (args.has("append")) ctx.vfs.appendFile(abs,
|
|
14053
|
-
else ctx.vfs.writeFile(abs,
|
|
14054
|
+
if (args.has("append")) ctx.vfs.appendFile(abs, bytes2, { cred: ctx.cred });
|
|
14055
|
+
else ctx.vfs.writeFile(abs, bytes2, { cred: ctx.cred });
|
|
14054
14056
|
} catch (e) {
|
|
14055
14057
|
status = ctx.reportError(e, target);
|
|
14056
14058
|
}
|
|
@@ -14063,12 +14065,12 @@ var rev = defineCommand({
|
|
|
14063
14065
|
path: "/usr/bin/rev",
|
|
14064
14066
|
summary: "reverse lines characterwise",
|
|
14065
14067
|
async run(ctx) {
|
|
14066
|
-
const { sources, ok } = await readInputs(ctx, ctx.args);
|
|
14068
|
+
const { sources, ok: ok2 } = await readInputs(ctx, ctx.args);
|
|
14067
14069
|
for (const source of sources) {
|
|
14068
14070
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
14069
14071
|
ctx.write(joinLines(lines.map((l) => [...l].reverse().join("")), trailingNewline));
|
|
14070
14072
|
}
|
|
14071
|
-
return
|
|
14073
|
+
return ok2 ? 0 : 1;
|
|
14072
14074
|
}
|
|
14073
14075
|
});
|
|
14074
14076
|
var tac = defineCommand({
|
|
@@ -14077,12 +14079,12 @@ var tac = defineCommand({
|
|
|
14077
14079
|
summary: "concatenate and print files in reverse",
|
|
14078
14080
|
async run(ctx) {
|
|
14079
14081
|
const args = parseArgs(ctx.args, [{ short: "s", long: "separator", arg: true }]);
|
|
14080
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14082
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14081
14083
|
for (const source of sources) {
|
|
14082
14084
|
const { lines } = splitLines(source.bytes);
|
|
14083
14085
|
ctx.write(joinLines(lines.reverse(), true));
|
|
14084
14086
|
}
|
|
14085
|
-
return
|
|
14087
|
+
return ok2 ? 0 : 1;
|
|
14086
14088
|
}
|
|
14087
14089
|
});
|
|
14088
14090
|
var nl = defineCommand({
|
|
@@ -14097,7 +14099,7 @@ var nl = defineCommand({
|
|
|
14097
14099
|
{ short: "v", long: "starting-line-number", arg: true, default: "1" },
|
|
14098
14100
|
{ short: "i", long: "line-increment", arg: true, default: "1" }
|
|
14099
14101
|
]);
|
|
14100
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14102
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14101
14103
|
const width = args.num("number-width", 6);
|
|
14102
14104
|
const separator = args.str("number-separator", " ");
|
|
14103
14105
|
const style = args.str("body-numbering", "t");
|
|
@@ -14114,7 +14116,7 @@ var nl = defineCommand({
|
|
|
14114
14116
|
}
|
|
14115
14117
|
}
|
|
14116
14118
|
}
|
|
14117
|
-
return
|
|
14119
|
+
return ok2 ? 0 : 1;
|
|
14118
14120
|
}
|
|
14119
14121
|
});
|
|
14120
14122
|
var fold = defineCommand({
|
|
@@ -14132,7 +14134,7 @@ var fold = defineCommand({
|
|
|
14132
14134
|
{ numericShortcut: "width" }
|
|
14133
14135
|
);
|
|
14134
14136
|
const width = args.num("width", 80);
|
|
14135
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14137
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14136
14138
|
for (const source of sources) {
|
|
14137
14139
|
for (const line of splitLines(source.bytes).lines) {
|
|
14138
14140
|
let rest = line;
|
|
@@ -14152,7 +14154,7 @@ var fold = defineCommand({
|
|
|
14152
14154
|
ctx.line(rest);
|
|
14153
14155
|
}
|
|
14154
14156
|
}
|
|
14155
|
-
return
|
|
14157
|
+
return ok2 ? 0 : 1;
|
|
14156
14158
|
}
|
|
14157
14159
|
});
|
|
14158
14160
|
var expandCmd = defineCommand({
|
|
@@ -14162,7 +14164,7 @@ var expandCmd = defineCommand({
|
|
|
14162
14164
|
async run(ctx) {
|
|
14163
14165
|
const args = parseArgs(ctx.args, [{ short: "t", long: "tabs", arg: true, default: "8" }, { short: "i", long: "initial" }]);
|
|
14164
14166
|
const tabs = args.num("tabs", 8);
|
|
14165
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14167
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14166
14168
|
for (const source of sources) {
|
|
14167
14169
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
14168
14170
|
const out = lines.map((line) => {
|
|
@@ -14175,7 +14177,7 @@ var expandCmd = defineCommand({
|
|
|
14175
14177
|
});
|
|
14176
14178
|
ctx.write(joinLines(out, trailingNewline));
|
|
14177
14179
|
}
|
|
14178
|
-
return
|
|
14180
|
+
return ok2 ? 0 : 1;
|
|
14179
14181
|
}
|
|
14180
14182
|
});
|
|
14181
14183
|
var unexpand = defineCommand({
|
|
@@ -14185,7 +14187,7 @@ var unexpand = defineCommand({
|
|
|
14185
14187
|
async run(ctx) {
|
|
14186
14188
|
const args = parseArgs(ctx.args, [{ short: "t", long: "tabs", arg: true, default: "8" }, { short: "a", long: "all" }]);
|
|
14187
14189
|
const tabs = args.num("tabs", 8);
|
|
14188
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14190
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14189
14191
|
for (const source of sources) {
|
|
14190
14192
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
14191
14193
|
const out = lines.map((line) => {
|
|
@@ -14195,7 +14197,7 @@ var unexpand = defineCommand({
|
|
|
14195
14197
|
});
|
|
14196
14198
|
ctx.write(joinLines(out, trailingNewline));
|
|
14197
14199
|
}
|
|
14198
|
-
return
|
|
14200
|
+
return ok2 ? 0 : 1;
|
|
14199
14201
|
}
|
|
14200
14202
|
});
|
|
14201
14203
|
var fmt = defineCommand({
|
|
@@ -14205,7 +14207,7 @@ var fmt = defineCommand({
|
|
|
14205
14207
|
async run(ctx) {
|
|
14206
14208
|
const args = parseArgs(ctx.args, [{ short: "w", long: "width", arg: true, default: "75" }], { numericShortcut: "width" });
|
|
14207
14209
|
const width = args.num("width", 75);
|
|
14208
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14210
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14209
14211
|
for (const source of sources) {
|
|
14210
14212
|
const paragraphs = decoder4.decode(source.bytes).split(/\n\s*\n/);
|
|
14211
14213
|
paragraphs.forEach((paragraph, idx) => {
|
|
@@ -14223,7 +14225,7 @@ var fmt = defineCommand({
|
|
|
14223
14225
|
if (line) ctx.line(line);
|
|
14224
14226
|
});
|
|
14225
14227
|
}
|
|
14226
|
-
return
|
|
14228
|
+
return ok2 ? 0 : 1;
|
|
14227
14229
|
}
|
|
14228
14230
|
});
|
|
14229
14231
|
var column = defineCommand({
|
|
@@ -14236,11 +14238,11 @@ var column = defineCommand({
|
|
|
14236
14238
|
{ short: "s", long: "separator", arg: true },
|
|
14237
14239
|
{ short: "o", long: "output-separator", arg: true, default: " " }
|
|
14238
14240
|
]);
|
|
14239
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14241
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14240
14242
|
const lines = sources.flatMap((s) => splitLines(s.bytes).lines).filter((l) => l !== "");
|
|
14241
14243
|
if (!args.has("table")) {
|
|
14242
14244
|
for (const line of lines) ctx.line(line);
|
|
14243
|
-
return
|
|
14245
|
+
return ok2 ? 0 : 1;
|
|
14244
14246
|
}
|
|
14245
14247
|
const separator = args.str("separator");
|
|
14246
14248
|
const rows = lines.map((line) => separator ? line.split(separator) : line.trim().split(/\s+/));
|
|
@@ -14250,7 +14252,7 @@ var column = defineCommand({
|
|
|
14250
14252
|
for (const row of rows) {
|
|
14251
14253
|
ctx.line(row.map((cell, i) => i === row.length - 1 ? cell : cell.padEnd(widths[i])).join(outputSeparator).trimEnd());
|
|
14252
14254
|
}
|
|
14253
|
-
return
|
|
14255
|
+
return ok2 ? 0 : 1;
|
|
14254
14256
|
}
|
|
14255
14257
|
});
|
|
14256
14258
|
var shuf = defineCommand({
|
|
@@ -14293,7 +14295,7 @@ var comm = defineCommand({
|
|
|
14293
14295
|
const args = parseArgs(ctx.args, [{ short: "1" }, { short: "2" }, { short: "3" }]);
|
|
14294
14296
|
const [a, b] = args.positional;
|
|
14295
14297
|
if (a === void 0 || b === void 0) return ctx.fail("missing operand", 1);
|
|
14296
|
-
const { sources, ok } = await readInputs(ctx, [a, b]);
|
|
14298
|
+
const { sources, ok: ok2 } = await readInputs(ctx, [a, b]);
|
|
14297
14299
|
const left = splitLines(sources[0].bytes).lines;
|
|
14298
14300
|
const right = splitLines(sources[1].bytes).lines;
|
|
14299
14301
|
let i = 0;
|
|
@@ -14313,7 +14315,7 @@ var comm = defineCommand({
|
|
|
14313
14315
|
j++;
|
|
14314
14316
|
}
|
|
14315
14317
|
}
|
|
14316
|
-
return
|
|
14318
|
+
return ok2 ? 0 : 1;
|
|
14317
14319
|
}
|
|
14318
14320
|
});
|
|
14319
14321
|
var join2 = defineCommand({
|
|
@@ -14334,7 +14336,7 @@ var join2 = defineCommand({
|
|
|
14334
14336
|
const joinChar = separator ?? " ";
|
|
14335
14337
|
const key1 = Number(args.str("j") ?? args.str("1", "1")) - 1;
|
|
14336
14338
|
const key2 = Number(args.str("j") ?? args.str("2", "1")) - 1;
|
|
14337
|
-
const { sources, ok } = await readInputs(ctx, [a, b]);
|
|
14339
|
+
const { sources, ok: ok2 } = await readInputs(ctx, [a, b]);
|
|
14338
14340
|
const left = splitLines(sources[0].bytes).lines.map(split2);
|
|
14339
14341
|
const right = splitLines(sources[1].bytes).lines.map(split2);
|
|
14340
14342
|
for (const l of left) {
|
|
@@ -14346,7 +14348,7 @@ var join2 = defineCommand({
|
|
|
14346
14348
|
}
|
|
14347
14349
|
}
|
|
14348
14350
|
}
|
|
14349
|
-
return
|
|
14351
|
+
return ok2 ? 0 : 1;
|
|
14350
14352
|
}
|
|
14351
14353
|
});
|
|
14352
14354
|
var split = defineCommand({
|
|
@@ -14362,17 +14364,17 @@ var split = defineCommand({
|
|
|
14362
14364
|
]);
|
|
14363
14365
|
const [input, prefixRaw] = args.positional;
|
|
14364
14366
|
const prefix = prefixRaw ?? "x";
|
|
14365
|
-
const { sources, ok } = await readInputs(ctx, input ? [input] : []);
|
|
14366
|
-
const
|
|
14367
|
+
const { sources, ok: ok2 } = await readInputs(ctx, input ? [input] : []);
|
|
14368
|
+
const bytes2 = sources[0]?.bytes ?? new Uint8Array(0);
|
|
14367
14369
|
const suffixLength = args.num("suffix-length", 2);
|
|
14368
14370
|
const chunks = [];
|
|
14369
14371
|
const byteSpec = args.str("bytes");
|
|
14370
14372
|
if (byteSpec !== void 0) {
|
|
14371
14373
|
const size = parseSize(byteSpec) ?? 1024;
|
|
14372
|
-
for (let i = 0; i <
|
|
14374
|
+
for (let i = 0; i < bytes2.length; i += size) chunks.push(bytes2.subarray(i, i + size));
|
|
14373
14375
|
} else {
|
|
14374
14376
|
const perChunk = args.num("lines", 1e3);
|
|
14375
|
-
const { lines } = splitLines(
|
|
14377
|
+
const { lines } = splitLines(bytes2);
|
|
14376
14378
|
for (let i = 0; i < lines.length; i += perChunk) {
|
|
14377
14379
|
chunks.push(new TextEncoder().encode(joinLines(lines.slice(i, i + perChunk), true)));
|
|
14378
14380
|
}
|
|
@@ -14381,7 +14383,7 @@ var split = defineCommand({
|
|
|
14381
14383
|
const suffix = args.has("numeric-suffixes") ? String(idx).padStart(suffixLength, "0") : numericToAlpha(idx, suffixLength);
|
|
14382
14384
|
ctx.vfs.writeFile(ctx.path(prefix + suffix), chunk, { cred: ctx.cred });
|
|
14383
14385
|
});
|
|
14384
|
-
return
|
|
14386
|
+
return ok2 ? 0 : 1;
|
|
14385
14387
|
}
|
|
14386
14388
|
});
|
|
14387
14389
|
function numericToAlpha(value, length) {
|
|
@@ -14582,19 +14584,19 @@ var grep = defineCommand({
|
|
|
14582
14584
|
let anyMatch = false;
|
|
14583
14585
|
let status = 1;
|
|
14584
14586
|
for (const target of targets) {
|
|
14585
|
-
let
|
|
14587
|
+
let bytes2;
|
|
14586
14588
|
if (target === "-") {
|
|
14587
|
-
|
|
14589
|
+
bytes2 = await ctx.stdin.readAll();
|
|
14588
14590
|
} else {
|
|
14589
14591
|
try {
|
|
14590
|
-
|
|
14592
|
+
bytes2 = ctx.vfs.readFile(ctx.path(target), ctx.cred);
|
|
14591
14593
|
} catch (e) {
|
|
14592
14594
|
if (!args.has("no-messages")) ctx.reportError(e, target);
|
|
14593
14595
|
status = 2;
|
|
14594
14596
|
continue;
|
|
14595
14597
|
}
|
|
14596
14598
|
}
|
|
14597
|
-
const { lines } = splitLines(
|
|
14599
|
+
const { lines } = splitLines(bytes2);
|
|
14598
14600
|
const matched = [];
|
|
14599
14601
|
let count = 0;
|
|
14600
14602
|
for (let i = 0; i < lines.length && count < maxCount; i++) {
|
|
@@ -15006,8 +15008,8 @@ var diff = defineCommand({
|
|
|
15006
15008
|
]);
|
|
15007
15009
|
const [a, b] = args.positional;
|
|
15008
15010
|
if (a === void 0 || b === void 0) return ctx.fail("missing operand", 2);
|
|
15009
|
-
const { sources, ok } = await readInputs(ctx, [a, b]);
|
|
15010
|
-
if (!
|
|
15011
|
+
const { sources, ok: ok2 } = await readInputs(ctx, [a, b]);
|
|
15012
|
+
if (!ok2 || sources.length < 2) return 2;
|
|
15011
15013
|
const normalize3 = (line) => {
|
|
15012
15014
|
let value = line;
|
|
15013
15015
|
if (args.has("ignore-all-space")) value = value.replace(/\s+/g, "");
|
|
@@ -15140,8 +15142,8 @@ var cmp = defineCommand({
|
|
|
15140
15142
|
const args = parseArgs(ctx.args, [{ short: "s", long: "silent" }, { short: "l", long: "verbose" }]);
|
|
15141
15143
|
const [a, b] = args.positional;
|
|
15142
15144
|
if (a === void 0 || b === void 0) return ctx.fail("missing operand", 2);
|
|
15143
|
-
const { sources, ok } = await readInputs(ctx, [a, b]);
|
|
15144
|
-
if (!
|
|
15145
|
+
const { sources, ok: ok2 } = await readInputs(ctx, [a, b]);
|
|
15146
|
+
if (!ok2) return 2;
|
|
15145
15147
|
const left = sources[0].bytes;
|
|
15146
15148
|
const right = sources[1].bytes;
|
|
15147
15149
|
const length = Math.min(left.length, right.length);
|
|
@@ -15251,9 +15253,9 @@ async function randomUuid() {
|
|
|
15251
15253
|
const { randomUUID } = await nodeCrypto();
|
|
15252
15254
|
return randomUUID();
|
|
15253
15255
|
}
|
|
15254
|
-
function toHex(
|
|
15256
|
+
function toHex(bytes2) {
|
|
15255
15257
|
let out = "";
|
|
15256
|
-
for (const byte of
|
|
15258
|
+
for (const byte of bytes2) out += byte.toString(16).padStart(2, "0");
|
|
15257
15259
|
return out;
|
|
15258
15260
|
}
|
|
15259
15261
|
function md5Hex(input) {
|
|
@@ -15381,8 +15383,8 @@ var BLOCK = 512;
|
|
|
15381
15383
|
var encoder4 = new TextEncoder();
|
|
15382
15384
|
var decoder6 = new TextDecoder();
|
|
15383
15385
|
function writeString(block, offset, value, length) {
|
|
15384
|
-
const
|
|
15385
|
-
for (let i = 0; i < length; i++) block[offset + i] = i <
|
|
15386
|
+
const bytes2 = encoder4.encode(value);
|
|
15387
|
+
for (let i = 0; i < length; i++) block[offset + i] = i < bytes2.length ? bytes2[i] : 0;
|
|
15386
15388
|
}
|
|
15387
15389
|
function writeOctal(block, offset, value, length) {
|
|
15388
15390
|
const text2 = value.toString(8).padStart(length - 1, "0");
|
|
@@ -15533,23 +15535,23 @@ var tar = defineCommand({
|
|
|
15533
15535
|
if (args.has("verbose")) ctx.line(name);
|
|
15534
15536
|
};
|
|
15535
15537
|
for (const operand of args.positional) add(resolve(baseDir, operand), operand);
|
|
15536
|
-
let
|
|
15537
|
-
if (compressed)
|
|
15538
|
-
if (archive === void 0 || archive === "-") ctx.write(
|
|
15539
|
-
else ctx.vfs.writeFile(ctx.path(archive),
|
|
15538
|
+
let bytes3 = createTar(entries2);
|
|
15539
|
+
if (compressed) bytes3 = await gzip(bytes3);
|
|
15540
|
+
if (archive === void 0 || archive === "-") ctx.write(bytes3);
|
|
15541
|
+
else ctx.vfs.writeFile(ctx.path(archive), bytes3, { cred: ctx.cred, mode: 420 });
|
|
15540
15542
|
return 0;
|
|
15541
15543
|
}
|
|
15542
|
-
let
|
|
15543
|
-
if (archive === void 0 || archive === "-")
|
|
15544
|
+
let bytes2;
|
|
15545
|
+
if (archive === void 0 || archive === "-") bytes2 = await ctx.stdin.readAll();
|
|
15544
15546
|
else {
|
|
15545
15547
|
try {
|
|
15546
|
-
|
|
15548
|
+
bytes2 = ctx.vfs.readFile(ctx.path(archive), ctx.cred);
|
|
15547
15549
|
} catch (e) {
|
|
15548
15550
|
return ctx.reportError(e, archive);
|
|
15549
15551
|
}
|
|
15550
15552
|
}
|
|
15551
|
-
if (
|
|
15552
|
-
const entries = readTar(
|
|
15553
|
+
if (bytes2[0] === 31 && bytes2[1] === 139) bytes2 = await gunzip(bytes2);
|
|
15554
|
+
const entries = readTar(bytes2);
|
|
15553
15555
|
const strip = args.num("strip-components", 0);
|
|
15554
15556
|
if (args.has("list")) {
|
|
15555
15557
|
for (const entry of entries) {
|
|
@@ -15705,18 +15707,18 @@ function makeSum(name, algorithm, path) {
|
|
|
15705
15707
|
{ long: "tag" }
|
|
15706
15708
|
]);
|
|
15707
15709
|
if (args.has("check")) return checkSums(ctx, algorithm, args.positional, args.has("quiet") || args.has("status"));
|
|
15708
|
-
const { sources, ok } = await readInputs(ctx, args.positional, { stdinName: "-" });
|
|
15710
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional, { stdinName: "-" });
|
|
15709
15711
|
for (const source of sources) {
|
|
15710
15712
|
const digest = await digestHex(algorithm, source.bytes);
|
|
15711
15713
|
if (args.has("tag")) ctx.line(`${algorithm.toUpperCase()} (${source.name}) = ${digest}`);
|
|
15712
15714
|
else ctx.line(`${digest} ${source.name}`);
|
|
15713
15715
|
}
|
|
15714
|
-
return
|
|
15716
|
+
return ok2 ? 0 : 1;
|
|
15715
15717
|
}
|
|
15716
15718
|
});
|
|
15717
15719
|
}
|
|
15718
15720
|
async function checkSums(ctx, algorithm, files, quiet) {
|
|
15719
|
-
const { sources, ok } = await readInputs(ctx, files);
|
|
15721
|
+
const { sources, ok: ok2 } = await readInputs(ctx, files);
|
|
15720
15722
|
let failures = 0;
|
|
15721
15723
|
let checked = 0;
|
|
15722
15724
|
for (const source of sources) {
|
|
@@ -15727,8 +15729,8 @@ async function checkSums(ctx, algorithm, files, quiet) {
|
|
|
15727
15729
|
checked++;
|
|
15728
15730
|
const [, expected, name] = m;
|
|
15729
15731
|
try {
|
|
15730
|
-
const
|
|
15731
|
-
const actual = await digestHex(algorithm,
|
|
15732
|
+
const bytes2 = ctx.vfs.readFile(ctx.path(name), ctx.cred);
|
|
15733
|
+
const actual = await digestHex(algorithm, bytes2);
|
|
15732
15734
|
if (actual === expected.toLowerCase()) {
|
|
15733
15735
|
if (!quiet) ctx.line(`${name}: OK`);
|
|
15734
15736
|
} else {
|
|
@@ -15742,7 +15744,7 @@ async function checkSums(ctx, algorithm, files, quiet) {
|
|
|
15742
15744
|
}
|
|
15743
15745
|
}
|
|
15744
15746
|
if (failures > 0) ctx.warn(`WARNING: ${failures} computed checksum${failures === 1 ? "" : "s"} did NOT match`);
|
|
15745
|
-
return
|
|
15747
|
+
return ok2 && failures === 0 && checked > 0 ? 0 : 1;
|
|
15746
15748
|
}
|
|
15747
15749
|
var md5sum = makeSum("md5sum", "md5", "/usr/bin/md5sum");
|
|
15748
15750
|
var sha1sum = makeSum("sha1sum", "sha1", "/usr/bin/sha1sum");
|
|
@@ -15755,11 +15757,11 @@ var cksum = defineCommand({
|
|
|
15755
15757
|
path: "/usr/bin/cksum",
|
|
15756
15758
|
summary: "checksum and count the bytes in a file",
|
|
15757
15759
|
async run(ctx) {
|
|
15758
|
-
const { sources, ok } = await readInputs(ctx, ctx.args, { stdinName: "" });
|
|
15760
|
+
const { sources, ok: ok2 } = await readInputs(ctx, ctx.args, { stdinName: "" });
|
|
15759
15761
|
for (const source of sources) {
|
|
15760
15762
|
ctx.line(`${crc32(source.bytes)} ${source.bytes.length}${source.name ? ` ${source.name}` : ""}`);
|
|
15761
15763
|
}
|
|
15762
|
-
return
|
|
15764
|
+
return ok2 ? 0 : 1;
|
|
15763
15765
|
}
|
|
15764
15766
|
});
|
|
15765
15767
|
var CRC_TABLE = (() => {
|
|
@@ -15787,7 +15789,7 @@ var base64Cmd = defineCommand({
|
|
|
15787
15789
|
{ short: "i", long: "ignore-garbage" },
|
|
15788
15790
|
{ short: "w", long: "wrap", arg: true, default: "76" }
|
|
15789
15791
|
]);
|
|
15790
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
15792
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
15791
15793
|
for (const source of sources) {
|
|
15792
15794
|
if (args.has("decode")) {
|
|
15793
15795
|
const text2 = new TextDecoder().decode(source.bytes).replace(/\s+/g, "");
|
|
@@ -15799,14 +15801,14 @@ var base64Cmd = defineCommand({
|
|
|
15799
15801
|
continue;
|
|
15800
15802
|
}
|
|
15801
15803
|
const encoded = Buffer.from(source.bytes).toString("base64");
|
|
15802
|
-
const
|
|
15803
|
-
if (
|
|
15804
|
+
const wrap2 = args.num("wrap", 76);
|
|
15805
|
+
if (wrap2 <= 0) {
|
|
15804
15806
|
ctx.line(encoded);
|
|
15805
15807
|
continue;
|
|
15806
15808
|
}
|
|
15807
|
-
for (let i = 0; i < encoded.length; i +=
|
|
15809
|
+
for (let i = 0; i < encoded.length; i += wrap2) ctx.line(encoded.slice(i, i + wrap2));
|
|
15808
15810
|
}
|
|
15809
|
-
return
|
|
15811
|
+
return ok2 ? 0 : 1;
|
|
15810
15812
|
}
|
|
15811
15813
|
});
|
|
15812
15814
|
var base32Cmd = defineCommand({
|
|
@@ -15815,7 +15817,7 @@ var base32Cmd = defineCommand({
|
|
|
15815
15817
|
summary: "base32 encode/decode data",
|
|
15816
15818
|
async run(ctx) {
|
|
15817
15819
|
const args = parseArgs(ctx.args, [{ short: "d", long: "decode" }, { short: "w", long: "wrap", arg: true, default: "76" }]);
|
|
15818
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
15820
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
15819
15821
|
const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
15820
15822
|
for (const source of sources) {
|
|
15821
15823
|
if (args.has("decode")) {
|
|
@@ -15849,10 +15851,10 @@ var base32Cmd = defineCommand({
|
|
|
15849
15851
|
}
|
|
15850
15852
|
if (bits > 0) out += ALPHABET[value << 5 - bits & 31];
|
|
15851
15853
|
while (out.length % 8 !== 0) out += "=";
|
|
15852
|
-
const
|
|
15853
|
-
for (let i = 0; i < out.length; i +=
|
|
15854
|
+
const wrap2 = args.num("wrap", 76);
|
|
15855
|
+
for (let i = 0; i < out.length; i += wrap2) ctx.line(out.slice(i, i + wrap2));
|
|
15854
15856
|
}
|
|
15855
|
-
return
|
|
15857
|
+
return ok2 ? 0 : 1;
|
|
15856
15858
|
}
|
|
15857
15859
|
});
|
|
15858
15860
|
var uuidgen = defineCommand({
|
|
@@ -15916,6 +15918,9 @@ function parseUrl(raw) {
|
|
|
15916
15918
|
return null;
|
|
15917
15919
|
}
|
|
15918
15920
|
}
|
|
15921
|
+
function isBrowser() {
|
|
15922
|
+
return typeof process === "undefined" || process.versions?.node == null;
|
|
15923
|
+
}
|
|
15919
15924
|
async function performRequest(ctx, url, init) {
|
|
15920
15925
|
const isLocal = ctx.kernel.net.isLocal(url.hostname);
|
|
15921
15926
|
if (isLocal) {
|
|
@@ -15942,11 +15947,18 @@ async function performRequest(ctx, url, init) {
|
|
|
15942
15947
|
`outbound network access to ${url.hostname} is disabled for this container (enable with network: { allowOutbound: true })`
|
|
15943
15948
|
);
|
|
15944
15949
|
}
|
|
15945
|
-
|
|
15946
|
-
|
|
15947
|
-
|
|
15948
|
-
|
|
15949
|
-
|
|
15950
|
+
let response;
|
|
15951
|
+
try {
|
|
15952
|
+
response = await fetch(url.toString(), {
|
|
15953
|
+
method: init.method,
|
|
15954
|
+
headers: init.headers,
|
|
15955
|
+
...init.body ? { body: init.body.slice().buffer } : {}
|
|
15956
|
+
});
|
|
15957
|
+
} catch (error) {
|
|
15958
|
+
throw isBrowser() ? new Error(
|
|
15959
|
+
`${error instanceof Error ? error.message : String(error)} \u2014 the request to ${url.hostname} was blocked by the browser. A page can only read a response from a host that sends CORS headers; route it through a proxy on your own origin, or run the container on a server.`
|
|
15960
|
+
) : error;
|
|
15961
|
+
}
|
|
15950
15962
|
const body = new Uint8Array(await response.arrayBuffer());
|
|
15951
15963
|
ctx.kernel.net.countRx(body.length);
|
|
15952
15964
|
const headers = {};
|
|
@@ -16925,7 +16937,7 @@ var less = defineCommand({
|
|
|
16925
16937
|
{ short: "X" },
|
|
16926
16938
|
{ short: "n" }
|
|
16927
16939
|
]);
|
|
16928
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
16940
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
16929
16941
|
let lineNumber = 1;
|
|
16930
16942
|
for (const source of sources) {
|
|
16931
16943
|
if (!args.has("N")) {
|
|
@@ -16936,7 +16948,7 @@ var less = defineCommand({
|
|
|
16936
16948
|
ctx.line(`${String(lineNumber++).padStart(6)} ${line}`);
|
|
16937
16949
|
}
|
|
16938
16950
|
}
|
|
16939
|
-
return
|
|
16951
|
+
return ok2 ? 0 : 1;
|
|
16940
16952
|
}
|
|
16941
16953
|
});
|
|
16942
16954
|
var helpCmd = defineCommand({
|
|
@@ -17028,13 +17040,19 @@ ${stdinPath === null ? "" : `(function () {
|
|
|
17028
17040
|
}
|
|
17029
17041
|
async function execute(ctx, invocation) {
|
|
17030
17042
|
const { pod } = ctx.kernel;
|
|
17043
|
+
const interactive = ctx.stdin.interactive || ctx.stdin.isTTY;
|
|
17031
17044
|
let exitCode = 0;
|
|
17032
17045
|
try {
|
|
17033
17046
|
const proc = await pod.spawn("node", [invocation.script], {
|
|
17034
17047
|
cwd: ctx.cwd,
|
|
17035
17048
|
env: { ...ctx.env, PWD: ctx.cwd },
|
|
17036
17049
|
argv: ["/usr/bin/node", invocation.argvPath ?? invocation.script, ...invocation.argv],
|
|
17037
|
-
...invocation.stdinPath ? { stdinPath: invocation.stdinPath } : {}
|
|
17050
|
+
...invocation.stdinPath ? { stdinPath: invocation.stdinPath } : {},
|
|
17051
|
+
/* An interactive caller's input was not captured to a file, so the
|
|
17052
|
+
* program's stdin has to stay open and be fed as it arrives — and be
|
|
17053
|
+
* reported as a terminal, since that is what decides whether a CLI
|
|
17054
|
+
* prompts or takes its defaults. */
|
|
17055
|
+
...interactive ? { interactiveStdin: true, tty: true } : {}
|
|
17038
17056
|
});
|
|
17039
17057
|
proc.on("output", (chunk) => {
|
|
17040
17058
|
try {
|
|
@@ -17048,13 +17066,19 @@ async function execute(ctx, invocation) {
|
|
|
17048
17066
|
} catch {
|
|
17049
17067
|
}
|
|
17050
17068
|
});
|
|
17069
|
+
proc.on("rawmode", (enabled) => {
|
|
17070
|
+
ctx.stdin.rawMode = enabled;
|
|
17071
|
+
});
|
|
17051
17072
|
let forwarding = false;
|
|
17052
|
-
if (
|
|
17073
|
+
if (interactive) {
|
|
17053
17074
|
forwarding = true;
|
|
17054
17075
|
void (async () => {
|
|
17055
17076
|
while (forwarding) {
|
|
17056
17077
|
const chunk = await ctx.stdin.read();
|
|
17057
|
-
if (chunk === null)
|
|
17078
|
+
if (chunk === null) {
|
|
17079
|
+
proc.endInput?.();
|
|
17080
|
+
break;
|
|
17081
|
+
}
|
|
17058
17082
|
try {
|
|
17059
17083
|
proc.write(new TextDecoder().decode(chunk));
|
|
17060
17084
|
} catch {
|
|
@@ -17095,10 +17119,10 @@ async function execute(ctx, invocation) {
|
|
|
17095
17119
|
}
|
|
17096
17120
|
async function captureStdin(ctx) {
|
|
17097
17121
|
if (ctx.stdin.isTTY || ctx.stdin.interactive) return null;
|
|
17098
|
-
const
|
|
17099
|
-
if (
|
|
17122
|
+
const bytes2 = await ctx.stdin.readAll();
|
|
17123
|
+
if (bytes2.length === 0) return null;
|
|
17100
17124
|
const path = tempPath("stdin", ctx.proc.pid, ".dat");
|
|
17101
|
-
ctx.vfs.writeFile(path,
|
|
17125
|
+
ctx.vfs.writeFile(path, bytes2, { privileged: true, mode: 384 });
|
|
17102
17126
|
return path;
|
|
17103
17127
|
}
|
|
17104
17128
|
var node = defineCommand({
|
|
@@ -17233,8 +17257,8 @@ ${prelude}${source}
|
|
|
17233
17257
|
`;
|
|
17234
17258
|
}
|
|
17235
17259
|
function resolveScript(ctx, operand) {
|
|
17236
|
-
const
|
|
17237
|
-
const candidates = [
|
|
17260
|
+
const base2 = ctx.path(operand);
|
|
17261
|
+
const candidates = [base2, `${base2}.js`, `${base2}.mjs`, `${base2}.cjs`, `${base2}.json`];
|
|
17238
17262
|
for (const candidate of candidates) {
|
|
17239
17263
|
try {
|
|
17240
17264
|
const st = ctx.vfs.stat(candidate, { cred: ctx.cred });
|
|
@@ -17811,12 +17835,12 @@ async function runCPythonProgram(ctx, source, argv, scriptDir, stdinText) {
|
|
|
17811
17835
|
}
|
|
17812
17836
|
});
|
|
17813
17837
|
if (stdinText !== null) {
|
|
17814
|
-
const
|
|
17838
|
+
const bytes2 = encoder7.encode(stdinText);
|
|
17815
17839
|
let offset = 0;
|
|
17816
17840
|
py.setStdin({
|
|
17817
17841
|
read: (buffer) => {
|
|
17818
|
-
const take = Math.min(buffer.length,
|
|
17819
|
-
buffer.set(
|
|
17842
|
+
const take = Math.min(buffer.length, bytes2.length - offset);
|
|
17843
|
+
buffer.set(bytes2.subarray(offset, offset + take));
|
|
17820
17844
|
offset += take;
|
|
17821
17845
|
return take;
|
|
17822
17846
|
}
|
|
@@ -17958,8 +17982,8 @@ function configurePython(options = {}) {
|
|
|
17958
17982
|
var isPythonAvailable = isCPythonAvailable;
|
|
17959
17983
|
async function readStdin(ctx) {
|
|
17960
17984
|
if (ctx.stdin.isTTY || ctx.stdin.interactive) return null;
|
|
17961
|
-
const
|
|
17962
|
-
return
|
|
17985
|
+
const bytes2 = await ctx.stdin.readAll();
|
|
17986
|
+
return bytes2.length ? new TextDecoder().decode(bytes2) : null;
|
|
17963
17987
|
}
|
|
17964
17988
|
var python = defineCommand({
|
|
17965
17989
|
name: "python3",
|
|
@@ -18070,17 +18094,17 @@ async function loadFactory() {
|
|
|
18070
18094
|
}
|
|
18071
18095
|
const wasmPath = require2.resolve("@ffmpeg/core/wasm");
|
|
18072
18096
|
const wasm = await fs.readFile(wasmPath);
|
|
18073
|
-
const module = await
|
|
18097
|
+
const module = await nodeOnlyModule("@ffmpeg/core");
|
|
18074
18098
|
return { factory: module.default, wasm: new Uint8Array(wasm) };
|
|
18075
18099
|
}
|
|
18076
18100
|
function getCompiled() {
|
|
18077
18101
|
compiled ??= (async () => {
|
|
18078
18102
|
const { factory, wasm } = await loadFactory();
|
|
18079
|
-
const
|
|
18103
|
+
const bytes2 = wasm.buffer.slice(
|
|
18080
18104
|
wasm.byteOffset,
|
|
18081
18105
|
wasm.byteOffset + wasm.byteLength
|
|
18082
18106
|
);
|
|
18083
|
-
return { factory, module: await WebAssembly.compile(
|
|
18107
|
+
return { factory, module: await WebAssembly.compile(bytes2) };
|
|
18084
18108
|
})();
|
|
18085
18109
|
void compiled.catch(() => compiled = null);
|
|
18086
18110
|
return compiled;
|
|
@@ -18155,6 +18179,34 @@ var ffprobe = defineCommand({
|
|
|
18155
18179
|
function ffmpegCommands() {
|
|
18156
18180
|
return [ffmpeg, ffprobe];
|
|
18157
18181
|
}
|
|
18182
|
+
var platformBuffer = globalThis.Buffer;
|
|
18183
|
+
var Buffer2 = platformBuffer ?? addBase64UrlSupport(index_js.Buffer);
|
|
18184
|
+
function addBase64UrlSupport(BufferClass) {
|
|
18185
|
+
const target = BufferClass;
|
|
18186
|
+
if (target.__sandboxedBase64Url) return BufferClass;
|
|
18187
|
+
Object.defineProperty(target, "__sandboxedBase64Url", { value: true });
|
|
18188
|
+
const from = target.from.bind(target);
|
|
18189
|
+
target.from = (value, encodingOrOffset, length) => from(value, normalizeEncoding(encodingOrOffset), length);
|
|
18190
|
+
const byteLength = target.byteLength.bind(target);
|
|
18191
|
+
target.byteLength = (value, encoding) => byteLength(value, normalizeEncoding(encoding));
|
|
18192
|
+
const isEncoding = target.isEncoding?.bind(target);
|
|
18193
|
+
if (isEncoding) target.isEncoding = (encoding) => encoding.toLowerCase() === "base64url" || isEncoding(encoding);
|
|
18194
|
+
const toString = target.prototype.toString;
|
|
18195
|
+
target.prototype.toString = function(encoding, start2, end) {
|
|
18196
|
+
if (encoding?.toLowerCase() !== "base64url") return toString.call(this, encoding, start2, end);
|
|
18197
|
+
return toString.call(this, "base64", start2, end).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
18198
|
+
};
|
|
18199
|
+
const write = target.prototype.write;
|
|
18200
|
+
target.prototype.write = function(...args) {
|
|
18201
|
+
const index = typeof args[1] === "string" ? 1 : typeof args[2] === "string" ? 2 : 3;
|
|
18202
|
+
if (typeof args[index] === "string") args[index] = normalizeEncoding(args[index]);
|
|
18203
|
+
return write.apply(this, args);
|
|
18204
|
+
};
|
|
18205
|
+
return BufferClass;
|
|
18206
|
+
}
|
|
18207
|
+
function normalizeEncoding(value) {
|
|
18208
|
+
return typeof value === "string" && value.toLowerCase() === "base64url" ? "base64" : value;
|
|
18209
|
+
}
|
|
18158
18210
|
|
|
18159
18211
|
// src/pkg/clean-installer.ts
|
|
18160
18212
|
init_path();
|
|
@@ -18196,10 +18248,13 @@ var CleanPackageInstaller = class _CleanPackageInstaller {
|
|
|
18196
18248
|
const version = resolveVersion(metadata, range);
|
|
18197
18249
|
const manifest = metadata.versions[version];
|
|
18198
18250
|
if (!manifest) throw new Error(`No matching version found for ${name}@${range}`);
|
|
18251
|
+
if (!supportsPlatform(manifest)) {
|
|
18252
|
+
throw new Error(`${name}@${version} is not compatible with linux/x64/glibc`);
|
|
18253
|
+
}
|
|
18199
18254
|
const identity = `${name}@${version}`;
|
|
18200
18255
|
const target = join(modulesRoot, name);
|
|
18201
|
-
const
|
|
18202
|
-
if (
|
|
18256
|
+
const installed2 = this.tryReadJson(join(target, "package.json"));
|
|
18257
|
+
if (installed2?.version === version) return installed2;
|
|
18203
18258
|
if (ancestry.has(identity)) return manifest;
|
|
18204
18259
|
options.onProgress?.(`Fetching ${identity}`);
|
|
18205
18260
|
const archive = await this.getTarball(manifest.dist.tarball);
|
|
@@ -18290,9 +18345,18 @@ var CleanPackageInstaller = class _CleanPackageInstaller {
|
|
|
18290
18345
|
}
|
|
18291
18346
|
}
|
|
18292
18347
|
};
|
|
18348
|
+
function supportsPlatform(manifest) {
|
|
18349
|
+
return !manifest.main?.endsWith(".node") && platformListAllows(manifest.os, "linux") && platformListAllows(manifest.cpu, "x64") && platformListAllows(manifest.libc, "glibc");
|
|
18350
|
+
}
|
|
18351
|
+
function platformListAllows(values, current) {
|
|
18352
|
+
if (!values?.length) return true;
|
|
18353
|
+
if (values.includes(`!${current}`)) return false;
|
|
18354
|
+
const positive = values.filter((value) => !value.startsWith("!"));
|
|
18355
|
+
return positive.length === 0 || positive.includes(current) || positive.includes("any");
|
|
18356
|
+
}
|
|
18293
18357
|
function resolveVersion(metadata, range) {
|
|
18294
|
-
const
|
|
18295
|
-
if (
|
|
18358
|
+
const tag2 = metadata["dist-tags"]?.[range];
|
|
18359
|
+
if (tag2) return tag2;
|
|
18296
18360
|
if (semver.valid(range) && metadata.versions[range]) return range;
|
|
18297
18361
|
const found = semver.maxSatisfying(Object.keys(metadata.versions), range === "latest" ? "*" : range, { includePrerelease: false });
|
|
18298
18362
|
if (!found) throw new Error(`No matching version found for ${metadata.name}@${range}`);
|
|
@@ -18306,11 +18370,11 @@ function verifyIntegrity(data, integrity, shasum, identity) {
|
|
|
18306
18370
|
const algorithm = choice.slice(0, dash);
|
|
18307
18371
|
const expected = choice.slice(dash + 1).replace(/\?.*$/, "");
|
|
18308
18372
|
const digest = algorithm === "sha512" ? sha512.sha512(data) : algorithm === "sha256" ? sha256.sha256(data) : null;
|
|
18309
|
-
if (digest &&
|
|
18373
|
+
if (digest && Buffer2.from(digest).toString("base64") === expected) return;
|
|
18310
18374
|
}
|
|
18311
18375
|
throw new Error(`Integrity check failed for ${identity}`);
|
|
18312
18376
|
}
|
|
18313
|
-
if (shasum &&
|
|
18377
|
+
if (shasum && Buffer2.from(sha1.sha1(data)).toString("hex") === shasum) return;
|
|
18314
18378
|
if (shasum) throw new Error(`Legacy checksum check failed for ${identity}`);
|
|
18315
18379
|
}
|
|
18316
18380
|
function extractNpmTarball(volume, compressed, destination) {
|
|
@@ -18376,11 +18440,11 @@ function safeTarget(destination, name) {
|
|
|
18376
18440
|
function stripPackageRoot(name) {
|
|
18377
18441
|
return name.replace(/^\.\//, "").replace(/^package\//, "").replace(/\/$/, "");
|
|
18378
18442
|
}
|
|
18379
|
-
function text(
|
|
18380
|
-
return new TextDecoder().decode(
|
|
18443
|
+
function text(bytes2, start2, length) {
|
|
18444
|
+
return new TextDecoder().decode(bytes2.subarray(start2, start2 + length)).replace(/\0.*$/, "").trim();
|
|
18381
18445
|
}
|
|
18382
|
-
function octal(
|
|
18383
|
-
return parseInt(text(
|
|
18446
|
+
function octal(bytes2, start2, length) {
|
|
18447
|
+
return parseInt(text(bytes2, start2, length).replace(/^0+/, "") || "0", 8);
|
|
18384
18448
|
}
|
|
18385
18449
|
function parsePax(data) {
|
|
18386
18450
|
const value = new TextDecoder().decode(data);
|
|
@@ -18392,8 +18456,8 @@ function parsePax(data) {
|
|
|
18392
18456
|
const length = Number(value.slice(offset, space));
|
|
18393
18457
|
if (!Number.isFinite(length) || length <= 0) break;
|
|
18394
18458
|
const record = value.slice(space + 1, offset + length - 1);
|
|
18395
|
-
const
|
|
18396
|
-
if (
|
|
18459
|
+
const equal2 = record.indexOf("=");
|
|
18460
|
+
if (equal2 > 0) result[record.slice(0, equal2)] = record.slice(equal2 + 1);
|
|
18397
18461
|
offset += length;
|
|
18398
18462
|
}
|
|
18399
18463
|
return result;
|
|
@@ -18967,6 +19031,13 @@ function findLocalBin(ctx, name) {
|
|
|
18967
19031
|
}
|
|
18968
19032
|
async function runInitializer(ctx, args) {
|
|
18969
19033
|
const [spec, ...rest] = args;
|
|
19034
|
+
if (!spec) {
|
|
19035
|
+
ctx.warn("npm create <initializer>");
|
|
19036
|
+
ctx.warn("");
|
|
19037
|
+
ctx.warn("Runs the package `create-<initializer>`, installing it if needed.");
|
|
19038
|
+
ctx.warn("Example: npm create vite@latest my-app");
|
|
19039
|
+
return 1;
|
|
19040
|
+
}
|
|
18970
19041
|
const { name, version } = splitPackageSpec(spec);
|
|
18971
19042
|
const suffix = version ? `@${version}` : "";
|
|
18972
19043
|
let packageName;
|
|
@@ -19069,12 +19140,12 @@ unless the container was created with network: { allowOutbound: true }.`,
|
|
|
19069
19140
|
}
|
|
19070
19141
|
ctx.stderr.write(`npx: installing ${packageSpec}...
|
|
19071
19142
|
`);
|
|
19072
|
-
const
|
|
19143
|
+
const installed2 = await installPackages(ctx, [packageSpec], {
|
|
19073
19144
|
cwd: root,
|
|
19074
19145
|
save: false,
|
|
19075
19146
|
quiet: true
|
|
19076
19147
|
});
|
|
19077
|
-
if (
|
|
19148
|
+
if (installed2 !== 0) return installed2;
|
|
19078
19149
|
if (!findLocalBin(ctx, command)) {
|
|
19079
19150
|
const binaries = packageBinaries(ctx, root, packageName);
|
|
19080
19151
|
const chosen = binaries.includes(command) ? command : binaries[0];
|
|
@@ -19303,8 +19374,8 @@ var ContainerFs = class {
|
|
|
19303
19374
|
return this.kernel.vfs;
|
|
19304
19375
|
}
|
|
19305
19376
|
async readFile(path, encoding) {
|
|
19306
|
-
const
|
|
19307
|
-
return encoding ? new TextDecoder().decode(
|
|
19377
|
+
const bytes2 = this.vfs.readFile(clean(path));
|
|
19378
|
+
return encoding ? new TextDecoder().decode(bytes2) : bytes2;
|
|
19308
19379
|
}
|
|
19309
19380
|
async writeFile(path, data, opts = {}) {
|
|
19310
19381
|
const abs = clean(path);
|
|
@@ -20052,6 +20123,18 @@ var CommonJsEngine = class {
|
|
|
20052
20123
|
main = null;
|
|
20053
20124
|
/** `package.json` per directory; resolution reads them constantly. */
|
|
20054
20125
|
manifests = /* @__PURE__ */ new Map();
|
|
20126
|
+
evaluationDepth = 0;
|
|
20127
|
+
/**
|
|
20128
|
+
* Is a module body running synchronously right now?
|
|
20129
|
+
*
|
|
20130
|
+
* `process.exit` unwinds by throwing, and that is only safe while one of
|
|
20131
|
+
* this engine's own frames is on the stack to catch it. Thrown from a later
|
|
20132
|
+
* callback — a stream handler, a timer — it would escape into whichever
|
|
20133
|
+
* library called that callback and surface as an unrelated crash.
|
|
20134
|
+
*/
|
|
20135
|
+
get isEvaluating() {
|
|
20136
|
+
return this.evaluationDepth > 0;
|
|
20137
|
+
}
|
|
20055
20138
|
/**
|
|
20056
20139
|
* Evaluate an entry point.
|
|
20057
20140
|
*
|
|
@@ -20157,7 +20240,13 @@ ${code}
|
|
|
20157
20240
|
};
|
|
20158
20241
|
//# sourceURL=sandboxedjs:${module.filename}`
|
|
20159
20242
|
)(this.globals);
|
|
20160
|
-
|
|
20243
|
+
this.evaluationDepth++;
|
|
20244
|
+
let result;
|
|
20245
|
+
try {
|
|
20246
|
+
result = factory(...bindings.map(([, value]) => value));
|
|
20247
|
+
} finally {
|
|
20248
|
+
this.evaluationDepth--;
|
|
20249
|
+
}
|
|
20161
20250
|
if (transformed?.topLevelAwait) module.pending = Promise.resolve(result).then(() => {
|
|
20162
20251
|
});
|
|
20163
20252
|
}
|
|
@@ -20454,9 +20543,717 @@ function splitSpecifier(specifier) {
|
|
|
20454
20543
|
return { name: parts.slice(0, size).join("/"), subpath: parts.slice(size).join("/") };
|
|
20455
20544
|
}
|
|
20456
20545
|
|
|
20546
|
+
// src/runtime/util-module.ts
|
|
20547
|
+
var customInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
20548
|
+
var promisifyCustom = /* @__PURE__ */ Symbol.for("nodejs.util.promisify.custom");
|
|
20549
|
+
var BREAK_LENGTH = 72;
|
|
20550
|
+
var MAX_ARRAY = 100;
|
|
20551
|
+
function inspect(value, options = {}) {
|
|
20552
|
+
const depth = options.depth === null ? Infinity : options.depth ?? 2;
|
|
20553
|
+
return render(value, depth, /* @__PURE__ */ new Set(), options);
|
|
20554
|
+
}
|
|
20555
|
+
function render(value, depth, seen, options) {
|
|
20556
|
+
switch (typeof value) {
|
|
20557
|
+
case "string":
|
|
20558
|
+
return quote2(value, options.maxStringLength ?? null);
|
|
20559
|
+
case "number":
|
|
20560
|
+
return Object.is(value, -0) ? "-0" : String(value);
|
|
20561
|
+
case "bigint":
|
|
20562
|
+
return `${value}n`;
|
|
20563
|
+
case "boolean":
|
|
20564
|
+
case "undefined":
|
|
20565
|
+
return String(value);
|
|
20566
|
+
case "symbol":
|
|
20567
|
+
return value.toString();
|
|
20568
|
+
case "function":
|
|
20569
|
+
return renderFunction(value);
|
|
20570
|
+
}
|
|
20571
|
+
if (value === null) return "null";
|
|
20572
|
+
const object = value;
|
|
20573
|
+
const custom = object[customInspect];
|
|
20574
|
+
if (typeof custom === "function") {
|
|
20575
|
+
return String(custom.call(object, depth, options));
|
|
20576
|
+
}
|
|
20577
|
+
if (seen.has(object)) return "[Circular *1]";
|
|
20578
|
+
if (depth < 0) return Array.isArray(object) ? "[Array]" : "[Object]";
|
|
20579
|
+
if (value instanceof Error) return renderError(value);
|
|
20580
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
|
|
20581
|
+
if (value instanceof RegExp) return String(value);
|
|
20582
|
+
if (Buffer2.isBuffer(value)) return renderBuffer(value);
|
|
20583
|
+
if (ArrayBuffer.isView(value)) return renderTypedArray(value);
|
|
20584
|
+
seen.add(object);
|
|
20585
|
+
try {
|
|
20586
|
+
if (Array.isArray(value)) return wrap(renderArray(value, depth, seen, options), "[", "]");
|
|
20587
|
+
if (value instanceof Map) return prefixed("Map", value.size, renderMap(value, depth, seen, options));
|
|
20588
|
+
if (value instanceof Set) return prefixed("Set", value.size, renderSet(value, depth, seen, options));
|
|
20589
|
+
if (value instanceof Promise) return "Promise { <pending> }";
|
|
20590
|
+
return renderObject(object, depth, seen, options);
|
|
20591
|
+
} finally {
|
|
20592
|
+
seen.delete(object);
|
|
20593
|
+
}
|
|
20594
|
+
}
|
|
20595
|
+
function renderArray(value, depth, seen, options) {
|
|
20596
|
+
const limit = options.maxArrayLength === null ? Infinity : options.maxArrayLength ?? MAX_ARRAY;
|
|
20597
|
+
const shown = value.slice(0, limit).map((item) => render(item, depth - 1, seen, options));
|
|
20598
|
+
const hidden = value.length - shown.length;
|
|
20599
|
+
if (hidden > 0) shown.push(`... ${hidden} more item${hidden === 1 ? "" : "s"}`);
|
|
20600
|
+
return shown;
|
|
20601
|
+
}
|
|
20602
|
+
function renderMap(value, depth, seen, options) {
|
|
20603
|
+
return [...value].map(
|
|
20604
|
+
([key, item]) => `${render(key, depth - 1, seen, options)} => ${render(item, depth - 1, seen, options)}`
|
|
20605
|
+
);
|
|
20606
|
+
}
|
|
20607
|
+
function renderSet(value, depth, seen, options) {
|
|
20608
|
+
return [...value].map((item) => render(item, depth - 1, seen, options));
|
|
20609
|
+
}
|
|
20610
|
+
function renderObject(object, depth, seen, options) {
|
|
20611
|
+
const keys = options.showHidden ? Object.getOwnPropertyNames(object) : Object.keys(object);
|
|
20612
|
+
if (options.sorted) keys.sort();
|
|
20613
|
+
const parts = keys.map((key) => {
|
|
20614
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
20615
|
+
const rendered = descriptor?.get ? descriptor.set ? "[Getter/Setter]" : "[Getter]" : render(object[key], depth - 1, seen, options);
|
|
20616
|
+
return `${propertyKey(key)}: ${rendered}`;
|
|
20617
|
+
});
|
|
20618
|
+
const name = constructorName(object);
|
|
20619
|
+
return wrap(parts, name ? `${name} {` : "{", "}", name ? void 0 : "{}");
|
|
20620
|
+
}
|
|
20621
|
+
function constructorName(object) {
|
|
20622
|
+
const name = Object.getPrototypeOf(object)?.constructor?.name;
|
|
20623
|
+
if (!name || name === "Object") return null;
|
|
20624
|
+
return name;
|
|
20625
|
+
}
|
|
20626
|
+
function renderError(error) {
|
|
20627
|
+
const base2 = error.stack ?? `${error.name}: ${error.message}`;
|
|
20628
|
+
const extra = Object.keys(error).filter((key) => key !== "message" && key !== "stack");
|
|
20629
|
+
if (extra.length === 0) return base2;
|
|
20630
|
+
return `${base2} { ${extra.map((key) => `${propertyKey(key)}: ${inspect(error[key], { depth: 0 })}`).join(", ")} }`;
|
|
20631
|
+
}
|
|
20632
|
+
function renderFunction(value) {
|
|
20633
|
+
const kind = /^class[\s{]/.test(Function.prototype.toString.call(value)) ? "class" : "Function";
|
|
20634
|
+
return value.name ? `[${kind}: ${value.name}]` : `[${kind} (anonymous)]`;
|
|
20635
|
+
}
|
|
20636
|
+
function renderBuffer(value) {
|
|
20637
|
+
const shown = [...value.subarray(0, 50)].map((byte) => byte.toString(16).padStart(2, "0"));
|
|
20638
|
+
const hidden = value.length - shown.length;
|
|
20639
|
+
const tail2 = hidden > 0 ? ` ... ${hidden} more byte${hidden === 1 ? "" : "s"}` : "";
|
|
20640
|
+
return `<Buffer ${shown.join(" ")}${tail2}>`;
|
|
20641
|
+
}
|
|
20642
|
+
function renderTypedArray(value) {
|
|
20643
|
+
const name = value.constructor?.name ?? "TypedArray";
|
|
20644
|
+
const items = [...value].slice(0, MAX_ARRAY);
|
|
20645
|
+
return `${name}(${value.length}) [ ${items.join(", ")} ]`;
|
|
20646
|
+
}
|
|
20647
|
+
function prefixed(name, size, parts) {
|
|
20648
|
+
return wrap(parts, `${name}(${size}) {`, "}", `${name}(0) {}`);
|
|
20649
|
+
}
|
|
20650
|
+
function wrap(parts, open, close, empty) {
|
|
20651
|
+
if (parts.length === 0) return empty ?? `${open}${close}`;
|
|
20652
|
+
const inline = `${open} ${parts.join(", ")} ${close}`;
|
|
20653
|
+
if (inline.length <= BREAK_LENGTH && !inline.includes("\n")) return inline;
|
|
20654
|
+
const indented = parts.map((part) => ` ${part.split("\n").join("\n ")}`);
|
|
20655
|
+
return `${open}
|
|
20656
|
+
${indented.join(",\n")}
|
|
20657
|
+
${close}`;
|
|
20658
|
+
}
|
|
20659
|
+
function quote2(value, maxLength) {
|
|
20660
|
+
let text2 = value;
|
|
20661
|
+
let tail2 = "";
|
|
20662
|
+
if (maxLength !== null && text2.length > maxLength) {
|
|
20663
|
+
tail2 = `... ${text2.length - maxLength} more character${text2.length - maxLength === 1 ? "" : "s"}`;
|
|
20664
|
+
text2 = text2.slice(0, maxLength);
|
|
20665
|
+
}
|
|
20666
|
+
const escaped = text2.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/'/g, "\\'");
|
|
20667
|
+
return `'${escaped}'${tail2}`;
|
|
20668
|
+
}
|
|
20669
|
+
function propertyKey(key) {
|
|
20670
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : quote2(key, null);
|
|
20671
|
+
}
|
|
20672
|
+
function format(...args) {
|
|
20673
|
+
return formatWithOptions({}, ...args);
|
|
20674
|
+
}
|
|
20675
|
+
function formatWithOptions(options, ...args) {
|
|
20676
|
+
const [first, ...rest] = args;
|
|
20677
|
+
const pieces = [];
|
|
20678
|
+
let index = 0;
|
|
20679
|
+
if (typeof first === "string" && first.includes("%")) {
|
|
20680
|
+
pieces.push(
|
|
20681
|
+
first.replace(/%([sdifjoOc%])/g, (match2, kind) => {
|
|
20682
|
+
if (kind === "%") return "%";
|
|
20683
|
+
if (index >= rest.length) return match2;
|
|
20684
|
+
const value = rest[index++];
|
|
20685
|
+
switch (kind) {
|
|
20686
|
+
case "s":
|
|
20687
|
+
return typeof value === "string" ? value : typeof value === "bigint" ? `${value}n` : typeof value === "object" && value !== null ? inspect(value, { ...options, depth: 0 }) : String(value);
|
|
20688
|
+
case "d":
|
|
20689
|
+
return typeof value === "bigint" ? `${value}n` : String(Number(value));
|
|
20690
|
+
case "i":
|
|
20691
|
+
return typeof value === "bigint" ? `${value}n` : String(parseInt(String(value), 10));
|
|
20692
|
+
case "f":
|
|
20693
|
+
return String(parseFloat(String(value)));
|
|
20694
|
+
case "j":
|
|
20695
|
+
try {
|
|
20696
|
+
return JSON.stringify(value) ?? "undefined";
|
|
20697
|
+
} catch {
|
|
20698
|
+
return "[Circular]";
|
|
20699
|
+
}
|
|
20700
|
+
case "o":
|
|
20701
|
+
return inspect(value, { ...options, showHidden: true, depth: 4 });
|
|
20702
|
+
case "O":
|
|
20703
|
+
return inspect(value, options);
|
|
20704
|
+
case "c":
|
|
20705
|
+
return "";
|
|
20706
|
+
default:
|
|
20707
|
+
return match2;
|
|
20708
|
+
}
|
|
20709
|
+
})
|
|
20710
|
+
);
|
|
20711
|
+
} else if (first !== void 0 || args.length > 0) {
|
|
20712
|
+
pieces.push(typeof first === "string" ? first : inspect(first, options));
|
|
20713
|
+
}
|
|
20714
|
+
for (; index < rest.length; index++) {
|
|
20715
|
+
const value = rest[index];
|
|
20716
|
+
pieces.push(typeof value === "string" ? value : inspect(value, options));
|
|
20717
|
+
}
|
|
20718
|
+
return pieces.join(" ");
|
|
20719
|
+
}
|
|
20720
|
+
function promisify(original) {
|
|
20721
|
+
if (typeof original !== "function") {
|
|
20722
|
+
throw Object.assign(new TypeError('The "original" argument must be of type function'), {
|
|
20723
|
+
code: "ERR_INVALID_ARG_TYPE"
|
|
20724
|
+
});
|
|
20725
|
+
}
|
|
20726
|
+
const override = original[promisifyCustom];
|
|
20727
|
+
if (typeof override === "function") return override;
|
|
20728
|
+
const wrapped = function(...args) {
|
|
20729
|
+
return new Promise((resolve2, reject) => {
|
|
20730
|
+
original.call(this, ...args, (error, ...values) => {
|
|
20731
|
+
if (error) reject(error);
|
|
20732
|
+
else resolve2(values.length > 1 ? values : values[0]);
|
|
20733
|
+
});
|
|
20734
|
+
});
|
|
20735
|
+
};
|
|
20736
|
+
Object.setPrototypeOf(wrapped, Object.getPrototypeOf(original));
|
|
20737
|
+
Object.defineProperty(wrapped, "name", { value: original.name, configurable: true });
|
|
20738
|
+
return wrapped;
|
|
20739
|
+
}
|
|
20740
|
+
promisify.custom = promisifyCustom;
|
|
20741
|
+
function callbackify(original) {
|
|
20742
|
+
return function(...args) {
|
|
20743
|
+
const callback = args.pop();
|
|
20744
|
+
Promise.resolve(original.apply(this, args)).then(
|
|
20745
|
+
(value) => callback(null, value),
|
|
20746
|
+
/* Node guarantees a truthy first argument, so a rejection with a falsy
|
|
20747
|
+
* reason is wrapped rather than passed through as "no error". */
|
|
20748
|
+
(reason) => callback(reason ?? Object.assign(new Error("Promise was rejected with a falsy value"), { reason }))
|
|
20749
|
+
);
|
|
20750
|
+
};
|
|
20751
|
+
}
|
|
20752
|
+
function inherits(constructor, superConstructor) {
|
|
20753
|
+
Object.defineProperty(constructor, "super_", {
|
|
20754
|
+
value: superConstructor,
|
|
20755
|
+
writable: true,
|
|
20756
|
+
configurable: true
|
|
20757
|
+
});
|
|
20758
|
+
Object.setPrototypeOf(constructor.prototype, superConstructor.prototype);
|
|
20759
|
+
}
|
|
20760
|
+
function deprecate(fn, message) {
|
|
20761
|
+
let warned = false;
|
|
20762
|
+
return function(...args) {
|
|
20763
|
+
if (!warned) {
|
|
20764
|
+
warned = true;
|
|
20765
|
+
console.warn(`DeprecationWarning: ${message}`);
|
|
20766
|
+
}
|
|
20767
|
+
return fn.apply(this, args);
|
|
20768
|
+
};
|
|
20769
|
+
}
|
|
20770
|
+
function debuglog(section, callback) {
|
|
20771
|
+
const noop = Object.assign(() => {
|
|
20772
|
+
}, { enabled: false });
|
|
20773
|
+
callback?.(noop);
|
|
20774
|
+
return noop;
|
|
20775
|
+
}
|
|
20776
|
+
var STYLES = {
|
|
20777
|
+
reset: [0, 0],
|
|
20778
|
+
bold: [1, 22],
|
|
20779
|
+
dim: [2, 22],
|
|
20780
|
+
italic: [3, 23],
|
|
20781
|
+
underline: [4, 24],
|
|
20782
|
+
blink: [5, 25],
|
|
20783
|
+
inverse: [7, 27],
|
|
20784
|
+
hidden: [8, 28],
|
|
20785
|
+
strikethrough: [9, 29],
|
|
20786
|
+
doubleunderline: [21, 24],
|
|
20787
|
+
framed: [51, 54],
|
|
20788
|
+
overlined: [53, 55],
|
|
20789
|
+
black: [30, 39],
|
|
20790
|
+
red: [31, 39],
|
|
20791
|
+
green: [32, 39],
|
|
20792
|
+
yellow: [33, 39],
|
|
20793
|
+
blue: [34, 39],
|
|
20794
|
+
magenta: [35, 39],
|
|
20795
|
+
cyan: [36, 39],
|
|
20796
|
+
white: [37, 39],
|
|
20797
|
+
gray: [90, 39],
|
|
20798
|
+
grey: [90, 39],
|
|
20799
|
+
blackBright: [90, 39],
|
|
20800
|
+
redBright: [91, 39],
|
|
20801
|
+
greenBright: [92, 39],
|
|
20802
|
+
yellowBright: [93, 39],
|
|
20803
|
+
blueBright: [94, 39],
|
|
20804
|
+
magentaBright: [95, 39],
|
|
20805
|
+
cyanBright: [96, 39],
|
|
20806
|
+
whiteBright: [97, 39],
|
|
20807
|
+
bgBlack: [40, 49],
|
|
20808
|
+
bgRed: [41, 49],
|
|
20809
|
+
bgGreen: [42, 49],
|
|
20810
|
+
bgYellow: [43, 49],
|
|
20811
|
+
bgBlue: [44, 49],
|
|
20812
|
+
bgMagenta: [45, 49],
|
|
20813
|
+
bgCyan: [46, 49],
|
|
20814
|
+
bgWhite: [47, 49],
|
|
20815
|
+
bgGray: [100, 49],
|
|
20816
|
+
bgGrey: [100, 49],
|
|
20817
|
+
bgBlackBright: [100, 49],
|
|
20818
|
+
bgRedBright: [101, 49],
|
|
20819
|
+
bgGreenBright: [102, 49],
|
|
20820
|
+
bgYellowBright: [103, 49],
|
|
20821
|
+
bgBlueBright: [104, 49],
|
|
20822
|
+
bgMagentaBright: [105, 49],
|
|
20823
|
+
bgCyanBright: [106, 49],
|
|
20824
|
+
bgWhiteBright: [107, 49]
|
|
20825
|
+
};
|
|
20826
|
+
function styleText(format3, text2) {
|
|
20827
|
+
const names = Array.isArray(format3) ? format3 : [format3];
|
|
20828
|
+
let open = "";
|
|
20829
|
+
let close = "";
|
|
20830
|
+
for (const name of names) {
|
|
20831
|
+
const style = STYLES[name];
|
|
20832
|
+
if (!style) {
|
|
20833
|
+
throw Object.assign(new TypeError(`The value "${name}" is invalid for argument 'format'`), {
|
|
20834
|
+
code: "ERR_INVALID_ARG_VALUE"
|
|
20835
|
+
});
|
|
20836
|
+
}
|
|
20837
|
+
open += `\x1B[${style[0]}m`;
|
|
20838
|
+
close = `\x1B[${style[1]}m${close}`;
|
|
20839
|
+
}
|
|
20840
|
+
return `${open}${text2}${close}`;
|
|
20841
|
+
}
|
|
20842
|
+
var tag = (value) => Object.prototype.toString.call(value).slice(8, -1);
|
|
20843
|
+
var types = {
|
|
20844
|
+
isPromise: (value) => value instanceof Promise || tag(value) === "Promise",
|
|
20845
|
+
isDate: (value) => tag(value) === "Date",
|
|
20846
|
+
isRegExp: (value) => tag(value) === "RegExp",
|
|
20847
|
+
isMap: (value) => tag(value) === "Map",
|
|
20848
|
+
isSet: (value) => tag(value) === "Set",
|
|
20849
|
+
isTypedArray: (value) => ArrayBuffer.isView(value) && !(value instanceof DataView),
|
|
20850
|
+
isUint8Array: (value) => value instanceof Uint8Array,
|
|
20851
|
+
isArrayBuffer: (value) => tag(value) === "ArrayBuffer",
|
|
20852
|
+
isArrayBufferView: (value) => ArrayBuffer.isView(value),
|
|
20853
|
+
isDataView: (value) => value instanceof DataView,
|
|
20854
|
+
isNativeError: (value) => value instanceof Error,
|
|
20855
|
+
isProxy: () => false,
|
|
20856
|
+
isAsyncFunction: (value) => tag(value) === "AsyncFunction",
|
|
20857
|
+
isGeneratorFunction: (value) => tag(value) === "GeneratorFunction",
|
|
20858
|
+
isBoxedPrimitive: (value) => ["String", "Number", "Boolean", "Symbol", "BigInt"].includes(tag(value)) && typeof value === "object"
|
|
20859
|
+
};
|
|
20860
|
+
function isDeepStrictEqual(a, b) {
|
|
20861
|
+
if (Object.is(a, b)) return true;
|
|
20862
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
20863
|
+
if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false;
|
|
20864
|
+
if (Array.isArray(a)) {
|
|
20865
|
+
const other = b;
|
|
20866
|
+
return a.length === other.length && a.every((item, index) => isDeepStrictEqual(item, other[index]));
|
|
20867
|
+
}
|
|
20868
|
+
if (a instanceof Date) return a.getTime() === b.getTime();
|
|
20869
|
+
if (a instanceof RegExp) return String(a) === String(b);
|
|
20870
|
+
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
|
|
20871
|
+
const left = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
20872
|
+
const right = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
|
|
20873
|
+
return left.length === right.length && left.every((byte, index) => byte === right[index]);
|
|
20874
|
+
}
|
|
20875
|
+
const keys = Object.keys(a);
|
|
20876
|
+
if (keys.length !== Object.keys(b).length) return false;
|
|
20877
|
+
return keys.every(
|
|
20878
|
+
(key) => Object.prototype.hasOwnProperty.call(b, key) && isDeepStrictEqual(a[key], b[key])
|
|
20879
|
+
);
|
|
20880
|
+
}
|
|
20881
|
+
var legacy = {
|
|
20882
|
+
isArray: Array.isArray,
|
|
20883
|
+
isBoolean: (value) => typeof value === "boolean",
|
|
20884
|
+
isNull: (value) => value === null,
|
|
20885
|
+
isNullOrUndefined: (value) => value == null,
|
|
20886
|
+
isNumber: (value) => typeof value === "number",
|
|
20887
|
+
isString: (value) => typeof value === "string",
|
|
20888
|
+
isSymbol: (value) => typeof value === "symbol",
|
|
20889
|
+
isUndefined: (value) => value === void 0,
|
|
20890
|
+
isRegExp: types.isRegExp,
|
|
20891
|
+
isObject: (value) => typeof value === "object" && value !== null,
|
|
20892
|
+
isDate: types.isDate,
|
|
20893
|
+
isError: types.isNativeError,
|
|
20894
|
+
isFunction: (value) => typeof value === "function",
|
|
20895
|
+
isPrimitive: (value) => value === null || typeof value !== "object" && typeof value !== "function",
|
|
20896
|
+
isBuffer: (value) => Buffer2.isBuffer(value)
|
|
20897
|
+
};
|
|
20898
|
+
inspect.custom = customInspect;
|
|
20899
|
+
var utilModule = {
|
|
20900
|
+
format,
|
|
20901
|
+
formatWithOptions,
|
|
20902
|
+
inspect,
|
|
20903
|
+
styleText,
|
|
20904
|
+
promisify,
|
|
20905
|
+
callbackify,
|
|
20906
|
+
inherits,
|
|
20907
|
+
deprecate,
|
|
20908
|
+
debuglog,
|
|
20909
|
+
debug: debuglog,
|
|
20910
|
+
types,
|
|
20911
|
+
isDeepStrictEqual,
|
|
20912
|
+
TextEncoder,
|
|
20913
|
+
TextDecoder,
|
|
20914
|
+
toUSVString: (value) => String(value),
|
|
20915
|
+
stripVTControlCharacters: (value) => value.replace(/\x1B\[[0-9;]*[A-Za-z]/g, ""),
|
|
20916
|
+
...legacy
|
|
20917
|
+
};
|
|
20918
|
+
var util_module_default = utilModule;
|
|
20919
|
+
|
|
20920
|
+
// src/runtime/assert-module.ts
|
|
20921
|
+
var AssertionError = class extends Error {
|
|
20922
|
+
actual;
|
|
20923
|
+
expected;
|
|
20924
|
+
operator;
|
|
20925
|
+
generatedMessage;
|
|
20926
|
+
name = "AssertionError";
|
|
20927
|
+
code = "ERR_ASSERTION";
|
|
20928
|
+
constructor(options) {
|
|
20929
|
+
const generated = options.message === void 0;
|
|
20930
|
+
super(options.message ?? describe(options.actual, options.expected, options.operator));
|
|
20931
|
+
this.actual = options.actual;
|
|
20932
|
+
this.expected = options.expected;
|
|
20933
|
+
this.operator = options.operator;
|
|
20934
|
+
this.generatedMessage = generated;
|
|
20935
|
+
}
|
|
20936
|
+
};
|
|
20937
|
+
function describe(actual, expected, operator) {
|
|
20938
|
+
if (operator === "fail") return "Failed";
|
|
20939
|
+
const rendered = (value) => inspect(value, { depth: 2 });
|
|
20940
|
+
return `${rendered(actual)} ${operator} ${rendered(expected)}`;
|
|
20941
|
+
}
|
|
20942
|
+
function fail(actual, expected, message, operator) {
|
|
20943
|
+
if (message instanceof Error) throw message;
|
|
20944
|
+
throw new AssertionError({ actual, expected, operator, ...message === void 0 ? {} : { message } });
|
|
20945
|
+
}
|
|
20946
|
+
function ok(value, message) {
|
|
20947
|
+
if (!value) fail(value, true, message, "==");
|
|
20948
|
+
}
|
|
20949
|
+
var equal = (actual, expected, message) => {
|
|
20950
|
+
if (actual != expected) fail(actual, expected, message, "==");
|
|
20951
|
+
};
|
|
20952
|
+
var notEqual = (actual, expected, message) => {
|
|
20953
|
+
if (actual == expected) fail(actual, expected, message, "!=");
|
|
20954
|
+
};
|
|
20955
|
+
var strictEqual = (actual, expected, message) => {
|
|
20956
|
+
if (!Object.is(actual, expected)) fail(actual, expected, message, "strictEqual");
|
|
20957
|
+
};
|
|
20958
|
+
var notStrictEqual = (actual, expected, message) => {
|
|
20959
|
+
if (Object.is(actual, expected)) fail(actual, expected, message, "notStrictEqual");
|
|
20960
|
+
};
|
|
20961
|
+
var deepStrictEqual = (actual, expected, message) => {
|
|
20962
|
+
if (!isDeepStrictEqual(actual, expected)) fail(actual, expected, message, "deepStrictEqual");
|
|
20963
|
+
};
|
|
20964
|
+
var notDeepStrictEqual = (actual, expected, message) => {
|
|
20965
|
+
if (isDeepStrictEqual(actual, expected)) fail(actual, expected, message, "notDeepStrictEqual");
|
|
20966
|
+
};
|
|
20967
|
+
function looseDeepEqual(a, b) {
|
|
20968
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
|
|
20969
|
+
return a == b;
|
|
20970
|
+
}
|
|
20971
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
20972
|
+
const keys = Object.keys(a);
|
|
20973
|
+
if (keys.length !== Object.keys(b).length) return false;
|
|
20974
|
+
return keys.every(
|
|
20975
|
+
(key) => looseDeepEqual(a[key], b[key])
|
|
20976
|
+
);
|
|
20977
|
+
}
|
|
20978
|
+
var deepEqual = (actual, expected, message) => {
|
|
20979
|
+
if (!looseDeepEqual(actual, expected)) fail(actual, expected, message, "deepEqual");
|
|
20980
|
+
};
|
|
20981
|
+
var notDeepEqual = (actual, expected, message) => {
|
|
20982
|
+
if (looseDeepEqual(actual, expected)) fail(actual, expected, message, "notDeepEqual");
|
|
20983
|
+
};
|
|
20984
|
+
function matches2(error, expected) {
|
|
20985
|
+
if (expected === void 0) return true;
|
|
20986
|
+
if (expected instanceof RegExp) return expected.test(String(error));
|
|
20987
|
+
if (typeof expected === "function") {
|
|
20988
|
+
if (error instanceof expected) return true;
|
|
20989
|
+
try {
|
|
20990
|
+
return Boolean(expected(error));
|
|
20991
|
+
} catch {
|
|
20992
|
+
return false;
|
|
20993
|
+
}
|
|
20994
|
+
}
|
|
20995
|
+
if (typeof expected === "object" && expected !== null) {
|
|
20996
|
+
return Object.entries(expected).every(
|
|
20997
|
+
([key, value]) => isDeepStrictEqual(error?.[key], value)
|
|
20998
|
+
);
|
|
20999
|
+
}
|
|
21000
|
+
return String(error) === String(expected);
|
|
21001
|
+
}
|
|
21002
|
+
function throws(block, expected, message) {
|
|
21003
|
+
const [error, threw] = capture(block);
|
|
21004
|
+
if (!threw) fail(void 0, expected, message ?? "Missing expected exception.", "throws");
|
|
21005
|
+
if (!matches2(error, expected)) throw error;
|
|
21006
|
+
}
|
|
21007
|
+
function doesNotThrow(block, expected, message) {
|
|
21008
|
+
const [error, threw] = capture(block);
|
|
21009
|
+
if (!threw) return;
|
|
21010
|
+
if (matches2(error, expected)) {
|
|
21011
|
+
fail(error, expected, message ?? "Got unwanted exception.", "doesNotThrow");
|
|
21012
|
+
}
|
|
21013
|
+
throw error;
|
|
21014
|
+
}
|
|
21015
|
+
async function rejects(block, expected, message) {
|
|
21016
|
+
const [error, threw] = await captureAsync(block);
|
|
21017
|
+
if (!threw) fail(void 0, expected, message ?? "Missing expected rejection.", "rejects");
|
|
21018
|
+
if (!matches2(error, expected)) throw error;
|
|
21019
|
+
}
|
|
21020
|
+
async function doesNotReject(block, expected, message) {
|
|
21021
|
+
const [error, threw] = await captureAsync(block);
|
|
21022
|
+
if (!threw) return;
|
|
21023
|
+
if (matches2(error, expected)) {
|
|
21024
|
+
fail(error, expected, message ?? "Got unwanted rejection.", "doesNotReject");
|
|
21025
|
+
}
|
|
21026
|
+
throw error;
|
|
21027
|
+
}
|
|
21028
|
+
function capture(block) {
|
|
21029
|
+
try {
|
|
21030
|
+
block();
|
|
21031
|
+
return [void 0, false];
|
|
21032
|
+
} catch (error) {
|
|
21033
|
+
return [error, true];
|
|
21034
|
+
}
|
|
21035
|
+
}
|
|
21036
|
+
async function captureAsync(block) {
|
|
21037
|
+
try {
|
|
21038
|
+
await (typeof block === "function" ? block() : block);
|
|
21039
|
+
return [void 0, false];
|
|
21040
|
+
} catch (error) {
|
|
21041
|
+
return [error, true];
|
|
21042
|
+
}
|
|
21043
|
+
}
|
|
21044
|
+
var match = (value, pattern, message) => {
|
|
21045
|
+
if (!pattern.test(value)) fail(value, pattern, message, "match");
|
|
21046
|
+
};
|
|
21047
|
+
var doesNotMatch = (value, pattern, message) => {
|
|
21048
|
+
if (pattern.test(value)) fail(value, pattern, message, "doesNotMatch");
|
|
21049
|
+
};
|
|
21050
|
+
var ifError = (value) => {
|
|
21051
|
+
if (value === null || value === void 0) return;
|
|
21052
|
+
if (value instanceof Error) throw value;
|
|
21053
|
+
fail(value, null, void 0, "ifError");
|
|
21054
|
+
};
|
|
21055
|
+
var base = {
|
|
21056
|
+
AssertionError,
|
|
21057
|
+
ok,
|
|
21058
|
+
equal,
|
|
21059
|
+
notEqual,
|
|
21060
|
+
strictEqual,
|
|
21061
|
+
notStrictEqual,
|
|
21062
|
+
deepEqual,
|
|
21063
|
+
notDeepEqual,
|
|
21064
|
+
deepStrictEqual,
|
|
21065
|
+
notDeepStrictEqual,
|
|
21066
|
+
throws,
|
|
21067
|
+
doesNotThrow,
|
|
21068
|
+
rejects,
|
|
21069
|
+
doesNotReject,
|
|
21070
|
+
match,
|
|
21071
|
+
doesNotMatch,
|
|
21072
|
+
ifError,
|
|
21073
|
+
fail: (message) => fail(void 0, void 0, message, "fail")
|
|
21074
|
+
};
|
|
21075
|
+
var assertModule = Object.assign(ok, base, {
|
|
21076
|
+
strict: Object.assign(ok, base, {
|
|
21077
|
+
equal: strictEqual,
|
|
21078
|
+
notEqual: notStrictEqual,
|
|
21079
|
+
deepEqual: deepStrictEqual,
|
|
21080
|
+
notDeepEqual: notDeepStrictEqual
|
|
21081
|
+
})
|
|
21082
|
+
});
|
|
21083
|
+
var assert_module_default = assertModule;
|
|
21084
|
+
var bytes = (data) => {
|
|
21085
|
+
if (typeof data === "string") return new Uint8Array(Buffer2.from(data, "utf8"));
|
|
21086
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
21087
|
+
return data;
|
|
21088
|
+
};
|
|
21089
|
+
function codec(name, run) {
|
|
21090
|
+
const sync2 = (data, options) => Buffer2.from(run(bytes(data), options));
|
|
21091
|
+
const async_ = (data, options, callback) => {
|
|
21092
|
+
const done = typeof options === "function" ? options : callback;
|
|
21093
|
+
const settings = typeof options === "function" ? void 0 : options;
|
|
21094
|
+
queueMicrotask(() => {
|
|
21095
|
+
try {
|
|
21096
|
+
done(null, sync2(data, settings));
|
|
21097
|
+
} catch (error) {
|
|
21098
|
+
done(error);
|
|
21099
|
+
}
|
|
21100
|
+
});
|
|
21101
|
+
};
|
|
21102
|
+
const Stream = class extends streamModule4__default.default.Transform {
|
|
21103
|
+
chunks = [];
|
|
21104
|
+
options;
|
|
21105
|
+
constructor(options) {
|
|
21106
|
+
super();
|
|
21107
|
+
this.options = options;
|
|
21108
|
+
}
|
|
21109
|
+
_transform(chunk, _encoding, next) {
|
|
21110
|
+
this.chunks.push(Buffer2.from(chunk));
|
|
21111
|
+
next();
|
|
21112
|
+
}
|
|
21113
|
+
_flush(next) {
|
|
21114
|
+
try {
|
|
21115
|
+
this.push(sync2(Buffer2.concat(this.chunks), this.options));
|
|
21116
|
+
next();
|
|
21117
|
+
} catch (error) {
|
|
21118
|
+
next(error);
|
|
21119
|
+
}
|
|
21120
|
+
}
|
|
21121
|
+
};
|
|
21122
|
+
Object.defineProperty(Stream, "name", { value: name });
|
|
21123
|
+
return { sync: sync2, async: async_, Stream };
|
|
21124
|
+
}
|
|
21125
|
+
var gzipCodec = codec("Gzip", (input, options) => pako.gzip(input, options));
|
|
21126
|
+
var gunzipCodec = codec("Gunzip", (input) => pako.ungzip(input));
|
|
21127
|
+
var deflateCodec = codec("Deflate", (input, options) => pako.deflate(input, options));
|
|
21128
|
+
var inflateCodec = codec("Inflate", (input) => pako.inflate(input));
|
|
21129
|
+
var deflateRawCodec = codec("DeflateRaw", (input, options) => pako.deflateRaw(input, options));
|
|
21130
|
+
var inflateRawCodec = codec("InflateRaw", (input) => pako.inflateRaw(input));
|
|
21131
|
+
var unzipCodec = codec(
|
|
21132
|
+
"Unzip",
|
|
21133
|
+
(input) => input[0] === 31 && input[1] === 139 ? pako.ungzip(input) : pako.inflate(input)
|
|
21134
|
+
);
|
|
21135
|
+
function brotliUnavailable(name) {
|
|
21136
|
+
const error = new Error(
|
|
21137
|
+
`zlib.${name} is unavailable: the sandboxed runtime has no Brotli implementation.`
|
|
21138
|
+
);
|
|
21139
|
+
error.code = "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM";
|
|
21140
|
+
throw error;
|
|
21141
|
+
}
|
|
21142
|
+
var zlibModule = {
|
|
21143
|
+
gzipSync: gzipCodec.sync,
|
|
21144
|
+
gzip: gzipCodec.async,
|
|
21145
|
+
createGzip: (o) => new gzipCodec.Stream(o),
|
|
21146
|
+
gunzipSync: gunzipCodec.sync,
|
|
21147
|
+
gunzip: gunzipCodec.async,
|
|
21148
|
+
createGunzip: (o) => new gunzipCodec.Stream(o),
|
|
21149
|
+
deflateSync: deflateCodec.sync,
|
|
21150
|
+
deflate: deflateCodec.async,
|
|
21151
|
+
createDeflate: (o) => new deflateCodec.Stream(o),
|
|
21152
|
+
inflateSync: inflateCodec.sync,
|
|
21153
|
+
inflate: inflateCodec.async,
|
|
21154
|
+
createInflate: (o) => new inflateCodec.Stream(o),
|
|
21155
|
+
deflateRawSync: deflateRawCodec.sync,
|
|
21156
|
+
deflateRaw: deflateRawCodec.async,
|
|
21157
|
+
createDeflateRaw: (o) => new deflateRawCodec.Stream(o),
|
|
21158
|
+
inflateRawSync: inflateRawCodec.sync,
|
|
21159
|
+
inflateRaw: inflateRawCodec.async,
|
|
21160
|
+
createInflateRaw: (o) => new inflateRawCodec.Stream(o),
|
|
21161
|
+
unzipSync: unzipCodec.sync,
|
|
21162
|
+
unzip: unzipCodec.async,
|
|
21163
|
+
createUnzip: (o) => new unzipCodec.Stream(o),
|
|
21164
|
+
brotliCompressSync: () => brotliUnavailable("brotliCompressSync"),
|
|
21165
|
+
brotliDecompressSync: () => brotliUnavailable("brotliDecompressSync"),
|
|
21166
|
+
brotliCompress: () => brotliUnavailable("brotliCompress"),
|
|
21167
|
+
brotliDecompress: () => brotliUnavailable("brotliDecompress"),
|
|
21168
|
+
createBrotliCompress: () => brotliUnavailable("createBrotliCompress"),
|
|
21169
|
+
createBrotliDecompress: () => brotliUnavailable("createBrotliDecompress"),
|
|
21170
|
+
constants: {
|
|
21171
|
+
Z_NO_FLUSH: 0,
|
|
21172
|
+
Z_PARTIAL_FLUSH: 1,
|
|
21173
|
+
Z_SYNC_FLUSH: 2,
|
|
21174
|
+
Z_FULL_FLUSH: 3,
|
|
21175
|
+
Z_FINISH: 4,
|
|
21176
|
+
Z_BLOCK: 5,
|
|
21177
|
+
Z_TREES: 6,
|
|
21178
|
+
Z_OK: 0,
|
|
21179
|
+
Z_STREAM_END: 1,
|
|
21180
|
+
Z_NEED_DICT: 2,
|
|
21181
|
+
Z_ERRNO: -1,
|
|
21182
|
+
Z_STREAM_ERROR: -2,
|
|
21183
|
+
Z_DATA_ERROR: -3,
|
|
21184
|
+
Z_MEM_ERROR: -4,
|
|
21185
|
+
Z_BUF_ERROR: -5,
|
|
21186
|
+
Z_VERSION_ERROR: -6,
|
|
21187
|
+
Z_NO_COMPRESSION: 0,
|
|
21188
|
+
Z_BEST_SPEED: 1,
|
|
21189
|
+
Z_BEST_COMPRESSION: 9,
|
|
21190
|
+
Z_DEFAULT_COMPRESSION: -1,
|
|
21191
|
+
Z_FILTERED: 1,
|
|
21192
|
+
Z_HUFFMAN_ONLY: 2,
|
|
21193
|
+
Z_RLE: 3,
|
|
21194
|
+
Z_FIXED: 4,
|
|
21195
|
+
Z_DEFAULT_STRATEGY: 0,
|
|
21196
|
+
DEFLATE: 1,
|
|
21197
|
+
INFLATE: 2,
|
|
21198
|
+
GZIP: 3,
|
|
21199
|
+
GUNZIP: 4,
|
|
21200
|
+
DEFLATERAW: 5,
|
|
21201
|
+
INFLATERAW: 6,
|
|
21202
|
+
UNZIP: 7
|
|
21203
|
+
}
|
|
21204
|
+
};
|
|
21205
|
+
var zlib_module_default = zlibModule;
|
|
21206
|
+
function fileURLToPath(url) {
|
|
21207
|
+
const value = typeof url === "string" ? new URL(url) : url;
|
|
21208
|
+
if (value.protocol !== "file:") {
|
|
21209
|
+
throw Object.assign(new TypeError("The URL must be of scheme file"), {
|
|
21210
|
+
code: "ERR_INVALID_URL_SCHEME"
|
|
21211
|
+
});
|
|
21212
|
+
}
|
|
21213
|
+
return decodeURIComponent(value.pathname);
|
|
21214
|
+
}
|
|
21215
|
+
function pathToFileURL(path) {
|
|
21216
|
+
const escaped = path.replace(/%/g, "%25").replace(/\\/g, "%5C").replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/\t/g, "%09").replace(/ /g, "%20").replace(/#/g, "%23").replace(/\?/g, "%3F");
|
|
21217
|
+
return new URL(`file://${escaped.startsWith("/") ? "" : "/"}${escaped}`);
|
|
21218
|
+
}
|
|
21219
|
+
function format2(value, options) {
|
|
21220
|
+
if (!(value instanceof URL)) return legacyUrl__default.default.format(value);
|
|
21221
|
+
const url = new URL(value.href);
|
|
21222
|
+
if (options?.auth === false) {
|
|
21223
|
+
url.username = "";
|
|
21224
|
+
url.password = "";
|
|
21225
|
+
}
|
|
21226
|
+
if (options?.fragment === false) url.hash = "";
|
|
21227
|
+
if (options?.search === false) url.search = "";
|
|
21228
|
+
return url.href;
|
|
21229
|
+
}
|
|
21230
|
+
var urlModule = {
|
|
21231
|
+
...legacyUrl__default.default,
|
|
21232
|
+
format: format2,
|
|
21233
|
+
fileURLToPath,
|
|
21234
|
+
pathToFileURL,
|
|
21235
|
+
URL,
|
|
21236
|
+
URLSearchParams,
|
|
21237
|
+
/** Names here are already Unicode; there is no IDNA table to consult. */
|
|
21238
|
+
domainToASCII: (domain) => domain.toLowerCase(),
|
|
21239
|
+
domainToUnicode: (domain) => domain.toLowerCase(),
|
|
21240
|
+
urlToHttpOptions: (url) => ({
|
|
21241
|
+
protocol: url.protocol,
|
|
21242
|
+
hostname: url.hostname,
|
|
21243
|
+
hash: url.hash,
|
|
21244
|
+
search: url.search,
|
|
21245
|
+
pathname: url.pathname,
|
|
21246
|
+
path: `${url.pathname}${url.search}`,
|
|
21247
|
+
href: url.href,
|
|
21248
|
+
...url.port ? { port: Number(url.port) } : {},
|
|
21249
|
+
...url.username || url.password ? { auth: `${url.username}:${url.password}` } : {}
|
|
21250
|
+
})
|
|
21251
|
+
};
|
|
21252
|
+
var url_module_default = urlModule;
|
|
21253
|
+
|
|
20457
21254
|
// src/runtime/core-modules.ts
|
|
20458
21255
|
init_path();
|
|
20459
|
-
var VirtualIncomingMessage = class extends
|
|
21256
|
+
var VirtualIncomingMessage = class extends streamModule4__default.default.Readable {
|
|
20460
21257
|
method;
|
|
20461
21258
|
url;
|
|
20462
21259
|
headers;
|
|
@@ -20477,7 +21274,7 @@ var VirtualIncomingMessage = class extends streamModule3__default.default.Readab
|
|
|
20477
21274
|
this.headers["content-length"] = String(body.length);
|
|
20478
21275
|
}
|
|
20479
21276
|
this.rawHeaders = Object.entries(this.headers).flatMap(([key, value]) => [key, value]);
|
|
20480
|
-
if (body.length) this.push(
|
|
21277
|
+
if (body.length) this.push(Buffer2.from(body));
|
|
20481
21278
|
this.push(null);
|
|
20482
21279
|
}
|
|
20483
21280
|
_read() {
|
|
@@ -20487,7 +21284,7 @@ var VirtualIncomingMessage = class extends streamModule3__default.default.Readab
|
|
|
20487
21284
|
return this;
|
|
20488
21285
|
}
|
|
20489
21286
|
};
|
|
20490
|
-
var VirtualServerResponse = class extends
|
|
21287
|
+
var VirtualServerResponse = class extends streamModule4__default.default.Writable {
|
|
20491
21288
|
statusCode = 200;
|
|
20492
21289
|
statusMessage = "OK";
|
|
20493
21290
|
headersSent = false;
|
|
@@ -20508,7 +21305,7 @@ var VirtualServerResponse = class extends streamModule3__default.default.Writabl
|
|
|
20508
21305
|
}
|
|
20509
21306
|
_write(chunk, encoding, callback) {
|
|
20510
21307
|
this.headersSent = true;
|
|
20511
|
-
this.chunks.push(
|
|
21308
|
+
this.chunks.push(Buffer2.isBuffer(chunk) ? chunk : Buffer2.from(chunk, encoding));
|
|
20512
21309
|
callback();
|
|
20513
21310
|
}
|
|
20514
21311
|
_final(callback) {
|
|
@@ -20520,7 +21317,7 @@ var VirtualServerResponse = class extends streamModule3__default.default.Writabl
|
|
|
20520
21317
|
statusCode: this.statusCode,
|
|
20521
21318
|
statusMessage: this.statusMessage || STATUS_CODES[this.statusCode] || "",
|
|
20522
21319
|
headers,
|
|
20523
|
-
body: new Uint8Array(
|
|
21320
|
+
body: new Uint8Array(Buffer2.concat(this.chunks))
|
|
20524
21321
|
});
|
|
20525
21322
|
callback();
|
|
20526
21323
|
}
|
|
@@ -20572,7 +21369,7 @@ var VirtualServerResponse = class extends streamModule3__default.default.Writabl
|
|
|
20572
21369
|
return this;
|
|
20573
21370
|
}
|
|
20574
21371
|
};
|
|
20575
|
-
var VirtualHttpServer = class extends
|
|
21372
|
+
var VirtualHttpServer = class extends EventEmitter4__default.default {
|
|
20576
21373
|
constructor(router, owner, listener) {
|
|
20577
21374
|
super();
|
|
20578
21375
|
this.router = router;
|
|
@@ -20696,7 +21493,7 @@ function socketStub() {
|
|
|
20696
21493
|
}
|
|
20697
21494
|
var METHODS = ["ACL", "BIND", "CHECKOUT", "CONNECT", "COPY", "DELETE", "GET", "HEAD", "LINK", "LOCK", "M-SEARCH", "MERGE", "MKACTIVITY", "MKCALENDAR", "MKCOL", "MOVE", "NOTIFY", "OPTIONS", "PATCH", "POST", "PROPFIND", "PROPPATCH", "PURGE", "PUT", "REBIND", "REPORT", "SEARCH", "SOURCE", "SUBSCRIBE", "TRACE", "UNBIND", "UNLINK", "UNLOCK", "UNSUBSCRIBE"];
|
|
20698
21495
|
var STATUS_CODES = { 100: "Continue", 200: "OK", 201: "Created", 202: "Accepted", 204: "No Content", 206: "Partial Content", 301: "Moved Permanently", 302: "Found", 304: "Not Modified", 307: "Temporary Redirect", 308: "Permanent Redirect", 400: "Bad Request", 401: "Unauthorized", 403: "Forbidden", 404: "Not Found", 405: "Method Not Allowed", 409: "Conflict", 413: "Payload Too Large", 415: "Unsupported Media Type", 422: "Unprocessable Entity", 429: "Too Many Requests", 500: "Internal Server Error", 501: "Not Implemented", 502: "Bad Gateway", 503: "Service Unavailable" };
|
|
20699
|
-
var hashes = { md5: legacy.md5, sha1: legacy.sha1, "sha-1": legacy.sha1, sha224: sha256.sha224, "sha-224": sha256.sha224, sha256: sha256.sha256, "sha-256": sha256.sha256, sha384: sha512.sha384, "sha-384": sha512.sha384, sha512: sha512.sha512, "sha-512": sha512.sha512 };
|
|
21496
|
+
var hashes = { md5: legacy$1.md5, sha1: legacy$1.sha1, "sha-1": legacy$1.sha1, sha224: sha256.sha224, "sha-224": sha256.sha224, sha256: sha256.sha256, "sha-256": sha256.sha256, sha384: sha512.sha384, "sha-384": sha512.sha384, sha512: sha512.sha512, "sha-512": sha512.sha512 };
|
|
20700
21497
|
function createCryptoModule() {
|
|
20701
21498
|
const cryptoObject = globalThis.crypto;
|
|
20702
21499
|
return {
|
|
@@ -20708,7 +21505,7 @@ function createCryptoModule() {
|
|
|
20708
21505
|
return api;
|
|
20709
21506
|
},
|
|
20710
21507
|
digest(encoding) {
|
|
20711
|
-
const value =
|
|
21508
|
+
const value = Buffer2.from(hash.digest());
|
|
20712
21509
|
return encoding ? value.toString(encoding) : value;
|
|
20713
21510
|
},
|
|
20714
21511
|
copy() {
|
|
@@ -20726,14 +21523,14 @@ function createCryptoModule() {
|
|
|
20726
21523
|
return api;
|
|
20727
21524
|
},
|
|
20728
21525
|
digest(encoding) {
|
|
20729
|
-
const value =
|
|
21526
|
+
const value = Buffer2.from(state.digest());
|
|
20730
21527
|
return encoding ? value.toString(encoding) : value;
|
|
20731
21528
|
}
|
|
20732
21529
|
};
|
|
20733
21530
|
return api;
|
|
20734
21531
|
},
|
|
20735
21532
|
randomBytes(size, callback) {
|
|
20736
|
-
const value =
|
|
21533
|
+
const value = Buffer2.alloc(size);
|
|
20737
21534
|
cryptoObject.getRandomValues(value);
|
|
20738
21535
|
if (callback) {
|
|
20739
21536
|
queueMicrotask(() => callback(null, value));
|
|
@@ -20766,7 +21563,7 @@ function createCryptoModule() {
|
|
|
20766
21563
|
queueMicrotask(() => done?.(null, target));
|
|
20767
21564
|
},
|
|
20768
21565
|
hash(algorithm, data, encoding = "hex") {
|
|
20769
|
-
const digest =
|
|
21566
|
+
const digest = Buffer2.from(hashFor(algorithm)(toBytes2(data)));
|
|
20770
21567
|
return encoding === "buffer" ? digest : digest.toString(encoding);
|
|
20771
21568
|
},
|
|
20772
21569
|
timingSafeEqual(a, b) {
|
|
@@ -20787,11 +21584,11 @@ function hashFor(algorithm) {
|
|
|
20787
21584
|
return hash;
|
|
20788
21585
|
}
|
|
20789
21586
|
function toBytes2(data, encoding) {
|
|
20790
|
-
return typeof data === "string" ?
|
|
21587
|
+
return typeof data === "string" ? Buffer2.from(data, encoding) : data;
|
|
20791
21588
|
}
|
|
20792
|
-
var ChildProcess = class extends
|
|
20793
|
-
stdout = new
|
|
20794
|
-
stderr = new
|
|
21589
|
+
var ChildProcess = class extends EventEmitter4__default.default {
|
|
21590
|
+
stdout = new streamModule4__default.default.PassThrough();
|
|
21591
|
+
stderr = new streamModule4__default.default.PassThrough();
|
|
20795
21592
|
stdin;
|
|
20796
21593
|
stdio;
|
|
20797
21594
|
pid;
|
|
@@ -20808,10 +21605,10 @@ var ChildProcess = class extends EventEmitter3__default.default {
|
|
|
20808
21605
|
this.pid = handle.pid;
|
|
20809
21606
|
this.spawnfile = file3;
|
|
20810
21607
|
this.spawnargs = [file3, ...args];
|
|
20811
|
-
this.stdin = new
|
|
21608
|
+
this.stdin = new streamModule4__default.default.Writable({
|
|
20812
21609
|
write: (chunk, _encoding, done) => {
|
|
20813
21610
|
try {
|
|
20814
|
-
handle.sendStdin(typeof chunk === "string" ? chunk :
|
|
21611
|
+
handle.sendStdin(typeof chunk === "string" ? chunk : Buffer2.from(chunk).toString("utf8"));
|
|
20815
21612
|
} catch {
|
|
20816
21613
|
}
|
|
20817
21614
|
done();
|
|
@@ -20881,8 +21678,8 @@ function createChildProcessModule(spawnChild, defaultCwd) {
|
|
|
20881
21678
|
child.stderr.on("data", (chunk) => err.push(String(chunk)));
|
|
20882
21679
|
child.on("close", (code) => {
|
|
20883
21680
|
const asBuffer = options.encoding === "buffer";
|
|
20884
|
-
const stdout = asBuffer ?
|
|
20885
|
-
const stderr = asBuffer ?
|
|
21681
|
+
const stdout = asBuffer ? Buffer2.from(out.join("")) : out.join("");
|
|
21682
|
+
const stderr = asBuffer ? Buffer2.from(err.join("")) : err.join("");
|
|
20886
21683
|
if (code === 0) {
|
|
20887
21684
|
callback(null, stdout, stderr);
|
|
20888
21685
|
return;
|
|
@@ -20933,6 +21730,326 @@ function unavailable(name) {
|
|
|
20933
21730
|
|
|
20934
21731
|
// src/runtime/core-modules.ts
|
|
20935
21732
|
init_signals();
|
|
21733
|
+
var CSI_KEYS = {
|
|
21734
|
+
"[A": "up",
|
|
21735
|
+
"[B": "down",
|
|
21736
|
+
"[C": "right",
|
|
21737
|
+
"[D": "left",
|
|
21738
|
+
"[E": "clear",
|
|
21739
|
+
"[F": "end",
|
|
21740
|
+
"[H": "home",
|
|
21741
|
+
"OA": "up",
|
|
21742
|
+
"OB": "down",
|
|
21743
|
+
"OC": "right",
|
|
21744
|
+
"OD": "left",
|
|
21745
|
+
"OE": "clear",
|
|
21746
|
+
"OF": "end",
|
|
21747
|
+
"OH": "home",
|
|
21748
|
+
"[1~": "home",
|
|
21749
|
+
"[2~": "insert",
|
|
21750
|
+
"[3~": "delete",
|
|
21751
|
+
"[4~": "end",
|
|
21752
|
+
"[5~": "pageup",
|
|
21753
|
+
"[6~": "pagedown",
|
|
21754
|
+
"[7~": "home",
|
|
21755
|
+
"[8~": "end",
|
|
21756
|
+
"[11~": "f1",
|
|
21757
|
+
"[12~": "f2",
|
|
21758
|
+
"[13~": "f3",
|
|
21759
|
+
"[14~": "f4",
|
|
21760
|
+
"[15~": "f5",
|
|
21761
|
+
"[17~": "f6",
|
|
21762
|
+
"[18~": "f7",
|
|
21763
|
+
"[19~": "f8",
|
|
21764
|
+
"[20~": "f9",
|
|
21765
|
+
"[21~": "f10",
|
|
21766
|
+
"[23~": "f11",
|
|
21767
|
+
"[24~": "f12",
|
|
21768
|
+
"OP": "f1",
|
|
21769
|
+
"OQ": "f2",
|
|
21770
|
+
"OR": "f3",
|
|
21771
|
+
"OS": "f4",
|
|
21772
|
+
"[Z": "tab"
|
|
21773
|
+
};
|
|
21774
|
+
var CONTROL_LETTERS = "abcdefghijklmnopqrstuvwxyz";
|
|
21775
|
+
function parseKeys(input) {
|
|
21776
|
+
const keys = [];
|
|
21777
|
+
let index = 0;
|
|
21778
|
+
while (index < input.length) {
|
|
21779
|
+
const char = input[index];
|
|
21780
|
+
if (char === "\x1B") {
|
|
21781
|
+
const rest = input.slice(index + 1);
|
|
21782
|
+
const match2 = /^(\[[0-9;]*[A-Za-z~]|O[A-Za-z])/.exec(rest);
|
|
21783
|
+
if (match2) {
|
|
21784
|
+
const sequence = match2[1];
|
|
21785
|
+
const name = CSI_KEYS[sequence];
|
|
21786
|
+
keys.push({
|
|
21787
|
+
sequence: `\x1B${sequence}`,
|
|
21788
|
+
name: name ?? "undefined",
|
|
21789
|
+
ctrl: false,
|
|
21790
|
+
/* xterm reports modifiers as `;5` (control) and `;2` (shift) before
|
|
21791
|
+
* the final letter. */
|
|
21792
|
+
meta: false,
|
|
21793
|
+
shift: /;2[A-Za-z~]$/.test(sequence),
|
|
21794
|
+
code: sequence
|
|
21795
|
+
});
|
|
21796
|
+
if (/;5[A-Za-z~]$/.test(sequence)) keys[keys.length - 1].ctrl = true;
|
|
21797
|
+
index += 1 + sequence.length;
|
|
21798
|
+
continue;
|
|
21799
|
+
}
|
|
21800
|
+
if (rest.length > 0 && rest[0] !== "\x1B") {
|
|
21801
|
+
const inner = parseKeys(rest[0])[0];
|
|
21802
|
+
if (inner) {
|
|
21803
|
+
keys.push({ ...inner, meta: true, sequence: `\x1B${inner.sequence}` });
|
|
21804
|
+
index += 2;
|
|
21805
|
+
continue;
|
|
21806
|
+
}
|
|
21807
|
+
}
|
|
21808
|
+
keys.push({ sequence: "\x1B", name: "escape", ctrl: false, meta: false, shift: false });
|
|
21809
|
+
index += 1;
|
|
21810
|
+
continue;
|
|
21811
|
+
}
|
|
21812
|
+
keys.push(parseSingle(char));
|
|
21813
|
+
index += 1;
|
|
21814
|
+
}
|
|
21815
|
+
return keys;
|
|
21816
|
+
}
|
|
21817
|
+
function parseSingle(char) {
|
|
21818
|
+
const code = char.charCodeAt(0);
|
|
21819
|
+
if (char === "\r") return { sequence: char, name: "return", ctrl: false, meta: false, shift: false };
|
|
21820
|
+
if (char === "\n") return { sequence: char, name: "enter", ctrl: false, meta: false, shift: false };
|
|
21821
|
+
if (char === " ") return { sequence: char, name: "tab", ctrl: false, meta: false, shift: false };
|
|
21822
|
+
if (char === "\x7F" || char === "\b") {
|
|
21823
|
+
return { sequence: char, name: "backspace", ctrl: false, meta: false, shift: false };
|
|
21824
|
+
}
|
|
21825
|
+
if (char === " ") return { sequence: char, name: "space", ctrl: false, meta: false, shift: false };
|
|
21826
|
+
if (code >= 1 && code <= 26) {
|
|
21827
|
+
return {
|
|
21828
|
+
sequence: char,
|
|
21829
|
+
name: CONTROL_LETTERS[code - 1],
|
|
21830
|
+
ctrl: true,
|
|
21831
|
+
meta: false,
|
|
21832
|
+
shift: false
|
|
21833
|
+
};
|
|
21834
|
+
}
|
|
21835
|
+
return {
|
|
21836
|
+
sequence: char,
|
|
21837
|
+
name: char.toLowerCase(),
|
|
21838
|
+
ctrl: false,
|
|
21839
|
+
meta: false,
|
|
21840
|
+
// An uppercase letter arrived because shift was held.
|
|
21841
|
+
shift: char !== char.toLowerCase()
|
|
21842
|
+
};
|
|
21843
|
+
}
|
|
21844
|
+
function emitKeypressEvents(stream) {
|
|
21845
|
+
if (!stream || stream.__sbxKeypress) return;
|
|
21846
|
+
stream.__sbxKeypress = true;
|
|
21847
|
+
stream.on("data", (chunk) => {
|
|
21848
|
+
for (const key of parseKeys(String(chunk))) {
|
|
21849
|
+
stream.emit("keypress", key.sequence, key);
|
|
21850
|
+
}
|
|
21851
|
+
});
|
|
21852
|
+
}
|
|
21853
|
+
function createReadlineModule(defaultInput) {
|
|
21854
|
+
class Interface extends EventEmitter4__default.default {
|
|
21855
|
+
constructor(input, output, terminal = false) {
|
|
21856
|
+
super();
|
|
21857
|
+
this.input = input;
|
|
21858
|
+
this.output = output;
|
|
21859
|
+
this.terminal = terminal;
|
|
21860
|
+
this.onTerminalKeypress = (sequence, key) => this.edit(sequence, key);
|
|
21861
|
+
if (terminal) {
|
|
21862
|
+
emitKeypressEvents(input);
|
|
21863
|
+
input?.on?.("keypress", this.onTerminalKeypress);
|
|
21864
|
+
} else {
|
|
21865
|
+
input?.on?.("data", (chunk) => this.receive(String(chunk)));
|
|
21866
|
+
}
|
|
21867
|
+
input?.on?.("end", () => this.close());
|
|
21868
|
+
}
|
|
21869
|
+
input;
|
|
21870
|
+
output;
|
|
21871
|
+
closed = false;
|
|
21872
|
+
buffer = "";
|
|
21873
|
+
pending = [];
|
|
21874
|
+
lines = [];
|
|
21875
|
+
line = "";
|
|
21876
|
+
cursor = 0;
|
|
21877
|
+
terminal;
|
|
21878
|
+
onTerminalKeypress;
|
|
21879
|
+
/** Split incoming data into lines, answering any waiting `question`. */
|
|
21880
|
+
receive(text2) {
|
|
21881
|
+
this.buffer += text2;
|
|
21882
|
+
let newline = this.buffer.indexOf("\n");
|
|
21883
|
+
while (newline >= 0) {
|
|
21884
|
+
const line = this.buffer.slice(0, newline).replace(/\r$/, "");
|
|
21885
|
+
this.buffer = this.buffer.slice(newline + 1);
|
|
21886
|
+
const waiting = this.pending.shift();
|
|
21887
|
+
if (waiting) waiting(line);
|
|
21888
|
+
else {
|
|
21889
|
+
this.lines.push(line);
|
|
21890
|
+
this.emit("line", line);
|
|
21891
|
+
}
|
|
21892
|
+
newline = this.buffer.indexOf("\n");
|
|
21893
|
+
}
|
|
21894
|
+
}
|
|
21895
|
+
question(query, callback) {
|
|
21896
|
+
this.output?.write?.(query);
|
|
21897
|
+
if (callback) {
|
|
21898
|
+
this.pending.push(callback);
|
|
21899
|
+
return;
|
|
21900
|
+
}
|
|
21901
|
+
return new Promise((resolve2) => this.pending.push(resolve2));
|
|
21902
|
+
}
|
|
21903
|
+
prompt() {
|
|
21904
|
+
this.output?.write?.(this.promptText);
|
|
21905
|
+
}
|
|
21906
|
+
promptText = "> ";
|
|
21907
|
+
setPrompt(text2) {
|
|
21908
|
+
this.promptText = text2;
|
|
21909
|
+
}
|
|
21910
|
+
pause() {
|
|
21911
|
+
this.input?.pause?.();
|
|
21912
|
+
return this;
|
|
21913
|
+
}
|
|
21914
|
+
resume() {
|
|
21915
|
+
this.input?.resume?.();
|
|
21916
|
+
return this;
|
|
21917
|
+
}
|
|
21918
|
+
write(text2, key) {
|
|
21919
|
+
if (!this.terminal) {
|
|
21920
|
+
if (text2) this.receive(text2);
|
|
21921
|
+
return;
|
|
21922
|
+
}
|
|
21923
|
+
if (key) {
|
|
21924
|
+
this.edit(text2 ?? "", {
|
|
21925
|
+
sequence: text2 ?? key.sequence ?? "",
|
|
21926
|
+
name: key.name,
|
|
21927
|
+
ctrl: key.ctrl ?? false,
|
|
21928
|
+
meta: key.meta ?? false,
|
|
21929
|
+
shift: key.shift ?? false,
|
|
21930
|
+
...key.code ? { code: key.code } : {}
|
|
21931
|
+
});
|
|
21932
|
+
return;
|
|
21933
|
+
}
|
|
21934
|
+
if (text2) {
|
|
21935
|
+
this.line = this.line.slice(0, this.cursor) + text2 + this.line.slice(this.cursor);
|
|
21936
|
+
this.cursor += text2.length;
|
|
21937
|
+
}
|
|
21938
|
+
}
|
|
21939
|
+
getCursorPos() {
|
|
21940
|
+
return { rows: 0, cols: this.cursor + this.promptText.length };
|
|
21941
|
+
}
|
|
21942
|
+
close() {
|
|
21943
|
+
if (this.closed) return;
|
|
21944
|
+
this.closed = true;
|
|
21945
|
+
if (this.terminal) {
|
|
21946
|
+
this.input?.off?.("keypress", this.onTerminalKeypress);
|
|
21947
|
+
this.input?.pause?.();
|
|
21948
|
+
}
|
|
21949
|
+
for (const waiting of this.pending.splice(0)) waiting("");
|
|
21950
|
+
this.emit("close");
|
|
21951
|
+
}
|
|
21952
|
+
edit(sequence, key) {
|
|
21953
|
+
if (this.closed) return;
|
|
21954
|
+
const name = key.name;
|
|
21955
|
+
if (name === "return" || name === "enter") {
|
|
21956
|
+
const value = this.line;
|
|
21957
|
+
this.line = "";
|
|
21958
|
+
this.cursor = 0;
|
|
21959
|
+
this.emit("line", value);
|
|
21960
|
+
return;
|
|
21961
|
+
}
|
|
21962
|
+
if (name === "left") {
|
|
21963
|
+
this.cursor = Math.max(0, this.cursor - 1);
|
|
21964
|
+
return;
|
|
21965
|
+
}
|
|
21966
|
+
if (name === "right") {
|
|
21967
|
+
this.cursor = Math.min(this.line.length, this.cursor + 1);
|
|
21968
|
+
return;
|
|
21969
|
+
}
|
|
21970
|
+
if (name === "home" || key.ctrl && name === "a") {
|
|
21971
|
+
this.cursor = 0;
|
|
21972
|
+
return;
|
|
21973
|
+
}
|
|
21974
|
+
if (name === "end" || key.ctrl && name === "e") {
|
|
21975
|
+
this.cursor = this.line.length;
|
|
21976
|
+
return;
|
|
21977
|
+
}
|
|
21978
|
+
if (name === "backspace" || key.ctrl && name === "h") {
|
|
21979
|
+
if (this.cursor > 0) {
|
|
21980
|
+
this.line = this.line.slice(0, this.cursor - 1) + this.line.slice(this.cursor);
|
|
21981
|
+
this.cursor--;
|
|
21982
|
+
}
|
|
21983
|
+
return;
|
|
21984
|
+
}
|
|
21985
|
+
if (name === "delete") {
|
|
21986
|
+
if (this.cursor < this.line.length) this.line = this.line.slice(0, this.cursor) + this.line.slice(this.cursor + 1);
|
|
21987
|
+
return;
|
|
21988
|
+
}
|
|
21989
|
+
if (key.ctrl && name === "u") {
|
|
21990
|
+
this.line = this.line.slice(this.cursor);
|
|
21991
|
+
this.cursor = 0;
|
|
21992
|
+
return;
|
|
21993
|
+
}
|
|
21994
|
+
if (key.ctrl && name === "k") {
|
|
21995
|
+
this.line = this.line.slice(0, this.cursor);
|
|
21996
|
+
return;
|
|
21997
|
+
}
|
|
21998
|
+
if (key.ctrl || key.meta || sequence.length !== 1 || sequence < " ") return;
|
|
21999
|
+
this.line = this.line.slice(0, this.cursor) + sequence + this.line.slice(this.cursor);
|
|
22000
|
+
this.cursor += sequence.length;
|
|
22001
|
+
}
|
|
22002
|
+
async *[Symbol.asyncIterator]() {
|
|
22003
|
+
while (!this.closed || this.lines.length) {
|
|
22004
|
+
const line = this.lines.shift();
|
|
22005
|
+
if (line !== void 0) {
|
|
22006
|
+
yield line;
|
|
22007
|
+
continue;
|
|
22008
|
+
}
|
|
22009
|
+
const next = await new Promise((resolve2) => {
|
|
22010
|
+
const onLine = (value) => {
|
|
22011
|
+
cleanup();
|
|
22012
|
+
resolve2(value);
|
|
22013
|
+
};
|
|
22014
|
+
const onClose = () => {
|
|
22015
|
+
cleanup();
|
|
22016
|
+
resolve2(null);
|
|
22017
|
+
};
|
|
22018
|
+
const cleanup = () => {
|
|
22019
|
+
this.off("line", onLine);
|
|
22020
|
+
this.off("close", onClose);
|
|
22021
|
+
};
|
|
22022
|
+
this.on("line", onLine);
|
|
22023
|
+
this.on("close", onClose);
|
|
22024
|
+
});
|
|
22025
|
+
if (next === null) return;
|
|
22026
|
+
yield next;
|
|
22027
|
+
}
|
|
22028
|
+
}
|
|
22029
|
+
}
|
|
22030
|
+
const createInterface = (options, output) => {
|
|
22031
|
+
if (options && typeof options === "object" && !options.on) {
|
|
22032
|
+
const instance = new Interface(options.input ?? defaultInput(), options.output, options.terminal === true);
|
|
22033
|
+
if (typeof options.prompt === "string") instance.setPrompt(options.prompt);
|
|
22034
|
+
return instance;
|
|
22035
|
+
}
|
|
22036
|
+
return new Interface(options ?? defaultInput(), output, Boolean(output));
|
|
22037
|
+
};
|
|
22038
|
+
const noop = () => {
|
|
22039
|
+
};
|
|
22040
|
+
const base2 = {
|
|
22041
|
+
Interface,
|
|
22042
|
+
createInterface,
|
|
22043
|
+
emitKeypressEvents,
|
|
22044
|
+
clearLine: noop,
|
|
22045
|
+
clearScreenDown: noop,
|
|
22046
|
+
cursorTo: noop,
|
|
22047
|
+
moveCursor: noop
|
|
22048
|
+
};
|
|
22049
|
+
return { ...base2, promises: { ...base2, Interface, createInterface } };
|
|
22050
|
+
}
|
|
22051
|
+
|
|
22052
|
+
// src/runtime/core-modules.ts
|
|
20936
22053
|
var Dirent = class {
|
|
20937
22054
|
/** Node 20+ exposes the containing directory, and `fs.glob` consumers read it. */
|
|
20938
22055
|
constructor(name, stat2, parentPath = "") {
|
|
@@ -21048,7 +22165,7 @@ var S_IFMT2 = 61440;
|
|
|
21048
22165
|
var S_IFREG2 = 32768;
|
|
21049
22166
|
var S_IFDIR2 = 16384;
|
|
21050
22167
|
var S_IFLNK2 = 40960;
|
|
21051
|
-
var FsWatcher = class extends
|
|
22168
|
+
var FsWatcher = class extends EventEmitter4__default.default {
|
|
21052
22169
|
close() {
|
|
21053
22170
|
this.removeAllListeners();
|
|
21054
22171
|
}
|
|
@@ -21069,7 +22186,7 @@ function createCoreModules(options) {
|
|
|
21069
22186
|
const stderrWrite = options.stderr ?? (() => {
|
|
21070
22187
|
});
|
|
21071
22188
|
const timers = createTrackedTimers();
|
|
21072
|
-
const processObject = Object.assign(new
|
|
22189
|
+
const processObject = Object.assign(new EventEmitter4__default.default(), processShim__default.default, {
|
|
21073
22190
|
argv: options.argv?.slice() ?? ["/usr/bin/node"],
|
|
21074
22191
|
argv0: "node",
|
|
21075
22192
|
execPath: "/usr/bin/node",
|
|
@@ -21105,14 +22222,27 @@ function createCoreModules(options) {
|
|
|
21105
22222
|
},
|
|
21106
22223
|
kill: () => true
|
|
21107
22224
|
});
|
|
21108
|
-
|
|
21109
|
-
processObject.
|
|
21110
|
-
processObject.
|
|
22225
|
+
const tty = options.tty === true;
|
|
22226
|
+
processObject.stdout = makeOutputStream(stdoutWrite, 1, tty);
|
|
22227
|
+
processObject.stderr = makeOutputStream(stderrWrite, 2, tty);
|
|
22228
|
+
const stdin = options.interactiveStdin ? new streamModule4__default.default.PassThrough() : new streamModule4__default.default.Readable({ read() {
|
|
21111
22229
|
this.push(null);
|
|
21112
22230
|
} });
|
|
21113
|
-
Object.assign(
|
|
21114
|
-
|
|
21115
|
-
|
|
22231
|
+
Object.assign(stdin, {
|
|
22232
|
+
fd: 0,
|
|
22233
|
+
isTTY: tty,
|
|
22234
|
+
setRawMode(enabled = true) {
|
|
22235
|
+
options.onRawMode?.(enabled !== false);
|
|
22236
|
+
return this;
|
|
22237
|
+
},
|
|
22238
|
+
ref() {
|
|
22239
|
+
return this;
|
|
22240
|
+
},
|
|
22241
|
+
unref() {
|
|
22242
|
+
return this;
|
|
22243
|
+
}
|
|
22244
|
+
});
|
|
22245
|
+
processObject.stdin = stdin;
|
|
21116
22246
|
const fs = createFsModule(volume, () => cwd, options.stdinPath);
|
|
21117
22247
|
const path = createPathModule(() => cwd);
|
|
21118
22248
|
const consoleObject = new Console(stdoutWrite, stderrWrite);
|
|
@@ -21130,9 +22260,9 @@ function createCoreModules(options) {
|
|
|
21130
22260
|
const readline = createReadlineModule(() => processObject.stdin);
|
|
21131
22261
|
const dns = createDnsModule();
|
|
21132
22262
|
const builtins = {
|
|
21133
|
-
assert:
|
|
21134
|
-
"assert/strict":
|
|
21135
|
-
buffer: { Buffer:
|
|
22263
|
+
assert: assert_module_default,
|
|
22264
|
+
"assert/strict": assert_module_default.strict ?? assert_module_default,
|
|
22265
|
+
buffer: { Buffer: Buffer2, SlowBuffer: Buffer2, INSPECT_MAX_BYTES: 50, kMaxLength: Buffer2.kMaxLength },
|
|
21136
22266
|
async_hooks: asyncHooks,
|
|
21137
22267
|
child_process: childProcess,
|
|
21138
22268
|
console: consoleObject,
|
|
@@ -21140,7 +22270,7 @@ function createCoreModules(options) {
|
|
|
21140
22270
|
crypto: createCryptoModule(),
|
|
21141
22271
|
dns,
|
|
21142
22272
|
"dns/promises": dns.promises,
|
|
21143
|
-
events:
|
|
22273
|
+
events: EventEmitter4__default.default,
|
|
21144
22274
|
fs,
|
|
21145
22275
|
"fs/promises": fs.promises,
|
|
21146
22276
|
module: moduleBuiltin,
|
|
@@ -21151,24 +22281,24 @@ function createCoreModules(options) {
|
|
|
21151
22281
|
"path/posix": path,
|
|
21152
22282
|
perf_hooks: { performance, PerformanceObserver: globalThis.PerformanceObserver },
|
|
21153
22283
|
process: processObject,
|
|
21154
|
-
punycode:
|
|
22284
|
+
punycode: url_module_default.punycode ?? {},
|
|
21155
22285
|
querystring: querystringModule__default.default,
|
|
21156
22286
|
readline,
|
|
21157
22287
|
"readline/promises": readline.promises,
|
|
21158
|
-
stream:
|
|
22288
|
+
stream: streamModule4__default.default,
|
|
21159
22289
|
"stream/promises": createStreamPromises(),
|
|
21160
22290
|
string_decoder: stringDecoderModule__default.default,
|
|
21161
22291
|
timers: { ...timersModule__default.default, ...timers.api },
|
|
21162
22292
|
"timers/promises": createTimerPromises(),
|
|
21163
|
-
tty: { isatty: () => false, ReadStream:
|
|
21164
|
-
url:
|
|
21165
|
-
util:
|
|
21166
|
-
"util/types":
|
|
21167
|
-
zlib:
|
|
22293
|
+
tty: { isatty: () => false, ReadStream: streamModule4__default.default.Readable, WriteStream: streamModule4__default.default.Writable },
|
|
22294
|
+
url: url_module_default,
|
|
22295
|
+
util: util_module_default,
|
|
22296
|
+
"util/types": util_module_default.types ?? {},
|
|
22297
|
+
zlib: zlib_module_default
|
|
21168
22298
|
};
|
|
21169
22299
|
for (const name of stubNames) builtins[name] = createUnsupportedModule(name);
|
|
21170
22300
|
const globals = {
|
|
21171
|
-
Buffer:
|
|
22301
|
+
Buffer: Buffer2,
|
|
21172
22302
|
console: consoleObject,
|
|
21173
22303
|
process: processObject,
|
|
21174
22304
|
...timers.api
|
|
@@ -21179,7 +22309,20 @@ function createCoreModules(options) {
|
|
|
21179
22309
|
});
|
|
21180
22310
|
globals.global = globalOverlay;
|
|
21181
22311
|
globals.globalThis = globalOverlay;
|
|
21182
|
-
return {
|
|
22312
|
+
return {
|
|
22313
|
+
builtins,
|
|
22314
|
+
globals,
|
|
22315
|
+
process: processObject,
|
|
22316
|
+
pendingHandles: timers.pending,
|
|
22317
|
+
pendingUnrefed: timers.pendingUnrefed,
|
|
22318
|
+
writeStdin: (data) => {
|
|
22319
|
+
if (options.interactiveStdin) stdin.write(data);
|
|
22320
|
+
},
|
|
22321
|
+
endStdin: () => {
|
|
22322
|
+
if (options.interactiveStdin) stdin.end();
|
|
22323
|
+
},
|
|
22324
|
+
readingStdin: () => Boolean(options.interactiveStdin) && stdin.readable === true && (stdin.readableFlowing === true || stdin.listenerCount("readable") > 0 || stdin.listenerCount("keypress") > 0)
|
|
22325
|
+
};
|
|
21183
22326
|
}
|
|
21184
22327
|
var ASYNC_FS_METHODS = [
|
|
21185
22328
|
"readFile",
|
|
@@ -21240,18 +22383,18 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21240
22383
|
const abs = (value) => {
|
|
21241
22384
|
if (typeof value === "number") return requiredFd(fds, value).path;
|
|
21242
22385
|
if (value instanceof URL) value = value.pathname;
|
|
21243
|
-
if (
|
|
22386
|
+
if (Buffer2.isBuffer(value) || value instanceof Uint8Array) value = new TextDecoder().decode(value);
|
|
21244
22387
|
if (typeof value !== "string") throw new TypeError("path must be a string, Buffer, or URL");
|
|
21245
22388
|
return value.startsWith("/") ? clean(value) : resolve(cwd(), value);
|
|
21246
22389
|
};
|
|
21247
|
-
const
|
|
21248
|
-
if (typeof data === "string") return new Uint8Array(
|
|
21249
|
-
if (
|
|
22390
|
+
const bytes2 = (data, encoding) => {
|
|
22391
|
+
if (typeof data === "string") return new Uint8Array(Buffer2.from(data, encoding));
|
|
22392
|
+
if (Buffer2.isBuffer(data) || data instanceof Uint8Array) return new Uint8Array(data);
|
|
21250
22393
|
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
21251
22394
|
throw new TypeError("data must be a string or byte array");
|
|
21252
22395
|
};
|
|
21253
22396
|
const read = (path, encoding) => {
|
|
21254
|
-
const data =
|
|
22397
|
+
const data = Buffer2.from(volume.readFileSync(resolveLinks(volume, abs(path))));
|
|
21255
22398
|
return encoding && encoding !== "buffer" ? data.toString(encoding) : data;
|
|
21256
22399
|
};
|
|
21257
22400
|
const mkdirRecursive = (path, mode) => {
|
|
@@ -21300,12 +22443,12 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21300
22443
|
readFileSync: (path, options) => read(path, typeof options === "object" && options ? options.encoding : options),
|
|
21301
22444
|
writeFileSync: (path, data, options) => {
|
|
21302
22445
|
const encoding = typeof options === "object" && options ? options.encoding : options === "buffer" ? void 0 : options ?? void 0;
|
|
21303
|
-
volume.writeFileSync(abs(path),
|
|
22446
|
+
volume.writeFileSync(abs(path), bytes2(data, encoding ?? void 0));
|
|
21304
22447
|
if (typeof options === "object" && options?.mode !== void 0) volume.chmodSync(abs(path), options.mode);
|
|
21305
22448
|
},
|
|
21306
22449
|
appendFileSync: (path, data, options) => {
|
|
21307
22450
|
const encoding = typeof options === "object" && options ? options.encoding : options === "buffer" ? void 0 : options ?? void 0;
|
|
21308
|
-
volume.appendFileSync(abs(path),
|
|
22451
|
+
volume.appendFileSync(abs(path), bytes2(data, encoding ?? void 0));
|
|
21309
22452
|
},
|
|
21310
22453
|
existsSync: (path) => {
|
|
21311
22454
|
try {
|
|
@@ -21323,7 +22466,7 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21323
22466
|
if (typeof options === "object" && options?.withFileTypes) {
|
|
21324
22467
|
return names.map((name) => new Dirent(name, new Stats2(volume.lstatSync(join(dir3, name))), dir3));
|
|
21325
22468
|
}
|
|
21326
|
-
if ((typeof options === "string" ? options : options?.encoding) === "buffer") return names.map((name) =>
|
|
22469
|
+
if ((typeof options === "string" ? options : options?.encoding) === "buffer") return names.map((name) => Buffer2.from(name));
|
|
21327
22470
|
return names;
|
|
21328
22471
|
},
|
|
21329
22472
|
mkdirSync: (path, options) => {
|
|
@@ -21344,7 +22487,7 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21344
22487
|
renameSync: (from, to) => volume.renameSync(abs(from), abs(to)),
|
|
21345
22488
|
readlinkSync: (path, encoding) => {
|
|
21346
22489
|
const value = volume.readlinkSync(abs(path));
|
|
21347
|
-
return encoding === "buffer" ?
|
|
22490
|
+
return encoding === "buffer" ? Buffer2.from(value) : value;
|
|
21348
22491
|
},
|
|
21349
22492
|
symlinkSync: (target, path) => volume.symlinkSync(target, abs(path)),
|
|
21350
22493
|
linkSync: (from, to) => volume.linkSync(abs(from), abs(to)),
|
|
@@ -21388,7 +22531,7 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21388
22531
|
},
|
|
21389
22532
|
writeSync: (fd, data, offset, length, position) => {
|
|
21390
22533
|
const file3 = requiredFd(fds, fd);
|
|
21391
|
-
const input =
|
|
22534
|
+
const input = bytes2(data);
|
|
21392
22535
|
const chunk = typeof data === "string" ? input : input.subarray(offset ?? 0, (offset ?? 0) + (length ?? input.length));
|
|
21393
22536
|
const old = volume.readFileSync(file3.path);
|
|
21394
22537
|
const start2 = file3.flags.startsWith("a") ? old.length : position ?? file3.position;
|
|
@@ -21400,13 +22543,13 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21400
22543
|
return chunk.length;
|
|
21401
22544
|
},
|
|
21402
22545
|
createReadStream: (path) => {
|
|
21403
|
-
const data =
|
|
21404
|
-
return
|
|
22546
|
+
const data = Buffer2.from(volume.readFileSync(resolveLinks(volume, abs(path))));
|
|
22547
|
+
return streamModule4__default.default.Readable.from([data]);
|
|
21405
22548
|
},
|
|
21406
22549
|
createWriteStream: (path, options) => {
|
|
21407
22550
|
const target = abs(path);
|
|
21408
22551
|
let first = true;
|
|
21409
|
-
return new
|
|
22552
|
+
return new streamModule4__default.default.Writable({ write(chunk, _encoding, done) {
|
|
21410
22553
|
try {
|
|
21411
22554
|
if (options?.flags?.startsWith("a") || !first) volume.appendFileSync(target, new Uint8Array(chunk));
|
|
21412
22555
|
else volume.writeFileSync(target, new Uint8Array(chunk));
|
|
@@ -21528,12 +22671,12 @@ function requiredFd(fds, fd) {
|
|
|
21528
22671
|
function fsError(code, syscall, path) {
|
|
21529
22672
|
return Object.assign(new Error(`${code}: ${syscall}, '${path}'`), { code, syscall, path });
|
|
21530
22673
|
}
|
|
21531
|
-
function makeOutputStream(write, fd) {
|
|
21532
|
-
const stream = new
|
|
21533
|
-
write(
|
|
22674
|
+
function makeOutputStream(write, fd, isTTY = false) {
|
|
22675
|
+
const stream = new streamModule4__default.default.Writable({ write(chunk, _encoding, done) {
|
|
22676
|
+
write(Buffer2.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk));
|
|
21534
22677
|
done();
|
|
21535
22678
|
} });
|
|
21536
|
-
return Object.assign(stream, { fd, isTTY
|
|
22679
|
+
return Object.assign(stream, { fd, isTTY, columns: 80, rows: 24 });
|
|
21537
22680
|
}
|
|
21538
22681
|
var Console = class {
|
|
21539
22682
|
constructor(out, err) {
|
|
@@ -21543,7 +22686,7 @@ var Console = class {
|
|
|
21543
22686
|
out;
|
|
21544
22687
|
err;
|
|
21545
22688
|
log = (...args) => {
|
|
21546
|
-
this.out(
|
|
22689
|
+
this.out(util_module_default.format(...args) + "\n");
|
|
21547
22690
|
};
|
|
21548
22691
|
info = (...args) => {
|
|
21549
22692
|
this.log(...args);
|
|
@@ -21552,20 +22695,20 @@ var Console = class {
|
|
|
21552
22695
|
this.log(...args);
|
|
21553
22696
|
};
|
|
21554
22697
|
warn = (...args) => {
|
|
21555
|
-
this.err(
|
|
22698
|
+
this.err(util_module_default.format(...args) + "\n");
|
|
21556
22699
|
};
|
|
21557
22700
|
error = (...args) => {
|
|
21558
22701
|
this.warn(...args);
|
|
21559
22702
|
};
|
|
21560
22703
|
dir = (value, options) => {
|
|
21561
|
-
this.out(
|
|
22704
|
+
this.out(util_module_default.inspect(value, options) + "\n");
|
|
21562
22705
|
};
|
|
21563
22706
|
trace = (...args) => {
|
|
21564
|
-
this.err(`Trace: ${
|
|
22707
|
+
this.err(`Trace: ${util_module_default.format(...args)}
|
|
21565
22708
|
`);
|
|
21566
22709
|
};
|
|
21567
22710
|
assert = (value, ...args) => {
|
|
21568
|
-
if (!value) this.err(`Assertion failed: ${
|
|
22711
|
+
if (!value) this.err(`Assertion failed: ${util_module_default.format(...args)}
|
|
21569
22712
|
`);
|
|
21570
22713
|
};
|
|
21571
22714
|
group = (...args) => {
|
|
@@ -21587,63 +22730,6 @@ var Console = class {
|
|
|
21587
22730
|
timeLog = (_label = "default") => {
|
|
21588
22731
|
};
|
|
21589
22732
|
};
|
|
21590
|
-
function createReadlineModule(stdin) {
|
|
21591
|
-
class Interface extends EventEmitter3__default.default {
|
|
21592
|
-
constructor(input) {
|
|
21593
|
-
super();
|
|
21594
|
-
this.input = input;
|
|
21595
|
-
input?.on?.("data", (chunk) => {
|
|
21596
|
-
for (const line of String(chunk).split("\n")) this.lines.push(line);
|
|
21597
|
-
while (this.lines.length > 1) this.emit("line", this.lines.shift());
|
|
21598
|
-
});
|
|
21599
|
-
input?.on?.("end", () => this.close());
|
|
21600
|
-
}
|
|
21601
|
-
input;
|
|
21602
|
-
closed = false;
|
|
21603
|
-
lines = [];
|
|
21604
|
-
question(_query, callback) {
|
|
21605
|
-
const answer = this.lines.shift() ?? "";
|
|
21606
|
-
if (callback) {
|
|
21607
|
-
queueMicrotask(() => callback(answer));
|
|
21608
|
-
return;
|
|
21609
|
-
}
|
|
21610
|
-
return Promise.resolve(answer);
|
|
21611
|
-
}
|
|
21612
|
-
prompt() {
|
|
21613
|
-
}
|
|
21614
|
-
setPrompt() {
|
|
21615
|
-
}
|
|
21616
|
-
pause() {
|
|
21617
|
-
return this;
|
|
21618
|
-
}
|
|
21619
|
-
resume() {
|
|
21620
|
-
return this;
|
|
21621
|
-
}
|
|
21622
|
-
write() {
|
|
21623
|
-
}
|
|
21624
|
-
close() {
|
|
21625
|
-
if (this.closed) return;
|
|
21626
|
-
this.closed = true;
|
|
21627
|
-
this.emit("close");
|
|
21628
|
-
}
|
|
21629
|
-
async *[Symbol.asyncIterator]() {
|
|
21630
|
-
while (this.lines.length) yield this.lines.shift();
|
|
21631
|
-
}
|
|
21632
|
-
}
|
|
21633
|
-
const createInterface = (options) => new Interface(options?.input ?? (Array.isArray(options) ? options[0] : stdin()));
|
|
21634
|
-
const noop = () => {
|
|
21635
|
-
};
|
|
21636
|
-
const base = {
|
|
21637
|
-
Interface,
|
|
21638
|
-
createInterface,
|
|
21639
|
-
clearLine: noop,
|
|
21640
|
-
clearScreenDown: noop,
|
|
21641
|
-
cursorTo: noop,
|
|
21642
|
-
moveCursor: noop,
|
|
21643
|
-
emitKeypressEvents: noop
|
|
21644
|
-
};
|
|
21645
|
-
return { ...base, promises: { ...base, Interface, createInterface } };
|
|
21646
|
-
}
|
|
21647
22733
|
function createDnsModule() {
|
|
21648
22734
|
const LOOPBACK = {
|
|
21649
22735
|
localhost: { address: "127.0.0.1", family: 4 },
|
|
@@ -21673,15 +22759,6 @@ function createDnsModule() {
|
|
|
21673
22759
|
}
|
|
21674
22760
|
});
|
|
21675
22761
|
};
|
|
21676
|
-
const notFound = (hostname) => Promise.reject(lookupThrow(hostname));
|
|
21677
|
-
const lookupThrow = (hostname) => {
|
|
21678
|
-
try {
|
|
21679
|
-
lookupSync(hostname);
|
|
21680
|
-
return null;
|
|
21681
|
-
} catch (error) {
|
|
21682
|
-
return error;
|
|
21683
|
-
}
|
|
21684
|
-
};
|
|
21685
22762
|
const promises = {
|
|
21686
22763
|
lookup: async (hostname, options) => {
|
|
21687
22764
|
const entry = lookupSync(hostname);
|
|
@@ -21689,7 +22766,10 @@ function createDnsModule() {
|
|
|
21689
22766
|
},
|
|
21690
22767
|
resolve4: async (hostname) => [lookupSync(hostname).address],
|
|
21691
22768
|
resolve6: async (hostname) => [lookupSync(hostname).address],
|
|
21692
|
-
reverse: async (address) =>
|
|
22769
|
+
reverse: async (address) => {
|
|
22770
|
+
if (address === "127.0.0.1") return ["localhost"];
|
|
22771
|
+
return [lookupSync(address).address];
|
|
22772
|
+
}
|
|
21693
22773
|
};
|
|
21694
22774
|
return {
|
|
21695
22775
|
lookup,
|
|
@@ -21830,33 +22910,78 @@ var ERRNO_CONSTANTS = {
|
|
|
21830
22910
|
};
|
|
21831
22911
|
function createTrackedTimers() {
|
|
21832
22912
|
const live = /* @__PURE__ */ new Set();
|
|
21833
|
-
const
|
|
22913
|
+
const unrefed = /* @__PURE__ */ new Set();
|
|
22914
|
+
const states = /* @__PURE__ */ new WeakMap();
|
|
22915
|
+
const track = (native) => {
|
|
22916
|
+
const state = { native, active: true, referenced: true };
|
|
22917
|
+
const handle = {
|
|
22918
|
+
ref() {
|
|
22919
|
+
state.referenced = true;
|
|
22920
|
+
unrefed.delete(handle);
|
|
22921
|
+
if (state.active) live.add(handle);
|
|
22922
|
+
state.native?.ref?.();
|
|
22923
|
+
return handle;
|
|
22924
|
+
},
|
|
22925
|
+
unref() {
|
|
22926
|
+
state.referenced = false;
|
|
22927
|
+
live.delete(handle);
|
|
22928
|
+
if (state.active) unrefed.add(handle);
|
|
22929
|
+
state.native?.unref?.();
|
|
22930
|
+
return handle;
|
|
22931
|
+
},
|
|
22932
|
+
hasRef: () => state.referenced,
|
|
22933
|
+
refresh() {
|
|
22934
|
+
state.native?.refresh?.();
|
|
22935
|
+
return handle;
|
|
22936
|
+
},
|
|
22937
|
+
[Symbol.toPrimitive]: () => Number(state.native)
|
|
22938
|
+
};
|
|
22939
|
+
states.set(handle, state);
|
|
21834
22940
|
live.add(handle);
|
|
21835
22941
|
return handle;
|
|
21836
22942
|
};
|
|
22943
|
+
const complete = (handle) => {
|
|
22944
|
+
const state = states.get(handle);
|
|
22945
|
+
if (state) state.active = false;
|
|
22946
|
+
live.delete(handle);
|
|
22947
|
+
unrefed.delete(handle);
|
|
22948
|
+
};
|
|
21837
22949
|
const setTimeoutTracked = (fn, delay, ...args) => {
|
|
21838
|
-
|
|
22950
|
+
let handle;
|
|
22951
|
+
const native = setTimeout(
|
|
21839
22952
|
(...inner) => {
|
|
21840
|
-
|
|
22953
|
+
complete(handle);
|
|
21841
22954
|
fn(...inner);
|
|
21842
22955
|
},
|
|
21843
22956
|
delay,
|
|
21844
22957
|
...args
|
|
21845
22958
|
);
|
|
21846
|
-
|
|
22959
|
+
handle = track(native);
|
|
21847
22960
|
return handle;
|
|
21848
22961
|
};
|
|
21849
22962
|
const setIntervalTracked = (fn, delay, ...args) => track(setInterval(fn, delay, ...args));
|
|
21850
22963
|
const hostSetImmediate = globalThis.setImmediate;
|
|
21851
22964
|
const setImmediateTracked = (fn, ...args) => {
|
|
21852
|
-
|
|
21853
|
-
|
|
22965
|
+
if (!hostSetImmediate) return setTimeoutTracked(fn, 0, ...args);
|
|
22966
|
+
let handle;
|
|
22967
|
+
const native = hostSetImmediate((...inner) => {
|
|
22968
|
+
complete(handle);
|
|
21854
22969
|
fn(...inner);
|
|
21855
|
-
}, ...args)
|
|
21856
|
-
|
|
22970
|
+
}, ...args);
|
|
22971
|
+
handle = track(native);
|
|
21857
22972
|
return handle;
|
|
21858
22973
|
};
|
|
21859
22974
|
const clear2 = (handle, native) => {
|
|
22975
|
+
if (typeof handle === "object" && handle !== null) {
|
|
22976
|
+
const state = states.get(handle);
|
|
22977
|
+
if (state) {
|
|
22978
|
+
state.active = false;
|
|
22979
|
+
live.delete(handle);
|
|
22980
|
+
unrefed.delete(handle);
|
|
22981
|
+
native(state.native);
|
|
22982
|
+
return;
|
|
22983
|
+
}
|
|
22984
|
+
}
|
|
21860
22985
|
live.delete(handle);
|
|
21861
22986
|
native(handle);
|
|
21862
22987
|
};
|
|
@@ -21869,7 +22994,8 @@ function createTrackedTimers() {
|
|
|
21869
22994
|
clearInterval: (handle) => clear2(handle, clearInterval),
|
|
21870
22995
|
clearImmediate: (handle) => clear2(handle, globalThis.clearImmediate ?? clearTimeout)
|
|
21871
22996
|
},
|
|
21872
|
-
pending: () => live.size
|
|
22997
|
+
pending: () => live.size,
|
|
22998
|
+
pendingUnrefed: () => unrefed.size
|
|
21873
22999
|
};
|
|
21874
23000
|
}
|
|
21875
23001
|
function createTimerPromises() {
|
|
@@ -21956,10 +23082,10 @@ function createStreamPromises() {
|
|
|
21956
23082
|
return {
|
|
21957
23083
|
pipeline: (...streams) => new Promise((resolve2, reject) => {
|
|
21958
23084
|
const callback = (error) => error ? reject(error) : resolve2();
|
|
21959
|
-
|
|
23085
|
+
streamModule4__default.default.pipeline(...streams, callback);
|
|
21960
23086
|
}),
|
|
21961
23087
|
finished: (stream) => new Promise((resolve2, reject) => {
|
|
21962
|
-
|
|
23088
|
+
streamModule4__default.default.finished(stream, (error) => error ? reject(error) : resolve2());
|
|
21963
23089
|
})
|
|
21964
23090
|
};
|
|
21965
23091
|
}
|
|
@@ -22086,26 +23212,26 @@ var MemoryVolume = class {
|
|
|
22086
23212
|
writeFileSync(path, data) {
|
|
22087
23213
|
const key = this.key(path);
|
|
22088
23214
|
this.requireParent(key, "open");
|
|
22089
|
-
const
|
|
23215
|
+
const bytes2 = typeof data === "string" ? encoder6.encode(data) : data.slice();
|
|
22090
23216
|
const current = this.entries.get(key);
|
|
22091
23217
|
if (current?.kind === "directory") throw new VolumeError("EISDIR", "open", key);
|
|
22092
23218
|
if (current?.kind === "symlink") throw new VolumeError("EINVAL", "open", key);
|
|
22093
23219
|
if (current) {
|
|
22094
|
-
current.data =
|
|
23220
|
+
current.data = bytes2;
|
|
22095
23221
|
this.touchChanged(current, true);
|
|
22096
23222
|
} else {
|
|
22097
|
-
this.entries.set(key, this.inode("file", 438,
|
|
23223
|
+
this.entries.set(key, this.inode("file", 438, bytes2));
|
|
22098
23224
|
}
|
|
22099
23225
|
}
|
|
22100
23226
|
appendFileSync(path, data) {
|
|
22101
23227
|
const key = this.key(path);
|
|
22102
|
-
const
|
|
23228
|
+
const bytes2 = typeof data === "string" ? encoder6.encode(data) : data;
|
|
22103
23229
|
const current = this.entries.get(key);
|
|
22104
|
-
if (!current) return this.writeFileSync(key,
|
|
23230
|
+
if (!current) return this.writeFileSync(key, bytes2);
|
|
22105
23231
|
if (current.kind !== "file") throw new VolumeError(current.kind === "directory" ? "EISDIR" : "EINVAL", "open", key);
|
|
22106
|
-
const next = new Uint8Array(current.data.length +
|
|
23232
|
+
const next = new Uint8Array(current.data.length + bytes2.length);
|
|
22107
23233
|
next.set(current.data);
|
|
22108
|
-
next.set(
|
|
23234
|
+
next.set(bytes2, current.data.length);
|
|
22109
23235
|
current.data = next;
|
|
22110
23236
|
this.touchChanged(current, true);
|
|
22111
23237
|
}
|
|
@@ -22379,8 +23505,38 @@ function esbuildUnavailable() {
|
|
|
22379
23505
|
error.code = "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM";
|
|
22380
23506
|
return error;
|
|
22381
23507
|
}
|
|
23508
|
+
var installed = false;
|
|
23509
|
+
function ensureProcessGlobal() {
|
|
23510
|
+
if (installed) return;
|
|
23511
|
+
installed = true;
|
|
23512
|
+
if (typeof globalThis.process !== "undefined") return;
|
|
23513
|
+
Object.defineProperty(globalThis, "process", {
|
|
23514
|
+
value: processShim__default.default,
|
|
23515
|
+
writable: true,
|
|
23516
|
+
configurable: true
|
|
23517
|
+
});
|
|
23518
|
+
}
|
|
23519
|
+
|
|
23520
|
+
// src/runtime/host-rolldown.ts
|
|
23521
|
+
async function loadHostRolldownBinding() {
|
|
23522
|
+
if (typeof window !== "undefined" && globalThis.crossOriginIsolated !== true) {
|
|
23523
|
+
throw new Error(
|
|
23524
|
+
"Vite 8/Rolldown requires cross-origin isolation. Serve the app with Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp headers."
|
|
23525
|
+
);
|
|
23526
|
+
}
|
|
23527
|
+
try {
|
|
23528
|
+
const loaded = await import('@rolldown/binding-wasm32-wasi');
|
|
23529
|
+
return "__fs" in loaded ? { ...loaded } : loaded.default ?? loaded;
|
|
23530
|
+
} catch (error) {
|
|
23531
|
+
if (typeof process !== "undefined" && process.env?.SANDBOXEDJS_DEBUG) {
|
|
23532
|
+
console.error("[sandboxedjs] Rolldown WASI binding unavailable:", error);
|
|
23533
|
+
}
|
|
23534
|
+
throw new Error("The optional Rolldown WASI binding could not be loaded.", { cause: error });
|
|
23535
|
+
}
|
|
23536
|
+
}
|
|
22382
23537
|
|
|
22383
23538
|
// src/runtime/local-runtime-pod.ts
|
|
23539
|
+
init_path();
|
|
22384
23540
|
var WASM_ALIASES = {
|
|
22385
23541
|
esbuild: "esbuild-wasm",
|
|
22386
23542
|
rollup: "@rollup/wasm-node"
|
|
@@ -22392,7 +23548,7 @@ var ProcessExit = class extends Error {
|
|
|
22392
23548
|
}
|
|
22393
23549
|
code;
|
|
22394
23550
|
};
|
|
22395
|
-
var LocalProcess = class extends
|
|
23551
|
+
var LocalProcess = class extends EventEmitter4__default.default {
|
|
22396
23552
|
constructor(task) {
|
|
22397
23553
|
super();
|
|
22398
23554
|
this.task = task;
|
|
@@ -22410,6 +23566,10 @@ var LocalProcess = class extends EventEmitter3__default.default {
|
|
|
22410
23566
|
killed = false;
|
|
22411
23567
|
out = [];
|
|
22412
23568
|
err = [];
|
|
23569
|
+
input;
|
|
23570
|
+
end;
|
|
23571
|
+
inputEnded = false;
|
|
23572
|
+
pendingInput = [];
|
|
22413
23573
|
resolveKilled;
|
|
22414
23574
|
killedPromise = new Promise((resolve2) => {
|
|
22415
23575
|
this.resolveKilled = resolve2;
|
|
@@ -22425,7 +23585,29 @@ var LocalProcess = class extends EventEmitter3__default.default {
|
|
|
22425
23585
|
this.err.push(text2);
|
|
22426
23586
|
this.emit("error", text2);
|
|
22427
23587
|
}
|
|
22428
|
-
|
|
23588
|
+
/**
|
|
23589
|
+
* Deliver input to the running program.
|
|
23590
|
+
*
|
|
23591
|
+
* The program's `process.stdin` does not exist until its task starts, so
|
|
23592
|
+
* anything written before then is held. Dropping it would lose the first
|
|
23593
|
+
* keystrokes of an interactive session, which arrive while the program is
|
|
23594
|
+
* still loading.
|
|
23595
|
+
*/
|
|
23596
|
+
write(data) {
|
|
23597
|
+
if (this.input) this.input(data);
|
|
23598
|
+
else this.pendingInput.push(data);
|
|
23599
|
+
}
|
|
23600
|
+
/** Close the program's input, which a reader sees as end-of-file. */
|
|
23601
|
+
endInput() {
|
|
23602
|
+
this.inputEnded = true;
|
|
23603
|
+
this.end?.();
|
|
23604
|
+
}
|
|
23605
|
+
/** Called by the task once the program's stdin exists. */
|
|
23606
|
+
acceptInput(input, end) {
|
|
23607
|
+
this.input = input;
|
|
23608
|
+
this.end = end;
|
|
23609
|
+
for (const chunk of this.pendingInput.splice(0)) input(chunk);
|
|
23610
|
+
if (this.inputEnded) end();
|
|
22429
23611
|
}
|
|
22430
23612
|
kill(_signal = "SIGTERM") {
|
|
22431
23613
|
this.killed = true;
|
|
@@ -22537,6 +23719,46 @@ var PodChildProcess = class {
|
|
|
22537
23719
|
}
|
|
22538
23720
|
};
|
|
22539
23721
|
var nextChildPid = 805306368;
|
|
23722
|
+
var liveProcesses = [];
|
|
23723
|
+
var reportingInstalled = false;
|
|
23724
|
+
function reportEscapedError(reason) {
|
|
23725
|
+
const target = liveProcesses.at(-1);
|
|
23726
|
+
if (!target) return false;
|
|
23727
|
+
target.error(formatError(reason));
|
|
23728
|
+
target.exitNow(1);
|
|
23729
|
+
return true;
|
|
23730
|
+
}
|
|
23731
|
+
function trackProcess(proc) {
|
|
23732
|
+
liveProcesses.push(proc);
|
|
23733
|
+
if (!reportingInstalled) {
|
|
23734
|
+
reportingInstalled = true;
|
|
23735
|
+
installEscapedErrorReporting();
|
|
23736
|
+
}
|
|
23737
|
+
return () => {
|
|
23738
|
+
const index = liveProcesses.indexOf(proc);
|
|
23739
|
+
if (index >= 0) liveProcesses.splice(index, 1);
|
|
23740
|
+
if (liveProcesses.length === 0) {
|
|
23741
|
+
reportingInstalled = false;
|
|
23742
|
+
removeEscapedErrorReporting();
|
|
23743
|
+
}
|
|
23744
|
+
};
|
|
23745
|
+
}
|
|
23746
|
+
var onNodeRejection = (reason) => {
|
|
23747
|
+
if (!reportEscapedError(reason)) throw reason;
|
|
23748
|
+
};
|
|
23749
|
+
var onBrowserRejection = (event) => {
|
|
23750
|
+
if (reportEscapedError(event.reason)) event.preventDefault();
|
|
23751
|
+
};
|
|
23752
|
+
function installEscapedErrorReporting() {
|
|
23753
|
+
const host2 = globalThis;
|
|
23754
|
+
if (host2.process?.on && host2.process.versions?.node) host2.process.on("unhandledRejection", onNodeRejection);
|
|
23755
|
+
else host2.addEventListener?.("unhandledrejection", onBrowserRejection);
|
|
23756
|
+
}
|
|
23757
|
+
function removeEscapedErrorReporting() {
|
|
23758
|
+
const host2 = globalThis;
|
|
23759
|
+
if (host2.process?.off && host2.process.versions?.node) host2.process.off("unhandledRejection", onNodeRejection);
|
|
23760
|
+
else host2.removeEventListener?.("unhandledrejection", onBrowserRejection);
|
|
23761
|
+
}
|
|
22540
23762
|
var DRAIN_TURNS = 4;
|
|
22541
23763
|
var LocalRuntimePod = class _LocalRuntimePod {
|
|
22542
23764
|
volume = new MemoryVolume();
|
|
@@ -22565,7 +23787,9 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22565
23787
|
aliases;
|
|
22566
23788
|
modules;
|
|
22567
23789
|
esbuild;
|
|
23790
|
+
rolldownBinding;
|
|
22568
23791
|
constructor(options) {
|
|
23792
|
+
ensureProcessGlobal();
|
|
22569
23793
|
this.workdir = options.workdir ?? "/";
|
|
22570
23794
|
this.env = { ...options.env };
|
|
22571
23795
|
this.aliases = { ...WASM_ALIASES, ...options.aliases };
|
|
@@ -22597,8 +23821,10 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22597
23821
|
const env2 = { ...this.env, ...isRecord(options.env) ? options.env : {} };
|
|
22598
23822
|
const owner = `${this.instanceId}:${Math.random().toString(36).slice(2)}`;
|
|
22599
23823
|
return new LocalProcess(async (proc) => {
|
|
23824
|
+
await this.prepareRolldown(cwd, env2);
|
|
23825
|
+
const untrack = trackProcess(proc);
|
|
22600
23826
|
let requestedExit = 0;
|
|
22601
|
-
let
|
|
23827
|
+
let engine;
|
|
22602
23828
|
const core = createCoreModules({
|
|
22603
23829
|
volume: this.volume,
|
|
22604
23830
|
cwd,
|
|
@@ -22606,16 +23832,24 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22606
23832
|
argv: Array.isArray(options.argv) ? options.argv : ["/usr/bin/node", script, ...args.slice(1)],
|
|
22607
23833
|
stdout: (text2) => proc.output(text2),
|
|
22608
23834
|
stderr: (text2) => proc.error(text2),
|
|
23835
|
+
/* `process.exit` ends the process either way. The throw is only to
|
|
23836
|
+
* abandon the rest of a module body still running synchronously —
|
|
23837
|
+
* thrown from a later callback it would escape into whichever library
|
|
23838
|
+
* scheduled that callback and look like an unrelated crash. */
|
|
22609
23839
|
onExit: (code) => {
|
|
22610
23840
|
requestedExit = code;
|
|
22611
|
-
if (evaluating) throw new ProcessExit(code);
|
|
22612
23841
|
proc.exitNow(code);
|
|
23842
|
+
if (engine?.isEvaluating) throw new ProcessExit(code);
|
|
22613
23843
|
},
|
|
22614
23844
|
http: { router: this.router, owner },
|
|
22615
23845
|
spawnChild: (config) => this.processManager.spawn(config),
|
|
22616
|
-
...typeof options.stdinPath === "string" ? { stdinPath: options.stdinPath } : {}
|
|
23846
|
+
...typeof options.stdinPath === "string" ? { stdinPath: options.stdinPath } : {},
|
|
23847
|
+
...options.interactiveStdin ? { interactiveStdin: true } : {},
|
|
23848
|
+
...options.tty ? { tty: true } : {},
|
|
23849
|
+
onRawMode: (enabled) => proc.emit("rawmode", enabled)
|
|
22617
23850
|
});
|
|
22618
|
-
|
|
23851
|
+
proc.acceptInput((data) => core.writeStdin(data), () => core.endStdin());
|
|
23852
|
+
engine = new CommonJsEngine(this.volume, {
|
|
22619
23853
|
cwd,
|
|
22620
23854
|
builtins: core.builtins,
|
|
22621
23855
|
globals: core.globals,
|
|
@@ -22623,22 +23857,38 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22623
23857
|
overrides: this.modules
|
|
22624
23858
|
});
|
|
22625
23859
|
try {
|
|
22626
|
-
|
|
22627
|
-
|
|
22628
|
-
} finally {
|
|
22629
|
-
evaluating = false;
|
|
22630
|
-
}
|
|
22631
|
-
await this.settle(owner, core.pendingHandles);
|
|
23860
|
+
await engine.run(script);
|
|
23861
|
+
await this.settle(owner, core.pendingHandles, core.pendingUnrefed, core.readingStdin);
|
|
22632
23862
|
if (this.router.activePorts(owner).length) {
|
|
22633
23863
|
await proc.waitForKill();
|
|
22634
23864
|
return 137;
|
|
22635
23865
|
}
|
|
22636
23866
|
return requestedExit;
|
|
22637
23867
|
} finally {
|
|
23868
|
+
untrack();
|
|
22638
23869
|
this.router.closeOwner(owner);
|
|
22639
23870
|
}
|
|
22640
23871
|
});
|
|
22641
23872
|
}
|
|
23873
|
+
/**
|
|
23874
|
+
* Rolldown's JavaScript API synchronously requires its compiled binding.
|
|
23875
|
+
* When a project contains Rolldown, preload the official WASI build in the
|
|
23876
|
+
* host and expose it through the module override table before evaluation.
|
|
23877
|
+
* Keeping this demand-driven avoids adding WASM startup cost to ordinary
|
|
23878
|
+
* shells and Node programs.
|
|
23879
|
+
*/
|
|
23880
|
+
async prepareRolldown(cwd, env2) {
|
|
23881
|
+
const specifier = "@rolldown/binding-wasm32-wasi";
|
|
23882
|
+
if (!this.modules[specifier] && packageInstalled(this.volume, cwd, "rolldown")) {
|
|
23883
|
+
this.rolldownBinding ??= loadHostRolldownBinding();
|
|
23884
|
+
const binding = await this.rolldownBinding;
|
|
23885
|
+
if (binding) this.modules[specifier] = binding;
|
|
23886
|
+
}
|
|
23887
|
+
if (this.modules[specifier]) {
|
|
23888
|
+
syncRolldownFileSystem(this.modules[specifier], this.volume, cwd);
|
|
23889
|
+
env2.NAPI_RS_FORCE_WASI ??= "true";
|
|
23890
|
+
}
|
|
23891
|
+
}
|
|
22642
23892
|
/**
|
|
22643
23893
|
* Wait until the process has either started serving or genuinely run out of
|
|
22644
23894
|
* work.
|
|
@@ -22654,12 +23904,18 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22654
23904
|
* A plain script that has genuinely finished falls straight through both,
|
|
22655
23905
|
* costing a handful of empty turns.
|
|
22656
23906
|
*/
|
|
22657
|
-
async settle(owner, pendingHandles) {
|
|
23907
|
+
async settle(owner, pendingHandles, pendingUnrefed, readingStdin) {
|
|
22658
23908
|
for (let turn = 0; turn < DRAIN_TURNS; turn++) {
|
|
22659
23909
|
if (this.router.activePorts(owner).length) return;
|
|
22660
23910
|
await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
22661
23911
|
}
|
|
22662
|
-
|
|
23912
|
+
if (pendingHandles() === 0 && pendingUnrefed() > 0 && !readingStdin()) {
|
|
23913
|
+
const deadline = Date.now() + 1e3;
|
|
23914
|
+
while (!this.router.activePorts(owner).length && Date.now() < deadline) {
|
|
23915
|
+
await new Promise((resolve2) => setTimeout(resolve2, 5));
|
|
23916
|
+
}
|
|
23917
|
+
}
|
|
23918
|
+
while (!this.router.activePorts(owner).length && (pendingHandles() > 0 || readingStdin())) {
|
|
22663
23919
|
await new Promise((resolve2) => setTimeout(resolve2, 5));
|
|
22664
23920
|
}
|
|
22665
23921
|
}
|
|
@@ -22711,6 +23967,60 @@ function formatError(error) {
|
|
|
22711
23967
|
function isRecord(value) {
|
|
22712
23968
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22713
23969
|
}
|
|
23970
|
+
function packageInstalled(volume, cwd, wanted) {
|
|
23971
|
+
for (let dir3 = clean(cwd); ; dir3 = dirname(dir3)) {
|
|
23972
|
+
if (packageTreeContains(volume, join(dir3, "node_modules"), wanted, /* @__PURE__ */ new Set())) return true;
|
|
23973
|
+
if (dir3 === "/") return false;
|
|
23974
|
+
}
|
|
23975
|
+
}
|
|
23976
|
+
function packageTreeContains(volume, modulesRoot, wanted, visited) {
|
|
23977
|
+
if (visited.has(modulesRoot) || !directory(volume, modulesRoot)) return false;
|
|
23978
|
+
visited.add(modulesRoot);
|
|
23979
|
+
if (directory(volume, join(modulesRoot, wanted))) return true;
|
|
23980
|
+
for (const entry of volume.readdirSync(modulesRoot)) {
|
|
23981
|
+
if (entry === ".bin") continue;
|
|
23982
|
+
const first = join(modulesRoot, entry);
|
|
23983
|
+
const packages = entry.startsWith("@") && directory(volume, first) ? volume.readdirSync(first).map((name) => join(first, name)) : [first];
|
|
23984
|
+
for (const root of packages) {
|
|
23985
|
+
if (directory(volume, root) && packageTreeContains(volume, join(root, "node_modules"), wanted, visited)) {
|
|
23986
|
+
return true;
|
|
23987
|
+
}
|
|
23988
|
+
}
|
|
23989
|
+
}
|
|
23990
|
+
return false;
|
|
23991
|
+
}
|
|
23992
|
+
function directory(volume, path) {
|
|
23993
|
+
try {
|
|
23994
|
+
return volume.lstatSync(path).isDirectory();
|
|
23995
|
+
} catch {
|
|
23996
|
+
return false;
|
|
23997
|
+
}
|
|
23998
|
+
}
|
|
23999
|
+
function syncRolldownFileSystem(binding, volume, root) {
|
|
24000
|
+
const fs = binding?.__fs;
|
|
24001
|
+
if (!fs?.mkdirSync || !fs?.writeFileSync) return;
|
|
24002
|
+
try {
|
|
24003
|
+
fs.rmSync?.(root, { recursive: true, force: true });
|
|
24004
|
+
} catch {
|
|
24005
|
+
}
|
|
24006
|
+
const copy = (path) => {
|
|
24007
|
+
const stat2 = volume.lstatSync(path);
|
|
24008
|
+
if (stat2.isDirectory()) {
|
|
24009
|
+
fs.mkdirSync(path, { recursive: true });
|
|
24010
|
+
for (const name of volume.readdirSync(path)) copy(join(path, name));
|
|
24011
|
+
} else if (stat2.isSymbolicLink()) {
|
|
24012
|
+
fs.mkdirSync(dirname(path), { recursive: true });
|
|
24013
|
+
try {
|
|
24014
|
+
fs.symlinkSync(volume.readlinkSync(path), path);
|
|
24015
|
+
} catch {
|
|
24016
|
+
}
|
|
24017
|
+
} else if (!path.endsWith(".node")) {
|
|
24018
|
+
fs.mkdirSync(dirname(path), { recursive: true });
|
|
24019
|
+
fs.writeFileSync(path, volume.readFileSync(path));
|
|
24020
|
+
}
|
|
24021
|
+
};
|
|
24022
|
+
copy(clean(root));
|
|
24023
|
+
}
|
|
22714
24024
|
|
|
22715
24025
|
// src/container/container.ts
|
|
22716
24026
|
var Container = class _Container {
|
|
@@ -22791,9 +24101,9 @@ var Container = class _Container {
|
|
|
22791
24101
|
}
|
|
22792
24102
|
mountSync(files, opts) {
|
|
22793
24103
|
this.assertActive();
|
|
22794
|
-
const
|
|
24104
|
+
const base2 = opts.cwd ?? this.defaults.cwd;
|
|
22795
24105
|
for (const [key, content] of Object.entries(files)) {
|
|
22796
|
-
const abs = resolve(
|
|
24106
|
+
const abs = resolve(base2, key);
|
|
22797
24107
|
const parent = dirname(abs);
|
|
22798
24108
|
if (!this.kernel.vfs.lexists(parent)) {
|
|
22799
24109
|
this.kernel.vfs.mkdir(parent, { recursive: true, mode: 493, cred: this.defaults.cred });
|
|
@@ -23035,17 +24345,17 @@ var Container = class _Container {
|
|
|
23035
24345
|
body: init.body ?? null
|
|
23036
24346
|
});
|
|
23037
24347
|
const bodyRaw = res.body;
|
|
23038
|
-
const
|
|
24348
|
+
const bytes2 = bodyRaw instanceof Uint8Array ? bodyRaw : (
|
|
23039
24349
|
// The binary dispatcher answers with an ArrayBuffer.
|
|
23040
24350
|
bodyRaw instanceof ArrayBuffer ? new Uint8Array(bodyRaw) : typeof bodyRaw === "string" ? new TextEncoder().encode(bodyRaw) : new Uint8Array(0)
|
|
23041
24351
|
);
|
|
23042
|
-
const body = typeof bodyRaw === "string" ? bodyRaw : new TextDecoder().decode(
|
|
24352
|
+
const body = typeof bodyRaw === "string" ? bodyRaw : new TextDecoder().decode(bytes2);
|
|
23043
24353
|
return {
|
|
23044
24354
|
status: res.statusCode ?? 200,
|
|
23045
24355
|
statusText: res.statusMessage ?? "",
|
|
23046
24356
|
headers: res.headers ?? {},
|
|
23047
24357
|
body,
|
|
23048
|
-
bytes,
|
|
24358
|
+
bytes: bytes2,
|
|
23049
24359
|
json() {
|
|
23050
24360
|
return JSON.parse(body);
|
|
23051
24361
|
}
|
|
@@ -23054,7 +24364,7 @@ var Container = class _Container {
|
|
|
23054
24364
|
/**
|
|
23055
24365
|
* Deliver a request whose body is bytes, without letting them become text.
|
|
23056
24366
|
*
|
|
23057
|
-
*
|
|
24367
|
+
* A RuntimePod's public `request()` may run the body through `toString("utf8")` on
|
|
23058
24368
|
* its way in, so anything above `0x7f` is replaced: a five-byte payload
|
|
23059
24369
|
* containing `0x89` and `0xff` arrives as nine. That silently destroys every
|
|
23060
24370
|
* upload — an image or a video reaches the server the wrong size and no
|
|
@@ -23156,7 +24466,7 @@ var Container = class _Container {
|
|
|
23156
24466
|
assertActive() {
|
|
23157
24467
|
if (this.disposed) throw new Error("container has been disposed");
|
|
23158
24468
|
}
|
|
23159
|
-
/** Tear down every process and release the
|
|
24469
|
+
/** Tear down every process and release the runtime pod. */
|
|
23160
24470
|
dispose() {
|
|
23161
24471
|
if (this.disposed) return;
|
|
23162
24472
|
this.disposed = true;
|
|
@@ -23275,7 +24585,7 @@ var Terminal = class {
|
|
|
23275
24585
|
this.currentStdin?.end();
|
|
23276
24586
|
return;
|
|
23277
24587
|
}
|
|
23278
|
-
this.write(ch === "\r" ? "\r\n" : ch);
|
|
24588
|
+
if (!this.currentStdin?.rawMode) this.write(ch === "\r" ? "\r\n" : ch);
|
|
23279
24589
|
this.currentStdin?.write(ch === "\r" ? "\n" : ch);
|
|
23280
24590
|
return;
|
|
23281
24591
|
}
|
|
@@ -23431,8 +24741,8 @@ var Terminal = class {
|
|
|
23431
24741
|
// ── completion ────────────────────────────────────────────────────────────
|
|
23432
24742
|
complete() {
|
|
23433
24743
|
const left = this.buffer.slice(0, this.cursor);
|
|
23434
|
-
const
|
|
23435
|
-
const word =
|
|
24744
|
+
const match2 = /(\S*)$/.exec(left);
|
|
24745
|
+
const word = match2?.[1] ?? "";
|
|
23436
24746
|
const isFirstWord = left.slice(0, left.length - word.length).trim() === "";
|
|
23437
24747
|
const candidates = isFirstWord && !word.includes("/") ? this.completeCommand(word) : this.completePath(word);
|
|
23438
24748
|
if (candidates.length === 0) return;
|
|
@@ -23537,13 +24847,13 @@ var Terminal = class {
|
|
|
23537
24847
|
this.writePrompt();
|
|
23538
24848
|
}
|
|
23539
24849
|
};
|
|
23540
|
-
function expandPrompt(
|
|
24850
|
+
function expandPrompt(format3, session) {
|
|
23541
24851
|
const shell = session.shell;
|
|
23542
24852
|
const home = shell.vars.get("HOME") ?? "/root";
|
|
23543
24853
|
const cwd = shell.cwd;
|
|
23544
24854
|
const user = shell.kernel.users.nameForUid(shell.cred.uid);
|
|
23545
24855
|
const now = new Date(shell.kernel.now());
|
|
23546
|
-
return
|
|
24856
|
+
return format3.replace(/\\(.)/g, (_, ch) => {
|
|
23547
24857
|
switch (ch) {
|
|
23548
24858
|
case "u":
|
|
23549
24859
|
return user;
|