@php-wasm/universal 1.2.2 → 1.2.3
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 +39 -8
- package/index.cjs.map +1 -1
- package/index.js +547 -253
- package/index.js.map +1 -1
- package/lib/error-reporting.d.ts +12 -0
- package/lib/index.d.ts +2 -0
- package/lib/php.d.ts +8 -0
- package/lib/rethrow-file-system-error.d.ts +2 -2
- package/lib/sandboxed-spawn-handler-factory.d.ts +12 -0
- package/lib/serialize-error.d.ts +17 -0
- package/package.json +7 -7
- package/__vite-browser-external-Dyvby5gX.cjs +0 -2
- package/__vite-browser-external-Dyvby5gX.cjs.map +0 -1
- package/__vite-browser-external-l0sNRNKZ.js +0 -2
- package/__vite-browser-external-l0sNRNKZ.js.map +0 -1
package/index.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
var
|
|
1
|
+
var q = (t) => {
|
|
2
2
|
throw TypeError(t);
|
|
3
3
|
};
|
|
4
|
-
var
|
|
5
|
-
var u = (t, e, r) => (
|
|
4
|
+
var N = (t, e, r) => e.has(t) || q("Cannot " + r);
|
|
5
|
+
var u = (t, e, r) => (N(t, e, "read from private field"), r ? r.call(t) : e.get(t)), _ = (t, e, r) => e.has(t) ? q("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r), f = (t, e, r, s) => (N(t, e, "write to private field"), s ? s.call(t, r) : e.set(t, r), r), m = (t, e, r) => (N(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, normalizePath, AcquireTimeoutError } from "@php-wasm/util";
|
|
9
9
|
import { parse, stringify } from "ini";
|
|
10
10
|
import { StreamedFile } from "@php-wasm/stream-compression";
|
|
11
|
+
class ErrnoError extends Error {
|
|
12
|
+
constructor(e, r, s) {
|
|
13
|
+
super(r, s), this.name = "ErrnoError", this.errno = e;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
11
16
|
const FileErrorCodes = {
|
|
12
17
|
0: "No error occurred. System call completed successfully.",
|
|
13
18
|
1: "Argument list too long.",
|
|
@@ -100,10 +105,14 @@ function rethrowFileSystemError(t = "") {
|
|
|
100
105
|
} catch (n) {
|
|
101
106
|
const i = typeof n == "object" ? n == null ? void 0 : n.errno : null;
|
|
102
107
|
if (i in FileErrorCodes) {
|
|
103
|
-
const o = FileErrorCodes[i], a = typeof s[1] == "string" ? s[1] : null,
|
|
104
|
-
throw new
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
const o = FileErrorCodes[i], a = typeof s[1] == "string" ? s[1] : null, l = a !== null ? t.replaceAll("{path}", a) : t;
|
|
109
|
+
throw new ErrnoError(
|
|
110
|
+
i,
|
|
111
|
+
`${l}: ${o}`,
|
|
112
|
+
{
|
|
113
|
+
cause: n
|
|
114
|
+
}
|
|
115
|
+
);
|
|
107
116
|
}
|
|
108
117
|
throw n;
|
|
109
118
|
}
|
|
@@ -184,9 +193,12 @@ class FSHelpers {
|
|
|
184
193
|
* @param options Options for the removal.
|
|
185
194
|
*/
|
|
186
195
|
static rmdir(e, r, s = { recursive: !0 }) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
196
|
+
const n = e.lookupPath(r, { follow: !1 });
|
|
197
|
+
if ((n == null ? void 0 : n.node.mount.mountpoint) === r)
|
|
198
|
+
throw new ErrnoError(10);
|
|
199
|
+
s != null && s.recursive && FSHelpers.listFiles(e, r).forEach((i) => {
|
|
200
|
+
const o = `${r}/${i}`;
|
|
201
|
+
FSHelpers.isDir(e, o) ? FSHelpers.rmdir(e, o, s) : FSHelpers.unlink(e, o);
|
|
190
202
|
}), e.getPath(e.lookupPath(r).node) === e.cwd() && e.chdir(joinPaths(e.cwd(), "..")), e.rmdir(r);
|
|
191
203
|
}
|
|
192
204
|
/**
|
|
@@ -311,8 +323,7 @@ class FSHelpers {
|
|
|
311
323
|
joinPaths(r, o),
|
|
312
324
|
joinPaths(s, o)
|
|
313
325
|
);
|
|
314
|
-
} else
|
|
315
|
-
e.writeFile(s, e.readFile(r));
|
|
326
|
+
} else e.isLink(n.mode) ? e.symlink(e.readlink(r), s) : e.writeFile(s, e.readFile(r));
|
|
316
327
|
}
|
|
317
328
|
}
|
|
318
329
|
FSHelpers.readFileAsText = rethrowFileSystemError('Could not read "{path}"')(
|
|
@@ -649,14 +660,14 @@ const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map(
|
|
|
649
660
|
let lastRuntimeId = 0;
|
|
650
661
|
async function loadPHPRuntime(t, ...e) {
|
|
651
662
|
const r = Object.assign({}, ...e), [s, n, i] = makePromise(), o = t.init(currentJsRuntime, {
|
|
652
|
-
onAbort(
|
|
653
|
-
i(
|
|
663
|
+
onAbort(l) {
|
|
664
|
+
i(l), logger.error(l);
|
|
654
665
|
},
|
|
655
666
|
ENV: {},
|
|
656
667
|
// Emscripten sometimes prepends a '/' to the path, which
|
|
657
668
|
// breaks vite dev mode. An identity `locateFile` function
|
|
658
669
|
// fixes it.
|
|
659
|
-
locateFile: (
|
|
670
|
+
locateFile: (l) => l,
|
|
660
671
|
...r,
|
|
661
672
|
noInitialRun: !0,
|
|
662
673
|
onRuntimeInitialized() {
|
|
@@ -665,8 +676,8 @@ async function loadPHPRuntime(t, ...e) {
|
|
|
665
676
|
});
|
|
666
677
|
await s;
|
|
667
678
|
const a = ++lastRuntimeId;
|
|
668
|
-
return o.FS, o.id = a, o.originalExit = o._exit, o._exit = function(
|
|
669
|
-
return o.outboundNetworkProxyServer && (o.outboundNetworkProxyServer.close(), o.outboundNetworkProxyServer.closeAllConnections()), loadedRuntimes.delete(a), o.originalExit(
|
|
679
|
+
return o.FS, o.id = a, o.originalExit = o._exit, o._exit = function(l) {
|
|
680
|
+
return o.outboundNetworkProxyServer && (o.outboundNetworkProxyServer.close(), o.outboundNetworkProxyServer.closeAllConnections()), loadedRuntimes.delete(a), o.originalExit(l);
|
|
670
681
|
}, o[RuntimeId] = a, loadedRuntimes.set(a, o), a;
|
|
671
682
|
}
|
|
672
683
|
function getLoadedRuntime(t) {
|
|
@@ -747,11 +758,9 @@ function improveWASMErrorReporting(t) {
|
|
|
747
758
|
(i = t.lastAsyncifyStackSource) == null ? void 0 : i.stack
|
|
748
759
|
);
|
|
749
760
|
if (e.hasListeners()) {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
});
|
|
754
|
-
throw e.dispatchEvent(c), o;
|
|
761
|
+
o.message = a;
|
|
762
|
+
const l = new ErrorEvent("error", { error: o });
|
|
763
|
+
throw e.dispatchEvent(l), o;
|
|
755
764
|
}
|
|
756
765
|
throw (!isExitCode(o) || o.status !== 0) && showCriticalErrorBox(a), o;
|
|
757
766
|
}
|
|
@@ -769,7 +778,7 @@ function clarifyErrorMessage(t, e) {
|
|
|
769
778
|
e || (r += `
|
|
770
779
|
|
|
771
780
|
This stack trace is lacking. For a better one initialize
|
|
772
|
-
the PHP runtime with
|
|
781
|
+
the PHP runtime with debug: true, e.g. loadNodeRuntime('8.1', { emscriptenOptions: { debug: true } }).
|
|
773
782
|
|
|
774
783
|
`);
|
|
775
784
|
const s = new Set(
|
|
@@ -787,7 +796,8 @@ the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
|
|
|
787
796
|
for (const i of s)
|
|
788
797
|
r += ` * ${i}
|
|
789
798
|
`;
|
|
790
|
-
return r
|
|
799
|
+
return r += `Original error message: ${t.message}
|
|
800
|
+
`, r;
|
|
791
801
|
}
|
|
792
802
|
return t.message;
|
|
793
803
|
}
|
|
@@ -852,7 +862,7 @@ class PHPExecutionFailureError extends Error {
|
|
|
852
862
|
}
|
|
853
863
|
}
|
|
854
864
|
const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php";
|
|
855
|
-
var
|
|
865
|
+
var k, E, x, g, v, T, d, z, W, B, $, V, G, J, Y, K, L, X, U, O;
|
|
856
866
|
class PHP {
|
|
857
867
|
/**
|
|
858
868
|
* Initializes a PHP runtime.
|
|
@@ -862,14 +872,14 @@ class PHP {
|
|
|
862
872
|
* @param requestHandlerOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
863
873
|
*/
|
|
864
874
|
constructor(t) {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
this.semaphore = new Semaphore({ concurrency: 1 }), t !== void 0 && this.initializeRuntime(t);
|
|
875
|
+
_(this, d);
|
|
876
|
+
_(this, k);
|
|
877
|
+
_(this, E);
|
|
878
|
+
_(this, x);
|
|
879
|
+
_(this, g);
|
|
880
|
+
_(this, v);
|
|
881
|
+
_(this, T);
|
|
882
|
+
f(this, E, !1), f(this, x, null), f(this, g, /* @__PURE__ */ new Map()), f(this, v, []), f(this, T, {}), this.cliCalled = !1, this.runStreamCalled = !1, this.semaphore = new Semaphore({ concurrency: 1 }), t !== void 0 && this.initializeRuntime(t);
|
|
873
883
|
}
|
|
874
884
|
/**
|
|
875
885
|
* Adds an event listener for a PHP event.
|
|
@@ -877,7 +887,7 @@ class PHP {
|
|
|
877
887
|
* @param listener - The listener function to be called when the event is triggered.
|
|
878
888
|
*/
|
|
879
889
|
addEventListener(t, e) {
|
|
880
|
-
u(this,
|
|
890
|
+
u(this, g).has(t) || u(this, g).set(t, /* @__PURE__ */ new Set()), u(this, g).get(t).add(e);
|
|
881
891
|
}
|
|
882
892
|
/**
|
|
883
893
|
* Removes an event listener for a PHP event.
|
|
@@ -886,10 +896,10 @@ class PHP {
|
|
|
886
896
|
*/
|
|
887
897
|
removeEventListener(t, e) {
|
|
888
898
|
var r;
|
|
889
|
-
(r = u(this,
|
|
899
|
+
(r = u(this, g).get(t)) == null || r.delete(e);
|
|
890
900
|
}
|
|
891
901
|
dispatchEvent(t) {
|
|
892
|
-
const e = u(this,
|
|
902
|
+
const e = u(this, g).get(t.type);
|
|
893
903
|
if (e)
|
|
894
904
|
for (const r of e)
|
|
895
905
|
r(t);
|
|
@@ -934,8 +944,8 @@ class PHP {
|
|
|
934
944
|
* @param listener Callback function to handle the message.
|
|
935
945
|
*/
|
|
936
946
|
onMessage(t) {
|
|
937
|
-
return u(this,
|
|
938
|
-
|
|
947
|
+
return u(this, v).push(t), async () => {
|
|
948
|
+
f(this, v, u(this, v).filter(
|
|
939
949
|
(e) => e !== t
|
|
940
950
|
));
|
|
941
951
|
};
|
|
@@ -1011,13 +1021,13 @@ class PHP {
|
|
|
1011
1021
|
}
|
|
1012
1022
|
`
|
|
1013
1023
|
), e.onMessage = async (r) => {
|
|
1014
|
-
for (const s of u(this,
|
|
1024
|
+
for (const s of u(this, v)) {
|
|
1015
1025
|
const n = await s(r);
|
|
1016
1026
|
if (n)
|
|
1017
1027
|
return n;
|
|
1018
1028
|
}
|
|
1019
1029
|
return "";
|
|
1020
|
-
},
|
|
1030
|
+
}, f(this, x, improveWASMErrorReporting(e)), this.dispatchEvent({
|
|
1021
1031
|
type: "runtime.initialized"
|
|
1022
1032
|
});
|
|
1023
1033
|
}
|
|
@@ -1032,7 +1042,7 @@ class PHP {
|
|
|
1032
1042
|
throw new Error(
|
|
1033
1043
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
1034
1044
|
);
|
|
1035
|
-
|
|
1045
|
+
f(this, k, t);
|
|
1036
1046
|
}
|
|
1037
1047
|
/**
|
|
1038
1048
|
* Changes the current working directory in the PHP filesystem.
|
|
@@ -1045,6 +1055,14 @@ class PHP {
|
|
|
1045
1055
|
chdir(t) {
|
|
1046
1056
|
this[__private__dont__use].FS.chdir(t);
|
|
1047
1057
|
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Changes the permissions of a file or directory.
|
|
1060
|
+
* @param path - The path to the file or directory.
|
|
1061
|
+
* @param mode - The new permissions.
|
|
1062
|
+
*/
|
|
1063
|
+
chmod(t, e) {
|
|
1064
|
+
this[__private__dont__use].FS.chmod(t, e);
|
|
1065
|
+
}
|
|
1048
1066
|
/**
|
|
1049
1067
|
* Do not use. Use new PHPRequestHandler() instead.
|
|
1050
1068
|
* @deprecated
|
|
@@ -1132,24 +1150,18 @@ class PHP {
|
|
|
1132
1150
|
const e = await this.runStream(t), r = await PHPResponse.fromStreamedResponse(
|
|
1133
1151
|
e
|
|
1134
1152
|
);
|
|
1135
|
-
if (r.exitCode !== 0)
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1153
|
+
if (r.exitCode !== 0)
|
|
1154
|
+
throw new PHPExecutionFailureError(
|
|
1155
|
+
`PHP.run() failed with exit code ${r.exitCode}.
|
|
1156
|
+
|
|
1157
|
+
=== Stdout ===
|
|
1158
|
+
${r.text}
|
|
1139
1159
|
|
|
1140
|
-
|
|
1160
|
+
=== Stderr ===
|
|
1161
|
+
${r.errors}`,
|
|
1141
1162
|
r,
|
|
1142
1163
|
"request"
|
|
1143
1164
|
);
|
|
1144
|
-
throw logger.error(s), this.dispatchEvent({
|
|
1145
|
-
type: "request.error",
|
|
1146
|
-
error: new Error(
|
|
1147
|
-
"PHP.run() failed with exit code " + r.exitCode
|
|
1148
|
-
),
|
|
1149
|
-
// Distinguish between PHP request and PHP-wasm errors
|
|
1150
|
-
source: "request"
|
|
1151
|
-
}), s;
|
|
1152
|
-
}
|
|
1153
1165
|
return r;
|
|
1154
1166
|
}
|
|
1155
1167
|
/**
|
|
@@ -1244,30 +1256,35 @@ class PHP {
|
|
|
1244
1256
|
* @returns A StreamedPHPResponse object.
|
|
1245
1257
|
*/
|
|
1246
1258
|
async runStream(t) {
|
|
1259
|
+
if (this.cliCalled)
|
|
1260
|
+
throw new Error(
|
|
1261
|
+
"php.runStream() can only be called if php.cli() was not called before. The two methods set a conflicting C-level global state."
|
|
1262
|
+
);
|
|
1263
|
+
this.runStreamCalled = !0;
|
|
1247
1264
|
const e = await this.semaphore.acquire();
|
|
1248
1265
|
let r;
|
|
1249
|
-
const s = m(this,
|
|
1250
|
-
if (u(this,
|
|
1266
|
+
const s = m(this, d, O).call(this, async () => {
|
|
1267
|
+
if (u(this, E) || (await m(this, d, W).call(this), f(this, E, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
|
|
1251
1268
|
throw new Error(
|
|
1252
1269
|
`The script path "${t.scriptPath}" does not exist.`
|
|
1253
1270
|
);
|
|
1254
|
-
m(this,
|
|
1255
|
-
const n = normalizeHeaders(t.headers || {}), i = n.host || "example.com:443", o = m(this,
|
|
1256
|
-
if (m(this,
|
|
1257
|
-
this.writeFile("/internal/eval.php", t.code), m(this,
|
|
1271
|
+
m(this, d, B).call(this, t.relativeUri || ""), m(this, d, J).call(this, t.method || "GET");
|
|
1272
|
+
const n = normalizeHeaders(t.headers || {}), i = n.host || "example.com:443", o = m(this, d, G).call(this, i, t.protocol || "http");
|
|
1273
|
+
if (m(this, d, $).call(this, i), m(this, d, V).call(this, o), m(this, d, Y).call(this, n), t.body && (r = m(this, d, K).call(this, t.body)), typeof t.code == "string")
|
|
1274
|
+
this.writeFile("/internal/eval.php", t.code), m(this, d, L).call(this, "/internal/eval.php");
|
|
1258
1275
|
else if (typeof t.scriptPath == "string")
|
|
1259
|
-
m(this,
|
|
1276
|
+
m(this, d, L).call(this, t.scriptPath || "");
|
|
1260
1277
|
else
|
|
1261
1278
|
throw new TypeError(
|
|
1262
1279
|
"The request object must have either a `code` or a `scriptPath` property."
|
|
1263
1280
|
);
|
|
1264
|
-
const a = m(this,
|
|
1265
|
-
for (const
|
|
1266
|
-
m(this,
|
|
1267
|
-
const
|
|
1268
|
-
for (const
|
|
1269
|
-
m(this,
|
|
1270
|
-
return
|
|
1281
|
+
const a = m(this, d, z).call(this, t.$_SERVER, n, o);
|
|
1282
|
+
for (const c in a)
|
|
1283
|
+
m(this, d, X).call(this, c, a[c]);
|
|
1284
|
+
const l = t.env || {};
|
|
1285
|
+
for (const c in l)
|
|
1286
|
+
m(this, d, U).call(this, c, l[c]);
|
|
1287
|
+
return await this[__private__dont__use].ccall(
|
|
1271
1288
|
"wasm_sapi_handle_request",
|
|
1272
1289
|
NUMBER,
|
|
1273
1290
|
[],
|
|
@@ -1276,12 +1293,12 @@ class PHP {
|
|
|
1276
1293
|
);
|
|
1277
1294
|
});
|
|
1278
1295
|
return await s.catch((n) => {
|
|
1279
|
-
this.dispatchEvent({
|
|
1296
|
+
throw this.dispatchEvent({
|
|
1280
1297
|
type: "request.error",
|
|
1281
1298
|
error: n,
|
|
1282
1299
|
// Distinguish between PHP request and PHP-wasm errors
|
|
1283
1300
|
source: n.source ?? "php-wasm"
|
|
1284
|
-
});
|
|
1301
|
+
}), n;
|
|
1285
1302
|
}).finally(() => {
|
|
1286
1303
|
r && this[__private__dont__use].free(r);
|
|
1287
1304
|
}).finally(() => {
|
|
@@ -1472,13 +1489,13 @@ class PHP {
|
|
|
1472
1489
|
*/
|
|
1473
1490
|
async hotSwapPHPRuntime(t, e) {
|
|
1474
1491
|
const r = this[__private__dont__use].FS, s = [];
|
|
1475
|
-
for (const [n, i] of Object.entries(u(this,
|
|
1492
|
+
for (const [n, i] of Object.entries(u(this, T)))
|
|
1476
1493
|
s.push({ mountHandler: i.mountHandler, vfsPath: n }), await i.unmount();
|
|
1477
1494
|
try {
|
|
1478
1495
|
this.exit();
|
|
1479
1496
|
} catch {
|
|
1480
1497
|
}
|
|
1481
|
-
this.initializeRuntime(t), u(this,
|
|
1498
|
+
this.initializeRuntime(t), u(this, k) && this.setSapiName(u(this, k)), copyFS(r, this[__private__dont__use].FS, "/internal"), e && copyFS(r, this[__private__dont__use].FS, e);
|
|
1482
1499
|
for (const { mountHandler: n, vfsPath: i } of s)
|
|
1483
1500
|
this.mkdir(i), await this.mount(i, n);
|
|
1484
1501
|
}
|
|
@@ -1497,10 +1514,10 @@ class PHP {
|
|
|
1497
1514
|
), s = {
|
|
1498
1515
|
mountHandler: e,
|
|
1499
1516
|
unmount: async () => {
|
|
1500
|
-
await r(), delete u(this,
|
|
1517
|
+
await r(), delete u(this, T)[t];
|
|
1501
1518
|
}
|
|
1502
1519
|
};
|
|
1503
|
-
return u(this,
|
|
1520
|
+
return u(this, T)[t] = s, () => {
|
|
1504
1521
|
s.unmount();
|
|
1505
1522
|
};
|
|
1506
1523
|
}
|
|
@@ -1518,9 +1535,18 @@ class PHP {
|
|
|
1518
1535
|
* @returns The exit code of the CLI session.
|
|
1519
1536
|
*/
|
|
1520
1537
|
async cli(t, e = {}) {
|
|
1538
|
+
if (this.cliCalled)
|
|
1539
|
+
throw new Error(
|
|
1540
|
+
"php.cli() can only be called once. The method sets a C-level global state that does not allow repeated calls."
|
|
1541
|
+
);
|
|
1542
|
+
if (this.runStreamCalled)
|
|
1543
|
+
throw new Error(
|
|
1544
|
+
"php.cli() can only be called if php.runStream() was not called before. The two methods set a conflicting C-level global state."
|
|
1545
|
+
);
|
|
1546
|
+
this.cliCalled = !0;
|
|
1521
1547
|
const r = await this.semaphore.acquire(), s = e.env || {};
|
|
1522
1548
|
for (const [n, i] of Object.entries(s))
|
|
1523
|
-
m(this,
|
|
1549
|
+
m(this, d, U).call(this, n, i);
|
|
1524
1550
|
t = [t[0], "-c", PHP_INI_PATH, ...t.slice(1)];
|
|
1525
1551
|
for (const n of t)
|
|
1526
1552
|
this[__private__dont__use].ccall(
|
|
@@ -1529,15 +1555,9 @@ class PHP {
|
|
|
1529
1555
|
[STRING],
|
|
1530
1556
|
[n]
|
|
1531
1557
|
);
|
|
1532
|
-
return await m(this,
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
[],
|
|
1536
|
-
[],
|
|
1537
|
-
{
|
|
1538
|
-
async: !0
|
|
1539
|
-
}
|
|
1540
|
-
)).then((n) => (n.exitCode.finally(r), n));
|
|
1558
|
+
return await m(this, d, O).call(this, () => this[__private__dont__use].ccall("run_cli", null, [], [], {
|
|
1559
|
+
async: !0
|
|
1560
|
+
})).then((n) => (n.exitCode.finally(r), n));
|
|
1541
1561
|
}
|
|
1542
1562
|
setSkipShebang(t) {
|
|
1543
1563
|
this[__private__dont__use].ccall(
|
|
@@ -1555,13 +1575,13 @@ class PHP {
|
|
|
1555
1575
|
this[__private__dont__use]._exit(t);
|
|
1556
1576
|
} catch {
|
|
1557
1577
|
}
|
|
1558
|
-
|
|
1578
|
+
f(this, E, !1), f(this, x, null), this[__private__dont__use] && (delete this[__private__dont__use].onMessage, delete this[__private__dont__use]);
|
|
1559
1579
|
}
|
|
1560
1580
|
[Symbol.dispose]() {
|
|
1561
|
-
u(this,
|
|
1581
|
+
u(this, E) && this.exit(0);
|
|
1562
1582
|
}
|
|
1563
1583
|
}
|
|
1564
|
-
|
|
1584
|
+
k = new WeakMap(), E = new WeakMap(), x = new WeakMap(), g = new WeakMap(), v = new WeakMap(), T = new WeakMap(), d = new WeakSet(), /**
|
|
1565
1585
|
* Prepares the $_SERVER entries for the PHP runtime.
|
|
1566
1586
|
*
|
|
1567
1587
|
* @param defaults Default entries to include in $_SERVER.
|
|
@@ -1570,7 +1590,7 @@ A = new WeakMap(), P = new WeakMap(), T = new WeakMap(), E = new WeakMap(), F =
|
|
|
1570
1590
|
* was provided.
|
|
1571
1591
|
* @returns Computed $_SERVER entries.
|
|
1572
1592
|
*/
|
|
1573
|
-
|
|
1593
|
+
z = function(t, e, r) {
|
|
1574
1594
|
const s = {
|
|
1575
1595
|
...t || {}
|
|
1576
1596
|
};
|
|
@@ -1580,11 +1600,11 @@ B = function(t, e, r) {
|
|
|
1580
1600
|
["content-type", "content-length"].includes(n.toLowerCase()) && (i = ""), s[`${i}${n.toUpperCase().replace(/-/g, "_")}`] = e[n];
|
|
1581
1601
|
}
|
|
1582
1602
|
return s;
|
|
1583
|
-
},
|
|
1584
|
-
|
|
1585
|
-
|
|
1603
|
+
}, W = function() {
|
|
1604
|
+
return this[__private__dont__use].ccall("php_wasm_init", null, [], [], {
|
|
1605
|
+
isAsync: !0
|
|
1586
1606
|
});
|
|
1587
|
-
},
|
|
1607
|
+
}, B = function(t) {
|
|
1588
1608
|
this[__private__dont__use].ccall(
|
|
1589
1609
|
"wasm_set_request_uri",
|
|
1590
1610
|
null,
|
|
@@ -1598,21 +1618,21 @@ B = function(t, e, r) {
|
|
|
1598
1618
|
[STRING],
|
|
1599
1619
|
[e]
|
|
1600
1620
|
);
|
|
1601
|
-
},
|
|
1621
|
+
}, $ = function(t) {
|
|
1602
1622
|
this[__private__dont__use].ccall(
|
|
1603
1623
|
"wasm_set_request_host",
|
|
1604
1624
|
null,
|
|
1605
1625
|
[STRING],
|
|
1606
1626
|
[t]
|
|
1607
1627
|
);
|
|
1608
|
-
},
|
|
1628
|
+
}, V = function(t) {
|
|
1609
1629
|
this[__private__dont__use].ccall(
|
|
1610
1630
|
"wasm_set_request_port",
|
|
1611
1631
|
null,
|
|
1612
1632
|
[NUMBER],
|
|
1613
1633
|
[t]
|
|
1614
1634
|
);
|
|
1615
|
-
},
|
|
1635
|
+
}, G = function(t, e) {
|
|
1616
1636
|
let r;
|
|
1617
1637
|
try {
|
|
1618
1638
|
r = parseInt(new URL(t).port, 10);
|
|
@@ -1626,7 +1646,7 @@ B = function(t, e, r) {
|
|
|
1626
1646
|
[STRING],
|
|
1627
1647
|
[t]
|
|
1628
1648
|
);
|
|
1629
|
-
},
|
|
1649
|
+
}, Y = function(t) {
|
|
1630
1650
|
t.cookie && this[__private__dont__use].ccall(
|
|
1631
1651
|
"wasm_set_cookies",
|
|
1632
1652
|
null,
|
|
@@ -1643,7 +1663,7 @@ B = function(t, e, r) {
|
|
|
1643
1663
|
[NUMBER],
|
|
1644
1664
|
[parseInt(t["content-length"], 10)]
|
|
1645
1665
|
);
|
|
1646
|
-
},
|
|
1666
|
+
}, K = function(t) {
|
|
1647
1667
|
let e, r;
|
|
1648
1668
|
typeof t == "string" ? (logger.warn(
|
|
1649
1669
|
"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"
|
|
@@ -1666,82 +1686,75 @@ B = function(t, e, r) {
|
|
|
1666
1686
|
[NUMBER],
|
|
1667
1687
|
[r]
|
|
1668
1688
|
), s;
|
|
1669
|
-
},
|
|
1689
|
+
}, L = function(t) {
|
|
1670
1690
|
this[__private__dont__use].ccall(
|
|
1671
1691
|
"wasm_set_path_translated",
|
|
1672
1692
|
null,
|
|
1673
1693
|
[STRING],
|
|
1674
1694
|
[t]
|
|
1675
1695
|
);
|
|
1676
|
-
},
|
|
1696
|
+
}, X = function(t, e) {
|
|
1677
1697
|
this[__private__dont__use].ccall(
|
|
1678
1698
|
"wasm_add_SERVER_entry",
|
|
1679
1699
|
null,
|
|
1680
1700
|
[STRING, STRING],
|
|
1681
1701
|
[t, e]
|
|
1682
1702
|
);
|
|
1683
|
-
},
|
|
1703
|
+
}, U = function(t, e) {
|
|
1684
1704
|
this[__private__dont__use].ccall(
|
|
1685
1705
|
"wasm_add_ENV_entry",
|
|
1686
1706
|
null,
|
|
1687
1707
|
[STRING, STRING],
|
|
1688
1708
|
[t, e]
|
|
1689
1709
|
);
|
|
1690
|
-
},
|
|
1710
|
+
}, O = async function(t) {
|
|
1691
1711
|
const e = this[__private__dont__use], r = await createInvertedReadableStream();
|
|
1692
|
-
e.onHeaders = (
|
|
1693
|
-
a || s || r.controller.enqueue(
|
|
1712
|
+
e.onHeaders = (h) => {
|
|
1713
|
+
a || s || r.controller.enqueue(h.slice());
|
|
1694
1714
|
};
|
|
1695
1715
|
let s = !1;
|
|
1696
1716
|
const n = () => {
|
|
1697
1717
|
s || (s = !0, r.controller.close());
|
|
1698
1718
|
}, i = await createInvertedReadableStream();
|
|
1699
|
-
e.onStdout = (
|
|
1700
|
-
n(), !a && i.controller.enqueue(
|
|
1719
|
+
e.onStdout = (h) => {
|
|
1720
|
+
n(), !a && i.controller.enqueue(h.slice());
|
|
1701
1721
|
};
|
|
1702
1722
|
const o = await createInvertedReadableStream();
|
|
1703
|
-
e.onStderr = (
|
|
1704
|
-
a || o.controller.enqueue(
|
|
1723
|
+
e.onStderr = (h) => {
|
|
1724
|
+
a || o.controller.enqueue(h.slice());
|
|
1705
1725
|
};
|
|
1706
|
-
let a = !1,
|
|
1707
|
-
const
|
|
1708
|
-
var
|
|
1726
|
+
let a = !1, l;
|
|
1727
|
+
const p = (async () => {
|
|
1728
|
+
var h;
|
|
1709
1729
|
try {
|
|
1710
1730
|
return await Promise.race([
|
|
1711
1731
|
t(),
|
|
1712
|
-
new Promise((
|
|
1713
|
-
var
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
else {
|
|
1718
|
-
const U = new Error("Rethrown");
|
|
1719
|
-
U.cause = v.error, U.betterMessage = v.message, w(U);
|
|
1720
|
-
}
|
|
1721
|
-
}, (k = u(this, T)) == null || k.addEventListener(
|
|
1732
|
+
new Promise((w, b) => {
|
|
1733
|
+
var j;
|
|
1734
|
+
l = (D) => {
|
|
1735
|
+
isExitCode(D.error) || b(D.error);
|
|
1736
|
+
}, (j = u(this, x)) == null || j.addEventListener(
|
|
1722
1737
|
"error",
|
|
1723
|
-
|
|
1738
|
+
l,
|
|
1724
1739
|
{ once: !0 }
|
|
1725
1740
|
);
|
|
1726
1741
|
})
|
|
1727
1742
|
]);
|
|
1728
|
-
} catch (
|
|
1729
|
-
if (isExitCode(
|
|
1730
|
-
return
|
|
1731
|
-
i.controller.error(
|
|
1732
|
-
for (const
|
|
1733
|
-
typeof this[
|
|
1743
|
+
} catch (y) {
|
|
1744
|
+
if (isExitCode(y))
|
|
1745
|
+
return y.status;
|
|
1746
|
+
i.controller.error(y), o.controller.error(y), r.controller.error(y), a = !0;
|
|
1747
|
+
for (const w in this)
|
|
1748
|
+
typeof this[w] == "function" && (this[w] = () => {
|
|
1734
1749
|
throw new Error(
|
|
1735
1750
|
"PHP runtime has crashed – see the earlier error for details."
|
|
1736
1751
|
);
|
|
1737
1752
|
});
|
|
1738
|
-
this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
|
|
1739
|
-
const _ = f, w = "betterMessage" in _ ? _.betterMessage : _.message, k = new Error(w);
|
|
1740
|
-
throw k.cause = _, logger.error(k), k;
|
|
1753
|
+
throw this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify(), y;
|
|
1741
1754
|
} finally {
|
|
1742
|
-
a || (i.controller.close(), o.controller.close(), n(), a = !0), (
|
|
1755
|
+
a || (i.controller.close(), o.controller.close(), n(), a = !0), (h = u(this, x)) == null || h.removeEventListener(
|
|
1743
1756
|
"error",
|
|
1744
|
-
|
|
1757
|
+
l
|
|
1745
1758
|
);
|
|
1746
1759
|
}
|
|
1747
1760
|
})();
|
|
@@ -1749,7 +1762,7 @@ B = function(t, e, r) {
|
|
|
1749
1762
|
r.stream,
|
|
1750
1763
|
i.stream,
|
|
1751
1764
|
o.stream,
|
|
1752
|
-
|
|
1765
|
+
p
|
|
1753
1766
|
);
|
|
1754
1767
|
};
|
|
1755
1768
|
function normalizeHeaders(t) {
|
|
@@ -1817,6 +1830,58 @@ async function withPHPIniValues(t, e, r) {
|
|
|
1817
1830
|
await t.writeFile(PHP_INI_PATH, s);
|
|
1818
1831
|
}
|
|
1819
1832
|
}
|
|
1833
|
+
async function printDebugDetails(t, e) {
|
|
1834
|
+
e && printResponseDebugDetails(
|
|
1835
|
+
await PHPResponse.fromStreamedResponse(e)
|
|
1836
|
+
), await prettyPrintFullStackTrace(t);
|
|
1837
|
+
}
|
|
1838
|
+
async function prettyPrintFullStackTrace(t) {
|
|
1839
|
+
let e = t, r = !0;
|
|
1840
|
+
for (; e; )
|
|
1841
|
+
r || process.stderr.write(`
|
|
1842
|
+
Caused by:
|
|
1843
|
+
|
|
1844
|
+
`), process.stderr.write(e.originalErrorClassName ?? e.name), process.stderr.write(": " + e.message + `
|
|
1845
|
+
`), process.stderr.write(
|
|
1846
|
+
(e.stack + "").split(`
|
|
1847
|
+
`).slice(1).join(`
|
|
1848
|
+
`)
|
|
1849
|
+
), process.stderr.write(`
|
|
1850
|
+
`), e.response && printResponseDebugDetails(e.response), e.phpLogs && (process.stderr.write(`
|
|
1851
|
+
|
|
1852
|
+
==== PHP error log ====
|
|
1853
|
+
|
|
1854
|
+
`), process.stderr.write(e.phpLogs)), e = e.cause, r = !1;
|
|
1855
|
+
process.stderr.write(`
|
|
1856
|
+
`);
|
|
1857
|
+
}
|
|
1858
|
+
function printResponseDebugDetails(t) {
|
|
1859
|
+
process.stderr.write(
|
|
1860
|
+
`
|
|
1861
|
+
exitCode=${t.exitCode} httpStatusCode=${t.httpStatusCode} `
|
|
1862
|
+
);
|
|
1863
|
+
const e = t.headers && Object.keys(t.headers).length > 0;
|
|
1864
|
+
e || process.stderr.write("responseHeaders=(empty) "), t.text || process.stderr.write("stdout=(empty) "), t.errors || process.stderr.write("stderr=(empty) "), process.stderr.write(`
|
|
1865
|
+
`), e && process.stderr.write(
|
|
1866
|
+
`
|
|
1867
|
+
==== PHP response headers ====
|
|
1868
|
+
|
|
1869
|
+
${JSON.stringify(
|
|
1870
|
+
t.headers,
|
|
1871
|
+
null,
|
|
1872
|
+
2
|
|
1873
|
+
)}
|
|
1874
|
+
|
|
1875
|
+
`
|
|
1876
|
+
), t.text && (process.stderr.write(`
|
|
1877
|
+
==== PHP stdout ====
|
|
1878
|
+
|
|
1879
|
+
`), process.stderr.write(t.text)), t.errors && (process.stderr.write(`
|
|
1880
|
+
==== PHP stderr ====
|
|
1881
|
+
|
|
1882
|
+
`), process.stderr.write(t.errors)), process.stderr.write(`
|
|
1883
|
+
`);
|
|
1884
|
+
}
|
|
1820
1885
|
class HttpCookieStore {
|
|
1821
1886
|
constructor() {
|
|
1822
1887
|
this.cookies = {};
|
|
@@ -1860,16 +1925,16 @@ async function* iteratePhpFiles(t, e, {
|
|
|
1860
1925
|
if (!o)
|
|
1861
1926
|
return;
|
|
1862
1927
|
const a = await t.listFiles(o);
|
|
1863
|
-
for (const
|
|
1864
|
-
const
|
|
1865
|
-
if (n.includes(
|
|
1928
|
+
for (const l of a) {
|
|
1929
|
+
const c = `${o}/${l}`;
|
|
1930
|
+
if (n.includes(c.substring(e.length + 1)))
|
|
1866
1931
|
continue;
|
|
1867
|
-
await t.isDir(
|
|
1868
|
-
streamReadFileFromPHP(t,
|
|
1932
|
+
await t.isDir(c) ? i.push(c) : yield new StreamedFile(
|
|
1933
|
+
streamReadFileFromPHP(t, c),
|
|
1869
1934
|
r ? joinPaths(
|
|
1870
1935
|
s || "",
|
|
1871
|
-
|
|
1872
|
-
) :
|
|
1936
|
+
c.substring(e.length + 1)
|
|
1937
|
+
) : c
|
|
1873
1938
|
);
|
|
1874
1939
|
}
|
|
1875
1940
|
}
|
|
@@ -1940,7 +2005,7 @@ class PHPProcessManager {
|
|
|
1940
2005
|
* and the waiting timeout is exceeded.
|
|
1941
2006
|
*/
|
|
1942
2007
|
async acquirePHPInstance({
|
|
1943
|
-
considerPrimary: e = !
|
|
2008
|
+
considerPrimary: e = !1
|
|
1944
2009
|
} = {}) {
|
|
1945
2010
|
if (this.primaryPhp || await this.getPrimaryPhp(), this.primaryIdle && e)
|
|
1946
2011
|
return this.primaryIdle = !1, {
|
|
@@ -1959,7 +2024,7 @@ class PHPProcessManager {
|
|
|
1959
2024
|
* for PHP to spawn.
|
|
1960
2025
|
*/
|
|
1961
2026
|
spawn(e) {
|
|
1962
|
-
if (e.isPrimary && this.
|
|
2027
|
+
if (e.isPrimary && this.allInstances.length > 0)
|
|
1963
2028
|
throw new Error(
|
|
1964
2029
|
"Requested spawning a primary PHP instance when another primary instance already started spawning."
|
|
1965
2030
|
);
|
|
@@ -2030,22 +2095,22 @@ function ensurePathPrefix(t, e) {
|
|
|
2030
2095
|
}
|
|
2031
2096
|
async function encodeAsMultipart(t) {
|
|
2032
2097
|
const e = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${e}`, s = new TextEncoder(), n = [];
|
|
2033
|
-
for (const [
|
|
2098
|
+
for (const [l, c] of Object.entries(t))
|
|
2034
2099
|
n.push(`--${e}\r
|
|
2035
|
-
`), n.push(`Content-Disposition: form-data; name="${
|
|
2036
|
-
`),
|
|
2100
|
+
`), n.push(`Content-Disposition: form-data; name="${l}"`), c instanceof File && n.push(`; filename="${c.name}"`), n.push(`\r
|
|
2101
|
+
`), c instanceof File && (n.push("Content-Type: application/octet-stream"), n.push(`\r
|
|
2037
2102
|
`)), n.push(`\r
|
|
2038
|
-
`),
|
|
2103
|
+
`), c instanceof File ? n.push(await fileToUint8Array(c)) : n.push(c), n.push(`\r
|
|
2039
2104
|
`);
|
|
2040
2105
|
n.push(`--${e}--\r
|
|
2041
2106
|
`);
|
|
2042
|
-
const i = n.reduce((
|
|
2107
|
+
const i = n.reduce((l, c) => l + c.length, 0), o = new Uint8Array(i);
|
|
2043
2108
|
let a = 0;
|
|
2044
|
-
for (const
|
|
2109
|
+
for (const l of n)
|
|
2045
2110
|
o.set(
|
|
2046
|
-
typeof
|
|
2111
|
+
typeof l == "string" ? s.encode(l) : l,
|
|
2047
2112
|
a
|
|
2048
|
-
), a +=
|
|
2113
|
+
), a += l.length;
|
|
2049
2114
|
return { bytes: o, contentType: r };
|
|
2050
2115
|
}
|
|
2051
2116
|
function fileToUint8Array(t) {
|
|
@@ -2147,7 +2212,7 @@ const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "app
|
|
|
2147
2212
|
xspf,
|
|
2148
2213
|
zip
|
|
2149
2214
|
};
|
|
2150
|
-
var S, C,
|
|
2215
|
+
var S, C, A, F, I, P, M, R, H, Q, Z, ee;
|
|
2151
2216
|
class PHPRequestHandler {
|
|
2152
2217
|
/**
|
|
2153
2218
|
* The request handler needs to decide whether to serve a static asset or
|
|
@@ -2161,15 +2226,15 @@ class PHPRequestHandler {
|
|
|
2161
2226
|
* @param config - Request Handler configuration.
|
|
2162
2227
|
*/
|
|
2163
2228
|
constructor(e) {
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2229
|
+
_(this, H);
|
|
2230
|
+
_(this, S);
|
|
2231
|
+
_(this, C);
|
|
2232
|
+
_(this, A);
|
|
2233
|
+
_(this, F);
|
|
2234
|
+
_(this, I);
|
|
2235
|
+
_(this, P);
|
|
2236
|
+
_(this, M);
|
|
2237
|
+
_(this, R);
|
|
2173
2238
|
const {
|
|
2174
2239
|
documentRoot: r = "/www/",
|
|
2175
2240
|
absoluteUrl: s = typeof location == "object" ? location.href : DEFAULT_BASE_URL,
|
|
@@ -2177,25 +2242,25 @@ class PHPRequestHandler {
|
|
|
2177
2242
|
getFileNotFoundAction: i = () => ({ type: "404" })
|
|
2178
2243
|
} = e;
|
|
2179
2244
|
"processManager" in e ? this.processManager = e.processManager : this.processManager = new PHPProcessManager({
|
|
2180
|
-
phpFactory: async (
|
|
2181
|
-
const
|
|
2182
|
-
...
|
|
2245
|
+
phpFactory: async (l) => {
|
|
2246
|
+
const c = await e.phpFactory({
|
|
2247
|
+
...l,
|
|
2183
2248
|
requestHandler: this
|
|
2184
2249
|
});
|
|
2185
|
-
return
|
|
2250
|
+
return c.isDir(r) || c.mkdir(r), c.chdir(r), c.requestHandler = this, c;
|
|
2186
2251
|
},
|
|
2187
2252
|
maxPhpInstances: e.maxPhpInstances
|
|
2188
|
-
}),
|
|
2253
|
+
}), f(this, R, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), f(this, S, r);
|
|
2189
2254
|
const o = new URL(s);
|
|
2190
|
-
|
|
2191
|
-
const a = u(this,
|
|
2192
|
-
|
|
2193
|
-
u(this,
|
|
2194
|
-
a ? `:${u(this,
|
|
2195
|
-
].join("")),
|
|
2255
|
+
f(this, A, o.hostname), f(this, F, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), f(this, C, (o.protocol || "").replace(":", ""));
|
|
2256
|
+
const a = u(this, F) !== 443 && u(this, F) !== 80;
|
|
2257
|
+
f(this, I, [
|
|
2258
|
+
u(this, A),
|
|
2259
|
+
a ? `:${u(this, F)}` : ""
|
|
2260
|
+
].join("")), f(this, P, o.pathname.replace(/\/+$/, "")), f(this, M, [
|
|
2196
2261
|
`${u(this, C)}://`,
|
|
2197
2262
|
u(this, I),
|
|
2198
|
-
u(this,
|
|
2263
|
+
u(this, P)
|
|
2199
2264
|
].join("")), this.rewriteRules = n, this.getFileNotFoundAction = i;
|
|
2200
2265
|
}
|
|
2201
2266
|
async getPrimaryPhp() {
|
|
@@ -2220,13 +2285,13 @@ class PHPRequestHandler {
|
|
|
2220
2285
|
*/
|
|
2221
2286
|
internalUrlToPath(e) {
|
|
2222
2287
|
const r = new URL(e);
|
|
2223
|
-
return r.pathname.startsWith(u(this,
|
|
2288
|
+
return r.pathname.startsWith(u(this, P)) && (r.pathname = r.pathname.slice(u(this, P).length)), toRelativeUrl(r);
|
|
2224
2289
|
}
|
|
2225
2290
|
/**
|
|
2226
2291
|
* The absolute URL of this PHPRequestHandler instance.
|
|
2227
2292
|
*/
|
|
2228
2293
|
get absoluteUrl() {
|
|
2229
|
-
return u(this,
|
|
2294
|
+
return u(this, M);
|
|
2230
2295
|
}
|
|
2231
2296
|
/**
|
|
2232
2297
|
* The directory in the PHP filesystem where the server will look
|
|
@@ -2291,7 +2356,7 @@ class PHPRequestHandler {
|
|
|
2291
2356
|
), n = applyRewriteRules(
|
|
2292
2357
|
removePathPrefix(
|
|
2293
2358
|
decodeURIComponent(s.pathname),
|
|
2294
|
-
u(this,
|
|
2359
|
+
u(this, P)
|
|
2295
2360
|
),
|
|
2296
2361
|
this.rewriteRules
|
|
2297
2362
|
), i = await this.getPrimaryPhp();
|
|
@@ -2304,9 +2369,9 @@ class PHPRequestHandler {
|
|
|
2304
2369
|
new Uint8Array(0)
|
|
2305
2370
|
);
|
|
2306
2371
|
for (const a of ["index.php", "index.html"]) {
|
|
2307
|
-
const
|
|
2308
|
-
if (i.isFile(
|
|
2309
|
-
o =
|
|
2372
|
+
const l = joinPaths(o, a);
|
|
2373
|
+
if (i.isFile(l)) {
|
|
2374
|
+
o = l;
|
|
2310
2375
|
break;
|
|
2311
2376
|
}
|
|
2312
2377
|
}
|
|
@@ -2336,9 +2401,9 @@ class PHPRequestHandler {
|
|
|
2336
2401
|
// Pass along URL with the #fragment filtered out
|
|
2337
2402
|
url: s.toString()
|
|
2338
2403
|
};
|
|
2339
|
-
return m(this, H,
|
|
2404
|
+
return m(this, H, Z).call(this, a, o);
|
|
2340
2405
|
} else
|
|
2341
|
-
return m(this, H,
|
|
2406
|
+
return m(this, H, Q).call(this, i, o);
|
|
2342
2407
|
else
|
|
2343
2408
|
return PHPResponse.forHttpCode(404);
|
|
2344
2409
|
}
|
|
@@ -2346,13 +2411,13 @@ class PHPRequestHandler {
|
|
|
2346
2411
|
await this.processManager[Symbol.asyncDispose]();
|
|
2347
2412
|
}
|
|
2348
2413
|
}
|
|
2349
|
-
S = new WeakMap(), C = new WeakMap(),
|
|
2414
|
+
S = new WeakMap(), C = new WeakMap(), A = new WeakMap(), F = new WeakMap(), I = new WeakMap(), P = new WeakMap(), M = new WeakMap(), R = new WeakMap(), H = new WeakSet(), /**
|
|
2350
2415
|
* Serves a static file from the PHP filesystem.
|
|
2351
2416
|
*
|
|
2352
2417
|
* @param fsPath - Absolute path of the static file to serve.
|
|
2353
2418
|
* @returns The response.
|
|
2354
2419
|
*/
|
|
2355
|
-
|
|
2420
|
+
Q = function(e, r) {
|
|
2356
2421
|
const s = e.readFileAsBuffer(r);
|
|
2357
2422
|
return new PHPResponse(
|
|
2358
2423
|
200,
|
|
@@ -2367,7 +2432,7 @@ Z = function(e, r) {
|
|
|
2367
2432
|
},
|
|
2368
2433
|
s
|
|
2369
2434
|
);
|
|
2370
|
-
},
|
|
2435
|
+
}, Z = async function(e, r) {
|
|
2371
2436
|
let s;
|
|
2372
2437
|
try {
|
|
2373
2438
|
s = await this.processManager.acquirePHPInstance({
|
|
@@ -2377,11 +2442,11 @@ Z = function(e, r) {
|
|
|
2377
2442
|
return n instanceof MaxPhpInstancesError ? PHPResponse.forHttpCode(502) : PHPResponse.forHttpCode(500);
|
|
2378
2443
|
}
|
|
2379
2444
|
try {
|
|
2380
|
-
return await m(this, H,
|
|
2445
|
+
return await m(this, H, ee).call(this, s.php, e, r);
|
|
2381
2446
|
} finally {
|
|
2382
2447
|
s.reap();
|
|
2383
2448
|
}
|
|
2384
|
-
},
|
|
2449
|
+
}, ee = async function(e, r, s) {
|
|
2385
2450
|
let n = "GET";
|
|
2386
2451
|
const i = {
|
|
2387
2452
|
host: u(this, I),
|
|
@@ -2391,21 +2456,21 @@ Z = function(e, r) {
|
|
|
2391
2456
|
let o = r.body;
|
|
2392
2457
|
if (typeof o == "object" && !(o instanceof Uint8Array)) {
|
|
2393
2458
|
n = "POST";
|
|
2394
|
-
const { bytes: a, contentType:
|
|
2395
|
-
o = a, i["content-type"] =
|
|
2459
|
+
const { bytes: a, contentType: l } = await encodeAsMultipart(o);
|
|
2460
|
+
o = a, i["content-type"] = l;
|
|
2396
2461
|
}
|
|
2397
2462
|
try {
|
|
2398
2463
|
const a = await e.run({
|
|
2399
2464
|
relativeUri: ensurePathPrefix(
|
|
2400
2465
|
toRelativeUrl(new URL(r.url)),
|
|
2401
|
-
u(this,
|
|
2466
|
+
u(this, P)
|
|
2402
2467
|
),
|
|
2403
2468
|
protocol: u(this, C),
|
|
2404
2469
|
method: r.method || n,
|
|
2405
2470
|
$_SERVER: {
|
|
2406
2471
|
REMOTE_ADDR: "127.0.0.1",
|
|
2407
2472
|
DOCUMENT_ROOT: u(this, S),
|
|
2408
|
-
HTTPS: u(this,
|
|
2473
|
+
HTTPS: u(this, M).startsWith("https://") ? "on" : ""
|
|
2409
2474
|
},
|
|
2410
2475
|
body: o,
|
|
2411
2476
|
scriptPath: s,
|
|
@@ -2415,9 +2480,9 @@ Z = function(e, r) {
|
|
|
2415
2480
|
a.headers
|
|
2416
2481
|
), a;
|
|
2417
2482
|
} catch (a) {
|
|
2418
|
-
const
|
|
2419
|
-
if (
|
|
2420
|
-
return
|
|
2483
|
+
const l = a;
|
|
2484
|
+
if (l != null && l.response)
|
|
2485
|
+
return l.response;
|
|
2421
2486
|
throw a;
|
|
2422
2487
|
}
|
|
2423
2488
|
};
|
|
@@ -2447,18 +2512,18 @@ function rotatePHPRuntime({
|
|
|
2447
2512
|
}) {
|
|
2448
2513
|
let n = 0;
|
|
2449
2514
|
async function i() {
|
|
2450
|
-
const
|
|
2515
|
+
const l = await t.semaphore.acquire();
|
|
2451
2516
|
try {
|
|
2452
2517
|
await t.hotSwapPHPRuntime(await r(), e), n = 0;
|
|
2453
2518
|
} finally {
|
|
2454
|
-
|
|
2519
|
+
l();
|
|
2455
2520
|
}
|
|
2456
2521
|
}
|
|
2457
2522
|
async function o() {
|
|
2458
2523
|
++n < s || await i();
|
|
2459
2524
|
}
|
|
2460
|
-
async function a(
|
|
2461
|
-
|
|
2525
|
+
async function a(l) {
|
|
2526
|
+
l.type === "request.error" && l.source === "php-wasm" && await i();
|
|
2462
2527
|
}
|
|
2463
2528
|
return t.addEventListener("request.error", a), t.addEventListener("request.end", o), function() {
|
|
2464
2529
|
t.removeEventListener("request.error", a), t.removeEventListener("request.end", o);
|
|
@@ -2485,6 +2550,56 @@ function proxyFileSystem(t, e, r) {
|
|
|
2485
2550
|
n
|
|
2486
2551
|
);
|
|
2487
2552
|
}
|
|
2553
|
+
function sandboxedSpawnHandlerFactory(t) {
|
|
2554
|
+
return createSpawnHandler(async function(e, r, s) {
|
|
2555
|
+
r.notifySpawn(), e[0] === "exec" && e.shift(), (e[0].endsWith(".php") || e[0].endsWith(".phar")) && e.unshift("php");
|
|
2556
|
+
const n = e[0].split("/").pop();
|
|
2557
|
+
if (e[0] === "/usr/bin/env" && e[1] === "stty" && e[2] === "size")
|
|
2558
|
+
r.stdout("18 140"), r.exit(0);
|
|
2559
|
+
else if (n === "tput" && e[1] === "cols")
|
|
2560
|
+
r.stdout("140"), r.exit(0);
|
|
2561
|
+
else if (n === "less")
|
|
2562
|
+
r.on("stdin", (i) => {
|
|
2563
|
+
r.stdout(i);
|
|
2564
|
+
}), r.exit(0);
|
|
2565
|
+
else if (n === "php") {
|
|
2566
|
+
const { php: i, reap: o } = await t.acquirePHPInstance({
|
|
2567
|
+
considerPrimary: !1
|
|
2568
|
+
});
|
|
2569
|
+
i.chdir(s.cwd);
|
|
2570
|
+
try {
|
|
2571
|
+
const a = await i.cli(e, {
|
|
2572
|
+
env: {
|
|
2573
|
+
...s.env,
|
|
2574
|
+
SCRIPT_PATH: e[1],
|
|
2575
|
+
// Set SHELL_PIPE to 0 to ensure WP-CLI formats
|
|
2576
|
+
// the output as ASCII tables.
|
|
2577
|
+
// @see https://github.com/wp-cli/wp-cli/issues/1102
|
|
2578
|
+
SHELL_PIPE: "0"
|
|
2579
|
+
}
|
|
2580
|
+
});
|
|
2581
|
+
a.stdout.pipeTo(
|
|
2582
|
+
new WritableStream({
|
|
2583
|
+
write(l) {
|
|
2584
|
+
r.stdout(l);
|
|
2585
|
+
}
|
|
2586
|
+
})
|
|
2587
|
+
), a.stderr.pipeTo(
|
|
2588
|
+
new WritableStream({
|
|
2589
|
+
write(l) {
|
|
2590
|
+
r.stderr(l);
|
|
2591
|
+
}
|
|
2592
|
+
})
|
|
2593
|
+
), r.exit(await a.exitCode);
|
|
2594
|
+
} catch (a) {
|
|
2595
|
+
throw r.exit(1), a;
|
|
2596
|
+
} finally {
|
|
2597
|
+
o();
|
|
2598
|
+
}
|
|
2599
|
+
} else
|
|
2600
|
+
r.exit(1);
|
|
2601
|
+
});
|
|
2602
|
+
}
|
|
2488
2603
|
function exposeSync(t, e, r, s = ["*"]) {
|
|
2489
2604
|
return expose(t, e, s, r.afterResponseSent);
|
|
2490
2605
|
}
|
|
@@ -2511,16 +2626,16 @@ function createSyncProxy(t, e = [], r) {
|
|
|
2511
2626
|
apply(s, n, i) {
|
|
2512
2627
|
if (e.at(-1) === "bind")
|
|
2513
2628
|
return createSyncProxy(t, e.slice(0, -1), r);
|
|
2514
|
-
const [a,
|
|
2629
|
+
const [a, l] = processArguments(i), c = r.send(
|
|
2515
2630
|
t,
|
|
2516
2631
|
{
|
|
2517
2632
|
type: MessageType.APPLY,
|
|
2518
2633
|
path: e.map(String),
|
|
2519
2634
|
argumentList: a
|
|
2520
2635
|
},
|
|
2521
|
-
|
|
2636
|
+
l
|
|
2522
2637
|
);
|
|
2523
|
-
return fromWireValue(
|
|
2638
|
+
return fromWireValue(c);
|
|
2524
2639
|
},
|
|
2525
2640
|
construct(s, n) {
|
|
2526
2641
|
const [i, o] = processArguments(n), a = r.send(
|
|
@@ -2541,9 +2656,15 @@ function wrapSync(t, e) {
|
|
|
2541
2656
|
}
|
|
2542
2657
|
class NodeSABSyncReceiveMessageTransport {
|
|
2543
2658
|
static async create() {
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2659
|
+
if (!NodeSABSyncReceiveMessageTransport.receiveMessageOnPort)
|
|
2660
|
+
try {
|
|
2661
|
+
NodeSABSyncReceiveMessageTransport.receiveMessageOnPort = require("worker_threads").receiveMessageOnPort;
|
|
2662
|
+
} catch {
|
|
2663
|
+
NodeSABSyncReceiveMessageTransport.receiveMessageOnPort = await import("worker_threads").then(
|
|
2664
|
+
(e) => e.receiveMessageOnPort
|
|
2665
|
+
);
|
|
2666
|
+
}
|
|
2667
|
+
return new NodeSABSyncReceiveMessageTransport();
|
|
2547
2668
|
}
|
|
2548
2669
|
constructor() {
|
|
2549
2670
|
}
|
|
@@ -2555,7 +2676,7 @@ class NodeSABSyncReceiveMessageTransport {
|
|
|
2555
2676
|
}
|
|
2556
2677
|
}
|
|
2557
2678
|
send(e, r, s) {
|
|
2558
|
-
var
|
|
2679
|
+
var c;
|
|
2559
2680
|
const n = new SharedArrayBuffer(4), i = new Int32Array(n);
|
|
2560
2681
|
i[0] = 0;
|
|
2561
2682
|
const o = generateUUID();
|
|
@@ -2565,10 +2686,10 @@ class NodeSABSyncReceiveMessageTransport {
|
|
|
2565
2686
|
), Atomics.wait(i, 0, 0, 5e3) === "timed-out")
|
|
2566
2687
|
throw new Error("Timeout waiting for response");
|
|
2567
2688
|
for (; ; ) {
|
|
2568
|
-
const
|
|
2569
|
-
if (((
|
|
2570
|
-
return
|
|
2571
|
-
if (!
|
|
2689
|
+
const p = NodeSABSyncReceiveMessageTransport.receiveMessageOnPort(e);
|
|
2690
|
+
if (((c = p.message) == null ? void 0 : c.id) === o)
|
|
2691
|
+
return p.message;
|
|
2692
|
+
if (!p)
|
|
2572
2693
|
throw new Error("No response received");
|
|
2573
2694
|
}
|
|
2574
2695
|
}
|
|
@@ -2605,7 +2726,7 @@ const WireValueType = {
|
|
|
2605
2726
|
deserialize(t) {
|
|
2606
2727
|
return t.start(), wrap(t);
|
|
2607
2728
|
}
|
|
2608
|
-
}, throwTransferHandler = {
|
|
2729
|
+
}, throwTransferHandler$1 = {
|
|
2609
2730
|
canHandle: (t) => isObject(t) && throwMarker in t,
|
|
2610
2731
|
serialize({ value: t }) {
|
|
2611
2732
|
let e;
|
|
@@ -2626,7 +2747,7 @@ const WireValueType = {
|
|
|
2626
2747
|
}
|
|
2627
2748
|
}, transferHandlers = /* @__PURE__ */ new Map([
|
|
2628
2749
|
["proxy", proxyTransferHandler],
|
|
2629
|
-
["throw", throwTransferHandler]
|
|
2750
|
+
["throw", throwTransferHandler$1]
|
|
2630
2751
|
]);
|
|
2631
2752
|
function isAllowedOrigin(t, e) {
|
|
2632
2753
|
for (const r of t)
|
|
@@ -2642,55 +2763,55 @@ function expose(t, e = globalThis, r = ["*"], s) {
|
|
|
2642
2763
|
console.warn(`Invalid origin '${i.origin}' for comlink proxy`);
|
|
2643
2764
|
return;
|
|
2644
2765
|
}
|
|
2645
|
-
const { id: o, type: a, path:
|
|
2766
|
+
const { id: o, type: a, path: l } = {
|
|
2646
2767
|
path: [],
|
|
2647
2768
|
...i.data
|
|
2648
|
-
},
|
|
2649
|
-
let
|
|
2769
|
+
}, c = (i.data.argumentList || []).map(fromWireValue);
|
|
2770
|
+
let p;
|
|
2650
2771
|
try {
|
|
2651
|
-
const
|
|
2772
|
+
const h = l.slice(0, -1).reduce((w, b) => w[b], t), y = l.reduce((w, b) => w[b], t);
|
|
2652
2773
|
switch (a) {
|
|
2653
2774
|
case MessageType.GET:
|
|
2654
|
-
|
|
2775
|
+
p = y;
|
|
2655
2776
|
break;
|
|
2656
2777
|
case MessageType.SET:
|
|
2657
|
-
|
|
2778
|
+
h[l.slice(-1)[0]] = fromWireValue(
|
|
2658
2779
|
i.data.value
|
|
2659
|
-
),
|
|
2780
|
+
), p = !0;
|
|
2660
2781
|
break;
|
|
2661
2782
|
case MessageType.APPLY:
|
|
2662
|
-
|
|
2783
|
+
p = y.apply(h, c);
|
|
2663
2784
|
break;
|
|
2664
2785
|
case MessageType.CONSTRUCT:
|
|
2665
2786
|
{
|
|
2666
|
-
const
|
|
2667
|
-
|
|
2787
|
+
const w = new y(...c);
|
|
2788
|
+
p = proxy(w);
|
|
2668
2789
|
}
|
|
2669
2790
|
break;
|
|
2670
2791
|
case MessageType.ENDPOINT:
|
|
2671
2792
|
{
|
|
2672
|
-
const { port1:
|
|
2673
|
-
expose(t,
|
|
2793
|
+
const { port1: w, port2: b } = new MessageChannel();
|
|
2794
|
+
expose(t, b), p = transfer(w, [w]);
|
|
2674
2795
|
}
|
|
2675
2796
|
break;
|
|
2676
2797
|
case MessageType.RELEASE:
|
|
2677
|
-
|
|
2798
|
+
p = void 0;
|
|
2678
2799
|
break;
|
|
2679
2800
|
default:
|
|
2680
2801
|
return;
|
|
2681
2802
|
}
|
|
2682
|
-
} catch (
|
|
2683
|
-
|
|
2803
|
+
} catch (h) {
|
|
2804
|
+
p = { value: h, [throwMarker]: 0 };
|
|
2684
2805
|
}
|
|
2685
|
-
Promise.resolve(
|
|
2686
|
-
const [
|
|
2687
|
-
e.postMessage({ ...
|
|
2806
|
+
Promise.resolve(p).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
|
|
2807
|
+
const [y, w] = toWireValue(h);
|
|
2808
|
+
e.postMessage({ ...y, id: o }, w), a === MessageType.RELEASE && (e.removeEventListener("message", n), closeEndPoint(e), finalizer in t && typeof t[finalizer] == "function" && t[finalizer]());
|
|
2688
2809
|
}).catch(() => {
|
|
2689
|
-
const [
|
|
2810
|
+
const [h, y] = toWireValue({
|
|
2690
2811
|
value: new TypeError("Unserializable return value"),
|
|
2691
2812
|
[throwMarker]: 0
|
|
2692
2813
|
});
|
|
2693
|
-
e.postMessage({ ...
|
|
2814
|
+
e.postMessage({ ...h, id: o }, y);
|
|
2694
2815
|
}).finally(() => {
|
|
2695
2816
|
s == null || s(i);
|
|
2696
2817
|
});
|
|
@@ -2751,61 +2872,61 @@ function createProxy(t, e, r = [], s = function() {
|
|
|
2751
2872
|
if (a === "then") {
|
|
2752
2873
|
if (r.length === 0)
|
|
2753
2874
|
return { then: () => i };
|
|
2754
|
-
const
|
|
2875
|
+
const l = requestResponseMessage(t, e, {
|
|
2755
2876
|
type: MessageType.GET,
|
|
2756
|
-
path: r.map((
|
|
2877
|
+
path: r.map((c) => c.toString())
|
|
2757
2878
|
}).then(fromWireValue);
|
|
2758
|
-
return
|
|
2879
|
+
return l.then.bind(l);
|
|
2759
2880
|
}
|
|
2760
2881
|
return createProxy(t, e, [...r, a]);
|
|
2761
2882
|
},
|
|
2762
|
-
set(o, a,
|
|
2883
|
+
set(o, a, l) {
|
|
2763
2884
|
throwIfProxyReleased(n);
|
|
2764
|
-
const [
|
|
2885
|
+
const [c, p] = toWireValue(l);
|
|
2765
2886
|
return requestResponseMessage(
|
|
2766
2887
|
t,
|
|
2767
2888
|
e,
|
|
2768
2889
|
{
|
|
2769
2890
|
type: MessageType.SET,
|
|
2770
|
-
path: [...r, a].map((
|
|
2771
|
-
value:
|
|
2891
|
+
path: [...r, a].map((h) => h.toString()),
|
|
2892
|
+
value: c
|
|
2772
2893
|
},
|
|
2773
|
-
|
|
2894
|
+
p
|
|
2774
2895
|
).then(fromWireValue);
|
|
2775
2896
|
},
|
|
2776
|
-
apply(o, a,
|
|
2897
|
+
apply(o, a, l) {
|
|
2777
2898
|
throwIfProxyReleased(n);
|
|
2778
|
-
const
|
|
2779
|
-
if (
|
|
2899
|
+
const c = r[r.length - 1];
|
|
2900
|
+
if (c === createEndpoint)
|
|
2780
2901
|
return requestResponseMessage(t, e, {
|
|
2781
2902
|
type: MessageType.ENDPOINT
|
|
2782
2903
|
}).then(fromWireValue);
|
|
2783
|
-
if (
|
|
2904
|
+
if (c === "bind")
|
|
2784
2905
|
return createProxy(t, e, r.slice(0, -1));
|
|
2785
|
-
const [
|
|
2906
|
+
const [p, h] = processArguments(l);
|
|
2786
2907
|
return requestResponseMessage(
|
|
2787
2908
|
t,
|
|
2788
2909
|
e,
|
|
2789
2910
|
{
|
|
2790
2911
|
type: MessageType.APPLY,
|
|
2791
|
-
path: r.map((
|
|
2792
|
-
argumentList:
|
|
2912
|
+
path: r.map((y) => y.toString()),
|
|
2913
|
+
argumentList: p
|
|
2793
2914
|
},
|
|
2794
|
-
|
|
2915
|
+
h
|
|
2795
2916
|
).then(fromWireValue);
|
|
2796
2917
|
},
|
|
2797
2918
|
construct(o, a) {
|
|
2798
2919
|
throwIfProxyReleased(n);
|
|
2799
|
-
const [
|
|
2920
|
+
const [l, c] = processArguments(a);
|
|
2800
2921
|
return requestResponseMessage(
|
|
2801
2922
|
t,
|
|
2802
2923
|
e,
|
|
2803
2924
|
{
|
|
2804
2925
|
type: MessageType.CONSTRUCT,
|
|
2805
|
-
path: r.map((
|
|
2806
|
-
argumentList:
|
|
2926
|
+
path: r.map((p) => p.toString()),
|
|
2927
|
+
argumentList: l
|
|
2807
2928
|
},
|
|
2808
|
-
|
|
2929
|
+
c
|
|
2809
2930
|
).then(fromWireValue);
|
|
2810
2931
|
}
|
|
2811
2932
|
});
|
|
@@ -2889,6 +3010,153 @@ function nodeEndpoint(t) {
|
|
|
2889
3010
|
start: t.start && t.start.bind(t)
|
|
2890
3011
|
};
|
|
2891
3012
|
}
|
|
3013
|
+
const list = [
|
|
3014
|
+
// Native ES errors https://262.ecma-international.org/12.0/#sec-well-known-intrinsic-objects
|
|
3015
|
+
Error,
|
|
3016
|
+
EvalError,
|
|
3017
|
+
RangeError,
|
|
3018
|
+
ReferenceError,
|
|
3019
|
+
SyntaxError,
|
|
3020
|
+
TypeError,
|
|
3021
|
+
URIError,
|
|
3022
|
+
AggregateError,
|
|
3023
|
+
// Built-in errors
|
|
3024
|
+
globalThis.DOMException,
|
|
3025
|
+
// Node-specific errors
|
|
3026
|
+
// https://nodejs.org/api/errors.html
|
|
3027
|
+
globalThis.AssertionError,
|
|
3028
|
+
globalThis.SystemError
|
|
3029
|
+
].filter(Boolean).map((t) => [t.name, t]), errorConstructors = new Map(list);
|
|
3030
|
+
class NonError extends Error {
|
|
3031
|
+
constructor(e) {
|
|
3032
|
+
super(NonError._prepareSuperMessage(e)), this.name = "NonError";
|
|
3033
|
+
}
|
|
3034
|
+
static _prepareSuperMessage(e) {
|
|
3035
|
+
try {
|
|
3036
|
+
return JSON.stringify(e);
|
|
3037
|
+
} catch {
|
|
3038
|
+
return String(e);
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
const errorProperties = [
|
|
3043
|
+
{
|
|
3044
|
+
property: "name",
|
|
3045
|
+
enumerable: !1
|
|
3046
|
+
},
|
|
3047
|
+
{
|
|
3048
|
+
property: "message",
|
|
3049
|
+
enumerable: !1
|
|
3050
|
+
},
|
|
3051
|
+
{
|
|
3052
|
+
property: "stack",
|
|
3053
|
+
enumerable: !1
|
|
3054
|
+
},
|
|
3055
|
+
{
|
|
3056
|
+
property: "code",
|
|
3057
|
+
enumerable: !0
|
|
3058
|
+
},
|
|
3059
|
+
{
|
|
3060
|
+
property: "cause",
|
|
3061
|
+
enumerable: !1
|
|
3062
|
+
},
|
|
3063
|
+
{
|
|
3064
|
+
property: "errors",
|
|
3065
|
+
enumerable: !1
|
|
3066
|
+
}
|
|
3067
|
+
], toJsonWasCalled = /* @__PURE__ */ new WeakSet(), toJSON = (t) => {
|
|
3068
|
+
toJsonWasCalled.add(t);
|
|
3069
|
+
const e = t.toJSON();
|
|
3070
|
+
return toJsonWasCalled.delete(t), e;
|
|
3071
|
+
}, newError = (t) => {
|
|
3072
|
+
const e = errorConstructors.get(t) ?? Error;
|
|
3073
|
+
return e === AggregateError ? new e([]) : new e();
|
|
3074
|
+
}, destroyCircular = ({
|
|
3075
|
+
from: t,
|
|
3076
|
+
seen: e,
|
|
3077
|
+
to: r,
|
|
3078
|
+
forceEnumerable: s,
|
|
3079
|
+
maxDepth: n,
|
|
3080
|
+
depth: i,
|
|
3081
|
+
useToJSON: o,
|
|
3082
|
+
serialize: a
|
|
3083
|
+
}) => {
|
|
3084
|
+
if (r || (Array.isArray(t) ? r = [] : !a && isErrorLike(t) ? r = newError(t.name) : r = {}), e.push(t), i >= n)
|
|
3085
|
+
return r;
|
|
3086
|
+
if (o && typeof t.toJSON == "function" && !toJsonWasCalled.has(t))
|
|
3087
|
+
return toJSON(t);
|
|
3088
|
+
const l = (c) => destroyCircular({
|
|
3089
|
+
from: c,
|
|
3090
|
+
seen: [...e],
|
|
3091
|
+
forceEnumerable: s,
|
|
3092
|
+
maxDepth: n,
|
|
3093
|
+
depth: i,
|
|
3094
|
+
useToJSON: o,
|
|
3095
|
+
serialize: a
|
|
3096
|
+
});
|
|
3097
|
+
for (const [c, p] of Object.entries(t)) {
|
|
3098
|
+
if (p && p instanceof Uint8Array && p.constructor.name === "Buffer") {
|
|
3099
|
+
r[c] = "[object Buffer]";
|
|
3100
|
+
continue;
|
|
3101
|
+
}
|
|
3102
|
+
if (p !== null && typeof p == "object" && typeof p.pipe == "function") {
|
|
3103
|
+
r[c] = "[object Stream]";
|
|
3104
|
+
continue;
|
|
3105
|
+
}
|
|
3106
|
+
if (typeof p != "function") {
|
|
3107
|
+
if (!p || typeof p != "object") {
|
|
3108
|
+
try {
|
|
3109
|
+
r[c] = p;
|
|
3110
|
+
} catch {
|
|
3111
|
+
}
|
|
3112
|
+
continue;
|
|
3113
|
+
}
|
|
3114
|
+
if (!e.includes(t[c])) {
|
|
3115
|
+
i++, r[c] = l(t[c]);
|
|
3116
|
+
continue;
|
|
3117
|
+
}
|
|
3118
|
+
r[c] = "[Circular]";
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
if (a || r instanceof Error)
|
|
3122
|
+
for (const { property: c, enumerable: p } of errorProperties)
|
|
3123
|
+
t[c] !== void 0 && t[c] !== null && Object.defineProperty(r, c, {
|
|
3124
|
+
value: isErrorLike(t[c]) || Array.isArray(t[c]) ? l(t[c]) : t[c],
|
|
3125
|
+
enumerable: s ? !0 : p,
|
|
3126
|
+
configurable: !0,
|
|
3127
|
+
writable: !0
|
|
3128
|
+
});
|
|
3129
|
+
return r;
|
|
3130
|
+
};
|
|
3131
|
+
function serializeError(t, e = {}) {
|
|
3132
|
+
const { maxDepth: r = Number.POSITIVE_INFINITY, useToJSON: s = !0 } = e;
|
|
3133
|
+
return typeof t == "object" && t !== null ? destroyCircular({
|
|
3134
|
+
from: t,
|
|
3135
|
+
seen: [],
|
|
3136
|
+
forceEnumerable: !0,
|
|
3137
|
+
maxDepth: r,
|
|
3138
|
+
depth: 0,
|
|
3139
|
+
useToJSON: s,
|
|
3140
|
+
serialize: !0
|
|
3141
|
+
}) : typeof t == "function" ? `[Function: ${t.name || "anonymous"}]` : t;
|
|
3142
|
+
}
|
|
3143
|
+
function deserializeError(t, e = {}) {
|
|
3144
|
+
const { maxDepth: r = Number.POSITIVE_INFINITY } = e;
|
|
3145
|
+
return t instanceof Error ? t : isMinimumViableSerializedError(t) ? destroyCircular({
|
|
3146
|
+
from: t,
|
|
3147
|
+
seen: [],
|
|
3148
|
+
to: newError(t.name),
|
|
3149
|
+
maxDepth: r,
|
|
3150
|
+
depth: 0,
|
|
3151
|
+
serialize: !1
|
|
3152
|
+
}) : new NonError(t);
|
|
3153
|
+
}
|
|
3154
|
+
function isErrorLike(t) {
|
|
3155
|
+
return !!t && typeof t == "object" && typeof t.name == "string" && typeof t.message == "string" && typeof t.stack == "string";
|
|
3156
|
+
}
|
|
3157
|
+
function isMinimumViableSerializedError(t) {
|
|
3158
|
+
return !!t && typeof t == "object" && typeof t.message == "string" && !Array.isArray(t);
|
|
3159
|
+
}
|
|
2892
3160
|
async function consumeAPISync(t) {
|
|
2893
3161
|
setupTransferHandlers();
|
|
2894
3162
|
const e = await NodeSABSyncReceiveMessageTransport.create();
|
|
@@ -2931,10 +3199,10 @@ function prepareForExpose(t, e) {
|
|
|
2931
3199
|
setupTransferHandlers();
|
|
2932
3200
|
const r = Promise.resolve();
|
|
2933
3201
|
let s, n;
|
|
2934
|
-
const i = new Promise((
|
|
2935
|
-
s =
|
|
3202
|
+
const i = new Promise((l, c) => {
|
|
3203
|
+
s = l, n = c;
|
|
2936
3204
|
}), o = proxyClone(t), a = new Proxy(o, {
|
|
2937
|
-
get: (
|
|
3205
|
+
get: (l, c) => c === "isConnected" ? () => r : c === "isReady" ? () => i : c in l ? l[c] : e == null ? void 0 : e[c]
|
|
2938
3206
|
});
|
|
2939
3207
|
return { setReady: s, setFailed: n, exposedApi: a };
|
|
2940
3208
|
}
|
|
@@ -2985,6 +3253,28 @@ function setupTransferHandlers() {
|
|
|
2985
3253
|
return r.response && (s[0].value.response = r.response), r.source && (s[0].value.source = r.source), s;
|
|
2986
3254
|
};
|
|
2987
3255
|
}
|
|
3256
|
+
const throwTransferHandler = transferHandlers.get(
|
|
3257
|
+
"throw"
|
|
3258
|
+
), throwTransferHandlerCustom = {
|
|
3259
|
+
canHandle: throwTransferHandler.canHandle,
|
|
3260
|
+
serialize: ({ value: t }) => {
|
|
3261
|
+
let e;
|
|
3262
|
+
return t instanceof Error ? (e = {
|
|
3263
|
+
isError: !0,
|
|
3264
|
+
value: serializeError(t)
|
|
3265
|
+
}, e.value.originalErrorClassName = t.constructor.name) : e = { isError: !1, value: t }, [e, []];
|
|
3266
|
+
},
|
|
3267
|
+
deserialize: (t) => {
|
|
3268
|
+
if (t.isError) {
|
|
3269
|
+
const e = deserializeError(t.value);
|
|
3270
|
+
throw new Error("Comlink method call failed", {
|
|
3271
|
+
cause: e
|
|
3272
|
+
});
|
|
3273
|
+
}
|
|
3274
|
+
throw t.value;
|
|
3275
|
+
}
|
|
3276
|
+
};
|
|
3277
|
+
transferHandlers.set("throw", throwTransferHandlerCustom);
|
|
2988
3278
|
function proxyClone(t) {
|
|
2989
3279
|
return new Proxy(t, {
|
|
2990
3280
|
get(e, r) {
|
|
@@ -3030,9 +3320,13 @@ export {
|
|
|
3030
3320
|
isExitCode,
|
|
3031
3321
|
iteratePhpFiles as iterateFiles,
|
|
3032
3322
|
loadPHPRuntime,
|
|
3323
|
+
prettyPrintFullStackTrace,
|
|
3324
|
+
printDebugDetails,
|
|
3325
|
+
printResponseDebugDetails,
|
|
3033
3326
|
proxyFileSystem,
|
|
3034
3327
|
removePathPrefix,
|
|
3035
3328
|
rotatePHPRuntime,
|
|
3329
|
+
sandboxedSpawnHandlerFactory,
|
|
3036
3330
|
setPhpIniEntries,
|
|
3037
3331
|
toRelativeUrl,
|
|
3038
3332
|
withPHPIniValues,
|