sandboxedjs 0.1.25 → 0.1.26

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/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 EventEmitter3 from 'events';
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 streamModule3 from 'stream-browserify';
13
- import utilModule from 'util';
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 urlModule from 'url';
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(base, ...parts) {
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 === "" ? base : `${base}/${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 base = idx < 0 ? norm : norm.slice(idx + 1);
263
- if (ext && base !== ext && base.endsWith(ext)) base = base.slice(0, -ext.length);
264
- return base;
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 base = basename(p);
268
- const idx = base.lastIndexOf(".");
269
- return idx <= 0 ? "" : base.slice(idx);
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 base = Number(baseMatch[1]);
1040
- if (base < 2 || base > 64) throw new ArithError(`invalid arithmetic base (error token is "${baseMatch[1]}")`);
1041
- out.push({ kind: "num", value: baseMatch[0], num: parseInBase(baseMatch[2], base) });
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, base) {
1085
+ function parseInBase(text2, base2) {
1089
1086
  let value = 0;
1090
1087
  for (const ch of text2) {
1091
1088
  let digit;
1092
- if (base <= 36) {
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 >= base) throw new ArithError(`value too great for base (error token is "${text2}")`);
1098
- value = value * base + digit;
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 base = this.unary();
1330
+ const base2 = this.unary();
1334
1331
  if (this.eat("**")) {
1335
1332
  const exp = this.power();
1336
- return Math.trunc(Math.pow(base, exp));
1333
+ return Math.trunc(Math.pow(base2, exp));
1337
1334
  }
1338
- return base;
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 matches2 = glob(ctx.vfs, pattern, {
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 (matches2.length === 0) {
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 matches2;
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(format, args) {
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(format, args, argIndex);
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(format, args, startIndex) {
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 < format.length) {
2613
- const c = format[i];
2609
+ while (i < format3.length) {
2610
+ const c = format3[i];
2614
2611
  if (c === "\\") {
2615
- decodeEscapes(format.slice(i, i + 12), { stopAtC: true });
2616
- const single = decodeSingleEscape(format, i);
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 (format[i + 1] === "%") {
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(format.slice(i));
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 format = args[start2];
2843
- if (format === void 0) {
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(format, args.slice(start2 + 1));
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 describe = args.includes("-v") || args.includes("-V");
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 (describe) {
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 render = (p) => home && p.startsWith(home) ? "~" + p.slice(home.length) : p;
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)} ${render(entry)}
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(render).join(" ") + "\n");
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 bytes = typeof data === "string" ? encoder.encode(data) : data;
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(bytes, opts.append ?? false);
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, bytes);
4474
- else this.volume.writeFileSync(real, bytes);
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 bytes = 0;
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
- bytes += st.size;
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 bytes = toBytes(data);
4792
- if (bytes.length === 0) return;
4793
- this.chunks.push(bytes);
4794
- this.buffered += bytes.length;
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 bytes = toBytes(data);
4924
- if (bytes.length === 0) return;
4925
- this.chunks.push(bytes);
4926
- this.total += bytes.length;
4927
- this.onWrite?.(bytes);
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 base = binary ? 1024 : 1e3;
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(base, exp));
5563
+ return Math.round(value * Math.pow(base2, exp));
5559
5564
  }
5560
5565
 
5561
5566
  // src/kernel/command.ts
@@ -6867,22 +6872,22 @@ var NetworkStack = class {
6867
6872
  `;
6868
6873
  return out;
6869
6874
  }
6870
- countTx(bytes, iface = "eth0") {
6875
+ countTx(bytes2, iface = "eth0") {
6871
6876
  const i = this.interface(iface);
6872
6877
  if (!i) return;
6873
- i.txBytes += bytes;
6874
- i.txPackets += Math.max(1, Math.ceil(bytes / 1400));
6878
+ i.txBytes += bytes2;
6879
+ i.txPackets += Math.max(1, Math.ceil(bytes2 / 1400));
6875
6880
  }
6876
- countRx(bytes, iface = "eth0") {
6881
+ countRx(bytes2, iface = "eth0") {
6877
6882
  const i = this.interface(iface);
6878
6883
  if (!i) return;
6879
- i.rxBytes += bytes;
6880
- i.rxPackets += Math.max(1, Math.ceil(bytes / 1400));
6884
+ i.rxBytes += bytes2;
6885
+ i.rxPackets += Math.max(1, Math.ceil(bytes2 / 1400));
6881
6886
  }
6882
6887
  };
6883
6888
  function randomMac() {
6884
- const bytes = [2, 66, 172, 17, 0, 2];
6885
- return bytes.map((b) => b.toString(16).padStart(2, "0")).join(":");
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 tag = rawTag.replace(/['"\\]/g, "");
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 === tag) {
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 \`${tag}')`, opToken.pos);
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 quote2 = null;
8765
+ let quote3 = null;
8761
8766
  for (let i = 0; i < text2.length; i++) {
8762
8767
  const c = text2[i];
8763
- if (quote2) {
8764
- if (c === quote2) quote2 = null;
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
- quote2 = c;
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 bytes = await ctx.stdin.readAll();
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 ok = true;
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
- ok = false;
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
- ok = false;
8949
+ ok2 = false;
8945
8950
  }
8946
8951
  }
8947
- return { sources, ok };
8952
+ return { sources, ok: ok2 };
8948
8953
  }
8949
- function splitLines(bytes) {
8950
- const text2 = decoder3.decode(bytes);
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(bytes, opts = {}) {
8963
- const base = opts.si ? 1e3 : 1024;
8967
+ function humanSize(bytes2, opts = {}) {
8968
+ const base2 = opts.si ? 1e3 : 1024;
8964
8969
  const units = opts.si ? SI_UNITS : IEC_UNITS;
8965
- if (bytes < base) return String(bytes);
8966
- let value = bytes;
8970
+ if (bytes2 < base2) return String(bytes2);
8971
+ let value = bytes2;
8967
8972
  let unit = 0;
8968
- while (value >= base && unit < units.length - 1) {
8969
- value /= base;
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 bytes;
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
- bytes = await ctx.stdin.readAll();
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
- bytes = ctx.vfs.readFile(abs, ctx.cred);
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(bytes);
9289
+ ctx.write(bytes2);
9285
9290
  continue;
9286
9291
  }
9287
- const text2 = new TextDecoder().decode(bytes);
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 format = args.str("format") ?? args.str("printf");
9878
- if (format) {
9879
- ctx.write(expandStatFormat(format, abs, st, ctx) + (args.str("printf") ? "" : "\n"));
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(format, path, st, ctx) {
9912
- return format.replace(/%(.)/g, (_, ch) => {
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 render = (value) => args.has("human-readable") ? humanSize(value) : String(asBytes ? value : Math.max(1, Math.ceil(value / 1024)));
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(`${render(st.size)} ${abs}`);
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(`${render(sum)} ${abs}`);
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(`${render(total)} total`);
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 match = mounts.filter((m) => contains(m.mountpoint, abs)).sort((a, b) => b.mountpoint.length - a.mountpoint.length)[0];
10032
- if (match) selected.set(match.mountpoint, match);
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 bytes = ctx.vfs.readFile(abs, ctx.cred).subarray(0, 512);
10142
- const magic = [...bytes.subarray(0, 4)];
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(bytes);
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 format = ctx.args[0];
10223
- if (format === void 0) return ctx.fail("usage: printf FORMAT [ARGUMENT]...", 2);
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(format, ctx.args.slice(1)));
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 format = args.str("format");
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 format ? formatPrintf(format, [String(v)]) : text2;
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(format, d) {
10650
+ function strftime(format3, d) {
10646
10651
  const pad2 = (n, w = 2, c = "0") => String(n).padStart(w, c);
10647
- return format.replace(/%([-_0^#]?)(\d*)([a-zA-Z%])/g, (_, flag, width, ch) => {
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 matches2 = ctx.kernel.procs.list({ comm: name });
10866
- if (matches2.length === 0) {
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 matches2) proc.deliver(signal);
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 matches2 = ctx.kernel.procs.list().filter((p) => re.test(args.has("f") ? p.cmdline : p.comm));
10886
- for (const proc of matches2) {
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 matches2.length ? 0 : 1;
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, match) {
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(match[0]);
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(match[Number(next)] ?? "");
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 = ok ? 0 : 1;
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 match;
11743
- while ((match = re.exec(input)) !== null) {
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, match.index) + applyReplacement(replacement, match);
11748
- last = match.index + match[0].length;
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 (match[0] === "") re.lastIndex++;
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 base = this.parsePostfix(noGt);
12412
+ const base2 = this.parsePostfix(noGt);
12408
12413
  if (this.isOp("^") || this.isOp("**")) {
12409
12414
  this.i++;
12410
- return { t: "binary", op: "^", left: base, right: this.parseUnary(noGt) };
12415
+ return { t: "binary", op: "^", left: base2, right: this.parseUnary(noGt) };
12411
12416
  }
12412
- return base;
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, format) {
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(format, [String(n)]);
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 match = groups[0];
13021
+ const match2 = groups[0];
13017
13022
  return replacement.replace(/\\?&|\\\\/g, (token) => {
13018
- if (token === "&") return match;
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 format = str(0);
13045
+ const format3 = str(0);
13041
13046
  const rest = args.slice(1).map((a) => this.outputStr(this.evaluate(a)));
13042
- return Value.fromString(formatPrintf(format, rest));
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 format = this.toStr(this.evaluate(stmt.args[0]));
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(format, rest), stmt.redirect);
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 bytes = ctx.vfs.readFile(ctx.path(operand), ctx.cred);
13495
- inputs.push({ name: operand, lines: splitLines(bytes).lines });
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 bytes = ctx.vfs.readFile(ctx.path(path), ctx.cred);
13643
+ const bytes2 = ctx.vfs.readFile(ctx.path(path), ctx.cred);
13639
13644
  const previous = offsets.get(path) ?? 0;
13640
- if (bytes.length > previous) {
13641
- ctx.write(bytes.subarray(previous));
13642
- offsets.set(path, bytes.length);
13643
- } else if (bytes.length < previous) {
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 bytes = await ctx.stdin.readAll();
14027
- ctx.write(bytes);
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, bytes, { cred: ctx.cred });
14033
- else ctx.vfs.writeFile(abs, bytes, { cred: ctx.cred });
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 ok ? 0 : 1;
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 bytes = sources[0]?.bytes ?? new Uint8Array(0);
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 < bytes.length; i += size) chunks.push(bytes.subarray(i, i + size));
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(bytes);
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 ok ? 0 : 1;
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 bytes;
14570
+ let bytes2;
14566
14571
  if (target === "-") {
14567
- bytes = await ctx.stdin.readAll();
14572
+ bytes2 = await ctx.stdin.readAll();
14568
14573
  } else {
14569
14574
  try {
14570
- bytes = ctx.vfs.readFile(ctx.path(target), ctx.cred);
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(bytes);
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 (!ok || sources.length < 2) return 2;
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 (!ok) return 2;
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(bytes) {
15239
+ function toHex(bytes2) {
15235
15240
  let out = "";
15236
- for (const byte of bytes) out += byte.toString(16).padStart(2, "0");
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 bytes = encoder4.encode(value);
15365
- for (let i = 0; i < length; i++) block[offset + i] = i < bytes.length ? bytes[i] : 0;
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 bytes2 = createTar(entries2);
15517
- if (compressed) bytes2 = await gzip(bytes2);
15518
- if (archive === void 0 || archive === "-") ctx.write(bytes2);
15519
- else ctx.vfs.writeFile(ctx.path(archive), bytes2, { cred: ctx.cred, mode: 420 });
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 bytes;
15523
- if (archive === void 0 || archive === "-") bytes = await ctx.stdin.readAll();
15527
+ let bytes2;
15528
+ if (archive === void 0 || archive === "-") bytes2 = await ctx.stdin.readAll();
15524
15529
  else {
15525
15530
  try {
15526
- bytes = ctx.vfs.readFile(ctx.path(archive), ctx.cred);
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 (bytes[0] === 31 && bytes[1] === 139) bytes = await gunzip(bytes);
15532
- const entries = readTar(bytes);
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 ok ? 0 : 1;
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 bytes = ctx.vfs.readFile(ctx.path(name), ctx.cred);
15711
- const actual = await digestHex(algorithm, bytes);
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 ok && failures === 0 && checked > 0 ? 0 : 1;
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 ok ? 0 : 1;
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 wrap = args.num("wrap", 76);
15783
- if (wrap <= 0) {
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 += wrap) ctx.line(encoded.slice(i, i + wrap));
15792
+ for (let i = 0; i < encoded.length; i += wrap2) ctx.line(encoded.slice(i, i + wrap2));
15788
15793
  }
15789
- return ok ? 0 : 1;
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 wrap = args.num("wrap", 76);
15833
- for (let i = 0; i < out.length; i += wrap) ctx.line(out.slice(i, i + wrap));
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 ok ? 0 : 1;
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
- const response = await fetch(url.toString(), {
15926
- method: init.method,
15927
- headers: init.headers,
15928
- ...init.body ? { body: init.body.slice().buffer } : {}
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 ok ? 0 : 1;
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 (ctx.stdin.interactive || ctx.stdin.isTTY) {
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) break;
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 bytes = await ctx.stdin.readAll();
17079
- if (bytes.length === 0) return null;
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, bytes, { privileged: true, mode: 384 });
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 base = ctx.path(operand);
17217
- const candidates = [base, `${base}.js`, `${base}.mjs`, `${base}.cjs`, `${base}.json`];
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 bytes = encoder7.encode(stdinText);
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, bytes.length - offset);
17799
- buffer.set(bytes.subarray(offset, offset + take));
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 bytes = await ctx.stdin.readAll();
17942
- return bytes.length ? new TextDecoder().decode(bytes) : null;
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 import('@ffmpeg/core');
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 bytes = wasm.buffer.slice(
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(bytes) };
18090
+ return { factory, module: await WebAssembly.compile(bytes2) };
18064
18091
  })();
18065
18092
  void compiled.catch(() => compiled = null);
18066
18093
  return compiled;
@@ -18135,6 +18162,8 @@ var ffprobe = defineCommand({
18135
18162
  function ffmpegCommands() {
18136
18163
  return [ffmpeg, ffprobe];
18137
18164
  }
18165
+ var platformBuffer = globalThis.Buffer;
18166
+ var Buffer2 = platformBuffer ?? Buffer$1;
18138
18167
 
18139
18168
  // src/pkg/clean-installer.ts
18140
18169
  init_path();
@@ -18178,8 +18207,8 @@ var CleanPackageInstaller = class _CleanPackageInstaller {
18178
18207
  if (!manifest) throw new Error(`No matching version found for ${name}@${range}`);
18179
18208
  const identity = `${name}@${version}`;
18180
18209
  const target = join(modulesRoot, name);
18181
- const installed = this.tryReadJson(join(target, "package.json"));
18182
- if (installed?.version === version) return installed;
18210
+ const installed2 = this.tryReadJson(join(target, "package.json"));
18211
+ if (installed2?.version === version) return installed2;
18183
18212
  if (ancestry.has(identity)) return manifest;
18184
18213
  options.onProgress?.(`Fetching ${identity}`);
18185
18214
  const archive = await this.getTarball(manifest.dist.tarball);
@@ -18271,8 +18300,8 @@ var CleanPackageInstaller = class _CleanPackageInstaller {
18271
18300
  }
18272
18301
  };
18273
18302
  function resolveVersion(metadata, range) {
18274
- const tag = metadata["dist-tags"]?.[range];
18275
- if (tag) return tag;
18303
+ const tag2 = metadata["dist-tags"]?.[range];
18304
+ if (tag2) return tag2;
18276
18305
  if (valid(range) && metadata.versions[range]) return range;
18277
18306
  const found = maxSatisfying(Object.keys(metadata.versions), range === "latest" ? "*" : range, { includePrerelease: false });
18278
18307
  if (!found) throw new Error(`No matching version found for ${metadata.name}@${range}`);
@@ -18286,11 +18315,11 @@ function verifyIntegrity(data, integrity, shasum, identity) {
18286
18315
  const algorithm = choice.slice(0, dash);
18287
18316
  const expected = choice.slice(dash + 1).replace(/\?.*$/, "");
18288
18317
  const digest = algorithm === "sha512" ? sha512(data) : algorithm === "sha256" ? sha256(data) : null;
18289
- if (digest && Buffer$1.from(digest).toString("base64") === expected) return;
18318
+ if (digest && Buffer2.from(digest).toString("base64") === expected) return;
18290
18319
  }
18291
18320
  throw new Error(`Integrity check failed for ${identity}`);
18292
18321
  }
18293
- if (shasum && Buffer$1.from(sha1(data)).toString("hex") === shasum) return;
18322
+ if (shasum && Buffer2.from(sha1(data)).toString("hex") === shasum) return;
18294
18323
  if (shasum) throw new Error(`Legacy checksum check failed for ${identity}`);
18295
18324
  }
18296
18325
  function extractNpmTarball(volume, compressed, destination) {
@@ -18356,11 +18385,11 @@ function safeTarget(destination, name) {
18356
18385
  function stripPackageRoot(name) {
18357
18386
  return name.replace(/^\.\//, "").replace(/^package\//, "").replace(/\/$/, "");
18358
18387
  }
18359
- function text(bytes, start2, length) {
18360
- return new TextDecoder().decode(bytes.subarray(start2, start2 + length)).replace(/\0.*$/, "").trim();
18388
+ function text(bytes2, start2, length) {
18389
+ return new TextDecoder().decode(bytes2.subarray(start2, start2 + length)).replace(/\0.*$/, "").trim();
18361
18390
  }
18362
- function octal(bytes, start2, length) {
18363
- return parseInt(text(bytes, start2, length).replace(/^0+/, "") || "0", 8);
18391
+ function octal(bytes2, start2, length) {
18392
+ return parseInt(text(bytes2, start2, length).replace(/^0+/, "") || "0", 8);
18364
18393
  }
18365
18394
  function parsePax(data) {
18366
18395
  const value = new TextDecoder().decode(data);
@@ -18372,8 +18401,8 @@ function parsePax(data) {
18372
18401
  const length = Number(value.slice(offset, space));
18373
18402
  if (!Number.isFinite(length) || length <= 0) break;
18374
18403
  const record = value.slice(space + 1, offset + length - 1);
18375
- const equal = record.indexOf("=");
18376
- if (equal > 0) result[record.slice(0, equal)] = record.slice(equal + 1);
18404
+ const equal2 = record.indexOf("=");
18405
+ if (equal2 > 0) result[record.slice(0, equal2)] = record.slice(equal2 + 1);
18377
18406
  offset += length;
18378
18407
  }
18379
18408
  return result;
@@ -18947,6 +18976,13 @@ function findLocalBin(ctx, name) {
18947
18976
  }
18948
18977
  async function runInitializer(ctx, args) {
18949
18978
  const [spec, ...rest] = args;
18979
+ if (!spec) {
18980
+ ctx.warn("npm create <initializer>");
18981
+ ctx.warn("");
18982
+ ctx.warn("Runs the package `create-<initializer>`, installing it if needed.");
18983
+ ctx.warn("Example: npm create vite@latest my-app");
18984
+ return 1;
18985
+ }
18950
18986
  const { name, version } = splitPackageSpec(spec);
18951
18987
  const suffix = version ? `@${version}` : "";
18952
18988
  let packageName;
@@ -19049,12 +19085,12 @@ unless the container was created with network: { allowOutbound: true }.`,
19049
19085
  }
19050
19086
  ctx.stderr.write(`npx: installing ${packageSpec}...
19051
19087
  `);
19052
- const installed = await installPackages(ctx, [packageSpec], {
19088
+ const installed2 = await installPackages(ctx, [packageSpec], {
19053
19089
  cwd: root,
19054
19090
  save: false,
19055
19091
  quiet: true
19056
19092
  });
19057
- if (installed !== 0) return installed;
19093
+ if (installed2 !== 0) return installed2;
19058
19094
  if (!findLocalBin(ctx, command)) {
19059
19095
  const binaries = packageBinaries(ctx, root, packageName);
19060
19096
  const chosen = binaries.includes(command) ? command : binaries[0];
@@ -19283,8 +19319,8 @@ var ContainerFs = class {
19283
19319
  return this.kernel.vfs;
19284
19320
  }
19285
19321
  async readFile(path, encoding) {
19286
- const bytes = this.vfs.readFile(clean(path));
19287
- return encoding ? new TextDecoder().decode(bytes) : bytes;
19322
+ const bytes2 = this.vfs.readFile(clean(path));
19323
+ return encoding ? new TextDecoder().decode(bytes2) : bytes2;
19288
19324
  }
19289
19325
  async writeFile(path, data, opts = {}) {
19290
19326
  const abs = clean(path);
@@ -20032,6 +20068,18 @@ var CommonJsEngine = class {
20032
20068
  main = null;
20033
20069
  /** `package.json` per directory; resolution reads them constantly. */
20034
20070
  manifests = /* @__PURE__ */ new Map();
20071
+ evaluationDepth = 0;
20072
+ /**
20073
+ * Is a module body running synchronously right now?
20074
+ *
20075
+ * `process.exit` unwinds by throwing, and that is only safe while one of
20076
+ * this engine's own frames is on the stack to catch it. Thrown from a later
20077
+ * callback — a stream handler, a timer — it would escape into whichever
20078
+ * library called that callback and surface as an unrelated crash.
20079
+ */
20080
+ get isEvaluating() {
20081
+ return this.evaluationDepth > 0;
20082
+ }
20035
20083
  /**
20036
20084
  * Evaluate an entry point.
20037
20085
  *
@@ -20137,7 +20185,13 @@ ${code}
20137
20185
  };
20138
20186
  //# sourceURL=sandboxedjs:${module.filename}`
20139
20187
  )(this.globals);
20140
- const result = factory(...bindings.map(([, value]) => value));
20188
+ this.evaluationDepth++;
20189
+ let result;
20190
+ try {
20191
+ result = factory(...bindings.map(([, value]) => value));
20192
+ } finally {
20193
+ this.evaluationDepth--;
20194
+ }
20141
20195
  if (transformed?.topLevelAwait) module.pending = Promise.resolve(result).then(() => {
20142
20196
  });
20143
20197
  }
@@ -20434,9 +20488,717 @@ function splitSpecifier(specifier) {
20434
20488
  return { name: parts.slice(0, size).join("/"), subpath: parts.slice(size).join("/") };
20435
20489
  }
20436
20490
 
20491
+ // src/runtime/util-module.ts
20492
+ var customInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
20493
+ var promisifyCustom = /* @__PURE__ */ Symbol.for("nodejs.util.promisify.custom");
20494
+ var BREAK_LENGTH = 72;
20495
+ var MAX_ARRAY = 100;
20496
+ function inspect(value, options = {}) {
20497
+ const depth = options.depth === null ? Infinity : options.depth ?? 2;
20498
+ return render(value, depth, /* @__PURE__ */ new Set(), options);
20499
+ }
20500
+ function render(value, depth, seen, options) {
20501
+ switch (typeof value) {
20502
+ case "string":
20503
+ return quote2(value, options.maxStringLength ?? null);
20504
+ case "number":
20505
+ return Object.is(value, -0) ? "-0" : String(value);
20506
+ case "bigint":
20507
+ return `${value}n`;
20508
+ case "boolean":
20509
+ case "undefined":
20510
+ return String(value);
20511
+ case "symbol":
20512
+ return value.toString();
20513
+ case "function":
20514
+ return renderFunction(value);
20515
+ }
20516
+ if (value === null) return "null";
20517
+ const object = value;
20518
+ const custom = object[customInspect];
20519
+ if (typeof custom === "function") {
20520
+ return String(custom.call(object, depth, options));
20521
+ }
20522
+ if (seen.has(object)) return "[Circular *1]";
20523
+ if (depth < 0) return Array.isArray(object) ? "[Array]" : "[Object]";
20524
+ if (value instanceof Error) return renderError(value);
20525
+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
20526
+ if (value instanceof RegExp) return String(value);
20527
+ if (Buffer2.isBuffer(value)) return renderBuffer(value);
20528
+ if (ArrayBuffer.isView(value)) return renderTypedArray(value);
20529
+ seen.add(object);
20530
+ try {
20531
+ if (Array.isArray(value)) return wrap(renderArray(value, depth, seen, options), "[", "]");
20532
+ if (value instanceof Map) return prefixed("Map", value.size, renderMap(value, depth, seen, options));
20533
+ if (value instanceof Set) return prefixed("Set", value.size, renderSet(value, depth, seen, options));
20534
+ if (value instanceof Promise) return "Promise { <pending> }";
20535
+ return renderObject(object, depth, seen, options);
20536
+ } finally {
20537
+ seen.delete(object);
20538
+ }
20539
+ }
20540
+ function renderArray(value, depth, seen, options) {
20541
+ const limit = options.maxArrayLength === null ? Infinity : options.maxArrayLength ?? MAX_ARRAY;
20542
+ const shown = value.slice(0, limit).map((item) => render(item, depth - 1, seen, options));
20543
+ const hidden = value.length - shown.length;
20544
+ if (hidden > 0) shown.push(`... ${hidden} more item${hidden === 1 ? "" : "s"}`);
20545
+ return shown;
20546
+ }
20547
+ function renderMap(value, depth, seen, options) {
20548
+ return [...value].map(
20549
+ ([key, item]) => `${render(key, depth - 1, seen, options)} => ${render(item, depth - 1, seen, options)}`
20550
+ );
20551
+ }
20552
+ function renderSet(value, depth, seen, options) {
20553
+ return [...value].map((item) => render(item, depth - 1, seen, options));
20554
+ }
20555
+ function renderObject(object, depth, seen, options) {
20556
+ const keys = options.showHidden ? Object.getOwnPropertyNames(object) : Object.keys(object);
20557
+ if (options.sorted) keys.sort();
20558
+ const parts = keys.map((key) => {
20559
+ const descriptor = Object.getOwnPropertyDescriptor(object, key);
20560
+ const rendered = descriptor?.get ? descriptor.set ? "[Getter/Setter]" : "[Getter]" : render(object[key], depth - 1, seen, options);
20561
+ return `${propertyKey(key)}: ${rendered}`;
20562
+ });
20563
+ const name = constructorName(object);
20564
+ return wrap(parts, name ? `${name} {` : "{", "}", name ? void 0 : "{}");
20565
+ }
20566
+ function constructorName(object) {
20567
+ const name = Object.getPrototypeOf(object)?.constructor?.name;
20568
+ if (!name || name === "Object") return null;
20569
+ return name;
20570
+ }
20571
+ function renderError(error) {
20572
+ const base2 = error.stack ?? `${error.name}: ${error.message}`;
20573
+ const extra = Object.keys(error).filter((key) => key !== "message" && key !== "stack");
20574
+ if (extra.length === 0) return base2;
20575
+ return `${base2} { ${extra.map((key) => `${propertyKey(key)}: ${inspect(error[key], { depth: 0 })}`).join(", ")} }`;
20576
+ }
20577
+ function renderFunction(value) {
20578
+ const kind = /^class[\s{]/.test(Function.prototype.toString.call(value)) ? "class" : "Function";
20579
+ return value.name ? `[${kind}: ${value.name}]` : `[${kind} (anonymous)]`;
20580
+ }
20581
+ function renderBuffer(value) {
20582
+ const shown = [...value.subarray(0, 50)].map((byte) => byte.toString(16).padStart(2, "0"));
20583
+ const hidden = value.length - shown.length;
20584
+ const tail2 = hidden > 0 ? ` ... ${hidden} more byte${hidden === 1 ? "" : "s"}` : "";
20585
+ return `<Buffer ${shown.join(" ")}${tail2}>`;
20586
+ }
20587
+ function renderTypedArray(value) {
20588
+ const name = value.constructor?.name ?? "TypedArray";
20589
+ const items = [...value].slice(0, MAX_ARRAY);
20590
+ return `${name}(${value.length}) [ ${items.join(", ")} ]`;
20591
+ }
20592
+ function prefixed(name, size, parts) {
20593
+ return wrap(parts, `${name}(${size}) {`, "}", `${name}(0) {}`);
20594
+ }
20595
+ function wrap(parts, open, close, empty) {
20596
+ if (parts.length === 0) return empty ?? `${open}${close}`;
20597
+ const inline = `${open} ${parts.join(", ")} ${close}`;
20598
+ if (inline.length <= BREAK_LENGTH && !inline.includes("\n")) return inline;
20599
+ const indented = parts.map((part) => ` ${part.split("\n").join("\n ")}`);
20600
+ return `${open}
20601
+ ${indented.join(",\n")}
20602
+ ${close}`;
20603
+ }
20604
+ function quote2(value, maxLength) {
20605
+ let text2 = value;
20606
+ let tail2 = "";
20607
+ if (maxLength !== null && text2.length > maxLength) {
20608
+ tail2 = `... ${text2.length - maxLength} more character${text2.length - maxLength === 1 ? "" : "s"}`;
20609
+ text2 = text2.slice(0, maxLength);
20610
+ }
20611
+ const escaped = text2.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/'/g, "\\'");
20612
+ return `'${escaped}'${tail2}`;
20613
+ }
20614
+ function propertyKey(key) {
20615
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : quote2(key, null);
20616
+ }
20617
+ function format(...args) {
20618
+ return formatWithOptions({}, ...args);
20619
+ }
20620
+ function formatWithOptions(options, ...args) {
20621
+ const [first, ...rest] = args;
20622
+ const pieces = [];
20623
+ let index = 0;
20624
+ if (typeof first === "string" && first.includes("%")) {
20625
+ pieces.push(
20626
+ first.replace(/%([sdifjoOc%])/g, (match2, kind) => {
20627
+ if (kind === "%") return "%";
20628
+ if (index >= rest.length) return match2;
20629
+ const value = rest[index++];
20630
+ switch (kind) {
20631
+ case "s":
20632
+ return typeof value === "string" ? value : typeof value === "bigint" ? `${value}n` : typeof value === "object" && value !== null ? inspect(value, { ...options, depth: 0 }) : String(value);
20633
+ case "d":
20634
+ return typeof value === "bigint" ? `${value}n` : String(Number(value));
20635
+ case "i":
20636
+ return typeof value === "bigint" ? `${value}n` : String(parseInt(String(value), 10));
20637
+ case "f":
20638
+ return String(parseFloat(String(value)));
20639
+ case "j":
20640
+ try {
20641
+ return JSON.stringify(value) ?? "undefined";
20642
+ } catch {
20643
+ return "[Circular]";
20644
+ }
20645
+ case "o":
20646
+ return inspect(value, { ...options, showHidden: true, depth: 4 });
20647
+ case "O":
20648
+ return inspect(value, options);
20649
+ case "c":
20650
+ return "";
20651
+ default:
20652
+ return match2;
20653
+ }
20654
+ })
20655
+ );
20656
+ } else if (first !== void 0 || args.length > 0) {
20657
+ pieces.push(typeof first === "string" ? first : inspect(first, options));
20658
+ }
20659
+ for (; index < rest.length; index++) {
20660
+ const value = rest[index];
20661
+ pieces.push(typeof value === "string" ? value : inspect(value, options));
20662
+ }
20663
+ return pieces.join(" ");
20664
+ }
20665
+ function promisify(original) {
20666
+ if (typeof original !== "function") {
20667
+ throw Object.assign(new TypeError('The "original" argument must be of type function'), {
20668
+ code: "ERR_INVALID_ARG_TYPE"
20669
+ });
20670
+ }
20671
+ const override = original[promisifyCustom];
20672
+ if (typeof override === "function") return override;
20673
+ const wrapped = function(...args) {
20674
+ return new Promise((resolve2, reject) => {
20675
+ original.call(this, ...args, (error, ...values) => {
20676
+ if (error) reject(error);
20677
+ else resolve2(values.length > 1 ? values : values[0]);
20678
+ });
20679
+ });
20680
+ };
20681
+ Object.setPrototypeOf(wrapped, Object.getPrototypeOf(original));
20682
+ Object.defineProperty(wrapped, "name", { value: original.name, configurable: true });
20683
+ return wrapped;
20684
+ }
20685
+ promisify.custom = promisifyCustom;
20686
+ function callbackify(original) {
20687
+ return function(...args) {
20688
+ const callback = args.pop();
20689
+ Promise.resolve(original.apply(this, args)).then(
20690
+ (value) => callback(null, value),
20691
+ /* Node guarantees a truthy first argument, so a rejection with a falsy
20692
+ * reason is wrapped rather than passed through as "no error". */
20693
+ (reason) => callback(reason ?? Object.assign(new Error("Promise was rejected with a falsy value"), { reason }))
20694
+ );
20695
+ };
20696
+ }
20697
+ function inherits(constructor, superConstructor) {
20698
+ Object.defineProperty(constructor, "super_", {
20699
+ value: superConstructor,
20700
+ writable: true,
20701
+ configurable: true
20702
+ });
20703
+ Object.setPrototypeOf(constructor.prototype, superConstructor.prototype);
20704
+ }
20705
+ function deprecate(fn, message) {
20706
+ let warned = false;
20707
+ return function(...args) {
20708
+ if (!warned) {
20709
+ warned = true;
20710
+ console.warn(`DeprecationWarning: ${message}`);
20711
+ }
20712
+ return fn.apply(this, args);
20713
+ };
20714
+ }
20715
+ function debuglog(section, callback) {
20716
+ const noop = Object.assign(() => {
20717
+ }, { enabled: false });
20718
+ callback?.(noop);
20719
+ return noop;
20720
+ }
20721
+ var STYLES = {
20722
+ reset: [0, 0],
20723
+ bold: [1, 22],
20724
+ dim: [2, 22],
20725
+ italic: [3, 23],
20726
+ underline: [4, 24],
20727
+ blink: [5, 25],
20728
+ inverse: [7, 27],
20729
+ hidden: [8, 28],
20730
+ strikethrough: [9, 29],
20731
+ doubleunderline: [21, 24],
20732
+ framed: [51, 54],
20733
+ overlined: [53, 55],
20734
+ black: [30, 39],
20735
+ red: [31, 39],
20736
+ green: [32, 39],
20737
+ yellow: [33, 39],
20738
+ blue: [34, 39],
20739
+ magenta: [35, 39],
20740
+ cyan: [36, 39],
20741
+ white: [37, 39],
20742
+ gray: [90, 39],
20743
+ grey: [90, 39],
20744
+ blackBright: [90, 39],
20745
+ redBright: [91, 39],
20746
+ greenBright: [92, 39],
20747
+ yellowBright: [93, 39],
20748
+ blueBright: [94, 39],
20749
+ magentaBright: [95, 39],
20750
+ cyanBright: [96, 39],
20751
+ whiteBright: [97, 39],
20752
+ bgBlack: [40, 49],
20753
+ bgRed: [41, 49],
20754
+ bgGreen: [42, 49],
20755
+ bgYellow: [43, 49],
20756
+ bgBlue: [44, 49],
20757
+ bgMagenta: [45, 49],
20758
+ bgCyan: [46, 49],
20759
+ bgWhite: [47, 49],
20760
+ bgGray: [100, 49],
20761
+ bgGrey: [100, 49],
20762
+ bgBlackBright: [100, 49],
20763
+ bgRedBright: [101, 49],
20764
+ bgGreenBright: [102, 49],
20765
+ bgYellowBright: [103, 49],
20766
+ bgBlueBright: [104, 49],
20767
+ bgMagentaBright: [105, 49],
20768
+ bgCyanBright: [106, 49],
20769
+ bgWhiteBright: [107, 49]
20770
+ };
20771
+ function styleText(format3, text2) {
20772
+ const names = Array.isArray(format3) ? format3 : [format3];
20773
+ let open = "";
20774
+ let close = "";
20775
+ for (const name of names) {
20776
+ const style = STYLES[name];
20777
+ if (!style) {
20778
+ throw Object.assign(new TypeError(`The value "${name}" is invalid for argument 'format'`), {
20779
+ code: "ERR_INVALID_ARG_VALUE"
20780
+ });
20781
+ }
20782
+ open += `\x1B[${style[0]}m`;
20783
+ close = `\x1B[${style[1]}m${close}`;
20784
+ }
20785
+ return `${open}${text2}${close}`;
20786
+ }
20787
+ var tag = (value) => Object.prototype.toString.call(value).slice(8, -1);
20788
+ var types = {
20789
+ isPromise: (value) => value instanceof Promise || tag(value) === "Promise",
20790
+ isDate: (value) => tag(value) === "Date",
20791
+ isRegExp: (value) => tag(value) === "RegExp",
20792
+ isMap: (value) => tag(value) === "Map",
20793
+ isSet: (value) => tag(value) === "Set",
20794
+ isTypedArray: (value) => ArrayBuffer.isView(value) && !(value instanceof DataView),
20795
+ isUint8Array: (value) => value instanceof Uint8Array,
20796
+ isArrayBuffer: (value) => tag(value) === "ArrayBuffer",
20797
+ isArrayBufferView: (value) => ArrayBuffer.isView(value),
20798
+ isDataView: (value) => value instanceof DataView,
20799
+ isNativeError: (value) => value instanceof Error,
20800
+ isProxy: () => false,
20801
+ isAsyncFunction: (value) => tag(value) === "AsyncFunction",
20802
+ isGeneratorFunction: (value) => tag(value) === "GeneratorFunction",
20803
+ isBoxedPrimitive: (value) => ["String", "Number", "Boolean", "Symbol", "BigInt"].includes(tag(value)) && typeof value === "object"
20804
+ };
20805
+ function isDeepStrictEqual(a, b) {
20806
+ if (Object.is(a, b)) return true;
20807
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
20808
+ if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false;
20809
+ if (Array.isArray(a)) {
20810
+ const other = b;
20811
+ return a.length === other.length && a.every((item, index) => isDeepStrictEqual(item, other[index]));
20812
+ }
20813
+ if (a instanceof Date) return a.getTime() === b.getTime();
20814
+ if (a instanceof RegExp) return String(a) === String(b);
20815
+ if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
20816
+ const left = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
20817
+ const right = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
20818
+ return left.length === right.length && left.every((byte, index) => byte === right[index]);
20819
+ }
20820
+ const keys = Object.keys(a);
20821
+ if (keys.length !== Object.keys(b).length) return false;
20822
+ return keys.every(
20823
+ (key) => Object.prototype.hasOwnProperty.call(b, key) && isDeepStrictEqual(a[key], b[key])
20824
+ );
20825
+ }
20826
+ var legacy = {
20827
+ isArray: Array.isArray,
20828
+ isBoolean: (value) => typeof value === "boolean",
20829
+ isNull: (value) => value === null,
20830
+ isNullOrUndefined: (value) => value == null,
20831
+ isNumber: (value) => typeof value === "number",
20832
+ isString: (value) => typeof value === "string",
20833
+ isSymbol: (value) => typeof value === "symbol",
20834
+ isUndefined: (value) => value === void 0,
20835
+ isRegExp: types.isRegExp,
20836
+ isObject: (value) => typeof value === "object" && value !== null,
20837
+ isDate: types.isDate,
20838
+ isError: types.isNativeError,
20839
+ isFunction: (value) => typeof value === "function",
20840
+ isPrimitive: (value) => value === null || typeof value !== "object" && typeof value !== "function",
20841
+ isBuffer: (value) => Buffer2.isBuffer(value)
20842
+ };
20843
+ inspect.custom = customInspect;
20844
+ var utilModule = {
20845
+ format,
20846
+ formatWithOptions,
20847
+ inspect,
20848
+ styleText,
20849
+ promisify,
20850
+ callbackify,
20851
+ inherits,
20852
+ deprecate,
20853
+ debuglog,
20854
+ debug: debuglog,
20855
+ types,
20856
+ isDeepStrictEqual,
20857
+ TextEncoder,
20858
+ TextDecoder,
20859
+ toUSVString: (value) => String(value),
20860
+ stripVTControlCharacters: (value) => value.replace(/\x1B\[[0-9;]*[A-Za-z]/g, ""),
20861
+ ...legacy
20862
+ };
20863
+ var util_module_default = utilModule;
20864
+
20865
+ // src/runtime/assert-module.ts
20866
+ var AssertionError = class extends Error {
20867
+ actual;
20868
+ expected;
20869
+ operator;
20870
+ generatedMessage;
20871
+ name = "AssertionError";
20872
+ code = "ERR_ASSERTION";
20873
+ constructor(options) {
20874
+ const generated = options.message === void 0;
20875
+ super(options.message ?? describe(options.actual, options.expected, options.operator));
20876
+ this.actual = options.actual;
20877
+ this.expected = options.expected;
20878
+ this.operator = options.operator;
20879
+ this.generatedMessage = generated;
20880
+ }
20881
+ };
20882
+ function describe(actual, expected, operator) {
20883
+ if (operator === "fail") return "Failed";
20884
+ const rendered = (value) => inspect(value, { depth: 2 });
20885
+ return `${rendered(actual)} ${operator} ${rendered(expected)}`;
20886
+ }
20887
+ function fail(actual, expected, message, operator) {
20888
+ if (message instanceof Error) throw message;
20889
+ throw new AssertionError({ actual, expected, operator, ...message === void 0 ? {} : { message } });
20890
+ }
20891
+ function ok(value, message) {
20892
+ if (!value) fail(value, true, message, "==");
20893
+ }
20894
+ var equal = (actual, expected, message) => {
20895
+ if (actual != expected) fail(actual, expected, message, "==");
20896
+ };
20897
+ var notEqual = (actual, expected, message) => {
20898
+ if (actual == expected) fail(actual, expected, message, "!=");
20899
+ };
20900
+ var strictEqual = (actual, expected, message) => {
20901
+ if (!Object.is(actual, expected)) fail(actual, expected, message, "strictEqual");
20902
+ };
20903
+ var notStrictEqual = (actual, expected, message) => {
20904
+ if (Object.is(actual, expected)) fail(actual, expected, message, "notStrictEqual");
20905
+ };
20906
+ var deepStrictEqual = (actual, expected, message) => {
20907
+ if (!isDeepStrictEqual(actual, expected)) fail(actual, expected, message, "deepStrictEqual");
20908
+ };
20909
+ var notDeepStrictEqual = (actual, expected, message) => {
20910
+ if (isDeepStrictEqual(actual, expected)) fail(actual, expected, message, "notDeepStrictEqual");
20911
+ };
20912
+ function looseDeepEqual(a, b) {
20913
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
20914
+ return a == b;
20915
+ }
20916
+ if (Array.isArray(a) !== Array.isArray(b)) return false;
20917
+ const keys = Object.keys(a);
20918
+ if (keys.length !== Object.keys(b).length) return false;
20919
+ return keys.every(
20920
+ (key) => looseDeepEqual(a[key], b[key])
20921
+ );
20922
+ }
20923
+ var deepEqual = (actual, expected, message) => {
20924
+ if (!looseDeepEqual(actual, expected)) fail(actual, expected, message, "deepEqual");
20925
+ };
20926
+ var notDeepEqual = (actual, expected, message) => {
20927
+ if (looseDeepEqual(actual, expected)) fail(actual, expected, message, "notDeepEqual");
20928
+ };
20929
+ function matches2(error, expected) {
20930
+ if (expected === void 0) return true;
20931
+ if (expected instanceof RegExp) return expected.test(String(error));
20932
+ if (typeof expected === "function") {
20933
+ if (error instanceof expected) return true;
20934
+ try {
20935
+ return Boolean(expected(error));
20936
+ } catch {
20937
+ return false;
20938
+ }
20939
+ }
20940
+ if (typeof expected === "object" && expected !== null) {
20941
+ return Object.entries(expected).every(
20942
+ ([key, value]) => isDeepStrictEqual(error?.[key], value)
20943
+ );
20944
+ }
20945
+ return String(error) === String(expected);
20946
+ }
20947
+ function throws(block, expected, message) {
20948
+ const [error, threw] = capture(block);
20949
+ if (!threw) fail(void 0, expected, message ?? "Missing expected exception.", "throws");
20950
+ if (!matches2(error, expected)) throw error;
20951
+ }
20952
+ function doesNotThrow(block, expected, message) {
20953
+ const [error, threw] = capture(block);
20954
+ if (!threw) return;
20955
+ if (matches2(error, expected)) {
20956
+ fail(error, expected, message ?? "Got unwanted exception.", "doesNotThrow");
20957
+ }
20958
+ throw error;
20959
+ }
20960
+ async function rejects(block, expected, message) {
20961
+ const [error, threw] = await captureAsync(block);
20962
+ if (!threw) fail(void 0, expected, message ?? "Missing expected rejection.", "rejects");
20963
+ if (!matches2(error, expected)) throw error;
20964
+ }
20965
+ async function doesNotReject(block, expected, message) {
20966
+ const [error, threw] = await captureAsync(block);
20967
+ if (!threw) return;
20968
+ if (matches2(error, expected)) {
20969
+ fail(error, expected, message ?? "Got unwanted rejection.", "doesNotReject");
20970
+ }
20971
+ throw error;
20972
+ }
20973
+ function capture(block) {
20974
+ try {
20975
+ block();
20976
+ return [void 0, false];
20977
+ } catch (error) {
20978
+ return [error, true];
20979
+ }
20980
+ }
20981
+ async function captureAsync(block) {
20982
+ try {
20983
+ await (typeof block === "function" ? block() : block);
20984
+ return [void 0, false];
20985
+ } catch (error) {
20986
+ return [error, true];
20987
+ }
20988
+ }
20989
+ var match = (value, pattern, message) => {
20990
+ if (!pattern.test(value)) fail(value, pattern, message, "match");
20991
+ };
20992
+ var doesNotMatch = (value, pattern, message) => {
20993
+ if (pattern.test(value)) fail(value, pattern, message, "doesNotMatch");
20994
+ };
20995
+ var ifError = (value) => {
20996
+ if (value === null || value === void 0) return;
20997
+ if (value instanceof Error) throw value;
20998
+ fail(value, null, void 0, "ifError");
20999
+ };
21000
+ var base = {
21001
+ AssertionError,
21002
+ ok,
21003
+ equal,
21004
+ notEqual,
21005
+ strictEqual,
21006
+ notStrictEqual,
21007
+ deepEqual,
21008
+ notDeepEqual,
21009
+ deepStrictEqual,
21010
+ notDeepStrictEqual,
21011
+ throws,
21012
+ doesNotThrow,
21013
+ rejects,
21014
+ doesNotReject,
21015
+ match,
21016
+ doesNotMatch,
21017
+ ifError,
21018
+ fail: (message) => fail(void 0, void 0, message, "fail")
21019
+ };
21020
+ var assertModule = Object.assign(ok, base, {
21021
+ strict: Object.assign(ok, base, {
21022
+ equal: strictEqual,
21023
+ notEqual: notStrictEqual,
21024
+ deepEqual: deepStrictEqual,
21025
+ notDeepEqual: notDeepStrictEqual
21026
+ })
21027
+ });
21028
+ var assert_module_default = assertModule;
21029
+ var bytes = (data) => {
21030
+ if (typeof data === "string") return new Uint8Array(Buffer2.from(data, "utf8"));
21031
+ if (data instanceof ArrayBuffer) return new Uint8Array(data);
21032
+ return data;
21033
+ };
21034
+ function codec(name, run) {
21035
+ const sync2 = (data, options) => Buffer2.from(run(bytes(data), options));
21036
+ const async_ = (data, options, callback) => {
21037
+ const done = typeof options === "function" ? options : callback;
21038
+ const settings = typeof options === "function" ? void 0 : options;
21039
+ queueMicrotask(() => {
21040
+ try {
21041
+ done(null, sync2(data, settings));
21042
+ } catch (error) {
21043
+ done(error);
21044
+ }
21045
+ });
21046
+ };
21047
+ const Stream = class extends streamModule4.Transform {
21048
+ chunks = [];
21049
+ options;
21050
+ constructor(options) {
21051
+ super();
21052
+ this.options = options;
21053
+ }
21054
+ _transform(chunk, _encoding, next) {
21055
+ this.chunks.push(Buffer2.from(chunk));
21056
+ next();
21057
+ }
21058
+ _flush(next) {
21059
+ try {
21060
+ this.push(sync2(Buffer2.concat(this.chunks), this.options));
21061
+ next();
21062
+ } catch (error) {
21063
+ next(error);
21064
+ }
21065
+ }
21066
+ };
21067
+ Object.defineProperty(Stream, "name", { value: name });
21068
+ return { sync: sync2, async: async_, Stream };
21069
+ }
21070
+ var gzipCodec = codec("Gzip", (input, options) => gzip$1(input, options));
21071
+ var gunzipCodec = codec("Gunzip", (input) => ungzip(input));
21072
+ var deflateCodec = codec("Deflate", (input, options) => deflate$1(input, options));
21073
+ var inflateCodec = codec("Inflate", (input) => inflate$1(input));
21074
+ var deflateRawCodec = codec("DeflateRaw", (input, options) => deflateRaw(input, options));
21075
+ var inflateRawCodec = codec("InflateRaw", (input) => inflateRaw(input));
21076
+ var unzipCodec = codec(
21077
+ "Unzip",
21078
+ (input) => input[0] === 31 && input[1] === 139 ? ungzip(input) : inflate$1(input)
21079
+ );
21080
+ function brotliUnavailable(name) {
21081
+ const error = new Error(
21082
+ `zlib.${name} is unavailable: the sandboxed runtime has no Brotli implementation.`
21083
+ );
21084
+ error.code = "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM";
21085
+ throw error;
21086
+ }
21087
+ var zlibModule = {
21088
+ gzipSync: gzipCodec.sync,
21089
+ gzip: gzipCodec.async,
21090
+ createGzip: (o) => new gzipCodec.Stream(o),
21091
+ gunzipSync: gunzipCodec.sync,
21092
+ gunzip: gunzipCodec.async,
21093
+ createGunzip: (o) => new gunzipCodec.Stream(o),
21094
+ deflateSync: deflateCodec.sync,
21095
+ deflate: deflateCodec.async,
21096
+ createDeflate: (o) => new deflateCodec.Stream(o),
21097
+ inflateSync: inflateCodec.sync,
21098
+ inflate: inflateCodec.async,
21099
+ createInflate: (o) => new inflateCodec.Stream(o),
21100
+ deflateRawSync: deflateRawCodec.sync,
21101
+ deflateRaw: deflateRawCodec.async,
21102
+ createDeflateRaw: (o) => new deflateRawCodec.Stream(o),
21103
+ inflateRawSync: inflateRawCodec.sync,
21104
+ inflateRaw: inflateRawCodec.async,
21105
+ createInflateRaw: (o) => new inflateRawCodec.Stream(o),
21106
+ unzipSync: unzipCodec.sync,
21107
+ unzip: unzipCodec.async,
21108
+ createUnzip: (o) => new unzipCodec.Stream(o),
21109
+ brotliCompressSync: () => brotliUnavailable("brotliCompressSync"),
21110
+ brotliDecompressSync: () => brotliUnavailable("brotliDecompressSync"),
21111
+ brotliCompress: () => brotliUnavailable("brotliCompress"),
21112
+ brotliDecompress: () => brotliUnavailable("brotliDecompress"),
21113
+ createBrotliCompress: () => brotliUnavailable("createBrotliCompress"),
21114
+ createBrotliDecompress: () => brotliUnavailable("createBrotliDecompress"),
21115
+ constants: {
21116
+ Z_NO_FLUSH: 0,
21117
+ Z_PARTIAL_FLUSH: 1,
21118
+ Z_SYNC_FLUSH: 2,
21119
+ Z_FULL_FLUSH: 3,
21120
+ Z_FINISH: 4,
21121
+ Z_BLOCK: 5,
21122
+ Z_TREES: 6,
21123
+ Z_OK: 0,
21124
+ Z_STREAM_END: 1,
21125
+ Z_NEED_DICT: 2,
21126
+ Z_ERRNO: -1,
21127
+ Z_STREAM_ERROR: -2,
21128
+ Z_DATA_ERROR: -3,
21129
+ Z_MEM_ERROR: -4,
21130
+ Z_BUF_ERROR: -5,
21131
+ Z_VERSION_ERROR: -6,
21132
+ Z_NO_COMPRESSION: 0,
21133
+ Z_BEST_SPEED: 1,
21134
+ Z_BEST_COMPRESSION: 9,
21135
+ Z_DEFAULT_COMPRESSION: -1,
21136
+ Z_FILTERED: 1,
21137
+ Z_HUFFMAN_ONLY: 2,
21138
+ Z_RLE: 3,
21139
+ Z_FIXED: 4,
21140
+ Z_DEFAULT_STRATEGY: 0,
21141
+ DEFLATE: 1,
21142
+ INFLATE: 2,
21143
+ GZIP: 3,
21144
+ GUNZIP: 4,
21145
+ DEFLATERAW: 5,
21146
+ INFLATERAW: 6,
21147
+ UNZIP: 7
21148
+ }
21149
+ };
21150
+ var zlib_module_default = zlibModule;
21151
+ function fileURLToPath(url) {
21152
+ const value = typeof url === "string" ? new URL(url) : url;
21153
+ if (value.protocol !== "file:") {
21154
+ throw Object.assign(new TypeError("The URL must be of scheme file"), {
21155
+ code: "ERR_INVALID_URL_SCHEME"
21156
+ });
21157
+ }
21158
+ return decodeURIComponent(value.pathname);
21159
+ }
21160
+ function pathToFileURL(path) {
21161
+ 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");
21162
+ return new URL(`file://${escaped.startsWith("/") ? "" : "/"}${escaped}`);
21163
+ }
21164
+ function format2(value, options) {
21165
+ if (!(value instanceof URL)) return legacyUrl.format(value);
21166
+ const url = new URL(value.href);
21167
+ if (options?.auth === false) {
21168
+ url.username = "";
21169
+ url.password = "";
21170
+ }
21171
+ if (options?.fragment === false) url.hash = "";
21172
+ if (options?.search === false) url.search = "";
21173
+ return url.href;
21174
+ }
21175
+ var urlModule = {
21176
+ ...legacyUrl,
21177
+ format: format2,
21178
+ fileURLToPath,
21179
+ pathToFileURL,
21180
+ URL,
21181
+ URLSearchParams,
21182
+ /** Names here are already Unicode; there is no IDNA table to consult. */
21183
+ domainToASCII: (domain) => domain.toLowerCase(),
21184
+ domainToUnicode: (domain) => domain.toLowerCase(),
21185
+ urlToHttpOptions: (url) => ({
21186
+ protocol: url.protocol,
21187
+ hostname: url.hostname,
21188
+ hash: url.hash,
21189
+ search: url.search,
21190
+ pathname: url.pathname,
21191
+ path: `${url.pathname}${url.search}`,
21192
+ href: url.href,
21193
+ ...url.port ? { port: Number(url.port) } : {},
21194
+ ...url.username || url.password ? { auth: `${url.username}:${url.password}` } : {}
21195
+ })
21196
+ };
21197
+ var url_module_default = urlModule;
21198
+
20437
21199
  // src/runtime/core-modules.ts
20438
21200
  init_path();
20439
- var VirtualIncomingMessage = class extends streamModule3.Readable {
21201
+ var VirtualIncomingMessage = class extends streamModule4.Readable {
20440
21202
  method;
20441
21203
  url;
20442
21204
  headers;
@@ -20457,7 +21219,7 @@ var VirtualIncomingMessage = class extends streamModule3.Readable {
20457
21219
  this.headers["content-length"] = String(body.length);
20458
21220
  }
20459
21221
  this.rawHeaders = Object.entries(this.headers).flatMap(([key, value]) => [key, value]);
20460
- if (body.length) this.push(Buffer$1.from(body));
21222
+ if (body.length) this.push(Buffer2.from(body));
20461
21223
  this.push(null);
20462
21224
  }
20463
21225
  _read() {
@@ -20467,7 +21229,7 @@ var VirtualIncomingMessage = class extends streamModule3.Readable {
20467
21229
  return this;
20468
21230
  }
20469
21231
  };
20470
- var VirtualServerResponse = class extends streamModule3.Writable {
21232
+ var VirtualServerResponse = class extends streamModule4.Writable {
20471
21233
  statusCode = 200;
20472
21234
  statusMessage = "OK";
20473
21235
  headersSent = false;
@@ -20488,7 +21250,7 @@ var VirtualServerResponse = class extends streamModule3.Writable {
20488
21250
  }
20489
21251
  _write(chunk, encoding, callback) {
20490
21252
  this.headersSent = true;
20491
- this.chunks.push(Buffer$1.isBuffer(chunk) ? chunk : Buffer$1.from(chunk, encoding));
21253
+ this.chunks.push(Buffer2.isBuffer(chunk) ? chunk : Buffer2.from(chunk, encoding));
20492
21254
  callback();
20493
21255
  }
20494
21256
  _final(callback) {
@@ -20500,7 +21262,7 @@ var VirtualServerResponse = class extends streamModule3.Writable {
20500
21262
  statusCode: this.statusCode,
20501
21263
  statusMessage: this.statusMessage || STATUS_CODES[this.statusCode] || "",
20502
21264
  headers,
20503
- body: new Uint8Array(Buffer$1.concat(this.chunks))
21265
+ body: new Uint8Array(Buffer2.concat(this.chunks))
20504
21266
  });
20505
21267
  callback();
20506
21268
  }
@@ -20552,7 +21314,7 @@ var VirtualServerResponse = class extends streamModule3.Writable {
20552
21314
  return this;
20553
21315
  }
20554
21316
  };
20555
- var VirtualHttpServer = class extends EventEmitter3 {
21317
+ var VirtualHttpServer = class extends EventEmitter4 {
20556
21318
  constructor(router, owner, listener) {
20557
21319
  super();
20558
21320
  this.router = router;
@@ -20688,7 +21450,7 @@ function createCryptoModule() {
20688
21450
  return api;
20689
21451
  },
20690
21452
  digest(encoding) {
20691
- const value = Buffer$1.from(hash.digest());
21453
+ const value = Buffer2.from(hash.digest());
20692
21454
  return encoding ? value.toString(encoding) : value;
20693
21455
  },
20694
21456
  copy() {
@@ -20706,14 +21468,14 @@ function createCryptoModule() {
20706
21468
  return api;
20707
21469
  },
20708
21470
  digest(encoding) {
20709
- const value = Buffer$1.from(state.digest());
21471
+ const value = Buffer2.from(state.digest());
20710
21472
  return encoding ? value.toString(encoding) : value;
20711
21473
  }
20712
21474
  };
20713
21475
  return api;
20714
21476
  },
20715
21477
  randomBytes(size, callback) {
20716
- const value = Buffer$1.alloc(size);
21478
+ const value = Buffer2.alloc(size);
20717
21479
  cryptoObject.getRandomValues(value);
20718
21480
  if (callback) {
20719
21481
  queueMicrotask(() => callback(null, value));
@@ -20746,7 +21508,7 @@ function createCryptoModule() {
20746
21508
  queueMicrotask(() => done?.(null, target));
20747
21509
  },
20748
21510
  hash(algorithm, data, encoding = "hex") {
20749
- const digest = Buffer$1.from(hashFor(algorithm)(toBytes2(data)));
21511
+ const digest = Buffer2.from(hashFor(algorithm)(toBytes2(data)));
20750
21512
  return encoding === "buffer" ? digest : digest.toString(encoding);
20751
21513
  },
20752
21514
  timingSafeEqual(a, b) {
@@ -20767,11 +21529,11 @@ function hashFor(algorithm) {
20767
21529
  return hash;
20768
21530
  }
20769
21531
  function toBytes2(data, encoding) {
20770
- return typeof data === "string" ? Buffer$1.from(data, encoding) : data;
21532
+ return typeof data === "string" ? Buffer2.from(data, encoding) : data;
20771
21533
  }
20772
- var ChildProcess = class extends EventEmitter3 {
20773
- stdout = new streamModule3.PassThrough();
20774
- stderr = new streamModule3.PassThrough();
21534
+ var ChildProcess = class extends EventEmitter4 {
21535
+ stdout = new streamModule4.PassThrough();
21536
+ stderr = new streamModule4.PassThrough();
20775
21537
  stdin;
20776
21538
  stdio;
20777
21539
  pid;
@@ -20788,10 +21550,10 @@ var ChildProcess = class extends EventEmitter3 {
20788
21550
  this.pid = handle.pid;
20789
21551
  this.spawnfile = file3;
20790
21552
  this.spawnargs = [file3, ...args];
20791
- this.stdin = new streamModule3.Writable({
21553
+ this.stdin = new streamModule4.Writable({
20792
21554
  write: (chunk, _encoding, done) => {
20793
21555
  try {
20794
- handle.sendStdin(typeof chunk === "string" ? chunk : Buffer$1.from(chunk).toString("utf8"));
21556
+ handle.sendStdin(typeof chunk === "string" ? chunk : Buffer2.from(chunk).toString("utf8"));
20795
21557
  } catch {
20796
21558
  }
20797
21559
  done();
@@ -20861,8 +21623,8 @@ function createChildProcessModule(spawnChild, defaultCwd) {
20861
21623
  child.stderr.on("data", (chunk) => err.push(String(chunk)));
20862
21624
  child.on("close", (code) => {
20863
21625
  const asBuffer = options.encoding === "buffer";
20864
- const stdout = asBuffer ? Buffer$1.from(out.join("")) : out.join("");
20865
- const stderr = asBuffer ? Buffer$1.from(err.join("")) : err.join("");
21626
+ const stdout = asBuffer ? Buffer2.from(out.join("")) : out.join("");
21627
+ const stderr = asBuffer ? Buffer2.from(err.join("")) : err.join("");
20866
21628
  if (code === 0) {
20867
21629
  callback(null, stdout, stderr);
20868
21630
  return;
@@ -20913,6 +21675,326 @@ function unavailable(name) {
20913
21675
 
20914
21676
  // src/runtime/core-modules.ts
20915
21677
  init_signals();
21678
+ var CSI_KEYS = {
21679
+ "[A": "up",
21680
+ "[B": "down",
21681
+ "[C": "right",
21682
+ "[D": "left",
21683
+ "[E": "clear",
21684
+ "[F": "end",
21685
+ "[H": "home",
21686
+ "OA": "up",
21687
+ "OB": "down",
21688
+ "OC": "right",
21689
+ "OD": "left",
21690
+ "OE": "clear",
21691
+ "OF": "end",
21692
+ "OH": "home",
21693
+ "[1~": "home",
21694
+ "[2~": "insert",
21695
+ "[3~": "delete",
21696
+ "[4~": "end",
21697
+ "[5~": "pageup",
21698
+ "[6~": "pagedown",
21699
+ "[7~": "home",
21700
+ "[8~": "end",
21701
+ "[11~": "f1",
21702
+ "[12~": "f2",
21703
+ "[13~": "f3",
21704
+ "[14~": "f4",
21705
+ "[15~": "f5",
21706
+ "[17~": "f6",
21707
+ "[18~": "f7",
21708
+ "[19~": "f8",
21709
+ "[20~": "f9",
21710
+ "[21~": "f10",
21711
+ "[23~": "f11",
21712
+ "[24~": "f12",
21713
+ "OP": "f1",
21714
+ "OQ": "f2",
21715
+ "OR": "f3",
21716
+ "OS": "f4",
21717
+ "[Z": "tab"
21718
+ };
21719
+ var CONTROL_LETTERS = "abcdefghijklmnopqrstuvwxyz";
21720
+ function parseKeys(input) {
21721
+ const keys = [];
21722
+ let index = 0;
21723
+ while (index < input.length) {
21724
+ const char = input[index];
21725
+ if (char === "\x1B") {
21726
+ const rest = input.slice(index + 1);
21727
+ const match2 = /^(\[[0-9;]*[A-Za-z~]|O[A-Za-z])/.exec(rest);
21728
+ if (match2) {
21729
+ const sequence = match2[1];
21730
+ const name = CSI_KEYS[sequence];
21731
+ keys.push({
21732
+ sequence: `\x1B${sequence}`,
21733
+ name: name ?? "undefined",
21734
+ ctrl: false,
21735
+ /* xterm reports modifiers as `;5` (control) and `;2` (shift) before
21736
+ * the final letter. */
21737
+ meta: false,
21738
+ shift: /;2[A-Za-z~]$/.test(sequence),
21739
+ code: sequence
21740
+ });
21741
+ if (/;5[A-Za-z~]$/.test(sequence)) keys[keys.length - 1].ctrl = true;
21742
+ index += 1 + sequence.length;
21743
+ continue;
21744
+ }
21745
+ if (rest.length > 0 && rest[0] !== "\x1B") {
21746
+ const inner = parseKeys(rest[0])[0];
21747
+ if (inner) {
21748
+ keys.push({ ...inner, meta: true, sequence: `\x1B${inner.sequence}` });
21749
+ index += 2;
21750
+ continue;
21751
+ }
21752
+ }
21753
+ keys.push({ sequence: "\x1B", name: "escape", ctrl: false, meta: false, shift: false });
21754
+ index += 1;
21755
+ continue;
21756
+ }
21757
+ keys.push(parseSingle(char));
21758
+ index += 1;
21759
+ }
21760
+ return keys;
21761
+ }
21762
+ function parseSingle(char) {
21763
+ const code = char.charCodeAt(0);
21764
+ if (char === "\r") return { sequence: char, name: "return", ctrl: false, meta: false, shift: false };
21765
+ if (char === "\n") return { sequence: char, name: "enter", ctrl: false, meta: false, shift: false };
21766
+ if (char === " ") return { sequence: char, name: "tab", ctrl: false, meta: false, shift: false };
21767
+ if (char === "\x7F" || char === "\b") {
21768
+ return { sequence: char, name: "backspace", ctrl: false, meta: false, shift: false };
21769
+ }
21770
+ if (char === " ") return { sequence: char, name: "space", ctrl: false, meta: false, shift: false };
21771
+ if (code >= 1 && code <= 26) {
21772
+ return {
21773
+ sequence: char,
21774
+ name: CONTROL_LETTERS[code - 1],
21775
+ ctrl: true,
21776
+ meta: false,
21777
+ shift: false
21778
+ };
21779
+ }
21780
+ return {
21781
+ sequence: char,
21782
+ name: char.toLowerCase(),
21783
+ ctrl: false,
21784
+ meta: false,
21785
+ // An uppercase letter arrived because shift was held.
21786
+ shift: char !== char.toLowerCase()
21787
+ };
21788
+ }
21789
+ function emitKeypressEvents(stream) {
21790
+ if (!stream || stream.__sbxKeypress) return;
21791
+ stream.__sbxKeypress = true;
21792
+ stream.on("data", (chunk) => {
21793
+ for (const key of parseKeys(String(chunk))) {
21794
+ stream.emit("keypress", key.sequence, key);
21795
+ }
21796
+ });
21797
+ }
21798
+ function createReadlineModule(defaultInput) {
21799
+ class Interface extends EventEmitter4 {
21800
+ constructor(input, output, terminal = false) {
21801
+ super();
21802
+ this.input = input;
21803
+ this.output = output;
21804
+ this.terminal = terminal;
21805
+ this.onTerminalKeypress = (sequence, key) => this.edit(sequence, key);
21806
+ if (terminal) {
21807
+ emitKeypressEvents(input);
21808
+ input?.on?.("keypress", this.onTerminalKeypress);
21809
+ } else {
21810
+ input?.on?.("data", (chunk) => this.receive(String(chunk)));
21811
+ }
21812
+ input?.on?.("end", () => this.close());
21813
+ }
21814
+ input;
21815
+ output;
21816
+ closed = false;
21817
+ buffer = "";
21818
+ pending = [];
21819
+ lines = [];
21820
+ line = "";
21821
+ cursor = 0;
21822
+ terminal;
21823
+ onTerminalKeypress;
21824
+ /** Split incoming data into lines, answering any waiting `question`. */
21825
+ receive(text2) {
21826
+ this.buffer += text2;
21827
+ let newline = this.buffer.indexOf("\n");
21828
+ while (newline >= 0) {
21829
+ const line = this.buffer.slice(0, newline).replace(/\r$/, "");
21830
+ this.buffer = this.buffer.slice(newline + 1);
21831
+ const waiting = this.pending.shift();
21832
+ if (waiting) waiting(line);
21833
+ else {
21834
+ this.lines.push(line);
21835
+ this.emit("line", line);
21836
+ }
21837
+ newline = this.buffer.indexOf("\n");
21838
+ }
21839
+ }
21840
+ question(query, callback) {
21841
+ this.output?.write?.(query);
21842
+ if (callback) {
21843
+ this.pending.push(callback);
21844
+ return;
21845
+ }
21846
+ return new Promise((resolve2) => this.pending.push(resolve2));
21847
+ }
21848
+ prompt() {
21849
+ this.output?.write?.(this.promptText);
21850
+ }
21851
+ promptText = "> ";
21852
+ setPrompt(text2) {
21853
+ this.promptText = text2;
21854
+ }
21855
+ pause() {
21856
+ this.input?.pause?.();
21857
+ return this;
21858
+ }
21859
+ resume() {
21860
+ this.input?.resume?.();
21861
+ return this;
21862
+ }
21863
+ write(text2, key) {
21864
+ if (!this.terminal) {
21865
+ if (text2) this.receive(text2);
21866
+ return;
21867
+ }
21868
+ if (key) {
21869
+ this.edit(text2 ?? "", {
21870
+ sequence: text2 ?? key.sequence ?? "",
21871
+ name: key.name,
21872
+ ctrl: key.ctrl ?? false,
21873
+ meta: key.meta ?? false,
21874
+ shift: key.shift ?? false,
21875
+ ...key.code ? { code: key.code } : {}
21876
+ });
21877
+ return;
21878
+ }
21879
+ if (text2) {
21880
+ this.line = this.line.slice(0, this.cursor) + text2 + this.line.slice(this.cursor);
21881
+ this.cursor += text2.length;
21882
+ }
21883
+ }
21884
+ getCursorPos() {
21885
+ return { rows: 0, cols: this.cursor + this.promptText.length };
21886
+ }
21887
+ close() {
21888
+ if (this.closed) return;
21889
+ this.closed = true;
21890
+ if (this.terminal) {
21891
+ this.input?.off?.("keypress", this.onTerminalKeypress);
21892
+ this.input?.pause?.();
21893
+ }
21894
+ for (const waiting of this.pending.splice(0)) waiting("");
21895
+ this.emit("close");
21896
+ }
21897
+ edit(sequence, key) {
21898
+ if (this.closed) return;
21899
+ const name = key.name;
21900
+ if (name === "return" || name === "enter") {
21901
+ const value = this.line;
21902
+ this.line = "";
21903
+ this.cursor = 0;
21904
+ this.emit("line", value);
21905
+ return;
21906
+ }
21907
+ if (name === "left") {
21908
+ this.cursor = Math.max(0, this.cursor - 1);
21909
+ return;
21910
+ }
21911
+ if (name === "right") {
21912
+ this.cursor = Math.min(this.line.length, this.cursor + 1);
21913
+ return;
21914
+ }
21915
+ if (name === "home" || key.ctrl && name === "a") {
21916
+ this.cursor = 0;
21917
+ return;
21918
+ }
21919
+ if (name === "end" || key.ctrl && name === "e") {
21920
+ this.cursor = this.line.length;
21921
+ return;
21922
+ }
21923
+ if (name === "backspace" || key.ctrl && name === "h") {
21924
+ if (this.cursor > 0) {
21925
+ this.line = this.line.slice(0, this.cursor - 1) + this.line.slice(this.cursor);
21926
+ this.cursor--;
21927
+ }
21928
+ return;
21929
+ }
21930
+ if (name === "delete") {
21931
+ if (this.cursor < this.line.length) this.line = this.line.slice(0, this.cursor) + this.line.slice(this.cursor + 1);
21932
+ return;
21933
+ }
21934
+ if (key.ctrl && name === "u") {
21935
+ this.line = this.line.slice(this.cursor);
21936
+ this.cursor = 0;
21937
+ return;
21938
+ }
21939
+ if (key.ctrl && name === "k") {
21940
+ this.line = this.line.slice(0, this.cursor);
21941
+ return;
21942
+ }
21943
+ if (key.ctrl || key.meta || sequence.length !== 1 || sequence < " ") return;
21944
+ this.line = this.line.slice(0, this.cursor) + sequence + this.line.slice(this.cursor);
21945
+ this.cursor += sequence.length;
21946
+ }
21947
+ async *[Symbol.asyncIterator]() {
21948
+ while (!this.closed || this.lines.length) {
21949
+ const line = this.lines.shift();
21950
+ if (line !== void 0) {
21951
+ yield line;
21952
+ continue;
21953
+ }
21954
+ const next = await new Promise((resolve2) => {
21955
+ const onLine = (value) => {
21956
+ cleanup();
21957
+ resolve2(value);
21958
+ };
21959
+ const onClose = () => {
21960
+ cleanup();
21961
+ resolve2(null);
21962
+ };
21963
+ const cleanup = () => {
21964
+ this.off("line", onLine);
21965
+ this.off("close", onClose);
21966
+ };
21967
+ this.on("line", onLine);
21968
+ this.on("close", onClose);
21969
+ });
21970
+ if (next === null) return;
21971
+ yield next;
21972
+ }
21973
+ }
21974
+ }
21975
+ const createInterface = (options, output) => {
21976
+ if (options && typeof options === "object" && !options.on) {
21977
+ const instance = new Interface(options.input ?? defaultInput(), options.output, options.terminal === true);
21978
+ if (typeof options.prompt === "string") instance.setPrompt(options.prompt);
21979
+ return instance;
21980
+ }
21981
+ return new Interface(options ?? defaultInput(), output, Boolean(output));
21982
+ };
21983
+ const noop = () => {
21984
+ };
21985
+ const base2 = {
21986
+ Interface,
21987
+ createInterface,
21988
+ emitKeypressEvents,
21989
+ clearLine: noop,
21990
+ clearScreenDown: noop,
21991
+ cursorTo: noop,
21992
+ moveCursor: noop
21993
+ };
21994
+ return { ...base2, promises: { ...base2, Interface, createInterface } };
21995
+ }
21996
+
21997
+ // src/runtime/core-modules.ts
20916
21998
  var Dirent = class {
20917
21999
  /** Node 20+ exposes the containing directory, and `fs.glob` consumers read it. */
20918
22000
  constructor(name, stat2, parentPath = "") {
@@ -21028,7 +22110,7 @@ var S_IFMT2 = 61440;
21028
22110
  var S_IFREG2 = 32768;
21029
22111
  var S_IFDIR2 = 16384;
21030
22112
  var S_IFLNK2 = 40960;
21031
- var FsWatcher = class extends EventEmitter3 {
22113
+ var FsWatcher = class extends EventEmitter4 {
21032
22114
  close() {
21033
22115
  this.removeAllListeners();
21034
22116
  }
@@ -21049,7 +22131,7 @@ function createCoreModules(options) {
21049
22131
  const stderrWrite = options.stderr ?? (() => {
21050
22132
  });
21051
22133
  const timers = createTrackedTimers();
21052
- const processObject = Object.assign(new EventEmitter3(), processShim, {
22134
+ const processObject = Object.assign(new EventEmitter4(), processShim, {
21053
22135
  argv: options.argv?.slice() ?? ["/usr/bin/node"],
21054
22136
  argv0: "node",
21055
22137
  execPath: "/usr/bin/node",
@@ -21085,14 +22167,27 @@ function createCoreModules(options) {
21085
22167
  },
21086
22168
  kill: () => true
21087
22169
  });
21088
- processObject.stdout = makeOutputStream(stdoutWrite, 1);
21089
- processObject.stderr = makeOutputStream(stderrWrite, 2);
21090
- processObject.stdin = new streamModule3.Readable({ read() {
22170
+ const tty = options.tty === true;
22171
+ processObject.stdout = makeOutputStream(stdoutWrite, 1, tty);
22172
+ processObject.stderr = makeOutputStream(stderrWrite, 2, tty);
22173
+ const stdin = options.interactiveStdin ? new streamModule4.PassThrough() : new streamModule4.Readable({ read() {
21091
22174
  this.push(null);
21092
22175
  } });
21093
- Object.assign(processObject.stdin, { fd: 0, isTTY: false, setRawMode() {
21094
- return this;
21095
- } });
22176
+ Object.assign(stdin, {
22177
+ fd: 0,
22178
+ isTTY: tty,
22179
+ setRawMode(enabled = true) {
22180
+ options.onRawMode?.(enabled !== false);
22181
+ return this;
22182
+ },
22183
+ ref() {
22184
+ return this;
22185
+ },
22186
+ unref() {
22187
+ return this;
22188
+ }
22189
+ });
22190
+ processObject.stdin = stdin;
21096
22191
  const fs = createFsModule(volume, () => cwd, options.stdinPath);
21097
22192
  const path = createPathModule(() => cwd);
21098
22193
  const consoleObject = new Console(stdoutWrite, stderrWrite);
@@ -21110,9 +22205,9 @@ function createCoreModules(options) {
21110
22205
  const readline = createReadlineModule(() => processObject.stdin);
21111
22206
  const dns = createDnsModule();
21112
22207
  const builtins = {
21113
- assert: assertModule,
21114
- "assert/strict": assertModule.strict ?? assertModule,
21115
- buffer: { Buffer: Buffer$1, SlowBuffer: Buffer$1, INSPECT_MAX_BYTES: 50, kMaxLength: Buffer$1.kMaxLength },
22208
+ assert: assert_module_default,
22209
+ "assert/strict": assert_module_default.strict ?? assert_module_default,
22210
+ buffer: { Buffer: Buffer2, SlowBuffer: Buffer2, INSPECT_MAX_BYTES: 50, kMaxLength: Buffer2.kMaxLength },
21116
22211
  async_hooks: asyncHooks,
21117
22212
  child_process: childProcess,
21118
22213
  console: consoleObject,
@@ -21120,7 +22215,7 @@ function createCoreModules(options) {
21120
22215
  crypto: createCryptoModule(),
21121
22216
  dns,
21122
22217
  "dns/promises": dns.promises,
21123
- events: EventEmitter3,
22218
+ events: EventEmitter4,
21124
22219
  fs,
21125
22220
  "fs/promises": fs.promises,
21126
22221
  module: moduleBuiltin,
@@ -21131,24 +22226,24 @@ function createCoreModules(options) {
21131
22226
  "path/posix": path,
21132
22227
  perf_hooks: { performance, PerformanceObserver: globalThis.PerformanceObserver },
21133
22228
  process: processObject,
21134
- punycode: urlModule.punycode ?? {},
22229
+ punycode: url_module_default.punycode ?? {},
21135
22230
  querystring: querystringModule,
21136
22231
  readline,
21137
22232
  "readline/promises": readline.promises,
21138
- stream: streamModule3,
22233
+ stream: streamModule4,
21139
22234
  "stream/promises": createStreamPromises(),
21140
22235
  string_decoder: stringDecoderModule,
21141
22236
  timers: { ...timersModule, ...timers.api },
21142
22237
  "timers/promises": createTimerPromises(),
21143
- tty: { isatty: () => false, ReadStream: streamModule3.Readable, WriteStream: streamModule3.Writable },
21144
- url: urlModule,
21145
- util: utilModule,
21146
- "util/types": utilModule.types ?? {},
21147
- zlib: zlibModule
22238
+ tty: { isatty: () => false, ReadStream: streamModule4.Readable, WriteStream: streamModule4.Writable },
22239
+ url: url_module_default,
22240
+ util: util_module_default,
22241
+ "util/types": util_module_default.types ?? {},
22242
+ zlib: zlib_module_default
21148
22243
  };
21149
22244
  for (const name of stubNames) builtins[name] = createUnsupportedModule(name);
21150
22245
  const globals = {
21151
- Buffer: Buffer$1,
22246
+ Buffer: Buffer2,
21152
22247
  console: consoleObject,
21153
22248
  process: processObject,
21154
22249
  ...timers.api
@@ -21159,7 +22254,19 @@ function createCoreModules(options) {
21159
22254
  });
21160
22255
  globals.global = globalOverlay;
21161
22256
  globals.globalThis = globalOverlay;
21162
- return { builtins, globals, process: processObject, pendingHandles: timers.pending };
22257
+ return {
22258
+ builtins,
22259
+ globals,
22260
+ process: processObject,
22261
+ pendingHandles: timers.pending,
22262
+ writeStdin: (data) => {
22263
+ if (options.interactiveStdin) stdin.write(data);
22264
+ },
22265
+ endStdin: () => {
22266
+ if (options.interactiveStdin) stdin.end();
22267
+ },
22268
+ readingStdin: () => Boolean(options.interactiveStdin) && stdin.readable === true && (stdin.readableFlowing === true || stdin.listenerCount("readable") > 0 || stdin.listenerCount("keypress") > 0)
22269
+ };
21163
22270
  }
21164
22271
  var ASYNC_FS_METHODS = [
21165
22272
  "readFile",
@@ -21220,18 +22327,18 @@ function createFsModule(volume, cwd, stdinPath) {
21220
22327
  const abs = (value) => {
21221
22328
  if (typeof value === "number") return requiredFd(fds, value).path;
21222
22329
  if (value instanceof URL) value = value.pathname;
21223
- if (Buffer$1.isBuffer(value) || value instanceof Uint8Array) value = new TextDecoder().decode(value);
22330
+ if (Buffer2.isBuffer(value) || value instanceof Uint8Array) value = new TextDecoder().decode(value);
21224
22331
  if (typeof value !== "string") throw new TypeError("path must be a string, Buffer, or URL");
21225
22332
  return value.startsWith("/") ? clean(value) : resolve(cwd(), value);
21226
22333
  };
21227
- const bytes = (data, encoding) => {
21228
- if (typeof data === "string") return new Uint8Array(Buffer$1.from(data, encoding));
21229
- if (Buffer$1.isBuffer(data) || data instanceof Uint8Array) return new Uint8Array(data);
22334
+ const bytes2 = (data, encoding) => {
22335
+ if (typeof data === "string") return new Uint8Array(Buffer2.from(data, encoding));
22336
+ if (Buffer2.isBuffer(data) || data instanceof Uint8Array) return new Uint8Array(data);
21230
22337
  if (data instanceof ArrayBuffer) return new Uint8Array(data);
21231
22338
  throw new TypeError("data must be a string or byte array");
21232
22339
  };
21233
22340
  const read = (path, encoding) => {
21234
- const data = Buffer$1.from(volume.readFileSync(resolveLinks(volume, abs(path))));
22341
+ const data = Buffer2.from(volume.readFileSync(resolveLinks(volume, abs(path))));
21235
22342
  return encoding && encoding !== "buffer" ? data.toString(encoding) : data;
21236
22343
  };
21237
22344
  const mkdirRecursive = (path, mode) => {
@@ -21280,12 +22387,12 @@ function createFsModule(volume, cwd, stdinPath) {
21280
22387
  readFileSync: (path, options) => read(path, typeof options === "object" && options ? options.encoding : options),
21281
22388
  writeFileSync: (path, data, options) => {
21282
22389
  const encoding = typeof options === "object" && options ? options.encoding : options === "buffer" ? void 0 : options ?? void 0;
21283
- volume.writeFileSync(abs(path), bytes(data, encoding ?? void 0));
22390
+ volume.writeFileSync(abs(path), bytes2(data, encoding ?? void 0));
21284
22391
  if (typeof options === "object" && options?.mode !== void 0) volume.chmodSync(abs(path), options.mode);
21285
22392
  },
21286
22393
  appendFileSync: (path, data, options) => {
21287
22394
  const encoding = typeof options === "object" && options ? options.encoding : options === "buffer" ? void 0 : options ?? void 0;
21288
- volume.appendFileSync(abs(path), bytes(data, encoding ?? void 0));
22395
+ volume.appendFileSync(abs(path), bytes2(data, encoding ?? void 0));
21289
22396
  },
21290
22397
  existsSync: (path) => {
21291
22398
  try {
@@ -21303,7 +22410,7 @@ function createFsModule(volume, cwd, stdinPath) {
21303
22410
  if (typeof options === "object" && options?.withFileTypes) {
21304
22411
  return names.map((name) => new Dirent(name, new Stats2(volume.lstatSync(join(dir3, name))), dir3));
21305
22412
  }
21306
- if ((typeof options === "string" ? options : options?.encoding) === "buffer") return names.map((name) => Buffer$1.from(name));
22413
+ if ((typeof options === "string" ? options : options?.encoding) === "buffer") return names.map((name) => Buffer2.from(name));
21307
22414
  return names;
21308
22415
  },
21309
22416
  mkdirSync: (path, options) => {
@@ -21324,7 +22431,7 @@ function createFsModule(volume, cwd, stdinPath) {
21324
22431
  renameSync: (from, to) => volume.renameSync(abs(from), abs(to)),
21325
22432
  readlinkSync: (path, encoding) => {
21326
22433
  const value = volume.readlinkSync(abs(path));
21327
- return encoding === "buffer" ? Buffer$1.from(value) : value;
22434
+ return encoding === "buffer" ? Buffer2.from(value) : value;
21328
22435
  },
21329
22436
  symlinkSync: (target, path) => volume.symlinkSync(target, abs(path)),
21330
22437
  linkSync: (from, to) => volume.linkSync(abs(from), abs(to)),
@@ -21368,7 +22475,7 @@ function createFsModule(volume, cwd, stdinPath) {
21368
22475
  },
21369
22476
  writeSync: (fd, data, offset, length, position) => {
21370
22477
  const file3 = requiredFd(fds, fd);
21371
- const input = bytes(data);
22478
+ const input = bytes2(data);
21372
22479
  const chunk = typeof data === "string" ? input : input.subarray(offset ?? 0, (offset ?? 0) + (length ?? input.length));
21373
22480
  const old = volume.readFileSync(file3.path);
21374
22481
  const start2 = file3.flags.startsWith("a") ? old.length : position ?? file3.position;
@@ -21380,13 +22487,13 @@ function createFsModule(volume, cwd, stdinPath) {
21380
22487
  return chunk.length;
21381
22488
  },
21382
22489
  createReadStream: (path) => {
21383
- const data = Buffer$1.from(volume.readFileSync(resolveLinks(volume, abs(path))));
21384
- return streamModule3.Readable.from([data]);
22490
+ const data = Buffer2.from(volume.readFileSync(resolveLinks(volume, abs(path))));
22491
+ return streamModule4.Readable.from([data]);
21385
22492
  },
21386
22493
  createWriteStream: (path, options) => {
21387
22494
  const target = abs(path);
21388
22495
  let first = true;
21389
- return new streamModule3.Writable({ write(chunk, _encoding, done) {
22496
+ return new streamModule4.Writable({ write(chunk, _encoding, done) {
21390
22497
  try {
21391
22498
  if (options?.flags?.startsWith("a") || !first) volume.appendFileSync(target, new Uint8Array(chunk));
21392
22499
  else volume.writeFileSync(target, new Uint8Array(chunk));
@@ -21508,12 +22615,12 @@ function requiredFd(fds, fd) {
21508
22615
  function fsError(code, syscall, path) {
21509
22616
  return Object.assign(new Error(`${code}: ${syscall}, '${path}'`), { code, syscall, path });
21510
22617
  }
21511
- function makeOutputStream(write, fd) {
21512
- const stream = new streamModule3.Writable({ write(chunk, _encoding, done) {
21513
- write(Buffer$1.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk));
22618
+ function makeOutputStream(write, fd, isTTY = false) {
22619
+ const stream = new streamModule4.Writable({ write(chunk, _encoding, done) {
22620
+ write(Buffer2.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk));
21514
22621
  done();
21515
22622
  } });
21516
- return Object.assign(stream, { fd, isTTY: false, columns: 80, rows: 24 });
22623
+ return Object.assign(stream, { fd, isTTY, columns: 80, rows: 24 });
21517
22624
  }
21518
22625
  var Console = class {
21519
22626
  constructor(out, err) {
@@ -21523,7 +22630,7 @@ var Console = class {
21523
22630
  out;
21524
22631
  err;
21525
22632
  log = (...args) => {
21526
- this.out(utilModule.format(...args) + "\n");
22633
+ this.out(util_module_default.format(...args) + "\n");
21527
22634
  };
21528
22635
  info = (...args) => {
21529
22636
  this.log(...args);
@@ -21532,20 +22639,20 @@ var Console = class {
21532
22639
  this.log(...args);
21533
22640
  };
21534
22641
  warn = (...args) => {
21535
- this.err(utilModule.format(...args) + "\n");
22642
+ this.err(util_module_default.format(...args) + "\n");
21536
22643
  };
21537
22644
  error = (...args) => {
21538
22645
  this.warn(...args);
21539
22646
  };
21540
22647
  dir = (value, options) => {
21541
- this.out(utilModule.inspect(value, options) + "\n");
22648
+ this.out(util_module_default.inspect(value, options) + "\n");
21542
22649
  };
21543
22650
  trace = (...args) => {
21544
- this.err(`Trace: ${utilModule.format(...args)}
22651
+ this.err(`Trace: ${util_module_default.format(...args)}
21545
22652
  `);
21546
22653
  };
21547
22654
  assert = (value, ...args) => {
21548
- if (!value) this.err(`Assertion failed: ${utilModule.format(...args)}
22655
+ if (!value) this.err(`Assertion failed: ${util_module_default.format(...args)}
21549
22656
  `);
21550
22657
  };
21551
22658
  group = (...args) => {
@@ -21567,63 +22674,6 @@ var Console = class {
21567
22674
  timeLog = (_label = "default") => {
21568
22675
  };
21569
22676
  };
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
22677
  function createDnsModule() {
21628
22678
  const LOOPBACK = {
21629
22679
  localhost: { address: "127.0.0.1", family: 4 },
@@ -21653,15 +22703,6 @@ function createDnsModule() {
21653
22703
  }
21654
22704
  });
21655
22705
  };
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
22706
  const promises = {
21666
22707
  lookup: async (hostname, options) => {
21667
22708
  const entry = lookupSync(hostname);
@@ -21669,7 +22710,10 @@ function createDnsModule() {
21669
22710
  },
21670
22711
  resolve4: async (hostname) => [lookupSync(hostname).address],
21671
22712
  resolve6: async (hostname) => [lookupSync(hostname).address],
21672
- reverse: async (address) => address === "127.0.0.1" ? ["localhost"] : notFound(address)
22713
+ reverse: async (address) => {
22714
+ if (address === "127.0.0.1") return ["localhost"];
22715
+ return [lookupSync(address).address];
22716
+ }
21673
22717
  };
21674
22718
  return {
21675
22719
  lookup,
@@ -21936,10 +22980,10 @@ function createStreamPromises() {
21936
22980
  return {
21937
22981
  pipeline: (...streams) => new Promise((resolve2, reject) => {
21938
22982
  const callback = (error) => error ? reject(error) : resolve2();
21939
- streamModule3.pipeline(...streams, callback);
22983
+ streamModule4.pipeline(...streams, callback);
21940
22984
  }),
21941
22985
  finished: (stream) => new Promise((resolve2, reject) => {
21942
- streamModule3.finished(stream, (error) => error ? reject(error) : resolve2());
22986
+ streamModule4.finished(stream, (error) => error ? reject(error) : resolve2());
21943
22987
  })
21944
22988
  };
21945
22989
  }
@@ -22066,26 +23110,26 @@ var MemoryVolume = class {
22066
23110
  writeFileSync(path, data) {
22067
23111
  const key = this.key(path);
22068
23112
  this.requireParent(key, "open");
22069
- const bytes = typeof data === "string" ? encoder6.encode(data) : data.slice();
23113
+ const bytes2 = typeof data === "string" ? encoder6.encode(data) : data.slice();
22070
23114
  const current = this.entries.get(key);
22071
23115
  if (current?.kind === "directory") throw new VolumeError("EISDIR", "open", key);
22072
23116
  if (current?.kind === "symlink") throw new VolumeError("EINVAL", "open", key);
22073
23117
  if (current) {
22074
- current.data = bytes;
23118
+ current.data = bytes2;
22075
23119
  this.touchChanged(current, true);
22076
23120
  } else {
22077
- this.entries.set(key, this.inode("file", 438, bytes));
23121
+ this.entries.set(key, this.inode("file", 438, bytes2));
22078
23122
  }
22079
23123
  }
22080
23124
  appendFileSync(path, data) {
22081
23125
  const key = this.key(path);
22082
- const bytes = typeof data === "string" ? encoder6.encode(data) : data;
23126
+ const bytes2 = typeof data === "string" ? encoder6.encode(data) : data;
22083
23127
  const current = this.entries.get(key);
22084
- if (!current) return this.writeFileSync(key, bytes);
23128
+ if (!current) return this.writeFileSync(key, bytes2);
22085
23129
  if (current.kind !== "file") throw new VolumeError(current.kind === "directory" ? "EISDIR" : "EINVAL", "open", key);
22086
- const next = new Uint8Array(current.data.length + bytes.length);
23130
+ const next = new Uint8Array(current.data.length + bytes2.length);
22087
23131
  next.set(current.data);
22088
- next.set(bytes, current.data.length);
23132
+ next.set(bytes2, current.data.length);
22089
23133
  current.data = next;
22090
23134
  this.touchChanged(current, true);
22091
23135
  }
@@ -22359,6 +23403,17 @@ function esbuildUnavailable() {
22359
23403
  error.code = "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM";
22360
23404
  return error;
22361
23405
  }
23406
+ var installed = false;
23407
+ function ensureProcessGlobal() {
23408
+ if (installed) return;
23409
+ installed = true;
23410
+ if (typeof globalThis.process !== "undefined") return;
23411
+ Object.defineProperty(globalThis, "process", {
23412
+ value: processShim,
23413
+ writable: true,
23414
+ configurable: true
23415
+ });
23416
+ }
22362
23417
 
22363
23418
  // src/runtime/local-runtime-pod.ts
22364
23419
  var WASM_ALIASES = {
@@ -22372,7 +23427,7 @@ var ProcessExit = class extends Error {
22372
23427
  }
22373
23428
  code;
22374
23429
  };
22375
- var LocalProcess = class extends EventEmitter3 {
23430
+ var LocalProcess = class extends EventEmitter4 {
22376
23431
  constructor(task) {
22377
23432
  super();
22378
23433
  this.task = task;
@@ -22390,6 +23445,10 @@ var LocalProcess = class extends EventEmitter3 {
22390
23445
  killed = false;
22391
23446
  out = [];
22392
23447
  err = [];
23448
+ input;
23449
+ end;
23450
+ inputEnded = false;
23451
+ pendingInput = [];
22393
23452
  resolveKilled;
22394
23453
  killedPromise = new Promise((resolve2) => {
22395
23454
  this.resolveKilled = resolve2;
@@ -22405,7 +23464,29 @@ var LocalProcess = class extends EventEmitter3 {
22405
23464
  this.err.push(text2);
22406
23465
  this.emit("error", text2);
22407
23466
  }
22408
- write(_data) {
23467
+ /**
23468
+ * Deliver input to the running program.
23469
+ *
23470
+ * The program's `process.stdin` does not exist until its task starts, so
23471
+ * anything written before then is held. Dropping it would lose the first
23472
+ * keystrokes of an interactive session, which arrive while the program is
23473
+ * still loading.
23474
+ */
23475
+ write(data) {
23476
+ if (this.input) this.input(data);
23477
+ else this.pendingInput.push(data);
23478
+ }
23479
+ /** Close the program's input, which a reader sees as end-of-file. */
23480
+ endInput() {
23481
+ this.inputEnded = true;
23482
+ this.end?.();
23483
+ }
23484
+ /** Called by the task once the program's stdin exists. */
23485
+ acceptInput(input, end) {
23486
+ this.input = input;
23487
+ this.end = end;
23488
+ for (const chunk of this.pendingInput.splice(0)) input(chunk);
23489
+ if (this.inputEnded) end();
22409
23490
  }
22410
23491
  kill(_signal = "SIGTERM") {
22411
23492
  this.killed = true;
@@ -22517,6 +23598,46 @@ var PodChildProcess = class {
22517
23598
  }
22518
23599
  };
22519
23600
  var nextChildPid = 805306368;
23601
+ var liveProcesses = [];
23602
+ var reportingInstalled = false;
23603
+ function reportEscapedError(reason) {
23604
+ const target = liveProcesses.at(-1);
23605
+ if (!target) return false;
23606
+ target.error(formatError(reason));
23607
+ target.exitNow(1);
23608
+ return true;
23609
+ }
23610
+ function trackProcess(proc) {
23611
+ liveProcesses.push(proc);
23612
+ if (!reportingInstalled) {
23613
+ reportingInstalled = true;
23614
+ installEscapedErrorReporting();
23615
+ }
23616
+ return () => {
23617
+ const index = liveProcesses.indexOf(proc);
23618
+ if (index >= 0) liveProcesses.splice(index, 1);
23619
+ if (liveProcesses.length === 0) {
23620
+ reportingInstalled = false;
23621
+ removeEscapedErrorReporting();
23622
+ }
23623
+ };
23624
+ }
23625
+ var onNodeRejection = (reason) => {
23626
+ if (!reportEscapedError(reason)) throw reason;
23627
+ };
23628
+ var onBrowserRejection = (event) => {
23629
+ if (reportEscapedError(event.reason)) event.preventDefault();
23630
+ };
23631
+ function installEscapedErrorReporting() {
23632
+ const host2 = globalThis;
23633
+ if (host2.process?.on && host2.process.versions?.node) host2.process.on("unhandledRejection", onNodeRejection);
23634
+ else host2.addEventListener?.("unhandledrejection", onBrowserRejection);
23635
+ }
23636
+ function removeEscapedErrorReporting() {
23637
+ const host2 = globalThis;
23638
+ if (host2.process?.off && host2.process.versions?.node) host2.process.off("unhandledRejection", onNodeRejection);
23639
+ else host2.removeEventListener?.("unhandledrejection", onBrowserRejection);
23640
+ }
22520
23641
  var DRAIN_TURNS = 4;
22521
23642
  var LocalRuntimePod = class _LocalRuntimePod {
22522
23643
  volume = new MemoryVolume();
@@ -22546,6 +23667,7 @@ var LocalRuntimePod = class _LocalRuntimePod {
22546
23667
  modules;
22547
23668
  esbuild;
22548
23669
  constructor(options) {
23670
+ ensureProcessGlobal();
22549
23671
  this.workdir = options.workdir ?? "/";
22550
23672
  this.env = { ...options.env };
22551
23673
  this.aliases = { ...WASM_ALIASES, ...options.aliases };
@@ -22577,8 +23699,9 @@ var LocalRuntimePod = class _LocalRuntimePod {
22577
23699
  const env2 = { ...this.env, ...isRecord(options.env) ? options.env : {} };
22578
23700
  const owner = `${this.instanceId}:${Math.random().toString(36).slice(2)}`;
22579
23701
  return new LocalProcess(async (proc) => {
23702
+ const untrack = trackProcess(proc);
22580
23703
  let requestedExit = 0;
22581
- let evaluating = true;
23704
+ let engine;
22582
23705
  const core = createCoreModules({
22583
23706
  volume: this.volume,
22584
23707
  cwd,
@@ -22586,16 +23709,24 @@ var LocalRuntimePod = class _LocalRuntimePod {
22586
23709
  argv: Array.isArray(options.argv) ? options.argv : ["/usr/bin/node", script, ...args.slice(1)],
22587
23710
  stdout: (text2) => proc.output(text2),
22588
23711
  stderr: (text2) => proc.error(text2),
23712
+ /* `process.exit` ends the process either way. The throw is only to
23713
+ * abandon the rest of a module body still running synchronously —
23714
+ * thrown from a later callback it would escape into whichever library
23715
+ * scheduled that callback and look like an unrelated crash. */
22589
23716
  onExit: (code) => {
22590
23717
  requestedExit = code;
22591
- if (evaluating) throw new ProcessExit(code);
22592
23718
  proc.exitNow(code);
23719
+ if (engine?.isEvaluating) throw new ProcessExit(code);
22593
23720
  },
22594
23721
  http: { router: this.router, owner },
22595
23722
  spawnChild: (config) => this.processManager.spawn(config),
22596
- ...typeof options.stdinPath === "string" ? { stdinPath: options.stdinPath } : {}
23723
+ ...typeof options.stdinPath === "string" ? { stdinPath: options.stdinPath } : {},
23724
+ ...options.interactiveStdin ? { interactiveStdin: true } : {},
23725
+ ...options.tty ? { tty: true } : {},
23726
+ onRawMode: (enabled) => proc.emit("rawmode", enabled)
22597
23727
  });
22598
- const engine = new CommonJsEngine(this.volume, {
23728
+ proc.acceptInput((data) => core.writeStdin(data), () => core.endStdin());
23729
+ engine = new CommonJsEngine(this.volume, {
22599
23730
  cwd,
22600
23731
  builtins: core.builtins,
22601
23732
  globals: core.globals,
@@ -22603,18 +23734,15 @@ var LocalRuntimePod = class _LocalRuntimePod {
22603
23734
  overrides: this.modules
22604
23735
  });
22605
23736
  try {
22606
- try {
22607
- await engine.run(script);
22608
- } finally {
22609
- evaluating = false;
22610
- }
22611
- await this.settle(owner, core.pendingHandles);
23737
+ await engine.run(script);
23738
+ await this.settle(owner, core.pendingHandles, core.readingStdin);
22612
23739
  if (this.router.activePorts(owner).length) {
22613
23740
  await proc.waitForKill();
22614
23741
  return 137;
22615
23742
  }
22616
23743
  return requestedExit;
22617
23744
  } finally {
23745
+ untrack();
22618
23746
  this.router.closeOwner(owner);
22619
23747
  }
22620
23748
  });
@@ -22634,12 +23762,12 @@ var LocalRuntimePod = class _LocalRuntimePod {
22634
23762
  * A plain script that has genuinely finished falls straight through both,
22635
23763
  * costing a handful of empty turns.
22636
23764
  */
22637
- async settle(owner, pendingHandles) {
23765
+ async settle(owner, pendingHandles, readingStdin) {
22638
23766
  for (let turn = 0; turn < DRAIN_TURNS; turn++) {
22639
23767
  if (this.router.activePorts(owner).length) return;
22640
23768
  await new Promise((resolve2) => setTimeout(resolve2, 0));
22641
23769
  }
22642
- while (!this.router.activePorts(owner).length && pendingHandles() > 0) {
23770
+ while (!this.router.activePorts(owner).length && (pendingHandles() > 0 || readingStdin())) {
22643
23771
  await new Promise((resolve2) => setTimeout(resolve2, 5));
22644
23772
  }
22645
23773
  }
@@ -22771,9 +23899,9 @@ var Container = class _Container {
22771
23899
  }
22772
23900
  mountSync(files, opts) {
22773
23901
  this.assertActive();
22774
- const base = opts.cwd ?? this.defaults.cwd;
23902
+ const base2 = opts.cwd ?? this.defaults.cwd;
22775
23903
  for (const [key, content] of Object.entries(files)) {
22776
- const abs = resolve(base, key);
23904
+ const abs = resolve(base2, key);
22777
23905
  const parent = dirname(abs);
22778
23906
  if (!this.kernel.vfs.lexists(parent)) {
22779
23907
  this.kernel.vfs.mkdir(parent, { recursive: true, mode: 493, cred: this.defaults.cred });
@@ -23015,17 +24143,17 @@ var Container = class _Container {
23015
24143
  body: init.body ?? null
23016
24144
  });
23017
24145
  const bodyRaw = res.body;
23018
- const bytes = bodyRaw instanceof Uint8Array ? bodyRaw : (
24146
+ const bytes2 = bodyRaw instanceof Uint8Array ? bodyRaw : (
23019
24147
  // The binary dispatcher answers with an ArrayBuffer.
23020
24148
  bodyRaw instanceof ArrayBuffer ? new Uint8Array(bodyRaw) : typeof bodyRaw === "string" ? new TextEncoder().encode(bodyRaw) : new Uint8Array(0)
23021
24149
  );
23022
- const body = typeof bodyRaw === "string" ? bodyRaw : new TextDecoder().decode(bytes);
24150
+ const body = typeof bodyRaw === "string" ? bodyRaw : new TextDecoder().decode(bytes2);
23023
24151
  return {
23024
24152
  status: res.statusCode ?? 200,
23025
24153
  statusText: res.statusMessage ?? "",
23026
24154
  headers: res.headers ?? {},
23027
24155
  body,
23028
- bytes,
24156
+ bytes: bytes2,
23029
24157
  json() {
23030
24158
  return JSON.parse(body);
23031
24159
  }
@@ -23255,7 +24383,7 @@ var Terminal = class {
23255
24383
  this.currentStdin?.end();
23256
24384
  return;
23257
24385
  }
23258
- this.write(ch === "\r" ? "\r\n" : ch);
24386
+ if (!this.currentStdin?.rawMode) this.write(ch === "\r" ? "\r\n" : ch);
23259
24387
  this.currentStdin?.write(ch === "\r" ? "\n" : ch);
23260
24388
  return;
23261
24389
  }
@@ -23411,8 +24539,8 @@ var Terminal = class {
23411
24539
  // ── completion ────────────────────────────────────────────────────────────
23412
24540
  complete() {
23413
24541
  const left = this.buffer.slice(0, this.cursor);
23414
- const match = /(\S*)$/.exec(left);
23415
- const word = match?.[1] ?? "";
24542
+ const match2 = /(\S*)$/.exec(left);
24543
+ const word = match2?.[1] ?? "";
23416
24544
  const isFirstWord = left.slice(0, left.length - word.length).trim() === "";
23417
24545
  const candidates = isFirstWord && !word.includes("/") ? this.completeCommand(word) : this.completePath(word);
23418
24546
  if (candidates.length === 0) return;
@@ -23517,13 +24645,13 @@ var Terminal = class {
23517
24645
  this.writePrompt();
23518
24646
  }
23519
24647
  };
23520
- function expandPrompt(format, session) {
24648
+ function expandPrompt(format3, session) {
23521
24649
  const shell = session.shell;
23522
24650
  const home = shell.vars.get("HOME") ?? "/root";
23523
24651
  const cwd = shell.cwd;
23524
24652
  const user = shell.kernel.users.nameForUid(shell.cred.uid);
23525
24653
  const now = new Date(shell.kernel.now());
23526
- return format.replace(/\\(.)/g, (_, ch) => {
24654
+ return format3.replace(/\\(.)/g, (_, ch) => {
23527
24655
  switch (ch) {
23528
24656
  case "u":
23529
24657
  return user;