@wp-playground/blueprints 0.1.45 → 0.1.49
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 +27 -20
- package/index.js +305 -277
- package/lib/steps/activate-plugin.d.ts +1 -1
- package/lib/steps/activate-theme.d.ts +12 -0
- package/lib/steps/client-methods.d.ts +174 -0
- package/lib/steps/handlers.d.ts +1 -0
- package/lib/steps/index.d.ts +16 -3
- package/lib/steps/install-plugin.d.ts +8 -3
- package/lib/steps/install-theme.d.ts +34 -1
- package/lib/steps/login.d.ts +19 -4
- package/lib/steps/site-data.d.ts +43 -0
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
const oe = async (r, { pluginPath: e }, t) => {
|
|
2
|
+
t?.tracker.setCaption(`Activating ${e}`);
|
|
3
|
+
const s = [
|
|
4
|
+
`${r.documentRoot}/wp-load.php`,
|
|
5
|
+
`${r.documentRoot}/wp-admin/includes/plugin.php`
|
|
6
|
+
];
|
|
7
|
+
if (!s.every(
|
|
8
|
+
(i) => r.fileExists(i)
|
|
9
|
+
))
|
|
10
|
+
throw new Error(
|
|
11
|
+
`Required WordPress files do not exist: ${s.join(", ")}`
|
|
12
|
+
);
|
|
13
|
+
await r.run({
|
|
14
|
+
code: `<?php
|
|
15
|
+
${s.map((i) => `require_once( '${i}' );`).join(`
|
|
16
|
+
`)}
|
|
17
|
+
activate_plugin('${e}');
|
|
18
|
+
`
|
|
19
|
+
});
|
|
20
|
+
}, ae = async (r, { themeFolderName: e }, t) => {
|
|
21
|
+
t?.tracker.setCaption(`Activating ${e}`);
|
|
22
|
+
const s = `${r.documentRoot}/wp-load.php`;
|
|
23
|
+
if (!r.fileExists(s))
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Required WordPress file does not exist: ${s}`
|
|
26
|
+
);
|
|
27
|
+
await r.run({
|
|
28
|
+
code: `<?php
|
|
29
|
+
require_once( '${s}' );
|
|
30
|
+
switch_theme( '${e}' );
|
|
31
|
+
`
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
function S(r) {
|
|
2
35
|
return new DOMParser().parseFromString(r.text, "text/html");
|
|
3
36
|
}
|
|
4
37
|
function E(r) {
|
|
@@ -9,30 +42,18 @@ async function g(r, e, t) {
|
|
|
9
42
|
let s = "";
|
|
10
43
|
await r.fileExists(e) && (s = await r.readFileAsText(e)), await r.writeFile(e, t(s));
|
|
11
44
|
}
|
|
12
|
-
async function
|
|
45
|
+
async function ce(r) {
|
|
13
46
|
return new Uint8Array(await r.arrayBuffer());
|
|
14
47
|
}
|
|
15
|
-
const
|
|
16
|
-
t
|
|
17
|
-
const i = b(
|
|
18
|
-
await r.request({
|
|
19
|
-
url: "/wp-admin/plugins.php"
|
|
20
|
-
})
|
|
21
|
-
).querySelector(
|
|
22
|
-
`tr[data-slug="${e}"] a`
|
|
23
|
-
).attributes.getNamedItem("href").value;
|
|
24
|
-
await r.request({
|
|
25
|
-
url: "/wp-admin/" + i
|
|
26
|
-
});
|
|
27
|
-
}, ce = async (r, e) => {
|
|
28
|
-
const t = new le(
|
|
48
|
+
const A = "/vfs-blueprints", O = "/vfs-blueprints/wp-config-consts.php", le = async (r, e) => {
|
|
49
|
+
const t = new ue(
|
|
29
50
|
r,
|
|
30
51
|
e.siteUrl,
|
|
31
52
|
e.wordpressPath || "/wordpress"
|
|
32
53
|
);
|
|
33
54
|
e.patchSqlitePlugin !== !1 && await t.patchSqlitePlugin(), e.addPhpInfo !== !1 && await t.addPhpInfo(), e.patchSiteUrl !== !1 && await t.patchSiteUrl(), e.disableSiteHealth !== !1 && await t.disableSiteHealth(), e.disableWpNewBlogNotification !== !1 && await t.disableWpNewBlogNotification();
|
|
34
55
|
};
|
|
35
|
-
class
|
|
56
|
+
class ue {
|
|
36
57
|
constructor(e, t, s) {
|
|
37
58
|
this.php = e, this.scopedSiteUrl = t, this.wordpressPath = s;
|
|
38
59
|
}
|
|
@@ -83,23 +104,23 @@ class le {
|
|
|
83
104
|
);
|
|
84
105
|
}
|
|
85
106
|
}
|
|
86
|
-
const
|
|
107
|
+
const he = async (r, { code: e }) => await r.run({ code: e }), pe = async (r, { options: e }) => await r.run(e), de = async (r, { key: e, value: t }) => {
|
|
87
108
|
await r.setPhpIniEntry(e, t);
|
|
88
|
-
},
|
|
109
|
+
}, fe = async (r, { request: e }) => await r.request(e), me = async (r, { fromPath: e, toPath: t }) => {
|
|
89
110
|
await r.writeFile(
|
|
90
111
|
t,
|
|
91
112
|
await r.readFileAsBuffer(e)
|
|
92
113
|
);
|
|
93
|
-
},
|
|
114
|
+
}, we = async (r, { fromPath: e, toPath: t }) => {
|
|
94
115
|
await r.mv(e, t);
|
|
95
|
-
}, we = async (r, { path: e }) => {
|
|
96
|
-
await r.mkdir(e);
|
|
97
116
|
}, ge = async (r, { path: e }) => {
|
|
98
|
-
await r.
|
|
117
|
+
await r.mkdir(e);
|
|
99
118
|
}, ye = async (r, { path: e }) => {
|
|
119
|
+
await r.unlink(e);
|
|
120
|
+
}, Pe = async (r, { path: e }) => {
|
|
100
121
|
await r.rmdir(e);
|
|
101
|
-
},
|
|
102
|
-
t instanceof File && (t = await
|
|
122
|
+
}, _e = async (r, { path: e, data: t }) => {
|
|
123
|
+
t instanceof File && (t = await ce(t)), await r.writeFile(e, t);
|
|
103
124
|
}, K = async (r, { consts: e }) => {
|
|
104
125
|
const t = await r.documentRoot;
|
|
105
126
|
await g(
|
|
@@ -121,7 +142,7 @@ const ue = async (r, { code: e }) => await r.run({ code: e }), he = async (r, {
|
|
|
121
142
|
}
|
|
122
143
|
?>${s}`
|
|
123
144
|
);
|
|
124
|
-
},
|
|
145
|
+
}, $e = async (r, { siteUrl: e }) => await K(r, {
|
|
125
146
|
consts: {
|
|
126
147
|
WP_HOME: e,
|
|
127
148
|
WP_SITEURL: e
|
|
@@ -153,25 +174,25 @@ class Y {
|
|
|
153
174
|
}
|
|
154
175
|
}
|
|
155
176
|
const be = Symbol("literal");
|
|
156
|
-
function
|
|
177
|
+
function $(r) {
|
|
157
178
|
if (typeof r == "string")
|
|
158
179
|
return r.startsWith("$") ? r : JSON.stringify(r);
|
|
159
180
|
if (typeof r == "number")
|
|
160
181
|
return r.toString();
|
|
161
182
|
if (Array.isArray(r))
|
|
162
|
-
return `array(${r.map(
|
|
183
|
+
return `array(${r.map($).join(", ")})`;
|
|
163
184
|
if (r === null)
|
|
164
185
|
return "null";
|
|
165
186
|
if (typeof r == "object")
|
|
166
|
-
return be in r ? r.toString() : `array(${Object.entries(r).map(([t, s]) => `${JSON.stringify(t)} => ${
|
|
187
|
+
return be in r ? r.toString() : `array(${Object.entries(r).map(([t, s]) => `${JSON.stringify(t)} => ${$(s)}`).join(", ")})`;
|
|
167
188
|
if (typeof r == "function")
|
|
168
189
|
return r();
|
|
169
190
|
throw new Error(`Unsupported value: ${r}`);
|
|
170
191
|
}
|
|
171
|
-
function
|
|
192
|
+
function T(r) {
|
|
172
193
|
const e = {};
|
|
173
194
|
for (const t in r)
|
|
174
|
-
e[t] =
|
|
195
|
+
e[t] = $(r[t]);
|
|
175
196
|
return e;
|
|
176
197
|
}
|
|
177
198
|
const I = `<?php
|
|
@@ -237,8 +258,8 @@ function delTree($dir)
|
|
|
237
258
|
return rmdir($dir);
|
|
238
259
|
}
|
|
239
260
|
`;
|
|
240
|
-
async function
|
|
241
|
-
const e = "wordpress-playground.zip", t = `/${e}`, s =
|
|
261
|
+
async function ve(r) {
|
|
262
|
+
const e = "wordpress-playground.zip", t = `/${e}`, s = T({
|
|
242
263
|
zipPath: t,
|
|
243
264
|
documentRoot: await r.documentRoot
|
|
244
265
|
});
|
|
@@ -249,7 +270,7 @@ async function $e(r) {
|
|
|
249
270
|
const n = await r.readFileAsBuffer(t);
|
|
250
271
|
return r.unlink(t), new File([n], e);
|
|
251
272
|
}
|
|
252
|
-
const
|
|
273
|
+
const Se = async (r, { fullSiteZip: e }) => {
|
|
253
274
|
const t = "/import.zip";
|
|
254
275
|
await r.writeFile(
|
|
255
276
|
t,
|
|
@@ -257,7 +278,7 @@ const ve = async (r, { fullSiteZip: e }) => {
|
|
|
257
278
|
);
|
|
258
279
|
const s = await r.absoluteUrl, n = await r.documentRoot;
|
|
259
280
|
await r.rmdir(n), await Z(r, { zipPath: t, extractToPath: "/" });
|
|
260
|
-
const i =
|
|
281
|
+
const i = T({ absoluteUrl: s });
|
|
261
282
|
await Re(
|
|
262
283
|
r,
|
|
263
284
|
`${n}/wp-config.php`,
|
|
@@ -269,7 +290,7 @@ const ve = async (r, { fullSiteZip: e }) => {
|
|
|
269
290
|
?>${o}`
|
|
270
291
|
);
|
|
271
292
|
}, Z = async (r, { zipPath: e, extractToPath: t }) => {
|
|
272
|
-
const s =
|
|
293
|
+
const s = T({
|
|
273
294
|
zipPath: e,
|
|
274
295
|
extractToPath: t
|
|
275
296
|
});
|
|
@@ -277,7 +298,7 @@ const ve = async (r, { fullSiteZip: e }) => {
|
|
|
277
298
|
r,
|
|
278
299
|
`unzip(${s.zipPath}, ${s.extractToPath});`
|
|
279
300
|
);
|
|
280
|
-
},
|
|
301
|
+
}, Ee = async (r, { file: e }) => {
|
|
281
302
|
const t = await r.request({
|
|
282
303
|
url: "/wp-admin/admin.php?import=wordpress"
|
|
283
304
|
}), s = L(t).getElementById("import-upload-form")?.getAttribute("action"), n = await r.request({
|
|
@@ -291,7 +312,7 @@ const ve = async (r, { fullSiteZip: e }) => {
|
|
|
291
312
|
throw console.log(n.text), new Error(
|
|
292
313
|
"Could not find an importer form in response. See the response text above for details."
|
|
293
314
|
);
|
|
294
|
-
const o =
|
|
315
|
+
const o = xe(i);
|
|
295
316
|
o.fetch_attachments = "1";
|
|
296
317
|
for (const a in o)
|
|
297
318
|
if (a.startsWith("user_map[")) {
|
|
@@ -307,7 +328,7 @@ const ve = async (r, { fullSiteZip: e }) => {
|
|
|
307
328
|
function L(r) {
|
|
308
329
|
return new DOMParser().parseFromString(r.text, "text/html");
|
|
309
330
|
}
|
|
310
|
-
function
|
|
331
|
+
function xe(r) {
|
|
311
332
|
return Object.fromEntries(new FormData(r).entries());
|
|
312
333
|
}
|
|
313
334
|
async function Re(r, e, t) {
|
|
@@ -331,23 +352,23 @@ const Te = async (r, { pluginZipFile: e, options: t = {} }, s) => {
|
|
|
331
352
|
try {
|
|
332
353
|
const n = "activate" in t ? t.activate : !0, i = await r.request({
|
|
333
354
|
url: "/wp-admin/plugin-install.php?tab=upload"
|
|
334
|
-
}), o =
|
|
355
|
+
}), o = S(i), a = new FormData(
|
|
335
356
|
o.querySelector(".wp-upload-form")
|
|
336
|
-
), { pluginzip: c, ...
|
|
357
|
+
), { pluginzip: c, ...l } = Object.fromEntries(
|
|
337
358
|
a.entries()
|
|
338
359
|
), h = await r.request({
|
|
339
360
|
url: "/wp-admin/update.php?action=upload-plugin",
|
|
340
361
|
method: "POST",
|
|
341
|
-
formData:
|
|
362
|
+
formData: l,
|
|
342
363
|
files: { pluginzip: e }
|
|
343
364
|
});
|
|
344
365
|
if (n) {
|
|
345
|
-
const
|
|
346
|
-
|
|
366
|
+
const b = S(h).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value, v = new URL(
|
|
367
|
+
b,
|
|
347
368
|
await r.pathToInternalUrl("/wp-admin/")
|
|
348
369
|
).toString();
|
|
349
370
|
await r.request({
|
|
350
|
-
url:
|
|
371
|
+
url: v
|
|
351
372
|
});
|
|
352
373
|
}
|
|
353
374
|
await r.isDir(
|
|
@@ -379,41 +400,41 @@ async function H(r, e, t) {
|
|
|
379
400
|
t(await r.readFileAsText(e))
|
|
380
401
|
);
|
|
381
402
|
}
|
|
382
|
-
const
|
|
403
|
+
const Fe = async (r, { themeZipFile: e, options: t = {} }, s) => {
|
|
383
404
|
s?.tracker.setCaption(
|
|
384
405
|
`Installing the ${E(e.name)} theme`
|
|
385
406
|
);
|
|
386
407
|
try {
|
|
387
408
|
const n = "activate" in t ? t.activate : !0, i = await r.request({
|
|
388
409
|
url: "/wp-admin/theme-install.php"
|
|
389
|
-
}), o =
|
|
410
|
+
}), o = S(i), a = new FormData(
|
|
390
411
|
o.querySelector(".wp-upload-form")
|
|
391
|
-
), { themezip: c, ...
|
|
412
|
+
), { themezip: c, ...l } = Object.fromEntries(
|
|
392
413
|
a.entries()
|
|
393
414
|
), h = await r.request({
|
|
394
415
|
url: "/wp-admin/update.php?action=upload-theme",
|
|
395
416
|
method: "POST",
|
|
396
|
-
formData:
|
|
417
|
+
formData: l,
|
|
397
418
|
files: { themezip: e }
|
|
398
419
|
});
|
|
399
420
|
if (n) {
|
|
400
|
-
const d =
|
|
421
|
+
const d = S(h), b = d.querySelector(
|
|
401
422
|
"#wpbody-content > .wrap"
|
|
402
423
|
);
|
|
403
|
-
if (
|
|
424
|
+
if (b?.textContent?.includes(
|
|
404
425
|
"Theme installation failed."
|
|
405
426
|
)) {
|
|
406
|
-
console.error(
|
|
427
|
+
console.error(b?.textContent);
|
|
407
428
|
return;
|
|
408
429
|
}
|
|
409
|
-
const
|
|
430
|
+
const v = d.querySelector(
|
|
410
431
|
"#wpbody-content .activatelink, .update-from-upload-actions .button.button-primary"
|
|
411
432
|
);
|
|
412
|
-
if (!
|
|
433
|
+
if (!v) {
|
|
413
434
|
console.error('The "activate" button was not found.');
|
|
414
435
|
return;
|
|
415
436
|
}
|
|
416
|
-
const ne =
|
|
437
|
+
const ne = v.attributes.getNamedItem("href").value, ie = new URL(
|
|
417
438
|
ne,
|
|
418
439
|
await r.pathToInternalUrl("/wp-admin/")
|
|
419
440
|
).toString();
|
|
@@ -426,7 +447,7 @@ const xe = async (r, { themeZipFile: e, options: t = {} }, s) => {
|
|
|
426
447
|
`Proceeding without the ${e.name} theme. Could not install it in wp-admin. The original error was: ${n}`
|
|
427
448
|
), console.error(n);
|
|
428
449
|
}
|
|
429
|
-
},
|
|
450
|
+
}, Ce = async (r, { username: e = "admin", password: t = "password" } = {}, s) => {
|
|
430
451
|
s?.tracker.setCaption(s?.initialCaption || "Logging in"), await r.request({
|
|
431
452
|
url: "/wp-login.php"
|
|
432
453
|
}), await r.request({
|
|
@@ -455,10 +476,10 @@ const xe = async (r, { themeZipFile: e, options: t = {} }, s) => {
|
|
|
455
476
|
admin_email: "admin@localhost.com"
|
|
456
477
|
}
|
|
457
478
|
});
|
|
458
|
-
},
|
|
479
|
+
}, Ue = async (r, { options: e }) => {
|
|
459
480
|
const t = `<?php
|
|
460
481
|
include 'wordpress/wp-load.php';
|
|
461
|
-
$site_options = ${
|
|
482
|
+
$site_options = ${$(e)};
|
|
462
483
|
foreach($site_options as $name => $value) {
|
|
463
484
|
update_option($name, $value);
|
|
464
485
|
}
|
|
@@ -467,12 +488,12 @@ const xe = async (r, { themeZipFile: e, options: t = {} }, s) => {
|
|
|
467
488
|
code: t
|
|
468
489
|
});
|
|
469
490
|
return X(s), { code: t, result: s };
|
|
470
|
-
},
|
|
491
|
+
}, Ae = async (r, { meta: e, userId: t }) => {
|
|
471
492
|
const s = `<?php
|
|
472
493
|
include 'wordpress/wp-load.php';
|
|
473
|
-
$meta = ${
|
|
494
|
+
$meta = ${$(e)};
|
|
474
495
|
foreach($meta as $name => $value) {
|
|
475
|
-
update_user_meta(${
|
|
496
|
+
update_user_meta(${$(t)}, $name, $value);
|
|
476
497
|
}
|
|
477
498
|
echo "Success";
|
|
478
499
|
`, n = await r.run({
|
|
@@ -485,8 +506,8 @@ async function X(r) {
|
|
|
485
506
|
throw console.log(r), new Error(`Failed to run code: ${r.text} ${r.errors}`);
|
|
486
507
|
}
|
|
487
508
|
const Oe = async (r, { consts: e }) => {
|
|
488
|
-
r.mkdir(
|
|
489
|
-
const t = `${
|
|
509
|
+
r.mkdir(A);
|
|
510
|
+
const t = `${A}/playground-consts.json`;
|
|
490
511
|
return await g(
|
|
491
512
|
r,
|
|
492
513
|
t,
|
|
@@ -494,44 +515,45 @@ const Oe = async (r, { consts: e }) => {
|
|
|
494
515
|
...JSON.parse(s || "{}"),
|
|
495
516
|
...e
|
|
496
517
|
})
|
|
497
|
-
), await g(r,
|
|
518
|
+
), await g(r, O, (s) => s.includes("playground-consts.json") ? s : `<?php
|
|
498
519
|
$consts = json_decode(file_get_contents('${t}'), true);
|
|
499
520
|
foreach ($consts as $const => $value) {
|
|
500
521
|
if (!defined($const)) {
|
|
501
522
|
define($const, $value);
|
|
502
523
|
}
|
|
503
524
|
}
|
|
504
|
-
?>${s}`),
|
|
505
|
-
},
|
|
525
|
+
?>${s}`), O;
|
|
526
|
+
}, Ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
506
527
|
__proto__: null,
|
|
507
|
-
activatePlugin:
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
528
|
+
activatePlugin: oe,
|
|
529
|
+
activateTheme: ae,
|
|
530
|
+
applyWordPressPatches: le,
|
|
531
|
+
cp: me,
|
|
532
|
+
defineSiteUrl: $e,
|
|
511
533
|
defineVirtualWpConfigConsts: Oe,
|
|
512
534
|
defineWpConfigConsts: K,
|
|
513
|
-
importFile:
|
|
535
|
+
importFile: Ee,
|
|
514
536
|
installPlugin: Te,
|
|
515
|
-
installTheme:
|
|
516
|
-
login:
|
|
517
|
-
mkdir:
|
|
518
|
-
mv:
|
|
519
|
-
replaceSite:
|
|
520
|
-
request:
|
|
521
|
-
rm:
|
|
522
|
-
rmdir:
|
|
523
|
-
runPHP:
|
|
524
|
-
runPHPWithOptions:
|
|
537
|
+
installTheme: Fe,
|
|
538
|
+
login: Ce,
|
|
539
|
+
mkdir: ge,
|
|
540
|
+
mv: we,
|
|
541
|
+
replaceSite: Se,
|
|
542
|
+
request: fe,
|
|
543
|
+
rm: ye,
|
|
544
|
+
rmdir: Pe,
|
|
545
|
+
runPHP: he,
|
|
546
|
+
runPHPWithOptions: pe,
|
|
525
547
|
runWpInstallationWizard: ke,
|
|
526
|
-
setPhpIniEntry:
|
|
527
|
-
setSiteOptions:
|
|
548
|
+
setPhpIniEntry: de,
|
|
549
|
+
setSiteOptions: Ue,
|
|
528
550
|
unzip: Z,
|
|
529
|
-
updateUserMeta:
|
|
530
|
-
writeFile:
|
|
531
|
-
zipEntireSite:
|
|
532
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
533
|
-
function
|
|
534
|
-
const t = r.headers.get("content-length") || "", s = parseInt(t, 10) ||
|
|
551
|
+
updateUserMeta: Ae,
|
|
552
|
+
writeFile: _e,
|
|
553
|
+
zipEntireSite: ve
|
|
554
|
+
}, Symbol.toStringTag, { value: "Module" })), Le = 5 * 1024 * 1024;
|
|
555
|
+
function He(r, e) {
|
|
556
|
+
const t = r.headers.get("content-length") || "", s = parseInt(t, 10) || Le;
|
|
535
557
|
function n(i, o) {
|
|
536
558
|
e(
|
|
537
559
|
new CustomEvent("progress", {
|
|
@@ -553,12 +575,12 @@ function Le(r, e) {
|
|
|
553
575
|
let a = 0;
|
|
554
576
|
for (; ; )
|
|
555
577
|
try {
|
|
556
|
-
const { done: c, value:
|
|
557
|
-
if (
|
|
578
|
+
const { done: c, value: l } = await o.read();
|
|
579
|
+
if (l && (a += l.byteLength), c) {
|
|
558
580
|
n(a, a), i.close();
|
|
559
581
|
break;
|
|
560
582
|
} else
|
|
561
|
-
n(a, s), i.enqueue(
|
|
583
|
+
n(a, s), i.enqueue(l);
|
|
562
584
|
} catch (c) {
|
|
563
585
|
console.error({ e: c }), i.error(c);
|
|
564
586
|
break;
|
|
@@ -572,7 +594,7 @@ function Le(r, e) {
|
|
|
572
594
|
}
|
|
573
595
|
);
|
|
574
596
|
}
|
|
575
|
-
const
|
|
597
|
+
const x = 1e-5;
|
|
576
598
|
class F extends EventTarget {
|
|
577
599
|
constructor({
|
|
578
600
|
weight: e = 1,
|
|
@@ -617,7 +639,7 @@ class F extends EventTarget {
|
|
|
617
639
|
* ```
|
|
618
640
|
*/
|
|
619
641
|
stage(e, t = "") {
|
|
620
|
-
if (e || (e = this._selfWeight), this._selfWeight - e < -
|
|
642
|
+
if (e || (e = this._selfWeight), this._selfWeight - e < -x)
|
|
621
643
|
throw new Error(
|
|
622
644
|
`Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`
|
|
623
645
|
);
|
|
@@ -659,7 +681,7 @@ class F extends EventTarget {
|
|
|
659
681
|
}, s);
|
|
660
682
|
}
|
|
661
683
|
set(e) {
|
|
662
|
-
this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress +
|
|
684
|
+
this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + x >= 100 && this.finish();
|
|
663
685
|
}
|
|
664
686
|
finish() {
|
|
665
687
|
this._fillInterval && clearInterval(this._fillInterval), this._selfDone = !0, this._selfProgress = 100, this._isFilling = !1, this._fillInterval = void 0, this.notifyProgress(), this.notifyDone();
|
|
@@ -677,7 +699,7 @@ class F extends EventTarget {
|
|
|
677
699
|
this._selfCaption = e, this.notifyProgress();
|
|
678
700
|
}
|
|
679
701
|
get done() {
|
|
680
|
-
return this.progress +
|
|
702
|
+
return this.progress + x >= 100;
|
|
681
703
|
}
|
|
682
704
|
get progress() {
|
|
683
705
|
if (this._selfDone)
|
|
@@ -740,7 +762,7 @@ class F extends EventTarget {
|
|
|
740
762
|
}
|
|
741
763
|
}
|
|
742
764
|
const N = Symbol("error"), q = Symbol("message");
|
|
743
|
-
class
|
|
765
|
+
class C extends Event {
|
|
744
766
|
/**
|
|
745
767
|
* Create a new `ErrorEvent`.
|
|
746
768
|
*
|
|
@@ -758,10 +780,10 @@ class k extends Event {
|
|
|
758
780
|
return this[q];
|
|
759
781
|
}
|
|
760
782
|
}
|
|
761
|
-
Object.defineProperty(
|
|
762
|
-
Object.defineProperty(
|
|
763
|
-
const
|
|
764
|
-
class
|
|
783
|
+
Object.defineProperty(C.prototype, "error", { enumerable: !0 });
|
|
784
|
+
Object.defineProperty(C.prototype, "message", { enumerable: !0 });
|
|
785
|
+
const Ne = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : C;
|
|
786
|
+
class qe extends EventTarget {
|
|
765
787
|
constructor() {
|
|
766
788
|
super(...arguments), this.listenersCount = 0;
|
|
767
789
|
}
|
|
@@ -775,11 +797,11 @@ class Ne extends EventTarget {
|
|
|
775
797
|
return this.listenersCount > 0;
|
|
776
798
|
}
|
|
777
799
|
}
|
|
778
|
-
function
|
|
800
|
+
function We(r) {
|
|
779
801
|
r.asm = {
|
|
780
802
|
...r.asm
|
|
781
803
|
};
|
|
782
|
-
const e = new
|
|
804
|
+
const e = new qe();
|
|
783
805
|
for (const t in r.asm)
|
|
784
806
|
if (typeof r.asm[t] == "function") {
|
|
785
807
|
const s = r.asm[t];
|
|
@@ -791,14 +813,14 @@ function qe(r) {
|
|
|
791
813
|
throw i;
|
|
792
814
|
if ("exitCode" in i && i?.exitCode === 0)
|
|
793
815
|
return;
|
|
794
|
-
const o =
|
|
816
|
+
const o = Me(
|
|
795
817
|
i,
|
|
796
818
|
r.lastAsyncifyStackSource?.stack
|
|
797
819
|
);
|
|
798
820
|
if (r.lastAsyncifyStackSource && (i.cause = r.lastAsyncifyStackSource), !e.hasListeners())
|
|
799
|
-
throw
|
|
821
|
+
throw Be(o), i;
|
|
800
822
|
e.dispatchEvent(
|
|
801
|
-
new
|
|
823
|
+
new Ne("error", {
|
|
802
824
|
error: i,
|
|
803
825
|
message: o
|
|
804
826
|
})
|
|
@@ -808,29 +830,29 @@ function qe(r) {
|
|
|
808
830
|
}
|
|
809
831
|
return e;
|
|
810
832
|
}
|
|
811
|
-
let
|
|
833
|
+
let R = [];
|
|
812
834
|
function De() {
|
|
813
|
-
return
|
|
835
|
+
return R;
|
|
814
836
|
}
|
|
815
|
-
function
|
|
837
|
+
function Me(r, e) {
|
|
816
838
|
if (r.message === "unreachable") {
|
|
817
|
-
let t =
|
|
839
|
+
let t = je;
|
|
818
840
|
e || (t += `
|
|
819
841
|
|
|
820
842
|
This stack trace is lacking. For a better one initialize
|
|
821
843
|
the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
|
|
822
844
|
|
|
823
|
-
`),
|
|
845
|
+
`), R = Ge(
|
|
824
846
|
e || r.stack || ""
|
|
825
847
|
);
|
|
826
|
-
for (const s of
|
|
848
|
+
for (const s of R)
|
|
827
849
|
t += ` * ${s}
|
|
828
850
|
`;
|
|
829
851
|
return t;
|
|
830
852
|
}
|
|
831
853
|
return r.message;
|
|
832
854
|
}
|
|
833
|
-
const
|
|
855
|
+
const je = `
|
|
834
856
|
"unreachable" WASM instruction executed.
|
|
835
857
|
|
|
836
858
|
The typical reason is a PHP function missing from the ASYNCIFY_ONLY
|
|
@@ -854,20 +876,20 @@ the Dockerfile, you'll need to trigger this error again with long stack
|
|
|
854
876
|
traces enabled. In node.js, you can do it using the --stack-trace-limit=100
|
|
855
877
|
CLI option:
|
|
856
878
|
|
|
857
|
-
`,
|
|
879
|
+
`, W = "\x1B[41m", ze = "\x1B[1m", D = "\x1B[0m", M = "\x1B[K";
|
|
858
880
|
let j = !1;
|
|
859
|
-
function
|
|
881
|
+
function Be(r) {
|
|
860
882
|
if (!j) {
|
|
861
|
-
j = !0, console.log(`${
|
|
883
|
+
j = !0, console.log(`${W}
|
|
862
884
|
${M}
|
|
863
|
-
${
|
|
885
|
+
${ze} WASM ERROR${D}${W}`);
|
|
864
886
|
for (const e of r.split(`
|
|
865
887
|
`))
|
|
866
888
|
console.log(`${M} ${e} `);
|
|
867
|
-
console.log(`${
|
|
889
|
+
console.log(`${D}`);
|
|
868
890
|
}
|
|
869
891
|
}
|
|
870
|
-
function
|
|
892
|
+
function Ge(r) {
|
|
871
893
|
try {
|
|
872
894
|
const e = r.split(`
|
|
873
895
|
`).slice(1).map((t) => {
|
|
@@ -884,12 +906,12 @@ function Be(r) {
|
|
|
884
906
|
return [];
|
|
885
907
|
}
|
|
886
908
|
}
|
|
887
|
-
class
|
|
909
|
+
class _ {
|
|
888
910
|
constructor(e, t, s, n = "", i = 0) {
|
|
889
911
|
this.httpStatusCode = e, this.headers = t, this.bytes = s, this.exitCode = i, this.errors = n;
|
|
890
912
|
}
|
|
891
913
|
static fromRawData(e) {
|
|
892
|
-
return new
|
|
914
|
+
return new _(
|
|
893
915
|
e.httpStatusCode,
|
|
894
916
|
e.headers,
|
|
895
917
|
e.bytes,
|
|
@@ -929,8 +951,8 @@ const ee = [
|
|
|
929
951
|
"7.1",
|
|
930
952
|
"7.0",
|
|
931
953
|
"5.6"
|
|
932
|
-
],
|
|
933
|
-
class
|
|
954
|
+
], Ve = ee[0];
|
|
955
|
+
class Je {
|
|
934
956
|
#e;
|
|
935
957
|
#t;
|
|
936
958
|
/**
|
|
@@ -1016,17 +1038,17 @@ class Ve {
|
|
|
1016
1038
|
return e.join("; ");
|
|
1017
1039
|
}
|
|
1018
1040
|
}
|
|
1019
|
-
const
|
|
1041
|
+
const Ke = "http://example.com";
|
|
1020
1042
|
function z(r) {
|
|
1021
1043
|
return r.toString().substring(r.origin.length);
|
|
1022
1044
|
}
|
|
1023
1045
|
function B(r, e) {
|
|
1024
1046
|
return !e || !r.startsWith(e) ? r : r.substring(e.length);
|
|
1025
1047
|
}
|
|
1026
|
-
function
|
|
1048
|
+
function Ye(r, e) {
|
|
1027
1049
|
return !e || r.startsWith(e) ? r : e + r;
|
|
1028
1050
|
}
|
|
1029
|
-
class
|
|
1051
|
+
class Ze {
|
|
1030
1052
|
#e;
|
|
1031
1053
|
#t;
|
|
1032
1054
|
#s;
|
|
@@ -1084,7 +1106,7 @@ class Ye {
|
|
|
1084
1106
|
async request(e) {
|
|
1085
1107
|
const t = e.url.startsWith("http://") || e.url.startsWith("https://"), s = new URL(
|
|
1086
1108
|
e.url,
|
|
1087
|
-
t ? void 0 :
|
|
1109
|
+
t ? void 0 : Ke
|
|
1088
1110
|
), n = B(
|
|
1089
1111
|
s.pathname,
|
|
1090
1112
|
this.#n
|
|
@@ -1100,20 +1122,20 @@ class Ye {
|
|
|
1100
1122
|
#l(e) {
|
|
1101
1123
|
const t = `${this.#e}${e}`;
|
|
1102
1124
|
if (!this.php.fileExists(t))
|
|
1103
|
-
return new
|
|
1125
|
+
return new _(
|
|
1104
1126
|
404,
|
|
1105
1127
|
{},
|
|
1106
1128
|
new TextEncoder().encode("404 File not found")
|
|
1107
1129
|
);
|
|
1108
1130
|
const s = this.php.readFileAsBuffer(t);
|
|
1109
|
-
return new
|
|
1131
|
+
return new _(
|
|
1110
1132
|
200,
|
|
1111
1133
|
{
|
|
1112
1134
|
"content-length": [`${s.byteLength}`],
|
|
1113
1135
|
// @TODO: Infer the content-type from the arrayBuffer instead of the file path.
|
|
1114
1136
|
// The code below won't return the correct mime-type if the extension
|
|
1115
1137
|
// was tampered with.
|
|
1116
|
-
"content-type": [
|
|
1138
|
+
"content-type": [Xe(t)],
|
|
1117
1139
|
"accept-ranges": ["bytes"],
|
|
1118
1140
|
"cache-control": ["public, max-age=0"]
|
|
1119
1141
|
},
|
|
@@ -1141,24 +1163,35 @@ class Ye {
|
|
|
1141
1163
|
}, o = [];
|
|
1142
1164
|
if (e.files && Object.keys(e.files).length) {
|
|
1143
1165
|
n = "POST";
|
|
1144
|
-
for (const
|
|
1145
|
-
const
|
|
1166
|
+
for (const l in e.files) {
|
|
1167
|
+
const h = e.files[l];
|
|
1146
1168
|
o.push({
|
|
1147
|
-
key:
|
|
1148
|
-
name:
|
|
1149
|
-
type:
|
|
1150
|
-
data: new Uint8Array(await
|
|
1169
|
+
key: l,
|
|
1170
|
+
name: h.name,
|
|
1171
|
+
type: h.type,
|
|
1172
|
+
data: new Uint8Array(await h.arrayBuffer())
|
|
1151
1173
|
});
|
|
1152
1174
|
}
|
|
1153
|
-
i["content-type"]?.startsWith("multipart/form-data") && (e.formData =
|
|
1175
|
+
i["content-type"]?.startsWith("multipart/form-data") && (e.formData = Qe(
|
|
1154
1176
|
e.body || ""
|
|
1155
1177
|
), i["content-type"] = "application/x-www-form-urlencoded", delete e.body);
|
|
1156
1178
|
}
|
|
1157
1179
|
let a;
|
|
1158
|
-
|
|
1180
|
+
e.formData !== void 0 ? (n = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
|
|
1159
1181
|
e.formData
|
|
1160
|
-
).toString()) : a = e.body
|
|
1161
|
-
|
|
1182
|
+
).toString()) : a = e.body;
|
|
1183
|
+
let c;
|
|
1184
|
+
try {
|
|
1185
|
+
c = this.#h(t.pathname);
|
|
1186
|
+
} catch {
|
|
1187
|
+
return new _(
|
|
1188
|
+
404,
|
|
1189
|
+
{},
|
|
1190
|
+
new TextEncoder().encode("404 File not found")
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
return await this.php.run({
|
|
1194
|
+
relativeUri: Ye(
|
|
1162
1195
|
z(t),
|
|
1163
1196
|
this.#n
|
|
1164
1197
|
),
|
|
@@ -1166,7 +1199,7 @@ class Ye {
|
|
|
1166
1199
|
method: e.method || n,
|
|
1167
1200
|
body: a,
|
|
1168
1201
|
fileInfos: o,
|
|
1169
|
-
scriptPath:
|
|
1202
|
+
scriptPath: c,
|
|
1170
1203
|
headers: i
|
|
1171
1204
|
});
|
|
1172
1205
|
} finally {
|
|
@@ -1179,16 +1212,21 @@ class Ye {
|
|
|
1179
1212
|
* Fall back to index.php as if there was a url rewriting rule in place.
|
|
1180
1213
|
*
|
|
1181
1214
|
* @param requestedPath - The requested pathname.
|
|
1215
|
+
* @throws {Error} If the requested path doesn't exist.
|
|
1182
1216
|
* @returns The resolved filesystem path.
|
|
1183
1217
|
*/
|
|
1184
1218
|
#h(e) {
|
|
1185
1219
|
let t = B(e, this.#n);
|
|
1186
1220
|
t.includes(".php") ? t = t.split(".php")[0] + ".php" : (t.endsWith("/") || (t += "/"), t.endsWith("index.php") || (t += "index.php"));
|
|
1187
1221
|
const s = `${this.#e}${t}`;
|
|
1188
|
-
|
|
1222
|
+
if (this.php.fileExists(s))
|
|
1223
|
+
return s;
|
|
1224
|
+
if (!this.php.fileExists(`${this.#e}/index.php`))
|
|
1225
|
+
throw new Error(`File not found: ${s}`);
|
|
1226
|
+
return `${this.#e}/index.php`;
|
|
1189
1227
|
}
|
|
1190
1228
|
}
|
|
1191
|
-
function
|
|
1229
|
+
function Qe(r) {
|
|
1192
1230
|
const e = {}, t = r.match(/--(.*)\r\n/);
|
|
1193
1231
|
if (!t)
|
|
1194
1232
|
return e;
|
|
@@ -1196,14 +1234,14 @@ function Ze(r) {
|
|
|
1196
1234
|
return n.shift(), n.pop(), n.forEach((i) => {
|
|
1197
1235
|
const o = i.indexOf(`\r
|
|
1198
1236
|
\r
|
|
1199
|
-
`), a = i.substring(0, o).trim(), c = i.substring(o + 4).trim(),
|
|
1200
|
-
if (
|
|
1201
|
-
const h =
|
|
1237
|
+
`), a = i.substring(0, o).trim(), c = i.substring(o + 4).trim(), l = a.match(/name="([^"]+)"/);
|
|
1238
|
+
if (l) {
|
|
1239
|
+
const h = l[1];
|
|
1202
1240
|
e[h] = c;
|
|
1203
1241
|
}
|
|
1204
1242
|
}), e;
|
|
1205
1243
|
}
|
|
1206
|
-
function
|
|
1244
|
+
function Xe(r) {
|
|
1207
1245
|
switch (r.split(".").pop()) {
|
|
1208
1246
|
case "css":
|
|
1209
1247
|
return "text/css";
|
|
@@ -1331,8 +1369,8 @@ function f(r = "") {
|
|
|
1331
1369
|
} catch (a) {
|
|
1332
1370
|
const c = typeof a == "object" ? a?.errno : null;
|
|
1333
1371
|
if (c in G) {
|
|
1334
|
-
const
|
|
1335
|
-
throw new Error(`${d}: ${
|
|
1372
|
+
const l = G[c], h = typeof o[0] == "string" ? o[0] : null, d = h !== null ? r.replaceAll("{path}", h) : r;
|
|
1373
|
+
throw new Error(`${d}: ${l}`, {
|
|
1336
1374
|
cause: a
|
|
1337
1375
|
});
|
|
1338
1376
|
}
|
|
@@ -1341,19 +1379,19 @@ function f(r = "") {
|
|
|
1341
1379
|
};
|
|
1342
1380
|
};
|
|
1343
1381
|
}
|
|
1344
|
-
const
|
|
1345
|
-
function
|
|
1346
|
-
return
|
|
1382
|
+
const et = [];
|
|
1383
|
+
function tt(r) {
|
|
1384
|
+
return et[r];
|
|
1347
1385
|
}
|
|
1348
1386
|
(function() {
|
|
1349
1387
|
return typeof process < "u" && process.release?.name === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
|
|
1350
1388
|
})();
|
|
1351
|
-
var
|
|
1352
|
-
for (var n = s > 1 ? void 0 : s ?
|
|
1389
|
+
var rt = Object.defineProperty, st = Object.getOwnPropertyDescriptor, m = (r, e, t, s) => {
|
|
1390
|
+
for (var n = s > 1 ? void 0 : s ? st(e, t) : e, i = r.length - 1, o; i >= 0; i--)
|
|
1353
1391
|
(o = r[i]) && (n = (s ? o(e, t, n) : o(n)) || n);
|
|
1354
|
-
return s && n &&
|
|
1392
|
+
return s && n && rt(e, t, n), n;
|
|
1355
1393
|
};
|
|
1356
|
-
const p = "string", P = "number",
|
|
1394
|
+
const p = "string", P = "number", u = Symbol("__private__dont__use");
|
|
1357
1395
|
class w {
|
|
1358
1396
|
/**
|
|
1359
1397
|
* Initializes a PHP runtime.
|
|
@@ -1363,8 +1401,8 @@ class w {
|
|
|
1363
1401
|
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
1364
1402
|
*/
|
|
1365
1403
|
constructor(e, t) {
|
|
1366
|
-
this.#e = [], this.#t = !1, this.#s = null, this.#r = {}, e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new
|
|
1367
|
-
new
|
|
1404
|
+
this.#e = [], this.#t = !1, this.#s = null, this.#r = {}, e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new Je(
|
|
1405
|
+
new Ze(this, t)
|
|
1368
1406
|
));
|
|
1369
1407
|
}
|
|
1370
1408
|
#e;
|
|
@@ -1390,18 +1428,18 @@ class w {
|
|
|
1390
1428
|
);
|
|
1391
1429
|
}
|
|
1392
1430
|
initializeRuntime(e) {
|
|
1393
|
-
if (this[
|
|
1431
|
+
if (this[u])
|
|
1394
1432
|
throw new Error("PHP runtime already initialized.");
|
|
1395
|
-
const t =
|
|
1433
|
+
const t = tt(e);
|
|
1396
1434
|
if (!t)
|
|
1397
1435
|
throw new Error("Invalid PHP runtime id.");
|
|
1398
|
-
this[
|
|
1436
|
+
this[u] = t, this.#s = We(t);
|
|
1399
1437
|
}
|
|
1400
1438
|
/** @inheritDoc */
|
|
1401
1439
|
setPhpIniPath(e) {
|
|
1402
1440
|
if (this.#t)
|
|
1403
1441
|
throw new Error("Cannot set PHP ini path after calling run().");
|
|
1404
|
-
this[
|
|
1442
|
+
this[u].ccall(
|
|
1405
1443
|
"wasm_set_phpini_path",
|
|
1406
1444
|
null,
|
|
1407
1445
|
["string"],
|
|
@@ -1416,7 +1454,7 @@ class w {
|
|
|
1416
1454
|
}
|
|
1417
1455
|
/** @inheritDoc */
|
|
1418
1456
|
chdir(e) {
|
|
1419
|
-
this[
|
|
1457
|
+
this[u].FS.chdir(e);
|
|
1420
1458
|
}
|
|
1421
1459
|
/** @inheritDoc */
|
|
1422
1460
|
async request(e, t) {
|
|
@@ -1442,14 +1480,14 @@ class w {
|
|
|
1442
1480
|
`) + `
|
|
1443
1481
|
|
|
1444
1482
|
`;
|
|
1445
|
-
this[
|
|
1483
|
+
this[u].ccall(
|
|
1446
1484
|
"wasm_set_phpini_entries",
|
|
1447
1485
|
null,
|
|
1448
1486
|
[p],
|
|
1449
1487
|
[e]
|
|
1450
1488
|
);
|
|
1451
1489
|
}
|
|
1452
|
-
this[
|
|
1490
|
+
this[u].ccall("php_wasm_init", null, [], []);
|
|
1453
1491
|
}
|
|
1454
1492
|
#n() {
|
|
1455
1493
|
const e = "/tmp/headers.json";
|
|
@@ -1470,14 +1508,14 @@ class w {
|
|
|
1470
1508
|
};
|
|
1471
1509
|
}
|
|
1472
1510
|
#o(e) {
|
|
1473
|
-
if (this[
|
|
1511
|
+
if (this[u].ccall(
|
|
1474
1512
|
"wasm_set_request_uri",
|
|
1475
1513
|
null,
|
|
1476
1514
|
[p],
|
|
1477
1515
|
[e]
|
|
1478
1516
|
), e.includes("?")) {
|
|
1479
1517
|
const t = e.substring(e.indexOf("?") + 1);
|
|
1480
|
-
this[
|
|
1518
|
+
this[u].ccall(
|
|
1481
1519
|
"wasm_set_query_string",
|
|
1482
1520
|
null,
|
|
1483
1521
|
[p],
|
|
@@ -1486,7 +1524,7 @@ class w {
|
|
|
1486
1524
|
}
|
|
1487
1525
|
}
|
|
1488
1526
|
#a(e, t) {
|
|
1489
|
-
this[
|
|
1527
|
+
this[u].ccall(
|
|
1490
1528
|
"wasm_set_request_host",
|
|
1491
1529
|
null,
|
|
1492
1530
|
[p],
|
|
@@ -1497,7 +1535,7 @@ class w {
|
|
|
1497
1535
|
s = parseInt(new URL(e).port, 10);
|
|
1498
1536
|
} catch {
|
|
1499
1537
|
}
|
|
1500
|
-
(!s || isNaN(s) || s === 80) && (s = t === "https" ? 443 : 80), this[
|
|
1538
|
+
(!s || isNaN(s) || s === 80) && (s = t === "https" ? 443 : 80), this[u].ccall(
|
|
1501
1539
|
"wasm_set_request_port",
|
|
1502
1540
|
null,
|
|
1503
1541
|
[P],
|
|
@@ -1505,7 +1543,7 @@ class w {
|
|
|
1505
1543
|
), (t === "https" || !t && s === 443) && this.addServerGlobalEntry("HTTPS", "on");
|
|
1506
1544
|
}
|
|
1507
1545
|
#c(e) {
|
|
1508
|
-
this[
|
|
1546
|
+
this[u].ccall(
|
|
1509
1547
|
"wasm_set_request_method",
|
|
1510
1548
|
null,
|
|
1511
1549
|
[p],
|
|
@@ -1513,17 +1551,17 @@ class w {
|
|
|
1513
1551
|
);
|
|
1514
1552
|
}
|
|
1515
1553
|
#l(e) {
|
|
1516
|
-
e.cookie && this[
|
|
1554
|
+
e.cookie && this[u].ccall(
|
|
1517
1555
|
"wasm_set_cookies",
|
|
1518
1556
|
null,
|
|
1519
1557
|
[p],
|
|
1520
1558
|
[e.cookie]
|
|
1521
|
-
), e["content-type"] && this[
|
|
1559
|
+
), e["content-type"] && this[u].ccall(
|
|
1522
1560
|
"wasm_set_content_type",
|
|
1523
1561
|
null,
|
|
1524
1562
|
[p],
|
|
1525
1563
|
[e["content-type"]]
|
|
1526
|
-
), e["content-length"] && this[
|
|
1564
|
+
), e["content-length"] && this[u].ccall(
|
|
1527
1565
|
"wasm_set_content_length",
|
|
1528
1566
|
null,
|
|
1529
1567
|
[P],
|
|
@@ -1536,12 +1574,12 @@ class w {
|
|
|
1536
1574
|
);
|
|
1537
1575
|
}
|
|
1538
1576
|
#u(e) {
|
|
1539
|
-
this[
|
|
1577
|
+
this[u].ccall(
|
|
1540
1578
|
"wasm_set_request_body",
|
|
1541
1579
|
null,
|
|
1542
1580
|
[p],
|
|
1543
1581
|
[e]
|
|
1544
|
-
), this[
|
|
1582
|
+
), this[u].ccall(
|
|
1545
1583
|
"wasm_set_content_length",
|
|
1546
1584
|
null,
|
|
1547
1585
|
[P],
|
|
@@ -1549,7 +1587,7 @@ class w {
|
|
|
1549
1587
|
);
|
|
1550
1588
|
}
|
|
1551
1589
|
#h(e) {
|
|
1552
|
-
this[
|
|
1590
|
+
this[u].ccall(
|
|
1553
1591
|
"wasm_set_path_translated",
|
|
1554
1592
|
null,
|
|
1555
1593
|
[p],
|
|
@@ -1561,7 +1599,7 @@ class w {
|
|
|
1561
1599
|
}
|
|
1562
1600
|
#p() {
|
|
1563
1601
|
for (const e in this.#r)
|
|
1564
|
-
this[
|
|
1602
|
+
this[u].ccall(
|
|
1565
1603
|
"wasm_add_SERVER_entry",
|
|
1566
1604
|
null,
|
|
1567
1605
|
[p, p],
|
|
@@ -1581,7 +1619,7 @@ class w {
|
|
|
1581
1619
|
const { key: t, name: s, type: n, data: i } = e, o = `/tmp/${Math.random().toFixed(20)}`;
|
|
1582
1620
|
this.writeFile(o, i);
|
|
1583
1621
|
const a = 0;
|
|
1584
|
-
this[
|
|
1622
|
+
this[u].ccall(
|
|
1585
1623
|
"wasm_add_uploaded_file",
|
|
1586
1624
|
null,
|
|
1587
1625
|
[p, p, p, p, P, P],
|
|
@@ -1589,7 +1627,7 @@ class w {
|
|
|
1589
1627
|
);
|
|
1590
1628
|
}
|
|
1591
1629
|
#f(e) {
|
|
1592
|
-
this[
|
|
1630
|
+
this[u].ccall(
|
|
1593
1631
|
"wasm_set_php_code",
|
|
1594
1632
|
null,
|
|
1595
1633
|
[p],
|
|
@@ -1599,36 +1637,25 @@ class w {
|
|
|
1599
1637
|
async #m() {
|
|
1600
1638
|
let e, t;
|
|
1601
1639
|
try {
|
|
1602
|
-
e = await new Promise(
|
|
1603
|
-
t = (
|
|
1604
|
-
const
|
|
1605
|
-
|
|
1640
|
+
e = await new Promise((i, o) => {
|
|
1641
|
+
t = (c) => {
|
|
1642
|
+
const l = new Error("Rethrown");
|
|
1643
|
+
l.cause = c.error, l.betterMessage = c.message, o(l);
|
|
1606
1644
|
}, this.#s?.addEventListener(
|
|
1607
1645
|
"error",
|
|
1608
1646
|
t
|
|
1609
1647
|
);
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
*/
|
|
1618
|
-
await await this[l].ccall(
|
|
1619
|
-
"wasm_sapi_handle_request",
|
|
1620
|
-
P,
|
|
1621
|
-
[],
|
|
1622
|
-
[]
|
|
1623
|
-
)
|
|
1624
|
-
);
|
|
1625
|
-
} catch (a) {
|
|
1626
|
-
o(a);
|
|
1627
|
-
}
|
|
1648
|
+
const a = this[u].ccall(
|
|
1649
|
+
"wasm_sapi_handle_request",
|
|
1650
|
+
P,
|
|
1651
|
+
[],
|
|
1652
|
+
[]
|
|
1653
|
+
);
|
|
1654
|
+
return a instanceof Promise ? a.then(i, o) : i(a);
|
|
1628
1655
|
});
|
|
1629
1656
|
} catch (i) {
|
|
1630
|
-
for (const
|
|
1631
|
-
typeof this[
|
|
1657
|
+
for (const l in this)
|
|
1658
|
+
typeof this[l] == "function" && (this[l] = () => {
|
|
1632
1659
|
throw new Error(
|
|
1633
1660
|
"PHP runtime has crashed – see the earlier error for details."
|
|
1634
1661
|
);
|
|
@@ -1640,7 +1667,7 @@ class w {
|
|
|
1640
1667
|
this.#s?.removeEventListener("error", t), this.#r = {};
|
|
1641
1668
|
}
|
|
1642
1669
|
const { headers: s, httpStatusCode: n } = this.#n();
|
|
1643
|
-
return new
|
|
1670
|
+
return new _(
|
|
1644
1671
|
n,
|
|
1645
1672
|
s,
|
|
1646
1673
|
this.readFileAsBuffer("/tmp/stdout"),
|
|
@@ -1649,7 +1676,7 @@ class w {
|
|
|
1649
1676
|
);
|
|
1650
1677
|
}
|
|
1651
1678
|
mkdir(e) {
|
|
1652
|
-
this[
|
|
1679
|
+
this[u].FS.mkdirTree(e);
|
|
1653
1680
|
}
|
|
1654
1681
|
mkdirTree(e) {
|
|
1655
1682
|
this.mkdir(e);
|
|
@@ -1658,28 +1685,28 @@ class w {
|
|
|
1658
1685
|
return new TextDecoder().decode(this.readFileAsBuffer(e));
|
|
1659
1686
|
}
|
|
1660
1687
|
readFileAsBuffer(e) {
|
|
1661
|
-
return this[
|
|
1688
|
+
return this[u].FS.readFile(e);
|
|
1662
1689
|
}
|
|
1663
1690
|
writeFile(e, t) {
|
|
1664
|
-
this[
|
|
1691
|
+
this[u].FS.writeFile(e, t);
|
|
1665
1692
|
}
|
|
1666
1693
|
unlink(e) {
|
|
1667
|
-
this[
|
|
1694
|
+
this[u].FS.unlink(e);
|
|
1668
1695
|
}
|
|
1669
1696
|
mv(e, t) {
|
|
1670
|
-
this[
|
|
1697
|
+
this[u].FS.mv(e, t);
|
|
1671
1698
|
}
|
|
1672
1699
|
rmdir(e, t = { recursive: !0 }) {
|
|
1673
1700
|
t?.recursive && this.listFiles(e).forEach((s) => {
|
|
1674
1701
|
const n = `${e}/${s}`;
|
|
1675
1702
|
this.isDir(n) ? this.rmdir(n, t) : this.unlink(n);
|
|
1676
|
-
}), this[
|
|
1703
|
+
}), this[u].FS.rmdir(e);
|
|
1677
1704
|
}
|
|
1678
1705
|
listFiles(e) {
|
|
1679
1706
|
if (!this.fileExists(e))
|
|
1680
1707
|
return [];
|
|
1681
1708
|
try {
|
|
1682
|
-
return this[
|
|
1709
|
+
return this[u].FS.readdir(e).filter(
|
|
1683
1710
|
(t) => t !== "." && t !== ".."
|
|
1684
1711
|
);
|
|
1685
1712
|
} catch (t) {
|
|
@@ -1687,13 +1714,13 @@ class w {
|
|
|
1687
1714
|
}
|
|
1688
1715
|
}
|
|
1689
1716
|
isDir(e) {
|
|
1690
|
-
return this.fileExists(e) ? this[
|
|
1691
|
-
this[
|
|
1717
|
+
return this.fileExists(e) ? this[u].FS.isDir(
|
|
1718
|
+
this[u].FS.lookupPath(e).node.mode
|
|
1692
1719
|
) : !1;
|
|
1693
1720
|
}
|
|
1694
1721
|
fileExists(e) {
|
|
1695
1722
|
try {
|
|
1696
|
-
return this[
|
|
1723
|
+
return this[u].FS.lookupPath(e), !0;
|
|
1697
1724
|
} catch {
|
|
1698
1725
|
return !1;
|
|
1699
1726
|
}
|
|
@@ -1738,15 +1765,15 @@ function te(r) {
|
|
|
1738
1765
|
e[t.toLowerCase()] = r[t];
|
|
1739
1766
|
return e;
|
|
1740
1767
|
}
|
|
1741
|
-
const
|
|
1768
|
+
const nt = [
|
|
1742
1769
|
"vfs",
|
|
1743
1770
|
"literal",
|
|
1744
1771
|
"wordpress.org/themes",
|
|
1745
1772
|
"wordpress.org/plugins",
|
|
1746
1773
|
"url"
|
|
1747
1774
|
];
|
|
1748
|
-
function
|
|
1749
|
-
return r && typeof r == "object" && typeof r.resource == "string" &&
|
|
1775
|
+
function it(r) {
|
|
1776
|
+
return r && typeof r == "object" && typeof r.resource == "string" && nt.includes(r.resource);
|
|
1750
1777
|
}
|
|
1751
1778
|
class y {
|
|
1752
1779
|
/**
|
|
@@ -1760,24 +1787,24 @@ class y {
|
|
|
1760
1787
|
let n;
|
|
1761
1788
|
switch (e.resource) {
|
|
1762
1789
|
case "vfs":
|
|
1763
|
-
n = new
|
|
1790
|
+
n = new ot(e, s);
|
|
1764
1791
|
break;
|
|
1765
1792
|
case "literal":
|
|
1766
|
-
n = new
|
|
1793
|
+
n = new at(e, s);
|
|
1767
1794
|
break;
|
|
1768
1795
|
case "wordpress.org/themes":
|
|
1769
|
-
n = new
|
|
1796
|
+
n = new ut(e, s);
|
|
1770
1797
|
break;
|
|
1771
1798
|
case "wordpress.org/plugins":
|
|
1772
|
-
n = new
|
|
1799
|
+
n = new ht(e, s);
|
|
1773
1800
|
break;
|
|
1774
1801
|
case "url":
|
|
1775
|
-
n = new
|
|
1802
|
+
n = new lt(e, s);
|
|
1776
1803
|
break;
|
|
1777
1804
|
default:
|
|
1778
1805
|
throw new Error(`Invalid resource: ${e}`);
|
|
1779
1806
|
}
|
|
1780
|
-
return n = new
|
|
1807
|
+
return n = new pt(n), t && (n = new dt(n, t)), n;
|
|
1781
1808
|
}
|
|
1782
1809
|
setPlayground(e) {
|
|
1783
1810
|
this.playground = e;
|
|
@@ -1787,7 +1814,7 @@ class y {
|
|
|
1787
1814
|
return !1;
|
|
1788
1815
|
}
|
|
1789
1816
|
}
|
|
1790
|
-
class
|
|
1817
|
+
class ot extends y {
|
|
1791
1818
|
/**
|
|
1792
1819
|
* Creates a new instance of `VFSResource`.
|
|
1793
1820
|
* @param playground The playground client.
|
|
@@ -1809,7 +1836,7 @@ class it extends y {
|
|
|
1809
1836
|
return this.resource.path;
|
|
1810
1837
|
}
|
|
1811
1838
|
}
|
|
1812
|
-
class
|
|
1839
|
+
class at extends y {
|
|
1813
1840
|
/**
|
|
1814
1841
|
* Creates a new instance of `LiteralResource`.
|
|
1815
1842
|
* @param resource The literal reference.
|
|
@@ -1827,7 +1854,7 @@ class ot extends y {
|
|
|
1827
1854
|
return this.resource.name;
|
|
1828
1855
|
}
|
|
1829
1856
|
}
|
|
1830
|
-
class
|
|
1857
|
+
class k extends y {
|
|
1831
1858
|
/**
|
|
1832
1859
|
* Creates a new instance of `FetchResource`.
|
|
1833
1860
|
* @param progress The progress tracker.
|
|
@@ -1840,9 +1867,9 @@ class C extends y {
|
|
|
1840
1867
|
this.progress?.setCaption(this.caption);
|
|
1841
1868
|
const e = this.getURL();
|
|
1842
1869
|
let t = await fetch(e);
|
|
1843
|
-
if (t = await
|
|
1870
|
+
if (t = await He(
|
|
1844
1871
|
t,
|
|
1845
|
-
this.progress?.loadingListener ??
|
|
1872
|
+
this.progress?.loadingListener ?? ct
|
|
1846
1873
|
), t.status !== 200)
|
|
1847
1874
|
throw new Error(`Could not download "${e}"`);
|
|
1848
1875
|
return new File([await t.blob()], this.name);
|
|
@@ -1867,9 +1894,9 @@ class C extends y {
|
|
|
1867
1894
|
return !0;
|
|
1868
1895
|
}
|
|
1869
1896
|
}
|
|
1870
|
-
const
|
|
1897
|
+
const ct = () => {
|
|
1871
1898
|
};
|
|
1872
|
-
class
|
|
1899
|
+
class lt extends k {
|
|
1873
1900
|
/**
|
|
1874
1901
|
* Creates a new instance of `UrlResource`.
|
|
1875
1902
|
* @param resource The URL reference.
|
|
@@ -1888,10 +1915,10 @@ class ct extends C {
|
|
|
1888
1915
|
}
|
|
1889
1916
|
}
|
|
1890
1917
|
let U = "https://playground.wordpress.net/plugin-proxy";
|
|
1891
|
-
function
|
|
1918
|
+
function yt(r) {
|
|
1892
1919
|
U = r;
|
|
1893
1920
|
}
|
|
1894
|
-
class
|
|
1921
|
+
class ut extends k {
|
|
1895
1922
|
constructor(e, t) {
|
|
1896
1923
|
super(t), this.resource = e;
|
|
1897
1924
|
}
|
|
@@ -1903,7 +1930,7 @@ class lt extends C {
|
|
|
1903
1930
|
return `${U}?theme=` + e;
|
|
1904
1931
|
}
|
|
1905
1932
|
}
|
|
1906
|
-
class
|
|
1933
|
+
class ht extends k {
|
|
1907
1934
|
constructor(e, t) {
|
|
1908
1935
|
super(t), this.resource = e;
|
|
1909
1936
|
}
|
|
@@ -1949,13 +1976,13 @@ class se extends y {
|
|
|
1949
1976
|
return this.resource.isAsync;
|
|
1950
1977
|
}
|
|
1951
1978
|
}
|
|
1952
|
-
class
|
|
1979
|
+
class pt extends se {
|
|
1953
1980
|
/** @inheritDoc */
|
|
1954
1981
|
async resolve() {
|
|
1955
1982
|
return this.promise || (this.promise = super.resolve()), this.promise;
|
|
1956
1983
|
}
|
|
1957
1984
|
}
|
|
1958
|
-
class
|
|
1985
|
+
class dt extends se {
|
|
1959
1986
|
constructor(e, t) {
|
|
1960
1987
|
super(e), this.semaphore = t;
|
|
1961
1988
|
}
|
|
@@ -1964,18 +1991,18 @@ class pt extends se {
|
|
|
1964
1991
|
return this.isAsync ? this.semaphore.run(() => super.resolve()) : super.resolve();
|
|
1965
1992
|
}
|
|
1966
1993
|
}
|
|
1967
|
-
const
|
|
1968
|
-
function
|
|
1994
|
+
const ft = ["6.2", "6.1", "6.0", "5.9"];
|
|
1995
|
+
function Pt(r, {
|
|
1969
1996
|
progress: e = new F(),
|
|
1970
1997
|
semaphore: t = new Y({ concurrency: 3 }),
|
|
1971
1998
|
onStepCompleted: s = () => {
|
|
1972
1999
|
}
|
|
1973
2000
|
} = {}) {
|
|
1974
|
-
const n = (r.steps || []).filter(
|
|
2001
|
+
const n = (r.steps || []).filter(mt), i = n.reduce(
|
|
1975
2002
|
(a, c) => a + (c.progress?.weight || 1),
|
|
1976
2003
|
0
|
|
1977
2004
|
), o = n.map(
|
|
1978
|
-
(a) =>
|
|
2005
|
+
(a) => wt(a, {
|
|
1979
2006
|
semaphore: t,
|
|
1980
2007
|
rootProgressTracker: e,
|
|
1981
2008
|
totalProgressWeight: i
|
|
@@ -1986,22 +2013,22 @@ function yt(r, {
|
|
|
1986
2013
|
php: V(
|
|
1987
2014
|
r.preferredVersions?.php,
|
|
1988
2015
|
ee,
|
|
1989
|
-
|
|
2016
|
+
Ve
|
|
1990
2017
|
),
|
|
1991
2018
|
wp: V(
|
|
1992
2019
|
r.preferredVersions?.wp,
|
|
1993
|
-
|
|
2020
|
+
ft,
|
|
1994
2021
|
"6.2"
|
|
1995
2022
|
)
|
|
1996
2023
|
},
|
|
1997
2024
|
run: async (a) => {
|
|
1998
2025
|
try {
|
|
1999
2026
|
for (const { resources: c } of o)
|
|
2000
|
-
for (const
|
|
2001
|
-
|
|
2002
|
-
for (const { run: c, step:
|
|
2027
|
+
for (const l of c)
|
|
2028
|
+
l.setPlayground(a), l.isAsync && l.resolve();
|
|
2029
|
+
for (const { run: c, step: l } of o) {
|
|
2003
2030
|
const h = await c(a);
|
|
2004
|
-
s(h,
|
|
2031
|
+
s(h, l);
|
|
2005
2032
|
}
|
|
2006
2033
|
try {
|
|
2007
2034
|
await a.goTo(
|
|
@@ -2018,10 +2045,10 @@ function yt(r, {
|
|
|
2018
2045
|
function V(r, e, t) {
|
|
2019
2046
|
return r && e.includes(r) ? r : t;
|
|
2020
2047
|
}
|
|
2021
|
-
function
|
|
2048
|
+
function mt(r) {
|
|
2022
2049
|
return !!(typeof r == "object" && r);
|
|
2023
2050
|
}
|
|
2024
|
-
function
|
|
2051
|
+
function wt(r, {
|
|
2025
2052
|
semaphore: e,
|
|
2026
2053
|
rootProgressTracker: t,
|
|
2027
2054
|
totalProgressWeight: s
|
|
@@ -2031,15 +2058,15 @@ function mt(r, {
|
|
|
2031
2058
|
), i = {};
|
|
2032
2059
|
for (const h of Object.keys(r)) {
|
|
2033
2060
|
let d = r[h];
|
|
2034
|
-
|
|
2061
|
+
it(d) && (d = y.create(d, {
|
|
2035
2062
|
semaphore: e
|
|
2036
2063
|
})), i[h] = d;
|
|
2037
2064
|
}
|
|
2038
2065
|
const o = async (h) => {
|
|
2039
2066
|
try {
|
|
2040
|
-
return n.fillSlowly(), await
|
|
2067
|
+
return n.fillSlowly(), await Ie[r.step](
|
|
2041
2068
|
h,
|
|
2042
|
-
await
|
|
2069
|
+
await gt(i),
|
|
2043
2070
|
{
|
|
2044
2071
|
tracker: n,
|
|
2045
2072
|
initialCaption: r.progress?.caption
|
|
@@ -2050,9 +2077,9 @@ function mt(r, {
|
|
|
2050
2077
|
}
|
|
2051
2078
|
}, a = J(i), c = J(i).filter(
|
|
2052
2079
|
(h) => h.isAsync
|
|
2053
|
-
),
|
|
2080
|
+
), l = 1 / (c.length + 1);
|
|
2054
2081
|
for (const h of c)
|
|
2055
|
-
h.progress = n.stage(
|
|
2082
|
+
h.progress = n.stage(l);
|
|
2056
2083
|
return { run: o, step: r, resources: a };
|
|
2057
2084
|
}
|
|
2058
2085
|
function J(r) {
|
|
@@ -2063,7 +2090,7 @@ function J(r) {
|
|
|
2063
2090
|
}
|
|
2064
2091
|
return e;
|
|
2065
2092
|
}
|
|
2066
|
-
async function
|
|
2093
|
+
async function gt(r) {
|
|
2067
2094
|
const e = {};
|
|
2068
2095
|
for (const t in r) {
|
|
2069
2096
|
const s = r[t];
|
|
@@ -2071,36 +2098,37 @@ async function wt(r) {
|
|
|
2071
2098
|
}
|
|
2072
2099
|
return e;
|
|
2073
2100
|
}
|
|
2074
|
-
async function
|
|
2101
|
+
async function _t(r, e) {
|
|
2075
2102
|
await r.run(e);
|
|
2076
2103
|
}
|
|
2077
2104
|
export {
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2105
|
+
oe as activatePlugin,
|
|
2106
|
+
ae as activateTheme,
|
|
2107
|
+
le as applyWordPressPatches,
|
|
2108
|
+
Pt as compileBlueprint,
|
|
2109
|
+
me as cp,
|
|
2110
|
+
$e as defineSiteUrl,
|
|
2083
2111
|
Oe as defineVirtualWpConfigConsts,
|
|
2084
2112
|
K as defineWpConfigConsts,
|
|
2085
|
-
|
|
2113
|
+
Ee as importFile,
|
|
2086
2114
|
Te as installPlugin,
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2115
|
+
Fe as installTheme,
|
|
2116
|
+
Ce as login,
|
|
2117
|
+
ge as mkdir,
|
|
2118
|
+
we as mv,
|
|
2119
|
+
Se as replaceSite,
|
|
2120
|
+
fe as request,
|
|
2121
|
+
ye as rm,
|
|
2122
|
+
Pe as rmdir,
|
|
2123
|
+
_t as runBlueprintSteps,
|
|
2124
|
+
he as runPHP,
|
|
2125
|
+
pe as runPHPWithOptions,
|
|
2098
2126
|
ke as runWpInstallationWizard,
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2127
|
+
de as setPhpIniEntry,
|
|
2128
|
+
yt as setPluginProxyURL,
|
|
2129
|
+
Ue as setSiteOptions,
|
|
2102
2130
|
Z as unzip,
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2131
|
+
Ae as updateUserMeta,
|
|
2132
|
+
_e as writeFile,
|
|
2133
|
+
ve as zipEntireSite
|
|
2106
2134
|
};
|