@php-wasm/web 0.1.40 → 0.1.46

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.
@@ -1,9 +1,154 @@
1
- class v {
1
+ const W = Symbol("error"), D = Symbol("message");
2
+ class I extends Event {
3
+ /**
4
+ * Create a new `ErrorEvent`.
5
+ *
6
+ * @param type The name of the event
7
+ * @param options A dictionary object that allows for setting
8
+ * attributes via object members of the same name.
9
+ */
10
+ constructor(e, r = {}) {
11
+ super(e), this[W] = r.error === void 0 ? null : r.error, this[D] = r.message === void 0 ? "" : r.message;
12
+ }
13
+ get error() {
14
+ return this[W];
15
+ }
16
+ get message() {
17
+ return this[D];
18
+ }
19
+ }
20
+ Object.defineProperty(I.prototype, "error", { enumerable: !0 });
21
+ Object.defineProperty(I.prototype, "message", { enumerable: !0 });
22
+ const ie = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : I;
23
+ class oe extends EventTarget {
24
+ constructor() {
25
+ super(...arguments), this.listenersCount = 0;
26
+ }
27
+ addEventListener(e, r) {
28
+ ++this.listenersCount, super.addEventListener(e, r);
29
+ }
30
+ removeEventListener(e, r) {
31
+ --this.listenersCount, super.removeEventListener(e, r);
32
+ }
33
+ hasListeners() {
34
+ return this.listenersCount > 0;
35
+ }
36
+ }
37
+ function ae(t) {
38
+ t.asm = {
39
+ ...t.asm
40
+ };
41
+ const e = new oe();
42
+ for (const r in t.asm)
43
+ if (typeof t.asm[r] == "function") {
44
+ const n = t.asm[r];
45
+ t.asm[r] = function(...s) {
46
+ try {
47
+ return n(...s);
48
+ } catch (o) {
49
+ if (!(o instanceof Error))
50
+ throw o;
51
+ if ("exitCode" in o && o?.exitCode === 0)
52
+ return;
53
+ const i = ce(
54
+ o,
55
+ t.lastAsyncifyStackSource?.stack
56
+ );
57
+ if (t.lastAsyncifyStackSource && (o.cause = t.lastAsyncifyStackSource), !e.hasListeners())
58
+ throw de(i), o;
59
+ e.dispatchEvent(
60
+ new ie("error", {
61
+ error: o,
62
+ message: i
63
+ })
64
+ );
65
+ }
66
+ };
67
+ }
68
+ return e;
69
+ }
70
+ let A = [];
71
+ function le() {
72
+ return A;
73
+ }
74
+ function ce(t, e) {
75
+ if (t.message === "unreachable") {
76
+ let r = ue;
77
+ e || (r += `
78
+
79
+ This stack trace is lacking. For a better one initialize
80
+ the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
81
+
82
+ `), A = fe(
83
+ e || t.stack || ""
84
+ );
85
+ for (const n of A)
86
+ r += ` * ${n}
87
+ `;
88
+ return r;
89
+ }
90
+ return t.message;
91
+ }
92
+ const ue = `
93
+ "unreachable" WASM instruction executed.
94
+
95
+ The typical reason is a PHP function missing from the ASYNCIFY_ONLY
96
+ list when building PHP.wasm.
97
+
98
+ You will need to file a new issue in the WordPress Playground repository
99
+ and paste this error message there:
100
+
101
+ https://github.com/WordPress/wordpress-playground/issues/new
102
+
103
+ If you're a core developer, the typical fix is to:
104
+
105
+ * Isolate a minimal reproduction of the error
106
+ * Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository
107
+ * Run 'npm run fix-asyncify'
108
+ * Commit the changes, push to the repo, release updated NPM packages
109
+
110
+ Below is a list of all the PHP functions found in the stack trace to
111
+ help with the minimal reproduction. If they're all already listed in
112
+ the Dockerfile, you'll need to trigger this error again with long stack
113
+ traces enabled. In node.js, you can do it using the --stack-trace-limit=100
114
+ CLI option:
115
+
116
+ `, $ = "\x1B[41m", he = "\x1B[1m", q = "\x1B[0m", z = "\x1B[K";
117
+ let B = !1;
118
+ function de(t) {
119
+ if (!B) {
120
+ B = !0, console.log(`${$}
121
+ ${z}
122
+ ${he} WASM ERROR${q}${$}`);
123
+ for (const e of t.split(`
124
+ `))
125
+ console.log(`${z} ${e} `);
126
+ console.log(`${q}`);
127
+ }
128
+ }
129
+ function fe(t) {
130
+ try {
131
+ const e = t.split(`
132
+ `).slice(1).map((r) => {
133
+ const n = r.trim().substring(3).split(" ");
134
+ return {
135
+ fn: n.length >= 2 ? n[0] : "<unknown>",
136
+ isWasm: r.includes("wasm://")
137
+ };
138
+ }).filter(
139
+ ({ fn: r, isWasm: n }) => n && !r.startsWith("dynCall_") && !r.startsWith("invoke_")
140
+ ).map(({ fn: r }) => r);
141
+ return Array.from(new Set(e));
142
+ } catch {
143
+ return [];
144
+ }
145
+ }
146
+ class b {
2
147
  constructor(e, r, n, s = "", o = 0) {
3
148
  this.httpStatusCode = e, this.headers = r, this.bytes = n, this.exitCode = o, this.errors = s;
4
149
  }
5
150
  static fromRawData(e) {
6
- return new v(
151
+ return new b(
7
152
  e.httpStatusCode,
8
153
  e.headers,
9
154
  e.bytes,
@@ -33,7 +178,7 @@ class v {
33
178
  return new TextDecoder().decode(this.bytes);
34
179
  }
35
180
  }
36
- const ie = [
181
+ const pe = [
37
182
  "8.2",
38
183
  "8.1",
39
184
  "8.0",
@@ -43,8 +188,8 @@ const ie = [
43
188
  "7.1",
44
189
  "7.0",
45
190
  "5.6"
46
- ], oe = ie[0];
47
- class ae {
191
+ ], me = pe[0];
192
+ class ge {
48
193
  #e;
49
194
  #t;
50
195
  /**
@@ -77,10 +222,10 @@ class ae {
77
222
  ...e,
78
223
  headers: {
79
224
  ...e.headers,
80
- cookie: this.#s()
225
+ cookie: this.#r()
81
226
  }
82
227
  });
83
- if (n.headers["set-cookie"] && this.#r(n.headers["set-cookie"]), this.#t.handleRedirects && n.headers.location && r < this.#t.maxRedirects) {
228
+ if (n.headers["set-cookie"] && this.#n(n.headers["set-cookie"]), this.#t.handleRedirects && n.headers.location && r < this.#t.maxRedirects) {
84
229
  const s = new URL(
85
230
  n.headers.location[0],
86
231
  this.requestHandler.absoluteUrl
@@ -112,7 +257,7 @@ class ae {
112
257
  get documentRoot() {
113
258
  return this.requestHandler.documentRoot;
114
259
  }
115
- #r(e) {
260
+ #n(e) {
116
261
  for (const r of e)
117
262
  try {
118
263
  if (!r.includes("="))
@@ -123,14 +268,14 @@ class ae {
123
268
  console.error(n);
124
269
  }
125
270
  }
126
- #s() {
271
+ #r() {
127
272
  const e = [];
128
273
  for (const r in this.#e)
129
274
  e.push(`${r}=${this.#e[r]}`);
130
275
  return e.join("; ");
131
276
  }
132
277
  }
133
- class ce {
278
+ class ye {
134
279
  constructor({ concurrency: e }) {
135
280
  this._running = 0, this.concurrency = e, this.queue = [];
136
281
  }
@@ -155,48 +300,48 @@ class ce {
155
300
  }
156
301
  }
157
302
  }
158
- const le = "http://example.com";
159
- function W(t) {
303
+ const we = "http://example.com";
304
+ function j(t) {
160
305
  return t.toString().substring(t.origin.length);
161
306
  }
162
- function D(t, e) {
307
+ function G(t, e) {
163
308
  return !e || !t.startsWith(e) ? t : t.substring(e.length);
164
309
  }
165
- function ue(t, e) {
310
+ function Pe(t, e) {
166
311
  return !e || t.startsWith(e) ? t : e + t;
167
312
  }
168
- class he {
313
+ class be {
169
314
  #e;
170
315
  #t;
316
+ #n;
171
317
  #r;
172
- #s;
173
318
  #i;
174
- #n;
319
+ #s;
175
320
  #o;
176
321
  #a;
177
- #c;
322
+ #l;
178
323
  /**
179
324
  * @param php - The PHP instance.
180
325
  * @param config - Request Handler configuration.
181
326
  */
182
327
  constructor(e, r = {}) {
183
- this.#a = new ce({ concurrency: 1 });
328
+ this.#a = new ye({ concurrency: 1 });
184
329
  const {
185
330
  documentRoot: n = "/www/",
186
331
  absoluteUrl: s = typeof location == "object" ? location?.href : "",
187
332
  isStaticFilePath: o = () => !1
188
333
  } = r;
189
- this.php = e, this.#e = n, this.#c = o;
334
+ this.php = e, this.#e = n, this.#l = o;
190
335
  const i = new URL(s);
191
- this.#r = i.hostname, this.#s = i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80, this.#t = (i.protocol || "").replace(":", "");
192
- const a = this.#s !== 443 && this.#s !== 80;
336
+ this.#n = i.hostname, this.#r = i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80, this.#t = (i.protocol || "").replace(":", "");
337
+ const a = this.#r !== 443 && this.#r !== 80;
193
338
  this.#i = [
194
- this.#r,
195
- a ? `:${this.#s}` : ""
196
- ].join(""), this.#n = i.pathname.replace(/\/+$/, ""), this.#o = [
339
+ this.#n,
340
+ a ? `:${this.#r}` : ""
341
+ ].join(""), this.#s = i.pathname.replace(/\/+$/, ""), this.#o = [
197
342
  `${this.#t}://`,
198
343
  this.#i,
199
- this.#n
344
+ this.#s
200
345
  ].join("");
201
346
  }
202
347
  /** @inheritDoc */
@@ -206,7 +351,7 @@ class he {
206
351
  /** @inheritDoc */
207
352
  internalUrlToPath(e) {
208
353
  const r = new URL(e);
209
- return r.pathname.startsWith(this.#n) && (r.pathname = r.pathname.slice(this.#n.length)), W(r);
354
+ return r.pathname.startsWith(this.#s) && (r.pathname = r.pathname.slice(this.#s.length)), j(r);
210
355
  }
211
356
  get isRequestRunning() {
212
357
  return this.#a.running > 0;
@@ -223,12 +368,12 @@ class he {
223
368
  async request(e) {
224
369
  const r = e.url.startsWith("http://") || e.url.startsWith("https://"), n = new URL(
225
370
  e.url,
226
- r ? void 0 : le
227
- ), s = D(
371
+ r ? void 0 : we
372
+ ), s = G(
228
373
  n.pathname,
229
- this.#n
374
+ this.#s
230
375
  );
231
- return this.#c(s) ? this.#l(s) : await this.#u(e, n);
376
+ return this.#l(s) ? this.#c(s) : await this.#u(e, n);
232
377
  }
233
378
  /**
234
379
  * Serves a static file from the PHP filesystem.
@@ -236,23 +381,23 @@ class he {
236
381
  * @param path - The requested static file path.
237
382
  * @returns The response.
238
383
  */
239
- #l(e) {
384
+ #c(e) {
240
385
  const r = `${this.#e}${e}`;
241
386
  if (!this.php.fileExists(r))
242
- return new v(
387
+ return new b(
243
388
  404,
244
389
  {},
245
390
  new TextEncoder().encode("404 File not found")
246
391
  );
247
392
  const n = this.php.readFileAsBuffer(r);
248
- return new v(
393
+ return new b(
249
394
  200,
250
395
  {
251
396
  "content-length": [`${n.byteLength}`],
252
397
  // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
253
398
  // The code below won't return the correct mime-type if the extension
254
399
  // was tampered with.
255
- "content-type": [fe(r)],
400
+ "content-type": [ve(r)],
256
401
  "accept-ranges": ["bytes"],
257
402
  "cache-control": ["public, max-age=0"]
258
403
  },
@@ -281,31 +426,42 @@ class he {
281
426
  if (e.files && Object.keys(e.files).length) {
282
427
  s = "POST";
283
428
  for (const c in e.files) {
284
- const l = e.files[c];
429
+ const h = e.files[c];
285
430
  i.push({
286
431
  key: c,
287
- name: l.name,
288
- type: l.type,
289
- data: new Uint8Array(await l.arrayBuffer())
432
+ name: h.name,
433
+ type: h.type,
434
+ data: new Uint8Array(await h.arrayBuffer())
290
435
  });
291
436
  }
292
- o["content-type"]?.startsWith("multipart/form-data") && (e.formData = de(
437
+ o["content-type"]?.startsWith("multipart/form-data") && (e.formData = Ee(
293
438
  e.body || ""
294
439
  ), o["content-type"] = "application/x-www-form-urlencoded", delete e.body);
295
440
  }
296
441
  let a;
297
- return e.formData !== void 0 ? (s = "POST", o["content-type"] = o["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
442
+ e.formData !== void 0 ? (s = "POST", o["content-type"] = o["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
298
443
  e.formData
299
- ).toString()) : a = e.body, await this.php.run({
300
- relativeUri: ue(
301
- W(r),
302
- this.#n
444
+ ).toString()) : a = e.body;
445
+ let l;
446
+ try {
447
+ l = this.#h(r.pathname);
448
+ } catch {
449
+ return new b(
450
+ 404,
451
+ {},
452
+ new TextEncoder().encode("404 File not found")
453
+ );
454
+ }
455
+ return await this.php.run({
456
+ relativeUri: Pe(
457
+ j(r),
458
+ this.#s
303
459
  ),
304
460
  protocol: this.#t,
305
461
  method: e.method || s,
306
462
  body: a,
307
463
  fileInfos: i,
308
- scriptPath: this.#h(r.pathname),
464
+ scriptPath: l,
309
465
  headers: o
310
466
  });
311
467
  } finally {
@@ -318,16 +474,21 @@ class he {
318
474
  * Fall back to index.php as if there was a url rewriting rule in place.
319
475
  *
320
476
  * @param requestedPath - The requested pathname.
477
+ * @throws {Error} If the requested path doesn't exist.
321
478
  * @returns The resolved filesystem path.
322
479
  */
323
480
  #h(e) {
324
- let r = D(e, this.#n);
481
+ let r = G(e, this.#s);
325
482
  r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
326
483
  const n = `${this.#e}${r}`;
327
- return this.php.fileExists(n) ? n : `${this.#e}/index.php`;
484
+ if (this.php.fileExists(n))
485
+ return n;
486
+ if (!this.php.fileExists(`${this.#e}/index.php`))
487
+ throw new Error(`File not found: ${n}`);
488
+ return `${this.#e}/index.php`;
328
489
  }
329
490
  }
330
- function de(t) {
491
+ function Ee(t) {
331
492
  const e = {}, r = t.match(/--(.*)\r\n/);
332
493
  if (!r)
333
494
  return e;
@@ -335,14 +496,14 @@ function de(t) {
335
496
  return s.shift(), s.pop(), s.forEach((o) => {
336
497
  const i = o.indexOf(`\r
337
498
  \r
338
- `), a = o.substring(0, i).trim(), c = o.substring(i + 4).trim(), l = a.match(/name="([^"]+)"/);
339
- if (l) {
340
- const h = l[1];
341
- e[h] = c;
499
+ `), a = o.substring(0, i).trim(), l = o.substring(i + 4).trim(), c = a.match(/name="([^"]+)"/);
500
+ if (c) {
501
+ const h = c[1];
502
+ e[h] = l;
342
503
  }
343
504
  }), e;
344
505
  }
345
- function fe(t) {
506
+ function ve(t) {
346
507
  switch (t.split(".").pop()) {
347
508
  case "css":
348
509
  return "text/css";
@@ -382,7 +543,7 @@ function fe(t) {
382
543
  return "application-octet-stream";
383
544
  }
384
545
  }
385
- const $ = {
546
+ const V = {
386
547
  0: "No error occurred. System call completed successfully.",
387
548
  1: "Argument list too long.",
388
549
  2: "Permission denied.",
@@ -468,10 +629,10 @@ function y(t = "") {
468
629
  try {
469
630
  return o.apply(this, i);
470
631
  } catch (a) {
471
- const c = typeof a == "object" ? a?.errno : null;
472
- if (c in $) {
473
- const l = $[c], h = typeof i[0] == "string" ? i[0] : null, g = h !== null ? t.replaceAll("{path}", h) : t;
474
- throw new Error(`${g}: ${l}`, {
632
+ const l = typeof a == "object" ? a?.errno : null;
633
+ if (l in V) {
634
+ const c = V[l], h = typeof i[0] == "string" ? i[0] : null, g = h !== null ? t.replaceAll("{path}", h) : t;
635
+ throw new Error(`${g}: ${c}`, {
475
636
  cause: a
476
637
  });
477
638
  }
@@ -480,191 +641,47 @@ function y(t = "") {
480
641
  };
481
642
  };
482
643
  }
483
- async function pe(t, e = {}, r = []) {
644
+ async function Re(t, e = {}, r = []) {
484
645
  let n, s;
485
- const o = new Promise((c) => {
486
- s = c;
487
- }), i = new Promise((c) => {
488
- n = c;
489
- }), a = t.init(ge, {
490
- onAbort(c) {
491
- console.error("WASM aborted: "), console.error(c);
646
+ const o = new Promise((l) => {
647
+ s = l;
648
+ }), i = new Promise((l) => {
649
+ n = l;
650
+ }), a = t.init(ke, {
651
+ onAbort(l) {
652
+ console.error("WASM aborted: "), console.error(l);
492
653
  },
493
654
  ENV: {},
494
655
  // Emscripten sometimes prepends a '/' to the path, which
495
656
  // breaks vite dev mode. An identity `locateFile` function
496
657
  // fixes it.
497
- locateFile: (c) => c,
658
+ locateFile: (l) => l,
498
659
  ...e,
499
660
  noInitialRun: !0,
500
661
  onRuntimeInitialized() {
501
662
  e.onRuntimeInitialized && e.onRuntimeInitialized(), n();
502
663
  },
503
- monitorRunDependencies(c) {
504
- c === 0 && (delete a.monitorRunDependencies, s());
664
+ monitorRunDependencies(l) {
665
+ l === 0 && (delete a.monitorRunDependencies, s());
505
666
  }
506
667
  });
507
- for (const { default: c } of r)
508
- c(a);
509
- return r.length || s(), await o, await i, A.push(a), A.length - 1;
668
+ for (const { default: l } of r)
669
+ l(a);
670
+ return r.length || s(), await o, await i, M.push(a), M.length - 1;
510
671
  }
511
- const A = [];
512
- function me(t) {
513
- return A[t];
514
- }
515
- const ge = function() {
516
- return typeof process < "u" && process.release?.name === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
517
- }(), q = Symbol("error"), z = Symbol("message");
518
- class I extends Event {
519
- /**
520
- * Create a new `ErrorEvent`.
521
- *
522
- * @param type The name of the event
523
- * @param options A dictionary object that allows for setting
524
- * attributes via object members of the same name.
525
- */
526
- constructor(e, r = {}) {
527
- super(e), this[q] = r.error === void 0 ? null : r.error, this[z] = r.message === void 0 ? "" : r.message;
528
- }
529
- get error() {
530
- return this[q];
531
- }
532
- get message() {
533
- return this[z];
534
- }
535
- }
536
- Object.defineProperty(I.prototype, "error", { enumerable: !0 });
537
- Object.defineProperty(I.prototype, "message", { enumerable: !0 });
538
- const ye = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : I;
539
- class we extends EventTarget {
540
- constructor() {
541
- super(...arguments), this.listenersCount = 0;
542
- }
543
- addEventListener(e, r) {
544
- ++this.listenersCount, super.addEventListener(e, r);
545
- }
546
- removeEventListener(e, r) {
547
- --this.listenersCount, super.removeEventListener(e, r);
548
- }
549
- hasListeners() {
550
- return this.listenersCount > 0;
551
- }
552
- }
553
- function Pe(t) {
554
- t.asm = {
555
- ...t.asm
556
- };
557
- const e = new we();
558
- for (const r in t.asm)
559
- if (typeof t.asm[r] == "function") {
560
- const n = t.asm[r];
561
- t.asm[r] = function(...s) {
562
- try {
563
- return n(...s);
564
- } catch (o) {
565
- if (!(o instanceof Error))
566
- throw o;
567
- if ("exitCode" in o && o?.exitCode === 0)
568
- return;
569
- const i = Ee(
570
- o,
571
- t.lastAsyncifyStackSource?.stack
572
- );
573
- if (t.lastAsyncifyStackSource && (o.cause = t.lastAsyncifyStackSource), !e.hasListeners())
574
- throw Se(i), o;
575
- e.dispatchEvent(
576
- new ye("error", {
577
- error: o,
578
- message: i
579
- })
580
- );
581
- }
582
- };
583
- }
584
- return e;
585
- }
586
- let M = [];
587
- function be() {
588
- return M;
589
- }
590
- function Ee(t, e) {
591
- if (t.message === "unreachable") {
592
- let r = ve;
593
- e || (r += `
594
-
595
- This stack trace is lacking. For a better one initialize
596
- the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
597
-
598
- `), M = ke(
599
- e || t.stack || ""
600
- );
601
- for (const n of M)
602
- r += ` * ${n}
603
- `;
604
- return r;
605
- }
606
- return t.message;
607
- }
608
- const ve = `
609
- "unreachable" WASM instruction executed.
610
-
611
- The typical reason is a PHP function missing from the ASYNCIFY_ONLY
612
- list when building PHP.wasm.
613
-
614
- You will need to file a new issue in the WordPress Playground repository
615
- and paste this error message there:
616
-
617
- https://github.com/WordPress/wordpress-playground/issues/new
618
-
619
- If you're a core developer, the typical fix is to:
620
-
621
- * Isolate a minimal reproduction of the error
622
- * Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository
623
- * Run 'npm run fix-asyncify'
624
- * Commit the changes, push to the repo, release updated NPM packages
625
-
626
- Below is a list of all the PHP functions found in the stack trace to
627
- help with the minimal reproduction. If they're all already listed in
628
- the Dockerfile, you'll need to trigger this error again with long stack
629
- traces enabled. In node.js, you can do it using the --stack-trace-limit=100
630
- CLI option:
631
-
632
- `, B = "\x1B[41m", Re = "\x1B[1m", j = "\x1B[0m", G = "\x1B[K";
633
- let V = !1;
672
+ const M = [];
634
673
  function Se(t) {
635
- if (!V) {
636
- V = !0, console.log(`${B}
637
- ${G}
638
- ${Re} WASM ERROR${j}${B}`);
639
- for (const e of t.split(`
640
- `))
641
- console.log(`${G} ${e} `);
642
- console.log(`${j}`);
643
- }
644
- }
645
- function ke(t) {
646
- try {
647
- const e = t.split(`
648
- `).slice(1).map((r) => {
649
- const n = r.trim().substring(3).split(" ");
650
- return {
651
- fn: n.length >= 2 ? n[0] : "<unknown>",
652
- isWasm: r.includes("wasm://")
653
- };
654
- }).filter(
655
- ({ fn: r, isWasm: n }) => n && !r.startsWith("dynCall_") && !r.startsWith("invoke_")
656
- ).map(({ fn: r }) => r);
657
- return Array.from(new Set(e));
658
- } catch {
659
- return [];
660
- }
674
+ return M[t];
661
675
  }
676
+ const ke = function() {
677
+ return typeof process < "u" && process.release?.name === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
678
+ }();
662
679
  var xe = Object.defineProperty, Te = Object.getOwnPropertyDescriptor, w = (t, e, r, n) => {
663
680
  for (var s = n > 1 ? void 0 : n ? Te(e, r) : e, o = t.length - 1, i; o >= 0; o--)
664
681
  (i = t[o]) && (s = (n ? i(e, r, s) : i(s)) || s);
665
682
  return n && s && xe(e, r, s), s;
666
683
  };
667
- const f = "string", b = "number", u = Symbol("__private__dont__use");
684
+ const f = "string", E = "number", u = Symbol("__private__dont__use");
668
685
  class m {
669
686
  /**
670
687
  * Initializes a PHP runtime.
@@ -674,12 +691,13 @@ class m {
674
691
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
675
692
  */
676
693
  constructor(e, r) {
677
- this.#e = [], this.#t = !1, this.#r = null, e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new ae(
678
- new he(this, r)
694
+ this.#e = [], this.#t = !1, this.#n = null, this.#r = {}, e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new ge(
695
+ new be(this, r)
679
696
  ));
680
697
  }
681
698
  #e;
682
699
  #t;
700
+ #n;
683
701
  #r;
684
702
  /** @inheritDoc */
685
703
  get absoluteUrl() {
@@ -702,10 +720,10 @@ class m {
702
720
  initializeRuntime(e) {
703
721
  if (this[u])
704
722
  throw new Error("PHP runtime already initialized.");
705
- const r = me(e);
723
+ const r = Se(e);
706
724
  if (!r)
707
725
  throw new Error("Invalid PHP runtime id.");
708
- this[u] = r, this.#r = Pe(r);
726
+ this[u] = r, this.#n = ae(r);
709
727
  }
710
728
  /** @inheritDoc */
711
729
  setPhpIniPath(e) {
@@ -736,17 +754,17 @@ class m {
736
754
  }
737
755
  /** @inheritDoc */
738
756
  async run(e) {
739
- this.#t || (this.#s(), this.#t = !0), this.#u(e.scriptPath || ""), this.#n(e.relativeUri || ""), this.#a(e.method || "GET");
757
+ this.#t || (this.#i(), this.#t = !0), this.#h(e.scriptPath || ""), this.#o(e.relativeUri || ""), this.#l(e.method || "GET");
740
758
  const { host: r, ...n } = {
741
759
  host: "example.com:443",
742
760
  ...K(e.headers || {})
743
761
  };
744
- if (this.#o(r, e.protocol || "http"), this.#c(n), e.body && this.#l(e.body), e.fileInfos)
762
+ if (this.#a(r, e.protocol || "http"), this.#c(n), e.body && this.#u(e.body), e.fileInfos)
745
763
  for (const s of e.fileInfos)
746
- this.#h(s);
747
- return e.code && this.#d(" ?>" + e.code), await this.#f();
764
+ this.#f(s);
765
+ return e.code && this.#p(" ?>" + e.code), this.#d(), await this.#m();
748
766
  }
749
- #s() {
767
+ #i() {
750
768
  if (this.#e.length > 0) {
751
769
  const e = this.#e.map(([r, n]) => `${r}=${n}`).join(`
752
770
  `) + `
@@ -761,7 +779,7 @@ class m {
761
779
  }
762
780
  this[u].ccall("php_wasm_init", null, [], []);
763
781
  }
764
- #i() {
782
+ #s() {
765
783
  const e = "/tmp/headers.json";
766
784
  if (!this.fileExists(e))
767
785
  throw new Error(
@@ -779,7 +797,7 @@ class m {
779
797
  httpStatusCode: r.status
780
798
  };
781
799
  }
782
- #n(e) {
800
+ #o(e) {
783
801
  if (this[u].ccall(
784
802
  "wasm_set_request_uri",
785
803
  null,
@@ -795,7 +813,7 @@ class m {
795
813
  );
796
814
  }
797
815
  }
798
- #o(e, r) {
816
+ #a(e, r) {
799
817
  this[u].ccall(
800
818
  "wasm_set_request_host",
801
819
  null,
@@ -810,11 +828,11 @@ class m {
810
828
  (!n || isNaN(n) || n === 80) && (n = r === "https" ? 443 : 80), this[u].ccall(
811
829
  "wasm_set_request_port",
812
830
  null,
813
- [b],
831
+ [E],
814
832
  [n]
815
833
  ), (r === "https" || !r && n === 443) && this.addServerGlobalEntry("HTTPS", "on");
816
834
  }
817
- #a(e) {
835
+ #l(e) {
818
836
  this[u].ccall(
819
837
  "wasm_set_request_method",
820
838
  null,
@@ -836,7 +854,7 @@ class m {
836
854
  ), e["content-length"] && this[u].ccall(
837
855
  "wasm_set_content_length",
838
856
  null,
839
- [b],
857
+ [E],
840
858
  [parseInt(e["content-length"], 10)]
841
859
  );
842
860
  for (const r in e)
@@ -845,7 +863,7 @@ class m {
845
863
  e[r]
846
864
  );
847
865
  }
848
- #l(e) {
866
+ #u(e) {
849
867
  this[u].ccall(
850
868
  "wasm_set_request_body",
851
869
  null,
@@ -854,11 +872,11 @@ class m {
854
872
  ), this[u].ccall(
855
873
  "wasm_set_content_length",
856
874
  null,
857
- [b],
875
+ [E],
858
876
  [new TextEncoder().encode(e).length]
859
877
  );
860
878
  }
861
- #u(e) {
879
+ #h(e) {
862
880
  this[u].ccall(
863
881
  "wasm_set_path_translated",
864
882
  null,
@@ -867,12 +885,16 @@ class m {
867
885
  );
868
886
  }
869
887
  addServerGlobalEntry(e, r) {
870
- this[u].ccall(
871
- "wasm_add_SERVER_entry",
872
- null,
873
- [f, f],
874
- [e, r]
875
- );
888
+ this.#r[e] = r;
889
+ }
890
+ #d() {
891
+ for (const e in this.#r)
892
+ this[u].ccall(
893
+ "wasm_add_SERVER_entry",
894
+ null,
895
+ [f, f],
896
+ [e, this.#r[e]]
897
+ );
876
898
  }
877
899
  /**
878
900
  * Adds file information to $_FILES superglobal in PHP.
@@ -883,18 +905,18 @@ class m {
883
905
  *
884
906
  * @param fileInfo - File details
885
907
  */
886
- #h(e) {
908
+ #f(e) {
887
909
  const { key: r, name: n, type: s, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`;
888
910
  this.writeFile(i, o);
889
911
  const a = 0;
890
912
  this[u].ccall(
891
913
  "wasm_add_uploaded_file",
892
914
  null,
893
- [f, f, f, f, b, b],
915
+ [f, f, f, f, E, E],
894
916
  [r, n, s, i, a, o.byteLength]
895
917
  );
896
918
  }
897
- #d(e) {
919
+ #p(e) {
898
920
  this[u].ccall(
899
921
  "wasm_set_php_code",
900
922
  null,
@@ -902,51 +924,40 @@ class m {
902
924
  [e]
903
925
  );
904
926
  }
905
- async #f() {
927
+ async #m() {
906
928
  let e, r;
907
929
  try {
908
- e = await new Promise(async (o, i) => {
909
- r = (a) => {
930
+ e = await new Promise((o, i) => {
931
+ r = (l) => {
910
932
  const c = new Error("Rethrown");
911
- c.cause = a.error, c.betterMessage = a.message, i(c);
912
- }, this.#r?.addEventListener(
933
+ c.cause = l.error, c.betterMessage = l.message, i(c);
934
+ }, this.#n?.addEventListener(
913
935
  "error",
914
936
  r
915
937
  );
916
- try {
917
- o(
918
- /**
919
- * This is awkward, but Asyncify makes wasm_sapi_handle_request return
920
- * Promise<Promise<number>>.
921
- *
922
- * @TODO: Determine whether this is a bug in emscripten or in our code.
923
- */
924
- await await this[u].ccall(
925
- "wasm_sapi_handle_request",
926
- b,
927
- [],
928
- []
929
- )
930
- );
931
- } catch (a) {
932
- i(a);
933
- }
938
+ const a = this[u].ccall(
939
+ "wasm_sapi_handle_request",
940
+ E,
941
+ [],
942
+ []
943
+ );
944
+ return a instanceof Promise ? a.then(o, i) : o(a);
934
945
  });
935
946
  } catch (o) {
936
- for (const l in this)
937
- typeof this[l] == "function" && (this[l] = () => {
947
+ for (const c in this)
948
+ typeof this[c] == "function" && (this[c] = () => {
938
949
  throw new Error(
939
950
  "PHP runtime has crashed – see the earlier error for details."
940
951
  );
941
952
  });
942
- this.functionsMaybeMissingFromAsyncify = be();
943
- const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, c = new Error(a);
944
- throw c.cause = i, c;
953
+ this.functionsMaybeMissingFromAsyncify = le();
954
+ const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, l = new Error(a);
955
+ throw l.cause = i, l;
945
956
  } finally {
946
- this.#r?.removeEventListener("error", r);
957
+ this.#n?.removeEventListener("error", r), this.#r = {};
947
958
  }
948
- const { headers: n, httpStatusCode: s } = this.#i();
949
- return new v(
959
+ const { headers: n, httpStatusCode: s } = this.#s();
960
+ return new b(
950
961
  s,
951
962
  n,
952
963
  this.readFileAsBuffer("/tmp/stdout"),
@@ -1092,42 +1103,42 @@ function F(t, e = globalThis, r = ["*"]) {
1092
1103
  console.warn(`Invalid origin '${s.origin}' for comlink proxy`);
1093
1104
  return;
1094
1105
  }
1095
- const { id: o, type: i, path: a } = Object.assign({ path: [] }, s.data), c = (s.data.argumentList || []).map(P);
1096
- let l;
1106
+ const { id: o, type: i, path: a } = Object.assign({ path: [] }, s.data), l = (s.data.argumentList || []).map(P);
1107
+ let c;
1097
1108
  try {
1098
1109
  const h = a.slice(0, -1).reduce((p, R) => p[R], t), g = a.reduce((p, R) => p[R], t);
1099
1110
  switch (i) {
1100
1111
  case "GET":
1101
- l = g;
1112
+ c = g;
1102
1113
  break;
1103
1114
  case "SET":
1104
- h[a.slice(-1)[0]] = P(s.data.value), l = !0;
1115
+ h[a.slice(-1)[0]] = P(s.data.value), c = !0;
1105
1116
  break;
1106
1117
  case "APPLY":
1107
- l = g.apply(h, c);
1118
+ c = g.apply(h, l);
1108
1119
  break;
1109
1120
  case "CONSTRUCT":
1110
1121
  {
1111
- const p = new g(...c);
1112
- l = re(p);
1122
+ const p = new g(...l);
1123
+ c = re(p);
1113
1124
  }
1114
1125
  break;
1115
1126
  case "ENDPOINT":
1116
1127
  {
1117
1128
  const { port1: p, port2: R } = new MessageChannel();
1118
- F(t, R), l = Ue(p, [p]);
1129
+ F(t, R), c = Ue(p, [p]);
1119
1130
  }
1120
1131
  break;
1121
1132
  case "RELEASE":
1122
- l = void 0;
1133
+ c = void 0;
1123
1134
  break;
1124
1135
  default:
1125
1136
  return;
1126
1137
  }
1127
1138
  } catch (h) {
1128
- l = { value: h, [x]: 0 };
1139
+ c = { value: h, [x]: 0 };
1129
1140
  }
1130
- Promise.resolve(l).catch((h) => ({ value: h, [x]: 0 })).then((h) => {
1141
+ Promise.resolve(c).catch((h) => ({ value: h, [x]: 0 })).then((h) => {
1131
1142
  const [g, p] = C(h);
1132
1143
  e.postMessage(Object.assign(Object.assign({}, g), { id: o }), p), i === "RELEASE" && (e.removeEventListener("message", n), Z(e), H in t && typeof t[H] == "function" && t[H]());
1133
1144
  }).catch((h) => {
@@ -1153,7 +1164,7 @@ function k(t) {
1153
1164
  throw new Error("Proxy has been released and is not useable");
1154
1165
  }
1155
1166
  function ee(t) {
1156
- return E(t, {
1167
+ return v(t, {
1157
1168
  type: "RELEASE"
1158
1169
  }).then(() => {
1159
1170
  Z(t);
@@ -1182,9 +1193,9 @@ function O(t, e = [], r = function() {
1182
1193
  if (i === "then") {
1183
1194
  if (e.length === 0)
1184
1195
  return { then: () => s };
1185
- const a = E(t, {
1196
+ const a = v(t, {
1186
1197
  type: "GET",
1187
- path: e.map((c) => c.toString())
1198
+ path: e.map((l) => l.toString())
1188
1199
  }).then(P);
1189
1200
  return a.then.bind(a);
1190
1201
  }
@@ -1192,37 +1203,37 @@ function O(t, e = [], r = function() {
1192
1203
  },
1193
1204
  set(o, i, a) {
1194
1205
  k(n);
1195
- const [c, l] = C(a);
1196
- return E(t, {
1206
+ const [l, c] = C(a);
1207
+ return v(t, {
1197
1208
  type: "SET",
1198
1209
  path: [...e, i].map((h) => h.toString()),
1199
- value: c
1200
- }, l).then(P);
1210
+ value: l
1211
+ }, c).then(P);
1201
1212
  },
1202
1213
  apply(o, i, a) {
1203
1214
  k(n);
1204
- const c = e[e.length - 1];
1205
- if (c === _e)
1206
- return E(t, {
1215
+ const l = e[e.length - 1];
1216
+ if (l === _e)
1217
+ return v(t, {
1207
1218
  type: "ENDPOINT"
1208
1219
  }).then(P);
1209
- if (c === "bind")
1220
+ if (l === "bind")
1210
1221
  return O(t, e.slice(0, -1));
1211
- const [l, h] = Y(a);
1212
- return E(t, {
1222
+ const [c, h] = Y(a);
1223
+ return v(t, {
1213
1224
  type: "APPLY",
1214
1225
  path: e.map((g) => g.toString()),
1215
- argumentList: l
1226
+ argumentList: c
1216
1227
  }, h).then(P);
1217
1228
  },
1218
1229
  construct(o, i) {
1219
1230
  k(n);
1220
- const [a, c] = Y(i);
1221
- return E(t, {
1231
+ const [a, l] = Y(i);
1232
+ return v(t, {
1222
1233
  type: "CONSTRUCT",
1223
- path: e.map((l) => l.toString()),
1234
+ path: e.map((c) => c.toString()),
1224
1235
  argumentList: a
1225
- }, c).then(P);
1236
+ }, l).then(P);
1226
1237
  }
1227
1238
  });
1228
1239
  return Oe(s, t), s;
@@ -1277,7 +1288,7 @@ function P(t) {
1277
1288
  return t.value;
1278
1289
  }
1279
1290
  }
1280
- function E(t, e, r) {
1291
+ function v(t, e, r) {
1281
1292
  return new Promise((n) => {
1282
1293
  const s = Ne();
1283
1294
  t.addEventListener("message", function o(i) {
@@ -1302,7 +1313,7 @@ function je(t, e) {
1302
1313
  const s = new Promise((a) => {
1303
1314
  n = a;
1304
1315
  }), o = N(t), i = new Proxy(o, {
1305
- get: (a, c) => c === "isConnected" ? () => r : c === "isReady" ? () => s : c in a ? a[c] : e?.[c]
1316
+ get: (a, l) => l === "isConnected" ? () => r : l === "isReady" ? () => s : l in a ? a[l] : e?.[l]
1306
1317
  });
1307
1318
  return F(
1308
1319
  i,
@@ -1336,7 +1347,7 @@ function se() {
1336
1347
  return [t.toRawData(), []];
1337
1348
  },
1338
1349
  deserialize(t) {
1339
- return v.fromRawData(t);
1350
+ return b.fromRawData(t);
1340
1351
  }
1341
1352
  }));
1342
1353
  }
@@ -1358,7 +1369,7 @@ function N(t) {
1358
1369
  }
1359
1370
  });
1360
1371
  }
1361
- async function We(t = oe) {
1372
+ async function We(t = me) {
1362
1373
  switch (t) {
1363
1374
  case "8.2":
1364
1375
  return await import("php_8_2.js");
@@ -1409,17 +1420,17 @@ class L extends m {
1409
1420
  const i = await Promise.all([
1410
1421
  We(e),
1411
1422
  ...r.dataModules || []
1412
- ]), [a, ...c] = i;
1423
+ ]), [a, ...l] = i;
1413
1424
  r.downloadMonitor?.setModules(i);
1414
- const l = await pe(
1425
+ const c = await Re(
1415
1426
  a,
1416
1427
  {
1417
1428
  ...r.emscriptenOptions || {},
1418
1429
  ...r.downloadMonitor?.getEmscriptenOptions() || {}
1419
1430
  },
1420
- c
1431
+ l
1421
1432
  );
1422
- return n.initializeRuntime(l), { dataModules: c };
1433
+ return n.initializeRuntime(c), { dataModules: l };
1423
1434
  })();
1424
1435
  return {
1425
1436
  php: n,
@@ -1532,14 +1543,14 @@ async function Ve(t, e, r, n) {
1532
1543
  `[window] Reloading the currently registered Service Worker (expected version: ${n}, registered version: ${i})`
1533
1544
  );
1534
1545
  for (const a of o) {
1535
- let c = !1;
1546
+ let l = !1;
1536
1547
  try {
1537
1548
  await a.update();
1538
1549
  } catch {
1539
- c = !0;
1550
+ l = !0;
1540
1551
  }
1541
- const l = a.waiting || a.installing;
1542
- l && !c && (i !== null ? l.postMessage("skip-waiting") : c = !0), c && (await a.unregister(), window.location.reload());
1552
+ const c = a.waiting || a.installing;
1553
+ c && !l && (i !== null ? c.postMessage("skip-waiting") : l = !0), l && (await a.unregister(), window.location.reload());
1543
1554
  }
1544
1555
  }
1545
1556
  } else
@@ -1553,7 +1564,7 @@ async function Ve(t, e, r, n) {
1553
1564
  async function(a) {
1554
1565
  if (console.debug("Message from ServiceWorker", a), e && a.data.scope !== e)
1555
1566
  return;
1556
- const c = a.data.args || [], l = a.data.method, h = await t[l](...c);
1567
+ const l = a.data.args || [], c = a.data.method, h = await t[c](...l);
1557
1568
  a.source.postMessage(De(a.data.requestId, h));
1558
1569
  }
1559
1570
  ), s.startMessages();