@php-wasm/universal 3.1.14 → 3.1.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.cjs +5 -5
- package/index.cjs.map +1 -1
- package/index.js +93 -52
- package/index.js.map +1 -1
- package/lib/universal-php.d.ts +1 -0
- package/package.json +7 -7
package/index.js
CHANGED
|
@@ -372,12 +372,12 @@ FSHelpers.mkdir = rethrowFileSystemError('Could not create directory "{path}"')(
|
|
|
372
372
|
FSHelpers.mkdir
|
|
373
373
|
);
|
|
374
374
|
const _private = /* @__PURE__ */ new WeakMap();
|
|
375
|
-
var
|
|
375
|
+
var v;
|
|
376
376
|
class PHPWorker {
|
|
377
377
|
/** @inheritDoc */
|
|
378
378
|
constructor(e, t) {
|
|
379
|
-
y(this,
|
|
380
|
-
this.absoluteUrl = "", this.documentRoot = "", this.chroot = null, g(this,
|
|
379
|
+
y(this, v);
|
|
380
|
+
this.absoluteUrl = "", this.documentRoot = "", this.chroot = null, g(this, v, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
|
|
381
381
|
monitor: t
|
|
382
382
|
}), e && this.__internal_setRequestHandler(e);
|
|
383
383
|
}
|
|
@@ -546,7 +546,7 @@ class PHPWorker {
|
|
|
546
546
|
}
|
|
547
547
|
/** @inheritDoc @php-wasm/universal!/PHP.addEventListener */
|
|
548
548
|
addEventListener(e, t) {
|
|
549
|
-
u(this,
|
|
549
|
+
u(this, v).has(e) || u(this, v).set(e, /* @__PURE__ */ new Set()), u(this, v).get(e).add(t);
|
|
550
550
|
}
|
|
551
551
|
/**
|
|
552
552
|
* Removes an event listener for a PHP event.
|
|
@@ -555,10 +555,10 @@ class PHPWorker {
|
|
|
555
555
|
*/
|
|
556
556
|
removeEventListener(e, t) {
|
|
557
557
|
var s;
|
|
558
|
-
(s = u(this,
|
|
558
|
+
(s = u(this, v).get(e)) == null || s.delete(t);
|
|
559
559
|
}
|
|
560
560
|
dispatchEvent(e) {
|
|
561
|
-
const t = u(this,
|
|
561
|
+
const t = u(this, v).get(e.type);
|
|
562
562
|
if (t)
|
|
563
563
|
for (const s of t)
|
|
564
564
|
s(e);
|
|
@@ -580,7 +580,7 @@ class PHPWorker {
|
|
|
580
580
|
await ((e = _private.get(this).requestHandler) == null ? void 0 : e[Symbol.asyncDispose]());
|
|
581
581
|
}
|
|
582
582
|
}
|
|
583
|
-
|
|
583
|
+
v = new WeakMap();
|
|
584
584
|
function isExitCode(r) {
|
|
585
585
|
return r instanceof Error ? (r == null ? void 0 : r.name) === "ExitStatus" && "status" in r : !1;
|
|
586
586
|
}
|
|
@@ -1052,7 +1052,7 @@ class PHPExecutionFailureError extends Error {
|
|
|
1052
1052
|
}
|
|
1053
1053
|
}
|
|
1054
1054
|
const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php", OPCACHE_FILE_FOLDER = "/internal/shared/opcache";
|
|
1055
|
-
var
|
|
1055
|
+
var C, R, b, x, T, H, w, p, Y, X, Q, K, Z, ee, te, re, $, se, q, z;
|
|
1056
1056
|
class PHP {
|
|
1057
1057
|
/**
|
|
1058
1058
|
* Initializes a PHP runtime.
|
|
@@ -1063,7 +1063,7 @@ class PHP {
|
|
|
1063
1063
|
*/
|
|
1064
1064
|
constructor(r) {
|
|
1065
1065
|
y(this, p);
|
|
1066
|
-
y(this,
|
|
1066
|
+
y(this, C);
|
|
1067
1067
|
y(this, R, !1);
|
|
1068
1068
|
y(this, b, null);
|
|
1069
1069
|
y(this, x, /* @__PURE__ */ new Map([
|
|
@@ -1265,7 +1265,7 @@ class PHP {
|
|
|
1265
1265
|
throw new Error(
|
|
1266
1266
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
1267
1267
|
);
|
|
1268
|
-
g(this,
|
|
1268
|
+
g(this, C, r);
|
|
1269
1269
|
}
|
|
1270
1270
|
/**
|
|
1271
1271
|
* Changes the current working directory in the PHP filesystem.
|
|
@@ -1503,9 +1503,9 @@ class PHP {
|
|
|
1503
1503
|
m(this, p, X).call(this, r.relativeUri || ""), m(this, p, ee).call(this, r.method || "GET");
|
|
1504
1504
|
const i = normalizeHeaders(r.headers || {}), o = i.host || "example.com:443", a = m(this, p, Z).call(this, o, r.protocol || "http");
|
|
1505
1505
|
if (m(this, p, Q).call(this, o), m(this, p, K).call(this, a), m(this, p, te).call(this, i), r.body && (t = m(this, p, re).call(this, r.body)), typeof r.code == "string")
|
|
1506
|
-
this.writeFile("/internal/eval.php", r.code), m(this, p,
|
|
1506
|
+
this.writeFile("/internal/eval.php", r.code), m(this, p, $).call(this, "/internal/eval.php");
|
|
1507
1507
|
else if (typeof r.scriptPath == "string")
|
|
1508
|
-
m(this, p,
|
|
1508
|
+
m(this, p, $).call(this, r.scriptPath || "");
|
|
1509
1509
|
else
|
|
1510
1510
|
throw new TypeError(
|
|
1511
1511
|
"The request object must have either a `code` or a `scriptPath` property."
|
|
@@ -1515,7 +1515,7 @@ class PHP {
|
|
|
1515
1515
|
m(this, p, se).call(this, d, c[d]);
|
|
1516
1516
|
const l = r.env || {};
|
|
1517
1517
|
for (const d in l)
|
|
1518
|
-
m(this, p,
|
|
1518
|
+
m(this, p, q).call(this, d, l[d]);
|
|
1519
1519
|
return await this[__private__dont__use].ccall(
|
|
1520
1520
|
"wasm_sapi_handle_request",
|
|
1521
1521
|
NUMBER,
|
|
@@ -1792,7 +1792,7 @@ class PHP {
|
|
|
1792
1792
|
this.exit();
|
|
1793
1793
|
} catch {
|
|
1794
1794
|
}
|
|
1795
|
-
this.initializeRuntime(r), s && (this[__private__dont__use].spawnProcess = s), u(this,
|
|
1795
|
+
this.initializeRuntime(r), s && (this[__private__dont__use].spawnProcess = s), u(this, C) && this.setSapiName(u(this, C));
|
|
1796
1796
|
const a = this[__private__dont__use].FS;
|
|
1797
1797
|
for (const c of t)
|
|
1798
1798
|
c && c !== "/request" && copyMEMFSNodes(e, a, c);
|
|
@@ -1852,7 +1852,7 @@ class PHP {
|
|
|
1852
1852
|
return await m(this, p, z).call(this, () => {
|
|
1853
1853
|
const s = e.env || {};
|
|
1854
1854
|
for (const [n, i] of Object.entries(s))
|
|
1855
|
-
m(this, p,
|
|
1855
|
+
m(this, p, q).call(this, n, i);
|
|
1856
1856
|
r = [r[0], "-c", PHP_INI_PATH, ...r.slice(1)];
|
|
1857
1857
|
for (const n of r)
|
|
1858
1858
|
this[__private__dont__use].ccall(
|
|
@@ -1885,38 +1885,48 @@ class PHP {
|
|
|
1885
1885
|
cwd: e.cwd ?? this.cwd()
|
|
1886
1886
|
}
|
|
1887
1887
|
), s = await createInvertedReadableStream();
|
|
1888
|
-
t.on("error", (
|
|
1889
|
-
s.controller
|
|
1890
|
-
}), t.stderr.on("data", (i) => {
|
|
1891
|
-
s.controller.enqueue(i);
|
|
1888
|
+
t.on("error", (a) => {
|
|
1889
|
+
safeStreamError$1(s.controller, a);
|
|
1892
1890
|
});
|
|
1893
|
-
const n =
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1891
|
+
const n = (a) => {
|
|
1892
|
+
try {
|
|
1893
|
+
s.controller.enqueue(a);
|
|
1894
|
+
} catch {
|
|
1895
|
+
t.stderr.off("data", n);
|
|
1896
|
+
}
|
|
1897
|
+
};
|
|
1898
|
+
t.stderr.on("data", n);
|
|
1899
|
+
const i = await createInvertedReadableStream(), o = (a) => {
|
|
1900
|
+
try {
|
|
1901
|
+
i.controller.enqueue(a);
|
|
1902
|
+
} catch {
|
|
1903
|
+
t.stdout.off("data", o);
|
|
1904
|
+
}
|
|
1905
|
+
};
|
|
1906
|
+
return t.stdout.on("data", o), t.on("exit", () => {
|
|
1897
1907
|
setTimeout(() => {
|
|
1898
1908
|
try {
|
|
1899
1909
|
s.controller.close();
|
|
1900
1910
|
} catch {
|
|
1901
1911
|
}
|
|
1902
1912
|
try {
|
|
1903
|
-
|
|
1913
|
+
i.controller.close();
|
|
1904
1914
|
} catch {
|
|
1905
1915
|
}
|
|
1906
1916
|
}, 0);
|
|
1907
1917
|
}), new StreamedPHPResponse(
|
|
1908
1918
|
// Headers stream
|
|
1909
1919
|
new ReadableStream({
|
|
1910
|
-
start(
|
|
1911
|
-
|
|
1920
|
+
start(a) {
|
|
1921
|
+
a.close();
|
|
1912
1922
|
}
|
|
1913
1923
|
}),
|
|
1914
|
-
|
|
1924
|
+
i.stream,
|
|
1915
1925
|
s.stream,
|
|
1916
1926
|
// Exit code
|
|
1917
|
-
new Promise((
|
|
1918
|
-
t.on("exit", (
|
|
1919
|
-
|
|
1927
|
+
new Promise((a) => {
|
|
1928
|
+
t.on("exit", (c) => {
|
|
1929
|
+
a(c);
|
|
1920
1930
|
});
|
|
1921
1931
|
})
|
|
1922
1932
|
);
|
|
@@ -1943,7 +1953,7 @@ class PHP {
|
|
|
1943
1953
|
this.exit(0);
|
|
1944
1954
|
}
|
|
1945
1955
|
}
|
|
1946
|
-
|
|
1956
|
+
C = new WeakMap(), R = new WeakMap(), b = new WeakMap(), x = new WeakMap(), T = new WeakMap(), H = new WeakMap(), w = new WeakMap(), p = new WeakSet(), /**
|
|
1947
1957
|
* Prepares the $_SERVER entries for the PHP runtime.
|
|
1948
1958
|
*
|
|
1949
1959
|
* @param defaults Default entries to include in $_SERVER.
|
|
@@ -2044,7 +2054,7 @@ Y = function(r, e, t) {
|
|
|
2044
2054
|
[NUMBER],
|
|
2045
2055
|
[t]
|
|
2046
2056
|
), s;
|
|
2047
|
-
},
|
|
2057
|
+
}, $ = function(r) {
|
|
2048
2058
|
this[__private__dont__use].ccall(
|
|
2049
2059
|
"wasm_set_path_translated",
|
|
2050
2060
|
null,
|
|
@@ -2058,7 +2068,7 @@ Y = function(r, e, t) {
|
|
|
2058
2068
|
[STRING, STRING],
|
|
2059
2069
|
[r, e]
|
|
2060
2070
|
);
|
|
2061
|
-
},
|
|
2071
|
+
}, q = function(r, e) {
|
|
2062
2072
|
this[__private__dont__use].ccall(
|
|
2063
2073
|
"wasm_add_ENV_entry",
|
|
2064
2074
|
null,
|
|
@@ -2102,7 +2112,7 @@ Y = function(r, e, t) {
|
|
|
2102
2112
|
} catch (f) {
|
|
2103
2113
|
if (isExitCode(f))
|
|
2104
2114
|
return f.status;
|
|
2105
|
-
i.controller
|
|
2115
|
+
safeStreamError$1(i.controller, f), safeStreamError$1(o.controller, f), safeStreamError$1(t.controller, f), a = !0;
|
|
2106
2116
|
for (const _ in this)
|
|
2107
2117
|
typeof this[_] == "function" && (this[_] = () => {
|
|
2108
2118
|
throw new Error(
|
|
@@ -2111,7 +2121,7 @@ Y = function(r, e, t) {
|
|
|
2111
2121
|
});
|
|
2112
2122
|
throw this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify(), f;
|
|
2113
2123
|
} finally {
|
|
2114
|
-
a || (i.controller
|
|
2124
|
+
a || (safeStreamClose$1(i.controller), safeStreamClose$1(o.controller), n(), a = !0), (h = u(this, b)) == null || h.removeEventListener(
|
|
2115
2125
|
"error",
|
|
2116
2126
|
c
|
|
2117
2127
|
);
|
|
@@ -2178,6 +2188,18 @@ async function createInvertedReadableStream(r = {}) {
|
|
|
2178
2188
|
controller: n
|
|
2179
2189
|
};
|
|
2180
2190
|
}
|
|
2191
|
+
function safeStreamError$1(r, e) {
|
|
2192
|
+
try {
|
|
2193
|
+
r.error(e);
|
|
2194
|
+
} catch {
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
function safeStreamClose$1(r) {
|
|
2198
|
+
try {
|
|
2199
|
+
r.close();
|
|
2200
|
+
} catch {
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2181
2203
|
const getNodeType = (r, e) => {
|
|
2182
2204
|
try {
|
|
2183
2205
|
return "contents" in r.lookupPath(e, { follow: !0 }).node ? "memfs" : (
|
|
@@ -2576,7 +2598,7 @@ const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "app
|
|
|
2576
2598
|
xspf,
|
|
2577
2599
|
zip
|
|
2578
2600
|
};
|
|
2579
|
-
var
|
|
2601
|
+
var S, M, U, L, I, E, A, k, B, P, ne, j, ie, oe, ae;
|
|
2580
2602
|
class PHPRequestHandler {
|
|
2581
2603
|
/**
|
|
2582
2604
|
* The request handler needs to decide whether to serve a static asset or
|
|
@@ -2591,8 +2613,8 @@ class PHPRequestHandler {
|
|
|
2591
2613
|
*/
|
|
2592
2614
|
constructor(e) {
|
|
2593
2615
|
y(this, P);
|
|
2594
|
-
y(this,
|
|
2595
|
-
y(this,
|
|
2616
|
+
y(this, S);
|
|
2617
|
+
y(this, M);
|
|
2596
2618
|
y(this, U);
|
|
2597
2619
|
y(this, L);
|
|
2598
2620
|
y(this, I);
|
|
@@ -2628,15 +2650,15 @@ class PHPRequestHandler {
|
|
|
2628
2650
|
throw new Error(
|
|
2629
2651
|
"Either php or phpFactory must be provided in the configuration."
|
|
2630
2652
|
);
|
|
2631
|
-
g(this, k, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), g(this,
|
|
2653
|
+
g(this, k, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), g(this, S, t);
|
|
2632
2654
|
const c = new URL(s);
|
|
2633
|
-
g(this, U, c.hostname), g(this, L, c.port ? Number(c.port) : c.protocol === "https:" ? 443 : 80), g(this,
|
|
2655
|
+
g(this, U, c.hostname), g(this, L, c.port ? Number(c.port) : c.protocol === "https:" ? 443 : 80), g(this, M, (c.protocol || "").replace(":", ""));
|
|
2634
2656
|
const l = u(this, L) !== 443 && u(this, L) !== 80;
|
|
2635
2657
|
g(this, I, [
|
|
2636
2658
|
u(this, U),
|
|
2637
2659
|
l ? `:${u(this, L)}` : ""
|
|
2638
2660
|
].join("")), g(this, E, c.pathname.replace(/\/+$/, "")), g(this, A, [
|
|
2639
|
-
`${u(this,
|
|
2661
|
+
`${u(this, M)}://`,
|
|
2640
2662
|
u(this, I),
|
|
2641
2663
|
u(this, E)
|
|
2642
2664
|
].join("")), this.rewriteRules = n, g(this, B, i), this.getFileNotFoundAction = o;
|
|
@@ -2676,7 +2698,7 @@ class PHPRequestHandler {
|
|
|
2676
2698
|
* for the files to serve. Default: `/var/www`.
|
|
2677
2699
|
*/
|
|
2678
2700
|
get documentRoot() {
|
|
2679
|
-
return u(this,
|
|
2701
|
+
return u(this, S);
|
|
2680
2702
|
}
|
|
2681
2703
|
/**
|
|
2682
2704
|
* Serves the request – either by serving a static file, or by
|
|
@@ -2803,7 +2825,7 @@ class PHPRequestHandler {
|
|
|
2803
2825
|
c.response
|
|
2804
2826
|
);
|
|
2805
2827
|
case "internal-redirect":
|
|
2806
|
-
a = joinPaths(u(this,
|
|
2828
|
+
a = joinPaths(u(this, S), c.uri);
|
|
2807
2829
|
break;
|
|
2808
2830
|
case "404":
|
|
2809
2831
|
return StreamedPHPResponse.forHttpCode(404);
|
|
@@ -2908,11 +2930,11 @@ class PHPRequestHandler {
|
|
|
2908
2930
|
prepare_$_SERVER_superglobal(e, t, s) {
|
|
2909
2931
|
const n = {
|
|
2910
2932
|
REMOTE_ADDR: "127.0.0.1",
|
|
2911
|
-
DOCUMENT_ROOT: u(this,
|
|
2933
|
+
DOCUMENT_ROOT: u(this, S),
|
|
2912
2934
|
HTTPS: u(this, A).startsWith("https://") ? "on" : ""
|
|
2913
2935
|
};
|
|
2914
|
-
return n.REQUEST_URI = e.pathname + e.search, s.startsWith(u(this,
|
|
2915
|
-
u(this,
|
|
2936
|
+
return n.REQUEST_URI = e.pathname + e.search, s.startsWith(u(this, S)) && (n.SCRIPT_NAME = s.substring(
|
|
2937
|
+
u(this, S).length
|
|
2916
2938
|
), n.PHP_SELF = t.pathname, n.REQUEST_URI.startsWith(n.SCRIPT_NAME) && (n.PATH_INFO = n.REQUEST_URI.substring(
|
|
2917
2939
|
n.SCRIPT_NAME.length
|
|
2918
2940
|
), n.PATH_INFO.includes("?") && (n.PATH_INFO = n.PATH_INFO.substring(
|
|
@@ -2924,7 +2946,7 @@ class PHPRequestHandler {
|
|
|
2924
2946
|
await this.instanceManager[Symbol.asyncDispose]();
|
|
2925
2947
|
}
|
|
2926
2948
|
}
|
|
2927
|
-
|
|
2949
|
+
S = new WeakMap(), M = new WeakMap(), U = new WeakMap(), L = new WeakMap(), I = new WeakMap(), E = new WeakMap(), A = new WeakMap(), k = new WeakMap(), B = new WeakMap(), P = new WeakSet(), /**
|
|
2928
2950
|
* Apply the rewrite rules to the original request URL.
|
|
2929
2951
|
*
|
|
2930
2952
|
* @param originalRequestUrl - The original request URL.
|
|
@@ -2959,7 +2981,7 @@ j = function(e) {
|
|
|
2959
2981
|
const s = e.slice(t.urlPrefix.length);
|
|
2960
2982
|
return joinPaths(t.fsPath, s);
|
|
2961
2983
|
}
|
|
2962
|
-
return joinPaths(u(this,
|
|
2984
|
+
return joinPaths(u(this, S), e);
|
|
2963
2985
|
}, /**
|
|
2964
2986
|
* Serves a static file from the PHP filesystem.
|
|
2965
2987
|
*
|
|
@@ -3015,7 +3037,7 @@ ie = function(e, t) {
|
|
|
3015
3037
|
toRelativeUrl(new URL(n.toString())),
|
|
3016
3038
|
u(this, E)
|
|
3017
3039
|
),
|
|
3018
|
-
protocol: u(this,
|
|
3040
|
+
protocol: u(this, M),
|
|
3019
3041
|
method: t.method || o,
|
|
3020
3042
|
$_SERVER: this.prepare_$_SERVER_superglobal(
|
|
3021
3043
|
s,
|
|
@@ -4040,13 +4062,20 @@ function portToStream(r) {
|
|
|
4040
4062
|
if (i)
|
|
4041
4063
|
switch (i.t) {
|
|
4042
4064
|
case "chunk":
|
|
4043
|
-
|
|
4065
|
+
try {
|
|
4066
|
+
e.enqueue(new Uint8Array(i.b));
|
|
4067
|
+
} catch {
|
|
4068
|
+
s();
|
|
4069
|
+
}
|
|
4044
4070
|
break;
|
|
4045
4071
|
case "close":
|
|
4046
|
-
e
|
|
4072
|
+
safeStreamClose(e), s();
|
|
4047
4073
|
break;
|
|
4048
4074
|
case "error":
|
|
4049
|
-
|
|
4075
|
+
safeStreamError(
|
|
4076
|
+
e,
|
|
4077
|
+
new Error(i.m || "Stream error")
|
|
4078
|
+
), s();
|
|
4050
4079
|
break;
|
|
4051
4080
|
}
|
|
4052
4081
|
}, s = () => {
|
|
@@ -4166,6 +4195,18 @@ function proxyClone(r) {
|
|
|
4166
4195
|
}
|
|
4167
4196
|
});
|
|
4168
4197
|
}
|
|
4198
|
+
function safeStreamError(r, e) {
|
|
4199
|
+
try {
|
|
4200
|
+
r.error(e);
|
|
4201
|
+
} catch {
|
|
4202
|
+
}
|
|
4203
|
+
}
|
|
4204
|
+
function safeStreamClose(r) {
|
|
4205
|
+
try {
|
|
4206
|
+
r.close();
|
|
4207
|
+
} catch {
|
|
4208
|
+
}
|
|
4209
|
+
}
|
|
4169
4210
|
const MAX_ADDRESSABLE_FILE_OFFSET = BigInt(Number.MAX_SAFE_INTEGER);
|
|
4170
4211
|
class IntervalNode {
|
|
4171
4212
|
constructor(e) {
|