@php-wasm/universal 3.1.40 → 3.1.42

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
@@ -371,12 +371,12 @@ FSHelpers.mkdir = rethrowFileSystemError('Could not create directory "{path}"')(
371
371
  FSHelpers.mkdir
372
372
  );
373
373
  const _private = /* @__PURE__ */ new WeakMap();
374
- var j;
374
+ var U;
375
375
  class PHPWorker {
376
376
  /** @inheritDoc */
377
377
  constructor(e, t) {
378
- E(this, j);
379
- this.absoluteUrl = "", this.documentRoot = "", this.chroot = null, x(this, j, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
378
+ E(this, U);
379
+ this.absoluteUrl = "", this.documentRoot = "", this.chroot = null, x(this, U, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
380
380
  monitor: t
381
381
  }), e && this.__internal_setRequestHandler(e);
382
382
  }
@@ -551,7 +551,7 @@ class PHPWorker {
551
551
  }
552
552
  /** @inheritDoc @php-wasm/universal!/PHP.addEventListener */
553
553
  addEventListener(e, t) {
554
- p(this, j).has(e) || p(this, j).set(e, /* @__PURE__ */ new Set()), p(this, j).get(e).add(t);
554
+ p(this, U).has(e) || p(this, U).set(e, /* @__PURE__ */ new Set()), p(this, U).get(e).add(t);
555
555
  }
556
556
  /**
557
557
  * Removes an event listener for a PHP event.
@@ -560,10 +560,10 @@ class PHPWorker {
560
560
  */
561
561
  removeEventListener(e, t) {
562
562
  var s;
563
- (s = p(this, j).get(e)) == null || s.delete(t);
563
+ (s = p(this, U).get(e)) == null || s.delete(t);
564
564
  }
565
565
  dispatchEvent(e) {
566
- const t = p(this, j).get(e.type);
566
+ const t = p(this, U).get(e.type);
567
567
  if (t)
568
568
  for (const s of t)
569
569
  s(e);
@@ -595,7 +595,7 @@ class PHPWorker {
595
595
  throw new Error("PHPWorker is not connected to a request handler.");
596
596
  }
597
597
  }
598
- j = new WeakMap();
598
+ U = new WeakMap();
599
599
  function isExitCode(r) {
600
600
  return r instanceof Error ? (r == null ? void 0 : r.name) === "ExitStatus" && "status" in r : !1;
601
601
  }
@@ -1069,7 +1069,7 @@ class PHPExecutionFailureError extends Error {
1069
1069
  }
1070
1070
  }
1071
1071
  const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php", OPCACHE_FILE_FOLDER = "/internal/shared/opcache";
1072
- var J, V, z, D, G, X, k, g, Pe, we, _e, ve, Ee, xe, Se, ke, fe, Fe, he, me;
1072
+ var Y, V, z, D, G, J, k, g, Pe, we, _e, ve, Ee, xe, Se, ke, fe, Fe, he, me;
1073
1073
  class PHP {
1074
1074
  /**
1075
1075
  * Initializes a PHP runtime.
@@ -1080,7 +1080,7 @@ class PHP {
1080
1080
  */
1081
1081
  constructor(r) {
1082
1082
  E(this, g);
1083
- E(this, J);
1083
+ E(this, Y);
1084
1084
  E(this, V, !1);
1085
1085
  E(this, z, null);
1086
1086
  E(this, D, /* @__PURE__ */ new Map([
@@ -1088,7 +1088,7 @@ class PHP {
1088
1088
  ["*", /* @__PURE__ */ new Set()]
1089
1089
  ]));
1090
1090
  E(this, G, []);
1091
- E(this, X, {});
1091
+ E(this, J, {});
1092
1092
  E(this, k, {
1093
1093
  enabled: !1,
1094
1094
  recreateRuntime: () => 0,
@@ -1282,7 +1282,7 @@ class PHP {
1282
1282
  throw new Error(
1283
1283
  "Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
1284
1284
  );
1285
- x(this, J, r);
1285
+ x(this, Y, r);
1286
1286
  }
1287
1287
  /**
1288
1288
  * Changes the current working directory in the PHP filesystem.
@@ -1795,14 +1795,14 @@ class PHP {
1795
1795
  async hotSwapPHPRuntime(r) {
1796
1796
  const e = this[__private__dont__use].FS, t = this.listFiles("/").map((c) => `/${c}`), s = this[__private__dont__use].spawnProcess, n = e.cwd();
1797
1797
  e.chdir("/");
1798
- const o = Object.entries(p(this, X)).map(
1798
+ const o = Object.entries(p(this, J)).map(
1799
1799
  ([c, l]) => ({
1800
1800
  mountHandler: l.mountHandler,
1801
1801
  mountPointSnapshot: snapshotMountPoint(e, c),
1802
1802
  vfsPath: c
1803
1803
  })
1804
1804
  ), i = Object.values(
1805
- p(this, X)
1805
+ p(this, J)
1806
1806
  ).reverse();
1807
1807
  for (const c of i)
1808
1808
  await c.unmount();
@@ -1810,7 +1810,7 @@ class PHP {
1810
1810
  this.exit();
1811
1811
  } catch {
1812
1812
  }
1813
- this.initializeRuntime(r), s && (this[__private__dont__use].spawnProcess = s), p(this, J) && this.setSapiName(p(this, J));
1813
+ this.initializeRuntime(r), s && (this[__private__dont__use].spawnProcess = s), p(this, Y) && this.setSapiName(p(this, Y));
1814
1814
  const a = this[__private__dont__use].FS;
1815
1815
  for (const c of t)
1816
1816
  c && c !== "/request" && copyMEMFSNodes(e, a, c);
@@ -1863,11 +1863,11 @@ class PHP {
1863
1863
  try {
1864
1864
  await t();
1865
1865
  } finally {
1866
- delete p(this, X)[r];
1866
+ delete p(this, J)[r];
1867
1867
  }
1868
1868
  }
1869
1869
  };
1870
- return p(this, X)[r] = s, () => s.unmount();
1870
+ return p(this, J)[r] = s, () => s.unmount();
1871
1871
  }
1872
1872
  /**
1873
1873
  * Starts a PHP CLI session with given arguments.
@@ -1991,7 +1991,7 @@ class PHP {
1991
1991
  this.exit(0);
1992
1992
  }
1993
1993
  }
1994
- J = new WeakMap(), V = new WeakMap(), z = new WeakMap(), D = new WeakMap(), G = new WeakMap(), X = new WeakMap(), k = new WeakMap(), g = new WeakSet(), /**
1994
+ Y = new WeakMap(), V = new WeakMap(), z = new WeakMap(), D = new WeakMap(), G = new WeakMap(), J = new WeakMap(), k = new WeakMap(), g = new WeakSet(), /**
1995
1995
  * Prepares the $_SERVER entries for the PHP runtime.
1996
1996
  *
1997
1997
  * @param defaults Default entries to include in $_SERVER.
@@ -2326,6 +2326,34 @@ Caused by:
2326
2326
  process.stderr.write(`
2327
2327
  `);
2328
2328
  }
2329
+ function describeError(r, e = /* @__PURE__ */ new WeakSet(), t = 0, s = {}) {
2330
+ return t > 10 ? "[Max error cause depth exceeded]" : r instanceof Error ? r.message ? r.message : describeErrorObject(r, e, t, {
2331
+ ...s,
2332
+ suppressGenericErrorName: !0
2333
+ }) : r && typeof r == "object" ? describeErrorObject(r, e, t, s) : String(r);
2334
+ }
2335
+ function describeErrorObject(r, e, t, s = {}) {
2336
+ if (e.has(r))
2337
+ return "[Circular error cause]";
2338
+ e.add(r);
2339
+ const n = [];
2340
+ if (r.name && !(s.suppressGenericErrorName && r.name === "Error") && n.push(String(r.name)), r.message && n.push(String(r.message)), r.errno !== void 0 && n.push(`errno: ${r.errno}`), r.code !== void 0 && n.push(`code: ${r.code}`), r.cause && n.push(
2341
+ `caused by: ${describeError(
2342
+ r.cause,
2343
+ e,
2344
+ t + 1,
2345
+ s
2346
+ )}`
2347
+ ), n.length > 0)
2348
+ return n.join(" — ");
2349
+ if (typeof r.stack == "string")
2350
+ return r.stack;
2351
+ try {
2352
+ return JSON.stringify(r);
2353
+ } catch {
2354
+ return String(r);
2355
+ }
2356
+ }
2329
2357
  function printResponseDebugDetails(r) {
2330
2358
  process.stderr.write(
2331
2359
  `
@@ -2704,7 +2732,7 @@ const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "app
2704
2732
  xspf,
2705
2733
  zip
2706
2734
  };
2707
- var A, Q, re, Y, K, I, Z, $, se, b, Re, oe, be, He, Te;
2735
+ var A, Q, re, X, K, I, Z, $, se, R, be, oe, Re, He, Te;
2708
2736
  class PHPRequestHandler {
2709
2737
  /**
2710
2738
  * The request handler needs to decide whether to serve a static asset or
@@ -2718,11 +2746,11 @@ class PHPRequestHandler {
2718
2746
  * @param config - Request Handler configuration.
2719
2747
  */
2720
2748
  constructor(e) {
2721
- E(this, b);
2749
+ E(this, R);
2722
2750
  E(this, A);
2723
2751
  E(this, Q);
2724
2752
  E(this, re);
2725
- E(this, Y);
2753
+ E(this, X);
2726
2754
  E(this, K);
2727
2755
  E(this, I);
2728
2756
  E(this, Z);
@@ -2758,11 +2786,11 @@ class PHPRequestHandler {
2758
2786
  );
2759
2787
  x(this, $, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), x(this, A, t);
2760
2788
  const c = new URL(s);
2761
- x(this, re, c.hostname), x(this, Y, c.port ? Number(c.port) : c.protocol === "https:" ? 443 : 80), x(this, Q, (c.protocol || "").replace(":", ""));
2762
- const l = p(this, Y) !== 443 && p(this, Y) !== 80;
2789
+ x(this, re, c.hostname), x(this, X, c.port ? Number(c.port) : c.protocol === "https:" ? 443 : 80), x(this, Q, (c.protocol || "").replace(":", ""));
2790
+ const l = p(this, X) !== 443 && p(this, X) !== 80;
2763
2791
  x(this, K, [
2764
2792
  p(this, re),
2765
- l ? `:${p(this, Y)}` : ""
2793
+ l ? `:${p(this, X)}` : ""
2766
2794
  ].join("")), x(this, I, c.pathname.replace(/\/+$/, "")), x(this, Z, [
2767
2795
  `${p(this, Q)}://`,
2768
2796
  p(this, K),
@@ -2880,7 +2908,7 @@ class PHPRequestHandler {
2880
2908
  // Remove the hash part of the URL as it's not meant for the server.
2881
2909
  e.url.split("#")[0],
2882
2910
  t ? void 0 : DEFAULT_BASE_URL
2883
- ), n = _(this, b, Re).call(this, s), o = await this.getPrimaryPhp(), i = removePathPrefix(
2911
+ ), n = _(this, R, be).call(this, s), o = await this.getPrimaryPhp(), i = removePathPrefix(
2884
2912
  /**
2885
2913
  * URL.pathname returns a URL-encoded path. We need to decode it
2886
2914
  * before using it as a filesystem path.
@@ -2888,7 +2916,7 @@ class PHPRequestHandler {
2888
2916
  decodeURIComponent(n.pathname),
2889
2917
  p(this, I)
2890
2918
  );
2891
- let a = _(this, b, oe).call(this, i);
2919
+ let a = _(this, R, oe).call(this, i);
2892
2920
  if (o.isDir(a)) {
2893
2921
  if (!i.endsWith("/"))
2894
2922
  return StreamedPHPResponse.fromPHPResponse(
@@ -2913,10 +2941,10 @@ class PHPRequestHandler {
2913
2941
  let c = i;
2914
2942
  for (; c.startsWith("/") && c !== dirname(c); ) {
2915
2943
  c = dirname(c);
2916
- const l = _(this, b, oe).call(this, c);
2944
+ const l = _(this, R, oe).call(this, c);
2917
2945
  if (o.isFile(l) && // Only run partial path resolution for PHP files.
2918
2946
  l.endsWith(".php")) {
2919
- a = _(this, b, oe).call(this, c);
2947
+ a = _(this, R, oe).call(this, c);
2920
2948
  break;
2921
2949
  }
2922
2950
  }
@@ -2941,8 +2969,8 @@ class PHPRequestHandler {
2941
2969
  );
2942
2970
  }
2943
2971
  }
2944
- return o.isFile(a) ? a.endsWith(".php") ? await _(this, b, He).call(this, e, s, n, a) : StreamedPHPResponse.fromPHPResponse(
2945
- _(this, b, be).call(this, o, a)
2972
+ return o.isFile(a) ? a.endsWith(".php") ? await _(this, R, He).call(this, e, s, n, a) : StreamedPHPResponse.fromPHPResponse(
2973
+ _(this, R, Re).call(this, o, a)
2946
2974
  ) : StreamedPHPResponse.forHttpCode(404);
2947
2975
  }
2948
2976
  /**
@@ -3052,13 +3080,13 @@ class PHPRequestHandler {
3052
3080
  await this.instanceManager[Symbol.asyncDispose]();
3053
3081
  }
3054
3082
  }
3055
- A = new WeakMap(), Q = new WeakMap(), re = new WeakMap(), Y = new WeakMap(), K = new WeakMap(), I = new WeakMap(), Z = new WeakMap(), $ = new WeakMap(), se = new WeakMap(), b = new WeakSet(), /**
3083
+ A = new WeakMap(), Q = new WeakMap(), re = new WeakMap(), X = new WeakMap(), K = new WeakMap(), I = new WeakMap(), Z = new WeakMap(), $ = new WeakMap(), se = new WeakMap(), R = new WeakSet(), /**
3056
3084
  * Apply the rewrite rules to the original request URL.
3057
3085
  *
3058
3086
  * @param originalRequestUrl - The original request URL.
3059
3087
  * @returns The rewritten request URL.
3060
3088
  */
3061
- Re = function(e) {
3089
+ be = function(e) {
3062
3090
  const t = removePathPrefix(
3063
3091
  decodeURIComponent(e.pathname),
3064
3092
  p(this, I)
@@ -3094,7 +3122,7 @@ oe = function(e) {
3094
3122
  * @param fsPath - Absolute path of the static file to serve.
3095
3123
  * @returns The response.
3096
3124
  */
3097
- be = function(e, t) {
3125
+ Re = function(e, t) {
3098
3126
  const s = e.readFileAsBuffer(t);
3099
3127
  return new PHPResponse(
3100
3128
  200,
@@ -3118,7 +3146,7 @@ be = function(e, t) {
3118
3146
  }
3119
3147
  let i;
3120
3148
  try {
3121
- i = await _(this, b, Te).call(this, o.php, e, t, s, n);
3149
+ i = await _(this, R, Te).call(this, o.php, e, t, s, n);
3122
3150
  } catch (a) {
3123
3151
  throw o.reap(), a;
3124
3152
  }
@@ -3391,7 +3419,7 @@ function validate11(r, { instancePath: e = "", parentData: t, parentDataProperty
3391
3419
  if (a) {
3392
3420
  if (r.mode !== void 0) {
3393
3421
  let f = r.mode;
3394
- const R = i;
3422
+ const b = i;
3395
3423
  if (typeof f != "string")
3396
3424
  return validate11.errors = [
3397
3425
  {
@@ -3414,7 +3442,7 @@ function validate11(r, { instancePath: e = "", parentData: t, parentDataProperty
3414
3442
  message: "must be equal to constant"
3415
3443
  }
3416
3444
  ], !1;
3417
- var a = R === i;
3445
+ var a = b === i;
3418
3446
  } else
3419
3447
  var a = !0;
3420
3448
  if (a) {
@@ -3434,15 +3462,15 @@ function validate11(r, { instancePath: e = "", parentData: t, parentDataProperty
3434
3462
  if (a) {
3435
3463
  if (r.iniEntries !== void 0) {
3436
3464
  let f = r.iniEntries;
3437
- const R = i;
3438
- if (i === R)
3465
+ const b = i;
3466
+ if (i === b)
3439
3467
  if (f && typeof f == "object" && !Array.isArray(f))
3440
- for (const U in f) {
3468
+ for (const j in f) {
3441
3469
  const m = i;
3442
- if (typeof f[U] != "string")
3470
+ if (typeof f[j] != "string")
3443
3471
  return validate11.errors = [
3444
3472
  {
3445
- instancePath: e + "/iniEntries/" + U.replace(
3473
+ instancePath: e + "/iniEntries/" + j.replace(
3446
3474
  /~/g,
3447
3475
  "~0"
3448
3476
  ).replace(
@@ -3473,21 +3501,21 @@ function validate11(r, { instancePath: e = "", parentData: t, parentDataProperty
3473
3501
  message: "must be object"
3474
3502
  }
3475
3503
  ], !1;
3476
- var a = R === i;
3504
+ var a = b === i;
3477
3505
  } else
3478
3506
  var a = !0;
3479
3507
  if (a) {
3480
3508
  if (r.env !== void 0) {
3481
3509
  let f = r.env;
3482
- const R = i;
3483
- if (i === R)
3510
+ const b = i;
3511
+ if (i === b)
3484
3512
  if (f && typeof f == "object" && !Array.isArray(f))
3485
- for (const U in f) {
3513
+ for (const j in f) {
3486
3514
  const m = i;
3487
- if (typeof f[U] != "string")
3515
+ if (typeof f[j] != "string")
3488
3516
  return validate11.errors = [
3489
3517
  {
3490
- instancePath: e + "/env/" + U.replace(
3518
+ instancePath: e + "/env/" + j.replace(
3491
3519
  /~/g,
3492
3520
  "~0"
3493
3521
  ).replace(
@@ -3518,7 +3546,7 @@ function validate11(r, { instancePath: e = "", parentData: t, parentDataProperty
3518
3546
  message: "must be object"
3519
3547
  }
3520
3548
  ], !1;
3521
- var a = R === i;
3549
+ var a = b === i;
3522
3550
  } else
3523
3551
  var a = !0;
3524
3552
  if (a) {
@@ -3542,12 +3570,12 @@ function validate11(r, { instancePath: e = "", parentData: t, parentDataProperty
3542
3570
  if (a) {
3543
3571
  if (r.artifacts !== void 0) {
3544
3572
  let f = r.artifacts;
3545
- const R = i;
3546
- if (i === R)
3573
+ const b = i;
3574
+ if (i === b)
3547
3575
  if (Array.isArray(f)) {
3548
3576
  var d = !0;
3549
- const U = f.length;
3550
- for (let m = 0; m < U; m++) {
3577
+ const j = f.length;
3578
+ for (let m = 0; m < j; m++) {
3551
3579
  let w = f[m];
3552
3580
  const W = i;
3553
3581
  if (i === W)
@@ -3851,13 +3879,13 @@ function validate11(r, { instancePath: e = "", parentData: t, parentDataProperty
3851
3879
  message: "must be array"
3852
3880
  }
3853
3881
  ], !1;
3854
- var a = R === i;
3882
+ var a = b === i;
3855
3883
  } else
3856
3884
  var a = !0;
3857
3885
  if (a)
3858
3886
  if (r.extraFiles !== void 0) {
3859
3887
  let f = r.extraFiles;
3860
- const R = i;
3888
+ const b = i;
3861
3889
  if (i === i)
3862
3890
  if (f && typeof f == "object" && !Array.isArray(
3863
3891
  f
@@ -4053,7 +4081,7 @@ function validate11(r, { instancePath: e = "", parentData: t, parentDataProperty
4053
4081
  message: "must be object"
4054
4082
  }
4055
4083
  ], !1;
4056
- var a = R === i;
4084
+ var a = b === i;
4057
4085
  } else
4058
4086
  var a = !0;
4059
4087
  }
@@ -4135,7 +4163,7 @@ async function resolvePHPExtension(r) {
4135
4163
  `No extension artifact found for PHP ${r.phpVersion}.`
4136
4164
  );
4137
4165
  s ?? (s = O.name), a = O.loadWithIniDirective, c = O.iniEntries, l = O.env, d = O.extensionDir;
4138
- const R = new Semaphore({
4166
+ const b = new Semaphore({
4139
4167
  concurrency: MAX_EXTENSION_SIDECAR_FILE_REQUESTS
4140
4168
  }), ce = [];
4141
4169
  for (const m of [O.extraFiles, f.extraFiles])
@@ -4148,16 +4176,16 @@ async function resolvePHPExtension(r) {
4148
4176
  if (!w.sourcePath) continue;
4149
4177
  const Me = new URL(w.sourcePath, M);
4150
4178
  ce.push(
4151
- R.run(() => fetchBytes(e, Me)).then((q) => {
4179
+ b.run(() => fetchBytes(e, Me)).then((q) => {
4152
4180
  o[W] = q;
4153
4181
  })
4154
4182
  );
4155
4183
  }
4156
- const [U] = await Promise.all([
4184
+ const [j] = await Promise.all([
4157
4185
  fetchBytes(e, new URL(f.sourcePath, M)),
4158
4186
  ...ce
4159
4187
  ]);
4160
- n = U;
4188
+ n = j;
4161
4189
  }
4162
4190
  const u = normalizePath(
4163
4191
  r.extensionDir ?? d ?? PHP_EXTENSIONS_DIR
@@ -6013,6 +6041,7 @@ export {
6013
6041
  consumeAPISync,
6014
6042
  createLegacyPhpIniPreRunStep,
6015
6043
  createObjectPoolProxy,
6044
+ describeError,
6016
6045
  ensurePathPrefix,
6017
6046
  exposeAPI,
6018
6047
  exposeSyncAPI,