@php-wasm/universal 3.0.42 → 3.0.44

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
@@ -2,7 +2,7 @@ var B = (t) => {
2
2
  throw TypeError(t);
3
3
  };
4
4
  var O = (t, e, r) => e.has(t) || B("Cannot " + r);
5
- var u = (t, e, r) => (O(t, e, "read from private field"), r ? r.call(t) : e.get(t)), y = (t, e, r) => e.has(t) ? B("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r), w = (t, e, r, s) => (O(t, e, "write to private field"), s ? s.call(t, r) : e.set(t, r), r), f = (t, e, r) => (O(t, e, "access private method"), r);
5
+ var u = (t, e, r) => (O(t, e, "read from private field"), r ? r.call(t) : e.get(t)), y = (t, e, r) => e.has(t) ? B("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r), P = (t, e, r, s) => (O(t, e, "write to private field"), s ? s.call(t, r) : e.set(t, r), r), m = (t, e, r) => (O(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, basename, normalizePath, AcquireTimeoutError, splitShellCommand } from "@php-wasm/util";
@@ -368,7 +368,7 @@ class PHPWorker {
368
368
  /** @inheritDoc */
369
369
  constructor(e, r) {
370
370
  y(this, x);
371
- this.absoluteUrl = "", this.documentRoot = "", this.chroot = null, w(this, x, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
371
+ this.absoluteUrl = "", this.documentRoot = "", this.chroot = null, P(this, x, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
372
372
  monitor: r
373
373
  }), e && this.__internal_setRequestHandler(e);
374
374
  }
@@ -961,7 +961,7 @@ class PHPExecutionFailureError extends Error {
961
961
  }
962
962
  }
963
963
  const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php", OPCACHE_FILE_FOLDER = "/internal/shared/opcache";
964
- var M, H, T, v, F, k, _, h, z, $, V, G, J, Y, Q, K, U, X, q, j;
964
+ var M, H, T, v, F, k, _, h, z, $, V, G, J, Y, Q, X, U, K, j, q;
965
965
  class PHP {
966
966
  /**
967
967
  * Initializes a PHP runtime.
@@ -1059,7 +1059,7 @@ class PHP {
1059
1059
  */
1060
1060
  onMessage(t) {
1061
1061
  return u(this, F).push(t), async () => {
1062
- w(this, F, u(this, F).filter(
1062
+ P(this, F, u(this, F).filter(
1063
1063
  (e) => e !== t
1064
1064
  ));
1065
1065
  };
@@ -1159,7 +1159,7 @@ class PHP {
1159
1159
  return n;
1160
1160
  }
1161
1161
  return "";
1162
- }, w(this, T, improveWASMErrorReporting(e)), this.dispatchEvent({
1162
+ }, P(this, T, improveWASMErrorReporting(e)), this.dispatchEvent({
1163
1163
  type: "runtime.initialized"
1164
1164
  });
1165
1165
  }
@@ -1174,7 +1174,7 @@ class PHP {
1174
1174
  throw new Error(
1175
1175
  "Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
1176
1176
  );
1177
- w(this, M, t);
1177
+ P(this, M, t);
1178
1178
  }
1179
1179
  /**
1180
1180
  * Changes the current working directory in the PHP filesystem.
@@ -1396,7 +1396,7 @@ class PHP {
1396
1396
  async runStream(t) {
1397
1397
  const e = await this.semaphore.acquire();
1398
1398
  let r;
1399
- const s = f(this, h, j).call(this, async () => {
1399
+ const s = m(this, h, q).call(this, async () => {
1400
1400
  if (u(this, H) || (await this[__private__dont__use].ccall(
1401
1401
  "php_wasm_init",
1402
1402
  null,
@@ -1405,26 +1405,26 @@ class PHP {
1405
1405
  {
1406
1406
  isAsync: !0
1407
1407
  }
1408
- ), w(this, H, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
1408
+ ), P(this, H, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
1409
1409
  throw new Error(
1410
1410
  `The script path "${t.scriptPath}" does not exist.`
1411
1411
  );
1412
- f(this, h, $).call(this, t.relativeUri || ""), f(this, h, Y).call(this, t.method || "GET");
1413
- const i = normalizeHeaders(t.headers || {}), o = i.host || "example.com:443", a = f(this, h, J).call(this, o, t.protocol || "http");
1414
- if (f(this, h, V).call(this, o), f(this, h, G).call(this, a), f(this, h, Q).call(this, i), t.body && (r = f(this, h, K).call(this, t.body)), typeof t.code == "string")
1415
- this.writeFile("/internal/eval.php", t.code), f(this, h, U).call(this, "/internal/eval.php");
1412
+ m(this, h, $).call(this, t.relativeUri || ""), m(this, h, Y).call(this, t.method || "GET");
1413
+ const i = normalizeHeaders(t.headers || {}), o = i.host || "example.com:443", a = m(this, h, J).call(this, o, t.protocol || "http");
1414
+ if (m(this, h, V).call(this, o), m(this, h, G).call(this, a), m(this, h, Q).call(this, i), t.body && (r = m(this, h, X).call(this, t.body)), typeof t.code == "string")
1415
+ this.writeFile("/internal/eval.php", t.code), m(this, h, U).call(this, "/internal/eval.php");
1416
1416
  else if (typeof t.scriptPath == "string")
1417
- f(this, h, U).call(this, t.scriptPath || "");
1417
+ m(this, h, U).call(this, t.scriptPath || "");
1418
1418
  else
1419
1419
  throw new TypeError(
1420
1420
  "The request object must have either a `code` or a `scriptPath` property."
1421
1421
  );
1422
- const c = f(this, h, z).call(this, t.$_SERVER, i, a);
1422
+ const c = m(this, h, z).call(this, t.$_SERVER, i, a);
1423
1423
  for (const p in c)
1424
- f(this, h, X).call(this, p, c[p]);
1424
+ m(this, h, K).call(this, p, c[p]);
1425
1425
  const l = t.env || {};
1426
1426
  for (const p in l)
1427
- f(this, h, q).call(this, p, l[p]);
1427
+ m(this, h, j).call(this, p, l[p]);
1428
1428
  return await this[__private__dont__use].ccall(
1429
1429
  "wasm_sapi_handle_request",
1430
1430
  NUMBER,
@@ -1647,7 +1647,7 @@ class PHP {
1647
1647
  * or an internal crash.
1648
1648
  */
1649
1649
  enableRuntimeRotation(t) {
1650
- w(this, _, {
1650
+ P(this, _, {
1651
1651
  ...u(this, _),
1652
1652
  enabled: !0,
1653
1653
  recreateRuntime: t.recreateRuntime,
@@ -1743,10 +1743,10 @@ class PHP {
1743
1743
  return this.subProcess(t, e);
1744
1744
  u(this, H) && (u(this, _).needsRotating = !0);
1745
1745
  const r = await this.semaphore.acquire();
1746
- return await f(this, h, j).call(this, () => {
1746
+ return await m(this, h, q).call(this, () => {
1747
1747
  const s = e.env || {};
1748
1748
  for (const [n, i] of Object.entries(s))
1749
- f(this, h, q).call(this, n, i);
1749
+ m(this, h, j).call(this, n, i);
1750
1750
  t = [t[0], "-c", PHP_INI_PATH, ...t.slice(1)];
1751
1751
  for (const n of t)
1752
1752
  this[__private__dont__use].ccall(
@@ -1831,7 +1831,7 @@ class PHP {
1831
1831
  this[__private__dont__use]._exit(t);
1832
1832
  } catch {
1833
1833
  }
1834
- w(this, H, !1), w(this, T, null), this[__private__dont__use] && (delete this[__private__dont__use].onMessage, delete this[__private__dont__use]);
1834
+ P(this, H, !1), P(this, T, null), this[__private__dont__use] && (delete this[__private__dont__use].onMessage, delete this[__private__dont__use]);
1835
1835
  }
1836
1836
  [Symbol.dispose]() {
1837
1837
  this.exit(0);
@@ -1915,7 +1915,7 @@ z = function(t, e, r) {
1915
1915
  [NUMBER],
1916
1916
  [parseInt(t["content-length"], 10)]
1917
1917
  );
1918
- }, K = function(t) {
1918
+ }, X = function(t) {
1919
1919
  let e, r;
1920
1920
  typeof t == "string" ? (logger.warn(
1921
1921
  "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"
@@ -1945,21 +1945,21 @@ z = function(t, e, r) {
1945
1945
  [STRING],
1946
1946
  [t]
1947
1947
  );
1948
- }, X = function(t, e) {
1948
+ }, K = function(t, e) {
1949
1949
  this[__private__dont__use].ccall(
1950
1950
  "wasm_add_SERVER_entry",
1951
1951
  null,
1952
1952
  [STRING, STRING],
1953
1953
  [t, e]
1954
1954
  );
1955
- }, q = function(t, e) {
1955
+ }, j = function(t, e) {
1956
1956
  this[__private__dont__use].ccall(
1957
1957
  "wasm_add_ENV_entry",
1958
1958
  null,
1959
1959
  [STRING, STRING],
1960
1960
  [t, e]
1961
1961
  );
1962
- }, j = async function(t) {
1962
+ }, q = async function(t) {
1963
1963
  u(this, _).enabled && u(this, _).needsRotating && await this.rotateRuntime(), ++u(this, _).requestsMade, u(this, _).requestsMade >= u(this, _).maxRequests && (u(this, _).needsRotating = !0);
1964
1964
  const e = this[__private__dont__use], r = await createInvertedReadableStream();
1965
1965
  e.onHeaders = (d) => {
@@ -1982,7 +1982,7 @@ z = function(t, e, r) {
1982
1982
  try {
1983
1983
  return await Promise.race([
1984
1984
  t(),
1985
- new Promise((P, b) => {
1985
+ new Promise((w, b) => {
1986
1986
  var D;
1987
1987
  c = (W) => {
1988
1988
  isExitCode(W.error) || b(W.error);
@@ -1993,17 +1993,17 @@ z = function(t, e, r) {
1993
1993
  );
1994
1994
  })
1995
1995
  ]);
1996
- } catch (m) {
1997
- if (isExitCode(m))
1998
- return m.status;
1999
- i.controller.error(m), o.controller.error(m), r.controller.error(m), a = !0;
2000
- for (const P in this)
2001
- typeof this[P] == "function" && (this[P] = () => {
1996
+ } catch (f) {
1997
+ if (isExitCode(f))
1998
+ return f.status;
1999
+ i.controller.error(f), o.controller.error(f), r.controller.error(f), a = !0;
2000
+ for (const w in this)
2001
+ typeof this[w] == "function" && (this[w] = () => {
2002
2002
  throw new Error(
2003
2003
  "PHP runtime has crashed – see the earlier error for details."
2004
2004
  );
2005
2005
  });
2006
- throw this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify(), m;
2006
+ throw this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify(), f;
2007
2007
  } finally {
2008
2008
  a || (i.controller.close(), o.controller.close(), n(), a = !0), (d = u(this, T)) == null || d.removeEventListener(
2009
2009
  "error",
@@ -2020,11 +2020,11 @@ z = function(t, e, r) {
2020
2020
  source: "php-wasm"
2021
2021
  }), d),
2022
2022
  (d) => {
2023
- const m = d.source ?? "php-wasm";
2023
+ const f = d.source ?? "php-wasm";
2024
2024
  throw this.dispatchEvent({
2025
2025
  type: "request.error",
2026
2026
  error: d,
2027
- source: m
2027
+ source: f
2028
2028
  }), d;
2029
2029
  }
2030
2030
  );
@@ -2386,9 +2386,7 @@ const SupportedPHPVersions = [
2386
2386
  "8.2",
2387
2387
  "8.1",
2388
2388
  "8.0",
2389
- "7.4",
2390
- "7.3",
2391
- "7.2"
2389
+ "7.4"
2392
2390
  ], LatestSupportedPHPVersion = SupportedPHPVersions[0], SupportedPHPVersionsList = SupportedPHPVersions, DEFAULT_BASE_URL = "http://example.com";
2393
2391
  function toRelativeUrl(t) {
2394
2392
  return t.origin === "null" ? t.toString() : t.toString().substring(t.origin.length);
@@ -2568,14 +2566,14 @@ class PHPRequestHandler {
2568
2566
  throw new Error(
2569
2567
  "Either php or phpFactory must be provided in the configuration."
2570
2568
  );
2571
- w(this, R, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), w(this, g, r);
2569
+ P(this, R, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), P(this, g, r);
2572
2570
  const a = new URL(s);
2573
- w(this, L, a.hostname), w(this, C, a.port ? Number(a.port) : a.protocol === "https:" ? 443 : 80), w(this, I, (a.protocol || "").replace(":", ""));
2571
+ P(this, L, a.hostname), P(this, C, a.port ? Number(a.port) : a.protocol === "https:" ? 443 : 80), P(this, I, (a.protocol || "").replace(":", ""));
2574
2572
  const c = u(this, C) !== 443 && u(this, C) !== 80;
2575
- w(this, A, [
2573
+ P(this, A, [
2576
2574
  u(this, L),
2577
2575
  c ? `:${u(this, C)}` : ""
2578
- ].join("")), w(this, E, a.pathname.replace(/\/+$/, "")), w(this, N, [
2576
+ ].join("")), P(this, E, a.pathname.replace(/\/+$/, "")), P(this, N, [
2579
2577
  `${u(this, I)}://`,
2580
2578
  u(this, A),
2581
2579
  u(this, E)
@@ -2671,7 +2669,7 @@ class PHPRequestHandler {
2671
2669
  // Remove the hash part of the URL as it's not meant for the server.
2672
2670
  e.url.split("#")[0],
2673
2671
  r ? void 0 : DEFAULT_BASE_URL
2674
- ), n = f(this, S, Z).call(this, s), i = await this.getPrimaryPhp();
2672
+ ), n = m(this, S, Z).call(this, s), i = await this.getPrimaryPhp();
2675
2673
  let o = joinPaths(
2676
2674
  u(this, g),
2677
2675
  /**
@@ -2737,7 +2735,7 @@ class PHPRequestHandler {
2737
2735
  }
2738
2736
  if (i.isFile(o))
2739
2737
  if (o.endsWith(".php")) {
2740
- const a = await f(this, S, te).call(this, e, s, n, o);
2738
+ const a = await m(this, S, te).call(this, e, s, n, o);
2741
2739
  return a.ok() && a.exitCode !== 0 ? new PHPResponse(
2742
2740
  500,
2743
2741
  a.headers,
@@ -2746,7 +2744,7 @@ class PHPRequestHandler {
2746
2744
  a.exitCode
2747
2745
  ) : a;
2748
2746
  } else
2749
- return f(this, S, ee).call(this, i, o);
2747
+ return m(this, S, ee).call(this, i, o);
2750
2748
  else
2751
2749
  return PHPResponse.forHttpCode(404);
2752
2750
  }
@@ -2908,7 +2906,7 @@ ee = function(e, r) {
2908
2906
  return o instanceof MaxPhpInstancesError ? PHPResponse.forHttpCode(502) : PHPResponse.forHttpCode(500);
2909
2907
  }
2910
2908
  try {
2911
- return await f(this, S, re).call(this, i.php, e, r, s, n);
2909
+ return await m(this, S, re).call(this, i.php, e, r, s, n);
2912
2910
  } finally {
2913
2911
  i.reap();
2914
2912
  }
@@ -2988,18 +2986,56 @@ async function writeFiles(t, e, r, { rmRoot: s = !1 } = {}) {
2988
2986
  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);
2989
2987
  }
2990
2988
  }
2989
+ function ensureProxyFSHasMmapSupport(t) {
2990
+ const e = Object.getOwnPropertySymbols(t)[0], r = t[e], s = r.PROXYFS, n = r.FS;
2991
+ s.stream_ops.mmap || (s.stream_ops.mmap = function(i, o, a, c, l) {
2992
+ if (!n.isFile(i.node.mode))
2993
+ throw new n.ErrnoError(19);
2994
+ if (a !== 0)
2995
+ throw new n.ErrnoError(22);
2996
+ const p = r.malloc(o);
2997
+ if (!p)
2998
+ throw new n.ErrnoError(48);
2999
+ const d = r.HEAPU8.subarray(p, p + o);
3000
+ let f = 0;
3001
+ for (; f < o; ) {
3002
+ const w = i.stream_ops.read(
3003
+ i,
3004
+ d,
3005
+ f,
3006
+ o - f,
3007
+ f
3008
+ );
3009
+ if (w <= 0) break;
3010
+ f += w;
3011
+ }
3012
+ if (f !== o)
3013
+ throw r.free(p), new n.ErrnoError(5);
3014
+ return { ptr: p, allocated: !0 };
3015
+ }, s.stream_ops.msync = function(i, o, a, c, l) {
3016
+ return l & 2 || i.stream_ops.write(
3017
+ i,
3018
+ o,
3019
+ a,
3020
+ c,
3021
+ a,
3022
+ !1
3023
+ ), 0;
3024
+ });
3025
+ }
2991
3026
  function proxyFileSystem(t, e, r) {
2992
- const s = Object.getOwnPropertySymbols(t)[0];
2993
- for (const n of r)
2994
- e.fileExists(n) || e.mkdir(n), t.fileExists(n) || t.mkdir(n), e[s].FS.mount(
3027
+ ensureProxyFSHasMmapSupport(e);
3028
+ const s = Object.getOwnPropertySymbols(e)[0], n = Object.getOwnPropertySymbols(t)[0];
3029
+ for (const i of r)
3030
+ e.fileExists(i) || e.mkdir(i), t.fileExists(i) || t.mkdir(i), e[s].FS.mount(
2995
3031
  // @ts-ignore
2996
3032
  e[s].PROXYFS,
2997
3033
  {
2998
- root: n,
3034
+ root: i,
2999
3035
  // @ts-ignore
3000
- fs: t[s].FS
3036
+ fs: t[n].FS
3001
3037
  },
3002
- n
3038
+ i
3003
3039
  );
3004
3040
  }
3005
3041
  function isPathToSharedFS(t, e) {
@@ -3256,10 +3292,10 @@ function expose(t, e = globalThis, r = ["*"], s) {
3256
3292
  }, l = (i.data.argumentList || []).map(fromWireValue);
3257
3293
  let p;
3258
3294
  try {
3259
- const d = c.slice(0, -1).reduce((P, b) => P[b], t), m = c.reduce((P, b) => P[b], t);
3295
+ const d = c.slice(0, -1).reduce((w, b) => w[b], t), f = c.reduce((w, b) => w[b], t);
3260
3296
  switch (a) {
3261
3297
  case MessageType.GET:
3262
- p = m;
3298
+ p = f;
3263
3299
  break;
3264
3300
  case MessageType.SET:
3265
3301
  d[c.slice(-1)[0]] = fromWireValue(
@@ -3267,18 +3303,18 @@ function expose(t, e = globalThis, r = ["*"], s) {
3267
3303
  ), p = !0;
3268
3304
  break;
3269
3305
  case MessageType.APPLY:
3270
- p = m.apply(d, l);
3306
+ p = f.apply(d, l);
3271
3307
  break;
3272
3308
  case MessageType.CONSTRUCT:
3273
3309
  {
3274
- const P = new m(...l);
3275
- p = proxy(P);
3310
+ const w = new f(...l);
3311
+ p = proxy(w);
3276
3312
  }
3277
3313
  break;
3278
3314
  case MessageType.ENDPOINT:
3279
3315
  {
3280
- const { port1: P, port2: b } = new MessageChannel();
3281
- expose(t, b), p = transfer(P, [P]);
3316
+ const { port1: w, port2: b } = new MessageChannel();
3317
+ expose(t, b), p = transfer(w, [w]);
3282
3318
  }
3283
3319
  break;
3284
3320
  case MessageType.RELEASE:
@@ -3291,14 +3327,14 @@ function expose(t, e = globalThis, r = ["*"], s) {
3291
3327
  p = { value: d, [throwMarker]: 0 };
3292
3328
  }
3293
3329
  Promise.resolve(p).catch((d) => ({ value: d, [throwMarker]: 0 })).then((d) => {
3294
- const [m, P] = toWireValue(d);
3295
- e.postMessage({ ...m, id: o }, P), a === MessageType.RELEASE && (e.removeEventListener("message", n), closeEndPoint(e), finalizer in t && typeof t[finalizer] == "function" && t[finalizer]());
3330
+ const [f, w] = toWireValue(d);
3331
+ e.postMessage({ ...f, id: o }, w), a === MessageType.RELEASE && (e.removeEventListener("message", n), closeEndPoint(e), finalizer in t && typeof t[finalizer] == "function" && t[finalizer]());
3296
3332
  }).catch(() => {
3297
- const [d, m] = toWireValue({
3333
+ const [d, f] = toWireValue({
3298
3334
  value: new TypeError("Unserializable return value"),
3299
3335
  [throwMarker]: 0
3300
3336
  });
3301
- e.postMessage({ ...d, id: o }, m);
3337
+ e.postMessage({ ...d, id: o }, f);
3302
3338
  }).finally(() => {
3303
3339
  s == null || s(i);
3304
3340
  });
@@ -3396,7 +3432,7 @@ function createProxy(t, e, r = [], s = function() {
3396
3432
  e,
3397
3433
  {
3398
3434
  type: MessageType.APPLY,
3399
- path: r.map((m) => m.toString()),
3435
+ path: r.map((f) => f.toString()),
3400
3436
  argumentList: p
3401
3437
  },
3402
3438
  d