@php-wasm/web 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.
Files changed (39) hide show
  1. package/index.d.ts +9 -22
  2. package/index.js +362 -346
  3. package/kitchen-sink/7_0_33/php_7_0.wasm +0 -0
  4. package/kitchen-sink/7_1_30/php_7_1.wasm +0 -0
  5. package/kitchen-sink/7_2_34/php_7_2.wasm +0 -0
  6. package/kitchen-sink/7_3_33/php_7_3.wasm +0 -0
  7. package/kitchen-sink/7_4_33/php_7_4.wasm +0 -0
  8. package/kitchen-sink/8_0_30/php_8_0.wasm +0 -0
  9. package/kitchen-sink/8_1_23/php_8_1.wasm +0 -0
  10. package/kitchen-sink/8_2_10/php_8_2.wasm +0 -0
  11. package/kitchen-sink/8_3_0/php_8_3.wasm +0 -0
  12. package/kitchen-sink/php_7_0.js +20 -3
  13. package/kitchen-sink/php_7_1.js +20 -3
  14. package/kitchen-sink/php_7_2.js +20 -3
  15. package/kitchen-sink/php_7_3.js +20 -3
  16. package/kitchen-sink/php_7_4.js +20 -3
  17. package/kitchen-sink/php_8_0.js +20 -3
  18. package/kitchen-sink/php_8_1.js +20 -3
  19. package/kitchen-sink/php_8_2.js +20 -3
  20. package/kitchen-sink/php_8_3.js +20 -3
  21. package/light/7_0_33/php_7_0.wasm +0 -0
  22. package/light/7_1_30/php_7_1.wasm +0 -0
  23. package/light/7_2_34/php_7_2.wasm +0 -0
  24. package/light/7_3_33/php_7_3.wasm +0 -0
  25. package/light/7_4_33/php_7_4.wasm +0 -0
  26. package/light/8_0_30/php_8_0.wasm +0 -0
  27. package/light/8_1_23/php_8_1.wasm +0 -0
  28. package/light/8_2_10/php_8_2.wasm +0 -0
  29. package/light/8_3_0/php_8_3.wasm +0 -0
  30. package/light/php_7_0.js +20 -3
  31. package/light/php_7_1.js +20 -3
  32. package/light/php_7_2.js +20 -3
  33. package/light/php_7_3.js +20 -3
  34. package/light/php_7_4.js +20 -3
  35. package/light/php_8_0.js +20 -3
  36. package/light/php_8_1.js +20 -3
  37. package/light/php_8_2.js +20 -3
  38. package/light/php_8_3.js +20 -3
  39. package/package.json +5 -5
package/index.js CHANGED
@@ -1,19 +1,19 @@
1
- var Q = (e, t, r) => {
1
+ var K = (e, t, r) => {
2
2
  if (!t.has(e))
3
3
  throw TypeError("Cannot " + r);
4
4
  };
5
- var l = (e, t, r) => (Q(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => {
5
+ var c = (e, t, r) => (K(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (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
- }, p = (e, t, r, s) => (Q(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
10
- var m = (e, t, r) => (Q(e, t, "access private method"), r);
9
+ }, p = (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);
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 o;
16
+ n != null && n.lastModified && (o = /* @__PURE__ */ new Date()), (!o || isNaN(o.getFullYear())) && (o = /* @__PURE__ */ new Date()), this.lastModifiedDate = o, this.lastModified = o.getMilliseconds(), this.name = s || "";
17
17
  }
18
18
  }
19
19
  global.File = e;
@@ -50,9 +50,9 @@ 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);
54
- new Uint8Array(s.buffer).set(o);
55
- const a = o.byteLength;
53
+ const s = r.byobRequest.view, o = await t.slice(e, e + s.byteLength).arrayBuffer(), i = new Uint8Array(o);
54
+ new Uint8Array(s.buffer).set(i);
55
+ const a = i.byteLength;
56
56
  r.byobRequest.respond(a), e += a, e >= t.size && r.close();
57
57
  }
58
58
  });
@@ -114,27 +114,27 @@ 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 o;
119
119
  try {
120
- return s(...i);
121
- } catch (o) {
122
- if (!(o instanceof Error))
123
- throw o;
120
+ return s(...n);
121
+ } catch (i) {
122
+ if (!(i instanceof Error))
123
+ throw i;
124
124
  const a = clarifyErrorMessage(
125
- o,
126
- (n = e.lastAsyncifyStackSource) == null ? void 0 : n.stack
125
+ i,
126
+ (o = e.lastAsyncifyStackSource) == null ? void 0 : o.stack
127
127
  );
128
- if (e.lastAsyncifyStackSource && (o.cause = e.lastAsyncifyStackSource), t.hasListeners()) {
128
+ if (e.lastAsyncifyStackSource && (i.cause = e.lastAsyncifyStackSource), t.hasListeners()) {
129
129
  t.dispatchEvent(
130
130
  new ErrorEvent("error", {
131
- error: o,
131
+ error: i,
132
132
  message: a
133
133
  })
134
134
  );
135
135
  return;
136
136
  }
137
- throw isExitCodeZero(o) || showCriticalErrorBox(a), o;
137
+ throw isExitCodeZero(i) || showCriticalErrorBox(a), i;
138
138
  }
139
139
  };
140
140
  }
@@ -259,20 +259,39 @@ function normalizePath(e) {
259
259
  function normalizePathsArray(e, t) {
260
260
  let r = 0;
261
261
  for (let s = e.length - 1; s >= 0; s--) {
262
- const i = e[s];
263
- i === "." ? e.splice(s, 1) : i === ".." ? (e.splice(s, 1), r++) : r && (e.splice(s, 1), r--);
262
+ const n = e[s];
263
+ n === "." ? e.splice(s, 1) : n === ".." ? (e.splice(s, 1), r++) : r && (e.splice(s, 1), r--);
264
264
  }
265
265
  if (t)
266
266
  for (; r; r--)
267
267
  e.unshift("..");
268
268
  return e;
269
269
  }
270
+ function splitShellCommand(e) {
271
+ let s = 0, n = "";
272
+ const o = [];
273
+ let i = "";
274
+ for (let a = 0; a < e.length; a++) {
275
+ const l = e[a];
276
+ l === "\\" ? ((e[a + 1] === '"' || e[a + 1] === "'") && a++, i += e[a]) : s === 0 ? l === '"' || l === "'" ? (s = 1, n = l) : l.match(/\s/) ? (i.trim().length && o.push(i.trim()), i = l) : o.length && !i ? i = o.pop() + l : i += l : s === 1 && (l === n ? (s = 0, n = "") : i += l);
277
+ }
278
+ return i && o.push(i.trim()), o;
279
+ }
270
280
  function createSpawnHandler(e) {
271
- return function(t) {
272
- const r = new ChildProcess(), s = new ProcessApi(r);
281
+ return function(t, r = [], s = {}) {
282
+ const n = new ChildProcess(), o = new ProcessApi(n);
273
283
  return setTimeout(async () => {
274
- await e(t, s), r.emit("spawn", !0);
275
- }), r;
284
+ let i = [];
285
+ if (r.length)
286
+ i = [t, ...r];
287
+ else if (typeof t == "string")
288
+ i = splitShellCommand(t);
289
+ else if (Array.isArray(t))
290
+ i = t;
291
+ else
292
+ throw new Error("Invalid command ", t);
293
+ await e(i, o, s), n.emit("spawn", !0);
294
+ }), n;
276
295
  };
277
296
  }
278
297
  class EventEmitter {
@@ -297,9 +316,15 @@ class ProcessApi extends EventEmitter {
297
316
  stdout(t) {
298
317
  typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stdout.emit("data", t);
299
318
  }
319
+ stdoutEnd() {
320
+ this.childProcess.stdout.emit("end", {});
321
+ }
300
322
  stderr(t) {
301
323
  typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stderr.emit("data", t);
302
324
  }
325
+ stderrEnd() {
326
+ this.childProcess.stderr.emit("end", {});
327
+ }
303
328
  exit(t) {
304
329
  this.exited || (this.exited = !0, this.childProcess.emit("exit", t));
305
330
  }
@@ -337,8 +362,8 @@ ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symb
337
362
  }, ReadableStream.prototype.iterate = // @ts-ignore
338
363
  ReadableStream.prototype[Symbol.asyncIterator]);
339
364
  class PHPResponse {
340
- constructor(t, r, s, i = "", n = 0) {
341
- this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = n, this.errors = i;
365
+ constructor(t, r, s, n = "", o = 0) {
366
+ this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = o, this.errors = n;
342
367
  }
343
368
  static fromRawData(t) {
344
369
  return new PHPResponse(
@@ -382,16 +407,16 @@ const SupportedPHPVersions = [
382
407
  "7.1",
383
408
  "7.0"
384
409
  ], LatestSupportedPHPVersion = SupportedPHPVersions[0];
385
- var R, H;
410
+ var b, T;
386
411
  class PHPBrowser {
387
412
  /**
388
413
  * @param server - The PHP server to browse.
389
414
  * @param config - The browser configuration.
390
415
  */
391
416
  constructor(t, r = {}) {
392
- d(this, R, void 0);
393
- d(this, H, void 0);
394
- this.requestHandler = t, p(this, R, {}), p(this, H, {
417
+ d(this, b, void 0);
418
+ d(this, T, void 0);
419
+ this.requestHandler = t, p(this, b, {}), p(this, T, {
395
420
  handleRedirects: !1,
396
421
  maxRedirects: 4,
397
422
  ...r
@@ -419,14 +444,14 @@ class PHPBrowser {
419
444
  cookie: this.serializeCookies()
420
445
  }
421
446
  });
422
- if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), l(this, H).handleRedirects && s.headers.location && r < l(this, H).maxRedirects) {
423
- const i = new URL(
447
+ if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), c(this, T).handleRedirects && s.headers.location && r < c(this, T).maxRedirects) {
448
+ const n = new URL(
424
449
  s.headers.location[0],
425
450
  this.requestHandler.absoluteUrl
426
451
  );
427
452
  return this.request(
428
453
  {
429
- url: i.toString(),
454
+ url: n.toString(),
430
455
  method: "GET",
431
456
  headers: {}
432
457
  },
@@ -456,20 +481,20 @@ class PHPBrowser {
456
481
  try {
457
482
  if (!r.includes("="))
458
483
  continue;
459
- const s = r.indexOf("="), i = r.substring(0, s), n = r.substring(s + 1).split(";")[0];
460
- l(this, R)[i] = n;
484
+ const s = r.indexOf("="), n = r.substring(0, s), o = r.substring(s + 1).split(";")[0];
485
+ c(this, b)[n] = o;
461
486
  } catch (s) {
462
487
  console.error(s);
463
488
  }
464
489
  }
465
490
  serializeCookies() {
466
491
  const t = [];
467
- for (const r in l(this, R))
468
- t.push(`${r}=${l(this, R)[r]}`);
492
+ for (const r in c(this, b))
493
+ t.push(`${r}=${c(this, b)[r]}`);
469
494
  return t.join("; ");
470
495
  }
471
496
  }
472
- R = new WeakMap(), H = new WeakMap();
497
+ b = new WeakMap(), T = new WeakMap();
473
498
  const DEFAULT_BASE_URL = "http://example.com";
474
499
  function toRelativeUrl(e) {
475
500
  return e.toString().substring(e.origin.length);
@@ -480,7 +505,35 @@ function removePathPrefix(e, t) {
480
505
  function ensurePathPrefix(e, t) {
481
506
  return !t || e.startsWith(t) ? e : t + e;
482
507
  }
483
- var E, k, L, S, C, g, F, x, N, Z, U, X, B, ee;
508
+ async function encodeAsMultipart(e) {
509
+ const t = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${t}`, s = new TextEncoder(), n = [];
510
+ for (const [l, u] of Object.entries(e))
511
+ n.push(`--${t}\r
512
+ `), n.push(`Content-Disposition: form-data; name="${l}"`), u instanceof File && n.push(`; filename="${u.name}"`), n.push(`\r
513
+ `), u instanceof File && (n.push("Content-Type: application/octet-stream"), n.push(`\r
514
+ `)), n.push(`\r
515
+ `), u instanceof File ? n.push(await fileToUint8Array(u)) : n.push(u), n.push(`\r
516
+ `);
517
+ n.push(`--${t}--\r
518
+ `);
519
+ const o = n.reduce((l, u) => l + u.length, 0), i = new Uint8Array(o);
520
+ let a = 0;
521
+ for (const l of n)
522
+ i.set(
523
+ typeof l == "string" ? s.encode(l) : l,
524
+ a
525
+ ), a += l.length;
526
+ return { bytes: i, contentType: r };
527
+ }
528
+ function fileToUint8Array(e) {
529
+ return new Promise((t) => {
530
+ const r = new FileReader();
531
+ r.onload = () => {
532
+ t(new Uint8Array(r.result));
533
+ }, r.readAsArrayBuffer(e);
534
+ });
535
+ }
536
+ var g, H, L, R, k, y, C, S, N, Z, U, X, O, ee;
484
537
  class PHPRequestHandler {
485
538
  /**
486
539
  * @param php - The PHP instance.
@@ -511,31 +564,31 @@ class PHPRequestHandler {
511
564
  * @throws {Error} If the requested path doesn't exist.
512
565
  * @returns The resolved filesystem path.
513
566
  */
514
- d(this, B);
515
- d(this, E, void 0);
516
- d(this, k, void 0);
567
+ d(this, O);
568
+ d(this, g, void 0);
569
+ d(this, H, void 0);
517
570
  d(this, L, void 0);
518
- d(this, S, void 0);
571
+ d(this, R, void 0);
572
+ d(this, k, void 0);
573
+ d(this, y, void 0);
519
574
  d(this, C, void 0);
520
- d(this, g, void 0);
521
- d(this, F, void 0);
522
- d(this, x, void 0);
523
- p(this, x, new Semaphore({ concurrency: 1 }));
575
+ d(this, S, void 0);
576
+ p(this, S, new Semaphore({ concurrency: 1 }));
524
577
  const {
525
578
  documentRoot: s = "/www/",
526
- absoluteUrl: i = typeof location == "object" ? location == null ? void 0 : location.href : ""
579
+ absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : ""
527
580
  } = r;
528
- this.php = t, p(this, E, s);
529
- const n = new URL(i);
530
- p(this, L, n.hostname), p(this, S, n.port ? Number(n.port) : n.protocol === "https:" ? 443 : 80), p(this, k, (n.protocol || "").replace(":", ""));
531
- const o = l(this, S) !== 443 && l(this, S) !== 80;
532
- p(this, C, [
533
- l(this, L),
534
- o ? `:${l(this, S)}` : ""
535
- ].join("")), p(this, g, n.pathname.replace(/\/+$/, "")), p(this, F, [
536
- `${l(this, k)}://`,
537
- l(this, C),
538
- l(this, g)
581
+ this.php = t, p(this, g, s);
582
+ const o = new URL(n);
583
+ p(this, L, o.hostname), p(this, R, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), p(this, H, (o.protocol || "").replace(":", ""));
584
+ const i = c(this, R) !== 443 && c(this, R) !== 80;
585
+ p(this, k, [
586
+ c(this, L),
587
+ i ? `:${c(this, R)}` : ""
588
+ ].join("")), p(this, y, o.pathname.replace(/\/+$/, "")), p(this, C, [
589
+ `${c(this, H)}://`,
590
+ c(this, k),
591
+ c(this, y)
539
592
  ].join(""));
540
593
  }
541
594
  /** @inheritDoc */
@@ -545,32 +598,32 @@ class PHPRequestHandler {
545
598
  /** @inheritDoc */
546
599
  internalUrlToPath(t) {
547
600
  const r = new URL(t);
548
- return r.pathname.startsWith(l(this, g)) && (r.pathname = r.pathname.slice(l(this, g).length)), toRelativeUrl(r);
601
+ return r.pathname.startsWith(c(this, y)) && (r.pathname = r.pathname.slice(c(this, y).length)), toRelativeUrl(r);
549
602
  }
550
603
  get isRequestRunning() {
551
- return l(this, x).running > 0;
604
+ return c(this, S).running > 0;
552
605
  }
553
606
  /** @inheritDoc */
554
607
  get absoluteUrl() {
555
- return l(this, F);
608
+ return c(this, C);
556
609
  }
557
610
  /** @inheritDoc */
558
611
  get documentRoot() {
559
- return l(this, E);
612
+ return c(this, g);
560
613
  }
561
614
  /** @inheritDoc */
562
615
  async request(t) {
563
616
  const r = t.url.startsWith("http://") || t.url.startsWith("https://"), s = new URL(
564
617
  t.url,
565
618
  r ? void 0 : DEFAULT_BASE_URL
566
- ), i = removePathPrefix(
619
+ ), n = removePathPrefix(
567
620
  s.pathname,
568
- l(this, g)
569
- ), n = `${l(this, E)}${i}`;
570
- return seemsLikeAPHPRequestHandlerPath(n) ? await m(this, U, X).call(this, t, s) : m(this, N, Z).call(this, n);
621
+ c(this, y)
622
+ ), o = `${c(this, g)}${n}`;
623
+ return seemsLikeAPHPRequestHandlerPath(o) ? await f(this, U, X).call(this, t, s) : f(this, N, Z).call(this, o);
571
624
  }
572
625
  }
573
- E = new WeakMap(), k = new WeakMap(), L = new WeakMap(), S = new WeakMap(), C = new WeakMap(), g = new WeakMap(), F = new WeakMap(), x = new WeakMap(), N = new WeakSet(), Z = function(t) {
626
+ g = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k = new WeakMap(), y = new WeakMap(), C = new WeakMap(), S = new WeakMap(), N = new WeakSet(), Z = function(t) {
574
627
  if (!this.php.fileExists(t))
575
628
  return new PHPResponse(
576
629
  404,
@@ -596,8 +649,8 @@ E = new WeakMap(), k = new WeakMap(), L = new WeakMap(), S = new WeakMap(), C =
596
649
  r
597
650
  );
598
651
  }, U = new WeakSet(), X = async function(t, r) {
599
- var i, n, o;
600
- if (l(this, x).running > 0 && ((i = t.headers) == null ? void 0 : i["x-request-issuer"]) === "php")
652
+ var n, o;
653
+ if (c(this, S).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
601
654
  return console.warn(
602
655
  "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."
603
656
  ), new PHPResponse(
@@ -605,47 +658,34 @@ E = new WeakMap(), k = new WeakMap(), L = new WeakMap(), S = new WeakMap(), C =
605
658
  {},
606
659
  new TextEncoder().encode("502 Bad Gateway")
607
660
  );
608
- const s = await l(this, x).acquire();
661
+ const s = await c(this, S).acquire();
609
662
  try {
610
- this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", l(this, E)), this.php.addServerGlobalEntry(
663
+ this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", c(this, g)), this.php.addServerGlobalEntry(
611
664
  "HTTPS",
612
- l(this, F).startsWith("https://") ? "on" : ""
665
+ c(this, C).startsWith("https://") ? "on" : ""
613
666
  );
614
- let a = "GET";
615
- const u = {
616
- host: l(this, C),
667
+ let i = "GET";
668
+ const a = {
669
+ host: c(this, k),
617
670
  ...normalizeHeaders(t.headers || {})
618
- }, c = [];
619
- if (t.files && Object.keys(t.files).length) {
620
- a = "POST";
621
- for (const f in t.files) {
622
- const y = t.files[f];
623
- c.push({
624
- key: f,
625
- name: y.name,
626
- type: y.type,
627
- data: new Uint8Array(await y.arrayBuffer())
628
- });
629
- }
630
- (n = u["content-type"]) != null && n.startsWith("multipart/form-data") && (t.formData = parseMultipartFormDataString(
631
- t.body || ""
632
- ), u["content-type"] = "application/x-www-form-urlencoded", delete t.body);
671
+ };
672
+ let l = t.body;
673
+ if (typeof l == "object" && !(l instanceof Uint8Array)) {
674
+ i = "POST";
675
+ const { bytes: h, contentType: m } = await encodeAsMultipart(l);
676
+ l = h, a["content-type"] = m;
633
677
  }
634
- let h;
635
- t.formData !== void 0 ? (a = "POST", u["content-type"] = u["content-type"] || "application/x-www-form-urlencoded", h = new URLSearchParams(
636
- t.formData
637
- ).toString()) : h = t.body;
638
- let _;
678
+ let u;
639
679
  try {
640
- let f = r.pathname;
680
+ let h = r.pathname;
641
681
  if ((o = t.headers) != null && o["x-rewrite-url"])
642
682
  try {
643
- f = new URL(
683
+ h = new URL(
644
684
  t.headers["x-rewrite-url"]
645
685
  ).pathname;
646
686
  } catch {
647
687
  }
648
- _ = m(this, B, ee).call(this, f);
688
+ u = f(this, O, ee).call(this, h);
649
689
  } catch {
650
690
  return new PHPResponse(
651
691
  404,
@@ -656,41 +696,25 @@ E = new WeakMap(), k = new WeakMap(), L = new WeakMap(), S = new WeakMap(), C =
656
696
  return await this.php.run({
657
697
  relativeUri: ensurePathPrefix(
658
698
  toRelativeUrl(r),
659
- l(this, g)
699
+ c(this, y)
660
700
  ),
661
- protocol: l(this, k),
662
- method: t.method || a,
663
- body: h,
664
- fileInfos: c,
665
- scriptPath: _,
666
- headers: u
701
+ protocol: c(this, H),
702
+ method: t.method || i,
703
+ body: l,
704
+ scriptPath: u,
705
+ headers: a
667
706
  });
668
707
  } finally {
669
708
  s();
670
709
  }
671
- }, B = new WeakSet(), ee = function(t) {
672
- let r = removePathPrefix(t, l(this, g));
673
- r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
674
- const s = `${l(this, E)}${r}`;
710
+ }, O = new WeakSet(), ee = function(t) {
711
+ let r = removePathPrefix(t, c(this, y));
712
+ r.includes(".php") ? r = r.split(".php")[0] + ".php" : this.php.isDir(`${c(this, g)}${r}`) ? (r.endsWith("/") || (r = `${r}/`), r = `${r}index.php`) : r = "/index.php";
713
+ const s = `${c(this, g)}${r}`;
675
714
  if (this.php.fileExists(s))
676
715
  return s;
677
716
  throw new Error(`File not found: ${s}`);
678
717
  };
679
- function parseMultipartFormDataString(e) {
680
- const t = {}, r = e.match(/--(.*)\r\n/);
681
- if (!r)
682
- return t;
683
- const s = r[1], i = e.split(`--${s}`);
684
- return i.shift(), i.pop(), i.forEach((n) => {
685
- const o = n.indexOf(`\r
686
- \r
687
- `), a = n.substring(0, o).trim(), u = n.substring(o + 4).trim(), c = a.match(/name="([^"]+)"/);
688
- if (c) {
689
- const h = c[1];
690
- t[h] = u;
691
- }
692
- }), t;
693
- }
694
718
  function inferMimeType(e) {
695
719
  switch (e.split(".").pop()) {
696
720
  case "css":
@@ -825,16 +849,16 @@ function getEmscriptenFsError(e) {
825
849
  return FileErrorCodes[t];
826
850
  }
827
851
  function rethrowFileSystemError(e = "") {
828
- return function(r, s, i) {
829
- const n = i.value;
830
- i.value = function(...o) {
852
+ return function(r, s, n) {
853
+ const o = n.value;
854
+ n.value = function(...i) {
831
855
  try {
832
- return n.apply(this, o);
856
+ return o.apply(this, i);
833
857
  } catch (a) {
834
- const u = typeof a == "object" ? a == null ? void 0 : a.errno : null;
835
- if (u in FileErrorCodes) {
836
- const c = FileErrorCodes[u], h = typeof o[0] == "string" ? o[0] : null, _ = h !== null ? e.replaceAll("{path}", h) : e;
837
- throw new Error(`${_}: ${c}`, {
858
+ const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
859
+ if (l in FileErrorCodes) {
860
+ const u = FileErrorCodes[l], h = typeof i[0] == "string" ? i[0] : null, m = h !== null ? e.replaceAll("{path}", h) : e;
861
+ throw new Error(`${m}: ${u}`, {
838
862
  cause: a
839
863
  });
840
864
  }
@@ -846,9 +870,9 @@ function rethrowFileSystemError(e = "") {
846
870
  const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map();
847
871
  let lastRuntimeId = 0;
848
872
  async function loadPHPRuntime(e, t = {}) {
849
- const [r, s, i] = makePromise(), n = e.init(currentJsRuntime, {
873
+ const [r, s, n] = makePromise(), o = e.init(currentJsRuntime, {
850
874
  onAbort(a) {
851
- i(a), console.error(a);
875
+ n(a), console.error(a);
852
876
  },
853
877
  ENV: {},
854
878
  // Emscripten sometimes prepends a '/' to the path, which
@@ -862,10 +886,10 @@ async function loadPHPRuntime(e, t = {}) {
862
886
  }
863
887
  });
864
888
  await r;
865
- const o = ++lastRuntimeId;
866
- return n.id = o, n.originalExit = n._exit, n._exit = function(a) {
867
- return loadedRuntimes.delete(o), n.originalExit(a);
868
- }, n[RuntimeId] = o, loadedRuntimes.set(o, n), o;
889
+ const i = ++lastRuntimeId;
890
+ return o.id = i, o.originalExit = o._exit, o._exit = function(a) {
891
+ return loadedRuntimes.delete(i), o.originalExit(a);
892
+ }, o[RuntimeId] = i, loadedRuntimes.set(i, o), i;
869
893
  }
870
894
  function getLoadedRuntime(e) {
871
895
  return loadedRuntimes.get(e);
@@ -880,12 +904,12 @@ const currentJsRuntime = function() {
880
904
  return e.unshift(t), e;
881
905
  };
882
906
  var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = (e, t, r, s) => {
883
- for (var i = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, n = e.length - 1, o; n >= 0; n--)
884
- (o = e[n]) && (i = (s ? o(t, r, i) : o(i)) || i);
885
- return s && i && __defProp(t, r, i), i;
907
+ for (var n = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, o = e.length - 1, i; o >= 0; o--)
908
+ (i = e[o]) && (n = (s ? i(t, r, n) : i(n)) || n);
909
+ return s && n && __defProp(t, r, n), n;
886
910
  };
887
911
  const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
888
- var T, M, I, w, v, b, P, A, O, te, W, re, q, se, z, ne, D, ie, $, oe, j, ae, G, le, V, ce, Y, ue, J, de, K, he;
912
+ var x, F, A, w, E, v, P, M, B, te, W, re, q, se, D, ne, $, ie, z, oe, j, ae, G, le, V, ce, Q, ue, Y, de, J, he;
889
913
  class BasePHP {
890
914
  /**
891
915
  * Initializes a PHP runtime.
@@ -895,55 +919,46 @@ class BasePHP {
895
919
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
896
920
  */
897
921
  constructor(e, t) {
898
- d(this, O);
922
+ d(this, B);
899
923
  d(this, W);
900
924
  d(this, q);
901
- d(this, z);
902
925
  d(this, D);
903
926
  d(this, $);
927
+ d(this, z);
904
928
  d(this, j);
905
929
  d(this, G);
906
930
  d(this, V);
907
- /**
908
- * Adds file information to $_FILES superglobal in PHP.
909
- *
910
- * In particular:
911
- * * Creates the file data in the filesystem
912
- * * Registers the file details in PHP
913
- *
914
- * @param fileInfo - File details
915
- */
931
+ d(this, Q);
916
932
  d(this, Y);
917
933
  d(this, J);
918
- d(this, K);
919
- d(this, T, void 0);
920
- d(this, M, void 0);
921
- d(this, I, void 0);
934
+ d(this, x, void 0);
935
+ d(this, F, void 0);
936
+ d(this, A, void 0);
922
937
  d(this, w, void 0);
938
+ d(this, E, void 0);
923
939
  d(this, v, void 0);
924
- d(this, b, void 0);
925
940
  d(this, P, void 0);
926
- d(this, A, void 0);
927
- p(this, T, []), p(this, w, !1), p(this, v, null), p(this, b, {}), p(this, P, /* @__PURE__ */ new Map()), p(this, A, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
941
+ d(this, M, void 0);
942
+ p(this, x, []), p(this, w, !1), p(this, E, null), p(this, v, {}), p(this, P, /* @__PURE__ */ new Map()), p(this, M, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
928
943
  new PHPRequestHandler(this, t)
929
944
  ));
930
945
  }
931
946
  addEventListener(e, t) {
932
- l(this, P).has(e) || l(this, P).set(e, /* @__PURE__ */ new Set()), l(this, P).get(e).add(t);
947
+ c(this, P).has(e) || c(this, P).set(e, /* @__PURE__ */ new Set()), c(this, P).get(e).add(t);
933
948
  }
934
949
  removeEventListener(e, t) {
935
950
  var r;
936
- (r = l(this, P).get(e)) == null || r.delete(t);
951
+ (r = c(this, P).get(e)) == null || r.delete(t);
937
952
  }
938
953
  dispatchEvent(e) {
939
- const t = l(this, P).get(e.type);
954
+ const t = c(this, P).get(e.type);
940
955
  if (t)
941
956
  for (const r of t)
942
957
  r(e);
943
958
  }
944
959
  /** @inheritDoc */
945
960
  async onMessage(e) {
946
- l(this, A).push(e);
961
+ c(this, M).push(e);
947
962
  }
948
963
  /** @inheritDoc */
949
964
  async setSpawnHandler(handler) {
@@ -974,13 +989,13 @@ class BasePHP {
974
989
  if (!t)
975
990
  throw new Error("Invalid PHP runtime id.");
976
991
  this[__private__dont__use] = t, t.onMessage = async (r) => {
977
- for (const s of l(this, A)) {
978
- const i = await s(r);
979
- if (i)
980
- return i;
992
+ for (const s of c(this, M)) {
993
+ const n = await s(r);
994
+ if (n)
995
+ return n;
981
996
  }
982
997
  return "";
983
- }, p(this, v, improveWASMErrorReporting(t)), this.dispatchEvent({
998
+ }, p(this, E, improveWASMErrorReporting(t)), this.dispatchEvent({
984
999
  type: "runtime.initialized"
985
1000
  });
986
1001
  }
@@ -995,13 +1010,13 @@ class BasePHP {
995
1010
  throw new Error(
996
1011
  "Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
997
1012
  );
998
- p(this, I, e);
1013
+ p(this, A, e);
999
1014
  }
1000
1015
  /** @inheritDoc */
1001
1016
  setPhpIniPath(e) {
1002
- if (l(this, w))
1017
+ if (c(this, w))
1003
1018
  throw new Error("Cannot set PHP ini path after calling run().");
1004
- p(this, M, e), this[__private__dont__use].ccall(
1019
+ p(this, F, e), this[__private__dont__use].ccall(
1005
1020
  "wasm_set_phpini_path",
1006
1021
  null,
1007
1022
  ["string"],
@@ -1010,9 +1025,9 @@ class BasePHP {
1010
1025
  }
1011
1026
  /** @inheritDoc */
1012
1027
  setPhpIniEntry(e, t) {
1013
- if (l(this, w))
1028
+ if (c(this, w))
1014
1029
  throw new Error("Cannot set PHP ini entries after calling run().");
1015
- l(this, T).push([e, t]);
1030
+ c(this, x).push([e, t]);
1016
1031
  }
1017
1032
  /** @inheritDoc */
1018
1033
  chdir(e) {
@@ -1029,25 +1044,29 @@ class BasePHP {
1029
1044
  const t = await this.semaphore.acquire();
1030
1045
  let r;
1031
1046
  try {
1032
- l(this, w) || (m(this, O, te).call(this), p(this, w, !0)), m(this, G, le).call(this, e.scriptPath || ""), m(this, q, se).call(this, e.relativeUri || ""), m(this, D, ie).call(this, e.method || "GET");
1033
- const s = normalizeHeaders(e.headers || {}), i = s.host || "example.com:443";
1034
- if (m(this, z, ne).call(this, i, e.protocol || "http"), m(this, $, oe).call(this, s), e.body && (r = m(this, j, ae).call(this, e.body)), e.fileInfos)
1035
- for (const o of e.fileInfos)
1036
- m(this, Y, ue).call(this, o);
1037
- typeof e.code == "string" && m(this, J, de).call(this, " ?>" + e.code), m(this, V, ce).call(this);
1038
- const n = await m(this, K, he).call(this);
1039
- if (e.throwOnError && n.exitCode !== 0) {
1040
- const o = {
1041
- stdout: n.text,
1042
- stderr: n.errors
1047
+ if (c(this, w) || (f(this, B, te).call(this), p(this, w, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
1048
+ throw new Error(
1049
+ `The script path "${e.scriptPath}" does not exist.`
1050
+ );
1051
+ f(this, G, le).call(this, e.scriptPath || ""), f(this, q, se).call(this, e.relativeUri || ""), f(this, $, ie).call(this, e.method || "GET");
1052
+ const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443";
1053
+ f(this, D, ne).call(this, n, e.protocol || "http"), f(this, z, oe).call(this, s), e.body && (r = f(this, j, ae).call(this, e.body)), typeof e.code == "string" && f(this, Y, de).call(this, " ?>" + e.code), f(this, V, ce).call(this);
1054
+ const o = e.env || {};
1055
+ for (const a in o)
1056
+ f(this, Q, ue).call(this, a, o[a]);
1057
+ const i = await f(this, J, he).call(this);
1058
+ if (e.throwOnError && i.exitCode !== 0) {
1059
+ const a = {
1060
+ stdout: i.text,
1061
+ stderr: i.errors
1043
1062
  };
1044
- console.warn("PHP.run() output was:", o);
1045
- const a = new Error(
1046
- `PHP.run() failed with exit code ${n.exitCode} and the following output`
1063
+ console.warn("PHP.run() output was:", a);
1064
+ const l = new Error(
1065
+ `PHP.run() failed with exit code ${i.exitCode} and the following output: ` + i.errors
1047
1066
  );
1048
- throw a.output = o, a;
1067
+ throw l.output = a, console.error(l), l;
1049
1068
  }
1050
- return n;
1069
+ return i;
1051
1070
  } finally {
1052
1071
  try {
1053
1072
  r && this[__private__dont__use].free(r);
@@ -1059,18 +1078,18 @@ class BasePHP {
1059
1078
  }
1060
1079
  }
1061
1080
  addServerGlobalEntry(e, t) {
1062
- l(this, b)[e] = t;
1081
+ c(this, v)[e] = t;
1063
1082
  }
1064
1083
  defineConstant(e, t) {
1065
1084
  let r = {};
1066
1085
  try {
1067
1086
  r = JSON.parse(
1068
- this.fileExists("/tmp/consts.json") && this.readFileAsText("/tmp/consts.json") || "{}"
1087
+ this.fileExists("/internal/consts.json") && this.readFileAsText("/internal/consts.json") || "{}"
1069
1088
  );
1070
1089
  } catch {
1071
1090
  }
1072
1091
  this.writeFile(
1073
- "/tmp/consts.json",
1092
+ "/internal/consts.json",
1074
1093
  JSON.stringify({
1075
1094
  ...r,
1076
1095
  [e]: t
@@ -1124,7 +1143,7 @@ class BasePHP {
1124
1143
  );
1125
1144
  if (t.prependPath) {
1126
1145
  const s = e.replace(/\/$/, "");
1127
- return r.map((i) => `${s}/${i}`);
1146
+ return r.map((n) => `${s}/${n}`);
1128
1147
  }
1129
1148
  return r;
1130
1149
  } catch (r) {
@@ -1155,9 +1174,9 @@ class BasePHP {
1155
1174
  this.exit();
1156
1175
  } catch {
1157
1176
  }
1158
- if (this.initializeRuntime(e), l(this, M) && this.setPhpIniPath(l(this, M)), l(this, I) && this.setSapiName(l(this, I)), this.requestHandler) {
1177
+ if (this.initializeRuntime(e), c(this, F) && this.setPhpIniPath(c(this, F)), c(this, A) && this.setSapiName(c(this, A)), this.requestHandler) {
1159
1178
  const r = this.documentRoot;
1160
- recreateMemFS(this[__private__dont__use].FS, t, r);
1179
+ copyFS(t, this[__private__dont__use].FS, r);
1161
1180
  }
1162
1181
  }
1163
1182
  exit(e = 0) {
@@ -1168,23 +1187,23 @@ class BasePHP {
1168
1187
  this[__private__dont__use]._exit(e);
1169
1188
  } catch {
1170
1189
  }
1171
- p(this, w, !1), p(this, v, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
1190
+ p(this, w, !1), p(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
1172
1191
  }
1173
1192
  }
1174
- T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v = new WeakMap(), b = new WeakMap(), P = new WeakMap(), A = new WeakMap(), O = new WeakSet(), te = function() {
1175
- if (this.setPhpIniEntry("auto_prepend_file", "/tmp/consts.php"), this.fileExists("/tmp/consts.php") || this.writeFile(
1176
- "/tmp/consts.php",
1193
+ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E = new WeakMap(), v = new WeakMap(), P = new WeakMap(), M = new WeakMap(), B = new WeakSet(), te = function() {
1194
+ if (this.setPhpIniEntry("auto_prepend_file", "/internal/consts.php"), this.fileExists("/internal/consts.php") || this.writeFile(
1195
+ "/internal/consts.php",
1177
1196
  `<?php
1178
- if(file_exists('/tmp/consts.json')) {
1179
- $consts = json_decode(file_get_contents('/tmp/consts.json'), true);
1197
+ if(file_exists('/internal/consts.json')) {
1198
+ $consts = json_decode(file_get_contents('/internal/consts.json'), true);
1180
1199
  foreach ($consts as $const => $value) {
1181
1200
  if (!defined($const) && is_scalar($value)) {
1182
1201
  define($const, $value);
1183
1202
  }
1184
1203
  }
1185
1204
  }`
1186
- ), l(this, T).length > 0) {
1187
- const e = l(this, T).map(([t, r]) => `${t}=${r}`).join(`
1205
+ ), c(this, x).length > 0) {
1206
+ const e = c(this, x).map(([t, r]) => `${t}=${r}`).join(`
1188
1207
  `) + `
1189
1208
 
1190
1209
  `;
@@ -1197,7 +1216,7 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
1197
1216
  }
1198
1217
  this[__private__dont__use].ccall("php_wasm_init", null, [], []);
1199
1218
  }, W = new WeakSet(), re = function() {
1200
- const e = "/tmp/headers.json";
1219
+ const e = "/internal/headers.json";
1201
1220
  if (!this.fileExists(e))
1202
1221
  throw new Error(
1203
1222
  "SAPI Error: Could not find response headers file."
@@ -1206,8 +1225,8 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
1206
1225
  for (const s of t.headers) {
1207
1226
  if (!s.includes(": "))
1208
1227
  continue;
1209
- const i = s.indexOf(": "), n = s.substring(0, i).toLowerCase(), o = s.substring(i + 2);
1210
- n in r || (r[n] = []), r[n].push(o);
1228
+ const n = s.indexOf(": "), o = s.substring(0, n).toLowerCase(), i = s.substring(n + 2);
1229
+ o in r || (r[o] = []), r[o].push(i);
1211
1230
  }
1212
1231
  return {
1213
1232
  headers: r,
@@ -1228,7 +1247,7 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
1228
1247
  [t]
1229
1248
  );
1230
1249
  }
1231
- }, z = new WeakSet(), ne = function(e, t) {
1250
+ }, D = new WeakSet(), ne = function(e, t) {
1232
1251
  this[__private__dont__use].ccall(
1233
1252
  "wasm_set_request_host",
1234
1253
  null,
@@ -1246,14 +1265,14 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
1246
1265
  [NUMBER],
1247
1266
  [r]
1248
1267
  ), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
1249
- }, D = new WeakSet(), ie = function(e) {
1268
+ }, $ = new WeakSet(), ie = function(e) {
1250
1269
  this[__private__dont__use].ccall(
1251
1270
  "wasm_set_request_method",
1252
1271
  null,
1253
1272
  [STRING],
1254
1273
  [e]
1255
1274
  );
1256
- }, $ = new WeakSet(), oe = function(e) {
1275
+ }, z = new WeakSet(), oe = function(e) {
1257
1276
  e.cookie && this[__private__dont__use].ccall(
1258
1277
  "wasm_set_cookies",
1259
1278
  null,
@@ -1278,24 +1297,28 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
1278
1297
  );
1279
1298
  }
1280
1299
  }, j = new WeakSet(), ae = function(e) {
1281
- const t = this[__private__dont__use].lengthBytesUTF8(e), r = this[__private__dont__use].malloc(t + 1);
1282
- if (!r)
1300
+ let t, r;
1301
+ typeof e == "string" ? (console.warn(
1302
+ "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"
1303
+ ), r = this[__private__dont__use].lengthBytesUTF8(e), t = r + 1) : (r = e.byteLength, t = e.byteLength);
1304
+ const s = this[__private__dont__use].malloc(t);
1305
+ if (!s)
1283
1306
  throw new Error("Could not allocate memory for the request body.");
1284
- return this[__private__dont__use].stringToUTF8(
1307
+ return typeof e == "string" ? this[__private__dont__use].stringToUTF8(
1285
1308
  e,
1286
- r,
1309
+ s,
1287
1310
  t + 1
1288
- ), this[__private__dont__use].ccall(
1311
+ ) : this[__private__dont__use].HEAPU8.set(e, s), this[__private__dont__use].ccall(
1289
1312
  "wasm_set_request_body",
1290
1313
  null,
1291
1314
  [NUMBER],
1292
- [r]
1315
+ [s]
1293
1316
  ), this[__private__dont__use].ccall(
1294
1317
  "wasm_set_content_length",
1295
1318
  null,
1296
1319
  [NUMBER],
1297
- [new TextEncoder().encode(e).length]
1298
- ), r;
1320
+ [r]
1321
+ ), s;
1299
1322
  }, G = new WeakSet(), le = function(e) {
1300
1323
  this[__private__dont__use].ccall(
1301
1324
  "wasm_set_path_translated",
@@ -1304,40 +1327,38 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
1304
1327
  [e]
1305
1328
  );
1306
1329
  }, V = new WeakSet(), ce = function() {
1307
- for (const e in l(this, b))
1330
+ for (const e in c(this, v))
1308
1331
  this[__private__dont__use].ccall(
1309
1332
  "wasm_add_SERVER_entry",
1310
1333
  null,
1311
1334
  [STRING, STRING],
1312
- [e, l(this, b)[e]]
1335
+ [e, c(this, v)[e]]
1313
1336
  );
1314
- }, Y = new WeakSet(), ue = function(e) {
1315
- const { key: t, name: r, type: s, data: i } = e, n = `/tmp/${Math.random().toFixed(20)}`;
1316
- this.writeFile(n, i);
1317
- const o = 0;
1337
+ }, Q = new WeakSet(), ue = function(e, t) {
1318
1338
  this[__private__dont__use].ccall(
1319
- "wasm_add_uploaded_file",
1339
+ "wasm_add_ENV_entry",
1320
1340
  null,
1321
- [STRING, STRING, STRING, STRING, NUMBER, NUMBER],
1322
- [t, r, s, n, o, i.byteLength]
1341
+ [STRING, STRING],
1342
+ [e, t]
1323
1343
  );
1324
- }, J = new WeakSet(), de = function(e) {
1344
+ }, Y = new WeakSet(), de = function(e) {
1325
1345
  this[__private__dont__use].ccall(
1326
1346
  "wasm_set_php_code",
1327
1347
  null,
1328
1348
  [STRING],
1329
1349
  [e]
1330
1350
  );
1331
- }, K = new WeakSet(), he = async function() {
1332
- var i;
1351
+ }, J = new WeakSet(), he = async function() {
1352
+ var n;
1333
1353
  let e, t;
1334
1354
  try {
1335
- e = await new Promise((n, o) => {
1336
- var u;
1337
- t = (c) => {
1355
+ e = await new Promise((o, i) => {
1356
+ var l;
1357
+ t = (u) => {
1358
+ console.error(u), console.error(u.error);
1338
1359
  const h = new Error("Rethrown");
1339
- h.cause = c.error, h.betterMessage = c.message, o(h);
1340
- }, (u = l(this, v)) == null || u.addEventListener(
1360
+ h.cause = u.error, h.betterMessage = u.message, i(h);
1361
+ }, (l = c(this, E)) == null || l.addEventListener(
1341
1362
  "error",
1342
1363
  t
1343
1364
  );
@@ -1348,27 +1369,27 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
1348
1369
  [],
1349
1370
  { async: !0 }
1350
1371
  );
1351
- return a instanceof Promise ? a.then(n, o) : n(a);
1372
+ return a instanceof Promise ? a.then(o, i) : o(a);
1352
1373
  });
1353
- } catch (n) {
1354
- for (const c in this)
1355
- typeof this[c] == "function" && (this[c] = () => {
1374
+ } catch (o) {
1375
+ for (const u in this)
1376
+ typeof this[u] == "function" && (this[u] = () => {
1356
1377
  throw new Error(
1357
1378
  "PHP runtime has crashed – see the earlier error for details."
1358
1379
  );
1359
1380
  });
1360
1381
  this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
1361
- const o = n, a = "betterMessage" in o ? o.betterMessage : o.message, u = new Error(a);
1362
- throw u.cause = o, u;
1382
+ const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, l = new Error(a);
1383
+ throw l.cause = i, console.error(l), l;
1363
1384
  } finally {
1364
- (i = l(this, v)) == null || i.removeEventListener("error", t), p(this, b, {});
1385
+ (n = c(this, E)) == null || n.removeEventListener("error", t), p(this, v, {});
1365
1386
  }
1366
- const { headers: r, httpStatusCode: s } = m(this, W, re).call(this);
1387
+ const { headers: r, httpStatusCode: s } = f(this, W, re).call(this);
1367
1388
  return new PHPResponse(
1368
1389
  s,
1369
1390
  r,
1370
- this.readFileAsBuffer("/tmp/stdout"),
1371
- this.readFileAsText("/tmp/stderr"),
1391
+ this.readFileAsBuffer("/internal/stdout"),
1392
+ this.readFileAsText("/internal/stderr"),
1372
1393
  e
1373
1394
  );
1374
1395
  };
@@ -1408,28 +1429,23 @@ function normalizeHeaders(e) {
1408
1429
  t[r.toLowerCase()] = e[r];
1409
1430
  return t;
1410
1431
  }
1411
- function recreateMemFS(e, t, r) {
1432
+ function copyFS(e, t, r) {
1412
1433
  let s;
1413
1434
  try {
1414
- s = t.lookupPath(r);
1435
+ s = e.lookupPath(r);
1415
1436
  } catch {
1416
1437
  return;
1417
1438
  }
1418
1439
  if (!("contents" in s.node))
1419
1440
  return;
1420
- try {
1421
- e = e.lookupPath(r);
1441
+ if (!e.isDir(s.node.mode)) {
1442
+ t.writeFile(r, e.readFile(r));
1422
1443
  return;
1423
- } catch {
1424
1444
  }
1425
- if (!t.isDir(s.node.mode)) {
1426
- e.writeFile(r, t.readFile(r));
1427
- return;
1428
- }
1429
- e.mkdirTree(r);
1430
- const i = t.readdir(r).filter((n) => n !== "." && n !== "..");
1431
- for (const n of i)
1432
- recreateMemFS(e, t, joinPaths(r, n));
1445
+ t.mkdirTree(r);
1446
+ const n = e.readdir(r).filter((o) => o !== "." && o !== "..");
1447
+ for (const o of n)
1448
+ copyFS(e, t, joinPaths(r, o));
1433
1449
  }
1434
1450
  /**
1435
1451
  * @license
@@ -1472,57 +1488,57 @@ function isAllowedOrigin(e, t) {
1472
1488
  return !1;
1473
1489
  }
1474
1490
  function expose(e, t = globalThis, r = ["*"]) {
1475
- t.addEventListener("message", function s(i) {
1476
- if (!i || !i.data)
1491
+ t.addEventListener("message", function s(n) {
1492
+ if (!n || !n.data)
1477
1493
  return;
1478
- if (!isAllowedOrigin(r, i.origin)) {
1479
- console.warn(`Invalid origin '${i.origin}' for comlink proxy`);
1494
+ if (!isAllowedOrigin(r, n.origin)) {
1495
+ console.warn(`Invalid origin '${n.origin}' for comlink proxy`);
1480
1496
  return;
1481
1497
  }
1482
- const { id: n, type: o, path: a } = Object.assign({ path: [] }, i.data), u = (i.data.argumentList || []).map(fromWireValue);
1483
- let c;
1498
+ const { id: o, type: i, path: a } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(fromWireValue);
1499
+ let u;
1484
1500
  try {
1485
- const h = a.slice(0, -1).reduce((f, y) => f[y], e), _ = a.reduce((f, y) => f[y], e);
1486
- switch (o) {
1501
+ const h = a.slice(0, -1).reduce((_, I) => _[I], e), m = a.reduce((_, I) => _[I], e);
1502
+ switch (i) {
1487
1503
  case "GET":
1488
- c = _;
1504
+ u = m;
1489
1505
  break;
1490
1506
  case "SET":
1491
- h[a.slice(-1)[0]] = fromWireValue(i.data.value), c = !0;
1507
+ h[a.slice(-1)[0]] = fromWireValue(n.data.value), u = !0;
1492
1508
  break;
1493
1509
  case "APPLY":
1494
- c = _.apply(h, u);
1510
+ u = m.apply(h, l);
1495
1511
  break;
1496
1512
  case "CONSTRUCT":
1497
1513
  {
1498
- const f = new _(...u);
1499
- c = proxy(f);
1514
+ const _ = new m(...l);
1515
+ u = proxy(_);
1500
1516
  }
1501
1517
  break;
1502
1518
  case "ENDPOINT":
1503
1519
  {
1504
- const { port1: f, port2: y } = new MessageChannel();
1505
- expose(e, y), c = transfer(f, [f]);
1520
+ const { port1: _, port2: I } = new MessageChannel();
1521
+ expose(e, I), u = transfer(_, [_]);
1506
1522
  }
1507
1523
  break;
1508
1524
  case "RELEASE":
1509
- c = void 0;
1525
+ u = void 0;
1510
1526
  break;
1511
1527
  default:
1512
1528
  return;
1513
1529
  }
1514
1530
  } catch (h) {
1515
- c = { value: h, [throwMarker]: 0 };
1531
+ u = { value: h, [throwMarker]: 0 };
1516
1532
  }
1517
- Promise.resolve(c).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
1518
- const [_, f] = toWireValue(h);
1519
- t.postMessage(Object.assign(Object.assign({}, _), { id: n }), f), o === "RELEASE" && (t.removeEventListener("message", s), closeEndPoint(t), finalizer in e && typeof e[finalizer] == "function" && e[finalizer]());
1533
+ Promise.resolve(u).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
1534
+ const [m, _] = toWireValue(h);
1535
+ t.postMessage(Object.assign(Object.assign({}, m), { id: o }), _), i === "RELEASE" && (t.removeEventListener("message", s), closeEndPoint(t), finalizer in e && typeof e[finalizer] == "function" && e[finalizer]());
1520
1536
  }).catch((h) => {
1521
- const [_, f] = toWireValue({
1537
+ const [m, _] = toWireValue({
1522
1538
  value: new TypeError("Unserializable return value"),
1523
1539
  [throwMarker]: 0
1524
1540
  });
1525
- t.postMessage(Object.assign(Object.assign({}, _), { id: n }), f);
1541
+ t.postMessage(Object.assign(Object.assign({}, m), { id: o }), _);
1526
1542
  });
1527
1543
  }), t.start && t.start();
1528
1544
  }
@@ -1560,59 +1576,59 @@ function unregisterProxy(e) {
1560
1576
  function createProxy(e, t = [], r = function() {
1561
1577
  }) {
1562
1578
  let s = !1;
1563
- const i = new Proxy(r, {
1564
- get(n, o) {
1565
- if (throwIfProxyReleased(s), o === releaseProxy)
1579
+ const n = new Proxy(r, {
1580
+ get(o, i) {
1581
+ if (throwIfProxyReleased(s), i === releaseProxy)
1566
1582
  return () => {
1567
- unregisterProxy(i), releaseEndpoint(e), s = !0;
1583
+ unregisterProxy(n), releaseEndpoint(e), s = !0;
1568
1584
  };
1569
- if (o === "then") {
1585
+ if (i === "then") {
1570
1586
  if (t.length === 0)
1571
- return { then: () => i };
1587
+ return { then: () => n };
1572
1588
  const a = requestResponseMessage(e, {
1573
1589
  type: "GET",
1574
- path: t.map((u) => u.toString())
1590
+ path: t.map((l) => l.toString())
1575
1591
  }).then(fromWireValue);
1576
1592
  return a.then.bind(a);
1577
1593
  }
1578
- return createProxy(e, [...t, o]);
1594
+ return createProxy(e, [...t, i]);
1579
1595
  },
1580
- set(n, o, a) {
1596
+ set(o, i, a) {
1581
1597
  throwIfProxyReleased(s);
1582
- const [u, c] = toWireValue(a);
1598
+ const [l, u] = toWireValue(a);
1583
1599
  return requestResponseMessage(e, {
1584
1600
  type: "SET",
1585
- path: [...t, o].map((h) => h.toString()),
1586
- value: u
1587
- }, c).then(fromWireValue);
1601
+ path: [...t, i].map((h) => h.toString()),
1602
+ value: l
1603
+ }, u).then(fromWireValue);
1588
1604
  },
1589
- apply(n, o, a) {
1605
+ apply(o, i, a) {
1590
1606
  throwIfProxyReleased(s);
1591
- const u = t[t.length - 1];
1592
- if (u === createEndpoint)
1607
+ const l = t[t.length - 1];
1608
+ if (l === createEndpoint)
1593
1609
  return requestResponseMessage(e, {
1594
1610
  type: "ENDPOINT"
1595
1611
  }).then(fromWireValue);
1596
- if (u === "bind")
1612
+ if (l === "bind")
1597
1613
  return createProxy(e, t.slice(0, -1));
1598
- const [c, h] = processArguments(a);
1614
+ const [u, h] = processArguments(a);
1599
1615
  return requestResponseMessage(e, {
1600
1616
  type: "APPLY",
1601
- path: t.map((_) => _.toString()),
1602
- argumentList: c
1617
+ path: t.map((m) => m.toString()),
1618
+ argumentList: u
1603
1619
  }, h).then(fromWireValue);
1604
1620
  },
1605
- construct(n, o) {
1621
+ construct(o, i) {
1606
1622
  throwIfProxyReleased(s);
1607
- const [a, u] = processArguments(o);
1623
+ const [a, l] = processArguments(i);
1608
1624
  return requestResponseMessage(e, {
1609
1625
  type: "CONSTRUCT",
1610
- path: t.map((c) => c.toString()),
1626
+ path: t.map((u) => u.toString()),
1611
1627
  argumentList: a
1612
- }, u).then(fromWireValue);
1628
+ }, l).then(fromWireValue);
1613
1629
  }
1614
1630
  });
1615
- return registerProxy(i, e), i;
1631
+ return registerProxy(n, e), n;
1616
1632
  }
1617
1633
  function myFlat(e) {
1618
1634
  return Array.prototype.concat.apply([], e);
@@ -1630,7 +1646,7 @@ function proxy(e) {
1630
1646
  }
1631
1647
  function windowEndpoint(e, t = globalThis, r = "*") {
1632
1648
  return {
1633
- postMessage: (s, i) => e.postMessage(s, r, i),
1649
+ postMessage: (s, n) => e.postMessage(s, r, n),
1634
1650
  addEventListener: t.addEventListener.bind(t),
1635
1651
  removeEventListener: t.removeEventListener.bind(t)
1636
1652
  };
@@ -1638,14 +1654,14 @@ function windowEndpoint(e, t = globalThis, r = "*") {
1638
1654
  function toWireValue(e) {
1639
1655
  for (const [t, r] of transferHandlers)
1640
1656
  if (r.canHandle(e)) {
1641
- const [s, i] = r.serialize(e);
1657
+ const [s, n] = r.serialize(e);
1642
1658
  return [
1643
1659
  {
1644
1660
  type: "HANDLER",
1645
1661
  name: t,
1646
1662
  value: s
1647
1663
  },
1648
- i
1664
+ n
1649
1665
  ];
1650
1666
  }
1651
1667
  return [
@@ -1666,10 +1682,10 @@ function fromWireValue(e) {
1666
1682
  }
1667
1683
  function requestResponseMessage(e, t, r) {
1668
1684
  return new Promise((s) => {
1669
- const i = generateUUID();
1670
- e.addEventListener("message", function n(o) {
1671
- !o.data || !o.data.id || o.data.id !== i || (e.removeEventListener("message", n), s(o.data));
1672
- }), e.start && e.start(), e.postMessage(Object.assign({ id: i }, t), r);
1685
+ const n = generateUUID();
1686
+ e.addEventListener("message", function o(i) {
1687
+ !i.data || !i.data.id || i.data.id !== n || (e.removeEventListener("message", o), s(i.data));
1688
+ }), e.start && e.start(), e.postMessage(Object.assign({ id: n }, t), r);
1673
1689
  });
1674
1690
  }
1675
1691
  function generateUUID() {
@@ -1679,14 +1695,14 @@ function consumeAPI(e) {
1679
1695
  setupTransferHandlers();
1680
1696
  const t = e instanceof Worker ? e : windowEndpoint(e), r = wrap(t), s = proxyClone(r);
1681
1697
  return new Proxy(s, {
1682
- get: (i, n) => n === "isConnected" ? async () => {
1683
- for (let o = 0; o < 10; o++)
1698
+ get: (n, o) => o === "isConnected" ? async () => {
1699
+ for (let i = 0; i < 10; i++)
1684
1700
  try {
1685
1701
  await runWithTimeout(r.isConnected(), 200);
1686
1702
  break;
1687
1703
  } catch {
1688
1704
  }
1689
- } : r[n]
1705
+ } : r[o]
1690
1706
  });
1691
1707
  }
1692
1708
  async function runWithTimeout(e, t) {
@@ -1697,16 +1713,16 @@ async function runWithTimeout(e, t) {
1697
1713
  function exposeAPI(e, t) {
1698
1714
  setupTransferHandlers();
1699
1715
  const r = Promise.resolve();
1700
- let s, i;
1701
- const n = new Promise((u, c) => {
1702
- s = u, i = c;
1703
- }), o = proxyClone(e), a = new Proxy(o, {
1704
- get: (u, c) => c === "isConnected" ? () => r : c === "isReady" ? () => n : c in u ? u[c] : t == null ? void 0 : t[c]
1716
+ let s, n;
1717
+ const o = new Promise((l, u) => {
1718
+ s = l, n = u;
1719
+ }), i = proxyClone(e), a = new Proxy(i, {
1720
+ get: (l, u) => u === "isConnected" ? () => r : u === "isReady" ? () => o : u in l ? l[u] : t == null ? void 0 : t[u]
1705
1721
  });
1706
1722
  return expose(
1707
1723
  a,
1708
1724
  typeof window < "u" ? windowEndpoint(self.parent) : void 0
1709
- ), [s, i, a];
1725
+ ), [s, n, a];
1710
1726
  }
1711
1727
  let isTransferHandlersSetup = !1;
1712
1728
  function setupTransferHandlers() {
@@ -1837,11 +1853,11 @@ class WebPHP extends BasePHP {
1837
1853
  );
1838
1854
  }
1839
1855
  static async loadRuntime(t, r = {}) {
1840
- var n;
1841
- const s = r.loadAllExtensions ? "kitchen-sink" : "light", i = await getPHPLoaderModule(t, s);
1842
- return (n = r.downloadMonitor) == null || n.expectAssets({
1843
- [i.dependencyFilename]: i.dependenciesTotalSize
1844
- }), await loadPHPRuntime(i, {
1856
+ var o;
1857
+ const s = r.loadAllExtensions ? "kitchen-sink" : "light", n = await getPHPLoaderModule(t, s);
1858
+ return (o = r.downloadMonitor) == null || o.expectAssets({
1859
+ [n.dependencyFilename]: n.dependenciesTotalSize
1860
+ }), await loadPHPRuntime(n, {
1845
1861
  ...r.emscriptenOptions || {},
1846
1862
  ...fakeWebsocket()
1847
1863
  });
@@ -1981,40 +1997,40 @@ async function registerServiceWorker(e, t, r) {
1981
1997
  updateViaCache: "none"
1982
1998
  })).update(), navigator.serviceWorker.addEventListener(
1983
1999
  "message",
1984
- async function(o) {
1985
- if (console.debug("[window][sw] Message from ServiceWorker", o), t && o.data.scope !== t)
2000
+ async function(i) {
2001
+ if (console.debug("[window][sw] Message from ServiceWorker", i), t && i.data.scope !== t)
1986
2002
  return;
1987
- const a = o.data.args || [], u = o.data.method, c = await e[u](...a);
1988
- o.source.postMessage(responseTo(o.data.requestId, c));
2003
+ const a = i.data.args || [], l = i.data.method, u = await e[l](...a);
2004
+ i.source.postMessage(responseTo(i.data.requestId, u));
1989
2005
  }
1990
2006
  ), s.startMessages();
1991
2007
  }
1992
2008
  async function spawnPHPWorkerThread(e, t = {}) {
1993
2009
  e = addQueryParams(e, t);
1994
2010
  const r = new Worker(e, { type: "module" });
1995
- return new Promise((s, i) => {
1996
- r.onerror = (o) => {
2011
+ return new Promise((s, n) => {
2012
+ r.onerror = (i) => {
1997
2013
  const a = new Error(
1998
- `WebWorker failed to load at ${e}. ${o.message ? `Original error: ${o.message}` : ""}`
2014
+ `WebWorker failed to load at ${e}. ${i.message ? `Original error: ${i.message}` : ""}`
1999
2015
  );
2000
- a.filename = o.filename, i(a);
2016
+ a.filename = i.filename, n(a);
2001
2017
  };
2002
- function n(o) {
2003
- o.data === "worker-script-started" && (s(r), r.removeEventListener("message", n));
2018
+ function o(i) {
2019
+ i.data === "worker-script-started" && (s(r), r.removeEventListener("message", o));
2004
2020
  }
2005
- r.addEventListener("message", n);
2021
+ r.addEventListener("message", o);
2006
2022
  });
2007
2023
  }
2008
2024
  function addQueryParams(e, t) {
2009
2025
  if (!Object.entries(t).length)
2010
2026
  return e + "";
2011
2027
  const r = new URL(e);
2012
- for (const [s, i] of Object.entries(t))
2013
- if (Array.isArray(i))
2014
- for (const n of i)
2015
- r.searchParams.append(s, n);
2028
+ for (const [s, n] of Object.entries(t))
2029
+ if (Array.isArray(n))
2030
+ for (const o of n)
2031
+ r.searchParams.append(s, o);
2016
2032
  else
2017
- r.searchParams.set(s, i);
2033
+ r.searchParams.set(s, n);
2018
2034
  return r.toString();
2019
2035
  }
2020
2036
  export {