@php-wasm/universal 0.9.13 → 0.9.14

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.
Files changed (3) hide show
  1. package/index.cjs +10 -12
  2. package/index.js +313 -425
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -1,13 +1,14 @@
1
- var Y = (t, e, r) => {
1
+ var V = (t, e, r) => {
2
2
  if (!e.has(t))
3
3
  throw TypeError("Cannot " + r);
4
4
  };
5
- var u = (t, e, r) => (Y(t, e, "read from private field"), r ? r.call(t) : e.get(t)), p = (t, e, r) => {
5
+ var u = (t, e, r) => (V(t, e, "read from private field"), r ? r.call(t) : e.get(t)), p = (t, e, r) => {
6
6
  if (e.has(t))
7
7
  throw TypeError("Cannot add the same private member more than once");
8
8
  e instanceof WeakSet ? e.add(t) : e.set(t, r);
9
- }, f = (t, e, r, s) => (Y(t, e, "write to private field"), s ? s.call(t, r) : e.set(t, r), r);
10
- var h = (t, e, r) => (Y(t, e, "access private method"), r);
9
+ }, h = (t, e, r, s) => (V(t, e, "write to private field"), s ? s.call(t, r) : e.set(t, r), r);
10
+ var d = (t, e, r) => (V(t, e, "access private method"), r);
11
+ import { parse, stringify } from "/home/runner/work/wordpress-playground/wordpress-playground/node_modules/ini/lib/ini.js";
11
12
  const currentJsRuntime$1 = function() {
12
13
  var t;
13
14
  return typeof process < "u" && ((t = process.release) == null ? void 0 : t.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
@@ -18,25 +19,25 @@ const currentJsRuntime$1 = function() {
18
19
  }();
19
20
  if (currentJsRuntime$1 === "NODE") {
20
21
  let t = function(r) {
21
- return new Promise(function(s, n) {
22
- r.onload = r.onerror = function(i) {
23
- r.onload = r.onerror = null, i.type === "load" ? s(r.result) : n(new Error("Failed to read the blob/file"));
22
+ return new Promise(function(s, i) {
23
+ r.onload = r.onerror = function(n) {
24
+ r.onload = r.onerror = null, n.type === "load" ? s(r.result) : i(new Error("Failed to read the blob/file"));
24
25
  };
25
26
  });
26
27
  }, e = function() {
27
- const r = new Uint8Array([1, 2, 3, 4]), n = new File([r], "test").stream();
28
+ const r = new Uint8Array([1, 2, 3, 4]), i = new File([r], "test").stream();
28
29
  try {
29
- return n.getReader({ mode: "byob" }), !0;
30
+ return i.getReader({ mode: "byob" }), !0;
30
31
  } catch {
31
32
  return !1;
32
33
  }
33
34
  };
34
35
  if (typeof File > "u") {
35
36
  class r extends Blob {
36
- constructor(n, i, o) {
37
- super(n);
38
- let l;
39
- o != null && o.lastModified && (l = /* @__PURE__ */ new Date()), (!l || isNaN(l.getFullYear())) && (l = /* @__PURE__ */ new Date()), this.lastModifiedDate = l, this.lastModified = l.getMilliseconds(), this.name = i || "";
37
+ constructor(i, n, o) {
38
+ super(i);
39
+ let a;
40
+ o != null && o.lastModified && (a = /* @__PURE__ */ new Date()), (!a || isNaN(a.getFullYear())) && (a = /* @__PURE__ */ new Date()), this.lastModifiedDate = a, this.lastModified = a.getMilliseconds(), this.name = n || "";
40
41
  }
41
42
  }
42
43
  global.File = r;
@@ -55,14 +56,14 @@ if (currentJsRuntime$1 === "NODE") {
55
56
  // 0.5 MB seems like a reasonable chunk size, let's adjust
56
57
  // this if needed.
57
58
  autoAllocateChunkSize: 512 * 1024,
58
- async pull(n) {
59
- const i = n.byobRequest.view, l = await s.slice(
59
+ async pull(i) {
60
+ const n = i.byobRequest.view, a = await s.slice(
60
61
  r,
61
- r + i.byteLength
62
- ).arrayBuffer(), c = new Uint8Array(l);
63
- new Uint8Array(i.buffer).set(c);
64
- const a = c.byteLength;
65
- n.byobRequest.respond(a), r += a, r >= s.size && n.close();
62
+ r + n.byteLength
63
+ ).arrayBuffer(), l = new Uint8Array(a);
64
+ new Uint8Array(n.buffer).set(l);
65
+ const c = l.byteLength;
66
+ i.byobRequest.respond(c), r += c, r >= s.size && i.close();
66
67
  }
67
68
  });
68
69
  });
@@ -162,20 +163,20 @@ function getEmscriptenFsError(t) {
162
163
  return FileErrorCodes[e];
163
164
  }
164
165
  function rethrowFileSystemError(t = "") {
165
- return function(r, s, n) {
166
- const i = n.value;
167
- n.value = function(...o) {
166
+ return function(r, s, i) {
167
+ const n = i.value;
168
+ i.value = function(...o) {
168
169
  try {
169
- return i.apply(this, o);
170
- } catch (l) {
171
- const c = typeof l == "object" ? l == null ? void 0 : l.errno : null;
172
- if (c in FileErrorCodes) {
173
- const a = FileErrorCodes[c], d = typeof o[1] == "string" ? o[1] : null, m = d !== null ? t.replaceAll("{path}", d) : t;
174
- throw new Error(`${m}: ${a}`, {
175
- cause: l
170
+ return n.apply(this, o);
171
+ } catch (a) {
172
+ const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
173
+ if (l in FileErrorCodes) {
174
+ const c = FileErrorCodes[l], P = typeof o[1] == "string" ? o[1] : null, de = P !== null ? t.replaceAll("{path}", P) : t;
175
+ throw new Error(`${de}: ${c}`, {
176
+ cause: a
176
177
  });
177
178
  }
178
- throw l;
179
+ throw a;
179
180
  }
180
181
  };
181
182
  };
@@ -344,19 +345,19 @@ const getDefaultHandlers = () => {
344
345
  }
345
346
  return [logToMemory, logToConsole, logEvent];
346
347
  }, logger = new Logger(getDefaultHandlers()), prepareLogMessage = (t) => t.replace(/\t/g, ""), formatLogEntry = (t, e, r) => {
347
- const s = /* @__PURE__ */ new Date(), n = new Intl.DateTimeFormat("en-GB", {
348
+ const s = /* @__PURE__ */ new Date(), i = new Intl.DateTimeFormat("en-GB", {
348
349
  year: "numeric",
349
350
  month: "short",
350
351
  day: "2-digit",
351
352
  timeZone: "UTC"
352
- }).format(s).replace(/ /g, "-"), i = new Intl.DateTimeFormat("en-GB", {
353
+ }).format(s).replace(/ /g, "-"), n = new Intl.DateTimeFormat("en-GB", {
353
354
  hour: "2-digit",
354
355
  minute: "2-digit",
355
356
  second: "2-digit",
356
357
  hour12: !1,
357
358
  timeZone: "UTC",
358
359
  timeZoneName: "short"
359
- }).format(s), o = n + " " + i;
360
+ }).format(s), o = i + " " + n;
360
361
  return t = prepareLogMessage(t), `[${o}] ${r} ${e}: ${t}`;
361
362
  }, SleepFinished = Symbol("SleepFinished");
362
363
  function sleep(t) {
@@ -430,8 +431,8 @@ function normalizePath(t) {
430
431
  function normalizePathsArray(t, e) {
431
432
  let r = 0;
432
433
  for (let s = t.length - 1; s >= 0; s--) {
433
- const n = t[s];
434
- n === "." ? t.splice(s, 1) : n === ".." ? (t.splice(s, 1), r++) : r && (t.splice(s, 1), r--);
434
+ const i = t[s];
435
+ i === "." ? t.splice(s, 1) : i === ".." ? (t.splice(s, 1), r++) : r && (t.splice(s, 1), r--);
435
436
  }
436
437
  if (e)
437
438
  for (; r; r--)
@@ -439,18 +440,18 @@ function normalizePathsArray(t, e) {
439
440
  return t;
440
441
  }
441
442
  function splitShellCommand(t) {
442
- let s = 0, n = "";
443
- const i = [];
443
+ let s = 0, i = "";
444
+ const n = [];
444
445
  let o = "";
445
- for (let l = 0; l < t.length; l++) {
446
- const c = t[l];
447
- c === "\\" ? ((t[l + 1] === '"' || t[l + 1] === "'") && l++, o += t[l]) : s === 0 ? c === '"' || c === "'" ? (s = 1, n = c) : c.match(/\s/) ? (o.trim().length && i.push(o.trim()), o = c) : i.length && !o ? o = i.pop() + c : o += c : s === 1 && (c === n ? (s = 0, n = "") : o += c);
446
+ for (let a = 0; a < t.length; a++) {
447
+ const l = t[a];
448
+ l === "\\" ? ((t[a + 1] === '"' || t[a + 1] === "'") && a++, o += t[a]) : s === 0 ? l === '"' || l === "'" ? (s = 1, i = l) : l.match(/\s/) ? (o.trim().length && n.push(o.trim()), o = l) : n.length && !o ? o = n.pop() + l : o += l : s === 1 && (l === i ? (s = 0, i = "") : o += l);
448
449
  }
449
- return o && i.push(o.trim()), i;
450
+ return o && n.push(o.trim()), n;
450
451
  }
451
452
  function createSpawnHandler(t) {
452
453
  return function(e, r = [], s = {}) {
453
- const n = new ChildProcess(), i = new ProcessApi(n);
454
+ const i = new ChildProcess(), n = new ProcessApi(i);
454
455
  return setTimeout(async () => {
455
456
  let o = [];
456
457
  if (r.length)
@@ -462,12 +463,12 @@ function createSpawnHandler(t) {
462
463
  else
463
464
  throw new Error("Invalid command ", e);
464
465
  try {
465
- await t(o, i, s);
466
- } catch (l) {
467
- n.emit("error", l), typeof l == "object" && l !== null && "message" in l && typeof l.message == "string" && i.stderr(l.message), i.exit(1);
466
+ await t(o, n, s);
467
+ } catch (a) {
468
+ i.emit("error", a), typeof a == "object" && a !== null && "message" in a && typeof a.message == "string" && n.stderr(a.message), n.exit(1);
468
469
  }
469
- n.emit("spawn", !0);
470
- }), n;
470
+ i.emit("spawn", !0);
471
+ }), i;
471
472
  };
472
473
  }
473
474
  class EventEmitter {
@@ -524,13 +525,13 @@ class ChildProcess extends EventEmitter {
524
525
  }
525
526
  }
526
527
  var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = (t, e, r, s) => {
527
- for (var n = s > 1 ? void 0 : s ? __getOwnPropDesc(e, r) : e, i = t.length - 1, o; i >= 0; i--)
528
- (o = t[i]) && (n = (s ? o(e, r, n) : o(n)) || n);
529
- return s && n && __defProp(e, r, n), n;
528
+ for (var i = s > 1 ? void 0 : s ? __getOwnPropDesc(e, r) : e, n = t.length - 1, o; n >= 0; n--)
529
+ (o = t[n]) && (i = (s ? o(e, r, i) : o(i)) || i);
530
+ return s && i && __defProp(e, r, i), i;
530
531
  };
531
- const _FSHelpers = class g {
532
+ const _FSHelpers = class f {
532
533
  static readFileAsText(e, r) {
533
- return new TextDecoder().decode(g.readFileAsBuffer(e, r));
534
+ return new TextDecoder().decode(f.readFileAsBuffer(e, r));
534
535
  }
535
536
  static readFileAsBuffer(e, r) {
536
537
  return e.readFile(r);
@@ -550,42 +551,42 @@ const _FSHelpers = class g {
550
551
  */
551
552
  static mv(e, r, s) {
552
553
  try {
553
- const n = e.lookupPath(r).node.mount, i = g.fileExists(e, s) ? e.lookupPath(s).node.mount : e.lookupPath(dirname(s)).node.mount;
554
- n.mountpoint !== i.mountpoint ? (g.copyRecursive(e, r, s), g.rmdir(e, r, { recursive: !0 })) : e.rename(r, s);
555
- } catch (n) {
556
- const i = getEmscriptenFsError(n);
557
- throw i ? new Error(
558
- `Could not move ${r} to ${s}: ${i}`,
554
+ const i = e.lookupPath(r).node.mount, n = f.fileExists(e, s) ? e.lookupPath(s).node.mount : e.lookupPath(dirname(s)).node.mount;
555
+ i.mountpoint !== n.mountpoint ? (f.copyRecursive(e, r, s), f.rmdir(e, r, { recursive: !0 })) : e.rename(r, s);
556
+ } catch (i) {
557
+ const n = getEmscriptenFsError(i);
558
+ throw n ? new Error(
559
+ `Could not move ${r} to ${s}: ${n}`,
559
560
  {
560
- cause: n
561
+ cause: i
561
562
  }
562
- ) : n;
563
+ ) : i;
563
564
  }
564
565
  }
565
566
  static rmdir(e, r, s = { recursive: !0 }) {
566
- s != null && s.recursive && g.listFiles(e, r).forEach((n) => {
567
- const i = `${r}/${n}`;
568
- g.isDir(e, i) ? g.rmdir(e, i, s) : g.unlink(e, i);
567
+ s != null && s.recursive && f.listFiles(e, r).forEach((i) => {
568
+ const n = `${r}/${i}`;
569
+ f.isDir(e, n) ? f.rmdir(e, n, s) : f.unlink(e, n);
569
570
  }), e.rmdir(r);
570
571
  }
571
572
  static listFiles(e, r, s = { prependPath: !1 }) {
572
- if (!g.fileExists(e, r))
573
+ if (!f.fileExists(e, r))
573
574
  return [];
574
575
  try {
575
- const n = e.readdir(r).filter(
576
- (i) => i !== "." && i !== ".."
576
+ const i = e.readdir(r).filter(
577
+ (n) => n !== "." && n !== ".."
577
578
  );
578
579
  if (s.prependPath) {
579
- const i = r.replace(/\/$/, "");
580
- return n.map((o) => `${i}/${o}`);
580
+ const n = r.replace(/\/$/, "");
581
+ return i.map((o) => `${n}/${o}`);
581
582
  }
582
- return n;
583
- } catch (n) {
584
- return logger.error(n, { path: r }), [];
583
+ return i;
584
+ } catch (i) {
585
+ return logger.error(i, { path: r }), [];
585
586
  }
586
587
  }
587
588
  static isDir(e, r) {
588
- return g.fileExists(e, r) ? e.isDir(e.lookupPath(r).node.mode) : !1;
589
+ return f.fileExists(e, r) ? e.isDir(e.lookupPath(r).node.mode) : !1;
589
590
  }
590
591
  static fileExists(e, r) {
591
592
  try {
@@ -598,14 +599,14 @@ const _FSHelpers = class g {
598
599
  e.mkdirTree(r);
599
600
  }
600
601
  static copyRecursive(e, r, s) {
601
- const n = e.lookupPath(r).node;
602
- if (e.isDir(n.mode)) {
602
+ const i = e.lookupPath(r).node;
603
+ if (e.isDir(i.mode)) {
603
604
  e.mkdirTree(s);
604
- const i = e.readdir(r).filter(
605
+ const n = e.readdir(r).filter(
605
606
  (o) => o !== "." && o !== ".."
606
607
  );
607
- for (const o of i)
608
- g.copyRecursive(
608
+ for (const o of n)
609
+ f.copyRecursive(
609
610
  e,
610
611
  joinPaths(r, o),
611
612
  joinPaths(s, o)
@@ -788,8 +789,8 @@ const responseTexts = {
788
789
  200: "OK"
789
790
  };
790
791
  class PHPResponse {
791
- constructor(e, r, s, n = "", i = 0) {
792
- this.httpStatusCode = e, this.headers = r, this.bytes = s, this.exitCode = i, this.errors = n;
792
+ constructor(e, r, s, i = "", n = 0) {
793
+ this.httpStatusCode = e, this.headers = r, this.bytes = s, this.exitCode = n, this.errors = i;
793
794
  }
794
795
  static forHttpCode(e, r = "") {
795
796
  return new PHPResponse(
@@ -834,15 +835,15 @@ class PHPResponse {
834
835
  const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map();
835
836
  let lastRuntimeId = 0;
836
837
  async function loadPHPRuntime(t, e = {}) {
837
- const [r, s, n] = makePromise(), i = t.init(currentJsRuntime, {
838
- onAbort(l) {
839
- n(l), logger.error(l);
838
+ const [r, s, i] = makePromise(), n = t.init(currentJsRuntime, {
839
+ onAbort(a) {
840
+ i(a), logger.error(a);
840
841
  },
841
842
  ENV: {},
842
843
  // Emscripten sometimes prepends a '/' to the path, which
843
844
  // breaks vite dev mode. An identity `locateFile` function
844
845
  // fixes it.
845
- locateFile: (l) => l,
846
+ locateFile: (a) => a,
846
847
  ...e,
847
848
  noInitialRun: !0,
848
849
  onRuntimeInitialized() {
@@ -851,9 +852,9 @@ async function loadPHPRuntime(t, e = {}) {
851
852
  });
852
853
  await r;
853
854
  const o = ++lastRuntimeId;
854
- return i.id = o, i.originalExit = i._exit, i._exit = function(l) {
855
- return loadedRuntimes.delete(o), i.originalExit(l);
856
- }, i[RuntimeId] = o, loadedRuntimes.set(o, i), o;
855
+ return n.id = o, n.originalExit = n._exit, n._exit = function(a) {
856
+ return loadedRuntimes.delete(o), n.originalExit(a);
857
+ }, n[RuntimeId] = o, loadedRuntimes.set(o, n), o;
857
858
  }
858
859
  function getLoadedRuntime(t) {
859
860
  return loadedRuntimes.get(t);
@@ -910,27 +911,27 @@ function improveWASMErrorReporting(t) {
910
911
  for (const r in t.wasmExports)
911
912
  if (typeof t.wasmExports[r] == "function") {
912
913
  const s = t.wasmExports[r];
913
- t.wasmExports[r] = function(...n) {
914
- var i;
914
+ t.wasmExports[r] = function(...i) {
915
+ var n;
915
916
  try {
916
- return s(...n);
917
+ return s(...i);
917
918
  } catch (o) {
918
919
  if (!(o instanceof Error))
919
920
  throw o;
920
- const l = clarifyErrorMessage(
921
+ const a = clarifyErrorMessage(
921
922
  o,
922
- (i = t.lastAsyncifyStackSource) == null ? void 0 : i.stack
923
+ (n = t.lastAsyncifyStackSource) == null ? void 0 : n.stack
923
924
  );
924
925
  if (t.lastAsyncifyStackSource && (o.cause = t.lastAsyncifyStackSource), e.hasListeners()) {
925
926
  e.dispatchEvent(
926
927
  new ErrorEvent("error", {
927
928
  error: o,
928
- message: l
929
+ message: a
929
930
  })
930
931
  );
931
932
  return;
932
933
  }
933
- throw isExitCodeZero(o) || showCriticalErrorBox(l), o;
934
+ throw isExitCodeZero(o) || showCriticalErrorBox(a), o;
934
935
  }
935
936
  };
936
937
  }
@@ -1019,7 +1020,7 @@ class PHPExecutionFailureError extends Error {
1019
1020
  }
1020
1021
  }
1021
1022
  const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php";
1022
- var S, E, x, v, R, M, ee, N, te, U, re, O, se, L, ne, D, ie, j, oe, $, ae, B, le, q, ce, I, K, z, ue, W, pe, G, de;
1023
+ var E, y, w, g, x, k, Q, A, Z, I, Y, C, K, M, X, N, ee, U, te, L, re, D, se, B, ie, H, J, q, ne, j, oe, O, ae;
1023
1024
  class PHP {
1024
1025
  /**
1025
1026
  * Initializes a PHP runtime.
@@ -1038,26 +1039,26 @@ class PHP {
1038
1039
  * was provided.
1039
1040
  * @returns Computed $_SERVER entries.
1040
1041
  */
1042
+ p(this, k);
1043
+ p(this, A);
1044
+ p(this, I);
1045
+ p(this, C);
1041
1046
  p(this, M);
1042
1047
  p(this, N);
1043
1048
  p(this, U);
1044
- p(this, O);
1045
1049
  p(this, L);
1046
1050
  p(this, D);
1047
- p(this, j);
1048
- p(this, $);
1049
1051
  p(this, B);
1052
+ p(this, H);
1050
1053
  p(this, q);
1051
- p(this, I);
1052
- p(this, z);
1053
- p(this, W);
1054
- p(this, G);
1055
- p(this, S, void 0);
1054
+ p(this, j);
1055
+ p(this, O);
1056
1056
  p(this, E, void 0);
1057
+ p(this, y, void 0);
1058
+ p(this, w, void 0);
1059
+ p(this, g, void 0);
1057
1060
  p(this, x, void 0);
1058
- p(this, v, void 0);
1059
- p(this, R, void 0);
1060
- f(this, E, !1), f(this, x, null), f(this, v, /* @__PURE__ */ new Map()), f(this, R, []), this.semaphore = new Semaphore({ concurrency: 1 }), t !== void 0 && this.initializeRuntime(t);
1061
+ h(this, y, !1), h(this, w, null), h(this, g, /* @__PURE__ */ new Map()), h(this, x, []), this.semaphore = new Semaphore({ concurrency: 1 }), t !== void 0 && this.initializeRuntime(t);
1061
1062
  }
1062
1063
  /**
1063
1064
  * Adds an event listener for a PHP event.
@@ -1065,7 +1066,7 @@ class PHP {
1065
1066
  * @param listener - The listener function to be called when the event is triggered.
1066
1067
  */
1067
1068
  addEventListener(t, e) {
1068
- u(this, v).has(t) || u(this, v).set(t, /* @__PURE__ */ new Set()), u(this, v).get(t).add(e);
1069
+ u(this, g).has(t) || u(this, g).set(t, /* @__PURE__ */ new Set()), u(this, g).get(t).add(e);
1069
1070
  }
1070
1071
  /**
1071
1072
  * Removes an event listener for a PHP event.
@@ -1074,10 +1075,10 @@ class PHP {
1074
1075
  */
1075
1076
  removeEventListener(t, e) {
1076
1077
  var r;
1077
- (r = u(this, v).get(t)) == null || r.delete(e);
1078
+ (r = u(this, g).get(t)) == null || r.delete(e);
1078
1079
  }
1079
1080
  dispatchEvent(t) {
1080
- const e = u(this, v).get(t.type);
1081
+ const e = u(this, g).get(t.type);
1081
1082
  if (e)
1082
1083
  for (const r of e)
1083
1084
  r(t);
@@ -1122,7 +1123,7 @@ class PHP {
1122
1123
  * @param listener Callback function to handle the message.
1123
1124
  */
1124
1125
  onMessage(t) {
1125
- u(this, R).push(t);
1126
+ u(this, x).push(t);
1126
1127
  }
1127
1128
  async setSpawnHandler(handler) {
1128
1129
  typeof handler == "string" && (handler = createSpawnHandler(eval(handler))), this[__private__dont__use].spawnProcess = handler;
@@ -1196,13 +1197,13 @@ class PHP {
1196
1197
  }
1197
1198
  `
1198
1199
  ), e.onMessage = async (r) => {
1199
- for (const s of u(this, R)) {
1200
- const n = await s(r);
1201
- if (n)
1202
- return n;
1200
+ for (const s of u(this, x)) {
1201
+ const i = await s(r);
1202
+ if (i)
1203
+ return i;
1203
1204
  }
1204
1205
  return "";
1205
- }, f(this, x, improveWASMErrorReporting(e)), this.dispatchEvent({
1206
+ }, h(this, w, improveWASMErrorReporting(e)), this.dispatchEvent({
1206
1207
  type: "runtime.initialized"
1207
1208
  });
1208
1209
  }
@@ -1217,7 +1218,7 @@ class PHP {
1217
1218
  throw new Error(
1218
1219
  "Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
1219
1220
  );
1220
- f(this, S, t);
1221
+ h(this, E, t);
1221
1222
  }
1222
1223
  /**
1223
1224
  * Changes the current working directory in the PHP filesystem.
@@ -1314,30 +1315,30 @@ class PHP {
1314
1315
  const e = await this.semaphore.acquire();
1315
1316
  let r;
1316
1317
  try {
1317
- if (u(this, E) || (h(this, N, te).call(this), f(this, E, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
1318
+ if (u(this, y) || (d(this, A, Z).call(this), h(this, y, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
1318
1319
  throw new Error(
1319
1320
  `The script path "${t.scriptPath}" does not exist.`
1320
1321
  );
1321
- h(this, O, se).call(this, t.relativeUri || ""), h(this, $, ae).call(this, t.method || "GET");
1322
- const s = normalizeHeaders(t.headers || {}), n = s.host || "example.com:443", i = h(this, j, oe).call(this, n, t.protocol || "http");
1323
- h(this, L, ne).call(this, n), h(this, D, ie).call(this, i), h(this, B, le).call(this, s), t.body && (r = h(this, q, ce).call(this, t.body)), typeof t.code == "string" ? (this.writeFile("/internal/eval.php", t.code), h(this, I, K).call(this, "/internal/eval.php")) : h(this, I, K).call(this, t.scriptPath || "");
1324
- const o = h(this, M, ee).call(this, t.$_SERVER, s, i);
1325
- for (const a in o)
1326
- h(this, z, ue).call(this, a, o[a]);
1327
- const l = t.env || {};
1328
- for (const a in l)
1329
- h(this, W, pe).call(this, a, l[a]);
1330
- const c = await h(this, G, de).call(this);
1331
- if (c.exitCode !== 0) {
1332
- logger.warn("PHP.run() output was:", c.text);
1333
- const a = new PHPExecutionFailureError(
1334
- `PHP.run() failed with exit code ${c.exitCode} and the following output: ` + c.errors,
1335
- c,
1322
+ d(this, C, K).call(this, t.relativeUri || ""), d(this, L, re).call(this, t.method || "GET");
1323
+ const s = normalizeHeaders(t.headers || {}), i = s.host || "example.com:443", n = d(this, U, te).call(this, i, t.protocol || "http");
1324
+ d(this, M, X).call(this, i), d(this, N, ee).call(this, n), d(this, D, se).call(this, s), t.body && (r = d(this, B, ie).call(this, t.body)), typeof t.code == "string" ? (this.writeFile("/internal/eval.php", t.code), d(this, H, J).call(this, "/internal/eval.php")) : d(this, H, J).call(this, t.scriptPath || "");
1325
+ const o = d(this, k, Q).call(this, t.$_SERVER, s, n);
1326
+ for (const c in o)
1327
+ d(this, q, ne).call(this, c, o[c]);
1328
+ const a = t.env || {};
1329
+ for (const c in a)
1330
+ d(this, j, oe).call(this, c, a[c]);
1331
+ const l = await d(this, O, ae).call(this);
1332
+ if (l.exitCode !== 0) {
1333
+ logger.warn("PHP.run() output was:", l.text);
1334
+ const c = new PHPExecutionFailureError(
1335
+ `PHP.run() failed with exit code ${l.exitCode} and the following output: ` + l.errors,
1336
+ l,
1336
1337
  "request"
1337
1338
  );
1338
- throw logger.error(a), a;
1339
+ throw logger.error(c), c;
1339
1340
  }
1340
- return c;
1341
+ return l;
1341
1342
  } catch (s) {
1342
1343
  throw this.dispatchEvent({
1343
1344
  type: "request.error",
@@ -1498,7 +1499,7 @@ class PHP {
1498
1499
  this.exit();
1499
1500
  } catch {
1500
1501
  }
1501
- this.initializeRuntime(t), u(this, S) && this.setSapiName(u(this, S)), e && copyFS(r, this[__private__dont__use].FS, e);
1502
+ this.initializeRuntime(t), u(this, E) && this.setSapiName(u(this, E)), e && copyFS(r, this[__private__dont__use].FS, e);
1502
1503
  }
1503
1504
  /**
1504
1505
  * Mounts a filesystem to a given path in the PHP filesystem.
@@ -1567,25 +1568,25 @@ class PHP {
1567
1568
  this[__private__dont__use]._exit(t);
1568
1569
  } catch {
1569
1570
  }
1570
- f(this, E, !1), f(this, x, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
1571
+ h(this, y, !1), h(this, w, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
1571
1572
  }
1572
1573
  [Symbol.dispose]() {
1573
- u(this, E) && this.exit(0);
1574
+ u(this, y) && this.exit(0);
1574
1575
  }
1575
1576
  }
1576
- S = new WeakMap(), E = new WeakMap(), x = new WeakMap(), v = new WeakMap(), R = new WeakMap(), M = new WeakSet(), ee = function(t, e, r) {
1577
+ E = new WeakMap(), y = new WeakMap(), w = new WeakMap(), g = new WeakMap(), x = new WeakMap(), k = new WeakSet(), Q = function(t, e, r) {
1577
1578
  const s = {
1578
1579
  ...t || {}
1579
1580
  };
1580
1581
  s.HTTPS = s.HTTPS || r === 443 ? "on" : "off";
1581
- for (const n in e) {
1582
- let i = "HTTP_";
1583
- ["content-type", "content-length"].includes(n.toLowerCase()) && (i = ""), s[`${i}${n.toUpperCase().replace(/-/g, "_")}`] = e[n];
1582
+ for (const i in e) {
1583
+ let n = "HTTP_";
1584
+ ["content-type", "content-length"].includes(i.toLowerCase()) && (n = ""), s[`${n}${i.toUpperCase().replace(/-/g, "_")}`] = e[i];
1584
1585
  }
1585
1586
  return s;
1586
- }, N = new WeakSet(), te = function() {
1587
+ }, A = new WeakSet(), Z = function() {
1587
1588
  this[__private__dont__use].ccall("php_wasm_init", null, [], []);
1588
- }, U = new WeakSet(), re = function() {
1589
+ }, I = new WeakSet(), Y = function() {
1589
1590
  const t = "/internal/headers.json";
1590
1591
  if (!this.fileExists(t))
1591
1592
  throw new Error(
@@ -1595,14 +1596,14 @@ S = new WeakMap(), E = new WeakMap(), x = new WeakMap(), v = new WeakMap(), R =
1595
1596
  for (const s of e.headers) {
1596
1597
  if (!s.includes(": "))
1597
1598
  continue;
1598
- const n = s.indexOf(": "), i = s.substring(0, n).toLowerCase(), o = s.substring(n + 2);
1599
- i in r || (r[i] = []), r[i].push(o);
1599
+ const i = s.indexOf(": "), n = s.substring(0, i).toLowerCase(), o = s.substring(i + 2);
1600
+ n in r || (r[n] = []), r[n].push(o);
1600
1601
  }
1601
1602
  return {
1602
1603
  headers: r,
1603
1604
  httpStatusCode: e.status
1604
1605
  };
1605
- }, O = new WeakSet(), se = function(t) {
1606
+ }, C = new WeakSet(), K = function(t) {
1606
1607
  if (this[__private__dont__use].ccall(
1607
1608
  "wasm_set_request_uri",
1608
1609
  null,
@@ -1617,35 +1618,35 @@ S = new WeakMap(), E = new WeakMap(), x = new WeakMap(), v = new WeakMap(), R =
1617
1618
  [e]
1618
1619
  );
1619
1620
  }
1620
- }, L = new WeakSet(), ne = function(t) {
1621
+ }, M = new WeakSet(), X = function(t) {
1621
1622
  this[__private__dont__use].ccall(
1622
1623
  "wasm_set_request_host",
1623
1624
  null,
1624
1625
  [STRING],
1625
1626
  [t]
1626
1627
  );
1627
- }, D = new WeakSet(), ie = function(t) {
1628
+ }, N = new WeakSet(), ee = function(t) {
1628
1629
  this[__private__dont__use].ccall(
1629
1630
  "wasm_set_request_port",
1630
1631
  null,
1631
1632
  [NUMBER],
1632
1633
  [t]
1633
1634
  );
1634
- }, j = new WeakSet(), oe = function(t, e) {
1635
+ }, U = new WeakSet(), te = function(t, e) {
1635
1636
  let r;
1636
1637
  try {
1637
1638
  r = parseInt(new URL(t).port, 10);
1638
1639
  } catch {
1639
1640
  }
1640
1641
  return (!r || isNaN(r) || r === 80) && (r = e === "https" ? 443 : 80), r;
1641
- }, $ = new WeakSet(), ae = function(t) {
1642
+ }, L = new WeakSet(), re = function(t) {
1642
1643
  this[__private__dont__use].ccall(
1643
1644
  "wasm_set_request_method",
1644
1645
  null,
1645
1646
  [STRING],
1646
1647
  [t]
1647
1648
  );
1648
- }, B = new WeakSet(), le = function(t) {
1649
+ }, D = new WeakSet(), se = function(t) {
1649
1650
  t.cookie && this[__private__dont__use].ccall(
1650
1651
  "wasm_set_cookies",
1651
1652
  null,
@@ -1662,7 +1663,7 @@ S = new WeakMap(), E = new WeakMap(), x = new WeakMap(), v = new WeakMap(), R =
1662
1663
  [NUMBER],
1663
1664
  [parseInt(t["content-length"], 10)]
1664
1665
  );
1665
- }, q = new WeakSet(), ce = function(t) {
1666
+ }, B = new WeakSet(), ie = function(t) {
1666
1667
  let e, r;
1667
1668
  typeof t == "string" ? (logger.warn(
1668
1669
  "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"
@@ -1685,64 +1686,64 @@ S = new WeakMap(), E = new WeakMap(), x = new WeakMap(), v = new WeakMap(), R =
1685
1686
  [NUMBER],
1686
1687
  [r]
1687
1688
  ), s;
1688
- }, I = new WeakSet(), K = function(t) {
1689
+ }, H = new WeakSet(), J = function(t) {
1689
1690
  this[__private__dont__use].ccall(
1690
1691
  "wasm_set_path_translated",
1691
1692
  null,
1692
1693
  [STRING],
1693
1694
  [t]
1694
1695
  );
1695
- }, z = new WeakSet(), ue = function(t, e) {
1696
+ }, q = new WeakSet(), ne = function(t, e) {
1696
1697
  this[__private__dont__use].ccall(
1697
1698
  "wasm_add_SERVER_entry",
1698
1699
  null,
1699
1700
  [STRING, STRING],
1700
1701
  [t, e]
1701
1702
  );
1702
- }, W = new WeakSet(), pe = function(t, e) {
1703
+ }, j = new WeakSet(), oe = function(t, e) {
1703
1704
  this[__private__dont__use].ccall(
1704
1705
  "wasm_add_ENV_entry",
1705
1706
  null,
1706
1707
  [STRING, STRING],
1707
1708
  [t, e]
1708
1709
  );
1709
- }, G = new WeakSet(), de = async function() {
1710
- var n;
1710
+ }, O = new WeakSet(), ae = async function() {
1711
+ var i;
1711
1712
  let t, e;
1712
1713
  try {
1713
- t = await new Promise((i, o) => {
1714
- var c;
1715
- e = (a) => {
1716
- logger.error(a), logger.error(a.error);
1717
- const d = new Error("Rethrown");
1718
- d.cause = a.error, d.betterMessage = a.message, o(d);
1719
- }, (c = u(this, x)) == null || c.addEventListener(
1714
+ t = await new Promise((n, o) => {
1715
+ var l;
1716
+ e = (c) => {
1717
+ logger.error(c), logger.error(c.error);
1718
+ const P = new Error("Rethrown");
1719
+ P.cause = c.error, P.betterMessage = c.message, o(P);
1720
+ }, (l = u(this, w)) == null || l.addEventListener(
1720
1721
  "error",
1721
1722
  e
1722
1723
  );
1723
- const l = this[__private__dont__use].ccall(
1724
+ const a = this[__private__dont__use].ccall(
1724
1725
  "wasm_sapi_handle_request",
1725
1726
  NUMBER,
1726
1727
  [],
1727
1728
  [],
1728
1729
  { async: !0 }
1729
1730
  );
1730
- return l instanceof Promise ? l.then(i, o) : i(l);
1731
+ return a instanceof Promise ? a.then(n, o) : n(a);
1731
1732
  });
1732
- } catch (i) {
1733
- for (const a in this)
1734
- typeof this[a] == "function" && (this[a] = () => {
1733
+ } catch (n) {
1734
+ for (const c in this)
1735
+ typeof this[c] == "function" && (this[c] = () => {
1735
1736
  throw new Error(
1736
1737
  "PHP runtime has crashed – see the earlier error for details."
1737
1738
  );
1738
1739
  });
1739
1740
  this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
1740
- const o = i, l = "betterMessage" in o ? o.betterMessage : o.message, c = new Error(l);
1741
- throw c.cause = o, logger.error(c), c;
1741
+ const o = n, a = "betterMessage" in o ? o.betterMessage : o.message, l = new Error(a);
1742
+ throw l.cause = o, logger.error(l), l;
1742
1743
  } finally {
1743
- (n = u(this, x)) == null || n.removeEventListener("error", e);
1744
+ (i = u(this, w)) == null || i.removeEventListener("error", e);
1744
1745
  }
1745
- const { headers: r, httpStatusCode: s } = h(this, U, re).call(this);
1746
+ const { headers: r, httpStatusCode: s } = d(this, I, Y).call(this);
1746
1747
  return new PHPResponse(
1747
1748
  t === 0 ? s : 500,
1748
1749
  r,
@@ -1771,137 +1772,24 @@ function copyFS(t, e, r) {
1771
1772
  return;
1772
1773
  }
1773
1774
  e.mkdirTree(r);
1774
- const n = t.readdir(r).filter((i) => i !== "." && i !== "..");
1775
- for (const i of n)
1776
- copyFS(t, e, joinPaths(r, i));
1775
+ const i = t.readdir(r).filter((n) => n !== "." && n !== "..");
1776
+ for (const n of i)
1777
+ copyFS(t, e, joinPaths(r, n));
1777
1778
  }
1778
- const { hasOwnProperty } = Object.prototype, encode = (t, e = {}) => {
1779
- typeof e == "string" && (e = { section: e }), e.align = e.align === !0, e.newline = e.newline === !0, e.sort = e.sort === !0, e.whitespace = e.whitespace === !0 || e.align === !0, e.platform = e.platform || typeof process < "u" && process.platform, e.bracketedArray = e.bracketedArray !== !1;
1780
- const r = e.platform === "win32" ? `\r
1781
- ` : `
1782
- `, s = e.whitespace ? " = " : "=", n = [], i = e.sort ? Object.keys(t).sort() : Object.keys(t);
1783
- let o = 0;
1784
- e.align && (o = safe(
1785
- i.filter((a) => t[a] === null || Array.isArray(t[a]) || typeof t[a] != "object").map((a) => Array.isArray(t[a]) ? `${a}[]` : a).concat([""]).reduce((a, d) => safe(a).length >= safe(d).length ? a : d)
1786
- ).length);
1787
- let l = "";
1788
- const c = e.bracketedArray ? "[]" : "";
1789
- for (const a of i) {
1790
- const d = t[a];
1791
- if (d && Array.isArray(d))
1792
- for (const m of d)
1793
- l += safe(`${a}${c}`).padEnd(o, " ") + s + safe(m) + r;
1794
- else
1795
- d && typeof d == "object" ? n.push(a) : l += safe(a).padEnd(o, " ") + s + safe(d) + r;
1796
- }
1797
- e.section && l.length && (l = "[" + safe(e.section) + "]" + (e.newline ? r + r : r) + l);
1798
- for (const a of n) {
1799
- const d = splitSections(a, ".").join("\\."), m = (e.section ? e.section + "." : "") + d, y = encode(t[a], {
1800
- ...e,
1801
- section: m
1802
- });
1803
- l.length && y.length && (l += r), l += y;
1804
- }
1805
- return l;
1806
- };
1807
- function splitSections(t, e) {
1808
- var r = 0, s = 0, n = 0, i = [];
1809
- do
1810
- if (n = t.indexOf(e, r), n !== -1) {
1811
- if (r = n + e.length, n > 0 && t[n - 1] === "\\")
1812
- continue;
1813
- i.push(t.slice(s, n)), s = n + e.length;
1814
- }
1815
- while (n !== -1);
1816
- return i.push(t.slice(s)), i;
1817
- }
1818
- const decode = (t, e = {}) => {
1819
- e.bracketedArray = e.bracketedArray !== !1;
1820
- const r = /* @__PURE__ */ Object.create(null);
1821
- let s = r, n = null;
1822
- const i = /^\[([^\]]*)\]\s*$|^([^=]+)(=(.*))?$/i, o = t.split(/[\r\n]+/g), l = {};
1823
- for (const a of o) {
1824
- if (!a || a.match(/^\s*[;#]/) || a.match(/^\s*$/))
1825
- continue;
1826
- const d = a.match(i);
1827
- if (!d)
1828
- continue;
1829
- if (d[1] !== void 0) {
1830
- if (n = unsafe(d[1]), n === "__proto__") {
1831
- s = /* @__PURE__ */ Object.create(null);
1832
- continue;
1833
- }
1834
- s = r[n] = r[n] || /* @__PURE__ */ Object.create(null);
1835
- continue;
1836
- }
1837
- const m = unsafe(d[2]);
1838
- let y;
1839
- e.bracketedArray ? y = m.length > 2 && m.slice(-2) === "[]" : (l[m] = ((l == null ? void 0 : l[m]) || 0) + 1, y = l[m] > 1);
1840
- const _ = y ? m.slice(0, -2) : m;
1841
- if (_ === "__proto__")
1842
- continue;
1843
- const A = d[3] ? unsafe(d[4]) : !0, X = A === "true" || A === "false" || A === "null" ? JSON.parse(A) : A;
1844
- y && (hasOwnProperty.call(s, _) ? Array.isArray(s[_]) || (s[_] = [s[_]]) : s[_] = []), Array.isArray(s[_]) ? s[_].push(X) : s[_] = X;
1845
- }
1846
- const c = [];
1847
- for (const a of Object.keys(r)) {
1848
- if (!hasOwnProperty.call(r, a) || typeof r[a] != "object" || Array.isArray(r[a]))
1849
- continue;
1850
- const d = splitSections(a, ".");
1851
- s = r;
1852
- const m = d.pop(), y = m.replace(/\\\./g, ".");
1853
- for (const _ of d)
1854
- _ !== "__proto__" && ((!hasOwnProperty.call(s, _) || typeof s[_] != "object") && (s[_] = /* @__PURE__ */ Object.create(null)), s = s[_]);
1855
- s === r && y === m || (s[y] = r[a], c.push(a));
1856
- }
1857
- for (const a of c)
1858
- delete r[a];
1859
- return r;
1860
- }, isQuoted = (t) => t.startsWith('"') && t.endsWith('"') || t.startsWith("'") && t.endsWith("'"), safe = (t) => typeof t != "string" || t.match(/[=\r\n]/) || t.match(/^\[/) || t.length > 1 && isQuoted(t) || t !== t.trim() ? JSON.stringify(t) : t.split(";").join("\\;").split("#").join("\\#"), unsafe = (t) => {
1861
- if (t = (t || "").trim(), isQuoted(t)) {
1862
- t.charAt(0) === "'" && (t = t.slice(1, -1));
1863
- try {
1864
- t = JSON.parse(t);
1865
- } catch {
1866
- }
1867
- } else {
1868
- let e = !1, r = "";
1869
- for (let s = 0, n = t.length; s < n; s++) {
1870
- const i = t.charAt(s);
1871
- if (e)
1872
- "\\;#".indexOf(i) !== -1 ? r += i : r += "\\" + i, e = !1;
1873
- else {
1874
- if (";#".indexOf(i) !== -1)
1875
- break;
1876
- i === "\\" ? e = !0 : r += i;
1877
- }
1878
- }
1879
- return e && (r += "\\"), r.trim();
1880
- }
1881
- return t;
1882
- };
1883
- var ini = {
1884
- parse: decode,
1885
- decode,
1886
- stringify: encode,
1887
- encode,
1888
- safe,
1889
- unsafe
1890
- };
1891
1779
  async function getPhpIniEntries(t, e) {
1892
- const r = ini.parse(await t.readFileAsText(PHP_INI_PATH));
1780
+ const r = parse(await t.readFileAsText(PHP_INI_PATH));
1893
1781
  if (e === void 0)
1894
1782
  return r;
1895
1783
  const s = {};
1896
- for (const n of e)
1897
- s[n] = r[n];
1784
+ for (const i of e)
1785
+ s[i] = r[i];
1898
1786
  return s;
1899
1787
  }
1900
1788
  async function setPhpIniEntries(t, e) {
1901
- const r = ini.parse(await t.readFileAsText(PHP_INI_PATH));
1902
- for (const [s, n] of Object.entries(e))
1903
- n == null ? delete r[s] : r[s] = n;
1904
- await t.writeFile(PHP_INI_PATH, ini.stringify(r));
1789
+ const r = parse(await t.readFileAsText(PHP_INI_PATH));
1790
+ for (const [s, i] of Object.entries(e))
1791
+ i == null ? delete r[s] : r[s] = i;
1792
+ await t.writeFile(PHP_INI_PATH, stringify(r));
1905
1793
  }
1906
1794
  async function withPHPIniValues(t, e, r) {
1907
1795
  const s = await t.readFileAsText(PHP_INI_PATH);
@@ -1921,8 +1809,8 @@ class HttpCookieStore {
1921
1809
  try {
1922
1810
  if (!r.includes("="))
1923
1811
  continue;
1924
- const s = r.indexOf("="), n = r.substring(0, s), i = r.substring(s + 1).split(";")[0];
1925
- this.cookies[n] = i;
1812
+ const s = r.indexOf("="), i = r.substring(0, s), n = r.substring(s + 1).split(";")[0];
1813
+ this.cookies[i] = n;
1926
1814
  } catch (s) {
1927
1815
  logger.error(s);
1928
1816
  }
@@ -1936,7 +1824,7 @@ class HttpCookieStore {
1936
1824
  }
1937
1825
  function concatUint8Array(...t) {
1938
1826
  const e = new Uint8Array(
1939
- t.reduce((s, n) => s + n.length, 0)
1827
+ t.reduce((s, i) => s + i.length, 0)
1940
1828
  );
1941
1829
  let r = 0;
1942
1830
  for (const s of t)
@@ -1970,22 +1858,22 @@ function concatBytes(t) {
1970
1858
  function limitBytes(t, e) {
1971
1859
  if (e === 0)
1972
1860
  return new ReadableStream({
1973
- start(n) {
1974
- n.close();
1861
+ start(i) {
1862
+ i.close();
1975
1863
  }
1976
1864
  });
1977
1865
  const r = t.getReader({ mode: "byob" });
1978
1866
  let s = 0;
1979
1867
  return new ReadableStream({
1980
- async pull(n) {
1981
- const { value: i, done: o } = await r.read(
1868
+ async pull(i) {
1869
+ const { value: n, done: o } = await r.read(
1982
1870
  new Uint8Array(e - s)
1983
1871
  );
1984
1872
  if (o) {
1985
- r.releaseLock(), n.close();
1873
+ r.releaseLock(), i.close();
1986
1874
  return;
1987
1875
  }
1988
- s += i.length, n.enqueue(i), s >= e && (r.releaseLock(), n.close());
1876
+ s += n.length, i.enqueue(n), s >= e && (r.releaseLock(), i.close());
1989
1877
  },
1990
1878
  cancel() {
1991
1879
  r.cancel();
@@ -2064,25 +1952,25 @@ function streamReadFileFromPHP(t, e) {
2064
1952
  async function* iteratePhpFiles(t, e, {
2065
1953
  relativePaths: r = !0,
2066
1954
  pathPrefix: s,
2067
- exceptPaths: n = []
1955
+ exceptPaths: i = []
2068
1956
  } = {}) {
2069
1957
  e = normalizePath(e);
2070
- const i = [e];
2071
- for (; i.length; ) {
2072
- const o = i.pop();
1958
+ const n = [e];
1959
+ for (; n.length; ) {
1960
+ const o = n.pop();
2073
1961
  if (!o)
2074
1962
  return;
2075
- const l = await t.listFiles(o);
2076
- for (const c of l) {
2077
- const a = `${o}/${c}`;
2078
- if (n.includes(a.substring(e.length + 1)))
1963
+ const a = await t.listFiles(o);
1964
+ for (const l of a) {
1965
+ const c = `${o}/${l}`;
1966
+ if (i.includes(c.substring(e.length + 1)))
2079
1967
  continue;
2080
- await t.isDir(a) ? i.push(a) : yield new StreamedFile(
2081
- streamReadFileFromPHP(t, a),
1968
+ await t.isDir(c) ? n.push(c) : yield new StreamedFile(
1969
+ streamReadFileFromPHP(t, c),
2082
1970
  r ? joinPaths(
2083
1971
  s || "",
2084
- a.substring(e.length + 1)
2085
- ) : a
1972
+ c.substring(e.length + 1)
1973
+ ) : c
2086
1974
  );
2087
1975
  }
2088
1976
  }
@@ -2168,15 +2056,15 @@ class PHPProcessManager {
2168
2056
  this.allInstances.push(r);
2169
2057
  const s = () => {
2170
2058
  this.allInstances = this.allInstances.filter(
2171
- (n) => n !== r
2059
+ (i) => i !== r
2172
2060
  );
2173
2061
  };
2174
- return r.catch((n) => {
2175
- throw s(), n;
2176
- }).then((n) => ({
2177
- ...n,
2062
+ return r.catch((i) => {
2063
+ throw s(), i;
2064
+ }).then((i) => ({
2065
+ ...i,
2178
2066
  reap: () => {
2179
- s(), n.reap();
2067
+ s(), i.reap();
2180
2068
  }
2181
2069
  }));
2182
2070
  }
@@ -2239,23 +2127,23 @@ function ensurePathPrefix(t, e) {
2239
2127
  return !e || t.startsWith(e) ? t : e + t;
2240
2128
  }
2241
2129
  async function encodeAsMultipart(t) {
2242
- const e = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${e}`, s = new TextEncoder(), n = [];
2243
- for (const [c, a] of Object.entries(t))
2244
- n.push(`--${e}\r
2245
- `), n.push(`Content-Disposition: form-data; name="${c}"`), a instanceof File && n.push(`; filename="${a.name}"`), n.push(`\r
2246
- `), a instanceof File && (n.push("Content-Type: application/octet-stream"), n.push(`\r
2247
- `)), n.push(`\r
2248
- `), a instanceof File ? n.push(await fileToUint8Array(a)) : n.push(a), n.push(`\r
2130
+ const e = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${e}`, s = new TextEncoder(), i = [];
2131
+ for (const [l, c] of Object.entries(t))
2132
+ i.push(`--${e}\r
2133
+ `), i.push(`Content-Disposition: form-data; name="${l}"`), c instanceof File && i.push(`; filename="${c.name}"`), i.push(`\r
2134
+ `), c instanceof File && (i.push("Content-Type: application/octet-stream"), i.push(`\r
2135
+ `)), i.push(`\r
2136
+ `), c instanceof File ? i.push(await fileToUint8Array(c)) : i.push(c), i.push(`\r
2249
2137
  `);
2250
- n.push(`--${e}--\r
2138
+ i.push(`--${e}--\r
2251
2139
  `);
2252
- const i = n.reduce((c, a) => c + a.length, 0), o = new Uint8Array(i);
2253
- let l = 0;
2254
- for (const c of n)
2140
+ const n = i.reduce((l, c) => l + c.length, 0), o = new Uint8Array(n);
2141
+ let a = 0;
2142
+ for (const l of i)
2255
2143
  o.set(
2256
- typeof c == "string" ? s.encode(c) : c,
2257
- l
2258
- ), l += c.length;
2144
+ typeof l == "string" ? s.encode(l) : l,
2145
+ a
2146
+ ), a += l.length;
2259
2147
  return { bytes: o, contentType: r };
2260
2148
  }
2261
2149
  function fileToUint8Array(t) {
@@ -2362,7 +2250,7 @@ const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "app
2362
2250
  xspf,
2363
2251
  zip
2364
2252
  };
2365
- var w, F, C, b, H, P, T, k, V, he, J, fe, Q, me, Z, _e;
2253
+ var m, R, T, v, b, _, S, F, $, le, z, ce, W, ue, G, pe;
2366
2254
  class PHPRequestHandler {
2367
2255
  /**
2368
2256
  * The request handler needs to decide whether to serve a static asset or
@@ -2382,11 +2270,11 @@ class PHPRequestHandler {
2382
2270
  * @param fsPath - Absolute path of the static file to serve.
2383
2271
  * @returns The response.
2384
2272
  */
2385
- p(this, V);
2273
+ p(this, $);
2386
2274
  /**
2387
2275
  * Spawns a new PHP instance and dispatches a request to it.
2388
2276
  */
2389
- p(this, J);
2277
+ p(this, z);
2390
2278
  /**
2391
2279
  * Runs the requested PHP file with all the request and $_SERVER
2392
2280
  * superglobals populated.
@@ -2394,7 +2282,7 @@ class PHPRequestHandler {
2394
2282
  * @param request - The request.
2395
2283
  * @returns The response.
2396
2284
  */
2397
- p(this, Q);
2285
+ p(this, W);
2398
2286
  /**
2399
2287
  * Resolve the requested path to the filesystem path of the requested PHP file.
2400
2288
  *
@@ -2404,41 +2292,41 @@ class PHPRequestHandler {
2404
2292
  * @throws {Error} If the requested path doesn't exist.
2405
2293
  * @returns The resolved filesystem path.
2406
2294
  */
2407
- p(this, Z);
2408
- p(this, w, void 0);
2409
- p(this, F, void 0);
2410
- p(this, C, void 0);
2411
- p(this, b, void 0);
2412
- p(this, H, void 0);
2413
- p(this, P, void 0);
2295
+ p(this, G);
2296
+ p(this, m, void 0);
2297
+ p(this, R, void 0);
2414
2298
  p(this, T, void 0);
2415
- p(this, k, void 0);
2299
+ p(this, v, void 0);
2300
+ p(this, b, void 0);
2301
+ p(this, _, void 0);
2302
+ p(this, S, void 0);
2303
+ p(this, F, void 0);
2416
2304
  const {
2417
2305
  documentRoot: r = "/www/",
2418
2306
  absoluteUrl: s = typeof location == "object" ? location == null ? void 0 : location.href : "",
2419
- rewriteRules: n = []
2307
+ rewriteRules: i = []
2420
2308
  } = e;
2421
2309
  "processManager" in e ? this.processManager = e.processManager : this.processManager = new PHPProcessManager({
2422
- phpFactory: async (l) => {
2423
- const c = await e.phpFactory({
2424
- ...l,
2310
+ phpFactory: async (a) => {
2311
+ const l = await e.phpFactory({
2312
+ ...a,
2425
2313
  requestHandler: this
2426
2314
  });
2427
- return c.requestHandler = this, c;
2315
+ return l.requestHandler = this, l;
2428
2316
  },
2429
2317
  maxPhpInstances: e.maxPhpInstances
2430
- }), f(this, k, new HttpCookieStore()), f(this, w, r);
2431
- const i = new URL(s);
2432
- f(this, C, i.hostname), f(this, b, i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80), f(this, F, (i.protocol || "").replace(":", ""));
2433
- const o = u(this, b) !== 443 && u(this, b) !== 80;
2434
- f(this, H, [
2435
- u(this, C),
2436
- o ? `:${u(this, b)}` : ""
2437
- ].join("")), f(this, P, i.pathname.replace(/\/+$/, "")), f(this, T, [
2438
- `${u(this, F)}://`,
2439
- u(this, H),
2440
- u(this, P)
2441
- ].join("")), this.rewriteRules = n;
2318
+ }), h(this, F, new HttpCookieStore()), h(this, m, r);
2319
+ const n = new URL(s);
2320
+ h(this, T, n.hostname), h(this, v, n.port ? Number(n.port) : n.protocol === "https:" ? 443 : 80), h(this, R, (n.protocol || "").replace(":", ""));
2321
+ const o = u(this, v) !== 443 && u(this, v) !== 80;
2322
+ h(this, b, [
2323
+ u(this, T),
2324
+ o ? `:${u(this, v)}` : ""
2325
+ ].join("")), h(this, _, n.pathname.replace(/\/+$/, "")), h(this, S, [
2326
+ `${u(this, R)}://`,
2327
+ u(this, b),
2328
+ u(this, _)
2329
+ ].join("")), this.rewriteRules = i;
2442
2330
  }
2443
2331
  async getPrimaryPhp() {
2444
2332
  return await this.processManager.getPrimaryPhp();
@@ -2462,20 +2350,20 @@ class PHPRequestHandler {
2462
2350
  */
2463
2351
  internalUrlToPath(e) {
2464
2352
  const r = new URL(e);
2465
- return r.pathname.startsWith(u(this, P)) && (r.pathname = r.pathname.slice(u(this, P).length)), toRelativeUrl(r);
2353
+ return r.pathname.startsWith(u(this, _)) && (r.pathname = r.pathname.slice(u(this, _).length)), toRelativeUrl(r);
2466
2354
  }
2467
2355
  /**
2468
2356
  * The absolute URL of this PHPRequestHandler instance.
2469
2357
  */
2470
2358
  get absoluteUrl() {
2471
- return u(this, T);
2359
+ return u(this, S);
2472
2360
  }
2473
2361
  /**
2474
2362
  * The directory in the PHP filesystem where the server will look
2475
2363
  * for the files to serve. Default: `/var/www`.
2476
2364
  */
2477
2365
  get documentRoot() {
2478
- return u(this, w);
2366
+ return u(this, m);
2479
2367
  }
2480
2368
  /**
2481
2369
  * Serves the request – either by serving a static file, or by
@@ -2530,17 +2418,17 @@ class PHPRequestHandler {
2530
2418
  // Remove the hash part of the URL as it's not meant for the server.
2531
2419
  e.url.split("#")[0],
2532
2420
  r ? void 0 : DEFAULT_BASE_URL
2533
- ), n = applyRewriteRules(
2421
+ ), i = applyRewriteRules(
2534
2422
  removePathPrefix(
2535
2423
  decodeURIComponent(s.pathname),
2536
- u(this, P)
2424
+ u(this, _)
2537
2425
  ),
2538
2426
  this.rewriteRules
2539
- ), i = joinPaths(u(this, w), n);
2540
- return seemsLikeAPHPRequestHandlerPath(i) ? h(this, J, fe).call(this, e, s) : h(this, V, he).call(this, await this.processManager.getPrimaryPhp(), i);
2427
+ ), n = joinPaths(u(this, m), i);
2428
+ return seemsLikeAPHPRequestHandlerPath(n) ? d(this, z, ce).call(this, e, s) : d(this, $, le).call(this, await this.processManager.getPrimaryPhp(), n);
2541
2429
  }
2542
2430
  }
2543
- w = new WeakMap(), F = new WeakMap(), C = new WeakMap(), b = new WeakMap(), H = new WeakMap(), P = new WeakMap(), T = new WeakMap(), k = new WeakMap(), V = new WeakSet(), he = function(e, r) {
2431
+ m = new WeakMap(), R = new WeakMap(), T = new WeakMap(), v = new WeakMap(), b = new WeakMap(), _ = new WeakMap(), S = new WeakMap(), F = new WeakMap(), $ = new WeakSet(), le = function(e, r) {
2544
2432
  if (!e.fileExists(r))
2545
2433
  return new PHPResponse(
2546
2434
  404,
@@ -2565,70 +2453,70 @@ w = new WeakMap(), F = new WeakMap(), C = new WeakMap(), b = new WeakMap(), H =
2565
2453
  },
2566
2454
  s
2567
2455
  );
2568
- }, J = new WeakSet(), fe = async function(e, r) {
2456
+ }, z = new WeakSet(), ce = async function(e, r) {
2569
2457
  let s;
2570
2458
  try {
2571
2459
  s = await this.processManager.acquirePHPInstance();
2572
- } catch (n) {
2573
- return n instanceof MaxPhpInstancesError ? PHPResponse.forHttpCode(502) : PHPResponse.forHttpCode(500);
2460
+ } catch (i) {
2461
+ return i instanceof MaxPhpInstancesError ? PHPResponse.forHttpCode(502) : PHPResponse.forHttpCode(500);
2574
2462
  }
2575
2463
  try {
2576
- return await h(this, Q, me).call(this, s.php, e, r);
2464
+ return await d(this, W, ue).call(this, s.php, e, r);
2577
2465
  } finally {
2578
2466
  s.reap();
2579
2467
  }
2580
- }, Q = new WeakSet(), me = async function(e, r, s) {
2581
- let n = "GET";
2582
- const i = {
2583
- host: u(this, H),
2468
+ }, W = new WeakSet(), ue = async function(e, r, s) {
2469
+ let i = "GET";
2470
+ const n = {
2471
+ host: u(this, b),
2584
2472
  ...normalizeHeaders(r.headers || {}),
2585
- cookie: u(this, k).getCookieRequestHeader()
2473
+ cookie: u(this, F).getCookieRequestHeader()
2586
2474
  };
2587
2475
  let o = r.body;
2588
2476
  if (typeof o == "object" && !(o instanceof Uint8Array)) {
2589
- n = "POST";
2590
- const { bytes: c, contentType: a } = await encodeAsMultipart(o);
2591
- o = c, i["content-type"] = a;
2477
+ i = "POST";
2478
+ const { bytes: l, contentType: c } = await encodeAsMultipart(o);
2479
+ o = l, n["content-type"] = c;
2592
2480
  }
2593
- let l;
2481
+ let a;
2594
2482
  try {
2595
- l = h(this, Z, _e).call(this, e, decodeURIComponent(s.pathname));
2483
+ a = d(this, G, pe).call(this, e, decodeURIComponent(s.pathname));
2596
2484
  } catch {
2597
2485
  return PHPResponse.forHttpCode(404);
2598
2486
  }
2599
2487
  try {
2600
- const c = await e.run({
2488
+ const l = await e.run({
2601
2489
  relativeUri: ensurePathPrefix(
2602
2490
  toRelativeUrl(s),
2603
- u(this, P)
2491
+ u(this, _)
2604
2492
  ),
2605
- protocol: u(this, F),
2606
- method: r.method || n,
2493
+ protocol: u(this, R),
2494
+ method: r.method || i,
2607
2495
  $_SERVER: {
2608
2496
  REMOTE_ADDR: "127.0.0.1",
2609
- DOCUMENT_ROOT: u(this, w),
2610
- HTTPS: u(this, T).startsWith("https://") ? "on" : ""
2497
+ DOCUMENT_ROOT: u(this, m),
2498
+ HTTPS: u(this, S).startsWith("https://") ? "on" : ""
2611
2499
  },
2612
2500
  body: o,
2613
- scriptPath: l,
2614
- headers: i
2501
+ scriptPath: a,
2502
+ headers: n
2615
2503
  });
2616
- return u(this, k).rememberCookiesFromResponseHeaders(
2617
- c.headers
2618
- ), c;
2619
- } catch (c) {
2620
- const a = c;
2621
- if (a != null && a.response)
2622
- return a.response;
2623
- throw c;
2624
- }
2625
- }, Z = new WeakSet(), _e = function(e, r) {
2626
- let s = removePathPrefix(r, u(this, P));
2627
- s = applyRewriteRules(s, this.rewriteRules), s.includes(".php") ? s = s.split(".php")[0] + ".php" : e.isDir(`${u(this, w)}${s}`) ? (s.endsWith("/") || (s = `${s}/`), s = `${s}index.php`) : s = "/index.php";
2628
- let n = `${u(this, w)}${s}`;
2629
- if (e.fileExists(n) || (n = `${u(this, w)}/index.php`), e.fileExists(n))
2630
- return n;
2631
- throw new Error(`File not found: ${n}`);
2504
+ return u(this, F).rememberCookiesFromResponseHeaders(
2505
+ l.headers
2506
+ ), l;
2507
+ } catch (l) {
2508
+ const c = l;
2509
+ if (c != null && c.response)
2510
+ return c.response;
2511
+ throw l;
2512
+ }
2513
+ }, G = new WeakSet(), pe = function(e, r) {
2514
+ let s = removePathPrefix(r, u(this, _));
2515
+ s = applyRewriteRules(s, this.rewriteRules), s.includes(".php") ? s = s.split(".php")[0] + ".php" : e.isDir(`${u(this, m)}${s}`) ? (s.endsWith("/") || (s = `${s}/`), s = `${s}index.php`) : s = "/index.php";
2516
+ let i = `${u(this, m)}${s}`;
2517
+ if (e.fileExists(i) || (i = `${u(this, m)}/index.php`), e.fileExists(i))
2518
+ return i;
2519
+ throw new Error(`File not found: ${i}`);
2632
2520
  };
2633
2521
  function inferMimeType(t) {
2634
2522
  const e = t.split(".").pop();
@@ -2663,11 +2551,11 @@ function rotatePHPRuntime({
2663
2551
  */
2664
2552
  maxRequests: s = 400
2665
2553
  }) {
2666
- let n = 0;
2667
- async function i() {
2668
- if (++n < s)
2554
+ let i = 0;
2555
+ async function n() {
2556
+ if (++i < s)
2669
2557
  return;
2670
- n = 0;
2558
+ i = 0;
2671
2559
  const o = await t.semaphore.acquire();
2672
2560
  try {
2673
2561
  t.hotSwapPHPRuntime(await r(), e);
@@ -2675,29 +2563,29 @@ function rotatePHPRuntime({
2675
2563
  o();
2676
2564
  }
2677
2565
  }
2678
- return t.addEventListener("request.end", i), function() {
2679
- t.removeEventListener("request.end", i);
2566
+ return t.addEventListener("request.end", n), function() {
2567
+ t.removeEventListener("request.end", n);
2680
2568
  };
2681
2569
  }
2682
2570
  async function writeFiles(t, e, r, { rmRoot: s = !1 } = {}) {
2683
2571
  s && await t.isDir(e) && await t.rmdir(e, { recursive: !0 });
2684
- for (const [n, i] of Object.entries(r)) {
2685
- const o = joinPaths(e, n);
2686
- await t.fileExists(dirname(o)) || await t.mkdir(dirname(o)), i instanceof Uint8Array || typeof i == "string" ? await t.writeFile(o, i) : await writeFiles(t, o, i);
2572
+ for (const [i, n] of Object.entries(r)) {
2573
+ const o = joinPaths(e, i);
2574
+ await t.fileExists(dirname(o)) || await t.mkdir(dirname(o)), n instanceof Uint8Array || typeof n == "string" ? await t.writeFile(o, n) : await writeFiles(t, o, n);
2687
2575
  }
2688
2576
  }
2689
2577
  function proxyFileSystem(t, e, r) {
2690
2578
  const s = Object.getOwnPropertySymbols(t)[0];
2691
- for (const n of r)
2692
- e.fileExists(n) || e.mkdir(n), t.fileExists(n) || t.mkdir(n), e[s].FS.mount(
2579
+ for (const i of r)
2580
+ e.fileExists(i) || e.mkdir(i), t.fileExists(i) || t.mkdir(i), e[s].FS.mount(
2693
2581
  // @ts-ignore
2694
2582
  e[s].PROXYFS,
2695
2583
  {
2696
- root: n,
2584
+ root: i,
2697
2585
  // @ts-ignore
2698
2586
  fs: t[s].FS
2699
2587
  },
2700
- n
2588
+ i
2701
2589
  );
2702
2590
  }
2703
2591
  export {