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.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import { Buffer as Buffer$1 } from 'buffer';
|
|
2
|
-
import { ungzip } from 'pako';
|
|
1
|
+
import { Buffer as Buffer$1 } from 'buffer/index.js';
|
|
2
|
+
import { ungzip, gzip as gzip$1, deflate as deflate$1, inflate as inflate$1, deflateRaw, inflateRaw } from 'pako';
|
|
3
3
|
import { sha256, sha224 } from '@noble/hashes/sha256';
|
|
4
4
|
import { sha512, sha384 } from '@noble/hashes/sha512';
|
|
5
5
|
import { sha1 } from '@noble/hashes/sha1';
|
|
6
6
|
import { valid, maxSatisfying } from 'semver';
|
|
7
7
|
import { Parser as Parser$1, parse as parse$1 } from 'acorn';
|
|
8
|
-
import
|
|
8
|
+
import EventEmitter4 from 'events/events.js';
|
|
9
9
|
import jsx from 'acorn-jsx';
|
|
10
10
|
import { exports as exports$1, imports } from 'resolve.exports';
|
|
11
11
|
import pathModule from 'path-browserify';
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import assertModule from 'assert';
|
|
15
|
-
import processShim from 'process';
|
|
16
|
-
import zlibModule from 'browserify-zlib';
|
|
12
|
+
import streamModule4 from 'stream-browserify';
|
|
13
|
+
import processShim from 'process/browser.js';
|
|
17
14
|
import querystringModule from 'querystring-es3';
|
|
18
|
-
import stringDecoderModule from 'string_decoder';
|
|
15
|
+
import stringDecoderModule from 'string_decoder/lib/string_decoder.js';
|
|
19
16
|
import timersModule from 'timers-browserify';
|
|
20
|
-
import
|
|
17
|
+
import legacyUrl from 'url/url.js';
|
|
21
18
|
import { sha1 as sha1$1, md5 } from '@noble/hashes/legacy';
|
|
22
19
|
import { hmac } from '@noble/hashes/hmac';
|
|
23
20
|
|
|
@@ -229,7 +226,7 @@ function join(...parts) {
|
|
|
229
226
|
const joined = parts.filter((p) => p !== "").join("/");
|
|
230
227
|
return joined === "" ? "." : normalize(joined);
|
|
231
228
|
}
|
|
232
|
-
function resolve(
|
|
229
|
+
function resolve(base2, ...parts) {
|
|
233
230
|
let resolved = "";
|
|
234
231
|
let absolute = false;
|
|
235
232
|
for (let i = parts.length - 1; i >= 0 && !absolute; i--) {
|
|
@@ -239,7 +236,7 @@ function resolve(base, ...parts) {
|
|
|
239
236
|
absolute = isAbsolute(part);
|
|
240
237
|
}
|
|
241
238
|
if (!absolute) {
|
|
242
|
-
resolved = resolved === "" ?
|
|
239
|
+
resolved = resolved === "" ? base2 : `${base2}/${resolved}`;
|
|
243
240
|
}
|
|
244
241
|
const norm = normalize(resolved);
|
|
245
242
|
return isAbsolute(norm) ? stripTrailing(norm) : stripTrailing(normalize(`/${norm}`));
|
|
@@ -259,14 +256,14 @@ function basename(p, ext) {
|
|
|
259
256
|
const norm = stripTrailing(normalize(p));
|
|
260
257
|
if (norm === "/") return "/";
|
|
261
258
|
const idx = norm.lastIndexOf("/");
|
|
262
|
-
let
|
|
263
|
-
if (ext &&
|
|
264
|
-
return
|
|
259
|
+
let base2 = idx < 0 ? norm : norm.slice(idx + 1);
|
|
260
|
+
if (ext && base2 !== ext && base2.endsWith(ext)) base2 = base2.slice(0, -ext.length);
|
|
261
|
+
return base2;
|
|
265
262
|
}
|
|
266
263
|
function extname(p) {
|
|
267
|
-
const
|
|
268
|
-
const idx =
|
|
269
|
-
return idx <= 0 ? "" :
|
|
264
|
+
const base2 = basename(p);
|
|
265
|
+
const idx = base2.lastIndexOf(".");
|
|
266
|
+
return idx <= 0 ? "" : base2.slice(idx);
|
|
270
267
|
}
|
|
271
268
|
function relative(from, to) {
|
|
272
269
|
const a = segments(normalize(from));
|
|
@@ -1036,9 +1033,9 @@ function tokenize(src) {
|
|
|
1036
1033
|
const rest = src.slice(i);
|
|
1037
1034
|
const baseMatch = /^(\d+)#([0-9a-zA-Z@_]+)/.exec(rest);
|
|
1038
1035
|
if (baseMatch) {
|
|
1039
|
-
const
|
|
1040
|
-
if (
|
|
1041
|
-
out.push({ kind: "num", value: baseMatch[0], num: parseInBase(baseMatch[2],
|
|
1036
|
+
const base2 = Number(baseMatch[1]);
|
|
1037
|
+
if (base2 < 2 || base2 > 64) throw new ArithError(`invalid arithmetic base (error token is "${baseMatch[1]}")`);
|
|
1038
|
+
out.push({ kind: "num", value: baseMatch[0], num: parseInBase(baseMatch[2], base2) });
|
|
1042
1039
|
i += baseMatch[0].length;
|
|
1043
1040
|
continue;
|
|
1044
1041
|
}
|
|
@@ -1085,17 +1082,17 @@ function tokenize(src) {
|
|
|
1085
1082
|
out.push({ kind: "eof", value: "" });
|
|
1086
1083
|
return out;
|
|
1087
1084
|
}
|
|
1088
|
-
function parseInBase(text2,
|
|
1085
|
+
function parseInBase(text2, base2) {
|
|
1089
1086
|
let value = 0;
|
|
1090
1087
|
for (const ch of text2) {
|
|
1091
1088
|
let digit;
|
|
1092
|
-
if (
|
|
1089
|
+
if (base2 <= 36) {
|
|
1093
1090
|
digit = DIGITS.toLowerCase().indexOf(ch.toLowerCase());
|
|
1094
1091
|
} else {
|
|
1095
1092
|
digit = DIGITS.indexOf(ch);
|
|
1096
1093
|
}
|
|
1097
|
-
if (digit < 0 || digit >=
|
|
1098
|
-
value = value *
|
|
1094
|
+
if (digit < 0 || digit >= base2) throw new ArithError(`value too great for base (error token is "${text2}")`);
|
|
1095
|
+
value = value * base2 + digit;
|
|
1099
1096
|
}
|
|
1100
1097
|
return value;
|
|
1101
1098
|
}
|
|
@@ -1330,12 +1327,12 @@ var init_arith = __esm({
|
|
|
1330
1327
|
}
|
|
1331
1328
|
}
|
|
1332
1329
|
power() {
|
|
1333
|
-
const
|
|
1330
|
+
const base2 = this.unary();
|
|
1334
1331
|
if (this.eat("**")) {
|
|
1335
1332
|
const exp = this.power();
|
|
1336
|
-
return Math.trunc(Math.pow(
|
|
1333
|
+
return Math.trunc(Math.pow(base2, exp));
|
|
1337
1334
|
}
|
|
1338
|
-
return
|
|
1335
|
+
return base2;
|
|
1339
1336
|
}
|
|
1340
1337
|
unary() {
|
|
1341
1338
|
if (this.eat("+")) return this.unary();
|
|
@@ -2164,18 +2161,18 @@ async function pathnameExpand(field, ctx) {
|
|
|
2164
2161
|
if (ctx.noglob) return [literal];
|
|
2165
2162
|
const pattern = field.map((f) => f.glob ? f.text : escapeGlob(f.text)).join("");
|
|
2166
2163
|
if (!hasMagic(pattern, ctx.extglob !== false)) return [literal];
|
|
2167
|
-
const
|
|
2164
|
+
const matches3 = glob(ctx.vfs, pattern, {
|
|
2168
2165
|
cwd: ctx.cwd,
|
|
2169
2166
|
cred: ctx.cred,
|
|
2170
2167
|
dot: ctx.dotglob ?? false,
|
|
2171
2168
|
extglob: ctx.extglob !== false
|
|
2172
2169
|
});
|
|
2173
|
-
if (
|
|
2170
|
+
if (matches3.length === 0) {
|
|
2174
2171
|
if (ctx.failglob) throw new ExpansionError(`no match: ${literal}`);
|
|
2175
2172
|
if (ctx.nullglob) return [];
|
|
2176
2173
|
return [literal];
|
|
2177
2174
|
}
|
|
2178
|
-
return
|
|
2175
|
+
return matches3;
|
|
2179
2176
|
}
|
|
2180
2177
|
function matchesPattern(value, pattern, extglob = true) {
|
|
2181
2178
|
return fnmatch(pattern, value, { pathname: false, dot: true, extglob });
|
|
@@ -2589,12 +2586,12 @@ function decodeEscapes(input, opts = {}) {
|
|
|
2589
2586
|
}
|
|
2590
2587
|
return { text: out, stopped: false };
|
|
2591
2588
|
}
|
|
2592
|
-
function formatPrintf(
|
|
2589
|
+
function formatPrintf(format3, args) {
|
|
2593
2590
|
let out = "";
|
|
2594
2591
|
let argIndex = 0;
|
|
2595
2592
|
let consumedAny = false;
|
|
2596
2593
|
do {
|
|
2597
|
-
const pass = formatOnce(
|
|
2594
|
+
const pass = formatOnce(format3, args, argIndex);
|
|
2598
2595
|
out += pass.text;
|
|
2599
2596
|
if (pass.stopped) return out;
|
|
2600
2597
|
consumedAny = pass.nextIndex > argIndex;
|
|
@@ -2603,17 +2600,17 @@ function formatPrintf(format, args) {
|
|
|
2603
2600
|
} while (argIndex < args.length && consumedAny);
|
|
2604
2601
|
return out;
|
|
2605
2602
|
}
|
|
2606
|
-
function formatOnce(
|
|
2603
|
+
function formatOnce(format3, args, startIndex) {
|
|
2607
2604
|
let out = "";
|
|
2608
2605
|
let i = 0;
|
|
2609
2606
|
let argIndex = startIndex;
|
|
2610
2607
|
let hasConversions = false;
|
|
2611
2608
|
const nextArg = () => args[argIndex++] ?? "";
|
|
2612
|
-
while (i <
|
|
2613
|
-
const c =
|
|
2609
|
+
while (i < format3.length) {
|
|
2610
|
+
const c = format3[i];
|
|
2614
2611
|
if (c === "\\") {
|
|
2615
|
-
decodeEscapes(
|
|
2616
|
-
const single = decodeSingleEscape(
|
|
2612
|
+
decodeEscapes(format3.slice(i, i + 12), { stopAtC: true });
|
|
2613
|
+
const single = decodeSingleEscape(format3, i);
|
|
2617
2614
|
if (single.stopped) return { text: out, nextIndex: argIndex, hasConversions, stopped: true };
|
|
2618
2615
|
out += single.text;
|
|
2619
2616
|
i = single.next;
|
|
@@ -2624,12 +2621,12 @@ function formatOnce(format, args, startIndex) {
|
|
|
2624
2621
|
i++;
|
|
2625
2622
|
continue;
|
|
2626
2623
|
}
|
|
2627
|
-
if (
|
|
2624
|
+
if (format3[i + 1] === "%") {
|
|
2628
2625
|
out += "%";
|
|
2629
2626
|
i += 2;
|
|
2630
2627
|
continue;
|
|
2631
2628
|
}
|
|
2632
|
-
const spec = /^%([-+ #0']*)(\*|\d+)?(?:\.(\*|\d+))?([diouxXeEfgGaAcsbq])/.exec(
|
|
2629
|
+
const spec = /^%([-+ #0']*)(\*|\d+)?(?:\.(\*|\d+))?([diouxXeEfgGaAcsbq])/.exec(format3.slice(i));
|
|
2633
2630
|
if (!spec) {
|
|
2634
2631
|
out += c;
|
|
2635
2632
|
i++;
|
|
@@ -2839,13 +2836,13 @@ function builtinPrintf({ argv, io }) {
|
|
|
2839
2836
|
varName = args[1];
|
|
2840
2837
|
start2 = 2;
|
|
2841
2838
|
}
|
|
2842
|
-
const
|
|
2843
|
-
if (
|
|
2839
|
+
const format3 = args[start2];
|
|
2840
|
+
if (format3 === void 0) {
|
|
2844
2841
|
io.stderr.write("printf: usage: printf [-v var] format [arguments]\n");
|
|
2845
2842
|
return 2;
|
|
2846
2843
|
}
|
|
2847
2844
|
try {
|
|
2848
|
-
const text2 = formatPrintf(
|
|
2845
|
+
const text2 = formatPrintf(format3, args.slice(start2 + 1));
|
|
2849
2846
|
if (varName) return 0;
|
|
2850
2847
|
io.stdout.write(text2);
|
|
2851
2848
|
return 0;
|
|
@@ -3593,10 +3590,10 @@ function builtinType({ shell, argv, io }) {
|
|
|
3593
3590
|
}
|
|
3594
3591
|
async function builtinCommand({ shell, argv, io }) {
|
|
3595
3592
|
const args = argv.slice(1);
|
|
3596
|
-
const
|
|
3593
|
+
const describe2 = args.includes("-v") || args.includes("-V");
|
|
3597
3594
|
const verbose = args.includes("-V");
|
|
3598
3595
|
const rest = args.filter((a) => a !== "-v" && a !== "-V" && a !== "-p");
|
|
3599
|
-
if (
|
|
3596
|
+
if (describe2) {
|
|
3600
3597
|
let status = 0;
|
|
3601
3598
|
for (const name of rest) {
|
|
3602
3599
|
if (isBuiltinName(name)) {
|
|
@@ -3835,13 +3832,13 @@ function builtinDirs({ shell, argv, io }) {
|
|
|
3835
3832
|
}
|
|
3836
3833
|
const entries = [shell.cwd, ...shell.dirStack];
|
|
3837
3834
|
const home = shell.vars.get("HOME");
|
|
3838
|
-
const
|
|
3835
|
+
const render2 = (p) => home && p.startsWith(home) ? "~" + p.slice(home.length) : p;
|
|
3839
3836
|
if (argv.includes("-v")) {
|
|
3840
|
-
entries.forEach((entry, idx) => io.stdout.write(`${String(idx).padStart(2)} ${
|
|
3837
|
+
entries.forEach((entry, idx) => io.stdout.write(`${String(idx).padStart(2)} ${render2(entry)}
|
|
3841
3838
|
`));
|
|
3842
3839
|
return 0;
|
|
3843
3840
|
}
|
|
3844
|
-
io.stdout.write(entries.map(
|
|
3841
|
+
io.stdout.write(entries.map(render2).join(" ") + "\n");
|
|
3845
3842
|
return 0;
|
|
3846
3843
|
}
|
|
3847
3844
|
function builtinPushd({ shell, argv, io }) {
|
|
@@ -4450,12 +4447,12 @@ var Vfs = class {
|
|
|
4450
4447
|
writeFile(abs, data, opts = {}) {
|
|
4451
4448
|
const cred = opts.privileged ? void 0 : opts.cred;
|
|
4452
4449
|
const real = this.resolvePath(abs, { cred });
|
|
4453
|
-
const
|
|
4450
|
+
const bytes2 = typeof data === "string" ? encoder.encode(data) : data;
|
|
4454
4451
|
const virt = this.lookupVirtual(real);
|
|
4455
4452
|
if (virt) {
|
|
4456
4453
|
if (!virt.write) throw new SysError("EACCES", "write", real);
|
|
4457
4454
|
this.require(this.statFromVirtual(real, virt), W_OK, cred, "open", real);
|
|
4458
|
-
virt.write(
|
|
4455
|
+
virt.write(bytes2, opts.append ?? false);
|
|
4459
4456
|
return;
|
|
4460
4457
|
}
|
|
4461
4458
|
if (this.isUnderProvider(real)) throw new SysError("ENOENT", "open", real);
|
|
@@ -4470,8 +4467,8 @@ var Vfs = class {
|
|
|
4470
4467
|
this.require(pst, W_OK | X_OK, cred, "open", real);
|
|
4471
4468
|
}
|
|
4472
4469
|
try {
|
|
4473
|
-
if (opts.append && existing) this.volume.appendFileSync(real,
|
|
4474
|
-
else this.volume.writeFileSync(real,
|
|
4470
|
+
if (opts.append && existing) this.volume.appendFileSync(real, bytes2);
|
|
4471
|
+
else this.volume.writeFileSync(real, bytes2);
|
|
4475
4472
|
} catch (e) {
|
|
4476
4473
|
throw toSysError(e, "open", real);
|
|
4477
4474
|
}
|
|
@@ -4723,7 +4720,7 @@ var Vfs = class {
|
|
|
4723
4720
|
usage(abs = "/") {
|
|
4724
4721
|
let files = 0;
|
|
4725
4722
|
let dirs = 0;
|
|
4726
|
-
let
|
|
4723
|
+
let bytes2 = 0;
|
|
4727
4724
|
for (const p of this.walk(abs)) {
|
|
4728
4725
|
let st = null;
|
|
4729
4726
|
try {
|
|
@@ -4734,10 +4731,10 @@ var Vfs = class {
|
|
|
4734
4731
|
if (st.isDirectory()) dirs++;
|
|
4735
4732
|
else {
|
|
4736
4733
|
files++;
|
|
4737
|
-
|
|
4734
|
+
bytes2 += st.size;
|
|
4738
4735
|
}
|
|
4739
4736
|
}
|
|
4740
|
-
return { files, dirs, bytes };
|
|
4737
|
+
return { files, dirs, bytes: bytes2 };
|
|
4741
4738
|
}
|
|
4742
4739
|
};
|
|
4743
4740
|
|
|
@@ -4774,6 +4771,14 @@ var Pipe = class _Pipe {
|
|
|
4774
4771
|
isTTY = false;
|
|
4775
4772
|
/** Set on pipes owned by an outside caller, who may never call `end()`. */
|
|
4776
4773
|
interactive = false;
|
|
4774
|
+
/**
|
|
4775
|
+
* Set while the running program has put the terminal in raw mode.
|
|
4776
|
+
*
|
|
4777
|
+
* A program in raw mode draws its own input — a prompt library redraws the
|
|
4778
|
+
* whole line on every keystroke — so the terminal must stop echoing, or
|
|
4779
|
+
* every character appears twice.
|
|
4780
|
+
*/
|
|
4781
|
+
rawMode = false;
|
|
4777
4782
|
columns;
|
|
4778
4783
|
rows;
|
|
4779
4784
|
get closed() {
|
|
@@ -4788,10 +4793,10 @@ var Pipe = class _Pipe {
|
|
|
4788
4793
|
write(data) {
|
|
4789
4794
|
if (this.readerClosed) throw new SysError("EPIPE", "write");
|
|
4790
4795
|
if (this.writerClosed) return;
|
|
4791
|
-
const
|
|
4792
|
-
if (
|
|
4793
|
-
this.chunks.push(
|
|
4794
|
-
this.buffered +=
|
|
4796
|
+
const bytes2 = toBytes(data);
|
|
4797
|
+
if (bytes2.length === 0) return;
|
|
4798
|
+
this.chunks.push(bytes2);
|
|
4799
|
+
this.buffered += bytes2.length;
|
|
4795
4800
|
this.wake();
|
|
4796
4801
|
}
|
|
4797
4802
|
end() {
|
|
@@ -4920,11 +4925,11 @@ var BufferSink = class {
|
|
|
4920
4925
|
}
|
|
4921
4926
|
write(data) {
|
|
4922
4927
|
if (this._closed) return;
|
|
4923
|
-
const
|
|
4924
|
-
if (
|
|
4925
|
-
this.chunks.push(
|
|
4926
|
-
this.total +=
|
|
4927
|
-
this.onWrite?.(
|
|
4928
|
+
const bytes2 = toBytes(data);
|
|
4929
|
+
if (bytes2.length === 0) return;
|
|
4930
|
+
this.chunks.push(bytes2);
|
|
4931
|
+
this.total += bytes2.length;
|
|
4932
|
+
this.onWrite?.(bytes2);
|
|
4928
4933
|
}
|
|
4929
4934
|
end() {
|
|
4930
4935
|
this._closed = true;
|
|
@@ -5553,9 +5558,9 @@ function parseSize(spec) {
|
|
|
5553
5558
|
const value = Number(m[1]);
|
|
5554
5559
|
const unit = (m[2] ?? "").toLowerCase();
|
|
5555
5560
|
const binary = m[3] !== "" || unit === "";
|
|
5556
|
-
const
|
|
5561
|
+
const base2 = binary ? 1024 : 1e3;
|
|
5557
5562
|
const exp = { "": 0, k: 1, m: 2, g: 3, t: 4, p: 5 }[unit] ?? 0;
|
|
5558
|
-
return Math.round(value * Math.pow(
|
|
5563
|
+
return Math.round(value * Math.pow(base2, exp));
|
|
5559
5564
|
}
|
|
5560
5565
|
|
|
5561
5566
|
// src/kernel/command.ts
|
|
@@ -6801,7 +6806,7 @@ var NetworkStack = class {
|
|
|
6801
6806
|
}
|
|
6802
6807
|
return [...out.values()].sort((a, b) => a.port - b.port);
|
|
6803
6808
|
}
|
|
6804
|
-
/** Ports
|
|
6809
|
+
/** Ports the pod's proxy has registered for this instance. */
|
|
6805
6810
|
knownPodPorts() {
|
|
6806
6811
|
try {
|
|
6807
6812
|
return this.pod.proxy.activePorts(this.pod.instanceId) ?? [];
|
|
@@ -6867,22 +6872,22 @@ var NetworkStack = class {
|
|
|
6867
6872
|
`;
|
|
6868
6873
|
return out;
|
|
6869
6874
|
}
|
|
6870
|
-
countTx(
|
|
6875
|
+
countTx(bytes2, iface = "eth0") {
|
|
6871
6876
|
const i = this.interface(iface);
|
|
6872
6877
|
if (!i) return;
|
|
6873
|
-
i.txBytes +=
|
|
6874
|
-
i.txPackets += Math.max(1, Math.ceil(
|
|
6878
|
+
i.txBytes += bytes2;
|
|
6879
|
+
i.txPackets += Math.max(1, Math.ceil(bytes2 / 1400));
|
|
6875
6880
|
}
|
|
6876
|
-
countRx(
|
|
6881
|
+
countRx(bytes2, iface = "eth0") {
|
|
6877
6882
|
const i = this.interface(iface);
|
|
6878
6883
|
if (!i) return;
|
|
6879
|
-
i.rxBytes +=
|
|
6880
|
-
i.rxPackets += Math.max(1, Math.ceil(
|
|
6884
|
+
i.rxBytes += bytes2;
|
|
6885
|
+
i.rxPackets += Math.max(1, Math.ceil(bytes2 / 1400));
|
|
6881
6886
|
}
|
|
6882
6887
|
};
|
|
6883
6888
|
function randomMac() {
|
|
6884
|
-
const
|
|
6885
|
-
return
|
|
6889
|
+
const bytes2 = [2, 66, 172, 17, 0, 2];
|
|
6890
|
+
return bytes2.map((b) => b.toString(16).padStart(2, "0")).join(":");
|
|
6886
6891
|
}
|
|
6887
6892
|
function hexIp(ip2) {
|
|
6888
6893
|
return ip2.split(".").reverse().map((o) => Number(o).toString(16).padStart(2, "0").toUpperCase()).join("");
|
|
@@ -7171,7 +7176,7 @@ var Lexer = class _Lexer {
|
|
|
7171
7176
|
const stripTabs = opToken.value === "<<-";
|
|
7172
7177
|
const rawTag = tagToken.value;
|
|
7173
7178
|
const quoted = /['"\\]/.test(rawTag);
|
|
7174
|
-
const
|
|
7179
|
+
const tag2 = rawTag.replace(/['"\\]/g, "");
|
|
7175
7180
|
const lines = [];
|
|
7176
7181
|
let found = false;
|
|
7177
7182
|
while (this.pos < this.src.length) {
|
|
@@ -7180,7 +7185,7 @@ var Lexer = class _Lexer {
|
|
|
7180
7185
|
const rawLine = this.src.slice(this.pos, eol);
|
|
7181
7186
|
this.pos = eol + 1;
|
|
7182
7187
|
const compare = stripTabs ? rawLine.replace(/^\t+/, "") : rawLine;
|
|
7183
|
-
if (compare ===
|
|
7188
|
+
if (compare === tag2) {
|
|
7184
7189
|
found = true;
|
|
7185
7190
|
break;
|
|
7186
7191
|
}
|
|
@@ -7188,9 +7193,9 @@ var Lexer = class _Lexer {
|
|
|
7188
7193
|
if (eol >= this.src.length) break;
|
|
7189
7194
|
}
|
|
7190
7195
|
if (!found) {
|
|
7191
|
-
throw new IncompleteInputError(`here-document delimited by end-of-file (wanted \`${
|
|
7196
|
+
throw new IncompleteInputError(`here-document delimited by end-of-file (wanted \`${tag2}')`, opToken.pos);
|
|
7192
7197
|
}
|
|
7193
|
-
opToken.heredoc = { tag, stripTabs, quoted, body: lines.length ? lines.join("\n") + "\n" : "" };
|
|
7198
|
+
opToken.heredoc = { tag: tag2, stripTabs, quoted, body: lines.length ? lines.join("\n") + "\n" : "" };
|
|
7194
7199
|
}
|
|
7195
7200
|
}
|
|
7196
7201
|
};
|
|
@@ -8757,16 +8762,16 @@ sys ${fmt2(Math.floor(ms * 0.2))}
|
|
|
8757
8762
|
function splitAliasWords(text2) {
|
|
8758
8763
|
const out = [];
|
|
8759
8764
|
let current = "";
|
|
8760
|
-
let
|
|
8765
|
+
let quote3 = null;
|
|
8761
8766
|
for (let i = 0; i < text2.length; i++) {
|
|
8762
8767
|
const c = text2[i];
|
|
8763
|
-
if (
|
|
8764
|
-
if (c ===
|
|
8768
|
+
if (quote3) {
|
|
8769
|
+
if (c === quote3) quote3 = null;
|
|
8765
8770
|
else current += c;
|
|
8766
8771
|
continue;
|
|
8767
8772
|
}
|
|
8768
8773
|
if (c === "'" || c === '"') {
|
|
8769
|
-
|
|
8774
|
+
quote3 = c;
|
|
8770
8775
|
continue;
|
|
8771
8776
|
}
|
|
8772
8777
|
if (c === " " || c === " ") {
|
|
@@ -8920,11 +8925,11 @@ var decoder3 = new TextDecoder();
|
|
|
8920
8925
|
async function readInputs(ctx, operands, opts = {}) {
|
|
8921
8926
|
const stdinName = opts.stdinName ?? "-";
|
|
8922
8927
|
if (operands.length === 0) {
|
|
8923
|
-
const
|
|
8924
|
-
return { sources: [{ name: stdinName, bytes }], ok: true };
|
|
8928
|
+
const bytes2 = await ctx.stdin.readAll();
|
|
8929
|
+
return { sources: [{ name: stdinName, bytes: bytes2 }], ok: true };
|
|
8925
8930
|
}
|
|
8926
8931
|
const sources = [];
|
|
8927
|
-
let
|
|
8932
|
+
let ok2 = true;
|
|
8928
8933
|
for (const operand of operands) {
|
|
8929
8934
|
if (operand === "-") {
|
|
8930
8935
|
sources.push({ name: stdinName, bytes: await ctx.stdin.readAll() });
|
|
@@ -8935,19 +8940,19 @@ async function readInputs(ctx, operands, opts = {}) {
|
|
|
8935
8940
|
const st = ctx.vfs.stat(abs, { cred: ctx.cred });
|
|
8936
8941
|
if (st.isDirectory()) {
|
|
8937
8942
|
ctx.warn(`${operand}: Is a directory`);
|
|
8938
|
-
|
|
8943
|
+
ok2 = false;
|
|
8939
8944
|
continue;
|
|
8940
8945
|
}
|
|
8941
8946
|
sources.push({ name: operand, bytes: ctx.vfs.readFile(abs, ctx.cred) });
|
|
8942
8947
|
} catch (e) {
|
|
8943
8948
|
ctx.reportError(e, operand);
|
|
8944
|
-
|
|
8949
|
+
ok2 = false;
|
|
8945
8950
|
}
|
|
8946
8951
|
}
|
|
8947
|
-
return { sources, ok };
|
|
8952
|
+
return { sources, ok: ok2 };
|
|
8948
8953
|
}
|
|
8949
|
-
function splitLines(
|
|
8950
|
-
const text2 = decoder3.decode(
|
|
8954
|
+
function splitLines(bytes2) {
|
|
8955
|
+
const text2 = decoder3.decode(bytes2);
|
|
8951
8956
|
if (text2 === "") return { lines: [], trailingNewline: true };
|
|
8952
8957
|
const trailingNewline = text2.endsWith("\n");
|
|
8953
8958
|
const body = trailingNewline ? text2.slice(0, -1) : text2;
|
|
@@ -8959,14 +8964,14 @@ function joinLines(lines, trailingNewline = true) {
|
|
|
8959
8964
|
}
|
|
8960
8965
|
var SI_UNITS = ["", "k", "M", "G", "T", "P", "E"];
|
|
8961
8966
|
var IEC_UNITS = ["", "K", "M", "G", "T", "P", "E"];
|
|
8962
|
-
function humanSize(
|
|
8963
|
-
const
|
|
8967
|
+
function humanSize(bytes2, opts = {}) {
|
|
8968
|
+
const base2 = opts.si ? 1e3 : 1024;
|
|
8964
8969
|
const units = opts.si ? SI_UNITS : IEC_UNITS;
|
|
8965
|
-
if (
|
|
8966
|
-
let value =
|
|
8970
|
+
if (bytes2 < base2) return String(bytes2);
|
|
8971
|
+
let value = bytes2;
|
|
8967
8972
|
let unit = 0;
|
|
8968
|
-
while (value >=
|
|
8969
|
-
value /=
|
|
8973
|
+
while (value >= base2 && unit < units.length - 1) {
|
|
8974
|
+
value /= base2;
|
|
8970
8975
|
unit++;
|
|
8971
8976
|
}
|
|
8972
8977
|
const rounded = value < 10 ? Math.ceil(value * 10) / 10 : Math.ceil(value);
|
|
@@ -9253,7 +9258,7 @@ var cat = defineCommand({
|
|
|
9253
9258
|
let lineNumber = 1;
|
|
9254
9259
|
let lastWasBlank = false;
|
|
9255
9260
|
for (const operand of operands) {
|
|
9256
|
-
let
|
|
9261
|
+
let bytes2;
|
|
9257
9262
|
if (operand === "-") {
|
|
9258
9263
|
if (plain) {
|
|
9259
9264
|
for (; ; ) {
|
|
@@ -9264,7 +9269,7 @@ var cat = defineCommand({
|
|
|
9264
9269
|
}
|
|
9265
9270
|
continue;
|
|
9266
9271
|
}
|
|
9267
|
-
|
|
9272
|
+
bytes2 = await ctx.stdin.readAll();
|
|
9268
9273
|
} else {
|
|
9269
9274
|
try {
|
|
9270
9275
|
const abs = ctx.path(operand);
|
|
@@ -9274,17 +9279,17 @@ var cat = defineCommand({
|
|
|
9274
9279
|
status = 1;
|
|
9275
9280
|
continue;
|
|
9276
9281
|
}
|
|
9277
|
-
|
|
9282
|
+
bytes2 = ctx.vfs.readFile(abs, ctx.cred);
|
|
9278
9283
|
} catch (e) {
|
|
9279
9284
|
status = ctx.reportError(e, operand);
|
|
9280
9285
|
continue;
|
|
9281
9286
|
}
|
|
9282
9287
|
}
|
|
9283
9288
|
if (plain) {
|
|
9284
|
-
ctx.write(
|
|
9289
|
+
ctx.write(bytes2);
|
|
9285
9290
|
continue;
|
|
9286
9291
|
}
|
|
9287
|
-
const text2 = new TextDecoder().decode(
|
|
9292
|
+
const text2 = new TextDecoder().decode(bytes2);
|
|
9288
9293
|
const hadTrailing = text2.endsWith("\n");
|
|
9289
9294
|
const parts = (hadTrailing ? text2.slice(0, -1) : text2).split("\n");
|
|
9290
9295
|
for (const raw of parts) {
|
|
@@ -9874,9 +9879,9 @@ var stat = defineCommand({
|
|
|
9874
9879
|
try {
|
|
9875
9880
|
const abs = ctx.path(operand);
|
|
9876
9881
|
const st = args.has("dereference") ? ctx.vfs.stat(abs, { cred: ctx.cred }) : ctx.vfs.lstat(abs);
|
|
9877
|
-
const
|
|
9878
|
-
if (
|
|
9879
|
-
ctx.write(expandStatFormat(
|
|
9882
|
+
const format3 = args.str("format") ?? args.str("printf");
|
|
9883
|
+
if (format3) {
|
|
9884
|
+
ctx.write(expandStatFormat(format3, abs, st, ctx) + (args.str("printf") ? "" : "\n"));
|
|
9880
9885
|
continue;
|
|
9881
9886
|
}
|
|
9882
9887
|
if (args.has("terse")) {
|
|
@@ -9908,8 +9913,8 @@ var stat = defineCommand({
|
|
|
9908
9913
|
function isoTime(ms) {
|
|
9909
9914
|
return new Date(ms).toISOString().replace("T", " ").replace("Z", " +0000");
|
|
9910
9915
|
}
|
|
9911
|
-
function expandStatFormat(
|
|
9912
|
-
return
|
|
9916
|
+
function expandStatFormat(format3, path, st, ctx) {
|
|
9917
|
+
return format3.replace(/%(.)/g, (_, ch) => {
|
|
9913
9918
|
switch (ch) {
|
|
9914
9919
|
case "n":
|
|
9915
9920
|
return path;
|
|
@@ -9968,7 +9973,7 @@ var du = defineCommand({
|
|
|
9968
9973
|
const operands = args.positional.length ? args.positional : ["."];
|
|
9969
9974
|
const maxDepth = args.num("max-depth", args.has("summarize") ? 0 : Infinity);
|
|
9970
9975
|
const asBytes = args.has("bytes");
|
|
9971
|
-
const
|
|
9976
|
+
const render2 = (value) => args.has("human-readable") ? humanSize(value) : String(asBytes ? value : Math.max(1, Math.ceil(value / 1024)));
|
|
9972
9977
|
let total = 0;
|
|
9973
9978
|
let status = 0;
|
|
9974
9979
|
const walk = (abs, depth) => {
|
|
@@ -9980,20 +9985,20 @@ var du = defineCommand({
|
|
|
9980
9985
|
return 0;
|
|
9981
9986
|
}
|
|
9982
9987
|
if (!st.isDirectory()) {
|
|
9983
|
-
if (args.has("all") && depth <= maxDepth) ctx.line(`${
|
|
9988
|
+
if (args.has("all") && depth <= maxDepth) ctx.line(`${render2(st.size)} ${abs}`);
|
|
9984
9989
|
return st.size;
|
|
9985
9990
|
}
|
|
9986
9991
|
let sum = 4096;
|
|
9987
9992
|
for (const name of safeReaddir(ctx, abs)) {
|
|
9988
9993
|
sum += walk(join(abs, name), depth + 1);
|
|
9989
9994
|
}
|
|
9990
|
-
if (depth <= maxDepth) ctx.line(`${
|
|
9995
|
+
if (depth <= maxDepth) ctx.line(`${render2(sum)} ${abs}`);
|
|
9991
9996
|
return sum;
|
|
9992
9997
|
};
|
|
9993
9998
|
for (const operand of operands) {
|
|
9994
9999
|
total += walk(ctx.path(operand), 0);
|
|
9995
10000
|
}
|
|
9996
|
-
if (args.has("total")) ctx.line(`${
|
|
10001
|
+
if (args.has("total")) ctx.line(`${render2(total)} total`);
|
|
9997
10002
|
return status;
|
|
9998
10003
|
}
|
|
9999
10004
|
});
|
|
@@ -10028,8 +10033,8 @@ var df = defineCommand({
|
|
|
10028
10033
|
ctx.warn(`${operand}: No such file or directory`);
|
|
10029
10034
|
continue;
|
|
10030
10035
|
}
|
|
10031
|
-
const
|
|
10032
|
-
if (
|
|
10036
|
+
const match2 = mounts.filter((m) => contains(m.mountpoint, abs)).sort((a, b) => b.mountpoint.length - a.mountpoint.length)[0];
|
|
10037
|
+
if (match2) selected.set(match2.mountpoint, match2);
|
|
10033
10038
|
}
|
|
10034
10039
|
mounts = [...selected.values()];
|
|
10035
10040
|
}
|
|
@@ -10138,15 +10143,15 @@ function describeFile(ctx, abs, st, mime) {
|
|
|
10138
10143
|
}
|
|
10139
10144
|
if (st.isCharacterDevice()) return mime ? "inode/chardevice" : "character special";
|
|
10140
10145
|
if (st.size === 0) return mime ? "inode/x-empty" : "empty";
|
|
10141
|
-
const
|
|
10142
|
-
const magic = [...
|
|
10146
|
+
const bytes2 = ctx.vfs.readFile(abs, ctx.cred).subarray(0, 512);
|
|
10147
|
+
const magic = [...bytes2.subarray(0, 4)];
|
|
10143
10148
|
if (magic[0] === 127 && magic[1] === 69 && magic[2] === 76 && magic[3] === 70) {
|
|
10144
10149
|
return mime ? "application/x-executable" : "ELF 64-bit LSB executable, x86-64";
|
|
10145
10150
|
}
|
|
10146
10151
|
if (magic[0] === 31 && magic[1] === 139) return mime ? "application/gzip" : "gzip compressed data";
|
|
10147
10152
|
if (magic[0] === 80 && magic[1] === 75) return mime ? "application/zip" : "Zip archive data";
|
|
10148
10153
|
if (magic[0] === 137 && magic[1] === 80) return mime ? "image/png" : "PNG image data";
|
|
10149
|
-
const text2 = new TextDecoder().decode(
|
|
10154
|
+
const text2 = new TextDecoder().decode(bytes2);
|
|
10150
10155
|
const printable = [...text2].every((c) => c === "\n" || c === " " || c === "\r" || c >= " " && c <= "~" || c.charCodeAt(0) > 127);
|
|
10151
10156
|
if (!printable) return mime ? "application/octet-stream" : "data";
|
|
10152
10157
|
if (text2.startsWith("#!")) {
|
|
@@ -10219,10 +10224,10 @@ var printfCmd = defineCommand({
|
|
|
10219
10224
|
summary: "format and print data",
|
|
10220
10225
|
usage: "printf FORMAT [ARGUMENT]...",
|
|
10221
10226
|
run(ctx) {
|
|
10222
|
-
const
|
|
10223
|
-
if (
|
|
10227
|
+
const format3 = ctx.args[0];
|
|
10228
|
+
if (format3 === void 0) return ctx.fail("usage: printf FORMAT [ARGUMENT]...", 2);
|
|
10224
10229
|
try {
|
|
10225
|
-
ctx.write(formatPrintf(
|
|
10230
|
+
ctx.write(formatPrintf(format3, ctx.args.slice(1)));
|
|
10226
10231
|
return 0;
|
|
10227
10232
|
} catch (e) {
|
|
10228
10233
|
return ctx.fail(e instanceof Error ? e.message : String(e));
|
|
@@ -10318,13 +10323,13 @@ var seq = defineCommand({
|
|
|
10318
10323
|
}
|
|
10319
10324
|
if (increment === 0) return ctx.fail("zero increment", 1);
|
|
10320
10325
|
const separator = args.str("separator", "\n");
|
|
10321
|
-
const
|
|
10326
|
+
const format3 = args.str("format");
|
|
10322
10327
|
const values = [];
|
|
10323
10328
|
if (increment > 0) for (let v = first; v <= last + 1e-9; v += increment) values.push(v);
|
|
10324
10329
|
else for (let v = first; v >= last - 1e-9; v += increment) values.push(v);
|
|
10325
10330
|
const rendered = values.map((v) => {
|
|
10326
10331
|
const text2 = Number.isInteger(v) ? String(v) : String(Number(v.toFixed(10)));
|
|
10327
|
-
return
|
|
10332
|
+
return format3 ? formatPrintf(format3, [String(v)]) : text2;
|
|
10328
10333
|
});
|
|
10329
10334
|
const width = args.has("equal-width") ? Math.max(0, ...rendered.map((r) => r.length)) : 0;
|
|
10330
10335
|
const out = rendered.map((r) => width ? r.padStart(width, "0") : r);
|
|
@@ -10642,9 +10647,9 @@ var date = defineCommand({
|
|
|
10642
10647
|
return 0;
|
|
10643
10648
|
}
|
|
10644
10649
|
});
|
|
10645
|
-
function strftime(
|
|
10650
|
+
function strftime(format3, d) {
|
|
10646
10651
|
const pad2 = (n, w = 2, c = "0") => String(n).padStart(w, c);
|
|
10647
|
-
return
|
|
10652
|
+
return format3.replace(/%([-_0^#]?)(\d*)([a-zA-Z%])/g, (_, flag, width, ch) => {
|
|
10648
10653
|
const value = (() => {
|
|
10649
10654
|
switch (ch) {
|
|
10650
10655
|
case "Y":
|
|
@@ -10862,13 +10867,13 @@ var killall = defineCommand({
|
|
|
10862
10867
|
const signal = signalArg ? normalizeSignal(signalArg.slice(1)) ?? "SIGTERM" : "SIGTERM";
|
|
10863
10868
|
let status = 0;
|
|
10864
10869
|
for (const name of args) {
|
|
10865
|
-
const
|
|
10866
|
-
if (
|
|
10870
|
+
const matches3 = ctx.kernel.procs.list({ comm: name });
|
|
10871
|
+
if (matches3.length === 0) {
|
|
10867
10872
|
ctx.warn(`${name}: no process found`);
|
|
10868
10873
|
status = 1;
|
|
10869
10874
|
continue;
|
|
10870
10875
|
}
|
|
10871
|
-
for (const proc of
|
|
10876
|
+
for (const proc of matches3) proc.deliver(signal);
|
|
10872
10877
|
}
|
|
10873
10878
|
return status;
|
|
10874
10879
|
}
|
|
@@ -10882,13 +10887,13 @@ var pgrep = defineCommand({
|
|
|
10882
10887
|
const pattern = args.positional[0];
|
|
10883
10888
|
if (pattern === void 0) return ctx.fail("no matching criteria specified", 2);
|
|
10884
10889
|
const re = new RegExp(pattern);
|
|
10885
|
-
const
|
|
10886
|
-
for (const proc of
|
|
10890
|
+
const matches3 = ctx.kernel.procs.list().filter((p) => re.test(args.has("f") ? p.cmdline : p.comm));
|
|
10891
|
+
for (const proc of matches3) {
|
|
10887
10892
|
if (args.has("a")) ctx.line(`${proc.pid} ${proc.cmdline}`);
|
|
10888
10893
|
else if (args.has("l")) ctx.line(`${proc.pid} ${proc.comm}`);
|
|
10889
10894
|
else ctx.line(String(proc.pid));
|
|
10890
10895
|
}
|
|
10891
|
-
return
|
|
10896
|
+
return matches3.length ? 0 : 1;
|
|
10892
10897
|
}
|
|
10893
10898
|
});
|
|
10894
10899
|
var top = defineCommand({
|
|
@@ -11420,7 +11425,7 @@ var BRACKET_CLASSES = {
|
|
|
11420
11425
|
function translateBracket(text2) {
|
|
11421
11426
|
return text2.replace(/\[:([a-z]+):\]/g, (_, name) => BRACKET_CLASSES[name] ?? "");
|
|
11422
11427
|
}
|
|
11423
|
-
function applyReplacement(replacement,
|
|
11428
|
+
function applyReplacement(replacement, match2) {
|
|
11424
11429
|
let out = "";
|
|
11425
11430
|
let caseMode = null;
|
|
11426
11431
|
let oneShot = null;
|
|
@@ -11437,7 +11442,7 @@ function applyReplacement(replacement, match) {
|
|
|
11437
11442
|
for (let i = 0; i < replacement.length; i++) {
|
|
11438
11443
|
const c = replacement[i];
|
|
11439
11444
|
if (c === "&") {
|
|
11440
|
-
emit(
|
|
11445
|
+
emit(match2[0]);
|
|
11441
11446
|
continue;
|
|
11442
11447
|
}
|
|
11443
11448
|
if (c !== "\\") {
|
|
@@ -11447,7 +11452,7 @@ function applyReplacement(replacement, match) {
|
|
|
11447
11452
|
const next = replacement[++i];
|
|
11448
11453
|
if (next === void 0) break;
|
|
11449
11454
|
if (/\d/.test(next)) {
|
|
11450
|
-
emit(
|
|
11455
|
+
emit(match2[Number(next)] ?? "");
|
|
11451
11456
|
continue;
|
|
11452
11457
|
}
|
|
11453
11458
|
switch (next) {
|
|
@@ -11525,8 +11530,8 @@ async function runSed(ctx) {
|
|
|
11525
11530
|
const inPlace = args.present("in-place");
|
|
11526
11531
|
const suffix = args.str("in-place") ?? "";
|
|
11527
11532
|
const suppress = args.has("quiet") || args.has("silent");
|
|
11528
|
-
const { sources, ok } = await readInputs(ctx, operands);
|
|
11529
|
-
let status =
|
|
11533
|
+
const { sources, ok: ok2 } = await readInputs(ctx, operands);
|
|
11534
|
+
let status = ok2 ? 0 : 1;
|
|
11530
11535
|
for (const source of sources) {
|
|
11531
11536
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
11532
11537
|
const state = {
|
|
@@ -11739,17 +11744,17 @@ function substitute2(input, regex, replacement, global, occurrence) {
|
|
|
11739
11744
|
let last = 0;
|
|
11740
11745
|
let count = 0;
|
|
11741
11746
|
let changed = false;
|
|
11742
|
-
let
|
|
11743
|
-
while ((
|
|
11747
|
+
let match2;
|
|
11748
|
+
while ((match2 = re.exec(input)) !== null) {
|
|
11744
11749
|
count++;
|
|
11745
11750
|
const wanted = occurrence > 0 ? count >= occurrence && (global || count === occurrence) : true;
|
|
11746
11751
|
if (wanted) {
|
|
11747
|
-
out += input.slice(last,
|
|
11748
|
-
last =
|
|
11752
|
+
out += input.slice(last, match2.index) + applyReplacement(replacement, match2);
|
|
11753
|
+
last = match2.index + match2[0].length;
|
|
11749
11754
|
changed = true;
|
|
11750
11755
|
if (!global) break;
|
|
11751
11756
|
}
|
|
11752
|
-
if (
|
|
11757
|
+
if (match2[0] === "") re.lastIndex++;
|
|
11753
11758
|
}
|
|
11754
11759
|
out += input.slice(last);
|
|
11755
11760
|
return { text: out, changed };
|
|
@@ -12404,12 +12409,12 @@ var AwkParser = class {
|
|
|
12404
12409
|
return this.parsePower(noGt);
|
|
12405
12410
|
}
|
|
12406
12411
|
parsePower(noGt) {
|
|
12407
|
-
const
|
|
12412
|
+
const base2 = this.parsePostfix(noGt);
|
|
12408
12413
|
if (this.isOp("^") || this.isOp("**")) {
|
|
12409
12414
|
this.i++;
|
|
12410
|
-
return { t: "binary", op: "^", left:
|
|
12415
|
+
return { t: "binary", op: "^", left: base2, right: this.parseUnary(noGt) };
|
|
12411
12416
|
}
|
|
12412
|
-
return
|
|
12417
|
+
return base2;
|
|
12413
12418
|
}
|
|
12414
12419
|
parsePostfix(noGt) {
|
|
12415
12420
|
if (this.isOp("++") || this.isOp("--")) {
|
|
@@ -12703,11 +12708,11 @@ var Interpreter = class {
|
|
|
12703
12708
|
toStrRaw(v) {
|
|
12704
12709
|
return v === void 0 ? "%.6g" : v.isNum ? String(v.num) : v.str;
|
|
12705
12710
|
}
|
|
12706
|
-
numToStr(n,
|
|
12711
|
+
numToStr(n, format3) {
|
|
12707
12712
|
if (Number.isInteger(n) && Math.abs(n) < 1e16) return String(n);
|
|
12708
12713
|
if (!Number.isFinite(n)) return n > 0 ? "inf" : Number.isNaN(n) ? "nan" : "-inf";
|
|
12709
12714
|
try {
|
|
12710
|
-
return formatPrintf(
|
|
12715
|
+
return formatPrintf(format3, [String(n)]);
|
|
12711
12716
|
} catch {
|
|
12712
12717
|
return String(n);
|
|
12713
12718
|
}
|
|
@@ -13013,9 +13018,9 @@ var Interpreter = class {
|
|
|
13013
13018
|
let count = 0;
|
|
13014
13019
|
const result = subject.replace(re, (...groups) => {
|
|
13015
13020
|
count++;
|
|
13016
|
-
const
|
|
13021
|
+
const match2 = groups[0];
|
|
13017
13022
|
return replacement.replace(/\\?&|\\\\/g, (token) => {
|
|
13018
|
-
if (token === "&") return
|
|
13023
|
+
if (token === "&") return match2;
|
|
13019
13024
|
if (token === "\\&") return "&";
|
|
13020
13025
|
return "\\";
|
|
13021
13026
|
});
|
|
@@ -13037,9 +13042,9 @@ var Interpreter = class {
|
|
|
13037
13042
|
return Value.fromNumber(m.index + 1);
|
|
13038
13043
|
}
|
|
13039
13044
|
case "sprintf": {
|
|
13040
|
-
const
|
|
13045
|
+
const format3 = str(0);
|
|
13041
13046
|
const rest = args.slice(1).map((a) => this.outputStr(this.evaluate(a)));
|
|
13042
|
-
return Value.fromString(formatPrintf(
|
|
13047
|
+
return Value.fromString(formatPrintf(format3, rest));
|
|
13043
13048
|
}
|
|
13044
13049
|
case "sin":
|
|
13045
13050
|
return Value.fromNumber(Math.sin(num(0)));
|
|
@@ -13186,12 +13191,12 @@ var Interpreter = class {
|
|
|
13186
13191
|
}
|
|
13187
13192
|
case "printf": {
|
|
13188
13193
|
if (stmt.args.length === 0) throw new AwkError("printf: no format supplied");
|
|
13189
|
-
const
|
|
13194
|
+
const format3 = this.toStr(this.evaluate(stmt.args[0]));
|
|
13190
13195
|
const rest = stmt.args.slice(1).map((a) => {
|
|
13191
13196
|
const v = this.evaluate(a);
|
|
13192
13197
|
return v.isNum ? String(v.num) : v.str;
|
|
13193
13198
|
});
|
|
13194
|
-
this.emit(formatPrintf(
|
|
13199
|
+
this.emit(formatPrintf(format3, rest), stmt.redirect);
|
|
13195
13200
|
return;
|
|
13196
13201
|
}
|
|
13197
13202
|
case "if":
|
|
@@ -13491,8 +13496,8 @@ async function runAwk(ctx) {
|
|
|
13491
13496
|
continue;
|
|
13492
13497
|
}
|
|
13493
13498
|
try {
|
|
13494
|
-
const
|
|
13495
|
-
inputs.push({ name: operand, lines: splitLines(
|
|
13499
|
+
const bytes2 = ctx.vfs.readFile(ctx.path(operand), ctx.cred);
|
|
13500
|
+
inputs.push({ name: operand, lines: splitLines(bytes2).lines });
|
|
13496
13501
|
} catch (e) {
|
|
13497
13502
|
ctx.reportError(e, operand);
|
|
13498
13503
|
return 2;
|
|
@@ -13547,7 +13552,7 @@ var head = defineCommand({
|
|
|
13547
13552
|
],
|
|
13548
13553
|
{ numericShortcut: "lines" }
|
|
13549
13554
|
);
|
|
13550
|
-
const { sources, ok } = await readInputs(ctx, args.positional, { stdinName: "standard input" });
|
|
13555
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional, { stdinName: "standard input" });
|
|
13551
13556
|
const showHeaders = (sources.length > 1 || args.has("verbose")) && !args.has("quiet");
|
|
13552
13557
|
sources.forEach((source, index) => {
|
|
13553
13558
|
if (showHeaders) {
|
|
@@ -13565,7 +13570,7 @@ var head = defineCommand({
|
|
|
13565
13570
|
const kept = count.fromEnd ? lines.slice(0, Math.max(0, lines.length - count.value)) : lines.slice(0, count.value);
|
|
13566
13571
|
ctx.write(joinLines(kept, trailingNewline || kept.length < lines.length));
|
|
13567
13572
|
});
|
|
13568
|
-
return
|
|
13573
|
+
return ok2 ? 0 : 1;
|
|
13569
13574
|
}
|
|
13570
13575
|
});
|
|
13571
13576
|
function parseCount(spec) {
|
|
@@ -13594,7 +13599,7 @@ var tail = defineCommand({
|
|
|
13594
13599
|
],
|
|
13595
13600
|
{ numericShortcut: "lines" }
|
|
13596
13601
|
);
|
|
13597
|
-
const { sources, ok } = await readInputs(ctx, args.positional, { stdinName: "standard input" });
|
|
13602
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional, { stdinName: "standard input" });
|
|
13598
13603
|
const showHeaders = (sources.length > 1 || args.has("verbose")) && !args.has("quiet");
|
|
13599
13604
|
sources.forEach((source, index) => {
|
|
13600
13605
|
if (showHeaders) {
|
|
@@ -13618,7 +13623,7 @@ var tail = defineCommand({
|
|
|
13618
13623
|
if (args.has("follow") && args.positional.length > 0) {
|
|
13619
13624
|
await followFiles(ctx, args.positional, Number(args.str("sleep-interval", "1")) * 1e3);
|
|
13620
13625
|
}
|
|
13621
|
-
return
|
|
13626
|
+
return ok2 ? 0 : 1;
|
|
13622
13627
|
}
|
|
13623
13628
|
});
|
|
13624
13629
|
async function followFiles(ctx, paths, intervalMs) {
|
|
@@ -13635,12 +13640,12 @@ async function followFiles(ctx, paths, intervalMs) {
|
|
|
13635
13640
|
if (ctx.signal.aborted) break;
|
|
13636
13641
|
for (const path of paths) {
|
|
13637
13642
|
try {
|
|
13638
|
-
const
|
|
13643
|
+
const bytes2 = ctx.vfs.readFile(ctx.path(path), ctx.cred);
|
|
13639
13644
|
const previous = offsets.get(path) ?? 0;
|
|
13640
|
-
if (
|
|
13641
|
-
ctx.write(
|
|
13642
|
-
offsets.set(path,
|
|
13643
|
-
} else if (
|
|
13645
|
+
if (bytes2.length > previous) {
|
|
13646
|
+
ctx.write(bytes2.subarray(previous));
|
|
13647
|
+
offsets.set(path, bytes2.length);
|
|
13648
|
+
} else if (bytes2.length < previous) {
|
|
13644
13649
|
offsets.set(path, 0);
|
|
13645
13650
|
}
|
|
13646
13651
|
} catch {
|
|
@@ -13661,7 +13666,7 @@ var wc = defineCommand({
|
|
|
13661
13666
|
{ short: "w", long: "words" },
|
|
13662
13667
|
{ short: "L", long: "max-line-length" }
|
|
13663
13668
|
]);
|
|
13664
|
-
const { sources, ok } = await readInputs(ctx, args.positional, { stdinName: "" });
|
|
13669
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional, { stdinName: "" });
|
|
13665
13670
|
const anyFlag = args.has("bytes") || args.has("chars") || args.has("lines") || args.has("words") || args.has("max-line-length");
|
|
13666
13671
|
const totals = { lines: 0, words: 0, bytes: 0, chars: 0, maxLine: 0 };
|
|
13667
13672
|
const rows = [];
|
|
@@ -13699,7 +13704,7 @@ var wc = defineCommand({
|
|
|
13699
13704
|
}
|
|
13700
13705
|
ctx.line(parts.join(" ") + (row.name ? ` ${row.name}` : ""));
|
|
13701
13706
|
}
|
|
13702
|
-
return
|
|
13707
|
+
return ok2 ? 0 : 1;
|
|
13703
13708
|
}
|
|
13704
13709
|
});
|
|
13705
13710
|
var sort = defineCommand({
|
|
@@ -13725,7 +13730,7 @@ var sort = defineCommand({
|
|
|
13725
13730
|
{ short: "z", long: "zero-terminated" },
|
|
13726
13731
|
{ short: "o", long: "output", arg: true }
|
|
13727
13732
|
]);
|
|
13728
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
13733
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
13729
13734
|
const all = [];
|
|
13730
13735
|
for (const source of sources) all.push(...splitLines(source.bytes).lines);
|
|
13731
13736
|
const separator = args.str("field-separator");
|
|
@@ -13789,7 +13794,7 @@ var sort = defineCommand({
|
|
|
13789
13794
|
const target = args.str("output");
|
|
13790
13795
|
if (target) ctx.vfs.writeFile(ctx.path(target), output, { cred: ctx.cred });
|
|
13791
13796
|
else ctx.write(output);
|
|
13792
|
-
return
|
|
13797
|
+
return ok2 ? 0 : 1;
|
|
13793
13798
|
}
|
|
13794
13799
|
});
|
|
13795
13800
|
var uniq = defineCommand({
|
|
@@ -13809,7 +13814,7 @@ var uniq = defineCommand({
|
|
|
13809
13814
|
{ short: "w", long: "check-chars", arg: true }
|
|
13810
13815
|
]);
|
|
13811
13816
|
const [input, output] = args.positional;
|
|
13812
|
-
const { sources, ok } = await readInputs(ctx, input ? [input] : []);
|
|
13817
|
+
const { sources, ok: ok2 } = await readInputs(ctx, input ? [input] : []);
|
|
13813
13818
|
const lines = sources.flatMap((s) => splitLines(s.bytes).lines);
|
|
13814
13819
|
const key = (line) => {
|
|
13815
13820
|
let value = line;
|
|
@@ -13841,7 +13846,7 @@ var uniq = defineCommand({
|
|
|
13841
13846
|
const text2 = joinLines(out, true);
|
|
13842
13847
|
if (output) ctx.vfs.writeFile(ctx.path(output), text2, { cred: ctx.cred });
|
|
13843
13848
|
else ctx.write(text2);
|
|
13844
|
-
return
|
|
13849
|
+
return ok2 ? 0 : 1;
|
|
13845
13850
|
}
|
|
13846
13851
|
});
|
|
13847
13852
|
var cut = defineCommand({
|
|
@@ -13865,7 +13870,7 @@ var cut = defineCommand({
|
|
|
13865
13870
|
const delimiter = args.str("delimiter", " ");
|
|
13866
13871
|
const outputDelimiter = args.str("output-delimiter", delimiter);
|
|
13867
13872
|
const byField = args.has("fields");
|
|
13868
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
13873
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
13869
13874
|
for (const source of sources) {
|
|
13870
13875
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
13871
13876
|
const out = lines.flatMap((line) => {
|
|
@@ -13880,7 +13885,7 @@ var cut = defineCommand({
|
|
|
13880
13885
|
});
|
|
13881
13886
|
ctx.write(joinLines(out, trailingNewline));
|
|
13882
13887
|
}
|
|
13883
|
-
return
|
|
13888
|
+
return ok2 ? 0 : 1;
|
|
13884
13889
|
}
|
|
13885
13890
|
});
|
|
13886
13891
|
function parseRanges(spec) {
|
|
@@ -13914,13 +13919,13 @@ var paste = defineCommand({
|
|
|
13914
13919
|
{ short: "s", long: "serial" }
|
|
13915
13920
|
]);
|
|
13916
13921
|
const delimiters = [...args.str("delimiters") || " "];
|
|
13917
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
13922
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
13918
13923
|
const columns = sources.map((s) => splitLines(s.bytes).lines);
|
|
13919
13924
|
if (args.has("serial")) {
|
|
13920
13925
|
for (const column2 of columns) {
|
|
13921
13926
|
ctx.line(column2.map((line, idx) => idx === 0 ? line : delimiters[(idx - 1) % delimiters.length] + line).join(""));
|
|
13922
13927
|
}
|
|
13923
|
-
return
|
|
13928
|
+
return ok2 ? 0 : 1;
|
|
13924
13929
|
}
|
|
13925
13930
|
const rows = Math.max(0, ...columns.map((c) => c.length));
|
|
13926
13931
|
for (let r = 0; r < rows; r++) {
|
|
@@ -13931,7 +13936,7 @@ var paste = defineCommand({
|
|
|
13931
13936
|
});
|
|
13932
13937
|
ctx.line(line);
|
|
13933
13938
|
}
|
|
13934
|
-
return
|
|
13939
|
+
return ok2 ? 0 : 1;
|
|
13935
13940
|
}
|
|
13936
13941
|
});
|
|
13937
13942
|
var tr = defineCommand({
|
|
@@ -14023,14 +14028,14 @@ var tee = defineCommand({
|
|
|
14023
14028
|
{ short: "a", long: "append" },
|
|
14024
14029
|
{ short: "i", long: "ignore-interrupts" }
|
|
14025
14030
|
]);
|
|
14026
|
-
const
|
|
14027
|
-
ctx.write(
|
|
14031
|
+
const bytes2 = await ctx.stdin.readAll();
|
|
14032
|
+
ctx.write(bytes2);
|
|
14028
14033
|
let status = 0;
|
|
14029
14034
|
for (const target of args.positional) {
|
|
14030
14035
|
try {
|
|
14031
14036
|
const abs = ctx.path(target);
|
|
14032
|
-
if (args.has("append")) ctx.vfs.appendFile(abs,
|
|
14033
|
-
else ctx.vfs.writeFile(abs,
|
|
14037
|
+
if (args.has("append")) ctx.vfs.appendFile(abs, bytes2, { cred: ctx.cred });
|
|
14038
|
+
else ctx.vfs.writeFile(abs, bytes2, { cred: ctx.cred });
|
|
14034
14039
|
} catch (e) {
|
|
14035
14040
|
status = ctx.reportError(e, target);
|
|
14036
14041
|
}
|
|
@@ -14043,12 +14048,12 @@ var rev = defineCommand({
|
|
|
14043
14048
|
path: "/usr/bin/rev",
|
|
14044
14049
|
summary: "reverse lines characterwise",
|
|
14045
14050
|
async run(ctx) {
|
|
14046
|
-
const { sources, ok } = await readInputs(ctx, ctx.args);
|
|
14051
|
+
const { sources, ok: ok2 } = await readInputs(ctx, ctx.args);
|
|
14047
14052
|
for (const source of sources) {
|
|
14048
14053
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
14049
14054
|
ctx.write(joinLines(lines.map((l) => [...l].reverse().join("")), trailingNewline));
|
|
14050
14055
|
}
|
|
14051
|
-
return
|
|
14056
|
+
return ok2 ? 0 : 1;
|
|
14052
14057
|
}
|
|
14053
14058
|
});
|
|
14054
14059
|
var tac = defineCommand({
|
|
@@ -14057,12 +14062,12 @@ var tac = defineCommand({
|
|
|
14057
14062
|
summary: "concatenate and print files in reverse",
|
|
14058
14063
|
async run(ctx) {
|
|
14059
14064
|
const args = parseArgs(ctx.args, [{ short: "s", long: "separator", arg: true }]);
|
|
14060
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14065
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14061
14066
|
for (const source of sources) {
|
|
14062
14067
|
const { lines } = splitLines(source.bytes);
|
|
14063
14068
|
ctx.write(joinLines(lines.reverse(), true));
|
|
14064
14069
|
}
|
|
14065
|
-
return
|
|
14070
|
+
return ok2 ? 0 : 1;
|
|
14066
14071
|
}
|
|
14067
14072
|
});
|
|
14068
14073
|
var nl = defineCommand({
|
|
@@ -14077,7 +14082,7 @@ var nl = defineCommand({
|
|
|
14077
14082
|
{ short: "v", long: "starting-line-number", arg: true, default: "1" },
|
|
14078
14083
|
{ short: "i", long: "line-increment", arg: true, default: "1" }
|
|
14079
14084
|
]);
|
|
14080
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14085
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14081
14086
|
const width = args.num("number-width", 6);
|
|
14082
14087
|
const separator = args.str("number-separator", " ");
|
|
14083
14088
|
const style = args.str("body-numbering", "t");
|
|
@@ -14094,7 +14099,7 @@ var nl = defineCommand({
|
|
|
14094
14099
|
}
|
|
14095
14100
|
}
|
|
14096
14101
|
}
|
|
14097
|
-
return
|
|
14102
|
+
return ok2 ? 0 : 1;
|
|
14098
14103
|
}
|
|
14099
14104
|
});
|
|
14100
14105
|
var fold = defineCommand({
|
|
@@ -14112,7 +14117,7 @@ var fold = defineCommand({
|
|
|
14112
14117
|
{ numericShortcut: "width" }
|
|
14113
14118
|
);
|
|
14114
14119
|
const width = args.num("width", 80);
|
|
14115
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14120
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14116
14121
|
for (const source of sources) {
|
|
14117
14122
|
for (const line of splitLines(source.bytes).lines) {
|
|
14118
14123
|
let rest = line;
|
|
@@ -14132,7 +14137,7 @@ var fold = defineCommand({
|
|
|
14132
14137
|
ctx.line(rest);
|
|
14133
14138
|
}
|
|
14134
14139
|
}
|
|
14135
|
-
return
|
|
14140
|
+
return ok2 ? 0 : 1;
|
|
14136
14141
|
}
|
|
14137
14142
|
});
|
|
14138
14143
|
var expandCmd = defineCommand({
|
|
@@ -14142,7 +14147,7 @@ var expandCmd = defineCommand({
|
|
|
14142
14147
|
async run(ctx) {
|
|
14143
14148
|
const args = parseArgs(ctx.args, [{ short: "t", long: "tabs", arg: true, default: "8" }, { short: "i", long: "initial" }]);
|
|
14144
14149
|
const tabs = args.num("tabs", 8);
|
|
14145
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14150
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14146
14151
|
for (const source of sources) {
|
|
14147
14152
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
14148
14153
|
const out = lines.map((line) => {
|
|
@@ -14155,7 +14160,7 @@ var expandCmd = defineCommand({
|
|
|
14155
14160
|
});
|
|
14156
14161
|
ctx.write(joinLines(out, trailingNewline));
|
|
14157
14162
|
}
|
|
14158
|
-
return
|
|
14163
|
+
return ok2 ? 0 : 1;
|
|
14159
14164
|
}
|
|
14160
14165
|
});
|
|
14161
14166
|
var unexpand = defineCommand({
|
|
@@ -14165,7 +14170,7 @@ var unexpand = defineCommand({
|
|
|
14165
14170
|
async run(ctx) {
|
|
14166
14171
|
const args = parseArgs(ctx.args, [{ short: "t", long: "tabs", arg: true, default: "8" }, { short: "a", long: "all" }]);
|
|
14167
14172
|
const tabs = args.num("tabs", 8);
|
|
14168
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14173
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14169
14174
|
for (const source of sources) {
|
|
14170
14175
|
const { lines, trailingNewline } = splitLines(source.bytes);
|
|
14171
14176
|
const out = lines.map((line) => {
|
|
@@ -14175,7 +14180,7 @@ var unexpand = defineCommand({
|
|
|
14175
14180
|
});
|
|
14176
14181
|
ctx.write(joinLines(out, trailingNewline));
|
|
14177
14182
|
}
|
|
14178
|
-
return
|
|
14183
|
+
return ok2 ? 0 : 1;
|
|
14179
14184
|
}
|
|
14180
14185
|
});
|
|
14181
14186
|
var fmt = defineCommand({
|
|
@@ -14185,7 +14190,7 @@ var fmt = defineCommand({
|
|
|
14185
14190
|
async run(ctx) {
|
|
14186
14191
|
const args = parseArgs(ctx.args, [{ short: "w", long: "width", arg: true, default: "75" }], { numericShortcut: "width" });
|
|
14187
14192
|
const width = args.num("width", 75);
|
|
14188
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14193
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14189
14194
|
for (const source of sources) {
|
|
14190
14195
|
const paragraphs = decoder4.decode(source.bytes).split(/\n\s*\n/);
|
|
14191
14196
|
paragraphs.forEach((paragraph, idx) => {
|
|
@@ -14203,7 +14208,7 @@ var fmt = defineCommand({
|
|
|
14203
14208
|
if (line) ctx.line(line);
|
|
14204
14209
|
});
|
|
14205
14210
|
}
|
|
14206
|
-
return
|
|
14211
|
+
return ok2 ? 0 : 1;
|
|
14207
14212
|
}
|
|
14208
14213
|
});
|
|
14209
14214
|
var column = defineCommand({
|
|
@@ -14216,11 +14221,11 @@ var column = defineCommand({
|
|
|
14216
14221
|
{ short: "s", long: "separator", arg: true },
|
|
14217
14222
|
{ short: "o", long: "output-separator", arg: true, default: " " }
|
|
14218
14223
|
]);
|
|
14219
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
14224
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
14220
14225
|
const lines = sources.flatMap((s) => splitLines(s.bytes).lines).filter((l) => l !== "");
|
|
14221
14226
|
if (!args.has("table")) {
|
|
14222
14227
|
for (const line of lines) ctx.line(line);
|
|
14223
|
-
return
|
|
14228
|
+
return ok2 ? 0 : 1;
|
|
14224
14229
|
}
|
|
14225
14230
|
const separator = args.str("separator");
|
|
14226
14231
|
const rows = lines.map((line) => separator ? line.split(separator) : line.trim().split(/\s+/));
|
|
@@ -14230,7 +14235,7 @@ var column = defineCommand({
|
|
|
14230
14235
|
for (const row of rows) {
|
|
14231
14236
|
ctx.line(row.map((cell, i) => i === row.length - 1 ? cell : cell.padEnd(widths[i])).join(outputSeparator).trimEnd());
|
|
14232
14237
|
}
|
|
14233
|
-
return
|
|
14238
|
+
return ok2 ? 0 : 1;
|
|
14234
14239
|
}
|
|
14235
14240
|
});
|
|
14236
14241
|
var shuf = defineCommand({
|
|
@@ -14273,7 +14278,7 @@ var comm = defineCommand({
|
|
|
14273
14278
|
const args = parseArgs(ctx.args, [{ short: "1" }, { short: "2" }, { short: "3" }]);
|
|
14274
14279
|
const [a, b] = args.positional;
|
|
14275
14280
|
if (a === void 0 || b === void 0) return ctx.fail("missing operand", 1);
|
|
14276
|
-
const { sources, ok } = await readInputs(ctx, [a, b]);
|
|
14281
|
+
const { sources, ok: ok2 } = await readInputs(ctx, [a, b]);
|
|
14277
14282
|
const left = splitLines(sources[0].bytes).lines;
|
|
14278
14283
|
const right = splitLines(sources[1].bytes).lines;
|
|
14279
14284
|
let i = 0;
|
|
@@ -14293,7 +14298,7 @@ var comm = defineCommand({
|
|
|
14293
14298
|
j++;
|
|
14294
14299
|
}
|
|
14295
14300
|
}
|
|
14296
|
-
return
|
|
14301
|
+
return ok2 ? 0 : 1;
|
|
14297
14302
|
}
|
|
14298
14303
|
});
|
|
14299
14304
|
var join2 = defineCommand({
|
|
@@ -14314,7 +14319,7 @@ var join2 = defineCommand({
|
|
|
14314
14319
|
const joinChar = separator ?? " ";
|
|
14315
14320
|
const key1 = Number(args.str("j") ?? args.str("1", "1")) - 1;
|
|
14316
14321
|
const key2 = Number(args.str("j") ?? args.str("2", "1")) - 1;
|
|
14317
|
-
const { sources, ok } = await readInputs(ctx, [a, b]);
|
|
14322
|
+
const { sources, ok: ok2 } = await readInputs(ctx, [a, b]);
|
|
14318
14323
|
const left = splitLines(sources[0].bytes).lines.map(split2);
|
|
14319
14324
|
const right = splitLines(sources[1].bytes).lines.map(split2);
|
|
14320
14325
|
for (const l of left) {
|
|
@@ -14326,7 +14331,7 @@ var join2 = defineCommand({
|
|
|
14326
14331
|
}
|
|
14327
14332
|
}
|
|
14328
14333
|
}
|
|
14329
|
-
return
|
|
14334
|
+
return ok2 ? 0 : 1;
|
|
14330
14335
|
}
|
|
14331
14336
|
});
|
|
14332
14337
|
var split = defineCommand({
|
|
@@ -14342,17 +14347,17 @@ var split = defineCommand({
|
|
|
14342
14347
|
]);
|
|
14343
14348
|
const [input, prefixRaw] = args.positional;
|
|
14344
14349
|
const prefix = prefixRaw ?? "x";
|
|
14345
|
-
const { sources, ok } = await readInputs(ctx, input ? [input] : []);
|
|
14346
|
-
const
|
|
14350
|
+
const { sources, ok: ok2 } = await readInputs(ctx, input ? [input] : []);
|
|
14351
|
+
const bytes2 = sources[0]?.bytes ?? new Uint8Array(0);
|
|
14347
14352
|
const suffixLength = args.num("suffix-length", 2);
|
|
14348
14353
|
const chunks = [];
|
|
14349
14354
|
const byteSpec = args.str("bytes");
|
|
14350
14355
|
if (byteSpec !== void 0) {
|
|
14351
14356
|
const size = parseSize(byteSpec) ?? 1024;
|
|
14352
|
-
for (let i = 0; i <
|
|
14357
|
+
for (let i = 0; i < bytes2.length; i += size) chunks.push(bytes2.subarray(i, i + size));
|
|
14353
14358
|
} else {
|
|
14354
14359
|
const perChunk = args.num("lines", 1e3);
|
|
14355
|
-
const { lines } = splitLines(
|
|
14360
|
+
const { lines } = splitLines(bytes2);
|
|
14356
14361
|
for (let i = 0; i < lines.length; i += perChunk) {
|
|
14357
14362
|
chunks.push(new TextEncoder().encode(joinLines(lines.slice(i, i + perChunk), true)));
|
|
14358
14363
|
}
|
|
@@ -14361,7 +14366,7 @@ var split = defineCommand({
|
|
|
14361
14366
|
const suffix = args.has("numeric-suffixes") ? String(idx).padStart(suffixLength, "0") : numericToAlpha(idx, suffixLength);
|
|
14362
14367
|
ctx.vfs.writeFile(ctx.path(prefix + suffix), chunk, { cred: ctx.cred });
|
|
14363
14368
|
});
|
|
14364
|
-
return
|
|
14369
|
+
return ok2 ? 0 : 1;
|
|
14365
14370
|
}
|
|
14366
14371
|
});
|
|
14367
14372
|
function numericToAlpha(value, length) {
|
|
@@ -14562,19 +14567,19 @@ var grep = defineCommand({
|
|
|
14562
14567
|
let anyMatch = false;
|
|
14563
14568
|
let status = 1;
|
|
14564
14569
|
for (const target of targets) {
|
|
14565
|
-
let
|
|
14570
|
+
let bytes2;
|
|
14566
14571
|
if (target === "-") {
|
|
14567
|
-
|
|
14572
|
+
bytes2 = await ctx.stdin.readAll();
|
|
14568
14573
|
} else {
|
|
14569
14574
|
try {
|
|
14570
|
-
|
|
14575
|
+
bytes2 = ctx.vfs.readFile(ctx.path(target), ctx.cred);
|
|
14571
14576
|
} catch (e) {
|
|
14572
14577
|
if (!args.has("no-messages")) ctx.reportError(e, target);
|
|
14573
14578
|
status = 2;
|
|
14574
14579
|
continue;
|
|
14575
14580
|
}
|
|
14576
14581
|
}
|
|
14577
|
-
const { lines } = splitLines(
|
|
14582
|
+
const { lines } = splitLines(bytes2);
|
|
14578
14583
|
const matched = [];
|
|
14579
14584
|
let count = 0;
|
|
14580
14585
|
for (let i = 0; i < lines.length && count < maxCount; i++) {
|
|
@@ -14986,8 +14991,8 @@ var diff = defineCommand({
|
|
|
14986
14991
|
]);
|
|
14987
14992
|
const [a, b] = args.positional;
|
|
14988
14993
|
if (a === void 0 || b === void 0) return ctx.fail("missing operand", 2);
|
|
14989
|
-
const { sources, ok } = await readInputs(ctx, [a, b]);
|
|
14990
|
-
if (!
|
|
14994
|
+
const { sources, ok: ok2 } = await readInputs(ctx, [a, b]);
|
|
14995
|
+
if (!ok2 || sources.length < 2) return 2;
|
|
14991
14996
|
const normalize3 = (line) => {
|
|
14992
14997
|
let value = line;
|
|
14993
14998
|
if (args.has("ignore-all-space")) value = value.replace(/\s+/g, "");
|
|
@@ -15120,8 +15125,8 @@ var cmp = defineCommand({
|
|
|
15120
15125
|
const args = parseArgs(ctx.args, [{ short: "s", long: "silent" }, { short: "l", long: "verbose" }]);
|
|
15121
15126
|
const [a, b] = args.positional;
|
|
15122
15127
|
if (a === void 0 || b === void 0) return ctx.fail("missing operand", 2);
|
|
15123
|
-
const { sources, ok } = await readInputs(ctx, [a, b]);
|
|
15124
|
-
if (!
|
|
15128
|
+
const { sources, ok: ok2 } = await readInputs(ctx, [a, b]);
|
|
15129
|
+
if (!ok2) return 2;
|
|
15125
15130
|
const left = sources[0].bytes;
|
|
15126
15131
|
const right = sources[1].bytes;
|
|
15127
15132
|
const length = Math.min(left.length, right.length);
|
|
@@ -15231,9 +15236,9 @@ async function randomUuid() {
|
|
|
15231
15236
|
const { randomUUID } = await nodeCrypto();
|
|
15232
15237
|
return randomUUID();
|
|
15233
15238
|
}
|
|
15234
|
-
function toHex(
|
|
15239
|
+
function toHex(bytes2) {
|
|
15235
15240
|
let out = "";
|
|
15236
|
-
for (const byte of
|
|
15241
|
+
for (const byte of bytes2) out += byte.toString(16).padStart(2, "0");
|
|
15237
15242
|
return out;
|
|
15238
15243
|
}
|
|
15239
15244
|
function md5Hex(input) {
|
|
@@ -15361,8 +15366,8 @@ var BLOCK = 512;
|
|
|
15361
15366
|
var encoder4 = new TextEncoder();
|
|
15362
15367
|
var decoder6 = new TextDecoder();
|
|
15363
15368
|
function writeString(block, offset, value, length) {
|
|
15364
|
-
const
|
|
15365
|
-
for (let i = 0; i < length; i++) block[offset + i] = i <
|
|
15369
|
+
const bytes2 = encoder4.encode(value);
|
|
15370
|
+
for (let i = 0; i < length; i++) block[offset + i] = i < bytes2.length ? bytes2[i] : 0;
|
|
15366
15371
|
}
|
|
15367
15372
|
function writeOctal(block, offset, value, length) {
|
|
15368
15373
|
const text2 = value.toString(8).padStart(length - 1, "0");
|
|
@@ -15513,23 +15518,23 @@ var tar = defineCommand({
|
|
|
15513
15518
|
if (args.has("verbose")) ctx.line(name);
|
|
15514
15519
|
};
|
|
15515
15520
|
for (const operand of args.positional) add(resolve(baseDir, operand), operand);
|
|
15516
|
-
let
|
|
15517
|
-
if (compressed)
|
|
15518
|
-
if (archive === void 0 || archive === "-") ctx.write(
|
|
15519
|
-
else ctx.vfs.writeFile(ctx.path(archive),
|
|
15521
|
+
let bytes3 = createTar(entries2);
|
|
15522
|
+
if (compressed) bytes3 = await gzip(bytes3);
|
|
15523
|
+
if (archive === void 0 || archive === "-") ctx.write(bytes3);
|
|
15524
|
+
else ctx.vfs.writeFile(ctx.path(archive), bytes3, { cred: ctx.cred, mode: 420 });
|
|
15520
15525
|
return 0;
|
|
15521
15526
|
}
|
|
15522
|
-
let
|
|
15523
|
-
if (archive === void 0 || archive === "-")
|
|
15527
|
+
let bytes2;
|
|
15528
|
+
if (archive === void 0 || archive === "-") bytes2 = await ctx.stdin.readAll();
|
|
15524
15529
|
else {
|
|
15525
15530
|
try {
|
|
15526
|
-
|
|
15531
|
+
bytes2 = ctx.vfs.readFile(ctx.path(archive), ctx.cred);
|
|
15527
15532
|
} catch (e) {
|
|
15528
15533
|
return ctx.reportError(e, archive);
|
|
15529
15534
|
}
|
|
15530
15535
|
}
|
|
15531
|
-
if (
|
|
15532
|
-
const entries = readTar(
|
|
15536
|
+
if (bytes2[0] === 31 && bytes2[1] === 139) bytes2 = await gunzip(bytes2);
|
|
15537
|
+
const entries = readTar(bytes2);
|
|
15533
15538
|
const strip = args.num("strip-components", 0);
|
|
15534
15539
|
if (args.has("list")) {
|
|
15535
15540
|
for (const entry of entries) {
|
|
@@ -15685,18 +15690,18 @@ function makeSum(name, algorithm, path) {
|
|
|
15685
15690
|
{ long: "tag" }
|
|
15686
15691
|
]);
|
|
15687
15692
|
if (args.has("check")) return checkSums(ctx, algorithm, args.positional, args.has("quiet") || args.has("status"));
|
|
15688
|
-
const { sources, ok } = await readInputs(ctx, args.positional, { stdinName: "-" });
|
|
15693
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional, { stdinName: "-" });
|
|
15689
15694
|
for (const source of sources) {
|
|
15690
15695
|
const digest = await digestHex(algorithm, source.bytes);
|
|
15691
15696
|
if (args.has("tag")) ctx.line(`${algorithm.toUpperCase()} (${source.name}) = ${digest}`);
|
|
15692
15697
|
else ctx.line(`${digest} ${source.name}`);
|
|
15693
15698
|
}
|
|
15694
|
-
return
|
|
15699
|
+
return ok2 ? 0 : 1;
|
|
15695
15700
|
}
|
|
15696
15701
|
});
|
|
15697
15702
|
}
|
|
15698
15703
|
async function checkSums(ctx, algorithm, files, quiet) {
|
|
15699
|
-
const { sources, ok } = await readInputs(ctx, files);
|
|
15704
|
+
const { sources, ok: ok2 } = await readInputs(ctx, files);
|
|
15700
15705
|
let failures = 0;
|
|
15701
15706
|
let checked = 0;
|
|
15702
15707
|
for (const source of sources) {
|
|
@@ -15707,8 +15712,8 @@ async function checkSums(ctx, algorithm, files, quiet) {
|
|
|
15707
15712
|
checked++;
|
|
15708
15713
|
const [, expected, name] = m;
|
|
15709
15714
|
try {
|
|
15710
|
-
const
|
|
15711
|
-
const actual = await digestHex(algorithm,
|
|
15715
|
+
const bytes2 = ctx.vfs.readFile(ctx.path(name), ctx.cred);
|
|
15716
|
+
const actual = await digestHex(algorithm, bytes2);
|
|
15712
15717
|
if (actual === expected.toLowerCase()) {
|
|
15713
15718
|
if (!quiet) ctx.line(`${name}: OK`);
|
|
15714
15719
|
} else {
|
|
@@ -15722,7 +15727,7 @@ async function checkSums(ctx, algorithm, files, quiet) {
|
|
|
15722
15727
|
}
|
|
15723
15728
|
}
|
|
15724
15729
|
if (failures > 0) ctx.warn(`WARNING: ${failures} computed checksum${failures === 1 ? "" : "s"} did NOT match`);
|
|
15725
|
-
return
|
|
15730
|
+
return ok2 && failures === 0 && checked > 0 ? 0 : 1;
|
|
15726
15731
|
}
|
|
15727
15732
|
var md5sum = makeSum("md5sum", "md5", "/usr/bin/md5sum");
|
|
15728
15733
|
var sha1sum = makeSum("sha1sum", "sha1", "/usr/bin/sha1sum");
|
|
@@ -15735,11 +15740,11 @@ var cksum = defineCommand({
|
|
|
15735
15740
|
path: "/usr/bin/cksum",
|
|
15736
15741
|
summary: "checksum and count the bytes in a file",
|
|
15737
15742
|
async run(ctx) {
|
|
15738
|
-
const { sources, ok } = await readInputs(ctx, ctx.args, { stdinName: "" });
|
|
15743
|
+
const { sources, ok: ok2 } = await readInputs(ctx, ctx.args, { stdinName: "" });
|
|
15739
15744
|
for (const source of sources) {
|
|
15740
15745
|
ctx.line(`${crc32(source.bytes)} ${source.bytes.length}${source.name ? ` ${source.name}` : ""}`);
|
|
15741
15746
|
}
|
|
15742
|
-
return
|
|
15747
|
+
return ok2 ? 0 : 1;
|
|
15743
15748
|
}
|
|
15744
15749
|
});
|
|
15745
15750
|
var CRC_TABLE = (() => {
|
|
@@ -15767,7 +15772,7 @@ var base64Cmd = defineCommand({
|
|
|
15767
15772
|
{ short: "i", long: "ignore-garbage" },
|
|
15768
15773
|
{ short: "w", long: "wrap", arg: true, default: "76" }
|
|
15769
15774
|
]);
|
|
15770
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
15775
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
15771
15776
|
for (const source of sources) {
|
|
15772
15777
|
if (args.has("decode")) {
|
|
15773
15778
|
const text2 = new TextDecoder().decode(source.bytes).replace(/\s+/g, "");
|
|
@@ -15779,14 +15784,14 @@ var base64Cmd = defineCommand({
|
|
|
15779
15784
|
continue;
|
|
15780
15785
|
}
|
|
15781
15786
|
const encoded = Buffer.from(source.bytes).toString("base64");
|
|
15782
|
-
const
|
|
15783
|
-
if (
|
|
15787
|
+
const wrap2 = args.num("wrap", 76);
|
|
15788
|
+
if (wrap2 <= 0) {
|
|
15784
15789
|
ctx.line(encoded);
|
|
15785
15790
|
continue;
|
|
15786
15791
|
}
|
|
15787
|
-
for (let i = 0; i < encoded.length; i +=
|
|
15792
|
+
for (let i = 0; i < encoded.length; i += wrap2) ctx.line(encoded.slice(i, i + wrap2));
|
|
15788
15793
|
}
|
|
15789
|
-
return
|
|
15794
|
+
return ok2 ? 0 : 1;
|
|
15790
15795
|
}
|
|
15791
15796
|
});
|
|
15792
15797
|
var base32Cmd = defineCommand({
|
|
@@ -15795,7 +15800,7 @@ var base32Cmd = defineCommand({
|
|
|
15795
15800
|
summary: "base32 encode/decode data",
|
|
15796
15801
|
async run(ctx) {
|
|
15797
15802
|
const args = parseArgs(ctx.args, [{ short: "d", long: "decode" }, { short: "w", long: "wrap", arg: true, default: "76" }]);
|
|
15798
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
15803
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
15799
15804
|
const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
15800
15805
|
for (const source of sources) {
|
|
15801
15806
|
if (args.has("decode")) {
|
|
@@ -15829,10 +15834,10 @@ var base32Cmd = defineCommand({
|
|
|
15829
15834
|
}
|
|
15830
15835
|
if (bits > 0) out += ALPHABET[value << 5 - bits & 31];
|
|
15831
15836
|
while (out.length % 8 !== 0) out += "=";
|
|
15832
|
-
const
|
|
15833
|
-
for (let i = 0; i < out.length; i +=
|
|
15837
|
+
const wrap2 = args.num("wrap", 76);
|
|
15838
|
+
for (let i = 0; i < out.length; i += wrap2) ctx.line(out.slice(i, i + wrap2));
|
|
15834
15839
|
}
|
|
15835
|
-
return
|
|
15840
|
+
return ok2 ? 0 : 1;
|
|
15836
15841
|
}
|
|
15837
15842
|
});
|
|
15838
15843
|
var uuidgen = defineCommand({
|
|
@@ -15896,6 +15901,9 @@ function parseUrl(raw) {
|
|
|
15896
15901
|
return null;
|
|
15897
15902
|
}
|
|
15898
15903
|
}
|
|
15904
|
+
function isBrowser() {
|
|
15905
|
+
return typeof process === "undefined" || process.versions?.node == null;
|
|
15906
|
+
}
|
|
15899
15907
|
async function performRequest(ctx, url, init) {
|
|
15900
15908
|
const isLocal = ctx.kernel.net.isLocal(url.hostname);
|
|
15901
15909
|
if (isLocal) {
|
|
@@ -15922,11 +15930,18 @@ async function performRequest(ctx, url, init) {
|
|
|
15922
15930
|
`outbound network access to ${url.hostname} is disabled for this container (enable with network: { allowOutbound: true })`
|
|
15923
15931
|
);
|
|
15924
15932
|
}
|
|
15925
|
-
|
|
15926
|
-
|
|
15927
|
-
|
|
15928
|
-
|
|
15929
|
-
|
|
15933
|
+
let response;
|
|
15934
|
+
try {
|
|
15935
|
+
response = await fetch(url.toString(), {
|
|
15936
|
+
method: init.method,
|
|
15937
|
+
headers: init.headers,
|
|
15938
|
+
...init.body ? { body: init.body.slice().buffer } : {}
|
|
15939
|
+
});
|
|
15940
|
+
} catch (error) {
|
|
15941
|
+
throw isBrowser() ? new Error(
|
|
15942
|
+
`${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.`
|
|
15943
|
+
) : error;
|
|
15944
|
+
}
|
|
15930
15945
|
const body = new Uint8Array(await response.arrayBuffer());
|
|
15931
15946
|
ctx.kernel.net.countRx(body.length);
|
|
15932
15947
|
const headers = {};
|
|
@@ -16905,7 +16920,7 @@ var less = defineCommand({
|
|
|
16905
16920
|
{ short: "X" },
|
|
16906
16921
|
{ short: "n" }
|
|
16907
16922
|
]);
|
|
16908
|
-
const { sources, ok } = await readInputs(ctx, args.positional);
|
|
16923
|
+
const { sources, ok: ok2 } = await readInputs(ctx, args.positional);
|
|
16909
16924
|
let lineNumber = 1;
|
|
16910
16925
|
for (const source of sources) {
|
|
16911
16926
|
if (!args.has("N")) {
|
|
@@ -16916,7 +16931,7 @@ var less = defineCommand({
|
|
|
16916
16931
|
ctx.line(`${String(lineNumber++).padStart(6)} ${line}`);
|
|
16917
16932
|
}
|
|
16918
16933
|
}
|
|
16919
|
-
return
|
|
16934
|
+
return ok2 ? 0 : 1;
|
|
16920
16935
|
}
|
|
16921
16936
|
});
|
|
16922
16937
|
var helpCmd = defineCommand({
|
|
@@ -17008,13 +17023,19 @@ ${stdinPath === null ? "" : `(function () {
|
|
|
17008
17023
|
}
|
|
17009
17024
|
async function execute(ctx, invocation) {
|
|
17010
17025
|
const { pod } = ctx.kernel;
|
|
17026
|
+
const interactive = ctx.stdin.interactive || ctx.stdin.isTTY;
|
|
17011
17027
|
let exitCode = 0;
|
|
17012
17028
|
try {
|
|
17013
17029
|
const proc = await pod.spawn("node", [invocation.script], {
|
|
17014
17030
|
cwd: ctx.cwd,
|
|
17015
17031
|
env: { ...ctx.env, PWD: ctx.cwd },
|
|
17016
17032
|
argv: ["/usr/bin/node", invocation.argvPath ?? invocation.script, ...invocation.argv],
|
|
17017
|
-
...invocation.stdinPath ? { stdinPath: invocation.stdinPath } : {}
|
|
17033
|
+
...invocation.stdinPath ? { stdinPath: invocation.stdinPath } : {},
|
|
17034
|
+
/* An interactive caller's input was not captured to a file, so the
|
|
17035
|
+
* program's stdin has to stay open and be fed as it arrives — and be
|
|
17036
|
+
* reported as a terminal, since that is what decides whether a CLI
|
|
17037
|
+
* prompts or takes its defaults. */
|
|
17038
|
+
...interactive ? { interactiveStdin: true, tty: true } : {}
|
|
17018
17039
|
});
|
|
17019
17040
|
proc.on("output", (chunk) => {
|
|
17020
17041
|
try {
|
|
@@ -17028,13 +17049,19 @@ async function execute(ctx, invocation) {
|
|
|
17028
17049
|
} catch {
|
|
17029
17050
|
}
|
|
17030
17051
|
});
|
|
17052
|
+
proc.on("rawmode", (enabled) => {
|
|
17053
|
+
ctx.stdin.rawMode = enabled;
|
|
17054
|
+
});
|
|
17031
17055
|
let forwarding = false;
|
|
17032
|
-
if (
|
|
17056
|
+
if (interactive) {
|
|
17033
17057
|
forwarding = true;
|
|
17034
17058
|
void (async () => {
|
|
17035
17059
|
while (forwarding) {
|
|
17036
17060
|
const chunk = await ctx.stdin.read();
|
|
17037
|
-
if (chunk === null)
|
|
17061
|
+
if (chunk === null) {
|
|
17062
|
+
proc.endInput?.();
|
|
17063
|
+
break;
|
|
17064
|
+
}
|
|
17038
17065
|
try {
|
|
17039
17066
|
proc.write(new TextDecoder().decode(chunk));
|
|
17040
17067
|
} catch {
|
|
@@ -17075,10 +17102,10 @@ async function execute(ctx, invocation) {
|
|
|
17075
17102
|
}
|
|
17076
17103
|
async function captureStdin(ctx) {
|
|
17077
17104
|
if (ctx.stdin.isTTY || ctx.stdin.interactive) return null;
|
|
17078
|
-
const
|
|
17079
|
-
if (
|
|
17105
|
+
const bytes2 = await ctx.stdin.readAll();
|
|
17106
|
+
if (bytes2.length === 0) return null;
|
|
17080
17107
|
const path = tempPath("stdin", ctx.proc.pid, ".dat");
|
|
17081
|
-
ctx.vfs.writeFile(path,
|
|
17108
|
+
ctx.vfs.writeFile(path, bytes2, { privileged: true, mode: 384 });
|
|
17082
17109
|
return path;
|
|
17083
17110
|
}
|
|
17084
17111
|
var node = defineCommand({
|
|
@@ -17213,8 +17240,8 @@ ${prelude}${source}
|
|
|
17213
17240
|
`;
|
|
17214
17241
|
}
|
|
17215
17242
|
function resolveScript(ctx, operand) {
|
|
17216
|
-
const
|
|
17217
|
-
const candidates = [
|
|
17243
|
+
const base2 = ctx.path(operand);
|
|
17244
|
+
const candidates = [base2, `${base2}.js`, `${base2}.mjs`, `${base2}.cjs`, `${base2}.json`];
|
|
17218
17245
|
for (const candidate of candidates) {
|
|
17219
17246
|
try {
|
|
17220
17247
|
const st = ctx.vfs.stat(candidate, { cred: ctx.cred });
|
|
@@ -17791,12 +17818,12 @@ async function runCPythonProgram(ctx, source, argv, scriptDir, stdinText) {
|
|
|
17791
17818
|
}
|
|
17792
17819
|
});
|
|
17793
17820
|
if (stdinText !== null) {
|
|
17794
|
-
const
|
|
17821
|
+
const bytes2 = encoder7.encode(stdinText);
|
|
17795
17822
|
let offset = 0;
|
|
17796
17823
|
py.setStdin({
|
|
17797
17824
|
read: (buffer) => {
|
|
17798
|
-
const take = Math.min(buffer.length,
|
|
17799
|
-
buffer.set(
|
|
17825
|
+
const take = Math.min(buffer.length, bytes2.length - offset);
|
|
17826
|
+
buffer.set(bytes2.subarray(offset, offset + take));
|
|
17800
17827
|
offset += take;
|
|
17801
17828
|
return take;
|
|
17802
17829
|
}
|
|
@@ -17938,8 +17965,8 @@ function configurePython(options = {}) {
|
|
|
17938
17965
|
var isPythonAvailable = isCPythonAvailable;
|
|
17939
17966
|
async function readStdin(ctx) {
|
|
17940
17967
|
if (ctx.stdin.isTTY || ctx.stdin.interactive) return null;
|
|
17941
|
-
const
|
|
17942
|
-
return
|
|
17968
|
+
const bytes2 = await ctx.stdin.readAll();
|
|
17969
|
+
return bytes2.length ? new TextDecoder().decode(bytes2) : null;
|
|
17943
17970
|
}
|
|
17944
17971
|
var python = defineCommand({
|
|
17945
17972
|
name: "python3",
|
|
@@ -18050,17 +18077,17 @@ async function loadFactory() {
|
|
|
18050
18077
|
}
|
|
18051
18078
|
const wasmPath = require2.resolve("@ffmpeg/core/wasm");
|
|
18052
18079
|
const wasm = await fs.readFile(wasmPath);
|
|
18053
|
-
const module = await
|
|
18080
|
+
const module = await nodeOnlyModule("@ffmpeg/core");
|
|
18054
18081
|
return { factory: module.default, wasm: new Uint8Array(wasm) };
|
|
18055
18082
|
}
|
|
18056
18083
|
function getCompiled() {
|
|
18057
18084
|
compiled ??= (async () => {
|
|
18058
18085
|
const { factory, wasm } = await loadFactory();
|
|
18059
|
-
const
|
|
18086
|
+
const bytes2 = wasm.buffer.slice(
|
|
18060
18087
|
wasm.byteOffset,
|
|
18061
18088
|
wasm.byteOffset + wasm.byteLength
|
|
18062
18089
|
);
|
|
18063
|
-
return { factory, module: await WebAssembly.compile(
|
|
18090
|
+
return { factory, module: await WebAssembly.compile(bytes2) };
|
|
18064
18091
|
})();
|
|
18065
18092
|
void compiled.catch(() => compiled = null);
|
|
18066
18093
|
return compiled;
|
|
@@ -18135,6 +18162,34 @@ var ffprobe = defineCommand({
|
|
|
18135
18162
|
function ffmpegCommands() {
|
|
18136
18163
|
return [ffmpeg, ffprobe];
|
|
18137
18164
|
}
|
|
18165
|
+
var platformBuffer = globalThis.Buffer;
|
|
18166
|
+
var Buffer2 = platformBuffer ?? addBase64UrlSupport(Buffer$1);
|
|
18167
|
+
function addBase64UrlSupport(BufferClass) {
|
|
18168
|
+
const target = BufferClass;
|
|
18169
|
+
if (target.__sandboxedBase64Url) return BufferClass;
|
|
18170
|
+
Object.defineProperty(target, "__sandboxedBase64Url", { value: true });
|
|
18171
|
+
const from = target.from.bind(target);
|
|
18172
|
+
target.from = (value, encodingOrOffset, length) => from(value, normalizeEncoding(encodingOrOffset), length);
|
|
18173
|
+
const byteLength = target.byteLength.bind(target);
|
|
18174
|
+
target.byteLength = (value, encoding) => byteLength(value, normalizeEncoding(encoding));
|
|
18175
|
+
const isEncoding = target.isEncoding?.bind(target);
|
|
18176
|
+
if (isEncoding) target.isEncoding = (encoding) => encoding.toLowerCase() === "base64url" || isEncoding(encoding);
|
|
18177
|
+
const toString = target.prototype.toString;
|
|
18178
|
+
target.prototype.toString = function(encoding, start2, end) {
|
|
18179
|
+
if (encoding?.toLowerCase() !== "base64url") return toString.call(this, encoding, start2, end);
|
|
18180
|
+
return toString.call(this, "base64", start2, end).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
18181
|
+
};
|
|
18182
|
+
const write = target.prototype.write;
|
|
18183
|
+
target.prototype.write = function(...args) {
|
|
18184
|
+
const index = typeof args[1] === "string" ? 1 : typeof args[2] === "string" ? 2 : 3;
|
|
18185
|
+
if (typeof args[index] === "string") args[index] = normalizeEncoding(args[index]);
|
|
18186
|
+
return write.apply(this, args);
|
|
18187
|
+
};
|
|
18188
|
+
return BufferClass;
|
|
18189
|
+
}
|
|
18190
|
+
function normalizeEncoding(value) {
|
|
18191
|
+
return typeof value === "string" && value.toLowerCase() === "base64url" ? "base64" : value;
|
|
18192
|
+
}
|
|
18138
18193
|
|
|
18139
18194
|
// src/pkg/clean-installer.ts
|
|
18140
18195
|
init_path();
|
|
@@ -18176,10 +18231,13 @@ var CleanPackageInstaller = class _CleanPackageInstaller {
|
|
|
18176
18231
|
const version = resolveVersion(metadata, range);
|
|
18177
18232
|
const manifest = metadata.versions[version];
|
|
18178
18233
|
if (!manifest) throw new Error(`No matching version found for ${name}@${range}`);
|
|
18234
|
+
if (!supportsPlatform(manifest)) {
|
|
18235
|
+
throw new Error(`${name}@${version} is not compatible with linux/x64/glibc`);
|
|
18236
|
+
}
|
|
18179
18237
|
const identity = `${name}@${version}`;
|
|
18180
18238
|
const target = join(modulesRoot, name);
|
|
18181
|
-
const
|
|
18182
|
-
if (
|
|
18239
|
+
const installed2 = this.tryReadJson(join(target, "package.json"));
|
|
18240
|
+
if (installed2?.version === version) return installed2;
|
|
18183
18241
|
if (ancestry.has(identity)) return manifest;
|
|
18184
18242
|
options.onProgress?.(`Fetching ${identity}`);
|
|
18185
18243
|
const archive = await this.getTarball(manifest.dist.tarball);
|
|
@@ -18270,9 +18328,18 @@ var CleanPackageInstaller = class _CleanPackageInstaller {
|
|
|
18270
18328
|
}
|
|
18271
18329
|
}
|
|
18272
18330
|
};
|
|
18331
|
+
function supportsPlatform(manifest) {
|
|
18332
|
+
return !manifest.main?.endsWith(".node") && platformListAllows(manifest.os, "linux") && platformListAllows(manifest.cpu, "x64") && platformListAllows(manifest.libc, "glibc");
|
|
18333
|
+
}
|
|
18334
|
+
function platformListAllows(values, current) {
|
|
18335
|
+
if (!values?.length) return true;
|
|
18336
|
+
if (values.includes(`!${current}`)) return false;
|
|
18337
|
+
const positive = values.filter((value) => !value.startsWith("!"));
|
|
18338
|
+
return positive.length === 0 || positive.includes(current) || positive.includes("any");
|
|
18339
|
+
}
|
|
18273
18340
|
function resolveVersion(metadata, range) {
|
|
18274
|
-
const
|
|
18275
|
-
if (
|
|
18341
|
+
const tag2 = metadata["dist-tags"]?.[range];
|
|
18342
|
+
if (tag2) return tag2;
|
|
18276
18343
|
if (valid(range) && metadata.versions[range]) return range;
|
|
18277
18344
|
const found = maxSatisfying(Object.keys(metadata.versions), range === "latest" ? "*" : range, { includePrerelease: false });
|
|
18278
18345
|
if (!found) throw new Error(`No matching version found for ${metadata.name}@${range}`);
|
|
@@ -18286,11 +18353,11 @@ function verifyIntegrity(data, integrity, shasum, identity) {
|
|
|
18286
18353
|
const algorithm = choice.slice(0, dash);
|
|
18287
18354
|
const expected = choice.slice(dash + 1).replace(/\?.*$/, "");
|
|
18288
18355
|
const digest = algorithm === "sha512" ? sha512(data) : algorithm === "sha256" ? sha256(data) : null;
|
|
18289
|
-
if (digest &&
|
|
18356
|
+
if (digest && Buffer2.from(digest).toString("base64") === expected) return;
|
|
18290
18357
|
}
|
|
18291
18358
|
throw new Error(`Integrity check failed for ${identity}`);
|
|
18292
18359
|
}
|
|
18293
|
-
if (shasum &&
|
|
18360
|
+
if (shasum && Buffer2.from(sha1(data)).toString("hex") === shasum) return;
|
|
18294
18361
|
if (shasum) throw new Error(`Legacy checksum check failed for ${identity}`);
|
|
18295
18362
|
}
|
|
18296
18363
|
function extractNpmTarball(volume, compressed, destination) {
|
|
@@ -18356,11 +18423,11 @@ function safeTarget(destination, name) {
|
|
|
18356
18423
|
function stripPackageRoot(name) {
|
|
18357
18424
|
return name.replace(/^\.\//, "").replace(/^package\//, "").replace(/\/$/, "");
|
|
18358
18425
|
}
|
|
18359
|
-
function text(
|
|
18360
|
-
return new TextDecoder().decode(
|
|
18426
|
+
function text(bytes2, start2, length) {
|
|
18427
|
+
return new TextDecoder().decode(bytes2.subarray(start2, start2 + length)).replace(/\0.*$/, "").trim();
|
|
18361
18428
|
}
|
|
18362
|
-
function octal(
|
|
18363
|
-
return parseInt(text(
|
|
18429
|
+
function octal(bytes2, start2, length) {
|
|
18430
|
+
return parseInt(text(bytes2, start2, length).replace(/^0+/, "") || "0", 8);
|
|
18364
18431
|
}
|
|
18365
18432
|
function parsePax(data) {
|
|
18366
18433
|
const value = new TextDecoder().decode(data);
|
|
@@ -18372,8 +18439,8 @@ function parsePax(data) {
|
|
|
18372
18439
|
const length = Number(value.slice(offset, space));
|
|
18373
18440
|
if (!Number.isFinite(length) || length <= 0) break;
|
|
18374
18441
|
const record = value.slice(space + 1, offset + length - 1);
|
|
18375
|
-
const
|
|
18376
|
-
if (
|
|
18442
|
+
const equal2 = record.indexOf("=");
|
|
18443
|
+
if (equal2 > 0) result[record.slice(0, equal2)] = record.slice(equal2 + 1);
|
|
18377
18444
|
offset += length;
|
|
18378
18445
|
}
|
|
18379
18446
|
return result;
|
|
@@ -18947,6 +19014,13 @@ function findLocalBin(ctx, name) {
|
|
|
18947
19014
|
}
|
|
18948
19015
|
async function runInitializer(ctx, args) {
|
|
18949
19016
|
const [spec, ...rest] = args;
|
|
19017
|
+
if (!spec) {
|
|
19018
|
+
ctx.warn("npm create <initializer>");
|
|
19019
|
+
ctx.warn("");
|
|
19020
|
+
ctx.warn("Runs the package `create-<initializer>`, installing it if needed.");
|
|
19021
|
+
ctx.warn("Example: npm create vite@latest my-app");
|
|
19022
|
+
return 1;
|
|
19023
|
+
}
|
|
18950
19024
|
const { name, version } = splitPackageSpec(spec);
|
|
18951
19025
|
const suffix = version ? `@${version}` : "";
|
|
18952
19026
|
let packageName;
|
|
@@ -19049,12 +19123,12 @@ unless the container was created with network: { allowOutbound: true }.`,
|
|
|
19049
19123
|
}
|
|
19050
19124
|
ctx.stderr.write(`npx: installing ${packageSpec}...
|
|
19051
19125
|
`);
|
|
19052
|
-
const
|
|
19126
|
+
const installed2 = await installPackages(ctx, [packageSpec], {
|
|
19053
19127
|
cwd: root,
|
|
19054
19128
|
save: false,
|
|
19055
19129
|
quiet: true
|
|
19056
19130
|
});
|
|
19057
|
-
if (
|
|
19131
|
+
if (installed2 !== 0) return installed2;
|
|
19058
19132
|
if (!findLocalBin(ctx, command)) {
|
|
19059
19133
|
const binaries = packageBinaries(ctx, root, packageName);
|
|
19060
19134
|
const chosen = binaries.includes(command) ? command : binaries[0];
|
|
@@ -19283,8 +19357,8 @@ var ContainerFs = class {
|
|
|
19283
19357
|
return this.kernel.vfs;
|
|
19284
19358
|
}
|
|
19285
19359
|
async readFile(path, encoding) {
|
|
19286
|
-
const
|
|
19287
|
-
return encoding ? new TextDecoder().decode(
|
|
19360
|
+
const bytes2 = this.vfs.readFile(clean(path));
|
|
19361
|
+
return encoding ? new TextDecoder().decode(bytes2) : bytes2;
|
|
19288
19362
|
}
|
|
19289
19363
|
async writeFile(path, data, opts = {}) {
|
|
19290
19364
|
const abs = clean(path);
|
|
@@ -20032,6 +20106,18 @@ var CommonJsEngine = class {
|
|
|
20032
20106
|
main = null;
|
|
20033
20107
|
/** `package.json` per directory; resolution reads them constantly. */
|
|
20034
20108
|
manifests = /* @__PURE__ */ new Map();
|
|
20109
|
+
evaluationDepth = 0;
|
|
20110
|
+
/**
|
|
20111
|
+
* Is a module body running synchronously right now?
|
|
20112
|
+
*
|
|
20113
|
+
* `process.exit` unwinds by throwing, and that is only safe while one of
|
|
20114
|
+
* this engine's own frames is on the stack to catch it. Thrown from a later
|
|
20115
|
+
* callback — a stream handler, a timer — it would escape into whichever
|
|
20116
|
+
* library called that callback and surface as an unrelated crash.
|
|
20117
|
+
*/
|
|
20118
|
+
get isEvaluating() {
|
|
20119
|
+
return this.evaluationDepth > 0;
|
|
20120
|
+
}
|
|
20035
20121
|
/**
|
|
20036
20122
|
* Evaluate an entry point.
|
|
20037
20123
|
*
|
|
@@ -20137,7 +20223,13 @@ ${code}
|
|
|
20137
20223
|
};
|
|
20138
20224
|
//# sourceURL=sandboxedjs:${module.filename}`
|
|
20139
20225
|
)(this.globals);
|
|
20140
|
-
|
|
20226
|
+
this.evaluationDepth++;
|
|
20227
|
+
let result;
|
|
20228
|
+
try {
|
|
20229
|
+
result = factory(...bindings.map(([, value]) => value));
|
|
20230
|
+
} finally {
|
|
20231
|
+
this.evaluationDepth--;
|
|
20232
|
+
}
|
|
20141
20233
|
if (transformed?.topLevelAwait) module.pending = Promise.resolve(result).then(() => {
|
|
20142
20234
|
});
|
|
20143
20235
|
}
|
|
@@ -20434,9 +20526,717 @@ function splitSpecifier(specifier) {
|
|
|
20434
20526
|
return { name: parts.slice(0, size).join("/"), subpath: parts.slice(size).join("/") };
|
|
20435
20527
|
}
|
|
20436
20528
|
|
|
20529
|
+
// src/runtime/util-module.ts
|
|
20530
|
+
var customInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
20531
|
+
var promisifyCustom = /* @__PURE__ */ Symbol.for("nodejs.util.promisify.custom");
|
|
20532
|
+
var BREAK_LENGTH = 72;
|
|
20533
|
+
var MAX_ARRAY = 100;
|
|
20534
|
+
function inspect(value, options = {}) {
|
|
20535
|
+
const depth = options.depth === null ? Infinity : options.depth ?? 2;
|
|
20536
|
+
return render(value, depth, /* @__PURE__ */ new Set(), options);
|
|
20537
|
+
}
|
|
20538
|
+
function render(value, depth, seen, options) {
|
|
20539
|
+
switch (typeof value) {
|
|
20540
|
+
case "string":
|
|
20541
|
+
return quote2(value, options.maxStringLength ?? null);
|
|
20542
|
+
case "number":
|
|
20543
|
+
return Object.is(value, -0) ? "-0" : String(value);
|
|
20544
|
+
case "bigint":
|
|
20545
|
+
return `${value}n`;
|
|
20546
|
+
case "boolean":
|
|
20547
|
+
case "undefined":
|
|
20548
|
+
return String(value);
|
|
20549
|
+
case "symbol":
|
|
20550
|
+
return value.toString();
|
|
20551
|
+
case "function":
|
|
20552
|
+
return renderFunction(value);
|
|
20553
|
+
}
|
|
20554
|
+
if (value === null) return "null";
|
|
20555
|
+
const object = value;
|
|
20556
|
+
const custom = object[customInspect];
|
|
20557
|
+
if (typeof custom === "function") {
|
|
20558
|
+
return String(custom.call(object, depth, options));
|
|
20559
|
+
}
|
|
20560
|
+
if (seen.has(object)) return "[Circular *1]";
|
|
20561
|
+
if (depth < 0) return Array.isArray(object) ? "[Array]" : "[Object]";
|
|
20562
|
+
if (value instanceof Error) return renderError(value);
|
|
20563
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
|
|
20564
|
+
if (value instanceof RegExp) return String(value);
|
|
20565
|
+
if (Buffer2.isBuffer(value)) return renderBuffer(value);
|
|
20566
|
+
if (ArrayBuffer.isView(value)) return renderTypedArray(value);
|
|
20567
|
+
seen.add(object);
|
|
20568
|
+
try {
|
|
20569
|
+
if (Array.isArray(value)) return wrap(renderArray(value, depth, seen, options), "[", "]");
|
|
20570
|
+
if (value instanceof Map) return prefixed("Map", value.size, renderMap(value, depth, seen, options));
|
|
20571
|
+
if (value instanceof Set) return prefixed("Set", value.size, renderSet(value, depth, seen, options));
|
|
20572
|
+
if (value instanceof Promise) return "Promise { <pending> }";
|
|
20573
|
+
return renderObject(object, depth, seen, options);
|
|
20574
|
+
} finally {
|
|
20575
|
+
seen.delete(object);
|
|
20576
|
+
}
|
|
20577
|
+
}
|
|
20578
|
+
function renderArray(value, depth, seen, options) {
|
|
20579
|
+
const limit = options.maxArrayLength === null ? Infinity : options.maxArrayLength ?? MAX_ARRAY;
|
|
20580
|
+
const shown = value.slice(0, limit).map((item) => render(item, depth - 1, seen, options));
|
|
20581
|
+
const hidden = value.length - shown.length;
|
|
20582
|
+
if (hidden > 0) shown.push(`... ${hidden} more item${hidden === 1 ? "" : "s"}`);
|
|
20583
|
+
return shown;
|
|
20584
|
+
}
|
|
20585
|
+
function renderMap(value, depth, seen, options) {
|
|
20586
|
+
return [...value].map(
|
|
20587
|
+
([key, item]) => `${render(key, depth - 1, seen, options)} => ${render(item, depth - 1, seen, options)}`
|
|
20588
|
+
);
|
|
20589
|
+
}
|
|
20590
|
+
function renderSet(value, depth, seen, options) {
|
|
20591
|
+
return [...value].map((item) => render(item, depth - 1, seen, options));
|
|
20592
|
+
}
|
|
20593
|
+
function renderObject(object, depth, seen, options) {
|
|
20594
|
+
const keys = options.showHidden ? Object.getOwnPropertyNames(object) : Object.keys(object);
|
|
20595
|
+
if (options.sorted) keys.sort();
|
|
20596
|
+
const parts = keys.map((key) => {
|
|
20597
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
20598
|
+
const rendered = descriptor?.get ? descriptor.set ? "[Getter/Setter]" : "[Getter]" : render(object[key], depth - 1, seen, options);
|
|
20599
|
+
return `${propertyKey(key)}: ${rendered}`;
|
|
20600
|
+
});
|
|
20601
|
+
const name = constructorName(object);
|
|
20602
|
+
return wrap(parts, name ? `${name} {` : "{", "}", name ? void 0 : "{}");
|
|
20603
|
+
}
|
|
20604
|
+
function constructorName(object) {
|
|
20605
|
+
const name = Object.getPrototypeOf(object)?.constructor?.name;
|
|
20606
|
+
if (!name || name === "Object") return null;
|
|
20607
|
+
return name;
|
|
20608
|
+
}
|
|
20609
|
+
function renderError(error) {
|
|
20610
|
+
const base2 = error.stack ?? `${error.name}: ${error.message}`;
|
|
20611
|
+
const extra = Object.keys(error).filter((key) => key !== "message" && key !== "stack");
|
|
20612
|
+
if (extra.length === 0) return base2;
|
|
20613
|
+
return `${base2} { ${extra.map((key) => `${propertyKey(key)}: ${inspect(error[key], { depth: 0 })}`).join(", ")} }`;
|
|
20614
|
+
}
|
|
20615
|
+
function renderFunction(value) {
|
|
20616
|
+
const kind = /^class[\s{]/.test(Function.prototype.toString.call(value)) ? "class" : "Function";
|
|
20617
|
+
return value.name ? `[${kind}: ${value.name}]` : `[${kind} (anonymous)]`;
|
|
20618
|
+
}
|
|
20619
|
+
function renderBuffer(value) {
|
|
20620
|
+
const shown = [...value.subarray(0, 50)].map((byte) => byte.toString(16).padStart(2, "0"));
|
|
20621
|
+
const hidden = value.length - shown.length;
|
|
20622
|
+
const tail2 = hidden > 0 ? ` ... ${hidden} more byte${hidden === 1 ? "" : "s"}` : "";
|
|
20623
|
+
return `<Buffer ${shown.join(" ")}${tail2}>`;
|
|
20624
|
+
}
|
|
20625
|
+
function renderTypedArray(value) {
|
|
20626
|
+
const name = value.constructor?.name ?? "TypedArray";
|
|
20627
|
+
const items = [...value].slice(0, MAX_ARRAY);
|
|
20628
|
+
return `${name}(${value.length}) [ ${items.join(", ")} ]`;
|
|
20629
|
+
}
|
|
20630
|
+
function prefixed(name, size, parts) {
|
|
20631
|
+
return wrap(parts, `${name}(${size}) {`, "}", `${name}(0) {}`);
|
|
20632
|
+
}
|
|
20633
|
+
function wrap(parts, open, close, empty) {
|
|
20634
|
+
if (parts.length === 0) return empty ?? `${open}${close}`;
|
|
20635
|
+
const inline = `${open} ${parts.join(", ")} ${close}`;
|
|
20636
|
+
if (inline.length <= BREAK_LENGTH && !inline.includes("\n")) return inline;
|
|
20637
|
+
const indented = parts.map((part) => ` ${part.split("\n").join("\n ")}`);
|
|
20638
|
+
return `${open}
|
|
20639
|
+
${indented.join(",\n")}
|
|
20640
|
+
${close}`;
|
|
20641
|
+
}
|
|
20642
|
+
function quote2(value, maxLength) {
|
|
20643
|
+
let text2 = value;
|
|
20644
|
+
let tail2 = "";
|
|
20645
|
+
if (maxLength !== null && text2.length > maxLength) {
|
|
20646
|
+
tail2 = `... ${text2.length - maxLength} more character${text2.length - maxLength === 1 ? "" : "s"}`;
|
|
20647
|
+
text2 = text2.slice(0, maxLength);
|
|
20648
|
+
}
|
|
20649
|
+
const escaped = text2.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/'/g, "\\'");
|
|
20650
|
+
return `'${escaped}'${tail2}`;
|
|
20651
|
+
}
|
|
20652
|
+
function propertyKey(key) {
|
|
20653
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : quote2(key, null);
|
|
20654
|
+
}
|
|
20655
|
+
function format(...args) {
|
|
20656
|
+
return formatWithOptions({}, ...args);
|
|
20657
|
+
}
|
|
20658
|
+
function formatWithOptions(options, ...args) {
|
|
20659
|
+
const [first, ...rest] = args;
|
|
20660
|
+
const pieces = [];
|
|
20661
|
+
let index = 0;
|
|
20662
|
+
if (typeof first === "string" && first.includes("%")) {
|
|
20663
|
+
pieces.push(
|
|
20664
|
+
first.replace(/%([sdifjoOc%])/g, (match2, kind) => {
|
|
20665
|
+
if (kind === "%") return "%";
|
|
20666
|
+
if (index >= rest.length) return match2;
|
|
20667
|
+
const value = rest[index++];
|
|
20668
|
+
switch (kind) {
|
|
20669
|
+
case "s":
|
|
20670
|
+
return typeof value === "string" ? value : typeof value === "bigint" ? `${value}n` : typeof value === "object" && value !== null ? inspect(value, { ...options, depth: 0 }) : String(value);
|
|
20671
|
+
case "d":
|
|
20672
|
+
return typeof value === "bigint" ? `${value}n` : String(Number(value));
|
|
20673
|
+
case "i":
|
|
20674
|
+
return typeof value === "bigint" ? `${value}n` : String(parseInt(String(value), 10));
|
|
20675
|
+
case "f":
|
|
20676
|
+
return String(parseFloat(String(value)));
|
|
20677
|
+
case "j":
|
|
20678
|
+
try {
|
|
20679
|
+
return JSON.stringify(value) ?? "undefined";
|
|
20680
|
+
} catch {
|
|
20681
|
+
return "[Circular]";
|
|
20682
|
+
}
|
|
20683
|
+
case "o":
|
|
20684
|
+
return inspect(value, { ...options, showHidden: true, depth: 4 });
|
|
20685
|
+
case "O":
|
|
20686
|
+
return inspect(value, options);
|
|
20687
|
+
case "c":
|
|
20688
|
+
return "";
|
|
20689
|
+
default:
|
|
20690
|
+
return match2;
|
|
20691
|
+
}
|
|
20692
|
+
})
|
|
20693
|
+
);
|
|
20694
|
+
} else if (first !== void 0 || args.length > 0) {
|
|
20695
|
+
pieces.push(typeof first === "string" ? first : inspect(first, options));
|
|
20696
|
+
}
|
|
20697
|
+
for (; index < rest.length; index++) {
|
|
20698
|
+
const value = rest[index];
|
|
20699
|
+
pieces.push(typeof value === "string" ? value : inspect(value, options));
|
|
20700
|
+
}
|
|
20701
|
+
return pieces.join(" ");
|
|
20702
|
+
}
|
|
20703
|
+
function promisify(original) {
|
|
20704
|
+
if (typeof original !== "function") {
|
|
20705
|
+
throw Object.assign(new TypeError('The "original" argument must be of type function'), {
|
|
20706
|
+
code: "ERR_INVALID_ARG_TYPE"
|
|
20707
|
+
});
|
|
20708
|
+
}
|
|
20709
|
+
const override = original[promisifyCustom];
|
|
20710
|
+
if (typeof override === "function") return override;
|
|
20711
|
+
const wrapped = function(...args) {
|
|
20712
|
+
return new Promise((resolve2, reject) => {
|
|
20713
|
+
original.call(this, ...args, (error, ...values) => {
|
|
20714
|
+
if (error) reject(error);
|
|
20715
|
+
else resolve2(values.length > 1 ? values : values[0]);
|
|
20716
|
+
});
|
|
20717
|
+
});
|
|
20718
|
+
};
|
|
20719
|
+
Object.setPrototypeOf(wrapped, Object.getPrototypeOf(original));
|
|
20720
|
+
Object.defineProperty(wrapped, "name", { value: original.name, configurable: true });
|
|
20721
|
+
return wrapped;
|
|
20722
|
+
}
|
|
20723
|
+
promisify.custom = promisifyCustom;
|
|
20724
|
+
function callbackify(original) {
|
|
20725
|
+
return function(...args) {
|
|
20726
|
+
const callback = args.pop();
|
|
20727
|
+
Promise.resolve(original.apply(this, args)).then(
|
|
20728
|
+
(value) => callback(null, value),
|
|
20729
|
+
/* Node guarantees a truthy first argument, so a rejection with a falsy
|
|
20730
|
+
* reason is wrapped rather than passed through as "no error". */
|
|
20731
|
+
(reason) => callback(reason ?? Object.assign(new Error("Promise was rejected with a falsy value"), { reason }))
|
|
20732
|
+
);
|
|
20733
|
+
};
|
|
20734
|
+
}
|
|
20735
|
+
function inherits(constructor, superConstructor) {
|
|
20736
|
+
Object.defineProperty(constructor, "super_", {
|
|
20737
|
+
value: superConstructor,
|
|
20738
|
+
writable: true,
|
|
20739
|
+
configurable: true
|
|
20740
|
+
});
|
|
20741
|
+
Object.setPrototypeOf(constructor.prototype, superConstructor.prototype);
|
|
20742
|
+
}
|
|
20743
|
+
function deprecate(fn, message) {
|
|
20744
|
+
let warned = false;
|
|
20745
|
+
return function(...args) {
|
|
20746
|
+
if (!warned) {
|
|
20747
|
+
warned = true;
|
|
20748
|
+
console.warn(`DeprecationWarning: ${message}`);
|
|
20749
|
+
}
|
|
20750
|
+
return fn.apply(this, args);
|
|
20751
|
+
};
|
|
20752
|
+
}
|
|
20753
|
+
function debuglog(section, callback) {
|
|
20754
|
+
const noop = Object.assign(() => {
|
|
20755
|
+
}, { enabled: false });
|
|
20756
|
+
callback?.(noop);
|
|
20757
|
+
return noop;
|
|
20758
|
+
}
|
|
20759
|
+
var STYLES = {
|
|
20760
|
+
reset: [0, 0],
|
|
20761
|
+
bold: [1, 22],
|
|
20762
|
+
dim: [2, 22],
|
|
20763
|
+
italic: [3, 23],
|
|
20764
|
+
underline: [4, 24],
|
|
20765
|
+
blink: [5, 25],
|
|
20766
|
+
inverse: [7, 27],
|
|
20767
|
+
hidden: [8, 28],
|
|
20768
|
+
strikethrough: [9, 29],
|
|
20769
|
+
doubleunderline: [21, 24],
|
|
20770
|
+
framed: [51, 54],
|
|
20771
|
+
overlined: [53, 55],
|
|
20772
|
+
black: [30, 39],
|
|
20773
|
+
red: [31, 39],
|
|
20774
|
+
green: [32, 39],
|
|
20775
|
+
yellow: [33, 39],
|
|
20776
|
+
blue: [34, 39],
|
|
20777
|
+
magenta: [35, 39],
|
|
20778
|
+
cyan: [36, 39],
|
|
20779
|
+
white: [37, 39],
|
|
20780
|
+
gray: [90, 39],
|
|
20781
|
+
grey: [90, 39],
|
|
20782
|
+
blackBright: [90, 39],
|
|
20783
|
+
redBright: [91, 39],
|
|
20784
|
+
greenBright: [92, 39],
|
|
20785
|
+
yellowBright: [93, 39],
|
|
20786
|
+
blueBright: [94, 39],
|
|
20787
|
+
magentaBright: [95, 39],
|
|
20788
|
+
cyanBright: [96, 39],
|
|
20789
|
+
whiteBright: [97, 39],
|
|
20790
|
+
bgBlack: [40, 49],
|
|
20791
|
+
bgRed: [41, 49],
|
|
20792
|
+
bgGreen: [42, 49],
|
|
20793
|
+
bgYellow: [43, 49],
|
|
20794
|
+
bgBlue: [44, 49],
|
|
20795
|
+
bgMagenta: [45, 49],
|
|
20796
|
+
bgCyan: [46, 49],
|
|
20797
|
+
bgWhite: [47, 49],
|
|
20798
|
+
bgGray: [100, 49],
|
|
20799
|
+
bgGrey: [100, 49],
|
|
20800
|
+
bgBlackBright: [100, 49],
|
|
20801
|
+
bgRedBright: [101, 49],
|
|
20802
|
+
bgGreenBright: [102, 49],
|
|
20803
|
+
bgYellowBright: [103, 49],
|
|
20804
|
+
bgBlueBright: [104, 49],
|
|
20805
|
+
bgMagentaBright: [105, 49],
|
|
20806
|
+
bgCyanBright: [106, 49],
|
|
20807
|
+
bgWhiteBright: [107, 49]
|
|
20808
|
+
};
|
|
20809
|
+
function styleText(format3, text2) {
|
|
20810
|
+
const names = Array.isArray(format3) ? format3 : [format3];
|
|
20811
|
+
let open = "";
|
|
20812
|
+
let close = "";
|
|
20813
|
+
for (const name of names) {
|
|
20814
|
+
const style = STYLES[name];
|
|
20815
|
+
if (!style) {
|
|
20816
|
+
throw Object.assign(new TypeError(`The value "${name}" is invalid for argument 'format'`), {
|
|
20817
|
+
code: "ERR_INVALID_ARG_VALUE"
|
|
20818
|
+
});
|
|
20819
|
+
}
|
|
20820
|
+
open += `\x1B[${style[0]}m`;
|
|
20821
|
+
close = `\x1B[${style[1]}m${close}`;
|
|
20822
|
+
}
|
|
20823
|
+
return `${open}${text2}${close}`;
|
|
20824
|
+
}
|
|
20825
|
+
var tag = (value) => Object.prototype.toString.call(value).slice(8, -1);
|
|
20826
|
+
var types = {
|
|
20827
|
+
isPromise: (value) => value instanceof Promise || tag(value) === "Promise",
|
|
20828
|
+
isDate: (value) => tag(value) === "Date",
|
|
20829
|
+
isRegExp: (value) => tag(value) === "RegExp",
|
|
20830
|
+
isMap: (value) => tag(value) === "Map",
|
|
20831
|
+
isSet: (value) => tag(value) === "Set",
|
|
20832
|
+
isTypedArray: (value) => ArrayBuffer.isView(value) && !(value instanceof DataView),
|
|
20833
|
+
isUint8Array: (value) => value instanceof Uint8Array,
|
|
20834
|
+
isArrayBuffer: (value) => tag(value) === "ArrayBuffer",
|
|
20835
|
+
isArrayBufferView: (value) => ArrayBuffer.isView(value),
|
|
20836
|
+
isDataView: (value) => value instanceof DataView,
|
|
20837
|
+
isNativeError: (value) => value instanceof Error,
|
|
20838
|
+
isProxy: () => false,
|
|
20839
|
+
isAsyncFunction: (value) => tag(value) === "AsyncFunction",
|
|
20840
|
+
isGeneratorFunction: (value) => tag(value) === "GeneratorFunction",
|
|
20841
|
+
isBoxedPrimitive: (value) => ["String", "Number", "Boolean", "Symbol", "BigInt"].includes(tag(value)) && typeof value === "object"
|
|
20842
|
+
};
|
|
20843
|
+
function isDeepStrictEqual(a, b) {
|
|
20844
|
+
if (Object.is(a, b)) return true;
|
|
20845
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
20846
|
+
if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false;
|
|
20847
|
+
if (Array.isArray(a)) {
|
|
20848
|
+
const other = b;
|
|
20849
|
+
return a.length === other.length && a.every((item, index) => isDeepStrictEqual(item, other[index]));
|
|
20850
|
+
}
|
|
20851
|
+
if (a instanceof Date) return a.getTime() === b.getTime();
|
|
20852
|
+
if (a instanceof RegExp) return String(a) === String(b);
|
|
20853
|
+
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
|
|
20854
|
+
const left = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
20855
|
+
const right = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
|
|
20856
|
+
return left.length === right.length && left.every((byte, index) => byte === right[index]);
|
|
20857
|
+
}
|
|
20858
|
+
const keys = Object.keys(a);
|
|
20859
|
+
if (keys.length !== Object.keys(b).length) return false;
|
|
20860
|
+
return keys.every(
|
|
20861
|
+
(key) => Object.prototype.hasOwnProperty.call(b, key) && isDeepStrictEqual(a[key], b[key])
|
|
20862
|
+
);
|
|
20863
|
+
}
|
|
20864
|
+
var legacy = {
|
|
20865
|
+
isArray: Array.isArray,
|
|
20866
|
+
isBoolean: (value) => typeof value === "boolean",
|
|
20867
|
+
isNull: (value) => value === null,
|
|
20868
|
+
isNullOrUndefined: (value) => value == null,
|
|
20869
|
+
isNumber: (value) => typeof value === "number",
|
|
20870
|
+
isString: (value) => typeof value === "string",
|
|
20871
|
+
isSymbol: (value) => typeof value === "symbol",
|
|
20872
|
+
isUndefined: (value) => value === void 0,
|
|
20873
|
+
isRegExp: types.isRegExp,
|
|
20874
|
+
isObject: (value) => typeof value === "object" && value !== null,
|
|
20875
|
+
isDate: types.isDate,
|
|
20876
|
+
isError: types.isNativeError,
|
|
20877
|
+
isFunction: (value) => typeof value === "function",
|
|
20878
|
+
isPrimitive: (value) => value === null || typeof value !== "object" && typeof value !== "function",
|
|
20879
|
+
isBuffer: (value) => Buffer2.isBuffer(value)
|
|
20880
|
+
};
|
|
20881
|
+
inspect.custom = customInspect;
|
|
20882
|
+
var utilModule = {
|
|
20883
|
+
format,
|
|
20884
|
+
formatWithOptions,
|
|
20885
|
+
inspect,
|
|
20886
|
+
styleText,
|
|
20887
|
+
promisify,
|
|
20888
|
+
callbackify,
|
|
20889
|
+
inherits,
|
|
20890
|
+
deprecate,
|
|
20891
|
+
debuglog,
|
|
20892
|
+
debug: debuglog,
|
|
20893
|
+
types,
|
|
20894
|
+
isDeepStrictEqual,
|
|
20895
|
+
TextEncoder,
|
|
20896
|
+
TextDecoder,
|
|
20897
|
+
toUSVString: (value) => String(value),
|
|
20898
|
+
stripVTControlCharacters: (value) => value.replace(/\x1B\[[0-9;]*[A-Za-z]/g, ""),
|
|
20899
|
+
...legacy
|
|
20900
|
+
};
|
|
20901
|
+
var util_module_default = utilModule;
|
|
20902
|
+
|
|
20903
|
+
// src/runtime/assert-module.ts
|
|
20904
|
+
var AssertionError = class extends Error {
|
|
20905
|
+
actual;
|
|
20906
|
+
expected;
|
|
20907
|
+
operator;
|
|
20908
|
+
generatedMessage;
|
|
20909
|
+
name = "AssertionError";
|
|
20910
|
+
code = "ERR_ASSERTION";
|
|
20911
|
+
constructor(options) {
|
|
20912
|
+
const generated = options.message === void 0;
|
|
20913
|
+
super(options.message ?? describe(options.actual, options.expected, options.operator));
|
|
20914
|
+
this.actual = options.actual;
|
|
20915
|
+
this.expected = options.expected;
|
|
20916
|
+
this.operator = options.operator;
|
|
20917
|
+
this.generatedMessage = generated;
|
|
20918
|
+
}
|
|
20919
|
+
};
|
|
20920
|
+
function describe(actual, expected, operator) {
|
|
20921
|
+
if (operator === "fail") return "Failed";
|
|
20922
|
+
const rendered = (value) => inspect(value, { depth: 2 });
|
|
20923
|
+
return `${rendered(actual)} ${operator} ${rendered(expected)}`;
|
|
20924
|
+
}
|
|
20925
|
+
function fail(actual, expected, message, operator) {
|
|
20926
|
+
if (message instanceof Error) throw message;
|
|
20927
|
+
throw new AssertionError({ actual, expected, operator, ...message === void 0 ? {} : { message } });
|
|
20928
|
+
}
|
|
20929
|
+
function ok(value, message) {
|
|
20930
|
+
if (!value) fail(value, true, message, "==");
|
|
20931
|
+
}
|
|
20932
|
+
var equal = (actual, expected, message) => {
|
|
20933
|
+
if (actual != expected) fail(actual, expected, message, "==");
|
|
20934
|
+
};
|
|
20935
|
+
var notEqual = (actual, expected, message) => {
|
|
20936
|
+
if (actual == expected) fail(actual, expected, message, "!=");
|
|
20937
|
+
};
|
|
20938
|
+
var strictEqual = (actual, expected, message) => {
|
|
20939
|
+
if (!Object.is(actual, expected)) fail(actual, expected, message, "strictEqual");
|
|
20940
|
+
};
|
|
20941
|
+
var notStrictEqual = (actual, expected, message) => {
|
|
20942
|
+
if (Object.is(actual, expected)) fail(actual, expected, message, "notStrictEqual");
|
|
20943
|
+
};
|
|
20944
|
+
var deepStrictEqual = (actual, expected, message) => {
|
|
20945
|
+
if (!isDeepStrictEqual(actual, expected)) fail(actual, expected, message, "deepStrictEqual");
|
|
20946
|
+
};
|
|
20947
|
+
var notDeepStrictEqual = (actual, expected, message) => {
|
|
20948
|
+
if (isDeepStrictEqual(actual, expected)) fail(actual, expected, message, "notDeepStrictEqual");
|
|
20949
|
+
};
|
|
20950
|
+
function looseDeepEqual(a, b) {
|
|
20951
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
|
|
20952
|
+
return a == b;
|
|
20953
|
+
}
|
|
20954
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
20955
|
+
const keys = Object.keys(a);
|
|
20956
|
+
if (keys.length !== Object.keys(b).length) return false;
|
|
20957
|
+
return keys.every(
|
|
20958
|
+
(key) => looseDeepEqual(a[key], b[key])
|
|
20959
|
+
);
|
|
20960
|
+
}
|
|
20961
|
+
var deepEqual = (actual, expected, message) => {
|
|
20962
|
+
if (!looseDeepEqual(actual, expected)) fail(actual, expected, message, "deepEqual");
|
|
20963
|
+
};
|
|
20964
|
+
var notDeepEqual = (actual, expected, message) => {
|
|
20965
|
+
if (looseDeepEqual(actual, expected)) fail(actual, expected, message, "notDeepEqual");
|
|
20966
|
+
};
|
|
20967
|
+
function matches2(error, expected) {
|
|
20968
|
+
if (expected === void 0) return true;
|
|
20969
|
+
if (expected instanceof RegExp) return expected.test(String(error));
|
|
20970
|
+
if (typeof expected === "function") {
|
|
20971
|
+
if (error instanceof expected) return true;
|
|
20972
|
+
try {
|
|
20973
|
+
return Boolean(expected(error));
|
|
20974
|
+
} catch {
|
|
20975
|
+
return false;
|
|
20976
|
+
}
|
|
20977
|
+
}
|
|
20978
|
+
if (typeof expected === "object" && expected !== null) {
|
|
20979
|
+
return Object.entries(expected).every(
|
|
20980
|
+
([key, value]) => isDeepStrictEqual(error?.[key], value)
|
|
20981
|
+
);
|
|
20982
|
+
}
|
|
20983
|
+
return String(error) === String(expected);
|
|
20984
|
+
}
|
|
20985
|
+
function throws(block, expected, message) {
|
|
20986
|
+
const [error, threw] = capture(block);
|
|
20987
|
+
if (!threw) fail(void 0, expected, message ?? "Missing expected exception.", "throws");
|
|
20988
|
+
if (!matches2(error, expected)) throw error;
|
|
20989
|
+
}
|
|
20990
|
+
function doesNotThrow(block, expected, message) {
|
|
20991
|
+
const [error, threw] = capture(block);
|
|
20992
|
+
if (!threw) return;
|
|
20993
|
+
if (matches2(error, expected)) {
|
|
20994
|
+
fail(error, expected, message ?? "Got unwanted exception.", "doesNotThrow");
|
|
20995
|
+
}
|
|
20996
|
+
throw error;
|
|
20997
|
+
}
|
|
20998
|
+
async function rejects(block, expected, message) {
|
|
20999
|
+
const [error, threw] = await captureAsync(block);
|
|
21000
|
+
if (!threw) fail(void 0, expected, message ?? "Missing expected rejection.", "rejects");
|
|
21001
|
+
if (!matches2(error, expected)) throw error;
|
|
21002
|
+
}
|
|
21003
|
+
async function doesNotReject(block, expected, message) {
|
|
21004
|
+
const [error, threw] = await captureAsync(block);
|
|
21005
|
+
if (!threw) return;
|
|
21006
|
+
if (matches2(error, expected)) {
|
|
21007
|
+
fail(error, expected, message ?? "Got unwanted rejection.", "doesNotReject");
|
|
21008
|
+
}
|
|
21009
|
+
throw error;
|
|
21010
|
+
}
|
|
21011
|
+
function capture(block) {
|
|
21012
|
+
try {
|
|
21013
|
+
block();
|
|
21014
|
+
return [void 0, false];
|
|
21015
|
+
} catch (error) {
|
|
21016
|
+
return [error, true];
|
|
21017
|
+
}
|
|
21018
|
+
}
|
|
21019
|
+
async function captureAsync(block) {
|
|
21020
|
+
try {
|
|
21021
|
+
await (typeof block === "function" ? block() : block);
|
|
21022
|
+
return [void 0, false];
|
|
21023
|
+
} catch (error) {
|
|
21024
|
+
return [error, true];
|
|
21025
|
+
}
|
|
21026
|
+
}
|
|
21027
|
+
var match = (value, pattern, message) => {
|
|
21028
|
+
if (!pattern.test(value)) fail(value, pattern, message, "match");
|
|
21029
|
+
};
|
|
21030
|
+
var doesNotMatch = (value, pattern, message) => {
|
|
21031
|
+
if (pattern.test(value)) fail(value, pattern, message, "doesNotMatch");
|
|
21032
|
+
};
|
|
21033
|
+
var ifError = (value) => {
|
|
21034
|
+
if (value === null || value === void 0) return;
|
|
21035
|
+
if (value instanceof Error) throw value;
|
|
21036
|
+
fail(value, null, void 0, "ifError");
|
|
21037
|
+
};
|
|
21038
|
+
var base = {
|
|
21039
|
+
AssertionError,
|
|
21040
|
+
ok,
|
|
21041
|
+
equal,
|
|
21042
|
+
notEqual,
|
|
21043
|
+
strictEqual,
|
|
21044
|
+
notStrictEqual,
|
|
21045
|
+
deepEqual,
|
|
21046
|
+
notDeepEqual,
|
|
21047
|
+
deepStrictEqual,
|
|
21048
|
+
notDeepStrictEqual,
|
|
21049
|
+
throws,
|
|
21050
|
+
doesNotThrow,
|
|
21051
|
+
rejects,
|
|
21052
|
+
doesNotReject,
|
|
21053
|
+
match,
|
|
21054
|
+
doesNotMatch,
|
|
21055
|
+
ifError,
|
|
21056
|
+
fail: (message) => fail(void 0, void 0, message, "fail")
|
|
21057
|
+
};
|
|
21058
|
+
var assertModule = Object.assign(ok, base, {
|
|
21059
|
+
strict: Object.assign(ok, base, {
|
|
21060
|
+
equal: strictEqual,
|
|
21061
|
+
notEqual: notStrictEqual,
|
|
21062
|
+
deepEqual: deepStrictEqual,
|
|
21063
|
+
notDeepEqual: notDeepStrictEqual
|
|
21064
|
+
})
|
|
21065
|
+
});
|
|
21066
|
+
var assert_module_default = assertModule;
|
|
21067
|
+
var bytes = (data) => {
|
|
21068
|
+
if (typeof data === "string") return new Uint8Array(Buffer2.from(data, "utf8"));
|
|
21069
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
21070
|
+
return data;
|
|
21071
|
+
};
|
|
21072
|
+
function codec(name, run) {
|
|
21073
|
+
const sync2 = (data, options) => Buffer2.from(run(bytes(data), options));
|
|
21074
|
+
const async_ = (data, options, callback) => {
|
|
21075
|
+
const done = typeof options === "function" ? options : callback;
|
|
21076
|
+
const settings = typeof options === "function" ? void 0 : options;
|
|
21077
|
+
queueMicrotask(() => {
|
|
21078
|
+
try {
|
|
21079
|
+
done(null, sync2(data, settings));
|
|
21080
|
+
} catch (error) {
|
|
21081
|
+
done(error);
|
|
21082
|
+
}
|
|
21083
|
+
});
|
|
21084
|
+
};
|
|
21085
|
+
const Stream = class extends streamModule4.Transform {
|
|
21086
|
+
chunks = [];
|
|
21087
|
+
options;
|
|
21088
|
+
constructor(options) {
|
|
21089
|
+
super();
|
|
21090
|
+
this.options = options;
|
|
21091
|
+
}
|
|
21092
|
+
_transform(chunk, _encoding, next) {
|
|
21093
|
+
this.chunks.push(Buffer2.from(chunk));
|
|
21094
|
+
next();
|
|
21095
|
+
}
|
|
21096
|
+
_flush(next) {
|
|
21097
|
+
try {
|
|
21098
|
+
this.push(sync2(Buffer2.concat(this.chunks), this.options));
|
|
21099
|
+
next();
|
|
21100
|
+
} catch (error) {
|
|
21101
|
+
next(error);
|
|
21102
|
+
}
|
|
21103
|
+
}
|
|
21104
|
+
};
|
|
21105
|
+
Object.defineProperty(Stream, "name", { value: name });
|
|
21106
|
+
return { sync: sync2, async: async_, Stream };
|
|
21107
|
+
}
|
|
21108
|
+
var gzipCodec = codec("Gzip", (input, options) => gzip$1(input, options));
|
|
21109
|
+
var gunzipCodec = codec("Gunzip", (input) => ungzip(input));
|
|
21110
|
+
var deflateCodec = codec("Deflate", (input, options) => deflate$1(input, options));
|
|
21111
|
+
var inflateCodec = codec("Inflate", (input) => inflate$1(input));
|
|
21112
|
+
var deflateRawCodec = codec("DeflateRaw", (input, options) => deflateRaw(input, options));
|
|
21113
|
+
var inflateRawCodec = codec("InflateRaw", (input) => inflateRaw(input));
|
|
21114
|
+
var unzipCodec = codec(
|
|
21115
|
+
"Unzip",
|
|
21116
|
+
(input) => input[0] === 31 && input[1] === 139 ? ungzip(input) : inflate$1(input)
|
|
21117
|
+
);
|
|
21118
|
+
function brotliUnavailable(name) {
|
|
21119
|
+
const error = new Error(
|
|
21120
|
+
`zlib.${name} is unavailable: the sandboxed runtime has no Brotli implementation.`
|
|
21121
|
+
);
|
|
21122
|
+
error.code = "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM";
|
|
21123
|
+
throw error;
|
|
21124
|
+
}
|
|
21125
|
+
var zlibModule = {
|
|
21126
|
+
gzipSync: gzipCodec.sync,
|
|
21127
|
+
gzip: gzipCodec.async,
|
|
21128
|
+
createGzip: (o) => new gzipCodec.Stream(o),
|
|
21129
|
+
gunzipSync: gunzipCodec.sync,
|
|
21130
|
+
gunzip: gunzipCodec.async,
|
|
21131
|
+
createGunzip: (o) => new gunzipCodec.Stream(o),
|
|
21132
|
+
deflateSync: deflateCodec.sync,
|
|
21133
|
+
deflate: deflateCodec.async,
|
|
21134
|
+
createDeflate: (o) => new deflateCodec.Stream(o),
|
|
21135
|
+
inflateSync: inflateCodec.sync,
|
|
21136
|
+
inflate: inflateCodec.async,
|
|
21137
|
+
createInflate: (o) => new inflateCodec.Stream(o),
|
|
21138
|
+
deflateRawSync: deflateRawCodec.sync,
|
|
21139
|
+
deflateRaw: deflateRawCodec.async,
|
|
21140
|
+
createDeflateRaw: (o) => new deflateRawCodec.Stream(o),
|
|
21141
|
+
inflateRawSync: inflateRawCodec.sync,
|
|
21142
|
+
inflateRaw: inflateRawCodec.async,
|
|
21143
|
+
createInflateRaw: (o) => new inflateRawCodec.Stream(o),
|
|
21144
|
+
unzipSync: unzipCodec.sync,
|
|
21145
|
+
unzip: unzipCodec.async,
|
|
21146
|
+
createUnzip: (o) => new unzipCodec.Stream(o),
|
|
21147
|
+
brotliCompressSync: () => brotliUnavailable("brotliCompressSync"),
|
|
21148
|
+
brotliDecompressSync: () => brotliUnavailable("brotliDecompressSync"),
|
|
21149
|
+
brotliCompress: () => brotliUnavailable("brotliCompress"),
|
|
21150
|
+
brotliDecompress: () => brotliUnavailable("brotliDecompress"),
|
|
21151
|
+
createBrotliCompress: () => brotliUnavailable("createBrotliCompress"),
|
|
21152
|
+
createBrotliDecompress: () => brotliUnavailable("createBrotliDecompress"),
|
|
21153
|
+
constants: {
|
|
21154
|
+
Z_NO_FLUSH: 0,
|
|
21155
|
+
Z_PARTIAL_FLUSH: 1,
|
|
21156
|
+
Z_SYNC_FLUSH: 2,
|
|
21157
|
+
Z_FULL_FLUSH: 3,
|
|
21158
|
+
Z_FINISH: 4,
|
|
21159
|
+
Z_BLOCK: 5,
|
|
21160
|
+
Z_TREES: 6,
|
|
21161
|
+
Z_OK: 0,
|
|
21162
|
+
Z_STREAM_END: 1,
|
|
21163
|
+
Z_NEED_DICT: 2,
|
|
21164
|
+
Z_ERRNO: -1,
|
|
21165
|
+
Z_STREAM_ERROR: -2,
|
|
21166
|
+
Z_DATA_ERROR: -3,
|
|
21167
|
+
Z_MEM_ERROR: -4,
|
|
21168
|
+
Z_BUF_ERROR: -5,
|
|
21169
|
+
Z_VERSION_ERROR: -6,
|
|
21170
|
+
Z_NO_COMPRESSION: 0,
|
|
21171
|
+
Z_BEST_SPEED: 1,
|
|
21172
|
+
Z_BEST_COMPRESSION: 9,
|
|
21173
|
+
Z_DEFAULT_COMPRESSION: -1,
|
|
21174
|
+
Z_FILTERED: 1,
|
|
21175
|
+
Z_HUFFMAN_ONLY: 2,
|
|
21176
|
+
Z_RLE: 3,
|
|
21177
|
+
Z_FIXED: 4,
|
|
21178
|
+
Z_DEFAULT_STRATEGY: 0,
|
|
21179
|
+
DEFLATE: 1,
|
|
21180
|
+
INFLATE: 2,
|
|
21181
|
+
GZIP: 3,
|
|
21182
|
+
GUNZIP: 4,
|
|
21183
|
+
DEFLATERAW: 5,
|
|
21184
|
+
INFLATERAW: 6,
|
|
21185
|
+
UNZIP: 7
|
|
21186
|
+
}
|
|
21187
|
+
};
|
|
21188
|
+
var zlib_module_default = zlibModule;
|
|
21189
|
+
function fileURLToPath(url) {
|
|
21190
|
+
const value = typeof url === "string" ? new URL(url) : url;
|
|
21191
|
+
if (value.protocol !== "file:") {
|
|
21192
|
+
throw Object.assign(new TypeError("The URL must be of scheme file"), {
|
|
21193
|
+
code: "ERR_INVALID_URL_SCHEME"
|
|
21194
|
+
});
|
|
21195
|
+
}
|
|
21196
|
+
return decodeURIComponent(value.pathname);
|
|
21197
|
+
}
|
|
21198
|
+
function pathToFileURL(path) {
|
|
21199
|
+
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");
|
|
21200
|
+
return new URL(`file://${escaped.startsWith("/") ? "" : "/"}${escaped}`);
|
|
21201
|
+
}
|
|
21202
|
+
function format2(value, options) {
|
|
21203
|
+
if (!(value instanceof URL)) return legacyUrl.format(value);
|
|
21204
|
+
const url = new URL(value.href);
|
|
21205
|
+
if (options?.auth === false) {
|
|
21206
|
+
url.username = "";
|
|
21207
|
+
url.password = "";
|
|
21208
|
+
}
|
|
21209
|
+
if (options?.fragment === false) url.hash = "";
|
|
21210
|
+
if (options?.search === false) url.search = "";
|
|
21211
|
+
return url.href;
|
|
21212
|
+
}
|
|
21213
|
+
var urlModule = {
|
|
21214
|
+
...legacyUrl,
|
|
21215
|
+
format: format2,
|
|
21216
|
+
fileURLToPath,
|
|
21217
|
+
pathToFileURL,
|
|
21218
|
+
URL,
|
|
21219
|
+
URLSearchParams,
|
|
21220
|
+
/** Names here are already Unicode; there is no IDNA table to consult. */
|
|
21221
|
+
domainToASCII: (domain) => domain.toLowerCase(),
|
|
21222
|
+
domainToUnicode: (domain) => domain.toLowerCase(),
|
|
21223
|
+
urlToHttpOptions: (url) => ({
|
|
21224
|
+
protocol: url.protocol,
|
|
21225
|
+
hostname: url.hostname,
|
|
21226
|
+
hash: url.hash,
|
|
21227
|
+
search: url.search,
|
|
21228
|
+
pathname: url.pathname,
|
|
21229
|
+
path: `${url.pathname}${url.search}`,
|
|
21230
|
+
href: url.href,
|
|
21231
|
+
...url.port ? { port: Number(url.port) } : {},
|
|
21232
|
+
...url.username || url.password ? { auth: `${url.username}:${url.password}` } : {}
|
|
21233
|
+
})
|
|
21234
|
+
};
|
|
21235
|
+
var url_module_default = urlModule;
|
|
21236
|
+
|
|
20437
21237
|
// src/runtime/core-modules.ts
|
|
20438
21238
|
init_path();
|
|
20439
|
-
var VirtualIncomingMessage = class extends
|
|
21239
|
+
var VirtualIncomingMessage = class extends streamModule4.Readable {
|
|
20440
21240
|
method;
|
|
20441
21241
|
url;
|
|
20442
21242
|
headers;
|
|
@@ -20457,7 +21257,7 @@ var VirtualIncomingMessage = class extends streamModule3.Readable {
|
|
|
20457
21257
|
this.headers["content-length"] = String(body.length);
|
|
20458
21258
|
}
|
|
20459
21259
|
this.rawHeaders = Object.entries(this.headers).flatMap(([key, value]) => [key, value]);
|
|
20460
|
-
if (body.length) this.push(
|
|
21260
|
+
if (body.length) this.push(Buffer2.from(body));
|
|
20461
21261
|
this.push(null);
|
|
20462
21262
|
}
|
|
20463
21263
|
_read() {
|
|
@@ -20467,7 +21267,7 @@ var VirtualIncomingMessage = class extends streamModule3.Readable {
|
|
|
20467
21267
|
return this;
|
|
20468
21268
|
}
|
|
20469
21269
|
};
|
|
20470
|
-
var VirtualServerResponse = class extends
|
|
21270
|
+
var VirtualServerResponse = class extends streamModule4.Writable {
|
|
20471
21271
|
statusCode = 200;
|
|
20472
21272
|
statusMessage = "OK";
|
|
20473
21273
|
headersSent = false;
|
|
@@ -20488,7 +21288,7 @@ var VirtualServerResponse = class extends streamModule3.Writable {
|
|
|
20488
21288
|
}
|
|
20489
21289
|
_write(chunk, encoding, callback) {
|
|
20490
21290
|
this.headersSent = true;
|
|
20491
|
-
this.chunks.push(
|
|
21291
|
+
this.chunks.push(Buffer2.isBuffer(chunk) ? chunk : Buffer2.from(chunk, encoding));
|
|
20492
21292
|
callback();
|
|
20493
21293
|
}
|
|
20494
21294
|
_final(callback) {
|
|
@@ -20500,7 +21300,7 @@ var VirtualServerResponse = class extends streamModule3.Writable {
|
|
|
20500
21300
|
statusCode: this.statusCode,
|
|
20501
21301
|
statusMessage: this.statusMessage || STATUS_CODES[this.statusCode] || "",
|
|
20502
21302
|
headers,
|
|
20503
|
-
body: new Uint8Array(
|
|
21303
|
+
body: new Uint8Array(Buffer2.concat(this.chunks))
|
|
20504
21304
|
});
|
|
20505
21305
|
callback();
|
|
20506
21306
|
}
|
|
@@ -20552,7 +21352,7 @@ var VirtualServerResponse = class extends streamModule3.Writable {
|
|
|
20552
21352
|
return this;
|
|
20553
21353
|
}
|
|
20554
21354
|
};
|
|
20555
|
-
var VirtualHttpServer = class extends
|
|
21355
|
+
var VirtualHttpServer = class extends EventEmitter4 {
|
|
20556
21356
|
constructor(router, owner, listener) {
|
|
20557
21357
|
super();
|
|
20558
21358
|
this.router = router;
|
|
@@ -20688,7 +21488,7 @@ function createCryptoModule() {
|
|
|
20688
21488
|
return api;
|
|
20689
21489
|
},
|
|
20690
21490
|
digest(encoding) {
|
|
20691
|
-
const value =
|
|
21491
|
+
const value = Buffer2.from(hash.digest());
|
|
20692
21492
|
return encoding ? value.toString(encoding) : value;
|
|
20693
21493
|
},
|
|
20694
21494
|
copy() {
|
|
@@ -20706,14 +21506,14 @@ function createCryptoModule() {
|
|
|
20706
21506
|
return api;
|
|
20707
21507
|
},
|
|
20708
21508
|
digest(encoding) {
|
|
20709
|
-
const value =
|
|
21509
|
+
const value = Buffer2.from(state.digest());
|
|
20710
21510
|
return encoding ? value.toString(encoding) : value;
|
|
20711
21511
|
}
|
|
20712
21512
|
};
|
|
20713
21513
|
return api;
|
|
20714
21514
|
},
|
|
20715
21515
|
randomBytes(size, callback) {
|
|
20716
|
-
const value =
|
|
21516
|
+
const value = Buffer2.alloc(size);
|
|
20717
21517
|
cryptoObject.getRandomValues(value);
|
|
20718
21518
|
if (callback) {
|
|
20719
21519
|
queueMicrotask(() => callback(null, value));
|
|
@@ -20746,7 +21546,7 @@ function createCryptoModule() {
|
|
|
20746
21546
|
queueMicrotask(() => done?.(null, target));
|
|
20747
21547
|
},
|
|
20748
21548
|
hash(algorithm, data, encoding = "hex") {
|
|
20749
|
-
const digest =
|
|
21549
|
+
const digest = Buffer2.from(hashFor(algorithm)(toBytes2(data)));
|
|
20750
21550
|
return encoding === "buffer" ? digest : digest.toString(encoding);
|
|
20751
21551
|
},
|
|
20752
21552
|
timingSafeEqual(a, b) {
|
|
@@ -20767,11 +21567,11 @@ function hashFor(algorithm) {
|
|
|
20767
21567
|
return hash;
|
|
20768
21568
|
}
|
|
20769
21569
|
function toBytes2(data, encoding) {
|
|
20770
|
-
return typeof data === "string" ?
|
|
21570
|
+
return typeof data === "string" ? Buffer2.from(data, encoding) : data;
|
|
20771
21571
|
}
|
|
20772
|
-
var ChildProcess = class extends
|
|
20773
|
-
stdout = new
|
|
20774
|
-
stderr = new
|
|
21572
|
+
var ChildProcess = class extends EventEmitter4 {
|
|
21573
|
+
stdout = new streamModule4.PassThrough();
|
|
21574
|
+
stderr = new streamModule4.PassThrough();
|
|
20775
21575
|
stdin;
|
|
20776
21576
|
stdio;
|
|
20777
21577
|
pid;
|
|
@@ -20788,10 +21588,10 @@ var ChildProcess = class extends EventEmitter3 {
|
|
|
20788
21588
|
this.pid = handle.pid;
|
|
20789
21589
|
this.spawnfile = file3;
|
|
20790
21590
|
this.spawnargs = [file3, ...args];
|
|
20791
|
-
this.stdin = new
|
|
21591
|
+
this.stdin = new streamModule4.Writable({
|
|
20792
21592
|
write: (chunk, _encoding, done) => {
|
|
20793
21593
|
try {
|
|
20794
|
-
handle.sendStdin(typeof chunk === "string" ? chunk :
|
|
21594
|
+
handle.sendStdin(typeof chunk === "string" ? chunk : Buffer2.from(chunk).toString("utf8"));
|
|
20795
21595
|
} catch {
|
|
20796
21596
|
}
|
|
20797
21597
|
done();
|
|
@@ -20861,8 +21661,8 @@ function createChildProcessModule(spawnChild, defaultCwd) {
|
|
|
20861
21661
|
child.stderr.on("data", (chunk) => err.push(String(chunk)));
|
|
20862
21662
|
child.on("close", (code) => {
|
|
20863
21663
|
const asBuffer = options.encoding === "buffer";
|
|
20864
|
-
const stdout = asBuffer ?
|
|
20865
|
-
const stderr = asBuffer ?
|
|
21664
|
+
const stdout = asBuffer ? Buffer2.from(out.join("")) : out.join("");
|
|
21665
|
+
const stderr = asBuffer ? Buffer2.from(err.join("")) : err.join("");
|
|
20866
21666
|
if (code === 0) {
|
|
20867
21667
|
callback(null, stdout, stderr);
|
|
20868
21668
|
return;
|
|
@@ -20913,6 +21713,326 @@ function unavailable(name) {
|
|
|
20913
21713
|
|
|
20914
21714
|
// src/runtime/core-modules.ts
|
|
20915
21715
|
init_signals();
|
|
21716
|
+
var CSI_KEYS = {
|
|
21717
|
+
"[A": "up",
|
|
21718
|
+
"[B": "down",
|
|
21719
|
+
"[C": "right",
|
|
21720
|
+
"[D": "left",
|
|
21721
|
+
"[E": "clear",
|
|
21722
|
+
"[F": "end",
|
|
21723
|
+
"[H": "home",
|
|
21724
|
+
"OA": "up",
|
|
21725
|
+
"OB": "down",
|
|
21726
|
+
"OC": "right",
|
|
21727
|
+
"OD": "left",
|
|
21728
|
+
"OE": "clear",
|
|
21729
|
+
"OF": "end",
|
|
21730
|
+
"OH": "home",
|
|
21731
|
+
"[1~": "home",
|
|
21732
|
+
"[2~": "insert",
|
|
21733
|
+
"[3~": "delete",
|
|
21734
|
+
"[4~": "end",
|
|
21735
|
+
"[5~": "pageup",
|
|
21736
|
+
"[6~": "pagedown",
|
|
21737
|
+
"[7~": "home",
|
|
21738
|
+
"[8~": "end",
|
|
21739
|
+
"[11~": "f1",
|
|
21740
|
+
"[12~": "f2",
|
|
21741
|
+
"[13~": "f3",
|
|
21742
|
+
"[14~": "f4",
|
|
21743
|
+
"[15~": "f5",
|
|
21744
|
+
"[17~": "f6",
|
|
21745
|
+
"[18~": "f7",
|
|
21746
|
+
"[19~": "f8",
|
|
21747
|
+
"[20~": "f9",
|
|
21748
|
+
"[21~": "f10",
|
|
21749
|
+
"[23~": "f11",
|
|
21750
|
+
"[24~": "f12",
|
|
21751
|
+
"OP": "f1",
|
|
21752
|
+
"OQ": "f2",
|
|
21753
|
+
"OR": "f3",
|
|
21754
|
+
"OS": "f4",
|
|
21755
|
+
"[Z": "tab"
|
|
21756
|
+
};
|
|
21757
|
+
var CONTROL_LETTERS = "abcdefghijklmnopqrstuvwxyz";
|
|
21758
|
+
function parseKeys(input) {
|
|
21759
|
+
const keys = [];
|
|
21760
|
+
let index = 0;
|
|
21761
|
+
while (index < input.length) {
|
|
21762
|
+
const char = input[index];
|
|
21763
|
+
if (char === "\x1B") {
|
|
21764
|
+
const rest = input.slice(index + 1);
|
|
21765
|
+
const match2 = /^(\[[0-9;]*[A-Za-z~]|O[A-Za-z])/.exec(rest);
|
|
21766
|
+
if (match2) {
|
|
21767
|
+
const sequence = match2[1];
|
|
21768
|
+
const name = CSI_KEYS[sequence];
|
|
21769
|
+
keys.push({
|
|
21770
|
+
sequence: `\x1B${sequence}`,
|
|
21771
|
+
name: name ?? "undefined",
|
|
21772
|
+
ctrl: false,
|
|
21773
|
+
/* xterm reports modifiers as `;5` (control) and `;2` (shift) before
|
|
21774
|
+
* the final letter. */
|
|
21775
|
+
meta: false,
|
|
21776
|
+
shift: /;2[A-Za-z~]$/.test(sequence),
|
|
21777
|
+
code: sequence
|
|
21778
|
+
});
|
|
21779
|
+
if (/;5[A-Za-z~]$/.test(sequence)) keys[keys.length - 1].ctrl = true;
|
|
21780
|
+
index += 1 + sequence.length;
|
|
21781
|
+
continue;
|
|
21782
|
+
}
|
|
21783
|
+
if (rest.length > 0 && rest[0] !== "\x1B") {
|
|
21784
|
+
const inner = parseKeys(rest[0])[0];
|
|
21785
|
+
if (inner) {
|
|
21786
|
+
keys.push({ ...inner, meta: true, sequence: `\x1B${inner.sequence}` });
|
|
21787
|
+
index += 2;
|
|
21788
|
+
continue;
|
|
21789
|
+
}
|
|
21790
|
+
}
|
|
21791
|
+
keys.push({ sequence: "\x1B", name: "escape", ctrl: false, meta: false, shift: false });
|
|
21792
|
+
index += 1;
|
|
21793
|
+
continue;
|
|
21794
|
+
}
|
|
21795
|
+
keys.push(parseSingle(char));
|
|
21796
|
+
index += 1;
|
|
21797
|
+
}
|
|
21798
|
+
return keys;
|
|
21799
|
+
}
|
|
21800
|
+
function parseSingle(char) {
|
|
21801
|
+
const code = char.charCodeAt(0);
|
|
21802
|
+
if (char === "\r") return { sequence: char, name: "return", ctrl: false, meta: false, shift: false };
|
|
21803
|
+
if (char === "\n") return { sequence: char, name: "enter", ctrl: false, meta: false, shift: false };
|
|
21804
|
+
if (char === " ") return { sequence: char, name: "tab", ctrl: false, meta: false, shift: false };
|
|
21805
|
+
if (char === "\x7F" || char === "\b") {
|
|
21806
|
+
return { sequence: char, name: "backspace", ctrl: false, meta: false, shift: false };
|
|
21807
|
+
}
|
|
21808
|
+
if (char === " ") return { sequence: char, name: "space", ctrl: false, meta: false, shift: false };
|
|
21809
|
+
if (code >= 1 && code <= 26) {
|
|
21810
|
+
return {
|
|
21811
|
+
sequence: char,
|
|
21812
|
+
name: CONTROL_LETTERS[code - 1],
|
|
21813
|
+
ctrl: true,
|
|
21814
|
+
meta: false,
|
|
21815
|
+
shift: false
|
|
21816
|
+
};
|
|
21817
|
+
}
|
|
21818
|
+
return {
|
|
21819
|
+
sequence: char,
|
|
21820
|
+
name: char.toLowerCase(),
|
|
21821
|
+
ctrl: false,
|
|
21822
|
+
meta: false,
|
|
21823
|
+
// An uppercase letter arrived because shift was held.
|
|
21824
|
+
shift: char !== char.toLowerCase()
|
|
21825
|
+
};
|
|
21826
|
+
}
|
|
21827
|
+
function emitKeypressEvents(stream) {
|
|
21828
|
+
if (!stream || stream.__sbxKeypress) return;
|
|
21829
|
+
stream.__sbxKeypress = true;
|
|
21830
|
+
stream.on("data", (chunk) => {
|
|
21831
|
+
for (const key of parseKeys(String(chunk))) {
|
|
21832
|
+
stream.emit("keypress", key.sequence, key);
|
|
21833
|
+
}
|
|
21834
|
+
});
|
|
21835
|
+
}
|
|
21836
|
+
function createReadlineModule(defaultInput) {
|
|
21837
|
+
class Interface extends EventEmitter4 {
|
|
21838
|
+
constructor(input, output, terminal = false) {
|
|
21839
|
+
super();
|
|
21840
|
+
this.input = input;
|
|
21841
|
+
this.output = output;
|
|
21842
|
+
this.terminal = terminal;
|
|
21843
|
+
this.onTerminalKeypress = (sequence, key) => this.edit(sequence, key);
|
|
21844
|
+
if (terminal) {
|
|
21845
|
+
emitKeypressEvents(input);
|
|
21846
|
+
input?.on?.("keypress", this.onTerminalKeypress);
|
|
21847
|
+
} else {
|
|
21848
|
+
input?.on?.("data", (chunk) => this.receive(String(chunk)));
|
|
21849
|
+
}
|
|
21850
|
+
input?.on?.("end", () => this.close());
|
|
21851
|
+
}
|
|
21852
|
+
input;
|
|
21853
|
+
output;
|
|
21854
|
+
closed = false;
|
|
21855
|
+
buffer = "";
|
|
21856
|
+
pending = [];
|
|
21857
|
+
lines = [];
|
|
21858
|
+
line = "";
|
|
21859
|
+
cursor = 0;
|
|
21860
|
+
terminal;
|
|
21861
|
+
onTerminalKeypress;
|
|
21862
|
+
/** Split incoming data into lines, answering any waiting `question`. */
|
|
21863
|
+
receive(text2) {
|
|
21864
|
+
this.buffer += text2;
|
|
21865
|
+
let newline = this.buffer.indexOf("\n");
|
|
21866
|
+
while (newline >= 0) {
|
|
21867
|
+
const line = this.buffer.slice(0, newline).replace(/\r$/, "");
|
|
21868
|
+
this.buffer = this.buffer.slice(newline + 1);
|
|
21869
|
+
const waiting = this.pending.shift();
|
|
21870
|
+
if (waiting) waiting(line);
|
|
21871
|
+
else {
|
|
21872
|
+
this.lines.push(line);
|
|
21873
|
+
this.emit("line", line);
|
|
21874
|
+
}
|
|
21875
|
+
newline = this.buffer.indexOf("\n");
|
|
21876
|
+
}
|
|
21877
|
+
}
|
|
21878
|
+
question(query, callback) {
|
|
21879
|
+
this.output?.write?.(query);
|
|
21880
|
+
if (callback) {
|
|
21881
|
+
this.pending.push(callback);
|
|
21882
|
+
return;
|
|
21883
|
+
}
|
|
21884
|
+
return new Promise((resolve2) => this.pending.push(resolve2));
|
|
21885
|
+
}
|
|
21886
|
+
prompt() {
|
|
21887
|
+
this.output?.write?.(this.promptText);
|
|
21888
|
+
}
|
|
21889
|
+
promptText = "> ";
|
|
21890
|
+
setPrompt(text2) {
|
|
21891
|
+
this.promptText = text2;
|
|
21892
|
+
}
|
|
21893
|
+
pause() {
|
|
21894
|
+
this.input?.pause?.();
|
|
21895
|
+
return this;
|
|
21896
|
+
}
|
|
21897
|
+
resume() {
|
|
21898
|
+
this.input?.resume?.();
|
|
21899
|
+
return this;
|
|
21900
|
+
}
|
|
21901
|
+
write(text2, key) {
|
|
21902
|
+
if (!this.terminal) {
|
|
21903
|
+
if (text2) this.receive(text2);
|
|
21904
|
+
return;
|
|
21905
|
+
}
|
|
21906
|
+
if (key) {
|
|
21907
|
+
this.edit(text2 ?? "", {
|
|
21908
|
+
sequence: text2 ?? key.sequence ?? "",
|
|
21909
|
+
name: key.name,
|
|
21910
|
+
ctrl: key.ctrl ?? false,
|
|
21911
|
+
meta: key.meta ?? false,
|
|
21912
|
+
shift: key.shift ?? false,
|
|
21913
|
+
...key.code ? { code: key.code } : {}
|
|
21914
|
+
});
|
|
21915
|
+
return;
|
|
21916
|
+
}
|
|
21917
|
+
if (text2) {
|
|
21918
|
+
this.line = this.line.slice(0, this.cursor) + text2 + this.line.slice(this.cursor);
|
|
21919
|
+
this.cursor += text2.length;
|
|
21920
|
+
}
|
|
21921
|
+
}
|
|
21922
|
+
getCursorPos() {
|
|
21923
|
+
return { rows: 0, cols: this.cursor + this.promptText.length };
|
|
21924
|
+
}
|
|
21925
|
+
close() {
|
|
21926
|
+
if (this.closed) return;
|
|
21927
|
+
this.closed = true;
|
|
21928
|
+
if (this.terminal) {
|
|
21929
|
+
this.input?.off?.("keypress", this.onTerminalKeypress);
|
|
21930
|
+
this.input?.pause?.();
|
|
21931
|
+
}
|
|
21932
|
+
for (const waiting of this.pending.splice(0)) waiting("");
|
|
21933
|
+
this.emit("close");
|
|
21934
|
+
}
|
|
21935
|
+
edit(sequence, key) {
|
|
21936
|
+
if (this.closed) return;
|
|
21937
|
+
const name = key.name;
|
|
21938
|
+
if (name === "return" || name === "enter") {
|
|
21939
|
+
const value = this.line;
|
|
21940
|
+
this.line = "";
|
|
21941
|
+
this.cursor = 0;
|
|
21942
|
+
this.emit("line", value);
|
|
21943
|
+
return;
|
|
21944
|
+
}
|
|
21945
|
+
if (name === "left") {
|
|
21946
|
+
this.cursor = Math.max(0, this.cursor - 1);
|
|
21947
|
+
return;
|
|
21948
|
+
}
|
|
21949
|
+
if (name === "right") {
|
|
21950
|
+
this.cursor = Math.min(this.line.length, this.cursor + 1);
|
|
21951
|
+
return;
|
|
21952
|
+
}
|
|
21953
|
+
if (name === "home" || key.ctrl && name === "a") {
|
|
21954
|
+
this.cursor = 0;
|
|
21955
|
+
return;
|
|
21956
|
+
}
|
|
21957
|
+
if (name === "end" || key.ctrl && name === "e") {
|
|
21958
|
+
this.cursor = this.line.length;
|
|
21959
|
+
return;
|
|
21960
|
+
}
|
|
21961
|
+
if (name === "backspace" || key.ctrl && name === "h") {
|
|
21962
|
+
if (this.cursor > 0) {
|
|
21963
|
+
this.line = this.line.slice(0, this.cursor - 1) + this.line.slice(this.cursor);
|
|
21964
|
+
this.cursor--;
|
|
21965
|
+
}
|
|
21966
|
+
return;
|
|
21967
|
+
}
|
|
21968
|
+
if (name === "delete") {
|
|
21969
|
+
if (this.cursor < this.line.length) this.line = this.line.slice(0, this.cursor) + this.line.slice(this.cursor + 1);
|
|
21970
|
+
return;
|
|
21971
|
+
}
|
|
21972
|
+
if (key.ctrl && name === "u") {
|
|
21973
|
+
this.line = this.line.slice(this.cursor);
|
|
21974
|
+
this.cursor = 0;
|
|
21975
|
+
return;
|
|
21976
|
+
}
|
|
21977
|
+
if (key.ctrl && name === "k") {
|
|
21978
|
+
this.line = this.line.slice(0, this.cursor);
|
|
21979
|
+
return;
|
|
21980
|
+
}
|
|
21981
|
+
if (key.ctrl || key.meta || sequence.length !== 1 || sequence < " ") return;
|
|
21982
|
+
this.line = this.line.slice(0, this.cursor) + sequence + this.line.slice(this.cursor);
|
|
21983
|
+
this.cursor += sequence.length;
|
|
21984
|
+
}
|
|
21985
|
+
async *[Symbol.asyncIterator]() {
|
|
21986
|
+
while (!this.closed || this.lines.length) {
|
|
21987
|
+
const line = this.lines.shift();
|
|
21988
|
+
if (line !== void 0) {
|
|
21989
|
+
yield line;
|
|
21990
|
+
continue;
|
|
21991
|
+
}
|
|
21992
|
+
const next = await new Promise((resolve2) => {
|
|
21993
|
+
const onLine = (value) => {
|
|
21994
|
+
cleanup();
|
|
21995
|
+
resolve2(value);
|
|
21996
|
+
};
|
|
21997
|
+
const onClose = () => {
|
|
21998
|
+
cleanup();
|
|
21999
|
+
resolve2(null);
|
|
22000
|
+
};
|
|
22001
|
+
const cleanup = () => {
|
|
22002
|
+
this.off("line", onLine);
|
|
22003
|
+
this.off("close", onClose);
|
|
22004
|
+
};
|
|
22005
|
+
this.on("line", onLine);
|
|
22006
|
+
this.on("close", onClose);
|
|
22007
|
+
});
|
|
22008
|
+
if (next === null) return;
|
|
22009
|
+
yield next;
|
|
22010
|
+
}
|
|
22011
|
+
}
|
|
22012
|
+
}
|
|
22013
|
+
const createInterface = (options, output) => {
|
|
22014
|
+
if (options && typeof options === "object" && !options.on) {
|
|
22015
|
+
const instance = new Interface(options.input ?? defaultInput(), options.output, options.terminal === true);
|
|
22016
|
+
if (typeof options.prompt === "string") instance.setPrompt(options.prompt);
|
|
22017
|
+
return instance;
|
|
22018
|
+
}
|
|
22019
|
+
return new Interface(options ?? defaultInput(), output, Boolean(output));
|
|
22020
|
+
};
|
|
22021
|
+
const noop = () => {
|
|
22022
|
+
};
|
|
22023
|
+
const base2 = {
|
|
22024
|
+
Interface,
|
|
22025
|
+
createInterface,
|
|
22026
|
+
emitKeypressEvents,
|
|
22027
|
+
clearLine: noop,
|
|
22028
|
+
clearScreenDown: noop,
|
|
22029
|
+
cursorTo: noop,
|
|
22030
|
+
moveCursor: noop
|
|
22031
|
+
};
|
|
22032
|
+
return { ...base2, promises: { ...base2, Interface, createInterface } };
|
|
22033
|
+
}
|
|
22034
|
+
|
|
22035
|
+
// src/runtime/core-modules.ts
|
|
20916
22036
|
var Dirent = class {
|
|
20917
22037
|
/** Node 20+ exposes the containing directory, and `fs.glob` consumers read it. */
|
|
20918
22038
|
constructor(name, stat2, parentPath = "") {
|
|
@@ -21028,7 +22148,7 @@ var S_IFMT2 = 61440;
|
|
|
21028
22148
|
var S_IFREG2 = 32768;
|
|
21029
22149
|
var S_IFDIR2 = 16384;
|
|
21030
22150
|
var S_IFLNK2 = 40960;
|
|
21031
|
-
var FsWatcher = class extends
|
|
22151
|
+
var FsWatcher = class extends EventEmitter4 {
|
|
21032
22152
|
close() {
|
|
21033
22153
|
this.removeAllListeners();
|
|
21034
22154
|
}
|
|
@@ -21049,7 +22169,7 @@ function createCoreModules(options) {
|
|
|
21049
22169
|
const stderrWrite = options.stderr ?? (() => {
|
|
21050
22170
|
});
|
|
21051
22171
|
const timers = createTrackedTimers();
|
|
21052
|
-
const processObject = Object.assign(new
|
|
22172
|
+
const processObject = Object.assign(new EventEmitter4(), processShim, {
|
|
21053
22173
|
argv: options.argv?.slice() ?? ["/usr/bin/node"],
|
|
21054
22174
|
argv0: "node",
|
|
21055
22175
|
execPath: "/usr/bin/node",
|
|
@@ -21085,14 +22205,27 @@ function createCoreModules(options) {
|
|
|
21085
22205
|
},
|
|
21086
22206
|
kill: () => true
|
|
21087
22207
|
});
|
|
21088
|
-
|
|
21089
|
-
processObject.
|
|
21090
|
-
processObject.
|
|
22208
|
+
const tty = options.tty === true;
|
|
22209
|
+
processObject.stdout = makeOutputStream(stdoutWrite, 1, tty);
|
|
22210
|
+
processObject.stderr = makeOutputStream(stderrWrite, 2, tty);
|
|
22211
|
+
const stdin = options.interactiveStdin ? new streamModule4.PassThrough() : new streamModule4.Readable({ read() {
|
|
21091
22212
|
this.push(null);
|
|
21092
22213
|
} });
|
|
21093
|
-
Object.assign(
|
|
21094
|
-
|
|
21095
|
-
|
|
22214
|
+
Object.assign(stdin, {
|
|
22215
|
+
fd: 0,
|
|
22216
|
+
isTTY: tty,
|
|
22217
|
+
setRawMode(enabled = true) {
|
|
22218
|
+
options.onRawMode?.(enabled !== false);
|
|
22219
|
+
return this;
|
|
22220
|
+
},
|
|
22221
|
+
ref() {
|
|
22222
|
+
return this;
|
|
22223
|
+
},
|
|
22224
|
+
unref() {
|
|
22225
|
+
return this;
|
|
22226
|
+
}
|
|
22227
|
+
});
|
|
22228
|
+
processObject.stdin = stdin;
|
|
21096
22229
|
const fs = createFsModule(volume, () => cwd, options.stdinPath);
|
|
21097
22230
|
const path = createPathModule(() => cwd);
|
|
21098
22231
|
const consoleObject = new Console(stdoutWrite, stderrWrite);
|
|
@@ -21110,9 +22243,9 @@ function createCoreModules(options) {
|
|
|
21110
22243
|
const readline = createReadlineModule(() => processObject.stdin);
|
|
21111
22244
|
const dns = createDnsModule();
|
|
21112
22245
|
const builtins = {
|
|
21113
|
-
assert:
|
|
21114
|
-
"assert/strict":
|
|
21115
|
-
buffer: { Buffer:
|
|
22246
|
+
assert: assert_module_default,
|
|
22247
|
+
"assert/strict": assert_module_default.strict ?? assert_module_default,
|
|
22248
|
+
buffer: { Buffer: Buffer2, SlowBuffer: Buffer2, INSPECT_MAX_BYTES: 50, kMaxLength: Buffer2.kMaxLength },
|
|
21116
22249
|
async_hooks: asyncHooks,
|
|
21117
22250
|
child_process: childProcess,
|
|
21118
22251
|
console: consoleObject,
|
|
@@ -21120,7 +22253,7 @@ function createCoreModules(options) {
|
|
|
21120
22253
|
crypto: createCryptoModule(),
|
|
21121
22254
|
dns,
|
|
21122
22255
|
"dns/promises": dns.promises,
|
|
21123
|
-
events:
|
|
22256
|
+
events: EventEmitter4,
|
|
21124
22257
|
fs,
|
|
21125
22258
|
"fs/promises": fs.promises,
|
|
21126
22259
|
module: moduleBuiltin,
|
|
@@ -21131,24 +22264,24 @@ function createCoreModules(options) {
|
|
|
21131
22264
|
"path/posix": path,
|
|
21132
22265
|
perf_hooks: { performance, PerformanceObserver: globalThis.PerformanceObserver },
|
|
21133
22266
|
process: processObject,
|
|
21134
|
-
punycode:
|
|
22267
|
+
punycode: url_module_default.punycode ?? {},
|
|
21135
22268
|
querystring: querystringModule,
|
|
21136
22269
|
readline,
|
|
21137
22270
|
"readline/promises": readline.promises,
|
|
21138
|
-
stream:
|
|
22271
|
+
stream: streamModule4,
|
|
21139
22272
|
"stream/promises": createStreamPromises(),
|
|
21140
22273
|
string_decoder: stringDecoderModule,
|
|
21141
22274
|
timers: { ...timersModule, ...timers.api },
|
|
21142
22275
|
"timers/promises": createTimerPromises(),
|
|
21143
|
-
tty: { isatty: () => false, ReadStream:
|
|
21144
|
-
url:
|
|
21145
|
-
util:
|
|
21146
|
-
"util/types":
|
|
21147
|
-
zlib:
|
|
22276
|
+
tty: { isatty: () => false, ReadStream: streamModule4.Readable, WriteStream: streamModule4.Writable },
|
|
22277
|
+
url: url_module_default,
|
|
22278
|
+
util: util_module_default,
|
|
22279
|
+
"util/types": util_module_default.types ?? {},
|
|
22280
|
+
zlib: zlib_module_default
|
|
21148
22281
|
};
|
|
21149
22282
|
for (const name of stubNames) builtins[name] = createUnsupportedModule(name);
|
|
21150
22283
|
const globals = {
|
|
21151
|
-
Buffer:
|
|
22284
|
+
Buffer: Buffer2,
|
|
21152
22285
|
console: consoleObject,
|
|
21153
22286
|
process: processObject,
|
|
21154
22287
|
...timers.api
|
|
@@ -21159,7 +22292,20 @@ function createCoreModules(options) {
|
|
|
21159
22292
|
});
|
|
21160
22293
|
globals.global = globalOverlay;
|
|
21161
22294
|
globals.globalThis = globalOverlay;
|
|
21162
|
-
return {
|
|
22295
|
+
return {
|
|
22296
|
+
builtins,
|
|
22297
|
+
globals,
|
|
22298
|
+
process: processObject,
|
|
22299
|
+
pendingHandles: timers.pending,
|
|
22300
|
+
pendingUnrefed: timers.pendingUnrefed,
|
|
22301
|
+
writeStdin: (data) => {
|
|
22302
|
+
if (options.interactiveStdin) stdin.write(data);
|
|
22303
|
+
},
|
|
22304
|
+
endStdin: () => {
|
|
22305
|
+
if (options.interactiveStdin) stdin.end();
|
|
22306
|
+
},
|
|
22307
|
+
readingStdin: () => Boolean(options.interactiveStdin) && stdin.readable === true && (stdin.readableFlowing === true || stdin.listenerCount("readable") > 0 || stdin.listenerCount("keypress") > 0)
|
|
22308
|
+
};
|
|
21163
22309
|
}
|
|
21164
22310
|
var ASYNC_FS_METHODS = [
|
|
21165
22311
|
"readFile",
|
|
@@ -21220,18 +22366,18 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21220
22366
|
const abs = (value) => {
|
|
21221
22367
|
if (typeof value === "number") return requiredFd(fds, value).path;
|
|
21222
22368
|
if (value instanceof URL) value = value.pathname;
|
|
21223
|
-
if (
|
|
22369
|
+
if (Buffer2.isBuffer(value) || value instanceof Uint8Array) value = new TextDecoder().decode(value);
|
|
21224
22370
|
if (typeof value !== "string") throw new TypeError("path must be a string, Buffer, or URL");
|
|
21225
22371
|
return value.startsWith("/") ? clean(value) : resolve(cwd(), value);
|
|
21226
22372
|
};
|
|
21227
|
-
const
|
|
21228
|
-
if (typeof data === "string") return new Uint8Array(
|
|
21229
|
-
if (
|
|
22373
|
+
const bytes2 = (data, encoding) => {
|
|
22374
|
+
if (typeof data === "string") return new Uint8Array(Buffer2.from(data, encoding));
|
|
22375
|
+
if (Buffer2.isBuffer(data) || data instanceof Uint8Array) return new Uint8Array(data);
|
|
21230
22376
|
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
21231
22377
|
throw new TypeError("data must be a string or byte array");
|
|
21232
22378
|
};
|
|
21233
22379
|
const read = (path, encoding) => {
|
|
21234
|
-
const data =
|
|
22380
|
+
const data = Buffer2.from(volume.readFileSync(resolveLinks(volume, abs(path))));
|
|
21235
22381
|
return encoding && encoding !== "buffer" ? data.toString(encoding) : data;
|
|
21236
22382
|
};
|
|
21237
22383
|
const mkdirRecursive = (path, mode) => {
|
|
@@ -21280,12 +22426,12 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21280
22426
|
readFileSync: (path, options) => read(path, typeof options === "object" && options ? options.encoding : options),
|
|
21281
22427
|
writeFileSync: (path, data, options) => {
|
|
21282
22428
|
const encoding = typeof options === "object" && options ? options.encoding : options === "buffer" ? void 0 : options ?? void 0;
|
|
21283
|
-
volume.writeFileSync(abs(path),
|
|
22429
|
+
volume.writeFileSync(abs(path), bytes2(data, encoding ?? void 0));
|
|
21284
22430
|
if (typeof options === "object" && options?.mode !== void 0) volume.chmodSync(abs(path), options.mode);
|
|
21285
22431
|
},
|
|
21286
22432
|
appendFileSync: (path, data, options) => {
|
|
21287
22433
|
const encoding = typeof options === "object" && options ? options.encoding : options === "buffer" ? void 0 : options ?? void 0;
|
|
21288
|
-
volume.appendFileSync(abs(path),
|
|
22434
|
+
volume.appendFileSync(abs(path), bytes2(data, encoding ?? void 0));
|
|
21289
22435
|
},
|
|
21290
22436
|
existsSync: (path) => {
|
|
21291
22437
|
try {
|
|
@@ -21303,7 +22449,7 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21303
22449
|
if (typeof options === "object" && options?.withFileTypes) {
|
|
21304
22450
|
return names.map((name) => new Dirent(name, new Stats2(volume.lstatSync(join(dir3, name))), dir3));
|
|
21305
22451
|
}
|
|
21306
|
-
if ((typeof options === "string" ? options : options?.encoding) === "buffer") return names.map((name) =>
|
|
22452
|
+
if ((typeof options === "string" ? options : options?.encoding) === "buffer") return names.map((name) => Buffer2.from(name));
|
|
21307
22453
|
return names;
|
|
21308
22454
|
},
|
|
21309
22455
|
mkdirSync: (path, options) => {
|
|
@@ -21324,7 +22470,7 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21324
22470
|
renameSync: (from, to) => volume.renameSync(abs(from), abs(to)),
|
|
21325
22471
|
readlinkSync: (path, encoding) => {
|
|
21326
22472
|
const value = volume.readlinkSync(abs(path));
|
|
21327
|
-
return encoding === "buffer" ?
|
|
22473
|
+
return encoding === "buffer" ? Buffer2.from(value) : value;
|
|
21328
22474
|
},
|
|
21329
22475
|
symlinkSync: (target, path) => volume.symlinkSync(target, abs(path)),
|
|
21330
22476
|
linkSync: (from, to) => volume.linkSync(abs(from), abs(to)),
|
|
@@ -21368,7 +22514,7 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21368
22514
|
},
|
|
21369
22515
|
writeSync: (fd, data, offset, length, position) => {
|
|
21370
22516
|
const file3 = requiredFd(fds, fd);
|
|
21371
|
-
const input =
|
|
22517
|
+
const input = bytes2(data);
|
|
21372
22518
|
const chunk = typeof data === "string" ? input : input.subarray(offset ?? 0, (offset ?? 0) + (length ?? input.length));
|
|
21373
22519
|
const old = volume.readFileSync(file3.path);
|
|
21374
22520
|
const start2 = file3.flags.startsWith("a") ? old.length : position ?? file3.position;
|
|
@@ -21380,13 +22526,13 @@ function createFsModule(volume, cwd, stdinPath) {
|
|
|
21380
22526
|
return chunk.length;
|
|
21381
22527
|
},
|
|
21382
22528
|
createReadStream: (path) => {
|
|
21383
|
-
const data =
|
|
21384
|
-
return
|
|
22529
|
+
const data = Buffer2.from(volume.readFileSync(resolveLinks(volume, abs(path))));
|
|
22530
|
+
return streamModule4.Readable.from([data]);
|
|
21385
22531
|
},
|
|
21386
22532
|
createWriteStream: (path, options) => {
|
|
21387
22533
|
const target = abs(path);
|
|
21388
22534
|
let first = true;
|
|
21389
|
-
return new
|
|
22535
|
+
return new streamModule4.Writable({ write(chunk, _encoding, done) {
|
|
21390
22536
|
try {
|
|
21391
22537
|
if (options?.flags?.startsWith("a") || !first) volume.appendFileSync(target, new Uint8Array(chunk));
|
|
21392
22538
|
else volume.writeFileSync(target, new Uint8Array(chunk));
|
|
@@ -21508,12 +22654,12 @@ function requiredFd(fds, fd) {
|
|
|
21508
22654
|
function fsError(code, syscall, path) {
|
|
21509
22655
|
return Object.assign(new Error(`${code}: ${syscall}, '${path}'`), { code, syscall, path });
|
|
21510
22656
|
}
|
|
21511
|
-
function makeOutputStream(write, fd) {
|
|
21512
|
-
const stream = new
|
|
21513
|
-
write(
|
|
22657
|
+
function makeOutputStream(write, fd, isTTY = false) {
|
|
22658
|
+
const stream = new streamModule4.Writable({ write(chunk, _encoding, done) {
|
|
22659
|
+
write(Buffer2.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk));
|
|
21514
22660
|
done();
|
|
21515
22661
|
} });
|
|
21516
|
-
return Object.assign(stream, { fd, isTTY
|
|
22662
|
+
return Object.assign(stream, { fd, isTTY, columns: 80, rows: 24 });
|
|
21517
22663
|
}
|
|
21518
22664
|
var Console = class {
|
|
21519
22665
|
constructor(out, err) {
|
|
@@ -21523,7 +22669,7 @@ var Console = class {
|
|
|
21523
22669
|
out;
|
|
21524
22670
|
err;
|
|
21525
22671
|
log = (...args) => {
|
|
21526
|
-
this.out(
|
|
22672
|
+
this.out(util_module_default.format(...args) + "\n");
|
|
21527
22673
|
};
|
|
21528
22674
|
info = (...args) => {
|
|
21529
22675
|
this.log(...args);
|
|
@@ -21532,20 +22678,20 @@ var Console = class {
|
|
|
21532
22678
|
this.log(...args);
|
|
21533
22679
|
};
|
|
21534
22680
|
warn = (...args) => {
|
|
21535
|
-
this.err(
|
|
22681
|
+
this.err(util_module_default.format(...args) + "\n");
|
|
21536
22682
|
};
|
|
21537
22683
|
error = (...args) => {
|
|
21538
22684
|
this.warn(...args);
|
|
21539
22685
|
};
|
|
21540
22686
|
dir = (value, options) => {
|
|
21541
|
-
this.out(
|
|
22687
|
+
this.out(util_module_default.inspect(value, options) + "\n");
|
|
21542
22688
|
};
|
|
21543
22689
|
trace = (...args) => {
|
|
21544
|
-
this.err(`Trace: ${
|
|
22690
|
+
this.err(`Trace: ${util_module_default.format(...args)}
|
|
21545
22691
|
`);
|
|
21546
22692
|
};
|
|
21547
22693
|
assert = (value, ...args) => {
|
|
21548
|
-
if (!value) this.err(`Assertion failed: ${
|
|
22694
|
+
if (!value) this.err(`Assertion failed: ${util_module_default.format(...args)}
|
|
21549
22695
|
`);
|
|
21550
22696
|
};
|
|
21551
22697
|
group = (...args) => {
|
|
@@ -21567,63 +22713,6 @@ var Console = class {
|
|
|
21567
22713
|
timeLog = (_label = "default") => {
|
|
21568
22714
|
};
|
|
21569
22715
|
};
|
|
21570
|
-
function createReadlineModule(stdin) {
|
|
21571
|
-
class Interface extends EventEmitter3 {
|
|
21572
|
-
constructor(input) {
|
|
21573
|
-
super();
|
|
21574
|
-
this.input = input;
|
|
21575
|
-
input?.on?.("data", (chunk) => {
|
|
21576
|
-
for (const line of String(chunk).split("\n")) this.lines.push(line);
|
|
21577
|
-
while (this.lines.length > 1) this.emit("line", this.lines.shift());
|
|
21578
|
-
});
|
|
21579
|
-
input?.on?.("end", () => this.close());
|
|
21580
|
-
}
|
|
21581
|
-
input;
|
|
21582
|
-
closed = false;
|
|
21583
|
-
lines = [];
|
|
21584
|
-
question(_query, callback) {
|
|
21585
|
-
const answer = this.lines.shift() ?? "";
|
|
21586
|
-
if (callback) {
|
|
21587
|
-
queueMicrotask(() => callback(answer));
|
|
21588
|
-
return;
|
|
21589
|
-
}
|
|
21590
|
-
return Promise.resolve(answer);
|
|
21591
|
-
}
|
|
21592
|
-
prompt() {
|
|
21593
|
-
}
|
|
21594
|
-
setPrompt() {
|
|
21595
|
-
}
|
|
21596
|
-
pause() {
|
|
21597
|
-
return this;
|
|
21598
|
-
}
|
|
21599
|
-
resume() {
|
|
21600
|
-
return this;
|
|
21601
|
-
}
|
|
21602
|
-
write() {
|
|
21603
|
-
}
|
|
21604
|
-
close() {
|
|
21605
|
-
if (this.closed) return;
|
|
21606
|
-
this.closed = true;
|
|
21607
|
-
this.emit("close");
|
|
21608
|
-
}
|
|
21609
|
-
async *[Symbol.asyncIterator]() {
|
|
21610
|
-
while (this.lines.length) yield this.lines.shift();
|
|
21611
|
-
}
|
|
21612
|
-
}
|
|
21613
|
-
const createInterface = (options) => new Interface(options?.input ?? (Array.isArray(options) ? options[0] : stdin()));
|
|
21614
|
-
const noop = () => {
|
|
21615
|
-
};
|
|
21616
|
-
const base = {
|
|
21617
|
-
Interface,
|
|
21618
|
-
createInterface,
|
|
21619
|
-
clearLine: noop,
|
|
21620
|
-
clearScreenDown: noop,
|
|
21621
|
-
cursorTo: noop,
|
|
21622
|
-
moveCursor: noop,
|
|
21623
|
-
emitKeypressEvents: noop
|
|
21624
|
-
};
|
|
21625
|
-
return { ...base, promises: { ...base, Interface, createInterface } };
|
|
21626
|
-
}
|
|
21627
22716
|
function createDnsModule() {
|
|
21628
22717
|
const LOOPBACK = {
|
|
21629
22718
|
localhost: { address: "127.0.0.1", family: 4 },
|
|
@@ -21653,15 +22742,6 @@ function createDnsModule() {
|
|
|
21653
22742
|
}
|
|
21654
22743
|
});
|
|
21655
22744
|
};
|
|
21656
|
-
const notFound = (hostname) => Promise.reject(lookupThrow(hostname));
|
|
21657
|
-
const lookupThrow = (hostname) => {
|
|
21658
|
-
try {
|
|
21659
|
-
lookupSync(hostname);
|
|
21660
|
-
return null;
|
|
21661
|
-
} catch (error) {
|
|
21662
|
-
return error;
|
|
21663
|
-
}
|
|
21664
|
-
};
|
|
21665
22745
|
const promises = {
|
|
21666
22746
|
lookup: async (hostname, options) => {
|
|
21667
22747
|
const entry = lookupSync(hostname);
|
|
@@ -21669,7 +22749,10 @@ function createDnsModule() {
|
|
|
21669
22749
|
},
|
|
21670
22750
|
resolve4: async (hostname) => [lookupSync(hostname).address],
|
|
21671
22751
|
resolve6: async (hostname) => [lookupSync(hostname).address],
|
|
21672
|
-
reverse: async (address) =>
|
|
22752
|
+
reverse: async (address) => {
|
|
22753
|
+
if (address === "127.0.0.1") return ["localhost"];
|
|
22754
|
+
return [lookupSync(address).address];
|
|
22755
|
+
}
|
|
21673
22756
|
};
|
|
21674
22757
|
return {
|
|
21675
22758
|
lookup,
|
|
@@ -21810,33 +22893,78 @@ var ERRNO_CONSTANTS = {
|
|
|
21810
22893
|
};
|
|
21811
22894
|
function createTrackedTimers() {
|
|
21812
22895
|
const live = /* @__PURE__ */ new Set();
|
|
21813
|
-
const
|
|
22896
|
+
const unrefed = /* @__PURE__ */ new Set();
|
|
22897
|
+
const states = /* @__PURE__ */ new WeakMap();
|
|
22898
|
+
const track = (native) => {
|
|
22899
|
+
const state = { native, active: true, referenced: true };
|
|
22900
|
+
const handle = {
|
|
22901
|
+
ref() {
|
|
22902
|
+
state.referenced = true;
|
|
22903
|
+
unrefed.delete(handle);
|
|
22904
|
+
if (state.active) live.add(handle);
|
|
22905
|
+
state.native?.ref?.();
|
|
22906
|
+
return handle;
|
|
22907
|
+
},
|
|
22908
|
+
unref() {
|
|
22909
|
+
state.referenced = false;
|
|
22910
|
+
live.delete(handle);
|
|
22911
|
+
if (state.active) unrefed.add(handle);
|
|
22912
|
+
state.native?.unref?.();
|
|
22913
|
+
return handle;
|
|
22914
|
+
},
|
|
22915
|
+
hasRef: () => state.referenced,
|
|
22916
|
+
refresh() {
|
|
22917
|
+
state.native?.refresh?.();
|
|
22918
|
+
return handle;
|
|
22919
|
+
},
|
|
22920
|
+
[Symbol.toPrimitive]: () => Number(state.native)
|
|
22921
|
+
};
|
|
22922
|
+
states.set(handle, state);
|
|
21814
22923
|
live.add(handle);
|
|
21815
22924
|
return handle;
|
|
21816
22925
|
};
|
|
22926
|
+
const complete = (handle) => {
|
|
22927
|
+
const state = states.get(handle);
|
|
22928
|
+
if (state) state.active = false;
|
|
22929
|
+
live.delete(handle);
|
|
22930
|
+
unrefed.delete(handle);
|
|
22931
|
+
};
|
|
21817
22932
|
const setTimeoutTracked = (fn, delay, ...args) => {
|
|
21818
|
-
|
|
22933
|
+
let handle;
|
|
22934
|
+
const native = setTimeout(
|
|
21819
22935
|
(...inner) => {
|
|
21820
|
-
|
|
22936
|
+
complete(handle);
|
|
21821
22937
|
fn(...inner);
|
|
21822
22938
|
},
|
|
21823
22939
|
delay,
|
|
21824
22940
|
...args
|
|
21825
22941
|
);
|
|
21826
|
-
|
|
22942
|
+
handle = track(native);
|
|
21827
22943
|
return handle;
|
|
21828
22944
|
};
|
|
21829
22945
|
const setIntervalTracked = (fn, delay, ...args) => track(setInterval(fn, delay, ...args));
|
|
21830
22946
|
const hostSetImmediate = globalThis.setImmediate;
|
|
21831
22947
|
const setImmediateTracked = (fn, ...args) => {
|
|
21832
|
-
|
|
21833
|
-
|
|
22948
|
+
if (!hostSetImmediate) return setTimeoutTracked(fn, 0, ...args);
|
|
22949
|
+
let handle;
|
|
22950
|
+
const native = hostSetImmediate((...inner) => {
|
|
22951
|
+
complete(handle);
|
|
21834
22952
|
fn(...inner);
|
|
21835
|
-
}, ...args)
|
|
21836
|
-
|
|
22953
|
+
}, ...args);
|
|
22954
|
+
handle = track(native);
|
|
21837
22955
|
return handle;
|
|
21838
22956
|
};
|
|
21839
22957
|
const clear2 = (handle, native) => {
|
|
22958
|
+
if (typeof handle === "object" && handle !== null) {
|
|
22959
|
+
const state = states.get(handle);
|
|
22960
|
+
if (state) {
|
|
22961
|
+
state.active = false;
|
|
22962
|
+
live.delete(handle);
|
|
22963
|
+
unrefed.delete(handle);
|
|
22964
|
+
native(state.native);
|
|
22965
|
+
return;
|
|
22966
|
+
}
|
|
22967
|
+
}
|
|
21840
22968
|
live.delete(handle);
|
|
21841
22969
|
native(handle);
|
|
21842
22970
|
};
|
|
@@ -21849,7 +22977,8 @@ function createTrackedTimers() {
|
|
|
21849
22977
|
clearInterval: (handle) => clear2(handle, clearInterval),
|
|
21850
22978
|
clearImmediate: (handle) => clear2(handle, globalThis.clearImmediate ?? clearTimeout)
|
|
21851
22979
|
},
|
|
21852
|
-
pending: () => live.size
|
|
22980
|
+
pending: () => live.size,
|
|
22981
|
+
pendingUnrefed: () => unrefed.size
|
|
21853
22982
|
};
|
|
21854
22983
|
}
|
|
21855
22984
|
function createTimerPromises() {
|
|
@@ -21936,10 +23065,10 @@ function createStreamPromises() {
|
|
|
21936
23065
|
return {
|
|
21937
23066
|
pipeline: (...streams) => new Promise((resolve2, reject) => {
|
|
21938
23067
|
const callback = (error) => error ? reject(error) : resolve2();
|
|
21939
|
-
|
|
23068
|
+
streamModule4.pipeline(...streams, callback);
|
|
21940
23069
|
}),
|
|
21941
23070
|
finished: (stream) => new Promise((resolve2, reject) => {
|
|
21942
|
-
|
|
23071
|
+
streamModule4.finished(stream, (error) => error ? reject(error) : resolve2());
|
|
21943
23072
|
})
|
|
21944
23073
|
};
|
|
21945
23074
|
}
|
|
@@ -22066,26 +23195,26 @@ var MemoryVolume = class {
|
|
|
22066
23195
|
writeFileSync(path, data) {
|
|
22067
23196
|
const key = this.key(path);
|
|
22068
23197
|
this.requireParent(key, "open");
|
|
22069
|
-
const
|
|
23198
|
+
const bytes2 = typeof data === "string" ? encoder6.encode(data) : data.slice();
|
|
22070
23199
|
const current = this.entries.get(key);
|
|
22071
23200
|
if (current?.kind === "directory") throw new VolumeError("EISDIR", "open", key);
|
|
22072
23201
|
if (current?.kind === "symlink") throw new VolumeError("EINVAL", "open", key);
|
|
22073
23202
|
if (current) {
|
|
22074
|
-
current.data =
|
|
23203
|
+
current.data = bytes2;
|
|
22075
23204
|
this.touchChanged(current, true);
|
|
22076
23205
|
} else {
|
|
22077
|
-
this.entries.set(key, this.inode("file", 438,
|
|
23206
|
+
this.entries.set(key, this.inode("file", 438, bytes2));
|
|
22078
23207
|
}
|
|
22079
23208
|
}
|
|
22080
23209
|
appendFileSync(path, data) {
|
|
22081
23210
|
const key = this.key(path);
|
|
22082
|
-
const
|
|
23211
|
+
const bytes2 = typeof data === "string" ? encoder6.encode(data) : data;
|
|
22083
23212
|
const current = this.entries.get(key);
|
|
22084
|
-
if (!current) return this.writeFileSync(key,
|
|
23213
|
+
if (!current) return this.writeFileSync(key, bytes2);
|
|
22085
23214
|
if (current.kind !== "file") throw new VolumeError(current.kind === "directory" ? "EISDIR" : "EINVAL", "open", key);
|
|
22086
|
-
const next = new Uint8Array(current.data.length +
|
|
23215
|
+
const next = new Uint8Array(current.data.length + bytes2.length);
|
|
22087
23216
|
next.set(current.data);
|
|
22088
|
-
next.set(
|
|
23217
|
+
next.set(bytes2, current.data.length);
|
|
22089
23218
|
current.data = next;
|
|
22090
23219
|
this.touchChanged(current, true);
|
|
22091
23220
|
}
|
|
@@ -22359,8 +23488,38 @@ function esbuildUnavailable() {
|
|
|
22359
23488
|
error.code = "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM";
|
|
22360
23489
|
return error;
|
|
22361
23490
|
}
|
|
23491
|
+
var installed = false;
|
|
23492
|
+
function ensureProcessGlobal() {
|
|
23493
|
+
if (installed) return;
|
|
23494
|
+
installed = true;
|
|
23495
|
+
if (typeof globalThis.process !== "undefined") return;
|
|
23496
|
+
Object.defineProperty(globalThis, "process", {
|
|
23497
|
+
value: processShim,
|
|
23498
|
+
writable: true,
|
|
23499
|
+
configurable: true
|
|
23500
|
+
});
|
|
23501
|
+
}
|
|
23502
|
+
|
|
23503
|
+
// src/runtime/host-rolldown.ts
|
|
23504
|
+
async function loadHostRolldownBinding() {
|
|
23505
|
+
if (typeof window !== "undefined" && globalThis.crossOriginIsolated !== true) {
|
|
23506
|
+
throw new Error(
|
|
23507
|
+
"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."
|
|
23508
|
+
);
|
|
23509
|
+
}
|
|
23510
|
+
try {
|
|
23511
|
+
const loaded = await import('@rolldown/binding-wasm32-wasi');
|
|
23512
|
+
return "__fs" in loaded ? { ...loaded } : loaded.default ?? loaded;
|
|
23513
|
+
} catch (error) {
|
|
23514
|
+
if (typeof process !== "undefined" && process.env?.SANDBOXEDJS_DEBUG) {
|
|
23515
|
+
console.error("[sandboxedjs] Rolldown WASI binding unavailable:", error);
|
|
23516
|
+
}
|
|
23517
|
+
throw new Error("The optional Rolldown WASI binding could not be loaded.", { cause: error });
|
|
23518
|
+
}
|
|
23519
|
+
}
|
|
22362
23520
|
|
|
22363
23521
|
// src/runtime/local-runtime-pod.ts
|
|
23522
|
+
init_path();
|
|
22364
23523
|
var WASM_ALIASES = {
|
|
22365
23524
|
esbuild: "esbuild-wasm",
|
|
22366
23525
|
rollup: "@rollup/wasm-node"
|
|
@@ -22372,7 +23531,7 @@ var ProcessExit = class extends Error {
|
|
|
22372
23531
|
}
|
|
22373
23532
|
code;
|
|
22374
23533
|
};
|
|
22375
|
-
var LocalProcess = class extends
|
|
23534
|
+
var LocalProcess = class extends EventEmitter4 {
|
|
22376
23535
|
constructor(task) {
|
|
22377
23536
|
super();
|
|
22378
23537
|
this.task = task;
|
|
@@ -22390,6 +23549,10 @@ var LocalProcess = class extends EventEmitter3 {
|
|
|
22390
23549
|
killed = false;
|
|
22391
23550
|
out = [];
|
|
22392
23551
|
err = [];
|
|
23552
|
+
input;
|
|
23553
|
+
end;
|
|
23554
|
+
inputEnded = false;
|
|
23555
|
+
pendingInput = [];
|
|
22393
23556
|
resolveKilled;
|
|
22394
23557
|
killedPromise = new Promise((resolve2) => {
|
|
22395
23558
|
this.resolveKilled = resolve2;
|
|
@@ -22405,7 +23568,29 @@ var LocalProcess = class extends EventEmitter3 {
|
|
|
22405
23568
|
this.err.push(text2);
|
|
22406
23569
|
this.emit("error", text2);
|
|
22407
23570
|
}
|
|
22408
|
-
|
|
23571
|
+
/**
|
|
23572
|
+
* Deliver input to the running program.
|
|
23573
|
+
*
|
|
23574
|
+
* The program's `process.stdin` does not exist until its task starts, so
|
|
23575
|
+
* anything written before then is held. Dropping it would lose the first
|
|
23576
|
+
* keystrokes of an interactive session, which arrive while the program is
|
|
23577
|
+
* still loading.
|
|
23578
|
+
*/
|
|
23579
|
+
write(data) {
|
|
23580
|
+
if (this.input) this.input(data);
|
|
23581
|
+
else this.pendingInput.push(data);
|
|
23582
|
+
}
|
|
23583
|
+
/** Close the program's input, which a reader sees as end-of-file. */
|
|
23584
|
+
endInput() {
|
|
23585
|
+
this.inputEnded = true;
|
|
23586
|
+
this.end?.();
|
|
23587
|
+
}
|
|
23588
|
+
/** Called by the task once the program's stdin exists. */
|
|
23589
|
+
acceptInput(input, end) {
|
|
23590
|
+
this.input = input;
|
|
23591
|
+
this.end = end;
|
|
23592
|
+
for (const chunk of this.pendingInput.splice(0)) input(chunk);
|
|
23593
|
+
if (this.inputEnded) end();
|
|
22409
23594
|
}
|
|
22410
23595
|
kill(_signal = "SIGTERM") {
|
|
22411
23596
|
this.killed = true;
|
|
@@ -22517,6 +23702,46 @@ var PodChildProcess = class {
|
|
|
22517
23702
|
}
|
|
22518
23703
|
};
|
|
22519
23704
|
var nextChildPid = 805306368;
|
|
23705
|
+
var liveProcesses = [];
|
|
23706
|
+
var reportingInstalled = false;
|
|
23707
|
+
function reportEscapedError(reason) {
|
|
23708
|
+
const target = liveProcesses.at(-1);
|
|
23709
|
+
if (!target) return false;
|
|
23710
|
+
target.error(formatError(reason));
|
|
23711
|
+
target.exitNow(1);
|
|
23712
|
+
return true;
|
|
23713
|
+
}
|
|
23714
|
+
function trackProcess(proc) {
|
|
23715
|
+
liveProcesses.push(proc);
|
|
23716
|
+
if (!reportingInstalled) {
|
|
23717
|
+
reportingInstalled = true;
|
|
23718
|
+
installEscapedErrorReporting();
|
|
23719
|
+
}
|
|
23720
|
+
return () => {
|
|
23721
|
+
const index = liveProcesses.indexOf(proc);
|
|
23722
|
+
if (index >= 0) liveProcesses.splice(index, 1);
|
|
23723
|
+
if (liveProcesses.length === 0) {
|
|
23724
|
+
reportingInstalled = false;
|
|
23725
|
+
removeEscapedErrorReporting();
|
|
23726
|
+
}
|
|
23727
|
+
};
|
|
23728
|
+
}
|
|
23729
|
+
var onNodeRejection = (reason) => {
|
|
23730
|
+
if (!reportEscapedError(reason)) throw reason;
|
|
23731
|
+
};
|
|
23732
|
+
var onBrowserRejection = (event) => {
|
|
23733
|
+
if (reportEscapedError(event.reason)) event.preventDefault();
|
|
23734
|
+
};
|
|
23735
|
+
function installEscapedErrorReporting() {
|
|
23736
|
+
const host2 = globalThis;
|
|
23737
|
+
if (host2.process?.on && host2.process.versions?.node) host2.process.on("unhandledRejection", onNodeRejection);
|
|
23738
|
+
else host2.addEventListener?.("unhandledrejection", onBrowserRejection);
|
|
23739
|
+
}
|
|
23740
|
+
function removeEscapedErrorReporting() {
|
|
23741
|
+
const host2 = globalThis;
|
|
23742
|
+
if (host2.process?.off && host2.process.versions?.node) host2.process.off("unhandledRejection", onNodeRejection);
|
|
23743
|
+
else host2.removeEventListener?.("unhandledrejection", onBrowserRejection);
|
|
23744
|
+
}
|
|
22520
23745
|
var DRAIN_TURNS = 4;
|
|
22521
23746
|
var LocalRuntimePod = class _LocalRuntimePod {
|
|
22522
23747
|
volume = new MemoryVolume();
|
|
@@ -22545,7 +23770,9 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22545
23770
|
aliases;
|
|
22546
23771
|
modules;
|
|
22547
23772
|
esbuild;
|
|
23773
|
+
rolldownBinding;
|
|
22548
23774
|
constructor(options) {
|
|
23775
|
+
ensureProcessGlobal();
|
|
22549
23776
|
this.workdir = options.workdir ?? "/";
|
|
22550
23777
|
this.env = { ...options.env };
|
|
22551
23778
|
this.aliases = { ...WASM_ALIASES, ...options.aliases };
|
|
@@ -22577,8 +23804,10 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22577
23804
|
const env2 = { ...this.env, ...isRecord(options.env) ? options.env : {} };
|
|
22578
23805
|
const owner = `${this.instanceId}:${Math.random().toString(36).slice(2)}`;
|
|
22579
23806
|
return new LocalProcess(async (proc) => {
|
|
23807
|
+
await this.prepareRolldown(cwd, env2);
|
|
23808
|
+
const untrack = trackProcess(proc);
|
|
22580
23809
|
let requestedExit = 0;
|
|
22581
|
-
let
|
|
23810
|
+
let engine;
|
|
22582
23811
|
const core = createCoreModules({
|
|
22583
23812
|
volume: this.volume,
|
|
22584
23813
|
cwd,
|
|
@@ -22586,16 +23815,24 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22586
23815
|
argv: Array.isArray(options.argv) ? options.argv : ["/usr/bin/node", script, ...args.slice(1)],
|
|
22587
23816
|
stdout: (text2) => proc.output(text2),
|
|
22588
23817
|
stderr: (text2) => proc.error(text2),
|
|
23818
|
+
/* `process.exit` ends the process either way. The throw is only to
|
|
23819
|
+
* abandon the rest of a module body still running synchronously —
|
|
23820
|
+
* thrown from a later callback it would escape into whichever library
|
|
23821
|
+
* scheduled that callback and look like an unrelated crash. */
|
|
22589
23822
|
onExit: (code) => {
|
|
22590
23823
|
requestedExit = code;
|
|
22591
|
-
if (evaluating) throw new ProcessExit(code);
|
|
22592
23824
|
proc.exitNow(code);
|
|
23825
|
+
if (engine?.isEvaluating) throw new ProcessExit(code);
|
|
22593
23826
|
},
|
|
22594
23827
|
http: { router: this.router, owner },
|
|
22595
23828
|
spawnChild: (config) => this.processManager.spawn(config),
|
|
22596
|
-
...typeof options.stdinPath === "string" ? { stdinPath: options.stdinPath } : {}
|
|
23829
|
+
...typeof options.stdinPath === "string" ? { stdinPath: options.stdinPath } : {},
|
|
23830
|
+
...options.interactiveStdin ? { interactiveStdin: true } : {},
|
|
23831
|
+
...options.tty ? { tty: true } : {},
|
|
23832
|
+
onRawMode: (enabled) => proc.emit("rawmode", enabled)
|
|
22597
23833
|
});
|
|
22598
|
-
|
|
23834
|
+
proc.acceptInput((data) => core.writeStdin(data), () => core.endStdin());
|
|
23835
|
+
engine = new CommonJsEngine(this.volume, {
|
|
22599
23836
|
cwd,
|
|
22600
23837
|
builtins: core.builtins,
|
|
22601
23838
|
globals: core.globals,
|
|
@@ -22603,22 +23840,38 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22603
23840
|
overrides: this.modules
|
|
22604
23841
|
});
|
|
22605
23842
|
try {
|
|
22606
|
-
|
|
22607
|
-
|
|
22608
|
-
} finally {
|
|
22609
|
-
evaluating = false;
|
|
22610
|
-
}
|
|
22611
|
-
await this.settle(owner, core.pendingHandles);
|
|
23843
|
+
await engine.run(script);
|
|
23844
|
+
await this.settle(owner, core.pendingHandles, core.pendingUnrefed, core.readingStdin);
|
|
22612
23845
|
if (this.router.activePorts(owner).length) {
|
|
22613
23846
|
await proc.waitForKill();
|
|
22614
23847
|
return 137;
|
|
22615
23848
|
}
|
|
22616
23849
|
return requestedExit;
|
|
22617
23850
|
} finally {
|
|
23851
|
+
untrack();
|
|
22618
23852
|
this.router.closeOwner(owner);
|
|
22619
23853
|
}
|
|
22620
23854
|
});
|
|
22621
23855
|
}
|
|
23856
|
+
/**
|
|
23857
|
+
* Rolldown's JavaScript API synchronously requires its compiled binding.
|
|
23858
|
+
* When a project contains Rolldown, preload the official WASI build in the
|
|
23859
|
+
* host and expose it through the module override table before evaluation.
|
|
23860
|
+
* Keeping this demand-driven avoids adding WASM startup cost to ordinary
|
|
23861
|
+
* shells and Node programs.
|
|
23862
|
+
*/
|
|
23863
|
+
async prepareRolldown(cwd, env2) {
|
|
23864
|
+
const specifier = "@rolldown/binding-wasm32-wasi";
|
|
23865
|
+
if (!this.modules[specifier] && packageInstalled(this.volume, cwd, "rolldown")) {
|
|
23866
|
+
this.rolldownBinding ??= loadHostRolldownBinding();
|
|
23867
|
+
const binding = await this.rolldownBinding;
|
|
23868
|
+
if (binding) this.modules[specifier] = binding;
|
|
23869
|
+
}
|
|
23870
|
+
if (this.modules[specifier]) {
|
|
23871
|
+
syncRolldownFileSystem(this.modules[specifier], this.volume, cwd);
|
|
23872
|
+
env2.NAPI_RS_FORCE_WASI ??= "true";
|
|
23873
|
+
}
|
|
23874
|
+
}
|
|
22622
23875
|
/**
|
|
22623
23876
|
* Wait until the process has either started serving or genuinely run out of
|
|
22624
23877
|
* work.
|
|
@@ -22634,12 +23887,18 @@ var LocalRuntimePod = class _LocalRuntimePod {
|
|
|
22634
23887
|
* A plain script that has genuinely finished falls straight through both,
|
|
22635
23888
|
* costing a handful of empty turns.
|
|
22636
23889
|
*/
|
|
22637
|
-
async settle(owner, pendingHandles) {
|
|
23890
|
+
async settle(owner, pendingHandles, pendingUnrefed, readingStdin) {
|
|
22638
23891
|
for (let turn = 0; turn < DRAIN_TURNS; turn++) {
|
|
22639
23892
|
if (this.router.activePorts(owner).length) return;
|
|
22640
23893
|
await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
22641
23894
|
}
|
|
22642
|
-
|
|
23895
|
+
if (pendingHandles() === 0 && pendingUnrefed() > 0 && !readingStdin()) {
|
|
23896
|
+
const deadline = Date.now() + 1e3;
|
|
23897
|
+
while (!this.router.activePorts(owner).length && Date.now() < deadline) {
|
|
23898
|
+
await new Promise((resolve2) => setTimeout(resolve2, 5));
|
|
23899
|
+
}
|
|
23900
|
+
}
|
|
23901
|
+
while (!this.router.activePorts(owner).length && (pendingHandles() > 0 || readingStdin())) {
|
|
22643
23902
|
await new Promise((resolve2) => setTimeout(resolve2, 5));
|
|
22644
23903
|
}
|
|
22645
23904
|
}
|
|
@@ -22691,6 +23950,60 @@ function formatError(error) {
|
|
|
22691
23950
|
function isRecord(value) {
|
|
22692
23951
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22693
23952
|
}
|
|
23953
|
+
function packageInstalled(volume, cwd, wanted) {
|
|
23954
|
+
for (let dir3 = clean(cwd); ; dir3 = dirname(dir3)) {
|
|
23955
|
+
if (packageTreeContains(volume, join(dir3, "node_modules"), wanted, /* @__PURE__ */ new Set())) return true;
|
|
23956
|
+
if (dir3 === "/") return false;
|
|
23957
|
+
}
|
|
23958
|
+
}
|
|
23959
|
+
function packageTreeContains(volume, modulesRoot, wanted, visited) {
|
|
23960
|
+
if (visited.has(modulesRoot) || !directory(volume, modulesRoot)) return false;
|
|
23961
|
+
visited.add(modulesRoot);
|
|
23962
|
+
if (directory(volume, join(modulesRoot, wanted))) return true;
|
|
23963
|
+
for (const entry of volume.readdirSync(modulesRoot)) {
|
|
23964
|
+
if (entry === ".bin") continue;
|
|
23965
|
+
const first = join(modulesRoot, entry);
|
|
23966
|
+
const packages = entry.startsWith("@") && directory(volume, first) ? volume.readdirSync(first).map((name) => join(first, name)) : [first];
|
|
23967
|
+
for (const root of packages) {
|
|
23968
|
+
if (directory(volume, root) && packageTreeContains(volume, join(root, "node_modules"), wanted, visited)) {
|
|
23969
|
+
return true;
|
|
23970
|
+
}
|
|
23971
|
+
}
|
|
23972
|
+
}
|
|
23973
|
+
return false;
|
|
23974
|
+
}
|
|
23975
|
+
function directory(volume, path) {
|
|
23976
|
+
try {
|
|
23977
|
+
return volume.lstatSync(path).isDirectory();
|
|
23978
|
+
} catch {
|
|
23979
|
+
return false;
|
|
23980
|
+
}
|
|
23981
|
+
}
|
|
23982
|
+
function syncRolldownFileSystem(binding, volume, root) {
|
|
23983
|
+
const fs = binding?.__fs;
|
|
23984
|
+
if (!fs?.mkdirSync || !fs?.writeFileSync) return;
|
|
23985
|
+
try {
|
|
23986
|
+
fs.rmSync?.(root, { recursive: true, force: true });
|
|
23987
|
+
} catch {
|
|
23988
|
+
}
|
|
23989
|
+
const copy = (path) => {
|
|
23990
|
+
const stat2 = volume.lstatSync(path);
|
|
23991
|
+
if (stat2.isDirectory()) {
|
|
23992
|
+
fs.mkdirSync(path, { recursive: true });
|
|
23993
|
+
for (const name of volume.readdirSync(path)) copy(join(path, name));
|
|
23994
|
+
} else if (stat2.isSymbolicLink()) {
|
|
23995
|
+
fs.mkdirSync(dirname(path), { recursive: true });
|
|
23996
|
+
try {
|
|
23997
|
+
fs.symlinkSync(volume.readlinkSync(path), path);
|
|
23998
|
+
} catch {
|
|
23999
|
+
}
|
|
24000
|
+
} else if (!path.endsWith(".node")) {
|
|
24001
|
+
fs.mkdirSync(dirname(path), { recursive: true });
|
|
24002
|
+
fs.writeFileSync(path, volume.readFileSync(path));
|
|
24003
|
+
}
|
|
24004
|
+
};
|
|
24005
|
+
copy(clean(root));
|
|
24006
|
+
}
|
|
22694
24007
|
|
|
22695
24008
|
// src/container/container.ts
|
|
22696
24009
|
var Container = class _Container {
|
|
@@ -22771,9 +24084,9 @@ var Container = class _Container {
|
|
|
22771
24084
|
}
|
|
22772
24085
|
mountSync(files, opts) {
|
|
22773
24086
|
this.assertActive();
|
|
22774
|
-
const
|
|
24087
|
+
const base2 = opts.cwd ?? this.defaults.cwd;
|
|
22775
24088
|
for (const [key, content] of Object.entries(files)) {
|
|
22776
|
-
const abs = resolve(
|
|
24089
|
+
const abs = resolve(base2, key);
|
|
22777
24090
|
const parent = dirname(abs);
|
|
22778
24091
|
if (!this.kernel.vfs.lexists(parent)) {
|
|
22779
24092
|
this.kernel.vfs.mkdir(parent, { recursive: true, mode: 493, cred: this.defaults.cred });
|
|
@@ -23015,17 +24328,17 @@ var Container = class _Container {
|
|
|
23015
24328
|
body: init.body ?? null
|
|
23016
24329
|
});
|
|
23017
24330
|
const bodyRaw = res.body;
|
|
23018
|
-
const
|
|
24331
|
+
const bytes2 = bodyRaw instanceof Uint8Array ? bodyRaw : (
|
|
23019
24332
|
// The binary dispatcher answers with an ArrayBuffer.
|
|
23020
24333
|
bodyRaw instanceof ArrayBuffer ? new Uint8Array(bodyRaw) : typeof bodyRaw === "string" ? new TextEncoder().encode(bodyRaw) : new Uint8Array(0)
|
|
23021
24334
|
);
|
|
23022
|
-
const body = typeof bodyRaw === "string" ? bodyRaw : new TextDecoder().decode(
|
|
24335
|
+
const body = typeof bodyRaw === "string" ? bodyRaw : new TextDecoder().decode(bytes2);
|
|
23023
24336
|
return {
|
|
23024
24337
|
status: res.statusCode ?? 200,
|
|
23025
24338
|
statusText: res.statusMessage ?? "",
|
|
23026
24339
|
headers: res.headers ?? {},
|
|
23027
24340
|
body,
|
|
23028
|
-
bytes,
|
|
24341
|
+
bytes: bytes2,
|
|
23029
24342
|
json() {
|
|
23030
24343
|
return JSON.parse(body);
|
|
23031
24344
|
}
|
|
@@ -23034,7 +24347,7 @@ var Container = class _Container {
|
|
|
23034
24347
|
/**
|
|
23035
24348
|
* Deliver a request whose body is bytes, without letting them become text.
|
|
23036
24349
|
*
|
|
23037
|
-
*
|
|
24350
|
+
* A RuntimePod's public `request()` may run the body through `toString("utf8")` on
|
|
23038
24351
|
* its way in, so anything above `0x7f` is replaced: a five-byte payload
|
|
23039
24352
|
* containing `0x89` and `0xff` arrives as nine. That silently destroys every
|
|
23040
24353
|
* upload — an image or a video reaches the server the wrong size and no
|
|
@@ -23136,7 +24449,7 @@ var Container = class _Container {
|
|
|
23136
24449
|
assertActive() {
|
|
23137
24450
|
if (this.disposed) throw new Error("container has been disposed");
|
|
23138
24451
|
}
|
|
23139
|
-
/** Tear down every process and release the
|
|
24452
|
+
/** Tear down every process and release the runtime pod. */
|
|
23140
24453
|
dispose() {
|
|
23141
24454
|
if (this.disposed) return;
|
|
23142
24455
|
this.disposed = true;
|
|
@@ -23255,7 +24568,7 @@ var Terminal = class {
|
|
|
23255
24568
|
this.currentStdin?.end();
|
|
23256
24569
|
return;
|
|
23257
24570
|
}
|
|
23258
|
-
this.write(ch === "\r" ? "\r\n" : ch);
|
|
24571
|
+
if (!this.currentStdin?.rawMode) this.write(ch === "\r" ? "\r\n" : ch);
|
|
23259
24572
|
this.currentStdin?.write(ch === "\r" ? "\n" : ch);
|
|
23260
24573
|
return;
|
|
23261
24574
|
}
|
|
@@ -23411,8 +24724,8 @@ var Terminal = class {
|
|
|
23411
24724
|
// ── completion ────────────────────────────────────────────────────────────
|
|
23412
24725
|
complete() {
|
|
23413
24726
|
const left = this.buffer.slice(0, this.cursor);
|
|
23414
|
-
const
|
|
23415
|
-
const word =
|
|
24727
|
+
const match2 = /(\S*)$/.exec(left);
|
|
24728
|
+
const word = match2?.[1] ?? "";
|
|
23416
24729
|
const isFirstWord = left.slice(0, left.length - word.length).trim() === "";
|
|
23417
24730
|
const candidates = isFirstWord && !word.includes("/") ? this.completeCommand(word) : this.completePath(word);
|
|
23418
24731
|
if (candidates.length === 0) return;
|
|
@@ -23517,13 +24830,13 @@ var Terminal = class {
|
|
|
23517
24830
|
this.writePrompt();
|
|
23518
24831
|
}
|
|
23519
24832
|
};
|
|
23520
|
-
function expandPrompt(
|
|
24833
|
+
function expandPrompt(format3, session) {
|
|
23521
24834
|
const shell = session.shell;
|
|
23522
24835
|
const home = shell.vars.get("HOME") ?? "/root";
|
|
23523
24836
|
const cwd = shell.cwd;
|
|
23524
24837
|
const user = shell.kernel.users.nameForUid(shell.cred.uid);
|
|
23525
24838
|
const now = new Date(shell.kernel.now());
|
|
23526
|
-
return
|
|
24839
|
+
return format3.replace(/\\(.)/g, (_, ch) => {
|
|
23527
24840
|
switch (ch) {
|
|
23528
24841
|
case "u":
|
|
23529
24842
|
return user;
|