@php-wasm/universal 0.1.39 → 0.1.41
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 +40 -0
- package/index.js +1070 -0
- package/lib/base-php.d.ts +70 -0
- package/lib/error-event-polyfill.d.ts +30 -0
- package/{src/lib/index.ts → lib/index.d.ts} +4 -36
- package/lib/is-local-php.d.ts +2 -0
- package/lib/is-remote-php.d.ts +2 -0
- package/{src/lib/load-php-runtime.ts → lib/load-php-runtime.d.ts} +23 -100
- package/lib/php-browser.d.ts +52 -0
- package/lib/php-request-handler.d.ts +43 -0
- package/lib/php-response.d.ts +54 -0
- package/lib/rethrow-file-system-error.d.ts +13 -0
- package/lib/supported-php-versions.d.ts +4 -0
- package/lib/universal-php.d.ts +309 -0
- package/{src/lib/urls.ts → lib/urls.d.ts} +4 -19
- package/lib/wasm-error-reporting.d.ts +26 -0
- package/package.json +4 -3
- package/.eslintrc.json +0 -18
- package/LICENSE +0 -339
- package/README.md +0 -0
- package/project.json +0 -50
- package/src/lib/base-php.ts +0 -555
- package/src/lib/error-event-polyfill.ts +0 -50
- package/src/lib/is-local-php.ts +0 -8
- package/src/lib/is-remote-php.ts +0 -8
- package/src/lib/php-browser.ts +0 -137
- package/src/lib/php-request-handler.ts +0 -381
- package/src/lib/php-response.ts +0 -104
- package/src/lib/rethrow-file-system-error.ts +0 -125
- package/src/lib/supported-php-versions.ts +0 -14
- package/src/lib/universal-php.ts +0 -354
- package/src/lib/wasm-error-reporting.ts +0 -172
- package/tsconfig.json +0 -22
- package/tsconfig.lib.json +0 -14
- package/tsconfig.spec.json +0 -20
- package/vite.config.ts +0 -47
- /package/{src/index.ts → index.d.ts} +0 -0
package/index.js
ADDED
|
@@ -0,0 +1,1070 @@
|
|
|
1
|
+
class y {
|
|
2
|
+
constructor(e, t, r, n = "", o = 0) {
|
|
3
|
+
this.httpStatusCode = e, this.headers = t, this.bytes = r, this.exitCode = o, this.errors = n;
|
|
4
|
+
}
|
|
5
|
+
static fromRawData(e) {
|
|
6
|
+
return new y(
|
|
7
|
+
e.httpStatusCode,
|
|
8
|
+
e.headers,
|
|
9
|
+
e.bytes,
|
|
10
|
+
e.errors,
|
|
11
|
+
e.exitCode
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
toRawData() {
|
|
15
|
+
return {
|
|
16
|
+
headers: this.headers,
|
|
17
|
+
bytes: this.bytes,
|
|
18
|
+
errors: this.errors,
|
|
19
|
+
exitCode: this.exitCode,
|
|
20
|
+
httpStatusCode: this.httpStatusCode
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Response body as JSON.
|
|
25
|
+
*/
|
|
26
|
+
get json() {
|
|
27
|
+
return JSON.parse(this.text);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Response body as text.
|
|
31
|
+
*/
|
|
32
|
+
get text() {
|
|
33
|
+
return new TextDecoder().decode(this.bytes);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const F = [
|
|
37
|
+
"8.2",
|
|
38
|
+
"8.1",
|
|
39
|
+
"8.0",
|
|
40
|
+
"7.4",
|
|
41
|
+
"7.3",
|
|
42
|
+
"7.2",
|
|
43
|
+
"7.1",
|
|
44
|
+
"7.0",
|
|
45
|
+
"5.6"
|
|
46
|
+
], ee = F[0], te = F;
|
|
47
|
+
class A {
|
|
48
|
+
#e;
|
|
49
|
+
#t;
|
|
50
|
+
/**
|
|
51
|
+
* @param server - The PHP server to browse.
|
|
52
|
+
* @param config - The browser configuration.
|
|
53
|
+
*/
|
|
54
|
+
constructor(e, t = {}) {
|
|
55
|
+
this.requestHandler = e, this.#e = {}, this.#t = {
|
|
56
|
+
handleRedirects: !1,
|
|
57
|
+
maxRedirects: 4,
|
|
58
|
+
...t
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Sends the request to the server.
|
|
63
|
+
*
|
|
64
|
+
* When cookies are present in the response, this method stores
|
|
65
|
+
* them and sends them with any subsequent requests.
|
|
66
|
+
*
|
|
67
|
+
* When a redirection is present in the response, this method
|
|
68
|
+
* follows it by discarding a response and sending a subsequent
|
|
69
|
+
* request.
|
|
70
|
+
*
|
|
71
|
+
* @param request - The request.
|
|
72
|
+
* @param redirects - Internal. The number of redirects handled so far.
|
|
73
|
+
* @returns PHPRequestHandler response.
|
|
74
|
+
*/
|
|
75
|
+
async request(e, t = 0) {
|
|
76
|
+
const r = await this.requestHandler.request({
|
|
77
|
+
...e,
|
|
78
|
+
headers: {
|
|
79
|
+
...e.headers,
|
|
80
|
+
cookie: this.#n()
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
if (r.headers["set-cookie"] && this.#r(r.headers["set-cookie"]), this.#t.handleRedirects && r.headers.location && t < this.#t.maxRedirects) {
|
|
84
|
+
const n = new URL(
|
|
85
|
+
r.headers.location[0],
|
|
86
|
+
this.requestHandler.absoluteUrl
|
|
87
|
+
);
|
|
88
|
+
return this.request(
|
|
89
|
+
{
|
|
90
|
+
url: n.toString(),
|
|
91
|
+
method: "GET",
|
|
92
|
+
headers: {}
|
|
93
|
+
},
|
|
94
|
+
t + 1
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return r;
|
|
98
|
+
}
|
|
99
|
+
/** @inheritDoc */
|
|
100
|
+
pathToInternalUrl(e) {
|
|
101
|
+
return this.requestHandler.pathToInternalUrl(e);
|
|
102
|
+
}
|
|
103
|
+
/** @inheritDoc */
|
|
104
|
+
internalUrlToPath(e) {
|
|
105
|
+
return this.requestHandler.internalUrlToPath(e);
|
|
106
|
+
}
|
|
107
|
+
/** @inheritDoc */
|
|
108
|
+
get absoluteUrl() {
|
|
109
|
+
return this.requestHandler.absoluteUrl;
|
|
110
|
+
}
|
|
111
|
+
/** @inheritDoc */
|
|
112
|
+
get documentRoot() {
|
|
113
|
+
return this.requestHandler.documentRoot;
|
|
114
|
+
}
|
|
115
|
+
#r(e) {
|
|
116
|
+
for (const t of e)
|
|
117
|
+
try {
|
|
118
|
+
if (!t.includes("="))
|
|
119
|
+
continue;
|
|
120
|
+
const r = t.indexOf("="), n = t.substring(0, r), o = t.substring(r + 1).split(";")[0];
|
|
121
|
+
this.#e[n] = o;
|
|
122
|
+
} catch (r) {
|
|
123
|
+
console.error(r);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
#n() {
|
|
127
|
+
const e = [];
|
|
128
|
+
for (const t in this.#e)
|
|
129
|
+
e.push(`${t}=${this.#e[t]}`);
|
|
130
|
+
return e.join("; ");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
class O {
|
|
134
|
+
constructor({ concurrency: e }) {
|
|
135
|
+
this._running = 0, this.concurrency = e, this.queue = [];
|
|
136
|
+
}
|
|
137
|
+
get running() {
|
|
138
|
+
return this._running;
|
|
139
|
+
}
|
|
140
|
+
async acquire() {
|
|
141
|
+
for (; ; )
|
|
142
|
+
if (this._running >= this.concurrency)
|
|
143
|
+
await new Promise((e) => this.queue.push(e));
|
|
144
|
+
else
|
|
145
|
+
return this._running++, () => {
|
|
146
|
+
this._running--, this.queue.length > 0 && this.queue.shift()();
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
async run(e) {
|
|
150
|
+
const t = await this.acquire();
|
|
151
|
+
try {
|
|
152
|
+
return await e();
|
|
153
|
+
} finally {
|
|
154
|
+
t();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const I = "http://example.com";
|
|
159
|
+
function v(s) {
|
|
160
|
+
return s.toString().substring(s.origin.length);
|
|
161
|
+
}
|
|
162
|
+
function _(s, e) {
|
|
163
|
+
return !e || !s.startsWith(e) ? s : s.substring(e.length);
|
|
164
|
+
}
|
|
165
|
+
function N(s, e) {
|
|
166
|
+
return !e || s.startsWith(e) ? s : e + s;
|
|
167
|
+
}
|
|
168
|
+
class L {
|
|
169
|
+
#e;
|
|
170
|
+
#t;
|
|
171
|
+
#r;
|
|
172
|
+
#n;
|
|
173
|
+
#o;
|
|
174
|
+
#s;
|
|
175
|
+
#i;
|
|
176
|
+
#a;
|
|
177
|
+
#l;
|
|
178
|
+
/**
|
|
179
|
+
* @param php - The PHP instance.
|
|
180
|
+
* @param config - Request Handler configuration.
|
|
181
|
+
*/
|
|
182
|
+
constructor(e, t = {}) {
|
|
183
|
+
this.#a = new O({ concurrency: 1 });
|
|
184
|
+
const {
|
|
185
|
+
documentRoot: r = "/www/",
|
|
186
|
+
absoluteUrl: n = typeof location == "object" ? location?.href : "",
|
|
187
|
+
isStaticFilePath: o = () => !1
|
|
188
|
+
} = t;
|
|
189
|
+
this.php = e, this.#e = r, this.#l = o;
|
|
190
|
+
const i = new URL(n);
|
|
191
|
+
this.#r = i.hostname, this.#n = i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80, this.#t = (i.protocol || "").replace(":", "");
|
|
192
|
+
const l = this.#n !== 443 && this.#n !== 80;
|
|
193
|
+
this.#o = [
|
|
194
|
+
this.#r,
|
|
195
|
+
l ? `:${this.#n}` : ""
|
|
196
|
+
].join(""), this.#s = i.pathname.replace(/\/+$/, ""), this.#i = [
|
|
197
|
+
`${this.#t}://`,
|
|
198
|
+
this.#o,
|
|
199
|
+
this.#s
|
|
200
|
+
].join("");
|
|
201
|
+
}
|
|
202
|
+
/** @inheritDoc */
|
|
203
|
+
pathToInternalUrl(e) {
|
|
204
|
+
return `${this.absoluteUrl}${e}`;
|
|
205
|
+
}
|
|
206
|
+
/** @inheritDoc */
|
|
207
|
+
internalUrlToPath(e) {
|
|
208
|
+
const t = new URL(e);
|
|
209
|
+
return t.pathname.startsWith(this.#s) && (t.pathname = t.pathname.slice(this.#s.length)), v(t);
|
|
210
|
+
}
|
|
211
|
+
get isRequestRunning() {
|
|
212
|
+
return this.#a.running > 0;
|
|
213
|
+
}
|
|
214
|
+
/** @inheritDoc */
|
|
215
|
+
get absoluteUrl() {
|
|
216
|
+
return this.#i;
|
|
217
|
+
}
|
|
218
|
+
/** @inheritDoc */
|
|
219
|
+
get documentRoot() {
|
|
220
|
+
return this.#e;
|
|
221
|
+
}
|
|
222
|
+
/** @inheritDoc */
|
|
223
|
+
async request(e) {
|
|
224
|
+
const t = e.url.startsWith("http://") || e.url.startsWith("https://"), r = new URL(
|
|
225
|
+
e.url,
|
|
226
|
+
t ? void 0 : I
|
|
227
|
+
), n = _(
|
|
228
|
+
r.pathname,
|
|
229
|
+
this.#s
|
|
230
|
+
);
|
|
231
|
+
return this.#l(n) ? this.#c(n) : await this.#h(e, r);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Serves a static file from the PHP filesystem.
|
|
235
|
+
*
|
|
236
|
+
* @param path - The requested static file path.
|
|
237
|
+
* @returns The response.
|
|
238
|
+
*/
|
|
239
|
+
#c(e) {
|
|
240
|
+
const t = `${this.#e}${e}`;
|
|
241
|
+
if (!this.php.fileExists(t))
|
|
242
|
+
return new y(
|
|
243
|
+
404,
|
|
244
|
+
{},
|
|
245
|
+
new TextEncoder().encode("404 File not found")
|
|
246
|
+
);
|
|
247
|
+
const r = this.php.readFileAsBuffer(t);
|
|
248
|
+
return new y(
|
|
249
|
+
200,
|
|
250
|
+
{
|
|
251
|
+
"content-length": [`${r.byteLength}`],
|
|
252
|
+
// @TODO: Infer the content-type from the arrayBuffer instead of the file path.
|
|
253
|
+
// The code below won't return the correct mime-type if the extension
|
|
254
|
+
// was tampered with.
|
|
255
|
+
"content-type": [M(t)],
|
|
256
|
+
"accept-ranges": ["bytes"],
|
|
257
|
+
"cache-control": ["public, max-age=0"]
|
|
258
|
+
},
|
|
259
|
+
r
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Runs the requested PHP file with all the request and $_SERVER
|
|
264
|
+
* superglobals populated.
|
|
265
|
+
*
|
|
266
|
+
* @param request - The request.
|
|
267
|
+
* @returns The response.
|
|
268
|
+
*/
|
|
269
|
+
async #h(e, t) {
|
|
270
|
+
const r = await this.#a.acquire();
|
|
271
|
+
try {
|
|
272
|
+
this.php.addServerGlobalEntry("DOCUMENT_ROOT", this.#e), this.php.addServerGlobalEntry(
|
|
273
|
+
"HTTPS",
|
|
274
|
+
this.#i.startsWith("https://") ? "on" : ""
|
|
275
|
+
);
|
|
276
|
+
let n = "GET";
|
|
277
|
+
const o = {
|
|
278
|
+
host: this.#o,
|
|
279
|
+
...H(e.headers || {})
|
|
280
|
+
}, i = [];
|
|
281
|
+
if (e.files && Object.keys(e.files).length) {
|
|
282
|
+
n = "POST";
|
|
283
|
+
for (const c in e.files) {
|
|
284
|
+
const d = e.files[c];
|
|
285
|
+
i.push({
|
|
286
|
+
key: c,
|
|
287
|
+
name: d.name,
|
|
288
|
+
type: d.type,
|
|
289
|
+
data: new Uint8Array(await d.arrayBuffer())
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
o["content-type"]?.startsWith("multipart/form-data") && (e.formData = $(
|
|
293
|
+
e.body || ""
|
|
294
|
+
), o["content-type"] = "application/x-www-form-urlencoded", delete e.body);
|
|
295
|
+
}
|
|
296
|
+
let l;
|
|
297
|
+
return e.formData !== void 0 ? (n = "POST", o["content-type"] = o["content-type"] || "application/x-www-form-urlencoded", l = new URLSearchParams(
|
|
298
|
+
e.formData
|
|
299
|
+
).toString()) : l = e.body, await this.php.run({
|
|
300
|
+
relativeUri: N(
|
|
301
|
+
v(t),
|
|
302
|
+
this.#s
|
|
303
|
+
),
|
|
304
|
+
protocol: this.#t,
|
|
305
|
+
method: e.method || n,
|
|
306
|
+
body: l,
|
|
307
|
+
fileInfos: i,
|
|
308
|
+
scriptPath: this.#u(t.pathname),
|
|
309
|
+
headers: o
|
|
310
|
+
});
|
|
311
|
+
} finally {
|
|
312
|
+
r();
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Resolve the requested path to the filesystem path of the requested PHP file.
|
|
317
|
+
*
|
|
318
|
+
* Fall back to index.php as if there was a url rewriting rule in place.
|
|
319
|
+
*
|
|
320
|
+
* @param requestedPath - The requested pathname.
|
|
321
|
+
* @returns The resolved filesystem path.
|
|
322
|
+
*/
|
|
323
|
+
#u(e) {
|
|
324
|
+
let t = _(e, this.#s);
|
|
325
|
+
t.includes(".php") ? t = t.split(".php")[0] + ".php" : (t.endsWith("/") || (t += "/"), t.endsWith("index.php") || (t += "index.php"));
|
|
326
|
+
const r = `${this.#e}${t}`;
|
|
327
|
+
return this.php.fileExists(r) ? r : `${this.#e}/index.php`;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function $(s) {
|
|
331
|
+
const e = {}, t = s.match(/--(.*)\r\n/);
|
|
332
|
+
if (!t)
|
|
333
|
+
return e;
|
|
334
|
+
const r = t[1], n = s.split(`--${r}`);
|
|
335
|
+
return n.shift(), n.pop(), n.forEach((o) => {
|
|
336
|
+
const i = o.indexOf(`\r
|
|
337
|
+
\r
|
|
338
|
+
`), l = o.substring(0, i).trim(), c = o.substring(i + 4).trim(), d = l.match(/name="([^"]+)"/);
|
|
339
|
+
if (d) {
|
|
340
|
+
const g = d[1];
|
|
341
|
+
e[g] = c;
|
|
342
|
+
}
|
|
343
|
+
}), e;
|
|
344
|
+
}
|
|
345
|
+
function M(s) {
|
|
346
|
+
switch (s.split(".").pop()) {
|
|
347
|
+
case "css":
|
|
348
|
+
return "text/css";
|
|
349
|
+
case "js":
|
|
350
|
+
return "application/javascript";
|
|
351
|
+
case "png":
|
|
352
|
+
return "image/png";
|
|
353
|
+
case "jpg":
|
|
354
|
+
case "jpeg":
|
|
355
|
+
return "image/jpeg";
|
|
356
|
+
case "gif":
|
|
357
|
+
return "image/gif";
|
|
358
|
+
case "svg":
|
|
359
|
+
return "image/svg+xml";
|
|
360
|
+
case "woff":
|
|
361
|
+
return "font/woff";
|
|
362
|
+
case "woff2":
|
|
363
|
+
return "font/woff2";
|
|
364
|
+
case "ttf":
|
|
365
|
+
return "font/ttf";
|
|
366
|
+
case "otf":
|
|
367
|
+
return "font/otf";
|
|
368
|
+
case "eot":
|
|
369
|
+
return "font/eot";
|
|
370
|
+
case "ico":
|
|
371
|
+
return "image/x-icon";
|
|
372
|
+
case "html":
|
|
373
|
+
return "text/html";
|
|
374
|
+
case "json":
|
|
375
|
+
return "application/json";
|
|
376
|
+
case "xml":
|
|
377
|
+
return "application/xml";
|
|
378
|
+
case "txt":
|
|
379
|
+
case "md":
|
|
380
|
+
return "text/plain";
|
|
381
|
+
default:
|
|
382
|
+
return "application-octet-stream";
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const R = {
|
|
386
|
+
0: "No error occurred. System call completed successfully.",
|
|
387
|
+
1: "Argument list too long.",
|
|
388
|
+
2: "Permission denied.",
|
|
389
|
+
3: "Address in use.",
|
|
390
|
+
4: "Address not available.",
|
|
391
|
+
5: "Address family not supported.",
|
|
392
|
+
6: "Resource unavailable, or operation would block.",
|
|
393
|
+
7: "Connection already in progress.",
|
|
394
|
+
8: "Bad file descriptor.",
|
|
395
|
+
9: "Bad message.",
|
|
396
|
+
10: "Device or resource busy.",
|
|
397
|
+
11: "Operation canceled.",
|
|
398
|
+
12: "No child processes.",
|
|
399
|
+
13: "Connection aborted.",
|
|
400
|
+
14: "Connection refused.",
|
|
401
|
+
15: "Connection reset.",
|
|
402
|
+
16: "Resource deadlock would occur.",
|
|
403
|
+
17: "Destination address required.",
|
|
404
|
+
18: "Mathematics argument out of domain of function.",
|
|
405
|
+
19: "Reserved.",
|
|
406
|
+
20: "File exists.",
|
|
407
|
+
21: "Bad address.",
|
|
408
|
+
22: "File too large.",
|
|
409
|
+
23: "Host is unreachable.",
|
|
410
|
+
24: "Identifier removed.",
|
|
411
|
+
25: "Illegal byte sequence.",
|
|
412
|
+
26: "Operation in progress.",
|
|
413
|
+
27: "Interrupted function.",
|
|
414
|
+
28: "Invalid argument.",
|
|
415
|
+
29: "I/O error.",
|
|
416
|
+
30: "Socket is connected.",
|
|
417
|
+
31: "There is a directory under that path.",
|
|
418
|
+
32: "Too many levels of symbolic links.",
|
|
419
|
+
33: "File descriptor value too large.",
|
|
420
|
+
34: "Too many links.",
|
|
421
|
+
35: "Message too large.",
|
|
422
|
+
36: "Reserved.",
|
|
423
|
+
37: "Filename too long.",
|
|
424
|
+
38: "Network is down.",
|
|
425
|
+
39: "Connection aborted by network.",
|
|
426
|
+
40: "Network unreachable.",
|
|
427
|
+
41: "Too many files open in system.",
|
|
428
|
+
42: "No buffer space available.",
|
|
429
|
+
43: "No such device.",
|
|
430
|
+
44: "There is no such file or directory OR the parent directory does not exist.",
|
|
431
|
+
45: "Executable file format error.",
|
|
432
|
+
46: "No locks available.",
|
|
433
|
+
47: "Reserved.",
|
|
434
|
+
48: "Not enough space.",
|
|
435
|
+
49: "No message of the desired type.",
|
|
436
|
+
50: "Protocol not available.",
|
|
437
|
+
51: "No space left on device.",
|
|
438
|
+
52: "Function not supported.",
|
|
439
|
+
53: "The socket is not connected.",
|
|
440
|
+
54: "Not a directory or a symbolic link to a directory.",
|
|
441
|
+
55: "Directory not empty.",
|
|
442
|
+
56: "State not recoverable.",
|
|
443
|
+
57: "Not a socket.",
|
|
444
|
+
58: "Not supported, or operation not supported on socket.",
|
|
445
|
+
59: "Inappropriate I/O control operation.",
|
|
446
|
+
60: "No such device or address.",
|
|
447
|
+
61: "Value too large to be stored in data type.",
|
|
448
|
+
62: "Previous owner died.",
|
|
449
|
+
63: "Operation not permitted.",
|
|
450
|
+
64: "Broken pipe.",
|
|
451
|
+
65: "Protocol error.",
|
|
452
|
+
66: "Protocol not supported.",
|
|
453
|
+
67: "Protocol wrong type for socket.",
|
|
454
|
+
68: "Result too large.",
|
|
455
|
+
69: "Read-only file system.",
|
|
456
|
+
70: "Invalid seek.",
|
|
457
|
+
71: "No such process.",
|
|
458
|
+
72: "Reserved.",
|
|
459
|
+
73: "Connection timed out.",
|
|
460
|
+
74: "Text file busy.",
|
|
461
|
+
75: "Cross-device link.",
|
|
462
|
+
76: "Extension: Capabilities insufficient."
|
|
463
|
+
};
|
|
464
|
+
function p(s = "") {
|
|
465
|
+
return function(t, r, n) {
|
|
466
|
+
const o = n.value;
|
|
467
|
+
n.value = function(...i) {
|
|
468
|
+
try {
|
|
469
|
+
return o.apply(this, i);
|
|
470
|
+
} catch (l) {
|
|
471
|
+
const c = typeof l == "object" ? l?.errno : null;
|
|
472
|
+
if (c in R) {
|
|
473
|
+
const d = R[c], g = typeof i[0] == "string" ? i[0] : null, U = g !== null ? s.replaceAll("{path}", g) : s;
|
|
474
|
+
throw new Error(`${U}: ${d}`, {
|
|
475
|
+
cause: l
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
throw l;
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
async function re(s, e = {}, t = []) {
|
|
484
|
+
let r, n;
|
|
485
|
+
const o = new Promise((c) => {
|
|
486
|
+
n = c;
|
|
487
|
+
}), i = new Promise((c) => {
|
|
488
|
+
r = c;
|
|
489
|
+
}), l = s.init(B, {
|
|
490
|
+
onAbort(c) {
|
|
491
|
+
console.error("WASM aborted: "), console.error(c);
|
|
492
|
+
},
|
|
493
|
+
ENV: {},
|
|
494
|
+
// Emscripten sometimes prepends a '/' to the path, which
|
|
495
|
+
// breaks vite dev mode. An identity `locateFile` function
|
|
496
|
+
// fixes it.
|
|
497
|
+
locateFile: (c) => c,
|
|
498
|
+
...e,
|
|
499
|
+
noInitialRun: !0,
|
|
500
|
+
onRuntimeInitialized() {
|
|
501
|
+
e.onRuntimeInitialized && e.onRuntimeInitialized(), r();
|
|
502
|
+
},
|
|
503
|
+
monitorRunDependencies(c) {
|
|
504
|
+
c === 0 && (delete l.monitorRunDependencies, n());
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
for (const { default: c } of t)
|
|
508
|
+
c(l);
|
|
509
|
+
return t.length || n(), await o, await i, w.push(l), w.length - 1;
|
|
510
|
+
}
|
|
511
|
+
const w = [];
|
|
512
|
+
function D(s) {
|
|
513
|
+
return w[s];
|
|
514
|
+
}
|
|
515
|
+
const B = function() {
|
|
516
|
+
return typeof process < "u" && process.release?.name === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
|
|
517
|
+
}(), E = Symbol("error"), S = Symbol("message");
|
|
518
|
+
class b extends Event {
|
|
519
|
+
/**
|
|
520
|
+
* Create a new `ErrorEvent`.
|
|
521
|
+
*
|
|
522
|
+
* @param type The name of the event
|
|
523
|
+
* @param options A dictionary object that allows for setting
|
|
524
|
+
* attributes via object members of the same name.
|
|
525
|
+
*/
|
|
526
|
+
constructor(e, t = {}) {
|
|
527
|
+
super(e), this[E] = t.error === void 0 ? null : t.error, this[S] = t.message === void 0 ? "" : t.message;
|
|
528
|
+
}
|
|
529
|
+
get error() {
|
|
530
|
+
return this[E];
|
|
531
|
+
}
|
|
532
|
+
get message() {
|
|
533
|
+
return this[S];
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
Object.defineProperty(b.prototype, "error", { enumerable: !0 });
|
|
537
|
+
Object.defineProperty(b.prototype, "message", { enumerable: !0 });
|
|
538
|
+
const q = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : b;
|
|
539
|
+
class W extends EventTarget {
|
|
540
|
+
constructor() {
|
|
541
|
+
super(...arguments), this.listenersCount = 0;
|
|
542
|
+
}
|
|
543
|
+
addEventListener(e, t) {
|
|
544
|
+
++this.listenersCount, super.addEventListener(e, t);
|
|
545
|
+
}
|
|
546
|
+
removeEventListener(e, t) {
|
|
547
|
+
--this.listenersCount, super.removeEventListener(e, t);
|
|
548
|
+
}
|
|
549
|
+
hasListeners() {
|
|
550
|
+
return this.listenersCount > 0;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
function j(s) {
|
|
554
|
+
s.asm = {
|
|
555
|
+
...s.asm
|
|
556
|
+
};
|
|
557
|
+
const e = new W();
|
|
558
|
+
for (const t in s.asm)
|
|
559
|
+
if (typeof s.asm[t] == "function") {
|
|
560
|
+
const r = s.asm[t];
|
|
561
|
+
s.asm[t] = function(...n) {
|
|
562
|
+
try {
|
|
563
|
+
return r(...n);
|
|
564
|
+
} catch (o) {
|
|
565
|
+
if (!(o instanceof Error))
|
|
566
|
+
throw o;
|
|
567
|
+
if ("exitCode" in o && o?.exitCode === 0)
|
|
568
|
+
return;
|
|
569
|
+
const i = G(
|
|
570
|
+
o,
|
|
571
|
+
s.lastAsyncifyStackSource?.stack
|
|
572
|
+
);
|
|
573
|
+
if (s.lastAsyncifyStackSource && (o.cause = s.lastAsyncifyStackSource), !e.hasListeners())
|
|
574
|
+
throw J(i), o;
|
|
575
|
+
e.dispatchEvent(
|
|
576
|
+
new q("error", {
|
|
577
|
+
error: o,
|
|
578
|
+
message: i
|
|
579
|
+
})
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
return e;
|
|
585
|
+
}
|
|
586
|
+
let P = [];
|
|
587
|
+
function z() {
|
|
588
|
+
return P;
|
|
589
|
+
}
|
|
590
|
+
function G(s, e) {
|
|
591
|
+
if (s.message === "unreachable") {
|
|
592
|
+
let t = V;
|
|
593
|
+
e || (t += `
|
|
594
|
+
|
|
595
|
+
This stack trace is lacking. For a better one initialize
|
|
596
|
+
the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
|
|
597
|
+
|
|
598
|
+
`), P = K(
|
|
599
|
+
e || s.stack || ""
|
|
600
|
+
);
|
|
601
|
+
for (const r of P)
|
|
602
|
+
t += ` * ${r}
|
|
603
|
+
`;
|
|
604
|
+
return t;
|
|
605
|
+
}
|
|
606
|
+
return s.message;
|
|
607
|
+
}
|
|
608
|
+
const V = `
|
|
609
|
+
"unreachable" WASM instruction executed.
|
|
610
|
+
|
|
611
|
+
The typical reason is a PHP function missing from the ASYNCIFY_ONLY
|
|
612
|
+
list when building PHP.wasm.
|
|
613
|
+
|
|
614
|
+
You will need to file a new issue in the WordPress Playground repository
|
|
615
|
+
and paste this error message there:
|
|
616
|
+
|
|
617
|
+
https://github.com/WordPress/wordpress-playground/issues/new
|
|
618
|
+
|
|
619
|
+
If you're a core developer, the typical fix is to:
|
|
620
|
+
|
|
621
|
+
* Isolate a minimal reproduction of the error
|
|
622
|
+
* Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository
|
|
623
|
+
* Run 'npm run fix-asyncify'
|
|
624
|
+
* Commit the changes, push to the repo, release updated NPM packages
|
|
625
|
+
|
|
626
|
+
Below is a list of all the PHP functions found in the stack trace to
|
|
627
|
+
help with the minimal reproduction. If they're all already listed in
|
|
628
|
+
the Dockerfile, you'll need to trigger this error again with long stack
|
|
629
|
+
traces enabled. In node.js, you can do it using the --stack-trace-limit=100
|
|
630
|
+
CLI option:
|
|
631
|
+
|
|
632
|
+
`, x = "\x1B[41m", Y = "\x1B[1m", k = "\x1B[0m", T = "\x1B[K";
|
|
633
|
+
let C = !1;
|
|
634
|
+
function J(s) {
|
|
635
|
+
if (!C) {
|
|
636
|
+
C = !0, console.log(`${x}
|
|
637
|
+
${T}
|
|
638
|
+
${Y} WASM ERROR${k}${x}`);
|
|
639
|
+
for (const e of s.split(`
|
|
640
|
+
`))
|
|
641
|
+
console.log(`${T} ${e} `);
|
|
642
|
+
console.log(`${k}`);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
function K(s) {
|
|
646
|
+
try {
|
|
647
|
+
const e = s.split(`
|
|
648
|
+
`).slice(1).map((t) => {
|
|
649
|
+
const r = t.trim().substring(3).split(" ");
|
|
650
|
+
return {
|
|
651
|
+
fn: r.length >= 2 ? r[0] : "<unknown>",
|
|
652
|
+
isWasm: t.includes("wasm://")
|
|
653
|
+
};
|
|
654
|
+
}).filter(
|
|
655
|
+
({ fn: t, isWasm: r }) => r && !t.startsWith("dynCall_") && !t.startsWith("invoke_")
|
|
656
|
+
).map(({ fn: t }) => t);
|
|
657
|
+
return Array.from(new Set(e));
|
|
658
|
+
} catch {
|
|
659
|
+
return [];
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
var Q = Object.defineProperty, X = Object.getOwnPropertyDescriptor, f = (s, e, t, r) => {
|
|
663
|
+
for (var n = r > 1 ? void 0 : r ? X(e, t) : e, o = s.length - 1, i; o >= 0; o--)
|
|
664
|
+
(i = s[o]) && (n = (r ? i(e, t, n) : i(n)) || n);
|
|
665
|
+
return r && n && Q(e, t, n), n;
|
|
666
|
+
};
|
|
667
|
+
const h = "string", m = "number", a = Symbol("__private__dont__use");
|
|
668
|
+
class u {
|
|
669
|
+
/**
|
|
670
|
+
* Initializes a PHP runtime.
|
|
671
|
+
*
|
|
672
|
+
* @internal
|
|
673
|
+
* @param PHPRuntime - Optional. PHP Runtime ID as initialized by loadPHPRuntime.
|
|
674
|
+
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
675
|
+
*/
|
|
676
|
+
constructor(e, t) {
|
|
677
|
+
this.#e = [], this.#t = !1, this.#r = null, e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new A(
|
|
678
|
+
new L(this, t)
|
|
679
|
+
));
|
|
680
|
+
}
|
|
681
|
+
#e;
|
|
682
|
+
#t;
|
|
683
|
+
#r;
|
|
684
|
+
/** @inheritDoc */
|
|
685
|
+
get absoluteUrl() {
|
|
686
|
+
return this.requestHandler.requestHandler.absoluteUrl;
|
|
687
|
+
}
|
|
688
|
+
/** @inheritDoc */
|
|
689
|
+
get documentRoot() {
|
|
690
|
+
return this.requestHandler.requestHandler.documentRoot;
|
|
691
|
+
}
|
|
692
|
+
/** @inheritDoc */
|
|
693
|
+
pathToInternalUrl(e) {
|
|
694
|
+
return this.requestHandler.requestHandler.pathToInternalUrl(e);
|
|
695
|
+
}
|
|
696
|
+
/** @inheritDoc */
|
|
697
|
+
internalUrlToPath(e) {
|
|
698
|
+
return this.requestHandler.requestHandler.internalUrlToPath(
|
|
699
|
+
e
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
initializeRuntime(e) {
|
|
703
|
+
if (this[a])
|
|
704
|
+
throw new Error("PHP runtime already initialized.");
|
|
705
|
+
const t = D(e);
|
|
706
|
+
if (!t)
|
|
707
|
+
throw new Error("Invalid PHP runtime id.");
|
|
708
|
+
this[a] = t, this.#r = j(t);
|
|
709
|
+
}
|
|
710
|
+
/** @inheritDoc */
|
|
711
|
+
setPhpIniPath(e) {
|
|
712
|
+
if (this.#t)
|
|
713
|
+
throw new Error("Cannot set PHP ini path after calling run().");
|
|
714
|
+
this[a].ccall(
|
|
715
|
+
"wasm_set_phpini_path",
|
|
716
|
+
null,
|
|
717
|
+
["string"],
|
|
718
|
+
[e]
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
/** @inheritDoc */
|
|
722
|
+
setPhpIniEntry(e, t) {
|
|
723
|
+
if (this.#t)
|
|
724
|
+
throw new Error("Cannot set PHP ini entries after calling run().");
|
|
725
|
+
this.#e.push([e, t]);
|
|
726
|
+
}
|
|
727
|
+
/** @inheritDoc */
|
|
728
|
+
chdir(e) {
|
|
729
|
+
this[a].FS.chdir(e);
|
|
730
|
+
}
|
|
731
|
+
/** @inheritDoc */
|
|
732
|
+
async request(e, t) {
|
|
733
|
+
if (!this.requestHandler)
|
|
734
|
+
throw new Error("No request handler available.");
|
|
735
|
+
return this.requestHandler.request(e, t);
|
|
736
|
+
}
|
|
737
|
+
/** @inheritDoc */
|
|
738
|
+
async run(e) {
|
|
739
|
+
this.#t || (this.#n(), this.#t = !0), this.#h(e.scriptPath || ""), this.#s(e.relativeUri || ""), this.#a(e.method || "GET");
|
|
740
|
+
const { host: t, ...r } = {
|
|
741
|
+
host: "example.com:443",
|
|
742
|
+
...H(e.headers || {})
|
|
743
|
+
};
|
|
744
|
+
if (this.#i(t, e.protocol || "http"), this.#l(r), e.body && this.#c(e.body), e.fileInfos)
|
|
745
|
+
for (const n of e.fileInfos)
|
|
746
|
+
this.#u(n);
|
|
747
|
+
return e.code && this.#d(" ?>" + e.code), await this.#p();
|
|
748
|
+
}
|
|
749
|
+
#n() {
|
|
750
|
+
if (this.#e.length > 0) {
|
|
751
|
+
const e = this.#e.map(([t, r]) => `${t}=${r}`).join(`
|
|
752
|
+
`) + `
|
|
753
|
+
|
|
754
|
+
`;
|
|
755
|
+
this[a].ccall(
|
|
756
|
+
"wasm_set_phpini_entries",
|
|
757
|
+
null,
|
|
758
|
+
[h],
|
|
759
|
+
[e]
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
this[a].ccall("php_wasm_init", null, [], []);
|
|
763
|
+
}
|
|
764
|
+
#o() {
|
|
765
|
+
const e = "/tmp/headers.json";
|
|
766
|
+
if (!this.fileExists(e))
|
|
767
|
+
throw new Error(
|
|
768
|
+
"SAPI Error: Could not find response headers file."
|
|
769
|
+
);
|
|
770
|
+
const t = JSON.parse(this.readFileAsText(e)), r = {};
|
|
771
|
+
for (const n of t.headers) {
|
|
772
|
+
if (!n.includes(": "))
|
|
773
|
+
continue;
|
|
774
|
+
const o = n.indexOf(": "), i = n.substring(0, o).toLowerCase(), l = n.substring(o + 2);
|
|
775
|
+
i in r || (r[i] = []), r[i].push(l);
|
|
776
|
+
}
|
|
777
|
+
return {
|
|
778
|
+
headers: r,
|
|
779
|
+
httpStatusCode: t.status
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
#s(e) {
|
|
783
|
+
if (this[a].ccall(
|
|
784
|
+
"wasm_set_request_uri",
|
|
785
|
+
null,
|
|
786
|
+
[h],
|
|
787
|
+
[e]
|
|
788
|
+
), e.includes("?")) {
|
|
789
|
+
const t = e.substring(e.indexOf("?") + 1);
|
|
790
|
+
this[a].ccall(
|
|
791
|
+
"wasm_set_query_string",
|
|
792
|
+
null,
|
|
793
|
+
[h],
|
|
794
|
+
[t]
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
#i(e, t) {
|
|
799
|
+
this[a].ccall(
|
|
800
|
+
"wasm_set_request_host",
|
|
801
|
+
null,
|
|
802
|
+
[h],
|
|
803
|
+
[e]
|
|
804
|
+
);
|
|
805
|
+
let r;
|
|
806
|
+
try {
|
|
807
|
+
r = parseInt(new URL(e).port, 10);
|
|
808
|
+
} catch {
|
|
809
|
+
}
|
|
810
|
+
(!r || isNaN(r) || r === 80) && (r = t === "https" ? 443 : 80), this[a].ccall(
|
|
811
|
+
"wasm_set_request_port",
|
|
812
|
+
null,
|
|
813
|
+
[m],
|
|
814
|
+
[r]
|
|
815
|
+
), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
|
|
816
|
+
}
|
|
817
|
+
#a(e) {
|
|
818
|
+
this[a].ccall(
|
|
819
|
+
"wasm_set_request_method",
|
|
820
|
+
null,
|
|
821
|
+
[h],
|
|
822
|
+
[e]
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
#l(e) {
|
|
826
|
+
e.cookie && this[a].ccall(
|
|
827
|
+
"wasm_set_cookies",
|
|
828
|
+
null,
|
|
829
|
+
[h],
|
|
830
|
+
[e.cookie]
|
|
831
|
+
), e["content-type"] && this[a].ccall(
|
|
832
|
+
"wasm_set_content_type",
|
|
833
|
+
null,
|
|
834
|
+
[h],
|
|
835
|
+
[e["content-type"]]
|
|
836
|
+
), e["content-length"] && this[a].ccall(
|
|
837
|
+
"wasm_set_content_length",
|
|
838
|
+
null,
|
|
839
|
+
[m],
|
|
840
|
+
[parseInt(e["content-length"], 10)]
|
|
841
|
+
);
|
|
842
|
+
for (const t in e)
|
|
843
|
+
this.addServerGlobalEntry(
|
|
844
|
+
`HTTP_${t.toUpperCase().replace(/-/g, "_")}`,
|
|
845
|
+
e[t]
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
#c(e) {
|
|
849
|
+
this[a].ccall(
|
|
850
|
+
"wasm_set_request_body",
|
|
851
|
+
null,
|
|
852
|
+
[h],
|
|
853
|
+
[e]
|
|
854
|
+
), this[a].ccall(
|
|
855
|
+
"wasm_set_content_length",
|
|
856
|
+
null,
|
|
857
|
+
[m],
|
|
858
|
+
[new TextEncoder().encode(e).length]
|
|
859
|
+
);
|
|
860
|
+
}
|
|
861
|
+
#h(e) {
|
|
862
|
+
this[a].ccall(
|
|
863
|
+
"wasm_set_path_translated",
|
|
864
|
+
null,
|
|
865
|
+
[h],
|
|
866
|
+
[e]
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
addServerGlobalEntry(e, t) {
|
|
870
|
+
this[a].ccall(
|
|
871
|
+
"wasm_add_SERVER_entry",
|
|
872
|
+
null,
|
|
873
|
+
[h, h],
|
|
874
|
+
[e, t]
|
|
875
|
+
);
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Adds file information to $_FILES superglobal in PHP.
|
|
879
|
+
*
|
|
880
|
+
* In particular:
|
|
881
|
+
* * Creates the file data in the filesystem
|
|
882
|
+
* * Registers the file details in PHP
|
|
883
|
+
*
|
|
884
|
+
* @param fileInfo - File details
|
|
885
|
+
*/
|
|
886
|
+
#u(e) {
|
|
887
|
+
const { key: t, name: r, type: n, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`;
|
|
888
|
+
this.writeFile(i, o);
|
|
889
|
+
const l = 0;
|
|
890
|
+
this[a].ccall(
|
|
891
|
+
"wasm_add_uploaded_file",
|
|
892
|
+
null,
|
|
893
|
+
[h, h, h, h, m, m],
|
|
894
|
+
[t, r, n, i, l, o.byteLength]
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
#d(e) {
|
|
898
|
+
this[a].ccall(
|
|
899
|
+
"wasm_set_php_code",
|
|
900
|
+
null,
|
|
901
|
+
[h],
|
|
902
|
+
[e]
|
|
903
|
+
);
|
|
904
|
+
}
|
|
905
|
+
async #p() {
|
|
906
|
+
let e, t;
|
|
907
|
+
try {
|
|
908
|
+
e = await new Promise(async (o, i) => {
|
|
909
|
+
t = (l) => {
|
|
910
|
+
const c = new Error("Rethrown");
|
|
911
|
+
c.cause = l.error, c.betterMessage = l.message, i(c);
|
|
912
|
+
}, this.#r?.addEventListener(
|
|
913
|
+
"error",
|
|
914
|
+
t
|
|
915
|
+
);
|
|
916
|
+
try {
|
|
917
|
+
o(
|
|
918
|
+
/**
|
|
919
|
+
* This is awkward, but Asyncify makes wasm_sapi_handle_request return
|
|
920
|
+
* Promise<Promise<number>>.
|
|
921
|
+
*
|
|
922
|
+
* @TODO: Determine whether this is a bug in emscripten or in our code.
|
|
923
|
+
*/
|
|
924
|
+
await await this[a].ccall(
|
|
925
|
+
"wasm_sapi_handle_request",
|
|
926
|
+
m,
|
|
927
|
+
[],
|
|
928
|
+
[]
|
|
929
|
+
)
|
|
930
|
+
);
|
|
931
|
+
} catch (l) {
|
|
932
|
+
i(l);
|
|
933
|
+
}
|
|
934
|
+
});
|
|
935
|
+
} catch (o) {
|
|
936
|
+
for (const d in this)
|
|
937
|
+
typeof this[d] == "function" && (this[d] = () => {
|
|
938
|
+
throw new Error(
|
|
939
|
+
"PHP runtime has crashed – see the earlier error for details."
|
|
940
|
+
);
|
|
941
|
+
});
|
|
942
|
+
this.functionsMaybeMissingFromAsyncify = z();
|
|
943
|
+
const i = o, l = "betterMessage" in i ? i.betterMessage : i.message, c = new Error(l);
|
|
944
|
+
throw c.cause = i, c;
|
|
945
|
+
} finally {
|
|
946
|
+
this.#r?.removeEventListener("error", t);
|
|
947
|
+
}
|
|
948
|
+
const { headers: r, httpStatusCode: n } = this.#o();
|
|
949
|
+
return new y(
|
|
950
|
+
n,
|
|
951
|
+
r,
|
|
952
|
+
this.readFileAsBuffer("/tmp/stdout"),
|
|
953
|
+
this.readFileAsText("/tmp/stderr"),
|
|
954
|
+
e
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
mkdir(e) {
|
|
958
|
+
this[a].FS.mkdirTree(e);
|
|
959
|
+
}
|
|
960
|
+
mkdirTree(e) {
|
|
961
|
+
this.mkdir(e);
|
|
962
|
+
}
|
|
963
|
+
readFileAsText(e) {
|
|
964
|
+
return new TextDecoder().decode(this.readFileAsBuffer(e));
|
|
965
|
+
}
|
|
966
|
+
readFileAsBuffer(e) {
|
|
967
|
+
return this[a].FS.readFile(e);
|
|
968
|
+
}
|
|
969
|
+
writeFile(e, t) {
|
|
970
|
+
this[a].FS.writeFile(e, t);
|
|
971
|
+
}
|
|
972
|
+
unlink(e) {
|
|
973
|
+
this[a].FS.unlink(e);
|
|
974
|
+
}
|
|
975
|
+
mv(e, t) {
|
|
976
|
+
this[a].FS.mv(e, t);
|
|
977
|
+
}
|
|
978
|
+
rmdir(e, t = { recursive: !0 }) {
|
|
979
|
+
t?.recursive && this.listFiles(e).forEach((r) => {
|
|
980
|
+
const n = `${e}/${r}`;
|
|
981
|
+
this.isDir(n) ? this.rmdir(n, t) : this.unlink(n);
|
|
982
|
+
}), this[a].FS.rmdir(e);
|
|
983
|
+
}
|
|
984
|
+
listFiles(e) {
|
|
985
|
+
if (!this.fileExists(e))
|
|
986
|
+
return [];
|
|
987
|
+
try {
|
|
988
|
+
return this[a].FS.readdir(e).filter(
|
|
989
|
+
(t) => t !== "." && t !== ".."
|
|
990
|
+
);
|
|
991
|
+
} catch (t) {
|
|
992
|
+
return console.error(t, { path: e }), [];
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
isDir(e) {
|
|
996
|
+
return this.fileExists(e) ? this[a].FS.isDir(
|
|
997
|
+
this[a].FS.lookupPath(e).node.mode
|
|
998
|
+
) : !1;
|
|
999
|
+
}
|
|
1000
|
+
fileExists(e) {
|
|
1001
|
+
try {
|
|
1002
|
+
return this[a].FS.lookupPath(e), !0;
|
|
1003
|
+
} catch {
|
|
1004
|
+
return !1;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
f([
|
|
1009
|
+
p('Could not create directory "{path}"')
|
|
1010
|
+
], u.prototype, "mkdir", 1);
|
|
1011
|
+
f([
|
|
1012
|
+
p('Could not create directory "{path}"')
|
|
1013
|
+
], u.prototype, "mkdirTree", 1);
|
|
1014
|
+
f([
|
|
1015
|
+
p('Could not read "{path}"')
|
|
1016
|
+
], u.prototype, "readFileAsText", 1);
|
|
1017
|
+
f([
|
|
1018
|
+
p('Could not read "{path}"')
|
|
1019
|
+
], u.prototype, "readFileAsBuffer", 1);
|
|
1020
|
+
f([
|
|
1021
|
+
p('Could not write to "{path}"')
|
|
1022
|
+
], u.prototype, "writeFile", 1);
|
|
1023
|
+
f([
|
|
1024
|
+
p('Could not unlink "{path}"')
|
|
1025
|
+
], u.prototype, "unlink", 1);
|
|
1026
|
+
f([
|
|
1027
|
+
p('Could not move "{path}"')
|
|
1028
|
+
], u.prototype, "mv", 1);
|
|
1029
|
+
f([
|
|
1030
|
+
p('Could not remove directory "{path}"')
|
|
1031
|
+
], u.prototype, "rmdir", 1);
|
|
1032
|
+
f([
|
|
1033
|
+
p('Could not list files in "{path}"')
|
|
1034
|
+
], u.prototype, "listFiles", 1);
|
|
1035
|
+
f([
|
|
1036
|
+
p('Could not stat "{path}"')
|
|
1037
|
+
], u.prototype, "isDir", 1);
|
|
1038
|
+
f([
|
|
1039
|
+
p('Could not stat "{path}"')
|
|
1040
|
+
], u.prototype, "fileExists", 1);
|
|
1041
|
+
function H(s) {
|
|
1042
|
+
const e = {};
|
|
1043
|
+
for (const t in s)
|
|
1044
|
+
e[t.toLowerCase()] = s[t];
|
|
1045
|
+
return e;
|
|
1046
|
+
}
|
|
1047
|
+
function Z(s) {
|
|
1048
|
+
return !(s instanceof u);
|
|
1049
|
+
}
|
|
1050
|
+
function se(s) {
|
|
1051
|
+
return !Z(s);
|
|
1052
|
+
}
|
|
1053
|
+
export {
|
|
1054
|
+
u as BasePHP,
|
|
1055
|
+
I as DEFAULT_BASE_URL,
|
|
1056
|
+
ee as LatestSupportedPHPVersion,
|
|
1057
|
+
A as PHPBrowser,
|
|
1058
|
+
L as PHPRequestHandler,
|
|
1059
|
+
y as PHPResponse,
|
|
1060
|
+
F as SupportedPHPVersions,
|
|
1061
|
+
te as SupportedPHPVersionsList,
|
|
1062
|
+
a as __private__dont__use,
|
|
1063
|
+
N as ensurePathPrefix,
|
|
1064
|
+
Z as isLocalPHP,
|
|
1065
|
+
se as isRemotePHP,
|
|
1066
|
+
re as loadPHPRuntime,
|
|
1067
|
+
_ as removePathPrefix,
|
|
1068
|
+
p as rethrowFileSystemError,
|
|
1069
|
+
v as toRelativeUrl
|
|
1070
|
+
};
|