@php-wasm/universal 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +17 -13
- package/index.cjs.map +1 -1
- package/index.js +598 -465
- package/index.js.map +1 -1
- package/lib/api.d.ts +18 -0
- package/lib/index.d.ts +2 -0
- package/lib/php-request-handler.d.ts +2 -1
- package/lib/php-worker.d.ts +2 -1
- package/package.json +8 -8
package/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
var
|
|
2
|
-
throw TypeError(
|
|
1
|
+
var O = (r) => {
|
|
2
|
+
throw TypeError(r);
|
|
3
3
|
};
|
|
4
|
-
var
|
|
5
|
-
var c = (
|
|
4
|
+
var q = (r, e, t) => e.has(r) || O("Cannot " + t);
|
|
5
|
+
var c = (r, e, t) => (q(r, e, "read from private field"), t ? t.call(r) : e.get(r)), h = (r, e, t) => e.has(r) ? O("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), f = (r, e, t, s) => (q(r, e, "write to private field"), s ? s.call(r, t) : e.set(r, t), t), d = (r, e, t) => (q(r, e, "access private method"), t);
|
|
6
6
|
import "@php-wasm/node-polyfills";
|
|
7
7
|
import { logger } from "@php-wasm/logger";
|
|
8
8
|
import { dirname, joinPaths, Semaphore, createSpawnHandler, normalizePath, AcquireTimeoutError } from "@php-wasm/util";
|
|
9
9
|
import { parse, stringify } from "ini";
|
|
10
10
|
import { StreamedFile } from "@php-wasm/stream-compression";
|
|
11
|
+
import * as Comlink from "comlink";
|
|
11
12
|
const FileErrorCodes = {
|
|
12
13
|
0: "No error occurred. System call completed successfully.",
|
|
13
14
|
1: "Argument list too long.",
|
|
@@ -87,20 +88,20 @@ const FileErrorCodes = {
|
|
|
87
88
|
75: "Cross-device link.",
|
|
88
89
|
76: "Extension: Capabilities insufficient."
|
|
89
90
|
};
|
|
90
|
-
function getEmscriptenFsError(
|
|
91
|
-
const e = typeof
|
|
91
|
+
function getEmscriptenFsError(r) {
|
|
92
|
+
const e = typeof r == "object" ? r == null ? void 0 : r.errno : null;
|
|
92
93
|
if (e in FileErrorCodes)
|
|
93
94
|
return FileErrorCodes[e];
|
|
94
95
|
}
|
|
95
|
-
function rethrowFileSystemError(
|
|
96
|
-
return function(
|
|
96
|
+
function rethrowFileSystemError(r = "") {
|
|
97
|
+
return function(t) {
|
|
97
98
|
return function(...s) {
|
|
98
99
|
try {
|
|
99
|
-
return
|
|
100
|
+
return t.apply(this, s);
|
|
100
101
|
} catch (i) {
|
|
101
102
|
const n = typeof i == "object" ? i == null ? void 0 : i.errno : null;
|
|
102
103
|
if (n in FileErrorCodes) {
|
|
103
|
-
const o = FileErrorCodes[n], a = typeof s[1] == "string" ? s[1] : null, l = a !== null ?
|
|
104
|
+
const o = FileErrorCodes[n], a = typeof s[1] == "string" ? s[1] : null, l = a !== null ? r.replaceAll("{path}", a) : r;
|
|
104
105
|
throw new Error(`${l}: ${o}`, {
|
|
105
106
|
cause: i
|
|
106
107
|
});
|
|
@@ -119,8 +120,8 @@ class FSHelpers {
|
|
|
119
120
|
* @param path - The file path to read.
|
|
120
121
|
* @returns The file contents.
|
|
121
122
|
*/
|
|
122
|
-
static readFileAsText(e,
|
|
123
|
-
return new TextDecoder().decode(FSHelpers.readFileAsBuffer(e,
|
|
123
|
+
static readFileAsText(e, t) {
|
|
124
|
+
return new TextDecoder().decode(FSHelpers.readFileAsBuffer(e, t));
|
|
124
125
|
}
|
|
125
126
|
/**
|
|
126
127
|
* Reads a file from the PHP filesystem and returns it as an array buffer.
|
|
@@ -130,8 +131,8 @@ class FSHelpers {
|
|
|
130
131
|
* @param path - The file path to read.
|
|
131
132
|
* @returns The file contents.
|
|
132
133
|
*/
|
|
133
|
-
static readFileAsBuffer(e,
|
|
134
|
-
return e.readFile(
|
|
134
|
+
static readFileAsBuffer(e, t) {
|
|
135
|
+
return e.readFile(t);
|
|
135
136
|
}
|
|
136
137
|
/**
|
|
137
138
|
* Overwrites data in a file in the PHP filesystem.
|
|
@@ -141,8 +142,8 @@ class FSHelpers {
|
|
|
141
142
|
* @param path - The file path to write to.
|
|
142
143
|
* @param data - The data to write to the file.
|
|
143
144
|
*/
|
|
144
|
-
static writeFile(e,
|
|
145
|
-
e.writeFile(
|
|
145
|
+
static writeFile(e, t, s) {
|
|
146
|
+
e.writeFile(t, s);
|
|
146
147
|
}
|
|
147
148
|
/**
|
|
148
149
|
* Removes a file from the PHP filesystem.
|
|
@@ -151,8 +152,8 @@ class FSHelpers {
|
|
|
151
152
|
* @param FS
|
|
152
153
|
* @param path - The file path to remove.
|
|
153
154
|
*/
|
|
154
|
-
static unlink(e,
|
|
155
|
-
e.unlink(
|
|
155
|
+
static unlink(e, t) {
|
|
156
|
+
e.unlink(t);
|
|
156
157
|
}
|
|
157
158
|
/**
|
|
158
159
|
* Moves a file or directory in the PHP filesystem to a
|
|
@@ -162,14 +163,14 @@ class FSHelpers {
|
|
|
162
163
|
* @param fromPath The path to rename.
|
|
163
164
|
* @param toPath The new path.
|
|
164
165
|
*/
|
|
165
|
-
static mv(e,
|
|
166
|
+
static mv(e, t, s) {
|
|
166
167
|
try {
|
|
167
|
-
const i = e.lookupPath(
|
|
168
|
-
i.mountpoint !== n.mountpoint ? (FSHelpers.copyRecursive(e,
|
|
168
|
+
const i = e.lookupPath(t).node.mount, n = FSHelpers.fileExists(e, s) ? e.lookupPath(s).node.mount : e.lookupPath(dirname(s)).node.mount;
|
|
169
|
+
i.mountpoint !== n.mountpoint ? (FSHelpers.copyRecursive(e, t, s), FSHelpers.isDir(e, t) ? FSHelpers.rmdir(e, t, { recursive: !0 }) : e.unlink(t)) : e.rename(t, s);
|
|
169
170
|
} catch (i) {
|
|
170
171
|
const n = getEmscriptenFsError(i);
|
|
171
172
|
throw n ? new Error(
|
|
172
|
-
`Could not move ${
|
|
173
|
+
`Could not move ${t} to ${s}: ${n}`,
|
|
173
174
|
{
|
|
174
175
|
cause: i
|
|
175
176
|
}
|
|
@@ -183,11 +184,11 @@ class FSHelpers {
|
|
|
183
184
|
* @param path The directory path to remove.
|
|
184
185
|
* @param options Options for the removal.
|
|
185
186
|
*/
|
|
186
|
-
static rmdir(e,
|
|
187
|
-
s != null && s.recursive && FSHelpers.listFiles(e,
|
|
188
|
-
const n = `${
|
|
187
|
+
static rmdir(e, t, s = { recursive: !0 }) {
|
|
188
|
+
s != null && s.recursive && FSHelpers.listFiles(e, t).forEach((i) => {
|
|
189
|
+
const n = `${t}/${i}`;
|
|
189
190
|
FSHelpers.isDir(e, n) ? FSHelpers.rmdir(e, n, s) : FSHelpers.unlink(e, n);
|
|
190
|
-
}), e.getPath(e.lookupPath(
|
|
191
|
+
}), e.getPath(e.lookupPath(t).node) === e.cwd() && e.chdir(joinPaths(e.cwd(), "..")), e.rmdir(t);
|
|
191
192
|
}
|
|
192
193
|
/**
|
|
193
194
|
* Lists the files and directories in the given directory.
|
|
@@ -197,20 +198,20 @@ class FSHelpers {
|
|
|
197
198
|
* @param options - Options for the listing.
|
|
198
199
|
* @returns The list of files and directories in the given directory.
|
|
199
200
|
*/
|
|
200
|
-
static listFiles(e,
|
|
201
|
-
if (!FSHelpers.fileExists(e,
|
|
201
|
+
static listFiles(e, t, s = { prependPath: !1 }) {
|
|
202
|
+
if (!FSHelpers.fileExists(e, t))
|
|
202
203
|
return [];
|
|
203
204
|
try {
|
|
204
|
-
const i = e.readdir(
|
|
205
|
+
const i = e.readdir(t).filter(
|
|
205
206
|
(n) => n !== "." && n !== ".."
|
|
206
207
|
);
|
|
207
208
|
if (s.prependPath) {
|
|
208
|
-
const n =
|
|
209
|
+
const n = t.replace(/\/$/, "");
|
|
209
210
|
return i.map((o) => `${n}/${o}`);
|
|
210
211
|
}
|
|
211
212
|
return i;
|
|
212
213
|
} catch (i) {
|
|
213
|
-
return logger.error(i, { path:
|
|
214
|
+
return logger.error(i, { path: t }), [];
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
/**
|
|
@@ -220,8 +221,8 @@ class FSHelpers {
|
|
|
220
221
|
* @param path – The path to check.
|
|
221
222
|
* @returns True if the path is a directory, false otherwise.
|
|
222
223
|
*/
|
|
223
|
-
static isDir(e,
|
|
224
|
-
return FSHelpers.fileExists(e,
|
|
224
|
+
static isDir(e, t) {
|
|
225
|
+
return FSHelpers.fileExists(e, t) ? e.isDir(e.lookupPath(t, { follow: !0 }).node.mode) : !1;
|
|
225
226
|
}
|
|
226
227
|
/**
|
|
227
228
|
* Checks if a file exists in the PHP filesystem.
|
|
@@ -230,8 +231,8 @@ class FSHelpers {
|
|
|
230
231
|
* @param path – The path to check.
|
|
231
232
|
* @returns True if the path is a file, false otherwise.
|
|
232
233
|
*/
|
|
233
|
-
static isFile(e,
|
|
234
|
-
return FSHelpers.fileExists(e,
|
|
234
|
+
static isFile(e, t) {
|
|
235
|
+
return FSHelpers.fileExists(e, t) ? e.isFile(e.lookupPath(t, { follow: !0 }).node.mode) : !1;
|
|
235
236
|
}
|
|
236
237
|
/**
|
|
237
238
|
* Creates a symlink in the PHP filesystem.
|
|
@@ -240,8 +241,8 @@ class FSHelpers {
|
|
|
240
241
|
* @param target
|
|
241
242
|
* @param link
|
|
242
243
|
*/
|
|
243
|
-
static symlink(e,
|
|
244
|
-
return e.symlink(
|
|
244
|
+
static symlink(e, t, s) {
|
|
245
|
+
return e.symlink(t, s);
|
|
245
246
|
}
|
|
246
247
|
/**
|
|
247
248
|
* Checks if a path is a symlink in the PHP filesystem.
|
|
@@ -250,8 +251,8 @@ class FSHelpers {
|
|
|
250
251
|
* @param path
|
|
251
252
|
* @returns True if the path is a symlink, false otherwise.
|
|
252
253
|
*/
|
|
253
|
-
static isSymlink(e,
|
|
254
|
-
return FSHelpers.fileExists(e,
|
|
254
|
+
static isSymlink(e, t) {
|
|
255
|
+
return FSHelpers.fileExists(e, t) ? e.isLink(e.lookupPath(t).node.mode) : !1;
|
|
255
256
|
}
|
|
256
257
|
/**
|
|
257
258
|
* Reads the target of a symlink in the PHP filesystem.
|
|
@@ -260,8 +261,8 @@ class FSHelpers {
|
|
|
260
261
|
* @returns The target of the symlink.
|
|
261
262
|
* @throws {@link @php-wasm/universal:ErrnoError} – If the path is not a symlink.
|
|
262
263
|
*/
|
|
263
|
-
static readlink(e,
|
|
264
|
-
return e.readlink(
|
|
264
|
+
static readlink(e, t) {
|
|
265
|
+
return e.readlink(t);
|
|
265
266
|
}
|
|
266
267
|
/**
|
|
267
268
|
* Gets the real path of a file in the PHP filesystem.
|
|
@@ -270,8 +271,8 @@ class FSHelpers {
|
|
|
270
271
|
*
|
|
271
272
|
* @returns The real path of the file.
|
|
272
273
|
*/
|
|
273
|
-
static realpath(e,
|
|
274
|
-
return e.lookupPath(
|
|
274
|
+
static realpath(e, t) {
|
|
275
|
+
return e.lookupPath(t, { follow: !0 }).path;
|
|
275
276
|
}
|
|
276
277
|
/**
|
|
277
278
|
* Checks if a file (or a directory) exists in the PHP filesystem.
|
|
@@ -280,9 +281,9 @@ class FSHelpers {
|
|
|
280
281
|
* @param path - The file path to check.
|
|
281
282
|
* @returns True if the file exists, false otherwise.
|
|
282
283
|
*/
|
|
283
|
-
static fileExists(e,
|
|
284
|
+
static fileExists(e, t) {
|
|
284
285
|
try {
|
|
285
|
-
return e.lookupPath(
|
|
286
|
+
return e.lookupPath(t), !0;
|
|
286
287
|
} catch {
|
|
287
288
|
return !1;
|
|
288
289
|
}
|
|
@@ -295,24 +296,24 @@ class FSHelpers {
|
|
|
295
296
|
* @param FS
|
|
296
297
|
* @param path - The directory path to create.
|
|
297
298
|
*/
|
|
298
|
-
static mkdir(e,
|
|
299
|
-
e.mkdirTree(
|
|
299
|
+
static mkdir(e, t) {
|
|
300
|
+
e.mkdirTree(t);
|
|
300
301
|
}
|
|
301
|
-
static copyRecursive(e,
|
|
302
|
-
const i = e.lookupPath(
|
|
302
|
+
static copyRecursive(e, t, s) {
|
|
303
|
+
const i = e.lookupPath(t).node;
|
|
303
304
|
if (e.isDir(i.mode)) {
|
|
304
305
|
e.mkdirTree(s);
|
|
305
|
-
const n = e.readdir(
|
|
306
|
+
const n = e.readdir(t).filter(
|
|
306
307
|
(o) => o !== "." && o !== ".."
|
|
307
308
|
);
|
|
308
309
|
for (const o of n)
|
|
309
310
|
FSHelpers.copyRecursive(
|
|
310
311
|
e,
|
|
311
|
-
joinPaths(
|
|
312
|
+
joinPaths(t, o),
|
|
312
313
|
joinPaths(s, o)
|
|
313
314
|
);
|
|
314
315
|
} else
|
|
315
|
-
e.writeFile(s, e.readFile(
|
|
316
|
+
e.writeFile(s, e.readFile(t));
|
|
316
317
|
}
|
|
317
318
|
}
|
|
318
319
|
FSHelpers.readFileAsText = rethrowFileSystemError('Could not read "{path}"')(
|
|
@@ -354,9 +355,9 @@ FSHelpers.copyRecursive = rethrowFileSystemError(
|
|
|
354
355
|
const _private = /* @__PURE__ */ new WeakMap();
|
|
355
356
|
class PHPWorker {
|
|
356
357
|
/** @inheritDoc */
|
|
357
|
-
constructor(e,
|
|
358
|
+
constructor(e, t) {
|
|
358
359
|
this.absoluteUrl = "", this.documentRoot = "", _private.set(this, {
|
|
359
|
-
monitor:
|
|
360
|
+
monitor: t
|
|
360
361
|
}), e && this.__internal_setRequestHandler(e);
|
|
361
362
|
}
|
|
362
363
|
__internal_setRequestHandler(e) {
|
|
@@ -393,16 +394,16 @@ class PHPWorker {
|
|
|
393
394
|
* The onDownloadProgress event listener.
|
|
394
395
|
*/
|
|
395
396
|
async onDownloadProgress(e) {
|
|
396
|
-
var
|
|
397
|
-
return (
|
|
397
|
+
var t;
|
|
398
|
+
return (t = _private.get(this).monitor) == null ? void 0 : t.addEventListener("progress", e);
|
|
398
399
|
}
|
|
399
400
|
/** @inheritDoc @php-wasm/universal!PHP.mv */
|
|
400
|
-
async mv(e,
|
|
401
|
-
return _private.get(this).php.mv(e,
|
|
401
|
+
async mv(e, t) {
|
|
402
|
+
return _private.get(this).php.mv(e, t);
|
|
402
403
|
}
|
|
403
404
|
/** @inheritDoc @php-wasm/universal!PHP.rmdir */
|
|
404
|
-
async rmdir(e,
|
|
405
|
-
return _private.get(this).php.rmdir(e,
|
|
405
|
+
async rmdir(e, t) {
|
|
406
|
+
return _private.get(this).php.rmdir(e, t);
|
|
406
407
|
}
|
|
407
408
|
/** @inheritDoc @php-wasm/universal!PHPRequestHandler.request */
|
|
408
409
|
async request(e) {
|
|
@@ -410,9 +411,9 @@ class PHPWorker {
|
|
|
410
411
|
}
|
|
411
412
|
/** @inheritDoc @php-wasm/universal!/PHP.run */
|
|
412
413
|
async run(e) {
|
|
413
|
-
const { php:
|
|
414
|
+
const { php: t, reap: s } = await _private.get(this).requestHandler.processManager.acquirePHPInstance();
|
|
414
415
|
try {
|
|
415
|
-
return await
|
|
416
|
+
return await t.run(e);
|
|
416
417
|
} finally {
|
|
417
418
|
s();
|
|
418
419
|
}
|
|
@@ -442,16 +443,16 @@ class PHPWorker {
|
|
|
442
443
|
return _private.get(this).php.readFileAsBuffer(e);
|
|
443
444
|
}
|
|
444
445
|
/** @inheritDoc @php-wasm/universal!/PHP.writeFile */
|
|
445
|
-
writeFile(e,
|
|
446
|
-
return _private.get(this).php.writeFile(e,
|
|
446
|
+
writeFile(e, t) {
|
|
447
|
+
return _private.get(this).php.writeFile(e, t);
|
|
447
448
|
}
|
|
448
449
|
/** @inheritDoc @php-wasm/universal!/PHP.unlink */
|
|
449
450
|
unlink(e) {
|
|
450
451
|
return _private.get(this).php.unlink(e);
|
|
451
452
|
}
|
|
452
453
|
/** @inheritDoc @php-wasm/universal!/PHP.listFiles */
|
|
453
|
-
listFiles(e,
|
|
454
|
-
return _private.get(this).php.listFiles(e,
|
|
454
|
+
listFiles(e, t) {
|
|
455
|
+
return _private.get(this).php.listFiles(e, t);
|
|
455
456
|
}
|
|
456
457
|
/** @inheritDoc @php-wasm/universal!/PHP.isDir */
|
|
457
458
|
isDir(e) {
|
|
@@ -470,16 +471,20 @@ class PHPWorker {
|
|
|
470
471
|
return _private.get(this).php.onMessage(e);
|
|
471
472
|
}
|
|
472
473
|
/** @inheritDoc @php-wasm/universal!/PHP.defineConstant */
|
|
473
|
-
defineConstant(e,
|
|
474
|
-
_private.get(this).php.defineConstant(e,
|
|
474
|
+
defineConstant(e, t) {
|
|
475
|
+
_private.get(this).php.defineConstant(e, t);
|
|
475
476
|
}
|
|
476
477
|
/** @inheritDoc @php-wasm/universal!/PHP.addEventListener */
|
|
477
|
-
addEventListener(e,
|
|
478
|
-
_private.get(this).php.addEventListener(e,
|
|
478
|
+
addEventListener(e, t) {
|
|
479
|
+
_private.get(this).php.addEventListener(e, t);
|
|
479
480
|
}
|
|
480
481
|
/** @inheritDoc @php-wasm/universal!/PHP.removeEventListener */
|
|
481
|
-
removeEventListener(e,
|
|
482
|
-
_private.get(this).php.removeEventListener(e,
|
|
482
|
+
removeEventListener(e, t) {
|
|
483
|
+
_private.get(this).php.removeEventListener(e, t);
|
|
484
|
+
}
|
|
485
|
+
async [Symbol.asyncDispose]() {
|
|
486
|
+
var e;
|
|
487
|
+
await ((e = _private.get(this).requestHandler) == null ? void 0 : e[Symbol.asyncDispose]());
|
|
483
488
|
}
|
|
484
489
|
}
|
|
485
490
|
const responseTexts = {
|
|
@@ -498,8 +503,8 @@ const responseTexts = {
|
|
|
498
503
|
200: "OK"
|
|
499
504
|
};
|
|
500
505
|
class StreamedPHPResponse {
|
|
501
|
-
constructor(e,
|
|
502
|
-
this.parsedHeaders = null, this.cachedStdoutText = null, this.cachedStderrText = null, this.headersStream = e, this.stdout =
|
|
506
|
+
constructor(e, t, s, i) {
|
|
507
|
+
this.parsedHeaders = null, this.cachedStdoutText = null, this.cachedStderrText = null, this.headersStream = e, this.stdout = t, this.stderr = s, this.exitCode = i;
|
|
503
508
|
}
|
|
504
509
|
/**
|
|
505
510
|
* True if the response is successful (HTTP status code 200-399),
|
|
@@ -539,7 +544,7 @@ class StreamedPHPResponse {
|
|
|
539
544
|
(e) => e !== 0 ? 500 : void 0
|
|
540
545
|
)
|
|
541
546
|
]).then((e) => e !== void 0 ? e : this.getParsedHeaders().then(
|
|
542
|
-
(
|
|
547
|
+
(t) => t.httpStatusCode,
|
|
543
548
|
() => 200
|
|
544
549
|
)).catch(() => 500);
|
|
545
550
|
}
|
|
@@ -559,16 +564,16 @@ class StreamedPHPResponse {
|
|
|
559
564
|
return this.parsedHeaders || (this.parsedHeaders = parseHeadersStream(this.headersStream)), await this.parsedHeaders;
|
|
560
565
|
}
|
|
561
566
|
}
|
|
562
|
-
async function parseHeadersStream(
|
|
563
|
-
const e = await streamToText(
|
|
564
|
-
let
|
|
567
|
+
async function parseHeadersStream(r) {
|
|
568
|
+
const e = await streamToText(r);
|
|
569
|
+
let t;
|
|
565
570
|
try {
|
|
566
|
-
|
|
571
|
+
t = JSON.parse(e);
|
|
567
572
|
} catch {
|
|
568
573
|
return { headers: {}, httpStatusCode: 200 };
|
|
569
574
|
}
|
|
570
575
|
const s = {};
|
|
571
|
-
for (const i of
|
|
576
|
+
for (const i of t.headers) {
|
|
572
577
|
if (!i.includes(": "))
|
|
573
578
|
continue;
|
|
574
579
|
const n = i.indexOf(": "), o = i.substring(0, n).toLowerCase(), a = i.substring(n + 2);
|
|
@@ -576,28 +581,28 @@ async function parseHeadersStream(t) {
|
|
|
576
581
|
}
|
|
577
582
|
return {
|
|
578
583
|
headers: s,
|
|
579
|
-
httpStatusCode:
|
|
584
|
+
httpStatusCode: t.status
|
|
580
585
|
};
|
|
581
586
|
}
|
|
582
|
-
async function streamToText(
|
|
583
|
-
const e =
|
|
587
|
+
async function streamToText(r) {
|
|
588
|
+
const e = r.pipeThrough(new TextDecoderStream()).getReader(), t = [];
|
|
584
589
|
for (; ; ) {
|
|
585
590
|
const { done: s, value: i } = await e.read();
|
|
586
591
|
if (s)
|
|
587
|
-
return
|
|
588
|
-
i &&
|
|
592
|
+
return t.join("");
|
|
593
|
+
i && t.push(i);
|
|
589
594
|
}
|
|
590
595
|
}
|
|
591
596
|
class PHPResponse {
|
|
592
|
-
constructor(e,
|
|
593
|
-
this.httpStatusCode = e, this.headers =
|
|
597
|
+
constructor(e, t, s, i = "", n = 0) {
|
|
598
|
+
this.httpStatusCode = e, this.headers = t, this.bytes = s, this.exitCode = n, this.errors = i;
|
|
594
599
|
}
|
|
595
|
-
static forHttpCode(e,
|
|
600
|
+
static forHttpCode(e, t = "") {
|
|
596
601
|
return new PHPResponse(
|
|
597
602
|
e,
|
|
598
603
|
{},
|
|
599
604
|
new TextEncoder().encode(
|
|
600
|
-
|
|
605
|
+
t || responseTexts[e] || ""
|
|
601
606
|
)
|
|
602
607
|
);
|
|
603
608
|
}
|
|
@@ -643,8 +648,8 @@ class PHPResponse {
|
|
|
643
648
|
}
|
|
644
649
|
const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map();
|
|
645
650
|
let lastRuntimeId = 0;
|
|
646
|
-
async function loadPHPRuntime(
|
|
647
|
-
const
|
|
651
|
+
async function loadPHPRuntime(r, ...e) {
|
|
652
|
+
const t = Object.assign({}, ...e), [s, i, n] = makePromise(), o = r.init(currentJsRuntime, {
|
|
648
653
|
onAbort(l) {
|
|
649
654
|
n(l), logger.error(l);
|
|
650
655
|
},
|
|
@@ -653,10 +658,10 @@ async function loadPHPRuntime(t, ...e) {
|
|
|
653
658
|
// breaks vite dev mode. An identity `locateFile` function
|
|
654
659
|
// fixes it.
|
|
655
660
|
locateFile: (l) => l,
|
|
656
|
-
...
|
|
661
|
+
...t,
|
|
657
662
|
noInitialRun: !0,
|
|
658
663
|
onRuntimeInitialized() {
|
|
659
|
-
|
|
664
|
+
t.onRuntimeInitialized && t.onRuntimeInitialized(o), i();
|
|
660
665
|
}
|
|
661
666
|
});
|
|
662
667
|
await s;
|
|
@@ -665,17 +670,17 @@ async function loadPHPRuntime(t, ...e) {
|
|
|
665
670
|
return o.outboundNetworkProxyServer && (o.outboundNetworkProxyServer.close(), o.outboundNetworkProxyServer.closeAllConnections()), loadedRuntimes.delete(a), o.originalExit(l);
|
|
666
671
|
}, o[RuntimeId] = a, loadedRuntimes.set(a, o), a;
|
|
667
672
|
}
|
|
668
|
-
function getLoadedRuntime(
|
|
669
|
-
return loadedRuntimes.get(
|
|
673
|
+
function getLoadedRuntime(r) {
|
|
674
|
+
return loadedRuntimes.get(r);
|
|
670
675
|
}
|
|
671
676
|
const currentJsRuntime = function() {
|
|
672
|
-
var
|
|
673
|
-
return typeof process < "u" && ((
|
|
677
|
+
var r;
|
|
678
|
+
return typeof process < "u" && ((r = process.release) == null ? void 0 : r.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
|
|
674
679
|
}(), makePromise = () => {
|
|
675
|
-
const
|
|
676
|
-
|
|
680
|
+
const r = [], e = new Promise((t, s) => {
|
|
681
|
+
r.push(t, s);
|
|
677
682
|
});
|
|
678
|
-
return
|
|
683
|
+
return r.unshift(e), r;
|
|
679
684
|
};
|
|
680
685
|
var _a;
|
|
681
686
|
const kError = Symbol("error"), kMessage = Symbol("message");
|
|
@@ -687,8 +692,8 @@ class ErrorEvent2 extends (_a = Event, _a) {
|
|
|
687
692
|
* @param options A dictionary object that allows for setting
|
|
688
693
|
* attributes via object members of the same name.
|
|
689
694
|
*/
|
|
690
|
-
constructor(e,
|
|
691
|
-
super(e), this[kError] =
|
|
695
|
+
constructor(e, t = {}) {
|
|
696
|
+
super(e), this[kError] = t.error === void 0 ? null : t.error, this[kMessage] = t.message === void 0 ? "" : t.message;
|
|
692
697
|
}
|
|
693
698
|
get error() {
|
|
694
699
|
return this[kError];
|
|
@@ -700,24 +705,24 @@ class ErrorEvent2 extends (_a = Event, _a) {
|
|
|
700
705
|
Object.defineProperty(ErrorEvent2.prototype, "error", { enumerable: !0 });
|
|
701
706
|
Object.defineProperty(ErrorEvent2.prototype, "message", { enumerable: !0 });
|
|
702
707
|
const ErrorEvent = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : ErrorEvent2;
|
|
703
|
-
function isExitCode(
|
|
704
|
-
return
|
|
708
|
+
function isExitCode(r) {
|
|
709
|
+
return r instanceof Error ? "exitCode" in r || (r == null ? void 0 : r.name) === "ExitStatus" && "status" in r : !1;
|
|
705
710
|
}
|
|
706
711
|
class UnhandledRejectionsTarget extends EventTarget {
|
|
707
712
|
constructor() {
|
|
708
713
|
super(...arguments), this.listenersCount = 0;
|
|
709
714
|
}
|
|
710
|
-
addEventListener(e,
|
|
715
|
+
addEventListener(e, t, s) {
|
|
711
716
|
++this.listenersCount, super.addEventListener(
|
|
712
717
|
e,
|
|
713
|
-
|
|
718
|
+
t,
|
|
714
719
|
s
|
|
715
720
|
);
|
|
716
721
|
}
|
|
717
|
-
removeEventListener(e,
|
|
722
|
+
removeEventListener(e, t, s) {
|
|
718
723
|
--this.listenersCount, super.removeEventListener(
|
|
719
724
|
e,
|
|
720
|
-
|
|
725
|
+
t,
|
|
721
726
|
s
|
|
722
727
|
);
|
|
723
728
|
}
|
|
@@ -725,23 +730,24 @@ class UnhandledRejectionsTarget extends EventTarget {
|
|
|
725
730
|
return this.listenersCount > 0;
|
|
726
731
|
}
|
|
727
732
|
}
|
|
728
|
-
function improveWASMErrorReporting(
|
|
733
|
+
function improveWASMErrorReporting(r) {
|
|
729
734
|
const e = new UnhandledRejectionsTarget();
|
|
730
|
-
for (const
|
|
731
|
-
if (typeof
|
|
732
|
-
const s =
|
|
733
|
-
|
|
735
|
+
for (const t in r.wasmExports)
|
|
736
|
+
if (typeof r.wasmExports[t] == "function") {
|
|
737
|
+
const s = r.wasmExports[t];
|
|
738
|
+
r.wasmExports[t] = function(...i) {
|
|
734
739
|
var n;
|
|
735
740
|
try {
|
|
736
741
|
return s(...i);
|
|
737
742
|
} catch (o) {
|
|
738
743
|
if (!(o instanceof Error))
|
|
739
744
|
throw o;
|
|
745
|
+
r.lastAsyncifyStackSource && (o.cause = r.lastAsyncifyStackSource);
|
|
740
746
|
const a = clarifyErrorMessage(
|
|
741
747
|
o,
|
|
742
|
-
(n =
|
|
748
|
+
(n = r.lastAsyncifyStackSource) == null ? void 0 : n.stack
|
|
743
749
|
);
|
|
744
|
-
if (
|
|
750
|
+
if (e.hasListeners()) {
|
|
745
751
|
const l = new ErrorEvent("error", {
|
|
746
752
|
error: o,
|
|
747
753
|
message: a
|
|
@@ -758,23 +764,33 @@ let functionsMaybeMissingFromAsyncify = [];
|
|
|
758
764
|
function getFunctionsMaybeMissingFromAsyncify() {
|
|
759
765
|
return functionsMaybeMissingFromAsyncify;
|
|
760
766
|
}
|
|
761
|
-
function clarifyErrorMessage(
|
|
762
|
-
if (
|
|
763
|
-
let
|
|
764
|
-
e || (
|
|
767
|
+
function clarifyErrorMessage(r, e) {
|
|
768
|
+
if (r.message === "unreachable") {
|
|
769
|
+
let t = UNREACHABLE_ERROR;
|
|
770
|
+
e || (t += `
|
|
765
771
|
|
|
766
772
|
This stack trace is lacking. For a better one initialize
|
|
767
773
|
the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
|
|
768
774
|
|
|
769
|
-
`)
|
|
770
|
-
|
|
775
|
+
`);
|
|
776
|
+
const s = new Set(
|
|
777
|
+
extractPHPFunctionsFromStack(e || "")
|
|
771
778
|
);
|
|
772
|
-
|
|
773
|
-
|
|
779
|
+
let i = r;
|
|
780
|
+
do {
|
|
781
|
+
for (const n of extractPHPFunctionsFromStack(
|
|
782
|
+
i.stack || ""
|
|
783
|
+
))
|
|
784
|
+
s.add(n);
|
|
785
|
+
i = i.cause;
|
|
786
|
+
} while (i);
|
|
787
|
+
functionsMaybeMissingFromAsyncify = Array.from(s);
|
|
788
|
+
for (const n of s)
|
|
789
|
+
t += ` * ${n}
|
|
774
790
|
`;
|
|
775
|
-
return
|
|
791
|
+
return t;
|
|
776
792
|
}
|
|
777
|
-
return
|
|
793
|
+
return r.message;
|
|
778
794
|
}
|
|
779
795
|
const UNREACHABLE_ERROR = `
|
|
780
796
|
"unreachable" WASM instruction executed.
|
|
@@ -802,29 +818,29 @@ CLI option:
|
|
|
802
818
|
|
|
803
819
|
`, redBg = "\x1B[41m", bold = "\x1B[1m", reset = "\x1B[0m", eol = "\x1B[K";
|
|
804
820
|
let logged = !1;
|
|
805
|
-
function showCriticalErrorBox(
|
|
806
|
-
if (!logged && (logged = !0, !(
|
|
821
|
+
function showCriticalErrorBox(r) {
|
|
822
|
+
if (!logged && (logged = !0, !(r != null && r.trim().startsWith("Program terminated with exit")))) {
|
|
807
823
|
logger.log(`${redBg}
|
|
808
824
|
${eol}
|
|
809
825
|
${bold} WASM ERROR${reset}${redBg}`);
|
|
810
|
-
for (const e of
|
|
826
|
+
for (const e of r.split(`
|
|
811
827
|
`))
|
|
812
828
|
logger.log(`${eol} ${e} `);
|
|
813
829
|
logger.log(`${reset}`);
|
|
814
830
|
}
|
|
815
831
|
}
|
|
816
|
-
function extractPHPFunctionsFromStack(
|
|
832
|
+
function extractPHPFunctionsFromStack(r) {
|
|
817
833
|
try {
|
|
818
|
-
const e =
|
|
819
|
-
`).slice(1).map((
|
|
820
|
-
const s =
|
|
834
|
+
const e = r.split(`
|
|
835
|
+
`).slice(1).map((t) => {
|
|
836
|
+
const s = t.trim().substring(3).split(" ");
|
|
821
837
|
return {
|
|
822
838
|
fn: s.length >= 2 ? s[0] : "<unknown>",
|
|
823
|
-
isWasm:
|
|
839
|
+
isWasm: t.includes("wasm:/")
|
|
824
840
|
};
|
|
825
841
|
}).filter(
|
|
826
|
-
({ fn:
|
|
827
|
-
).map(({ fn:
|
|
842
|
+
({ fn: t, isWasm: s }) => s && !t.startsWith("dynCall_") && !t.startsWith("invoke_")
|
|
843
|
+
).map(({ fn: t }) => t);
|
|
828
844
|
return Array.from(new Set(e));
|
|
829
845
|
} catch {
|
|
830
846
|
return [];
|
|
@@ -832,12 +848,12 @@ function extractPHPFunctionsFromStack(t) {
|
|
|
832
848
|
}
|
|
833
849
|
const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
|
|
834
850
|
class PHPExecutionFailureError extends Error {
|
|
835
|
-
constructor(e,
|
|
836
|
-
super(e), this.response =
|
|
851
|
+
constructor(e, t, s) {
|
|
852
|
+
super(e), this.response = t, this.source = s;
|
|
837
853
|
}
|
|
838
854
|
}
|
|
839
855
|
const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php";
|
|
840
|
-
var
|
|
856
|
+
var T, _, H, P, R, k, u, z, L, W, G, V, J, Y, K, X, $, Q, B, D;
|
|
841
857
|
class PHP {
|
|
842
858
|
/**
|
|
843
859
|
* Initializes a PHP runtime.
|
|
@@ -846,38 +862,38 @@ class PHP {
|
|
|
846
862
|
* @param PHPRuntime - Optional. PHP Runtime ID as initialized by loadPHPRuntime.
|
|
847
863
|
* @param requestHandlerOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
848
864
|
*/
|
|
849
|
-
constructor(
|
|
850
|
-
h(this,
|
|
851
|
-
h(this,
|
|
852
|
-
h(this,
|
|
853
|
-
h(this,
|
|
865
|
+
constructor(r) {
|
|
866
|
+
h(this, u);
|
|
867
|
+
h(this, T);
|
|
868
|
+
h(this, _, !1);
|
|
869
|
+
h(this, H, null);
|
|
854
870
|
h(this, P, /* @__PURE__ */ new Map());
|
|
855
871
|
h(this, R, []);
|
|
856
|
-
h(this,
|
|
857
|
-
this.semaphore = new Semaphore({ concurrency: 1 }),
|
|
872
|
+
h(this, k, {});
|
|
873
|
+
this.semaphore = new Semaphore({ concurrency: 1 }), r !== void 0 && this.initializeRuntime(r);
|
|
858
874
|
}
|
|
859
875
|
/**
|
|
860
876
|
* Adds an event listener for a PHP event.
|
|
861
877
|
* @param eventType - The type of event to listen for.
|
|
862
878
|
* @param listener - The listener function to be called when the event is triggered.
|
|
863
879
|
*/
|
|
864
|
-
addEventListener(
|
|
865
|
-
c(this, P).has(
|
|
880
|
+
addEventListener(r, e) {
|
|
881
|
+
c(this, P).has(r) || c(this, P).set(r, /* @__PURE__ */ new Set()), c(this, P).get(r).add(e);
|
|
866
882
|
}
|
|
867
883
|
/**
|
|
868
884
|
* Removes an event listener for a PHP event.
|
|
869
885
|
* @param eventType - The type of event to remove the listener from.
|
|
870
886
|
* @param listener - The listener function to be removed.
|
|
871
887
|
*/
|
|
872
|
-
removeEventListener(
|
|
873
|
-
var
|
|
874
|
-
(
|
|
888
|
+
removeEventListener(r, e) {
|
|
889
|
+
var t;
|
|
890
|
+
(t = c(this, P).get(r)) == null || t.delete(e);
|
|
875
891
|
}
|
|
876
|
-
dispatchEvent(
|
|
877
|
-
const e = c(this, P).get(
|
|
892
|
+
dispatchEvent(r) {
|
|
893
|
+
const e = c(this, P).get(r.type);
|
|
878
894
|
if (e)
|
|
879
|
-
for (const
|
|
880
|
-
r
|
|
895
|
+
for (const t of e)
|
|
896
|
+
t(r);
|
|
881
897
|
}
|
|
882
898
|
/**
|
|
883
899
|
* Listens to message sent by the PHP code.
|
|
@@ -918,10 +934,10 @@ class PHP {
|
|
|
918
934
|
*
|
|
919
935
|
* @param listener Callback function to handle the message.
|
|
920
936
|
*/
|
|
921
|
-
onMessage(
|
|
922
|
-
return c(this, R).push(
|
|
923
|
-
|
|
924
|
-
(e) => e !==
|
|
937
|
+
onMessage(r) {
|
|
938
|
+
return c(this, R).push(r), async () => {
|
|
939
|
+
f(this, R, c(this, R).filter(
|
|
940
|
+
(e) => e !== r
|
|
925
941
|
));
|
|
926
942
|
};
|
|
927
943
|
}
|
|
@@ -937,17 +953,17 @@ class PHP {
|
|
|
937
953
|
return this.requestHandler.documentRoot;
|
|
938
954
|
}
|
|
939
955
|
/** @deprecated Use PHPRequestHandler instead. */
|
|
940
|
-
pathToInternalUrl(
|
|
941
|
-
return this.requestHandler.pathToInternalUrl(
|
|
956
|
+
pathToInternalUrl(r) {
|
|
957
|
+
return this.requestHandler.pathToInternalUrl(r);
|
|
942
958
|
}
|
|
943
959
|
/** @deprecated Use PHPRequestHandler instead. */
|
|
944
|
-
internalUrlToPath(
|
|
945
|
-
return this.requestHandler.internalUrlToPath(
|
|
960
|
+
internalUrlToPath(r) {
|
|
961
|
+
return this.requestHandler.internalUrlToPath(r);
|
|
946
962
|
}
|
|
947
|
-
initializeRuntime(
|
|
963
|
+
initializeRuntime(r) {
|
|
948
964
|
if (this[__private__dont__use])
|
|
949
965
|
throw new Error("PHP runtime already initialized.");
|
|
950
|
-
const e = getLoadedRuntime(
|
|
966
|
+
const e = getLoadedRuntime(r);
|
|
951
967
|
if (!e)
|
|
952
968
|
throw new Error("Invalid PHP runtime id.");
|
|
953
969
|
this[__private__dont__use] = e, this[__private__dont__use].ccall(
|
|
@@ -995,29 +1011,29 @@ class PHP {
|
|
|
995
1011
|
require_once $file;
|
|
996
1012
|
}
|
|
997
1013
|
`
|
|
998
|
-
), e.onMessage = async (
|
|
1014
|
+
), e.onMessage = async (t) => {
|
|
999
1015
|
for (const s of c(this, R)) {
|
|
1000
|
-
const i = await s(
|
|
1016
|
+
const i = await s(t);
|
|
1001
1017
|
if (i)
|
|
1002
1018
|
return i;
|
|
1003
1019
|
}
|
|
1004
1020
|
return "";
|
|
1005
|
-
},
|
|
1021
|
+
}, f(this, H, improveWASMErrorReporting(e)), this.dispatchEvent({
|
|
1006
1022
|
type: "runtime.initialized"
|
|
1007
1023
|
});
|
|
1008
1024
|
}
|
|
1009
1025
|
/** @inheritDoc */
|
|
1010
|
-
async setSapiName(
|
|
1026
|
+
async setSapiName(r) {
|
|
1011
1027
|
if (this[__private__dont__use].ccall(
|
|
1012
1028
|
"wasm_set_sapi_name",
|
|
1013
1029
|
NUMBER,
|
|
1014
1030
|
[STRING],
|
|
1015
|
-
[
|
|
1031
|
+
[r]
|
|
1016
1032
|
) !== 0)
|
|
1017
1033
|
throw new Error(
|
|
1018
1034
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
1019
1035
|
);
|
|
1020
|
-
|
|
1036
|
+
f(this, T, r);
|
|
1021
1037
|
}
|
|
1022
1038
|
/**
|
|
1023
1039
|
* Changes the current working directory in the PHP filesystem.
|
|
@@ -1027,19 +1043,19 @@ class PHP {
|
|
|
1027
1043
|
*
|
|
1028
1044
|
* @param path - The new working directory.
|
|
1029
1045
|
*/
|
|
1030
|
-
chdir(
|
|
1031
|
-
this[__private__dont__use].FS.chdir(
|
|
1046
|
+
chdir(r) {
|
|
1047
|
+
this[__private__dont__use].FS.chdir(r);
|
|
1032
1048
|
}
|
|
1033
1049
|
/**
|
|
1034
1050
|
* Do not use. Use new PHPRequestHandler() instead.
|
|
1035
1051
|
* @deprecated
|
|
1036
1052
|
*/
|
|
1037
|
-
async request(
|
|
1053
|
+
async request(r) {
|
|
1038
1054
|
if (logger.warn(
|
|
1039
1055
|
"PHP.request() is deprecated. Please use new PHPRequestHandler() instead."
|
|
1040
1056
|
), !this.requestHandler)
|
|
1041
1057
|
throw new Error("No request handler available.");
|
|
1042
|
-
return this.requestHandler.request(
|
|
1058
|
+
return this.requestHandler.request(r);
|
|
1043
1059
|
}
|
|
1044
1060
|
/**
|
|
1045
1061
|
* Runs PHP code.
|
|
@@ -1113,29 +1129,29 @@ class PHP {
|
|
|
1113
1129
|
* @deprecated Use stream() instead.
|
|
1114
1130
|
* @param request - PHP runtime options.
|
|
1115
1131
|
*/
|
|
1116
|
-
async run(
|
|
1117
|
-
const e = await this.runStream(
|
|
1132
|
+
async run(r) {
|
|
1133
|
+
const e = await this.runStream(r), t = await PHPResponse.fromStreamedResponse(
|
|
1118
1134
|
e
|
|
1119
1135
|
);
|
|
1120
|
-
if (
|
|
1121
|
-
logger.warn("PHP.run() output was:",
|
|
1136
|
+
if (t.exitCode !== 0) {
|
|
1137
|
+
logger.warn("PHP.run() output was:", t.text);
|
|
1122
1138
|
const s = new PHPExecutionFailureError(
|
|
1123
|
-
`PHP.run() failed with exit code ${
|
|
1139
|
+
`PHP.run() failed with exit code ${t.exitCode} and the following output: ` + t.errors + `
|
|
1124
1140
|
|
|
1125
|
-
` +
|
|
1126
|
-
|
|
1141
|
+
` + t.text,
|
|
1142
|
+
t,
|
|
1127
1143
|
"request"
|
|
1128
1144
|
);
|
|
1129
1145
|
throw logger.error(s), this.dispatchEvent({
|
|
1130
1146
|
type: "request.error",
|
|
1131
1147
|
error: new Error(
|
|
1132
|
-
"PHP.run() failed with exit code " +
|
|
1148
|
+
"PHP.run() failed with exit code " + t.exitCode
|
|
1133
1149
|
),
|
|
1134
1150
|
// Distinguish between PHP request and PHP-wasm errors
|
|
1135
1151
|
source: "request"
|
|
1136
1152
|
}), s;
|
|
1137
1153
|
}
|
|
1138
|
-
return
|
|
1154
|
+
return t;
|
|
1139
1155
|
}
|
|
1140
1156
|
/**
|
|
1141
1157
|
* Runs PHP code and returns a StreamedPHPResponse object that can be used to
|
|
@@ -1228,31 +1244,31 @@ class PHP {
|
|
|
1228
1244
|
* @param request - PHP runtime options.
|
|
1229
1245
|
* @returns A StreamedPHPResponse object.
|
|
1230
1246
|
*/
|
|
1231
|
-
async runStream(
|
|
1247
|
+
async runStream(r) {
|
|
1232
1248
|
const e = await this.semaphore.acquire();
|
|
1233
|
-
let
|
|
1234
|
-
const s = d(this,
|
|
1235
|
-
if (c(this,
|
|
1249
|
+
let t;
|
|
1250
|
+
const s = d(this, u, D).call(this, () => {
|
|
1251
|
+
if (c(this, _) || (d(this, u, L).call(this), f(this, _, !0)), r.scriptPath && !this.fileExists(r.scriptPath))
|
|
1236
1252
|
throw new Error(
|
|
1237
|
-
`The script path "${
|
|
1253
|
+
`The script path "${r.scriptPath}" does not exist.`
|
|
1238
1254
|
);
|
|
1239
|
-
d(this,
|
|
1240
|
-
const i = normalizeHeaders(
|
|
1241
|
-
if (d(this,
|
|
1242
|
-
this.writeFile("/internal/eval.php",
|
|
1243
|
-
else if (typeof
|
|
1244
|
-
d(this,
|
|
1255
|
+
d(this, u, W).call(this, r.relativeUri || ""), d(this, u, Y).call(this, r.method || "GET");
|
|
1256
|
+
const i = normalizeHeaders(r.headers || {}), n = i.host || "example.com:443", o = d(this, u, J).call(this, n, r.protocol || "http");
|
|
1257
|
+
if (d(this, u, G).call(this, n), d(this, u, V).call(this, o), d(this, u, K).call(this, i), r.body && (t = d(this, u, X).call(this, r.body)), typeof r.code == "string")
|
|
1258
|
+
this.writeFile("/internal/eval.php", r.code), d(this, u, $).call(this, "/internal/eval.php");
|
|
1259
|
+
else if (typeof r.scriptPath == "string")
|
|
1260
|
+
d(this, u, $).call(this, r.scriptPath || "");
|
|
1245
1261
|
else
|
|
1246
1262
|
throw new TypeError(
|
|
1247
1263
|
"The request object must have either a `code` or a `scriptPath` property."
|
|
1248
1264
|
);
|
|
1249
|
-
const a = d(this,
|
|
1250
|
-
for (const
|
|
1251
|
-
d(this,
|
|
1252
|
-
const l =
|
|
1253
|
-
for (const
|
|
1254
|
-
d(this,
|
|
1255
|
-
return c(this,
|
|
1265
|
+
const a = d(this, u, z).call(this, r.$_SERVER, i, o);
|
|
1266
|
+
for (const p in a)
|
|
1267
|
+
d(this, u, Q).call(this, p, a[p]);
|
|
1268
|
+
const l = r.env || {};
|
|
1269
|
+
for (const p in l)
|
|
1270
|
+
d(this, u, B).call(this, p, l[p]);
|
|
1271
|
+
return c(this, _) || (d(this, u, L).call(this), f(this, _, !0)), this[__private__dont__use].ccall(
|
|
1256
1272
|
"wasm_sapi_handle_request",
|
|
1257
1273
|
NUMBER,
|
|
1258
1274
|
[],
|
|
@@ -1268,7 +1284,7 @@ class PHP {
|
|
|
1268
1284
|
source: i.source ?? "php-wasm"
|
|
1269
1285
|
});
|
|
1270
1286
|
}).finally(() => {
|
|
1271
|
-
|
|
1287
|
+
t && this[__private__dont__use].free(t);
|
|
1272
1288
|
}).finally(() => {
|
|
1273
1289
|
e(), this.dispatchEvent({
|
|
1274
1290
|
type: "request.end"
|
|
@@ -1280,10 +1296,10 @@ class PHP {
|
|
|
1280
1296
|
* @param key - The name of the constant.
|
|
1281
1297
|
* @param value - The value of the constant.
|
|
1282
1298
|
*/
|
|
1283
|
-
defineConstant(
|
|
1284
|
-
let
|
|
1299
|
+
defineConstant(r, e) {
|
|
1300
|
+
let t = {};
|
|
1285
1301
|
try {
|
|
1286
|
-
|
|
1302
|
+
t = JSON.parse(
|
|
1287
1303
|
this.fileExists("/internal/shared/consts.json") && this.readFileAsText("/internal/shared/consts.json") || "{}"
|
|
1288
1304
|
);
|
|
1289
1305
|
} catch {
|
|
@@ -1291,8 +1307,8 @@ class PHP {
|
|
|
1291
1307
|
this.writeFile(
|
|
1292
1308
|
"/internal/shared/consts.json",
|
|
1293
1309
|
JSON.stringify({
|
|
1294
|
-
...
|
|
1295
|
-
[
|
|
1310
|
+
...t,
|
|
1311
|
+
[r]: e
|
|
1296
1312
|
})
|
|
1297
1313
|
);
|
|
1298
1314
|
}
|
|
@@ -1303,14 +1319,14 @@ class PHP {
|
|
|
1303
1319
|
*
|
|
1304
1320
|
* @param path - The directory path to create.
|
|
1305
1321
|
*/
|
|
1306
|
-
mkdir(
|
|
1307
|
-
return FSHelpers.mkdir(this[__private__dont__use].FS,
|
|
1322
|
+
mkdir(r) {
|
|
1323
|
+
return FSHelpers.mkdir(this[__private__dont__use].FS, r);
|
|
1308
1324
|
}
|
|
1309
1325
|
/**
|
|
1310
1326
|
* @deprecated Use mkdir instead.
|
|
1311
1327
|
*/
|
|
1312
|
-
mkdirTree(
|
|
1313
|
-
return FSHelpers.mkdir(this[__private__dont__use].FS,
|
|
1328
|
+
mkdirTree(r) {
|
|
1329
|
+
return FSHelpers.mkdir(this[__private__dont__use].FS, r);
|
|
1314
1330
|
}
|
|
1315
1331
|
/**
|
|
1316
1332
|
* Reads a file from the PHP filesystem and returns it as a string.
|
|
@@ -1319,8 +1335,8 @@ class PHP {
|
|
|
1319
1335
|
* @param path - The file path to read.
|
|
1320
1336
|
* @returns The file contents.
|
|
1321
1337
|
*/
|
|
1322
|
-
readFileAsText(
|
|
1323
|
-
return FSHelpers.readFileAsText(this[__private__dont__use].FS,
|
|
1338
|
+
readFileAsText(r) {
|
|
1339
|
+
return FSHelpers.readFileAsText(this[__private__dont__use].FS, r);
|
|
1324
1340
|
}
|
|
1325
1341
|
/**
|
|
1326
1342
|
* Reads a file from the PHP filesystem and returns it as an array buffer.
|
|
@@ -1329,8 +1345,8 @@ class PHP {
|
|
|
1329
1345
|
* @param path - The file path to read.
|
|
1330
1346
|
* @returns The file contents.
|
|
1331
1347
|
*/
|
|
1332
|
-
readFileAsBuffer(
|
|
1333
|
-
return FSHelpers.readFileAsBuffer(this[__private__dont__use].FS,
|
|
1348
|
+
readFileAsBuffer(r) {
|
|
1349
|
+
return FSHelpers.readFileAsBuffer(this[__private__dont__use].FS, r);
|
|
1334
1350
|
}
|
|
1335
1351
|
/**
|
|
1336
1352
|
* Overwrites data in a file in the PHP filesystem.
|
|
@@ -1339,8 +1355,8 @@ class PHP {
|
|
|
1339
1355
|
* @param path - The file path to write to.
|
|
1340
1356
|
* @param data - The data to write to the file.
|
|
1341
1357
|
*/
|
|
1342
|
-
writeFile(
|
|
1343
|
-
return FSHelpers.writeFile(this[__private__dont__use].FS,
|
|
1358
|
+
writeFile(r, e) {
|
|
1359
|
+
return FSHelpers.writeFile(this[__private__dont__use].FS, r, e);
|
|
1344
1360
|
}
|
|
1345
1361
|
/**
|
|
1346
1362
|
* Removes a file from the PHP filesystem.
|
|
@@ -1348,8 +1364,8 @@ class PHP {
|
|
|
1348
1364
|
* @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
|
|
1349
1365
|
* @param path - The file path to remove.
|
|
1350
1366
|
*/
|
|
1351
|
-
unlink(
|
|
1352
|
-
return FSHelpers.unlink(this[__private__dont__use].FS,
|
|
1367
|
+
unlink(r) {
|
|
1368
|
+
return FSHelpers.unlink(this[__private__dont__use].FS, r);
|
|
1353
1369
|
}
|
|
1354
1370
|
/**
|
|
1355
1371
|
* Moves a file or directory in the PHP filesystem to a
|
|
@@ -1358,8 +1374,8 @@ class PHP {
|
|
|
1358
1374
|
* @param oldPath The path to rename.
|
|
1359
1375
|
* @param newPath The new path.
|
|
1360
1376
|
*/
|
|
1361
|
-
mv(
|
|
1362
|
-
return FSHelpers.mv(this[__private__dont__use].FS,
|
|
1377
|
+
mv(r, e) {
|
|
1378
|
+
return FSHelpers.mv(this[__private__dont__use].FS, r, e);
|
|
1363
1379
|
}
|
|
1364
1380
|
/**
|
|
1365
1381
|
* Removes a directory from the PHP filesystem.
|
|
@@ -1367,8 +1383,8 @@ class PHP {
|
|
|
1367
1383
|
* @param path The directory path to remove.
|
|
1368
1384
|
* @param options Options for the removal.
|
|
1369
1385
|
*/
|
|
1370
|
-
rmdir(
|
|
1371
|
-
return FSHelpers.rmdir(this[__private__dont__use].FS,
|
|
1386
|
+
rmdir(r, e = { recursive: !0 }) {
|
|
1387
|
+
return FSHelpers.rmdir(this[__private__dont__use].FS, r, e);
|
|
1372
1388
|
}
|
|
1373
1389
|
/**
|
|
1374
1390
|
* Lists the files and directories in the given directory.
|
|
@@ -1377,10 +1393,10 @@ class PHP {
|
|
|
1377
1393
|
* @param options - Options for the listing.
|
|
1378
1394
|
* @returns The list of files and directories in the given directory.
|
|
1379
1395
|
*/
|
|
1380
|
-
listFiles(
|
|
1396
|
+
listFiles(r, e = { prependPath: !1 }) {
|
|
1381
1397
|
return FSHelpers.listFiles(
|
|
1382
1398
|
this[__private__dont__use].FS,
|
|
1383
|
-
|
|
1399
|
+
r,
|
|
1384
1400
|
e
|
|
1385
1401
|
);
|
|
1386
1402
|
}
|
|
@@ -1390,8 +1406,8 @@ class PHP {
|
|
|
1390
1406
|
* @param path – The path to check.
|
|
1391
1407
|
* @returns True if the path is a directory, false otherwise.
|
|
1392
1408
|
*/
|
|
1393
|
-
isDir(
|
|
1394
|
-
return FSHelpers.isDir(this[__private__dont__use].FS,
|
|
1409
|
+
isDir(r) {
|
|
1410
|
+
return FSHelpers.isDir(this[__private__dont__use].FS, r);
|
|
1395
1411
|
}
|
|
1396
1412
|
/**
|
|
1397
1413
|
* Checks if a file exists in the PHP filesystem.
|
|
@@ -1399,16 +1415,16 @@ class PHP {
|
|
|
1399
1415
|
* @param path – The path to check.
|
|
1400
1416
|
* @returns True if the path is a file, false otherwise.
|
|
1401
1417
|
*/
|
|
1402
|
-
isFile(
|
|
1403
|
-
return FSHelpers.isFile(this[__private__dont__use].FS,
|
|
1418
|
+
isFile(r) {
|
|
1419
|
+
return FSHelpers.isFile(this[__private__dont__use].FS, r);
|
|
1404
1420
|
}
|
|
1405
1421
|
/**
|
|
1406
1422
|
* Creates a symlink in the PHP filesystem.
|
|
1407
1423
|
* @param target
|
|
1408
1424
|
* @param path
|
|
1409
1425
|
*/
|
|
1410
|
-
symlink(
|
|
1411
|
-
return FSHelpers.symlink(this[__private__dont__use].FS,
|
|
1426
|
+
symlink(r, e) {
|
|
1427
|
+
return FSHelpers.symlink(this[__private__dont__use].FS, r, e);
|
|
1412
1428
|
}
|
|
1413
1429
|
/**
|
|
1414
1430
|
* Checks if a path is a symlink in the PHP filesystem.
|
|
@@ -1416,8 +1432,8 @@ class PHP {
|
|
|
1416
1432
|
* @param path
|
|
1417
1433
|
* @returns True if the path is a symlink, false otherwise.
|
|
1418
1434
|
*/
|
|
1419
|
-
isSymlink(
|
|
1420
|
-
return FSHelpers.isSymlink(this[__private__dont__use].FS,
|
|
1435
|
+
isSymlink(r) {
|
|
1436
|
+
return FSHelpers.isSymlink(this[__private__dont__use].FS, r);
|
|
1421
1437
|
}
|
|
1422
1438
|
/**
|
|
1423
1439
|
* Reads the target of a symlink in the PHP filesystem.
|
|
@@ -1425,16 +1441,16 @@ class PHP {
|
|
|
1425
1441
|
* @param path
|
|
1426
1442
|
* @returns The target of the symlink.
|
|
1427
1443
|
*/
|
|
1428
|
-
readlink(
|
|
1429
|
-
return FSHelpers.readlink(this[__private__dont__use].FS,
|
|
1444
|
+
readlink(r) {
|
|
1445
|
+
return FSHelpers.readlink(this[__private__dont__use].FS, r);
|
|
1430
1446
|
}
|
|
1431
1447
|
/**
|
|
1432
1448
|
* Resolves the real path of a file in the PHP filesystem.
|
|
1433
1449
|
* @param path
|
|
1434
1450
|
* @returns The real path of the file.
|
|
1435
1451
|
*/
|
|
1436
|
-
realpath(
|
|
1437
|
-
return FSHelpers.realpath(this[__private__dont__use].FS,
|
|
1452
|
+
realpath(r) {
|
|
1453
|
+
return FSHelpers.realpath(this[__private__dont__use].FS, r);
|
|
1438
1454
|
}
|
|
1439
1455
|
/**
|
|
1440
1456
|
* Checks if a file (or a directory) exists in the PHP filesystem.
|
|
@@ -1442,8 +1458,8 @@ class PHP {
|
|
|
1442
1458
|
* @param path - The file path to check.
|
|
1443
1459
|
* @returns True if the file exists, false otherwise.
|
|
1444
1460
|
*/
|
|
1445
|
-
fileExists(
|
|
1446
|
-
return FSHelpers.fileExists(this[__private__dont__use].FS,
|
|
1461
|
+
fileExists(r) {
|
|
1462
|
+
return FSHelpers.fileExists(this[__private__dont__use].FS, r);
|
|
1447
1463
|
}
|
|
1448
1464
|
/**
|
|
1449
1465
|
* Hot-swaps the PHP runtime for a new one without
|
|
@@ -1455,15 +1471,15 @@ class PHP {
|
|
|
1455
1471
|
* is fully decoupled from the request handler and
|
|
1456
1472
|
* accepts a constructor-level cwd argument.
|
|
1457
1473
|
*/
|
|
1458
|
-
async hotSwapPHPRuntime(
|
|
1459
|
-
const
|
|
1460
|
-
for (const [i, n] of Object.entries(c(this,
|
|
1474
|
+
async hotSwapPHPRuntime(r, e) {
|
|
1475
|
+
const t = this[__private__dont__use].FS, s = [];
|
|
1476
|
+
for (const [i, n] of Object.entries(c(this, k)))
|
|
1461
1477
|
s.push({ mountHandler: n.mountHandler, vfsPath: i }), await n.unmount();
|
|
1462
1478
|
try {
|
|
1463
1479
|
this.exit();
|
|
1464
1480
|
} catch {
|
|
1465
1481
|
}
|
|
1466
|
-
this.initializeRuntime(
|
|
1482
|
+
this.initializeRuntime(r), c(this, T) && this.setSapiName(c(this, T)), copyFS(t, this[__private__dont__use].FS, "/internal"), e && copyFS(t, this[__private__dont__use].FS, e);
|
|
1467
1483
|
for (const { mountHandler: i, vfsPath: n } of s)
|
|
1468
1484
|
this.mkdir(n), await this.mount(n, i);
|
|
1469
1485
|
}
|
|
@@ -1474,18 +1490,18 @@ class PHP {
|
|
|
1474
1490
|
* @param mountHandler - The mount handler to use.
|
|
1475
1491
|
* @return Unmount function to unmount the filesystem.
|
|
1476
1492
|
*/
|
|
1477
|
-
async mount(
|
|
1478
|
-
const
|
|
1493
|
+
async mount(r, e) {
|
|
1494
|
+
const t = await e(
|
|
1479
1495
|
this,
|
|
1480
1496
|
this[__private__dont__use].FS,
|
|
1481
|
-
|
|
1497
|
+
r
|
|
1482
1498
|
), s = {
|
|
1483
1499
|
mountHandler: e,
|
|
1484
1500
|
unmount: async () => {
|
|
1485
|
-
await
|
|
1501
|
+
await t(), delete c(this, k)[r];
|
|
1486
1502
|
}
|
|
1487
1503
|
};
|
|
1488
|
-
return c(this,
|
|
1504
|
+
return c(this, k)[r] = s, () => {
|
|
1489
1505
|
s.unmount();
|
|
1490
1506
|
};
|
|
1491
1507
|
}
|
|
@@ -1502,45 +1518,45 @@ class PHP {
|
|
|
1502
1518
|
* @param argv - The arguments to pass to the CLI.
|
|
1503
1519
|
* @returns The exit code of the CLI session.
|
|
1504
1520
|
*/
|
|
1505
|
-
async cli(
|
|
1506
|
-
const
|
|
1521
|
+
async cli(r, e = {}) {
|
|
1522
|
+
const t = await this.semaphore.acquire(), s = e.env || {};
|
|
1507
1523
|
for (const [i, n] of Object.entries(s))
|
|
1508
|
-
d(this,
|
|
1509
|
-
|
|
1510
|
-
for (const i of
|
|
1524
|
+
d(this, u, B).call(this, i, n);
|
|
1525
|
+
r = [r[0], "-c", PHP_INI_PATH, ...r.slice(1)];
|
|
1526
|
+
for (const i of r)
|
|
1511
1527
|
this[__private__dont__use].ccall(
|
|
1512
1528
|
"wasm_add_cli_arg",
|
|
1513
1529
|
null,
|
|
1514
1530
|
[STRING],
|
|
1515
1531
|
[i]
|
|
1516
1532
|
);
|
|
1517
|
-
return await d(this,
|
|
1533
|
+
return await d(this, u, D).call(this, () => this[__private__dont__use].ccall("run_cli", null, [], [], {
|
|
1518
1534
|
async: !0
|
|
1519
|
-
})).then((i) => (i.exitCode.finally(
|
|
1535
|
+
})).then((i) => (i.exitCode.finally(t), i));
|
|
1520
1536
|
}
|
|
1521
|
-
setSkipShebang(
|
|
1537
|
+
setSkipShebang(r) {
|
|
1522
1538
|
this[__private__dont__use].ccall(
|
|
1523
1539
|
"wasm_set_skip_shebang",
|
|
1524
1540
|
null,
|
|
1525
1541
|
[NUMBER],
|
|
1526
|
-
[
|
|
1542
|
+
[r ? 1 : 0]
|
|
1527
1543
|
);
|
|
1528
1544
|
}
|
|
1529
|
-
exit(
|
|
1545
|
+
exit(r = 0) {
|
|
1530
1546
|
this.dispatchEvent({
|
|
1531
1547
|
type: "runtime.beforedestroy"
|
|
1532
1548
|
});
|
|
1533
1549
|
try {
|
|
1534
|
-
this[__private__dont__use]._exit(
|
|
1550
|
+
this[__private__dont__use]._exit(r);
|
|
1535
1551
|
} catch {
|
|
1536
1552
|
}
|
|
1537
|
-
|
|
1553
|
+
f(this, _, !1), f(this, H, null), this[__private__dont__use] && (delete this[__private__dont__use].onMessage, delete this[__private__dont__use]);
|
|
1538
1554
|
}
|
|
1539
1555
|
[Symbol.dispose]() {
|
|
1540
|
-
c(this,
|
|
1556
|
+
c(this, _) && this.exit(0);
|
|
1541
1557
|
}
|
|
1542
1558
|
}
|
|
1543
|
-
|
|
1559
|
+
T = new WeakMap(), _ = new WeakMap(), H = new WeakMap(), P = new WeakMap(), R = new WeakMap(), k = new WeakMap(), u = new WeakSet(), /**
|
|
1544
1560
|
* Prepares the $_SERVER entries for the PHP runtime.
|
|
1545
1561
|
*
|
|
1546
1562
|
* @param defaults Default entries to include in $_SERVER.
|
|
@@ -1549,90 +1565,90 @@ b = new WeakMap(), f = new WeakMap(), E = new WeakMap(), P = new WeakMap(), R =
|
|
|
1549
1565
|
* was provided.
|
|
1550
1566
|
* @returns Computed $_SERVER entries.
|
|
1551
1567
|
*/
|
|
1552
|
-
z = function(
|
|
1568
|
+
z = function(r, e, t) {
|
|
1553
1569
|
const s = {
|
|
1554
|
-
...
|
|
1570
|
+
...r || {}
|
|
1555
1571
|
};
|
|
1556
|
-
s.HTTPS = s.HTTPS ||
|
|
1572
|
+
s.HTTPS = s.HTTPS || t === 443 ? "on" : "off";
|
|
1557
1573
|
for (const i in e) {
|
|
1558
1574
|
let n = "HTTP_";
|
|
1559
1575
|
["content-type", "content-length"].includes(i.toLowerCase()) && (n = ""), s[`${n}${i.toUpperCase().replace(/-/g, "_")}`] = e[i];
|
|
1560
1576
|
}
|
|
1561
1577
|
return s;
|
|
1562
|
-
},
|
|
1578
|
+
}, L = function() {
|
|
1563
1579
|
this[__private__dont__use].ccall("php_wasm_init", null, [], []);
|
|
1564
|
-
}, W = function(
|
|
1580
|
+
}, W = function(r) {
|
|
1565
1581
|
this[__private__dont__use].ccall(
|
|
1566
1582
|
"wasm_set_request_uri",
|
|
1567
1583
|
null,
|
|
1568
1584
|
[STRING],
|
|
1569
|
-
[
|
|
1585
|
+
[r]
|
|
1570
1586
|
);
|
|
1571
1587
|
let e = "";
|
|
1572
|
-
|
|
1588
|
+
r.includes("?") && (e = r.substring(r.indexOf("?") + 1)), this[__private__dont__use].ccall(
|
|
1573
1589
|
"wasm_set_query_string",
|
|
1574
1590
|
null,
|
|
1575
1591
|
[STRING],
|
|
1576
1592
|
[e]
|
|
1577
1593
|
);
|
|
1578
|
-
}, G = function(
|
|
1594
|
+
}, G = function(r) {
|
|
1579
1595
|
this[__private__dont__use].ccall(
|
|
1580
1596
|
"wasm_set_request_host",
|
|
1581
1597
|
null,
|
|
1582
1598
|
[STRING],
|
|
1583
|
-
[
|
|
1599
|
+
[r]
|
|
1584
1600
|
);
|
|
1585
|
-
}, V = function(
|
|
1601
|
+
}, V = function(r) {
|
|
1586
1602
|
this[__private__dont__use].ccall(
|
|
1587
1603
|
"wasm_set_request_port",
|
|
1588
1604
|
null,
|
|
1589
1605
|
[NUMBER],
|
|
1590
|
-
[
|
|
1606
|
+
[r]
|
|
1591
1607
|
);
|
|
1592
|
-
}, J = function(
|
|
1593
|
-
let
|
|
1608
|
+
}, J = function(r, e) {
|
|
1609
|
+
let t;
|
|
1594
1610
|
try {
|
|
1595
|
-
|
|
1611
|
+
t = parseInt(new URL(r).port, 10);
|
|
1596
1612
|
} catch {
|
|
1597
1613
|
}
|
|
1598
|
-
return (!
|
|
1599
|
-
}, Y = function(
|
|
1614
|
+
return (!t || isNaN(t) || t === 80) && (t = e === "https" ? 443 : 80), t;
|
|
1615
|
+
}, Y = function(r) {
|
|
1600
1616
|
this[__private__dont__use].ccall(
|
|
1601
1617
|
"wasm_set_request_method",
|
|
1602
1618
|
null,
|
|
1603
1619
|
[STRING],
|
|
1604
|
-
[
|
|
1620
|
+
[r]
|
|
1605
1621
|
);
|
|
1606
|
-
}, K = function(
|
|
1607
|
-
|
|
1622
|
+
}, K = function(r) {
|
|
1623
|
+
r.cookie && this[__private__dont__use].ccall(
|
|
1608
1624
|
"wasm_set_cookies",
|
|
1609
1625
|
null,
|
|
1610
1626
|
[STRING],
|
|
1611
|
-
[
|
|
1612
|
-
),
|
|
1627
|
+
[r.cookie]
|
|
1628
|
+
), r["content-type"] && this[__private__dont__use].ccall(
|
|
1613
1629
|
"wasm_set_content_type",
|
|
1614
1630
|
null,
|
|
1615
1631
|
[STRING],
|
|
1616
|
-
[
|
|
1617
|
-
),
|
|
1632
|
+
[r["content-type"]]
|
|
1633
|
+
), r["content-length"] && this[__private__dont__use].ccall(
|
|
1618
1634
|
"wasm_set_content_length",
|
|
1619
1635
|
null,
|
|
1620
1636
|
[NUMBER],
|
|
1621
|
-
[parseInt(
|
|
1637
|
+
[parseInt(r["content-length"], 10)]
|
|
1622
1638
|
);
|
|
1623
|
-
}, X = function(
|
|
1624
|
-
let e,
|
|
1625
|
-
typeof
|
|
1639
|
+
}, X = function(r) {
|
|
1640
|
+
let e, t;
|
|
1641
|
+
typeof r == "string" ? (logger.warn(
|
|
1626
1642
|
"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"
|
|
1627
|
-
),
|
|
1643
|
+
), t = this[__private__dont__use].lengthBytesUTF8(r), e = t + 1) : (t = r.byteLength, e = r.byteLength);
|
|
1628
1644
|
const s = this[__private__dont__use].malloc(e);
|
|
1629
1645
|
if (!s)
|
|
1630
1646
|
throw new Error("Could not allocate memory for the request body.");
|
|
1631
|
-
return typeof
|
|
1632
|
-
|
|
1647
|
+
return typeof r == "string" ? this[__private__dont__use].stringToUTF8(
|
|
1648
|
+
r,
|
|
1633
1649
|
s,
|
|
1634
1650
|
e + 1
|
|
1635
|
-
) : this[__private__dont__use].HEAPU8.set(
|
|
1651
|
+
) : this[__private__dont__use].HEAPU8.set(r, s), this[__private__dont__use].ccall(
|
|
1636
1652
|
"wasm_set_request_body",
|
|
1637
1653
|
null,
|
|
1638
1654
|
[NUMBER],
|
|
@@ -1641,59 +1657,59 @@ z = function(t, e, r) {
|
|
|
1641
1657
|
"wasm_set_content_length",
|
|
1642
1658
|
null,
|
|
1643
1659
|
[NUMBER],
|
|
1644
|
-
[
|
|
1660
|
+
[t]
|
|
1645
1661
|
), s;
|
|
1646
|
-
},
|
|
1662
|
+
}, $ = function(r) {
|
|
1647
1663
|
this[__private__dont__use].ccall(
|
|
1648
1664
|
"wasm_set_path_translated",
|
|
1649
1665
|
null,
|
|
1650
1666
|
[STRING],
|
|
1651
|
-
[
|
|
1667
|
+
[r]
|
|
1652
1668
|
);
|
|
1653
|
-
}, Q = function(
|
|
1669
|
+
}, Q = function(r, e) {
|
|
1654
1670
|
this[__private__dont__use].ccall(
|
|
1655
1671
|
"wasm_add_SERVER_entry",
|
|
1656
1672
|
null,
|
|
1657
1673
|
[STRING, STRING],
|
|
1658
|
-
[
|
|
1674
|
+
[r, e]
|
|
1659
1675
|
);
|
|
1660
|
-
},
|
|
1676
|
+
}, B = function(r, e) {
|
|
1661
1677
|
this[__private__dont__use].ccall(
|
|
1662
1678
|
"wasm_add_ENV_entry",
|
|
1663
1679
|
null,
|
|
1664
1680
|
[STRING, STRING],
|
|
1665
|
-
[
|
|
1681
|
+
[r, e]
|
|
1666
1682
|
);
|
|
1667
|
-
},
|
|
1668
|
-
const e = this[__private__dont__use],
|
|
1669
|
-
e.onHeaders = (
|
|
1670
|
-
a || s ||
|
|
1683
|
+
}, D = async function(r) {
|
|
1684
|
+
const e = this[__private__dont__use], t = await createInvertedReadableStream();
|
|
1685
|
+
e.onHeaders = (m) => {
|
|
1686
|
+
a || s || t.controller.enqueue(m.slice());
|
|
1671
1687
|
};
|
|
1672
1688
|
let s = !1;
|
|
1673
1689
|
const i = () => {
|
|
1674
|
-
s || (s = !0,
|
|
1690
|
+
s || (s = !0, t.controller.close());
|
|
1675
1691
|
}, n = await createInvertedReadableStream();
|
|
1676
|
-
e.onStdout = (
|
|
1677
|
-
i(), !a && n.controller.enqueue(
|
|
1692
|
+
e.onStdout = (m) => {
|
|
1693
|
+
i(), !a && n.controller.enqueue(m.slice());
|
|
1678
1694
|
};
|
|
1679
1695
|
const o = await createInvertedReadableStream();
|
|
1680
|
-
e.onStderr = (
|
|
1681
|
-
a || o.controller.enqueue(
|
|
1696
|
+
e.onStderr = (m) => {
|
|
1697
|
+
a || o.controller.enqueue(m.slice());
|
|
1682
1698
|
};
|
|
1683
1699
|
let a = !1, l;
|
|
1684
|
-
const
|
|
1685
|
-
var
|
|
1700
|
+
const E = (async () => {
|
|
1701
|
+
var m;
|
|
1686
1702
|
try {
|
|
1687
1703
|
return await Promise.race([
|
|
1688
|
-
|
|
1689
|
-
new Promise((
|
|
1690
|
-
var
|
|
1691
|
-
l = (
|
|
1692
|
-
if (logger.error(
|
|
1704
|
+
r(),
|
|
1705
|
+
new Promise((N, U) => {
|
|
1706
|
+
var b;
|
|
1707
|
+
l = (w) => {
|
|
1708
|
+
if (logger.error(w), logger.error(w.error), !isExitCode(w.error)) {
|
|
1693
1709
|
const j = new Error("Rethrown");
|
|
1694
|
-
j.cause =
|
|
1710
|
+
j.cause = w.error, j.betterMessage = w.message, U(j);
|
|
1695
1711
|
}
|
|
1696
|
-
}, (
|
|
1712
|
+
}, (b = c(this, H)) == null || b.addEventListener(
|
|
1697
1713
|
"error",
|
|
1698
1714
|
l,
|
|
1699
1715
|
{ once: !0 }
|
|
@@ -1703,93 +1719,93 @@ z = function(t, e, r) {
|
|
|
1703
1719
|
} catch (S) {
|
|
1704
1720
|
if (isExitCode(S))
|
|
1705
1721
|
return S.exitCode;
|
|
1706
|
-
n.controller.error(S), o.controller.error(S),
|
|
1707
|
-
for (const
|
|
1708
|
-
typeof this[
|
|
1722
|
+
n.controller.error(S), o.controller.error(S), t.controller.error(S), a = !0;
|
|
1723
|
+
for (const w in this)
|
|
1724
|
+
typeof this[w] == "function" && (this[w] = () => {
|
|
1709
1725
|
throw new Error(
|
|
1710
1726
|
"PHP runtime has crashed – see the earlier error for details."
|
|
1711
1727
|
);
|
|
1712
1728
|
});
|
|
1713
1729
|
this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
|
|
1714
|
-
const
|
|
1715
|
-
throw
|
|
1730
|
+
const N = S, U = "betterMessage" in N ? N.betterMessage : N.message, b = new Error(U);
|
|
1731
|
+
throw b.cause = N, logger.error(b), b;
|
|
1716
1732
|
} finally {
|
|
1717
|
-
a || (n.controller.close(), o.controller.close(), i(), a = !0), (
|
|
1733
|
+
a || (n.controller.close(), o.controller.close(), i(), a = !0), (m = c(this, H)) == null || m.removeEventListener(
|
|
1718
1734
|
"error",
|
|
1719
1735
|
l
|
|
1720
1736
|
);
|
|
1721
1737
|
}
|
|
1722
1738
|
})();
|
|
1723
1739
|
return new StreamedPHPResponse(
|
|
1724
|
-
|
|
1740
|
+
t.stream,
|
|
1725
1741
|
n.stream,
|
|
1726
1742
|
o.stream,
|
|
1727
|
-
|
|
1743
|
+
E
|
|
1728
1744
|
);
|
|
1729
1745
|
};
|
|
1730
|
-
function normalizeHeaders(
|
|
1746
|
+
function normalizeHeaders(r) {
|
|
1731
1747
|
const e = {};
|
|
1732
|
-
for (const
|
|
1733
|
-
e[
|
|
1748
|
+
for (const t in r)
|
|
1749
|
+
e[t.toLowerCase()] = r[t];
|
|
1734
1750
|
return e;
|
|
1735
1751
|
}
|
|
1736
|
-
function copyFS(
|
|
1752
|
+
function copyFS(r, e, t) {
|
|
1737
1753
|
let s;
|
|
1738
1754
|
try {
|
|
1739
|
-
s =
|
|
1755
|
+
s = r.lookupPath(t);
|
|
1740
1756
|
} catch {
|
|
1741
1757
|
return;
|
|
1742
1758
|
}
|
|
1743
1759
|
if (!("contents" in s.node))
|
|
1744
1760
|
return;
|
|
1745
|
-
if (!
|
|
1746
|
-
e.writeFile(
|
|
1761
|
+
if (!r.isDir(s.node.mode)) {
|
|
1762
|
+
e.writeFile(t, r.readFile(t));
|
|
1747
1763
|
return;
|
|
1748
1764
|
}
|
|
1749
|
-
e.mkdirTree(
|
|
1750
|
-
const i =
|
|
1765
|
+
e.mkdirTree(t);
|
|
1766
|
+
const i = r.readdir(t).filter((n) => n !== "." && n !== "..");
|
|
1751
1767
|
for (const n of i)
|
|
1752
|
-
copyFS(
|
|
1768
|
+
copyFS(r, e, joinPaths(t, n));
|
|
1753
1769
|
}
|
|
1754
|
-
async function createInvertedReadableStream(
|
|
1770
|
+
async function createInvertedReadableStream(r = {}) {
|
|
1755
1771
|
let e;
|
|
1756
|
-
const
|
|
1772
|
+
const t = new Promise(
|
|
1757
1773
|
(n) => {
|
|
1758
1774
|
e = n;
|
|
1759
1775
|
}
|
|
1760
1776
|
), s = new ReadableStream({
|
|
1761
|
-
...
|
|
1777
|
+
...r,
|
|
1762
1778
|
start(n) {
|
|
1763
|
-
if (e(n),
|
|
1764
|
-
return
|
|
1779
|
+
if (e(n), r.start)
|
|
1780
|
+
return r.start(n);
|
|
1765
1781
|
}
|
|
1766
|
-
}), i = await
|
|
1782
|
+
}), i = await t;
|
|
1767
1783
|
return {
|
|
1768
1784
|
stream: s,
|
|
1769
1785
|
controller: i
|
|
1770
1786
|
};
|
|
1771
1787
|
}
|
|
1772
|
-
async function getPhpIniEntries(
|
|
1773
|
-
const
|
|
1788
|
+
async function getPhpIniEntries(r, e) {
|
|
1789
|
+
const t = parse(await r.readFileAsText(PHP_INI_PATH));
|
|
1774
1790
|
if (e === void 0)
|
|
1775
|
-
return
|
|
1791
|
+
return t;
|
|
1776
1792
|
const s = {};
|
|
1777
1793
|
for (const i of e)
|
|
1778
|
-
s[i] =
|
|
1794
|
+
s[i] = t[i];
|
|
1779
1795
|
return s;
|
|
1780
1796
|
}
|
|
1781
|
-
async function setPhpIniEntries(
|
|
1782
|
-
const
|
|
1797
|
+
async function setPhpIniEntries(r, e) {
|
|
1798
|
+
const t = parse(await r.readFileAsText(PHP_INI_PATH));
|
|
1783
1799
|
for (const [s, i] of Object.entries(e))
|
|
1784
|
-
i == null ? delete
|
|
1785
|
-
await
|
|
1800
|
+
i == null ? delete t[s] : t[s] = i;
|
|
1801
|
+
await r.writeFile(PHP_INI_PATH, stringify(t));
|
|
1786
1802
|
}
|
|
1787
|
-
async function withPHPIniValues(
|
|
1788
|
-
const s = await
|
|
1803
|
+
async function withPHPIniValues(r, e, t) {
|
|
1804
|
+
const s = await r.readFileAsText(PHP_INI_PATH);
|
|
1789
1805
|
try {
|
|
1790
|
-
return await setPhpIniEntries(
|
|
1806
|
+
return await setPhpIniEntries(r, e), await t();
|
|
1791
1807
|
} finally {
|
|
1792
|
-
await
|
|
1808
|
+
await r.writeFile(PHP_INI_PATH, s);
|
|
1793
1809
|
}
|
|
1794
1810
|
}
|
|
1795
1811
|
class HttpCookieStore {
|
|
@@ -1798,11 +1814,11 @@ class HttpCookieStore {
|
|
|
1798
1814
|
}
|
|
1799
1815
|
rememberCookiesFromResponseHeaders(e) {
|
|
1800
1816
|
if (e != null && e["set-cookie"])
|
|
1801
|
-
for (const
|
|
1817
|
+
for (const t of e["set-cookie"])
|
|
1802
1818
|
try {
|
|
1803
|
-
if (!
|
|
1819
|
+
if (!t.includes("="))
|
|
1804
1820
|
continue;
|
|
1805
|
-
const s =
|
|
1821
|
+
const s = t.indexOf("="), i = t.substring(0, s), n = t.substring(s + 1).split(";")[0];
|
|
1806
1822
|
this.cookies[i] = n;
|
|
1807
1823
|
} catch (s) {
|
|
1808
1824
|
logger.error(s);
|
|
@@ -1810,21 +1826,21 @@ class HttpCookieStore {
|
|
|
1810
1826
|
}
|
|
1811
1827
|
getCookieRequestHeader() {
|
|
1812
1828
|
const e = [];
|
|
1813
|
-
for (const
|
|
1814
|
-
e.push(`${
|
|
1829
|
+
for (const t in this.cookies)
|
|
1830
|
+
e.push(`${t}=${this.cookies[t]}`);
|
|
1815
1831
|
return e.join("; ");
|
|
1816
1832
|
}
|
|
1817
1833
|
}
|
|
1818
|
-
function streamReadFileFromPHP(
|
|
1834
|
+
function streamReadFileFromPHP(r, e) {
|
|
1819
1835
|
return new ReadableStream({
|
|
1820
|
-
async pull(
|
|
1821
|
-
const s = await
|
|
1822
|
-
|
|
1836
|
+
async pull(t) {
|
|
1837
|
+
const s = await r.readFileAsBuffer(e);
|
|
1838
|
+
t.enqueue(s), t.close();
|
|
1823
1839
|
}
|
|
1824
1840
|
});
|
|
1825
1841
|
}
|
|
1826
|
-
async function* iteratePhpFiles(
|
|
1827
|
-
relativePaths:
|
|
1842
|
+
async function* iteratePhpFiles(r, e, {
|
|
1843
|
+
relativePaths: t = !0,
|
|
1828
1844
|
pathPrefix: s,
|
|
1829
1845
|
exceptPaths: i = []
|
|
1830
1846
|
} = {}) {
|
|
@@ -1834,28 +1850,28 @@ async function* iteratePhpFiles(t, e, {
|
|
|
1834
1850
|
const o = n.pop();
|
|
1835
1851
|
if (!o)
|
|
1836
1852
|
return;
|
|
1837
|
-
const a = await
|
|
1853
|
+
const a = await r.listFiles(o);
|
|
1838
1854
|
for (const l of a) {
|
|
1839
|
-
const
|
|
1840
|
-
if (i.includes(
|
|
1855
|
+
const p = `${o}/${l}`;
|
|
1856
|
+
if (i.includes(p.substring(e.length + 1)))
|
|
1841
1857
|
continue;
|
|
1842
|
-
await
|
|
1843
|
-
streamReadFileFromPHP(
|
|
1844
|
-
|
|
1858
|
+
await r.isDir(p) ? n.push(p) : yield new StreamedFile(
|
|
1859
|
+
streamReadFileFromPHP(r, p),
|
|
1860
|
+
t ? joinPaths(
|
|
1845
1861
|
s || "",
|
|
1846
|
-
|
|
1847
|
-
) :
|
|
1862
|
+
p.substring(e.length + 1)
|
|
1863
|
+
) : p
|
|
1848
1864
|
);
|
|
1849
1865
|
}
|
|
1850
1866
|
}
|
|
1851
1867
|
}
|
|
1852
|
-
function writeFilesStreamToPhp(
|
|
1868
|
+
function writeFilesStreamToPhp(r, e) {
|
|
1853
1869
|
return new WritableStream({
|
|
1854
|
-
async write(
|
|
1855
|
-
const s = joinPaths(e,
|
|
1856
|
-
|
|
1870
|
+
async write(t) {
|
|
1871
|
+
const s = joinPaths(e, t.name);
|
|
1872
|
+
t.type === "directory" ? await r.mkdir(s) : (await r.mkdir(dirname(s)), await r.writeFile(
|
|
1857
1873
|
s,
|
|
1858
|
-
new Uint8Array(await
|
|
1874
|
+
new Uint8Array(await t.arrayBuffer())
|
|
1859
1875
|
));
|
|
1860
1876
|
}
|
|
1861
1877
|
});
|
|
@@ -1924,8 +1940,8 @@ class PHPProcessManager {
|
|
|
1924
1940
|
this.primaryIdle = !0;
|
|
1925
1941
|
}
|
|
1926
1942
|
};
|
|
1927
|
-
const
|
|
1928
|
-
return this.semaphore.remaining > 0 ? this.nextInstance = this.spawn({ isPrimary: !1 }) : this.nextInstance = null, await
|
|
1943
|
+
const t = this.nextInstance || this.spawn({ isPrimary: !1 });
|
|
1944
|
+
return this.semaphore.remaining > 0 ? this.nextInstance = this.spawn({ isPrimary: !1 }) : this.nextInstance = null, await t;
|
|
1929
1945
|
}
|
|
1930
1946
|
/**
|
|
1931
1947
|
* Initiated spawning of a new PHP instance.
|
|
@@ -1938,14 +1954,14 @@ class PHPProcessManager {
|
|
|
1938
1954
|
throw new Error(
|
|
1939
1955
|
"Requested spawning a primary PHP instance when another primary instance already started spawning."
|
|
1940
1956
|
);
|
|
1941
|
-
const
|
|
1942
|
-
this.allInstances.push(
|
|
1957
|
+
const t = this.doSpawn(e);
|
|
1958
|
+
this.allInstances.push(t);
|
|
1943
1959
|
const s = () => {
|
|
1944
1960
|
this.allInstances = this.allInstances.filter(
|
|
1945
|
-
(i) => i !==
|
|
1961
|
+
(i) => i !== t
|
|
1946
1962
|
);
|
|
1947
1963
|
};
|
|
1948
|
-
return
|
|
1964
|
+
return t.catch((i) => {
|
|
1949
1965
|
throw s(), i;
|
|
1950
1966
|
}).then((i) => ({
|
|
1951
1967
|
...i,
|
|
@@ -1958,9 +1974,9 @@ class PHPProcessManager {
|
|
|
1958
1974
|
* Actually acquires the lock and spawns a new PHP instance.
|
|
1959
1975
|
*/
|
|
1960
1976
|
async doSpawn(e) {
|
|
1961
|
-
let
|
|
1977
|
+
let t;
|
|
1962
1978
|
try {
|
|
1963
|
-
|
|
1979
|
+
t = await this.semaphore.acquire();
|
|
1964
1980
|
} catch (s) {
|
|
1965
1981
|
throw s instanceof AcquireTimeoutError ? new MaxPhpInstancesError(this.maxPhpInstances) : s;
|
|
1966
1982
|
}
|
|
@@ -1969,17 +1985,17 @@ class PHPProcessManager {
|
|
|
1969
1985
|
return {
|
|
1970
1986
|
php: s,
|
|
1971
1987
|
reap() {
|
|
1972
|
-
s.exit(),
|
|
1988
|
+
s.exit(), t();
|
|
1973
1989
|
}
|
|
1974
1990
|
};
|
|
1975
1991
|
} catch (s) {
|
|
1976
|
-
throw
|
|
1992
|
+
throw t(), s;
|
|
1977
1993
|
}
|
|
1978
1994
|
}
|
|
1979
1995
|
async [Symbol.asyncDispose]() {
|
|
1980
1996
|
this.primaryPhp && this.primaryPhp.exit(), await Promise.all(
|
|
1981
1997
|
this.allInstances.map(
|
|
1982
|
-
(e) => e.then(({ reap:
|
|
1998
|
+
(e) => e.then(({ reap: t }) => t())
|
|
1983
1999
|
)
|
|
1984
2000
|
);
|
|
1985
2001
|
}
|
|
@@ -1994,37 +2010,37 @@ const SupportedPHPVersions = [
|
|
|
1994
2010
|
"7.3",
|
|
1995
2011
|
"7.2"
|
|
1996
2012
|
], LatestSupportedPHPVersion = SupportedPHPVersions[0], SupportedPHPVersionsList = SupportedPHPVersions, DEFAULT_BASE_URL = "http://example.com";
|
|
1997
|
-
function toRelativeUrl(
|
|
1998
|
-
return
|
|
2013
|
+
function toRelativeUrl(r) {
|
|
2014
|
+
return r.toString().substring(r.origin.length);
|
|
1999
2015
|
}
|
|
2000
|
-
function removePathPrefix(
|
|
2001
|
-
return !e || !
|
|
2016
|
+
function removePathPrefix(r, e) {
|
|
2017
|
+
return !e || !r.startsWith(e) ? r : r.substring(e.length);
|
|
2002
2018
|
}
|
|
2003
|
-
function ensurePathPrefix(
|
|
2004
|
-
return !e ||
|
|
2019
|
+
function ensurePathPrefix(r, e) {
|
|
2020
|
+
return !e || r.startsWith(e) ? r : e + r;
|
|
2005
2021
|
}
|
|
2006
|
-
async function encodeAsMultipart(
|
|
2007
|
-
const e = `----${Math.random().toString(36).slice(2)}`,
|
|
2008
|
-
for (const [l,
|
|
2022
|
+
async function encodeAsMultipart(r) {
|
|
2023
|
+
const e = `----${Math.random().toString(36).slice(2)}`, t = `multipart/form-data; boundary=${e}`, s = new TextEncoder(), i = [];
|
|
2024
|
+
for (const [l, p] of Object.entries(r))
|
|
2009
2025
|
i.push(`--${e}\r
|
|
2010
|
-
`), i.push(`Content-Disposition: form-data; name="${l}"`),
|
|
2011
|
-
`),
|
|
2026
|
+
`), i.push(`Content-Disposition: form-data; name="${l}"`), p instanceof File && i.push(`; filename="${p.name}"`), i.push(`\r
|
|
2027
|
+
`), p instanceof File && (i.push("Content-Type: application/octet-stream"), i.push(`\r
|
|
2012
2028
|
`)), i.push(`\r
|
|
2013
|
-
`),
|
|
2029
|
+
`), p instanceof File ? i.push(await fileToUint8Array(p)) : i.push(p), i.push(`\r
|
|
2014
2030
|
`);
|
|
2015
2031
|
i.push(`--${e}--\r
|
|
2016
2032
|
`);
|
|
2017
|
-
const n = i.reduce((l,
|
|
2033
|
+
const n = i.reduce((l, p) => l + p.length, 0), o = new Uint8Array(n);
|
|
2018
2034
|
let a = 0;
|
|
2019
2035
|
for (const l of i)
|
|
2020
2036
|
o.set(
|
|
2021
2037
|
typeof l == "string" ? s.encode(l) : l,
|
|
2022
2038
|
a
|
|
2023
2039
|
), a += l.length;
|
|
2024
|
-
return { bytes: o, contentType:
|
|
2040
|
+
return { bytes: o, contentType: t };
|
|
2025
2041
|
}
|
|
2026
|
-
function fileToUint8Array(
|
|
2027
|
-
return
|
|
2042
|
+
function fileToUint8Array(r) {
|
|
2043
|
+
return r.arrayBuffer().then((e) => new Uint8Array(e));
|
|
2028
2044
|
}
|
|
2029
2045
|
const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "application/atom+xml", avi = "video/x-msvideo", avif = "image/avif", bin = "application/octet-stream", bmp = "image/x-ms-bmp", cco = "application/x-cocoa", css = "text/css", data = "application/octet-stream", deb = "application/octet-stream", der = "application/x-x509-ca-cert", dmg = "application/octet-stream", doc = "application/msword", docx = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", eot = "application/vnd.ms-fontobject", flv = "video/x-flv", gif = "image/gif", gz = "application/gzip", hqx = "application/mac-binhex40", htc = "text/x-component", html = "text/html", ico = "image/x-icon", iso = "application/octet-stream", jad = "text/vnd.sun.j2me.app-descriptor", jar = "application/java-archive", jardiff = "application/x-java-archive-diff", jng = "image/x-jng", jnlp = "application/x-java-jnlp-file", jpg = "image/jpeg", jpeg = "image/jpeg", js = "application/javascript", json = "application/json", kml = "application/vnd.google-earth.kml+xml", kmz = "application/vnd.google-earth.kmz", m3u8 = "application/vnd.apple.mpegurl", m4a = "audio/x-m4a", m4v = "video/x-m4v", md = "text/plain", mid = "audio/midi", mml = "text/mathml", mng = "video/x-mng", mov = "video/quicktime", mp3 = "audio/mpeg", mp4 = "video/mp4", mpeg = "video/mpeg", msi = "application/octet-stream", odg = "application/vnd.oasis.opendocument.graphics", odp = "application/vnd.oasis.opendocument.presentation", ods = "application/vnd.oasis.opendocument.spreadsheet", odt = "application/vnd.oasis.opendocument.text", ogg = "audio/ogg", otf = "font/otf", pdf = "application/pdf", pl = "application/x-perl", png = "image/png", ppt = "application/vnd.ms-powerpoint", pptx = "application/vnd.openxmlformats-officedocument.presentationml.presentation", prc = "application/x-pilot", ps = "application/postscript", ra = "audio/x-realaudio", rar = "application/x-rar-compressed", rpm = "application/x-redhat-package-manager", rss = "application/rss+xml", rtf = "application/rtf", run = "application/x-makeself", sea = "application/x-sea", sit = "application/x-stuffit", svg = "image/svg+xml", swf = "application/x-shockwave-flash", tcl = "application/x-tcl", tar = "application/x-tar", tif = "image/tiff", ts = "video/mp2t", ttf = "font/ttf", txt = "text/plain", wasm = "application/wasm", wbmp = "image/vnd.wap.wbmp", webm = "video/webm", webp = "image/webp", wml = "text/vnd.wap.wml", wmlc = "application/vnd.wap.wmlc", wmv = "video/x-ms-wmv", woff = "font/woff", woff2 = "font/woff2", xhtml = "application/xhtml+xml", xls = "application/vnd.ms-excel", xlsx = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", xml = "text/xml", xpi = "application/x-xpinstall", xspf = "application/xspf+xml", zip = "application/zip", mimeTypes = {
|
|
2030
2046
|
_default,
|
|
@@ -2122,7 +2138,7 @@ const _default = "application/octet-stream", asx = "video/x-ms-asf", atom = "app
|
|
|
2122
2138
|
xspf,
|
|
2123
2139
|
zip
|
|
2124
2140
|
};
|
|
2125
|
-
var g,
|
|
2141
|
+
var g, C, M, F, I, y, A, v, x, Z, ee, te;
|
|
2126
2142
|
class PHPRequestHandler {
|
|
2127
2143
|
/**
|
|
2128
2144
|
* The request handler needs to decide whether to serve a static asset or
|
|
@@ -2138,39 +2154,39 @@ class PHPRequestHandler {
|
|
|
2138
2154
|
constructor(e) {
|
|
2139
2155
|
h(this, x);
|
|
2140
2156
|
h(this, g);
|
|
2141
|
-
h(this, k);
|
|
2142
|
-
h(this, N);
|
|
2143
|
-
h(this, H);
|
|
2144
|
-
h(this, I);
|
|
2145
|
-
h(this, _);
|
|
2146
2157
|
h(this, C);
|
|
2158
|
+
h(this, M);
|
|
2159
|
+
h(this, F);
|
|
2160
|
+
h(this, I);
|
|
2161
|
+
h(this, y);
|
|
2162
|
+
h(this, A);
|
|
2147
2163
|
h(this, v);
|
|
2148
2164
|
const {
|
|
2149
|
-
documentRoot:
|
|
2165
|
+
documentRoot: t = "/www/",
|
|
2150
2166
|
absoluteUrl: s = typeof location == "object" ? location.href : DEFAULT_BASE_URL,
|
|
2151
2167
|
rewriteRules: i = [],
|
|
2152
2168
|
getFileNotFoundAction: n = () => ({ type: "404" })
|
|
2153
2169
|
} = e;
|
|
2154
2170
|
"processManager" in e ? this.processManager = e.processManager : this.processManager = new PHPProcessManager({
|
|
2155
2171
|
phpFactory: async (l) => {
|
|
2156
|
-
const
|
|
2172
|
+
const p = await e.phpFactory({
|
|
2157
2173
|
...l,
|
|
2158
2174
|
requestHandler: this
|
|
2159
2175
|
});
|
|
2160
|
-
return
|
|
2176
|
+
return p.isDir(t) || p.mkdir(t), p.chdir(t), p.requestHandler = this, p;
|
|
2161
2177
|
},
|
|
2162
2178
|
maxPhpInstances: e.maxPhpInstances
|
|
2163
|
-
}),
|
|
2179
|
+
}), f(this, v, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), f(this, g, t);
|
|
2164
2180
|
const o = new URL(s);
|
|
2165
|
-
|
|
2166
|
-
const a = c(this,
|
|
2167
|
-
|
|
2168
|
-
c(this,
|
|
2169
|
-
a ? `:${c(this,
|
|
2170
|
-
].join("")),
|
|
2171
|
-
`${c(this,
|
|
2181
|
+
f(this, M, o.hostname), f(this, F, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), f(this, C, (o.protocol || "").replace(":", ""));
|
|
2182
|
+
const a = c(this, F) !== 443 && c(this, F) !== 80;
|
|
2183
|
+
f(this, I, [
|
|
2184
|
+
c(this, M),
|
|
2185
|
+
a ? `:${c(this, F)}` : ""
|
|
2186
|
+
].join("")), f(this, y, o.pathname.replace(/\/+$/, "")), f(this, A, [
|
|
2187
|
+
`${c(this, C)}://`,
|
|
2172
2188
|
c(this, I),
|
|
2173
|
-
c(this,
|
|
2189
|
+
c(this, y)
|
|
2174
2190
|
].join("")), this.rewriteRules = i, this.getFileNotFoundAction = n;
|
|
2175
2191
|
}
|
|
2176
2192
|
async getPrimaryPhp() {
|
|
@@ -2194,14 +2210,14 @@ class PHPRequestHandler {
|
|
|
2194
2210
|
* @returns The relative path.
|
|
2195
2211
|
*/
|
|
2196
2212
|
internalUrlToPath(e) {
|
|
2197
|
-
const
|
|
2198
|
-
return
|
|
2213
|
+
const t = new URL(e);
|
|
2214
|
+
return t.pathname.startsWith(c(this, y)) && (t.pathname = t.pathname.slice(c(this, y).length)), toRelativeUrl(t);
|
|
2199
2215
|
}
|
|
2200
2216
|
/**
|
|
2201
2217
|
* The absolute URL of this PHPRequestHandler instance.
|
|
2202
2218
|
*/
|
|
2203
2219
|
get absoluteUrl() {
|
|
2204
|
-
return c(this,
|
|
2220
|
+
return c(this, A);
|
|
2205
2221
|
}
|
|
2206
2222
|
/**
|
|
2207
2223
|
* The directory in the PHP filesystem where the server will look
|
|
@@ -2259,14 +2275,14 @@ class PHPRequestHandler {
|
|
|
2259
2275
|
* @param request - PHP Request data.
|
|
2260
2276
|
*/
|
|
2261
2277
|
async request(e) {
|
|
2262
|
-
const
|
|
2278
|
+
const t = URL.canParse(e.url), s = new URL(
|
|
2263
2279
|
// Remove the hash part of the URL as it's not meant for the server.
|
|
2264
2280
|
e.url.split("#")[0],
|
|
2265
|
-
|
|
2281
|
+
t ? void 0 : DEFAULT_BASE_URL
|
|
2266
2282
|
), i = applyRewriteRules(
|
|
2267
2283
|
removePathPrefix(
|
|
2268
2284
|
decodeURIComponent(s.pathname),
|
|
2269
|
-
c(this,
|
|
2285
|
+
c(this, y)
|
|
2270
2286
|
),
|
|
2271
2287
|
this.rewriteRules
|
|
2272
2288
|
), n = await this.getPrimaryPhp();
|
|
@@ -2317,15 +2333,18 @@ class PHPRequestHandler {
|
|
|
2317
2333
|
else
|
|
2318
2334
|
return PHPResponse.forHttpCode(404);
|
|
2319
2335
|
}
|
|
2336
|
+
async [Symbol.asyncDispose]() {
|
|
2337
|
+
await this.processManager[Symbol.asyncDispose]();
|
|
2338
|
+
}
|
|
2320
2339
|
}
|
|
2321
|
-
g = new WeakMap(),
|
|
2340
|
+
g = new WeakMap(), C = new WeakMap(), M = new WeakMap(), F = new WeakMap(), I = new WeakMap(), y = new WeakMap(), A = new WeakMap(), v = new WeakMap(), x = new WeakSet(), /**
|
|
2322
2341
|
* Serves a static file from the PHP filesystem.
|
|
2323
2342
|
*
|
|
2324
2343
|
* @param fsPath - Absolute path of the static file to serve.
|
|
2325
2344
|
* @returns The response.
|
|
2326
2345
|
*/
|
|
2327
|
-
Z = function(e,
|
|
2328
|
-
const s = e.readFileAsBuffer(
|
|
2346
|
+
Z = function(e, t) {
|
|
2347
|
+
const s = e.readFileAsBuffer(t);
|
|
2329
2348
|
return new PHPResponse(
|
|
2330
2349
|
200,
|
|
2331
2350
|
{
|
|
@@ -2333,13 +2352,13 @@ Z = function(e, r) {
|
|
|
2333
2352
|
// @TODO: Infer the content-type from the arrayBuffer instead of the
|
|
2334
2353
|
// file path. The code below won't return the correct mime-type if the
|
|
2335
2354
|
// extension was tampered with.
|
|
2336
|
-
"content-type": [inferMimeType(
|
|
2355
|
+
"content-type": [inferMimeType(t)],
|
|
2337
2356
|
"accept-ranges": ["bytes"],
|
|
2338
2357
|
"cache-control": ["public, max-age=0"]
|
|
2339
2358
|
},
|
|
2340
2359
|
s
|
|
2341
2360
|
);
|
|
2342
|
-
}, ee = async function(e,
|
|
2361
|
+
}, ee = async function(e, t) {
|
|
2343
2362
|
let s;
|
|
2344
2363
|
try {
|
|
2345
2364
|
s = await this.processManager.acquirePHPInstance({
|
|
@@ -2349,18 +2368,18 @@ Z = function(e, r) {
|
|
|
2349
2368
|
return i instanceof MaxPhpInstancesError ? PHPResponse.forHttpCode(502) : PHPResponse.forHttpCode(500);
|
|
2350
2369
|
}
|
|
2351
2370
|
try {
|
|
2352
|
-
return await d(this, x, te).call(this, s.php, e,
|
|
2371
|
+
return await d(this, x, te).call(this, s.php, e, t);
|
|
2353
2372
|
} finally {
|
|
2354
2373
|
s.reap();
|
|
2355
2374
|
}
|
|
2356
|
-
}, te = async function(e,
|
|
2375
|
+
}, te = async function(e, t, s) {
|
|
2357
2376
|
let i = "GET";
|
|
2358
2377
|
const n = {
|
|
2359
2378
|
host: c(this, I),
|
|
2360
|
-
...normalizeHeaders(
|
|
2379
|
+
...normalizeHeaders(t.headers || {})
|
|
2361
2380
|
};
|
|
2362
2381
|
c(this, v) && (n.cookie = c(this, v).getCookieRequestHeader());
|
|
2363
|
-
let o =
|
|
2382
|
+
let o = t.body;
|
|
2364
2383
|
if (typeof o == "object" && !(o instanceof Uint8Array)) {
|
|
2365
2384
|
i = "POST";
|
|
2366
2385
|
const { bytes: a, contentType: l } = await encodeAsMultipart(o);
|
|
@@ -2369,15 +2388,15 @@ Z = function(e, r) {
|
|
|
2369
2388
|
try {
|
|
2370
2389
|
const a = await e.run({
|
|
2371
2390
|
relativeUri: ensurePathPrefix(
|
|
2372
|
-
toRelativeUrl(new URL(
|
|
2373
|
-
c(this,
|
|
2391
|
+
toRelativeUrl(new URL(t.url)),
|
|
2392
|
+
c(this, y)
|
|
2374
2393
|
),
|
|
2375
|
-
protocol: c(this,
|
|
2376
|
-
method:
|
|
2394
|
+
protocol: c(this, C),
|
|
2395
|
+
method: t.method || i,
|
|
2377
2396
|
$_SERVER: {
|
|
2378
2397
|
REMOTE_ADDR: "127.0.0.1",
|
|
2379
2398
|
DOCUMENT_ROOT: c(this, g),
|
|
2380
|
-
HTTPS: c(this,
|
|
2399
|
+
HTTPS: c(this, A).startsWith("https://") ? "on" : ""
|
|
2381
2400
|
},
|
|
2382
2401
|
body: o,
|
|
2383
2402
|
scriptPath: s,
|
|
@@ -2393,20 +2412,20 @@ Z = function(e, r) {
|
|
|
2393
2412
|
throw a;
|
|
2394
2413
|
}
|
|
2395
2414
|
};
|
|
2396
|
-
function inferMimeType(
|
|
2397
|
-
const e =
|
|
2415
|
+
function inferMimeType(r) {
|
|
2416
|
+
const e = r.split(".").pop();
|
|
2398
2417
|
return mimeTypes[e] || mimeTypes._default;
|
|
2399
2418
|
}
|
|
2400
|
-
function applyRewriteRules(
|
|
2401
|
-
for (const
|
|
2402
|
-
if (new RegExp(
|
|
2403
|
-
return
|
|
2404
|
-
return
|
|
2419
|
+
function applyRewriteRules(r, e) {
|
|
2420
|
+
for (const t of e)
|
|
2421
|
+
if (new RegExp(t.match).test(r))
|
|
2422
|
+
return r.replace(t.match, t.replacement);
|
|
2423
|
+
return r;
|
|
2405
2424
|
}
|
|
2406
2425
|
function rotatePHPRuntime({
|
|
2407
|
-
php:
|
|
2426
|
+
php: r,
|
|
2408
2427
|
cwd: e,
|
|
2409
|
-
recreateRuntime:
|
|
2428
|
+
recreateRuntime: t,
|
|
2410
2429
|
/*
|
|
2411
2430
|
* 400 is an arbitrary number that should trigger a rotation
|
|
2412
2431
|
* way before the memory gets too fragmented. If it doesn't,
|
|
@@ -2419,9 +2438,9 @@ function rotatePHPRuntime({
|
|
|
2419
2438
|
}) {
|
|
2420
2439
|
let i = 0;
|
|
2421
2440
|
async function n() {
|
|
2422
|
-
const l = await
|
|
2441
|
+
const l = await r.semaphore.acquire();
|
|
2423
2442
|
try {
|
|
2424
|
-
await
|
|
2443
|
+
await r.hotSwapPHPRuntime(await t(), e), i = 0;
|
|
2425
2444
|
} finally {
|
|
2426
2445
|
l();
|
|
2427
2446
|
}
|
|
@@ -2432,31 +2451,143 @@ function rotatePHPRuntime({
|
|
|
2432
2451
|
async function a(l) {
|
|
2433
2452
|
l.type === "request.error" && l.source === "php-wasm" && await n();
|
|
2434
2453
|
}
|
|
2435
|
-
return
|
|
2436
|
-
|
|
2454
|
+
return r.addEventListener("request.error", a), r.addEventListener("request.end", o), function() {
|
|
2455
|
+
r.removeEventListener("request.error", a), r.removeEventListener("request.end", o);
|
|
2437
2456
|
};
|
|
2438
2457
|
}
|
|
2439
|
-
async function writeFiles(
|
|
2440
|
-
s && await
|
|
2441
|
-
for (const [i, n] of Object.entries(
|
|
2458
|
+
async function writeFiles(r, e, t, { rmRoot: s = !1 } = {}) {
|
|
2459
|
+
s && await r.isDir(e) && await r.rmdir(e, { recursive: !0 });
|
|
2460
|
+
for (const [i, n] of Object.entries(t)) {
|
|
2442
2461
|
const o = joinPaths(e, i);
|
|
2443
|
-
await
|
|
2462
|
+
await r.fileExists(dirname(o)) || await r.mkdir(dirname(o)), n instanceof Uint8Array || typeof n == "string" ? await r.writeFile(o, n) : await writeFiles(r, o, n);
|
|
2444
2463
|
}
|
|
2445
2464
|
}
|
|
2446
|
-
function proxyFileSystem(
|
|
2447
|
-
const s = Object.getOwnPropertySymbols(
|
|
2448
|
-
for (const i of
|
|
2449
|
-
e.fileExists(i) || e.mkdir(i),
|
|
2465
|
+
function proxyFileSystem(r, e, t) {
|
|
2466
|
+
const s = Object.getOwnPropertySymbols(r)[0];
|
|
2467
|
+
for (const i of t)
|
|
2468
|
+
e.fileExists(i) || e.mkdir(i), r.fileExists(i) || r.mkdir(i), e[s].FS.mount(
|
|
2450
2469
|
// @ts-ignore
|
|
2451
2470
|
e[s].PROXYFS,
|
|
2452
2471
|
{
|
|
2453
2472
|
root: i,
|
|
2454
2473
|
// @ts-ignore
|
|
2455
|
-
fs:
|
|
2474
|
+
fs: r[s].FS
|
|
2456
2475
|
},
|
|
2457
2476
|
i
|
|
2458
2477
|
);
|
|
2459
2478
|
}
|
|
2479
|
+
/**
|
|
2480
|
+
* @license
|
|
2481
|
+
* Copyright 2019 Google LLC
|
|
2482
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2483
|
+
*/
|
|
2484
|
+
function nodeEndpoint(r) {
|
|
2485
|
+
const e = /* @__PURE__ */ new WeakMap();
|
|
2486
|
+
return {
|
|
2487
|
+
postMessage: r.postMessage.bind(r),
|
|
2488
|
+
addEventListener: (t, s) => {
|
|
2489
|
+
const i = (n) => {
|
|
2490
|
+
"handleEvent" in s ? s.handleEvent({ data: n }) : s({ data: n });
|
|
2491
|
+
};
|
|
2492
|
+
r.on("message", i), e.set(s, i);
|
|
2493
|
+
},
|
|
2494
|
+
removeEventListener: (t, s) => {
|
|
2495
|
+
const i = e.get(s);
|
|
2496
|
+
i && (r.off("message", i), e.delete(s));
|
|
2497
|
+
},
|
|
2498
|
+
start: r.start && r.start.bind(r)
|
|
2499
|
+
};
|
|
2500
|
+
}
|
|
2501
|
+
function consumeAPI(r, e = void 0) {
|
|
2502
|
+
setupTransferHandlers();
|
|
2503
|
+
let t;
|
|
2504
|
+
import.meta.url.startsWith("file://") ? t = nodeEndpoint(r) : t = r instanceof Worker ? r : Comlink.windowEndpoint(r, e);
|
|
2505
|
+
const i = Comlink.wrap(t), n = proxyClone(i);
|
|
2506
|
+
return new Proxy(n, {
|
|
2507
|
+
get: (o, a) => a === "isConnected" ? async () => {
|
|
2508
|
+
for (; ; )
|
|
2509
|
+
try {
|
|
2510
|
+
await runWithTimeout(i.isConnected(), 200);
|
|
2511
|
+
break;
|
|
2512
|
+
} catch {
|
|
2513
|
+
}
|
|
2514
|
+
} : i[a]
|
|
2515
|
+
});
|
|
2516
|
+
}
|
|
2517
|
+
async function runWithTimeout(r, e) {
|
|
2518
|
+
return new Promise((t, s) => {
|
|
2519
|
+
setTimeout(s, e), r.then(t);
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2522
|
+
function exposeAPI(r, e, t) {
|
|
2523
|
+
setupTransferHandlers();
|
|
2524
|
+
const s = Promise.resolve();
|
|
2525
|
+
let i, n;
|
|
2526
|
+
const o = new Promise((E, m) => {
|
|
2527
|
+
i = E, n = m;
|
|
2528
|
+
}), a = proxyClone(r), l = new Proxy(a, {
|
|
2529
|
+
get: (E, m) => m === "isConnected" ? () => s : m === "isReady" ? () => o : m in E ? E[m] : e == null ? void 0 : e[m]
|
|
2530
|
+
});
|
|
2531
|
+
let p;
|
|
2532
|
+
return t ? p = nodeEndpoint(t) : p = typeof window < "u" ? Comlink.windowEndpoint(self.parent) : void 0, Comlink.expose(l, p), [i, n, l];
|
|
2533
|
+
}
|
|
2534
|
+
let isTransferHandlersSetup = !1;
|
|
2535
|
+
function setupTransferHandlers() {
|
|
2536
|
+
if (isTransferHandlersSetup)
|
|
2537
|
+
return;
|
|
2538
|
+
isTransferHandlersSetup = !0, Comlink.transferHandlers.set("EVENT", {
|
|
2539
|
+
canHandle: (t) => t instanceof CustomEvent,
|
|
2540
|
+
serialize: (t) => [
|
|
2541
|
+
{
|
|
2542
|
+
detail: t.detail
|
|
2543
|
+
},
|
|
2544
|
+
[]
|
|
2545
|
+
],
|
|
2546
|
+
deserialize: (t) => t
|
|
2547
|
+
}), Comlink.transferHandlers.set("FUNCTION", {
|
|
2548
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
2549
|
+
canHandle: (t) => typeof t == "function",
|
|
2550
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
2551
|
+
serialize(t) {
|
|
2552
|
+
const { port1: s, port2: i } = new MessageChannel();
|
|
2553
|
+
return Comlink.expose(t, s), [i, [i]];
|
|
2554
|
+
},
|
|
2555
|
+
deserialize(t) {
|
|
2556
|
+
return t.start(), Comlink.wrap(t);
|
|
2557
|
+
}
|
|
2558
|
+
}), Comlink.transferHandlers.set("PHPResponse", {
|
|
2559
|
+
canHandle: (t) => typeof t == "object" && t !== null && "headers" in t && "bytes" in t && "errors" in t && "exitCode" in t && "httpStatusCode" in t,
|
|
2560
|
+
serialize(t) {
|
|
2561
|
+
return [t.toRawData(), []];
|
|
2562
|
+
},
|
|
2563
|
+
deserialize(t) {
|
|
2564
|
+
return PHPResponse.fromRawData(t);
|
|
2565
|
+
}
|
|
2566
|
+
});
|
|
2567
|
+
const r = Comlink.transferHandlers.get("throw"), e = r == null ? void 0 : r.serialize;
|
|
2568
|
+
r.serialize = ({ value: t }) => {
|
|
2569
|
+
const s = e({ value: t });
|
|
2570
|
+
return t.response && (s[0].value.response = t.response), t.source && (s[0].value.source = t.source), s;
|
|
2571
|
+
};
|
|
2572
|
+
}
|
|
2573
|
+
function proxyClone(r) {
|
|
2574
|
+
return new Proxy(r, {
|
|
2575
|
+
get(e, t) {
|
|
2576
|
+
switch (typeof e[t]) {
|
|
2577
|
+
case "function":
|
|
2578
|
+
return (...s) => e[t](...s);
|
|
2579
|
+
case "object":
|
|
2580
|
+
return e[t] === null ? e[t] : proxyClone(e[t]);
|
|
2581
|
+
case "undefined":
|
|
2582
|
+
case "number":
|
|
2583
|
+
case "string":
|
|
2584
|
+
return e[t];
|
|
2585
|
+
default:
|
|
2586
|
+
return Comlink.proxy(e[t]);
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
});
|
|
2590
|
+
}
|
|
2460
2591
|
export {
|
|
2461
2592
|
DEFAULT_BASE_URL,
|
|
2462
2593
|
FSHelpers,
|
|
@@ -2474,7 +2605,9 @@ export {
|
|
|
2474
2605
|
UnhandledRejectionsTarget,
|
|
2475
2606
|
__private__dont__use,
|
|
2476
2607
|
applyRewriteRules,
|
|
2608
|
+
consumeAPI,
|
|
2477
2609
|
ensurePathPrefix,
|
|
2610
|
+
exposeAPI,
|
|
2478
2611
|
getLoadedRuntime,
|
|
2479
2612
|
getPhpIniEntries,
|
|
2480
2613
|
isExitCode,
|