@php-wasm/universal 0.9.14 → 0.9.16
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/LICENSE +339 -0
- package/README.md +0 -0
- package/index.cjs +9 -12
- package/index.d.ts +1605 -1
- package/index.js +164 -691
- package/package.json +52 -42
- package/lib/emscripten-types.d.ts +0 -265
- package/lib/encode-as-multipart.d.ts +0 -10
- package/lib/error-event-polyfill.d.ts +0 -30
- package/lib/fs-helpers.d.ts +0 -94
- package/lib/http-cookie-store.d.ts +0 -8
- package/lib/index.d.ts +0 -32
- package/lib/ini.d.ts +0 -45
- package/lib/is-exit-code-zero.d.ts +0 -7
- package/lib/iterate-files.d.ts +0 -26
- package/lib/load-php-runtime.d.ts +0 -150
- package/lib/php-process-manager.d.ts +0 -104
- package/lib/php-request-handler.d.ts +0 -219
- package/lib/php-response.d.ts +0 -55
- package/lib/php-worker.d.ts +0 -77
- package/lib/php.d.ts +0 -314
- package/lib/proxy-file-system.d.ts +0 -7
- package/lib/rethrow-file-system-error.d.ts +0 -18
- package/lib/rotate-php-runtime.d.ts +0 -24
- package/lib/stream-read-file-from-php.d.ts +0 -5
- package/lib/supported-php-extensions.d.ts +0 -7
- package/lib/supported-php-versions.d.ts +0 -4
- package/lib/universal-php.d.ts +0 -121
- package/lib/urls.d.ts +0 -46
- package/lib/wasm-error-reporting.d.ts +0 -26
- package/lib/write-files-stream-to-php.d.ts +0 -5
- package/lib/write-files.d.ts +0 -28
package/index.js
CHANGED
|
@@ -2,82 +2,17 @@ var V = (t, e, r) => {
|
|
|
2
2
|
if (!e.has(t))
|
|
3
3
|
throw TypeError("Cannot " + r);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
5
|
+
var c = (t, e, r) => (V(t, e, "read from private field"), r ? r.call(t) : e.get(t)), u = (t, e, r) => {
|
|
6
6
|
if (e.has(t))
|
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
|
8
8
|
e instanceof WeakSet ? e.add(t) : e.set(t, r);
|
|
9
9
|
}, h = (t, e, r, s) => (V(t, e, "write to private field"), s ? s.call(t, r) : e.set(t, r), r);
|
|
10
10
|
var d = (t, e, r) => (V(t, e, "access private method"), r);
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
typeof WorkerGlobalScope < "u" && // @ts-ignore
|
|
17
|
-
self instanceof WorkerGlobalScope ? "WORKER" : "NODE"
|
|
18
|
-
);
|
|
19
|
-
}();
|
|
20
|
-
if (currentJsRuntime$1 === "NODE") {
|
|
21
|
-
let t = function(r) {
|
|
22
|
-
return new Promise(function(s, i) {
|
|
23
|
-
r.onload = r.onerror = function(n) {
|
|
24
|
-
r.onload = r.onerror = null, n.type === "load" ? s(r.result) : i(new Error("Failed to read the blob/file"));
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
}, e = function() {
|
|
28
|
-
const r = new Uint8Array([1, 2, 3, 4]), i = new File([r], "test").stream();
|
|
29
|
-
try {
|
|
30
|
-
return i.getReader({ mode: "byob" }), !0;
|
|
31
|
-
} catch {
|
|
32
|
-
return !1;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
if (typeof File > "u") {
|
|
36
|
-
class r extends Blob {
|
|
37
|
-
constructor(i, n, o) {
|
|
38
|
-
super(i);
|
|
39
|
-
let a;
|
|
40
|
-
o != null && o.lastModified && (a = /* @__PURE__ */ new Date()), (!a || isNaN(a.getFullYear())) && (a = /* @__PURE__ */ new Date()), this.lastModifiedDate = a, this.lastModified = a.getMilliseconds(), this.name = n || "";
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
global.File = r;
|
|
44
|
-
}
|
|
45
|
-
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
|
|
46
|
-
const s = new FileReader();
|
|
47
|
-
return s.readAsArrayBuffer(this), t(s);
|
|
48
|
-
}), typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
|
|
49
|
-
const s = new FileReader();
|
|
50
|
-
return s.readAsText(this), t(s);
|
|
51
|
-
}), (typeof Blob.prototype.stream > "u" || !e()) && (Blob.prototype.stream = function() {
|
|
52
|
-
let r = 0;
|
|
53
|
-
const s = this;
|
|
54
|
-
return new ReadableStream({
|
|
55
|
-
type: "bytes",
|
|
56
|
-
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
57
|
-
// this if needed.
|
|
58
|
-
autoAllocateChunkSize: 512 * 1024,
|
|
59
|
-
async pull(i) {
|
|
60
|
-
const n = i.byobRequest.view, a = await s.slice(
|
|
61
|
-
r,
|
|
62
|
-
r + n.byteLength
|
|
63
|
-
).arrayBuffer(), l = new Uint8Array(a);
|
|
64
|
-
new Uint8Array(n.buffer).set(l);
|
|
65
|
-
const c = l.byteLength;
|
|
66
|
-
i.byobRequest.respond(c), r += c, r >= s.size && i.close();
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
if (currentJsRuntime$1 === "NODE" && typeof CustomEvent > "u") {
|
|
72
|
-
class t extends Event {
|
|
73
|
-
constructor(r, s = {}) {
|
|
74
|
-
super(r, s), this.detail = s.detail;
|
|
75
|
-
}
|
|
76
|
-
initCustomEvent() {
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
globalThis.CustomEvent = t;
|
|
80
|
-
}
|
|
11
|
+
import "@php-wasm/node-polyfills";
|
|
12
|
+
import { logger } from "@php-wasm/logger";
|
|
13
|
+
import { dirname, joinPaths, Semaphore, createSpawnHandler, normalizePath, AcquireTimeoutError } from "@php-wasm/util";
|
|
14
|
+
import { parse, stringify } from "ini";
|
|
15
|
+
import { StreamedFile } from "@php-wasm/stream-compression";
|
|
81
16
|
const FileErrorCodes = {
|
|
82
17
|
0: "No error occurred. System call completed successfully.",
|
|
83
18
|
1: "Argument list too long.",
|
|
@@ -168,370 +103,27 @@ function rethrowFileSystemError(t = "") {
|
|
|
168
103
|
i.value = function(...o) {
|
|
169
104
|
try {
|
|
170
105
|
return n.apply(this, o);
|
|
171
|
-
} catch (
|
|
172
|
-
const l = typeof
|
|
106
|
+
} catch (p) {
|
|
107
|
+
const l = typeof p == "object" ? p == null ? void 0 : p.errno : null;
|
|
173
108
|
if (l in FileErrorCodes) {
|
|
174
|
-
const
|
|
175
|
-
throw new Error(`${de}: ${
|
|
176
|
-
cause:
|
|
109
|
+
const a = FileErrorCodes[l], y = typeof o[1] == "string" ? o[1] : null, de = y !== null ? t.replaceAll("{path}", y) : t;
|
|
110
|
+
throw new Error(`${de}: ${a}`, {
|
|
111
|
+
cause: p
|
|
177
112
|
});
|
|
178
113
|
}
|
|
179
|
-
throw
|
|
114
|
+
throw p;
|
|
180
115
|
}
|
|
181
116
|
};
|
|
182
117
|
};
|
|
183
118
|
}
|
|
184
|
-
const logEventType = "playground-log", logEvent = (t, ...e) => {
|
|
185
|
-
logger.dispatchEvent(
|
|
186
|
-
new CustomEvent(logEventType, {
|
|
187
|
-
detail: {
|
|
188
|
-
log: t,
|
|
189
|
-
args: e
|
|
190
|
-
}
|
|
191
|
-
})
|
|
192
|
-
);
|
|
193
|
-
}, logToConsole = (t, ...e) => {
|
|
194
|
-
switch (typeof t.message == "string" ? t.message = prepareLogMessage(t.message) : t.message.message && typeof t.message.message == "string" && (t.message.message = prepareLogMessage(t.message.message)), t.severity) {
|
|
195
|
-
case "Debug":
|
|
196
|
-
console.debug(t.message, ...e);
|
|
197
|
-
break;
|
|
198
|
-
case "Info":
|
|
199
|
-
console.info(t.message, ...e);
|
|
200
|
-
break;
|
|
201
|
-
case "Warn":
|
|
202
|
-
console.warn(t.message, ...e);
|
|
203
|
-
break;
|
|
204
|
-
case "Error":
|
|
205
|
-
console.error(t.message, ...e);
|
|
206
|
-
break;
|
|
207
|
-
case "Fatal":
|
|
208
|
-
console.error(t.message, ...e);
|
|
209
|
-
break;
|
|
210
|
-
default:
|
|
211
|
-
console.log(t.message, ...e);
|
|
212
|
-
}
|
|
213
|
-
}, prepareLogMessage$1 = (t) => t instanceof Error ? [t.message, t.stack].join(`
|
|
214
|
-
`) : JSON.stringify(t, null, 2), logs = [], addToLogArray = (t) => {
|
|
215
|
-
logs.push(t);
|
|
216
|
-
}, logToMemory = (t) => {
|
|
217
|
-
if (t.raw === !0)
|
|
218
|
-
addToLogArray(t.message);
|
|
219
|
-
else {
|
|
220
|
-
const e = formatLogEntry(
|
|
221
|
-
typeof t.message == "object" ? prepareLogMessage$1(t.message) : t.message,
|
|
222
|
-
t.severity ?? "Info",
|
|
223
|
-
t.prefix ?? "JavaScript"
|
|
224
|
-
);
|
|
225
|
-
addToLogArray(e);
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
class Logger extends EventTarget {
|
|
229
|
-
// constructor
|
|
230
|
-
constructor(e = []) {
|
|
231
|
-
super(), this.handlers = e, this.fatalErrorEvent = "playground-fatal-error";
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Get all logs.
|
|
235
|
-
* @returns string[]
|
|
236
|
-
*/
|
|
237
|
-
getLogs() {
|
|
238
|
-
return this.handlers.includes(logToMemory) ? [...logs] : (this.error(`Logs aren't stored because the logToMemory handler isn't registered.
|
|
239
|
-
If you're using a custom logger instance, make sure to register logToMemory handler.
|
|
240
|
-
`), []);
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Log message with severity.
|
|
244
|
-
*
|
|
245
|
-
* @param message any
|
|
246
|
-
* @param severity LogSeverity
|
|
247
|
-
* @param raw boolean
|
|
248
|
-
* @param args any
|
|
249
|
-
*/
|
|
250
|
-
logMessage(e, ...r) {
|
|
251
|
-
for (const s of this.handlers)
|
|
252
|
-
s(e, ...r);
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Log message
|
|
256
|
-
*
|
|
257
|
-
* @param message any
|
|
258
|
-
* @param args any
|
|
259
|
-
*/
|
|
260
|
-
log(e, ...r) {
|
|
261
|
-
this.logMessage(
|
|
262
|
-
{
|
|
263
|
-
message: e,
|
|
264
|
-
severity: void 0,
|
|
265
|
-
prefix: "JavaScript",
|
|
266
|
-
raw: !1
|
|
267
|
-
},
|
|
268
|
-
...r
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Log debug message
|
|
273
|
-
*
|
|
274
|
-
* @param message any
|
|
275
|
-
* @param args any
|
|
276
|
-
*/
|
|
277
|
-
debug(e, ...r) {
|
|
278
|
-
this.logMessage(
|
|
279
|
-
{
|
|
280
|
-
message: e,
|
|
281
|
-
severity: "Debug",
|
|
282
|
-
prefix: "JavaScript",
|
|
283
|
-
raw: !1
|
|
284
|
-
},
|
|
285
|
-
...r
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Log info message
|
|
290
|
-
*
|
|
291
|
-
* @param message any
|
|
292
|
-
* @param args any
|
|
293
|
-
*/
|
|
294
|
-
info(e, ...r) {
|
|
295
|
-
this.logMessage(
|
|
296
|
-
{
|
|
297
|
-
message: e,
|
|
298
|
-
severity: "Info",
|
|
299
|
-
prefix: "JavaScript",
|
|
300
|
-
raw: !1
|
|
301
|
-
},
|
|
302
|
-
...r
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Log warning message
|
|
307
|
-
*
|
|
308
|
-
* @param message any
|
|
309
|
-
* @param args any
|
|
310
|
-
*/
|
|
311
|
-
warn(e, ...r) {
|
|
312
|
-
this.logMessage(
|
|
313
|
-
{
|
|
314
|
-
message: e,
|
|
315
|
-
severity: "Warn",
|
|
316
|
-
prefix: "JavaScript",
|
|
317
|
-
raw: !1
|
|
318
|
-
},
|
|
319
|
-
...r
|
|
320
|
-
);
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Log error message
|
|
324
|
-
*
|
|
325
|
-
* @param message any
|
|
326
|
-
* @param args any
|
|
327
|
-
*/
|
|
328
|
-
error(e, ...r) {
|
|
329
|
-
this.logMessage(
|
|
330
|
-
{
|
|
331
|
-
message: e,
|
|
332
|
-
severity: "Error",
|
|
333
|
-
prefix: "JavaScript",
|
|
334
|
-
raw: !1
|
|
335
|
-
},
|
|
336
|
-
...r
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
const getDefaultHandlers = () => {
|
|
341
|
-
try {
|
|
342
|
-
if (process.env.NODE_ENV === "test")
|
|
343
|
-
return [logToMemory, logEvent];
|
|
344
|
-
} catch {
|
|
345
|
-
}
|
|
346
|
-
return [logToMemory, logToConsole, logEvent];
|
|
347
|
-
}, logger = new Logger(getDefaultHandlers()), prepareLogMessage = (t) => t.replace(/\t/g, ""), formatLogEntry = (t, e, r) => {
|
|
348
|
-
const s = /* @__PURE__ */ new Date(), i = new Intl.DateTimeFormat("en-GB", {
|
|
349
|
-
year: "numeric",
|
|
350
|
-
month: "short",
|
|
351
|
-
day: "2-digit",
|
|
352
|
-
timeZone: "UTC"
|
|
353
|
-
}).format(s).replace(/ /g, "-"), n = new Intl.DateTimeFormat("en-GB", {
|
|
354
|
-
hour: "2-digit",
|
|
355
|
-
minute: "2-digit",
|
|
356
|
-
second: "2-digit",
|
|
357
|
-
hour12: !1,
|
|
358
|
-
timeZone: "UTC",
|
|
359
|
-
timeZoneName: "short"
|
|
360
|
-
}).format(s), o = i + " " + n;
|
|
361
|
-
return t = prepareLogMessage(t), `[${o}] ${r} ${e}: ${t}`;
|
|
362
|
-
}, SleepFinished = Symbol("SleepFinished");
|
|
363
|
-
function sleep(t) {
|
|
364
|
-
return new Promise((e) => {
|
|
365
|
-
setTimeout(() => e(SleepFinished), t);
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
class AcquireTimeoutError extends Error {
|
|
369
|
-
constructor() {
|
|
370
|
-
super("Acquiring lock timed out");
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
class Semaphore {
|
|
374
|
-
constructor({ concurrency: e, timeout: r }) {
|
|
375
|
-
this._running = 0, this.concurrency = e, this.timeout = r, this.queue = [];
|
|
376
|
-
}
|
|
377
|
-
get remaining() {
|
|
378
|
-
return this.concurrency - this.running;
|
|
379
|
-
}
|
|
380
|
-
get running() {
|
|
381
|
-
return this._running;
|
|
382
|
-
}
|
|
383
|
-
async acquire() {
|
|
384
|
-
for (; ; )
|
|
385
|
-
if (this._running >= this.concurrency) {
|
|
386
|
-
const e = new Promise((r) => {
|
|
387
|
-
this.queue.push(r);
|
|
388
|
-
});
|
|
389
|
-
this.timeout !== void 0 ? await Promise.race([e, sleep(this.timeout)]).then(
|
|
390
|
-
(r) => {
|
|
391
|
-
if (r === SleepFinished)
|
|
392
|
-
throw new AcquireTimeoutError();
|
|
393
|
-
}
|
|
394
|
-
) : await e;
|
|
395
|
-
} else {
|
|
396
|
-
this._running++;
|
|
397
|
-
let e = !1;
|
|
398
|
-
return () => {
|
|
399
|
-
e || (e = !0, this._running--, this.queue.length > 0 && this.queue.shift()());
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
async run(e) {
|
|
404
|
-
const r = await this.acquire();
|
|
405
|
-
try {
|
|
406
|
-
return await e();
|
|
407
|
-
} finally {
|
|
408
|
-
r();
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
function joinPaths(...t) {
|
|
413
|
-
let e = t.join("/");
|
|
414
|
-
const r = e[0] === "/", s = e.substring(e.length - 1) === "/";
|
|
415
|
-
return e = normalizePath(e), !e && !r && (e = "."), e && s && (e += "/"), e;
|
|
416
|
-
}
|
|
417
|
-
function dirname(t) {
|
|
418
|
-
if (t === "/")
|
|
419
|
-
return "/";
|
|
420
|
-
t = normalizePath(t);
|
|
421
|
-
const e = t.lastIndexOf("/");
|
|
422
|
-
return e === -1 ? "" : e === 0 ? "/" : t.substr(0, e);
|
|
423
|
-
}
|
|
424
|
-
function normalizePath(t) {
|
|
425
|
-
const e = t[0] === "/";
|
|
426
|
-
return t = normalizePathsArray(
|
|
427
|
-
t.split("/").filter((r) => !!r),
|
|
428
|
-
!e
|
|
429
|
-
).join("/"), (e ? "/" : "") + t.replace(/\/$/, "");
|
|
430
|
-
}
|
|
431
|
-
function normalizePathsArray(t, e) {
|
|
432
|
-
let r = 0;
|
|
433
|
-
for (let s = t.length - 1; s >= 0; s--) {
|
|
434
|
-
const i = t[s];
|
|
435
|
-
i === "." ? t.splice(s, 1) : i === ".." ? (t.splice(s, 1), r++) : r && (t.splice(s, 1), r--);
|
|
436
|
-
}
|
|
437
|
-
if (e)
|
|
438
|
-
for (; r; r--)
|
|
439
|
-
t.unshift("..");
|
|
440
|
-
return t;
|
|
441
|
-
}
|
|
442
|
-
function splitShellCommand(t) {
|
|
443
|
-
let s = 0, i = "";
|
|
444
|
-
const n = [];
|
|
445
|
-
let o = "";
|
|
446
|
-
for (let a = 0; a < t.length; a++) {
|
|
447
|
-
const l = t[a];
|
|
448
|
-
l === "\\" ? ((t[a + 1] === '"' || t[a + 1] === "'") && a++, o += t[a]) : s === 0 ? l === '"' || l === "'" ? (s = 1, i = l) : l.match(/\s/) ? (o.trim().length && n.push(o.trim()), o = l) : n.length && !o ? o = n.pop() + l : o += l : s === 1 && (l === i ? (s = 0, i = "") : o += l);
|
|
449
|
-
}
|
|
450
|
-
return o && n.push(o.trim()), n;
|
|
451
|
-
}
|
|
452
|
-
function createSpawnHandler(t) {
|
|
453
|
-
return function(e, r = [], s = {}) {
|
|
454
|
-
const i = new ChildProcess(), n = new ProcessApi(i);
|
|
455
|
-
return setTimeout(async () => {
|
|
456
|
-
let o = [];
|
|
457
|
-
if (r.length)
|
|
458
|
-
o = [e, ...r];
|
|
459
|
-
else if (typeof e == "string")
|
|
460
|
-
o = splitShellCommand(e);
|
|
461
|
-
else if (Array.isArray(e))
|
|
462
|
-
o = e;
|
|
463
|
-
else
|
|
464
|
-
throw new Error("Invalid command ", e);
|
|
465
|
-
try {
|
|
466
|
-
await t(o, n, s);
|
|
467
|
-
} catch (a) {
|
|
468
|
-
i.emit("error", a), typeof a == "object" && a !== null && "message" in a && typeof a.message == "string" && n.stderr(a.message), n.exit(1);
|
|
469
|
-
}
|
|
470
|
-
i.emit("spawn", !0);
|
|
471
|
-
}), i;
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
class EventEmitter {
|
|
475
|
-
constructor() {
|
|
476
|
-
this.listeners = {};
|
|
477
|
-
}
|
|
478
|
-
emit(e, r) {
|
|
479
|
-
this.listeners[e] && this.listeners[e].forEach(function(s) {
|
|
480
|
-
s(r);
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
on(e, r) {
|
|
484
|
-
this.listeners[e] || (this.listeners[e] = []), this.listeners[e].push(r);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
class ProcessApi extends EventEmitter {
|
|
488
|
-
constructor(e) {
|
|
489
|
-
super(), this.childProcess = e, this.exited = !1, this.stdinData = [], e.on("stdin", (r) => {
|
|
490
|
-
this.stdinData ? this.stdinData.push(r.slice()) : this.emit("stdin", r);
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
stdout(e) {
|
|
494
|
-
typeof e == "string" && (e = new TextEncoder().encode(e)), this.childProcess.stdout.emit("data", e);
|
|
495
|
-
}
|
|
496
|
-
stdoutEnd() {
|
|
497
|
-
this.childProcess.stdout.emit("end", {});
|
|
498
|
-
}
|
|
499
|
-
stderr(e) {
|
|
500
|
-
typeof e == "string" && (e = new TextEncoder().encode(e)), this.childProcess.stderr.emit("data", e);
|
|
501
|
-
}
|
|
502
|
-
stderrEnd() {
|
|
503
|
-
this.childProcess.stderr.emit("end", {});
|
|
504
|
-
}
|
|
505
|
-
exit(e) {
|
|
506
|
-
this.exited || (this.exited = !0, this.childProcess.emit("exit", e));
|
|
507
|
-
}
|
|
508
|
-
flushStdin() {
|
|
509
|
-
if (this.stdinData)
|
|
510
|
-
for (let e = 0; e < this.stdinData.length; e++)
|
|
511
|
-
this.emit("stdin", this.stdinData[e]);
|
|
512
|
-
this.stdinData = null;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
let lastPid = 9743;
|
|
516
|
-
class ChildProcess extends EventEmitter {
|
|
517
|
-
constructor(e = lastPid++) {
|
|
518
|
-
super(), this.pid = e, this.stdout = new EventEmitter(), this.stderr = new EventEmitter();
|
|
519
|
-
const r = this;
|
|
520
|
-
this.stdin = {
|
|
521
|
-
write: (s) => {
|
|
522
|
-
r.emit("stdin", s);
|
|
523
|
-
}
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
119
|
var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = (t, e, r, s) => {
|
|
528
120
|
for (var i = s > 1 ? void 0 : s ? __getOwnPropDesc(e, r) : e, n = t.length - 1, o; n >= 0; n--)
|
|
529
121
|
(o = t[n]) && (i = (s ? o(e, r, i) : o(i)) || i);
|
|
530
122
|
return s && i && __defProp(e, r, i), i;
|
|
531
123
|
};
|
|
532
|
-
const _FSHelpers = class
|
|
124
|
+
const _FSHelpers = class m {
|
|
533
125
|
static readFileAsText(e, r) {
|
|
534
|
-
return new TextDecoder().decode(
|
|
126
|
+
return new TextDecoder().decode(m.readFileAsBuffer(e, r));
|
|
535
127
|
}
|
|
536
128
|
static readFileAsBuffer(e, r) {
|
|
537
129
|
return e.readFile(r);
|
|
@@ -551,8 +143,8 @@ const _FSHelpers = class f {
|
|
|
551
143
|
*/
|
|
552
144
|
static mv(e, r, s) {
|
|
553
145
|
try {
|
|
554
|
-
const i = e.lookupPath(r).node.mount, n =
|
|
555
|
-
i.mountpoint !== n.mountpoint ? (
|
|
146
|
+
const i = e.lookupPath(r).node.mount, n = m.fileExists(e, s) ? e.lookupPath(s).node.mount : e.lookupPath(dirname(s)).node.mount;
|
|
147
|
+
i.mountpoint !== n.mountpoint ? (m.copyRecursive(e, r, s), m.rmdir(e, r, { recursive: !0 })) : e.rename(r, s);
|
|
556
148
|
} catch (i) {
|
|
557
149
|
const n = getEmscriptenFsError(i);
|
|
558
150
|
throw n ? new Error(
|
|
@@ -564,13 +156,13 @@ const _FSHelpers = class f {
|
|
|
564
156
|
}
|
|
565
157
|
}
|
|
566
158
|
static rmdir(e, r, s = { recursive: !0 }) {
|
|
567
|
-
s != null && s.recursive &&
|
|
159
|
+
s != null && s.recursive && m.listFiles(e, r).forEach((i) => {
|
|
568
160
|
const n = `${r}/${i}`;
|
|
569
|
-
|
|
161
|
+
m.isDir(e, n) ? m.rmdir(e, n, s) : m.unlink(e, n);
|
|
570
162
|
}), e.rmdir(r);
|
|
571
163
|
}
|
|
572
164
|
static listFiles(e, r, s = { prependPath: !1 }) {
|
|
573
|
-
if (!
|
|
165
|
+
if (!m.fileExists(e, r))
|
|
574
166
|
return [];
|
|
575
167
|
try {
|
|
576
168
|
const i = e.readdir(r).filter(
|
|
@@ -586,7 +178,7 @@ const _FSHelpers = class f {
|
|
|
586
178
|
}
|
|
587
179
|
}
|
|
588
180
|
static isDir(e, r) {
|
|
589
|
-
return
|
|
181
|
+
return m.fileExists(e, r) ? e.isDir(e.lookupPath(r).node.mode) : !1;
|
|
590
182
|
}
|
|
591
183
|
static fileExists(e, r) {
|
|
592
184
|
try {
|
|
@@ -606,7 +198,7 @@ const _FSHelpers = class f {
|
|
|
606
198
|
(o) => o !== "." && o !== ".."
|
|
607
199
|
);
|
|
608
200
|
for (const o of n)
|
|
609
|
-
|
|
201
|
+
m.copyRecursive(
|
|
610
202
|
e,
|
|
611
203
|
joinPaths(r, o),
|
|
612
204
|
joinPaths(s, o)
|
|
@@ -836,14 +428,14 @@ const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map(
|
|
|
836
428
|
let lastRuntimeId = 0;
|
|
837
429
|
async function loadPHPRuntime(t, e = {}) {
|
|
838
430
|
const [r, s, i] = makePromise(), n = t.init(currentJsRuntime, {
|
|
839
|
-
onAbort(
|
|
840
|
-
i(
|
|
431
|
+
onAbort(p) {
|
|
432
|
+
i(p), logger.error(p);
|
|
841
433
|
},
|
|
842
434
|
ENV: {},
|
|
843
435
|
// Emscripten sometimes prepends a '/' to the path, which
|
|
844
436
|
// breaks vite dev mode. An identity `locateFile` function
|
|
845
437
|
// fixes it.
|
|
846
|
-
locateFile: (
|
|
438
|
+
locateFile: (p) => p,
|
|
847
439
|
...e,
|
|
848
440
|
noInitialRun: !0,
|
|
849
441
|
onRuntimeInitialized() {
|
|
@@ -852,8 +444,8 @@ async function loadPHPRuntime(t, e = {}) {
|
|
|
852
444
|
});
|
|
853
445
|
await r;
|
|
854
446
|
const o = ++lastRuntimeId;
|
|
855
|
-
return n.id = o, n.originalExit = n._exit, n._exit = function(
|
|
856
|
-
return loadedRuntimes.delete(o), n.originalExit(
|
|
447
|
+
return n.id = o, n.originalExit = n._exit, n._exit = function(p) {
|
|
448
|
+
return loadedRuntimes.delete(o), n.originalExit(p);
|
|
857
449
|
}, n[RuntimeId] = o, loadedRuntimes.set(o, n), o;
|
|
858
450
|
}
|
|
859
451
|
function getLoadedRuntime(t) {
|
|
@@ -918,7 +510,7 @@ function improveWASMErrorReporting(t) {
|
|
|
918
510
|
} catch (o) {
|
|
919
511
|
if (!(o instanceof Error))
|
|
920
512
|
throw o;
|
|
921
|
-
const
|
|
513
|
+
const p = clarifyErrorMessage(
|
|
922
514
|
o,
|
|
923
515
|
(n = t.lastAsyncifyStackSource) == null ? void 0 : n.stack
|
|
924
516
|
);
|
|
@@ -926,12 +518,12 @@ function improveWASMErrorReporting(t) {
|
|
|
926
518
|
e.dispatchEvent(
|
|
927
519
|
new ErrorEvent("error", {
|
|
928
520
|
error: o,
|
|
929
|
-
message:
|
|
521
|
+
message: p
|
|
930
522
|
})
|
|
931
523
|
);
|
|
932
524
|
return;
|
|
933
525
|
}
|
|
934
|
-
throw isExitCodeZero(o) || showCriticalErrorBox(
|
|
526
|
+
throw isExitCodeZero(o) || showCriticalErrorBox(p), o;
|
|
935
527
|
}
|
|
936
528
|
};
|
|
937
529
|
}
|
|
@@ -1020,7 +612,7 @@ class PHPExecutionFailureError extends Error {
|
|
|
1020
612
|
}
|
|
1021
613
|
}
|
|
1022
614
|
const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php";
|
|
1023
|
-
var
|
|
615
|
+
var x, P, w, g, E, k, Y, I, Z, C, K, A, X, N, Q, M, ee, j, te, U, re, L, se, $, ie, b, J, q, ne, B, oe, O, ae;
|
|
1024
616
|
class PHP {
|
|
1025
617
|
/**
|
|
1026
618
|
* Initializes a PHP runtime.
|
|
@@ -1039,26 +631,26 @@ class PHP {
|
|
|
1039
631
|
* was provided.
|
|
1040
632
|
* @returns Computed $_SERVER entries.
|
|
1041
633
|
*/
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
h(this,
|
|
634
|
+
u(this, k);
|
|
635
|
+
u(this, I);
|
|
636
|
+
u(this, C);
|
|
637
|
+
u(this, A);
|
|
638
|
+
u(this, N);
|
|
639
|
+
u(this, M);
|
|
640
|
+
u(this, j);
|
|
641
|
+
u(this, U);
|
|
642
|
+
u(this, L);
|
|
643
|
+
u(this, $);
|
|
644
|
+
u(this, b);
|
|
645
|
+
u(this, q);
|
|
646
|
+
u(this, B);
|
|
647
|
+
u(this, O);
|
|
648
|
+
u(this, x, void 0);
|
|
649
|
+
u(this, P, void 0);
|
|
650
|
+
u(this, w, void 0);
|
|
651
|
+
u(this, g, void 0);
|
|
652
|
+
u(this, E, void 0);
|
|
653
|
+
h(this, P, !1), h(this, w, null), h(this, g, /* @__PURE__ */ new Map()), h(this, E, []), this.semaphore = new Semaphore({ concurrency: 1 }), t !== void 0 && this.initializeRuntime(t);
|
|
1062
654
|
}
|
|
1063
655
|
/**
|
|
1064
656
|
* Adds an event listener for a PHP event.
|
|
@@ -1066,7 +658,7 @@ class PHP {
|
|
|
1066
658
|
* @param listener - The listener function to be called when the event is triggered.
|
|
1067
659
|
*/
|
|
1068
660
|
addEventListener(t, e) {
|
|
1069
|
-
|
|
661
|
+
c(this, g).has(t) || c(this, g).set(t, /* @__PURE__ */ new Set()), c(this, g).get(t).add(e);
|
|
1070
662
|
}
|
|
1071
663
|
/**
|
|
1072
664
|
* Removes an event listener for a PHP event.
|
|
@@ -1075,10 +667,10 @@ class PHP {
|
|
|
1075
667
|
*/
|
|
1076
668
|
removeEventListener(t, e) {
|
|
1077
669
|
var r;
|
|
1078
|
-
(r =
|
|
670
|
+
(r = c(this, g).get(t)) == null || r.delete(e);
|
|
1079
671
|
}
|
|
1080
672
|
dispatchEvent(t) {
|
|
1081
|
-
const e =
|
|
673
|
+
const e = c(this, g).get(t.type);
|
|
1082
674
|
if (e)
|
|
1083
675
|
for (const r of e)
|
|
1084
676
|
r(t);
|
|
@@ -1123,7 +715,7 @@ class PHP {
|
|
|
1123
715
|
* @param listener Callback function to handle the message.
|
|
1124
716
|
*/
|
|
1125
717
|
onMessage(t) {
|
|
1126
|
-
|
|
718
|
+
c(this, E).push(t);
|
|
1127
719
|
}
|
|
1128
720
|
async setSpawnHandler(handler) {
|
|
1129
721
|
typeof handler == "string" && (handler = createSpawnHandler(eval(handler))), this[__private__dont__use].spawnProcess = handler;
|
|
@@ -1197,7 +789,7 @@ class PHP {
|
|
|
1197
789
|
}
|
|
1198
790
|
`
|
|
1199
791
|
), e.onMessage = async (r) => {
|
|
1200
|
-
for (const s of
|
|
792
|
+
for (const s of c(this, E)) {
|
|
1201
793
|
const i = await s(r);
|
|
1202
794
|
if (i)
|
|
1203
795
|
return i;
|
|
@@ -1218,7 +810,7 @@ class PHP {
|
|
|
1218
810
|
throw new Error(
|
|
1219
811
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
1220
812
|
);
|
|
1221
|
-
h(this,
|
|
813
|
+
h(this, x, t);
|
|
1222
814
|
}
|
|
1223
815
|
/**
|
|
1224
816
|
* Changes the current working directory in the PHP filesystem.
|
|
@@ -1315,28 +907,28 @@ class PHP {
|
|
|
1315
907
|
const e = await this.semaphore.acquire();
|
|
1316
908
|
let r;
|
|
1317
909
|
try {
|
|
1318
|
-
if (
|
|
910
|
+
if (c(this, P) || (d(this, I, Z).call(this), h(this, P, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
|
|
1319
911
|
throw new Error(
|
|
1320
912
|
`The script path "${t.scriptPath}" does not exist.`
|
|
1321
913
|
);
|
|
1322
|
-
d(this,
|
|
1323
|
-
const s = normalizeHeaders(t.headers || {}), i = s.host || "example.com:443", n = d(this,
|
|
1324
|
-
d(this,
|
|
1325
|
-
const o = d(this, k,
|
|
1326
|
-
for (const
|
|
1327
|
-
d(this, q, ne).call(this,
|
|
1328
|
-
const
|
|
1329
|
-
for (const
|
|
1330
|
-
d(this,
|
|
914
|
+
d(this, A, X).call(this, t.relativeUri || ""), d(this, U, re).call(this, t.method || "GET");
|
|
915
|
+
const s = normalizeHeaders(t.headers || {}), i = s.host || "example.com:443", n = d(this, j, te).call(this, i, t.protocol || "http");
|
|
916
|
+
d(this, N, Q).call(this, i), d(this, M, ee).call(this, n), d(this, L, se).call(this, s), t.body && (r = d(this, $, ie).call(this, t.body)), typeof t.code == "string" ? (this.writeFile("/internal/eval.php", t.code), d(this, b, J).call(this, "/internal/eval.php")) : d(this, b, J).call(this, t.scriptPath || "");
|
|
917
|
+
const o = d(this, k, Y).call(this, t.$_SERVER, s, n);
|
|
918
|
+
for (const a in o)
|
|
919
|
+
d(this, q, ne).call(this, a, o[a]);
|
|
920
|
+
const p = t.env || {};
|
|
921
|
+
for (const a in p)
|
|
922
|
+
d(this, B, oe).call(this, a, p[a]);
|
|
1331
923
|
const l = await d(this, O, ae).call(this);
|
|
1332
924
|
if (l.exitCode !== 0) {
|
|
1333
925
|
logger.warn("PHP.run() output was:", l.text);
|
|
1334
|
-
const
|
|
926
|
+
const a = new PHPExecutionFailureError(
|
|
1335
927
|
`PHP.run() failed with exit code ${l.exitCode} and the following output: ` + l.errors,
|
|
1336
928
|
l,
|
|
1337
929
|
"request"
|
|
1338
930
|
);
|
|
1339
|
-
throw logger.error(
|
|
931
|
+
throw logger.error(a), a;
|
|
1340
932
|
}
|
|
1341
933
|
return l;
|
|
1342
934
|
} catch (s) {
|
|
@@ -1499,7 +1091,7 @@ class PHP {
|
|
|
1499
1091
|
this.exit();
|
|
1500
1092
|
} catch {
|
|
1501
1093
|
}
|
|
1502
|
-
this.initializeRuntime(t),
|
|
1094
|
+
this.initializeRuntime(t), c(this, x) && this.setSapiName(c(this, x)), e && copyFS(r, this[__private__dont__use].FS, e);
|
|
1503
1095
|
}
|
|
1504
1096
|
/**
|
|
1505
1097
|
* Mounts a filesystem to a given path in the PHP filesystem.
|
|
@@ -1568,13 +1160,13 @@ class PHP {
|
|
|
1568
1160
|
this[__private__dont__use]._exit(t);
|
|
1569
1161
|
} catch {
|
|
1570
1162
|
}
|
|
1571
|
-
h(this,
|
|
1163
|
+
h(this, P, !1), h(this, w, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1572
1164
|
}
|
|
1573
1165
|
[Symbol.dispose]() {
|
|
1574
|
-
|
|
1166
|
+
c(this, P) && this.exit(0);
|
|
1575
1167
|
}
|
|
1576
1168
|
}
|
|
1577
|
-
|
|
1169
|
+
x = new WeakMap(), P = new WeakMap(), w = new WeakMap(), g = new WeakMap(), E = new WeakMap(), k = new WeakSet(), Y = function(t, e, r) {
|
|
1578
1170
|
const s = {
|
|
1579
1171
|
...t || {}
|
|
1580
1172
|
};
|
|
@@ -1584,9 +1176,9 @@ E = new WeakMap(), y = new WeakMap(), w = new WeakMap(), g = new WeakMap(), x =
|
|
|
1584
1176
|
["content-type", "content-length"].includes(i.toLowerCase()) && (n = ""), s[`${n}${i.toUpperCase().replace(/-/g, "_")}`] = e[i];
|
|
1585
1177
|
}
|
|
1586
1178
|
return s;
|
|
1587
|
-
},
|
|
1179
|
+
}, I = new WeakSet(), Z = function() {
|
|
1588
1180
|
this[__private__dont__use].ccall("php_wasm_init", null, [], []);
|
|
1589
|
-
},
|
|
1181
|
+
}, C = new WeakSet(), K = function() {
|
|
1590
1182
|
const t = "/internal/headers.json";
|
|
1591
1183
|
if (!this.fileExists(t))
|
|
1592
1184
|
throw new Error(
|
|
@@ -1603,7 +1195,7 @@ E = new WeakMap(), y = new WeakMap(), w = new WeakMap(), g = new WeakMap(), x =
|
|
|
1603
1195
|
headers: r,
|
|
1604
1196
|
httpStatusCode: e.status
|
|
1605
1197
|
};
|
|
1606
|
-
},
|
|
1198
|
+
}, A = new WeakSet(), X = function(t) {
|
|
1607
1199
|
if (this[__private__dont__use].ccall(
|
|
1608
1200
|
"wasm_set_request_uri",
|
|
1609
1201
|
null,
|
|
@@ -1618,35 +1210,35 @@ E = new WeakMap(), y = new WeakMap(), w = new WeakMap(), g = new WeakMap(), x =
|
|
|
1618
1210
|
[e]
|
|
1619
1211
|
);
|
|
1620
1212
|
}
|
|
1621
|
-
},
|
|
1213
|
+
}, N = new WeakSet(), Q = function(t) {
|
|
1622
1214
|
this[__private__dont__use].ccall(
|
|
1623
1215
|
"wasm_set_request_host",
|
|
1624
1216
|
null,
|
|
1625
1217
|
[STRING],
|
|
1626
1218
|
[t]
|
|
1627
1219
|
);
|
|
1628
|
-
},
|
|
1220
|
+
}, M = new WeakSet(), ee = function(t) {
|
|
1629
1221
|
this[__private__dont__use].ccall(
|
|
1630
1222
|
"wasm_set_request_port",
|
|
1631
1223
|
null,
|
|
1632
1224
|
[NUMBER],
|
|
1633
1225
|
[t]
|
|
1634
1226
|
);
|
|
1635
|
-
},
|
|
1227
|
+
}, j = new WeakSet(), te = function(t, e) {
|
|
1636
1228
|
let r;
|
|
1637
1229
|
try {
|
|
1638
1230
|
r = parseInt(new URL(t).port, 10);
|
|
1639
1231
|
} catch {
|
|
1640
1232
|
}
|
|
1641
1233
|
return (!r || isNaN(r) || r === 80) && (r = e === "https" ? 443 : 80), r;
|
|
1642
|
-
},
|
|
1234
|
+
}, U = new WeakSet(), re = function(t) {
|
|
1643
1235
|
this[__private__dont__use].ccall(
|
|
1644
1236
|
"wasm_set_request_method",
|
|
1645
1237
|
null,
|
|
1646
1238
|
[STRING],
|
|
1647
1239
|
[t]
|
|
1648
1240
|
);
|
|
1649
|
-
},
|
|
1241
|
+
}, L = new WeakSet(), se = function(t) {
|
|
1650
1242
|
t.cookie && this[__private__dont__use].ccall(
|
|
1651
1243
|
"wasm_set_cookies",
|
|
1652
1244
|
null,
|
|
@@ -1663,7 +1255,7 @@ E = new WeakMap(), y = new WeakMap(), w = new WeakMap(), g = new WeakMap(), x =
|
|
|
1663
1255
|
[NUMBER],
|
|
1664
1256
|
[parseInt(t["content-length"], 10)]
|
|
1665
1257
|
);
|
|
1666
|
-
},
|
|
1258
|
+
}, $ = new WeakSet(), ie = function(t) {
|
|
1667
1259
|
let e, r;
|
|
1668
1260
|
typeof t == "string" ? (logger.warn(
|
|
1669
1261
|
"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"
|
|
@@ -1686,7 +1278,7 @@ E = new WeakMap(), y = new WeakMap(), w = new WeakMap(), g = new WeakMap(), x =
|
|
|
1686
1278
|
[NUMBER],
|
|
1687
1279
|
[r]
|
|
1688
1280
|
), s;
|
|
1689
|
-
},
|
|
1281
|
+
}, b = new WeakSet(), J = function(t) {
|
|
1690
1282
|
this[__private__dont__use].ccall(
|
|
1691
1283
|
"wasm_set_path_translated",
|
|
1692
1284
|
null,
|
|
@@ -1700,7 +1292,7 @@ E = new WeakMap(), y = new WeakMap(), w = new WeakMap(), g = new WeakMap(), x =
|
|
|
1700
1292
|
[STRING, STRING],
|
|
1701
1293
|
[t, e]
|
|
1702
1294
|
);
|
|
1703
|
-
},
|
|
1295
|
+
}, B = new WeakSet(), oe = function(t, e) {
|
|
1704
1296
|
this[__private__dont__use].ccall(
|
|
1705
1297
|
"wasm_add_ENV_entry",
|
|
1706
1298
|
null,
|
|
@@ -1713,37 +1305,37 @@ E = new WeakMap(), y = new WeakMap(), w = new WeakMap(), g = new WeakMap(), x =
|
|
|
1713
1305
|
try {
|
|
1714
1306
|
t = await new Promise((n, o) => {
|
|
1715
1307
|
var l;
|
|
1716
|
-
e = (
|
|
1717
|
-
logger.error(
|
|
1718
|
-
const
|
|
1719
|
-
|
|
1720
|
-
}, (l =
|
|
1308
|
+
e = (a) => {
|
|
1309
|
+
logger.error(a), logger.error(a.error);
|
|
1310
|
+
const y = new Error("Rethrown");
|
|
1311
|
+
y.cause = a.error, y.betterMessage = a.message, o(y);
|
|
1312
|
+
}, (l = c(this, w)) == null || l.addEventListener(
|
|
1721
1313
|
"error",
|
|
1722
1314
|
e
|
|
1723
1315
|
);
|
|
1724
|
-
const
|
|
1316
|
+
const p = this[__private__dont__use].ccall(
|
|
1725
1317
|
"wasm_sapi_handle_request",
|
|
1726
1318
|
NUMBER,
|
|
1727
1319
|
[],
|
|
1728
1320
|
[],
|
|
1729
1321
|
{ async: !0 }
|
|
1730
1322
|
);
|
|
1731
|
-
return
|
|
1323
|
+
return p instanceof Promise ? p.then(n, o) : n(p);
|
|
1732
1324
|
});
|
|
1733
1325
|
} catch (n) {
|
|
1734
|
-
for (const
|
|
1735
|
-
typeof this[
|
|
1326
|
+
for (const a in this)
|
|
1327
|
+
typeof this[a] == "function" && (this[a] = () => {
|
|
1736
1328
|
throw new Error(
|
|
1737
1329
|
"PHP runtime has crashed – see the earlier error for details."
|
|
1738
1330
|
);
|
|
1739
1331
|
});
|
|
1740
1332
|
this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
|
|
1741
|
-
const o = n,
|
|
1333
|
+
const o = n, p = "betterMessage" in o ? o.betterMessage : o.message, l = new Error(p);
|
|
1742
1334
|
throw l.cause = o, logger.error(l), l;
|
|
1743
1335
|
} finally {
|
|
1744
|
-
(i =
|
|
1336
|
+
(i = c(this, w)) == null || i.removeEventListener("error", e);
|
|
1745
1337
|
}
|
|
1746
|
-
const { headers: r, httpStatusCode: s } = d(this,
|
|
1338
|
+
const { headers: r, httpStatusCode: s } = d(this, C, K).call(this);
|
|
1747
1339
|
return new PHPResponse(
|
|
1748
1340
|
t === 0 ? s : 500,
|
|
1749
1341
|
r,
|
|
@@ -1822,125 +1414,6 @@ class HttpCookieStore {
|
|
|
1822
1414
|
return e.join("; ");
|
|
1823
1415
|
}
|
|
1824
1416
|
}
|
|
1825
|
-
function concatUint8Array(...t) {
|
|
1826
|
-
const e = new Uint8Array(
|
|
1827
|
-
t.reduce((s, i) => s + i.length, 0)
|
|
1828
|
-
);
|
|
1829
|
-
let r = 0;
|
|
1830
|
-
for (const s of t)
|
|
1831
|
-
e.set(s, r), r += s.length;
|
|
1832
|
-
return e;
|
|
1833
|
-
}
|
|
1834
|
-
function concatBytes(t) {
|
|
1835
|
-
if (t === void 0) {
|
|
1836
|
-
let e = new Uint8Array();
|
|
1837
|
-
return new TransformStream({
|
|
1838
|
-
transform(r) {
|
|
1839
|
-
e = concatUint8Array(e, r);
|
|
1840
|
-
},
|
|
1841
|
-
flush(r) {
|
|
1842
|
-
r.enqueue(e);
|
|
1843
|
-
}
|
|
1844
|
-
});
|
|
1845
|
-
} else {
|
|
1846
|
-
const e = new ArrayBuffer(t || 0);
|
|
1847
|
-
let r = 0;
|
|
1848
|
-
return new TransformStream({
|
|
1849
|
-
transform(s) {
|
|
1850
|
-
new Uint8Array(e).set(s, r), r += s.byteLength;
|
|
1851
|
-
},
|
|
1852
|
-
flush(s) {
|
|
1853
|
-
s.enqueue(new Uint8Array(e));
|
|
1854
|
-
}
|
|
1855
|
-
});
|
|
1856
|
-
}
|
|
1857
|
-
}
|
|
1858
|
-
function limitBytes(t, e) {
|
|
1859
|
-
if (e === 0)
|
|
1860
|
-
return new ReadableStream({
|
|
1861
|
-
start(i) {
|
|
1862
|
-
i.close();
|
|
1863
|
-
}
|
|
1864
|
-
});
|
|
1865
|
-
const r = t.getReader({ mode: "byob" });
|
|
1866
|
-
let s = 0;
|
|
1867
|
-
return new ReadableStream({
|
|
1868
|
-
async pull(i) {
|
|
1869
|
-
const { value: n, done: o } = await r.read(
|
|
1870
|
-
new Uint8Array(e - s)
|
|
1871
|
-
);
|
|
1872
|
-
if (o) {
|
|
1873
|
-
r.releaseLock(), i.close();
|
|
1874
|
-
return;
|
|
1875
|
-
}
|
|
1876
|
-
s += n.length, i.enqueue(n), s >= e && (r.releaseLock(), i.close());
|
|
1877
|
-
},
|
|
1878
|
-
cancel() {
|
|
1879
|
-
r.cancel();
|
|
1880
|
-
}
|
|
1881
|
-
});
|
|
1882
|
-
}
|
|
1883
|
-
async function collectBytes(t, e) {
|
|
1884
|
-
return e !== void 0 && (t = limitBytes(t, e)), await t.pipeThrough(concatBytes(e)).getReader().read().then(({ value: r }) => r);
|
|
1885
|
-
}
|
|
1886
|
-
class StreamedFile extends File {
|
|
1887
|
-
/**
|
|
1888
|
-
* Creates a new StreamedFile instance.
|
|
1889
|
-
*
|
|
1890
|
-
* @param readableStream The readable stream containing the file data.
|
|
1891
|
-
* @param name The name of the file.
|
|
1892
|
-
* @param type The MIME type of the file.
|
|
1893
|
-
*/
|
|
1894
|
-
constructor(e, r, s) {
|
|
1895
|
-
super([], r, { type: s }), this.readableStream = e;
|
|
1896
|
-
}
|
|
1897
|
-
/**
|
|
1898
|
-
* Overrides the slice() method of the File class.
|
|
1899
|
-
*
|
|
1900
|
-
* @returns A Blob representing a portion of the file.
|
|
1901
|
-
*/
|
|
1902
|
-
slice() {
|
|
1903
|
-
throw new Error("slice() is not possible on a StreamedFile");
|
|
1904
|
-
}
|
|
1905
|
-
/**
|
|
1906
|
-
* Returns the readable stream associated with the file.
|
|
1907
|
-
*
|
|
1908
|
-
* @returns The readable stream.
|
|
1909
|
-
*/
|
|
1910
|
-
stream() {
|
|
1911
|
-
return this.readableStream;
|
|
1912
|
-
}
|
|
1913
|
-
/**
|
|
1914
|
-
* Loads the file data into memory and then returns it as a string.
|
|
1915
|
-
*
|
|
1916
|
-
* @returns File data as text.
|
|
1917
|
-
*/
|
|
1918
|
-
async text() {
|
|
1919
|
-
return new TextDecoder().decode(await this.arrayBuffer());
|
|
1920
|
-
}
|
|
1921
|
-
/**
|
|
1922
|
-
* Loads the file data into memory and then returns it as an ArrayBuffer.
|
|
1923
|
-
*
|
|
1924
|
-
* @returns File data as an ArrayBuffer.
|
|
1925
|
-
*/
|
|
1926
|
-
async arrayBuffer() {
|
|
1927
|
-
return await collectBytes(this.stream());
|
|
1928
|
-
}
|
|
1929
|
-
}
|
|
1930
|
-
ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symbol.asyncIterator] = async function* () {
|
|
1931
|
-
const t = this.getReader();
|
|
1932
|
-
try {
|
|
1933
|
-
for (; ; ) {
|
|
1934
|
-
const { done: e, value: r } = await t.read();
|
|
1935
|
-
if (e)
|
|
1936
|
-
return;
|
|
1937
|
-
yield r;
|
|
1938
|
-
}
|
|
1939
|
-
} finally {
|
|
1940
|
-
t.releaseLock();
|
|
1941
|
-
}
|
|
1942
|
-
}, ReadableStream.prototype.iterate = // @ts-ignore
|
|
1943
|
-
ReadableStream.prototype[Symbol.asyncIterator]);
|
|
1944
1417
|
function streamReadFileFromPHP(t, e) {
|
|
1945
1418
|
return new ReadableStream({
|
|
1946
1419
|
async pull(r) {
|
|
@@ -1960,17 +1433,17 @@ async function* iteratePhpFiles(t, e, {
|
|
|
1960
1433
|
const o = n.pop();
|
|
1961
1434
|
if (!o)
|
|
1962
1435
|
return;
|
|
1963
|
-
const
|
|
1964
|
-
for (const l of
|
|
1965
|
-
const
|
|
1966
|
-
if (i.includes(
|
|
1436
|
+
const p = await t.listFiles(o);
|
|
1437
|
+
for (const l of p) {
|
|
1438
|
+
const a = `${o}/${l}`;
|
|
1439
|
+
if (i.includes(a.substring(e.length + 1)))
|
|
1967
1440
|
continue;
|
|
1968
|
-
await t.isDir(
|
|
1969
|
-
streamReadFileFromPHP(t,
|
|
1441
|
+
await t.isDir(a) ? n.push(a) : yield new StreamedFile(
|
|
1442
|
+
streamReadFileFromPHP(t, a),
|
|
1970
1443
|
r ? joinPaths(
|
|
1971
1444
|
s || "",
|
|
1972
|
-
|
|
1973
|
-
) :
|
|
1445
|
+
a.substring(e.length + 1)
|
|
1446
|
+
) : a
|
|
1974
1447
|
);
|
|
1975
1448
|
}
|
|
1976
1449
|
}
|
|
@@ -2128,22 +1601,22 @@ function ensurePathPrefix(t, e) {
|
|
|
2128
1601
|
}
|
|
2129
1602
|
async function encodeAsMultipart(t) {
|
|
2130
1603
|
const e = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${e}`, s = new TextEncoder(), i = [];
|
|
2131
|
-
for (const [l,
|
|
1604
|
+
for (const [l, a] of Object.entries(t))
|
|
2132
1605
|
i.push(`--${e}\r
|
|
2133
|
-
`), i.push(`Content-Disposition: form-data; name="${l}"`),
|
|
2134
|
-
`),
|
|
1606
|
+
`), i.push(`Content-Disposition: form-data; name="${l}"`), a instanceof File && i.push(`; filename="${a.name}"`), i.push(`\r
|
|
1607
|
+
`), a instanceof File && (i.push("Content-Type: application/octet-stream"), i.push(`\r
|
|
2135
1608
|
`)), i.push(`\r
|
|
2136
|
-
`),
|
|
1609
|
+
`), a instanceof File ? i.push(await fileToUint8Array(a)) : i.push(a), i.push(`\r
|
|
2137
1610
|
`);
|
|
2138
1611
|
i.push(`--${e}--\r
|
|
2139
1612
|
`);
|
|
2140
|
-
const n = i.reduce((l,
|
|
2141
|
-
let
|
|
1613
|
+
const n = i.reduce((l, a) => l + a.length, 0), o = new Uint8Array(n);
|
|
1614
|
+
let p = 0;
|
|
2142
1615
|
for (const l of i)
|
|
2143
1616
|
o.set(
|
|
2144
1617
|
typeof l == "string" ? s.encode(l) : l,
|
|
2145
|
-
|
|
2146
|
-
),
|
|
1618
|
+
p
|
|
1619
|
+
), p += l.length;
|
|
2147
1620
|
return { bytes: o, contentType: r };
|
|
2148
1621
|
}
|
|
2149
1622
|
function fileToUint8Array(t) {
|
|
@@ -2250,7 +1723,7 @@ const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "app
|
|
|
2250
1723
|
xspf,
|
|
2251
1724
|
zip
|
|
2252
1725
|
};
|
|
2253
|
-
var
|
|
1726
|
+
var f, R, T, v, S, _, H, F, D, le, z, ce, W, pe, G, ue;
|
|
2254
1727
|
class PHPRequestHandler {
|
|
2255
1728
|
/**
|
|
2256
1729
|
* The request handler needs to decide whether to serve a static asset or
|
|
@@ -2270,11 +1743,11 @@ class PHPRequestHandler {
|
|
|
2270
1743
|
* @param fsPath - Absolute path of the static file to serve.
|
|
2271
1744
|
* @returns The response.
|
|
2272
1745
|
*/
|
|
2273
|
-
|
|
1746
|
+
u(this, D);
|
|
2274
1747
|
/**
|
|
2275
1748
|
* Spawns a new PHP instance and dispatches a request to it.
|
|
2276
1749
|
*/
|
|
2277
|
-
|
|
1750
|
+
u(this, z);
|
|
2278
1751
|
/**
|
|
2279
1752
|
* Runs the requested PHP file with all the request and $_SERVER
|
|
2280
1753
|
* superglobals populated.
|
|
@@ -2282,7 +1755,7 @@ class PHPRequestHandler {
|
|
|
2282
1755
|
* @param request - The request.
|
|
2283
1756
|
* @returns The response.
|
|
2284
1757
|
*/
|
|
2285
|
-
|
|
1758
|
+
u(this, W);
|
|
2286
1759
|
/**
|
|
2287
1760
|
* Resolve the requested path to the filesystem path of the requested PHP file.
|
|
2288
1761
|
*
|
|
@@ -2292,40 +1765,40 @@ class PHPRequestHandler {
|
|
|
2292
1765
|
* @throws {Error} If the requested path doesn't exist.
|
|
2293
1766
|
* @returns The resolved filesystem path.
|
|
2294
1767
|
*/
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
1768
|
+
u(this, G);
|
|
1769
|
+
u(this, f, void 0);
|
|
1770
|
+
u(this, R, void 0);
|
|
1771
|
+
u(this, T, void 0);
|
|
1772
|
+
u(this, v, void 0);
|
|
1773
|
+
u(this, S, void 0);
|
|
1774
|
+
u(this, _, void 0);
|
|
1775
|
+
u(this, H, void 0);
|
|
1776
|
+
u(this, F, void 0);
|
|
2304
1777
|
const {
|
|
2305
1778
|
documentRoot: r = "/www/",
|
|
2306
1779
|
absoluteUrl: s = typeof location == "object" ? location == null ? void 0 : location.href : "",
|
|
2307
1780
|
rewriteRules: i = []
|
|
2308
1781
|
} = e;
|
|
2309
1782
|
"processManager" in e ? this.processManager = e.processManager : this.processManager = new PHPProcessManager({
|
|
2310
|
-
phpFactory: async (
|
|
1783
|
+
phpFactory: async (p) => {
|
|
2311
1784
|
const l = await e.phpFactory({
|
|
2312
|
-
...
|
|
1785
|
+
...p,
|
|
2313
1786
|
requestHandler: this
|
|
2314
1787
|
});
|
|
2315
1788
|
return l.requestHandler = this, l;
|
|
2316
1789
|
},
|
|
2317
1790
|
maxPhpInstances: e.maxPhpInstances
|
|
2318
|
-
}), h(this, F, new HttpCookieStore()), h(this,
|
|
1791
|
+
}), h(this, F, new HttpCookieStore()), h(this, f, r);
|
|
2319
1792
|
const n = new URL(s);
|
|
2320
1793
|
h(this, T, n.hostname), h(this, v, n.port ? Number(n.port) : n.protocol === "https:" ? 443 : 80), h(this, R, (n.protocol || "").replace(":", ""));
|
|
2321
|
-
const o =
|
|
2322
|
-
h(this,
|
|
2323
|
-
|
|
2324
|
-
o ? `:${
|
|
2325
|
-
].join("")), h(this, _, n.pathname.replace(/\/+$/, "")), h(this,
|
|
2326
|
-
`${
|
|
2327
|
-
|
|
2328
|
-
|
|
1794
|
+
const o = c(this, v) !== 443 && c(this, v) !== 80;
|
|
1795
|
+
h(this, S, [
|
|
1796
|
+
c(this, T),
|
|
1797
|
+
o ? `:${c(this, v)}` : ""
|
|
1798
|
+
].join("")), h(this, _, n.pathname.replace(/\/+$/, "")), h(this, H, [
|
|
1799
|
+
`${c(this, R)}://`,
|
|
1800
|
+
c(this, S),
|
|
1801
|
+
c(this, _)
|
|
2329
1802
|
].join("")), this.rewriteRules = i;
|
|
2330
1803
|
}
|
|
2331
1804
|
async getPrimaryPhp() {
|
|
@@ -2350,20 +1823,20 @@ class PHPRequestHandler {
|
|
|
2350
1823
|
*/
|
|
2351
1824
|
internalUrlToPath(e) {
|
|
2352
1825
|
const r = new URL(e);
|
|
2353
|
-
return r.pathname.startsWith(
|
|
1826
|
+
return r.pathname.startsWith(c(this, _)) && (r.pathname = r.pathname.slice(c(this, _).length)), toRelativeUrl(r);
|
|
2354
1827
|
}
|
|
2355
1828
|
/**
|
|
2356
1829
|
* The absolute URL of this PHPRequestHandler instance.
|
|
2357
1830
|
*/
|
|
2358
1831
|
get absoluteUrl() {
|
|
2359
|
-
return
|
|
1832
|
+
return c(this, H);
|
|
2360
1833
|
}
|
|
2361
1834
|
/**
|
|
2362
1835
|
* The directory in the PHP filesystem where the server will look
|
|
2363
1836
|
* for the files to serve. Default: `/var/www`.
|
|
2364
1837
|
*/
|
|
2365
1838
|
get documentRoot() {
|
|
2366
|
-
return
|
|
1839
|
+
return c(this, f);
|
|
2367
1840
|
}
|
|
2368
1841
|
/**
|
|
2369
1842
|
* Serves the request – either by serving a static file, or by
|
|
@@ -2421,14 +1894,14 @@ class PHPRequestHandler {
|
|
|
2421
1894
|
), i = applyRewriteRules(
|
|
2422
1895
|
removePathPrefix(
|
|
2423
1896
|
decodeURIComponent(s.pathname),
|
|
2424
|
-
|
|
1897
|
+
c(this, _)
|
|
2425
1898
|
),
|
|
2426
1899
|
this.rewriteRules
|
|
2427
|
-
), n = joinPaths(
|
|
2428
|
-
return seemsLikeAPHPRequestHandlerPath(n) ? d(this, z, ce).call(this, e, s) : d(this,
|
|
1900
|
+
), n = joinPaths(c(this, f), i);
|
|
1901
|
+
return seemsLikeAPHPRequestHandlerPath(n) ? d(this, z, ce).call(this, e, s) : d(this, D, le).call(this, await this.processManager.getPrimaryPhp(), n);
|
|
2429
1902
|
}
|
|
2430
1903
|
}
|
|
2431
|
-
|
|
1904
|
+
f = new WeakMap(), R = new WeakMap(), T = new WeakMap(), v = new WeakMap(), S = new WeakMap(), _ = new WeakMap(), H = new WeakMap(), F = new WeakMap(), D = new WeakSet(), le = function(e, r) {
|
|
2432
1905
|
if (!e.fileExists(r))
|
|
2433
1906
|
return new PHPResponse(
|
|
2434
1907
|
404,
|
|
@@ -2461,26 +1934,26 @@ m = new WeakMap(), R = new WeakMap(), T = new WeakMap(), v = new WeakMap(), b =
|
|
|
2461
1934
|
return i instanceof MaxPhpInstancesError ? PHPResponse.forHttpCode(502) : PHPResponse.forHttpCode(500);
|
|
2462
1935
|
}
|
|
2463
1936
|
try {
|
|
2464
|
-
return await d(this, W,
|
|
1937
|
+
return await d(this, W, pe).call(this, s.php, e, r);
|
|
2465
1938
|
} finally {
|
|
2466
1939
|
s.reap();
|
|
2467
1940
|
}
|
|
2468
|
-
}, W = new WeakSet(),
|
|
1941
|
+
}, W = new WeakSet(), pe = async function(e, r, s) {
|
|
2469
1942
|
let i = "GET";
|
|
2470
1943
|
const n = {
|
|
2471
|
-
host:
|
|
1944
|
+
host: c(this, S),
|
|
2472
1945
|
...normalizeHeaders(r.headers || {}),
|
|
2473
|
-
cookie:
|
|
1946
|
+
cookie: c(this, F).getCookieRequestHeader()
|
|
2474
1947
|
};
|
|
2475
1948
|
let o = r.body;
|
|
2476
1949
|
if (typeof o == "object" && !(o instanceof Uint8Array)) {
|
|
2477
1950
|
i = "POST";
|
|
2478
|
-
const { bytes: l, contentType:
|
|
2479
|
-
o = l, n["content-type"] =
|
|
1951
|
+
const { bytes: l, contentType: a } = await encodeAsMultipart(o);
|
|
1952
|
+
o = l, n["content-type"] = a;
|
|
2480
1953
|
}
|
|
2481
|
-
let
|
|
1954
|
+
let p;
|
|
2482
1955
|
try {
|
|
2483
|
-
|
|
1956
|
+
p = d(this, G, ue).call(this, e, decodeURIComponent(s.pathname));
|
|
2484
1957
|
} catch {
|
|
2485
1958
|
return PHPResponse.forHttpCode(404);
|
|
2486
1959
|
}
|
|
@@ -2488,33 +1961,33 @@ m = new WeakMap(), R = new WeakMap(), T = new WeakMap(), v = new WeakMap(), b =
|
|
|
2488
1961
|
const l = await e.run({
|
|
2489
1962
|
relativeUri: ensurePathPrefix(
|
|
2490
1963
|
toRelativeUrl(s),
|
|
2491
|
-
|
|
1964
|
+
c(this, _)
|
|
2492
1965
|
),
|
|
2493
|
-
protocol:
|
|
1966
|
+
protocol: c(this, R),
|
|
2494
1967
|
method: r.method || i,
|
|
2495
1968
|
$_SERVER: {
|
|
2496
1969
|
REMOTE_ADDR: "127.0.0.1",
|
|
2497
|
-
DOCUMENT_ROOT:
|
|
2498
|
-
HTTPS:
|
|
1970
|
+
DOCUMENT_ROOT: c(this, f),
|
|
1971
|
+
HTTPS: c(this, H).startsWith("https://") ? "on" : ""
|
|
2499
1972
|
},
|
|
2500
1973
|
body: o,
|
|
2501
|
-
scriptPath:
|
|
1974
|
+
scriptPath: p,
|
|
2502
1975
|
headers: n
|
|
2503
1976
|
});
|
|
2504
|
-
return
|
|
1977
|
+
return c(this, F).rememberCookiesFromResponseHeaders(
|
|
2505
1978
|
l.headers
|
|
2506
1979
|
), l;
|
|
2507
1980
|
} catch (l) {
|
|
2508
|
-
const
|
|
2509
|
-
if (
|
|
2510
|
-
return
|
|
1981
|
+
const a = l;
|
|
1982
|
+
if (a != null && a.response)
|
|
1983
|
+
return a.response;
|
|
2511
1984
|
throw l;
|
|
2512
1985
|
}
|
|
2513
|
-
}, G = new WeakSet(),
|
|
2514
|
-
let s = removePathPrefix(r,
|
|
2515
|
-
s = applyRewriteRules(s, this.rewriteRules), s.includes(".php") ? s = s.split(".php")[0] + ".php" : e.isDir(`${
|
|
2516
|
-
let i = `${
|
|
2517
|
-
if (e.fileExists(i) || (i = `${
|
|
1986
|
+
}, G = new WeakSet(), ue = function(e, r) {
|
|
1987
|
+
let s = removePathPrefix(r, c(this, _));
|
|
1988
|
+
s = applyRewriteRules(s, this.rewriteRules), s.includes(".php") ? s = s.split(".php")[0] + ".php" : e.isDir(`${c(this, f)}${s}`) ? (s.endsWith("/") || (s = `${s}/`), s = `${s}index.php`) : s = "/index.php";
|
|
1989
|
+
let i = `${c(this, f)}${s}`;
|
|
1990
|
+
if (e.fileExists(i) || (i = `${c(this, f)}/index.php`), e.fileExists(i))
|
|
2518
1991
|
return i;
|
|
2519
1992
|
throw new Error(`File not found: ${i}`);
|
|
2520
1993
|
};
|