@php-wasm/web 0.6.14 → 0.6.15
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 +73 -58
- package/package.json +6 -6
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var c = (e, t, r) => (K(e, t, "read from private field"), r ? r.call(e) : t.get(
|
|
|
6
6
|
if (t.has(e))
|
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
|
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
11
|
const currentJsRuntime$1 = function() {
|
|
12
12
|
var e;
|
|
@@ -431,7 +431,7 @@ class PHPBrowser {
|
|
|
431
431
|
constructor(t, r = {}) {
|
|
432
432
|
d(this, R, void 0);
|
|
433
433
|
d(this, T, void 0);
|
|
434
|
-
this.requestHandler = t,
|
|
434
|
+
this.requestHandler = t, p(this, R, {}), p(this, T, {
|
|
435
435
|
handleRedirects: !1,
|
|
436
436
|
maxRedirects: 4,
|
|
437
437
|
...r
|
|
@@ -588,20 +588,20 @@ class PHPRequestHandler {
|
|
|
588
588
|
d(this, y, void 0);
|
|
589
589
|
d(this, C, void 0);
|
|
590
590
|
d(this, S, void 0);
|
|
591
|
-
|
|
591
|
+
p(this, S, new Semaphore({ concurrency: 1 }));
|
|
592
592
|
const {
|
|
593
593
|
documentRoot: s = "/www/",
|
|
594
594
|
absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : "",
|
|
595
595
|
rewriteRules: o = []
|
|
596
596
|
} = r;
|
|
597
|
-
this.php = t,
|
|
597
|
+
this.php = t, p(this, g, s);
|
|
598
598
|
const i = new URL(n);
|
|
599
|
-
|
|
599
|
+
p(this, N, i.hostname), p(this, b, i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80), p(this, H, (i.protocol || "").replace(":", ""));
|
|
600
600
|
const a = c(this, b) !== 443 && c(this, b) !== 80;
|
|
601
|
-
|
|
601
|
+
p(this, k, [
|
|
602
602
|
c(this, N),
|
|
603
603
|
a ? `:${c(this, b)}` : ""
|
|
604
|
-
].join("")),
|
|
604
|
+
].join("")), p(this, y, i.pathname.replace(/\/+$/, "")), p(this, C, [
|
|
605
605
|
`${c(this, H)}://`,
|
|
606
606
|
c(this, k),
|
|
607
607
|
c(this, y)
|
|
@@ -634,9 +634,12 @@ class PHPRequestHandler {
|
|
|
634
634
|
t.url.split("#")[0],
|
|
635
635
|
r ? void 0 : DEFAULT_BASE_URL
|
|
636
636
|
), n = applyRewriteRules(
|
|
637
|
-
removePathPrefix(
|
|
637
|
+
removePathPrefix(
|
|
638
|
+
decodeURIComponent(s.pathname),
|
|
639
|
+
c(this, y)
|
|
640
|
+
),
|
|
638
641
|
this.rewriteRules
|
|
639
|
-
), o =
|
|
642
|
+
), o = joinPaths(c(this, g), n);
|
|
640
643
|
return seemsLikeAPHPRequestHandlerPath(o) ? await f(this, O, X).call(this, t, s) : f(this, L, Z).call(this, o);
|
|
641
644
|
}
|
|
642
645
|
}
|
|
@@ -689,12 +692,12 @@ g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), b = new WeakMap(), k =
|
|
|
689
692
|
let a = t.body;
|
|
690
693
|
if (typeof a == "object" && !(a instanceof Uint8Array)) {
|
|
691
694
|
o = "POST";
|
|
692
|
-
const { bytes: u, contentType:
|
|
693
|
-
a = u, i["content-type"] =
|
|
695
|
+
const { bytes: u, contentType: h } = await encodeAsMultipart(a);
|
|
696
|
+
a = u, i["content-type"] = h;
|
|
694
697
|
}
|
|
695
698
|
let l;
|
|
696
699
|
try {
|
|
697
|
-
l = f(this, U, ee).call(this, r.pathname);
|
|
700
|
+
l = f(this, U, ee).call(this, decodeURIComponent(r.pathname));
|
|
698
701
|
} catch {
|
|
699
702
|
return new PHPResponse(
|
|
700
703
|
404,
|
|
@@ -872,7 +875,7 @@ function rethrowFileSystemError(e = "") {
|
|
|
872
875
|
} catch (a) {
|
|
873
876
|
const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
874
877
|
if (l in FileErrorCodes) {
|
|
875
|
-
const u = FileErrorCodes[l],
|
|
878
|
+
const u = FileErrorCodes[l], h = typeof i[0] == "string" ? i[0] : null, _ = h !== null ? e.replaceAll("{path}", h) : e;
|
|
876
879
|
throw new Error(`${_}: ${u}`, {
|
|
877
880
|
cause: a
|
|
878
881
|
});
|
|
@@ -954,7 +957,7 @@ class BasePHP {
|
|
|
954
957
|
d(this, v, void 0);
|
|
955
958
|
d(this, P, void 0);
|
|
956
959
|
d(this, M, void 0);
|
|
957
|
-
|
|
960
|
+
p(this, x, []), p(this, w, !1), p(this, E, null), p(this, v, {}), p(this, P, /* @__PURE__ */ new Map()), p(this, M, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
|
|
958
961
|
new PHPRequestHandler(this, t)
|
|
959
962
|
));
|
|
960
963
|
}
|
|
@@ -1010,7 +1013,7 @@ class BasePHP {
|
|
|
1010
1013
|
return n;
|
|
1011
1014
|
}
|
|
1012
1015
|
return "";
|
|
1013
|
-
},
|
|
1016
|
+
}, p(this, E, improveWASMErrorReporting(t)), this.dispatchEvent({
|
|
1014
1017
|
type: "runtime.initialized"
|
|
1015
1018
|
});
|
|
1016
1019
|
}
|
|
@@ -1025,13 +1028,13 @@ class BasePHP {
|
|
|
1025
1028
|
throw new Error(
|
|
1026
1029
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
1027
1030
|
);
|
|
1028
|
-
|
|
1031
|
+
p(this, A, e);
|
|
1029
1032
|
}
|
|
1030
1033
|
/** @inheritDoc */
|
|
1031
1034
|
setPhpIniPath(e) {
|
|
1032
1035
|
if (c(this, w))
|
|
1033
1036
|
throw new Error("Cannot set PHP ini path after calling run().");
|
|
1034
|
-
|
|
1037
|
+
p(this, F, e), this[__private__dont__use].ccall(
|
|
1035
1038
|
"wasm_set_phpini_path",
|
|
1036
1039
|
null,
|
|
1037
1040
|
["string"],
|
|
@@ -1059,7 +1062,7 @@ class BasePHP {
|
|
|
1059
1062
|
const t = await this.semaphore.acquire();
|
|
1060
1063
|
let r;
|
|
1061
1064
|
try {
|
|
1062
|
-
if (c(this, w) || (f(this, W, te).call(this),
|
|
1065
|
+
if (c(this, w) || (f(this, W, te).call(this), p(this, w, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
|
|
1063
1066
|
throw new Error(
|
|
1064
1067
|
`The script path "${e.scriptPath}" does not exist.`
|
|
1065
1068
|
);
|
|
@@ -1071,15 +1074,11 @@ class BasePHP {
|
|
|
1071
1074
|
f(this, J, ue).call(this, a, o[a]);
|
|
1072
1075
|
const i = await f(this, Y, he).call(this);
|
|
1073
1076
|
if (i.exitCode !== 0) {
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
stderr: i.errors
|
|
1077
|
-
};
|
|
1078
|
-
console.warn("PHP.run() output was:", a);
|
|
1079
|
-
const l = new Error(
|
|
1077
|
+
console.warn("PHP.run() output was:", i.text);
|
|
1078
|
+
const a = new Error(
|
|
1080
1079
|
`PHP.run() failed with exit code ${i.exitCode} and the following output: ` + i.errors
|
|
1081
1080
|
);
|
|
1082
|
-
throw
|
|
1081
|
+
throw a.response = i, a.source = "request", console.error(a), a;
|
|
1083
1082
|
}
|
|
1084
1083
|
return i;
|
|
1085
1084
|
} catch (s) {
|
|
@@ -1209,7 +1208,7 @@ class BasePHP {
|
|
|
1209
1208
|
this[__private__dont__use]._exit(e);
|
|
1210
1209
|
} catch {
|
|
1211
1210
|
}
|
|
1212
|
-
|
|
1211
|
+
p(this, w, !1), p(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1213
1212
|
}
|
|
1214
1213
|
}
|
|
1215
1214
|
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() {
|
|
@@ -1378,8 +1377,8 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1378
1377
|
var l;
|
|
1379
1378
|
t = (u) => {
|
|
1380
1379
|
console.error(u), console.error(u.error);
|
|
1381
|
-
const
|
|
1382
|
-
|
|
1380
|
+
const h = new Error("Rethrown");
|
|
1381
|
+
h.cause = u.error, h.betterMessage = u.message, i(h);
|
|
1383
1382
|
}, (l = c(this, E)) == null || l.addEventListener(
|
|
1384
1383
|
"error",
|
|
1385
1384
|
t
|
|
@@ -1404,7 +1403,7 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1404
1403
|
const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, l = new Error(a);
|
|
1405
1404
|
throw l.cause = i, console.error(l), l;
|
|
1406
1405
|
} finally {
|
|
1407
|
-
(n = c(this, E)) == null || n.removeEventListener("error", t),
|
|
1406
|
+
(n = c(this, E)) == null || n.removeEventListener("error", t), p(this, v, {});
|
|
1408
1407
|
}
|
|
1409
1408
|
const { headers: r, httpStatusCode: s } = f(this, q, re).call(this);
|
|
1410
1409
|
return new PHPResponse(
|
|
@@ -1520,16 +1519,16 @@ function expose(e, t = globalThis, r = ["*"]) {
|
|
|
1520
1519
|
const { id: o, type: i, path: a } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(fromWireValue);
|
|
1521
1520
|
let u;
|
|
1522
1521
|
try {
|
|
1523
|
-
const
|
|
1522
|
+
const h = a.slice(0, -1).reduce((m, I) => m[I], e), _ = a.reduce((m, I) => m[I], e);
|
|
1524
1523
|
switch (i) {
|
|
1525
1524
|
case "GET":
|
|
1526
1525
|
u = _;
|
|
1527
1526
|
break;
|
|
1528
1527
|
case "SET":
|
|
1529
|
-
|
|
1528
|
+
h[a.slice(-1)[0]] = fromWireValue(n.data.value), u = !0;
|
|
1530
1529
|
break;
|
|
1531
1530
|
case "APPLY":
|
|
1532
|
-
u = _.apply(
|
|
1531
|
+
u = _.apply(h, l);
|
|
1533
1532
|
break;
|
|
1534
1533
|
case "CONSTRUCT":
|
|
1535
1534
|
{
|
|
@@ -1549,13 +1548,13 @@ function expose(e, t = globalThis, r = ["*"]) {
|
|
|
1549
1548
|
default:
|
|
1550
1549
|
return;
|
|
1551
1550
|
}
|
|
1552
|
-
} catch (
|
|
1553
|
-
u = { value:
|
|
1551
|
+
} catch (h) {
|
|
1552
|
+
u = { value: h, [throwMarker]: 0 };
|
|
1554
1553
|
}
|
|
1555
|
-
Promise.resolve(u).catch((
|
|
1556
|
-
const [_, m] = toWireValue(
|
|
1554
|
+
Promise.resolve(u).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
|
|
1555
|
+
const [_, m] = toWireValue(h);
|
|
1557
1556
|
t.postMessage(Object.assign(Object.assign({}, _), { id: o }), m), i === "RELEASE" && (t.removeEventListener("message", s), closeEndPoint(t), finalizer in e && typeof e[finalizer] == "function" && e[finalizer]());
|
|
1558
|
-
}).catch((
|
|
1557
|
+
}).catch((h) => {
|
|
1559
1558
|
const [_, m] = toWireValue({
|
|
1560
1559
|
value: new TypeError("Unserializable return value"),
|
|
1561
1560
|
[throwMarker]: 0
|
|
@@ -1620,7 +1619,7 @@ function createProxy(e, t = [], r = function() {
|
|
|
1620
1619
|
const [l, u] = toWireValue(a);
|
|
1621
1620
|
return requestResponseMessage(e, {
|
|
1622
1621
|
type: "SET",
|
|
1623
|
-
path: [...t, i].map((
|
|
1622
|
+
path: [...t, i].map((h) => h.toString()),
|
|
1624
1623
|
value: l
|
|
1625
1624
|
}, u).then(fromWireValue);
|
|
1626
1625
|
},
|
|
@@ -1633,12 +1632,12 @@ function createProxy(e, t = [], r = function() {
|
|
|
1633
1632
|
}).then(fromWireValue);
|
|
1634
1633
|
if (l === "bind")
|
|
1635
1634
|
return createProxy(e, t.slice(0, -1));
|
|
1636
|
-
const [u,
|
|
1635
|
+
const [u, h] = processArguments(a);
|
|
1637
1636
|
return requestResponseMessage(e, {
|
|
1638
1637
|
type: "APPLY",
|
|
1639
1638
|
path: t.map((_) => _.toString()),
|
|
1640
1639
|
argumentList: u
|
|
1641
|
-
},
|
|
1640
|
+
}, h).then(fromWireValue);
|
|
1642
1641
|
},
|
|
1643
1642
|
construct(o, i) {
|
|
1644
1643
|
throwIfProxyReleased(s);
|
|
@@ -1748,34 +1747,41 @@ function exposeAPI(e, t) {
|
|
|
1748
1747
|
}
|
|
1749
1748
|
let isTransferHandlersSetup = !1;
|
|
1750
1749
|
function setupTransferHandlers() {
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1750
|
+
if (isTransferHandlersSetup)
|
|
1751
|
+
return;
|
|
1752
|
+
isTransferHandlersSetup = !0, transferHandlers.set("EVENT", {
|
|
1753
|
+
canHandle: (r) => r instanceof CustomEvent,
|
|
1754
|
+
serialize: (r) => [
|
|
1754
1755
|
{
|
|
1755
|
-
detail:
|
|
1756
|
+
detail: r.detail
|
|
1756
1757
|
},
|
|
1757
1758
|
[]
|
|
1758
1759
|
],
|
|
1759
|
-
deserialize: (
|
|
1760
|
+
deserialize: (r) => r
|
|
1760
1761
|
}), transferHandlers.set("FUNCTION", {
|
|
1761
|
-
canHandle: (
|
|
1762
|
-
serialize(
|
|
1762
|
+
canHandle: (r) => typeof r == "function",
|
|
1763
|
+
serialize(r) {
|
|
1763
1764
|
console.debug("[Comlink][Performance] Proxying a function");
|
|
1764
|
-
const { port1:
|
|
1765
|
-
return expose(
|
|
1765
|
+
const { port1: s, port2: n } = new MessageChannel();
|
|
1766
|
+
return expose(r, s), [n, [n]];
|
|
1766
1767
|
},
|
|
1767
|
-
deserialize(
|
|
1768
|
-
return
|
|
1768
|
+
deserialize(r) {
|
|
1769
|
+
return r.start(), wrap(r);
|
|
1769
1770
|
}
|
|
1770
1771
|
}), transferHandlers.set("PHPResponse", {
|
|
1771
|
-
canHandle: (
|
|
1772
|
-
serialize(
|
|
1773
|
-
return [
|
|
1772
|
+
canHandle: (r) => typeof r == "object" && r !== null && "headers" in r && "bytes" in r && "errors" in r && "exitCode" in r && "httpStatusCode" in r,
|
|
1773
|
+
serialize(r) {
|
|
1774
|
+
return [r.toRawData(), []];
|
|
1774
1775
|
},
|
|
1775
|
-
deserialize(
|
|
1776
|
-
return PHPResponse.fromRawData(
|
|
1776
|
+
deserialize(r) {
|
|
1777
|
+
return PHPResponse.fromRawData(r);
|
|
1777
1778
|
}
|
|
1778
|
-
})
|
|
1779
|
+
});
|
|
1780
|
+
const e = transferHandlers.get("throw"), t = e == null ? void 0 : e.serialize;
|
|
1781
|
+
e.serialize = ({ value: r }) => {
|
|
1782
|
+
const s = t({ value: r });
|
|
1783
|
+
return r.response && (s[0].value.response = r.response), r.source && (s[0].value.source = r.source), s;
|
|
1784
|
+
};
|
|
1779
1785
|
}
|
|
1780
1786
|
function proxyClone(e) {
|
|
1781
1787
|
return new Proxy(e, {
|
|
@@ -2022,7 +2028,16 @@ async function registerServiceWorker(e, t, r) {
|
|
|
2022
2028
|
async function(i) {
|
|
2023
2029
|
if (t && i.data.scope !== t)
|
|
2024
2030
|
return;
|
|
2025
|
-
const a = i.data.args || [], l = i.data.method
|
|
2031
|
+
const a = i.data.args || [], l = i.data.method;
|
|
2032
|
+
let u;
|
|
2033
|
+
try {
|
|
2034
|
+
u = await e[l](...a);
|
|
2035
|
+
} catch (h) {
|
|
2036
|
+
if (l === "request" && h && typeof h == "object" && "response" in h)
|
|
2037
|
+
u = h.response;
|
|
2038
|
+
else
|
|
2039
|
+
throw h;
|
|
2040
|
+
}
|
|
2026
2041
|
i.source.postMessage(responseTo(i.data.requestId, u));
|
|
2027
2042
|
}
|
|
2028
2043
|
), s.startMessages();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/web",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.15",
|
|
4
4
|
"description": "PHP.wasm for the web",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
"type": "module",
|
|
30
30
|
"main": "index.js",
|
|
31
31
|
"types": "index.d.ts",
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "e05126da329a26535905b0ab65415d20118f0197",
|
|
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.
|
|
40
|
-
"@php-wasm/util": "0.6.
|
|
41
|
-
"@php-wasm/web-service-worker": "0.6.
|
|
42
|
-
"@php-wasm/progress": "0.6.
|
|
39
|
+
"@php-wasm/universal": "0.6.15",
|
|
40
|
+
"@php-wasm/util": "0.6.15",
|
|
41
|
+
"@php-wasm/web-service-worker": "0.6.15",
|
|
42
|
+
"@php-wasm/progress": "0.6.15"
|
|
43
43
|
}
|
|
44
44
|
}
|