sandboxedjs 0.1.24 → 0.1.25

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.d.cts CHANGED
@@ -2527,6 +2527,7 @@ declare class LocalRuntimePod implements RuntimePod {
2527
2527
  private readonly env;
2528
2528
  private readonly aliases;
2529
2529
  private readonly modules;
2530
+ private readonly esbuild;
2530
2531
  private constructor();
2531
2532
  static boot(options?: LocalRuntimeOptions): Promise<LocalRuntimePod>;
2532
2533
  spawn(command: string, args?: string[], options?: Record<string, unknown>): Promise<RuntimeProcess>;
package/dist/index.d.ts CHANGED
@@ -2527,6 +2527,7 @@ declare class LocalRuntimePod implements RuntimePod {
2527
2527
  private readonly env;
2528
2528
  private readonly aliases;
2529
2529
  private readonly modules;
2530
+ private readonly esbuild;
2530
2531
  private constructor();
2531
2532
  static boot(options?: LocalRuntimeOptions): Promise<LocalRuntimePod>;
2532
2533
  spawn(command: string, args?: string[], options?: Record<string, unknown>): Promise<RuntimeProcess>;
package/dist/index.js CHANGED
@@ -833,8 +833,8 @@ function splitTopLevel(s, sep) {
833
833
  out.push(cur);
834
834
  return out;
835
835
  }
836
- function compileBracket(pattern, start) {
837
- let i = start + 1;
836
+ function compileBracket(pattern, start2) {
837
+ let i = start2 + 1;
838
838
  let negate = false;
839
839
  if (pattern[i] === "!" || pattern[i] === "^") {
840
840
  negate = true;
@@ -1186,7 +1186,7 @@ var init_arith = __esm({
1186
1186
  return value;
1187
1187
  }
1188
1188
  assignment() {
1189
- const start = this.i;
1189
+ const start2 = this.i;
1190
1190
  const t = this.peek();
1191
1191
  if (t.kind === "name") {
1192
1192
  const next = this.toks[this.i + 1];
@@ -1236,7 +1236,7 @@ var init_arith = __esm({
1236
1236
  return this.writeVar(t.value, Math.trunc(result));
1237
1237
  }
1238
1238
  }
1239
- this.i = start;
1239
+ this.i = start2;
1240
1240
  return this.ternary();
1241
1241
  }
1242
1242
  ternary() {
@@ -1529,7 +1529,7 @@ function splitBraceAlternatives(body) {
1529
1529
  function expandSequence(body) {
1530
1530
  const numeric = /^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/.exec(body);
1531
1531
  if (numeric) {
1532
- const start = Number(numeric[1]);
1532
+ const start2 = Number(numeric[1]);
1533
1533
  const end = Number(numeric[2]);
1534
1534
  let step = numeric[3] !== void 0 ? Math.abs(Number(numeric[3])) : 1;
1535
1535
  if (step === 0) step = 1;
@@ -1538,18 +1538,18 @@ function expandSequence(body) {
1538
1538
  /^-?0\d/.test(numeric[2]) ? numeric[2].replace("-", "").length : 0
1539
1539
  );
1540
1540
  const out = [];
1541
- if (start <= end) for (let i = start; i <= end; i += step) out.push(padNumber(i, width));
1542
- else for (let i = start; i >= end; i -= step) out.push(padNumber(i, width));
1541
+ if (start2 <= end) for (let i = start2; i <= end; i += step) out.push(padNumber(i, width));
1542
+ else for (let i = start2; i >= end; i -= step) out.push(padNumber(i, width));
1543
1543
  return out;
1544
1544
  }
1545
1545
  const alpha = /^([A-Za-z])\.\.([A-Za-z])(?:\.\.(-?\d+))?$/.exec(body);
1546
1546
  if (alpha) {
1547
- const start = alpha[1].charCodeAt(0);
1547
+ const start2 = alpha[1].charCodeAt(0);
1548
1548
  const end = alpha[2].charCodeAt(0);
1549
1549
  const step = alpha[3] !== void 0 ? Math.abs(Number(alpha[3])) || 1 : 1;
1550
1550
  const out = [];
1551
- if (start <= end) for (let i = start; i <= end; i += step) out.push(String.fromCharCode(i));
1552
- else for (let i = start; i >= end; i -= step) out.push(String.fromCharCode(i));
1551
+ if (start2 <= end) for (let i = start2; i <= end; i += step) out.push(String.fromCharCode(i));
1552
+ else for (let i = start2; i >= end; i -= step) out.push(String.fromCharCode(i));
1553
1553
  return out;
1554
1554
  }
1555
1555
  return null;
@@ -1659,10 +1659,10 @@ async function expandFragments(word, ctx, opts = {}) {
1659
1659
  flushLiteral();
1660
1660
  return out;
1661
1661
  }
1662
- async function expandDoubleQuoted(word, start, ctx, opts) {
1662
+ async function expandDoubleQuoted(word, start2, ctx, opts) {
1663
1663
  const out = [];
1664
1664
  let literal = "";
1665
- let i = start;
1665
+ let i = start2;
1666
1666
  const flush = () => {
1667
1667
  if (literal !== "") {
1668
1668
  out.push({ text: literal, split: false, glob: false });
@@ -1962,9 +1962,9 @@ function stripAffix(value, pattern, op, ctx) {
1962
1962
  function substitute(value, pattern, replacement, opts) {
1963
1963
  const matchOpts = { pathname: false, dot: true, extglob: opts.extglob };
1964
1964
  const chars = [...value];
1965
- const matchAt = (start) => {
1966
- for (let end = chars.length; end >= start; end--) {
1967
- if (fnmatch(pattern, chars.slice(start, end).join(""), matchOpts)) return end;
1965
+ const matchAt = (start2) => {
1966
+ for (let end = chars.length; end >= start2; end--) {
1967
+ if (fnmatch(pattern, chars.slice(start2, end).join(""), matchOpts)) return end;
1968
1968
  }
1969
1969
  return -1;
1970
1970
  };
@@ -1973,9 +1973,9 @@ function substitute(value, pattern, replacement, opts) {
1973
1973
  return end < 0 ? value : replacement + chars.slice(end).join("");
1974
1974
  }
1975
1975
  if (opts.anchorEnd) {
1976
- for (let start = 0; start <= chars.length; start++) {
1977
- if (fnmatch(pattern, chars.slice(start).join(""), matchOpts)) {
1978
- return chars.slice(0, start).join("") + replacement;
1976
+ for (let start2 = 0; start2 <= chars.length; start2++) {
1977
+ if (fnmatch(pattern, chars.slice(start2).join(""), matchOpts)) {
1978
+ return chars.slice(0, start2).join("") + replacement;
1979
1979
  }
1980
1980
  }
1981
1981
  return value;
@@ -2834,18 +2834,18 @@ function builtinEcho({ argv, io }) {
2834
2834
  function builtinPrintf({ argv, io }) {
2835
2835
  const args = argv.slice(1);
2836
2836
  let varName;
2837
- let start = 0;
2837
+ let start2 = 0;
2838
2838
  if (args[0] === "-v" && args[1] !== void 0) {
2839
2839
  varName = args[1];
2840
- start = 2;
2840
+ start2 = 2;
2841
2841
  }
2842
- const format = args[start];
2842
+ const format = args[start2];
2843
2843
  if (format === void 0) {
2844
2844
  io.stderr.write("printf: usage: printf [-v var] format [arguments]\n");
2845
2845
  return 2;
2846
2846
  }
2847
2847
  try {
2848
- const text2 = formatPrintf(format, args.slice(start + 1));
2848
+ const text2 = formatPrintf(format, args.slice(start2 + 1));
2849
2849
  if (varName) return 0;
2850
2850
  io.stdout.write(text2);
2851
2851
  return 0;
@@ -3901,9 +3901,9 @@ function builtinHistory({ shell, argv, io }) {
3901
3901
  return 0;
3902
3902
  }
3903
3903
  const limit = Number(args.find((a) => /^\d+$/.test(a)) ?? shell.history.length);
3904
- const start = Math.max(0, shell.history.length - limit);
3905
- shell.history.slice(start).forEach((entry, idx) => {
3906
- io.stdout.write(`${String(start + idx + 1).padStart(5)} ${entry}
3904
+ const start2 = Math.max(0, shell.history.length - limit);
3905
+ shell.history.slice(start2).forEach((entry, idx) => {
3906
+ io.stdout.write(`${String(start2 + idx + 1).padStart(5)} ${entry}
3907
3907
  `);
3908
3908
  });
3909
3909
  return 0;
@@ -4672,8 +4672,8 @@ var Vfs = class {
4672
4672
  /** Depth-first walk yielding absolute paths. Symlinks are not followed. */
4673
4673
  *walk(abs, opts = {}) {
4674
4674
  const { includeSelf = true, cred, maxDepth = Infinity } = opts;
4675
- const start = clean(abs);
4676
- if (includeSelf) yield start;
4675
+ const start2 = clean(abs);
4676
+ if (includeSelf) yield start2;
4677
4677
  const recurse = (dir3, depth) => {
4678
4678
  if (depth > maxDepth) return [];
4679
4679
  let names;
@@ -4697,11 +4697,11 @@ var Vfs = class {
4697
4697
  };
4698
4698
  let st = null;
4699
4699
  try {
4700
- st = this.lstat(start);
4700
+ st = this.lstat(start2);
4701
4701
  } catch {
4702
4702
  return;
4703
4703
  }
4704
- if (st.isDirectory()) yield* recurse(start, 1);
4704
+ if (st.isDirectory()) yield* recurse(start2, 1);
4705
4705
  }
4706
4706
  /** Recursive copy used by `cp -r` and the container's `copyIn` helper. */
4707
4707
  copyTree(from, to, cred) {
@@ -5229,8 +5229,8 @@ var ProcessTable = class {
5229
5229
  this.map.clear();
5230
5230
  }
5231
5231
  };
5232
- function resetPidCounter(start = 1) {
5233
- nextPid = start;
5232
+ function resetPidCounter(start2 = 1) {
5233
+ nextPid = start2;
5234
5234
  }
5235
5235
 
5236
5236
  // src/kernel/users.ts
@@ -6508,8 +6508,8 @@ function createProcProvider(kernel) {
6508
6508
  loadavg: () => textFile(() => {
6509
6509
  const running = kernel.procs.list().filter((p) => p.state === "R").length;
6510
6510
  const total = kernel.procs.list().length;
6511
- const load2 = (running / kernel.cpus).toFixed(2);
6512
- return `${load2} ${load2} ${load2} ${running}/${total} ${kernel.procs.list().length + 1}
6511
+ const load = (running / kernel.cpus).toFixed(2);
6512
+ return `${load} ${load} ${load} ${running}/${total} ${kernel.procs.list().length + 1}
6513
6513
  `;
6514
6514
  }),
6515
6515
  meminfo: () => textFile(() => {
@@ -7009,7 +7009,7 @@ var Lexer = class _Lexer {
7009
7009
  return null;
7010
7010
  }
7011
7011
  readWord() {
7012
- const start = this.pos;
7012
+ const start2 = this.pos;
7013
7013
  let out = "";
7014
7014
  while (this.pos < this.src.length) {
7015
7015
  const ch = this.src[this.pos];
@@ -7059,10 +7059,10 @@ var Lexer = class _Lexer {
7059
7059
  out = this.src[this.pos] ?? "";
7060
7060
  this.pos++;
7061
7061
  }
7062
- this.push({ type: "word", value: out, pos: start });
7062
+ this.push({ type: "word", value: out, pos: start2 });
7063
7063
  }
7064
7064
  readDoubleQuoted() {
7065
- const start = this.pos;
7065
+ const start2 = this.pos;
7066
7066
  this.pos++;
7067
7067
  let out = '"';
7068
7068
  while (this.pos < this.src.length) {
@@ -7093,14 +7093,14 @@ var Lexer = class _Lexer {
7093
7093
  out += ch;
7094
7094
  this.pos++;
7095
7095
  }
7096
- throw new IncompleteInputError("unexpected EOF while looking for matching `\"'", start);
7096
+ throw new IncompleteInputError("unexpected EOF while looking for matching `\"'", start2);
7097
7097
  }
7098
7098
  /**
7099
7099
  * Consume a balanced `$( ... )` or `${ ... }`, honouring nesting and quotes
7100
7100
  * inside. `prefix` is emitted before the opening delimiter.
7101
7101
  */
7102
7102
  readBalanced(open, close, openIdx, prefix) {
7103
- const start = this.pos;
7103
+ const start2 = this.pos;
7104
7104
  let depth = 0;
7105
7105
  let i = openIdx;
7106
7106
  for (; i < this.src.length; i++) {
@@ -7111,7 +7111,7 @@ var Lexer = class _Lexer {
7111
7111
  }
7112
7112
  if (c === "'" && open === "(") {
7113
7113
  const end = this.src.indexOf("'", i + 1);
7114
- if (end < 0) throw new IncompleteInputError("unexpected EOF in command substitution", start);
7114
+ if (end < 0) throw new IncompleteInputError("unexpected EOF in command substitution", start2);
7115
7115
  i = end;
7116
7116
  continue;
7117
7117
  }
@@ -7129,7 +7129,7 @@ var Lexer = class _Lexer {
7129
7129
  if (depth === 0) break;
7130
7130
  }
7131
7131
  }
7132
- if (i >= this.src.length) throw new IncompleteInputError(`unexpected EOF while looking for matching \`${close}'`, start);
7132
+ if (i >= this.src.length) throw new IncompleteInputError(`unexpected EOF while looking for matching \`${close}'`, start2);
7133
7133
  const text2 = prefix + this.src.slice(openIdx, i + 1);
7134
7134
  this.pos = i + 1;
7135
7135
  return text2;
@@ -11174,9 +11174,9 @@ var ScriptParser = class {
11174
11174
  }
11175
11175
  parseRange() {
11176
11176
  this.skipBlanks();
11177
- const start = this.parseAddress();
11178
- if (!start) return { negated: this.parseNegation() };
11179
- let range = { start, negated: false };
11177
+ const start2 = this.parseAddress();
11178
+ if (!start2) return { negated: this.parseNegation() };
11179
+ let range = { start: start2, negated: false };
11180
11180
  if (this.src[this.i] === ",") {
11181
11181
  this.i++;
11182
11182
  this.skipBlanks();
@@ -11385,8 +11385,8 @@ function toJsRegex(pattern, extended) {
11385
11385
  }
11386
11386
  return out;
11387
11387
  }
11388
- function findBracketEnd(pattern, start) {
11389
- let i = start + 1;
11388
+ function findBracketEnd(pattern, start2) {
11389
+ let i = start2 + 1;
11390
11390
  if (pattern[i] === "^") i++;
11391
11391
  if (pattern[i] === "]") i++;
11392
11392
  while (i < pattern.length) {
@@ -12977,14 +12977,14 @@ var Interpreter = class {
12977
12977
  }
12978
12978
  case "substr": {
12979
12979
  const source = [...str(0)];
12980
- let start = Math.round(num(1));
12980
+ let start2 = Math.round(num(1));
12981
12981
  let length = args.length > 2 ? Math.round(num(2)) : Infinity;
12982
- if (start < 1) {
12983
- if (Number.isFinite(length)) length += start - 1;
12984
- start = 1;
12982
+ if (start2 < 1) {
12983
+ if (Number.isFinite(length)) length += start2 - 1;
12984
+ start2 = 1;
12985
12985
  }
12986
12986
  if (length <= 0) return Value.fromString("");
12987
- return Value.fromString(source.slice(start - 1, Number.isFinite(length) ? start - 1 + length : void 0).join(""));
12987
+ return Value.fromString(source.slice(start2 - 1, Number.isFinite(length) ? start2 - 1 + length : void 0).join(""));
12988
12988
  }
12989
12989
  case "index": {
12990
12990
  const haystack = [...str(0)];
@@ -13402,8 +13402,8 @@ function translateEre(pattern) {
13402
13402
  }
13403
13403
  return out;
13404
13404
  }
13405
- function findClassEnd(pattern, start) {
13406
- let i = start + 1;
13405
+ function findClassEnd(pattern, start2) {
13406
+ let i = start2 + 1;
13407
13407
  if (pattern[i] === "^") i++;
13408
13408
  if (pattern[i] === "]") i++;
13409
13409
  while (i < pattern.length) {
@@ -13733,10 +13733,10 @@ var sort = defineCommand({
13733
13733
  const fieldOf = (line, spec) => {
13734
13734
  const m = /^(\d+)(?:\.(\d+))?([a-zA-Z]*)(?:,(\d+)(?:\.(\d+))?([a-zA-Z]*))?$/.exec(spec);
13735
13735
  if (!m) return line;
13736
- const start = Number(m[1]) - 1;
13736
+ const start2 = Number(m[1]) - 1;
13737
13737
  const end = m[4] !== void 0 ? Number(m[4]) : void 0;
13738
13738
  const fields = separator === void 0 ? line.trim().split(/\s+/) : line.split(separator);
13739
- const slice = fields.slice(start, end === void 0 ? void 0 : end);
13739
+ const slice = fields.slice(start2, end === void 0 ? void 0 : end);
13740
13740
  return slice.join(separator ?? " ");
13741
13741
  };
13742
13742
  const normalize3 = (line) => {
@@ -13887,9 +13887,9 @@ function parseRanges(spec) {
13887
13887
  return spec.split(",").map((part) => {
13888
13888
  const m = /^(\d*)-(\d*)$/.exec(part);
13889
13889
  if (m) {
13890
- const start = m[1] === "" ? 1 : Number(m[1]);
13890
+ const start2 = m[1] === "" ? 1 : Number(m[1]);
13891
13891
  const end = m[2] === "" ? Infinity : Number(m[2]);
13892
- return [start, end];
13892
+ return [start2, end];
13893
13893
  }
13894
13894
  const n = Number(part);
13895
13895
  return [n, n];
@@ -13898,7 +13898,7 @@ function parseRanges(spec) {
13898
13898
  function pick(items, ranges, complement) {
13899
13899
  const selected = items.filter((_, idx) => {
13900
13900
  const position = idx + 1;
13901
- const inRange = ranges.some(([start, end]) => position >= start && position <= end);
13901
+ const inRange = ranges.some(([start2, end]) => position >= start2 && position <= end);
13902
13902
  return complement ? !inRange : inRange;
13903
13903
  });
13904
13904
  return selected;
@@ -14002,9 +14002,9 @@ function expandSet(spec) {
14002
14002
  continue;
14003
14003
  }
14004
14004
  if (spec[i + 1] === "-" && i + 2 < spec.length && spec[i + 2] !== "]") {
14005
- const start = spec.charCodeAt(i);
14005
+ const start2 = spec.charCodeAt(i);
14006
14006
  const end = spec.charCodeAt(i + 2);
14007
- for (let c = start; c <= end; c++) out.push(String.fromCharCode(c));
14007
+ for (let c = start2; c <= end; c++) out.push(String.fromCharCode(c));
14008
14008
  i += 3;
14009
14009
  continue;
14010
14010
  }
@@ -14607,10 +14607,10 @@ var grep = defineCommand({
14607
14607
  const emitted = /* @__PURE__ */ new Set();
14608
14608
  let lastPrinted = -2;
14609
14609
  for (const index of matched) {
14610
- const start = Math.max(0, index - before);
14610
+ const start2 = Math.max(0, index - before);
14611
14611
  const end = Math.min(lines.length - 1, index + after);
14612
- if ((before || after) && lastPrinted >= 0 && start > lastPrinted + 1) ctx.line("--");
14613
- for (let i = start; i <= end; i++) {
14612
+ if ((before || after) && lastPrinted >= 0 && start2 > lastPrinted + 1) ctx.line("--");
14613
+ for (let i = start2; i <= end; i++) {
14614
14614
  if (emitted.has(i)) continue;
14615
14615
  emitted.add(i);
14616
14616
  const isMatchLine = matched.includes(i);
@@ -15026,8 +15026,8 @@ var diff = defineCommand({
15026
15026
  return 1;
15027
15027
  }
15028
15028
  });
15029
- function formatRange(start, count) {
15030
- return count <= 1 ? String(start) : `${start},${start + count - 1}`;
15029
+ function formatRange(start2, count) {
15030
+ return count <= 1 ? String(start2) : `${start2},${start2 + count - 1}`;
15031
15031
  }
15032
15032
  function diffLines(a, b) {
15033
15033
  const n = a.length;
@@ -15084,11 +15084,11 @@ function buildHunks(edits, a, b, context) {
15084
15084
  i++;
15085
15085
  continue;
15086
15086
  }
15087
- let start = Math.max(0, i - context);
15087
+ let start2 = Math.max(0, i - context);
15088
15088
  let end = i;
15089
15089
  while (end < edits.length && (changed[end] || edits.slice(end, end + context + 1).some((_, k) => changed[end + k]))) end++;
15090
15090
  end = Math.min(edits.length, end + context);
15091
- const slice = edits.slice(start, end);
15091
+ const slice = edits.slice(start2, end);
15092
15092
  const aStart = slice.find((e) => e.op !== "insert")?.aIndex ?? 0;
15093
15093
  const bStart = slice.find((e) => e.op !== "delete")?.bIndex ?? 0;
15094
15094
  const lines = [];
@@ -18356,11 +18356,11 @@ function safeTarget(destination, name) {
18356
18356
  function stripPackageRoot(name) {
18357
18357
  return name.replace(/^\.\//, "").replace(/^package\//, "").replace(/\/$/, "");
18358
18358
  }
18359
- function text(bytes, start, length) {
18360
- return new TextDecoder().decode(bytes.subarray(start, start + length)).replace(/\0.*$/, "").trim();
18359
+ function text(bytes, start2, length) {
18360
+ return new TextDecoder().decode(bytes.subarray(start2, start2 + length)).replace(/\0.*$/, "").trim();
18361
18361
  }
18362
- function octal(bytes, start, length) {
18363
- return parseInt(text(bytes, start, length).replace(/^0+/, "") || "0", 8);
18362
+ function octal(bytes, start2, length) {
18363
+ return parseInt(text(bytes, start2, length).replace(/^0+/, "") || "0", 8);
18364
18364
  }
18365
18365
  function parsePax(data) {
18366
18366
  const value = new TextDecoder().decode(data);
@@ -20077,8 +20077,8 @@ var CommonJsEngine = class {
20077
20077
  throw this.moduleNotFound(specifier, importer);
20078
20078
  }
20079
20079
  load(filename, parent, isMain) {
20080
- const cached2 = this.cache.get(filename);
20081
- if (cached2) return cached2;
20080
+ const cached = this.cache.get(filename);
20081
+ if (cached) return cached;
20082
20082
  const module = {
20083
20083
  id: isMain ? "." : filename,
20084
20084
  filename,
@@ -20311,8 +20311,8 @@ ${code}
20311
20311
  }
20312
20312
  }
20313
20313
  readManifest(root) {
20314
- const cached2 = this.manifests.get(root);
20315
- if (cached2 !== void 0) return cached2;
20314
+ const cached = this.manifests.get(root);
20315
+ if (cached !== void 0) return cached;
20316
20316
  let manifest = null;
20317
20317
  try {
20318
20318
  manifest = JSON.parse(this.readText(join(root, "package.json")));
@@ -20374,8 +20374,8 @@ function namespaceOf(exports) {
20374
20374
  }
20375
20375
  const target = exports;
20376
20376
  if (target.__esModule) return target;
20377
- const cached2 = namespaces.get(target);
20378
- if (cached2) return cached2;
20377
+ const cached = namespaces.get(target);
20378
+ if (cached) return cached;
20379
20379
  const namespace = {};
20380
20380
  for (const key of ownKeys(target)) {
20381
20381
  if (key === "default" || key === "__esModule") continue;
@@ -20740,9 +20740,9 @@ function createCryptoModule() {
20740
20740
  },
20741
20741
  randomFill(target, offset = 0, size, callback) {
20742
20742
  const done = [offset, size, callback].find((value) => typeof value === "function");
20743
- const start = typeof offset === "number" ? offset : 0;
20744
- const length = typeof size === "number" ? size : target.length - start;
20745
- cryptoObject.getRandomValues(target.subarray(start, start + length));
20743
+ const start2 = typeof offset === "number" ? offset : 0;
20744
+ const length = typeof size === "number" ? size : target.length - start2;
20745
+ cryptoObject.getRandomValues(target.subarray(start2, start2 + length));
20746
20746
  queueMicrotask(() => done?.(null, target));
20747
20747
  },
20748
20748
  hash(algorithm, data, encoding = "hex") {
@@ -20839,7 +20839,7 @@ function createChildProcessModule(spawnChild, defaultCwd) {
20839
20839
  const shell = typeof options.shell === "string" ? options.shell : "/bin/sh";
20840
20840
  return { file: shell, args: ["-c", command] };
20841
20841
  };
20842
- const start = (file3, args, options) => {
20842
+ const start2 = (file3, args, options) => {
20843
20843
  const resolved = options.shell ? throughShell([file3, ...args].join(" "), options) : { file: file3, args };
20844
20844
  const handle = spawnChild({
20845
20845
  command: resolved.file,
@@ -20850,8 +20850,8 @@ function createChildProcessModule(spawnChild, defaultCwd) {
20850
20850
  return new ChildProcess(handle, resolved.file, resolved.args);
20851
20851
  };
20852
20852
  const spawn = (file3, args = [], options = {}) => {
20853
- if (!Array.isArray(args)) return start(file3, [], args);
20854
- return start(file3, args, options);
20853
+ if (!Array.isArray(args)) return start2(file3, [], args);
20854
+ return start2(file3, args, options);
20855
20855
  };
20856
20856
  const collect = (child, options, callback) => {
20857
20857
  if (!callback) return child;
@@ -20879,12 +20879,12 @@ ${err.join("")}`),
20879
20879
  const exec = (command, options = {}, callback) => {
20880
20880
  const [opts, cb] = normalize2(options, callback);
20881
20881
  const { file: file3, args } = throughShell(command, opts);
20882
- return collect(start(file3, args, { ...opts, shell: false }), opts, cb);
20882
+ return collect(start2(file3, args, { ...opts, shell: false }), opts, cb);
20883
20883
  };
20884
20884
  const execFile = (file3, args = [], options = {}, callback) => {
20885
20885
  const list = Array.isArray(args) ? args : [];
20886
20886
  const [opts, cb] = Array.isArray(args) ? normalize2(options, callback) : normalize2(args, options);
20887
- return collect(start(file3, list, opts), opts, cb);
20887
+ return collect(start2(file3, list, opts), opts, cb);
20888
20888
  };
20889
20889
  return {
20890
20890
  spawn,
@@ -21360,9 +21360,9 @@ function createFsModule(volume, cwd, stdinPath) {
21360
21360
  readSync: (fd, target, offset, length, position) => {
21361
21361
  const file3 = requiredFd(fds, fd);
21362
21362
  const source = volume.readFileSync(resolveLinks(volume, file3.path));
21363
- const start = position ?? file3.position;
21364
- const count = Math.max(0, Math.min(length, source.length - start));
21365
- target.set(source.subarray(start, start + count), offset);
21363
+ const start2 = position ?? file3.position;
21364
+ const count = Math.max(0, Math.min(length, source.length - start2));
21365
+ target.set(source.subarray(start2, start2 + count), offset);
21366
21366
  if (position == null) file3.position += count;
21367
21367
  return count;
21368
21368
  },
@@ -21371,12 +21371,12 @@ function createFsModule(volume, cwd, stdinPath) {
21371
21371
  const input = bytes(data);
21372
21372
  const chunk = typeof data === "string" ? input : input.subarray(offset ?? 0, (offset ?? 0) + (length ?? input.length));
21373
21373
  const old = volume.readFileSync(file3.path);
21374
- const start = file3.flags.startsWith("a") ? old.length : position ?? file3.position;
21375
- const next = new Uint8Array(Math.max(old.length, start + chunk.length));
21374
+ const start2 = file3.flags.startsWith("a") ? old.length : position ?? file3.position;
21375
+ const next = new Uint8Array(Math.max(old.length, start2 + chunk.length));
21376
21376
  next.set(old);
21377
- next.set(chunk, start);
21377
+ next.set(chunk, start2);
21378
21378
  volume.writeFileSync(file3.path, next);
21379
- if (position == null) file3.position = start + chunk.length;
21379
+ if (position == null) file3.position = start2 + chunk.length;
21380
21380
  return chunk.length;
21381
21381
  },
21382
21382
  createReadStream: (path) => {
@@ -22304,29 +22304,61 @@ var MemoryVolume = class {
22304
22304
  };
22305
22305
 
22306
22306
  // src/runtime/host-esbuild.ts
22307
- var cached = null;
22308
- function loadHostEsbuild() {
22309
- cached ??= load().catch((error) => {
22310
- if (typeof process !== "undefined" && process.env?.SANDBOXEDJS_DEBUG) {
22311
- console.error("[sandboxedjs] host esbuild unavailable:", error);
22312
- }
22313
- return null;
22307
+ var ASYNC_API = ["transform", "build", "context", "formatMessages", "analyzeMetafile"];
22308
+ function createHostEsbuild() {
22309
+ let loading = null;
22310
+ let started = null;
22311
+ const ensure = async () => {
22312
+ loading ??= start().then((api) => started = api);
22313
+ return loading;
22314
+ };
22315
+ const module = new Proxy({}, {
22316
+ get(_target, key) {
22317
+ if (typeof key !== "string") return void 0;
22318
+ if (ASYNC_API.includes(key)) {
22319
+ return async (...args) => {
22320
+ const api = await ensure();
22321
+ if (!api) throw esbuildUnavailable();
22322
+ return api[key](...args);
22323
+ };
22324
+ }
22325
+ if (key === "stop") return stop;
22326
+ return started?.[key];
22327
+ },
22328
+ has: (_target, key) => typeof key === "string"
22314
22329
  });
22315
- return cached;
22330
+ function stop() {
22331
+ try {
22332
+ started?.stop?.();
22333
+ } catch {
22334
+ }
22335
+ started = null;
22336
+ }
22337
+ return { module, stop };
22316
22338
  }
22317
- async function load() {
22339
+ async function start() {
22318
22340
  if (typeof process === "undefined" || process.versions?.node == null) return null;
22319
22341
  for (const specifier of ["esbuild-wasm", "esbuild"]) {
22320
22342
  try {
22321
- const esbuild = await nodeOnlyModule(specifier);
22322
- const api = esbuild.default ?? esbuild;
22343
+ const loaded = await nodeOnlyModule(specifier);
22344
+ const api = loaded.default ?? loaded;
22323
22345
  if (specifier === "esbuild-wasm") await api.initialize({});
22324
22346
  return api;
22325
- } catch {
22347
+ } catch (error) {
22348
+ if (typeof process !== "undefined" && process.env?.SANDBOXEDJS_DEBUG) {
22349
+ console.error(`[sandboxedjs] ${specifier} unavailable:`, error);
22350
+ }
22326
22351
  }
22327
22352
  }
22328
22353
  return null;
22329
22354
  }
22355
+ function esbuildUnavailable() {
22356
+ const error = new Error(
22357
+ "esbuild is unavailable: install `esbuild-wasm` to give the sandboxed runtime a build of esbuild it can execute."
22358
+ );
22359
+ error.code = "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM";
22360
+ return error;
22361
+ }
22330
22362
 
22331
22363
  // src/runtime/local-runtime-pod.ts
22332
22364
  var WASM_ALIASES = {
@@ -22512,11 +22544,16 @@ var LocalRuntimePod = class _LocalRuntimePod {
22512
22544
  env;
22513
22545
  aliases;
22514
22546
  modules;
22547
+ esbuild;
22515
22548
  constructor(options) {
22516
22549
  this.workdir = options.workdir ?? "/";
22517
22550
  this.env = { ...options.env };
22518
22551
  this.aliases = { ...WASM_ALIASES, ...options.aliases };
22519
22552
  this.modules = { ...options.modules };
22553
+ if (options.hostEsbuild !== false && !this.modules.esbuild) {
22554
+ this.esbuild = createHostEsbuild();
22555
+ this.modules.esbuild = this.esbuild.module;
22556
+ }
22520
22557
  if (options.onServerReady) {
22521
22558
  const notify = options.onServerReady;
22522
22559
  this.router.onListen = (port) => notify(port, `http://localhost:${port}`);
@@ -22529,12 +22566,7 @@ var LocalRuntimePod = class _LocalRuntimePod {
22529
22566
  this.seed(options.files ?? {});
22530
22567
  }
22531
22568
  static async boot(options = {}) {
22532
- const pod = new _LocalRuntimePod(options);
22533
- if (options.hostEsbuild !== false && !pod.modules.esbuild) {
22534
- const esbuild = await loadHostEsbuild();
22535
- if (esbuild) pod.modules.esbuild = esbuild;
22536
- }
22537
- return pod;
22569
+ return new _LocalRuntimePod(options);
22538
22570
  }
22539
22571
  async spawn(command, args = [], options = {}) {
22540
22572
  this.assertActive();
@@ -22626,6 +22658,7 @@ var LocalRuntimePod = class _LocalRuntimePod {
22626
22658
  teardown() {
22627
22659
  this.disposed = true;
22628
22660
  this.router.closeAll();
22661
+ this.esbuild?.stop();
22629
22662
  }
22630
22663
  seed(files) {
22631
22664
  for (const [path, data] of Object.entries(files)) {