@php-wasm/universal 1.2.1 → 1.2.2

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,14 +1,13 @@
1
- var O = (r) => {
2
- throw TypeError(r);
1
+ var W = (t) => {
2
+ throw TypeError(t);
3
3
  };
4
- var q = (r, e, t) => e.has(r) || O("Cannot " + t);
5
- var c = (r, e, t) => (q(r, e, "read from private field"), t ? t.call(r) : e.get(r)), h = (r, e, t) => e.has(r) ? O("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), f = (r, e, t, s) => (q(r, e, "write to private field"), s ? s.call(r, t) : e.set(r, t), t), d = (r, e, t) => (q(r, e, "access private method"), t);
4
+ var q = (t, e, r) => e.has(t) || W("Cannot " + r);
5
+ var u = (t, e, r) => (q(t, e, "read from private field"), r ? r.call(t) : e.get(t)), y = (t, e, r) => e.has(t) ? W("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r), g = (t, e, r, s) => (q(t, e, "write to private field"), s ? s.call(t, r) : e.set(t, r), r), m = (t, e, r) => (q(t, e, "access private method"), r);
6
6
  import "@php-wasm/node-polyfills";
7
7
  import { logger } from "@php-wasm/logger";
8
8
  import { dirname, joinPaths, Semaphore, createSpawnHandler, normalizePath, AcquireTimeoutError } from "@php-wasm/util";
9
9
  import { parse, stringify } from "ini";
10
10
  import { StreamedFile } from "@php-wasm/stream-compression";
11
- import * as Comlink from "comlink";
12
11
  const FileErrorCodes = {
13
12
  0: "No error occurred. System call completed successfully.",
14
13
  1: "Argument list too long.",
@@ -88,25 +87,25 @@ const FileErrorCodes = {
88
87
  75: "Cross-device link.",
89
88
  76: "Extension: Capabilities insufficient."
90
89
  };
91
- function getEmscriptenFsError(r) {
92
- const e = typeof r == "object" ? r == null ? void 0 : r.errno : null;
90
+ function getEmscriptenFsError(t) {
91
+ const e = typeof t == "object" ? t == null ? void 0 : t.errno : null;
93
92
  if (e in FileErrorCodes)
94
93
  return FileErrorCodes[e];
95
94
  }
96
- function rethrowFileSystemError(r = "") {
97
- return function(t) {
95
+ function rethrowFileSystemError(t = "") {
96
+ return function(r) {
98
97
  return function(...s) {
99
98
  try {
100
- return t.apply(this, s);
101
- } catch (i) {
102
- const n = typeof i == "object" ? i == null ? void 0 : i.errno : null;
103
- if (n in FileErrorCodes) {
104
- const o = FileErrorCodes[n], a = typeof s[1] == "string" ? s[1] : null, l = a !== null ? r.replaceAll("{path}", a) : r;
105
- throw new Error(`${l}: ${o}`, {
106
- cause: i
99
+ return r.apply(this, s);
100
+ } catch (n) {
101
+ const i = typeof n == "object" ? n == null ? void 0 : n.errno : null;
102
+ if (i in FileErrorCodes) {
103
+ const o = FileErrorCodes[i], a = typeof s[1] == "string" ? s[1] : null, c = a !== null ? t.replaceAll("{path}", a) : t;
104
+ throw new Error(`${c}: ${o}`, {
105
+ cause: n
107
106
  });
108
107
  }
109
- throw i;
108
+ throw n;
110
109
  }
111
110
  };
112
111
  };
@@ -120,8 +119,8 @@ class FSHelpers {
120
119
  * @param path - The file path to read.
121
120
  * @returns The file contents.
122
121
  */
123
- static readFileAsText(e, t) {
124
- return new TextDecoder().decode(FSHelpers.readFileAsBuffer(e, t));
122
+ static readFileAsText(e, r) {
123
+ return new TextDecoder().decode(FSHelpers.readFileAsBuffer(e, r));
125
124
  }
126
125
  /**
127
126
  * Reads a file from the PHP filesystem and returns it as an array buffer.
@@ -131,8 +130,8 @@ class FSHelpers {
131
130
  * @param path - The file path to read.
132
131
  * @returns The file contents.
133
132
  */
134
- static readFileAsBuffer(e, t) {
135
- return e.readFile(t);
133
+ static readFileAsBuffer(e, r) {
134
+ return e.readFile(r);
136
135
  }
137
136
  /**
138
137
  * Overwrites data in a file in the PHP filesystem.
@@ -142,8 +141,8 @@ class FSHelpers {
142
141
  * @param path - The file path to write to.
143
142
  * @param data - The data to write to the file.
144
143
  */
145
- static writeFile(e, t, s) {
146
- e.writeFile(t, s);
144
+ static writeFile(e, r, s) {
145
+ e.writeFile(r, s);
147
146
  }
148
147
  /**
149
148
  * Removes a file from the PHP filesystem.
@@ -152,8 +151,8 @@ class FSHelpers {
152
151
  * @param FS
153
152
  * @param path - The file path to remove.
154
153
  */
155
- static unlink(e, t) {
156
- e.unlink(t);
154
+ static unlink(e, r) {
155
+ e.unlink(r);
157
156
  }
158
157
  /**
159
158
  * Moves a file or directory in the PHP filesystem to a
@@ -163,18 +162,18 @@ class FSHelpers {
163
162
  * @param fromPath The path to rename.
164
163
  * @param toPath The new path.
165
164
  */
166
- static mv(e, t, s) {
165
+ static mv(e, r, s) {
167
166
  try {
168
- const i = e.lookupPath(t).node.mount, n = FSHelpers.fileExists(e, s) ? e.lookupPath(s).node.mount : e.lookupPath(dirname(s)).node.mount;
169
- i.mountpoint !== n.mountpoint ? (FSHelpers.copyRecursive(e, t, s), FSHelpers.isDir(e, t) ? FSHelpers.rmdir(e, t, { recursive: !0 }) : e.unlink(t)) : e.rename(t, s);
170
- } catch (i) {
171
- const n = getEmscriptenFsError(i);
172
- throw n ? new Error(
173
- `Could not move ${t} to ${s}: ${n}`,
167
+ const n = e.lookupPath(r).node.mount, i = FSHelpers.fileExists(e, s) ? e.lookupPath(s).node.mount : e.lookupPath(dirname(s)).node.mount;
168
+ n.mountpoint !== i.mountpoint ? (FSHelpers.copyRecursive(e, r, s), FSHelpers.isDir(e, r) ? FSHelpers.rmdir(e, r, { recursive: !0 }) : e.unlink(r)) : e.rename(r, s);
169
+ } catch (n) {
170
+ const i = getEmscriptenFsError(n);
171
+ throw i ? new Error(
172
+ `Could not move ${r} to ${s}: ${i}`,
174
173
  {
175
- cause: i
174
+ cause: n
176
175
  }
177
- ) : i;
176
+ ) : n;
178
177
  }
179
178
  }
180
179
  /**
@@ -184,11 +183,11 @@ class FSHelpers {
184
183
  * @param path The directory path to remove.
185
184
  * @param options Options for the removal.
186
185
  */
187
- static rmdir(e, t, s = { recursive: !0 }) {
188
- s != null && s.recursive && FSHelpers.listFiles(e, t).forEach((i) => {
189
- const n = `${t}/${i}`;
190
- FSHelpers.isDir(e, n) ? FSHelpers.rmdir(e, n, s) : FSHelpers.unlink(e, n);
191
- }), e.getPath(e.lookupPath(t).node) === e.cwd() && e.chdir(joinPaths(e.cwd(), "..")), e.rmdir(t);
186
+ static rmdir(e, r, s = { recursive: !0 }) {
187
+ s != null && s.recursive && FSHelpers.listFiles(e, r).forEach((n) => {
188
+ const i = `${r}/${n}`;
189
+ FSHelpers.isDir(e, i) ? FSHelpers.rmdir(e, i, s) : FSHelpers.unlink(e, i);
190
+ }), e.getPath(e.lookupPath(r).node) === e.cwd() && e.chdir(joinPaths(e.cwd(), "..")), e.rmdir(r);
192
191
  }
193
192
  /**
194
193
  * Lists the files and directories in the given directory.
@@ -198,20 +197,20 @@ class FSHelpers {
198
197
  * @param options - Options for the listing.
199
198
  * @returns The list of files and directories in the given directory.
200
199
  */
201
- static listFiles(e, t, s = { prependPath: !1 }) {
202
- if (!FSHelpers.fileExists(e, t))
200
+ static listFiles(e, r, s = { prependPath: !1 }) {
201
+ if (!FSHelpers.fileExists(e, r))
203
202
  return [];
204
203
  try {
205
- const i = e.readdir(t).filter(
206
- (n) => n !== "." && n !== ".."
204
+ const n = e.readdir(r).filter(
205
+ (i) => i !== "." && i !== ".."
207
206
  );
208
207
  if (s.prependPath) {
209
- const n = t.replace(/\/$/, "");
210
- return i.map((o) => `${n}/${o}`);
208
+ const i = r.replace(/\/$/, "");
209
+ return n.map((o) => `${i}/${o}`);
211
210
  }
212
- return i;
213
- } catch (i) {
214
- return logger.error(i, { path: t }), [];
211
+ return n;
212
+ } catch (n) {
213
+ return logger.error(n, { path: r }), [];
215
214
  }
216
215
  }
217
216
  /**
@@ -221,8 +220,8 @@ class FSHelpers {
221
220
  * @param path – The path to check.
222
221
  * @returns True if the path is a directory, false otherwise.
223
222
  */
224
- static isDir(e, t) {
225
- return FSHelpers.fileExists(e, t) ? e.isDir(e.lookupPath(t, { follow: !0 }).node.mode) : !1;
223
+ static isDir(e, r) {
224
+ return FSHelpers.fileExists(e, r) ? e.isDir(e.lookupPath(r, { follow: !0 }).node.mode) : !1;
226
225
  }
227
226
  /**
228
227
  * Checks if a file exists in the PHP filesystem.
@@ -231,8 +230,8 @@ class FSHelpers {
231
230
  * @param path – The path to check.
232
231
  * @returns True if the path is a file, false otherwise.
233
232
  */
234
- static isFile(e, t) {
235
- return FSHelpers.fileExists(e, t) ? e.isFile(e.lookupPath(t, { follow: !0 }).node.mode) : !1;
233
+ static isFile(e, r) {
234
+ return FSHelpers.fileExists(e, r) ? e.isFile(e.lookupPath(r, { follow: !0 }).node.mode) : !1;
236
235
  }
237
236
  /**
238
237
  * Creates a symlink in the PHP filesystem.
@@ -241,8 +240,8 @@ class FSHelpers {
241
240
  * @param target
242
241
  * @param link
243
242
  */
244
- static symlink(e, t, s) {
245
- return e.symlink(t, s);
243
+ static symlink(e, r, s) {
244
+ return e.symlink(r, s);
246
245
  }
247
246
  /**
248
247
  * Checks if a path is a symlink in the PHP filesystem.
@@ -251,8 +250,8 @@ class FSHelpers {
251
250
  * @param path
252
251
  * @returns True if the path is a symlink, false otherwise.
253
252
  */
254
- static isSymlink(e, t) {
255
- return FSHelpers.fileExists(e, t) ? e.isLink(e.lookupPath(t).node.mode) : !1;
253
+ static isSymlink(e, r) {
254
+ return FSHelpers.fileExists(e, r) ? e.isLink(e.lookupPath(r).node.mode) : !1;
256
255
  }
257
256
  /**
258
257
  * Reads the target of a symlink in the PHP filesystem.
@@ -261,8 +260,8 @@ class FSHelpers {
261
260
  * @returns The target of the symlink.
262
261
  * @throws {@link @php-wasm/universal:ErrnoError} – If the path is not a symlink.
263
262
  */
264
- static readlink(e, t) {
265
- return e.readlink(t);
263
+ static readlink(e, r) {
264
+ return e.readlink(r);
266
265
  }
267
266
  /**
268
267
  * Gets the real path of a file in the PHP filesystem.
@@ -271,8 +270,8 @@ class FSHelpers {
271
270
  *
272
271
  * @returns The real path of the file.
273
272
  */
274
- static realpath(e, t) {
275
- return e.lookupPath(t, { follow: !0 }).path;
273
+ static realpath(e, r) {
274
+ return e.lookupPath(r, { follow: !0 }).path;
276
275
  }
277
276
  /**
278
277
  * Checks if a file (or a directory) exists in the PHP filesystem.
@@ -281,9 +280,9 @@ class FSHelpers {
281
280
  * @param path - The file path to check.
282
281
  * @returns True if the file exists, false otherwise.
283
282
  */
284
- static fileExists(e, t) {
283
+ static fileExists(e, r) {
285
284
  try {
286
- return e.lookupPath(t), !0;
285
+ return e.lookupPath(r), !0;
287
286
  } catch {
288
287
  return !1;
289
288
  }
@@ -296,24 +295,24 @@ class FSHelpers {
296
295
  * @param FS
297
296
  * @param path - The directory path to create.
298
297
  */
299
- static mkdir(e, t) {
300
- e.mkdirTree(t);
298
+ static mkdir(e, r) {
299
+ e.mkdirTree(r);
301
300
  }
302
- static copyRecursive(e, t, s) {
303
- const i = e.lookupPath(t).node;
304
- if (e.isDir(i.mode)) {
301
+ static copyRecursive(e, r, s) {
302
+ const n = e.lookupPath(r).node;
303
+ if (e.isDir(n.mode)) {
305
304
  e.mkdirTree(s);
306
- const n = e.readdir(t).filter(
305
+ const i = e.readdir(r).filter(
307
306
  (o) => o !== "." && o !== ".."
308
307
  );
309
- for (const o of n)
308
+ for (const o of i)
310
309
  FSHelpers.copyRecursive(
311
310
  e,
312
- joinPaths(t, o),
311
+ joinPaths(r, o),
313
312
  joinPaths(s, o)
314
313
  );
315
314
  } else
316
- e.writeFile(s, e.readFile(t));
315
+ e.writeFile(s, e.readFile(r));
317
316
  }
318
317
  }
319
318
  FSHelpers.readFileAsText = rethrowFileSystemError('Could not read "{path}"')(
@@ -355,9 +354,9 @@ FSHelpers.copyRecursive = rethrowFileSystemError(
355
354
  const _private = /* @__PURE__ */ new WeakMap();
356
355
  class PHPWorker {
357
356
  /** @inheritDoc */
358
- constructor(e, t) {
357
+ constructor(e, r) {
359
358
  this.absoluteUrl = "", this.documentRoot = "", _private.set(this, {
360
- monitor: t
359
+ monitor: r
361
360
  }), e && this.__internal_setRequestHandler(e);
362
361
  }
363
362
  __internal_setRequestHandler(e) {
@@ -394,16 +393,16 @@ class PHPWorker {
394
393
  * The onDownloadProgress event listener.
395
394
  */
396
395
  async onDownloadProgress(e) {
397
- var t;
398
- return (t = _private.get(this).monitor) == null ? void 0 : t.addEventListener("progress", e);
396
+ var r;
397
+ return (r = _private.get(this).monitor) == null ? void 0 : r.addEventListener("progress", e);
399
398
  }
400
399
  /** @inheritDoc @php-wasm/universal!PHP.mv */
401
- async mv(e, t) {
402
- return _private.get(this).php.mv(e, t);
400
+ async mv(e, r) {
401
+ return _private.get(this).php.mv(e, r);
403
402
  }
404
403
  /** @inheritDoc @php-wasm/universal!PHP.rmdir */
405
- async rmdir(e, t) {
406
- return _private.get(this).php.rmdir(e, t);
404
+ async rmdir(e, r) {
405
+ return _private.get(this).php.rmdir(e, r);
407
406
  }
408
407
  /** @inheritDoc @php-wasm/universal!PHPRequestHandler.request */
409
408
  async request(e) {
@@ -411,9 +410,9 @@ class PHPWorker {
411
410
  }
412
411
  /** @inheritDoc @php-wasm/universal!/PHP.run */
413
412
  async run(e) {
414
- const { php: t, reap: s } = await _private.get(this).requestHandler.processManager.acquirePHPInstance();
413
+ const { php: r, reap: s } = await _private.get(this).requestHandler.processManager.acquirePHPInstance();
415
414
  try {
416
- return await t.run(e);
415
+ return await r.run(e);
417
416
  } finally {
418
417
  s();
419
418
  }
@@ -443,16 +442,16 @@ class PHPWorker {
443
442
  return _private.get(this).php.readFileAsBuffer(e);
444
443
  }
445
444
  /** @inheritDoc @php-wasm/universal!/PHP.writeFile */
446
- writeFile(e, t) {
447
- return _private.get(this).php.writeFile(e, t);
445
+ writeFile(e, r) {
446
+ return _private.get(this).php.writeFile(e, r);
448
447
  }
449
448
  /** @inheritDoc @php-wasm/universal!/PHP.unlink */
450
449
  unlink(e) {
451
450
  return _private.get(this).php.unlink(e);
452
451
  }
453
452
  /** @inheritDoc @php-wasm/universal!/PHP.listFiles */
454
- listFiles(e, t) {
455
- return _private.get(this).php.listFiles(e, t);
453
+ listFiles(e, r) {
454
+ return _private.get(this).php.listFiles(e, r);
456
455
  }
457
456
  /** @inheritDoc @php-wasm/universal!/PHP.isDir */
458
457
  isDir(e) {
@@ -471,16 +470,16 @@ class PHPWorker {
471
470
  return _private.get(this).php.onMessage(e);
472
471
  }
473
472
  /** @inheritDoc @php-wasm/universal!/PHP.defineConstant */
474
- defineConstant(e, t) {
475
- _private.get(this).php.defineConstant(e, t);
473
+ defineConstant(e, r) {
474
+ _private.get(this).php.defineConstant(e, r);
476
475
  }
477
476
  /** @inheritDoc @php-wasm/universal!/PHP.addEventListener */
478
- addEventListener(e, t) {
479
- _private.get(this).php.addEventListener(e, t);
477
+ addEventListener(e, r) {
478
+ _private.get(this).php.addEventListener(e, r);
480
479
  }
481
480
  /** @inheritDoc @php-wasm/universal!/PHP.removeEventListener */
482
- removeEventListener(e, t) {
483
- _private.get(this).php.removeEventListener(e, t);
481
+ removeEventListener(e, r) {
482
+ _private.get(this).php.removeEventListener(e, r);
484
483
  }
485
484
  async [Symbol.asyncDispose]() {
486
485
  var e;
@@ -503,8 +502,8 @@ const responseTexts = {
503
502
  200: "OK"
504
503
  };
505
504
  class StreamedPHPResponse {
506
- constructor(e, t, s, i) {
507
- this.parsedHeaders = null, this.cachedStdoutText = null, this.cachedStderrText = null, this.headersStream = e, this.stdout = t, this.stderr = s, this.exitCode = i;
505
+ constructor(e, r, s, n) {
506
+ this.parsedHeaders = null, this.cachedStdoutText = null, this.cachedStderrText = null, this.headersStream = e, this.stdout = r, this.stderr = s, this.exitCode = n;
508
507
  }
509
508
  /**
510
509
  * True if the response is successful (HTTP status code 200-399),
@@ -544,7 +543,7 @@ class StreamedPHPResponse {
544
543
  (e) => e !== 0 ? 500 : void 0
545
544
  )
546
545
  ]).then((e) => e !== void 0 ? e : this.getParsedHeaders().then(
547
- (t) => t.httpStatusCode,
546
+ (r) => r.httpStatusCode,
548
547
  () => 200
549
548
  )).catch(() => 500);
550
549
  }
@@ -564,45 +563,45 @@ class StreamedPHPResponse {
564
563
  return this.parsedHeaders || (this.parsedHeaders = parseHeadersStream(this.headersStream)), await this.parsedHeaders;
565
564
  }
566
565
  }
567
- async function parseHeadersStream(r) {
568
- const e = await streamToText(r);
569
- let t;
566
+ async function parseHeadersStream(t) {
567
+ const e = await streamToText(t);
568
+ let r;
570
569
  try {
571
- t = JSON.parse(e);
570
+ r = JSON.parse(e);
572
571
  } catch {
573
572
  return { headers: {}, httpStatusCode: 200 };
574
573
  }
575
574
  const s = {};
576
- for (const i of t.headers) {
577
- if (!i.includes(": "))
575
+ for (const n of r.headers) {
576
+ if (!n.includes(": "))
578
577
  continue;
579
- const n = i.indexOf(": "), o = i.substring(0, n).toLowerCase(), a = i.substring(n + 2);
578
+ const i = n.indexOf(": "), o = n.substring(0, i).toLowerCase(), a = n.substring(i + 2);
580
579
  o in s || (s[o] = []), s[o].push(a);
581
580
  }
582
581
  return {
583
582
  headers: s,
584
- httpStatusCode: t.status
583
+ httpStatusCode: r.status
585
584
  };
586
585
  }
587
- async function streamToText(r) {
588
- const e = r.pipeThrough(new TextDecoderStream()).getReader(), t = [];
586
+ async function streamToText(t) {
587
+ const e = t.pipeThrough(new TextDecoderStream()).getReader(), r = [];
589
588
  for (; ; ) {
590
- const { done: s, value: i } = await e.read();
589
+ const { done: s, value: n } = await e.read();
591
590
  if (s)
592
- return t.join("");
593
- i && t.push(i);
591
+ return r.join("");
592
+ n && r.push(n);
594
593
  }
595
594
  }
596
595
  class PHPResponse {
597
- constructor(e, t, s, i = "", n = 0) {
598
- this.httpStatusCode = e, this.headers = t, this.bytes = s, this.exitCode = n, this.errors = i;
596
+ constructor(e, r, s, n = "", i = 0) {
597
+ this.httpStatusCode = e, this.headers = r, this.bytes = s, this.exitCode = i, this.errors = n;
599
598
  }
600
- static forHttpCode(e, t = "") {
599
+ static forHttpCode(e, r = "") {
601
600
  return new PHPResponse(
602
601
  e,
603
602
  {},
604
603
  new TextEncoder().encode(
605
- t || responseTexts[e] || ""
604
+ r || responseTexts[e] || ""
606
605
  )
607
606
  );
608
607
  }
@@ -648,39 +647,39 @@ class PHPResponse {
648
647
  }
649
648
  const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map();
650
649
  let lastRuntimeId = 0;
651
- async function loadPHPRuntime(r, ...e) {
652
- const t = Object.assign({}, ...e), [s, i, n] = makePromise(), o = r.init(currentJsRuntime, {
653
- onAbort(l) {
654
- n(l), logger.error(l);
650
+ async function loadPHPRuntime(t, ...e) {
651
+ const r = Object.assign({}, ...e), [s, n, i] = makePromise(), o = t.init(currentJsRuntime, {
652
+ onAbort(c) {
653
+ i(c), logger.error(c);
655
654
  },
656
655
  ENV: {},
657
656
  // Emscripten sometimes prepends a '/' to the path, which
658
657
  // breaks vite dev mode. An identity `locateFile` function
659
658
  // fixes it.
660
- locateFile: (l) => l,
661
- ...t,
659
+ locateFile: (c) => c,
660
+ ...r,
662
661
  noInitialRun: !0,
663
662
  onRuntimeInitialized() {
664
- t.onRuntimeInitialized && t.onRuntimeInitialized(o), i();
663
+ r.onRuntimeInitialized && r.onRuntimeInitialized(o), n();
665
664
  }
666
665
  });
667
666
  await s;
668
667
  const a = ++lastRuntimeId;
669
- return o.FS, o.id = a, o.originalExit = o._exit, o._exit = function(l) {
670
- return o.outboundNetworkProxyServer && (o.outboundNetworkProxyServer.close(), o.outboundNetworkProxyServer.closeAllConnections()), loadedRuntimes.delete(a), o.originalExit(l);
668
+ return o.FS, o.id = a, o.originalExit = o._exit, o._exit = function(c) {
669
+ return o.outboundNetworkProxyServer && (o.outboundNetworkProxyServer.close(), o.outboundNetworkProxyServer.closeAllConnections()), loadedRuntimes.delete(a), o.originalExit(c);
671
670
  }, o[RuntimeId] = a, loadedRuntimes.set(a, o), a;
672
671
  }
673
- function getLoadedRuntime(r) {
674
- return loadedRuntimes.get(r);
672
+ function getLoadedRuntime(t) {
673
+ return loadedRuntimes.get(t);
675
674
  }
676
675
  const currentJsRuntime = function() {
677
- var r;
678
- return typeof process < "u" && ((r = process.release) == null ? void 0 : r.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
676
+ var t;
677
+ return typeof process < "u" && ((t = process.release) == null ? void 0 : t.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
679
678
  }(), makePromise = () => {
680
- const r = [], e = new Promise((t, s) => {
681
- r.push(t, s);
679
+ const t = [], e = new Promise((r, s) => {
680
+ t.push(r, s);
682
681
  });
683
- return r.unshift(e), r;
682
+ return t.unshift(e), t;
684
683
  };
685
684
  var _a;
686
685
  const kError = Symbol("error"), kMessage = Symbol("message");
@@ -692,8 +691,8 @@ class ErrorEvent2 extends (_a = Event, _a) {
692
691
  * @param options A dictionary object that allows for setting
693
692
  * attributes via object members of the same name.
694
693
  */
695
- constructor(e, t = {}) {
696
- super(e), this[kError] = t.error === void 0 ? null : t.error, this[kMessage] = t.message === void 0 ? "" : t.message;
694
+ constructor(e, r = {}) {
695
+ super(e), this[kError] = r.error === void 0 ? null : r.error, this[kMessage] = r.message === void 0 ? "" : r.message;
697
696
  }
698
697
  get error() {
699
698
  return this[kError];
@@ -705,24 +704,24 @@ class ErrorEvent2 extends (_a = Event, _a) {
705
704
  Object.defineProperty(ErrorEvent2.prototype, "error", { enumerable: !0 });
706
705
  Object.defineProperty(ErrorEvent2.prototype, "message", { enumerable: !0 });
707
706
  const ErrorEvent = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : ErrorEvent2;
708
- function isExitCode(r) {
709
- return r instanceof Error ? "exitCode" in r || (r == null ? void 0 : r.name) === "ExitStatus" && "status" in r : !1;
707
+ function isExitCode(t) {
708
+ return t instanceof Error ? (t == null ? void 0 : t.name) === "ExitStatus" && "status" in t : !1;
710
709
  }
711
710
  class UnhandledRejectionsTarget extends EventTarget {
712
711
  constructor() {
713
712
  super(...arguments), this.listenersCount = 0;
714
713
  }
715
- addEventListener(e, t, s) {
714
+ addEventListener(e, r, s) {
716
715
  ++this.listenersCount, super.addEventListener(
717
716
  e,
718
- t,
717
+ r,
719
718
  s
720
719
  );
721
720
  }
722
- removeEventListener(e, t, s) {
721
+ removeEventListener(e, r, s) {
723
722
  --this.listenersCount, super.removeEventListener(
724
723
  e,
725
- t,
724
+ r,
726
725
  s
727
726
  );
728
727
  }
@@ -730,31 +729,31 @@ class UnhandledRejectionsTarget extends EventTarget {
730
729
  return this.listenersCount > 0;
731
730
  }
732
731
  }
733
- function improveWASMErrorReporting(r) {
732
+ function improveWASMErrorReporting(t) {
734
733
  const e = new UnhandledRejectionsTarget();
735
- for (const t in r.wasmExports)
736
- if (typeof r.wasmExports[t] == "function") {
737
- const s = r.wasmExports[t];
738
- r.wasmExports[t] = function(...i) {
739
- var n;
734
+ for (const r in t.wasmExports)
735
+ if (typeof t.wasmExports[r] == "function") {
736
+ const s = t.wasmExports[r];
737
+ t.wasmExports[r] = function(...n) {
738
+ var i;
740
739
  try {
741
- return s(...i);
740
+ return s(...n);
742
741
  } catch (o) {
743
742
  if (!(o instanceof Error))
744
743
  throw o;
745
- r.lastAsyncifyStackSource && (o.cause = r.lastAsyncifyStackSource);
744
+ t.lastAsyncifyStackSource && (o.cause = t.lastAsyncifyStackSource);
746
745
  const a = clarifyErrorMessage(
747
746
  o,
748
- (n = r.lastAsyncifyStackSource) == null ? void 0 : n.stack
747
+ (i = t.lastAsyncifyStackSource) == null ? void 0 : i.stack
749
748
  );
750
749
  if (e.hasListeners()) {
751
- const l = new ErrorEvent("error", {
750
+ const c = new ErrorEvent("error", {
752
751
  error: o,
753
752
  message: a
754
753
  });
755
- throw e.dispatchEvent(l), o;
754
+ throw e.dispatchEvent(c), o;
756
755
  }
757
- throw (!isExitCode(o) || o.exitCode !== 0) && showCriticalErrorBox(a), o;
756
+ throw (!isExitCode(o) || o.status !== 0) && showCriticalErrorBox(a), o;
758
757
  }
759
758
  };
760
759
  }
@@ -764,10 +763,10 @@ let functionsMaybeMissingFromAsyncify = [];
764
763
  function getFunctionsMaybeMissingFromAsyncify() {
765
764
  return functionsMaybeMissingFromAsyncify;
766
765
  }
767
- function clarifyErrorMessage(r, e) {
768
- if (r.message === "unreachable") {
769
- let t = UNREACHABLE_ERROR;
770
- e || (t += `
766
+ function clarifyErrorMessage(t, e) {
767
+ if (t.message === "unreachable") {
768
+ let r = UNREACHABLE_ERROR;
769
+ e || (r += `
771
770
 
772
771
  This stack trace is lacking. For a better one initialize
773
772
  the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
@@ -776,21 +775,21 @@ the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
776
775
  const s = new Set(
777
776
  extractPHPFunctionsFromStack(e || "")
778
777
  );
779
- let i = r;
778
+ let n = t;
780
779
  do {
781
- for (const n of extractPHPFunctionsFromStack(
782
- i.stack || ""
780
+ for (const i of extractPHPFunctionsFromStack(
781
+ n.stack || ""
783
782
  ))
784
- s.add(n);
785
- i = i.cause;
786
- } while (i);
783
+ s.add(i);
784
+ n = n.cause;
785
+ } while (n);
787
786
  functionsMaybeMissingFromAsyncify = Array.from(s);
788
- for (const n of s)
789
- t += ` * ${n}
787
+ for (const i of s)
788
+ r += ` * ${i}
790
789
  `;
791
- return t;
790
+ return r;
792
791
  }
793
- return r.message;
792
+ return t.message;
794
793
  }
795
794
  const UNREACHABLE_ERROR = `
796
795
  "unreachable" WASM instruction executed.
@@ -818,29 +817,29 @@ CLI option:
818
817
 
819
818
  `, redBg = "\x1B[41m", bold = "\x1B[1m", reset = "\x1B[0m", eol = "\x1B[K";
820
819
  let logged = !1;
821
- function showCriticalErrorBox(r) {
822
- if (!logged && (logged = !0, !(r != null && r.trim().startsWith("Program terminated with exit")))) {
820
+ function showCriticalErrorBox(t) {
821
+ if (!logged && (logged = !0, !(t != null && t.trim().startsWith("Program terminated with exit")))) {
823
822
  logger.log(`${redBg}
824
823
  ${eol}
825
824
  ${bold} WASM ERROR${reset}${redBg}`);
826
- for (const e of r.split(`
825
+ for (const e of t.split(`
827
826
  `))
828
827
  logger.log(`${eol} ${e} `);
829
828
  logger.log(`${reset}`);
830
829
  }
831
830
  }
832
- function extractPHPFunctionsFromStack(r) {
831
+ function extractPHPFunctionsFromStack(t) {
833
832
  try {
834
- const e = r.split(`
835
- `).slice(1).map((t) => {
836
- const s = t.trim().substring(3).split(" ");
833
+ const e = t.split(`
834
+ `).slice(1).map((r) => {
835
+ const s = r.trim().substring(3).split(" ");
837
836
  return {
838
837
  fn: s.length >= 2 ? s[0] : "<unknown>",
839
- isWasm: t.includes("wasm:/")
838
+ isWasm: r.includes("wasm:/")
840
839
  };
841
840
  }).filter(
842
- ({ fn: t, isWasm: s }) => s && !t.startsWith("dynCall_") && !t.startsWith("invoke_")
843
- ).map(({ fn: t }) => t);
841
+ ({ fn: r, isWasm: s }) => s && !r.startsWith("dynCall_") && !r.startsWith("invoke_")
842
+ ).map(({ fn: r }) => r);
844
843
  return Array.from(new Set(e));
845
844
  } catch {
846
845
  return [];
@@ -848,12 +847,12 @@ function extractPHPFunctionsFromStack(r) {
848
847
  }
849
848
  const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
850
849
  class PHPExecutionFailureError extends Error {
851
- constructor(e, t, s) {
852
- super(e), this.response = t, this.source = s;
850
+ constructor(e, r, s) {
851
+ super(e), this.response = r, this.source = s;
853
852
  }
854
853
  }
855
854
  const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php";
856
- var T, _, H, P, R, k, u, z, L, W, G, V, J, Y, K, X, $, Q, B, D;
855
+ var A, P, T, E, F, M, p, B, j, $, V, G, Y, J, K, X, O, Q, z, D;
857
856
  class PHP {
858
857
  /**
859
858
  * Initializes a PHP runtime.
@@ -862,38 +861,38 @@ class PHP {
862
861
  * @param PHPRuntime - Optional. PHP Runtime ID as initialized by loadPHPRuntime.
863
862
  * @param requestHandlerOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
864
863
  */
865
- constructor(r) {
866
- h(this, u);
867
- h(this, T);
868
- h(this, _, !1);
869
- h(this, H, null);
870
- h(this, P, /* @__PURE__ */ new Map());
871
- h(this, R, []);
872
- h(this, k, {});
873
- this.semaphore = new Semaphore({ concurrency: 1 }), r !== void 0 && this.initializeRuntime(r);
864
+ constructor(t) {
865
+ y(this, p);
866
+ y(this, A);
867
+ y(this, P, !1);
868
+ y(this, T, null);
869
+ y(this, E, /* @__PURE__ */ new Map());
870
+ y(this, F, []);
871
+ y(this, M, {});
872
+ this.semaphore = new Semaphore({ concurrency: 1 }), t !== void 0 && this.initializeRuntime(t);
874
873
  }
875
874
  /**
876
875
  * Adds an event listener for a PHP event.
877
876
  * @param eventType - The type of event to listen for.
878
877
  * @param listener - The listener function to be called when the event is triggered.
879
878
  */
880
- addEventListener(r, e) {
881
- c(this, P).has(r) || c(this, P).set(r, /* @__PURE__ */ new Set()), c(this, P).get(r).add(e);
879
+ addEventListener(t, e) {
880
+ u(this, E).has(t) || u(this, E).set(t, /* @__PURE__ */ new Set()), u(this, E).get(t).add(e);
882
881
  }
883
882
  /**
884
883
  * Removes an event listener for a PHP event.
885
884
  * @param eventType - The type of event to remove the listener from.
886
885
  * @param listener - The listener function to be removed.
887
886
  */
888
- removeEventListener(r, e) {
889
- var t;
890
- (t = c(this, P).get(r)) == null || t.delete(e);
887
+ removeEventListener(t, e) {
888
+ var r;
889
+ (r = u(this, E).get(t)) == null || r.delete(e);
891
890
  }
892
- dispatchEvent(r) {
893
- const e = c(this, P).get(r.type);
891
+ dispatchEvent(t) {
892
+ const e = u(this, E).get(t.type);
894
893
  if (e)
895
- for (const t of e)
896
- t(r);
894
+ for (const r of e)
895
+ r(t);
897
896
  }
898
897
  /**
899
898
  * Listens to message sent by the PHP code.
@@ -934,10 +933,10 @@ class PHP {
934
933
  *
935
934
  * @param listener Callback function to handle the message.
936
935
  */
937
- onMessage(r) {
938
- return c(this, R).push(r), async () => {
939
- f(this, R, c(this, R).filter(
940
- (e) => e !== r
936
+ onMessage(t) {
937
+ return u(this, F).push(t), async () => {
938
+ g(this, F, u(this, F).filter(
939
+ (e) => e !== t
941
940
  ));
942
941
  };
943
942
  }
@@ -953,17 +952,17 @@ class PHP {
953
952
  return this.requestHandler.documentRoot;
954
953
  }
955
954
  /** @deprecated Use PHPRequestHandler instead. */
956
- pathToInternalUrl(r) {
957
- return this.requestHandler.pathToInternalUrl(r);
955
+ pathToInternalUrl(t) {
956
+ return this.requestHandler.pathToInternalUrl(t);
958
957
  }
959
958
  /** @deprecated Use PHPRequestHandler instead. */
960
- internalUrlToPath(r) {
961
- return this.requestHandler.internalUrlToPath(r);
959
+ internalUrlToPath(t) {
960
+ return this.requestHandler.internalUrlToPath(t);
962
961
  }
963
- initializeRuntime(r) {
962
+ initializeRuntime(t) {
964
963
  if (this[__private__dont__use])
965
964
  throw new Error("PHP runtime already initialized.");
966
- const e = getLoadedRuntime(r);
965
+ const e = getLoadedRuntime(t);
967
966
  if (!e)
968
967
  throw new Error("Invalid PHP runtime id.");
969
968
  this[__private__dont__use] = e, this[__private__dont__use].ccall(
@@ -1011,29 +1010,29 @@ class PHP {
1011
1010
  require_once $file;
1012
1011
  }
1013
1012
  `
1014
- ), e.onMessage = async (t) => {
1015
- for (const s of c(this, R)) {
1016
- const i = await s(t);
1017
- if (i)
1018
- return i;
1013
+ ), e.onMessage = async (r) => {
1014
+ for (const s of u(this, F)) {
1015
+ const n = await s(r);
1016
+ if (n)
1017
+ return n;
1019
1018
  }
1020
1019
  return "";
1021
- }, f(this, H, improveWASMErrorReporting(e)), this.dispatchEvent({
1020
+ }, g(this, T, improveWASMErrorReporting(e)), this.dispatchEvent({
1022
1021
  type: "runtime.initialized"
1023
1022
  });
1024
1023
  }
1025
1024
  /** @inheritDoc */
1026
- async setSapiName(r) {
1025
+ async setSapiName(t) {
1027
1026
  if (this[__private__dont__use].ccall(
1028
1027
  "wasm_set_sapi_name",
1029
1028
  NUMBER,
1030
1029
  [STRING],
1031
- [r]
1030
+ [t]
1032
1031
  ) !== 0)
1033
1032
  throw new Error(
1034
1033
  "Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
1035
1034
  );
1036
- f(this, T, r);
1035
+ g(this, A, t);
1037
1036
  }
1038
1037
  /**
1039
1038
  * Changes the current working directory in the PHP filesystem.
@@ -1043,19 +1042,19 @@ class PHP {
1043
1042
  *
1044
1043
  * @param path - The new working directory.
1045
1044
  */
1046
- chdir(r) {
1047
- this[__private__dont__use].FS.chdir(r);
1045
+ chdir(t) {
1046
+ this[__private__dont__use].FS.chdir(t);
1048
1047
  }
1049
1048
  /**
1050
1049
  * Do not use. Use new PHPRequestHandler() instead.
1051
1050
  * @deprecated
1052
1051
  */
1053
- async request(r) {
1052
+ async request(t) {
1054
1053
  if (logger.warn(
1055
1054
  "PHP.request() is deprecated. Please use new PHPRequestHandler() instead."
1056
1055
  ), !this.requestHandler)
1057
1056
  throw new Error("No request handler available.");
1058
- return this.requestHandler.request(r);
1057
+ return this.requestHandler.request(t);
1059
1058
  }
1060
1059
  /**
1061
1060
  * Runs PHP code.
@@ -1129,29 +1128,29 @@ class PHP {
1129
1128
  * @deprecated Use stream() instead.
1130
1129
  * @param request - PHP runtime options.
1131
1130
  */
1132
- async run(r) {
1133
- const e = await this.runStream(r), t = await PHPResponse.fromStreamedResponse(
1131
+ async run(t) {
1132
+ const e = await this.runStream(t), r = await PHPResponse.fromStreamedResponse(
1134
1133
  e
1135
1134
  );
1136
- if (t.exitCode !== 0) {
1137
- logger.warn("PHP.run() output was:", t.text);
1135
+ if (r.exitCode !== 0) {
1136
+ logger.warn("PHP.run() output was:", r.text);
1138
1137
  const s = new PHPExecutionFailureError(
1139
- `PHP.run() failed with exit code ${t.exitCode} and the following output: ` + t.errors + `
1138
+ `PHP.run() failed with exit code ${r.exitCode} and the following output: ` + r.errors + `
1140
1139
 
1141
- ` + t.text,
1142
- t,
1140
+ ` + r.text,
1141
+ r,
1143
1142
  "request"
1144
1143
  );
1145
1144
  throw logger.error(s), this.dispatchEvent({
1146
1145
  type: "request.error",
1147
1146
  error: new Error(
1148
- "PHP.run() failed with exit code " + t.exitCode
1147
+ "PHP.run() failed with exit code " + r.exitCode
1149
1148
  ),
1150
1149
  // Distinguish between PHP request and PHP-wasm errors
1151
1150
  source: "request"
1152
1151
  }), s;
1153
1152
  }
1154
- return t;
1153
+ return r;
1155
1154
  }
1156
1155
  /**
1157
1156
  * Runs PHP code and returns a StreamedPHPResponse object that can be used to
@@ -1244,31 +1243,31 @@ class PHP {
1244
1243
  * @param request - PHP runtime options.
1245
1244
  * @returns A StreamedPHPResponse object.
1246
1245
  */
1247
- async runStream(r) {
1246
+ async runStream(t) {
1248
1247
  const e = await this.semaphore.acquire();
1249
- let t;
1250
- const s = d(this, u, D).call(this, () => {
1251
- if (c(this, _) || (d(this, u, L).call(this), f(this, _, !0)), r.scriptPath && !this.fileExists(r.scriptPath))
1248
+ let r;
1249
+ const s = m(this, p, D).call(this, async () => {
1250
+ if (u(this, P) || (await m(this, p, j).call(this), g(this, P, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
1252
1251
  throw new Error(
1253
- `The script path "${r.scriptPath}" does not exist.`
1252
+ `The script path "${t.scriptPath}" does not exist.`
1254
1253
  );
1255
- d(this, u, W).call(this, r.relativeUri || ""), d(this, u, Y).call(this, r.method || "GET");
1256
- const i = normalizeHeaders(r.headers || {}), n = i.host || "example.com:443", o = d(this, u, J).call(this, n, r.protocol || "http");
1257
- if (d(this, u, G).call(this, n), d(this, u, V).call(this, o), d(this, u, K).call(this, i), r.body && (t = d(this, u, X).call(this, r.body)), typeof r.code == "string")
1258
- this.writeFile("/internal/eval.php", r.code), d(this, u, $).call(this, "/internal/eval.php");
1259
- else if (typeof r.scriptPath == "string")
1260
- d(this, u, $).call(this, r.scriptPath || "");
1254
+ m(this, p, $).call(this, t.relativeUri || ""), m(this, p, J).call(this, t.method || "GET");
1255
+ const n = normalizeHeaders(t.headers || {}), i = n.host || "example.com:443", o = m(this, p, Y).call(this, i, t.protocol || "http");
1256
+ if (m(this, p, V).call(this, i), m(this, p, G).call(this, o), m(this, p, K).call(this, n), t.body && (r = m(this, p, X).call(this, t.body)), typeof t.code == "string")
1257
+ this.writeFile("/internal/eval.php", t.code), m(this, p, O).call(this, "/internal/eval.php");
1258
+ else if (typeof t.scriptPath == "string")
1259
+ m(this, p, O).call(this, t.scriptPath || "");
1261
1260
  else
1262
1261
  throw new TypeError(
1263
1262
  "The request object must have either a `code` or a `scriptPath` property."
1264
1263
  );
1265
- const a = d(this, u, z).call(this, r.$_SERVER, i, o);
1266
- for (const p in a)
1267
- d(this, u, Q).call(this, p, a[p]);
1268
- const l = r.env || {};
1269
- for (const p in l)
1270
- d(this, u, B).call(this, p, l[p]);
1271
- return c(this, _) || (d(this, u, L).call(this), f(this, _, !0)), this[__private__dont__use].ccall(
1264
+ const a = m(this, p, B).call(this, t.$_SERVER, n, o);
1265
+ for (const l in a)
1266
+ m(this, p, Q).call(this, l, a[l]);
1267
+ const c = t.env || {};
1268
+ for (const l in c)
1269
+ m(this, p, z).call(this, l, c[l]);
1270
+ return u(this, P) || (await m(this, p, j).call(this), g(this, P, !0)), await this[__private__dont__use].ccall(
1272
1271
  "wasm_sapi_handle_request",
1273
1272
  NUMBER,
1274
1273
  [],
@@ -1276,15 +1275,15 @@ class PHP {
1276
1275
  { async: !0 }
1277
1276
  );
1278
1277
  });
1279
- return await s.catch((i) => {
1278
+ return await s.catch((n) => {
1280
1279
  this.dispatchEvent({
1281
1280
  type: "request.error",
1282
- error: i,
1281
+ error: n,
1283
1282
  // Distinguish between PHP request and PHP-wasm errors
1284
- source: i.source ?? "php-wasm"
1283
+ source: n.source ?? "php-wasm"
1285
1284
  });
1286
1285
  }).finally(() => {
1287
- t && this[__private__dont__use].free(t);
1286
+ r && this[__private__dont__use].free(r);
1288
1287
  }).finally(() => {
1289
1288
  e(), this.dispatchEvent({
1290
1289
  type: "request.end"
@@ -1296,10 +1295,10 @@ class PHP {
1296
1295
  * @param key - The name of the constant.
1297
1296
  * @param value - The value of the constant.
1298
1297
  */
1299
- defineConstant(r, e) {
1300
- let t = {};
1298
+ defineConstant(t, e) {
1299
+ let r = {};
1301
1300
  try {
1302
- t = JSON.parse(
1301
+ r = JSON.parse(
1303
1302
  this.fileExists("/internal/shared/consts.json") && this.readFileAsText("/internal/shared/consts.json") || "{}"
1304
1303
  );
1305
1304
  } catch {
@@ -1307,8 +1306,8 @@ class PHP {
1307
1306
  this.writeFile(
1308
1307
  "/internal/shared/consts.json",
1309
1308
  JSON.stringify({
1310
- ...t,
1311
- [r]: e
1309
+ ...r,
1310
+ [t]: e
1312
1311
  })
1313
1312
  );
1314
1313
  }
@@ -1319,14 +1318,14 @@ class PHP {
1319
1318
  *
1320
1319
  * @param path - The directory path to create.
1321
1320
  */
1322
- mkdir(r) {
1323
- return FSHelpers.mkdir(this[__private__dont__use].FS, r);
1321
+ mkdir(t) {
1322
+ return FSHelpers.mkdir(this[__private__dont__use].FS, t);
1324
1323
  }
1325
1324
  /**
1326
1325
  * @deprecated Use mkdir instead.
1327
1326
  */
1328
- mkdirTree(r) {
1329
- return FSHelpers.mkdir(this[__private__dont__use].FS, r);
1327
+ mkdirTree(t) {
1328
+ return FSHelpers.mkdir(this[__private__dont__use].FS, t);
1330
1329
  }
1331
1330
  /**
1332
1331
  * Reads a file from the PHP filesystem and returns it as a string.
@@ -1335,8 +1334,8 @@ class PHP {
1335
1334
  * @param path - The file path to read.
1336
1335
  * @returns The file contents.
1337
1336
  */
1338
- readFileAsText(r) {
1339
- return FSHelpers.readFileAsText(this[__private__dont__use].FS, r);
1337
+ readFileAsText(t) {
1338
+ return FSHelpers.readFileAsText(this[__private__dont__use].FS, t);
1340
1339
  }
1341
1340
  /**
1342
1341
  * Reads a file from the PHP filesystem and returns it as an array buffer.
@@ -1345,8 +1344,8 @@ class PHP {
1345
1344
  * @param path - The file path to read.
1346
1345
  * @returns The file contents.
1347
1346
  */
1348
- readFileAsBuffer(r) {
1349
- return FSHelpers.readFileAsBuffer(this[__private__dont__use].FS, r);
1347
+ readFileAsBuffer(t) {
1348
+ return FSHelpers.readFileAsBuffer(this[__private__dont__use].FS, t);
1350
1349
  }
1351
1350
  /**
1352
1351
  * Overwrites data in a file in the PHP filesystem.
@@ -1355,8 +1354,8 @@ class PHP {
1355
1354
  * @param path - The file path to write to.
1356
1355
  * @param data - The data to write to the file.
1357
1356
  */
1358
- writeFile(r, e) {
1359
- return FSHelpers.writeFile(this[__private__dont__use].FS, r, e);
1357
+ writeFile(t, e) {
1358
+ return FSHelpers.writeFile(this[__private__dont__use].FS, t, e);
1360
1359
  }
1361
1360
  /**
1362
1361
  * Removes a file from the PHP filesystem.
@@ -1364,8 +1363,8 @@ class PHP {
1364
1363
  * @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
1365
1364
  * @param path - The file path to remove.
1366
1365
  */
1367
- unlink(r) {
1368
- return FSHelpers.unlink(this[__private__dont__use].FS, r);
1366
+ unlink(t) {
1367
+ return FSHelpers.unlink(this[__private__dont__use].FS, t);
1369
1368
  }
1370
1369
  /**
1371
1370
  * Moves a file or directory in the PHP filesystem to a
@@ -1374,8 +1373,8 @@ class PHP {
1374
1373
  * @param oldPath The path to rename.
1375
1374
  * @param newPath The new path.
1376
1375
  */
1377
- mv(r, e) {
1378
- return FSHelpers.mv(this[__private__dont__use].FS, r, e);
1376
+ mv(t, e) {
1377
+ return FSHelpers.mv(this[__private__dont__use].FS, t, e);
1379
1378
  }
1380
1379
  /**
1381
1380
  * Removes a directory from the PHP filesystem.
@@ -1383,8 +1382,8 @@ class PHP {
1383
1382
  * @param path The directory path to remove.
1384
1383
  * @param options Options for the removal.
1385
1384
  */
1386
- rmdir(r, e = { recursive: !0 }) {
1387
- return FSHelpers.rmdir(this[__private__dont__use].FS, r, e);
1385
+ rmdir(t, e = { recursive: !0 }) {
1386
+ return FSHelpers.rmdir(this[__private__dont__use].FS, t, e);
1388
1387
  }
1389
1388
  /**
1390
1389
  * Lists the files and directories in the given directory.
@@ -1393,10 +1392,10 @@ class PHP {
1393
1392
  * @param options - Options for the listing.
1394
1393
  * @returns The list of files and directories in the given directory.
1395
1394
  */
1396
- listFiles(r, e = { prependPath: !1 }) {
1395
+ listFiles(t, e = { prependPath: !1 }) {
1397
1396
  return FSHelpers.listFiles(
1398
1397
  this[__private__dont__use].FS,
1399
- r,
1398
+ t,
1400
1399
  e
1401
1400
  );
1402
1401
  }
@@ -1406,8 +1405,8 @@ class PHP {
1406
1405
  * @param path – The path to check.
1407
1406
  * @returns True if the path is a directory, false otherwise.
1408
1407
  */
1409
- isDir(r) {
1410
- return FSHelpers.isDir(this[__private__dont__use].FS, r);
1408
+ isDir(t) {
1409
+ return FSHelpers.isDir(this[__private__dont__use].FS, t);
1411
1410
  }
1412
1411
  /**
1413
1412
  * Checks if a file exists in the PHP filesystem.
@@ -1415,16 +1414,16 @@ class PHP {
1415
1414
  * @param path – The path to check.
1416
1415
  * @returns True if the path is a file, false otherwise.
1417
1416
  */
1418
- isFile(r) {
1419
- return FSHelpers.isFile(this[__private__dont__use].FS, r);
1417
+ isFile(t) {
1418
+ return FSHelpers.isFile(this[__private__dont__use].FS, t);
1420
1419
  }
1421
1420
  /**
1422
1421
  * Creates a symlink in the PHP filesystem.
1423
1422
  * @param target
1424
1423
  * @param path
1425
1424
  */
1426
- symlink(r, e) {
1427
- return FSHelpers.symlink(this[__private__dont__use].FS, r, e);
1425
+ symlink(t, e) {
1426
+ return FSHelpers.symlink(this[__private__dont__use].FS, t, e);
1428
1427
  }
1429
1428
  /**
1430
1429
  * Checks if a path is a symlink in the PHP filesystem.
@@ -1432,8 +1431,8 @@ class PHP {
1432
1431
  * @param path
1433
1432
  * @returns True if the path is a symlink, false otherwise.
1434
1433
  */
1435
- isSymlink(r) {
1436
- return FSHelpers.isSymlink(this[__private__dont__use].FS, r);
1434
+ isSymlink(t) {
1435
+ return FSHelpers.isSymlink(this[__private__dont__use].FS, t);
1437
1436
  }
1438
1437
  /**
1439
1438
  * Reads the target of a symlink in the PHP filesystem.
@@ -1441,16 +1440,16 @@ class PHP {
1441
1440
  * @param path
1442
1441
  * @returns The target of the symlink.
1443
1442
  */
1444
- readlink(r) {
1445
- return FSHelpers.readlink(this[__private__dont__use].FS, r);
1443
+ readlink(t) {
1444
+ return FSHelpers.readlink(this[__private__dont__use].FS, t);
1446
1445
  }
1447
1446
  /**
1448
1447
  * Resolves the real path of a file in the PHP filesystem.
1449
1448
  * @param path
1450
1449
  * @returns The real path of the file.
1451
1450
  */
1452
- realpath(r) {
1453
- return FSHelpers.realpath(this[__private__dont__use].FS, r);
1451
+ realpath(t) {
1452
+ return FSHelpers.realpath(this[__private__dont__use].FS, t);
1454
1453
  }
1455
1454
  /**
1456
1455
  * Checks if a file (or a directory) exists in the PHP filesystem.
@@ -1458,8 +1457,8 @@ class PHP {
1458
1457
  * @param path - The file path to check.
1459
1458
  * @returns True if the file exists, false otherwise.
1460
1459
  */
1461
- fileExists(r) {
1462
- return FSHelpers.fileExists(this[__private__dont__use].FS, r);
1460
+ fileExists(t) {
1461
+ return FSHelpers.fileExists(this[__private__dont__use].FS, t);
1463
1462
  }
1464
1463
  /**
1465
1464
  * Hot-swaps the PHP runtime for a new one without
@@ -1471,17 +1470,17 @@ class PHP {
1471
1470
  * is fully decoupled from the request handler and
1472
1471
  * accepts a constructor-level cwd argument.
1473
1472
  */
1474
- async hotSwapPHPRuntime(r, e) {
1475
- const t = this[__private__dont__use].FS, s = [];
1476
- for (const [i, n] of Object.entries(c(this, k)))
1477
- s.push({ mountHandler: n.mountHandler, vfsPath: i }), await n.unmount();
1473
+ async hotSwapPHPRuntime(t, e) {
1474
+ const r = this[__private__dont__use].FS, s = [];
1475
+ for (const [n, i] of Object.entries(u(this, M)))
1476
+ s.push({ mountHandler: i.mountHandler, vfsPath: n }), await i.unmount();
1478
1477
  try {
1479
1478
  this.exit();
1480
1479
  } catch {
1481
1480
  }
1482
- this.initializeRuntime(r), c(this, T) && this.setSapiName(c(this, T)), copyFS(t, this[__private__dont__use].FS, "/internal"), e && copyFS(t, this[__private__dont__use].FS, e);
1483
- for (const { mountHandler: i, vfsPath: n } of s)
1484
- this.mkdir(n), await this.mount(n, i);
1481
+ this.initializeRuntime(t), u(this, A) && this.setSapiName(u(this, A)), copyFS(r, this[__private__dont__use].FS, "/internal"), e && copyFS(r, this[__private__dont__use].FS, e);
1482
+ for (const { mountHandler: n, vfsPath: i } of s)
1483
+ this.mkdir(i), await this.mount(i, n);
1485
1484
  }
1486
1485
  /**
1487
1486
  * Mounts a filesystem to a given path in the PHP filesystem.
@@ -1490,18 +1489,18 @@ class PHP {
1490
1489
  * @param mountHandler - The mount handler to use.
1491
1490
  * @return Unmount function to unmount the filesystem.
1492
1491
  */
1493
- async mount(r, e) {
1494
- const t = await e(
1492
+ async mount(t, e) {
1493
+ const r = await e(
1495
1494
  this,
1496
1495
  this[__private__dont__use].FS,
1497
- r
1496
+ t
1498
1497
  ), s = {
1499
1498
  mountHandler: e,
1500
1499
  unmount: async () => {
1501
- await t(), delete c(this, k)[r];
1500
+ await r(), delete u(this, M)[t];
1502
1501
  }
1503
1502
  };
1504
- return c(this, k)[r] = s, () => {
1503
+ return u(this, M)[t] = s, () => {
1505
1504
  s.unmount();
1506
1505
  };
1507
1506
  }
@@ -1518,45 +1517,51 @@ class PHP {
1518
1517
  * @param argv - The arguments to pass to the CLI.
1519
1518
  * @returns The exit code of the CLI session.
1520
1519
  */
1521
- async cli(r, e = {}) {
1522
- const t = await this.semaphore.acquire(), s = e.env || {};
1523
- for (const [i, n] of Object.entries(s))
1524
- d(this, u, B).call(this, i, n);
1525
- r = [r[0], "-c", PHP_INI_PATH, ...r.slice(1)];
1526
- for (const i of r)
1520
+ async cli(t, e = {}) {
1521
+ const r = await this.semaphore.acquire(), s = e.env || {};
1522
+ for (const [n, i] of Object.entries(s))
1523
+ m(this, p, z).call(this, n, i);
1524
+ t = [t[0], "-c", PHP_INI_PATH, ...t.slice(1)];
1525
+ for (const n of t)
1527
1526
  this[__private__dont__use].ccall(
1528
1527
  "wasm_add_cli_arg",
1529
1528
  null,
1530
1529
  [STRING],
1531
- [i]
1530
+ [n]
1532
1531
  );
1533
- return await d(this, u, D).call(this, () => this[__private__dont__use].ccall("run_cli", null, [], [], {
1534
- async: !0
1535
- })).then((i) => (i.exitCode.finally(t), i));
1532
+ return await m(this, p, D).call(this, async () => await this[__private__dont__use].ccall(
1533
+ "run_cli",
1534
+ null,
1535
+ [],
1536
+ [],
1537
+ {
1538
+ async: !0
1539
+ }
1540
+ )).then((n) => (n.exitCode.finally(r), n));
1536
1541
  }
1537
- setSkipShebang(r) {
1542
+ setSkipShebang(t) {
1538
1543
  this[__private__dont__use].ccall(
1539
1544
  "wasm_set_skip_shebang",
1540
1545
  null,
1541
1546
  [NUMBER],
1542
- [r ? 1 : 0]
1547
+ [t ? 1 : 0]
1543
1548
  );
1544
1549
  }
1545
- exit(r = 0) {
1550
+ exit(t = 0) {
1546
1551
  this.dispatchEvent({
1547
1552
  type: "runtime.beforedestroy"
1548
1553
  });
1549
1554
  try {
1550
- this[__private__dont__use]._exit(r);
1555
+ this[__private__dont__use]._exit(t);
1551
1556
  } catch {
1552
1557
  }
1553
- f(this, _, !1), f(this, H, null), this[__private__dont__use] && (delete this[__private__dont__use].onMessage, delete this[__private__dont__use]);
1558
+ g(this, P, !1), g(this, T, null), this[__private__dont__use] && (delete this[__private__dont__use].onMessage, delete this[__private__dont__use]);
1554
1559
  }
1555
1560
  [Symbol.dispose]() {
1556
- c(this, _) && this.exit(0);
1561
+ u(this, P) && this.exit(0);
1557
1562
  }
1558
1563
  }
1559
- T = new WeakMap(), _ = new WeakMap(), H = new WeakMap(), P = new WeakMap(), R = new WeakMap(), k = new WeakMap(), u = new WeakSet(), /**
1564
+ A = new WeakMap(), P = new WeakMap(), T = new WeakMap(), E = new WeakMap(), F = new WeakMap(), M = new WeakMap(), p = new WeakSet(), /**
1560
1565
  * Prepares the $_SERVER entries for the PHP runtime.
1561
1566
  *
1562
1567
  * @param defaults Default entries to include in $_SERVER.
@@ -1565,90 +1570,92 @@ T = new WeakMap(), _ = new WeakMap(), H = new WeakMap(), P = new WeakMap(), R =
1565
1570
  * was provided.
1566
1571
  * @returns Computed $_SERVER entries.
1567
1572
  */
1568
- z = function(r, e, t) {
1573
+ B = function(t, e, r) {
1569
1574
  const s = {
1570
- ...r || {}
1575
+ ...t || {}
1571
1576
  };
1572
- s.HTTPS = s.HTTPS || t === 443 ? "on" : "off";
1573
- for (const i in e) {
1574
- let n = "HTTP_";
1575
- ["content-type", "content-length"].includes(i.toLowerCase()) && (n = ""), s[`${n}${i.toUpperCase().replace(/-/g, "_")}`] = e[i];
1577
+ s.HTTPS = s.HTTPS || r === 443 ? "on" : "off";
1578
+ for (const n in e) {
1579
+ let i = "HTTP_";
1580
+ ["content-type", "content-length"].includes(n.toLowerCase()) && (i = ""), s[`${i}${n.toUpperCase().replace(/-/g, "_")}`] = e[n];
1576
1581
  }
1577
1582
  return s;
1578
- }, L = function() {
1579
- this[__private__dont__use].ccall("php_wasm_init", null, [], []);
1580
- }, W = function(r) {
1583
+ }, j = async function() {
1584
+ await this[__private__dont__use].ccall("php_wasm_init", null, [], [], {
1585
+ async: !0
1586
+ });
1587
+ }, $ = function(t) {
1581
1588
  this[__private__dont__use].ccall(
1582
1589
  "wasm_set_request_uri",
1583
1590
  null,
1584
1591
  [STRING],
1585
- [r]
1592
+ [t]
1586
1593
  );
1587
1594
  let e = "";
1588
- r.includes("?") && (e = r.substring(r.indexOf("?") + 1)), this[__private__dont__use].ccall(
1595
+ t.includes("?") && (e = t.substring(t.indexOf("?") + 1)), this[__private__dont__use].ccall(
1589
1596
  "wasm_set_query_string",
1590
1597
  null,
1591
1598
  [STRING],
1592
1599
  [e]
1593
1600
  );
1594
- }, G = function(r) {
1601
+ }, V = function(t) {
1595
1602
  this[__private__dont__use].ccall(
1596
1603
  "wasm_set_request_host",
1597
1604
  null,
1598
1605
  [STRING],
1599
- [r]
1606
+ [t]
1600
1607
  );
1601
- }, V = function(r) {
1608
+ }, G = function(t) {
1602
1609
  this[__private__dont__use].ccall(
1603
1610
  "wasm_set_request_port",
1604
1611
  null,
1605
1612
  [NUMBER],
1606
- [r]
1613
+ [t]
1607
1614
  );
1608
- }, J = function(r, e) {
1609
- let t;
1615
+ }, Y = function(t, e) {
1616
+ let r;
1610
1617
  try {
1611
- t = parseInt(new URL(r).port, 10);
1618
+ r = parseInt(new URL(t).port, 10);
1612
1619
  } catch {
1613
1620
  }
1614
- return (!t || isNaN(t) || t === 80) && (t = e === "https" ? 443 : 80), t;
1615
- }, Y = function(r) {
1621
+ return (!r || isNaN(r) || r === 80) && (r = e === "https" ? 443 : 80), r;
1622
+ }, J = function(t) {
1616
1623
  this[__private__dont__use].ccall(
1617
1624
  "wasm_set_request_method",
1618
1625
  null,
1619
1626
  [STRING],
1620
- [r]
1627
+ [t]
1621
1628
  );
1622
- }, K = function(r) {
1623
- r.cookie && this[__private__dont__use].ccall(
1629
+ }, K = function(t) {
1630
+ t.cookie && this[__private__dont__use].ccall(
1624
1631
  "wasm_set_cookies",
1625
1632
  null,
1626
1633
  [STRING],
1627
- [r.cookie]
1628
- ), r["content-type"] && this[__private__dont__use].ccall(
1634
+ [t.cookie]
1635
+ ), t["content-type"] && this[__private__dont__use].ccall(
1629
1636
  "wasm_set_content_type",
1630
1637
  null,
1631
1638
  [STRING],
1632
- [r["content-type"]]
1633
- ), r["content-length"] && this[__private__dont__use].ccall(
1639
+ [t["content-type"]]
1640
+ ), t["content-length"] && this[__private__dont__use].ccall(
1634
1641
  "wasm_set_content_length",
1635
1642
  null,
1636
1643
  [NUMBER],
1637
- [parseInt(r["content-length"], 10)]
1644
+ [parseInt(t["content-length"], 10)]
1638
1645
  );
1639
- }, X = function(r) {
1640
- let e, t;
1641
- typeof r == "string" ? (logger.warn(
1646
+ }, X = function(t) {
1647
+ let e, r;
1648
+ typeof t == "string" ? (logger.warn(
1642
1649
  "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"
1643
- ), t = this[__private__dont__use].lengthBytesUTF8(r), e = t + 1) : (t = r.byteLength, e = r.byteLength);
1650
+ ), r = this[__private__dont__use].lengthBytesUTF8(t), e = r + 1) : (r = t.byteLength, e = t.byteLength);
1644
1651
  const s = this[__private__dont__use].malloc(e);
1645
1652
  if (!s)
1646
1653
  throw new Error("Could not allocate memory for the request body.");
1647
- return typeof r == "string" ? this[__private__dont__use].stringToUTF8(
1648
- r,
1654
+ return typeof t == "string" ? this[__private__dont__use].stringToUTF8(
1655
+ t,
1649
1656
  s,
1650
1657
  e + 1
1651
- ) : this[__private__dont__use].HEAPU8.set(r, s), this[__private__dont__use].ccall(
1658
+ ) : this[__private__dont__use].HEAPU8.set(t, s), this[__private__dont__use].ccall(
1652
1659
  "wasm_set_request_body",
1653
1660
  null,
1654
1661
  [NUMBER],
@@ -1657,155 +1664,157 @@ z = function(r, e, t) {
1657
1664
  "wasm_set_content_length",
1658
1665
  null,
1659
1666
  [NUMBER],
1660
- [t]
1667
+ [r]
1661
1668
  ), s;
1662
- }, $ = function(r) {
1669
+ }, O = function(t) {
1663
1670
  this[__private__dont__use].ccall(
1664
1671
  "wasm_set_path_translated",
1665
1672
  null,
1666
1673
  [STRING],
1667
- [r]
1674
+ [t]
1668
1675
  );
1669
- }, Q = function(r, e) {
1676
+ }, Q = function(t, e) {
1670
1677
  this[__private__dont__use].ccall(
1671
1678
  "wasm_add_SERVER_entry",
1672
1679
  null,
1673
1680
  [STRING, STRING],
1674
- [r, e]
1681
+ [t, e]
1675
1682
  );
1676
- }, B = function(r, e) {
1683
+ }, z = function(t, e) {
1677
1684
  this[__private__dont__use].ccall(
1678
1685
  "wasm_add_ENV_entry",
1679
1686
  null,
1680
1687
  [STRING, STRING],
1681
- [r, e]
1688
+ [t, e]
1682
1689
  );
1683
- }, D = async function(r) {
1684
- const e = this[__private__dont__use], t = await createInvertedReadableStream();
1685
- e.onHeaders = (m) => {
1686
- a || s || t.controller.enqueue(m.slice());
1690
+ }, D = async function(t) {
1691
+ const e = this[__private__dont__use], r = await createInvertedReadableStream();
1692
+ e.onHeaders = (d) => {
1693
+ a || s || r.controller.enqueue(d.slice());
1687
1694
  };
1688
1695
  let s = !1;
1689
- const i = () => {
1690
- s || (s = !0, t.controller.close());
1691
- }, n = await createInvertedReadableStream();
1692
- e.onStdout = (m) => {
1693
- i(), !a && n.controller.enqueue(m.slice());
1696
+ const n = () => {
1697
+ s || (s = !0, r.controller.close());
1698
+ }, i = await createInvertedReadableStream();
1699
+ e.onStdout = (d) => {
1700
+ n(), !a && i.controller.enqueue(d.slice());
1694
1701
  };
1695
1702
  const o = await createInvertedReadableStream();
1696
- e.onStderr = (m) => {
1697
- a || o.controller.enqueue(m.slice());
1703
+ e.onStderr = (d) => {
1704
+ a || o.controller.enqueue(d.slice());
1698
1705
  };
1699
- let a = !1, l;
1700
- const E = (async () => {
1701
- var m;
1706
+ let a = !1, c;
1707
+ const h = (async () => {
1708
+ var d;
1702
1709
  try {
1703
1710
  return await Promise.race([
1704
- r(),
1705
- new Promise((N, U) => {
1706
- var b;
1707
- l = (w) => {
1708
- if (logger.error(w), logger.error(w.error), !isExitCode(w.error)) {
1709
- const j = new Error("Rethrown");
1710
- j.cause = w.error, j.betterMessage = w.message, U(j);
1711
+ t(),
1712
+ new Promise((_, w) => {
1713
+ var k;
1714
+ c = (v) => {
1715
+ if (isExitCode(v.error) && v.error.status === 0)
1716
+ _(v.error.status);
1717
+ else {
1718
+ const U = new Error("Rethrown");
1719
+ U.cause = v.error, U.betterMessage = v.message, w(U);
1711
1720
  }
1712
- }, (b = c(this, H)) == null || b.addEventListener(
1721
+ }, (k = u(this, T)) == null || k.addEventListener(
1713
1722
  "error",
1714
- l,
1723
+ c,
1715
1724
  { once: !0 }
1716
1725
  );
1717
1726
  })
1718
1727
  ]);
1719
- } catch (S) {
1720
- if (isExitCode(S))
1721
- return S.exitCode;
1722
- n.controller.error(S), o.controller.error(S), t.controller.error(S), a = !0;
1723
- for (const w in this)
1724
- typeof this[w] == "function" && (this[w] = () => {
1728
+ } catch (f) {
1729
+ if (isExitCode(f))
1730
+ return f.status;
1731
+ i.controller.error(f), o.controller.error(f), r.controller.error(f), a = !0;
1732
+ for (const v in this)
1733
+ typeof this[v] == "function" && (this[v] = () => {
1725
1734
  throw new Error(
1726
1735
  "PHP runtime has crashed – see the earlier error for details."
1727
1736
  );
1728
1737
  });
1729
1738
  this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
1730
- const N = S, U = "betterMessage" in N ? N.betterMessage : N.message, b = new Error(U);
1731
- throw b.cause = N, logger.error(b), b;
1739
+ const _ = f, w = "betterMessage" in _ ? _.betterMessage : _.message, k = new Error(w);
1740
+ throw k.cause = _, logger.error(k), k;
1732
1741
  } finally {
1733
- a || (n.controller.close(), o.controller.close(), i(), a = !0), (m = c(this, H)) == null || m.removeEventListener(
1742
+ a || (i.controller.close(), o.controller.close(), n(), a = !0), (d = u(this, T)) == null || d.removeEventListener(
1734
1743
  "error",
1735
- l
1744
+ c
1736
1745
  );
1737
1746
  }
1738
1747
  })();
1739
1748
  return new StreamedPHPResponse(
1740
- t.stream,
1741
- n.stream,
1749
+ r.stream,
1750
+ i.stream,
1742
1751
  o.stream,
1743
- E
1752
+ h
1744
1753
  );
1745
1754
  };
1746
- function normalizeHeaders(r) {
1755
+ function normalizeHeaders(t) {
1747
1756
  const e = {};
1748
- for (const t in r)
1749
- e[t.toLowerCase()] = r[t];
1757
+ for (const r in t)
1758
+ e[r.toLowerCase()] = t[r];
1750
1759
  return e;
1751
1760
  }
1752
- function copyFS(r, e, t) {
1761
+ function copyFS(t, e, r) {
1753
1762
  let s;
1754
1763
  try {
1755
- s = r.lookupPath(t);
1764
+ s = t.lookupPath(r);
1756
1765
  } catch {
1757
1766
  return;
1758
1767
  }
1759
1768
  if (!("contents" in s.node))
1760
1769
  return;
1761
- if (!r.isDir(s.node.mode)) {
1762
- e.writeFile(t, r.readFile(t));
1770
+ if (!t.isDir(s.node.mode)) {
1771
+ e.writeFile(r, t.readFile(r));
1763
1772
  return;
1764
1773
  }
1765
- e.mkdirTree(t);
1766
- const i = r.readdir(t).filter((n) => n !== "." && n !== "..");
1767
- for (const n of i)
1768
- copyFS(r, e, joinPaths(t, n));
1774
+ e.mkdirTree(r);
1775
+ const n = t.readdir(r).filter((i) => i !== "." && i !== "..");
1776
+ for (const i of n)
1777
+ copyFS(t, e, joinPaths(r, i));
1769
1778
  }
1770
- async function createInvertedReadableStream(r = {}) {
1779
+ async function createInvertedReadableStream(t = {}) {
1771
1780
  let e;
1772
- const t = new Promise(
1773
- (n) => {
1774
- e = n;
1781
+ const r = new Promise(
1782
+ (i) => {
1783
+ e = i;
1775
1784
  }
1776
1785
  ), s = new ReadableStream({
1777
- ...r,
1778
- start(n) {
1779
- if (e(n), r.start)
1780
- return r.start(n);
1786
+ ...t,
1787
+ start(i) {
1788
+ if (e(i), t.start)
1789
+ return t.start(i);
1781
1790
  }
1782
- }), i = await t;
1791
+ }), n = await r;
1783
1792
  return {
1784
1793
  stream: s,
1785
- controller: i
1794
+ controller: n
1786
1795
  };
1787
1796
  }
1788
- async function getPhpIniEntries(r, e) {
1789
- const t = parse(await r.readFileAsText(PHP_INI_PATH));
1797
+ async function getPhpIniEntries(t, e) {
1798
+ const r = parse(await t.readFileAsText(PHP_INI_PATH));
1790
1799
  if (e === void 0)
1791
- return t;
1800
+ return r;
1792
1801
  const s = {};
1793
- for (const i of e)
1794
- s[i] = t[i];
1802
+ for (const n of e)
1803
+ s[n] = r[n];
1795
1804
  return s;
1796
1805
  }
1797
- async function setPhpIniEntries(r, e) {
1798
- const t = parse(await r.readFileAsText(PHP_INI_PATH));
1799
- for (const [s, i] of Object.entries(e))
1800
- i == null ? delete t[s] : t[s] = i;
1801
- await r.writeFile(PHP_INI_PATH, stringify(t));
1806
+ async function setPhpIniEntries(t, e) {
1807
+ const r = parse(await t.readFileAsText(PHP_INI_PATH));
1808
+ for (const [s, n] of Object.entries(e))
1809
+ n == null ? delete r[s] : r[s] = n;
1810
+ await t.writeFile(PHP_INI_PATH, stringify(r));
1802
1811
  }
1803
- async function withPHPIniValues(r, e, t) {
1804
- const s = await r.readFileAsText(PHP_INI_PATH);
1812
+ async function withPHPIniValues(t, e, r) {
1813
+ const s = await t.readFileAsText(PHP_INI_PATH);
1805
1814
  try {
1806
- return await setPhpIniEntries(r, e), await t();
1815
+ return await setPhpIniEntries(t, e), await r();
1807
1816
  } finally {
1808
- await r.writeFile(PHP_INI_PATH, s);
1817
+ await t.writeFile(PHP_INI_PATH, s);
1809
1818
  }
1810
1819
  }
1811
1820
  class HttpCookieStore {
@@ -1814,64 +1823,64 @@ class HttpCookieStore {
1814
1823
  }
1815
1824
  rememberCookiesFromResponseHeaders(e) {
1816
1825
  if (e != null && e["set-cookie"])
1817
- for (const t of e["set-cookie"])
1826
+ for (const r of e["set-cookie"])
1818
1827
  try {
1819
- if (!t.includes("="))
1828
+ if (!r.includes("="))
1820
1829
  continue;
1821
- const s = t.indexOf("="), i = t.substring(0, s), n = t.substring(s + 1).split(";")[0];
1822
- this.cookies[i] = n;
1830
+ const s = r.indexOf("="), n = r.substring(0, s), i = r.substring(s + 1).split(";")[0];
1831
+ this.cookies[n] = i;
1823
1832
  } catch (s) {
1824
1833
  logger.error(s);
1825
1834
  }
1826
1835
  }
1827
1836
  getCookieRequestHeader() {
1828
1837
  const e = [];
1829
- for (const t in this.cookies)
1830
- e.push(`${t}=${this.cookies[t]}`);
1838
+ for (const r in this.cookies)
1839
+ e.push(`${r}=${this.cookies[r]}`);
1831
1840
  return e.join("; ");
1832
1841
  }
1833
1842
  }
1834
- function streamReadFileFromPHP(r, e) {
1843
+ function streamReadFileFromPHP(t, e) {
1835
1844
  return new ReadableStream({
1836
- async pull(t) {
1837
- const s = await r.readFileAsBuffer(e);
1838
- t.enqueue(s), t.close();
1845
+ async pull(r) {
1846
+ const s = await t.readFileAsBuffer(e);
1847
+ r.enqueue(s), r.close();
1839
1848
  }
1840
1849
  });
1841
1850
  }
1842
- async function* iteratePhpFiles(r, e, {
1843
- relativePaths: t = !0,
1851
+ async function* iteratePhpFiles(t, e, {
1852
+ relativePaths: r = !0,
1844
1853
  pathPrefix: s,
1845
- exceptPaths: i = []
1854
+ exceptPaths: n = []
1846
1855
  } = {}) {
1847
1856
  e = normalizePath(e);
1848
- const n = [e];
1849
- for (; n.length; ) {
1850
- const o = n.pop();
1857
+ const i = [e];
1858
+ for (; i.length; ) {
1859
+ const o = i.pop();
1851
1860
  if (!o)
1852
1861
  return;
1853
- const a = await r.listFiles(o);
1854
- for (const l of a) {
1855
- const p = `${o}/${l}`;
1856
- if (i.includes(p.substring(e.length + 1)))
1862
+ const a = await t.listFiles(o);
1863
+ for (const c of a) {
1864
+ const l = `${o}/${c}`;
1865
+ if (n.includes(l.substring(e.length + 1)))
1857
1866
  continue;
1858
- await r.isDir(p) ? n.push(p) : yield new StreamedFile(
1859
- streamReadFileFromPHP(r, p),
1860
- t ? joinPaths(
1867
+ await t.isDir(l) ? i.push(l) : yield new StreamedFile(
1868
+ streamReadFileFromPHP(t, l),
1869
+ r ? joinPaths(
1861
1870
  s || "",
1862
- p.substring(e.length + 1)
1863
- ) : p
1871
+ l.substring(e.length + 1)
1872
+ ) : l
1864
1873
  );
1865
1874
  }
1866
1875
  }
1867
1876
  }
1868
- function writeFilesStreamToPhp(r, e) {
1877
+ function writeFilesStreamToPhp(t, e) {
1869
1878
  return new WritableStream({
1870
- async write(t) {
1871
- const s = joinPaths(e, t.name);
1872
- t.type === "directory" ? await r.mkdir(s) : (await r.mkdir(dirname(s)), await r.writeFile(
1879
+ async write(r) {
1880
+ const s = joinPaths(e, r.name);
1881
+ r.type === "directory" ? await t.mkdir(s) : (await t.mkdir(dirname(s)), await t.writeFile(
1873
1882
  s,
1874
- new Uint8Array(await t.arrayBuffer())
1883
+ new Uint8Array(await r.arrayBuffer())
1875
1884
  ));
1876
1885
  }
1877
1886
  });
@@ -1940,8 +1949,8 @@ class PHPProcessManager {
1940
1949
  this.primaryIdle = !0;
1941
1950
  }
1942
1951
  };
1943
- const t = this.nextInstance || this.spawn({ isPrimary: !1 });
1944
- return this.semaphore.remaining > 0 ? this.nextInstance = this.spawn({ isPrimary: !1 }) : this.nextInstance = null, await t;
1952
+ const r = this.nextInstance || this.spawn({ isPrimary: !1 });
1953
+ return this.semaphore.remaining > 0 ? this.nextInstance = this.spawn({ isPrimary: !1 }) : this.nextInstance = null, await r;
1945
1954
  }
1946
1955
  /**
1947
1956
  * Initiated spawning of a new PHP instance.
@@ -1954,19 +1963,19 @@ class PHPProcessManager {
1954
1963
  throw new Error(
1955
1964
  "Requested spawning a primary PHP instance when another primary instance already started spawning."
1956
1965
  );
1957
- const t = this.doSpawn(e);
1958
- this.allInstances.push(t);
1966
+ const r = this.doSpawn(e);
1967
+ this.allInstances.push(r);
1959
1968
  const s = () => {
1960
1969
  this.allInstances = this.allInstances.filter(
1961
- (i) => i !== t
1970
+ (n) => n !== r
1962
1971
  );
1963
1972
  };
1964
- return t.catch((i) => {
1965
- throw s(), i;
1966
- }).then((i) => ({
1967
- ...i,
1973
+ return r.catch((n) => {
1974
+ throw s(), n;
1975
+ }).then((n) => ({
1976
+ ...n,
1968
1977
  reap: () => {
1969
- s(), i.reap();
1978
+ s(), n.reap();
1970
1979
  }
1971
1980
  }));
1972
1981
  }
@@ -1974,9 +1983,9 @@ class PHPProcessManager {
1974
1983
  * Actually acquires the lock and spawns a new PHP instance.
1975
1984
  */
1976
1985
  async doSpawn(e) {
1977
- let t;
1986
+ let r;
1978
1987
  try {
1979
- t = await this.semaphore.acquire();
1988
+ r = await this.semaphore.acquire();
1980
1989
  } catch (s) {
1981
1990
  throw s instanceof AcquireTimeoutError ? new MaxPhpInstancesError(this.maxPhpInstances) : s;
1982
1991
  }
@@ -1985,17 +1994,17 @@ class PHPProcessManager {
1985
1994
  return {
1986
1995
  php: s,
1987
1996
  reap() {
1988
- s.exit(), t();
1997
+ s.exit(), r();
1989
1998
  }
1990
1999
  };
1991
2000
  } catch (s) {
1992
- throw t(), s;
2001
+ throw r(), s;
1993
2002
  }
1994
2003
  }
1995
2004
  async [Symbol.asyncDispose]() {
1996
2005
  this.primaryPhp && this.primaryPhp.exit(), await Promise.all(
1997
2006
  this.allInstances.map(
1998
- (e) => e.then(({ reap: t }) => t())
2007
+ (e) => e.then(({ reap: r }) => r())
1999
2008
  )
2000
2009
  );
2001
2010
  }
@@ -2010,37 +2019,37 @@ const SupportedPHPVersions = [
2010
2019
  "7.3",
2011
2020
  "7.2"
2012
2021
  ], LatestSupportedPHPVersion = SupportedPHPVersions[0], SupportedPHPVersionsList = SupportedPHPVersions, DEFAULT_BASE_URL = "http://example.com";
2013
- function toRelativeUrl(r) {
2014
- return r.toString().substring(r.origin.length);
2015
- }
2016
- function removePathPrefix(r, e) {
2017
- return !e || !r.startsWith(e) ? r : r.substring(e.length);
2018
- }
2019
- function ensurePathPrefix(r, e) {
2020
- return !e || r.startsWith(e) ? r : e + r;
2021
- }
2022
- async function encodeAsMultipart(r) {
2023
- const e = `----${Math.random().toString(36).slice(2)}`, t = `multipart/form-data; boundary=${e}`, s = new TextEncoder(), i = [];
2024
- for (const [l, p] of Object.entries(r))
2025
- i.push(`--${e}\r
2026
- `), i.push(`Content-Disposition: form-data; name="${l}"`), p instanceof File && i.push(`; filename="${p.name}"`), i.push(`\r
2027
- `), p instanceof File && (i.push("Content-Type: application/octet-stream"), i.push(`\r
2028
- `)), i.push(`\r
2029
- `), p instanceof File ? i.push(await fileToUint8Array(p)) : i.push(p), i.push(`\r
2022
+ function toRelativeUrl(t) {
2023
+ return t.toString().substring(t.origin.length);
2024
+ }
2025
+ function removePathPrefix(t, e) {
2026
+ return !e || !t.startsWith(e) ? t : t.substring(e.length);
2027
+ }
2028
+ function ensurePathPrefix(t, e) {
2029
+ return !e || t.startsWith(e) ? t : e + t;
2030
+ }
2031
+ async function encodeAsMultipart(t) {
2032
+ const e = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${e}`, s = new TextEncoder(), n = [];
2033
+ for (const [c, l] of Object.entries(t))
2034
+ n.push(`--${e}\r
2035
+ `), n.push(`Content-Disposition: form-data; name="${c}"`), l instanceof File && n.push(`; filename="${l.name}"`), n.push(`\r
2036
+ `), l instanceof File && (n.push("Content-Type: application/octet-stream"), n.push(`\r
2037
+ `)), n.push(`\r
2038
+ `), l instanceof File ? n.push(await fileToUint8Array(l)) : n.push(l), n.push(`\r
2030
2039
  `);
2031
- i.push(`--${e}--\r
2040
+ n.push(`--${e}--\r
2032
2041
  `);
2033
- const n = i.reduce((l, p) => l + p.length, 0), o = new Uint8Array(n);
2042
+ const i = n.reduce((c, l) => c + l.length, 0), o = new Uint8Array(i);
2034
2043
  let a = 0;
2035
- for (const l of i)
2044
+ for (const c of n)
2036
2045
  o.set(
2037
- typeof l == "string" ? s.encode(l) : l,
2046
+ typeof c == "string" ? s.encode(c) : c,
2038
2047
  a
2039
- ), a += l.length;
2040
- return { bytes: o, contentType: t };
2048
+ ), a += c.length;
2049
+ return { bytes: o, contentType: r };
2041
2050
  }
2042
- function fileToUint8Array(r) {
2043
- return r.arrayBuffer().then((e) => new Uint8Array(e));
2051
+ function fileToUint8Array(t) {
2052
+ return t.arrayBuffer().then((e) => new Uint8Array(e));
2044
2053
  }
2045
2054
  const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "application/atom+xml", avi = "video/x-msvideo", avif = "image/avif", bin = "application/octet-stream", bmp = "image/x-ms-bmp", cco = "application/x-cocoa", css = "text/css", data = "application/octet-stream", deb = "application/octet-stream", der = "application/x-x509-ca-cert", dmg = "application/octet-stream", doc = "application/msword", docx = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", eot = "application/vnd.ms-fontobject", flv = "video/x-flv", gif = "image/gif", gz = "application/gzip", hqx = "application/mac-binhex40", htc = "text/x-component", html = "text/html", ico = "image/x-icon", iso = "application/octet-stream", jad = "text/vnd.sun.j2me.app-descriptor", jar = "application/java-archive", jardiff = "application/x-java-archive-diff", jng = "image/x-jng", jnlp = "application/x-java-jnlp-file", jpg = "image/jpeg", jpeg = "image/jpeg", js = "application/javascript", json = "application/json", kml = "application/vnd.google-earth.kml+xml", kmz = "application/vnd.google-earth.kmz", m3u8 = "application/vnd.apple.mpegurl", m4a = "audio/x-m4a", m4v = "video/x-m4v", md = "text/plain", mid = "audio/midi", mml = "text/mathml", mng = "video/x-mng", mov = "video/quicktime", mp3 = "audio/mpeg", mp4 = "video/mp4", mpeg = "video/mpeg", msi = "application/octet-stream", odg = "application/vnd.oasis.opendocument.graphics", odp = "application/vnd.oasis.opendocument.presentation", ods = "application/vnd.oasis.opendocument.spreadsheet", odt = "application/vnd.oasis.opendocument.text", ogg = "audio/ogg", otf = "font/otf", pdf = "application/pdf", pl = "application/x-perl", png = "image/png", ppt = "application/vnd.ms-powerpoint", pptx = "application/vnd.openxmlformats-officedocument.presentationml.presentation", prc = "application/x-pilot", ps = "application/postscript", ra = "audio/x-realaudio", rar = "application/x-rar-compressed", rpm = "application/x-redhat-package-manager", rss = "application/rss+xml", rtf = "application/rtf", run = "application/x-makeself", sea = "application/x-sea", sit = "application/x-stuffit", svg = "image/svg+xml", swf = "application/x-shockwave-flash", tcl = "application/x-tcl", tar = "application/x-tar", tif = "image/tiff", ts = "video/mp2t", ttf = "font/ttf", txt = "text/plain", wasm = "application/wasm", wbmp = "image/vnd.wap.wbmp", webm = "video/webm", webp = "image/webp", wml = "text/vnd.wap.wml", wmlc = "application/vnd.wap.wmlc", wmv = "video/x-ms-wmv", woff = "font/woff", woff2 = "font/woff2", xhtml = "application/xhtml+xml", xls = "application/vnd.ms-excel", xlsx = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", xml = "text/xml", xpi = "application/x-xpinstall", xspf = "application/xspf+xml", zip = "application/zip", mimeTypes = {
2046
2055
  _default,
@@ -2138,7 +2147,7 @@ const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "app
2138
2147
  xspf,
2139
2148
  zip
2140
2149
  };
2141
- var g, C, M, F, I, y, A, v, x, Z, ee, te;
2150
+ var S, C, L, b, I, x, N, R, H, Z, ee, te;
2142
2151
  class PHPRequestHandler {
2143
2152
  /**
2144
2153
  * The request handler needs to decide whether to serve a static asset or
@@ -2152,42 +2161,42 @@ class PHPRequestHandler {
2152
2161
  * @param config - Request Handler configuration.
2153
2162
  */
2154
2163
  constructor(e) {
2155
- h(this, x);
2156
- h(this, g);
2157
- h(this, C);
2158
- h(this, M);
2159
- h(this, F);
2160
- h(this, I);
2161
- h(this, y);
2162
- h(this, A);
2163
- h(this, v);
2164
+ y(this, H);
2165
+ y(this, S);
2166
+ y(this, C);
2167
+ y(this, L);
2168
+ y(this, b);
2169
+ y(this, I);
2170
+ y(this, x);
2171
+ y(this, N);
2172
+ y(this, R);
2164
2173
  const {
2165
- documentRoot: t = "/www/",
2174
+ documentRoot: r = "/www/",
2166
2175
  absoluteUrl: s = typeof location == "object" ? location.href : DEFAULT_BASE_URL,
2167
- rewriteRules: i = [],
2168
- getFileNotFoundAction: n = () => ({ type: "404" })
2176
+ rewriteRules: n = [],
2177
+ getFileNotFoundAction: i = () => ({ type: "404" })
2169
2178
  } = e;
2170
2179
  "processManager" in e ? this.processManager = e.processManager : this.processManager = new PHPProcessManager({
2171
- phpFactory: async (l) => {
2172
- const p = await e.phpFactory({
2173
- ...l,
2180
+ phpFactory: async (c) => {
2181
+ const l = await e.phpFactory({
2182
+ ...c,
2174
2183
  requestHandler: this
2175
2184
  });
2176
- return p.isDir(t) || p.mkdir(t), p.chdir(t), p.requestHandler = this, p;
2185
+ return l.isDir(r) || l.mkdir(r), l.chdir(r), l.requestHandler = this, l;
2177
2186
  },
2178
2187
  maxPhpInstances: e.maxPhpInstances
2179
- }), f(this, v, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), f(this, g, t);
2188
+ }), g(this, R, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), g(this, S, r);
2180
2189
  const o = new URL(s);
2181
- f(this, M, o.hostname), f(this, F, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), f(this, C, (o.protocol || "").replace(":", ""));
2182
- const a = c(this, F) !== 443 && c(this, F) !== 80;
2183
- f(this, I, [
2184
- c(this, M),
2185
- a ? `:${c(this, F)}` : ""
2186
- ].join("")), f(this, y, o.pathname.replace(/\/+$/, "")), f(this, A, [
2187
- `${c(this, C)}://`,
2188
- c(this, I),
2189
- c(this, y)
2190
- ].join("")), this.rewriteRules = i, this.getFileNotFoundAction = n;
2190
+ g(this, L, o.hostname), g(this, b, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), g(this, C, (o.protocol || "").replace(":", ""));
2191
+ const a = u(this, b) !== 443 && u(this, b) !== 80;
2192
+ g(this, I, [
2193
+ u(this, L),
2194
+ a ? `:${u(this, b)}` : ""
2195
+ ].join("")), g(this, x, o.pathname.replace(/\/+$/, "")), g(this, N, [
2196
+ `${u(this, C)}://`,
2197
+ u(this, I),
2198
+ u(this, x)
2199
+ ].join("")), this.rewriteRules = n, this.getFileNotFoundAction = i;
2191
2200
  }
2192
2201
  async getPrimaryPhp() {
2193
2202
  return await this.processManager.getPrimaryPhp();
@@ -2210,21 +2219,21 @@ class PHPRequestHandler {
2210
2219
  * @returns The relative path.
2211
2220
  */
2212
2221
  internalUrlToPath(e) {
2213
- const t = new URL(e);
2214
- return t.pathname.startsWith(c(this, y)) && (t.pathname = t.pathname.slice(c(this, y).length)), toRelativeUrl(t);
2222
+ const r = new URL(e);
2223
+ return r.pathname.startsWith(u(this, x)) && (r.pathname = r.pathname.slice(u(this, x).length)), toRelativeUrl(r);
2215
2224
  }
2216
2225
  /**
2217
2226
  * The absolute URL of this PHPRequestHandler instance.
2218
2227
  */
2219
2228
  get absoluteUrl() {
2220
- return c(this, A);
2229
+ return u(this, N);
2221
2230
  }
2222
2231
  /**
2223
2232
  * The directory in the PHP filesystem where the server will look
2224
2233
  * for the files to serve. Default: `/var/www`.
2225
2234
  */
2226
2235
  get documentRoot() {
2227
- return c(this, g);
2236
+ return u(this, S);
2228
2237
  }
2229
2238
  /**
2230
2239
  * Serves the request – either by serving a static file, or by
@@ -2275,19 +2284,19 @@ class PHPRequestHandler {
2275
2284
  * @param request - PHP Request data.
2276
2285
  */
2277
2286
  async request(e) {
2278
- const t = URL.canParse(e.url), s = new URL(
2287
+ const r = URL.canParse(e.url), s = new URL(
2279
2288
  // Remove the hash part of the URL as it's not meant for the server.
2280
2289
  e.url.split("#")[0],
2281
- t ? void 0 : DEFAULT_BASE_URL
2282
- ), i = applyRewriteRules(
2290
+ r ? void 0 : DEFAULT_BASE_URL
2291
+ ), n = applyRewriteRules(
2283
2292
  removePathPrefix(
2284
2293
  decodeURIComponent(s.pathname),
2285
- c(this, y)
2294
+ u(this, x)
2286
2295
  ),
2287
2296
  this.rewriteRules
2288
- ), n = await this.getPrimaryPhp();
2289
- let o = joinPaths(c(this, g), i);
2290
- if (n.isDir(o)) {
2297
+ ), i = await this.getPrimaryPhp();
2298
+ let o = joinPaths(u(this, S), n);
2299
+ if (i.isDir(o)) {
2291
2300
  if (!o.endsWith("/"))
2292
2301
  return new PHPResponse(
2293
2302
  301,
@@ -2295,22 +2304,22 @@ class PHPRequestHandler {
2295
2304
  new Uint8Array(0)
2296
2305
  );
2297
2306
  for (const a of ["index.php", "index.html"]) {
2298
- const l = joinPaths(o, a);
2299
- if (n.isFile(l)) {
2300
- o = l;
2307
+ const c = joinPaths(o, a);
2308
+ if (i.isFile(c)) {
2309
+ o = c;
2301
2310
  break;
2302
2311
  }
2303
2312
  }
2304
2313
  }
2305
- if (!n.isFile(o)) {
2314
+ if (!i.isFile(o)) {
2306
2315
  const a = this.getFileNotFoundAction(
2307
- i
2316
+ n
2308
2317
  );
2309
2318
  switch (a.type) {
2310
2319
  case "response":
2311
2320
  return a.response;
2312
2321
  case "internal-redirect":
2313
- o = joinPaths(c(this, g), a.uri);
2322
+ o = joinPaths(u(this, S), a.uri);
2314
2323
  break;
2315
2324
  case "404":
2316
2325
  return PHPResponse.forHttpCode(404);
@@ -2320,16 +2329,16 @@ class PHPRequestHandler {
2320
2329
  );
2321
2330
  }
2322
2331
  }
2323
- if (n.isFile(o))
2332
+ if (i.isFile(o))
2324
2333
  if (o.endsWith(".php")) {
2325
2334
  const a = {
2326
2335
  ...e,
2327
2336
  // Pass along URL with the #fragment filtered out
2328
2337
  url: s.toString()
2329
2338
  };
2330
- return d(this, x, ee).call(this, a, o);
2339
+ return m(this, H, ee).call(this, a, o);
2331
2340
  } else
2332
- return d(this, x, Z).call(this, n, o);
2341
+ return m(this, H, Z).call(this, i, o);
2333
2342
  else
2334
2343
  return PHPResponse.forHttpCode(404);
2335
2344
  }
@@ -2337,14 +2346,14 @@ class PHPRequestHandler {
2337
2346
  await this.processManager[Symbol.asyncDispose]();
2338
2347
  }
2339
2348
  }
2340
- g = new WeakMap(), C = new WeakMap(), M = new WeakMap(), F = new WeakMap(), I = new WeakMap(), y = new WeakMap(), A = new WeakMap(), v = new WeakMap(), x = new WeakSet(), /**
2349
+ S = new WeakMap(), C = new WeakMap(), L = new WeakMap(), b = new WeakMap(), I = new WeakMap(), x = new WeakMap(), N = new WeakMap(), R = new WeakMap(), H = new WeakSet(), /**
2341
2350
  * Serves a static file from the PHP filesystem.
2342
2351
  *
2343
2352
  * @param fsPath - Absolute path of the static file to serve.
2344
2353
  * @returns The response.
2345
2354
  */
2346
- Z = function(e, t) {
2347
- const s = e.readFileAsBuffer(t);
2355
+ Z = function(e, r) {
2356
+ const s = e.readFileAsBuffer(r);
2348
2357
  return new PHPResponse(
2349
2358
  200,
2350
2359
  {
@@ -2352,80 +2361,80 @@ Z = function(e, t) {
2352
2361
  // @TODO: Infer the content-type from the arrayBuffer instead of the
2353
2362
  // file path. The code below won't return the correct mime-type if the
2354
2363
  // extension was tampered with.
2355
- "content-type": [inferMimeType(t)],
2364
+ "content-type": [inferMimeType(r)],
2356
2365
  "accept-ranges": ["bytes"],
2357
2366
  "cache-control": ["public, max-age=0"]
2358
2367
  },
2359
2368
  s
2360
2369
  );
2361
- }, ee = async function(e, t) {
2370
+ }, ee = async function(e, r) {
2362
2371
  let s;
2363
2372
  try {
2364
2373
  s = await this.processManager.acquirePHPInstance({
2365
2374
  considerPrimary: !0
2366
2375
  });
2367
- } catch (i) {
2368
- return i instanceof MaxPhpInstancesError ? PHPResponse.forHttpCode(502) : PHPResponse.forHttpCode(500);
2376
+ } catch (n) {
2377
+ return n instanceof MaxPhpInstancesError ? PHPResponse.forHttpCode(502) : PHPResponse.forHttpCode(500);
2369
2378
  }
2370
2379
  try {
2371
- return await d(this, x, te).call(this, s.php, e, t);
2380
+ return await m(this, H, te).call(this, s.php, e, r);
2372
2381
  } finally {
2373
2382
  s.reap();
2374
2383
  }
2375
- }, te = async function(e, t, s) {
2376
- let i = "GET";
2377
- const n = {
2378
- host: c(this, I),
2379
- ...normalizeHeaders(t.headers || {})
2384
+ }, te = async function(e, r, s) {
2385
+ let n = "GET";
2386
+ const i = {
2387
+ host: u(this, I),
2388
+ ...normalizeHeaders(r.headers || {})
2380
2389
  };
2381
- c(this, v) && (n.cookie = c(this, v).getCookieRequestHeader());
2382
- let o = t.body;
2390
+ u(this, R) && (i.cookie = u(this, R).getCookieRequestHeader());
2391
+ let o = r.body;
2383
2392
  if (typeof o == "object" && !(o instanceof Uint8Array)) {
2384
- i = "POST";
2385
- const { bytes: a, contentType: l } = await encodeAsMultipart(o);
2386
- o = a, n["content-type"] = l;
2393
+ n = "POST";
2394
+ const { bytes: a, contentType: c } = await encodeAsMultipart(o);
2395
+ o = a, i["content-type"] = c;
2387
2396
  }
2388
2397
  try {
2389
2398
  const a = await e.run({
2390
2399
  relativeUri: ensurePathPrefix(
2391
- toRelativeUrl(new URL(t.url)),
2392
- c(this, y)
2400
+ toRelativeUrl(new URL(r.url)),
2401
+ u(this, x)
2393
2402
  ),
2394
- protocol: c(this, C),
2395
- method: t.method || i,
2403
+ protocol: u(this, C),
2404
+ method: r.method || n,
2396
2405
  $_SERVER: {
2397
2406
  REMOTE_ADDR: "127.0.0.1",
2398
- DOCUMENT_ROOT: c(this, g),
2399
- HTTPS: c(this, A).startsWith("https://") ? "on" : ""
2407
+ DOCUMENT_ROOT: u(this, S),
2408
+ HTTPS: u(this, N).startsWith("https://") ? "on" : ""
2400
2409
  },
2401
2410
  body: o,
2402
2411
  scriptPath: s,
2403
- headers: n
2412
+ headers: i
2404
2413
  });
2405
- return c(this, v) && c(this, v).rememberCookiesFromResponseHeaders(
2414
+ return u(this, R) && u(this, R).rememberCookiesFromResponseHeaders(
2406
2415
  a.headers
2407
2416
  ), a;
2408
2417
  } catch (a) {
2409
- const l = a;
2410
- if (l != null && l.response)
2411
- return l.response;
2418
+ const c = a;
2419
+ if (c != null && c.response)
2420
+ return c.response;
2412
2421
  throw a;
2413
2422
  }
2414
2423
  };
2415
- function inferMimeType(r) {
2416
- const e = r.split(".").pop();
2424
+ function inferMimeType(t) {
2425
+ const e = t.split(".").pop();
2417
2426
  return mimeTypes[e] || mimeTypes._default;
2418
2427
  }
2419
- function applyRewriteRules(r, e) {
2420
- for (const t of e)
2421
- if (new RegExp(t.match).test(r))
2422
- return r.replace(t.match, t.replacement);
2423
- return r;
2428
+ function applyRewriteRules(t, e) {
2429
+ for (const r of e)
2430
+ if (new RegExp(r.match).test(t))
2431
+ return t.replace(r.match, r.replacement);
2432
+ return t;
2424
2433
  }
2425
2434
  function rotatePHPRuntime({
2426
- php: r,
2435
+ php: t,
2427
2436
  cwd: e,
2428
- recreateRuntime: t,
2437
+ recreateRuntime: r,
2429
2438
  /*
2430
2439
  * 400 is an arbitrary number that should trigger a rotation
2431
2440
  * way before the memory gets too fragmented. If it doesn't,
@@ -2436,154 +2445,560 @@ function rotatePHPRuntime({
2436
2445
  */
2437
2446
  maxRequests: s = 400
2438
2447
  }) {
2439
- let i = 0;
2440
- async function n() {
2441
- const l = await r.semaphore.acquire();
2448
+ let n = 0;
2449
+ async function i() {
2450
+ const c = await t.semaphore.acquire();
2442
2451
  try {
2443
- await r.hotSwapPHPRuntime(await t(), e), i = 0;
2452
+ await t.hotSwapPHPRuntime(await r(), e), n = 0;
2444
2453
  } finally {
2445
- l();
2454
+ c();
2446
2455
  }
2447
2456
  }
2448
2457
  async function o() {
2449
- ++i < s || await n();
2458
+ ++n < s || await i();
2450
2459
  }
2451
- async function a(l) {
2452
- l.type === "request.error" && l.source === "php-wasm" && await n();
2460
+ async function a(c) {
2461
+ c.type === "request.error" && c.source === "php-wasm" && await i();
2453
2462
  }
2454
- return r.addEventListener("request.error", a), r.addEventListener("request.end", o), function() {
2455
- r.removeEventListener("request.error", a), r.removeEventListener("request.end", o);
2463
+ return t.addEventListener("request.error", a), t.addEventListener("request.end", o), function() {
2464
+ t.removeEventListener("request.error", a), t.removeEventListener("request.end", o);
2456
2465
  };
2457
2466
  }
2458
- async function writeFiles(r, e, t, { rmRoot: s = !1 } = {}) {
2459
- s && await r.isDir(e) && await r.rmdir(e, { recursive: !0 });
2460
- for (const [i, n] of Object.entries(t)) {
2461
- const o = joinPaths(e, i);
2462
- await r.fileExists(dirname(o)) || await r.mkdir(dirname(o)), n instanceof Uint8Array || typeof n == "string" ? await r.writeFile(o, n) : await writeFiles(r, o, n);
2467
+ async function writeFiles(t, e, r, { rmRoot: s = !1 } = {}) {
2468
+ s && await t.isDir(e) && await t.rmdir(e, { recursive: !0 });
2469
+ for (const [n, i] of Object.entries(r)) {
2470
+ const o = joinPaths(e, n);
2471
+ await t.fileExists(dirname(o)) || await t.mkdir(dirname(o)), i instanceof Uint8Array || typeof i == "string" ? await t.writeFile(o, i) : await writeFiles(t, o, i);
2463
2472
  }
2464
2473
  }
2465
- function proxyFileSystem(r, e, t) {
2466
- const s = Object.getOwnPropertySymbols(r)[0];
2467
- for (const i of t)
2468
- e.fileExists(i) || e.mkdir(i), r.fileExists(i) || r.mkdir(i), e[s].FS.mount(
2474
+ function proxyFileSystem(t, e, r) {
2475
+ const s = Object.getOwnPropertySymbols(t)[0];
2476
+ for (const n of r)
2477
+ e.fileExists(n) || e.mkdir(n), t.fileExists(n) || t.mkdir(n), e[s].FS.mount(
2469
2478
  // @ts-ignore
2470
2479
  e[s].PROXYFS,
2471
2480
  {
2472
- root: i,
2481
+ root: n,
2473
2482
  // @ts-ignore
2474
- fs: r[s].FS
2483
+ fs: t[s].FS
2475
2484
  },
2476
- i
2485
+ n
2477
2486
  );
2478
2487
  }
2488
+ function exposeSync(t, e, r, s = ["*"]) {
2489
+ return expose(t, e, s, r.afterResponseSent);
2490
+ }
2491
+ function createSyncProxy(t, e = [], r) {
2492
+ return new Proxy(() => {
2493
+ }, {
2494
+ get(s, n) {
2495
+ return n === "then" && !e.length ? {
2496
+ then: (i, o) => o(createSyncProxy(t, [], r))
2497
+ } : createSyncProxy(t, [...e, n], r);
2498
+ },
2499
+ set(s, n, i) {
2500
+ const [o, a] = toWireValue(i);
2501
+ return r.send(
2502
+ t,
2503
+ {
2504
+ type: MessageType.SET,
2505
+ path: [...e, n].map(String),
2506
+ value: o
2507
+ },
2508
+ a
2509
+ ), !0;
2510
+ },
2511
+ apply(s, n, i) {
2512
+ if (e.at(-1) === "bind")
2513
+ return createSyncProxy(t, e.slice(0, -1), r);
2514
+ const [a, c] = processArguments(i), l = r.send(
2515
+ t,
2516
+ {
2517
+ type: MessageType.APPLY,
2518
+ path: e.map(String),
2519
+ argumentList: a
2520
+ },
2521
+ c
2522
+ );
2523
+ return fromWireValue(l);
2524
+ },
2525
+ construct(s, n) {
2526
+ const [i, o] = processArguments(n), a = r.send(
2527
+ t,
2528
+ {
2529
+ type: MessageType.CONSTRUCT,
2530
+ path: e.map(String),
2531
+ argumentList: i
2532
+ },
2533
+ o
2534
+ );
2535
+ return fromWireValue(a);
2536
+ }
2537
+ });
2538
+ }
2539
+ function wrapSync(t, e) {
2540
+ return createSyncProxy(t, [], e);
2541
+ }
2542
+ class NodeSABSyncReceiveMessageTransport {
2543
+ static async create() {
2544
+ return NodeSABSyncReceiveMessageTransport.receiveMessageOnPort || (NodeSABSyncReceiveMessageTransport.receiveMessageOnPort = await import("./__vite-browser-external-l0sNRNKZ.js").then(
2545
+ (e) => e.receiveMessageOnPort
2546
+ )), new NodeSABSyncReceiveMessageTransport();
2547
+ }
2548
+ constructor() {
2549
+ }
2550
+ afterResponseSent(e) {
2551
+ const { notifyBuffer: r } = e.data;
2552
+ if (r) {
2553
+ const s = new Int32Array(r);
2554
+ s[0] = 1, Atomics.notify(s, 0);
2555
+ }
2556
+ }
2557
+ send(e, r, s) {
2558
+ var l;
2559
+ const n = new SharedArrayBuffer(4), i = new Int32Array(n);
2560
+ i[0] = 0;
2561
+ const o = generateUUID();
2562
+ if (e.postMessage(
2563
+ { ...r, id: o, notifyBuffer: n },
2564
+ s
2565
+ ), Atomics.wait(i, 0, 0, 5e3) === "timed-out")
2566
+ throw new Error("Timeout waiting for response");
2567
+ for (; ; ) {
2568
+ const h = NodeSABSyncReceiveMessageTransport.receiveMessageOnPort(e);
2569
+ if (((l = h.message) == null ? void 0 : l.id) === o)
2570
+ return h.message;
2571
+ if (!h)
2572
+ throw new Error("No response received");
2573
+ }
2574
+ }
2575
+ }
2576
+ /**
2577
+ * Original, unmodified Comlink library from Google:
2578
+ *
2579
+ * @license
2580
+ * Copyright 2019 Google LLC
2581
+ * SPDX-License-Identifier: Apache-2.0
2582
+ */
2583
+ const proxyMarker = Symbol("Comlink.proxy"), createEndpoint = Symbol("Comlink.endpoint"), releaseProxy = Symbol("Comlink.releaseProxy"), finalizer = Symbol("Comlink.finalizer"), throwMarker = Symbol("Comlink.thrown");
2479
2584
  /**
2480
2585
  * @license
2481
2586
  * Copyright 2019 Google LLC
2482
2587
  * SPDX-License-Identifier: Apache-2.0
2483
2588
  */
2484
- function nodeEndpoint(r) {
2589
+ const WireValueType = {
2590
+ RAW: "RAW",
2591
+ HANDLER: "HANDLER"
2592
+ }, MessageType = {
2593
+ GET: "GET",
2594
+ SET: "SET",
2595
+ APPLY: "APPLY",
2596
+ CONSTRUCT: "CONSTRUCT",
2597
+ ENDPOINT: "ENDPOINT",
2598
+ RELEASE: "RELEASE"
2599
+ }, isObject = (t) => typeof t == "object" && t !== null || typeof t == "function", proxyTransferHandler = {
2600
+ canHandle: (t) => isObject(t) && t[proxyMarker],
2601
+ serialize(t) {
2602
+ const { port1: e, port2: r } = new MessageChannel();
2603
+ return expose(t, e), [r, [r]];
2604
+ },
2605
+ deserialize(t) {
2606
+ return t.start(), wrap(t);
2607
+ }
2608
+ }, throwTransferHandler = {
2609
+ canHandle: (t) => isObject(t) && throwMarker in t,
2610
+ serialize({ value: t }) {
2611
+ let e;
2612
+ return t instanceof Error ? e = {
2613
+ isError: !0,
2614
+ value: {
2615
+ message: t.message,
2616
+ name: t.name,
2617
+ stack: t.stack
2618
+ }
2619
+ } : e = { isError: !1, value: t }, [e, []];
2620
+ },
2621
+ deserialize(t) {
2622
+ throw t.isError ? Object.assign(
2623
+ new Error(t.value.message),
2624
+ t.value
2625
+ ) : t.value;
2626
+ }
2627
+ }, transferHandlers = /* @__PURE__ */ new Map([
2628
+ ["proxy", proxyTransferHandler],
2629
+ ["throw", throwTransferHandler]
2630
+ ]);
2631
+ function isAllowedOrigin(t, e) {
2632
+ for (const r of t)
2633
+ if (e === r || r === "*" || r instanceof RegExp && r.test(e))
2634
+ return !0;
2635
+ return !1;
2636
+ }
2637
+ function expose(t, e = globalThis, r = ["*"], s) {
2638
+ e.addEventListener("message", function n(i) {
2639
+ if (!i || !i.data)
2640
+ return;
2641
+ if (!isAllowedOrigin(r, i.origin)) {
2642
+ console.warn(`Invalid origin '${i.origin}' for comlink proxy`);
2643
+ return;
2644
+ }
2645
+ const { id: o, type: a, path: c } = {
2646
+ path: [],
2647
+ ...i.data
2648
+ }, l = (i.data.argumentList || []).map(fromWireValue);
2649
+ let h;
2650
+ try {
2651
+ const d = c.slice(0, -1).reduce((_, w) => _[w], t), f = c.reduce((_, w) => _[w], t);
2652
+ switch (a) {
2653
+ case MessageType.GET:
2654
+ h = f;
2655
+ break;
2656
+ case MessageType.SET:
2657
+ d[c.slice(-1)[0]] = fromWireValue(
2658
+ i.data.value
2659
+ ), h = !0;
2660
+ break;
2661
+ case MessageType.APPLY:
2662
+ h = f.apply(d, l);
2663
+ break;
2664
+ case MessageType.CONSTRUCT:
2665
+ {
2666
+ const _ = new f(...l);
2667
+ h = proxy(_);
2668
+ }
2669
+ break;
2670
+ case MessageType.ENDPOINT:
2671
+ {
2672
+ const { port1: _, port2: w } = new MessageChannel();
2673
+ expose(t, w), h = transfer(_, [_]);
2674
+ }
2675
+ break;
2676
+ case MessageType.RELEASE:
2677
+ h = void 0;
2678
+ break;
2679
+ default:
2680
+ return;
2681
+ }
2682
+ } catch (d) {
2683
+ h = { value: d, [throwMarker]: 0 };
2684
+ }
2685
+ Promise.resolve(h).catch((d) => ({ value: d, [throwMarker]: 0 })).then((d) => {
2686
+ const [f, _] = toWireValue(d);
2687
+ e.postMessage({ ...f, id: o }, _), a === MessageType.RELEASE && (e.removeEventListener("message", n), closeEndPoint(e), finalizer in t && typeof t[finalizer] == "function" && t[finalizer]());
2688
+ }).catch(() => {
2689
+ const [d, f] = toWireValue({
2690
+ value: new TypeError("Unserializable return value"),
2691
+ [throwMarker]: 0
2692
+ });
2693
+ e.postMessage({ ...d, id: o }, f);
2694
+ }).finally(() => {
2695
+ s == null || s(i);
2696
+ });
2697
+ }), e.start && e.start();
2698
+ }
2699
+ function isMessagePort(t) {
2700
+ return t.constructor.name === "MessagePort";
2701
+ }
2702
+ function closeEndPoint(t) {
2703
+ isMessagePort(t) && t.close();
2704
+ }
2705
+ function wrap(t, e) {
2706
+ const r = /* @__PURE__ */ new Map();
2707
+ return t.addEventListener("message", function(n) {
2708
+ const { data: i } = n;
2709
+ if (!i || !i.id)
2710
+ return;
2711
+ const o = r.get(i.id);
2712
+ if (o)
2713
+ try {
2714
+ o(i);
2715
+ } finally {
2716
+ r.delete(i.id);
2717
+ }
2718
+ }), createProxy(t, r, [], e);
2719
+ }
2720
+ function throwIfProxyReleased(t) {
2721
+ if (t)
2722
+ throw new Error("Proxy has been released and is not useable");
2723
+ }
2724
+ function releaseEndpoint(t) {
2725
+ return requestResponseMessage(t, /* @__PURE__ */ new Map(), {
2726
+ type: MessageType.RELEASE
2727
+ }).then(() => {
2728
+ closeEndPoint(t);
2729
+ });
2730
+ }
2731
+ const proxyCounter = /* @__PURE__ */ new WeakMap(), proxyFinalizers = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
2732
+ const e = (proxyCounter.get(t) || 0) - 1;
2733
+ proxyCounter.set(t, e), e === 0 && releaseEndpoint(t);
2734
+ });
2735
+ function registerProxy(t, e) {
2736
+ const r = (proxyCounter.get(e) || 0) + 1;
2737
+ proxyCounter.set(e, r), proxyFinalizers && proxyFinalizers.register(t, e, t);
2738
+ }
2739
+ function unregisterProxy(t) {
2740
+ proxyFinalizers && proxyFinalizers.unregister(t);
2741
+ }
2742
+ function createProxy(t, e, r = [], s = function() {
2743
+ }) {
2744
+ let n = !1;
2745
+ const i = new Proxy(s, {
2746
+ get(o, a) {
2747
+ if (throwIfProxyReleased(n), a === releaseProxy)
2748
+ return () => {
2749
+ unregisterProxy(i), releaseEndpoint(t), e.clear(), n = !0;
2750
+ };
2751
+ if (a === "then") {
2752
+ if (r.length === 0)
2753
+ return { then: () => i };
2754
+ const c = requestResponseMessage(t, e, {
2755
+ type: MessageType.GET,
2756
+ path: r.map((l) => l.toString())
2757
+ }).then(fromWireValue);
2758
+ return c.then.bind(c);
2759
+ }
2760
+ return createProxy(t, e, [...r, a]);
2761
+ },
2762
+ set(o, a, c) {
2763
+ throwIfProxyReleased(n);
2764
+ const [l, h] = toWireValue(c);
2765
+ return requestResponseMessage(
2766
+ t,
2767
+ e,
2768
+ {
2769
+ type: MessageType.SET,
2770
+ path: [...r, a].map((d) => d.toString()),
2771
+ value: l
2772
+ },
2773
+ h
2774
+ ).then(fromWireValue);
2775
+ },
2776
+ apply(o, a, c) {
2777
+ throwIfProxyReleased(n);
2778
+ const l = r[r.length - 1];
2779
+ if (l === createEndpoint)
2780
+ return requestResponseMessage(t, e, {
2781
+ type: MessageType.ENDPOINT
2782
+ }).then(fromWireValue);
2783
+ if (l === "bind")
2784
+ return createProxy(t, e, r.slice(0, -1));
2785
+ const [h, d] = processArguments(c);
2786
+ return requestResponseMessage(
2787
+ t,
2788
+ e,
2789
+ {
2790
+ type: MessageType.APPLY,
2791
+ path: r.map((f) => f.toString()),
2792
+ argumentList: h
2793
+ },
2794
+ d
2795
+ ).then(fromWireValue);
2796
+ },
2797
+ construct(o, a) {
2798
+ throwIfProxyReleased(n);
2799
+ const [c, l] = processArguments(a);
2800
+ return requestResponseMessage(
2801
+ t,
2802
+ e,
2803
+ {
2804
+ type: MessageType.CONSTRUCT,
2805
+ path: r.map((h) => h.toString()),
2806
+ argumentList: c
2807
+ },
2808
+ l
2809
+ ).then(fromWireValue);
2810
+ }
2811
+ });
2812
+ return registerProxy(i, t), i;
2813
+ }
2814
+ function myFlat(t) {
2815
+ return Array.prototype.concat.apply([], t);
2816
+ }
2817
+ function processArguments(t) {
2818
+ const e = t.map(toWireValue);
2819
+ return [e.map((r) => r[0]), myFlat(e.map((r) => r[1]))];
2820
+ }
2821
+ const transferCache = /* @__PURE__ */ new WeakMap();
2822
+ function transfer(t, e) {
2823
+ return transferCache.set(t, e), t;
2824
+ }
2825
+ function proxy(t) {
2826
+ return Object.assign(t, { [proxyMarker]: !0 });
2827
+ }
2828
+ function windowEndpoint(t, e = globalThis, r = "*") {
2829
+ return {
2830
+ postMessage: (s, n) => t.postMessage(s, r, n),
2831
+ addEventListener: e.addEventListener.bind(e),
2832
+ removeEventListener: e.removeEventListener.bind(e)
2833
+ };
2834
+ }
2835
+ function toWireValue(t) {
2836
+ for (const [e, r] of transferHandlers)
2837
+ if (r.canHandle(t)) {
2838
+ const [s, n] = r.serialize(t);
2839
+ return [
2840
+ {
2841
+ type: WireValueType.HANDLER,
2842
+ name: e,
2843
+ value: s
2844
+ },
2845
+ n
2846
+ ];
2847
+ }
2848
+ return [
2849
+ {
2850
+ type: WireValueType.RAW,
2851
+ value: t
2852
+ },
2853
+ transferCache.get(t) || []
2854
+ ];
2855
+ }
2856
+ function fromWireValue(t) {
2857
+ switch (t.type) {
2858
+ case WireValueType.HANDLER:
2859
+ return transferHandlers.get(t.name).deserialize(t.value);
2860
+ case WireValueType.RAW:
2861
+ return t.value;
2862
+ }
2863
+ }
2864
+ function requestResponseMessage(t, e, r, s) {
2865
+ return new Promise((n) => {
2866
+ const i = generateUUID();
2867
+ e.set(i, n), t.start && t.start(), t.postMessage({ id: i, ...r }, s);
2868
+ });
2869
+ }
2870
+ function generateUUID() {
2871
+ return new Array(4).fill(0).map(
2872
+ () => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)
2873
+ ).join("-");
2874
+ }
2875
+ function nodeEndpoint(t) {
2485
2876
  const e = /* @__PURE__ */ new WeakMap();
2486
2877
  return {
2487
- postMessage: r.postMessage.bind(r),
2488
- addEventListener: (t, s) => {
2489
- const i = (n) => {
2490
- "handleEvent" in s ? s.handleEvent({ data: n }) : s({ data: n });
2878
+ postMessage: t.postMessage.bind(t),
2879
+ addEventListener: (r, s) => {
2880
+ const n = (i) => {
2881
+ "handleEvent" in s ? s.handleEvent({ data: i }) : s({ data: i });
2491
2882
  };
2492
- r.on("message", i), e.set(s, i);
2883
+ t.on("message", n), e.set(s, n);
2493
2884
  },
2494
- removeEventListener: (t, s) => {
2495
- const i = e.get(s);
2496
- i && (r.off("message", i), e.delete(s));
2885
+ removeEventListener: (r, s) => {
2886
+ const n = e.get(s);
2887
+ n && (t.off("message", n), e.delete(s));
2497
2888
  },
2498
- start: r.start && r.start.bind(r)
2889
+ start: t.start && t.start.bind(t)
2499
2890
  };
2500
2891
  }
2501
- function consumeAPI(r, e = void 0) {
2892
+ async function consumeAPISync(t) {
2893
+ setupTransferHandlers();
2894
+ const e = await NodeSABSyncReceiveMessageTransport.create();
2895
+ return wrapSync(t, e);
2896
+ }
2897
+ function consumeAPI(t, e = void 0) {
2502
2898
  setupTransferHandlers();
2503
- let t;
2504
- import.meta.url.startsWith("file://") ? t = nodeEndpoint(r) : t = r instanceof Worker ? r : Comlink.windowEndpoint(r, e);
2505
- const i = Comlink.wrap(t), n = proxyClone(i);
2506
- return new Proxy(n, {
2899
+ let r;
2900
+ import.meta.url.startsWith("file://") ? r = nodeEndpoint(t) : r = t instanceof Worker ? t : windowEndpoint(t, e);
2901
+ const n = wrap(r), i = proxyClone(n);
2902
+ return new Proxy(i, {
2507
2903
  get: (o, a) => a === "isConnected" ? async () => {
2508
2904
  for (; ; )
2509
2905
  try {
2510
- await runWithTimeout(i.isConnected(), 200);
2906
+ await runWithTimeout(n.isConnected(), 200);
2511
2907
  break;
2512
2908
  } catch {
2513
2909
  }
2514
- } : i[a]
2910
+ } : n[a]
2515
2911
  });
2516
2912
  }
2517
- async function runWithTimeout(r, e) {
2518
- return new Promise((t, s) => {
2519
- setTimeout(s, e), r.then(t);
2913
+ async function runWithTimeout(t, e) {
2914
+ return new Promise((r, s) => {
2915
+ setTimeout(s, e), t.then(r);
2520
2916
  });
2521
2917
  }
2522
- function exposeAPI(r, e, t) {
2918
+ function exposeAPI(t, e, r) {
2919
+ const { setReady: s, setFailed: n, exposedApi: i } = prepareForExpose(
2920
+ t,
2921
+ e
2922
+ );
2923
+ let o;
2924
+ return r ? o = nodeEndpoint(r) : o = typeof window < "u" ? windowEndpoint(self.parent) : void 0, expose(i, o), [s, n, i];
2925
+ }
2926
+ async function exposeSyncAPI(t, e) {
2927
+ const { setReady: r, setFailed: s, exposedApi: n } = prepareForExpose(t), i = await NodeSABSyncReceiveMessageTransport.create(), o = nodeEndpoint(e);
2928
+ return exposeSync(n, o, i), [r, s, n];
2929
+ }
2930
+ function prepareForExpose(t, e) {
2523
2931
  setupTransferHandlers();
2524
- const s = Promise.resolve();
2525
- let i, n;
2526
- const o = new Promise((E, m) => {
2527
- i = E, n = m;
2528
- }), a = proxyClone(r), l = new Proxy(a, {
2529
- get: (E, m) => m === "isConnected" ? () => s : m === "isReady" ? () => o : m in E ? E[m] : e == null ? void 0 : e[m]
2932
+ const r = Promise.resolve();
2933
+ let s, n;
2934
+ const i = new Promise((c, l) => {
2935
+ s = c, n = l;
2936
+ }), o = proxyClone(t), a = new Proxy(o, {
2937
+ get: (c, l) => l === "isConnected" ? () => r : l === "isReady" ? () => i : l in c ? c[l] : e == null ? void 0 : e[l]
2530
2938
  });
2531
- let p;
2532
- return t ? p = nodeEndpoint(t) : p = typeof window < "u" ? Comlink.windowEndpoint(self.parent) : void 0, Comlink.expose(l, p), [i, n, l];
2939
+ return { setReady: s, setFailed: n, exposedApi: a };
2533
2940
  }
2534
2941
  let isTransferHandlersSetup = !1;
2535
2942
  function setupTransferHandlers() {
2536
2943
  if (isTransferHandlersSetup)
2537
2944
  return;
2538
- isTransferHandlersSetup = !0, Comlink.transferHandlers.set("EVENT", {
2539
- canHandle: (t) => t instanceof CustomEvent,
2540
- serialize: (t) => [
2945
+ isTransferHandlersSetup = !0, transferHandlers.set("EVENT", {
2946
+ canHandle: (r) => r instanceof CustomEvent,
2947
+ serialize: (r) => [
2541
2948
  {
2542
- detail: t.detail
2949
+ detail: r.detail
2543
2950
  },
2544
2951
  []
2545
2952
  ],
2546
- deserialize: (t) => t
2547
- }), Comlink.transferHandlers.set("FUNCTION", {
2953
+ deserialize: (r) => r
2954
+ }), transferHandlers.set("FUNCTION", {
2548
2955
  // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
2549
- canHandle: (t) => typeof t == "function",
2956
+ canHandle: (r) => typeof r == "function",
2550
2957
  // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
2551
- serialize(t) {
2552
- const { port1: s, port2: i } = new MessageChannel();
2553
- return Comlink.expose(t, s), [i, [i]];
2958
+ serialize(r) {
2959
+ const { port1: s, port2: n } = new MessageChannel();
2960
+ return expose(r, s), [n, [n]];
2961
+ },
2962
+ deserialize(r) {
2963
+ return r.start(), wrap(r);
2964
+ }
2965
+ }), transferHandlers.set("MESSAGE_PORT", {
2966
+ canHandle: (r) => r instanceof MessagePort,
2967
+ serialize(r) {
2968
+ return [r, [r]];
2554
2969
  },
2555
- deserialize(t) {
2556
- return t.start(), Comlink.wrap(t);
2970
+ deserialize(r) {
2971
+ return r;
2557
2972
  }
2558
- }), Comlink.transferHandlers.set("PHPResponse", {
2559
- canHandle: (t) => typeof t == "object" && t !== null && "headers" in t && "bytes" in t && "errors" in t && "exitCode" in t && "httpStatusCode" in t,
2560
- serialize(t) {
2561
- return [t.toRawData(), []];
2973
+ }), transferHandlers.set("PHPResponse", {
2974
+ canHandle: (r) => typeof r == "object" && r !== null && "headers" in r && "bytes" in r && "errors" in r && "exitCode" in r && "httpStatusCode" in r,
2975
+ serialize(r) {
2976
+ return [r.toRawData(), []];
2562
2977
  },
2563
- deserialize(t) {
2564
- return PHPResponse.fromRawData(t);
2978
+ deserialize(r) {
2979
+ return PHPResponse.fromRawData(r);
2565
2980
  }
2566
2981
  });
2567
- const r = Comlink.transferHandlers.get("throw"), e = r == null ? void 0 : r.serialize;
2568
- r.serialize = ({ value: t }) => {
2569
- const s = e({ value: t });
2570
- return t.response && (s[0].value.response = t.response), t.source && (s[0].value.source = t.source), s;
2982
+ const t = transferHandlers.get("throw"), e = t == null ? void 0 : t.serialize;
2983
+ t.serialize = ({ value: r }) => {
2984
+ const s = e({ value: r });
2985
+ return r.response && (s[0].value.response = r.response), r.source && (s[0].value.source = r.source), s;
2571
2986
  };
2572
2987
  }
2573
- function proxyClone(r) {
2574
- return new Proxy(r, {
2575
- get(e, t) {
2576
- switch (typeof e[t]) {
2988
+ function proxyClone(t) {
2989
+ return new Proxy(t, {
2990
+ get(e, r) {
2991
+ switch (typeof e[r]) {
2577
2992
  case "function":
2578
- return (...s) => e[t](...s);
2993
+ return (...s) => e[r](...s);
2579
2994
  case "object":
2580
- return e[t] === null ? e[t] : proxyClone(e[t]);
2995
+ return e[r] === null ? e[r] : proxyClone(e[r]);
2581
2996
  case "undefined":
2582
2997
  case "number":
2583
2998
  case "string":
2584
- return e[t];
2999
+ return e[r];
2585
3000
  default:
2586
- return Comlink.proxy(e[t]);
3001
+ return proxy(e[r]);
2587
3002
  }
2588
3003
  }
2589
3004
  });
@@ -2606,8 +3021,10 @@ export {
2606
3021
  __private__dont__use,
2607
3022
  applyRewriteRules,
2608
3023
  consumeAPI,
3024
+ consumeAPISync,
2609
3025
  ensurePathPrefix,
2610
3026
  exposeAPI,
3027
+ exposeSyncAPI,
2611
3028
  getLoadedRuntime,
2612
3029
  getPhpIniEntries,
2613
3030
  isExitCode,