@php-wasm/fs-journal 0.7.18 → 0.7.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +14 -9
- package/index.js +448 -422
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var
|
|
1
|
+
var H = (e, t, r) => {
|
|
2
2
|
if (!t.has(e))
|
|
3
3
|
throw TypeError("Cannot " + r);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
5
|
+
var f = (e, t, r) => (H(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);
|
|
9
|
-
},
|
|
10
|
-
var
|
|
9
|
+
}, p = (e, t, r, s) => (H(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
|
|
10
|
+
var h = (e, t, r) => (H(e, t, "access private method"), r);
|
|
11
11
|
const currentJsRuntime = function() {
|
|
12
12
|
var e;
|
|
13
13
|
return typeof process < "u" && ((e = process.release) == null ? void 0 : e.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
|
|
@@ -18,25 +18,25 @@ const currentJsRuntime = function() {
|
|
|
18
18
|
}();
|
|
19
19
|
if (currentJsRuntime === "NODE") {
|
|
20
20
|
let e = function(r) {
|
|
21
|
-
return new Promise(function(s,
|
|
22
|
-
r.onload = r.onerror = function(
|
|
23
|
-
r.onload = r.onerror = null,
|
|
21
|
+
return new Promise(function(s, n) {
|
|
22
|
+
r.onload = r.onerror = function(i) {
|
|
23
|
+
r.onload = r.onerror = null, i.type === "load" ? s(r.result) : n(new Error("Failed to read the blob/file"));
|
|
24
24
|
};
|
|
25
25
|
});
|
|
26
26
|
}, t = function() {
|
|
27
|
-
const r = new Uint8Array([1, 2, 3, 4]),
|
|
27
|
+
const r = new Uint8Array([1, 2, 3, 4]), n = new File([r], "test").stream();
|
|
28
28
|
try {
|
|
29
|
-
return
|
|
29
|
+
return n.getReader({ mode: "byob" }), !0;
|
|
30
30
|
} catch {
|
|
31
31
|
return !1;
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
if (typeof File > "u") {
|
|
35
35
|
class r extends Blob {
|
|
36
|
-
constructor(
|
|
37
|
-
super(
|
|
36
|
+
constructor(n, i, o) {
|
|
37
|
+
super(n);
|
|
38
38
|
let a;
|
|
39
|
-
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 =
|
|
39
|
+
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 = i || "";
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
global.File = r;
|
|
@@ -55,14 +55,14 @@ if (currentJsRuntime === "NODE") {
|
|
|
55
55
|
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
56
56
|
// this if needed.
|
|
57
57
|
autoAllocateChunkSize: 512 * 1024,
|
|
58
|
-
async pull(
|
|
59
|
-
const
|
|
58
|
+
async pull(n) {
|
|
59
|
+
const i = n.byobRequest.view, a = await s.slice(
|
|
60
60
|
r,
|
|
61
|
-
r +
|
|
61
|
+
r + i.byteLength
|
|
62
62
|
).arrayBuffer(), l = new Uint8Array(a);
|
|
63
|
-
new Uint8Array(
|
|
63
|
+
new Uint8Array(i.buffer).set(l);
|
|
64
64
|
const c = l.byteLength;
|
|
65
|
-
|
|
65
|
+
n.byobRequest.respond(c), r += c, r >= s.size && n.close();
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
});
|
|
@@ -77,33 +77,170 @@ if (currentJsRuntime === "NODE" && typeof CustomEvent > "u") {
|
|
|
77
77
|
}
|
|
78
78
|
globalThis.CustomEvent = e;
|
|
79
79
|
}
|
|
80
|
-
const
|
|
81
|
-
|
|
80
|
+
const responseTexts = {
|
|
81
|
+
500: "Internal Server Error",
|
|
82
|
+
502: "Bad Gateway",
|
|
83
|
+
404: "Not Found",
|
|
84
|
+
403: "Forbidden",
|
|
85
|
+
401: "Unauthorized",
|
|
86
|
+
400: "Bad Request",
|
|
87
|
+
301: "Moved Permanently",
|
|
88
|
+
302: "Found",
|
|
89
|
+
307: "Temporary Redirect",
|
|
90
|
+
308: "Permanent Redirect",
|
|
91
|
+
204: "No Content",
|
|
92
|
+
201: "Created",
|
|
93
|
+
200: "OK"
|
|
94
|
+
};
|
|
95
|
+
class PHPResponse {
|
|
96
|
+
constructor(t, r, s, n = "", i = 0) {
|
|
97
|
+
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = i, this.errors = n;
|
|
98
|
+
}
|
|
99
|
+
static forHttpCode(t, r = "") {
|
|
100
|
+
return new PHPResponse(
|
|
101
|
+
t,
|
|
102
|
+
{},
|
|
103
|
+
new TextEncoder().encode(
|
|
104
|
+
r || responseTexts[t] || ""
|
|
105
|
+
)
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
static fromRawData(t) {
|
|
109
|
+
return new PHPResponse(
|
|
110
|
+
t.httpStatusCode,
|
|
111
|
+
t.headers,
|
|
112
|
+
t.bytes,
|
|
113
|
+
t.errors,
|
|
114
|
+
t.exitCode
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
toRawData() {
|
|
118
|
+
return {
|
|
119
|
+
headers: this.headers,
|
|
120
|
+
bytes: this.bytes,
|
|
121
|
+
errors: this.errors,
|
|
122
|
+
exitCode: this.exitCode,
|
|
123
|
+
httpStatusCode: this.httpStatusCode
|
|
124
|
+
};
|
|
125
|
+
}
|
|
82
126
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* @param type The name of the event
|
|
86
|
-
* @param options A dictionary object that allows for setting
|
|
87
|
-
* attributes via object members of the same name.
|
|
127
|
+
* Response body as JSON.
|
|
88
128
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
get error() {
|
|
93
|
-
return this[kError];
|
|
129
|
+
get json() {
|
|
130
|
+
return JSON.parse(this.text);
|
|
94
131
|
}
|
|
95
|
-
|
|
96
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Response body as text.
|
|
134
|
+
*/
|
|
135
|
+
get text() {
|
|
136
|
+
return new TextDecoder().decode(this.bytes);
|
|
97
137
|
}
|
|
98
138
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
139
|
+
const FileErrorCodes = {
|
|
140
|
+
0: "No error occurred. System call completed successfully.",
|
|
141
|
+
1: "Argument list too long.",
|
|
142
|
+
2: "Permission denied.",
|
|
143
|
+
3: "Address in use.",
|
|
144
|
+
4: "Address not available.",
|
|
145
|
+
5: "Address family not supported.",
|
|
146
|
+
6: "Resource unavailable, or operation would block.",
|
|
147
|
+
7: "Connection already in progress.",
|
|
148
|
+
8: "Bad file descriptor.",
|
|
149
|
+
9: "Bad message.",
|
|
150
|
+
10: "Device or resource busy.",
|
|
151
|
+
11: "Operation canceled.",
|
|
152
|
+
12: "No child processes.",
|
|
153
|
+
13: "Connection aborted.",
|
|
154
|
+
14: "Connection refused.",
|
|
155
|
+
15: "Connection reset.",
|
|
156
|
+
16: "Resource deadlock would occur.",
|
|
157
|
+
17: "Destination address required.",
|
|
158
|
+
18: "Mathematics argument out of domain of function.",
|
|
159
|
+
19: "Reserved.",
|
|
160
|
+
20: "File exists.",
|
|
161
|
+
21: "Bad address.",
|
|
162
|
+
22: "File too large.",
|
|
163
|
+
23: "Host is unreachable.",
|
|
164
|
+
24: "Identifier removed.",
|
|
165
|
+
25: "Illegal byte sequence.",
|
|
166
|
+
26: "Operation in progress.",
|
|
167
|
+
27: "Interrupted function.",
|
|
168
|
+
28: "Invalid argument.",
|
|
169
|
+
29: "I/O error.",
|
|
170
|
+
30: "Socket is connected.",
|
|
171
|
+
31: "There is a directory under that path.",
|
|
172
|
+
32: "Too many levels of symbolic links.",
|
|
173
|
+
33: "File descriptor value too large.",
|
|
174
|
+
34: "Too many links.",
|
|
175
|
+
35: "Message too large.",
|
|
176
|
+
36: "Reserved.",
|
|
177
|
+
37: "Filename too long.",
|
|
178
|
+
38: "Network is down.",
|
|
179
|
+
39: "Connection aborted by network.",
|
|
180
|
+
40: "Network unreachable.",
|
|
181
|
+
41: "Too many files open in system.",
|
|
182
|
+
42: "No buffer space available.",
|
|
183
|
+
43: "No such device.",
|
|
184
|
+
44: "There is no such file or directory OR the parent directory does not exist.",
|
|
185
|
+
45: "Executable file format error.",
|
|
186
|
+
46: "No locks available.",
|
|
187
|
+
47: "Reserved.",
|
|
188
|
+
48: "Not enough space.",
|
|
189
|
+
49: "No message of the desired type.",
|
|
190
|
+
50: "Protocol not available.",
|
|
191
|
+
51: "No space left on device.",
|
|
192
|
+
52: "Function not supported.",
|
|
193
|
+
53: "The socket is not connected.",
|
|
194
|
+
54: "Not a directory or a symbolic link to a directory.",
|
|
195
|
+
55: "Directory not empty.",
|
|
196
|
+
56: "State not recoverable.",
|
|
197
|
+
57: "Not a socket.",
|
|
198
|
+
58: "Not supported, or operation not supported on socket.",
|
|
199
|
+
59: "Inappropriate I/O control operation.",
|
|
200
|
+
60: "No such device or address.",
|
|
201
|
+
61: "Value too large to be stored in data type.",
|
|
202
|
+
62: "Previous owner died.",
|
|
203
|
+
63: "Operation not permitted.",
|
|
204
|
+
64: "Broken pipe.",
|
|
205
|
+
65: "Protocol error.",
|
|
206
|
+
66: "Protocol not supported.",
|
|
207
|
+
67: "Protocol wrong type for socket.",
|
|
208
|
+
68: "Result too large.",
|
|
209
|
+
69: "Read-only file system.",
|
|
210
|
+
70: "Invalid seek.",
|
|
211
|
+
71: "No such process.",
|
|
212
|
+
72: "Reserved.",
|
|
213
|
+
73: "Connection timed out.",
|
|
214
|
+
74: "Text file busy.",
|
|
215
|
+
75: "Cross-device link.",
|
|
216
|
+
76: "Extension: Capabilities insufficient."
|
|
217
|
+
};
|
|
218
|
+
function getEmscriptenFsError(e) {
|
|
219
|
+
const t = typeof e == "object" ? e == null ? void 0 : e.errno : null;
|
|
220
|
+
if (t in FileErrorCodes)
|
|
221
|
+
return FileErrorCodes[t];
|
|
222
|
+
}
|
|
223
|
+
function rethrowFileSystemError(e = "") {
|
|
224
|
+
return function(r, s, n) {
|
|
225
|
+
const i = n.value;
|
|
226
|
+
n.value = function(...o) {
|
|
227
|
+
try {
|
|
228
|
+
return i.apply(this, o);
|
|
229
|
+
} catch (a) {
|
|
230
|
+
const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
231
|
+
if (l in FileErrorCodes) {
|
|
232
|
+
const c = FileErrorCodes[l], u = typeof o[0] == "string" ? o[0] : null, g = u !== null ? e.replaceAll("{path}", u) : e;
|
|
233
|
+
throw new Error(`${g}: ${c}`, {
|
|
234
|
+
cause: a
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
throw a;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
};
|
|
104
241
|
}
|
|
105
242
|
const logToConsole = (e, ...t) => {
|
|
106
|
-
switch (e.severity) {
|
|
243
|
+
switch (typeof e.message == "string" ? e.message = prepareLogMessage(e.message) : e.message.message && typeof e.message.message == "string" && (e.message.message = prepareLogMessage(e.message.message)), e.severity) {
|
|
107
244
|
case "Debug":
|
|
108
245
|
console.debug(e.message, ...t);
|
|
109
246
|
break;
|
|
@@ -122,17 +259,15 @@ const logToConsole = (e, ...t) => {
|
|
|
122
259
|
default:
|
|
123
260
|
console.log(e.message, ...t);
|
|
124
261
|
}
|
|
125
|
-
}, prepareLogMessage = (e
|
|
126
|
-
|
|
127
|
-
...t.map((r) => JSON.stringify(r))
|
|
128
|
-
].join(" "), logs = [], addToLogArray = (e) => {
|
|
262
|
+
}, prepareLogMessage$1 = (e) => e instanceof Error ? [e.message, e.stack].join(`
|
|
263
|
+
`) : JSON.stringify(e, null, 2), logs = [], addToLogArray = (e) => {
|
|
129
264
|
logs.push(e);
|
|
130
265
|
}, logToMemory = (e) => {
|
|
131
266
|
if (e.raw === !0)
|
|
132
267
|
addToLogArray(e.message);
|
|
133
268
|
else {
|
|
134
269
|
const t = formatLogEntry(
|
|
135
|
-
typeof e.message == "object" ? prepareLogMessage(e.message) : e.message,
|
|
270
|
+
typeof e.message == "object" ? prepareLogMessage$1(e.message) : e.message,
|
|
136
271
|
e.severity ?? "Info",
|
|
137
272
|
e.prefix ?? "JavaScript"
|
|
138
273
|
);
|
|
@@ -251,22 +386,61 @@ class Logger extends EventTarget {
|
|
|
251
386
|
);
|
|
252
387
|
}
|
|
253
388
|
}
|
|
254
|
-
const
|
|
255
|
-
|
|
389
|
+
const getDefaultHandlers = () => {
|
|
390
|
+
try {
|
|
391
|
+
if (process.env.NODE_ENV === "test")
|
|
392
|
+
return [logToMemory];
|
|
393
|
+
} catch {
|
|
394
|
+
}
|
|
395
|
+
return [logToMemory, logToConsole];
|
|
396
|
+
}, logger = new Logger(getDefaultHandlers()), prepareLogMessage = (e) => e.replace(/\t/g, ""), formatLogEntry = (e, t, r) => {
|
|
397
|
+
const s = /* @__PURE__ */ new Date(), n = new Intl.DateTimeFormat("en-GB", {
|
|
256
398
|
year: "numeric",
|
|
257
399
|
month: "short",
|
|
258
400
|
day: "2-digit",
|
|
259
401
|
timeZone: "UTC"
|
|
260
|
-
}).format(s).replace(/ /g, "-"),
|
|
402
|
+
}).format(s).replace(/ /g, "-"), i = new Intl.DateTimeFormat("en-GB", {
|
|
261
403
|
hour: "2-digit",
|
|
262
404
|
minute: "2-digit",
|
|
263
405
|
second: "2-digit",
|
|
264
406
|
hour12: !1,
|
|
265
407
|
timeZone: "UTC",
|
|
266
408
|
timeZoneName: "short"
|
|
267
|
-
}).format(s);
|
|
268
|
-
return `[${
|
|
269
|
-
};
|
|
409
|
+
}).format(s), o = n + " " + i;
|
|
410
|
+
return e = prepareLogMessage(e), `[${o}] ${r} ${t}: ${e}`;
|
|
411
|
+
}, loadedRuntimes = /* @__PURE__ */ new Map();
|
|
412
|
+
function getLoadedRuntime(e) {
|
|
413
|
+
return loadedRuntimes.get(e);
|
|
414
|
+
}
|
|
415
|
+
(function() {
|
|
416
|
+
var e;
|
|
417
|
+
return typeof process < "u" && ((e = process.release) == null ? void 0 : e.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
|
|
418
|
+
})();
|
|
419
|
+
const kError = Symbol("error"), kMessage = Symbol("message");
|
|
420
|
+
class ErrorEvent2 extends Event {
|
|
421
|
+
/**
|
|
422
|
+
* Create a new `ErrorEvent`.
|
|
423
|
+
*
|
|
424
|
+
* @param type The name of the event
|
|
425
|
+
* @param options A dictionary object that allows for setting
|
|
426
|
+
* attributes via object members of the same name.
|
|
427
|
+
*/
|
|
428
|
+
constructor(t, r = {}) {
|
|
429
|
+
super(t), this[kError] = r.error === void 0 ? null : r.error, this[kMessage] = r.message === void 0 ? "" : r.message;
|
|
430
|
+
}
|
|
431
|
+
get error() {
|
|
432
|
+
return this[kError];
|
|
433
|
+
}
|
|
434
|
+
get message() {
|
|
435
|
+
return this[kMessage];
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
Object.defineProperty(ErrorEvent2.prototype, "error", { enumerable: !0 });
|
|
439
|
+
Object.defineProperty(ErrorEvent2.prototype, "message", { enumerable: !0 });
|
|
440
|
+
const ErrorEvent = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : ErrorEvent2;
|
|
441
|
+
function isExitCodeZero(e) {
|
|
442
|
+
return e instanceof Error ? "exitCode" in e && (e == null ? void 0 : e.exitCode) === 0 || (e == null ? void 0 : e.name) === "ExitStatus" && "status" in e && e.status === 0 : !1;
|
|
443
|
+
}
|
|
270
444
|
class UnhandledRejectionsTarget extends EventTarget {
|
|
271
445
|
constructor() {
|
|
272
446
|
super(...arguments), this.listenersCount = 0;
|
|
@@ -289,16 +463,16 @@ function improveWASMErrorReporting(e) {
|
|
|
289
463
|
for (const r in e.asm)
|
|
290
464
|
if (typeof e.asm[r] == "function") {
|
|
291
465
|
const s = e.asm[r];
|
|
292
|
-
e.asm[r] = function(...
|
|
293
|
-
var
|
|
466
|
+
e.asm[r] = function(...n) {
|
|
467
|
+
var i;
|
|
294
468
|
try {
|
|
295
|
-
return s(...
|
|
469
|
+
return s(...n);
|
|
296
470
|
} catch (o) {
|
|
297
471
|
if (!(o instanceof Error))
|
|
298
472
|
throw o;
|
|
299
473
|
const a = clarifyErrorMessage(
|
|
300
474
|
o,
|
|
301
|
-
(
|
|
475
|
+
(i = e.lastAsyncifyStackSource) == null ? void 0 : i.stack
|
|
302
476
|
);
|
|
303
477
|
if (e.lastAsyncifyStackSource && (o.cause = e.lastAsyncifyStackSource), t.hasListeners()) {
|
|
304
478
|
t.dispatchEvent(
|
|
@@ -446,6 +620,13 @@ function joinPaths(...e) {
|
|
|
446
620
|
const r = t[0] === "/", s = t.substring(t.length - 1) === "/";
|
|
447
621
|
return t = normalizePath$1(t), !t && !r && (t = "."), t && s && (t += "/"), t;
|
|
448
622
|
}
|
|
623
|
+
function dirname(e) {
|
|
624
|
+
if (e === "/")
|
|
625
|
+
return "/";
|
|
626
|
+
e = normalizePath$1(e);
|
|
627
|
+
const t = e.lastIndexOf("/");
|
|
628
|
+
return t === -1 ? "" : t === 0 ? "/" : e.substr(0, t);
|
|
629
|
+
}
|
|
449
630
|
function basename(e) {
|
|
450
631
|
if (e === "/")
|
|
451
632
|
return "/";
|
|
@@ -463,8 +644,8 @@ function normalizePath$1(e) {
|
|
|
463
644
|
function normalizePathsArray(e, t) {
|
|
464
645
|
let r = 0;
|
|
465
646
|
for (let s = e.length - 1; s >= 0; s--) {
|
|
466
|
-
const
|
|
467
|
-
|
|
647
|
+
const n = e[s];
|
|
648
|
+
n === "." ? e.splice(s, 1) : n === ".." ? (e.splice(s, 1), r++) : r && (e.splice(s, 1), r--);
|
|
468
649
|
}
|
|
469
650
|
if (t)
|
|
470
651
|
for (; r; r--)
|
|
@@ -472,18 +653,18 @@ function normalizePathsArray(e, t) {
|
|
|
472
653
|
return e;
|
|
473
654
|
}
|
|
474
655
|
function splitShellCommand(e) {
|
|
475
|
-
let s = 0,
|
|
476
|
-
const
|
|
656
|
+
let s = 0, n = "";
|
|
657
|
+
const i = [];
|
|
477
658
|
let o = "";
|
|
478
659
|
for (let a = 0; a < e.length; a++) {
|
|
479
660
|
const l = e[a];
|
|
480
|
-
l === "\\" ? ((e[a + 1] === '"' || e[a + 1] === "'") && a++, o += e[a]) : s === 0 ? l === '"' || l === "'" ? (s = 1,
|
|
661
|
+
l === "\\" ? ((e[a + 1] === '"' || e[a + 1] === "'") && a++, o += e[a]) : s === 0 ? l === '"' || l === "'" ? (s = 1, n = l) : l.match(/\s/) ? (o.trim().length && i.push(o.trim()), o = l) : i.length && !o ? o = i.pop() + l : o += l : s === 1 && (l === n ? (s = 0, n = "") : o += l);
|
|
481
662
|
}
|
|
482
|
-
return o &&
|
|
663
|
+
return o && i.push(o.trim()), i;
|
|
483
664
|
}
|
|
484
665
|
function createSpawnHandler(e) {
|
|
485
666
|
return function(t, r = [], s = {}) {
|
|
486
|
-
const
|
|
667
|
+
const n = new ChildProcess(), i = new ProcessApi(n);
|
|
487
668
|
return setTimeout(async () => {
|
|
488
669
|
let o = [];
|
|
489
670
|
if (r.length)
|
|
@@ -495,12 +676,12 @@ function createSpawnHandler(e) {
|
|
|
495
676
|
else
|
|
496
677
|
throw new Error("Invalid command ", t);
|
|
497
678
|
try {
|
|
498
|
-
await e(o,
|
|
679
|
+
await e(o, i, s);
|
|
499
680
|
} catch (a) {
|
|
500
|
-
|
|
681
|
+
n.emit("error", a), typeof a == "object" && a !== null && "message" in a && typeof a.message == "string" && i.stderr(a.message), i.exit(1);
|
|
501
682
|
}
|
|
502
|
-
|
|
503
|
-
}),
|
|
683
|
+
n.emit("spawn", !0);
|
|
684
|
+
}), n;
|
|
504
685
|
};
|
|
505
686
|
}
|
|
506
687
|
class EventEmitter {
|
|
@@ -556,194 +737,10 @@ class ChildProcess extends EventEmitter {
|
|
|
556
737
|
};
|
|
557
738
|
}
|
|
558
739
|
}
|
|
559
|
-
ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symbol.asyncIterator] = async function* () {
|
|
560
|
-
const e = this.getReader();
|
|
561
|
-
try {
|
|
562
|
-
for (; ; ) {
|
|
563
|
-
const { done: t, value: r } = await e.read();
|
|
564
|
-
if (t)
|
|
565
|
-
return;
|
|
566
|
-
yield r;
|
|
567
|
-
}
|
|
568
|
-
} finally {
|
|
569
|
-
e.releaseLock();
|
|
570
|
-
}
|
|
571
|
-
}, ReadableStream.prototype.iterate = // @ts-ignore
|
|
572
|
-
ReadableStream.prototype[Symbol.asyncIterator]);
|
|
573
|
-
const responseTexts = {
|
|
574
|
-
500: "Internal Server Error",
|
|
575
|
-
502: "Bad Gateway",
|
|
576
|
-
404: "Not Found",
|
|
577
|
-
403: "Forbidden",
|
|
578
|
-
401: "Unauthorized",
|
|
579
|
-
400: "Bad Request",
|
|
580
|
-
301: "Moved Permanently",
|
|
581
|
-
302: "Found",
|
|
582
|
-
307: "Temporary Redirect",
|
|
583
|
-
308: "Permanent Redirect",
|
|
584
|
-
204: "No Content",
|
|
585
|
-
201: "Created",
|
|
586
|
-
200: "OK"
|
|
587
|
-
};
|
|
588
|
-
class PHPResponse {
|
|
589
|
-
constructor(t, r, s, i = "", n = 0) {
|
|
590
|
-
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = n, this.errors = i;
|
|
591
|
-
}
|
|
592
|
-
static forHttpCode(t, r = "") {
|
|
593
|
-
return new PHPResponse(
|
|
594
|
-
t,
|
|
595
|
-
{},
|
|
596
|
-
new TextEncoder().encode(
|
|
597
|
-
r || responseTexts[t] || ""
|
|
598
|
-
)
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
|
-
static fromRawData(t) {
|
|
602
|
-
return new PHPResponse(
|
|
603
|
-
t.httpStatusCode,
|
|
604
|
-
t.headers,
|
|
605
|
-
t.bytes,
|
|
606
|
-
t.errors,
|
|
607
|
-
t.exitCode
|
|
608
|
-
);
|
|
609
|
-
}
|
|
610
|
-
toRawData() {
|
|
611
|
-
return {
|
|
612
|
-
headers: this.headers,
|
|
613
|
-
bytes: this.bytes,
|
|
614
|
-
errors: this.errors,
|
|
615
|
-
exitCode: this.exitCode,
|
|
616
|
-
httpStatusCode: this.httpStatusCode
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
|
-
/**
|
|
620
|
-
* Response body as JSON.
|
|
621
|
-
*/
|
|
622
|
-
get json() {
|
|
623
|
-
return JSON.parse(this.text);
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* Response body as text.
|
|
627
|
-
*/
|
|
628
|
-
get text() {
|
|
629
|
-
return new TextDecoder().decode(this.bytes);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
const FileErrorCodes = {
|
|
633
|
-
0: "No error occurred. System call completed successfully.",
|
|
634
|
-
1: "Argument list too long.",
|
|
635
|
-
2: "Permission denied.",
|
|
636
|
-
3: "Address in use.",
|
|
637
|
-
4: "Address not available.",
|
|
638
|
-
5: "Address family not supported.",
|
|
639
|
-
6: "Resource unavailable, or operation would block.",
|
|
640
|
-
7: "Connection already in progress.",
|
|
641
|
-
8: "Bad file descriptor.",
|
|
642
|
-
9: "Bad message.",
|
|
643
|
-
10: "Device or resource busy.",
|
|
644
|
-
11: "Operation canceled.",
|
|
645
|
-
12: "No child processes.",
|
|
646
|
-
13: "Connection aborted.",
|
|
647
|
-
14: "Connection refused.",
|
|
648
|
-
15: "Connection reset.",
|
|
649
|
-
16: "Resource deadlock would occur.",
|
|
650
|
-
17: "Destination address required.",
|
|
651
|
-
18: "Mathematics argument out of domain of function.",
|
|
652
|
-
19: "Reserved.",
|
|
653
|
-
20: "File exists.",
|
|
654
|
-
21: "Bad address.",
|
|
655
|
-
22: "File too large.",
|
|
656
|
-
23: "Host is unreachable.",
|
|
657
|
-
24: "Identifier removed.",
|
|
658
|
-
25: "Illegal byte sequence.",
|
|
659
|
-
26: "Operation in progress.",
|
|
660
|
-
27: "Interrupted function.",
|
|
661
|
-
28: "Invalid argument.",
|
|
662
|
-
29: "I/O error.",
|
|
663
|
-
30: "Socket is connected.",
|
|
664
|
-
31: "There is a directory under that path.",
|
|
665
|
-
32: "Too many levels of symbolic links.",
|
|
666
|
-
33: "File descriptor value too large.",
|
|
667
|
-
34: "Too many links.",
|
|
668
|
-
35: "Message too large.",
|
|
669
|
-
36: "Reserved.",
|
|
670
|
-
37: "Filename too long.",
|
|
671
|
-
38: "Network is down.",
|
|
672
|
-
39: "Connection aborted by network.",
|
|
673
|
-
40: "Network unreachable.",
|
|
674
|
-
41: "Too many files open in system.",
|
|
675
|
-
42: "No buffer space available.",
|
|
676
|
-
43: "No such device.",
|
|
677
|
-
44: "There is no such file or directory OR the parent directory does not exist.",
|
|
678
|
-
45: "Executable file format error.",
|
|
679
|
-
46: "No locks available.",
|
|
680
|
-
47: "Reserved.",
|
|
681
|
-
48: "Not enough space.",
|
|
682
|
-
49: "No message of the desired type.",
|
|
683
|
-
50: "Protocol not available.",
|
|
684
|
-
51: "No space left on device.",
|
|
685
|
-
52: "Function not supported.",
|
|
686
|
-
53: "The socket is not connected.",
|
|
687
|
-
54: "Not a directory or a symbolic link to a directory.",
|
|
688
|
-
55: "Directory not empty.",
|
|
689
|
-
56: "State not recoverable.",
|
|
690
|
-
57: "Not a socket.",
|
|
691
|
-
58: "Not supported, or operation not supported on socket.",
|
|
692
|
-
59: "Inappropriate I/O control operation.",
|
|
693
|
-
60: "No such device or address.",
|
|
694
|
-
61: "Value too large to be stored in data type.",
|
|
695
|
-
62: "Previous owner died.",
|
|
696
|
-
63: "Operation not permitted.",
|
|
697
|
-
64: "Broken pipe.",
|
|
698
|
-
65: "Protocol error.",
|
|
699
|
-
66: "Protocol not supported.",
|
|
700
|
-
67: "Protocol wrong type for socket.",
|
|
701
|
-
68: "Result too large.",
|
|
702
|
-
69: "Read-only file system.",
|
|
703
|
-
70: "Invalid seek.",
|
|
704
|
-
71: "No such process.",
|
|
705
|
-
72: "Reserved.",
|
|
706
|
-
73: "Connection timed out.",
|
|
707
|
-
74: "Text file busy.",
|
|
708
|
-
75: "Cross-device link.",
|
|
709
|
-
76: "Extension: Capabilities insufficient."
|
|
710
|
-
};
|
|
711
|
-
function getEmscriptenFsError(e) {
|
|
712
|
-
const t = typeof e == "object" ? e == null ? void 0 : e.errno : null;
|
|
713
|
-
if (t in FileErrorCodes)
|
|
714
|
-
return FileErrorCodes[t];
|
|
715
|
-
}
|
|
716
|
-
function rethrowFileSystemError(e = "") {
|
|
717
|
-
return function(r, s, i) {
|
|
718
|
-
const n = i.value;
|
|
719
|
-
i.value = function(...o) {
|
|
720
|
-
try {
|
|
721
|
-
return n.apply(this, o);
|
|
722
|
-
} catch (a) {
|
|
723
|
-
const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
724
|
-
if (l in FileErrorCodes) {
|
|
725
|
-
const c = FileErrorCodes[l], d = typeof o[0] == "string" ? o[0] : null, g = d !== null ? e.replaceAll("{path}", d) : e;
|
|
726
|
-
throw new Error(`${g}: ${c}`, {
|
|
727
|
-
cause: a
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
throw a;
|
|
731
|
-
}
|
|
732
|
-
};
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
const loadedRuntimes = /* @__PURE__ */ new Map();
|
|
736
|
-
function getLoadedRuntime(e) {
|
|
737
|
-
return loadedRuntimes.get(e);
|
|
738
|
-
}
|
|
739
|
-
(function() {
|
|
740
|
-
var e;
|
|
741
|
-
return typeof process < "u" && ((e = process.release) == null ? void 0 : e.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
|
|
742
|
-
})();
|
|
743
740
|
var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = (e, t, r, s) => {
|
|
744
|
-
for (var
|
|
745
|
-
(o = e[
|
|
746
|
-
return s &&
|
|
741
|
+
for (var n = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, i = e.length - 1, o; i >= 0; i--)
|
|
742
|
+
(o = e[i]) && (n = (s ? o(t, r, n) : o(n)) || n);
|
|
743
|
+
return s && n && __defProp(t, r, n), n;
|
|
747
744
|
};
|
|
748
745
|
const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
|
|
749
746
|
class PHPExecutionFailureError extends Error {
|
|
@@ -751,7 +748,8 @@ class PHPExecutionFailureError extends Error {
|
|
|
751
748
|
super(t), this.response = r, this.source = s;
|
|
752
749
|
}
|
|
753
750
|
}
|
|
754
|
-
|
|
751
|
+
const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php";
|
|
752
|
+
var E, m, y, _, w, P, B, b, L, R, U, S, $, T, q, F, W, x, z, C, j, k, G, N, J, v, O, A, V, M, Q, I, Y;
|
|
755
753
|
class BasePHP {
|
|
756
754
|
/**
|
|
757
755
|
* Initializes a PHP runtime.
|
|
@@ -770,46 +768,43 @@ class BasePHP {
|
|
|
770
768
|
* was provided.
|
|
771
769
|
* @returns Computed $_SERVER entries.
|
|
772
770
|
*/
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
u(this, m, void 0);
|
|
794
|
-
u(this, P, void 0);
|
|
795
|
-
f(this, E, []), f(this, _, !1), f(this, y, null), f(this, m, /* @__PURE__ */ new Map()), f(this, P, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e);
|
|
771
|
+
d(this, P);
|
|
772
|
+
d(this, b);
|
|
773
|
+
d(this, R);
|
|
774
|
+
d(this, S);
|
|
775
|
+
d(this, T);
|
|
776
|
+
d(this, F);
|
|
777
|
+
d(this, x);
|
|
778
|
+
d(this, C);
|
|
779
|
+
d(this, k);
|
|
780
|
+
d(this, N);
|
|
781
|
+
d(this, v);
|
|
782
|
+
d(this, A);
|
|
783
|
+
d(this, M);
|
|
784
|
+
d(this, I);
|
|
785
|
+
d(this, E, void 0);
|
|
786
|
+
d(this, m, void 0);
|
|
787
|
+
d(this, y, void 0);
|
|
788
|
+
d(this, _, void 0);
|
|
789
|
+
d(this, w, void 0);
|
|
790
|
+
p(this, m, !1), p(this, y, null), p(this, _, /* @__PURE__ */ new Map()), p(this, w, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e);
|
|
796
791
|
}
|
|
797
792
|
addEventListener(e, t) {
|
|
798
|
-
|
|
793
|
+
f(this, _).has(e) || f(this, _).set(e, /* @__PURE__ */ new Set()), f(this, _).get(e).add(t);
|
|
799
794
|
}
|
|
800
795
|
removeEventListener(e, t) {
|
|
801
796
|
var r;
|
|
802
|
-
(r =
|
|
797
|
+
(r = f(this, _).get(e)) == null || r.delete(t);
|
|
803
798
|
}
|
|
804
799
|
dispatchEvent(e) {
|
|
805
|
-
const t =
|
|
800
|
+
const t = f(this, _).get(e.type);
|
|
806
801
|
if (t)
|
|
807
802
|
for (const r of t)
|
|
808
803
|
r(e);
|
|
809
804
|
}
|
|
810
805
|
/** @inheritDoc */
|
|
811
806
|
async onMessage(e) {
|
|
812
|
-
|
|
807
|
+
f(this, w).push(e);
|
|
813
808
|
}
|
|
814
809
|
/** @inheritDoc */
|
|
815
810
|
async setSpawnHandler(handler) {
|
|
@@ -837,14 +832,60 @@ class BasePHP {
|
|
|
837
832
|
const t = getLoadedRuntime(e);
|
|
838
833
|
if (!t)
|
|
839
834
|
throw new Error("Invalid PHP runtime id.");
|
|
840
|
-
this[__private__dont__use] = t,
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
835
|
+
this[__private__dont__use] = t, this[__private__dont__use].ccall(
|
|
836
|
+
"wasm_set_phpini_path",
|
|
837
|
+
null,
|
|
838
|
+
["string"],
|
|
839
|
+
[PHP_INI_PATH]
|
|
840
|
+
), this.fileExists(PHP_INI_PATH) || this.writeFile(
|
|
841
|
+
PHP_INI_PATH,
|
|
842
|
+
[
|
|
843
|
+
"auto_prepend_file=" + AUTO_PREPEND_SCRIPT,
|
|
844
|
+
"memory_limit=256M",
|
|
845
|
+
"ignore_repeated_errors = 1",
|
|
846
|
+
"error_reporting = E_ALL",
|
|
847
|
+
"display_errors = 1",
|
|
848
|
+
"html_errors = 1",
|
|
849
|
+
"display_startup_errors = On",
|
|
850
|
+
"log_errors = 1",
|
|
851
|
+
"always_populate_raw_post_data = -1",
|
|
852
|
+
"upload_max_filesize = 2000M",
|
|
853
|
+
"post_max_size = 2000M",
|
|
854
|
+
"disable_functions = curl_exec,curl_multi_exec",
|
|
855
|
+
"allow_url_fopen = Off",
|
|
856
|
+
"allow_url_include = Off",
|
|
857
|
+
"session.save_path = /home/web_user",
|
|
858
|
+
"implicit_flush = 1",
|
|
859
|
+
"output_buffering = 0",
|
|
860
|
+
"max_execution_time = 0",
|
|
861
|
+
"max_input_time = -1"
|
|
862
|
+
].join(`
|
|
863
|
+
`)
|
|
864
|
+
), this.fileExists(AUTO_PREPEND_SCRIPT) || this.writeFile(
|
|
865
|
+
AUTO_PREPEND_SCRIPT,
|
|
866
|
+
`<?php
|
|
867
|
+
// Define constants set via defineConstant() calls
|
|
868
|
+
if(file_exists('/internal/shared/consts.json')) {
|
|
869
|
+
$consts = json_decode(file_get_contents('/internal/shared/consts.json'), true);
|
|
870
|
+
foreach ($consts as $const => $value) {
|
|
871
|
+
if (!defined($const) && is_scalar($value)) {
|
|
872
|
+
define($const, $value);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
// Preload all the files from /internal/shared/preload
|
|
877
|
+
foreach (glob('/internal/shared/preload/*.php') as $file) {
|
|
878
|
+
require_once $file;
|
|
879
|
+
}
|
|
880
|
+
`
|
|
881
|
+
), t.onMessage = async (r) => {
|
|
882
|
+
for (const s of f(this, w)) {
|
|
883
|
+
const n = await s(r);
|
|
884
|
+
if (n)
|
|
885
|
+
return n;
|
|
845
886
|
}
|
|
846
887
|
return "";
|
|
847
|
-
},
|
|
888
|
+
}, p(this, y, improveWASMErrorReporting(t)), this.dispatchEvent({
|
|
848
889
|
type: "runtime.initialized"
|
|
849
890
|
});
|
|
850
891
|
}
|
|
@@ -859,24 +900,7 @@ class BasePHP {
|
|
|
859
900
|
throw new Error(
|
|
860
901
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
861
902
|
);
|
|
862
|
-
|
|
863
|
-
}
|
|
864
|
-
/** @inheritDoc */
|
|
865
|
-
setPhpIniPath(e) {
|
|
866
|
-
if (h(this, _))
|
|
867
|
-
throw new Error("Cannot set PHP ini path after calling run().");
|
|
868
|
-
f(this, w, e), this[__private__dont__use].ccall(
|
|
869
|
-
"wasm_set_phpini_path",
|
|
870
|
-
null,
|
|
871
|
-
["string"],
|
|
872
|
-
[e]
|
|
873
|
-
);
|
|
874
|
-
}
|
|
875
|
-
/** @inheritDoc */
|
|
876
|
-
setPhpIniEntry(e, t) {
|
|
877
|
-
if (h(this, _))
|
|
878
|
-
throw new Error("Cannot set PHP ini entries after calling run().");
|
|
879
|
-
h(this, E).push([e, t]);
|
|
903
|
+
p(this, E, e);
|
|
880
904
|
}
|
|
881
905
|
/** @inheritDoc */
|
|
882
906
|
chdir(e) {
|
|
@@ -898,20 +922,20 @@ class BasePHP {
|
|
|
898
922
|
const t = await this.semaphore.acquire();
|
|
899
923
|
let r;
|
|
900
924
|
try {
|
|
901
|
-
if (
|
|
925
|
+
if (f(this, m) || (h(this, b, L).call(this), p(this, m, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
|
|
902
926
|
throw new Error(
|
|
903
927
|
`The script path "${e.scriptPath}" does not exist.`
|
|
904
928
|
);
|
|
905
|
-
|
|
906
|
-
const s = normalizeHeaders(e.headers || {}),
|
|
907
|
-
|
|
908
|
-
const o =
|
|
929
|
+
h(this, S, $).call(this, e.relativeUri || ""), h(this, C, j).call(this, e.method || "GET");
|
|
930
|
+
const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443", i = h(this, x, z).call(this, n, e.protocol || "http");
|
|
931
|
+
h(this, T, q).call(this, n), h(this, F, W).call(this, i), h(this, k, G).call(this, s), e.body && (r = h(this, N, J).call(this, e.body)), typeof e.code == "string" ? (this.writeFile("/internal/eval.php", e.code), h(this, v, O).call(this, "/internal/eval.php")) : h(this, v, O).call(this, e.scriptPath || "");
|
|
932
|
+
const o = h(this, P, B).call(this, e.$_SERVER, s, i);
|
|
909
933
|
for (const c in o)
|
|
910
|
-
|
|
934
|
+
h(this, A, V).call(this, c, o[c]);
|
|
911
935
|
const a = e.env || {};
|
|
912
936
|
for (const c in a)
|
|
913
|
-
|
|
914
|
-
const l = await
|
|
937
|
+
h(this, M, Q).call(this, c, a[c]);
|
|
938
|
+
const l = await h(this, I, Y).call(this);
|
|
915
939
|
if (l.exitCode !== 0) {
|
|
916
940
|
logger.warn("PHP.run() output was:", l.text);
|
|
917
941
|
const c = new PHPExecutionFailureError(
|
|
@@ -943,12 +967,12 @@ class BasePHP {
|
|
|
943
967
|
let r = {};
|
|
944
968
|
try {
|
|
945
969
|
r = JSON.parse(
|
|
946
|
-
this.fileExists("/internal/consts.json") && this.readFileAsText("/internal/consts.json") || "{}"
|
|
970
|
+
this.fileExists("/internal/shared/consts.json") && this.readFileAsText("/internal/shared/consts.json") || "{}"
|
|
947
971
|
);
|
|
948
972
|
} catch {
|
|
949
973
|
}
|
|
950
974
|
this.writeFile(
|
|
951
|
-
"/internal/consts.json",
|
|
975
|
+
"/internal/shared/consts.json",
|
|
952
976
|
JSON.stringify({
|
|
953
977
|
...r,
|
|
954
978
|
[e]: t
|
|
@@ -975,16 +999,18 @@ class BasePHP {
|
|
|
975
999
|
}
|
|
976
1000
|
/** @inheritDoc */
|
|
977
1001
|
mv(e, t) {
|
|
1002
|
+
const r = this[__private__dont__use].FS;
|
|
978
1003
|
try {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1004
|
+
const s = r.lookupPath(e).node.mount, n = this.fileExists(t) ? r.lookupPath(t).node.mount : r.lookupPath(dirname(t)).node.mount;
|
|
1005
|
+
s.mountpoint !== n.mountpoint ? (copyRecursive(r, e, t), this.rmdir(e, { recursive: !0 })) : r.rename(e, t);
|
|
1006
|
+
} catch (s) {
|
|
1007
|
+
const n = getEmscriptenFsError(s);
|
|
1008
|
+
throw n ? new Error(
|
|
1009
|
+
`Could not move ${e} to ${t}: ${n}`,
|
|
984
1010
|
{
|
|
985
|
-
cause:
|
|
1011
|
+
cause: s
|
|
986
1012
|
}
|
|
987
|
-
) :
|
|
1013
|
+
) : s;
|
|
988
1014
|
}
|
|
989
1015
|
}
|
|
990
1016
|
rmdir(e, t = { recursive: !0 }) {
|
|
@@ -1002,7 +1028,7 @@ class BasePHP {
|
|
|
1002
1028
|
);
|
|
1003
1029
|
if (t.prependPath) {
|
|
1004
1030
|
const s = e.replace(/\/$/, "");
|
|
1005
|
-
return r.map((
|
|
1031
|
+
return r.map((n) => `${s}/${n}`);
|
|
1006
1032
|
}
|
|
1007
1033
|
return r;
|
|
1008
1034
|
} catch (r) {
|
|
@@ -1037,7 +1063,7 @@ class BasePHP {
|
|
|
1037
1063
|
this.exit();
|
|
1038
1064
|
} catch {
|
|
1039
1065
|
}
|
|
1040
|
-
this.initializeRuntime(e),
|
|
1066
|
+
this.initializeRuntime(e), f(this, E) && this.setSapiName(f(this, E)), t && copyFS(r, this[__private__dont__use].FS, t);
|
|
1041
1067
|
}
|
|
1042
1068
|
exit(e = 0) {
|
|
1043
1069
|
this.dispatchEvent({
|
|
@@ -1047,48 +1073,25 @@ class BasePHP {
|
|
|
1047
1073
|
this[__private__dont__use]._exit(e);
|
|
1048
1074
|
} catch {
|
|
1049
1075
|
}
|
|
1050
|
-
|
|
1076
|
+
p(this, m, !1), p(this, y, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1051
1077
|
}
|
|
1052
1078
|
[Symbol.dispose]() {
|
|
1053
|
-
|
|
1079
|
+
f(this, m) && this.exit(0);
|
|
1054
1080
|
}
|
|
1055
1081
|
}
|
|
1056
|
-
E = new WeakMap(),
|
|
1082
|
+
E = new WeakMap(), m = new WeakMap(), y = new WeakMap(), _ = new WeakMap(), w = new WeakMap(), P = new WeakSet(), B = function(e, t, r) {
|
|
1057
1083
|
const s = {
|
|
1058
1084
|
...e || {}
|
|
1059
1085
|
};
|
|
1060
1086
|
s.HTTPS = s.HTTPS || r === 443 ? "on" : "off";
|
|
1061
|
-
for (const
|
|
1062
|
-
let
|
|
1063
|
-
["content-type", "content-length"].includes(
|
|
1087
|
+
for (const n in t) {
|
|
1088
|
+
let i = "HTTP_";
|
|
1089
|
+
["content-type", "content-length"].includes(n.toLowerCase()) && (i = ""), s[`${i}${n.toUpperCase().replace(/-/g, "_")}`] = t[n];
|
|
1064
1090
|
}
|
|
1065
1091
|
return s;
|
|
1066
|
-
},
|
|
1067
|
-
if (this.setPhpIniEntry("auto_prepend_file", "/internal/consts.php"), this.fileExists("/internal/consts.php") || this.writeFile(
|
|
1068
|
-
"/internal/consts.php",
|
|
1069
|
-
`<?php
|
|
1070
|
-
if(file_exists('/internal/consts.json')) {
|
|
1071
|
-
$consts = json_decode(file_get_contents('/internal/consts.json'), true);
|
|
1072
|
-
foreach ($consts as $const => $value) {
|
|
1073
|
-
if (!defined($const) && is_scalar($value)) {
|
|
1074
|
-
define($const, $value);
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
}`
|
|
1078
|
-
), h(this, E).length > 0) {
|
|
1079
|
-
const e = h(this, E).map(([t, r]) => `${t}=${r}`).join(`
|
|
1080
|
-
`) + `
|
|
1081
|
-
|
|
1082
|
-
`;
|
|
1083
|
-
this[__private__dont__use].ccall(
|
|
1084
|
-
"wasm_set_phpini_entries",
|
|
1085
|
-
null,
|
|
1086
|
-
[STRING],
|
|
1087
|
-
[e]
|
|
1088
|
-
);
|
|
1089
|
-
}
|
|
1092
|
+
}, b = new WeakSet(), L = function() {
|
|
1090
1093
|
this[__private__dont__use].ccall("php_wasm_init", null, [], []);
|
|
1091
|
-
}, R = new WeakSet(),
|
|
1094
|
+
}, R = new WeakSet(), U = function() {
|
|
1092
1095
|
const e = "/internal/headers.json";
|
|
1093
1096
|
if (!this.fileExists(e))
|
|
1094
1097
|
throw new Error(
|
|
@@ -1098,14 +1101,14 @@ E = new WeakMap(), w = new WeakMap(), v = new WeakMap(), _ = new WeakMap(), y =
|
|
|
1098
1101
|
for (const s of t.headers) {
|
|
1099
1102
|
if (!s.includes(": "))
|
|
1100
1103
|
continue;
|
|
1101
|
-
const
|
|
1102
|
-
|
|
1104
|
+
const n = s.indexOf(": "), i = s.substring(0, n).toLowerCase(), o = s.substring(n + 2);
|
|
1105
|
+
i in r || (r[i] = []), r[i].push(o);
|
|
1103
1106
|
}
|
|
1104
1107
|
return {
|
|
1105
1108
|
headers: r,
|
|
1106
1109
|
httpStatusCode: t.status
|
|
1107
1110
|
};
|
|
1108
|
-
},
|
|
1111
|
+
}, S = new WeakSet(), $ = function(e) {
|
|
1109
1112
|
if (this[__private__dont__use].ccall(
|
|
1110
1113
|
"wasm_set_request_uri",
|
|
1111
1114
|
null,
|
|
@@ -1120,35 +1123,35 @@ E = new WeakMap(), w = new WeakMap(), v = new WeakMap(), _ = new WeakMap(), y =
|
|
|
1120
1123
|
[t]
|
|
1121
1124
|
);
|
|
1122
1125
|
}
|
|
1123
|
-
},
|
|
1126
|
+
}, T = new WeakSet(), q = function(e) {
|
|
1124
1127
|
this[__private__dont__use].ccall(
|
|
1125
1128
|
"wasm_set_request_host",
|
|
1126
1129
|
null,
|
|
1127
1130
|
[STRING],
|
|
1128
1131
|
[e]
|
|
1129
1132
|
);
|
|
1130
|
-
},
|
|
1133
|
+
}, F = new WeakSet(), W = function(e) {
|
|
1131
1134
|
this[__private__dont__use].ccall(
|
|
1132
1135
|
"wasm_set_request_port",
|
|
1133
1136
|
null,
|
|
1134
1137
|
[NUMBER],
|
|
1135
1138
|
[e]
|
|
1136
1139
|
);
|
|
1137
|
-
}, x = new WeakSet(),
|
|
1140
|
+
}, x = new WeakSet(), z = function(e, t) {
|
|
1138
1141
|
let r;
|
|
1139
1142
|
try {
|
|
1140
1143
|
r = parseInt(new URL(e).port, 10);
|
|
1141
1144
|
} catch {
|
|
1142
1145
|
}
|
|
1143
1146
|
return (!r || isNaN(r) || r === 80) && (r = t === "https" ? 443 : 80), r;
|
|
1144
|
-
},
|
|
1147
|
+
}, C = new WeakSet(), j = function(e) {
|
|
1145
1148
|
this[__private__dont__use].ccall(
|
|
1146
1149
|
"wasm_set_request_method",
|
|
1147
1150
|
null,
|
|
1148
1151
|
[STRING],
|
|
1149
1152
|
[e]
|
|
1150
1153
|
);
|
|
1151
|
-
},
|
|
1154
|
+
}, k = new WeakSet(), G = function(e) {
|
|
1152
1155
|
e.cookie && this[__private__dont__use].ccall(
|
|
1153
1156
|
"wasm_set_cookies",
|
|
1154
1157
|
null,
|
|
@@ -1165,7 +1168,7 @@ E = new WeakMap(), w = new WeakMap(), v = new WeakMap(), _ = new WeakMap(), y =
|
|
|
1165
1168
|
[NUMBER],
|
|
1166
1169
|
[parseInt(e["content-length"], 10)]
|
|
1167
1170
|
);
|
|
1168
|
-
}, N = new WeakSet(),
|
|
1171
|
+
}, N = new WeakSet(), J = function(e) {
|
|
1169
1172
|
let t, r;
|
|
1170
1173
|
typeof e == "string" ? (logger.warn(
|
|
1171
1174
|
"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"
|
|
@@ -1188,45 +1191,38 @@ E = new WeakMap(), w = new WeakMap(), v = new WeakMap(), _ = new WeakMap(), y =
|
|
|
1188
1191
|
[NUMBER],
|
|
1189
1192
|
[r]
|
|
1190
1193
|
), s;
|
|
1191
|
-
},
|
|
1194
|
+
}, v = new WeakSet(), O = function(e) {
|
|
1192
1195
|
this[__private__dont__use].ccall(
|
|
1193
1196
|
"wasm_set_path_translated",
|
|
1194
1197
|
null,
|
|
1195
1198
|
[STRING],
|
|
1196
1199
|
[e]
|
|
1197
1200
|
);
|
|
1198
|
-
},
|
|
1201
|
+
}, A = new WeakSet(), V = function(e, t) {
|
|
1199
1202
|
this[__private__dont__use].ccall(
|
|
1200
1203
|
"wasm_add_SERVER_entry",
|
|
1201
1204
|
null,
|
|
1202
1205
|
[STRING, STRING],
|
|
1203
1206
|
[e, t]
|
|
1204
1207
|
);
|
|
1205
|
-
},
|
|
1208
|
+
}, M = new WeakSet(), Q = function(e, t) {
|
|
1206
1209
|
this[__private__dont__use].ccall(
|
|
1207
1210
|
"wasm_add_ENV_entry",
|
|
1208
1211
|
null,
|
|
1209
1212
|
[STRING, STRING],
|
|
1210
1213
|
[e, t]
|
|
1211
1214
|
);
|
|
1212
|
-
},
|
|
1213
|
-
|
|
1214
|
-
"wasm_set_php_code",
|
|
1215
|
-
null,
|
|
1216
|
-
[STRING],
|
|
1217
|
-
[e]
|
|
1218
|
-
);
|
|
1219
|
-
}, B = new WeakSet(), ee = async function() {
|
|
1220
|
-
var i;
|
|
1215
|
+
}, I = new WeakSet(), Y = async function() {
|
|
1216
|
+
var n;
|
|
1221
1217
|
let e, t;
|
|
1222
1218
|
try {
|
|
1223
|
-
e = await new Promise((
|
|
1219
|
+
e = await new Promise((i, o) => {
|
|
1224
1220
|
var l;
|
|
1225
1221
|
t = (c) => {
|
|
1226
1222
|
logger.error(c), logger.error(c.error);
|
|
1227
|
-
const
|
|
1228
|
-
|
|
1229
|
-
}, (l =
|
|
1223
|
+
const u = new Error("Rethrown");
|
|
1224
|
+
u.cause = c.error, u.betterMessage = c.message, o(u);
|
|
1225
|
+
}, (l = f(this, y)) == null || l.addEventListener(
|
|
1230
1226
|
"error",
|
|
1231
1227
|
t
|
|
1232
1228
|
);
|
|
@@ -1237,9 +1233,9 @@ E = new WeakMap(), w = new WeakMap(), v = new WeakMap(), _ = new WeakMap(), y =
|
|
|
1237
1233
|
[],
|
|
1238
1234
|
{ async: !0 }
|
|
1239
1235
|
);
|
|
1240
|
-
return a instanceof Promise ? a.then(
|
|
1236
|
+
return a instanceof Promise ? a.then(i, o) : i(a);
|
|
1241
1237
|
});
|
|
1242
|
-
} catch (
|
|
1238
|
+
} catch (i) {
|
|
1243
1239
|
for (const c in this)
|
|
1244
1240
|
typeof this[c] == "function" && (this[c] = () => {
|
|
1245
1241
|
throw new Error(
|
|
@@ -1247,12 +1243,12 @@ E = new WeakMap(), w = new WeakMap(), v = new WeakMap(), _ = new WeakMap(), y =
|
|
|
1247
1243
|
);
|
|
1248
1244
|
});
|
|
1249
1245
|
this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
|
|
1250
|
-
const o =
|
|
1246
|
+
const o = i, a = "betterMessage" in o ? o.betterMessage : o.message, l = new Error(a);
|
|
1251
1247
|
throw l.cause = o, logger.error(l), l;
|
|
1252
1248
|
} finally {
|
|
1253
|
-
(
|
|
1249
|
+
(n = f(this, y)) == null || n.removeEventListener("error", t);
|
|
1254
1250
|
}
|
|
1255
|
-
const { headers: r, httpStatusCode: s } =
|
|
1251
|
+
const { headers: r, httpStatusCode: s } = h(this, R, U).call(this);
|
|
1256
1252
|
return new PHPResponse(
|
|
1257
1253
|
e === 0 ? s : 500,
|
|
1258
1254
|
r,
|
|
@@ -1311,36 +1307,66 @@ function copyFS(e, t, r) {
|
|
|
1311
1307
|
return;
|
|
1312
1308
|
}
|
|
1313
1309
|
t.mkdirTree(r);
|
|
1314
|
-
const
|
|
1315
|
-
for (const
|
|
1316
|
-
copyFS(e, t, joinPaths(r,
|
|
1310
|
+
const n = e.readdir(r).filter((i) => i !== "." && i !== "..");
|
|
1311
|
+
for (const i of n)
|
|
1312
|
+
copyFS(e, t, joinPaths(r, i));
|
|
1317
1313
|
}
|
|
1314
|
+
function copyRecursive(e, t, r) {
|
|
1315
|
+
const s = e.lookupPath(t).node;
|
|
1316
|
+
if (e.isDir(s.mode)) {
|
|
1317
|
+
e.mkdirTree(r);
|
|
1318
|
+
const n = e.readdir(t).filter(
|
|
1319
|
+
(i) => i !== "." && i !== ".."
|
|
1320
|
+
);
|
|
1321
|
+
for (const i of n)
|
|
1322
|
+
copyRecursive(
|
|
1323
|
+
e,
|
|
1324
|
+
joinPaths(t, i),
|
|
1325
|
+
joinPaths(r, i)
|
|
1326
|
+
);
|
|
1327
|
+
} else
|
|
1328
|
+
e.writeFile(r, e.readFile(t));
|
|
1329
|
+
}
|
|
1330
|
+
ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symbol.asyncIterator] = async function* () {
|
|
1331
|
+
const e = this.getReader();
|
|
1332
|
+
try {
|
|
1333
|
+
for (; ; ) {
|
|
1334
|
+
const { done: t, value: r } = await e.read();
|
|
1335
|
+
if (t)
|
|
1336
|
+
return;
|
|
1337
|
+
yield r;
|
|
1338
|
+
}
|
|
1339
|
+
} finally {
|
|
1340
|
+
e.releaseLock();
|
|
1341
|
+
}
|
|
1342
|
+
}, ReadableStream.prototype.iterate = // @ts-ignore
|
|
1343
|
+
ReadableStream.prototype[Symbol.asyncIterator]);
|
|
1318
1344
|
function journalFSEvents(e, t, r = () => {
|
|
1319
1345
|
}) {
|
|
1320
1346
|
function s() {
|
|
1321
1347
|
t = normalizePath(t);
|
|
1322
|
-
const
|
|
1323
|
-
if (
|
|
1324
|
-
r(
|
|
1325
|
-
else if (
|
|
1348
|
+
const i = e[__private__dont__use].FS, o = createFSHooks(i, (u) => {
|
|
1349
|
+
if (u.path.startsWith(t))
|
|
1350
|
+
r(u);
|
|
1351
|
+
else if (u.operation === "RENAME" && u.toPath.startsWith(t))
|
|
1326
1352
|
for (const g of recordExistingPath(
|
|
1327
1353
|
e,
|
|
1328
|
-
|
|
1329
|
-
|
|
1354
|
+
u.path,
|
|
1355
|
+
u.toPath
|
|
1330
1356
|
))
|
|
1331
1357
|
r(g);
|
|
1332
1358
|
}), a = {};
|
|
1333
|
-
for (const [
|
|
1334
|
-
a[
|
|
1359
|
+
for (const [u] of Object.entries(o))
|
|
1360
|
+
a[u] = i[u];
|
|
1335
1361
|
function l() {
|
|
1336
|
-
for (const [
|
|
1337
|
-
|
|
1338
|
-
return g(...
|
|
1362
|
+
for (const [u, g] of Object.entries(o))
|
|
1363
|
+
i[u] = function(...D) {
|
|
1364
|
+
return g(...D), a[u].apply(this, D);
|
|
1339
1365
|
};
|
|
1340
1366
|
}
|
|
1341
1367
|
function c() {
|
|
1342
|
-
for (const [
|
|
1343
|
-
e[__private__dont__use].FS[
|
|
1368
|
+
for (const [u, g] of Object.entries(a))
|
|
1369
|
+
e[__private__dont__use].FS[u] = g;
|
|
1344
1370
|
}
|
|
1345
1371
|
e[__private__dont__use].journal = {
|
|
1346
1372
|
bind: l,
|
|
@@ -1348,11 +1374,11 @@ function journalFSEvents(e, t, r = () => {
|
|
|
1348
1374
|
}, l();
|
|
1349
1375
|
}
|
|
1350
1376
|
e.addEventListener("runtime.initialized", s), e[__private__dont__use] && s();
|
|
1351
|
-
function
|
|
1377
|
+
function n() {
|
|
1352
1378
|
e[__private__dont__use].journal.unbind(), delete e[__private__dont__use].journal;
|
|
1353
1379
|
}
|
|
1354
|
-
return e.addEventListener("runtime.beforedestroy",
|
|
1355
|
-
return e.removeEventListener("runtime.initialized", s), e.removeEventListener("runtime.beforedestroy",
|
|
1380
|
+
return e.addEventListener("runtime.beforedestroy", n), function() {
|
|
1381
|
+
return e.removeEventListener("runtime.initialized", s), e.removeEventListener("runtime.beforedestroy", n), e[__private__dont__use].journal.unbind();
|
|
1356
1382
|
};
|
|
1357
1383
|
}
|
|
1358
1384
|
const createFSHooks = (e, t = () => {
|
|
@@ -1404,16 +1430,16 @@ const createFSHooks = (e, t = () => {
|
|
|
1404
1430
|
},
|
|
1405
1431
|
rename(r, s) {
|
|
1406
1432
|
try {
|
|
1407
|
-
const
|
|
1433
|
+
const n = e.lookupPath(r, {
|
|
1408
1434
|
follow: !0
|
|
1409
|
-
}),
|
|
1435
|
+
}), i = e.lookupPath(s, {
|
|
1410
1436
|
parent: !0
|
|
1411
1437
|
}).path;
|
|
1412
1438
|
t({
|
|
1413
1439
|
operation: "RENAME",
|
|
1414
|
-
nodeType: e.isDir(
|
|
1415
|
-
path:
|
|
1416
|
-
toPath: joinPaths(
|
|
1440
|
+
nodeType: e.isDir(n.node.mode) ? "directory" : "file",
|
|
1441
|
+
path: n.path,
|
|
1442
|
+
toPath: joinPaths(i, basename(s))
|
|
1417
1443
|
});
|
|
1418
1444
|
} catch {
|
|
1419
1445
|
}
|
|
@@ -1459,52 +1485,52 @@ function normalizeFilesystemOperations(e) {
|
|
|
1459
1485
|
const t = {};
|
|
1460
1486
|
for (let r = e.length - 1; r >= 0; r--) {
|
|
1461
1487
|
for (let s = r - 1; s >= 0; s--) {
|
|
1462
|
-
const
|
|
1463
|
-
if (
|
|
1488
|
+
const n = checkRelationship(e[r], e[s]);
|
|
1489
|
+
if (n === "none")
|
|
1464
1490
|
continue;
|
|
1465
|
-
const
|
|
1466
|
-
if (
|
|
1491
|
+
const i = e[r], o = e[s];
|
|
1492
|
+
if (i.operation === "RENAME" && o.operation === "RENAME") {
|
|
1467
1493
|
logger.warn(
|
|
1468
1494
|
"[FS Journal] Normalizing a double rename is not yet supported:",
|
|
1469
1495
|
{
|
|
1470
|
-
current:
|
|
1496
|
+
current: i,
|
|
1471
1497
|
last: o
|
|
1472
1498
|
}
|
|
1473
1499
|
);
|
|
1474
1500
|
continue;
|
|
1475
1501
|
}
|
|
1476
|
-
(o.operation === "CREATE" || o.operation === "WRITE") && (
|
|
1502
|
+
(o.operation === "CREATE" || o.operation === "WRITE") && (i.operation === "RENAME" ? n === "same_node" ? (t[s] = [], t[r] = [
|
|
1477
1503
|
{
|
|
1478
1504
|
...o,
|
|
1479
|
-
path:
|
|
1505
|
+
path: i.toPath
|
|
1480
1506
|
},
|
|
1481
1507
|
...t[r] || []
|
|
1482
|
-
]) :
|
|
1508
|
+
]) : n === "descendant" && (t[s] = [], t[r] = [
|
|
1483
1509
|
{
|
|
1484
1510
|
...o,
|
|
1485
1511
|
path: joinPaths(
|
|
1486
|
-
|
|
1487
|
-
o.path.substring(
|
|
1512
|
+
i.toPath,
|
|
1513
|
+
o.path.substring(i.path.length)
|
|
1488
1514
|
)
|
|
1489
1515
|
},
|
|
1490
1516
|
...t[r] || []
|
|
1491
|
-
]) :
|
|
1517
|
+
]) : i.operation === "WRITE" && n === "same_node" ? t[s] = [] : i.operation === "DELETE" && n === "same_node" && (t[s] = [], t[r] = []));
|
|
1492
1518
|
}
|
|
1493
1519
|
if (Object.entries(t).length > 0) {
|
|
1494
|
-
const s = e.flatMap((
|
|
1520
|
+
const s = e.flatMap((n, i) => i in t ? t[i] : [n]);
|
|
1495
1521
|
return normalizeFilesystemOperations(s);
|
|
1496
1522
|
}
|
|
1497
1523
|
}
|
|
1498
1524
|
return e;
|
|
1499
1525
|
}
|
|
1500
1526
|
function checkRelationship(e, t) {
|
|
1501
|
-
const r = e.path, s = e.operation !== "WRITE" && e.nodeType === "directory",
|
|
1502
|
-
return
|
|
1527
|
+
const r = e.path, s = e.operation !== "WRITE" && e.nodeType === "directory", n = t.operation !== "WRITE" && t.nodeType === "directory", i = t.operation === "RENAME" ? t.toPath : t.path;
|
|
1528
|
+
return i === r ? "same_node" : n && r.startsWith(i + "/") ? "ancestor" : s && i.startsWith(r + "/") ? "descendant" : "none";
|
|
1503
1529
|
}
|
|
1504
1530
|
async function hydrateUpdateFileOps(e, t) {
|
|
1505
1531
|
const s = t.filter(
|
|
1506
|
-
(
|
|
1507
|
-
).map((
|
|
1532
|
+
(n) => n.operation === "WRITE"
|
|
1533
|
+
).map((n) => hydrateOp(e, n));
|
|
1508
1534
|
return await Promise.all(s), t;
|
|
1509
1535
|
}
|
|
1510
1536
|
const hydrateLock = new Semaphore({ concurrency: 15 });
|