@php-wasm/universal 0.6.2 → 0.6.4

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,19 +1,19 @@
1
- var K = (e, t, r) => {
1
+ var J = (e, t, r) => {
2
2
  if (!t.has(e))
3
3
  throw TypeError("Cannot " + r);
4
4
  };
5
- var a = (e, t, r) => (K(e, t, "read from private field"), r ? r.call(e) : t.get(e)), c = (e, t, r) => {
5
+ var a = (e, t, r) => (J(e, t, "read from private field"), r ? r.call(e) : t.get(e)), u = (e, t, r) => {
6
6
  if (t.has(e))
7
7
  throw TypeError("Cannot add the same private member more than once");
8
8
  t instanceof WeakSet ? t.add(e) : t.set(e, r);
9
- }, u = (e, t, r, s) => (K(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
10
- var f = (e, t, r) => (K(e, t, "access private method"), r);
9
+ }, h = (e, t, r, s) => (J(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
10
+ var f = (e, t, r) => (J(e, t, "access private method"), r);
11
11
  if (typeof File > "u") {
12
12
  class e extends Blob {
13
- constructor(r, s, i) {
13
+ constructor(r, s, n) {
14
14
  super(r);
15
- let n;
16
- i != null && i.lastModified && (n = /* @__PURE__ */ new Date()), (!n || isNaN(n.getFullYear())) && (n = /* @__PURE__ */ new Date()), this.lastModifiedDate = n, this.lastModified = n.getMilliseconds(), this.name = s || "";
15
+ let i;
16
+ n != null && n.lastModified && (i = /* @__PURE__ */ new Date()), (!i || isNaN(i.getFullYear())) && (i = /* @__PURE__ */ new Date()), this.lastModifiedDate = i, this.lastModified = i.getMilliseconds(), this.name = s || "";
17
17
  }
18
18
  }
19
19
  global.File = e;
@@ -50,7 +50,7 @@ function isByobSupported() {
50
50
  // this if needed.
51
51
  autoAllocateChunkSize: 512 * 1024,
52
52
  async pull(r) {
53
- const s = r.byobRequest.view, n = await t.slice(e, e + s.byteLength).arrayBuffer(), o = new Uint8Array(n);
53
+ const s = r.byobRequest.view, i = await t.slice(e, e + s.byteLength).arrayBuffer(), o = new Uint8Array(i);
54
54
  new Uint8Array(s.buffer).set(o);
55
55
  const l = o.byteLength;
56
56
  r.byobRequest.respond(l), e += l, e >= t.size && r.close();
@@ -114,16 +114,16 @@ function improveWASMErrorReporting(e) {
114
114
  for (const r in e.asm)
115
115
  if (typeof e.asm[r] == "function") {
116
116
  const s = e.asm[r];
117
- e.asm[r] = function(...i) {
118
- var n;
117
+ e.asm[r] = function(...n) {
118
+ var i;
119
119
  try {
120
- return s(...i);
120
+ return s(...n);
121
121
  } catch (o) {
122
122
  if (!(o instanceof Error))
123
123
  throw o;
124
124
  const l = clarifyErrorMessage(
125
125
  o,
126
- (n = e.lastAsyncifyStackSource) == null ? void 0 : n.stack
126
+ (i = e.lastAsyncifyStackSource) == null ? void 0 : i.stack
127
127
  );
128
128
  if (e.lastAsyncifyStackSource && (o.cause = e.lastAsyncifyStackSource), t.hasListeners()) {
129
129
  t.dispatchEvent(
@@ -266,20 +266,39 @@ function normalizePath(e) {
266
266
  function normalizePathsArray(e, t) {
267
267
  let r = 0;
268
268
  for (let s = e.length - 1; s >= 0; s--) {
269
- const i = e[s];
270
- i === "." ? e.splice(s, 1) : i === ".." ? (e.splice(s, 1), r++) : r && (e.splice(s, 1), r--);
269
+ const n = e[s];
270
+ n === "." ? e.splice(s, 1) : n === ".." ? (e.splice(s, 1), r++) : r && (e.splice(s, 1), r--);
271
271
  }
272
272
  if (t)
273
273
  for (; r; r--)
274
274
  e.unshift("..");
275
275
  return e;
276
276
  }
277
+ function splitShellCommand(e) {
278
+ let s = 0, n = "";
279
+ const i = [];
280
+ let o = "";
281
+ for (let l = 0; l < e.length; l++) {
282
+ const c = e[l];
283
+ c === "\\" ? ((e[l + 1] === '"' || e[l + 1] === "'") && l++, o += e[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);
284
+ }
285
+ return o && i.push(o.trim()), i;
286
+ }
277
287
  function createSpawnHandler(e) {
278
- return function(t) {
279
- const r = new ChildProcess(), s = new ProcessApi(r);
288
+ return function(t, r = [], s = {}) {
289
+ const n = new ChildProcess(), i = new ProcessApi(n);
280
290
  return setTimeout(async () => {
281
- await e(t, s), r.emit("spawn", !0);
282
- }), r;
291
+ let o = [];
292
+ if (r.length)
293
+ o = [t, ...r];
294
+ else if (typeof t == "string")
295
+ o = splitShellCommand(t);
296
+ else if (Array.isArray(t))
297
+ o = t;
298
+ else
299
+ throw new Error("Invalid command ", t);
300
+ await e(o, i, s), n.emit("spawn", !0);
301
+ }), n;
283
302
  };
284
303
  }
285
304
  class EventEmitter {
@@ -304,9 +323,15 @@ class ProcessApi extends EventEmitter {
304
323
  stdout(t) {
305
324
  typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stdout.emit("data", t);
306
325
  }
326
+ stdoutEnd() {
327
+ this.childProcess.stdout.emit("end", {});
328
+ }
307
329
  stderr(t) {
308
330
  typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stderr.emit("data", t);
309
331
  }
332
+ stderrEnd() {
333
+ this.childProcess.stderr.emit("end", {});
334
+ }
310
335
  exit(t) {
311
336
  this.exited || (this.exited = !0, this.childProcess.emit("exit", t));
312
337
  }
@@ -331,7 +356,7 @@ class ChildProcess extends EventEmitter {
331
356
  }
332
357
  function concatUint8Array(...e) {
333
358
  const t = new Uint8Array(
334
- e.reduce((s, i) => s + i.length, 0)
359
+ e.reduce((s, n) => s + n.length, 0)
335
360
  );
336
361
  let r = 0;
337
362
  for (const s of e)
@@ -365,22 +390,22 @@ function concatBytes(e) {
365
390
  function limitBytes(e, t) {
366
391
  if (t === 0)
367
392
  return new ReadableStream({
368
- start(i) {
369
- i.close();
393
+ start(n) {
394
+ n.close();
370
395
  }
371
396
  });
372
397
  const r = e.getReader({ mode: "byob" });
373
398
  let s = 0;
374
399
  return new ReadableStream({
375
- async pull(i) {
376
- const { value: n, done: o } = await r.read(
400
+ async pull(n) {
401
+ const { value: i, done: o } = await r.read(
377
402
  new Uint8Array(t - s)
378
403
  );
379
404
  if (o) {
380
- r.releaseLock(), i.close();
405
+ r.releaseLock(), n.close();
381
406
  return;
382
407
  }
383
- s += n.length, i.enqueue(n), s >= t && (r.releaseLock(), i.close());
408
+ s += i.length, n.enqueue(i), s >= t && (r.releaseLock(), n.close());
384
409
  },
385
410
  cancel() {
386
411
  r.cancel();
@@ -459,20 +484,20 @@ function streamReadFileFromPHP(e, t) {
459
484
  async function* iteratePhpFiles(e, t, {
460
485
  relativePaths: r = !0,
461
486
  pathPrefix: s,
462
- exceptPaths: i = []
487
+ exceptPaths: n = []
463
488
  } = {}) {
464
489
  t = normalizePath(t);
465
- const n = [t];
466
- for (; n.length; ) {
467
- const o = n.pop();
490
+ const i = [t];
491
+ for (; i.length; ) {
492
+ const o = i.pop();
468
493
  if (!o)
469
494
  return;
470
495
  const l = await e.listFiles(o);
471
- for (const h of l) {
472
- const d = `${o}/${h}`;
473
- if (i.includes(d.substring(t.length + 1)))
496
+ for (const c of l) {
497
+ const d = `${o}/${c}`;
498
+ if (n.includes(d.substring(t.length + 1)))
474
499
  continue;
475
- await e.isDir(d) ? n.push(d) : yield new StreamedFile(
500
+ await e.isDir(d) ? i.push(d) : yield new StreamedFile(
476
501
  streamReadFileFromPHP(e, d),
477
502
  r ? joinPaths(
478
503
  s || "",
@@ -494,8 +519,8 @@ function writeFilesStreamToPhp(e, t) {
494
519
  });
495
520
  }
496
521
  class PHPResponse {
497
- constructor(t, r, s, i = "", n = 0) {
498
- this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = n, this.errors = i;
522
+ constructor(t, r, s, n = "", i = 0) {
523
+ this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = i, this.errors = n;
499
524
  }
500
525
  static fromRawData(t) {
501
526
  return new PHPResponse(
@@ -546,16 +571,16 @@ const SupportedPHPVersions = [
546
571
  ], SupportedPHPExtensionBundles = {
547
572
  "kitchen-sink": SupportedPHPExtensionsList
548
573
  };
549
- var E, H;
574
+ var E, b;
550
575
  class PHPBrowser {
551
576
  /**
552
577
  * @param server - The PHP server to browse.
553
578
  * @param config - The browser configuration.
554
579
  */
555
580
  constructor(t, r = {}) {
556
- c(this, E, void 0);
557
- c(this, H, void 0);
558
- this.requestHandler = t, u(this, E, {}), u(this, H, {
581
+ u(this, E, void 0);
582
+ u(this, b, void 0);
583
+ this.requestHandler = t, h(this, E, {}), h(this, b, {
559
584
  handleRedirects: !1,
560
585
  maxRedirects: 4,
561
586
  ...r
@@ -583,14 +608,14 @@ class PHPBrowser {
583
608
  cookie: this.serializeCookies()
584
609
  }
585
610
  });
586
- if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), a(this, H).handleRedirects && s.headers.location && r < a(this, H).maxRedirects) {
587
- const i = new URL(
611
+ if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), a(this, b).handleRedirects && s.headers.location && r < a(this, b).maxRedirects) {
612
+ const n = new URL(
588
613
  s.headers.location[0],
589
614
  this.requestHandler.absoluteUrl
590
615
  );
591
616
  return this.request(
592
617
  {
593
- url: i.toString(),
618
+ url: n.toString(),
594
619
  method: "GET",
595
620
  headers: {}
596
621
  },
@@ -620,8 +645,8 @@ class PHPBrowser {
620
645
  try {
621
646
  if (!r.includes("="))
622
647
  continue;
623
- const s = r.indexOf("="), i = r.substring(0, s), n = r.substring(s + 1).split(";")[0];
624
- a(this, E)[i] = n;
648
+ const s = r.indexOf("="), n = r.substring(0, s), i = r.substring(s + 1).split(";")[0];
649
+ a(this, E)[n] = i;
625
650
  } catch (s) {
626
651
  console.error(s);
627
652
  }
@@ -633,7 +658,7 @@ class PHPBrowser {
633
658
  return t.join("; ");
634
659
  }
635
660
  }
636
- E = new WeakMap(), H = new WeakMap();
661
+ E = new WeakMap(), b = new WeakMap();
637
662
  const DEFAULT_BASE_URL = "http://example.com";
638
663
  function toRelativeUrl(e) {
639
664
  return e.toString().substring(e.origin.length);
@@ -644,7 +669,35 @@ function removePathPrefix(e, t) {
644
669
  function ensurePathPrefix(e, t) {
645
670
  return !t || e.startsWith(t) ? e : t + e;
646
671
  }
647
- var P, x, A, v, F, m, T, R, L, Q, N, X, M, ee;
672
+ async function encodeAsMultipart(e) {
673
+ const t = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${t}`, s = new TextEncoder(), n = [];
674
+ for (const [c, d] of Object.entries(e))
675
+ n.push(`--${t}\r
676
+ `), n.push(`Content-Disposition: form-data; name="${c}"`), d instanceof File && n.push(`; filename="${d.name}"`), n.push(`\r
677
+ `), d instanceof File && (n.push("Content-Type: application/octet-stream"), n.push(`\r
678
+ `)), n.push(`\r
679
+ `), d instanceof File ? n.push(await fileToUint8Array(d)) : n.push(d), n.push(`\r
680
+ `);
681
+ n.push(`--${t}--\r
682
+ `);
683
+ const i = n.reduce((c, d) => c + d.length, 0), o = new Uint8Array(i);
684
+ let l = 0;
685
+ for (const c of n)
686
+ o.set(
687
+ typeof c == "string" ? s.encode(c) : c,
688
+ l
689
+ ), l += c.length;
690
+ return { bytes: o, contentType: r };
691
+ }
692
+ function fileToUint8Array(e) {
693
+ return new Promise((t) => {
694
+ const r = new FileReader();
695
+ r.onload = () => {
696
+ t(new Uint8Array(r.result));
697
+ }, r.readAsArrayBuffer(e);
698
+ });
699
+ }
700
+ var m, H, k, v, x, _, F, R, B, Y, I, Z, L, K;
648
701
  class PHPRequestHandler {
649
702
  /**
650
703
  * @param php - The PHP instance.
@@ -657,7 +710,7 @@ class PHPRequestHandler {
657
710
  * @param fsPath - Absolute path of the static file to serve.
658
711
  * @returns The response.
659
712
  */
660
- c(this, L);
713
+ u(this, B);
661
714
  /**
662
715
  * Runs the requested PHP file with all the request and $_SERVER
663
716
  * superglobals populated.
@@ -665,7 +718,7 @@ class PHPRequestHandler {
665
718
  * @param request - The request.
666
719
  * @returns The response.
667
720
  */
668
- c(this, N);
721
+ u(this, I);
669
722
  /**
670
723
  * Resolve the requested path to the filesystem path of the requested PHP file.
671
724
  *
@@ -675,31 +728,31 @@ class PHPRequestHandler {
675
728
  * @throws {Error} If the requested path doesn't exist.
676
729
  * @returns The resolved filesystem path.
677
730
  */
678
- c(this, M);
679
- c(this, P, void 0);
680
- c(this, x, void 0);
681
- c(this, A, void 0);
682
- c(this, v, void 0);
683
- c(this, F, void 0);
684
- c(this, m, void 0);
685
- c(this, T, void 0);
686
- c(this, R, void 0);
687
- u(this, R, new Semaphore({ concurrency: 1 }));
731
+ u(this, L);
732
+ u(this, m, void 0);
733
+ u(this, H, void 0);
734
+ u(this, k, void 0);
735
+ u(this, v, void 0);
736
+ u(this, x, void 0);
737
+ u(this, _, void 0);
738
+ u(this, F, void 0);
739
+ u(this, R, void 0);
740
+ h(this, R, new Semaphore({ concurrency: 1 }));
688
741
  const {
689
742
  documentRoot: s = "/www/",
690
- absoluteUrl: i = typeof location == "object" ? location == null ? void 0 : location.href : ""
743
+ absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : ""
691
744
  } = r;
692
- this.php = t, u(this, P, s);
693
- const n = new URL(i);
694
- u(this, A, n.hostname), u(this, v, n.port ? Number(n.port) : n.protocol === "https:" ? 443 : 80), u(this, x, (n.protocol || "").replace(":", ""));
745
+ this.php = t, h(this, m, s);
746
+ const i = new URL(n);
747
+ h(this, k, i.hostname), h(this, v, i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80), h(this, H, (i.protocol || "").replace(":", ""));
695
748
  const o = a(this, v) !== 443 && a(this, v) !== 80;
696
- u(this, F, [
697
- a(this, A),
749
+ h(this, x, [
750
+ a(this, k),
698
751
  o ? `:${a(this, v)}` : ""
699
- ].join("")), u(this, m, n.pathname.replace(/\/+$/, "")), u(this, T, [
700
- `${a(this, x)}://`,
701
- a(this, F),
702
- a(this, m)
752
+ ].join("")), h(this, _, i.pathname.replace(/\/+$/, "")), h(this, F, [
753
+ `${a(this, H)}://`,
754
+ a(this, x),
755
+ a(this, _)
703
756
  ].join(""));
704
757
  }
705
758
  /** @inheritDoc */
@@ -709,32 +762,32 @@ class PHPRequestHandler {
709
762
  /** @inheritDoc */
710
763
  internalUrlToPath(t) {
711
764
  const r = new URL(t);
712
- return r.pathname.startsWith(a(this, m)) && (r.pathname = r.pathname.slice(a(this, m).length)), toRelativeUrl(r);
765
+ return r.pathname.startsWith(a(this, _)) && (r.pathname = r.pathname.slice(a(this, _).length)), toRelativeUrl(r);
713
766
  }
714
767
  get isRequestRunning() {
715
768
  return a(this, R).running > 0;
716
769
  }
717
770
  /** @inheritDoc */
718
771
  get absoluteUrl() {
719
- return a(this, T);
772
+ return a(this, F);
720
773
  }
721
774
  /** @inheritDoc */
722
775
  get documentRoot() {
723
- return a(this, P);
776
+ return a(this, m);
724
777
  }
725
778
  /** @inheritDoc */
726
779
  async request(t) {
727
780
  const r = t.url.startsWith("http://") || t.url.startsWith("https://"), s = new URL(
728
781
  t.url,
729
782
  r ? void 0 : DEFAULT_BASE_URL
730
- ), i = removePathPrefix(
783
+ ), n = removePathPrefix(
731
784
  s.pathname,
732
- a(this, m)
733
- ), n = `${a(this, P)}${i}`;
734
- return seemsLikeAPHPRequestHandlerPath(n) ? await f(this, N, X).call(this, t, s) : f(this, L, Q).call(this, n);
785
+ a(this, _)
786
+ ), i = `${a(this, m)}${n}`;
787
+ return seemsLikeAPHPRequestHandlerPath(i) ? await f(this, I, Z).call(this, t, s) : f(this, B, Y).call(this, i);
735
788
  }
736
789
  }
737
- P = new WeakMap(), x = new WeakMap(), A = new WeakMap(), v = new WeakMap(), F = new WeakMap(), m = new WeakMap(), T = new WeakMap(), R = new WeakMap(), L = new WeakSet(), Q = function(t) {
790
+ m = new WeakMap(), H = new WeakMap(), k = new WeakMap(), v = new WeakMap(), x = new WeakMap(), _ = new WeakMap(), F = new WeakMap(), R = new WeakMap(), B = new WeakSet(), Y = function(t) {
738
791
  if (!this.php.fileExists(t))
739
792
  return new PHPResponse(
740
793
  404,
@@ -759,9 +812,9 @@ P = new WeakMap(), x = new WeakMap(), A = new WeakMap(), v = new WeakMap(), F =
759
812
  },
760
813
  r
761
814
  );
762
- }, N = new WeakSet(), X = async function(t, r) {
763
- var i, n, o;
764
- if (a(this, R).running > 0 && ((i = t.headers) == null ? void 0 : i["x-request-issuer"]) === "php")
815
+ }, I = new WeakSet(), Z = async function(t, r) {
816
+ var n, i;
817
+ if (a(this, R).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
765
818
  return console.warn(
766
819
  "Possible deadlock: Called request() before the previous request() have finished. PHP likely issued an HTTP call to itself. Normally this would lead to infinite waiting as Request 1 holds the lock that the Request 2 is waiting to acquire. That's not useful, so PHPRequestHandler will return error 502 instead."
767
820
  ), new PHPResponse(
@@ -771,45 +824,32 @@ P = new WeakMap(), x = new WeakMap(), A = new WeakMap(), v = new WeakMap(), F =
771
824
  );
772
825
  const s = await a(this, R).acquire();
773
826
  try {
774
- this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", a(this, P)), this.php.addServerGlobalEntry(
827
+ this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", a(this, m)), this.php.addServerGlobalEntry(
775
828
  "HTTPS",
776
- a(this, T).startsWith("https://") ? "on" : ""
829
+ a(this, F).startsWith("https://") ? "on" : ""
777
830
  );
778
- let l = "GET";
779
- const h = {
780
- host: a(this, F),
831
+ let o = "GET";
832
+ const l = {
833
+ host: a(this, x),
781
834
  ...normalizeHeaders(t.headers || {})
782
- }, d = [];
783
- if (t.files && Object.keys(t.files).length) {
784
- l = "POST";
785
- for (const S in t.files) {
786
- const U = t.files[S];
787
- d.push({
788
- key: S,
789
- name: U.name,
790
- type: U.type,
791
- data: new Uint8Array(await U.arrayBuffer())
792
- });
793
- }
794
- (n = h["content-type"]) != null && n.startsWith("multipart/form-data") && (t.formData = parseMultipartFormDataString(
795
- t.body || ""
796
- ), h["content-type"] = "application/x-www-form-urlencoded", delete t.body);
835
+ };
836
+ let c = t.body;
837
+ if (typeof c == "object" && !(c instanceof Uint8Array)) {
838
+ o = "POST";
839
+ const { bytes: p, contentType: U } = await encodeAsMultipart(c);
840
+ c = p, l["content-type"] = U;
797
841
  }
798
- let p;
799
- t.formData !== void 0 ? (l = "POST", h["content-type"] = h["content-type"] || "application/x-www-form-urlencoded", p = new URLSearchParams(
800
- t.formData
801
- ).toString()) : p = t.body;
802
- let I;
842
+ let d;
803
843
  try {
804
- let S = r.pathname;
805
- if ((o = t.headers) != null && o["x-rewrite-url"])
844
+ let p = r.pathname;
845
+ if ((i = t.headers) != null && i["x-rewrite-url"])
806
846
  try {
807
- S = new URL(
847
+ p = new URL(
808
848
  t.headers["x-rewrite-url"]
809
849
  ).pathname;
810
850
  } catch {
811
851
  }
812
- I = f(this, M, ee).call(this, S);
852
+ d = f(this, L, K).call(this, p);
813
853
  } catch {
814
854
  return new PHPResponse(
815
855
  404,
@@ -820,41 +860,25 @@ P = new WeakMap(), x = new WeakMap(), A = new WeakMap(), v = new WeakMap(), F =
820
860
  return await this.php.run({
821
861
  relativeUri: ensurePathPrefix(
822
862
  toRelativeUrl(r),
823
- a(this, m)
863
+ a(this, _)
824
864
  ),
825
- protocol: a(this, x),
826
- method: t.method || l,
827
- body: p,
828
- fileInfos: d,
829
- scriptPath: I,
830
- headers: h
865
+ protocol: a(this, H),
866
+ method: t.method || o,
867
+ body: c,
868
+ scriptPath: d,
869
+ headers: l
831
870
  });
832
871
  } finally {
833
872
  s();
834
873
  }
835
- }, M = new WeakSet(), ee = function(t) {
836
- let r = removePathPrefix(t, a(this, m));
837
- r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
838
- const s = `${a(this, P)}${r}`;
874
+ }, L = new WeakSet(), K = function(t) {
875
+ let r = removePathPrefix(t, a(this, _));
876
+ r.includes(".php") ? r = r.split(".php")[0] + ".php" : this.php.isDir(`${a(this, m)}${r}`) ? (r.endsWith("/") || (r = `${r}/`), r = `${r}index.php`) : r = "/index.php";
877
+ const s = `${a(this, m)}${r}`;
839
878
  if (this.php.fileExists(s))
840
879
  return s;
841
880
  throw new Error(`File not found: ${s}`);
842
881
  };
843
- function parseMultipartFormDataString(e) {
844
- const t = {}, r = e.match(/--(.*)\r\n/);
845
- if (!r)
846
- return t;
847
- const s = r[1], i = e.split(`--${s}`);
848
- return i.shift(), i.pop(), i.forEach((n) => {
849
- const o = n.indexOf(`\r
850
- \r
851
- `), l = n.substring(0, o).trim(), h = n.substring(o + 4).trim(), d = l.match(/name="([^"]+)"/);
852
- if (d) {
853
- const p = d[1];
854
- t[p] = h;
855
- }
856
- }), t;
857
- }
858
882
  function inferMimeType(e) {
859
883
  switch (e.split(".").pop()) {
860
884
  case "css":
@@ -989,16 +1013,16 @@ function getEmscriptenFsError(e) {
989
1013
  return FileErrorCodes[t];
990
1014
  }
991
1015
  function rethrowFileSystemError(e = "") {
992
- return function(r, s, i) {
993
- const n = i.value;
994
- i.value = function(...o) {
1016
+ return function(r, s, n) {
1017
+ const i = n.value;
1018
+ n.value = function(...o) {
995
1019
  try {
996
- return n.apply(this, o);
1020
+ return i.apply(this, o);
997
1021
  } catch (l) {
998
- const h = typeof l == "object" ? l == null ? void 0 : l.errno : null;
999
- if (h in FileErrorCodes) {
1000
- const d = FileErrorCodes[h], p = typeof o[0] == "string" ? o[0] : null, I = p !== null ? e.replaceAll("{path}", p) : e;
1001
- throw new Error(`${I}: ${d}`, {
1022
+ const c = typeof l == "object" ? l == null ? void 0 : l.errno : null;
1023
+ if (c in FileErrorCodes) {
1024
+ const d = FileErrorCodes[c], p = typeof o[0] == "string" ? o[0] : null, U = p !== null ? e.replaceAll("{path}", p) : e;
1025
+ throw new Error(`${U}: ${d}`, {
1002
1026
  cause: l
1003
1027
  });
1004
1028
  }
@@ -1010,9 +1034,9 @@ function rethrowFileSystemError(e = "") {
1010
1034
  const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map();
1011
1035
  let lastRuntimeId = 0;
1012
1036
  async function loadPHPRuntime(e, t = {}) {
1013
- const [r, s, i] = makePromise(), n = e.init(currentJsRuntime, {
1037
+ const [r, s, n] = makePromise(), i = e.init(currentJsRuntime, {
1014
1038
  onAbort(l) {
1015
- i(l), console.error(l);
1039
+ n(l), console.error(l);
1016
1040
  },
1017
1041
  ENV: {},
1018
1042
  // Emscripten sometimes prepends a '/' to the path, which
@@ -1027,9 +1051,9 @@ async function loadPHPRuntime(e, t = {}) {
1027
1051
  });
1028
1052
  await r;
1029
1053
  const o = ++lastRuntimeId;
1030
- return n.id = o, n.originalExit = n._exit, n._exit = function(l) {
1031
- return loadedRuntimes.delete(o), n.originalExit(l);
1032
- }, n[RuntimeId] = o, loadedRuntimes.set(o, n), o;
1054
+ return i.id = o, i.originalExit = i._exit, i._exit = function(l) {
1055
+ return loadedRuntimes.delete(o), i.originalExit(l);
1056
+ }, i[RuntimeId] = o, loadedRuntimes.set(o, i), o;
1033
1057
  }
1034
1058
  function getLoadedRuntime(e) {
1035
1059
  return loadedRuntimes.get(e);
@@ -1044,12 +1068,12 @@ const currentJsRuntime = function() {
1044
1068
  return e.unshift(t), e;
1045
1069
  };
1046
1070
  var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = (e, t, r, s) => {
1047
- for (var i = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, n = e.length - 1, o; n >= 0; n--)
1048
- (o = e[n]) && (i = (s ? o(t, r, i) : o(i)) || i);
1049
- return s && i && __defProp(t, r, i), i;
1071
+ for (var n = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, i = e.length - 1, o; i >= 0; i--)
1072
+ (o = e[i]) && (n = (s ? o(t, r, n) : o(n)) || n);
1073
+ return s && n && __defProp(t, r, n), n;
1050
1074
  };
1051
1075
  const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
1052
- var b, C, k, _, w, g, y, B, q, te, O, re, D, se, $, ne, j, ie, z, oe, G, ae, W, le, V, ce, J, ue, Y, de, Z, he;
1076
+ var S, T, A, y, w, g, P, C, N, X, M, ee, q, te, O, re, $, se, D, ne, j, ie, z, oe, W, ae, G, le, V, ce, Q, ue;
1053
1077
  class BasePHP {
1054
1078
  /**
1055
1079
  * Initializes a PHP runtime.
@@ -1059,55 +1083,46 @@ class BasePHP {
1059
1083
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
1060
1084
  */
1061
1085
  constructor(e, t) {
1062
- c(this, q);
1063
- c(this, O);
1064
- c(this, D);
1065
- c(this, $);
1066
- c(this, j);
1067
- c(this, z);
1068
- c(this, G);
1069
- c(this, W);
1070
- c(this, V);
1071
- /**
1072
- * Adds file information to $_FILES superglobal in PHP.
1073
- *
1074
- * In particular:
1075
- * * Creates the file data in the filesystem
1076
- * * Registers the file details in PHP
1077
- *
1078
- * @param fileInfo - File details
1079
- */
1080
- c(this, J);
1081
- c(this, Y);
1082
- c(this, Z);
1083
- c(this, b, void 0);
1084
- c(this, C, void 0);
1085
- c(this, k, void 0);
1086
- c(this, _, void 0);
1087
- c(this, w, void 0);
1088
- c(this, g, void 0);
1089
- c(this, y, void 0);
1090
- c(this, B, void 0);
1091
- u(this, b, []), u(this, _, !1), u(this, w, null), u(this, g, {}), u(this, y, /* @__PURE__ */ new Map()), u(this, B, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
1086
+ u(this, N);
1087
+ u(this, M);
1088
+ u(this, q);
1089
+ u(this, O);
1090
+ u(this, $);
1091
+ u(this, D);
1092
+ u(this, j);
1093
+ u(this, z);
1094
+ u(this, W);
1095
+ u(this, G);
1096
+ u(this, V);
1097
+ u(this, Q);
1098
+ u(this, S, void 0);
1099
+ u(this, T, void 0);
1100
+ u(this, A, void 0);
1101
+ u(this, y, void 0);
1102
+ u(this, w, void 0);
1103
+ u(this, g, void 0);
1104
+ u(this, P, void 0);
1105
+ u(this, C, void 0);
1106
+ h(this, S, []), h(this, y, !1), h(this, w, null), h(this, g, {}), h(this, P, /* @__PURE__ */ new Map()), h(this, C, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
1092
1107
  new PHPRequestHandler(this, t)
1093
1108
  ));
1094
1109
  }
1095
1110
  addEventListener(e, t) {
1096
- a(this, y).has(e) || a(this, y).set(e, /* @__PURE__ */ new Set()), a(this, y).get(e).add(t);
1111
+ a(this, P).has(e) || a(this, P).set(e, /* @__PURE__ */ new Set()), a(this, P).get(e).add(t);
1097
1112
  }
1098
1113
  removeEventListener(e, t) {
1099
1114
  var r;
1100
- (r = a(this, y).get(e)) == null || r.delete(t);
1115
+ (r = a(this, P).get(e)) == null || r.delete(t);
1101
1116
  }
1102
1117
  dispatchEvent(e) {
1103
- const t = a(this, y).get(e.type);
1118
+ const t = a(this, P).get(e.type);
1104
1119
  if (t)
1105
1120
  for (const r of t)
1106
1121
  r(e);
1107
1122
  }
1108
1123
  /** @inheritDoc */
1109
1124
  async onMessage(e) {
1110
- a(this, B).push(e);
1125
+ a(this, C).push(e);
1111
1126
  }
1112
1127
  /** @inheritDoc */
1113
1128
  async setSpawnHandler(handler) {
@@ -1138,13 +1153,13 @@ class BasePHP {
1138
1153
  if (!t)
1139
1154
  throw new Error("Invalid PHP runtime id.");
1140
1155
  this[__private__dont__use] = t, t.onMessage = async (r) => {
1141
- for (const s of a(this, B)) {
1142
- const i = await s(r);
1143
- if (i)
1144
- return i;
1156
+ for (const s of a(this, C)) {
1157
+ const n = await s(r);
1158
+ if (n)
1159
+ return n;
1145
1160
  }
1146
1161
  return "";
1147
- }, u(this, w, improveWASMErrorReporting(t)), this.dispatchEvent({
1162
+ }, h(this, w, improveWASMErrorReporting(t)), this.dispatchEvent({
1148
1163
  type: "runtime.initialized"
1149
1164
  });
1150
1165
  }
@@ -1159,13 +1174,13 @@ class BasePHP {
1159
1174
  throw new Error(
1160
1175
  "Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
1161
1176
  );
1162
- u(this, k, e);
1177
+ h(this, A, e);
1163
1178
  }
1164
1179
  /** @inheritDoc */
1165
1180
  setPhpIniPath(e) {
1166
- if (a(this, _))
1181
+ if (a(this, y))
1167
1182
  throw new Error("Cannot set PHP ini path after calling run().");
1168
- u(this, C, e), this[__private__dont__use].ccall(
1183
+ h(this, T, e), this[__private__dont__use].ccall(
1169
1184
  "wasm_set_phpini_path",
1170
1185
  null,
1171
1186
  ["string"],
@@ -1174,9 +1189,9 @@ class BasePHP {
1174
1189
  }
1175
1190
  /** @inheritDoc */
1176
1191
  setPhpIniEntry(e, t) {
1177
- if (a(this, _))
1192
+ if (a(this, y))
1178
1193
  throw new Error("Cannot set PHP ini entries after calling run().");
1179
- a(this, b).push([e, t]);
1194
+ a(this, S).push([e, t]);
1180
1195
  }
1181
1196
  /** @inheritDoc */
1182
1197
  chdir(e) {
@@ -1193,25 +1208,29 @@ class BasePHP {
1193
1208
  const t = await this.semaphore.acquire();
1194
1209
  let r;
1195
1210
  try {
1196
- a(this, _) || (f(this, q, te).call(this), u(this, _, !0)), f(this, W, le).call(this, e.scriptPath || ""), f(this, D, se).call(this, e.relativeUri || ""), f(this, j, ie).call(this, e.method || "GET");
1197
- const s = normalizeHeaders(e.headers || {}), i = s.host || "example.com:443";
1198
- if (f(this, $, ne).call(this, i, e.protocol || "http"), f(this, z, oe).call(this, s), e.body && (r = f(this, G, ae).call(this, e.body)), e.fileInfos)
1199
- for (const o of e.fileInfos)
1200
- f(this, J, ue).call(this, o);
1201
- typeof e.code == "string" && f(this, Y, de).call(this, " ?>" + e.code), f(this, V, ce).call(this);
1202
- const n = await f(this, Z, he).call(this);
1203
- if (e.throwOnError && n.exitCode !== 0) {
1204
- const o = {
1205
- stdout: n.text,
1206
- stderr: n.errors
1211
+ if (a(this, y) || (f(this, N, X).call(this), h(this, y, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
1212
+ throw new Error(
1213
+ `The script path "${e.scriptPath}" does not exist.`
1214
+ );
1215
+ f(this, z, oe).call(this, e.scriptPath || ""), f(this, q, te).call(this, e.relativeUri || ""), f(this, $, se).call(this, e.method || "GET");
1216
+ const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443";
1217
+ f(this, O, re).call(this, n, e.protocol || "http"), f(this, D, ne).call(this, s), e.body && (r = f(this, j, ie).call(this, e.body)), typeof e.code == "string" && f(this, V, ce).call(this, " ?>" + e.code), f(this, W, ae).call(this);
1218
+ const i = e.env || {};
1219
+ for (const l in i)
1220
+ f(this, G, le).call(this, l, i[l]);
1221
+ const o = await f(this, Q, ue).call(this);
1222
+ if (e.throwOnError && o.exitCode !== 0) {
1223
+ const l = {
1224
+ stdout: o.text,
1225
+ stderr: o.errors
1207
1226
  };
1208
- console.warn("PHP.run() output was:", o);
1209
- const l = new Error(
1210
- `PHP.run() failed with exit code ${n.exitCode} and the following output`
1227
+ console.warn("PHP.run() output was:", l);
1228
+ const c = new Error(
1229
+ `PHP.run() failed with exit code ${o.exitCode} and the following output: ` + o.errors
1211
1230
  );
1212
- throw l.output = o, l;
1231
+ throw c.output = l, console.error(c), c;
1213
1232
  }
1214
- return n;
1233
+ return o;
1215
1234
  } finally {
1216
1235
  try {
1217
1236
  r && this[__private__dont__use].free(r);
@@ -1229,12 +1248,12 @@ class BasePHP {
1229
1248
  let r = {};
1230
1249
  try {
1231
1250
  r = JSON.parse(
1232
- this.fileExists("/tmp/consts.json") && this.readFileAsText("/tmp/consts.json") || "{}"
1251
+ this.fileExists("/internal/consts.json") && this.readFileAsText("/internal/consts.json") || "{}"
1233
1252
  );
1234
1253
  } catch {
1235
1254
  }
1236
1255
  this.writeFile(
1237
- "/tmp/consts.json",
1256
+ "/internal/consts.json",
1238
1257
  JSON.stringify({
1239
1258
  ...r,
1240
1259
  [e]: t
@@ -1288,7 +1307,7 @@ class BasePHP {
1288
1307
  );
1289
1308
  if (t.prependPath) {
1290
1309
  const s = e.replace(/\/$/, "");
1291
- return r.map((i) => `${s}/${i}`);
1310
+ return r.map((n) => `${s}/${n}`);
1292
1311
  }
1293
1312
  return r;
1294
1313
  } catch (r) {
@@ -1319,9 +1338,9 @@ class BasePHP {
1319
1338
  this.exit();
1320
1339
  } catch {
1321
1340
  }
1322
- if (this.initializeRuntime(e), a(this, C) && this.setPhpIniPath(a(this, C)), a(this, k) && this.setSapiName(a(this, k)), this.requestHandler) {
1341
+ if (this.initializeRuntime(e), a(this, T) && this.setPhpIniPath(a(this, T)), a(this, A) && this.setSapiName(a(this, A)), this.requestHandler) {
1323
1342
  const r = this.documentRoot;
1324
- recreateMemFS(this[__private__dont__use].FS, t, r);
1343
+ copyFS(t, this[__private__dont__use].FS, r);
1325
1344
  }
1326
1345
  }
1327
1346
  exit(e = 0) {
@@ -1332,23 +1351,23 @@ class BasePHP {
1332
1351
  this[__private__dont__use]._exit(e);
1333
1352
  } catch {
1334
1353
  }
1335
- u(this, _, !1), u(this, w, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
1354
+ h(this, y, !1), h(this, w, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
1336
1355
  }
1337
1356
  }
1338
- b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w = new WeakMap(), g = new WeakMap(), y = new WeakMap(), B = new WeakMap(), q = new WeakSet(), te = function() {
1339
- if (this.setPhpIniEntry("auto_prepend_file", "/tmp/consts.php"), this.fileExists("/tmp/consts.php") || this.writeFile(
1340
- "/tmp/consts.php",
1357
+ S = new WeakMap(), T = new WeakMap(), A = new WeakMap(), y = new WeakMap(), w = new WeakMap(), g = new WeakMap(), P = new WeakMap(), C = new WeakMap(), N = new WeakSet(), X = function() {
1358
+ if (this.setPhpIniEntry("auto_prepend_file", "/internal/consts.php"), this.fileExists("/internal/consts.php") || this.writeFile(
1359
+ "/internal/consts.php",
1341
1360
  `<?php
1342
- if(file_exists('/tmp/consts.json')) {
1343
- $consts = json_decode(file_get_contents('/tmp/consts.json'), true);
1361
+ if(file_exists('/internal/consts.json')) {
1362
+ $consts = json_decode(file_get_contents('/internal/consts.json'), true);
1344
1363
  foreach ($consts as $const => $value) {
1345
1364
  if (!defined($const) && is_scalar($value)) {
1346
1365
  define($const, $value);
1347
1366
  }
1348
1367
  }
1349
1368
  }`
1350
- ), a(this, b).length > 0) {
1351
- const e = a(this, b).map(([t, r]) => `${t}=${r}`).join(`
1369
+ ), a(this, S).length > 0) {
1370
+ const e = a(this, S).map(([t, r]) => `${t}=${r}`).join(`
1352
1371
  `) + `
1353
1372
 
1354
1373
  `;
@@ -1360,8 +1379,8 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
1360
1379
  );
1361
1380
  }
1362
1381
  this[__private__dont__use].ccall("php_wasm_init", null, [], []);
1363
- }, O = new WeakSet(), re = function() {
1364
- const e = "/tmp/headers.json";
1382
+ }, M = new WeakSet(), ee = function() {
1383
+ const e = "/internal/headers.json";
1365
1384
  if (!this.fileExists(e))
1366
1385
  throw new Error(
1367
1386
  "SAPI Error: Could not find response headers file."
@@ -1370,14 +1389,14 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
1370
1389
  for (const s of t.headers) {
1371
1390
  if (!s.includes(": "))
1372
1391
  continue;
1373
- const i = s.indexOf(": "), n = s.substring(0, i).toLowerCase(), o = s.substring(i + 2);
1374
- n in r || (r[n] = []), r[n].push(o);
1392
+ const n = s.indexOf(": "), i = s.substring(0, n).toLowerCase(), o = s.substring(n + 2);
1393
+ i in r || (r[i] = []), r[i].push(o);
1375
1394
  }
1376
1395
  return {
1377
1396
  headers: r,
1378
1397
  httpStatusCode: t.status
1379
1398
  };
1380
- }, D = new WeakSet(), se = function(e) {
1399
+ }, q = new WeakSet(), te = function(e) {
1381
1400
  if (this[__private__dont__use].ccall(
1382
1401
  "wasm_set_request_uri",
1383
1402
  null,
@@ -1392,7 +1411,7 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
1392
1411
  [t]
1393
1412
  );
1394
1413
  }
1395
- }, $ = new WeakSet(), ne = function(e, t) {
1414
+ }, O = new WeakSet(), re = function(e, t) {
1396
1415
  this[__private__dont__use].ccall(
1397
1416
  "wasm_set_request_host",
1398
1417
  null,
@@ -1410,14 +1429,14 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
1410
1429
  [NUMBER],
1411
1430
  [r]
1412
1431
  ), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
1413
- }, j = new WeakSet(), ie = function(e) {
1432
+ }, $ = new WeakSet(), se = function(e) {
1414
1433
  this[__private__dont__use].ccall(
1415
1434
  "wasm_set_request_method",
1416
1435
  null,
1417
1436
  [STRING],
1418
1437
  [e]
1419
1438
  );
1420
- }, z = new WeakSet(), oe = function(e) {
1439
+ }, D = new WeakSet(), ne = function(e) {
1421
1440
  e.cookie && this[__private__dont__use].ccall(
1422
1441
  "wasm_set_cookies",
1423
1442
  null,
@@ -1441,33 +1460,37 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
1441
1460
  e[t]
1442
1461
  );
1443
1462
  }
1444
- }, G = new WeakSet(), ae = function(e) {
1445
- const t = this[__private__dont__use].lengthBytesUTF8(e), r = this[__private__dont__use].malloc(t + 1);
1446
- if (!r)
1463
+ }, j = new WeakSet(), ie = function(e) {
1464
+ let t, r;
1465
+ typeof e == "string" ? (console.warn(
1466
+ "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"
1467
+ ), r = this[__private__dont__use].lengthBytesUTF8(e), t = r + 1) : (r = e.byteLength, t = e.byteLength);
1468
+ const s = this[__private__dont__use].malloc(t);
1469
+ if (!s)
1447
1470
  throw new Error("Could not allocate memory for the request body.");
1448
- return this[__private__dont__use].stringToUTF8(
1471
+ return typeof e == "string" ? this[__private__dont__use].stringToUTF8(
1449
1472
  e,
1450
- r,
1473
+ s,
1451
1474
  t + 1
1452
- ), this[__private__dont__use].ccall(
1475
+ ) : this[__private__dont__use].HEAPU8.set(e, s), this[__private__dont__use].ccall(
1453
1476
  "wasm_set_request_body",
1454
1477
  null,
1455
1478
  [NUMBER],
1456
- [r]
1479
+ [s]
1457
1480
  ), this[__private__dont__use].ccall(
1458
1481
  "wasm_set_content_length",
1459
1482
  null,
1460
1483
  [NUMBER],
1461
- [new TextEncoder().encode(e).length]
1462
- ), r;
1463
- }, W = new WeakSet(), le = function(e) {
1484
+ [r]
1485
+ ), s;
1486
+ }, z = new WeakSet(), oe = function(e) {
1464
1487
  this[__private__dont__use].ccall(
1465
1488
  "wasm_set_path_translated",
1466
1489
  null,
1467
1490
  [STRING],
1468
1491
  [e]
1469
1492
  );
1470
- }, V = new WeakSet(), ce = function() {
1493
+ }, W = new WeakSet(), ae = function() {
1471
1494
  for (const e in a(this, g))
1472
1495
  this[__private__dont__use].ccall(
1473
1496
  "wasm_add_SERVER_entry",
@@ -1475,33 +1498,31 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
1475
1498
  [STRING, STRING],
1476
1499
  [e, a(this, g)[e]]
1477
1500
  );
1478
- }, J = new WeakSet(), ue = function(e) {
1479
- const { key: t, name: r, type: s, data: i } = e, n = `/tmp/${Math.random().toFixed(20)}`;
1480
- this.writeFile(n, i);
1481
- const o = 0;
1501
+ }, G = new WeakSet(), le = function(e, t) {
1482
1502
  this[__private__dont__use].ccall(
1483
- "wasm_add_uploaded_file",
1503
+ "wasm_add_ENV_entry",
1484
1504
  null,
1485
- [STRING, STRING, STRING, STRING, NUMBER, NUMBER],
1486
- [t, r, s, n, o, i.byteLength]
1505
+ [STRING, STRING],
1506
+ [e, t]
1487
1507
  );
1488
- }, Y = new WeakSet(), de = function(e) {
1508
+ }, V = new WeakSet(), ce = function(e) {
1489
1509
  this[__private__dont__use].ccall(
1490
1510
  "wasm_set_php_code",
1491
1511
  null,
1492
1512
  [STRING],
1493
1513
  [e]
1494
1514
  );
1495
- }, Z = new WeakSet(), he = async function() {
1496
- var i;
1515
+ }, Q = new WeakSet(), ue = async function() {
1516
+ var n;
1497
1517
  let e, t;
1498
1518
  try {
1499
- e = await new Promise((n, o) => {
1500
- var h;
1519
+ e = await new Promise((i, o) => {
1520
+ var c;
1501
1521
  t = (d) => {
1522
+ console.error(d), console.error(d.error);
1502
1523
  const p = new Error("Rethrown");
1503
1524
  p.cause = d.error, p.betterMessage = d.message, o(p);
1504
- }, (h = a(this, w)) == null || h.addEventListener(
1525
+ }, (c = a(this, w)) == null || c.addEventListener(
1505
1526
  "error",
1506
1527
  t
1507
1528
  );
@@ -1512,9 +1533,9 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
1512
1533
  [],
1513
1534
  { async: !0 }
1514
1535
  );
1515
- return l instanceof Promise ? l.then(n, o) : n(l);
1536
+ return l instanceof Promise ? l.then(i, o) : i(l);
1516
1537
  });
1517
- } catch (n) {
1538
+ } catch (i) {
1518
1539
  for (const d in this)
1519
1540
  typeof this[d] == "function" && (this[d] = () => {
1520
1541
  throw new Error(
@@ -1522,17 +1543,17 @@ b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), w =
1522
1543
  );
1523
1544
  });
1524
1545
  this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
1525
- const o = n, l = "betterMessage" in o ? o.betterMessage : o.message, h = new Error(l);
1526
- throw h.cause = o, h;
1546
+ const o = i, l = "betterMessage" in o ? o.betterMessage : o.message, c = new Error(l);
1547
+ throw c.cause = o, console.error(c), c;
1527
1548
  } finally {
1528
- (i = a(this, w)) == null || i.removeEventListener("error", t), u(this, g, {});
1549
+ (n = a(this, w)) == null || n.removeEventListener("error", t), h(this, g, {});
1529
1550
  }
1530
- const { headers: r, httpStatusCode: s } = f(this, O, re).call(this);
1551
+ const { headers: r, httpStatusCode: s } = f(this, M, ee).call(this);
1531
1552
  return new PHPResponse(
1532
1553
  s,
1533
1554
  r,
1534
- this.readFileAsBuffer("/tmp/stdout"),
1535
- this.readFileAsText("/tmp/stderr"),
1555
+ this.readFileAsBuffer("/internal/stdout"),
1556
+ this.readFileAsText("/internal/stderr"),
1536
1557
  e
1537
1558
  );
1538
1559
  };
@@ -1572,28 +1593,23 @@ function normalizeHeaders(e) {
1572
1593
  t[r.toLowerCase()] = e[r];
1573
1594
  return t;
1574
1595
  }
1575
- function recreateMemFS(e, t, r) {
1596
+ function copyFS(e, t, r) {
1576
1597
  let s;
1577
1598
  try {
1578
- s = t.lookupPath(r);
1599
+ s = e.lookupPath(r);
1579
1600
  } catch {
1580
1601
  return;
1581
1602
  }
1582
1603
  if (!("contents" in s.node))
1583
1604
  return;
1584
- try {
1585
- e = e.lookupPath(r);
1586
- return;
1587
- } catch {
1588
- }
1589
- if (!t.isDir(s.node.mode)) {
1590
- e.writeFile(r, t.readFile(r));
1605
+ if (!e.isDir(s.node.mode)) {
1606
+ t.writeFile(r, e.readFile(r));
1591
1607
  return;
1592
1608
  }
1593
- e.mkdirTree(r);
1594
- const i = t.readdir(r).filter((n) => n !== "." && n !== "..");
1595
- for (const n of i)
1596
- recreateMemFS(e, t, joinPaths(r, n));
1609
+ t.mkdirTree(r);
1610
+ const n = e.readdir(r).filter((i) => i !== "." && i !== "..");
1611
+ for (const i of n)
1612
+ copyFS(e, t, joinPaths(r, i));
1597
1613
  }
1598
1614
  function isLocalPHP(e) {
1599
1615
  return !(e instanceof BasePHP);
@@ -1607,26 +1623,26 @@ function rotatePHPRuntime({
1607
1623
  maxRequests: r
1608
1624
  }) {
1609
1625
  let s = 0;
1610
- async function i() {
1626
+ async function n() {
1611
1627
  if (++s < r)
1612
1628
  return;
1613
1629
  s = 0;
1614
- const n = await e.semaphore.acquire();
1630
+ const i = await e.semaphore.acquire();
1615
1631
  try {
1616
1632
  e.hotSwapPHPRuntime(await t());
1617
1633
  } finally {
1618
- n();
1634
+ i();
1619
1635
  }
1620
1636
  }
1621
- return e.addEventListener("request.end", i), function() {
1622
- e.removeEventListener("request.end", i);
1637
+ return e.addEventListener("request.end", n), function() {
1638
+ e.removeEventListener("request.end", n);
1623
1639
  };
1624
1640
  }
1625
1641
  async function writeFiles(e, t, r, { rmRoot: s = !1 } = {}) {
1626
1642
  s && await e.isDir(t) && await e.rmdir(t, { recursive: !0 });
1627
- for (const [i, n] of Object.entries(r)) {
1628
- const o = joinPaths(t, i);
1629
- await e.fileExists(dirname(o)) || await e.mkdir(dirname(o)), await e.writeFile(o, n);
1643
+ for (const [n, i] of Object.entries(r)) {
1644
+ const o = joinPaths(t, n);
1645
+ await e.fileExists(dirname(o)) || await e.mkdir(dirname(o)), await e.writeFile(o, i);
1630
1646
  }
1631
1647
  }
1632
1648
  export {