@php-wasm/universal 3.0.19 → 3.0.21

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/index.js CHANGED
@@ -1,8 +1,8 @@
1
- var z = (t) => {
1
+ var B = (t) => {
2
2
  throw TypeError(t);
3
3
  };
4
- var O = (t, e, r) => e.has(t) || z("Cannot " + r);
5
- var u = (t, e, r) => (O(t, e, "read from private field"), r ? r.call(t) : e.get(t)), m = (t, e, r) => e.has(t) ? z("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r), w = (t, e, r, s) => (O(t, e, "write to private field"), s ? s.call(t, r) : e.set(t, r), r), y = (t, e, r) => (O(t, e, "access private method"), r);
4
+ var O = (t, e, r) => e.has(t) || B("Cannot " + r);
5
+ var u = (t, e, r) => (O(t, e, "read from private field"), r ? r.call(t) : e.get(t)), y = (t, e, r) => e.has(t) ? B("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r), w = (t, e, r, s) => (O(t, e, "write to private field"), s ? s.call(t, r) : e.set(t, r), r), f = (t, e, r) => (O(t, e, "access private method"), r);
6
6
  import "@php-wasm/node-polyfills";
7
7
  import { logger } from "@php-wasm/logger";
8
8
  import { dirname, joinPaths, Semaphore, createSpawnHandler, basename, normalizePath, AcquireTimeoutError } from "@php-wasm/util";
@@ -105,10 +105,10 @@ function rethrowFileSystemError(t = "") {
105
105
  } catch (n) {
106
106
  const i = typeof n == "object" ? n == null ? void 0 : n.errno : null;
107
107
  if (i in FileErrorCodes) {
108
- const o = FileErrorCodes[i], c = typeof s[1] == "string" ? s[1] : null, a = c !== null ? t.replaceAll("{path}", c) : t;
108
+ const o = FileErrorCodes[i], a = typeof s[1] == "string" ? s[1] : null, c = a !== null ? t.replaceAll("{path}", a) : t;
109
109
  throw new ErrnoError(
110
110
  i,
111
- `${a}: ${o}`,
111
+ `${c}: ${o}`,
112
112
  {
113
113
  cause: n
114
114
  }
@@ -363,12 +363,12 @@ FSHelpers.copyRecursive = rethrowFileSystemError(
363
363
  'Could not copy files from "{path}"'
364
364
  )(FSHelpers.copyRecursive);
365
365
  const _private = /* @__PURE__ */ new WeakMap();
366
- var P;
366
+ var S;
367
367
  class PHPWorker {
368
368
  /** @inheritDoc */
369
369
  constructor(e, r) {
370
- m(this, P);
371
- this.absoluteUrl = "", this.documentRoot = "", this.chroot = null, w(this, P, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
370
+ y(this, S);
371
+ this.absoluteUrl = "", this.documentRoot = "", this.chroot = null, w(this, S, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
372
372
  monitor: r
373
373
  }), e && this.__internal_setRequestHandler(e);
374
374
  }
@@ -524,7 +524,7 @@ class PHPWorker {
524
524
  }
525
525
  /** @inheritDoc @php-wasm/universal!/PHP.addEventListener */
526
526
  addEventListener(e, r) {
527
- u(this, P).has(e) || u(this, P).set(e, /* @__PURE__ */ new Set()), u(this, P).get(e).add(r);
527
+ u(this, S).has(e) || u(this, S).set(e, /* @__PURE__ */ new Set()), u(this, S).get(e).add(r);
528
528
  }
529
529
  /**
530
530
  * Removes an event listener for a PHP event.
@@ -533,10 +533,10 @@ class PHPWorker {
533
533
  */
534
534
  removeEventListener(e, r) {
535
535
  var s;
536
- (s = u(this, P).get(e)) == null || s.delete(r);
536
+ (s = u(this, S).get(e)) == null || s.delete(r);
537
537
  }
538
538
  dispatchEvent(e) {
539
- const r = u(this, P).get(e.type);
539
+ const r = u(this, S).get(e.type);
540
540
  if (r)
541
541
  for (const s of r)
542
542
  s(e);
@@ -558,7 +558,7 @@ class PHPWorker {
558
558
  await ((e = _private.get(this).requestHandler) == null ? void 0 : e[Symbol.asyncDispose]());
559
559
  }
560
560
  }
561
- P = new WeakMap();
561
+ S = new WeakMap();
562
562
  function isExitCode(t) {
563
563
  return t instanceof Error ? (t == null ? void 0 : t.name) === "ExitStatus" && "status" in t : !1;
564
564
  }
@@ -566,14 +566,14 @@ const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map(
566
566
  let lastRuntimeId = 0;
567
567
  async function loadPHPRuntime(t, ...e) {
568
568
  const r = Object.assign({}, ...e), [s, n, i] = makePromise(), o = t.init(currentJsRuntime, {
569
- onAbort(a) {
570
- i(a), logger.error(a);
569
+ onAbort(c) {
570
+ i(c), logger.error(c);
571
571
  },
572
572
  ENV: {},
573
573
  // Emscripten sometimes prepends a '/' to the path, which
574
574
  // breaks vite dev mode. An identity `locateFile` function
575
575
  // fixes it.
576
- locateFile: (a) => a,
576
+ locateFile: (c) => c,
577
577
  ...r,
578
578
  noInitialRun: !0,
579
579
  onRuntimeInitialized() {
@@ -581,10 +581,10 @@ async function loadPHPRuntime(t, ...e) {
581
581
  }
582
582
  });
583
583
  await s;
584
- const c = ++lastRuntimeId;
585
- return o.FS, o.id = c, o.originalExit = o._exit, o._exit = function(a) {
586
- return o.outboundNetworkProxyServer && (o.outboundNetworkProxyServer.close(), o.outboundNetworkProxyServer.closeAllConnections()), loadedRuntimes.delete(c), o.originalExit(a);
587
- }, o[RuntimeId] = c, loadedRuntimes.set(c, o), c;
584
+ const a = ++lastRuntimeId;
585
+ return o.FS, o.id = a, o.originalExit = o._exit, o._exit = function(c) {
586
+ return o.outboundNetworkProxyServer && (o.outboundNetworkProxyServer.close(), o.outboundNetworkProxyServer.closeAllConnections()), loadedRuntimes.delete(a), o.originalExit(c);
587
+ }, o[RuntimeId] = a, loadedRuntimes.set(a, o), a;
588
588
  }
589
589
  function getLoadedRuntime(t) {
590
590
  return loadedRuntimes.get(t);
@@ -689,8 +689,8 @@ async function parseHeadersStream(t) {
689
689
  for (const n of r.headers) {
690
690
  if (!n.includes(": "))
691
691
  continue;
692
- const i = n.indexOf(": "), o = n.substring(0, i).toLowerCase(), c = n.substring(i + 2);
693
- o in s || (s[o] = []), s[o].push(c);
692
+ const i = n.indexOf(": "), o = n.substring(0, i).toLowerCase(), a = n.substring(i + 2);
693
+ o in s || (s[o] = []), s[o].push(a);
694
694
  }
695
695
  return {
696
696
  headers: s,
@@ -712,12 +712,12 @@ async function streamToBytes(t) {
712
712
  const { done: s, value: n } = await e.read();
713
713
  if (s) {
714
714
  const i = r.reduce(
715
- (a, l) => a + l.byteLength,
715
+ (c, l) => c + l.byteLength,
716
716
  0
717
717
  ), o = new Uint8Array(i);
718
- let c = 0;
719
- for (const a of r)
720
- o.set(a, c), c += a.byteLength;
718
+ let a = 0;
719
+ for (const c of r)
720
+ o.set(c, a), a += c.byteLength;
721
721
  return o;
722
722
  }
723
723
  n && r.push(n);
@@ -841,16 +841,16 @@ function improveWASMErrorReporting(t) {
841
841
  if (!(o instanceof Error))
842
842
  throw o;
843
843
  t.lastAsyncifyStackSource && (o.cause = t.lastAsyncifyStackSource);
844
- const c = clarifyErrorMessage(
844
+ const a = clarifyErrorMessage(
845
845
  o,
846
846
  (i = t.lastAsyncifyStackSource) == null ? void 0 : i.stack
847
847
  );
848
848
  if (e.hasListeners()) {
849
- o.message = c;
850
- const a = new ErrorEvent("error", { error: o });
851
- throw e.dispatchEvent(a), o;
849
+ o.message = a;
850
+ const c = new ErrorEvent("error", { error: o });
851
+ throw e.dispatchEvent(c), o;
852
852
  }
853
- throw (!isExitCode(o) || o.status !== 0) && showCriticalErrorBox(c), o;
853
+ throw (!isExitCode(o) || o.status !== 0) && showCriticalErrorBox(a), o;
854
854
  }
855
855
  };
856
856
  }
@@ -950,7 +950,7 @@ class PHPExecutionFailureError extends Error {
950
950
  }
951
951
  }
952
952
  const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php", OPCACHE_FILE_FOLDER = "/internal/shared/opcache";
953
- var M, H, T, E, F, k, _, h, B, $, V, G, J, Y, K, X, U, Q, q, j;
953
+ var M, H, T, v, F, k, _, h, z, $, V, G, J, Y, Q, K, U, X, j, D;
954
954
  class PHP {
955
955
  /**
956
956
  * Initializes a PHP runtime.
@@ -960,17 +960,17 @@ class PHP {
960
960
  * @param requestHandlerOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
961
961
  */
962
962
  constructor(t) {
963
- m(this, h);
964
- m(this, M);
965
- m(this, H, !1);
966
- m(this, T, null);
967
- m(this, E, /* @__PURE__ */ new Map([
963
+ y(this, h);
964
+ y(this, M);
965
+ y(this, H, !1);
966
+ y(this, T, null);
967
+ y(this, v, /* @__PURE__ */ new Map([
968
968
  // Listen to all events
969
969
  ["*", /* @__PURE__ */ new Set()]
970
970
  ]));
971
- m(this, F, []);
972
- m(this, k, {});
973
- m(this, _, {
971
+ y(this, F, []);
972
+ y(this, k, {});
973
+ y(this, _, {
974
974
  enabled: !1,
975
975
  recreateRuntime: () => 0,
976
976
  needsRotating: !1,
@@ -987,7 +987,7 @@ class PHP {
987
987
  * @param listener - The listener function to be called when the event is triggered.
988
988
  */
989
989
  addEventListener(t, e) {
990
- u(this, E).has(t) || u(this, E).set(t, /* @__PURE__ */ new Set()), u(this, E).get(t).add(e);
990
+ u(this, v).has(t) || u(this, v).set(t, /* @__PURE__ */ new Set()), u(this, v).get(t).add(e);
991
991
  }
992
992
  /**
993
993
  * Removes an event listener for a PHP event.
@@ -996,12 +996,12 @@ class PHP {
996
996
  */
997
997
  removeEventListener(t, e) {
998
998
  var r;
999
- (r = u(this, E).get(t)) == null || r.delete(e);
999
+ (r = u(this, v).get(t)) == null || r.delete(e);
1000
1000
  }
1001
1001
  dispatchEvent(t) {
1002
1002
  const e = [
1003
- ...u(this, E).get(t.type) || [],
1004
- ...u(this, E).get("*") || []
1003
+ ...u(this, v).get(t.type) || [],
1004
+ ...u(this, v).get("*") || []
1005
1005
  ];
1006
1006
  if (e)
1007
1007
  for (const r of e)
@@ -1387,7 +1387,7 @@ class PHP {
1387
1387
  async runStream(t) {
1388
1388
  const e = await this.semaphore.acquire();
1389
1389
  let r;
1390
- const s = y(this, h, j).call(this, async () => {
1390
+ const s = f(this, h, D).call(this, async () => {
1391
1391
  if (u(this, H) || (await this[__private__dont__use].ccall(
1392
1392
  "php_wasm_init",
1393
1393
  null,
@@ -1400,22 +1400,22 @@ class PHP {
1400
1400
  throw new Error(
1401
1401
  `The script path "${t.scriptPath}" does not exist.`
1402
1402
  );
1403
- y(this, h, $).call(this, t.relativeUri || ""), y(this, h, Y).call(this, t.method || "GET");
1404
- const i = normalizeHeaders(t.headers || {}), o = i.host || "example.com:443", c = y(this, h, J).call(this, o, t.protocol || "http");
1405
- if (y(this, h, V).call(this, o), y(this, h, G).call(this, c), y(this, h, K).call(this, i), t.body && (r = y(this, h, X).call(this, t.body)), typeof t.code == "string")
1406
- this.writeFile("/internal/eval.php", t.code), y(this, h, U).call(this, "/internal/eval.php");
1403
+ f(this, h, $).call(this, t.relativeUri || ""), f(this, h, Y).call(this, t.method || "GET");
1404
+ const i = normalizeHeaders(t.headers || {}), o = i.host || "example.com:443", a = f(this, h, J).call(this, o, t.protocol || "http");
1405
+ if (f(this, h, V).call(this, o), f(this, h, G).call(this, a), f(this, h, Q).call(this, i), t.body && (r = f(this, h, K).call(this, t.body)), typeof t.code == "string")
1406
+ this.writeFile("/internal/eval.php", t.code), f(this, h, U).call(this, "/internal/eval.php");
1407
1407
  else if (typeof t.scriptPath == "string")
1408
- y(this, h, U).call(this, t.scriptPath || "");
1408
+ f(this, h, U).call(this, t.scriptPath || "");
1409
1409
  else
1410
1410
  throw new TypeError(
1411
1411
  "The request object must have either a `code` or a `scriptPath` property."
1412
1412
  );
1413
- const a = y(this, h, B).call(this, t.$_SERVER, i, c);
1414
- for (const d in a)
1415
- y(this, h, Q).call(this, d, a[d]);
1413
+ const c = f(this, h, z).call(this, t.$_SERVER, i, a);
1414
+ for (const d in c)
1415
+ f(this, h, X).call(this, d, c[d]);
1416
1416
  const l = t.env || {};
1417
1417
  for (const d in l)
1418
- y(this, h, q).call(this, d, l[d]);
1418
+ f(this, h, j).call(this, d, l[d]);
1419
1419
  return await this[__private__dont__use].ccall(
1420
1420
  "wasm_sapi_handle_request",
1421
1421
  NUMBER,
@@ -1661,35 +1661,35 @@ class PHP {
1661
1661
  * @param runtime
1662
1662
  */
1663
1663
  async hotSwapPHPRuntime(t) {
1664
- const e = this[__private__dont__use].FS, r = this.listFiles("/").map((a) => `/${a}`), s = this[__private__dont__use].spawnProcess, n = e.cwd();
1664
+ const e = this[__private__dont__use].FS, r = this.listFiles("/").map((c) => `/${c}`), s = this[__private__dont__use].spawnProcess, n = e.cwd();
1665
1665
  e.chdir("/");
1666
1666
  const i = Object.entries(u(this, k)).map(
1667
- ([a, l]) => ({
1667
+ ([c, l]) => ({
1668
1668
  mountHandler: l.mountHandler,
1669
- vfsPath: a
1669
+ vfsPath: c
1670
1670
  })
1671
1671
  ), o = Object.values(
1672
1672
  u(this, k)
1673
1673
  ).reverse();
1674
- for (const a of o)
1675
- await a.unmount();
1674
+ for (const c of o)
1675
+ await c.unmount();
1676
1676
  try {
1677
1677
  this.exit();
1678
1678
  } catch {
1679
1679
  }
1680
1680
  this.initializeRuntime(t), s && (this[__private__dont__use].spawnProcess = s), u(this, M) && this.setSapiName(u(this, M));
1681
- const c = this[__private__dont__use].FS;
1682
- for (const a of r)
1683
- a && a !== "/request" && copyMEMFSNodes(e, c, a);
1684
- for (const { mountHandler: a, vfsPath: l } of i)
1685
- this.mkdir(l), await this.mount(l, a);
1681
+ const a = this[__private__dont__use].FS;
1682
+ for (const c of r)
1683
+ c && c !== "/request" && copyMEMFSNodes(e, a, c);
1684
+ for (const { mountHandler: c, vfsPath: l } of i)
1685
+ this.mkdir(l), await this.mount(l, c);
1686
1686
  try {
1687
- c.chdir(n);
1688
- } catch (a) {
1687
+ a.chdir(n);
1688
+ } catch (c) {
1689
1689
  throw new Error(
1690
1690
  `Failed to restore CWD to ${n} after PHP runtime rotation.`,
1691
1691
  {
1692
- cause: a
1692
+ cause: c
1693
1693
  }
1694
1694
  );
1695
1695
  }
@@ -1734,10 +1734,10 @@ class PHP {
1734
1734
  return this.subProcess(t, e);
1735
1735
  u(this, H) && (u(this, _).needsRotating = !0);
1736
1736
  const r = await this.semaphore.acquire();
1737
- return await y(this, h, j).call(this, () => {
1737
+ return await f(this, h, D).call(this, () => {
1738
1738
  const s = e.env || {};
1739
1739
  for (const [n, i] of Object.entries(s))
1740
- y(this, h, q).call(this, n, i);
1740
+ f(this, h, j).call(this, n, i);
1741
1741
  t = [t[0], "-c", PHP_INI_PATH, ...t.slice(1)];
1742
1742
  for (const n of t)
1743
1743
  this[__private__dont__use].ccall(
@@ -1828,7 +1828,7 @@ class PHP {
1828
1828
  this.exit(0);
1829
1829
  }
1830
1830
  }
1831
- M = new WeakMap(), H = new WeakMap(), T = new WeakMap(), E = new WeakMap(), F = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), h = new WeakSet(), /**
1831
+ M = new WeakMap(), H = new WeakMap(), T = new WeakMap(), v = new WeakMap(), F = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), h = new WeakSet(), /**
1832
1832
  * Prepares the $_SERVER entries for the PHP runtime.
1833
1833
  *
1834
1834
  * @param defaults Default entries to include in $_SERVER.
@@ -1837,7 +1837,7 @@ M = new WeakMap(), H = new WeakMap(), T = new WeakMap(), E = new WeakMap(), F =
1837
1837
  * was provided.
1838
1838
  * @returns Computed $_SERVER entries.
1839
1839
  */
1840
- B = function(t, e, r) {
1840
+ z = function(t, e, r) {
1841
1841
  const s = {
1842
1842
  ...t || {}
1843
1843
  };
@@ -1889,7 +1889,7 @@ B = function(t, e, r) {
1889
1889
  [STRING],
1890
1890
  [t]
1891
1891
  );
1892
- }, K = function(t) {
1892
+ }, Q = function(t) {
1893
1893
  t.cookie && this[__private__dont__use].ccall(
1894
1894
  "wasm_set_cookies",
1895
1895
  null,
@@ -1906,7 +1906,7 @@ B = function(t, e, r) {
1906
1906
  [NUMBER],
1907
1907
  [parseInt(t["content-length"], 10)]
1908
1908
  );
1909
- }, X = function(t) {
1909
+ }, K = function(t) {
1910
1910
  let e, r;
1911
1911
  typeof t == "string" ? (logger.warn(
1912
1912
  "Passing a string as the request body is deprecated. Please use a Uint8Array instead. See https://github.com/WordPress/wordpress-playground/issues/997 for more details"
@@ -1936,69 +1936,69 @@ B = function(t, e, r) {
1936
1936
  [STRING],
1937
1937
  [t]
1938
1938
  );
1939
- }, Q = function(t, e) {
1939
+ }, X = function(t, e) {
1940
1940
  this[__private__dont__use].ccall(
1941
1941
  "wasm_add_SERVER_entry",
1942
1942
  null,
1943
1943
  [STRING, STRING],
1944
1944
  [t, e]
1945
1945
  );
1946
- }, q = function(t, e) {
1946
+ }, j = function(t, e) {
1947
1947
  this[__private__dont__use].ccall(
1948
1948
  "wasm_add_ENV_entry",
1949
1949
  null,
1950
1950
  [STRING, STRING],
1951
1951
  [t, e]
1952
1952
  );
1953
- }, j = async function(t) {
1953
+ }, D = async function(t) {
1954
1954
  u(this, _).enabled && u(this, _).needsRotating && await this.rotateRuntime(), ++u(this, _).requestsMade, u(this, _).requestsMade >= u(this, _).maxRequests && (u(this, _).needsRotating = !0);
1955
1955
  const e = this[__private__dont__use], r = await createInvertedReadableStream();
1956
1956
  e.onHeaders = (p) => {
1957
- c || s || r.controller.enqueue(p.slice());
1957
+ a || s || r.controller.enqueue(p.slice());
1958
1958
  };
1959
1959
  let s = !1;
1960
1960
  const n = () => {
1961
1961
  s || (s = !0, r.controller.close());
1962
1962
  }, i = await createInvertedReadableStream();
1963
1963
  e.onStdout = (p) => {
1964
- n(), !c && i.controller.enqueue(p.slice());
1964
+ n(), !a && i.controller.enqueue(p.slice());
1965
1965
  };
1966
1966
  const o = await createInvertedReadableStream();
1967
1967
  e.onStderr = (p) => {
1968
- c || o.controller.enqueue(p.slice());
1968
+ a || o.controller.enqueue(p.slice());
1969
1969
  };
1970
- let c = !1, a;
1970
+ let a = !1, c;
1971
1971
  const d = (async () => {
1972
1972
  var p;
1973
1973
  try {
1974
1974
  return await Promise.race([
1975
1975
  t(),
1976
1976
  new Promise((g, b) => {
1977
- var D;
1978
- a = (W) => {
1977
+ var q;
1978
+ c = (W) => {
1979
1979
  isExitCode(W.error) || b(W.error);
1980
- }, (D = u(this, T)) == null || D.addEventListener(
1980
+ }, (q = u(this, T)) == null || q.addEventListener(
1981
1981
  "error",
1982
- a,
1982
+ c,
1983
1983
  { once: !0 }
1984
1984
  );
1985
1985
  })
1986
1986
  ]);
1987
- } catch (f) {
1988
- if (isExitCode(f))
1989
- return f.status;
1990
- i.controller.error(f), o.controller.error(f), r.controller.error(f), c = !0;
1987
+ } catch (m) {
1988
+ if (isExitCode(m))
1989
+ return m.status;
1990
+ i.controller.error(m), o.controller.error(m), r.controller.error(m), a = !0;
1991
1991
  for (const g in this)
1992
1992
  typeof this[g] == "function" && (this[g] = () => {
1993
1993
  throw new Error(
1994
1994
  "PHP runtime has crashed – see the earlier error for details."
1995
1995
  );
1996
1996
  });
1997
- throw this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify(), f;
1997
+ throw this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify(), m;
1998
1998
  } finally {
1999
- c || (i.controller.close(), o.controller.close(), n(), c = !0), (p = u(this, T)) == null || p.removeEventListener(
1999
+ a || (i.controller.close(), o.controller.close(), n(), a = !0), (p = u(this, T)) == null || p.removeEventListener(
2000
2000
  "error",
2001
- a
2001
+ c
2002
2002
  );
2003
2003
  }
2004
2004
  })().then(
@@ -2011,11 +2011,11 @@ B = function(t, e, r) {
2011
2011
  source: "php-wasm"
2012
2012
  }), p),
2013
2013
  (p) => {
2014
- const f = p.source ?? "php-wasm";
2014
+ const m = p.source ?? "php-wasm";
2015
2015
  throw this.dispatchEvent({
2016
2016
  type: "request.error",
2017
2017
  error: p,
2018
- source: f
2018
+ source: m
2019
2019
  }), p;
2020
2020
  }
2021
2021
  );
@@ -2192,9 +2192,9 @@ async function* iteratePhpFiles(t, e, {
2192
2192
  const o = i.pop();
2193
2193
  if (!o)
2194
2194
  return;
2195
- const c = await t.listFiles(o);
2196
- for (const a of c) {
2197
- const l = `${o}/${a}`;
2195
+ const a = await t.listFiles(o);
2196
+ for (const c of a) {
2197
+ const l = `${o}/${c}`;
2198
2198
  if (n.includes(l.substring(e.length + 1)))
2199
2199
  continue;
2200
2200
  await t.isDir(l) ? i.push(l) : yield new StreamedFile(
@@ -2363,22 +2363,22 @@ function ensurePathPrefix(t, e) {
2363
2363
  }
2364
2364
  async function encodeAsMultipart(t) {
2365
2365
  const e = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${e}`, s = new TextEncoder(), n = [];
2366
- for (const [a, l] of Object.entries(t))
2366
+ for (const [c, l] of Object.entries(t))
2367
2367
  n.push(`--${e}\r
2368
- `), n.push(`Content-Disposition: form-data; name="${a}"`), l instanceof File && n.push(`; filename="${l.name}"`), n.push(`\r
2368
+ `), n.push(`Content-Disposition: form-data; name="${c}"`), l instanceof File && n.push(`; filename="${l.name}"`), n.push(`\r
2369
2369
  `), l instanceof File && (n.push("Content-Type: application/octet-stream"), n.push(`\r
2370
2370
  `)), n.push(`\r
2371
2371
  `), l instanceof File ? n.push(await fileToUint8Array(l)) : n.push(l), n.push(`\r
2372
2372
  `);
2373
2373
  n.push(`--${e}--\r
2374
2374
  `);
2375
- const i = n.reduce((a, l) => a + l.length, 0), o = new Uint8Array(i);
2376
- let c = 0;
2377
- for (const a of n)
2375
+ const i = n.reduce((c, l) => c + l.length, 0), o = new Uint8Array(i);
2376
+ let a = 0;
2377
+ for (const c of n)
2378
2378
  o.set(
2379
- typeof a == "string" ? s.encode(a) : a,
2380
- c
2381
- ), c += a.length;
2379
+ typeof c == "string" ? s.encode(c) : c,
2380
+ a
2381
+ ), a += c.length;
2382
2382
  return { bytes: o, contentType: r };
2383
2383
  }
2384
2384
  function fileToUint8Array(t) {
@@ -2480,7 +2480,7 @@ const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "app
2480
2480
  xspf,
2481
2481
  zip
2482
2482
  };
2483
- var S, I, L, C, A, x, N, v, R, Z, ee, te;
2483
+ var P, I, L, C, A, E, N, R, x, Z, ee, te, re;
2484
2484
  class PHPRequestHandler {
2485
2485
  /**
2486
2486
  * The request handler needs to decide whether to serve a static asset or
@@ -2494,15 +2494,15 @@ class PHPRequestHandler {
2494
2494
  * @param config - Request Handler configuration.
2495
2495
  */
2496
2496
  constructor(e) {
2497
- m(this, R);
2498
- m(this, S);
2499
- m(this, I);
2500
- m(this, L);
2501
- m(this, C);
2502
- m(this, A);
2503
- m(this, x);
2504
- m(this, N);
2505
- m(this, v);
2497
+ y(this, x);
2498
+ y(this, P);
2499
+ y(this, I);
2500
+ y(this, L);
2501
+ y(this, C);
2502
+ y(this, A);
2503
+ y(this, E);
2504
+ y(this, N);
2505
+ y(this, R);
2506
2506
  const {
2507
2507
  documentRoot: r = "/www/",
2508
2508
  absoluteUrl: s = typeof location == "object" ? location.href : DEFAULT_BASE_URL,
@@ -2510,25 +2510,25 @@ class PHPRequestHandler {
2510
2510
  getFileNotFoundAction: i = () => ({ type: "404" })
2511
2511
  } = e;
2512
2512
  "processManager" in e ? this.processManager = e.processManager : this.processManager = new PHPProcessManager({
2513
- phpFactory: async (a) => {
2513
+ phpFactory: async (c) => {
2514
2514
  const l = await e.phpFactory({
2515
- ...a,
2515
+ ...c,
2516
2516
  requestHandler: this
2517
2517
  });
2518
2518
  return l.isDir(r) || l.mkdir(r), l.chdir(r), l.requestHandler = this, l;
2519
2519
  },
2520
2520
  maxPhpInstances: e.maxPhpInstances
2521
- }), w(this, v, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), w(this, S, r);
2521
+ }), w(this, R, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), w(this, P, r);
2522
2522
  const o = new URL(s);
2523
2523
  w(this, L, o.hostname), w(this, C, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), w(this, I, (o.protocol || "").replace(":", ""));
2524
- const c = u(this, C) !== 443 && u(this, C) !== 80;
2524
+ const a = u(this, C) !== 443 && u(this, C) !== 80;
2525
2525
  w(this, A, [
2526
2526
  u(this, L),
2527
- c ? `:${u(this, C)}` : ""
2528
- ].join("")), w(this, x, o.pathname.replace(/\/+$/, "")), w(this, N, [
2527
+ a ? `:${u(this, C)}` : ""
2528
+ ].join("")), w(this, E, o.pathname.replace(/\/+$/, "")), w(this, N, [
2529
2529
  `${u(this, I)}://`,
2530
2530
  u(this, A),
2531
- u(this, x)
2531
+ u(this, E)
2532
2532
  ].join("")), this.rewriteRules = n, this.getFileNotFoundAction = i;
2533
2533
  }
2534
2534
  async getPrimaryPhp() {
@@ -2553,7 +2553,7 @@ class PHPRequestHandler {
2553
2553
  */
2554
2554
  internalUrlToPath(e) {
2555
2555
  const r = new URL(e, "https://playground.internal");
2556
- return r.pathname.startsWith(u(this, x)) && (r.pathname = r.pathname.slice(u(this, x).length)), toRelativeUrl(r);
2556
+ return r.pathname.startsWith(u(this, E)) && (r.pathname = r.pathname.slice(u(this, E).length)), toRelativeUrl(r);
2557
2557
  }
2558
2558
  /**
2559
2559
  * The absolute URL of this PHPRequestHandler instance.
@@ -2566,7 +2566,7 @@ class PHPRequestHandler {
2566
2566
  * for the files to serve. Default: `/var/www`.
2567
2567
  */
2568
2568
  get documentRoot() {
2569
- return u(this, S);
2569
+ return u(this, P);
2570
2570
  }
2571
2571
  /**
2572
2572
  * Serves the request – either by serving a static file, or by
@@ -2621,54 +2621,73 @@ class PHPRequestHandler {
2621
2621
  // Remove the hash part of the URL as it's not meant for the server.
2622
2622
  e.url.split("#")[0],
2623
2623
  r ? void 0 : DEFAULT_BASE_URL
2624
- ), n = applyRewriteRules(
2624
+ ), n = f(this, x, Z).call(this, s), i = await this.getPrimaryPhp();
2625
+ let o = joinPaths(
2626
+ u(this, P),
2627
+ /**
2628
+ * Turn a URL such as `https://playground/scope:my-site/wp-admin/index.php`
2629
+ * into a site-relative path, such as `/wp-admin/index.php`.
2630
+ */
2625
2631
  removePathPrefix(
2626
- decodeURIComponent(s.pathname),
2627
- u(this, x)
2628
- ),
2629
- this.rewriteRules
2630
- ), i = await this.getPrimaryPhp();
2631
- let o = joinPaths(u(this, S), n);
2632
+ /**
2633
+ * URL.pathname returns a URL-encoded path. We need to decode it
2634
+ * before using it as a filesystem path.
2635
+ */
2636
+ decodeURIComponent(n.pathname),
2637
+ u(this, E)
2638
+ )
2639
+ );
2632
2640
  if (i.isDir(o)) {
2633
2641
  if (!o.endsWith("/"))
2634
2642
  return new PHPResponse(
2635
2643
  301,
2636
- { Location: [`${s.pathname}/`] },
2644
+ { Location: [`${n.pathname}/`] },
2637
2645
  new Uint8Array(0)
2638
2646
  );
2639
- for (const c of ["index.php", "index.html"]) {
2640
- const a = joinPaths(o, c);
2641
- if (i.isFile(a)) {
2642
- o = a;
2647
+ for (const a of ["index.php", "index.html"]) {
2648
+ const c = joinPaths(o, a);
2649
+ if (i.isFile(c)) {
2650
+ o = c, n.pathname = joinPaths(
2651
+ n.pathname,
2652
+ a
2653
+ );
2643
2654
  break;
2644
2655
  }
2645
2656
  }
2646
2657
  }
2647
2658
  if (!i.isFile(o)) {
2648
- const c = this.getFileNotFoundAction(
2649
- n
2659
+ let a = n.pathname;
2660
+ for (; a.startsWith("/") && a !== dirname(a); ) {
2661
+ a = dirname(a);
2662
+ const c = joinPaths(u(this, P), a);
2663
+ if (i.isFile(c) && // Only run partial path resolution for PHP files.
2664
+ c.endsWith(".php")) {
2665
+ o = joinPaths(u(this, P), a);
2666
+ break;
2667
+ }
2668
+ }
2669
+ }
2670
+ if (!i.isFile(o)) {
2671
+ const a = this.getFileNotFoundAction(
2672
+ n.pathname
2650
2673
  );
2651
- switch (c.type) {
2674
+ switch (a.type) {
2652
2675
  case "response":
2653
- return c.response;
2676
+ return a.response;
2654
2677
  case "internal-redirect":
2655
- o = joinPaths(u(this, S), c.uri);
2678
+ o = joinPaths(u(this, P), a.uri);
2656
2679
  break;
2657
2680
  case "404":
2658
2681
  return PHPResponse.forHttpCode(404);
2659
2682
  default:
2660
2683
  throw new Error(
2661
- `Unsupported file-not-found action type: '${c.type}'`
2684
+ `Unsupported file-not-found action type: '${a.type}'`
2662
2685
  );
2663
2686
  }
2664
2687
  }
2665
2688
  if (i.isFile(o))
2666
2689
  if (o.endsWith(".php")) {
2667
- const c = {
2668
- ...e,
2669
- // Pass along URL with the #fragment filtered out
2670
- url: s.toString()
2671
- }, a = await y(this, R, ee).call(this, c, o);
2690
+ const a = await f(this, x, te).call(this, e, s, n, o);
2672
2691
  return a.ok() && a.exitCode !== 0 ? new PHPResponse(
2673
2692
  500,
2674
2693
  a.headers,
@@ -2677,21 +2696,144 @@ class PHPRequestHandler {
2677
2696
  a.exitCode
2678
2697
  ) : a;
2679
2698
  } else
2680
- return y(this, R, Z).call(this, i, o);
2699
+ return f(this, x, ee).call(this, i, o);
2681
2700
  else
2682
2701
  return PHPResponse.forHttpCode(404);
2683
2702
  }
2703
+ /**
2704
+ * Computes the essential $_SERVER entries for a request.
2705
+ *
2706
+ * php_wasm.c sets some defaults, assuming it runs as a CLI script.
2707
+ * This function overrides them with the values correct in the request
2708
+ * context.
2709
+ *
2710
+ * @TODO: Consolidate the $_SERVER setting logic into a single place instead
2711
+ * of splitting it between the C SAPI and the TypeScript code. The PHP
2712
+ * class has a `.cli()` method that could take care of the CLI-specific
2713
+ * $_SERVER values.
2714
+ *
2715
+ * Path and URL-related $_SERVER entries are theoretically documented
2716
+ * at https://www.php.net/manual/en/reserved.variables.server.php,
2717
+ * but that page is not very helpful in practice. Here are tables derived
2718
+ * by interacting with PHP servers:
2719
+ *
2720
+ * ## PHP Dev Server
2721
+ *
2722
+ * Setup:
2723
+ * – `/home/adam/subdir/script.php` file contains `<?php phpinfo(); ?>`
2724
+ * – `php -S 127.0.0.1:8041` running in `/home/adam` directory
2725
+ * – A request is sent to `http://127.0.0.1:8041/subdir/script.php/b.php/c.php`
2726
+ *
2727
+ * Results:
2728
+ *
2729
+ * $_SERVER['REQUEST_URI'] | `/subdir/script.php/b.php/c.php`
2730
+ * $_SERVER['SCRIPT_NAME'] | `/subdir/script.php`
2731
+ * $_SERVER['SCRIPT_FILENAME']| `/home/adam/subdir/script.php`
2732
+ * $_SERVER['PATH_INFO'] | `/b.php/c.php`
2733
+ * $_SERVER['PHP_SELF'] | `/subdir/script.php/b.php/c.php`
2734
+ *
2735
+ * ## Apache – rewriting rules
2736
+ *
2737
+ * Setup:
2738
+ * – `/var/www/html/subdir/script.php` file contains `<?php phpinfo(); ?>`
2739
+ * – Apache is listening on port 8041
2740
+ * – The document root is `/var/www/html`
2741
+ * – A request is sent to `http://127.0.0.1:8041/api/v1/user/123`
2742
+ *
2743
+ * .htaccess file:
2744
+ *
2745
+ * ```apache
2746
+ * RewriteEngine On
2747
+ * RewriteRule ^api/v1/user/([0-9]+)$ /subdir/script.php?endpoint=user&id=$1 [L,QSA]
2748
+ * ```
2749
+ *
2750
+ * Results:
2751
+ *
2752
+ * ```
2753
+ * $_SERVER['REQUEST_URI'] | /api/v1/user/123
2754
+ * $_SERVER['SCRIPT_NAME'] | /subdir/script.php
2755
+ * $_SERVER['SCRIPT_FILENAME'] | /var/www/html/subdir/script.php
2756
+ * $_SERVER['PATH_INFO'] | (key not set)
2757
+ * $_SERVER['PHP_SELF'] | /subdir/script.php
2758
+ * $_SERVER['QUERY_STRING'] | endpoint=user&id=123
2759
+ * $_SERVER['REDIRECT_STATUS'] | 200
2760
+ * $_SERVER['REDIRECT_URL'] | /api/v1/user/123
2761
+ * $_SERVER['REDIRECT_QUERY_STRING'] | endpoint=user&id=123
2762
+ * === $_GET Variables ===
2763
+ * $_GET['endpoint'] | user
2764
+ * $_GET['id'] | 123
2765
+ * ```
2766
+ *
2767
+ * ## Apache – vanilla request
2768
+ *
2769
+ * Setup:
2770
+ * – The same as above.
2771
+ * – A request sent http://localhost:8041/subdir/script.php?param=value
2772
+ *
2773
+ * Results:
2774
+ *
2775
+ * ```
2776
+ * $_SERVER['REQUEST_URI'] | /subdir/script.php?param=value
2777
+ * $_SERVER['SCRIPT_NAME'] | /subdir/script.php
2778
+ * $_SERVER['SCRIPT_FILENAME'] | /var/www/html/subdir/script.php
2779
+ * $_SERVER['PATH_INFO'] | (key not set)
2780
+ * $_SERVER['PHP_SELF'] | /subdir/script.php
2781
+ * $_SERVER['REDIRECT_URL'] | (key not set)
2782
+ * $_SERVER['REDIRECT_STATUS'] | (key not set)
2783
+ * $_SERVER['QUERY_STRING'] | param=value
2784
+ * $_SERVER['REQUEST_METHOD'] | GET
2785
+ * $_SERVER['DOCUMENT_ROOT'] | /var/www/html
2786
+ *
2787
+ * === $_GET Variables ===
2788
+ * $_GET['param'] | value
2789
+ * ```
2790
+ */
2791
+ prepare_$_SERVER_superglobal(e, r, s) {
2792
+ const n = {
2793
+ REMOTE_ADDR: "127.0.0.1",
2794
+ DOCUMENT_ROOT: u(this, P),
2795
+ HTTPS: u(this, N).startsWith("https://") ? "on" : ""
2796
+ };
2797
+ return n.REQUEST_URI = e.pathname + e.search, s.startsWith(u(this, P)) && (n.SCRIPT_NAME = s.substring(
2798
+ u(this, P).length
2799
+ ), n.PHP_SELF = r.pathname, n.REQUEST_URI.startsWith(n.SCRIPT_NAME) && (n.PATH_INFO = n.REQUEST_URI.substring(
2800
+ n.SCRIPT_NAME.length
2801
+ ), n.PATH_INFO.includes("?") && (n.PATH_INFO = n.PATH_INFO.substring(
2802
+ 0,
2803
+ n.PATH_INFO.indexOf("?")
2804
+ )))), n.QUERY_STRING = r.search.substring(1), n;
2805
+ }
2684
2806
  async [Symbol.asyncDispose]() {
2685
2807
  await this.processManager[Symbol.asyncDispose]();
2686
2808
  }
2687
2809
  }
2688
- S = new WeakMap(), I = new WeakMap(), L = new WeakMap(), C = new WeakMap(), A = new WeakMap(), x = new WeakMap(), N = new WeakMap(), v = new WeakMap(), R = new WeakSet(), /**
2810
+ P = new WeakMap(), I = new WeakMap(), L = new WeakMap(), C = new WeakMap(), A = new WeakMap(), E = new WeakMap(), N = new WeakMap(), R = new WeakMap(), x = new WeakSet(), /**
2811
+ * Apply the rewrite rules to the original request URL.
2812
+ *
2813
+ * @param originalRequestUrl - The original request URL.
2814
+ * @returns The rewritten request URL.
2815
+ */
2816
+ Z = function(e) {
2817
+ const r = removePathPrefix(
2818
+ decodeURIComponent(e.pathname),
2819
+ u(this, E)
2820
+ ), s = applyRewriteRules(
2821
+ r,
2822
+ this.rewriteRules
2823
+ ), n = new URL(
2824
+ joinPaths(u(this, E), s),
2825
+ e.toString()
2826
+ );
2827
+ for (const [i, o] of e.searchParams.entries())
2828
+ n.searchParams.append(i, o);
2829
+ return n;
2830
+ }, /**
2689
2831
  * Serves a static file from the PHP filesystem.
2690
2832
  *
2691
2833
  * @param fsPath - Absolute path of the static file to serve.
2692
2834
  * @returns The response.
2693
2835
  */
2694
- Z = function(e, r) {
2836
+ ee = function(e, r) {
2695
2837
  const s = e.readFileAsBuffer(r);
2696
2838
  return new PHPResponse(
2697
2839
  200,
@@ -2706,58 +2848,58 @@ Z = function(e, r) {
2706
2848
  },
2707
2849
  s
2708
2850
  );
2709
- }, ee = async function(e, r) {
2710
- let s;
2851
+ }, te = async function(e, r, s, n) {
2852
+ let i;
2711
2853
  try {
2712
- s = await this.processManager.acquirePHPInstance({
2854
+ i = await this.processManager.acquirePHPInstance({
2713
2855
  considerPrimary: !0
2714
2856
  });
2715
- } catch (n) {
2716
- return n instanceof MaxPhpInstancesError ? PHPResponse.forHttpCode(502) : PHPResponse.forHttpCode(500);
2857
+ } catch (o) {
2858
+ return o instanceof MaxPhpInstancesError ? PHPResponse.forHttpCode(502) : PHPResponse.forHttpCode(500);
2717
2859
  }
2718
2860
  try {
2719
- return await y(this, R, te).call(this, s.php, e, r);
2861
+ return await f(this, x, re).call(this, i.php, e, r, s, n);
2720
2862
  } finally {
2721
- s.reap();
2863
+ i.reap();
2722
2864
  }
2723
- }, te = async function(e, r, s) {
2724
- let n = "GET";
2725
- const i = {
2865
+ }, re = async function(e, r, s, n, i) {
2866
+ let o = "GET";
2867
+ const a = {
2726
2868
  host: u(this, A),
2727
2869
  ...normalizeHeaders(r.headers || {})
2728
2870
  };
2729
- u(this, v) && (i.cookie = u(this, v).getCookieRequestHeader());
2730
- let o = r.body;
2731
- if (typeof o == "object" && !(o instanceof Uint8Array)) {
2732
- n = "POST";
2733
- const { bytes: c, contentType: a } = await encodeAsMultipart(o);
2734
- o = c, i["content-type"] = a;
2871
+ u(this, R) && (a.cookie = u(this, R).getCookieRequestHeader());
2872
+ let c = r.body;
2873
+ if (typeof c == "object" && !(c instanceof Uint8Array)) {
2874
+ o = "POST";
2875
+ const { bytes: l, contentType: d } = await encodeAsMultipart(c);
2876
+ c = l, a["content-type"] = d;
2735
2877
  }
2736
2878
  try {
2737
- const c = await e.run({
2879
+ const l = await e.run({
2738
2880
  relativeUri: ensurePathPrefix(
2739
- toRelativeUrl(new URL(r.url)),
2740
- u(this, x)
2881
+ toRelativeUrl(new URL(n.toString())),
2882
+ u(this, E)
2741
2883
  ),
2742
2884
  protocol: u(this, I),
2743
- method: r.method || n,
2744
- $_SERVER: {
2745
- REMOTE_ADDR: "127.0.0.1",
2746
- DOCUMENT_ROOT: u(this, S),
2747
- HTTPS: u(this, N).startsWith("https://") ? "on" : ""
2748
- },
2749
- body: o,
2750
- scriptPath: s,
2751
- headers: i
2885
+ method: r.method || o,
2886
+ $_SERVER: this.prepare_$_SERVER_superglobal(
2887
+ s,
2888
+ n,
2889
+ i
2890
+ ),
2891
+ body: c,
2892
+ scriptPath: i,
2893
+ headers: a
2752
2894
  });
2753
- return u(this, v) && u(this, v).rememberCookiesFromResponseHeaders(
2754
- c.headers
2755
- ), c;
2756
- } catch (c) {
2757
- const a = c;
2758
- if (a != null && a.response)
2759
- return a.response;
2760
- throw c;
2895
+ return u(this, R) && u(this, R).rememberCookiesFromResponseHeaders(
2896
+ l.headers
2897
+ ), l;
2898
+ } catch (l) {
2899
+ const d = l;
2900
+ if (d != null && d.response)
2901
+ return d.response;
2902
+ throw l;
2761
2903
  }
2762
2904
  };
2763
2905
  function inferMimeType(t) {
@@ -2766,8 +2908,10 @@ function inferMimeType(t) {
2766
2908
  }
2767
2909
  function applyRewriteRules(t, e) {
2768
2910
  for (const r of e)
2769
- if (new RegExp(r.match).test(t))
2770
- return t.replace(r.match, r.replacement);
2911
+ if (new RegExp(r.match).test(t)) {
2912
+ t = t.replace(r.match, r.replacement);
2913
+ break;
2914
+ }
2771
2915
  return t;
2772
2916
  }
2773
2917
  function rotatePHPRuntime({
@@ -2815,11 +2959,11 @@ function sandboxedSpawnHandlerFactory(t) {
2815
2959
  else if (n === "tput" && e[1] === "cols")
2816
2960
  r.stdout("140"), r.exit(0);
2817
2961
  else if (n === "less") {
2818
- r.on("stdin", (c) => {
2819
- r.stdout(c);
2820
- }), await new Promise((c) => {
2962
+ r.on("stdin", (a) => {
2963
+ r.stdout(a);
2964
+ }), await new Promise((a) => {
2821
2965
  r.childProcess.stdin.on("finish", () => {
2822
- c(!0);
2966
+ a(!0);
2823
2967
  });
2824
2968
  }), r.exit(0);
2825
2969
  return;
@@ -2833,10 +2977,10 @@ function sandboxedSpawnHandlerFactory(t) {
2833
2977
  });
2834
2978
  try {
2835
2979
  s.cwd && i.chdir(s.cwd);
2836
- const c = i.cwd();
2980
+ const a = i.cwd();
2837
2981
  switch (n) {
2838
2982
  case "php": {
2839
- const a = await i.cli(e, {
2983
+ const c = await i.cli(e, {
2840
2984
  env: {
2841
2985
  ...s.env,
2842
2986
  SCRIPT_PATH: e[1],
@@ -2846,37 +2990,37 @@ function sandboxedSpawnHandlerFactory(t) {
2846
2990
  SHELL_PIPE: "0"
2847
2991
  }
2848
2992
  });
2849
- a.stdout.pipeTo(
2993
+ c.stdout.pipeTo(
2850
2994
  new WritableStream({
2851
2995
  write(l) {
2852
2996
  r.stdout(l);
2853
2997
  }
2854
2998
  })
2855
- ), a.stderr.pipeTo(
2999
+ ), c.stderr.pipeTo(
2856
3000
  new WritableStream({
2857
3001
  write(l) {
2858
3002
  r.stderr(l);
2859
3003
  }
2860
3004
  })
2861
- ), r.exit(await a.exitCode);
3005
+ ), r.exit(await c.exitCode);
2862
3006
  break;
2863
3007
  }
2864
3008
  case "ls": {
2865
- const a = i.listFiles(e[1] ?? c);
2866
- for (const l of a)
3009
+ const c = i.listFiles(e[1] ?? a);
3010
+ for (const l of c)
2867
3011
  r.stdout(l + `
2868
3012
  `);
2869
3013
  await new Promise((l) => setTimeout(l, 10)), r.exit(0);
2870
3014
  break;
2871
3015
  }
2872
3016
  case "pwd": {
2873
- r.stdout(c + `
2874
- `), await new Promise((a) => setTimeout(a, 10)), r.exit(0);
3017
+ r.stdout(a + `
3018
+ `), await new Promise((c) => setTimeout(c, 10)), r.exit(0);
2875
3019
  break;
2876
3020
  }
2877
3021
  }
2878
- } catch (c) {
2879
- throw r.exit(1), c;
3022
+ } catch (a) {
3023
+ throw r.exit(1), a;
2880
3024
  } finally {
2881
3025
  o();
2882
3026
  }
@@ -2894,7 +3038,7 @@ function createSyncProxy(t, e = [], r) {
2894
3038
  } : createSyncProxy(t, [...e, n], r);
2895
3039
  },
2896
3040
  set(s, n, i) {
2897
- const [o, c] = toWireValue(i);
3041
+ const [o, a] = toWireValue(i);
2898
3042
  return r.send(
2899
3043
  t,
2900
3044
  {
@@ -2902,25 +3046,25 @@ function createSyncProxy(t, e = [], r) {
2902
3046
  path: [...e, n].map(String),
2903
3047
  value: o
2904
3048
  },
2905
- c
3049
+ a
2906
3050
  ), !0;
2907
3051
  },
2908
3052
  apply(s, n, i) {
2909
3053
  if (e.at(-1) === "bind")
2910
3054
  return createSyncProxy(t, e.slice(0, -1), r);
2911
- const [c, a] = processArguments(i), l = r.send(
3055
+ const [a, c] = processArguments(i), l = r.send(
2912
3056
  t,
2913
3057
  {
2914
3058
  type: MessageType.APPLY,
2915
3059
  path: e.map(String),
2916
- argumentList: c
3060
+ argumentList: a
2917
3061
  },
2918
- a
3062
+ c
2919
3063
  );
2920
3064
  return fromWireValue(l);
2921
3065
  },
2922
3066
  construct(s, n) {
2923
- const [i, o] = processArguments(n), c = r.send(
3067
+ const [i, o] = processArguments(n), a = r.send(
2924
3068
  t,
2925
3069
  {
2926
3070
  type: MessageType.CONSTRUCT,
@@ -2929,7 +3073,7 @@ function createSyncProxy(t, e = [], r) {
2929
3073
  },
2930
3074
  o
2931
3075
  );
2932
- return fromWireValue(c);
3076
+ return fromWireValue(a);
2933
3077
  }
2934
3078
  });
2935
3079
  }
@@ -3045,28 +3189,28 @@ function expose(t, e = globalThis, r = ["*"], s) {
3045
3189
  console.warn(`Invalid origin '${i.origin}' for comlink proxy`);
3046
3190
  return;
3047
3191
  }
3048
- const { id: o, type: c, path: a } = {
3192
+ const { id: o, type: a, path: c } = {
3049
3193
  path: [],
3050
3194
  ...i.data
3051
3195
  }, l = (i.data.argumentList || []).map(fromWireValue);
3052
3196
  let d;
3053
3197
  try {
3054
- const p = a.slice(0, -1).reduce((g, b) => g[b], t), f = a.reduce((g, b) => g[b], t);
3055
- switch (c) {
3198
+ const p = c.slice(0, -1).reduce((g, b) => g[b], t), m = c.reduce((g, b) => g[b], t);
3199
+ switch (a) {
3056
3200
  case MessageType.GET:
3057
- d = f;
3201
+ d = m;
3058
3202
  break;
3059
3203
  case MessageType.SET:
3060
- p[a.slice(-1)[0]] = fromWireValue(
3204
+ p[c.slice(-1)[0]] = fromWireValue(
3061
3205
  i.data.value
3062
3206
  ), d = !0;
3063
3207
  break;
3064
3208
  case MessageType.APPLY:
3065
- d = f.apply(p, l);
3209
+ d = m.apply(p, l);
3066
3210
  break;
3067
3211
  case MessageType.CONSTRUCT:
3068
3212
  {
3069
- const g = new f(...l);
3213
+ const g = new m(...l);
3070
3214
  d = proxy(g);
3071
3215
  }
3072
3216
  break;
@@ -3086,14 +3230,14 @@ function expose(t, e = globalThis, r = ["*"], s) {
3086
3230
  d = { value: p, [throwMarker]: 0 };
3087
3231
  }
3088
3232
  Promise.resolve(d).catch((p) => ({ value: p, [throwMarker]: 0 })).then((p) => {
3089
- const [f, g] = toWireValue(p);
3090
- e.postMessage({ ...f, id: o }, g), c === MessageType.RELEASE && (e.removeEventListener("message", n), closeEndPoint(e), finalizer in t && typeof t[finalizer] == "function" && t[finalizer]());
3233
+ const [m, g] = toWireValue(p);
3234
+ e.postMessage({ ...m, id: o }, g), a === MessageType.RELEASE && (e.removeEventListener("message", n), closeEndPoint(e), finalizer in t && typeof t[finalizer] == "function" && t[finalizer]());
3091
3235
  }).catch(() => {
3092
- const [p, f] = toWireValue({
3236
+ const [p, m] = toWireValue({
3093
3237
  value: new TypeError("Unserializable return value"),
3094
3238
  [throwMarker]: 0
3095
3239
  });
3096
- e.postMessage({ ...p, id: o }, f);
3240
+ e.postMessage({ ...p, id: o }, m);
3097
3241
  }).finally(() => {
3098
3242
  s == null || s(i);
3099
3243
  });
@@ -3146,37 +3290,37 @@ function createProxy(t, e, r = [], s = function() {
3146
3290
  }) {
3147
3291
  let n = !1;
3148
3292
  const i = new Proxy(s, {
3149
- get(o, c) {
3150
- if (throwIfProxyReleased(n), c === releaseProxy)
3293
+ get(o, a) {
3294
+ if (throwIfProxyReleased(n), a === releaseProxy)
3151
3295
  return () => {
3152
3296
  unregisterProxy(i), releaseEndpoint(t), e.clear(), n = !0;
3153
3297
  };
3154
- if (c === "then") {
3298
+ if (a === "then") {
3155
3299
  if (r.length === 0)
3156
3300
  return { then: () => i };
3157
- const a = requestResponseMessage(t, e, {
3301
+ const c = requestResponseMessage(t, e, {
3158
3302
  type: MessageType.GET,
3159
3303
  path: r.map((l) => l.toString())
3160
3304
  }).then(fromWireValue);
3161
- return a.then.bind(a);
3305
+ return c.then.bind(c);
3162
3306
  }
3163
- return createProxy(t, e, [...r, c]);
3307
+ return createProxy(t, e, [...r, a]);
3164
3308
  },
3165
- set(o, c, a) {
3309
+ set(o, a, c) {
3166
3310
  throwIfProxyReleased(n);
3167
- const [l, d] = toWireValue(a);
3311
+ const [l, d] = toWireValue(c);
3168
3312
  return requestResponseMessage(
3169
3313
  t,
3170
3314
  e,
3171
3315
  {
3172
3316
  type: MessageType.SET,
3173
- path: [...r, c].map((p) => p.toString()),
3317
+ path: [...r, a].map((p) => p.toString()),
3174
3318
  value: l
3175
3319
  },
3176
3320
  d
3177
3321
  ).then(fromWireValue);
3178
3322
  },
3179
- apply(o, c, a) {
3323
+ apply(o, a, c) {
3180
3324
  throwIfProxyReleased(n);
3181
3325
  const l = r[r.length - 1];
3182
3326
  if (l === createEndpoint)
@@ -3185,28 +3329,28 @@ function createProxy(t, e, r = [], s = function() {
3185
3329
  }).then(fromWireValue);
3186
3330
  if (l === "bind")
3187
3331
  return createProxy(t, e, r.slice(0, -1));
3188
- const [d, p] = processArguments(a);
3332
+ const [d, p] = processArguments(c);
3189
3333
  return requestResponseMessage(
3190
3334
  t,
3191
3335
  e,
3192
3336
  {
3193
3337
  type: MessageType.APPLY,
3194
- path: r.map((f) => f.toString()),
3338
+ path: r.map((m) => m.toString()),
3195
3339
  argumentList: d
3196
3340
  },
3197
3341
  p
3198
3342
  ).then(fromWireValue);
3199
3343
  },
3200
- construct(o, c) {
3344
+ construct(o, a) {
3201
3345
  throwIfProxyReleased(n);
3202
- const [a, l] = processArguments(c);
3346
+ const [c, l] = processArguments(a);
3203
3347
  return requestResponseMessage(
3204
3348
  t,
3205
3349
  e,
3206
3350
  {
3207
3351
  type: MessageType.CONSTRUCT,
3208
3352
  path: r.map((d) => d.toString()),
3209
- argumentList: a
3353
+ argumentList: c
3210
3354
  },
3211
3355
  l
3212
3356
  ).then(fromWireValue);
@@ -3361,20 +3505,20 @@ const errorProperties = [
3361
3505
  maxDepth: n,
3362
3506
  depth: i,
3363
3507
  useToJSON: o,
3364
- serialize: c
3508
+ serialize: a
3365
3509
  }) => {
3366
- if (r || (Array.isArray(t) ? r = [] : !c && isErrorLike(t) ? r = newError(t.name) : r = {}), e.push(t), i >= n)
3510
+ if (r || (Array.isArray(t) ? r = [] : !a && isErrorLike(t) ? r = newError(t.name) : r = {}), e.push(t), i >= n)
3367
3511
  return r;
3368
3512
  if (o && typeof t.toJSON == "function" && !toJsonWasCalled.has(t))
3369
3513
  return toJSON(t);
3370
- const a = (l) => destroyCircular({
3514
+ const c = (l) => destroyCircular({
3371
3515
  from: l,
3372
3516
  seen: [...e],
3373
3517
  forceEnumerable: s,
3374
3518
  maxDepth: n,
3375
3519
  depth: i,
3376
3520
  useToJSON: o,
3377
- serialize: c
3521
+ serialize: a
3378
3522
  });
3379
3523
  for (const [l, d] of Object.entries(t)) {
3380
3524
  if (d && d instanceof Uint8Array && d.constructor.name === "Buffer") {
@@ -3394,16 +3538,16 @@ const errorProperties = [
3394
3538
  continue;
3395
3539
  }
3396
3540
  if (!e.includes(t[l])) {
3397
- i++, r[l] = a(t[l]);
3541
+ i++, r[l] = c(t[l]);
3398
3542
  continue;
3399
3543
  }
3400
3544
  r[l] = "[Circular]";
3401
3545
  }
3402
3546
  }
3403
- if (c || r instanceof Error)
3547
+ if (a || r instanceof Error)
3404
3548
  for (const { property: l, enumerable: d } of errorProperties)
3405
3549
  t[l] !== void 0 && t[l] !== null && Object.defineProperty(r, l, {
3406
- value: isErrorLike(t[l]) || Array.isArray(t[l]) ? a(t[l]) : t[l],
3550
+ value: isErrorLike(t[l]) || Array.isArray(t[l]) ? c(t[l]) : t[l],
3407
3551
  enumerable: s ? !0 : d,
3408
3552
  configurable: !0,
3409
3553
  writable: !0
@@ -3450,14 +3594,14 @@ function consumeAPI(t, e = void 0) {
3450
3594
  import.meta.url.startsWith("file://") ? r = nodeEndpoint(t) : r = t instanceof Worker ? t : windowEndpoint(t, e);
3451
3595
  const n = wrap(r), i = proxyClone(n);
3452
3596
  return new Proxy(i, {
3453
- get: (o, c) => c === "isConnected" ? async () => {
3597
+ get: (o, a) => a === "isConnected" ? async () => {
3454
3598
  for (; ; )
3455
3599
  try {
3456
3600
  await runWithTimeout(n.isConnected(), 200);
3457
3601
  break;
3458
3602
  } catch {
3459
3603
  }
3460
- } : n[c]
3604
+ } : n[a]
3461
3605
  });
3462
3606
  }
3463
3607
  async function runWithTimeout(t, e) {
@@ -3481,12 +3625,12 @@ function prepareForExpose(t, e) {
3481
3625
  setupTransferHandlers();
3482
3626
  const r = Promise.resolve();
3483
3627
  let s, n;
3484
- const i = new Promise((a, l) => {
3485
- s = a, n = l;
3486
- }), o = proxyClone(t), c = new Proxy(o, {
3487
- get: (a, l) => l === "isConnected" ? () => r : l === "isReady" ? () => i : l in a ? a[l] : e == null ? void 0 : e[l]
3628
+ const i = new Promise((c, l) => {
3629
+ s = c, n = l;
3630
+ }), o = proxyClone(t), a = new Proxy(o, {
3631
+ get: (c, l) => l === "isConnected" ? () => r : l === "isReady" ? () => i : l in c ? c[l] : e == null ? void 0 : e[l]
3488
3632
  });
3489
- return { setReady: s, setFailed: n, exposedApi: c };
3633
+ return { setReady: s, setFailed: n, exposedApi: a };
3490
3634
  }
3491
3635
  let isTransferHandlersSetup = !1;
3492
3636
  function setupTransferHandlers() {
@@ -3545,28 +3689,28 @@ function setupTransferHandlers() {
3545
3689
  stderr: r.stderr,
3546
3690
  exitCodePort: n
3547
3691
  }, [n]];
3548
- const i = streamToPort(r.headersStream), o = streamToPort(r.stdout), c = streamToPort(r.stderr);
3692
+ const i = streamToPort(r.headersStream), o = streamToPort(r.stdout), a = streamToPort(r.stderr);
3549
3693
  return [
3550
3694
  {
3551
3695
  __type: "StreamedPHPResponse",
3552
3696
  headersPort: i,
3553
3697
  stdoutPort: o,
3554
- stderrPort: c,
3698
+ stderrPort: a,
3555
3699
  exitCodePort: n
3556
3700
  },
3557
- [i, o, c, n]
3701
+ [i, o, a, n]
3558
3702
  ];
3559
3703
  },
3560
3704
  deserialize(r) {
3561
3705
  if (r.headers && r.stdout && r.stderr) {
3562
- const c = portToPromise(
3706
+ const a = portToPromise(
3563
3707
  r.exitCodePort
3564
3708
  );
3565
3709
  return new StreamedPHPResponse(
3566
3710
  r.headers,
3567
3711
  r.stdout,
3568
3712
  r.stderr,
3569
- c
3713
+ a
3570
3714
  );
3571
3715
  }
3572
3716
  const s = portToStream(r.headersPort), n = portToStream(r.stdoutPort), i = portToStream(r.stderrPort), o = portToPromise(r.exitCodePort);
@@ -3607,10 +3751,10 @@ function streamToPort(t) {
3607
3751
  break;
3608
3752
  }
3609
3753
  if (i) {
3610
- const o = i.byteOffset === 0 && i.byteLength === i.buffer.byteLength ? i : i.slice(), c = o.buffer;
3754
+ const o = i.byteOffset === 0 && i.byteLength === i.buffer.byteLength ? i : i.slice(), a = o.buffer;
3611
3755
  try {
3612
- e.postMessage({ t: "chunk", b: c }, [
3613
- c
3756
+ e.postMessage({ t: "chunk", b: a }, [
3757
+ a
3614
3758
  ]);
3615
3759
  } catch {
3616
3760
  e.postMessage({