@php-wasm/web 0.6.3 → 0.6.4
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.d.ts +4 -0
- package/index.js +270 -234
- package/kitchen-sink/7_0_33/php_7_0.wasm +0 -0
- package/kitchen-sink/7_1_30/php_7_1.wasm +0 -0
- package/kitchen-sink/7_2_34/php_7_2.wasm +0 -0
- package/kitchen-sink/7_3_33/php_7_3.wasm +0 -0
- package/kitchen-sink/7_4_33/php_7_4.wasm +0 -0
- package/kitchen-sink/8_0_30/php_8_0.wasm +0 -0
- package/kitchen-sink/8_1_23/php_8_1.wasm +0 -0
- package/kitchen-sink/8_2_10/php_8_2.wasm +0 -0
- package/kitchen-sink/8_3_0/php_8_3.wasm +0 -0
- package/kitchen-sink/php_7_0.js +3 -3
- package/kitchen-sink/php_7_1.js +3 -3
- package/kitchen-sink/php_7_2.js +3 -3
- package/kitchen-sink/php_7_3.js +3 -3
- package/kitchen-sink/php_7_4.js +3 -3
- package/kitchen-sink/php_8_0.js +3 -3
- package/kitchen-sink/php_8_1.js +3 -3
- package/kitchen-sink/php_8_2.js +3 -3
- package/kitchen-sink/php_8_3.js +3 -3
- package/light/7_0_33/php_7_0.wasm +0 -0
- package/light/7_1_30/php_7_1.wasm +0 -0
- package/light/7_2_34/php_7_2.wasm +0 -0
- package/light/7_3_33/php_7_3.wasm +0 -0
- package/light/7_4_33/php_7_4.wasm +0 -0
- package/light/8_0_30/php_8_0.wasm +0 -0
- package/light/8_1_23/php_8_1.wasm +0 -0
- package/light/8_2_10/php_8_2.wasm +0 -0
- package/light/8_3_0/php_8_3.wasm +0 -0
- package/light/php_7_0.js +3 -3
- package/light/php_7_1.js +3 -3
- package/light/php_7_2.js +3 -3
- package/light/php_7_3.js +3 -3
- package/light/php_7_4.js +3 -3
- package/light/php_8_0.js +3 -3
- package/light/php_8_1.js +3 -3
- package/light/php_8_2.js +3 -3
- package/light/php_8_3.js +3 -3
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@ var K = (e, t, r) => {
|
|
|
2
2
|
if (!t.has(e))
|
|
3
3
|
throw TypeError("Cannot " + r);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
5
|
+
var c = (e, t, r) => (K(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => {
|
|
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);
|
|
@@ -12,8 +12,8 @@ if (typeof File > "u") {
|
|
|
12
12
|
class e extends Blob {
|
|
13
13
|
constructor(r, s, n) {
|
|
14
14
|
super(r);
|
|
15
|
-
let
|
|
16
|
-
n != null && n.lastModified && (
|
|
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 || "";
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
global.File = e;
|
|
@@ -50,9 +50,9 @@ function isByobSupported() {
|
|
|
50
50
|
// this if needed.
|
|
51
51
|
autoAllocateChunkSize: 512 * 1024,
|
|
52
52
|
async pull(r) {
|
|
53
|
-
const s = r.byobRequest.view,
|
|
54
|
-
new Uint8Array(s.buffer).set(
|
|
55
|
-
const a =
|
|
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
56
|
r.byobRequest.respond(a), e += a, e >= t.size && r.close();
|
|
57
57
|
}
|
|
58
58
|
});
|
|
@@ -115,26 +115,26 @@ function improveWASMErrorReporting(e) {
|
|
|
115
115
|
if (typeof e.asm[r] == "function") {
|
|
116
116
|
const s = e.asm[r];
|
|
117
117
|
e.asm[r] = function(...n) {
|
|
118
|
-
var
|
|
118
|
+
var o;
|
|
119
119
|
try {
|
|
120
120
|
return s(...n);
|
|
121
|
-
} catch (
|
|
122
|
-
if (!(
|
|
123
|
-
throw
|
|
121
|
+
} catch (i) {
|
|
122
|
+
if (!(i instanceof Error))
|
|
123
|
+
throw i;
|
|
124
124
|
const a = clarifyErrorMessage(
|
|
125
|
-
|
|
126
|
-
(
|
|
125
|
+
i,
|
|
126
|
+
(o = e.lastAsyncifyStackSource) == null ? void 0 : o.stack
|
|
127
127
|
);
|
|
128
|
-
if (e.lastAsyncifyStackSource && (
|
|
128
|
+
if (e.lastAsyncifyStackSource && (i.cause = e.lastAsyncifyStackSource), t.hasListeners()) {
|
|
129
129
|
t.dispatchEvent(
|
|
130
130
|
new ErrorEvent("error", {
|
|
131
|
-
error:
|
|
131
|
+
error: i,
|
|
132
132
|
message: a
|
|
133
133
|
})
|
|
134
134
|
);
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
137
|
-
throw isExitCodeZero(
|
|
137
|
+
throw isExitCodeZero(i) || showCriticalErrorBox(a), i;
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
140
|
}
|
|
@@ -267,12 +267,31 @@ function normalizePathsArray(e, t) {
|
|
|
267
267
|
e.unshift("..");
|
|
268
268
|
return e;
|
|
269
269
|
}
|
|
270
|
+
function splitShellCommand(e) {
|
|
271
|
+
let s = 0, n = "";
|
|
272
|
+
const o = [];
|
|
273
|
+
let i = "";
|
|
274
|
+
for (let a = 0; a < e.length; a++) {
|
|
275
|
+
const l = e[a];
|
|
276
|
+
l === "\\" ? ((e[a + 1] === '"' || e[a + 1] === "'") && a++, i += e[a]) : s === 0 ? l === '"' || l === "'" ? (s = 1, n = l) : l.match(/\s/) ? (i.trim().length && o.push(i.trim()), i = l) : o.length && !i ? i = o.pop() + l : i += l : s === 1 && (l === n ? (s = 0, n = "") : i += l);
|
|
277
|
+
}
|
|
278
|
+
return i && o.push(i.trim()), o;
|
|
279
|
+
}
|
|
270
280
|
function createSpawnHandler(e) {
|
|
271
|
-
return function(t) {
|
|
272
|
-
const
|
|
281
|
+
return function(t, r = [], s = {}) {
|
|
282
|
+
const n = new ChildProcess(), o = new ProcessApi(n);
|
|
273
283
|
return setTimeout(async () => {
|
|
274
|
-
|
|
275
|
-
|
|
284
|
+
let i = [];
|
|
285
|
+
if (r.length)
|
|
286
|
+
i = [t, ...r];
|
|
287
|
+
else if (typeof t == "string")
|
|
288
|
+
i = splitShellCommand(t);
|
|
289
|
+
else if (Array.isArray(t))
|
|
290
|
+
i = t;
|
|
291
|
+
else
|
|
292
|
+
throw new Error("Invalid command ", t);
|
|
293
|
+
await e(i, o, s), n.emit("spawn", !0);
|
|
294
|
+
}), n;
|
|
276
295
|
};
|
|
277
296
|
}
|
|
278
297
|
class EventEmitter {
|
|
@@ -297,9 +316,15 @@ class ProcessApi extends EventEmitter {
|
|
|
297
316
|
stdout(t) {
|
|
298
317
|
typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stdout.emit("data", t);
|
|
299
318
|
}
|
|
319
|
+
stdoutEnd() {
|
|
320
|
+
this.childProcess.stdout.emit("end", {});
|
|
321
|
+
}
|
|
300
322
|
stderr(t) {
|
|
301
323
|
typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stderr.emit("data", t);
|
|
302
324
|
}
|
|
325
|
+
stderrEnd() {
|
|
326
|
+
this.childProcess.stderr.emit("end", {});
|
|
327
|
+
}
|
|
303
328
|
exit(t) {
|
|
304
329
|
this.exited || (this.exited = !0, this.childProcess.emit("exit", t));
|
|
305
330
|
}
|
|
@@ -337,8 +362,8 @@ ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symb
|
|
|
337
362
|
}, ReadableStream.prototype.iterate = // @ts-ignore
|
|
338
363
|
ReadableStream.prototype[Symbol.asyncIterator]);
|
|
339
364
|
class PHPResponse {
|
|
340
|
-
constructor(t, r, s, n = "",
|
|
341
|
-
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode =
|
|
365
|
+
constructor(t, r, s, n = "", o = 0) {
|
|
366
|
+
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = o, this.errors = n;
|
|
342
367
|
}
|
|
343
368
|
static fromRawData(t) {
|
|
344
369
|
return new PHPResponse(
|
|
@@ -419,7 +444,7 @@ class PHPBrowser {
|
|
|
419
444
|
cookie: this.serializeCookies()
|
|
420
445
|
}
|
|
421
446
|
});
|
|
422
|
-
if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]),
|
|
447
|
+
if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), c(this, T).handleRedirects && s.headers.location && r < c(this, T).maxRedirects) {
|
|
423
448
|
const n = new URL(
|
|
424
449
|
s.headers.location[0],
|
|
425
450
|
this.requestHandler.absoluteUrl
|
|
@@ -456,16 +481,16 @@ class PHPBrowser {
|
|
|
456
481
|
try {
|
|
457
482
|
if (!r.includes("="))
|
|
458
483
|
continue;
|
|
459
|
-
const s = r.indexOf("="), n = r.substring(0, s),
|
|
460
|
-
|
|
484
|
+
const s = r.indexOf("="), n = r.substring(0, s), o = r.substring(s + 1).split(";")[0];
|
|
485
|
+
c(this, b)[n] = o;
|
|
461
486
|
} catch (s) {
|
|
462
487
|
console.error(s);
|
|
463
488
|
}
|
|
464
489
|
}
|
|
465
490
|
serializeCookies() {
|
|
466
491
|
const t = [];
|
|
467
|
-
for (const r in
|
|
468
|
-
t.push(`${r}=${
|
|
492
|
+
for (const r in c(this, b))
|
|
493
|
+
t.push(`${r}=${c(this, b)[r]}`);
|
|
469
494
|
return t.join("; ");
|
|
470
495
|
}
|
|
471
496
|
}
|
|
@@ -482,23 +507,23 @@ function ensurePathPrefix(e, t) {
|
|
|
482
507
|
}
|
|
483
508
|
async function encodeAsMultipart(e) {
|
|
484
509
|
const t = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${t}`, s = new TextEncoder(), n = [];
|
|
485
|
-
for (const [
|
|
510
|
+
for (const [l, u] of Object.entries(e))
|
|
486
511
|
n.push(`--${t}\r
|
|
487
|
-
`), n.push(`Content-Disposition: form-data; name="${
|
|
488
|
-
`),
|
|
489
|
-
|
|
490
|
-
`),
|
|
512
|
+
`), n.push(`Content-Disposition: form-data; name="${l}"`), u instanceof File && n.push(`; filename="${u.name}"`), n.push(`\r
|
|
513
|
+
`), u instanceof File && (n.push("Content-Type: application/octet-stream"), n.push(`\r
|
|
514
|
+
`)), n.push(`\r
|
|
515
|
+
`), u instanceof File ? n.push(await fileToUint8Array(u)) : n.push(u), n.push(`\r
|
|
491
516
|
`);
|
|
492
517
|
n.push(`--${t}--\r
|
|
493
518
|
`);
|
|
494
|
-
const
|
|
519
|
+
const o = n.reduce((l, u) => l + u.length, 0), i = new Uint8Array(o);
|
|
495
520
|
let a = 0;
|
|
496
|
-
for (const
|
|
497
|
-
|
|
498
|
-
typeof
|
|
521
|
+
for (const l of n)
|
|
522
|
+
i.set(
|
|
523
|
+
typeof l == "string" ? s.encode(l) : l,
|
|
499
524
|
a
|
|
500
|
-
), a +=
|
|
501
|
-
return { bytes:
|
|
525
|
+
), a += l.length;
|
|
526
|
+
return { bytes: i, contentType: r };
|
|
502
527
|
}
|
|
503
528
|
function fileToUint8Array(e) {
|
|
504
529
|
return new Promise((t) => {
|
|
@@ -508,7 +533,7 @@ function fileToUint8Array(e) {
|
|
|
508
533
|
}, r.readAsArrayBuffer(e);
|
|
509
534
|
});
|
|
510
535
|
}
|
|
511
|
-
var
|
|
536
|
+
var g, H, L, R, k, y, C, S, N, Z, U, X, O, ee;
|
|
512
537
|
class PHPRequestHandler {
|
|
513
538
|
/**
|
|
514
539
|
* @param php - The PHP instance.
|
|
@@ -540,30 +565,30 @@ class PHPRequestHandler {
|
|
|
540
565
|
* @returns The resolved filesystem path.
|
|
541
566
|
*/
|
|
542
567
|
d(this, O);
|
|
543
|
-
d(this,
|
|
568
|
+
d(this, g, void 0);
|
|
544
569
|
d(this, H, void 0);
|
|
545
570
|
d(this, L, void 0);
|
|
546
571
|
d(this, R, void 0);
|
|
547
572
|
d(this, k, void 0);
|
|
548
573
|
d(this, y, void 0);
|
|
549
574
|
d(this, C, void 0);
|
|
550
|
-
d(this,
|
|
551
|
-
p(this,
|
|
575
|
+
d(this, S, void 0);
|
|
576
|
+
p(this, S, new Semaphore({ concurrency: 1 }));
|
|
552
577
|
const {
|
|
553
578
|
documentRoot: s = "/www/",
|
|
554
579
|
absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : ""
|
|
555
580
|
} = r;
|
|
556
|
-
this.php = t, p(this,
|
|
557
|
-
const
|
|
558
|
-
p(this, L,
|
|
559
|
-
const
|
|
581
|
+
this.php = t, p(this, g, s);
|
|
582
|
+
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(":", ""));
|
|
584
|
+
const i = c(this, R) !== 443 && c(this, R) !== 80;
|
|
560
585
|
p(this, k, [
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
].join("")), p(this, y,
|
|
564
|
-
`${
|
|
565
|
-
|
|
566
|
-
|
|
586
|
+
c(this, L),
|
|
587
|
+
i ? `:${c(this, R)}` : ""
|
|
588
|
+
].join("")), p(this, y, o.pathname.replace(/\/+$/, "")), p(this, C, [
|
|
589
|
+
`${c(this, H)}://`,
|
|
590
|
+
c(this, k),
|
|
591
|
+
c(this, y)
|
|
567
592
|
].join(""));
|
|
568
593
|
}
|
|
569
594
|
/** @inheritDoc */
|
|
@@ -573,18 +598,18 @@ class PHPRequestHandler {
|
|
|
573
598
|
/** @inheritDoc */
|
|
574
599
|
internalUrlToPath(t) {
|
|
575
600
|
const r = new URL(t);
|
|
576
|
-
return r.pathname.startsWith(
|
|
601
|
+
return r.pathname.startsWith(c(this, y)) && (r.pathname = r.pathname.slice(c(this, y).length)), toRelativeUrl(r);
|
|
577
602
|
}
|
|
578
603
|
get isRequestRunning() {
|
|
579
|
-
return
|
|
604
|
+
return c(this, S).running > 0;
|
|
580
605
|
}
|
|
581
606
|
/** @inheritDoc */
|
|
582
607
|
get absoluteUrl() {
|
|
583
|
-
return
|
|
608
|
+
return c(this, C);
|
|
584
609
|
}
|
|
585
610
|
/** @inheritDoc */
|
|
586
611
|
get documentRoot() {
|
|
587
|
-
return
|
|
612
|
+
return c(this, g);
|
|
588
613
|
}
|
|
589
614
|
/** @inheritDoc */
|
|
590
615
|
async request(t) {
|
|
@@ -593,12 +618,12 @@ class PHPRequestHandler {
|
|
|
593
618
|
r ? void 0 : DEFAULT_BASE_URL
|
|
594
619
|
), n = removePathPrefix(
|
|
595
620
|
s.pathname,
|
|
596
|
-
|
|
597
|
-
),
|
|
598
|
-
return seemsLikeAPHPRequestHandlerPath(
|
|
621
|
+
c(this, y)
|
|
622
|
+
), 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);
|
|
599
624
|
}
|
|
600
625
|
}
|
|
601
|
-
|
|
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) {
|
|
602
627
|
if (!this.php.fileExists(t))
|
|
603
628
|
return new PHPResponse(
|
|
604
629
|
404,
|
|
@@ -623,9 +648,9 @@ P = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k =
|
|
|
623
648
|
},
|
|
624
649
|
r
|
|
625
650
|
);
|
|
626
|
-
}, U = new WeakSet(),
|
|
627
|
-
var n,
|
|
628
|
-
if (
|
|
651
|
+
}, U = new WeakSet(), X = async function(t, r) {
|
|
652
|
+
var n, o;
|
|
653
|
+
if (c(this, S).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
|
|
629
654
|
return console.warn(
|
|
630
655
|
"Possible deadlock: Called request() before the previous request() have finished. PHP likely issued an HTTP call to itself. Normally this would lead to infinite waiting as Request 1 holds the lock that the Request 2 is waiting to acquire. That's not useful, so PHPRequestHandler will return error 502 instead."
|
|
631
656
|
), new PHPResponse(
|
|
@@ -633,34 +658,34 @@ P = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k =
|
|
|
633
658
|
{},
|
|
634
659
|
new TextEncoder().encode("502 Bad Gateway")
|
|
635
660
|
);
|
|
636
|
-
const s = await
|
|
661
|
+
const s = await c(this, S).acquire();
|
|
637
662
|
try {
|
|
638
|
-
this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT",
|
|
663
|
+
this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", c(this, g)), this.php.addServerGlobalEntry(
|
|
639
664
|
"HTTPS",
|
|
640
|
-
|
|
665
|
+
c(this, C).startsWith("https://") ? "on" : ""
|
|
641
666
|
);
|
|
642
|
-
let
|
|
667
|
+
let i = "GET";
|
|
643
668
|
const a = {
|
|
644
|
-
host:
|
|
669
|
+
host: c(this, k),
|
|
645
670
|
...normalizeHeaders(t.headers || {})
|
|
646
671
|
};
|
|
647
|
-
let
|
|
648
|
-
if (typeof
|
|
649
|
-
|
|
650
|
-
const { bytes: h, contentType: m } = await encodeAsMultipart(
|
|
651
|
-
|
|
672
|
+
let l = t.body;
|
|
673
|
+
if (typeof l == "object" && !(l instanceof Uint8Array)) {
|
|
674
|
+
i = "POST";
|
|
675
|
+
const { bytes: h, contentType: m } = await encodeAsMultipart(l);
|
|
676
|
+
l = h, a["content-type"] = m;
|
|
652
677
|
}
|
|
653
|
-
let
|
|
678
|
+
let u;
|
|
654
679
|
try {
|
|
655
680
|
let h = r.pathname;
|
|
656
|
-
if ((
|
|
681
|
+
if ((o = t.headers) != null && o["x-rewrite-url"])
|
|
657
682
|
try {
|
|
658
683
|
h = new URL(
|
|
659
684
|
t.headers["x-rewrite-url"]
|
|
660
685
|
).pathname;
|
|
661
686
|
} catch {
|
|
662
687
|
}
|
|
663
|
-
|
|
688
|
+
u = f(this, O, ee).call(this, h);
|
|
664
689
|
} catch {
|
|
665
690
|
return new PHPResponse(
|
|
666
691
|
404,
|
|
@@ -671,21 +696,21 @@ P = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k =
|
|
|
671
696
|
return await this.php.run({
|
|
672
697
|
relativeUri: ensurePathPrefix(
|
|
673
698
|
toRelativeUrl(r),
|
|
674
|
-
|
|
699
|
+
c(this, y)
|
|
675
700
|
),
|
|
676
|
-
protocol:
|
|
677
|
-
method: t.method ||
|
|
678
|
-
body:
|
|
679
|
-
scriptPath:
|
|
701
|
+
protocol: c(this, H),
|
|
702
|
+
method: t.method || i,
|
|
703
|
+
body: l,
|
|
704
|
+
scriptPath: u,
|
|
680
705
|
headers: a
|
|
681
706
|
});
|
|
682
707
|
} finally {
|
|
683
708
|
s();
|
|
684
709
|
}
|
|
685
|
-
}, O = new WeakSet(),
|
|
686
|
-
let r = removePathPrefix(t,
|
|
687
|
-
r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r
|
|
688
|
-
const s = `${
|
|
710
|
+
}, O = new WeakSet(), ee = function(t) {
|
|
711
|
+
let r = removePathPrefix(t, c(this, y));
|
|
712
|
+
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
|
+
const s = `${c(this, g)}${r}`;
|
|
689
714
|
if (this.php.fileExists(s))
|
|
690
715
|
return s;
|
|
691
716
|
throw new Error(`File not found: ${s}`);
|
|
@@ -825,15 +850,15 @@ function getEmscriptenFsError(e) {
|
|
|
825
850
|
}
|
|
826
851
|
function rethrowFileSystemError(e = "") {
|
|
827
852
|
return function(r, s, n) {
|
|
828
|
-
const
|
|
829
|
-
n.value = function(...
|
|
853
|
+
const o = n.value;
|
|
854
|
+
n.value = function(...i) {
|
|
830
855
|
try {
|
|
831
|
-
return
|
|
856
|
+
return o.apply(this, i);
|
|
832
857
|
} catch (a) {
|
|
833
|
-
const
|
|
834
|
-
if (
|
|
835
|
-
const
|
|
836
|
-
throw new Error(`${m}: ${
|
|
858
|
+
const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
859
|
+
if (l in FileErrorCodes) {
|
|
860
|
+
const u = FileErrorCodes[l], h = typeof i[0] == "string" ? i[0] : null, m = h !== null ? e.replaceAll("{path}", h) : e;
|
|
861
|
+
throw new Error(`${m}: ${u}`, {
|
|
837
862
|
cause: a
|
|
838
863
|
});
|
|
839
864
|
}
|
|
@@ -845,7 +870,7 @@ function rethrowFileSystemError(e = "") {
|
|
|
845
870
|
const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map();
|
|
846
871
|
let lastRuntimeId = 0;
|
|
847
872
|
async function loadPHPRuntime(e, t = {}) {
|
|
848
|
-
const [r, s, n] = makePromise(),
|
|
873
|
+
const [r, s, n] = makePromise(), o = e.init(currentJsRuntime, {
|
|
849
874
|
onAbort(a) {
|
|
850
875
|
n(a), console.error(a);
|
|
851
876
|
},
|
|
@@ -861,10 +886,10 @@ async function loadPHPRuntime(e, t = {}) {
|
|
|
861
886
|
}
|
|
862
887
|
});
|
|
863
888
|
await r;
|
|
864
|
-
const
|
|
865
|
-
return
|
|
866
|
-
return loadedRuntimes.delete(
|
|
867
|
-
},
|
|
889
|
+
const i = ++lastRuntimeId;
|
|
890
|
+
return o.id = i, o.originalExit = o._exit, o._exit = function(a) {
|
|
891
|
+
return loadedRuntimes.delete(i), o.originalExit(a);
|
|
892
|
+
}, o[RuntimeId] = i, loadedRuntimes.set(i, o), i;
|
|
868
893
|
}
|
|
869
894
|
function getLoadedRuntime(e) {
|
|
870
895
|
return loadedRuntimes.get(e);
|
|
@@ -879,12 +904,12 @@ const currentJsRuntime = function() {
|
|
|
879
904
|
return e.unshift(t), e;
|
|
880
905
|
};
|
|
881
906
|
var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = (e, t, r, s) => {
|
|
882
|
-
for (var n = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t,
|
|
883
|
-
(
|
|
907
|
+
for (var n = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
908
|
+
(i = e[o]) && (n = (s ? i(t, r, n) : i(n)) || n);
|
|
884
909
|
return s && n && __defProp(t, r, n), n;
|
|
885
910
|
};
|
|
886
911
|
const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
|
|
887
|
-
var
|
|
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;
|
|
888
913
|
class BasePHP {
|
|
889
914
|
/**
|
|
890
915
|
* Initializes a PHP runtime.
|
|
@@ -894,45 +919,46 @@ class BasePHP {
|
|
|
894
919
|
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
895
920
|
*/
|
|
896
921
|
constructor(e, t) {
|
|
897
|
-
d(this, q);
|
|
898
922
|
d(this, B);
|
|
899
923
|
d(this, W);
|
|
924
|
+
d(this, q);
|
|
925
|
+
d(this, D);
|
|
900
926
|
d(this, $);
|
|
901
927
|
d(this, z);
|
|
902
|
-
d(this, D);
|
|
903
928
|
d(this, j);
|
|
904
929
|
d(this, G);
|
|
905
930
|
d(this, V);
|
|
931
|
+
d(this, Q);
|
|
906
932
|
d(this, Y);
|
|
907
933
|
d(this, J);
|
|
908
|
-
d(this,
|
|
934
|
+
d(this, x, void 0);
|
|
909
935
|
d(this, F, void 0);
|
|
910
936
|
d(this, A, void 0);
|
|
911
|
-
d(this,
|
|
937
|
+
d(this, w, void 0);
|
|
912
938
|
d(this, E, void 0);
|
|
913
939
|
d(this, v, void 0);
|
|
914
|
-
d(this,
|
|
940
|
+
d(this, P, void 0);
|
|
915
941
|
d(this, M, void 0);
|
|
916
|
-
p(this,
|
|
942
|
+
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(
|
|
917
943
|
new PHPRequestHandler(this, t)
|
|
918
944
|
));
|
|
919
945
|
}
|
|
920
946
|
addEventListener(e, t) {
|
|
921
|
-
|
|
947
|
+
c(this, P).has(e) || c(this, P).set(e, /* @__PURE__ */ new Set()), c(this, P).get(e).add(t);
|
|
922
948
|
}
|
|
923
949
|
removeEventListener(e, t) {
|
|
924
950
|
var r;
|
|
925
|
-
(r =
|
|
951
|
+
(r = c(this, P).get(e)) == null || r.delete(t);
|
|
926
952
|
}
|
|
927
953
|
dispatchEvent(e) {
|
|
928
|
-
const t =
|
|
954
|
+
const t = c(this, P).get(e.type);
|
|
929
955
|
if (t)
|
|
930
956
|
for (const r of t)
|
|
931
957
|
r(e);
|
|
932
958
|
}
|
|
933
959
|
/** @inheritDoc */
|
|
934
960
|
async onMessage(e) {
|
|
935
|
-
|
|
961
|
+
c(this, M).push(e);
|
|
936
962
|
}
|
|
937
963
|
/** @inheritDoc */
|
|
938
964
|
async setSpawnHandler(handler) {
|
|
@@ -963,7 +989,7 @@ class BasePHP {
|
|
|
963
989
|
if (!t)
|
|
964
990
|
throw new Error("Invalid PHP runtime id.");
|
|
965
991
|
this[__private__dont__use] = t, t.onMessage = async (r) => {
|
|
966
|
-
for (const s of
|
|
992
|
+
for (const s of c(this, M)) {
|
|
967
993
|
const n = await s(r);
|
|
968
994
|
if (n)
|
|
969
995
|
return n;
|
|
@@ -988,7 +1014,7 @@ class BasePHP {
|
|
|
988
1014
|
}
|
|
989
1015
|
/** @inheritDoc */
|
|
990
1016
|
setPhpIniPath(e) {
|
|
991
|
-
if (
|
|
1017
|
+
if (c(this, w))
|
|
992
1018
|
throw new Error("Cannot set PHP ini path after calling run().");
|
|
993
1019
|
p(this, F, e), this[__private__dont__use].ccall(
|
|
994
1020
|
"wasm_set_phpini_path",
|
|
@@ -999,9 +1025,9 @@ class BasePHP {
|
|
|
999
1025
|
}
|
|
1000
1026
|
/** @inheritDoc */
|
|
1001
1027
|
setPhpIniEntry(e, t) {
|
|
1002
|
-
if (
|
|
1028
|
+
if (c(this, w))
|
|
1003
1029
|
throw new Error("Cannot set PHP ini entries after calling run().");
|
|
1004
|
-
|
|
1030
|
+
c(this, x).push([e, t]);
|
|
1005
1031
|
}
|
|
1006
1032
|
/** @inheritDoc */
|
|
1007
1033
|
chdir(e) {
|
|
@@ -1018,20 +1044,27 @@ class BasePHP {
|
|
|
1018
1044
|
const t = await this.semaphore.acquire();
|
|
1019
1045
|
let r;
|
|
1020
1046
|
try {
|
|
1021
|
-
|
|
1047
|
+
if (c(this, w) || (f(this, B, te).call(this), p(this, w, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
|
|
1048
|
+
throw new Error(
|
|
1049
|
+
`The script path "${e.scriptPath}" does not exist.`
|
|
1050
|
+
);
|
|
1051
|
+
f(this, G, le).call(this, e.scriptPath || ""), f(this, q, se).call(this, e.relativeUri || ""), f(this, $, ie).call(this, e.method || "GET");
|
|
1022
1052
|
const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443";
|
|
1023
|
-
f(this,
|
|
1024
|
-
const
|
|
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);
|
|
1054
|
+
const o = e.env || {};
|
|
1055
|
+
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);
|
|
1025
1058
|
if (e.throwOnError && i.exitCode !== 0) {
|
|
1026
|
-
const
|
|
1059
|
+
const a = {
|
|
1027
1060
|
stdout: i.text,
|
|
1028
1061
|
stderr: i.errors
|
|
1029
1062
|
};
|
|
1030
|
-
console.warn("PHP.run() output was:",
|
|
1031
|
-
const
|
|
1032
|
-
`PHP.run() failed with exit code ${i.exitCode} and the following output`
|
|
1063
|
+
console.warn("PHP.run() output was:", a);
|
|
1064
|
+
const l = new Error(
|
|
1065
|
+
`PHP.run() failed with exit code ${i.exitCode} and the following output: ` + i.errors
|
|
1033
1066
|
);
|
|
1034
|
-
throw
|
|
1067
|
+
throw l.output = a, console.error(l), l;
|
|
1035
1068
|
}
|
|
1036
1069
|
return i;
|
|
1037
1070
|
} finally {
|
|
@@ -1045,18 +1078,18 @@ class BasePHP {
|
|
|
1045
1078
|
}
|
|
1046
1079
|
}
|
|
1047
1080
|
addServerGlobalEntry(e, t) {
|
|
1048
|
-
|
|
1081
|
+
c(this, v)[e] = t;
|
|
1049
1082
|
}
|
|
1050
1083
|
defineConstant(e, t) {
|
|
1051
1084
|
let r = {};
|
|
1052
1085
|
try {
|
|
1053
1086
|
r = JSON.parse(
|
|
1054
|
-
this.fileExists("/
|
|
1087
|
+
this.fileExists("/internal/consts.json") && this.readFileAsText("/internal/consts.json") || "{}"
|
|
1055
1088
|
);
|
|
1056
1089
|
} catch {
|
|
1057
1090
|
}
|
|
1058
1091
|
this.writeFile(
|
|
1059
|
-
"/
|
|
1092
|
+
"/internal/consts.json",
|
|
1060
1093
|
JSON.stringify({
|
|
1061
1094
|
...r,
|
|
1062
1095
|
[e]: t
|
|
@@ -1141,9 +1174,9 @@ class BasePHP {
|
|
|
1141
1174
|
this.exit();
|
|
1142
1175
|
} catch {
|
|
1143
1176
|
}
|
|
1144
|
-
if (this.initializeRuntime(e),
|
|
1177
|
+
if (this.initializeRuntime(e), c(this, F) && this.setPhpIniPath(c(this, F)), c(this, A) && this.setSapiName(c(this, A)), this.requestHandler) {
|
|
1145
1178
|
const r = this.documentRoot;
|
|
1146
|
-
|
|
1179
|
+
copyFS(t, this[__private__dont__use].FS, r);
|
|
1147
1180
|
}
|
|
1148
1181
|
}
|
|
1149
1182
|
exit(e = 0) {
|
|
@@ -1154,23 +1187,23 @@ class BasePHP {
|
|
|
1154
1187
|
this[__private__dont__use]._exit(e);
|
|
1155
1188
|
} catch {
|
|
1156
1189
|
}
|
|
1157
|
-
p(this,
|
|
1190
|
+
p(this, w, !1), p(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1158
1191
|
}
|
|
1159
1192
|
}
|
|
1160
|
-
|
|
1161
|
-
if (this.setPhpIniEntry("auto_prepend_file", "/
|
|
1162
|
-
"/
|
|
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() {
|
|
1194
|
+
if (this.setPhpIniEntry("auto_prepend_file", "/internal/consts.php"), this.fileExists("/internal/consts.php") || this.writeFile(
|
|
1195
|
+
"/internal/consts.php",
|
|
1163
1196
|
`<?php
|
|
1164
|
-
if(file_exists('/
|
|
1165
|
-
$consts = json_decode(file_get_contents('/
|
|
1197
|
+
if(file_exists('/internal/consts.json')) {
|
|
1198
|
+
$consts = json_decode(file_get_contents('/internal/consts.json'), true);
|
|
1166
1199
|
foreach ($consts as $const => $value) {
|
|
1167
1200
|
if (!defined($const) && is_scalar($value)) {
|
|
1168
1201
|
define($const, $value);
|
|
1169
1202
|
}
|
|
1170
1203
|
}
|
|
1171
1204
|
}`
|
|
1172
|
-
),
|
|
1173
|
-
const e =
|
|
1205
|
+
), c(this, x).length > 0) {
|
|
1206
|
+
const e = c(this, x).map(([t, r]) => `${t}=${r}`).join(`
|
|
1174
1207
|
`) + `
|
|
1175
1208
|
|
|
1176
1209
|
`;
|
|
@@ -1182,8 +1215,8 @@ S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E =
|
|
|
1182
1215
|
);
|
|
1183
1216
|
}
|
|
1184
1217
|
this[__private__dont__use].ccall("php_wasm_init", null, [], []);
|
|
1185
|
-
},
|
|
1186
|
-
const e = "/
|
|
1218
|
+
}, W = new WeakSet(), re = function() {
|
|
1219
|
+
const e = "/internal/headers.json";
|
|
1187
1220
|
if (!this.fileExists(e))
|
|
1188
1221
|
throw new Error(
|
|
1189
1222
|
"SAPI Error: Could not find response headers file."
|
|
@@ -1192,14 +1225,14 @@ S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E =
|
|
|
1192
1225
|
for (const s of t.headers) {
|
|
1193
1226
|
if (!s.includes(": "))
|
|
1194
1227
|
continue;
|
|
1195
|
-
const n = s.indexOf(": "),
|
|
1196
|
-
|
|
1228
|
+
const n = s.indexOf(": "), o = s.substring(0, n).toLowerCase(), i = s.substring(n + 2);
|
|
1229
|
+
o in r || (r[o] = []), r[o].push(i);
|
|
1197
1230
|
}
|
|
1198
1231
|
return {
|
|
1199
1232
|
headers: r,
|
|
1200
1233
|
httpStatusCode: t.status
|
|
1201
1234
|
};
|
|
1202
|
-
},
|
|
1235
|
+
}, q = new WeakSet(), se = function(e) {
|
|
1203
1236
|
if (this[__private__dont__use].ccall(
|
|
1204
1237
|
"wasm_set_request_uri",
|
|
1205
1238
|
null,
|
|
@@ -1214,7 +1247,7 @@ S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E =
|
|
|
1214
1247
|
[t]
|
|
1215
1248
|
);
|
|
1216
1249
|
}
|
|
1217
|
-
},
|
|
1250
|
+
}, D = new WeakSet(), ne = function(e, t) {
|
|
1218
1251
|
this[__private__dont__use].ccall(
|
|
1219
1252
|
"wasm_set_request_host",
|
|
1220
1253
|
null,
|
|
@@ -1232,14 +1265,14 @@ S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E =
|
|
|
1232
1265
|
[NUMBER],
|
|
1233
1266
|
[r]
|
|
1234
1267
|
), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
|
|
1235
|
-
},
|
|
1268
|
+
}, $ = new WeakSet(), ie = function(e) {
|
|
1236
1269
|
this[__private__dont__use].ccall(
|
|
1237
1270
|
"wasm_set_request_method",
|
|
1238
1271
|
null,
|
|
1239
1272
|
[STRING],
|
|
1240
1273
|
[e]
|
|
1241
1274
|
);
|
|
1242
|
-
},
|
|
1275
|
+
}, z = new WeakSet(), oe = function(e) {
|
|
1243
1276
|
e.cookie && this[__private__dont__use].ccall(
|
|
1244
1277
|
"wasm_set_cookies",
|
|
1245
1278
|
null,
|
|
@@ -1263,7 +1296,7 @@ S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E =
|
|
|
1263
1296
|
e[t]
|
|
1264
1297
|
);
|
|
1265
1298
|
}
|
|
1266
|
-
}, j = new WeakSet(),
|
|
1299
|
+
}, j = new WeakSet(), ae = function(e) {
|
|
1267
1300
|
let t, r;
|
|
1268
1301
|
typeof e == "string" ? (console.warn(
|
|
1269
1302
|
"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"
|
|
@@ -1286,38 +1319,46 @@ S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E =
|
|
|
1286
1319
|
[NUMBER],
|
|
1287
1320
|
[r]
|
|
1288
1321
|
), s;
|
|
1289
|
-
}, G = new WeakSet(),
|
|
1322
|
+
}, G = new WeakSet(), le = function(e) {
|
|
1290
1323
|
this[__private__dont__use].ccall(
|
|
1291
1324
|
"wasm_set_path_translated",
|
|
1292
1325
|
null,
|
|
1293
1326
|
[STRING],
|
|
1294
1327
|
[e]
|
|
1295
1328
|
);
|
|
1296
|
-
}, V = new WeakSet(),
|
|
1297
|
-
for (const e in
|
|
1329
|
+
}, V = new WeakSet(), ce = function() {
|
|
1330
|
+
for (const e in c(this, v))
|
|
1298
1331
|
this[__private__dont__use].ccall(
|
|
1299
1332
|
"wasm_add_SERVER_entry",
|
|
1300
1333
|
null,
|
|
1301
1334
|
[STRING, STRING],
|
|
1302
|
-
[e,
|
|
1335
|
+
[e, c(this, v)[e]]
|
|
1303
1336
|
);
|
|
1304
|
-
},
|
|
1337
|
+
}, Q = new WeakSet(), ue = function(e, t) {
|
|
1338
|
+
this[__private__dont__use].ccall(
|
|
1339
|
+
"wasm_add_ENV_entry",
|
|
1340
|
+
null,
|
|
1341
|
+
[STRING, STRING],
|
|
1342
|
+
[e, t]
|
|
1343
|
+
);
|
|
1344
|
+
}, Y = new WeakSet(), de = function(e) {
|
|
1305
1345
|
this[__private__dont__use].ccall(
|
|
1306
1346
|
"wasm_set_php_code",
|
|
1307
1347
|
null,
|
|
1308
1348
|
[STRING],
|
|
1309
1349
|
[e]
|
|
1310
1350
|
);
|
|
1311
|
-
}, J = new WeakSet(),
|
|
1351
|
+
}, J = new WeakSet(), he = async function() {
|
|
1312
1352
|
var n;
|
|
1313
1353
|
let e, t;
|
|
1314
1354
|
try {
|
|
1315
|
-
e = await new Promise((
|
|
1316
|
-
var
|
|
1317
|
-
t = (
|
|
1355
|
+
e = await new Promise((o, i) => {
|
|
1356
|
+
var l;
|
|
1357
|
+
t = (u) => {
|
|
1358
|
+
console.error(u), console.error(u.error);
|
|
1318
1359
|
const h = new Error("Rethrown");
|
|
1319
|
-
h.cause =
|
|
1320
|
-
}, (
|
|
1360
|
+
h.cause = u.error, h.betterMessage = u.message, i(h);
|
|
1361
|
+
}, (l = c(this, E)) == null || l.addEventListener(
|
|
1321
1362
|
"error",
|
|
1322
1363
|
t
|
|
1323
1364
|
);
|
|
@@ -1328,27 +1369,27 @@ S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E =
|
|
|
1328
1369
|
[],
|
|
1329
1370
|
{ async: !0 }
|
|
1330
1371
|
);
|
|
1331
|
-
return a instanceof Promise ? a.then(
|
|
1372
|
+
return a instanceof Promise ? a.then(o, i) : o(a);
|
|
1332
1373
|
});
|
|
1333
|
-
} catch (
|
|
1334
|
-
for (const
|
|
1335
|
-
typeof this[
|
|
1374
|
+
} catch (o) {
|
|
1375
|
+
for (const u in this)
|
|
1376
|
+
typeof this[u] == "function" && (this[u] = () => {
|
|
1336
1377
|
throw new Error(
|
|
1337
1378
|
"PHP runtime has crashed – see the earlier error for details."
|
|
1338
1379
|
);
|
|
1339
1380
|
});
|
|
1340
1381
|
this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
|
|
1341
|
-
const
|
|
1342
|
-
throw
|
|
1382
|
+
const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, l = new Error(a);
|
|
1383
|
+
throw l.cause = i, console.error(l), l;
|
|
1343
1384
|
} finally {
|
|
1344
|
-
(n =
|
|
1385
|
+
(n = c(this, E)) == null || n.removeEventListener("error", t), p(this, v, {});
|
|
1345
1386
|
}
|
|
1346
|
-
const { headers: r, httpStatusCode: s } = f(this,
|
|
1387
|
+
const { headers: r, httpStatusCode: s } = f(this, W, re).call(this);
|
|
1347
1388
|
return new PHPResponse(
|
|
1348
1389
|
s,
|
|
1349
1390
|
r,
|
|
1350
|
-
this.readFileAsBuffer("/
|
|
1351
|
-
this.readFileAsText("/
|
|
1391
|
+
this.readFileAsBuffer("/internal/stdout"),
|
|
1392
|
+
this.readFileAsText("/internal/stderr"),
|
|
1352
1393
|
e
|
|
1353
1394
|
);
|
|
1354
1395
|
};
|
|
@@ -1388,28 +1429,23 @@ function normalizeHeaders(e) {
|
|
|
1388
1429
|
t[r.toLowerCase()] = e[r];
|
|
1389
1430
|
return t;
|
|
1390
1431
|
}
|
|
1391
|
-
function
|
|
1432
|
+
function copyFS(e, t, r) {
|
|
1392
1433
|
let s;
|
|
1393
1434
|
try {
|
|
1394
|
-
s =
|
|
1435
|
+
s = e.lookupPath(r);
|
|
1395
1436
|
} catch {
|
|
1396
1437
|
return;
|
|
1397
1438
|
}
|
|
1398
1439
|
if (!("contents" in s.node))
|
|
1399
1440
|
return;
|
|
1400
|
-
|
|
1401
|
-
|
|
1441
|
+
if (!e.isDir(s.node.mode)) {
|
|
1442
|
+
t.writeFile(r, e.readFile(r));
|
|
1402
1443
|
return;
|
|
1403
|
-
} catch {
|
|
1404
1444
|
}
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
e.mkdirTree(r);
|
|
1410
|
-
const n = t.readdir(r).filter((i) => i !== "." && i !== "..");
|
|
1411
|
-
for (const i of n)
|
|
1412
|
-
recreateMemFS(e, t, joinPaths(r, i));
|
|
1445
|
+
t.mkdirTree(r);
|
|
1446
|
+
const n = e.readdir(r).filter((o) => o !== "." && o !== "..");
|
|
1447
|
+
for (const o of n)
|
|
1448
|
+
copyFS(e, t, joinPaths(r, o));
|
|
1413
1449
|
}
|
|
1414
1450
|
/**
|
|
1415
1451
|
* @license
|
|
@@ -1459,50 +1495,50 @@ function expose(e, t = globalThis, r = ["*"]) {
|
|
|
1459
1495
|
console.warn(`Invalid origin '${n.origin}' for comlink proxy`);
|
|
1460
1496
|
return;
|
|
1461
1497
|
}
|
|
1462
|
-
const { id:
|
|
1463
|
-
let
|
|
1498
|
+
const { id: o, type: i, path: a } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(fromWireValue);
|
|
1499
|
+
let u;
|
|
1464
1500
|
try {
|
|
1465
1501
|
const h = a.slice(0, -1).reduce((_, I) => _[I], e), m = a.reduce((_, I) => _[I], e);
|
|
1466
|
-
switch (
|
|
1502
|
+
switch (i) {
|
|
1467
1503
|
case "GET":
|
|
1468
|
-
|
|
1504
|
+
u = m;
|
|
1469
1505
|
break;
|
|
1470
1506
|
case "SET":
|
|
1471
|
-
h[a.slice(-1)[0]] = fromWireValue(n.data.value),
|
|
1507
|
+
h[a.slice(-1)[0]] = fromWireValue(n.data.value), u = !0;
|
|
1472
1508
|
break;
|
|
1473
1509
|
case "APPLY":
|
|
1474
|
-
|
|
1510
|
+
u = m.apply(h, l);
|
|
1475
1511
|
break;
|
|
1476
1512
|
case "CONSTRUCT":
|
|
1477
1513
|
{
|
|
1478
|
-
const _ = new m(...
|
|
1479
|
-
|
|
1514
|
+
const _ = new m(...l);
|
|
1515
|
+
u = proxy(_);
|
|
1480
1516
|
}
|
|
1481
1517
|
break;
|
|
1482
1518
|
case "ENDPOINT":
|
|
1483
1519
|
{
|
|
1484
1520
|
const { port1: _, port2: I } = new MessageChannel();
|
|
1485
|
-
expose(e, I),
|
|
1521
|
+
expose(e, I), u = transfer(_, [_]);
|
|
1486
1522
|
}
|
|
1487
1523
|
break;
|
|
1488
1524
|
case "RELEASE":
|
|
1489
|
-
|
|
1525
|
+
u = void 0;
|
|
1490
1526
|
break;
|
|
1491
1527
|
default:
|
|
1492
1528
|
return;
|
|
1493
1529
|
}
|
|
1494
1530
|
} catch (h) {
|
|
1495
|
-
|
|
1531
|
+
u = { value: h, [throwMarker]: 0 };
|
|
1496
1532
|
}
|
|
1497
|
-
Promise.resolve(
|
|
1533
|
+
Promise.resolve(u).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
|
|
1498
1534
|
const [m, _] = toWireValue(h);
|
|
1499
|
-
t.postMessage(Object.assign(Object.assign({}, m), { id:
|
|
1535
|
+
t.postMessage(Object.assign(Object.assign({}, m), { id: o }), _), i === "RELEASE" && (t.removeEventListener("message", s), closeEndPoint(t), finalizer in e && typeof e[finalizer] == "function" && e[finalizer]());
|
|
1500
1536
|
}).catch((h) => {
|
|
1501
1537
|
const [m, _] = toWireValue({
|
|
1502
1538
|
value: new TypeError("Unserializable return value"),
|
|
1503
1539
|
[throwMarker]: 0
|
|
1504
1540
|
});
|
|
1505
|
-
t.postMessage(Object.assign(Object.assign({}, m), { id:
|
|
1541
|
+
t.postMessage(Object.assign(Object.assign({}, m), { id: o }), _);
|
|
1506
1542
|
});
|
|
1507
1543
|
}), t.start && t.start();
|
|
1508
1544
|
}
|
|
@@ -1541,55 +1577,55 @@ function createProxy(e, t = [], r = function() {
|
|
|
1541
1577
|
}) {
|
|
1542
1578
|
let s = !1;
|
|
1543
1579
|
const n = new Proxy(r, {
|
|
1544
|
-
get(
|
|
1545
|
-
if (throwIfProxyReleased(s),
|
|
1580
|
+
get(o, i) {
|
|
1581
|
+
if (throwIfProxyReleased(s), i === releaseProxy)
|
|
1546
1582
|
return () => {
|
|
1547
1583
|
unregisterProxy(n), releaseEndpoint(e), s = !0;
|
|
1548
1584
|
};
|
|
1549
|
-
if (
|
|
1585
|
+
if (i === "then") {
|
|
1550
1586
|
if (t.length === 0)
|
|
1551
1587
|
return { then: () => n };
|
|
1552
1588
|
const a = requestResponseMessage(e, {
|
|
1553
1589
|
type: "GET",
|
|
1554
|
-
path: t.map((
|
|
1590
|
+
path: t.map((l) => l.toString())
|
|
1555
1591
|
}).then(fromWireValue);
|
|
1556
1592
|
return a.then.bind(a);
|
|
1557
1593
|
}
|
|
1558
|
-
return createProxy(e, [...t,
|
|
1594
|
+
return createProxy(e, [...t, i]);
|
|
1559
1595
|
},
|
|
1560
|
-
set(
|
|
1596
|
+
set(o, i, a) {
|
|
1561
1597
|
throwIfProxyReleased(s);
|
|
1562
|
-
const [
|
|
1598
|
+
const [l, u] = toWireValue(a);
|
|
1563
1599
|
return requestResponseMessage(e, {
|
|
1564
1600
|
type: "SET",
|
|
1565
|
-
path: [...t,
|
|
1566
|
-
value:
|
|
1567
|
-
},
|
|
1601
|
+
path: [...t, i].map((h) => h.toString()),
|
|
1602
|
+
value: l
|
|
1603
|
+
}, u).then(fromWireValue);
|
|
1568
1604
|
},
|
|
1569
|
-
apply(
|
|
1605
|
+
apply(o, i, a) {
|
|
1570
1606
|
throwIfProxyReleased(s);
|
|
1571
|
-
const
|
|
1572
|
-
if (
|
|
1607
|
+
const l = t[t.length - 1];
|
|
1608
|
+
if (l === createEndpoint)
|
|
1573
1609
|
return requestResponseMessage(e, {
|
|
1574
1610
|
type: "ENDPOINT"
|
|
1575
1611
|
}).then(fromWireValue);
|
|
1576
|
-
if (
|
|
1612
|
+
if (l === "bind")
|
|
1577
1613
|
return createProxy(e, t.slice(0, -1));
|
|
1578
|
-
const [
|
|
1614
|
+
const [u, h] = processArguments(a);
|
|
1579
1615
|
return requestResponseMessage(e, {
|
|
1580
1616
|
type: "APPLY",
|
|
1581
1617
|
path: t.map((m) => m.toString()),
|
|
1582
|
-
argumentList:
|
|
1618
|
+
argumentList: u
|
|
1583
1619
|
}, h).then(fromWireValue);
|
|
1584
1620
|
},
|
|
1585
|
-
construct(
|
|
1621
|
+
construct(o, i) {
|
|
1586
1622
|
throwIfProxyReleased(s);
|
|
1587
|
-
const [a,
|
|
1623
|
+
const [a, l] = processArguments(i);
|
|
1588
1624
|
return requestResponseMessage(e, {
|
|
1589
1625
|
type: "CONSTRUCT",
|
|
1590
|
-
path: t.map((
|
|
1626
|
+
path: t.map((u) => u.toString()),
|
|
1591
1627
|
argumentList: a
|
|
1592
|
-
},
|
|
1628
|
+
}, l).then(fromWireValue);
|
|
1593
1629
|
}
|
|
1594
1630
|
});
|
|
1595
1631
|
return registerProxy(n, e), n;
|
|
@@ -1647,8 +1683,8 @@ function fromWireValue(e) {
|
|
|
1647
1683
|
function requestResponseMessage(e, t, r) {
|
|
1648
1684
|
return new Promise((s) => {
|
|
1649
1685
|
const n = generateUUID();
|
|
1650
|
-
e.addEventListener("message", function i
|
|
1651
|
-
!
|
|
1686
|
+
e.addEventListener("message", function o(i) {
|
|
1687
|
+
!i.data || !i.data.id || i.data.id !== n || (e.removeEventListener("message", o), s(i.data));
|
|
1652
1688
|
}), e.start && e.start(), e.postMessage(Object.assign({ id: n }, t), r);
|
|
1653
1689
|
});
|
|
1654
1690
|
}
|
|
@@ -1659,14 +1695,14 @@ function consumeAPI(e) {
|
|
|
1659
1695
|
setupTransferHandlers();
|
|
1660
1696
|
const t = e instanceof Worker ? e : windowEndpoint(e), r = wrap(t), s = proxyClone(r);
|
|
1661
1697
|
return new Proxy(s, {
|
|
1662
|
-
get: (n,
|
|
1663
|
-
for (let
|
|
1698
|
+
get: (n, o) => o === "isConnected" ? async () => {
|
|
1699
|
+
for (let i = 0; i < 10; i++)
|
|
1664
1700
|
try {
|
|
1665
1701
|
await runWithTimeout(r.isConnected(), 200);
|
|
1666
1702
|
break;
|
|
1667
1703
|
} catch {
|
|
1668
1704
|
}
|
|
1669
|
-
} : r[
|
|
1705
|
+
} : r[o]
|
|
1670
1706
|
});
|
|
1671
1707
|
}
|
|
1672
1708
|
async function runWithTimeout(e, t) {
|
|
@@ -1678,10 +1714,10 @@ function exposeAPI(e, t) {
|
|
|
1678
1714
|
setupTransferHandlers();
|
|
1679
1715
|
const r = Promise.resolve();
|
|
1680
1716
|
let s, n;
|
|
1681
|
-
const
|
|
1682
|
-
s =
|
|
1683
|
-
}),
|
|
1684
|
-
get: (
|
|
1717
|
+
const o = new Promise((l, u) => {
|
|
1718
|
+
s = l, n = u;
|
|
1719
|
+
}), i = proxyClone(e), a = new Proxy(i, {
|
|
1720
|
+
get: (l, u) => u === "isConnected" ? () => r : u === "isReady" ? () => o : u in l ? l[u] : t == null ? void 0 : t[u]
|
|
1685
1721
|
});
|
|
1686
1722
|
return expose(
|
|
1687
1723
|
a,
|
|
@@ -1817,9 +1853,9 @@ class WebPHP extends BasePHP {
|
|
|
1817
1853
|
);
|
|
1818
1854
|
}
|
|
1819
1855
|
static async loadRuntime(t, r = {}) {
|
|
1820
|
-
var
|
|
1856
|
+
var o;
|
|
1821
1857
|
const s = r.loadAllExtensions ? "kitchen-sink" : "light", n = await getPHPLoaderModule(t, s);
|
|
1822
|
-
return (
|
|
1858
|
+
return (o = r.downloadMonitor) == null || o.expectAssets({
|
|
1823
1859
|
[n.dependencyFilename]: n.dependenciesTotalSize
|
|
1824
1860
|
}), await loadPHPRuntime(n, {
|
|
1825
1861
|
...r.emscriptenOptions || {},
|
|
@@ -1961,11 +1997,11 @@ async function registerServiceWorker(e, t, r) {
|
|
|
1961
1997
|
updateViaCache: "none"
|
|
1962
1998
|
})).update(), navigator.serviceWorker.addEventListener(
|
|
1963
1999
|
"message",
|
|
1964
|
-
async function(
|
|
1965
|
-
if (console.debug("[window][sw] Message from ServiceWorker",
|
|
2000
|
+
async function(i) {
|
|
2001
|
+
if (console.debug("[window][sw] Message from ServiceWorker", i), t && i.data.scope !== t)
|
|
1966
2002
|
return;
|
|
1967
|
-
const a =
|
|
1968
|
-
|
|
2003
|
+
const a = i.data.args || [], l = i.data.method, u = await e[l](...a);
|
|
2004
|
+
i.source.postMessage(responseTo(i.data.requestId, u));
|
|
1969
2005
|
}
|
|
1970
2006
|
), s.startMessages();
|
|
1971
2007
|
}
|
|
@@ -1973,16 +2009,16 @@ async function spawnPHPWorkerThread(e, t = {}) {
|
|
|
1973
2009
|
e = addQueryParams(e, t);
|
|
1974
2010
|
const r = new Worker(e, { type: "module" });
|
|
1975
2011
|
return new Promise((s, n) => {
|
|
1976
|
-
r.onerror = (
|
|
2012
|
+
r.onerror = (i) => {
|
|
1977
2013
|
const a = new Error(
|
|
1978
|
-
`WebWorker failed to load at ${e}. ${
|
|
2014
|
+
`WebWorker failed to load at ${e}. ${i.message ? `Original error: ${i.message}` : ""}`
|
|
1979
2015
|
);
|
|
1980
|
-
a.filename =
|
|
2016
|
+
a.filename = i.filename, n(a);
|
|
1981
2017
|
};
|
|
1982
|
-
function i
|
|
1983
|
-
|
|
2018
|
+
function o(i) {
|
|
2019
|
+
i.data === "worker-script-started" && (s(r), r.removeEventListener("message", o));
|
|
1984
2020
|
}
|
|
1985
|
-
r.addEventListener("message",
|
|
2021
|
+
r.addEventListener("message", o);
|
|
1986
2022
|
});
|
|
1987
2023
|
}
|
|
1988
2024
|
function addQueryParams(e, t) {
|
|
@@ -1991,8 +2027,8 @@ function addQueryParams(e, t) {
|
|
|
1991
2027
|
const r = new URL(e);
|
|
1992
2028
|
for (const [s, n] of Object.entries(t))
|
|
1993
2029
|
if (Array.isArray(n))
|
|
1994
|
-
for (const
|
|
1995
|
-
r.searchParams.append(s,
|
|
2030
|
+
for (const o of n)
|
|
2031
|
+
r.searchParams.append(s, o);
|
|
1996
2032
|
else
|
|
1997
2033
|
r.searchParams.set(s, n);
|
|
1998
2034
|
return r.toString();
|