@php-wasm/web 0.6.6 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +82 -72
  2. package/package.json +5 -5
package/index.js CHANGED
@@ -8,56 +8,66 @@ var c = (e, t, r) => (K(e, t, "read from private field"), r ? r.call(e) : t.get(
8
8
  t instanceof WeakSet ? t.add(e) : t.set(e, r);
9
9
  }, p = (e, t, r, s) => (K(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
10
10
  var f = (e, t, r) => (K(e, t, "access private method"), r);
11
- if (typeof File > "u") {
12
- class e extends Blob {
13
- constructor(r, s, n) {
14
- super(r);
15
- let o;
16
- n != null && n.lastModified && (o = /* @__PURE__ */ new Date()), (!o || isNaN(o.getFullYear())) && (o = /* @__PURE__ */ new Date()), this.lastModifiedDate = o, this.lastModified = o.getMilliseconds(), this.name = s || "";
11
+ const currentJsRuntime$1 = function() {
12
+ var e;
13
+ return typeof process < "u" && ((e = process.release) == null ? void 0 : e.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
14
+ // @ts-ignore
15
+ typeof WorkerGlobalScope < "u" && // @ts-ignore
16
+ self instanceof WorkerGlobalScope ? "WORKER" : "NODE"
17
+ );
18
+ }();
19
+ if (currentJsRuntime$1 === "NODE") {
20
+ let e = function(r) {
21
+ return new Promise(function(s, n) {
22
+ r.onload = r.onerror = function(o) {
23
+ r.onload = r.onerror = null, o.type === "load" ? s(r.result) : n(new Error("Failed to read the blob/file"));
24
+ };
25
+ });
26
+ }, t = function() {
27
+ const r = new Uint8Array([1, 2, 3, 4]), n = new File([r], "test").stream();
28
+ try {
29
+ return n.getReader({ mode: "byob" }), !0;
30
+ } catch {
31
+ return !1;
17
32
  }
18
- }
19
- global.File = e;
20
- }
21
- function asPromise(e) {
22
- return new Promise(function(t, r) {
23
- e.onload = e.onerror = function(s) {
24
- e.onload = e.onerror = null, s.type === "load" ? t(e.result) : r(new Error("Failed to read the blob/file"));
25
- };
26
- });
27
- }
28
- typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
29
- const t = new FileReader();
30
- return t.readAsArrayBuffer(this), asPromise(t);
31
- });
32
- typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
33
- const t = new FileReader();
34
- return t.readAsText(this), asPromise(t);
35
- });
36
- function isByobSupported() {
37
- const e = new Uint8Array([1, 2, 3, 4]), r = new File([e], "test").stream();
38
- try {
39
- return r.getReader({ mode: "byob" }), !0;
40
- } catch {
41
- return !1;
42
- }
43
- }
44
- (typeof Blob.prototype.stream > "u" || !isByobSupported()) && (Blob.prototype.stream = function() {
45
- let e = 0;
46
- const t = this;
47
- return new ReadableStream({
48
- type: "bytes",
49
- // 0.5 MB seems like a reasonable chunk size, let's adjust
50
- // this if needed.
51
- autoAllocateChunkSize: 512 * 1024,
52
- async pull(r) {
53
- const s = r.byobRequest.view, o = await t.slice(e, e + s.byteLength).arrayBuffer(), i = new Uint8Array(o);
54
- new Uint8Array(s.buffer).set(i);
55
- const a = i.byteLength;
56
- r.byobRequest.respond(a), e += a, e >= t.size && r.close();
33
+ };
34
+ if (typeof File > "u") {
35
+ class r extends Blob {
36
+ constructor(n, o, i) {
37
+ super(n);
38
+ let a;
39
+ i != null && i.lastModified && (a = /* @__PURE__ */ new Date()), (!a || isNaN(a.getFullYear())) && (a = /* @__PURE__ */ new Date()), this.lastModifiedDate = a, this.lastModified = a.getMilliseconds(), this.name = o || "";
40
+ }
57
41
  }
42
+ global.File = r;
43
+ }
44
+ typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
45
+ const s = new FileReader();
46
+ return s.readAsArrayBuffer(this), e(s);
47
+ }), typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
48
+ const s = new FileReader();
49
+ return s.readAsText(this), e(s);
50
+ }), (typeof Blob.prototype.stream > "u" || !t()) && (Blob.prototype.stream = function() {
51
+ let r = 0;
52
+ const s = this;
53
+ return new ReadableStream({
54
+ type: "bytes",
55
+ // 0.5 MB seems like a reasonable chunk size, let's adjust
56
+ // this if needed.
57
+ autoAllocateChunkSize: 512 * 1024,
58
+ async pull(n) {
59
+ const o = n.byobRequest.view, a = await s.slice(
60
+ r,
61
+ r + o.byteLength
62
+ ).arrayBuffer(), l = new Uint8Array(a);
63
+ new Uint8Array(o.buffer).set(l);
64
+ const u = l.byteLength;
65
+ n.byobRequest.respond(u), r += u, r >= s.size && n.close();
66
+ }
67
+ });
58
68
  });
59
- });
60
- if (typeof CustomEvent > "u") {
69
+ }
70
+ if (currentJsRuntime$1 === "NODE" && typeof CustomEvent > "u") {
61
71
  class e extends Event {
62
72
  constructor(r, s = {}) {
63
73
  super(r, s), this.detail = s.detail;
@@ -533,7 +543,7 @@ function fileToUint8Array(e) {
533
543
  }, r.readAsArrayBuffer(e);
534
544
  });
535
545
  }
536
- var g, H, L, R, k, y, C, S, N, Z, U, X, O, ee;
546
+ var g, H, N, R, k, y, C, S, L, Z, O, X, U, ee;
537
547
  class PHPRequestHandler {
538
548
  /**
539
549
  * @param php - The PHP instance.
@@ -546,7 +556,7 @@ class PHPRequestHandler {
546
556
  * @param fsPath - Absolute path of the static file to serve.
547
557
  * @returns The response.
548
558
  */
549
- d(this, N);
559
+ d(this, L);
550
560
  /**
551
561
  * Runs the requested PHP file with all the request and $_SERVER
552
562
  * superglobals populated.
@@ -554,7 +564,7 @@ class PHPRequestHandler {
554
564
  * @param request - The request.
555
565
  * @returns The response.
556
566
  */
557
- d(this, U);
567
+ d(this, O);
558
568
  /**
559
569
  * Resolve the requested path to the filesystem path of the requested PHP file.
560
570
  *
@@ -564,10 +574,10 @@ class PHPRequestHandler {
564
574
  * @throws {Error} If the requested path doesn't exist.
565
575
  * @returns The resolved filesystem path.
566
576
  */
567
- d(this, O);
577
+ d(this, U);
568
578
  d(this, g, void 0);
569
579
  d(this, H, void 0);
570
- d(this, L, void 0);
580
+ d(this, N, void 0);
571
581
  d(this, R, void 0);
572
582
  d(this, k, void 0);
573
583
  d(this, y, void 0);
@@ -580,10 +590,10 @@ class PHPRequestHandler {
580
590
  } = r;
581
591
  this.php = t, p(this, g, s);
582
592
  const o = new URL(n);
583
- p(this, L, o.hostname), p(this, R, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), p(this, H, (o.protocol || "").replace(":", ""));
593
+ p(this, N, o.hostname), p(this, R, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), p(this, H, (o.protocol || "").replace(":", ""));
584
594
  const i = c(this, R) !== 443 && c(this, R) !== 80;
585
595
  p(this, k, [
586
- c(this, L),
596
+ c(this, N),
587
597
  i ? `:${c(this, R)}` : ""
588
598
  ].join("")), p(this, y, o.pathname.replace(/\/+$/, "")), p(this, C, [
589
599
  `${c(this, H)}://`,
@@ -620,10 +630,10 @@ class PHPRequestHandler {
620
630
  s.pathname,
621
631
  c(this, y)
622
632
  ), o = `${c(this, g)}${n}`;
623
- return seemsLikeAPHPRequestHandlerPath(o) ? await f(this, U, X).call(this, t, s) : f(this, N, Z).call(this, o);
633
+ return seemsLikeAPHPRequestHandlerPath(o) ? await f(this, O, X).call(this, t, s) : f(this, L, Z).call(this, o);
624
634
  }
625
635
  }
626
- g = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k = new WeakMap(), y = new WeakMap(), C = new WeakMap(), S = new WeakMap(), N = new WeakSet(), Z = function(t) {
636
+ g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), R = new WeakMap(), k = new WeakMap(), y = new WeakMap(), C = new WeakMap(), S = new WeakMap(), L = new WeakSet(), Z = function(t) {
627
637
  if (!this.php.fileExists(t))
628
638
  return new PHPResponse(
629
639
  404,
@@ -648,7 +658,7 @@ g = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k =
648
658
  },
649
659
  r
650
660
  );
651
- }, U = new WeakSet(), X = async function(t, r) {
661
+ }, O = new WeakSet(), X = async function(t, r) {
652
662
  var n, o;
653
663
  if (c(this, S).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
654
664
  return console.warn(
@@ -685,7 +695,7 @@ g = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k =
685
695
  ).pathname;
686
696
  } catch {
687
697
  }
688
- u = f(this, O, ee).call(this, h);
698
+ u = f(this, U, ee).call(this, h);
689
699
  } catch {
690
700
  return new PHPResponse(
691
701
  404,
@@ -707,7 +717,7 @@ g = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k =
707
717
  } finally {
708
718
  s();
709
719
  }
710
- }, O = new WeakSet(), ee = function(t) {
720
+ }, U = new WeakSet(), ee = function(t) {
711
721
  let r = removePathPrefix(t, c(this, y));
712
722
  r.includes(".php") ? r = r.split(".php")[0] + ".php" : this.php.isDir(`${c(this, g)}${r}`) ? (r.endsWith("/") || (r = `${r}/`), r = `${r}index.php`) : r = "/index.php";
713
723
  const s = `${c(this, g)}${r}`;
@@ -909,7 +919,7 @@ var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyD
909
919
  return s && n && __defProp(t, r, n), n;
910
920
  };
911
921
  const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
912
- var x, F, A, w, E, v, P, M, B, te, W, re, q, se, D, ne, $, ie, z, oe, j, ae, G, le, V, ce, Q, ue, Y, de, J, he;
922
+ var x, F, A, w, E, v, P, M, W, te, B, re, q, se, D, ne, $, ie, z, oe, j, ae, G, le, V, ce, J, ue, Q, de, Y, he;
913
923
  class BasePHP {
914
924
  /**
915
925
  * Initializes a PHP runtime.
@@ -919,8 +929,8 @@ class BasePHP {
919
929
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
920
930
  */
921
931
  constructor(e, t) {
922
- d(this, B);
923
932
  d(this, W);
933
+ d(this, B);
924
934
  d(this, q);
925
935
  d(this, D);
926
936
  d(this, $);
@@ -928,9 +938,9 @@ class BasePHP {
928
938
  d(this, j);
929
939
  d(this, G);
930
940
  d(this, V);
941
+ d(this, J);
931
942
  d(this, Q);
932
943
  d(this, Y);
933
- d(this, J);
934
944
  d(this, x, void 0);
935
945
  d(this, F, void 0);
936
946
  d(this, A, void 0);
@@ -1044,17 +1054,17 @@ class BasePHP {
1044
1054
  const t = await this.semaphore.acquire();
1045
1055
  let r;
1046
1056
  try {
1047
- if (c(this, w) || (f(this, B, te).call(this), p(this, w, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
1057
+ if (c(this, w) || (f(this, W, te).call(this), p(this, w, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
1048
1058
  throw new Error(
1049
1059
  `The script path "${e.scriptPath}" does not exist.`
1050
1060
  );
1051
1061
  f(this, G, le).call(this, e.scriptPath || ""), f(this, q, se).call(this, e.relativeUri || ""), f(this, $, ie).call(this, e.method || "GET");
1052
1062
  const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443";
1053
- f(this, D, ne).call(this, n, e.protocol || "http"), f(this, z, oe).call(this, s), e.body && (r = f(this, j, ae).call(this, e.body)), typeof e.code == "string" && f(this, Y, de).call(this, " ?>" + e.code), f(this, V, ce).call(this);
1063
+ f(this, D, ne).call(this, n, e.protocol || "http"), f(this, z, oe).call(this, s), e.body && (r = f(this, j, ae).call(this, e.body)), typeof e.code == "string" && f(this, Q, de).call(this, " ?>" + e.code), f(this, V, ce).call(this);
1054
1064
  const o = e.env || {};
1055
1065
  for (const a in o)
1056
- f(this, Q, ue).call(this, a, o[a]);
1057
- const i = await f(this, J, he).call(this);
1066
+ f(this, J, ue).call(this, a, o[a]);
1067
+ const i = await f(this, Y, he).call(this);
1058
1068
  if (e.throwOnError && i.exitCode !== 0) {
1059
1069
  const a = {
1060
1070
  stdout: i.text,
@@ -1190,7 +1200,7 @@ class BasePHP {
1190
1200
  p(this, w, !1), p(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
1191
1201
  }
1192
1202
  }
1193
- x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E = new WeakMap(), v = new WeakMap(), P = new WeakMap(), M = new WeakMap(), B = new WeakSet(), te = function() {
1203
+ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E = new WeakMap(), v = new WeakMap(), P = new WeakMap(), M = new WeakMap(), W = new WeakSet(), te = function() {
1194
1204
  if (this.setPhpIniEntry("auto_prepend_file", "/internal/consts.php"), this.fileExists("/internal/consts.php") || this.writeFile(
1195
1205
  "/internal/consts.php",
1196
1206
  `<?php
@@ -1215,7 +1225,7 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
1215
1225
  );
1216
1226
  }
1217
1227
  this[__private__dont__use].ccall("php_wasm_init", null, [], []);
1218
- }, W = new WeakSet(), re = function() {
1228
+ }, B = new WeakSet(), re = function() {
1219
1229
  const e = "/internal/headers.json";
1220
1230
  if (!this.fileExists(e))
1221
1231
  throw new Error(
@@ -1334,21 +1344,21 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
1334
1344
  [STRING, STRING],
1335
1345
  [e, c(this, v)[e]]
1336
1346
  );
1337
- }, Q = new WeakSet(), ue = function(e, t) {
1347
+ }, J = new WeakSet(), ue = function(e, t) {
1338
1348
  this[__private__dont__use].ccall(
1339
1349
  "wasm_add_ENV_entry",
1340
1350
  null,
1341
1351
  [STRING, STRING],
1342
1352
  [e, t]
1343
1353
  );
1344
- }, Y = new WeakSet(), de = function(e) {
1354
+ }, Q = new WeakSet(), de = function(e) {
1345
1355
  this[__private__dont__use].ccall(
1346
1356
  "wasm_set_php_code",
1347
1357
  null,
1348
1358
  [STRING],
1349
1359
  [e]
1350
1360
  );
1351
- }, J = new WeakSet(), he = async function() {
1361
+ }, Y = new WeakSet(), he = async function() {
1352
1362
  var n;
1353
1363
  let e, t;
1354
1364
  try {
@@ -1384,7 +1394,7 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
1384
1394
  } finally {
1385
1395
  (n = c(this, E)) == null || n.removeEventListener("error", t), p(this, v, {});
1386
1396
  }
1387
- const { headers: r, httpStatusCode: s } = f(this, W, re).call(this);
1397
+ const { headers: r, httpStatusCode: s } = f(this, B, re).call(this);
1388
1398
  return new PHPResponse(
1389
1399
  s,
1390
1400
  r,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/web",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "description": "PHP.wasm for the web",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,15 +29,15 @@
29
29
  "type": "module",
30
30
  "main": "index.js",
31
31
  "types": "index.d.ts",
32
- "gitHead": "90f82ca946f8573b358c1320be0b6b8674f67cfc",
32
+ "gitHead": "c4c52563eee8997b94cd4a0875e10fb5d8ccda42",
33
33
  "engines": {
34
34
  "node": ">=16.15.1",
35
35
  "npm": ">=8.11.0"
36
36
  },
37
37
  "dependencies": {
38
38
  "comlink": "^4.4.1",
39
- "@php-wasm/universal": "0.6.6",
40
- "@php-wasm/web-service-worker": "0.6.6",
41
- "@php-wasm/progress": "0.6.6"
39
+ "@php-wasm/universal": "0.6.7",
40
+ "@php-wasm/web-service-worker": "0.6.7",
41
+ "@php-wasm/progress": "0.6.7"
42
42
  }
43
43
  }