@php-wasm/universal 3.1.25 → 3.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,8 +1,8 @@
1
- var J = (r) => {
1
+ var ue = (r) => {
2
2
  throw TypeError(r);
3
3
  };
4
- var q = (r, e, t) => e.has(r) || J("Cannot " + t);
5
- var d = (r, e, t) => (q(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), w = (r, e, t, s) => (q(r, e, "write to private field"), s ? s.call(r, t) : e.set(r, t), t), m = (r, e, t) => (q(r, e, "access private method"), t);
4
+ var ae = (r, e, t) => e.has(r) || ue("Cannot " + t);
5
+ var u = (r, e, t) => (ae(r, e, "read from private field"), t ? t.call(r) : e.get(r)), _ = (r, e, t) => e.has(r) ? ue("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), v = (r, e, t, s) => (ae(r, e, "write to private field"), s ? s.call(r, t) : e.set(r, t), t), P = (r, e, t) => (ae(r, e, "access private method"), t);
6
6
  import { logger } from "@php-wasm/logger";
7
7
  import { dirname, joinPaths, Semaphore, createSpawnHandler, basename, normalizePath, AcquireTimeoutError, splitShellCommand } from "@php-wasm/util";
8
8
  import { parse, stringify } from "ini";
@@ -371,12 +371,12 @@ FSHelpers.mkdir = rethrowFileSystemError('Could not create directory "{path}"')(
371
371
  FSHelpers.mkdir
372
372
  );
373
373
  const _private = /* @__PURE__ */ new WeakMap();
374
- var v;
374
+ var O;
375
375
  class PHPWorker {
376
376
  /** @inheritDoc */
377
377
  constructor(e, t) {
378
- y(this, v);
379
- this.absoluteUrl = "", this.documentRoot = "", this.chroot = null, w(this, v, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
378
+ _(this, O);
379
+ this.absoluteUrl = "", this.documentRoot = "", this.chroot = null, v(this, O, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
380
380
  monitor: t
381
381
  }), e && this.__internal_setRequestHandler(e);
382
382
  }
@@ -551,7 +551,7 @@ class PHPWorker {
551
551
  }
552
552
  /** @inheritDoc @php-wasm/universal!/PHP.addEventListener */
553
553
  addEventListener(e, t) {
554
- d(this, v).has(e) || d(this, v).set(e, /* @__PURE__ */ new Set()), d(this, v).get(e).add(t);
554
+ u(this, O).has(e) || u(this, O).set(e, /* @__PURE__ */ new Set()), u(this, O).get(e).add(t);
555
555
  }
556
556
  /**
557
557
  * Removes an event listener for a PHP event.
@@ -560,10 +560,10 @@ class PHPWorker {
560
560
  */
561
561
  removeEventListener(e, t) {
562
562
  var s;
563
- (s = d(this, v).get(e)) == null || s.delete(t);
563
+ (s = u(this, O).get(e)) == null || s.delete(t);
564
564
  }
565
565
  dispatchEvent(e) {
566
- const t = d(this, v).get(e.type);
566
+ const t = u(this, O).get(e.type);
567
567
  if (t)
568
568
  for (const s of t)
569
569
  s(e);
@@ -595,7 +595,7 @@ class PHPWorker {
595
595
  throw new Error("PHPWorker is not connected to a request handler.");
596
596
  }
597
597
  }
598
- v = new WeakMap();
598
+ O = new WeakMap();
599
599
  function isExitCode(r) {
600
600
  return r instanceof Error ? (r == null ? void 0 : r.name) === "ExitStatus" && "status" in r : !1;
601
601
  }
@@ -662,8 +662,8 @@ const currentJsRuntime = function() {
662
662
  201: "Created",
663
663
  200: "OK"
664
664
  };
665
- var O, U;
666
- const W = class W {
665
+ var K, Z;
666
+ const se = class se {
667
667
  constructor(e, t, s, n) {
668
668
  /**
669
669
  * Headers stream that doesn't get locked when the consumer
@@ -672,14 +672,14 @@ const W = class W {
672
672
  * Both streams must be readable when the StreamedPHPResponse is transferred
673
673
  * from the worker thread into the service worker.
674
674
  */
675
- y(this, O);
675
+ _(this, K);
676
676
  /**
677
677
  * Headers stream reserved for internal parsing.
678
678
  */
679
- y(this, U);
679
+ _(this, Z);
680
680
  this.cachedParsedHeaders = null, this.cachedStdoutBytes = null, this.cachedStderrText = null;
681
681
  const [i, o] = e.tee();
682
- w(this, O, i), w(this, U, o), this.stdout = t, this.stderr = s, this.exitCode = n;
682
+ v(this, K, i), v(this, Z, o), this.stdout = t, this.stderr = s, this.exitCode = n;
683
683
  }
684
684
  /**
685
685
  * Creates a StreamedPHPResponse from a buffered PHPResponse.
@@ -708,7 +708,7 @@ const W = class W {
708
708
  ), a.close();
709
709
  }
710
710
  });
711
- return new W(
711
+ return new se(
712
712
  i,
713
713
  t,
714
714
  o,
@@ -720,7 +720,7 @@ const W = class W {
720
720
  * Shorthand for `StreamedPHPResponse.fromPHPResponse(PHPResponse.forHttpCode(...))`.
721
721
  */
722
722
  static forHttpCode(e, t = "") {
723
- return W.fromPHPResponse(
723
+ return se.fromPHPResponse(
724
724
  PHPResponse.forHttpCode(e, t)
725
725
  );
726
726
  }
@@ -729,7 +729,7 @@ const W = class W {
729
729
  * For parsed headers, use the `headers` property instead.
730
730
  */
731
731
  getHeadersStream() {
732
- return d(this, O);
732
+ return u(this, K);
733
733
  }
734
734
  /**
735
735
  * True if the response is successful (HTTP status code 200-399),
@@ -790,12 +790,12 @@ const W = class W {
790
790
  }
791
791
  async getParsedHeaders() {
792
792
  return this.cachedParsedHeaders || (this.cachedParsedHeaders = parseHeadersStream(
793
- d(this, U)
793
+ u(this, Z)
794
794
  )), await this.cachedParsedHeaders;
795
795
  }
796
796
  };
797
- O = new WeakMap(), U = new WeakMap();
798
- let StreamedPHPResponse = W;
797
+ K = new WeakMap(), Z = new WeakMap();
798
+ let StreamedPHPResponse = se;
799
799
  async function parseHeadersStream(r) {
800
800
  const e = await streamToText(r);
801
801
  let t;
@@ -1069,7 +1069,7 @@ class PHPExecutionFailureError extends Error {
1069
1069
  }
1070
1070
  }
1071
1071
  const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php", OPCACHE_FILE_FOLDER = "/internal/shared/opcache";
1072
- var I, R, H, F, b, T, _, f, Y, X, Q, K, Z, ee, te, re, z, se, V, G;
1072
+ var G, B, q, U, W, $, x, y, pe, he, fe, me, ye, ge, Pe, we, ce, _e, le, de;
1073
1073
  class PHP {
1074
1074
  /**
1075
1075
  * Initializes a PHP runtime.
@@ -1079,17 +1079,17 @@ class PHP {
1079
1079
  * @param requestHandlerOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
1080
1080
  */
1081
1081
  constructor(r) {
1082
- y(this, f);
1083
- y(this, I);
1084
- y(this, R, !1);
1085
- y(this, H, null);
1086
- y(this, F, /* @__PURE__ */ new Map([
1082
+ _(this, y);
1083
+ _(this, G);
1084
+ _(this, B, !1);
1085
+ _(this, q, null);
1086
+ _(this, U, /* @__PURE__ */ new Map([
1087
1087
  // Listen to all events
1088
1088
  ["*", /* @__PURE__ */ new Set()]
1089
1089
  ]));
1090
- y(this, b, []);
1091
- y(this, T, {});
1092
- y(this, _, {
1090
+ _(this, W, []);
1091
+ _(this, $, {});
1092
+ _(this, x, {
1093
1093
  enabled: !1,
1094
1094
  recreateRuntime: () => 0,
1095
1095
  needsRotating: !1,
@@ -1097,7 +1097,7 @@ class PHP {
1097
1097
  requestsMade: 0
1098
1098
  });
1099
1099
  this.semaphore = new Semaphore({ concurrency: 1 }), r !== void 0 && this.initializeRuntime(r), this.addEventListener("request.error", (e) => {
1100
- e.source === "php-wasm" && (d(this, _).needsRotating = !0);
1100
+ e.source === "php-wasm" && (u(this, x).needsRotating = !0);
1101
1101
  });
1102
1102
  }
1103
1103
  /**
@@ -1106,7 +1106,7 @@ class PHP {
1106
1106
  * @param listener - The listener function to be called when the event is triggered.
1107
1107
  */
1108
1108
  addEventListener(r, e) {
1109
- d(this, F).has(r) || d(this, F).set(r, /* @__PURE__ */ new Set()), d(this, F).get(r).add(e);
1109
+ u(this, U).has(r) || u(this, U).set(r, /* @__PURE__ */ new Set()), u(this, U).get(r).add(e);
1110
1110
  }
1111
1111
  /**
1112
1112
  * Removes an event listener for a PHP event.
@@ -1115,12 +1115,12 @@ class PHP {
1115
1115
  */
1116
1116
  removeEventListener(r, e) {
1117
1117
  var t;
1118
- (t = d(this, F).get(r)) == null || t.delete(e);
1118
+ (t = u(this, U).get(r)) == null || t.delete(e);
1119
1119
  }
1120
1120
  dispatchEvent(r) {
1121
1121
  const e = [
1122
- ...d(this, F).get(r.type) || [],
1123
- ...d(this, F).get("*") || []
1122
+ ...u(this, U).get(r.type) || [],
1123
+ ...u(this, U).get("*") || []
1124
1124
  ];
1125
1125
  if (e)
1126
1126
  for (const t of e)
@@ -1166,8 +1166,8 @@ class PHP {
1166
1166
  * @param listener Callback function to handle the message.
1167
1167
  */
1168
1168
  onMessage(r) {
1169
- return d(this, b).push(r), async () => {
1170
- w(this, b, d(this, b).filter(
1169
+ return u(this, W).push(r), async () => {
1170
+ v(this, W, u(this, W).filter(
1171
1171
  (e) => e !== r
1172
1172
  ));
1173
1173
  };
@@ -1261,13 +1261,13 @@ class PHP {
1261
1261
  }
1262
1262
  `
1263
1263
  ), e.onMessage = async (t) => {
1264
- for (const s of d(this, b)) {
1264
+ for (const s of u(this, W)) {
1265
1265
  const n = await s(t);
1266
1266
  if (n)
1267
1267
  return n;
1268
1268
  }
1269
1269
  return "";
1270
- }, w(this, H, improveWASMErrorReporting(e)), this.dispatchEvent({
1270
+ }, v(this, q, improveWASMErrorReporting(e)), this.dispatchEvent({
1271
1271
  type: "runtime.initialized"
1272
1272
  });
1273
1273
  }
@@ -1282,7 +1282,7 @@ class PHP {
1282
1282
  throw new Error(
1283
1283
  "Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
1284
1284
  );
1285
- w(this, I, r);
1285
+ v(this, G, r);
1286
1286
  }
1287
1287
  /**
1288
1288
  * Changes the current working directory in the PHP filesystem.
@@ -1504,8 +1504,8 @@ class PHP {
1504
1504
  async runStream(r) {
1505
1505
  const e = await this.semaphore.acquire();
1506
1506
  let t;
1507
- const s = m(this, f, G).call(this, async () => {
1508
- if (d(this, R) || (await this[__private__dont__use].ccall(
1507
+ const s = P(this, y, de).call(this, async () => {
1508
+ if (u(this, B) || (await this[__private__dont__use].ccall(
1509
1509
  "php_wasm_init",
1510
1510
  null,
1511
1511
  [],
@@ -1513,26 +1513,26 @@ class PHP {
1513
1513
  {
1514
1514
  isAsync: !0
1515
1515
  }
1516
- ), w(this, R, !0)), r.scriptPath && !this.fileExists(r.scriptPath))
1516
+ ), v(this, B, !0)), r.scriptPath && !this.fileExists(r.scriptPath))
1517
1517
  throw new Error(
1518
1518
  `The script path "${r.scriptPath}" does not exist.`
1519
1519
  );
1520
- m(this, f, X).call(this, r.relativeUri || ""), m(this, f, ee).call(this, r.method || "GET");
1521
- const i = normalizeHeaders(r.headers || {}), o = i.host || "example.com:443", a = m(this, f, Z).call(this, o, r.protocol || "http");
1522
- if (m(this, f, Q).call(this, o), m(this, f, K).call(this, a), m(this, f, te).call(this, i), r.body && (t = m(this, f, re).call(this, r.body)), typeof r.code == "string")
1523
- this.writeFile("/internal/eval.php", r.code), m(this, f, z).call(this, "/internal/eval.php");
1520
+ P(this, y, he).call(this, r.relativeUri || ""), P(this, y, ge).call(this, r.method || "GET");
1521
+ const i = normalizeHeaders(r.headers || {}), o = i.host || "example.com:443", a = P(this, y, ye).call(this, o, r.protocol || "http");
1522
+ if (P(this, y, fe).call(this, o), P(this, y, me).call(this, a), P(this, y, Pe).call(this, i), r.body && (t = P(this, y, we).call(this, r.body)), typeof r.code == "string")
1523
+ this.writeFile("/internal/eval.php", r.code), P(this, y, ce).call(this, "/internal/eval.php");
1524
1524
  else if (typeof r.scriptPath == "string")
1525
- m(this, f, z).call(this, r.scriptPath || "");
1525
+ P(this, y, ce).call(this, r.scriptPath || "");
1526
1526
  else
1527
1527
  throw new TypeError(
1528
1528
  "The request object must have either a `code` or a `scriptPath` property."
1529
1529
  );
1530
- const c = m(this, f, Y).call(this, r.$_SERVER, i, a);
1531
- for (const u in c)
1532
- m(this, f, se).call(this, u, c[u]);
1530
+ const c = P(this, y, pe).call(this, r.$_SERVER, i, a);
1531
+ for (const d in c)
1532
+ P(this, y, _e).call(this, d, c[d]);
1533
1533
  const l = r.env || {};
1534
- for (const u in l)
1535
- m(this, f, V).call(this, u, l[u]);
1534
+ for (const d in l)
1535
+ P(this, y, le).call(this, d, l[d]);
1536
1536
  return await this[__private__dont__use].ccall(
1537
1537
  "wasm_sapi_handle_request",
1538
1538
  NUMBER,
@@ -1770,21 +1770,21 @@ class PHP {
1770
1770
  * or an internal crash.
1771
1771
  */
1772
1772
  enableRuntimeRotation(r) {
1773
- w(this, _, {
1774
- ...d(this, _),
1773
+ v(this, x, {
1774
+ ...u(this, x),
1775
1775
  enabled: !0,
1776
1776
  recreateRuntime: r.recreateRuntime,
1777
1777
  maxRequests: r.maxRequests ?? 400
1778
1778
  });
1779
1779
  }
1780
1780
  async rotateRuntime() {
1781
- if (!d(this, _).enabled)
1781
+ if (!u(this, x).enabled)
1782
1782
  throw new Error(
1783
1783
  "Runtime rotation is not enabled. Call enableRuntimeRotation() first."
1784
1784
  );
1785
1785
  await this.hotSwapPHPRuntime(
1786
- await d(this, _).recreateRuntime()
1787
- ), d(this, _).requestsMade = 0, d(this, _).needsRotating = !1;
1786
+ await u(this, x).recreateRuntime()
1787
+ ), u(this, x).requestsMade = 0, u(this, x).needsRotating = !1;
1788
1788
  }
1789
1789
  /**
1790
1790
  * Hot-swaps the PHP runtime for a new one without
@@ -1795,13 +1795,13 @@ class PHP {
1795
1795
  async hotSwapPHPRuntime(r) {
1796
1796
  const e = this[__private__dont__use].FS, t = this.listFiles("/").map((c) => `/${c}`), s = this[__private__dont__use].spawnProcess, n = e.cwd();
1797
1797
  e.chdir("/");
1798
- const i = Object.entries(d(this, T)).map(
1798
+ const i = Object.entries(u(this, $)).map(
1799
1799
  ([c, l]) => ({
1800
1800
  mountHandler: l.mountHandler,
1801
1801
  vfsPath: c
1802
1802
  })
1803
1803
  ), o = Object.values(
1804
- d(this, T)
1804
+ u(this, $)
1805
1805
  ).reverse();
1806
1806
  for (const c of o)
1807
1807
  await c.unmount();
@@ -1809,7 +1809,7 @@ class PHP {
1809
1809
  this.exit();
1810
1810
  } catch {
1811
1811
  }
1812
- this.initializeRuntime(r), s && (this[__private__dont__use].spawnProcess = s), d(this, I) && this.setSapiName(d(this, I));
1812
+ this.initializeRuntime(r), s && (this[__private__dont__use].spawnProcess = s), u(this, G) && this.setSapiName(u(this, G));
1813
1813
  const a = this[__private__dont__use].FS;
1814
1814
  for (const c of t)
1815
1815
  c && c !== "/request" && copyMEMFSNodes(e, a, c);
@@ -1844,11 +1844,11 @@ class PHP {
1844
1844
  try {
1845
1845
  await t();
1846
1846
  } finally {
1847
- delete d(this, T)[r];
1847
+ delete u(this, $)[r];
1848
1848
  }
1849
1849
  }
1850
1850
  };
1851
- return d(this, T)[r] = s, () => s.unmount();
1851
+ return u(this, $)[r] = s, () => s.unmount();
1852
1852
  }
1853
1853
  /**
1854
1854
  * Starts a PHP CLI session with given arguments.
@@ -1866,12 +1866,12 @@ class PHP {
1866
1866
  async cli(r, e = {}) {
1867
1867
  if (basename(r[0] ?? "") !== "php")
1868
1868
  return this.subProcess(r, e);
1869
- d(this, R) && (d(this, _).needsRotating = !0);
1869
+ u(this, B) && (u(this, x).needsRotating = !0);
1870
1870
  const t = await this.semaphore.acquire();
1871
- return await m(this, f, G).call(this, () => {
1871
+ return await P(this, y, de).call(this, () => {
1872
1872
  const s = e.env || {};
1873
1873
  for (const [n, i] of Object.entries(s))
1874
- m(this, f, V).call(this, n, i);
1874
+ P(this, y, le).call(this, n, i);
1875
1875
  r = [r[0], "-c", PHP_INI_PATH, ...r.slice(1)];
1876
1876
  for (const n of r)
1877
1877
  this[__private__dont__use].ccall(
@@ -1884,7 +1884,7 @@ class PHP {
1884
1884
  async: !0
1885
1885
  });
1886
1886
  }).then((s) => (s.exitCode.finally(t), s)).finally(() => {
1887
- d(this, _).needsRotating = !0;
1887
+ u(this, x).needsRotating = !0;
1888
1888
  });
1889
1889
  }
1890
1890
  /**
@@ -1966,13 +1966,13 @@ class PHP {
1966
1966
  this[__private__dont__use]._exit(r);
1967
1967
  } catch {
1968
1968
  }
1969
- w(this, R, !1), w(this, H, null), this[__private__dont__use] && (delete this[__private__dont__use].onMessage, delete this[__private__dont__use]);
1969
+ v(this, B, !1), v(this, q, null), this[__private__dont__use] && (delete this[__private__dont__use].onMessage, delete this[__private__dont__use]);
1970
1970
  }
1971
1971
  [Symbol.dispose]() {
1972
1972
  this.exit(0);
1973
1973
  }
1974
1974
  }
1975
- I = new WeakMap(), R = new WeakMap(), H = new WeakMap(), F = new WeakMap(), b = new WeakMap(), T = new WeakMap(), _ = new WeakMap(), f = new WeakSet(), /**
1975
+ G = new WeakMap(), B = new WeakMap(), q = new WeakMap(), U = new WeakMap(), W = new WeakMap(), $ = new WeakMap(), x = new WeakMap(), y = new WeakSet(), /**
1976
1976
  * Prepares the $_SERVER entries for the PHP runtime.
1977
1977
  *
1978
1978
  * @param defaults Default entries to include in $_SERVER.
@@ -1981,7 +1981,7 @@ I = new WeakMap(), R = new WeakMap(), H = new WeakMap(), F = new WeakMap(), b =
1981
1981
  * was provided.
1982
1982
  * @returns Computed $_SERVER entries.
1983
1983
  */
1984
- Y = function(r, e, t) {
1984
+ pe = function(r, e, t) {
1985
1985
  const s = {
1986
1986
  ...r || {}
1987
1987
  };
@@ -1991,7 +1991,7 @@ Y = function(r, e, t) {
1991
1991
  ["content-type", "content-length"].includes(n.toLowerCase()) && (i = ""), s[`${i}${n.toUpperCase().replace(/-/g, "_")}`] = e[n];
1992
1992
  }
1993
1993
  return s;
1994
- }, X = function(r) {
1994
+ }, he = function(r) {
1995
1995
  this[__private__dont__use].ccall(
1996
1996
  "wasm_set_request_uri",
1997
1997
  null,
@@ -2005,35 +2005,35 @@ Y = function(r, e, t) {
2005
2005
  [STRING],
2006
2006
  [e]
2007
2007
  );
2008
- }, Q = function(r) {
2008
+ }, fe = function(r) {
2009
2009
  this[__private__dont__use].ccall(
2010
2010
  "wasm_set_request_host",
2011
2011
  null,
2012
2012
  [STRING],
2013
2013
  [r]
2014
2014
  );
2015
- }, K = function(r) {
2015
+ }, me = function(r) {
2016
2016
  this[__private__dont__use].ccall(
2017
2017
  "wasm_set_request_port",
2018
2018
  null,
2019
2019
  [NUMBER],
2020
2020
  [r]
2021
2021
  );
2022
- }, Z = function(r, e) {
2022
+ }, ye = function(r, e) {
2023
2023
  let t;
2024
2024
  try {
2025
2025
  t = parseInt(new URL(r).port, 10);
2026
2026
  } catch {
2027
2027
  }
2028
2028
  return (!t || isNaN(t) || t === 80) && (t = e === "https" ? 443 : 80), t;
2029
- }, ee = function(r) {
2029
+ }, ge = function(r) {
2030
2030
  this[__private__dont__use].ccall(
2031
2031
  "wasm_set_request_method",
2032
2032
  null,
2033
2033
  [STRING],
2034
2034
  [r]
2035
2035
  );
2036
- }, te = function(r) {
2036
+ }, Pe = function(r) {
2037
2037
  r.cookie && this[__private__dont__use].ccall(
2038
2038
  "wasm_set_cookies",
2039
2039
  null,
@@ -2050,7 +2050,7 @@ Y = function(r, e, t) {
2050
2050
  [NUMBER],
2051
2051
  [parseInt(r["content-length"], 10)]
2052
2052
  );
2053
- }, re = function(r) {
2053
+ }, we = function(r) {
2054
2054
  let e, t;
2055
2055
  typeof r == "string" ? (logger.warn(
2056
2056
  "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"
@@ -2073,101 +2073,101 @@ Y = function(r, e, t) {
2073
2073
  [NUMBER],
2074
2074
  [t]
2075
2075
  ), s;
2076
- }, z = function(r) {
2076
+ }, ce = function(r) {
2077
2077
  this[__private__dont__use].ccall(
2078
2078
  "wasm_set_path_translated",
2079
2079
  null,
2080
2080
  [STRING],
2081
2081
  [r]
2082
2082
  );
2083
- }, se = function(r, e) {
2083
+ }, _e = function(r, e) {
2084
2084
  this[__private__dont__use].ccall(
2085
2085
  "wasm_add_SERVER_entry",
2086
2086
  null,
2087
2087
  [STRING, STRING],
2088
2088
  [r, e]
2089
2089
  );
2090
- }, V = function(r, e) {
2090
+ }, le = function(r, e) {
2091
2091
  this[__private__dont__use].ccall(
2092
2092
  "wasm_add_ENV_entry",
2093
2093
  null,
2094
2094
  [STRING, STRING],
2095
2095
  [r, e]
2096
2096
  );
2097
- }, G = async function(r) {
2098
- d(this, _).enabled && d(this, _).needsRotating && await this.rotateRuntime(), ++d(this, _).requestsMade, d(this, _).requestsMade >= d(this, _).maxRequests && (d(this, _).needsRotating = !0);
2097
+ }, de = async function(r) {
2098
+ u(this, x).enabled && u(this, x).needsRotating && await this.rotateRuntime(), ++u(this, x).requestsMade, u(this, x).requestsMade >= u(this, x).maxRequests && (u(this, x).needsRotating = !0);
2099
2099
  const e = this[__private__dont__use], t = await createInvertedReadableStream();
2100
- e.onHeaders = (h) => {
2101
- a || s || t.controller.enqueue(h.slice());
2100
+ e.onHeaders = (p) => {
2101
+ a || s || t.controller.enqueue(p.slice());
2102
2102
  };
2103
2103
  let s = !1;
2104
2104
  const n = () => {
2105
2105
  s || (s = !0, t.controller.close());
2106
2106
  }, i = await createInvertedReadableStream();
2107
- e.onStdout = (h) => {
2108
- n(), !a && i.controller.enqueue(h.slice());
2107
+ e.onStdout = (p) => {
2108
+ n(), !a && i.controller.enqueue(p.slice());
2109
2109
  };
2110
2110
  const o = await createInvertedReadableStream();
2111
- e.onStderr = (h) => {
2112
- a || o.controller.enqueue(h.slice());
2111
+ e.onStderr = (p) => {
2112
+ a || o.controller.enqueue(p.slice());
2113
2113
  };
2114
2114
  let a = !1, c;
2115
- const u = (async () => {
2116
- var h;
2115
+ const d = (async () => {
2116
+ var p;
2117
2117
  try {
2118
2118
  return await Promise.race([
2119
2119
  r(),
2120
- new Promise((g, S) => {
2121
- var $;
2120
+ new Promise((f, k) => {
2121
+ var R;
2122
2122
  c = (N) => {
2123
- isExitCode(N.error) || S(N.error);
2124
- }, ($ = d(this, H)) == null || $.addEventListener(
2123
+ isExitCode(N.error) || k(N.error);
2124
+ }, (R = u(this, q)) == null || R.addEventListener(
2125
2125
  "error",
2126
2126
  c,
2127
2127
  { once: !0 }
2128
2128
  );
2129
2129
  })
2130
2130
  ]);
2131
- } catch (p) {
2132
- if (isExitCode(p))
2133
- return p.status;
2134
- safeStreamError$1(i.controller, p), safeStreamError$1(o.controller, p), safeStreamError$1(t.controller, p), a = !0;
2135
- for (const g in this)
2136
- typeof this[g] == "function" && (this[g] = () => {
2131
+ } catch (h) {
2132
+ if (isExitCode(h))
2133
+ return h.status;
2134
+ safeStreamError$1(i.controller, h), safeStreamError$1(o.controller, h), safeStreamError$1(t.controller, h), a = !0;
2135
+ for (const f in this)
2136
+ typeof this[f] == "function" && (this[f] = () => {
2137
2137
  throw new Error(
2138
2138
  "PHP runtime has crashed – see the earlier error for details."
2139
2139
  );
2140
2140
  });
2141
- throw this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify(), p;
2141
+ throw this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify(), h;
2142
2142
  } finally {
2143
- a || (safeStreamClose$1(i.controller), safeStreamClose$1(o.controller), n(), a = !0), (h = d(this, H)) == null || h.removeEventListener(
2143
+ a || (safeStreamClose$1(i.controller), safeStreamClose$1(o.controller), n(), a = !0), (p = u(this, q)) == null || p.removeEventListener(
2144
2144
  "error",
2145
2145
  c
2146
2146
  );
2147
2147
  }
2148
2148
  })().then(
2149
- (h) => (h !== 0 && this.dispatchEvent({
2149
+ (p) => (p !== 0 && this.dispatchEvent({
2150
2150
  type: "request.error",
2151
2151
  error: new Error(
2152
- `PHP.run() failed with exit code ${h}.`
2152
+ `PHP.run() failed with exit code ${p}.`
2153
2153
  ),
2154
2154
  // Distinguish between PHP request and PHP-wasm errors
2155
2155
  source: "php-wasm"
2156
- }), h),
2157
- (h) => {
2158
- const p = h.source ?? "php-wasm";
2156
+ }), p),
2157
+ (p) => {
2158
+ const h = p.source ?? "php-wasm";
2159
2159
  throw this.dispatchEvent({
2160
2160
  type: "request.error",
2161
- error: h,
2162
- source: p
2163
- }), h;
2161
+ error: p,
2162
+ source: h
2163
+ }), p;
2164
2164
  }
2165
2165
  );
2166
2166
  return new StreamedPHPResponse(
2167
2167
  t.stream,
2168
2168
  i.stream,
2169
2169
  o.stream,
2170
- u
2170
+ d
2171
2171
  );
2172
2172
  };
2173
2173
  function normalizeHeaders(r) {
@@ -2658,7 +2658,7 @@ const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "app
2658
2658
  xspf,
2659
2659
  zip
2660
2660
  };
2661
- var x, C, j, L, M, E, A, k, D, P, ne, B, ie, oe, ae;
2661
+ var A, Y, ee, z, J, M, X, j, te, H, ve, re, Ee, xe, Se;
2662
2662
  class PHPRequestHandler {
2663
2663
  /**
2664
2664
  * The request handler needs to decide whether to serve a static asset or
@@ -2672,24 +2672,24 @@ class PHPRequestHandler {
2672
2672
  * @param config - Request Handler configuration.
2673
2673
  */
2674
2674
  constructor(e) {
2675
- y(this, P);
2676
- y(this, x);
2677
- y(this, C);
2678
- y(this, j);
2679
- y(this, L);
2680
- y(this, M);
2681
- y(this, E);
2682
- y(this, A);
2683
- y(this, k);
2684
- y(this, D);
2675
+ _(this, H);
2676
+ _(this, A);
2677
+ _(this, Y);
2678
+ _(this, ee);
2679
+ _(this, z);
2680
+ _(this, J);
2681
+ _(this, M);
2682
+ _(this, X);
2683
+ _(this, j);
2684
+ _(this, te);
2685
2685
  const {
2686
2686
  documentRoot: t = "/www/",
2687
2687
  absoluteUrl: s = typeof location == "object" ? location.href : DEFAULT_BASE_URL,
2688
2688
  rewriteRules: n = [],
2689
2689
  pathAliases: i = [],
2690
2690
  getFileNotFoundAction: o = () => ({ type: "404" })
2691
- } = e, a = (u) => {
2692
- u.isDir(t) || u.mkdir(t), u.chdir(t), u.requestHandler = this;
2691
+ } = e, a = (d) => {
2692
+ d.isDir(t) || d.mkdir(t), d.chdir(t), d.requestHandler = this;
2693
2693
  };
2694
2694
  if (e.php)
2695
2695
  a(e.php), this.instanceManager = new SinglePHPInstanceManager({
@@ -2697,12 +2697,12 @@ class PHPRequestHandler {
2697
2697
  });
2698
2698
  else if (e.phpFactory)
2699
2699
  this.instanceManager = new PHPProcessManager({
2700
- phpFactory: async (u) => {
2701
- const h = await e.phpFactory({
2702
- ...u,
2700
+ phpFactory: async (d) => {
2701
+ const p = await e.phpFactory({
2702
+ ...d,
2703
2703
  requestHandler: this
2704
2704
  });
2705
- return a(h), h;
2705
+ return a(p), p;
2706
2706
  },
2707
2707
  maxPhpInstances: e.maxPhpInstances
2708
2708
  });
@@ -2710,18 +2710,18 @@ class PHPRequestHandler {
2710
2710
  throw new Error(
2711
2711
  "Either php or phpFactory must be provided in the configuration."
2712
2712
  );
2713
- w(this, k, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), w(this, x, t);
2713
+ v(this, j, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), v(this, A, t);
2714
2714
  const c = new URL(s);
2715
- w(this, j, c.hostname), w(this, L, c.port ? Number(c.port) : c.protocol === "https:" ? 443 : 80), w(this, C, (c.protocol || "").replace(":", ""));
2716
- const l = d(this, L) !== 443 && d(this, L) !== 80;
2717
- w(this, M, [
2718
- d(this, j),
2719
- l ? `:${d(this, L)}` : ""
2720
- ].join("")), w(this, E, c.pathname.replace(/\/+$/, "")), w(this, A, [
2721
- `${d(this, C)}://`,
2722
- d(this, M),
2723
- d(this, E)
2724
- ].join("")), this.rewriteRules = n, w(this, D, i), this.getFileNotFoundAction = o;
2715
+ v(this, ee, c.hostname), v(this, z, c.port ? Number(c.port) : c.protocol === "https:" ? 443 : 80), v(this, Y, (c.protocol || "").replace(":", ""));
2716
+ const l = u(this, z) !== 443 && u(this, z) !== 80;
2717
+ v(this, J, [
2718
+ u(this, ee),
2719
+ l ? `:${u(this, z)}` : ""
2720
+ ].join("")), v(this, M, c.pathname.replace(/\/+$/, "")), v(this, X, [
2721
+ `${u(this, Y)}://`,
2722
+ u(this, J),
2723
+ u(this, M)
2724
+ ].join("")), this.rewriteRules = n, v(this, te, i), this.getFileNotFoundAction = o;
2725
2725
  }
2726
2726
  async getPrimaryPhp() {
2727
2727
  return await this.instanceManager.getPrimaryPhp();
@@ -2745,20 +2745,20 @@ class PHPRequestHandler {
2745
2745
  */
2746
2746
  internalUrlToPath(e) {
2747
2747
  const t = new URL(e, "https://playground.internal");
2748
- return t.pathname.startsWith(d(this, E)) && (t.pathname = t.pathname.slice(d(this, E).length)), toRelativeUrl(t);
2748
+ return t.pathname.startsWith(u(this, M)) && (t.pathname = t.pathname.slice(u(this, M).length)), toRelativeUrl(t);
2749
2749
  }
2750
2750
  /**
2751
2751
  * The absolute URL of this PHPRequestHandler instance.
2752
2752
  */
2753
2753
  get absoluteUrl() {
2754
- return d(this, A);
2754
+ return u(this, X);
2755
2755
  }
2756
2756
  /**
2757
2757
  * The directory in the PHP filesystem where the server will look
2758
2758
  * for the files to serve. Default: `/var/www`.
2759
2759
  */
2760
2760
  get documentRoot() {
2761
- return d(this, x);
2761
+ return u(this, A);
2762
2762
  }
2763
2763
  /**
2764
2764
  * Serves the request – either by serving a static file, or by
@@ -2834,15 +2834,15 @@ class PHPRequestHandler {
2834
2834
  // Remove the hash part of the URL as it's not meant for the server.
2835
2835
  e.url.split("#")[0],
2836
2836
  t ? void 0 : DEFAULT_BASE_URL
2837
- ), n = m(this, P, ne).call(this, s), i = await this.getPrimaryPhp(), o = removePathPrefix(
2837
+ ), n = P(this, H, ve).call(this, s), i = await this.getPrimaryPhp(), o = removePathPrefix(
2838
2838
  /**
2839
2839
  * URL.pathname returns a URL-encoded path. We need to decode it
2840
2840
  * before using it as a filesystem path.
2841
2841
  */
2842
2842
  decodeURIComponent(n.pathname),
2843
- d(this, E)
2843
+ u(this, M)
2844
2844
  );
2845
- let a = m(this, P, B).call(this, o);
2845
+ let a = P(this, H, re).call(this, o);
2846
2846
  if (i.isDir(a)) {
2847
2847
  if (!o.endsWith("/"))
2848
2848
  return StreamedPHPResponse.fromPHPResponse(
@@ -2867,10 +2867,10 @@ class PHPRequestHandler {
2867
2867
  let c = o;
2868
2868
  for (; c.startsWith("/") && c !== dirname(c); ) {
2869
2869
  c = dirname(c);
2870
- const l = m(this, P, B).call(this, c);
2870
+ const l = P(this, H, re).call(this, c);
2871
2871
  if (i.isFile(l) && // Only run partial path resolution for PHP files.
2872
2872
  l.endsWith(".php")) {
2873
- a = m(this, P, B).call(this, c);
2873
+ a = P(this, H, re).call(this, c);
2874
2874
  break;
2875
2875
  }
2876
2876
  }
@@ -2885,7 +2885,7 @@ class PHPRequestHandler {
2885
2885
  c.response
2886
2886
  );
2887
2887
  case "internal-redirect":
2888
- a = joinPaths(d(this, x), c.uri);
2888
+ a = joinPaths(u(this, A), c.uri);
2889
2889
  break;
2890
2890
  case "404":
2891
2891
  return StreamedPHPResponse.forHttpCode(404);
@@ -2895,8 +2895,8 @@ class PHPRequestHandler {
2895
2895
  );
2896
2896
  }
2897
2897
  }
2898
- return i.isFile(a) ? a.endsWith(".php") ? await m(this, P, oe).call(this, e, s, n, a) : StreamedPHPResponse.fromPHPResponse(
2899
- m(this, P, ie).call(this, i, a)
2898
+ return i.isFile(a) ? a.endsWith(".php") ? await P(this, H, xe).call(this, e, s, n, a) : StreamedPHPResponse.fromPHPResponse(
2899
+ P(this, H, Ee).call(this, i, a)
2900
2900
  ) : StreamedPHPResponse.forHttpCode(404);
2901
2901
  }
2902
2902
  /**
@@ -2990,11 +2990,11 @@ class PHPRequestHandler {
2990
2990
  prepare_$_SERVER_superglobal(e, t, s) {
2991
2991
  const n = {
2992
2992
  REMOTE_ADDR: "127.0.0.1",
2993
- DOCUMENT_ROOT: d(this, x),
2994
- HTTPS: d(this, A).startsWith("https://") ? "on" : ""
2993
+ DOCUMENT_ROOT: u(this, A),
2994
+ HTTPS: u(this, X).startsWith("https://") ? "on" : ""
2995
2995
  };
2996
- return n.REQUEST_URI = e.pathname + e.search, s.startsWith(d(this, x)) && (n.SCRIPT_NAME = s.substring(
2997
- d(this, x).length
2996
+ return n.REQUEST_URI = e.pathname + e.search, s.startsWith(u(this, A)) && (n.SCRIPT_NAME = s.substring(
2997
+ u(this, A).length
2998
2998
  ), n.PHP_SELF = t.pathname, n.REQUEST_URI.startsWith(n.SCRIPT_NAME) && (n.PATH_INFO = n.REQUEST_URI.substring(
2999
2999
  n.SCRIPT_NAME.length
3000
3000
  ), n.PATH_INFO.includes("?") && (n.PATH_INFO = n.PATH_INFO.substring(
@@ -3006,21 +3006,21 @@ class PHPRequestHandler {
3006
3006
  await this.instanceManager[Symbol.asyncDispose]();
3007
3007
  }
3008
3008
  }
3009
- x = new WeakMap(), C = new WeakMap(), j = new WeakMap(), L = new WeakMap(), M = new WeakMap(), E = new WeakMap(), A = new WeakMap(), k = new WeakMap(), D = new WeakMap(), P = new WeakSet(), /**
3009
+ A = new WeakMap(), Y = new WeakMap(), ee = new WeakMap(), z = new WeakMap(), J = new WeakMap(), M = new WeakMap(), X = new WeakMap(), j = new WeakMap(), te = new WeakMap(), H = new WeakSet(), /**
3010
3010
  * Apply the rewrite rules to the original request URL.
3011
3011
  *
3012
3012
  * @param originalRequestUrl - The original request URL.
3013
3013
  * @returns The rewritten request URL.
3014
3014
  */
3015
- ne = function(e) {
3015
+ ve = function(e) {
3016
3016
  const t = removePathPrefix(
3017
3017
  decodeURIComponent(e.pathname),
3018
- d(this, E)
3018
+ u(this, M)
3019
3019
  ), s = applyRewriteRules(
3020
3020
  t,
3021
3021
  this.rewriteRules
3022
3022
  ), n = new URL(
3023
- joinPaths(d(this, E), s),
3023
+ joinPaths(u(this, M), s),
3024
3024
  e.toString()
3025
3025
  );
3026
3026
  for (const [i, o] of e.searchParams.entries())
@@ -3035,20 +3035,20 @@ ne = function(e) {
3035
3035
  * @param urlPath - The URL path to resolve (e.g., '/phpmyadmin/index.php')
3036
3036
  * @returns The resolved filesystem path
3037
3037
  */
3038
- B = function(e) {
3039
- for (const t of d(this, D))
3038
+ re = function(e) {
3039
+ for (const t of u(this, te))
3040
3040
  if (e === t.urlPrefix || e.startsWith(t.urlPrefix + "/")) {
3041
3041
  const s = e.slice(t.urlPrefix.length);
3042
3042
  return joinPaths(t.fsPath, s);
3043
3043
  }
3044
- return joinPaths(d(this, x), e);
3044
+ return joinPaths(u(this, A), e);
3045
3045
  }, /**
3046
3046
  * Serves a static file from the PHP filesystem.
3047
3047
  *
3048
3048
  * @param fsPath - Absolute path of the static file to serve.
3049
3049
  * @returns The response.
3050
3050
  */
3051
- ie = function(e, t) {
3051
+ Ee = function(e, t) {
3052
3052
  const s = e.readFileAsBuffer(t);
3053
3053
  return new PHPResponse(
3054
3054
  200,
@@ -3063,7 +3063,7 @@ ie = function(e, t) {
3063
3063
  },
3064
3064
  s
3065
3065
  );
3066
- }, oe = async function(e, t, s, n) {
3066
+ }, xe = async function(e, t, s, n) {
3067
3067
  let i;
3068
3068
  try {
3069
3069
  i = await this.instanceManager.acquirePHPInstance();
@@ -3072,32 +3072,32 @@ ie = function(e, t) {
3072
3072
  }
3073
3073
  let o;
3074
3074
  try {
3075
- o = await m(this, P, ae).call(this, i.php, e, t, s, n);
3075
+ o = await P(this, H, Se).call(this, i.php, e, t, s, n);
3076
3076
  } catch (a) {
3077
3077
  throw i.reap(), a;
3078
3078
  }
3079
3079
  return o.finished.finally(() => {
3080
3080
  i == null || i.reap();
3081
3081
  }), o;
3082
- }, ae = async function(e, t, s, n, i) {
3082
+ }, Se = async function(e, t, s, n, i) {
3083
3083
  let o = "GET";
3084
3084
  const a = {
3085
- host: d(this, M),
3085
+ host: u(this, J),
3086
3086
  ...normalizeHeaders(t.headers || {})
3087
3087
  };
3088
- d(this, k) && (a.cookie = d(this, k).getCookieRequestHeader());
3088
+ u(this, j) && (a.cookie = u(this, j).getCookieRequestHeader());
3089
3089
  let c = t.body;
3090
3090
  if (typeof c == "object" && !(c instanceof Uint8Array)) {
3091
3091
  o = "POST";
3092
- const { bytes: u, contentType: h } = await encodeAsMultipart(c);
3093
- c = u, a["content-type"] = h;
3092
+ const { bytes: d, contentType: p } = await encodeAsMultipart(c);
3093
+ c = d, a["content-type"] = p;
3094
3094
  }
3095
3095
  const l = await e.runStream({
3096
3096
  relativeUri: ensurePathPrefix(
3097
3097
  toRelativeUrl(new URL(n.toString())),
3098
- d(this, E)
3098
+ u(this, M)
3099
3099
  ),
3100
- protocol: d(this, C),
3100
+ protocol: u(this, Y),
3101
3101
  method: t.method || o,
3102
3102
  $_SERVER: this.prepare_$_SERVER_superglobal(
3103
3103
  s,
@@ -3108,10 +3108,10 @@ ie = function(e, t) {
3108
3108
  scriptPath: i,
3109
3109
  headers: a
3110
3110
  });
3111
- if (d(this, k)) {
3112
- const u = await l.headers;
3113
- d(this, k).rememberCookiesFromResponseHeaders(
3114
- u
3111
+ if (u(this, j)) {
3112
+ const d = await l.headers;
3113
+ u(this, j).rememberCookiesFromResponseHeaders(
3114
+ d
3115
3115
  );
3116
3116
  }
3117
3117
  return l;
@@ -3152,91 +3152,634 @@ async function writeFiles(r, e, t, { rmRoot: s = !1 } = {}) {
3152
3152
  await r.fileExists(dirname(o)) || await r.mkdir(dirname(o)), i instanceof Uint8Array || typeof i == "string" ? await r.writeFile(o, i) : await writeFiles(r, o, i);
3153
3153
  }
3154
3154
  }
3155
- const PHP_EXTENSIONS_DIR = "/internal/shared/extensions";
3156
- async function resolvePHPExtension(r) {
3157
- const e = await resolvePHPExtensionSource(
3158
- r,
3159
- r.fetch ?? globalThis.fetch
3160
- );
3161
- return buildResolvedPHPExtension({
3162
- name: r.name ?? e.name,
3163
- soBytes: e.soBytes,
3164
- loadWithIniDirective: r.loadWithIniDirective,
3165
- iniEntries: r.iniEntries,
3166
- extraFiles: r.extraFiles,
3167
- env: r.env,
3168
- extensionDir: r.extensionDir
3169
- });
3170
- }
3171
- function withResolvedPHPExtensions(r, e) {
3172
- if (!e.length)
3173
- return r;
3174
- const t = {
3175
- ...r.ENV
3176
- };
3177
- for (const s of e) {
3178
- Object.assign(t, s.env);
3179
- const n = t.PHP_INI_SCAN_DIR, i = n ? n.split(":") : [];
3180
- t.PHP_INI_SCAN_DIR = !n || !i.includes(s.extensionDir) ? [...i, s.extensionDir].join(":") : n;
3155
+ const schema13 = {
3156
+ properties: {
3157
+ nodes: {
3158
+ items: {
3159
+ properties: {
3160
+ type: {
3161
+ enum: ["file", "directory"]
3162
+ }
3163
+ }
3164
+ }
3165
+ }
3181
3166
  }
3182
- return {
3183
- ...r,
3184
- ENV: t,
3185
- onRuntimeInitialized: (s) => {
3186
- var n;
3187
- (n = r.onRuntimeInitialized) == null || n.call(r, s);
3188
- for (const i of e)
3189
- installPHPExtensionFilesSync(s.FS, i);
3167
+ };
3168
+ function validate11(r, { instancePath: e = "", parentData: t, parentDataProperty: s, rootData: n = r } = {}) {
3169
+ let i = null, o = 0;
3170
+ if (r && typeof r == "object" && !Array.isArray(r)) {
3171
+ let N;
3172
+ if (r.name === void 0 && (N = "name") || r.artifacts === void 0 && (N = "artifacts"))
3173
+ return validate11.errors = [
3174
+ {
3175
+ instancePath: e,
3176
+ schemaPath: "#/required",
3177
+ keyword: "required",
3178
+ params: { missingProperty: N },
3179
+ message: "must have required property '" + N + "'"
3180
+ }
3181
+ ], !1;
3182
+ for (const m in r)
3183
+ if (!(m === "name" || m === "version" || m === "mode" || m === "artifacts" || m === "extraFiles"))
3184
+ return validate11.errors = [
3185
+ {
3186
+ instancePath: e,
3187
+ schemaPath: "#/additionalProperties",
3188
+ keyword: "additionalProperties",
3189
+ params: { additionalProperty: m },
3190
+ message: "must NOT have additional properties"
3191
+ }
3192
+ ], !1;
3193
+ {
3194
+ if (r.name !== void 0) {
3195
+ const m = o;
3196
+ if (typeof r.name != "string")
3197
+ return validate11.errors = [
3198
+ {
3199
+ instancePath: e + "/name",
3200
+ schemaPath: "#/properties/name/type",
3201
+ keyword: "type",
3202
+ params: { type: "string" },
3203
+ message: "must be string"
3204
+ }
3205
+ ], !1;
3206
+ var a = m === o;
3207
+ } else
3208
+ var a = !0;
3209
+ if (a) {
3210
+ if (r.version !== void 0) {
3211
+ const m = o;
3212
+ if (typeof r.version != "string")
3213
+ return validate11.errors = [
3214
+ {
3215
+ instancePath: e + "/version",
3216
+ schemaPath: "#/properties/version/type",
3217
+ keyword: "type",
3218
+ params: { type: "string" },
3219
+ message: "must be string"
3220
+ }
3221
+ ], !1;
3222
+ var a = m === o;
3223
+ } else
3224
+ var a = !0;
3225
+ if (a) {
3226
+ if (r.mode !== void 0) {
3227
+ let m = r.mode;
3228
+ const D = o;
3229
+ if (typeof m != "string")
3230
+ return validate11.errors = [
3231
+ {
3232
+ instancePath: e + "/mode",
3233
+ schemaPath: "#/properties/mode/type",
3234
+ keyword: "type",
3235
+ params: { type: "string" },
3236
+ message: "must be string"
3237
+ }
3238
+ ], !1;
3239
+ if (m !== "php-extension")
3240
+ return validate11.errors = [
3241
+ {
3242
+ instancePath: e + "/mode",
3243
+ schemaPath: "#/properties/mode/const",
3244
+ keyword: "const",
3245
+ params: {
3246
+ allowedValue: "php-extension"
3247
+ },
3248
+ message: "must be equal to constant"
3249
+ }
3250
+ ], !1;
3251
+ var a = D === o;
3252
+ } else
3253
+ var a = !0;
3254
+ if (a) {
3255
+ if (r.artifacts !== void 0) {
3256
+ let m = r.artifacts;
3257
+ const D = o;
3258
+ if (Array.isArray(m)) {
3259
+ var c = !0;
3260
+ const S = m.length;
3261
+ for (let g = 0; g < S; g++) {
3262
+ let b = m[g];
3263
+ const Q = o;
3264
+ if (b && typeof b == "object" && !Array.isArray(b)) {
3265
+ let F;
3266
+ if (b.phpVersion === void 0 && (F = "phpVersion") || b.sourcePath === void 0 && (F = "sourcePath"))
3267
+ return validate11.errors = [
3268
+ {
3269
+ instancePath: e + "/artifacts/" + g,
3270
+ schemaPath: "#/properties/artifacts/items/required",
3271
+ keyword: "required",
3272
+ params: {
3273
+ missingProperty: F
3274
+ },
3275
+ message: "must have required property '" + F + "'"
3276
+ }
3277
+ ], !1;
3278
+ for (const E in b)
3279
+ if (!(E === "phpVersion" || E === "sourcePath" || E === "extraFiles"))
3280
+ return validate11.errors = [
3281
+ {
3282
+ instancePath: e + "/artifacts/" + g,
3283
+ schemaPath: "#/properties/artifacts/items/additionalProperties",
3284
+ keyword: "additionalProperties",
3285
+ params: {
3286
+ additionalProperty: E
3287
+ },
3288
+ message: "must NOT have additional properties"
3289
+ }
3290
+ ], !1;
3291
+ {
3292
+ if (b.phpVersion !== void 0) {
3293
+ const E = o;
3294
+ if (typeof b.phpVersion != "string")
3295
+ return validate11.errors = [
3296
+ {
3297
+ instancePath: e + "/artifacts/" + g + "/phpVersion",
3298
+ schemaPath: "#/properties/artifacts/items/properties/phpVersion/type",
3299
+ keyword: "type",
3300
+ params: {
3301
+ type: "string"
3302
+ },
3303
+ message: "must be string"
3304
+ }
3305
+ ], !1;
3306
+ var l = E === o;
3307
+ } else
3308
+ var l = !0;
3309
+ if (l) {
3310
+ if (b.sourcePath !== void 0) {
3311
+ const E = o;
3312
+ if (typeof b.sourcePath != "string")
3313
+ return validate11.errors = [
3314
+ {
3315
+ instancePath: e + "/artifacts/" + g + "/sourcePath",
3316
+ schemaPath: "#/properties/artifacts/items/properties/sourcePath/type",
3317
+ keyword: "type",
3318
+ params: {
3319
+ type: "string"
3320
+ },
3321
+ message: "must be string"
3322
+ }
3323
+ ], !1;
3324
+ var l = E === o;
3325
+ } else
3326
+ var l = !0;
3327
+ if (l)
3328
+ if (b.extraFiles !== void 0) {
3329
+ let E = b.extraFiles;
3330
+ const Fe = o;
3331
+ if (E && typeof E == "object" && !Array.isArray(
3332
+ E
3333
+ )) {
3334
+ for (const w in E)
3335
+ if (!(w === "vfsRoot" || w === "nodes"))
3336
+ return validate11.errors = [
3337
+ {
3338
+ instancePath: e + "/artifacts/" + g + "/extraFiles",
3339
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/additionalProperties",
3340
+ keyword: "additionalProperties",
3341
+ params: {
3342
+ additionalProperty: w
3343
+ },
3344
+ message: "must NOT have additional properties"
3345
+ }
3346
+ ], !1;
3347
+ {
3348
+ if (E.vfsRoot !== void 0) {
3349
+ const w = o;
3350
+ if (typeof E.vfsRoot != "string")
3351
+ return validate11.errors = [
3352
+ {
3353
+ instancePath: e + "/artifacts/" + g + "/extraFiles/vfsRoot",
3354
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/vfsRoot/type",
3355
+ keyword: "type",
3356
+ params: {
3357
+ type: "string"
3358
+ },
3359
+ message: "must be string"
3360
+ }
3361
+ ], !1;
3362
+ var d = w === o;
3363
+ } else
3364
+ var d = !0;
3365
+ if (d)
3366
+ if (E.nodes !== void 0) {
3367
+ let w = E.nodes;
3368
+ const ie = o;
3369
+ if (Array.isArray(
3370
+ w
3371
+ )) {
3372
+ var p = !0;
3373
+ const ke = w.length;
3374
+ for (let C = 0; C < ke; C++) {
3375
+ let L = w[C];
3376
+ const Re = o;
3377
+ if (L && typeof L == "object" && !Array.isArray(
3378
+ L
3379
+ )) {
3380
+ let oe;
3381
+ if (L.vfsPath === void 0 && (oe = "vfsPath"))
3382
+ return validate11.errors = [
3383
+ {
3384
+ instancePath: e + "/artifacts/" + g + "/extraFiles/nodes/" + C,
3385
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/required",
3386
+ keyword: "required",
3387
+ params: {
3388
+ missingProperty: oe
3389
+ },
3390
+ message: "must have required property '" + oe + "'"
3391
+ }
3392
+ ], !1;
3393
+ for (const T in L)
3394
+ if (!(T === "vfsPath" || T === "type" || T === "sourcePath"))
3395
+ return validate11.errors = [
3396
+ {
3397
+ instancePath: e + "/artifacts/" + g + "/extraFiles/nodes/" + C,
3398
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/additionalProperties",
3399
+ keyword: "additionalProperties",
3400
+ params: {
3401
+ additionalProperty: T
3402
+ },
3403
+ message: "must NOT have additional properties"
3404
+ }
3405
+ ], !1;
3406
+ {
3407
+ if (L.vfsPath !== void 0) {
3408
+ const T = o;
3409
+ if (typeof L.vfsPath != "string")
3410
+ return validate11.errors = [
3411
+ {
3412
+ instancePath: e + "/artifacts/" + g + "/extraFiles/nodes/" + C + "/vfsPath",
3413
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/vfsPath/type",
3414
+ keyword: "type",
3415
+ params: {
3416
+ type: "string"
3417
+ },
3418
+ message: "must be string"
3419
+ }
3420
+ ], !1;
3421
+ var h = T === o;
3422
+ } else
3423
+ var h = !0;
3424
+ if (h) {
3425
+ if (L.type !== void 0) {
3426
+ let T = L.type;
3427
+ const be = o;
3428
+ if (typeof T != "string")
3429
+ return validate11.errors = [
3430
+ {
3431
+ instancePath: e + "/artifacts/" + g + "/extraFiles/nodes/" + C + "/type",
3432
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/type/type",
3433
+ keyword: "type",
3434
+ params: {
3435
+ type: "string"
3436
+ },
3437
+ message: "must be string"
3438
+ }
3439
+ ], !1;
3440
+ if (!(T === "file" || T === "directory"))
3441
+ return validate11.errors = [
3442
+ {
3443
+ instancePath: e + "/artifacts/" + g + "/extraFiles/nodes/" + C + "/type",
3444
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/type/enum",
3445
+ keyword: "enum",
3446
+ params: {
3447
+ allowedValues: schema13.properties.nodes.items.properties.type.enum
3448
+ },
3449
+ message: "must be equal to one of the allowed values"
3450
+ }
3451
+ ], !1;
3452
+ var h = be === o;
3453
+ } else
3454
+ var h = !0;
3455
+ if (h)
3456
+ if (L.sourcePath !== void 0) {
3457
+ const T = o;
3458
+ if (typeof L.sourcePath != "string")
3459
+ return validate11.errors = [
3460
+ {
3461
+ instancePath: e + "/artifacts/" + g + "/extraFiles/nodes/" + C + "/sourcePath",
3462
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/sourcePath/type",
3463
+ keyword: "type",
3464
+ params: {
3465
+ type: "string"
3466
+ },
3467
+ message: "must be string"
3468
+ }
3469
+ ], !1;
3470
+ var h = T === o;
3471
+ } else
3472
+ var h = !0;
3473
+ }
3474
+ }
3475
+ } else
3476
+ return validate11.errors = [
3477
+ {
3478
+ instancePath: e + "/artifacts/" + g + "/extraFiles/nodes/" + C,
3479
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/type",
3480
+ keyword: "type",
3481
+ params: {
3482
+ type: "object"
3483
+ },
3484
+ message: "must be object"
3485
+ }
3486
+ ], !1;
3487
+ var p = Re === o;
3488
+ if (!p)
3489
+ break;
3490
+ }
3491
+ } else
3492
+ return validate11.errors = [
3493
+ {
3494
+ instancePath: e + "/artifacts/" + g + "/extraFiles/nodes",
3495
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/type",
3496
+ keyword: "type",
3497
+ params: {
3498
+ type: "array"
3499
+ },
3500
+ message: "must be array"
3501
+ }
3502
+ ], !1;
3503
+ var d = ie === o;
3504
+ } else
3505
+ var d = !0;
3506
+ }
3507
+ } else
3508
+ return validate11.errors = [
3509
+ {
3510
+ instancePath: e + "/artifacts/" + g + "/extraFiles",
3511
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/type",
3512
+ keyword: "type",
3513
+ params: {
3514
+ type: "object"
3515
+ },
3516
+ message: "must be object"
3517
+ }
3518
+ ], !1;
3519
+ var l = Fe === o;
3520
+ } else
3521
+ var l = !0;
3522
+ }
3523
+ }
3524
+ } else
3525
+ return validate11.errors = [
3526
+ {
3527
+ instancePath: e + "/artifacts/" + g,
3528
+ schemaPath: "#/properties/artifacts/items/type",
3529
+ keyword: "type",
3530
+ params: {
3531
+ type: "object"
3532
+ },
3533
+ message: "must be object"
3534
+ }
3535
+ ], !1;
3536
+ var c = Q === o;
3537
+ if (!c)
3538
+ break;
3539
+ }
3540
+ } else
3541
+ return validate11.errors = [
3542
+ {
3543
+ instancePath: e + "/artifacts",
3544
+ schemaPath: "#/properties/artifacts/type",
3545
+ keyword: "type",
3546
+ params: { type: "array" },
3547
+ message: "must be array"
3548
+ }
3549
+ ], !1;
3550
+ var a = D === o;
3551
+ } else
3552
+ var a = !0;
3553
+ if (a)
3554
+ if (r.extraFiles !== void 0) {
3555
+ let m = r.extraFiles;
3556
+ const D = o;
3557
+ if (m && typeof m == "object" && !Array.isArray(m)) {
3558
+ for (const S in m)
3559
+ if (!(S === "vfsRoot" || S === "nodes"))
3560
+ return validate11.errors = [
3561
+ {
3562
+ instancePath: e + "/extraFiles",
3563
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/additionalProperties",
3564
+ keyword: "additionalProperties",
3565
+ params: {
3566
+ additionalProperty: S
3567
+ },
3568
+ message: "must NOT have additional properties"
3569
+ }
3570
+ ], !1;
3571
+ {
3572
+ if (m.vfsRoot !== void 0) {
3573
+ const S = o;
3574
+ if (typeof m.vfsRoot != "string")
3575
+ return validate11.errors = [
3576
+ {
3577
+ instancePath: e + "/extraFiles/vfsRoot",
3578
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/vfsRoot/type",
3579
+ keyword: "type",
3580
+ params: {
3581
+ type: "string"
3582
+ },
3583
+ message: "must be string"
3584
+ }
3585
+ ], !1;
3586
+ var f = S === o;
3587
+ } else
3588
+ var f = !0;
3589
+ if (f)
3590
+ if (m.nodes !== void 0) {
3591
+ let S = m.nodes;
3592
+ const g = o;
3593
+ if (Array.isArray(
3594
+ S
3595
+ )) {
3596
+ var k = !0;
3597
+ const Q = S.length;
3598
+ for (let I = 0; I < Q; I++) {
3599
+ let F = S[I];
3600
+ const E = o;
3601
+ if (F && typeof F == "object" && !Array.isArray(
3602
+ F
3603
+ )) {
3604
+ let ne;
3605
+ if (F.vfsPath === void 0 && (ne = "vfsPath"))
3606
+ return validate11.errors = [
3607
+ {
3608
+ instancePath: e + "/extraFiles/nodes/" + I,
3609
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/required",
3610
+ keyword: "required",
3611
+ params: {
3612
+ missingProperty: ne
3613
+ },
3614
+ message: "must have required property '" + ne + "'"
3615
+ }
3616
+ ], !1;
3617
+ for (const w in F)
3618
+ if (!(w === "vfsPath" || w === "type" || w === "sourcePath"))
3619
+ return validate11.errors = [
3620
+ {
3621
+ instancePath: e + "/extraFiles/nodes/" + I,
3622
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/additionalProperties",
3623
+ keyword: "additionalProperties",
3624
+ params: {
3625
+ additionalProperty: w
3626
+ },
3627
+ message: "must NOT have additional properties"
3628
+ }
3629
+ ], !1;
3630
+ {
3631
+ if (F.vfsPath !== void 0) {
3632
+ const w = o;
3633
+ if (typeof F.vfsPath != "string")
3634
+ return validate11.errors = [
3635
+ {
3636
+ instancePath: e + "/extraFiles/nodes/" + I + "/vfsPath",
3637
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/vfsPath/type",
3638
+ keyword: "type",
3639
+ params: {
3640
+ type: "string"
3641
+ },
3642
+ message: "must be string"
3643
+ }
3644
+ ], !1;
3645
+ var R = w === o;
3646
+ } else
3647
+ var R = !0;
3648
+ if (R) {
3649
+ if (F.type !== void 0) {
3650
+ let w = F.type;
3651
+ const ie = o;
3652
+ if (typeof w != "string")
3653
+ return validate11.errors = [
3654
+ {
3655
+ instancePath: e + "/extraFiles/nodes/" + I + "/type",
3656
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/type/type",
3657
+ keyword: "type",
3658
+ params: {
3659
+ type: "string"
3660
+ },
3661
+ message: "must be string"
3662
+ }
3663
+ ], !1;
3664
+ if (!(w === "file" || w === "directory"))
3665
+ return validate11.errors = [
3666
+ {
3667
+ instancePath: e + "/extraFiles/nodes/" + I + "/type",
3668
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/type/enum",
3669
+ keyword: "enum",
3670
+ params: {
3671
+ allowedValues: schema13.properties.nodes.items.properties.type.enum
3672
+ },
3673
+ message: "must be equal to one of the allowed values"
3674
+ }
3675
+ ], !1;
3676
+ var R = ie === o;
3677
+ } else
3678
+ var R = !0;
3679
+ if (R)
3680
+ if (F.sourcePath !== void 0) {
3681
+ const w = o;
3682
+ if (typeof F.sourcePath != "string")
3683
+ return validate11.errors = [
3684
+ {
3685
+ instancePath: e + "/extraFiles/nodes/" + I + "/sourcePath",
3686
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/properties/sourcePath/type",
3687
+ keyword: "type",
3688
+ params: {
3689
+ type: "string"
3690
+ },
3691
+ message: "must be string"
3692
+ }
3693
+ ], !1;
3694
+ var R = w === o;
3695
+ } else
3696
+ var R = !0;
3697
+ }
3698
+ }
3699
+ } else
3700
+ return validate11.errors = [
3701
+ {
3702
+ instancePath: e + "/extraFiles/nodes/" + I,
3703
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/items/type",
3704
+ keyword: "type",
3705
+ params: {
3706
+ type: "object"
3707
+ },
3708
+ message: "must be object"
3709
+ }
3710
+ ], !1;
3711
+ var k = E === o;
3712
+ if (!k)
3713
+ break;
3714
+ }
3715
+ } else
3716
+ return validate11.errors = [
3717
+ {
3718
+ instancePath: e + "/extraFiles/nodes",
3719
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/properties/nodes/type",
3720
+ keyword: "type",
3721
+ params: {
3722
+ type: "array"
3723
+ },
3724
+ message: "must be array"
3725
+ }
3726
+ ], !1;
3727
+ var f = g === o;
3728
+ } else
3729
+ var f = !0;
3730
+ }
3731
+ } else
3732
+ return validate11.errors = [
3733
+ {
3734
+ instancePath: e + "/extraFiles",
3735
+ schemaPath: "#/definitions/PHPExtensionManifestExtraFiles/type",
3736
+ keyword: "type",
3737
+ params: {
3738
+ type: "object"
3739
+ },
3740
+ message: "must be object"
3741
+ }
3742
+ ], !1;
3743
+ var a = D === o;
3744
+ } else
3745
+ var a = !0;
3746
+ }
3747
+ }
3748
+ }
3190
3749
  }
3191
- };
3192
- }
3193
- function buildResolvedPHPExtension(r) {
3194
- const e = r.extensionDir ?? PHP_EXTENSIONS_DIR, t = r.name;
3195
- if (!/^[a-zA-Z0-9_-]+$/.test(t))
3196
- throw new Error(
3197
- `Invalid PHP extension name ${JSON.stringify(
3198
- t
3199
- )}. Extension names are used to build VFS file names and ini paths, so they may only contain [a-zA-Z0-9_-].`
3200
- );
3201
- const s = r.loadWithIniDirective ?? "extension", n = joinPaths(e, `${t}.so`), i = joinPaths(e, `${t}.ini`), o = [
3202
- `${s}=${n}`,
3203
- ...Object.entries(r.iniEntries ?? {}).map(
3204
- ([c, l]) => `${c}=${l}`
3205
- )
3206
- ].join(`
3207
- `), a = r.extraFiles ? {
3208
- ...r.extraFiles,
3209
- targetPath: r.extraFiles.targetPath ?? joinPaths(e, `${t}-assets`)
3210
- } : void 0;
3211
- return {
3212
- soPath: n,
3213
- soBytes: toUint8Array(r.soBytes),
3214
- iniPath: i,
3215
- iniContent: o,
3216
- extraFiles: a,
3217
- env: r.env,
3218
- extensionDir: e
3219
- };
3750
+ } else
3751
+ return validate11.errors = [
3752
+ {
3753
+ instancePath: e,
3754
+ schemaPath: "#/type",
3755
+ keyword: "type",
3756
+ params: { type: "object" },
3757
+ message: "must be object"
3758
+ }
3759
+ ], !1;
3760
+ return validate11.errors = i, o === 0;
3220
3761
  }
3221
- function installPHPExtensionFilesSync(r, e) {
3222
- const t = "soPath" in e ? e : buildResolvedPHPExtension(e);
3223
- return FSHelpers.fileExists(r, t.extensionDir) || r.mkdirTree(t.extensionDir), r.writeFile(t.soPath, t.soBytes), r.writeFile(t.iniPath, t.iniContent), t.extraFiles && writeFileTreeSync(
3224
- r,
3225
- t.extraFiles.targetPath,
3226
- t.extraFiles.files
3227
- ), t;
3762
+ function validate10(r, { instancePath: e = "", parentData: t, parentDataProperty: s, rootData: n = r } = {}) {
3763
+ let i = null, o = 0;
3764
+ return validate11(r, {
3765
+ instancePath: e,
3766
+ parentData: t,
3767
+ parentDataProperty: s,
3768
+ rootData: n
3769
+ }) || (i = i === null ? validate11.errors : i.concat(validate11.errors), o = i.length), validate10.errors = i, o === 0;
3228
3770
  }
3229
- async function resolvePHPExtensionSource(r, e) {
3230
- const t = r.source;
3771
+ const PHP_EXTENSIONS_DIR = "/internal/shared/extensions", MAX_EXTENSION_SIDECAR_FILE_REQUESTS = 5;
3772
+ async function resolvePHPExtension(r) {
3773
+ const e = r.fetch ?? globalThis.fetch, t = r.source;
3774
+ let s = r.name, n;
3775
+ const i = {}, o = [];
3231
3776
  if (t.format === "so") {
3232
- const h = r.name ?? t.name;
3233
- if (!h)
3777
+ if (s || (s = t.name), !s)
3234
3778
  throw new Error(
3235
3779
  "name is required when loading an extension from direct bytes."
3236
3780
  );
3237
- return t.sha256 && await assertSha256(t.bytes, t.sha256, h), { name: h, soBytes: toUint8Array(t.bytes) };
3238
- }
3239
- if (t.format === "url") {
3781
+ n = toUint8Array(t.bytes);
3782
+ } else if (t.format === "url") {
3240
3783
  let h;
3241
3784
  try {
3242
3785
  h = new URL(String(t.url));
@@ -3247,101 +3790,140 @@ async function resolvePHPExtensionSource(r, e) {
3247
3790
  )}`
3248
3791
  );
3249
3792
  }
3250
- const p = r.name ?? t.name ?? (() => {
3251
- const N = h.pathname.split("/").pop() ?? "";
3252
- return N.endsWith(".so") ? N.slice(0, -3) : void 0;
3253
- })();
3254
- if (!p)
3793
+ if (s || (s = t.name), !s && h.pathname.endsWith(".so") && (s = basename(h.pathname).slice(0, -3)), !s)
3255
3794
  throw new Error(
3256
3795
  "name is required when loading an extension from a direct URL."
3257
3796
  );
3258
- if (!e)
3259
- throw new Error(
3260
- "resolvePHPExtension() requires a fetch implementation."
3261
- );
3262
- const g = await e(h);
3263
- if (!g.ok)
3264
- throw new Error(
3265
- `Failed to fetch ${String(h)}: ${g.status}`
3266
- );
3267
- const S = new Uint8Array(await g.arrayBuffer());
3268
- return t.sha256 && await assertSha256(S, t.sha256, String(h)), { name: p, soBytes: S };
3269
- }
3270
- const s = "manifestUrl" in t ? new URL(String(t.manifestUrl)) : void 0;
3271
- let n;
3272
- if ("manifest" in t)
3273
- n = t.manifest;
3274
- else {
3275
- if (!e)
3797
+ n = await fetchBytes(e, h);
3798
+ } else {
3799
+ let h, f;
3800
+ if ("manifest" in t ? (h = t.manifest, t.baseUrl && (f = new URL(String(t.baseUrl)))) : (f = new URL(String(t.manifestUrl)), h = await (await e(f)).json()), !validate10(h))
3276
3801
  throw new Error(
3277
- "resolvePHPExtension() requires a fetch implementation."
3802
+ `Invalid PHP extension manifest: ${JSON.stringify(
3803
+ validate10.errors
3804
+ )}`
3278
3805
  );
3279
- const h = await e(s);
3280
- if (!h.ok)
3806
+ const k = h;
3807
+ if (!f)
3281
3808
  throw new Error(
3282
- `Failed to fetch ${String(s)}: ${h.status}`
3809
+ "Manifest artifacts require a manifest URL or baseUrl so relative files can be resolved."
3283
3810
  );
3284
- n = await h.json();
3285
- }
3286
- if (!n || typeof n != "object")
3287
- throw new Error("Extension manifest must be an object.");
3288
- const i = n;
3289
- if (typeof i.name != "string" || !i.name)
3290
- throw new Error("Extension manifest must include a name.");
3291
- if (!Array.isArray(i.artifacts))
3292
- throw new Error("Extension manifest must include an artifacts array.");
3293
- for (const h of i.artifacts) {
3294
- if (!h || typeof h.phpVersion != "string" || typeof h.file != "string")
3295
- throw new Error("Extension manifest contains an invalid artifact.");
3296
- if ("asyncMode" in h)
3811
+ const R = k.artifacts.find(
3812
+ (V) => V.phpVersion === r.phpVersion
3813
+ );
3814
+ if (!R)
3297
3815
  throw new Error(
3298
- "Extension manifests do not use asyncMode. External PHP extensions require JSPI."
3816
+ `No extension artifact found for PHP ${r.phpVersion}.`
3299
3817
  );
3300
- }
3301
- const o = "baseUrl" in t && t.baseUrl ? new URL(String(t.baseUrl)) : s, a = i.artifacts.find(
3302
- (h) => h.phpVersion === r.phpVersion
3818
+ s ?? (s = k.name);
3819
+ const N = new Semaphore({
3820
+ concurrency: MAX_EXTENSION_SIDECAR_FILE_REQUESTS
3821
+ }), m = [];
3822
+ for (const V of [k.extraFiles, R.extraFiles])
3823
+ for (const S of (V == null ? void 0 : V.nodes) ?? []) {
3824
+ const g = joinPaths(V.vfsRoot ?? "", S.vfsPath);
3825
+ if (S.type === "directory") {
3826
+ o.push(g);
3827
+ continue;
3828
+ }
3829
+ if (!S.sourcePath) continue;
3830
+ const b = new URL(S.sourcePath, f);
3831
+ m.push(
3832
+ N.run(() => fetchBytes(e, b)).then((Q) => {
3833
+ i[g] = Q;
3834
+ })
3835
+ );
3836
+ }
3837
+ const [D] = await Promise.all([
3838
+ fetchBytes(e, new URL(R.sourcePath, f)),
3839
+ ...m
3840
+ ]);
3841
+ n = D;
3842
+ }
3843
+ const a = normalizePath(
3844
+ r.extensionDir ?? PHP_EXTENSIONS_DIR
3303
3845
  );
3304
- if (!a)
3305
- throw new Error(
3306
- `No extension artifact found for PHP ${r.phpVersion}.`
3307
- );
3308
- if (!o)
3309
- throw new Error(
3310
- "Manifest artifacts require a manifest URL or baseUrl so relative files can be resolved."
3311
- );
3312
- const c = new URL(a.file, o);
3313
- if (!e)
3314
- throw new Error(
3315
- "resolvePHPExtension() requires a fetch implementation."
3316
- );
3317
- const l = await e(c);
3318
- if (!l.ok)
3319
- throw new Error(
3320
- `Failed to fetch ${String(c)}: ${l.status}`
3321
- );
3322
- const u = new Uint8Array(await l.arrayBuffer());
3323
- return a.sha256 && await assertSha256(u, a.sha256, a.file), {
3324
- name: i.name,
3325
- soBytes: u
3846
+ r.extraFiles && (Object.assign(i, r.extraFiles.files), o.push(...r.extraFiles.directories ?? []));
3847
+ const c = r.loadWithIniDirective ?? "extension", l = joinPaths(a, `${s}.so`), d = joinPaths(a, `${s}.ini`), p = [
3848
+ `${c}=${l}`,
3849
+ ...Object.entries(r.iniEntries ?? {}).map(
3850
+ ([h, f]) => `${h}=${f}`
3851
+ )
3852
+ ].join(`
3853
+ `);
3854
+ return {
3855
+ soPath: l,
3856
+ soBytes: n,
3857
+ iniPath: d,
3858
+ iniContent: p,
3859
+ extraFiles: {
3860
+ files: i,
3861
+ directories: o
3862
+ },
3863
+ env: r.env,
3864
+ extensionDir: a
3326
3865
  };
3327
3866
  }
3328
- function writeFileTreeSync(r, e, t) {
3329
- FSHelpers.fileExists(r, e) || r.mkdirTree(e);
3330
- for (const [s, n] of Object.entries(t)) {
3331
- const i = joinPaths(e, s), o = dirname(i);
3332
- FSHelpers.fileExists(r, o) || r.mkdirTree(o), n instanceof Uint8Array || typeof n == "string" ? r.writeFile(i, n) : writeFileTreeSync(r, i, n);
3867
+ function withResolvedPHPExtensions(r, e) {
3868
+ var s;
3869
+ if (!e.length)
3870
+ return r;
3871
+ const t = { ...r.ENV };
3872
+ for (const n of e) {
3873
+ Object.assign(t, n.env);
3874
+ const i = ((s = t.PHP_INI_SCAN_DIR) == null ? void 0 : s.split(":")) ?? [];
3875
+ i.includes(n.extensionDir) || (i.push(n.extensionDir), t.PHP_INI_SCAN_DIR = i.join(":"));
3333
3876
  }
3877
+ return {
3878
+ ...r,
3879
+ ENV: t,
3880
+ onRuntimeInitialized: (n) => {
3881
+ var i;
3882
+ (i = r.onRuntimeInitialized) == null || i.call(r, n);
3883
+ for (const o of e)
3884
+ installPHPExtensionFilesSync(n.FS, o);
3885
+ }
3886
+ };
3334
3887
  }
3335
- async function assertSha256(r, e, t) {
3336
- var o;
3337
- const s = (o = globalThis.crypto) == null ? void 0 : o.subtle;
3338
- if (!s)
3339
- throw new Error(
3340
- `Cannot verify ${t}: crypto.subtle is not available.`
3341
- );
3342
- const n = await s.digest("SHA-256", toUint8Array(r));
3343
- if (Array.from(new Uint8Array(n)).map((a) => a.toString(16).padStart(2, "0")).join("") !== e)
3344
- throw new Error(`SHA-256 mismatch for ${t}.`);
3888
+ function installPHPExtensionFilesSync(r, e) {
3889
+ let t;
3890
+ if ("soPath" in e)
3891
+ t = e;
3892
+ else {
3893
+ const s = e.extensionDir ?? PHP_EXTENSIONS_DIR, n = e.loadWithIniDirective ?? "extension", i = joinPaths(s, `${e.name}.so`);
3894
+ t = {
3895
+ soPath: i,
3896
+ soBytes: toUint8Array(e.soBytes),
3897
+ iniPath: joinPaths(s, `${e.name}.ini`),
3898
+ iniContent: [
3899
+ `${n}=${i}`,
3900
+ ...Object.entries(e.iniEntries ?? {}).map(
3901
+ ([o, a]) => `${o}=${a}`
3902
+ )
3903
+ ].join(`
3904
+ `),
3905
+ extraFiles: e.extraFiles,
3906
+ env: e.env,
3907
+ extensionDir: s
3908
+ };
3909
+ }
3910
+ if (mkdirIfMissing(r, t.extensionDir), r.writeFile(t.soPath, t.soBytes), r.writeFile(t.iniPath, t.iniContent), t.extraFiles) {
3911
+ const { directories: s = [], files: n } = t.extraFiles;
3912
+ for (const i of s)
3913
+ mkdirIfMissing(r, i);
3914
+ for (const [i, o] of Object.entries(n))
3915
+ mkdirIfMissing(r, dirname(i)), r.writeFile(i, o);
3916
+ }
3917
+ return t;
3918
+ }
3919
+ function mkdirIfMissing(r, e) {
3920
+ FSHelpers.fileExists(r, e) || r.mkdirTree(e);
3921
+ }
3922
+ async function fetchBytes(r, e) {
3923
+ const t = await r(e);
3924
+ if (!t.ok)
3925
+ throw new Error(`Failed to fetch ${String(e)}: ${t.status}`);
3926
+ return new Uint8Array(await t.arrayBuffer());
3345
3927
  }
3346
3928
  function toUint8Array(r) {
3347
3929
  return r instanceof Uint8Array ? r : new Uint8Array(r);
@@ -3358,25 +3940,25 @@ function ensureProxyFSHasMmapSupport(r) {
3358
3940
  throw new n.ErrnoError(19);
3359
3941
  if (a !== 0)
3360
3942
  throw new n.ErrnoError(22);
3361
- const u = t.malloc(o);
3362
- if (!u)
3943
+ const d = t.malloc(o);
3944
+ if (!d)
3363
3945
  throw new n.ErrnoError(48);
3364
- const h = t.HEAPU8.subarray(u, u + o);
3365
- let p = 0;
3366
- for (; p < o; ) {
3367
- const g = i.stream_ops.read(
3946
+ const p = t.HEAPU8.subarray(d, d + o);
3947
+ let h = 0;
3948
+ for (; h < o; ) {
3949
+ const f = i.stream_ops.read(
3368
3950
  i,
3369
- h,
3370
3951
  p,
3371
- o - p,
3372
- p
3952
+ h,
3953
+ o - h,
3954
+ h
3373
3955
  );
3374
- if (g <= 0) break;
3375
- p += g;
3956
+ if (f <= 0) break;
3957
+ h += f;
3376
3958
  }
3377
- if (p !== o)
3378
- throw t.free(u), new n.ErrnoError(5);
3379
- return { ptr: u, allocated: !0 };
3959
+ if (h !== o)
3960
+ throw t.free(d), new n.ErrnoError(5);
3961
+ return { ptr: d, allocated: !0 };
3380
3962
  }, s.stream_ops.msync = function(i, o, a, c, l) {
3381
3963
  return l & 2 || i.stream_ops.write(
3382
3964
  i,
@@ -3584,10 +4166,10 @@ class NodeSABSyncReceiveMessageTransport {
3584
4166
  ), Atomics.wait(i, 0, 0, 5e3) === "timed-out")
3585
4167
  throw new Error("Timeout waiting for response");
3586
4168
  for (; ; ) {
3587
- const u = NodeSABSyncReceiveMessageTransport.receiveMessageOnPort(e);
3588
- if (((l = u.message) == null ? void 0 : l.id) === o)
3589
- return u.message;
3590
- if (!u)
4169
+ const d = NodeSABSyncReceiveMessageTransport.receiveMessageOnPort(e);
4170
+ if (((l = d.message) == null ? void 0 : l.id) === o)
4171
+ return d.message;
4172
+ if (!d)
3591
4173
  throw new Error("No response received");
3592
4174
  }
3593
4175
  }
@@ -3665,51 +4247,51 @@ function expose(r, e = globalThis, t = ["*"], s) {
3665
4247
  path: [],
3666
4248
  ...i.data
3667
4249
  }, l = (i.data.argumentList || []).map(fromWireValue);
3668
- let u;
4250
+ let d;
3669
4251
  try {
3670
- const h = c.slice(0, -1).reduce((g, S) => g[S], r), p = c.reduce((g, S) => g[S], r);
4252
+ const p = c.slice(0, -1).reduce((f, k) => f[k], r), h = c.reduce((f, k) => f[k], r);
3671
4253
  switch (a) {
3672
4254
  case MessageType.GET:
3673
- u = p;
4255
+ d = h;
3674
4256
  break;
3675
4257
  case MessageType.SET:
3676
- h[c.slice(-1)[0]] = fromWireValue(
4258
+ p[c.slice(-1)[0]] = fromWireValue(
3677
4259
  i.data.value
3678
- ), u = !0;
4260
+ ), d = !0;
3679
4261
  break;
3680
4262
  case MessageType.APPLY:
3681
- u = p.apply(h, l);
4263
+ d = h.apply(p, l);
3682
4264
  break;
3683
4265
  case MessageType.CONSTRUCT:
3684
4266
  {
3685
- const g = new p(...l);
3686
- u = proxy(g);
4267
+ const f = new h(...l);
4268
+ d = proxy(f);
3687
4269
  }
3688
4270
  break;
3689
4271
  case MessageType.ENDPOINT:
3690
4272
  {
3691
- const { port1: g, port2: S } = new MessageChannel();
3692
- expose(r, S), u = transfer(g, [g]);
4273
+ const { port1: f, port2: k } = new MessageChannel();
4274
+ expose(r, k), d = transfer(f, [f]);
3693
4275
  }
3694
4276
  break;
3695
4277
  case MessageType.RELEASE:
3696
- u = void 0;
4278
+ d = void 0;
3697
4279
  break;
3698
4280
  default:
3699
4281
  return;
3700
4282
  }
3701
- } catch (h) {
3702
- u = { value: h, [throwMarker]: 0 };
4283
+ } catch (p) {
4284
+ d = { value: p, [throwMarker]: 0 };
3703
4285
  }
3704
- Promise.resolve(u).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
3705
- const [p, g] = toWireValue(h);
3706
- e.postMessage({ ...p, id: o }, g), a === MessageType.RELEASE && (e.removeEventListener("message", n), closeEndPoint(e), finalizer in r && typeof r[finalizer] == "function" && r[finalizer]());
4286
+ Promise.resolve(d).catch((p) => ({ value: p, [throwMarker]: 0 })).then((p) => {
4287
+ const [h, f] = toWireValue(p);
4288
+ e.postMessage({ ...h, id: o }, f), a === MessageType.RELEASE && (e.removeEventListener("message", n), closeEndPoint(e), finalizer in r && typeof r[finalizer] == "function" && r[finalizer]());
3707
4289
  }).catch(() => {
3708
- const [h, p] = toWireValue({
4290
+ const [p, h] = toWireValue({
3709
4291
  value: new TypeError("Unserializable return value"),
3710
4292
  [throwMarker]: 0
3711
4293
  });
3712
- e.postMessage({ ...h, id: o }, p);
4294
+ e.postMessage({ ...p, id: o }, h);
3713
4295
  }).finally(() => {
3714
4296
  s == null || s(i);
3715
4297
  });
@@ -3780,16 +4362,16 @@ function createProxy(r, e, t = [], s = function() {
3780
4362
  },
3781
4363
  set(o, a, c) {
3782
4364
  throwIfProxyReleased(n);
3783
- const [l, u] = toWireValue(c);
4365
+ const [l, d] = toWireValue(c);
3784
4366
  return requestResponseMessage(
3785
4367
  r,
3786
4368
  e,
3787
4369
  {
3788
4370
  type: MessageType.SET,
3789
- path: [...t, a].map((h) => h.toString()),
4371
+ path: [...t, a].map((p) => p.toString()),
3790
4372
  value: l
3791
4373
  },
3792
- u
4374
+ d
3793
4375
  ).then(fromWireValue);
3794
4376
  },
3795
4377
  apply(o, a, c) {
@@ -3801,16 +4383,16 @@ function createProxy(r, e, t = [], s = function() {
3801
4383
  }).then(fromWireValue);
3802
4384
  if (l === "bind")
3803
4385
  return createProxy(r, e, t.slice(0, -1));
3804
- const [u, h] = processArguments(c);
4386
+ const [d, p] = processArguments(c);
3805
4387
  return requestResponseMessage(
3806
4388
  r,
3807
4389
  e,
3808
4390
  {
3809
4391
  type: MessageType.APPLY,
3810
- path: t.map((p) => p.toString()),
3811
- argumentList: u
4392
+ path: t.map((h) => h.toString()),
4393
+ argumentList: d
3812
4394
  },
3813
- h
4395
+ p
3814
4396
  ).then(fromWireValue);
3815
4397
  },
3816
4398
  construct(o, a) {
@@ -3821,7 +4403,7 @@ function createProxy(r, e, t = [], s = function() {
3821
4403
  e,
3822
4404
  {
3823
4405
  type: MessageType.CONSTRUCT,
3824
- path: t.map((u) => u.toString()),
4406
+ path: t.map((d) => d.toString()),
3825
4407
  argumentList: c
3826
4408
  },
3827
4409
  l
@@ -4021,19 +4603,19 @@ const errorProperties = [
4021
4603
  useToJSON: o,
4022
4604
  serialize: a
4023
4605
  });
4024
- for (const [l, u] of Object.entries(r)) {
4025
- if (u && u instanceof Uint8Array && u.constructor.name === "Buffer") {
4606
+ for (const [l, d] of Object.entries(r)) {
4607
+ if (d && d instanceof Uint8Array && d.constructor.name === "Buffer") {
4026
4608
  t[l] = "[object Buffer]";
4027
4609
  continue;
4028
4610
  }
4029
- if (u !== null && typeof u == "object" && typeof u.pipe == "function") {
4611
+ if (d !== null && typeof d == "object" && typeof d.pipe == "function") {
4030
4612
  t[l] = "[object Stream]";
4031
4613
  continue;
4032
4614
  }
4033
- if (typeof u != "function") {
4034
- if (!u || typeof u != "object") {
4615
+ if (typeof d != "function") {
4616
+ if (!d || typeof d != "object") {
4035
4617
  try {
4036
- t[l] = u;
4618
+ t[l] = d;
4037
4619
  } catch {
4038
4620
  }
4039
4621
  continue;
@@ -4046,10 +4628,10 @@ const errorProperties = [
4046
4628
  }
4047
4629
  }
4048
4630
  if (a || t instanceof Error)
4049
- for (const { property: l, enumerable: u } of errorProperties)
4631
+ for (const { property: l, enumerable: d } of errorProperties)
4050
4632
  r[l] !== void 0 && r[l] !== null && Object.defineProperty(t, l, {
4051
4633
  value: isErrorLike(r[l]) || Array.isArray(r[l]) ? c(r[l]) : r[l],
4052
- enumerable: s ? !0 : u,
4634
+ enumerable: s ? !0 : d,
4053
4635
  configurable: !0,
4054
4636
  writable: !0
4055
4637
  });
@@ -4994,23 +5576,23 @@ function createObjectPoolProxy(r) {
4994
5576
  }
4995
5577
  function i(o) {
4996
5578
  return s().then((a) => {
4997
- const c = (u) => {
4998
- const h = u == null ? void 0 : u.finished;
4999
- return h && typeof h.then == "function" ? Promise.resolve(h).then(
5579
+ const c = (d) => {
5580
+ const p = d == null ? void 0 : d.finished;
5581
+ return p && typeof p.then == "function" ? Promise.resolve(p).then(
5000
5582
  () => n(a),
5001
5583
  () => n(a)
5002
- ) : n(a), u;
5584
+ ) : n(a), d;
5003
5585
  };
5004
5586
  let l;
5005
5587
  try {
5006
5588
  l = o(a);
5007
- } catch (u) {
5008
- throw n(a), u;
5589
+ } catch (d) {
5590
+ throw n(a), d;
5009
5591
  }
5010
5592
  return l != null && typeof l.then == "function" ? l.then(
5011
- (u) => c(u),
5012
- (u) => {
5013
- throw n(a), u;
5593
+ (d) => c(d),
5594
+ (d) => {
5595
+ throw n(a), d;
5014
5596
  }
5015
5597
  ) : c(l);
5016
5598
  });
@@ -5022,14 +5604,14 @@ function createObjectPoolProxy(r) {
5022
5604
  if (a !== "then")
5023
5605
  return new Proxy(function() {
5024
5606
  }, {
5025
- apply(c, l, u) {
5026
- return i((h) => h[a](...u));
5607
+ apply(c, l, d) {
5608
+ return i((p) => p[a](...d));
5027
5609
  },
5028
5610
  get(c, l) {
5029
5611
  if (l === "then")
5030
- return (u, h) => i((p) => p[a]).then(
5031
- u,
5032
- h
5612
+ return (d, p) => i((h) => h[a]).then(
5613
+ d,
5614
+ p
5033
5615
  );
5034
5616
  }
5035
5617
  });