@php-wasm/universal 3.1.5 → 3.1.8

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 G = (r) => {
1
+ var J = (r) => {
2
2
  throw TypeError(r);
3
3
  };
4
- var D = (r, e, t) => e.has(r) || G("Cannot " + t);
5
- var u = (r, e, t) => (D(r, e, "read from private field"), t ? t.call(r) : e.get(r)), y = (r, e, t) => e.has(r) ? G("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), g = (r, e, t, s) => (D(r, e, "write to private field"), s ? s.call(r, t) : e.set(r, t), t), m = (r, e, t) => (D(r, e, "access private method"), t);
4
+ var W = (r, e, t) => e.has(r) || J("Cannot " + t);
5
+ var u = (r, e, t) => (W(r, e, "read from private field"), t ? t.call(r) : e.get(r)), y = (r, e, t) => e.has(r) ? J("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), g = (r, e, t, s) => (W(r, e, "write to private field"), s ? s.call(r, t) : e.set(r, t), t), m = (r, e, t) => (W(r, e, "access private method"), t);
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, splitShellCommand } from "@php-wasm/util";
@@ -372,12 +372,12 @@ FSHelpers.mkdir = rethrowFileSystemError('Could not create directory "{path}"')(
372
372
  FSHelpers.mkdir
373
373
  );
374
374
  const _private = /* @__PURE__ */ new WeakMap();
375
- var x;
375
+ var S;
376
376
  class PHPWorker {
377
377
  /** @inheritDoc */
378
378
  constructor(e, t) {
379
- y(this, x);
380
- this.absoluteUrl = "", this.documentRoot = "", this.chroot = null, g(this, x, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
379
+ y(this, S);
380
+ this.absoluteUrl = "", this.documentRoot = "", this.chroot = null, g(this, S, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
381
381
  monitor: t
382
382
  }), e && this.__internal_setRequestHandler(e);
383
383
  }
@@ -546,7 +546,7 @@ class PHPWorker {
546
546
  }
547
547
  /** @inheritDoc @php-wasm/universal!/PHP.addEventListener */
548
548
  addEventListener(e, t) {
549
- u(this, x).has(e) || u(this, x).set(e, /* @__PURE__ */ new Set()), u(this, x).get(e).add(t);
549
+ u(this, S).has(e) || u(this, S).set(e, /* @__PURE__ */ new Set()), u(this, S).get(e).add(t);
550
550
  }
551
551
  /**
552
552
  * Removes an event listener for a PHP event.
@@ -555,10 +555,10 @@ class PHPWorker {
555
555
  */
556
556
  removeEventListener(e, t) {
557
557
  var s;
558
- (s = u(this, x).get(e)) == null || s.delete(t);
558
+ (s = u(this, S).get(e)) == null || s.delete(t);
559
559
  }
560
560
  dispatchEvent(e) {
561
- const t = u(this, x).get(e.type);
561
+ const t = u(this, S).get(e.type);
562
562
  if (t)
563
563
  for (const s of t)
564
564
  s(e);
@@ -580,7 +580,7 @@ class PHPWorker {
580
580
  await ((e = _private.get(this).requestHandler) == null ? void 0 : e[Symbol.asyncDispose]());
581
581
  }
582
582
  }
583
- x = new WeakMap();
583
+ S = new WeakMap();
584
584
  function isExitCode(r) {
585
585
  return r instanceof Error ? (r == null ? void 0 : r.name) === "ExitStatus" && "status" in r : !1;
586
586
  }
@@ -645,14 +645,24 @@ const currentJsRuntime = function() {
645
645
  201: "Created",
646
646
  200: "OK"
647
647
  };
648
- var C;
649
- const j = class j {
648
+ var N, O;
649
+ const D = class D {
650
650
  constructor(e, t, s, n) {
651
651
  /**
652
- * Response headers stream (internal).
652
+ * Headers stream that doesn't get locked when the consumer
653
+ * reads the parsed headers. api.ts transfers the obj.getHeadersStream(),
654
+ * and boot-playground-remote.ts copies the streamedResponse.headers.
655
+ * Both streams must be readable when the StreamedPHPResponse is transferred
656
+ * from the worker thread into the service worker.
653
657
  */
654
- y(this, C);
655
- this.parsedHeaders = null, this.cachedStdoutBytes = null, this.cachedStderrText = null, g(this, C, e), this.stdout = t, this.stderr = s, this.exitCode = n;
658
+ y(this, N);
659
+ /**
660
+ * Headers stream reserved for internal parsing.
661
+ */
662
+ y(this, O);
663
+ this.cachedParsedHeaders = null, this.cachedStdoutBytes = null, this.cachedStderrText = null;
664
+ const [i, o] = e.tee();
665
+ g(this, N, i), g(this, O, o), this.stdout = t, this.stderr = s, this.exitCode = n;
656
666
  }
657
667
  /**
658
668
  * Creates a StreamedPHPResponse from a buffered PHPResponse.
@@ -660,43 +670,40 @@ const j = class j {
660
670
  */
661
671
  static fromPHPResponse(e) {
662
672
  const t = new ReadableStream({
663
- start(c) {
664
- c.enqueue(e.bytes), c.close();
673
+ start(a) {
674
+ a.enqueue(e.bytes), a.close();
665
675
  }
666
676
  }), s = [];
667
- for (const [c, l] of Object.entries(e.headers))
668
- for (const d of l)
669
- s.push(`${c}: ${d}`);
677
+ for (const [a, c] of Object.entries(e.headers))
678
+ for (const l of c)
679
+ s.push(`${a}: ${l}`);
670
680
  const n = JSON.stringify({
671
681
  status: e.httpStatusCode,
672
682
  headers: s
673
683
  }), i = new ReadableStream({
674
- start(c) {
675
- c.enqueue(new TextEncoder().encode(n)), c.close();
684
+ start(a) {
685
+ a.enqueue(new TextEncoder().encode(n)), a.close();
676
686
  }
677
687
  }), o = new ReadableStream({
678
- start(c) {
679
- e.errors.length > 0 && c.enqueue(
688
+ start(a) {
689
+ e.errors.length > 0 && a.enqueue(
680
690
  new TextEncoder().encode(e.errors)
681
- ), c.close();
691
+ ), a.close();
682
692
  }
683
- }), a = new j(
693
+ });
694
+ return new D(
684
695
  i,
685
696
  t,
686
697
  o,
687
698
  Promise.resolve(e.exitCode)
688
699
  );
689
- return a.parsedHeaders = Promise.resolve({
690
- headers: e.headers,
691
- httpStatusCode: e.httpStatusCode
692
- }), a;
693
700
  }
694
701
  /**
695
702
  * Creates a StreamedPHPResponse for a given HTTP status code.
696
703
  * Shorthand for `StreamedPHPResponse.fromPHPResponse(PHPResponse.forHttpCode(...))`.
697
704
  */
698
705
  static forHttpCode(e, t = "") {
699
- return j.fromPHPResponse(
706
+ return D.fromPHPResponse(
700
707
  PHPResponse.forHttpCode(e, t)
701
708
  );
702
709
  }
@@ -705,7 +712,7 @@ const j = class j {
705
712
  * For parsed headers, use the `headers` property instead.
706
713
  */
707
714
  getHeadersStream() {
708
- return u(this, C);
715
+ return u(this, N);
709
716
  }
710
717
  /**
711
718
  * True if the response is successful (HTTP status code 200-399),
@@ -765,11 +772,13 @@ const j = class j {
765
772
  return this.cachedStderrText || (this.cachedStderrText = streamToText(this.stderr)), this.cachedStderrText;
766
773
  }
767
774
  async getParsedHeaders() {
768
- return this.parsedHeaders || (this.parsedHeaders = parseHeadersStream(u(this, C))), await this.parsedHeaders;
775
+ return this.cachedParsedHeaders || (this.cachedParsedHeaders = parseHeadersStream(
776
+ u(this, O)
777
+ )), await this.cachedParsedHeaders;
769
778
  }
770
779
  };
771
- C = new WeakMap();
772
- let StreamedPHPResponse = j;
780
+ N = new WeakMap(), O = new WeakMap();
781
+ let StreamedPHPResponse = D;
773
782
  async function parseHeadersStream(r) {
774
783
  const e = await streamToText(r);
775
784
  let t;
@@ -1043,7 +1052,7 @@ class PHPExecutionFailureError extends Error {
1043
1052
  }
1044
1053
  }
1045
1054
  const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php", OPCACHE_FILE_FOLDER = "/internal/shared/opcache";
1046
- var M, R, b, S, H, T, w, p, J, Y, X, Q, K, Z, ee, te, W, re, q, $;
1055
+ var M, R, b, x, T, H, w, p, Y, X, Q, K, Z, ee, te, re, q, se, $, z;
1047
1056
  class PHP {
1048
1057
  /**
1049
1058
  * Initializes a PHP runtime.
@@ -1057,12 +1066,12 @@ class PHP {
1057
1066
  y(this, M);
1058
1067
  y(this, R, !1);
1059
1068
  y(this, b, null);
1060
- y(this, S, /* @__PURE__ */ new Map([
1069
+ y(this, x, /* @__PURE__ */ new Map([
1061
1070
  // Listen to all events
1062
1071
  ["*", /* @__PURE__ */ new Set()]
1063
1072
  ]));
1064
- y(this, H, []);
1065
- y(this, T, {});
1073
+ y(this, T, []);
1074
+ y(this, H, {});
1066
1075
  y(this, w, {
1067
1076
  enabled: !1,
1068
1077
  recreateRuntime: () => 0,
@@ -1080,7 +1089,7 @@ class PHP {
1080
1089
  * @param listener - The listener function to be called when the event is triggered.
1081
1090
  */
1082
1091
  addEventListener(r, e) {
1083
- u(this, S).has(r) || u(this, S).set(r, /* @__PURE__ */ new Set()), u(this, S).get(r).add(e);
1092
+ u(this, x).has(r) || u(this, x).set(r, /* @__PURE__ */ new Set()), u(this, x).get(r).add(e);
1084
1093
  }
1085
1094
  /**
1086
1095
  * Removes an event listener for a PHP event.
@@ -1089,12 +1098,12 @@ class PHP {
1089
1098
  */
1090
1099
  removeEventListener(r, e) {
1091
1100
  var t;
1092
- (t = u(this, S).get(r)) == null || t.delete(e);
1101
+ (t = u(this, x).get(r)) == null || t.delete(e);
1093
1102
  }
1094
1103
  dispatchEvent(r) {
1095
1104
  const e = [
1096
- ...u(this, S).get(r.type) || [],
1097
- ...u(this, S).get("*") || []
1105
+ ...u(this, x).get(r.type) || [],
1106
+ ...u(this, x).get("*") || []
1098
1107
  ];
1099
1108
  if (e)
1100
1109
  for (const t of e)
@@ -1140,8 +1149,8 @@ class PHP {
1140
1149
  * @param listener Callback function to handle the message.
1141
1150
  */
1142
1151
  onMessage(r) {
1143
- return u(this, H).push(r), async () => {
1144
- g(this, H, u(this, H).filter(
1152
+ return u(this, T).push(r), async () => {
1153
+ g(this, T, u(this, T).filter(
1145
1154
  (e) => e !== r
1146
1155
  ));
1147
1156
  };
@@ -1235,7 +1244,7 @@ class PHP {
1235
1244
  }
1236
1245
  `
1237
1246
  ), e.onMessage = async (t) => {
1238
- for (const s of u(this, H)) {
1247
+ for (const s of u(this, T)) {
1239
1248
  const n = await s(t);
1240
1249
  if (n)
1241
1250
  return n;
@@ -1478,7 +1487,7 @@ class PHP {
1478
1487
  async runStream(r) {
1479
1488
  const e = await this.semaphore.acquire();
1480
1489
  let t;
1481
- const s = m(this, p, $).call(this, async () => {
1490
+ const s = m(this, p, z).call(this, async () => {
1482
1491
  if (u(this, R) || (await this[__private__dont__use].ccall(
1483
1492
  "php_wasm_init",
1484
1493
  null,
@@ -1491,22 +1500,22 @@ class PHP {
1491
1500
  throw new Error(
1492
1501
  `The script path "${r.scriptPath}" does not exist.`
1493
1502
  );
1494
- m(this, p, Y).call(this, r.relativeUri || ""), m(this, p, Z).call(this, r.method || "GET");
1495
- const i = normalizeHeaders(r.headers || {}), o = i.host || "example.com:443", a = m(this, p, K).call(this, o, r.protocol || "http");
1496
- if (m(this, p, X).call(this, o), m(this, p, Q).call(this, a), m(this, p, ee).call(this, i), r.body && (t = m(this, p, te).call(this, r.body)), typeof r.code == "string")
1497
- this.writeFile("/internal/eval.php", r.code), m(this, p, W).call(this, "/internal/eval.php");
1503
+ m(this, p, X).call(this, r.relativeUri || ""), m(this, p, ee).call(this, r.method || "GET");
1504
+ const i = normalizeHeaders(r.headers || {}), o = i.host || "example.com:443", a = m(this, p, Z).call(this, o, r.protocol || "http");
1505
+ if (m(this, p, Q).call(this, o), m(this, p, K).call(this, a), m(this, p, te).call(this, i), r.body && (t = m(this, p, re).call(this, r.body)), typeof r.code == "string")
1506
+ this.writeFile("/internal/eval.php", r.code), m(this, p, q).call(this, "/internal/eval.php");
1498
1507
  else if (typeof r.scriptPath == "string")
1499
- m(this, p, W).call(this, r.scriptPath || "");
1508
+ m(this, p, q).call(this, r.scriptPath || "");
1500
1509
  else
1501
1510
  throw new TypeError(
1502
1511
  "The request object must have either a `code` or a `scriptPath` property."
1503
1512
  );
1504
- const c = m(this, p, J).call(this, r.$_SERVER, i, a);
1513
+ const c = m(this, p, Y).call(this, r.$_SERVER, i, a);
1505
1514
  for (const d in c)
1506
- m(this, p, re).call(this, d, c[d]);
1515
+ m(this, p, se).call(this, d, c[d]);
1507
1516
  const l = r.env || {};
1508
1517
  for (const d in l)
1509
- m(this, p, q).call(this, d, l[d]);
1518
+ m(this, p, $).call(this, d, l[d]);
1510
1519
  return await this[__private__dont__use].ccall(
1511
1520
  "wasm_sapi_handle_request",
1512
1521
  NUMBER,
@@ -1769,13 +1778,13 @@ class PHP {
1769
1778
  async hotSwapPHPRuntime(r) {
1770
1779
  const e = this[__private__dont__use].FS, t = this.listFiles("/").map((c) => `/${c}`), s = this[__private__dont__use].spawnProcess, n = e.cwd();
1771
1780
  e.chdir("/");
1772
- const i = Object.entries(u(this, T)).map(
1781
+ const i = Object.entries(u(this, H)).map(
1773
1782
  ([c, l]) => ({
1774
1783
  mountHandler: l.mountHandler,
1775
1784
  vfsPath: c
1776
1785
  })
1777
1786
  ), o = Object.values(
1778
- u(this, T)
1787
+ u(this, H)
1779
1788
  ).reverse();
1780
1789
  for (const c of o)
1781
1790
  await c.unmount();
@@ -1815,10 +1824,10 @@ class PHP {
1815
1824
  ), s = {
1816
1825
  mountHandler: e,
1817
1826
  unmount: async () => {
1818
- await t(), delete u(this, T)[r];
1827
+ await t(), delete u(this, H)[r];
1819
1828
  }
1820
1829
  };
1821
- return u(this, T)[r] = s, () => {
1830
+ return u(this, H)[r] = s, () => {
1822
1831
  s.unmount();
1823
1832
  };
1824
1833
  }
@@ -1840,10 +1849,10 @@ class PHP {
1840
1849
  return this.subProcess(r, e);
1841
1850
  u(this, R) && (u(this, w).needsRotating = !0);
1842
1851
  const t = await this.semaphore.acquire();
1843
- return await m(this, p, $).call(this, () => {
1852
+ return await m(this, p, z).call(this, () => {
1844
1853
  const s = e.env || {};
1845
1854
  for (const [n, i] of Object.entries(s))
1846
- m(this, p, q).call(this, n, i);
1855
+ m(this, p, $).call(this, n, i);
1847
1856
  r = [r[0], "-c", PHP_INI_PATH, ...r.slice(1)];
1848
1857
  for (const n of r)
1849
1858
  this[__private__dont__use].ccall(
@@ -1934,7 +1943,7 @@ class PHP {
1934
1943
  this.exit(0);
1935
1944
  }
1936
1945
  }
1937
- M = new WeakMap(), R = new WeakMap(), b = new WeakMap(), S = new WeakMap(), H = new WeakMap(), T = new WeakMap(), w = new WeakMap(), p = new WeakSet(), /**
1946
+ M = new WeakMap(), R = new WeakMap(), b = new WeakMap(), x = new WeakMap(), T = new WeakMap(), H = new WeakMap(), w = new WeakMap(), p = new WeakSet(), /**
1938
1947
  * Prepares the $_SERVER entries for the PHP runtime.
1939
1948
  *
1940
1949
  * @param defaults Default entries to include in $_SERVER.
@@ -1943,7 +1952,7 @@ M = new WeakMap(), R = new WeakMap(), b = new WeakMap(), S = new WeakMap(), H =
1943
1952
  * was provided.
1944
1953
  * @returns Computed $_SERVER entries.
1945
1954
  */
1946
- J = function(r, e, t) {
1955
+ Y = function(r, e, t) {
1947
1956
  const s = {
1948
1957
  ...r || {}
1949
1958
  };
@@ -1953,7 +1962,7 @@ J = function(r, e, t) {
1953
1962
  ["content-type", "content-length"].includes(n.toLowerCase()) && (i = ""), s[`${i}${n.toUpperCase().replace(/-/g, "_")}`] = e[n];
1954
1963
  }
1955
1964
  return s;
1956
- }, Y = function(r) {
1965
+ }, X = function(r) {
1957
1966
  this[__private__dont__use].ccall(
1958
1967
  "wasm_set_request_uri",
1959
1968
  null,
@@ -1967,35 +1976,35 @@ J = function(r, e, t) {
1967
1976
  [STRING],
1968
1977
  [e]
1969
1978
  );
1970
- }, X = function(r) {
1979
+ }, Q = function(r) {
1971
1980
  this[__private__dont__use].ccall(
1972
1981
  "wasm_set_request_host",
1973
1982
  null,
1974
1983
  [STRING],
1975
1984
  [r]
1976
1985
  );
1977
- }, Q = function(r) {
1986
+ }, K = function(r) {
1978
1987
  this[__private__dont__use].ccall(
1979
1988
  "wasm_set_request_port",
1980
1989
  null,
1981
1990
  [NUMBER],
1982
1991
  [r]
1983
1992
  );
1984
- }, K = function(r, e) {
1993
+ }, Z = function(r, e) {
1985
1994
  let t;
1986
1995
  try {
1987
1996
  t = parseInt(new URL(r).port, 10);
1988
1997
  } catch {
1989
1998
  }
1990
1999
  return (!t || isNaN(t) || t === 80) && (t = e === "https" ? 443 : 80), t;
1991
- }, Z = function(r) {
2000
+ }, ee = function(r) {
1992
2001
  this[__private__dont__use].ccall(
1993
2002
  "wasm_set_request_method",
1994
2003
  null,
1995
2004
  [STRING],
1996
2005
  [r]
1997
2006
  );
1998
- }, ee = function(r) {
2007
+ }, te = function(r) {
1999
2008
  r.cookie && this[__private__dont__use].ccall(
2000
2009
  "wasm_set_cookies",
2001
2010
  null,
@@ -2012,7 +2021,7 @@ J = function(r, e, t) {
2012
2021
  [NUMBER],
2013
2022
  [parseInt(r["content-length"], 10)]
2014
2023
  );
2015
- }, te = function(r) {
2024
+ }, re = function(r) {
2016
2025
  let e, t;
2017
2026
  typeof r == "string" ? (logger.warn(
2018
2027
  "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"
@@ -2035,28 +2044,28 @@ J = function(r, e, t) {
2035
2044
  [NUMBER],
2036
2045
  [t]
2037
2046
  ), s;
2038
- }, W = function(r) {
2047
+ }, q = function(r) {
2039
2048
  this[__private__dont__use].ccall(
2040
2049
  "wasm_set_path_translated",
2041
2050
  null,
2042
2051
  [STRING],
2043
2052
  [r]
2044
2053
  );
2045
- }, re = function(r, e) {
2054
+ }, se = function(r, e) {
2046
2055
  this[__private__dont__use].ccall(
2047
2056
  "wasm_add_SERVER_entry",
2048
2057
  null,
2049
2058
  [STRING, STRING],
2050
2059
  [r, e]
2051
2060
  );
2052
- }, q = function(r, e) {
2061
+ }, $ = function(r, e) {
2053
2062
  this[__private__dont__use].ccall(
2054
2063
  "wasm_add_ENV_entry",
2055
2064
  null,
2056
2065
  [STRING, STRING],
2057
2066
  [r, e]
2058
2067
  );
2059
- }, $ = async function(r) {
2068
+ }, z = async function(r) {
2060
2069
  u(this, w).enabled && u(this, w).needsRotating && await this.rotateRuntime(), ++u(this, w).requestsMade, u(this, w).requestsMade >= u(this, w).maxRequests && (u(this, w).needsRotating = !0);
2061
2070
  const e = this[__private__dont__use], t = await createInvertedReadableStream();
2062
2071
  e.onHeaders = (h) => {
@@ -2080,10 +2089,10 @@ J = function(r, e, t) {
2080
2089
  return await Promise.race([
2081
2090
  r(),
2082
2091
  new Promise((_, F) => {
2083
- var z;
2084
- c = (V) => {
2085
- isExitCode(V.error) || F(V.error);
2086
- }, (z = u(this, b)) == null || z.addEventListener(
2092
+ var V;
2093
+ c = (G) => {
2094
+ isExitCode(G.error) || F(G.error);
2095
+ }, (V = u(this, b)) == null || V.addEventListener(
2087
2096
  "error",
2088
2097
  c,
2089
2098
  { once: !0 }
@@ -2567,7 +2576,7 @@ const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "app
2567
2576
  xspf,
2568
2577
  zip
2569
2578
  };
2570
- var v, I, O, L, A, E, N, k, U, P, se, B, ne, ie, oe;
2579
+ var v, C, U, L, I, E, A, k, B, P, ne, j, ie, oe, ae;
2571
2580
  class PHPRequestHandler {
2572
2581
  /**
2573
2582
  * The request handler needs to decide whether to serve a static asset or
@@ -2583,14 +2592,14 @@ class PHPRequestHandler {
2583
2592
  constructor(e) {
2584
2593
  y(this, P);
2585
2594
  y(this, v);
2586
- y(this, I);
2587
- y(this, O);
2595
+ y(this, C);
2596
+ y(this, U);
2588
2597
  y(this, L);
2589
- y(this, A);
2598
+ y(this, I);
2590
2599
  y(this, E);
2591
- y(this, N);
2600
+ y(this, A);
2592
2601
  y(this, k);
2593
- y(this, U);
2602
+ y(this, B);
2594
2603
  const {
2595
2604
  documentRoot: t = "/www/",
2596
2605
  absoluteUrl: s = typeof location == "object" ? location.href : DEFAULT_BASE_URL,
@@ -2621,16 +2630,16 @@ class PHPRequestHandler {
2621
2630
  );
2622
2631
  g(this, k, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), g(this, v, t);
2623
2632
  const c = new URL(s);
2624
- g(this, O, c.hostname), g(this, L, c.port ? Number(c.port) : c.protocol === "https:" ? 443 : 80), g(this, I, (c.protocol || "").replace(":", ""));
2633
+ g(this, U, c.hostname), g(this, L, c.port ? Number(c.port) : c.protocol === "https:" ? 443 : 80), g(this, C, (c.protocol || "").replace(":", ""));
2625
2634
  const l = u(this, L) !== 443 && u(this, L) !== 80;
2626
- g(this, A, [
2627
- u(this, O),
2635
+ g(this, I, [
2636
+ u(this, U),
2628
2637
  l ? `:${u(this, L)}` : ""
2629
- ].join("")), g(this, E, c.pathname.replace(/\/+$/, "")), g(this, N, [
2630
- `${u(this, I)}://`,
2631
- u(this, A),
2638
+ ].join("")), g(this, E, c.pathname.replace(/\/+$/, "")), g(this, A, [
2639
+ `${u(this, C)}://`,
2640
+ u(this, I),
2632
2641
  u(this, E)
2633
- ].join("")), this.rewriteRules = n, g(this, U, i), this.getFileNotFoundAction = o;
2642
+ ].join("")), this.rewriteRules = n, g(this, B, i), this.getFileNotFoundAction = o;
2634
2643
  }
2635
2644
  async getPrimaryPhp() {
2636
2645
  return await this.instanceManager.getPrimaryPhp();
@@ -2660,7 +2669,7 @@ class PHPRequestHandler {
2660
2669
  * The absolute URL of this PHPRequestHandler instance.
2661
2670
  */
2662
2671
  get absoluteUrl() {
2663
- return u(this, N);
2672
+ return u(this, A);
2664
2673
  }
2665
2674
  /**
2666
2675
  * The directory in the PHP filesystem where the server will look
@@ -2743,7 +2752,7 @@ class PHPRequestHandler {
2743
2752
  // Remove the hash part of the URL as it's not meant for the server.
2744
2753
  e.url.split("#")[0],
2745
2754
  t ? void 0 : DEFAULT_BASE_URL
2746
- ), n = m(this, P, se).call(this, s), i = await this.getPrimaryPhp(), o = removePathPrefix(
2755
+ ), n = m(this, P, ne).call(this, s), i = await this.getPrimaryPhp(), o = removePathPrefix(
2747
2756
  /**
2748
2757
  * URL.pathname returns a URL-encoded path. We need to decode it
2749
2758
  * before using it as a filesystem path.
@@ -2751,13 +2760,13 @@ class PHPRequestHandler {
2751
2760
  decodeURIComponent(n.pathname),
2752
2761
  u(this, E)
2753
2762
  );
2754
- let a = m(this, P, B).call(this, o);
2763
+ let a = m(this, P, j).call(this, o);
2755
2764
  if (i.isDir(a)) {
2756
2765
  if (!o.endsWith("/"))
2757
2766
  return StreamedPHPResponse.fromPHPResponse(
2758
2767
  new PHPResponse(
2759
2768
  301,
2760
- { Location: [`${n.pathname}/`] },
2769
+ { location: [`${n.pathname}/`] },
2761
2770
  new Uint8Array(0)
2762
2771
  )
2763
2772
  );
@@ -2776,10 +2785,10 @@ class PHPRequestHandler {
2776
2785
  let c = o;
2777
2786
  for (; c.startsWith("/") && c !== dirname(c); ) {
2778
2787
  c = dirname(c);
2779
- const l = m(this, P, B).call(this, c);
2788
+ const l = m(this, P, j).call(this, c);
2780
2789
  if (i.isFile(l) && // Only run partial path resolution for PHP files.
2781
2790
  l.endsWith(".php")) {
2782
- a = m(this, P, B).call(this, c);
2791
+ a = m(this, P, j).call(this, c);
2783
2792
  break;
2784
2793
  }
2785
2794
  }
@@ -2804,8 +2813,8 @@ class PHPRequestHandler {
2804
2813
  );
2805
2814
  }
2806
2815
  }
2807
- return i.isFile(a) ? a.endsWith(".php") ? await m(this, P, ie).call(this, e, s, n, a) : StreamedPHPResponse.fromPHPResponse(
2808
- m(this, P, ne).call(this, i, a)
2816
+ return i.isFile(a) ? a.endsWith(".php") ? await m(this, P, oe).call(this, e, s, n, a) : StreamedPHPResponse.fromPHPResponse(
2817
+ m(this, P, ie).call(this, i, a)
2809
2818
  ) : StreamedPHPResponse.forHttpCode(404);
2810
2819
  }
2811
2820
  /**
@@ -2900,7 +2909,7 @@ class PHPRequestHandler {
2900
2909
  const n = {
2901
2910
  REMOTE_ADDR: "127.0.0.1",
2902
2911
  DOCUMENT_ROOT: u(this, v),
2903
- HTTPS: u(this, N).startsWith("https://") ? "on" : ""
2912
+ HTTPS: u(this, A).startsWith("https://") ? "on" : ""
2904
2913
  };
2905
2914
  return n.REQUEST_URI = e.pathname + e.search, s.startsWith(u(this, v)) && (n.SCRIPT_NAME = s.substring(
2906
2915
  u(this, v).length
@@ -2915,13 +2924,13 @@ class PHPRequestHandler {
2915
2924
  await this.instanceManager[Symbol.asyncDispose]();
2916
2925
  }
2917
2926
  }
2918
- v = new WeakMap(), I = new WeakMap(), O = new WeakMap(), L = new WeakMap(), A = new WeakMap(), E = new WeakMap(), N = new WeakMap(), k = new WeakMap(), U = new WeakMap(), P = new WeakSet(), /**
2927
+ v = new WeakMap(), C = new WeakMap(), U = new WeakMap(), L = new WeakMap(), I = new WeakMap(), E = new WeakMap(), A = new WeakMap(), k = new WeakMap(), B = new WeakMap(), P = new WeakSet(), /**
2919
2928
  * Apply the rewrite rules to the original request URL.
2920
2929
  *
2921
2930
  * @param originalRequestUrl - The original request URL.
2922
2931
  * @returns The rewritten request URL.
2923
2932
  */
2924
- se = function(e) {
2933
+ ne = function(e) {
2925
2934
  const t = removePathPrefix(
2926
2935
  decodeURIComponent(e.pathname),
2927
2936
  u(this, E)
@@ -2944,8 +2953,8 @@ se = function(e) {
2944
2953
  * @param urlPath - The URL path to resolve (e.g., '/phpmyadmin/index.php')
2945
2954
  * @returns The resolved filesystem path
2946
2955
  */
2947
- B = function(e) {
2948
- for (const t of u(this, U))
2956
+ j = function(e) {
2957
+ for (const t of u(this, B))
2949
2958
  if (e === t.urlPrefix || e.startsWith(t.urlPrefix + "/")) {
2950
2959
  const s = e.slice(t.urlPrefix.length);
2951
2960
  return joinPaths(t.fsPath, s);
@@ -2957,7 +2966,7 @@ B = function(e) {
2957
2966
  * @param fsPath - Absolute path of the static file to serve.
2958
2967
  * @returns The response.
2959
2968
  */
2960
- ne = function(e, t) {
2969
+ ie = function(e, t) {
2961
2970
  const s = e.readFileAsBuffer(t);
2962
2971
  return new PHPResponse(
2963
2972
  200,
@@ -2972,7 +2981,7 @@ ne = function(e, t) {
2972
2981
  },
2973
2982
  s
2974
2983
  );
2975
- }, ie = async function(e, t, s, n) {
2984
+ }, oe = async function(e, t, s, n) {
2976
2985
  let i;
2977
2986
  try {
2978
2987
  i = await this.instanceManager.acquirePHPInstance();
@@ -2981,17 +2990,17 @@ ne = function(e, t) {
2981
2990
  }
2982
2991
  let o;
2983
2992
  try {
2984
- o = await m(this, P, oe).call(this, i.php, e, t, s, n);
2993
+ o = await m(this, P, ae).call(this, i.php, e, t, s, n);
2985
2994
  } catch (a) {
2986
2995
  throw i.reap(), a;
2987
2996
  }
2988
2997
  return o.finished.finally(() => {
2989
2998
  i == null || i.reap();
2990
2999
  }), o;
2991
- }, oe = async function(e, t, s, n, i) {
3000
+ }, ae = async function(e, t, s, n, i) {
2992
3001
  let o = "GET";
2993
3002
  const a = {
2994
- host: u(this, A),
3003
+ host: u(this, I),
2995
3004
  ...normalizeHeaders(t.headers || {})
2996
3005
  };
2997
3006
  u(this, k) && (a.cookie = u(this, k).getCookieRequestHeader());
@@ -3006,7 +3015,7 @@ ne = function(e, t) {
3006
3015
  toRelativeUrl(new URL(n.toString())),
3007
3016
  u(this, E)
3008
3017
  ),
3009
- protocol: u(this, I),
3018
+ protocol: u(this, C),
3010
3019
  method: t.method || o,
3011
3020
  $_SERVER: this.prepare_$_SERVER_superglobal(
3012
3021
  s,
@@ -3018,10 +3027,10 @@ ne = function(e, t) {
3018
3027
  headers: a
3019
3028
  });
3020
3029
  if (u(this, k)) {
3021
- const d = u(this, k);
3022
- l.headers.then((h) => {
3023
- d.rememberCookiesFromResponseHeaders(h);
3024
- });
3030
+ const d = await l.headers;
3031
+ u(this, k).rememberCookiesFromResponseHeaders(
3032
+ d
3033
+ );
3025
3034
  }
3026
3035
  return l;
3027
3036
  };
@@ -3098,20 +3107,28 @@ function ensureProxyFSHasMmapSupport(r) {
3098
3107
  ), 0;
3099
3108
  });
3100
3109
  }
3101
- function proxyFileSystem(r, e, t) {
3102
- ensureProxyFSHasMmapSupport(e);
3103
- const s = Object.getOwnPropertySymbols(e)[0], n = Object.getOwnPropertySymbols(r)[0];
3104
- for (const i of t)
3105
- e.fileExists(i) || e.mkdir(i), r.fileExists(i) || r.mkdir(i), e[s].FS.mount(
3106
- // @ts-ignore
3107
- e[s].PROXYFS,
3108
- {
3109
- root: i,
3110
+ async function proxyFileSystem(r, e, t) {
3111
+ const s = Object.getOwnPropertySymbols(r)[0];
3112
+ for (const n of t)
3113
+ r.fileExists(n) || r.mkdir(n), e.mkdir(n), await e.mount(n, (i) => {
3114
+ ensureProxyFSHasMmapSupport(i);
3115
+ const o = Object.getOwnPropertySymbols(i)[0];
3116
+ return i[o].FS.mount(
3110
3117
  // @ts-ignore
3111
- fs: r[n].FS
3112
- },
3113
- i
3114
- );
3118
+ i[o].PROXYFS,
3119
+ {
3120
+ root: n,
3121
+ // @ts-ignore
3122
+ fs: r[s].FS
3123
+ },
3124
+ n
3125
+ ), () => {
3126
+ try {
3127
+ i[o].FS.unmount(n);
3128
+ } catch {
3129
+ }
3130
+ };
3131
+ });
3115
3132
  }
3116
3133
  function isPathToSharedFS(r, e) {
3117
3134
  var i;
@@ -3192,7 +3209,9 @@ function sandboxedSpawnHandlerFactory(r) {
3192
3209
  }
3193
3210
  }
3194
3211
  } catch (a) {
3195
- throw t.exit(1), a;
3212
+ const c = a instanceof Error ? a.message + `
3213
+ ` + a.stack : typeof a == "object" && a !== null ? JSON.stringify(a, Object.getOwnPropertyNames(a)) : String(a);
3214
+ throw t.stderr(`[spawn error] ${c}`), t.exit(1), a;
3196
3215
  } finally {
3197
3216
  o();
3198
3217
  }
@@ -3952,19 +3971,21 @@ function setupTransferHandlers() {
3952
3971
  }
3953
3972
  });
3954
3973
  }
3974
+ let _cachedSupportsTransferableStreams;
3955
3975
  function supportsTransferableStreams() {
3956
- try {
3957
- if (typeof ReadableStream > "u") return !1;
3958
- const { port1: r } = new MessageChannel(), e = new ReadableStream();
3959
- r.postMessage(e);
3976
+ if (typeof ReadableStream > "u" && (_cachedSupportsTransferableStreams = !1), _cachedSupportsTransferableStreams === void 0)
3960
3977
  try {
3961
- r.close();
3978
+ const { port1: r } = new MessageChannel(), e = new ReadableStream();
3979
+ r.postMessage(e, [e]);
3980
+ try {
3981
+ r.close();
3982
+ } catch {
3983
+ }
3984
+ _cachedSupportsTransferableStreams = !0;
3962
3985
  } catch {
3986
+ _cachedSupportsTransferableStreams = !1;
3963
3987
  }
3964
- return !0;
3965
- } catch {
3966
- return !1;
3967
- }
3988
+ return _cachedSupportsTransferableStreams;
3968
3989
  }
3969
3990
  function streamToPort(r) {
3970
3991
  const { port1: e, port2: t } = new MessageChannel();
@@ -4765,6 +4786,7 @@ export {
4765
4786
  iteratePhpFiles as iterateFiles,
4766
4787
  loadPHPRuntime,
4767
4788
  popLoadedRuntime,
4789
+ portToStream,
4768
4790
  prettyPrintFullStackTrace,
4769
4791
  printDebugDetails,
4770
4792
  printResponseDebugDetails,
@@ -4774,6 +4796,7 @@ export {
4774
4796
  rotatePHPRuntime,
4775
4797
  sandboxedSpawnHandlerFactory,
4776
4798
  setPhpIniEntries,
4799
+ streamToPort,
4777
4800
  toRelativeUrl,
4778
4801
  withPHPIniValues,
4779
4802
  writeFiles,