@wp-playground/client 0.1.40 → 0.1.46

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.js CHANGED
@@ -1,43 +1,64 @@
1
- function x(t) {
1
+ const ke = async (t, { pluginPath: e }, r) => {
2
+ r?.tracker.setCaption(`Activating ${e}`);
3
+ const s = [
4
+ `${t.documentRoot}/wp-load.php`,
5
+ `${t.documentRoot}/wp-admin/includes/plugin.php`
6
+ ];
7
+ if (!s.every(
8
+ (i) => t.fileExists(i)
9
+ ))
10
+ throw new Error(
11
+ `Required WordPress files do not exist: ${s.join(", ")}`
12
+ );
13
+ await t.run({
14
+ code: `<?php
15
+ ${s.map((i) => `require_once( '${i}' );`).join(`
16
+ `)}
17
+ activate_plugin('${e}');
18
+ `
19
+ });
20
+ }, Oe = async (t, { themeFolderName: e }, r) => {
21
+ r?.tracker.setCaption(`Activating ${e}`);
22
+ const s = `${t.documentRoot}/wp-load.php`;
23
+ if (!t.fileExists(s))
24
+ throw new Error(
25
+ `Required WordPress file does not exist: ${s}`
26
+ );
27
+ await t.run({
28
+ code: `<?php
29
+ require_once( '${s}' );
30
+ switch_theme( '${e}' );
31
+ `
32
+ });
33
+ };
34
+ function F(t) {
2
35
  return new DOMParser().parseFromString(t.text, "text/html");
3
36
  }
4
37
  function L(t) {
5
38
  const e = t.split(".").shift().replace("-", " ");
6
39
  return e.charAt(0).toUpperCase() + e.slice(1).toLowerCase();
7
40
  }
8
- async function E(t, e, r) {
41
+ async function P(t, e, r) {
9
42
  let s = "";
10
43
  await t.fileExists(e) && (s = await t.readFileAsText(e)), await t.writeFile(e, r(s));
11
44
  }
12
- async function Ce(t) {
45
+ async function Ae(t) {
13
46
  return new Uint8Array(await t.arrayBuffer());
14
47
  }
15
- const ke = async (t, { plugin: e }, r) => {
16
- r?.tracker.setCaption(`Activating ${e}`);
17
- const i = x(
18
- await t.request({
19
- url: "/wp-admin/plugins.php"
20
- })
21
- ).querySelector(
22
- `tr[data-slug="${e}"] a`
23
- ).attributes.getNamedItem("href").value;
24
- await t.request({
25
- url: "/wp-admin/" + i
26
- });
27
- }, Fe = async (t, e) => {
28
- const r = new Oe(
48
+ const G = "/vfs-blueprints", J = "/vfs-blueprints/wp-config-consts.php", Le = async (t, e) => {
49
+ const r = new Ue(
29
50
  t,
30
51
  e.siteUrl,
31
52
  e.wordpressPath || "/wordpress"
32
53
  );
33
54
  e.patchSqlitePlugin !== !1 && await r.patchSqlitePlugin(), e.addPhpInfo !== !1 && await r.addPhpInfo(), e.patchSiteUrl !== !1 && await r.patchSiteUrl(), e.disableSiteHealth !== !1 && await r.disableSiteHealth(), e.disableWpNewBlogNotification !== !1 && await r.disableWpNewBlogNotification();
34
55
  };
35
- class Oe {
56
+ class Ue {
36
57
  constructor(e, r, s) {
37
58
  this.php = e, this.scopedSiteUrl = r, this.wordpressPath = s;
38
59
  }
39
60
  async patchSqlitePlugin() {
40
- await E(
61
+ await P(
41
62
  this.php,
42
63
  `${this.wordpressPath}/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php`,
43
64
  (e) => e.replace(
@@ -53,7 +74,7 @@ class Oe {
53
74
  );
54
75
  }
55
76
  async patchSiteUrl() {
56
- await E(
77
+ await P(
57
78
  this.php,
58
79
  `${this.wordpressPath}/wp-config.php`,
59
80
  (e) => `<?php
@@ -65,7 +86,7 @@ class Oe {
65
86
  );
66
87
  }
67
88
  async disableSiteHealth() {
68
- await E(
89
+ await P(
69
90
  this.php,
70
91
  `${this.wordpressPath}/wp-includes/default-filters.php`,
71
92
  (e) => e.replace(
@@ -75,7 +96,7 @@ class Oe {
75
96
  );
76
97
  }
77
98
  async disableWpNewBlogNotification() {
78
- await E(
99
+ await P(
79
100
  this.php,
80
101
  `${this.wordpressPath}/wp-config.php`,
81
102
  // The original version of this function crashes WASM PHP, let's define an empty one instead.
@@ -83,33 +104,33 @@ class Oe {
83
104
  );
84
105
  }
85
106
  }
86
- const Ae = async (t, { code: e }) => await t.run({ code: e }), Le = async (t, { options: e }) => await t.run(e), Ue = async (t, { key: e, value: r }) => {
107
+ const He = async (t, { code: e }) => await t.run({ code: e }), Ie = async (t, { options: e }) => await t.run(e), Ne = async (t, { key: e, value: r }) => {
87
108
  await t.setPhpIniEntry(e, r);
88
- }, He = async (t, { request: e }) => await t.request(e), Ie = async (t, { fromPath: e, toPath: r }) => {
109
+ }, We = async (t, { request: e }) => await t.request(e), Me = async (t, { fromPath: e, toPath: r }) => {
89
110
  await t.writeFile(
90
111
  r,
91
112
  await t.readFileAsBuffer(e)
92
113
  );
93
- }, Ne = async (t, { fromPath: e, toPath: r }) => {
114
+ }, De = async (t, { fromPath: e, toPath: r }) => {
94
115
  await t.mv(e, r);
95
- }, Me = async (t, { path: e }) => {
116
+ }, qe = async (t, { path: e }) => {
96
117
  await t.mkdir(e);
97
- }, We = async (t, { path: e }) => {
118
+ }, ze = async (t, { path: e }) => {
98
119
  await t.unlink(e);
99
- }, De = async (t, { path: e }) => {
120
+ }, je = async (t, { path: e }) => {
100
121
  await t.rmdir(e);
101
- }, ze = async (t, { path: e, data: r }) => {
102
- r instanceof File && (r = await Ce(r)), await t.writeFile(e, r);
103
- }, he = async (t, { consts: e }) => {
122
+ }, Be = async (t, { path: e, data: r }) => {
123
+ r instanceof File && (r = await Ae(r)), await t.writeFile(e, r);
124
+ }, pe = async (t, { consts: e }) => {
104
125
  const r = await t.documentRoot;
105
- await E(
126
+ await P(
106
127
  t,
107
128
  `${r}/playground-consts.json`,
108
129
  (s) => JSON.stringify({
109
130
  ...JSON.parse(s || "{}"),
110
131
  ...e
111
132
  })
112
- ), await E(
133
+ ), await P(
113
134
  t,
114
135
  `${r}/wp-config.php`,
115
136
  (s) => s.includes("playground-consts.json") ? s : `<?php
@@ -121,13 +142,13 @@ const Ae = async (t, { code: e }) => await t.run({ code: e }), Le = async (t, {
121
142
  }
122
143
  ?>${s}`
123
144
  );
124
- }, qe = async (t, { siteUrl: e }) => await he(t, {
145
+ }, Ve = async (t, { siteUrl: e }) => await pe(t, {
125
146
  consts: {
126
147
  WP_HOME: e,
127
148
  WP_SITEURL: e
128
149
  }
129
150
  });
130
- class de {
151
+ class fe {
131
152
  constructor({ concurrency: e }) {
132
153
  this._running = 0, this.concurrency = e, this.queue = [];
133
154
  }
@@ -152,29 +173,29 @@ class de {
152
173
  }
153
174
  }
154
175
  }
155
- const je = Symbol("literal");
156
- function v(t) {
176
+ const Ge = Symbol("literal");
177
+ function S(t) {
157
178
  if (typeof t == "string")
158
179
  return t.startsWith("$") ? t : JSON.stringify(t);
159
180
  if (typeof t == "number")
160
181
  return t.toString();
161
182
  if (Array.isArray(t))
162
- return `array(${t.map(v).join(", ")})`;
183
+ return `array(${t.map(S).join(", ")})`;
163
184
  if (t === null)
164
185
  return "null";
165
186
  if (typeof t == "object")
166
- return je in t ? t.toString() : `array(${Object.entries(t).map(([r, s]) => `${JSON.stringify(r)} => ${v(s)}`).join(", ")})`;
187
+ return Ge in t ? t.toString() : `array(${Object.entries(t).map(([r, s]) => `${JSON.stringify(r)} => ${S(s)}`).join(", ")})`;
167
188
  if (typeof t == "function")
168
189
  return t();
169
190
  throw new Error(`Unsupported value: ${t}`);
170
191
  }
171
- function W(t) {
192
+ function M(t) {
172
193
  const e = {};
173
194
  for (const r in t)
174
- e[r] = v(t[r]);
195
+ e[r] = S(t[r]);
175
196
  return e;
176
197
  }
177
- const G = `<?php
198
+ const Y = `<?php
178
199
 
179
200
  function zipDir($dir, $output, $additionalFiles = array())
180
201
  {
@@ -237,28 +258,28 @@ function delTree($dir)
237
258
  return rmdir($dir);
238
259
  }
239
260
  `;
240
- async function Be(t) {
241
- const e = "wordpress-playground.zip", r = `/${e}`, s = W({
261
+ async function Je(t) {
262
+ const e = "wordpress-playground.zip", r = `/${e}`, s = M({
242
263
  zipPath: r,
243
264
  documentRoot: await t.documentRoot
244
265
  });
245
- await fe(
266
+ await we(
246
267
  t,
247
268
  `zipDir(${s.documentRoot}, ${s.zipPath});`
248
269
  );
249
270
  const n = await t.readFileAsBuffer(r);
250
271
  return t.unlink(r), new File([n], e);
251
272
  }
252
- const Ve = async (t, { fullSiteZip: e }) => {
273
+ const Ye = async (t, { fullSiteZip: e }) => {
253
274
  const r = "/import.zip";
254
275
  await t.writeFile(
255
276
  r,
256
277
  new Uint8Array(await e.arrayBuffer())
257
278
  );
258
279
  const s = await t.absoluteUrl, n = await t.documentRoot;
259
- await t.rmdir(n), await pe(t, { zipPath: r, extractToPath: "/" });
260
- const i = W({ absoluteUrl: s });
261
- await Ye(
280
+ await t.rmdir(n), await me(t, { zipPath: r, extractToPath: "/" });
281
+ const i = M({ absoluteUrl: s });
282
+ await Xe(
262
283
  t,
263
284
  `${n}/wp-config.php`,
264
285
  (o) => `<?php
@@ -268,35 +289,35 @@ const Ve = async (t, { fullSiteZip: e }) => {
268
289
  }
269
290
  ?>${o}`
270
291
  );
271
- }, pe = async (t, { zipPath: e, extractToPath: r }) => {
272
- const s = W({
292
+ }, me = async (t, { zipPath: e, extractToPath: r }) => {
293
+ const s = M({
273
294
  zipPath: e,
274
295
  extractToPath: r
275
296
  });
276
- await fe(
297
+ await we(
277
298
  t,
278
299
  `unzip(${s.zipPath}, ${s.extractToPath});`
279
300
  );
280
- }, Ge = async (t, { file: e }) => {
301
+ }, Ke = async (t, { file: e }) => {
281
302
  const r = await t.request({
282
303
  url: "/wp-admin/admin.php?import=wordpress"
283
- }), s = J(r).getElementById("import-upload-form")?.getAttribute("action"), n = await t.request({
304
+ }), s = K(r).getElementById("import-upload-form")?.getAttribute("action"), n = await t.request({
284
305
  url: `/wp-admin/${s}`,
285
306
  method: "POST",
286
307
  files: { import: e }
287
- }), i = J(n).querySelector(
308
+ }), i = K(n).querySelector(
288
309
  "#wpbody-content form"
289
310
  );
290
311
  if (!i)
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 = Je(i);
315
+ const o = Qe(i);
295
316
  o.fetch_attachments = "1";
296
317
  for (const a in o)
297
318
  if (a.startsWith("user_map[")) {
298
- const c = "user_new[" + a.slice(9, -1) + "]";
299
- o[c] = "1";
319
+ const l = "user_new[" + a.slice(9, -1) + "]";
320
+ o[l] = "1";
300
321
  }
301
322
  await t.request({
302
323
  url: i.action,
@@ -304,45 +325,45 @@ const Ve = async (t, { fullSiteZip: e }) => {
304
325
  formData: o
305
326
  });
306
327
  };
307
- function J(t) {
328
+ function K(t) {
308
329
  return new DOMParser().parseFromString(t.text, "text/html");
309
330
  }
310
- function Je(t) {
331
+ function Qe(t) {
311
332
  return Object.fromEntries(new FormData(t).entries());
312
333
  }
313
- async function Ye(t, e, r) {
334
+ async function Xe(t, e, r) {
314
335
  await t.writeFile(
315
336
  e,
316
337
  r(await t.readFileAsText(e))
317
338
  );
318
339
  }
319
- async function fe(t, e) {
340
+ async function we(t, e) {
320
341
  const r = await t.run({
321
- code: G + e
342
+ code: Y + e
322
343
  });
323
344
  if (r.exitCode !== 0)
324
- throw console.log(G + e), console.log(e + ""), console.log(r.errors), r.errors;
345
+ throw console.log(Y + e), console.log(e + ""), console.log(r.errors), r.errors;
325
346
  return r;
326
347
  }
327
- const Ke = async (t, { pluginZipFile: e, options: r = {} }, s) => {
348
+ const Ze = async (t, { pluginZipFile: e, options: r = {} }, s) => {
328
349
  s?.tracker.setCaption(
329
350
  `Installing the ${L(e?.name)} plugin`
330
351
  );
331
352
  try {
332
353
  const n = "activate" in r ? r.activate : !0, i = await t.request({
333
354
  url: "/wp-admin/plugin-install.php?tab=upload"
334
- }), o = x(i), a = new FormData(
355
+ }), o = F(i), a = new FormData(
335
356
  o.querySelector(".wp-upload-form")
336
- ), { pluginzip: c, ...l } = Object.fromEntries(
357
+ ), { pluginzip: l, ...c } = Object.fromEntries(
337
358
  a.entries()
338
359
  ), u = await t.request({
339
360
  url: "/wp-admin/update.php?action=upload-plugin",
340
361
  method: "POST",
341
- formData: l,
362
+ formData: c,
342
363
  files: { pluginzip: e }
343
364
  });
344
365
  if (n) {
345
- const p = x(u).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value, y = new URL(
366
+ const p = F(u).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value, y = new URL(
346
367
  p,
347
368
  await t.pathToInternalUrl("/wp-admin/")
348
369
  ).toString();
@@ -352,14 +373,14 @@ const Ke = async (t, { pluginZipFile: e, options: r = {} }, s) => {
352
373
  }
353
374
  await t.isDir(
354
375
  "/wordpress/wp-content/plugins/gutenberg"
355
- ) && !await t.fileExists("/wordpress/.gutenberg-patched") && (await t.writeFile("/wordpress/.gutenberg-patched", "1"), await Y(
376
+ ) && !await t.fileExists("/wordpress/.gutenberg-patched") && (await t.writeFile("/wordpress/.gutenberg-patched", "1"), await Q(
356
377
  t,
357
378
  "/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.js",
358
379
  (d) => d.replace(
359
380
  /srcDoc:("[^"]+"|[^,]+)/g,
360
381
  'src:"/wp-includes/empty.html"'
361
382
  )
362
- ), await Y(
383
+ ), await Q(
363
384
  t,
364
385
  "/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.min.js",
365
386
  (d) => d.replace(
@@ -373,31 +394,31 @@ const Ke = async (t, { pluginZipFile: e, options: r = {} }, s) => {
373
394
  ), console.error(n);
374
395
  }
375
396
  };
376
- async function Y(t, e, r) {
397
+ async function Q(t, e, r) {
377
398
  return await t.writeFile(
378
399
  e,
379
400
  r(await t.readFileAsText(e))
380
401
  );
381
402
  }
382
- const Qe = async (t, { themeZipFile: e, options: r = {} }, s) => {
403
+ const et = async (t, { themeZipFile: e, options: r = {} }, s) => {
383
404
  s?.tracker.setCaption(
384
405
  `Installing the ${L(e.name)} theme`
385
406
  );
386
407
  try {
387
408
  const n = "activate" in r ? r.activate : !0, i = await t.request({
388
409
  url: "/wp-admin/theme-install.php"
389
- }), o = x(i), a = new FormData(
410
+ }), o = F(i), a = new FormData(
390
411
  o.querySelector(".wp-upload-form")
391
- ), { themezip: c, ...l } = Object.fromEntries(
412
+ ), { themezip: l, ...c } = Object.fromEntries(
392
413
  a.entries()
393
414
  ), u = await t.request({
394
415
  url: "/wp-admin/update.php?action=upload-theme",
395
416
  method: "POST",
396
- formData: l,
417
+ formData: c,
397
418
  files: { themezip: e }
398
419
  });
399
420
  if (n) {
400
- const d = x(u), p = d.querySelector(
421
+ const d = F(u), p = d.querySelector(
401
422
  "#wpbody-content > .wrap"
402
423
  );
403
424
  if (p?.textContent?.includes(
@@ -413,12 +434,12 @@ const Qe = async (t, { themeZipFile: e, options: r = {} }, s) => {
413
434
  console.error('The "activate" button was not found.');
414
435
  return;
415
436
  }
416
- const xe = y.attributes.getNamedItem("href").value, Te = new URL(
417
- xe,
437
+ const Ce = y.attributes.getNamedItem("href").value, Fe = new URL(
438
+ Ce,
418
439
  await t.pathToInternalUrl("/wp-admin/")
419
440
  ).toString();
420
441
  await t.request({
421
- url: Te
442
+ url: Fe
422
443
  });
423
444
  }
424
445
  } catch (n) {
@@ -426,7 +447,7 @@ const Qe = async (t, { themeZipFile: e, options: r = {} }, 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
- }, Xe = async (t, { username: e = "admin", password: r = "password" } = {}, s) => {
450
+ }, tt = async (t, { username: e = "admin", password: r = "password" } = {}, s) => {
430
451
  s?.tracker.setCaption(s?.initialCaption || "Logging in"), await t.request({
431
452
  url: "/wp-login.php"
432
453
  }), await t.request({
@@ -438,7 +459,7 @@ const Qe = async (t, { themeZipFile: e, options: r = {} }, s) => {
438
459
  rememberme: "forever"
439
460
  }
440
461
  });
441
- }, Ze = async (t, { options: e }) => {
462
+ }, rt = async (t, { options: e }) => {
442
463
  await t.request({
443
464
  url: "/wp-admin/install.php?step=2",
444
465
  method: "POST",
@@ -455,10 +476,10 @@ const Qe = async (t, { themeZipFile: e, options: r = {} }, s) => {
455
476
  admin_email: "admin@localhost.com"
456
477
  }
457
478
  });
458
- }, et = async (t, { options: e }) => {
479
+ }, st = async (t, { options: e }) => {
459
480
  const r = `<?php
460
481
  include 'wordpress/wp-load.php';
461
- $site_options = ${v(e)};
482
+ $site_options = ${S(e)};
462
483
  foreach($site_options as $name => $value) {
463
484
  update_option($name, $value);
464
485
  }
@@ -466,53 +487,73 @@ const Qe = async (t, { themeZipFile: e, options: r = {} }, s) => {
466
487
  `, s = await t.run({
467
488
  code: r
468
489
  });
469
- return me(s), { code: r, result: s };
470
- }, tt = async (t, { meta: e, userId: r }) => {
490
+ return ge(s), { code: r, result: s };
491
+ }, nt = async (t, { meta: e, userId: r }) => {
471
492
  const s = `<?php
472
493
  include 'wordpress/wp-load.php';
473
- $meta = ${v(e)};
494
+ $meta = ${S(e)};
474
495
  foreach($meta as $name => $value) {
475
- update_user_meta(${v(r)}, $name, $value);
496
+ update_user_meta(${S(r)}, $name, $value);
476
497
  }
477
498
  echo "Success";
478
499
  `, n = await t.run({
479
500
  code: s
480
501
  });
481
- return me(n), { code: s, result: n };
502
+ return ge(n), { code: s, result: n };
482
503
  };
483
- async function me(t) {
504
+ async function ge(t) {
484
505
  if (t.text !== "Success")
485
506
  throw console.log(t), new Error(`Failed to run code: ${t.text} ${t.errors}`);
486
507
  }
487
- const rt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
508
+ const it = async (t, { consts: e }) => {
509
+ t.mkdir(G);
510
+ const r = `${G}/playground-consts.json`;
511
+ return await P(
512
+ t,
513
+ r,
514
+ (s) => JSON.stringify({
515
+ ...JSON.parse(s || "{}"),
516
+ ...e
517
+ })
518
+ ), await P(t, J, (s) => s.includes("playground-consts.json") ? s : `<?php
519
+ $consts = json_decode(file_get_contents('${r}'), true);
520
+ foreach ($consts as $const => $value) {
521
+ if (!defined($const)) {
522
+ define($const, $value);
523
+ }
524
+ }
525
+ ?>${s}`), J;
526
+ }, ot = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
488
527
  __proto__: null,
489
528
  activatePlugin: ke,
490
- applyWordPressPatches: Fe,
491
- cp: Ie,
492
- defineSiteUrl: qe,
493
- defineWpConfigConsts: he,
494
- importFile: Ge,
495
- installPlugin: Ke,
496
- installTheme: Qe,
497
- login: Xe,
498
- mkdir: Me,
499
- mv: Ne,
500
- replaceSite: Ve,
501
- request: He,
502
- rm: We,
503
- rmdir: De,
504
- runPHP: Ae,
505
- runPHPWithOptions: Le,
506
- runWpInstallationWizard: Ze,
507
- setPhpIniEntry: Ue,
508
- setSiteOptions: et,
509
- unzip: pe,
510
- updateUserMeta: tt,
511
- writeFile: ze,
512
- zipEntireSite: Be
513
- }, Symbol.toStringTag, { value: "Module" })), st = 5 * 1024 * 1024;
514
- function nt(t, e) {
515
- const r = t.headers.get("content-length") || "", s = parseInt(r, 10) || st;
529
+ activateTheme: Oe,
530
+ applyWordPressPatches: Le,
531
+ cp: Me,
532
+ defineSiteUrl: Ve,
533
+ defineVirtualWpConfigConsts: it,
534
+ defineWpConfigConsts: pe,
535
+ importFile: Ke,
536
+ installPlugin: Ze,
537
+ installTheme: et,
538
+ login: tt,
539
+ mkdir: qe,
540
+ mv: De,
541
+ replaceSite: Ye,
542
+ request: We,
543
+ rm: ze,
544
+ rmdir: je,
545
+ runPHP: He,
546
+ runPHPWithOptions: Ie,
547
+ runWpInstallationWizard: rt,
548
+ setPhpIniEntry: Ne,
549
+ setSiteOptions: st,
550
+ unzip: me,
551
+ updateUserMeta: nt,
552
+ writeFile: Be,
553
+ zipEntireSite: Je
554
+ }, Symbol.toStringTag, { value: "Module" })), at = 5 * 1024 * 1024;
555
+ function ct(t, e) {
556
+ const r = t.headers.get("content-length") || "", s = parseInt(r, 10) || at;
516
557
  function n(i, o) {
517
558
  e(
518
559
  new CustomEvent("progress", {
@@ -534,14 +575,14 @@ function nt(t, e) {
534
575
  let a = 0;
535
576
  for (; ; )
536
577
  try {
537
- const { done: c, value: l } = await o.read();
538
- if (l && (a += l.byteLength), c) {
578
+ const { done: l, value: c } = await o.read();
579
+ if (c && (a += c.byteLength), l) {
539
580
  n(a, a), i.close();
540
581
  break;
541
582
  } else
542
- n(a, s), i.enqueue(l);
543
- } catch (c) {
544
- console.error({ e: c }), i.error(c);
583
+ n(a, s), i.enqueue(c);
584
+ } catch (l) {
585
+ console.error({ e: l }), i.error(l);
545
586
  break;
546
587
  }
547
588
  }
@@ -720,12 +761,157 @@ class U extends EventTarget {
720
761
  this.dispatchEvent(new CustomEvent("done"));
721
762
  }
722
763
  }
723
- class S {
764
+ const X = Symbol("error"), Z = Symbol("message");
765
+ class D extends Event {
766
+ /**
767
+ * Create a new `ErrorEvent`.
768
+ *
769
+ * @param type The name of the event
770
+ * @param options A dictionary object that allows for setting
771
+ * attributes via object members of the same name.
772
+ */
773
+ constructor(e, r = {}) {
774
+ super(e), this[X] = r.error === void 0 ? null : r.error, this[Z] = r.message === void 0 ? "" : r.message;
775
+ }
776
+ get error() {
777
+ return this[X];
778
+ }
779
+ get message() {
780
+ return this[Z];
781
+ }
782
+ }
783
+ Object.defineProperty(D.prototype, "error", { enumerable: !0 });
784
+ Object.defineProperty(D.prototype, "message", { enumerable: !0 });
785
+ const lt = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : D;
786
+ class ut extends EventTarget {
787
+ constructor() {
788
+ super(...arguments), this.listenersCount = 0;
789
+ }
790
+ addEventListener(e, r) {
791
+ ++this.listenersCount, super.addEventListener(e, r);
792
+ }
793
+ removeEventListener(e, r) {
794
+ --this.listenersCount, super.removeEventListener(e, r);
795
+ }
796
+ hasListeners() {
797
+ return this.listenersCount > 0;
798
+ }
799
+ }
800
+ function ht(t) {
801
+ t.asm = {
802
+ ...t.asm
803
+ };
804
+ const e = new ut();
805
+ for (const r in t.asm)
806
+ if (typeof t.asm[r] == "function") {
807
+ const s = t.asm[r];
808
+ t.asm[r] = function(...n) {
809
+ try {
810
+ return s(...n);
811
+ } catch (i) {
812
+ if (!(i instanceof Error))
813
+ throw i;
814
+ if ("exitCode" in i && i?.exitCode === 0)
815
+ return;
816
+ const o = pt(
817
+ i,
818
+ t.lastAsyncifyStackSource?.stack
819
+ );
820
+ if (t.lastAsyncifyStackSource && (i.cause = t.lastAsyncifyStackSource), !e.hasListeners())
821
+ throw wt(o), i;
822
+ e.dispatchEvent(
823
+ new lt("error", {
824
+ error: i,
825
+ message: o
826
+ })
827
+ );
828
+ }
829
+ };
830
+ }
831
+ return e;
832
+ }
833
+ let N = [];
834
+ function dt() {
835
+ return N;
836
+ }
837
+ function pt(t, e) {
838
+ if (t.message === "unreachable") {
839
+ let r = ft;
840
+ e || (r += `
841
+
842
+ This stack trace is lacking. For a better one initialize
843
+ the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
844
+
845
+ `), N = gt(
846
+ e || t.stack || ""
847
+ );
848
+ for (const s of N)
849
+ r += ` * ${s}
850
+ `;
851
+ return r;
852
+ }
853
+ return t.message;
854
+ }
855
+ const ft = `
856
+ "unreachable" WASM instruction executed.
857
+
858
+ The typical reason is a PHP function missing from the ASYNCIFY_ONLY
859
+ list when building PHP.wasm.
860
+
861
+ You will need to file a new issue in the WordPress Playground repository
862
+ and paste this error message there:
863
+
864
+ https://github.com/WordPress/wordpress-playground/issues/new
865
+
866
+ If you're a core developer, the typical fix is to:
867
+
868
+ * Isolate a minimal reproduction of the error
869
+ * Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository
870
+ * Run 'npm run fix-asyncify'
871
+ * Commit the changes, push to the repo, release updated NPM packages
872
+
873
+ Below is a list of all the PHP functions found in the stack trace to
874
+ help with the minimal reproduction. If they're all already listed in
875
+ the Dockerfile, you'll need to trigger this error again with long stack
876
+ traces enabled. In node.js, you can do it using the --stack-trace-limit=100
877
+ CLI option:
878
+
879
+ `, ee = "\x1B[41m", mt = "\x1B[1m", te = "\x1B[0m", re = "\x1B[K";
880
+ let se = !1;
881
+ function wt(t) {
882
+ if (!se) {
883
+ se = !0, console.log(`${ee}
884
+ ${re}
885
+ ${mt} WASM ERROR${te}${ee}`);
886
+ for (const e of t.split(`
887
+ `))
888
+ console.log(`${re} ${e} `);
889
+ console.log(`${te}`);
890
+ }
891
+ }
892
+ function gt(t) {
893
+ try {
894
+ const e = t.split(`
895
+ `).slice(1).map((r) => {
896
+ const s = r.trim().substring(3).split(" ");
897
+ return {
898
+ fn: s.length >= 2 ? s[0] : "<unknown>",
899
+ isWasm: r.includes("wasm://")
900
+ };
901
+ }).filter(
902
+ ({ fn: r, isWasm: s }) => s && !r.startsWith("dynCall_") && !r.startsWith("invoke_")
903
+ ).map(({ fn: r }) => r);
904
+ return Array.from(new Set(e));
905
+ } catch {
906
+ return [];
907
+ }
908
+ }
909
+ class _ {
724
910
  constructor(e, r, s, n = "", i = 0) {
725
911
  this.httpStatusCode = e, this.headers = r, this.bytes = s, this.exitCode = i, this.errors = n;
726
912
  }
727
913
  static fromRawData(e) {
728
- return new S(
914
+ return new _(
729
915
  e.httpStatusCode,
730
916
  e.headers,
731
917
  e.bytes,
@@ -755,7 +941,7 @@ class S {
755
941
  return new TextDecoder().decode(this.bytes);
756
942
  }
757
943
  }
758
- const D = [
944
+ const q = [
759
945
  "8.2",
760
946
  "8.1",
761
947
  "8.0",
@@ -765,8 +951,8 @@ const D = [
765
951
  "7.1",
766
952
  "7.0",
767
953
  "5.6"
768
- ], it = D[0], rr = D;
769
- class ot {
954
+ ], yt = q[0], or = q;
955
+ class Pt {
770
956
  #e;
771
957
  #t;
772
958
  /**
@@ -799,10 +985,10 @@ class ot {
799
985
  ...e,
800
986
  headers: {
801
987
  ...e.headers,
802
- cookie: this.#n()
988
+ cookie: this.#r()
803
989
  }
804
990
  });
805
- if (s.headers["set-cookie"] && this.#r(s.headers["set-cookie"]), this.#t.handleRedirects && s.headers.location && r < this.#t.maxRedirects) {
991
+ if (s.headers["set-cookie"] && this.#s(s.headers["set-cookie"]), this.#t.handleRedirects && s.headers.location && r < this.#t.maxRedirects) {
806
992
  const n = new URL(
807
993
  s.headers.location[0],
808
994
  this.requestHandler.absoluteUrl
@@ -834,7 +1020,7 @@ class ot {
834
1020
  get documentRoot() {
835
1021
  return this.requestHandler.documentRoot;
836
1022
  }
837
- #r(e) {
1023
+ #s(e) {
838
1024
  for (const r of e)
839
1025
  try {
840
1026
  if (!r.includes("="))
@@ -845,30 +1031,30 @@ class ot {
845
1031
  console.error(s);
846
1032
  }
847
1033
  }
848
- #n() {
1034
+ #r() {
849
1035
  const e = [];
850
1036
  for (const r in this.#e)
851
1037
  e.push(`${r}=${this.#e[r]}`);
852
1038
  return e.join("; ");
853
1039
  }
854
1040
  }
855
- const at = "http://example.com";
856
- function K(t) {
1041
+ const bt = "http://example.com";
1042
+ function ne(t) {
857
1043
  return t.toString().substring(t.origin.length);
858
1044
  }
859
- function Q(t, e) {
1045
+ function ie(t, e) {
860
1046
  return !e || !t.startsWith(e) ? t : t.substring(e.length);
861
1047
  }
862
- function ct(t, e) {
1048
+ function _t(t, e) {
863
1049
  return !e || t.startsWith(e) ? t : e + t;
864
1050
  }
865
- class lt {
1051
+ class $t {
866
1052
  #e;
867
1053
  #t;
1054
+ #s;
868
1055
  #r;
869
- #n;
870
1056
  #i;
871
- #s;
1057
+ #n;
872
1058
  #o;
873
1059
  #a;
874
1060
  #c;
@@ -877,7 +1063,7 @@ class lt {
877
1063
  * @param config - Request Handler configuration.
878
1064
  */
879
1065
  constructor(e, r = {}) {
880
- this.#a = new de({ concurrency: 1 });
1066
+ this.#a = new fe({ concurrency: 1 });
881
1067
  const {
882
1068
  documentRoot: s = "/www/",
883
1069
  absoluteUrl: n = typeof location == "object" ? location?.href : "",
@@ -885,15 +1071,15 @@ class lt {
885
1071
  } = r;
886
1072
  this.php = e, this.#e = s, this.#c = i;
887
1073
  const o = new URL(n);
888
- this.#r = o.hostname, this.#n = o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80, this.#t = (o.protocol || "").replace(":", "");
889
- const a = this.#n !== 443 && this.#n !== 80;
1074
+ this.#s = o.hostname, this.#r = o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80, this.#t = (o.protocol || "").replace(":", "");
1075
+ const a = this.#r !== 443 && this.#r !== 80;
890
1076
  this.#i = [
891
- this.#r,
892
- a ? `:${this.#n}` : ""
893
- ].join(""), this.#s = o.pathname.replace(/\/+$/, ""), this.#o = [
1077
+ this.#s,
1078
+ a ? `:${this.#r}` : ""
1079
+ ].join(""), this.#n = o.pathname.replace(/\/+$/, ""), this.#o = [
894
1080
  `${this.#t}://`,
895
1081
  this.#i,
896
- this.#s
1082
+ this.#n
897
1083
  ].join("");
898
1084
  }
899
1085
  /** @inheritDoc */
@@ -903,7 +1089,7 @@ class lt {
903
1089
  /** @inheritDoc */
904
1090
  internalUrlToPath(e) {
905
1091
  const r = new URL(e);
906
- return r.pathname.startsWith(this.#s) && (r.pathname = r.pathname.slice(this.#s.length)), K(r);
1092
+ return r.pathname.startsWith(this.#n) && (r.pathname = r.pathname.slice(this.#n.length)), ne(r);
907
1093
  }
908
1094
  get isRequestRunning() {
909
1095
  return this.#a.running > 0;
@@ -920,10 +1106,10 @@ class lt {
920
1106
  async request(e) {
921
1107
  const r = e.url.startsWith("http://") || e.url.startsWith("https://"), s = new URL(
922
1108
  e.url,
923
- r ? void 0 : at
924
- ), n = Q(
1109
+ r ? void 0 : bt
1110
+ ), n = ie(
925
1111
  s.pathname,
926
- this.#s
1112
+ this.#n
927
1113
  );
928
1114
  return this.#c(n) ? this.#l(n) : await this.#u(e, s);
929
1115
  }
@@ -936,20 +1122,20 @@ class lt {
936
1122
  #l(e) {
937
1123
  const r = `${this.#e}${e}`;
938
1124
  if (!this.php.fileExists(r))
939
- return new S(
1125
+ return new _(
940
1126
  404,
941
1127
  {},
942
1128
  new TextEncoder().encode("404 File not found")
943
1129
  );
944
1130
  const s = this.php.readFileAsBuffer(r);
945
- return new S(
1131
+ return new _(
946
1132
  200,
947
1133
  {
948
1134
  "content-length": [`${s.byteLength}`],
949
1135
  // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
950
1136
  // The code below won't return the correct mime-type if the extension
951
1137
  // was tampered with.
952
- "content-type": [ht(r)],
1138
+ "content-type": [vt(r)],
953
1139
  "accept-ranges": ["bytes"],
954
1140
  "cache-control": ["public, max-age=0"]
955
1141
  },
@@ -973,36 +1159,47 @@ class lt {
973
1159
  let n = "GET";
974
1160
  const i = {
975
1161
  host: this.#i,
976
- ...ge(e.headers || {})
1162
+ ...ye(e.headers || {})
977
1163
  }, o = [];
978
1164
  if (e.files && Object.keys(e.files).length) {
979
1165
  n = "POST";
980
1166
  for (const c in e.files) {
981
- const l = e.files[c];
1167
+ const u = e.files[c];
982
1168
  o.push({
983
1169
  key: c,
984
- name: l.name,
985
- type: l.type,
986
- data: new Uint8Array(await l.arrayBuffer())
1170
+ name: u.name,
1171
+ type: u.type,
1172
+ data: new Uint8Array(await u.arrayBuffer())
987
1173
  });
988
1174
  }
989
- i["content-type"]?.startsWith("multipart/form-data") && (e.formData = ut(
1175
+ i["content-type"]?.startsWith("multipart/form-data") && (e.formData = Et(
990
1176
  e.body || ""
991
1177
  ), i["content-type"] = "application/x-www-form-urlencoded", delete e.body);
992
1178
  }
993
1179
  let a;
994
- return e.formData !== void 0 ? (n = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
1180
+ e.formData !== void 0 ? (n = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
995
1181
  e.formData
996
- ).toString()) : a = e.body, await this.php.run({
997
- relativeUri: ct(
998
- K(r),
999
- this.#s
1182
+ ).toString()) : a = e.body;
1183
+ let l;
1184
+ try {
1185
+ l = this.#h(r.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: _t(
1195
+ ne(r),
1196
+ this.#n
1000
1197
  ),
1001
1198
  protocol: this.#t,
1002
1199
  method: e.method || n,
1003
1200
  body: a,
1004
1201
  fileInfos: o,
1005
- scriptPath: this.#h(r.pathname),
1202
+ scriptPath: l,
1006
1203
  headers: i
1007
1204
  });
1008
1205
  } finally {
@@ -1015,16 +1212,21 @@ class lt {
1015
1212
  * Fall back to index.php as if there was a url rewriting rule in place.
1016
1213
  *
1017
1214
  * @param requestedPath - The requested pathname.
1215
+ * @throws {Error} If the requested path doesn't exist.
1018
1216
  * @returns The resolved filesystem path.
1019
1217
  */
1020
1218
  #h(e) {
1021
- let r = Q(e, this.#s);
1219
+ let r = ie(e, this.#n);
1022
1220
  r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
1023
1221
  const s = `${this.#e}${r}`;
1024
- return this.php.fileExists(s) ? s : `${this.#e}/index.php`;
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`;
1025
1227
  }
1026
1228
  }
1027
- function ut(t) {
1229
+ function Et(t) {
1028
1230
  const e = {}, r = t.match(/--(.*)\r\n/);
1029
1231
  if (!r)
1030
1232
  return e;
@@ -1032,14 +1234,14 @@ function ut(t) {
1032
1234
  return n.shift(), n.pop(), n.forEach((i) => {
1033
1235
  const o = i.indexOf(`\r
1034
1236
  \r
1035
- `), a = i.substring(0, o).trim(), c = i.substring(o + 4).trim(), l = a.match(/name="([^"]+)"/);
1036
- if (l) {
1037
- const u = l[1];
1038
- e[u] = c;
1237
+ `), a = i.substring(0, o).trim(), l = i.substring(o + 4).trim(), c = a.match(/name="([^"]+)"/);
1238
+ if (c) {
1239
+ const u = c[1];
1240
+ e[u] = l;
1039
1241
  }
1040
1242
  }), e;
1041
1243
  }
1042
- function ht(t) {
1244
+ function vt(t) {
1043
1245
  switch (t.split(".").pop()) {
1044
1246
  case "css":
1045
1247
  return "text/css";
@@ -1079,7 +1281,7 @@ function ht(t) {
1079
1281
  return "application-octet-stream";
1080
1282
  }
1081
1283
  }
1082
- const X = {
1284
+ const oe = {
1083
1285
  0: "No error occurred. System call completed successfully.",
1084
1286
  1: "Argument list too long.",
1085
1287
  2: "Permission denied.",
@@ -1165,10 +1367,10 @@ function m(t = "") {
1165
1367
  try {
1166
1368
  return i.apply(this, o);
1167
1369
  } catch (a) {
1168
- const c = typeof a == "object" ? a?.errno : null;
1169
- if (c in X) {
1170
- const l = X[c], u = typeof o[0] == "string" ? o[0] : null, d = u !== null ? t.replaceAll("{path}", u) : t;
1171
- throw new Error(`${d}: ${l}`, {
1370
+ const l = typeof a == "object" ? a?.errno : null;
1371
+ if (l in oe) {
1372
+ const c = oe[l], u = typeof o[0] == "string" ? o[0] : null, d = u !== null ? t.replaceAll("{path}", u) : t;
1373
+ throw new Error(`${d}: ${c}`, {
1172
1374
  cause: a
1173
1375
  });
1174
1376
  }
@@ -1177,165 +1379,20 @@ function m(t = "") {
1177
1379
  };
1178
1380
  };
1179
1381
  }
1180
- const dt = [];
1181
- function pt(t) {
1182
- return dt[t];
1382
+ const St = [];
1383
+ function Rt(t) {
1384
+ return St[t];
1183
1385
  }
1184
1386
  (function() {
1185
1387
  return typeof process < "u" && process.release?.name === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
1186
1388
  })();
1187
- const Z = Symbol("error"), ee = Symbol("message");
1188
- class z extends Event {
1189
- /**
1190
- * Create a new `ErrorEvent`.
1191
- *
1192
- * @param type The name of the event
1193
- * @param options A dictionary object that allows for setting
1194
- * attributes via object members of the same name.
1195
- */
1196
- constructor(e, r = {}) {
1197
- super(e), this[Z] = r.error === void 0 ? null : r.error, this[ee] = r.message === void 0 ? "" : r.message;
1198
- }
1199
- get error() {
1200
- return this[Z];
1201
- }
1202
- get message() {
1203
- return this[ee];
1204
- }
1205
- }
1206
- Object.defineProperty(z.prototype, "error", { enumerable: !0 });
1207
- Object.defineProperty(z.prototype, "message", { enumerable: !0 });
1208
- const ft = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : z;
1209
- class mt extends EventTarget {
1210
- constructor() {
1211
- super(...arguments), this.listenersCount = 0;
1212
- }
1213
- addEventListener(e, r) {
1214
- ++this.listenersCount, super.addEventListener(e, r);
1215
- }
1216
- removeEventListener(e, r) {
1217
- --this.listenersCount, super.removeEventListener(e, r);
1218
- }
1219
- hasListeners() {
1220
- return this.listenersCount > 0;
1221
- }
1222
- }
1223
- function gt(t) {
1224
- t.asm = {
1225
- ...t.asm
1226
- };
1227
- const e = new mt();
1228
- for (const r in t.asm)
1229
- if (typeof t.asm[r] == "function") {
1230
- const s = t.asm[r];
1231
- t.asm[r] = function(...n) {
1232
- try {
1233
- return s(...n);
1234
- } catch (i) {
1235
- if (!(i instanceof Error))
1236
- throw i;
1237
- if ("exitCode" in i && i?.exitCode === 0)
1238
- return;
1239
- const o = yt(
1240
- i,
1241
- t.lastAsyncifyStackSource?.stack
1242
- );
1243
- if (t.lastAsyncifyStackSource && (i.cause = t.lastAsyncifyStackSource), !e.hasListeners())
1244
- throw _t(o), i;
1245
- e.dispatchEvent(
1246
- new ft("error", {
1247
- error: i,
1248
- message: o
1249
- })
1250
- );
1251
- }
1252
- };
1253
- }
1254
- return e;
1255
- }
1256
- let N = [];
1257
- function wt() {
1258
- return N;
1259
- }
1260
- function yt(t, e) {
1261
- if (t.message === "unreachable") {
1262
- let r = Pt;
1263
- e || (r += `
1264
-
1265
- This stack trace is lacking. For a better one initialize
1266
- the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
1267
-
1268
- `), N = $t(
1269
- e || t.stack || ""
1270
- );
1271
- for (const s of N)
1272
- r += ` * ${s}
1273
- `;
1274
- return r;
1275
- }
1276
- return t.message;
1277
- }
1278
- const Pt = `
1279
- "unreachable" WASM instruction executed.
1280
-
1281
- The typical reason is a PHP function missing from the ASYNCIFY_ONLY
1282
- list when building PHP.wasm.
1283
-
1284
- You will need to file a new issue in the WordPress Playground repository
1285
- and paste this error message there:
1286
-
1287
- https://github.com/WordPress/wordpress-playground/issues/new
1288
-
1289
- If you're a core developer, the typical fix is to:
1290
-
1291
- * Isolate a minimal reproduction of the error
1292
- * Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository
1293
- * Run 'npm run fix-asyncify'
1294
- * Commit the changes, push to the repo, release updated NPM packages
1295
-
1296
- Below is a list of all the PHP functions found in the stack trace to
1297
- help with the minimal reproduction. If they're all already listed in
1298
- the Dockerfile, you'll need to trigger this error again with long stack
1299
- traces enabled. In node.js, you can do it using the --stack-trace-limit=100
1300
- CLI option:
1301
-
1302
- `, te = "\x1B[41m", bt = "\x1B[1m", re = "\x1B[0m", se = "\x1B[K";
1303
- let ne = !1;
1304
- function _t(t) {
1305
- if (!ne) {
1306
- ne = !0, console.log(`${te}
1307
- ${se}
1308
- ${bt} WASM ERROR${re}${te}`);
1309
- for (const e of t.split(`
1310
- `))
1311
- console.log(`${se} ${e} `);
1312
- console.log(`${re}`);
1313
- }
1314
- }
1315
- function $t(t) {
1316
- try {
1317
- const e = t.split(`
1318
- `).slice(1).map((r) => {
1319
- const s = r.trim().substring(3).split(" ");
1320
- return {
1321
- fn: s.length >= 2 ? s[0] : "<unknown>",
1322
- isWasm: r.includes("wasm://")
1323
- };
1324
- }).filter(
1325
- ({ fn: r, isWasm: s }) => s && !r.startsWith("dynCall_") && !r.startsWith("invoke_")
1326
- ).map(({ fn: r }) => r);
1327
- return Array.from(new Set(e));
1328
- } catch {
1329
- return [];
1330
- }
1331
- }
1332
- var Et = Object.defineProperty, vt = Object.getOwnPropertyDescriptor, g = (t, e, r, s) => {
1333
- for (var n = s > 1 ? void 0 : s ? vt(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1389
+ var xt = Object.defineProperty, Tt = Object.getOwnPropertyDescriptor, w = (t, e, r, s) => {
1390
+ for (var n = s > 1 ? void 0 : s ? Tt(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1334
1391
  (o = t[i]) && (n = (s ? o(e, r, n) : o(n)) || n);
1335
- return s && n && Et(e, r, n), n;
1392
+ return s && n && xt(e, r, n), n;
1336
1393
  };
1337
- const f = "string", _ = "number", h = Symbol("__private__dont__use");
1338
- class w {
1394
+ const f = "string", E = "number", h = Symbol("__private__dont__use");
1395
+ class g {
1339
1396
  /**
1340
1397
  * Initializes a PHP runtime.
1341
1398
  *
@@ -1344,12 +1401,13 @@ class w {
1344
1401
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
1345
1402
  */
1346
1403
  constructor(e, r) {
1347
- this.#e = [], this.#t = !1, this.#r = null, e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new ot(
1348
- new lt(this, r)
1404
+ this.#e = [], this.#t = !1, this.#s = null, this.#r = {}, e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new Pt(
1405
+ new $t(this, r)
1349
1406
  ));
1350
1407
  }
1351
1408
  #e;
1352
1409
  #t;
1410
+ #s;
1353
1411
  #r;
1354
1412
  /** @inheritDoc */
1355
1413
  get absoluteUrl() {
@@ -1372,10 +1430,10 @@ class w {
1372
1430
  initializeRuntime(e) {
1373
1431
  if (this[h])
1374
1432
  throw new Error("PHP runtime already initialized.");
1375
- const r = pt(e);
1433
+ const r = Rt(e);
1376
1434
  if (!r)
1377
1435
  throw new Error("Invalid PHP runtime id.");
1378
- this[h] = r, this.#r = gt(r);
1436
+ this[h] = r, this.#s = ht(r);
1379
1437
  }
1380
1438
  /** @inheritDoc */
1381
1439
  setPhpIniPath(e) {
@@ -1406,17 +1464,17 @@ class w {
1406
1464
  }
1407
1465
  /** @inheritDoc */
1408
1466
  async run(e) {
1409
- this.#t || (this.#n(), this.#t = !0), this.#u(e.scriptPath || ""), this.#s(e.relativeUri || ""), this.#a(e.method || "GET");
1467
+ this.#t || (this.#i(), this.#t = !0), this.#h(e.scriptPath || ""), this.#o(e.relativeUri || ""), this.#c(e.method || "GET");
1410
1468
  const { host: r, ...s } = {
1411
1469
  host: "example.com:443",
1412
- ...ge(e.headers || {})
1470
+ ...ye(e.headers || {})
1413
1471
  };
1414
- if (this.#o(r, e.protocol || "http"), this.#c(s), e.body && this.#l(e.body), e.fileInfos)
1472
+ if (this.#a(r, e.protocol || "http"), this.#l(s), e.body && this.#u(e.body), e.fileInfos)
1415
1473
  for (const n of e.fileInfos)
1416
- this.#h(n);
1417
- return e.code && this.#d(" ?>" + e.code), await this.#p();
1474
+ this.#p(n);
1475
+ return e.code && this.#f(" ?>" + e.code), this.#d(), await this.#m();
1418
1476
  }
1419
- #n() {
1477
+ #i() {
1420
1478
  if (this.#e.length > 0) {
1421
1479
  const e = this.#e.map(([r, s]) => `${r}=${s}`).join(`
1422
1480
  `) + `
@@ -1431,7 +1489,7 @@ class w {
1431
1489
  }
1432
1490
  this[h].ccall("php_wasm_init", null, [], []);
1433
1491
  }
1434
- #i() {
1492
+ #n() {
1435
1493
  const e = "/tmp/headers.json";
1436
1494
  if (!this.fileExists(e))
1437
1495
  throw new Error(
@@ -1449,7 +1507,7 @@ class w {
1449
1507
  httpStatusCode: r.status
1450
1508
  };
1451
1509
  }
1452
- #s(e) {
1510
+ #o(e) {
1453
1511
  if (this[h].ccall(
1454
1512
  "wasm_set_request_uri",
1455
1513
  null,
@@ -1465,7 +1523,7 @@ class w {
1465
1523
  );
1466
1524
  }
1467
1525
  }
1468
- #o(e, r) {
1526
+ #a(e, r) {
1469
1527
  this[h].ccall(
1470
1528
  "wasm_set_request_host",
1471
1529
  null,
@@ -1480,11 +1538,11 @@ class w {
1480
1538
  (!s || isNaN(s) || s === 80) && (s = r === "https" ? 443 : 80), this[h].ccall(
1481
1539
  "wasm_set_request_port",
1482
1540
  null,
1483
- [_],
1541
+ [E],
1484
1542
  [s]
1485
1543
  ), (r === "https" || !r && s === 443) && this.addServerGlobalEntry("HTTPS", "on");
1486
1544
  }
1487
- #a(e) {
1545
+ #c(e) {
1488
1546
  this[h].ccall(
1489
1547
  "wasm_set_request_method",
1490
1548
  null,
@@ -1492,7 +1550,7 @@ class w {
1492
1550
  [e]
1493
1551
  );
1494
1552
  }
1495
- #c(e) {
1553
+ #l(e) {
1496
1554
  e.cookie && this[h].ccall(
1497
1555
  "wasm_set_cookies",
1498
1556
  null,
@@ -1506,7 +1564,7 @@ class w {
1506
1564
  ), e["content-length"] && this[h].ccall(
1507
1565
  "wasm_set_content_length",
1508
1566
  null,
1509
- [_],
1567
+ [E],
1510
1568
  [parseInt(e["content-length"], 10)]
1511
1569
  );
1512
1570
  for (const r in e)
@@ -1515,7 +1573,7 @@ class w {
1515
1573
  e[r]
1516
1574
  );
1517
1575
  }
1518
- #l(e) {
1576
+ #u(e) {
1519
1577
  this[h].ccall(
1520
1578
  "wasm_set_request_body",
1521
1579
  null,
@@ -1524,11 +1582,11 @@ class w {
1524
1582
  ), this[h].ccall(
1525
1583
  "wasm_set_content_length",
1526
1584
  null,
1527
- [_],
1585
+ [E],
1528
1586
  [new TextEncoder().encode(e).length]
1529
1587
  );
1530
1588
  }
1531
- #u(e) {
1589
+ #h(e) {
1532
1590
  this[h].ccall(
1533
1591
  "wasm_set_path_translated",
1534
1592
  null,
@@ -1537,12 +1595,16 @@ class w {
1537
1595
  );
1538
1596
  }
1539
1597
  addServerGlobalEntry(e, r) {
1540
- this[h].ccall(
1541
- "wasm_add_SERVER_entry",
1542
- null,
1543
- [f, f],
1544
- [e, r]
1545
- );
1598
+ this.#r[e] = r;
1599
+ }
1600
+ #d() {
1601
+ for (const e in this.#r)
1602
+ this[h].ccall(
1603
+ "wasm_add_SERVER_entry",
1604
+ null,
1605
+ [f, f],
1606
+ [e, this.#r[e]]
1607
+ );
1546
1608
  }
1547
1609
  /**
1548
1610
  * Adds file information to $_FILES superglobal in PHP.
@@ -1553,18 +1615,18 @@ class w {
1553
1615
  *
1554
1616
  * @param fileInfo - File details
1555
1617
  */
1556
- #h(e) {
1618
+ #p(e) {
1557
1619
  const { key: r, name: s, type: n, data: i } = e, o = `/tmp/${Math.random().toFixed(20)}`;
1558
1620
  this.writeFile(o, i);
1559
1621
  const a = 0;
1560
1622
  this[h].ccall(
1561
1623
  "wasm_add_uploaded_file",
1562
1624
  null,
1563
- [f, f, f, f, _, _],
1625
+ [f, f, f, f, E, E],
1564
1626
  [r, s, n, o, a, i.byteLength]
1565
1627
  );
1566
1628
  }
1567
- #d(e) {
1629
+ #f(e) {
1568
1630
  this[h].ccall(
1569
1631
  "wasm_set_php_code",
1570
1632
  null,
@@ -1572,51 +1634,40 @@ class w {
1572
1634
  [e]
1573
1635
  );
1574
1636
  }
1575
- async #p() {
1637
+ async #m() {
1576
1638
  let e, r;
1577
1639
  try {
1578
- e = await new Promise(async (i, o) => {
1579
- r = (a) => {
1640
+ e = await new Promise((i, o) => {
1641
+ r = (l) => {
1580
1642
  const c = new Error("Rethrown");
1581
- c.cause = a.error, c.betterMessage = a.message, o(c);
1582
- }, this.#r?.addEventListener(
1643
+ c.cause = l.error, c.betterMessage = l.message, o(c);
1644
+ }, this.#s?.addEventListener(
1583
1645
  "error",
1584
1646
  r
1585
1647
  );
1586
- try {
1587
- i(
1588
- /**
1589
- * This is awkward, but Asyncify makes wasm_sapi_handle_request return
1590
- * Promise<Promise<number>>.
1591
- *
1592
- * @TODO: Determine whether this is a bug in emscripten or in our code.
1593
- */
1594
- await await this[h].ccall(
1595
- "wasm_sapi_handle_request",
1596
- _,
1597
- [],
1598
- []
1599
- )
1600
- );
1601
- } catch (a) {
1602
- o(a);
1603
- }
1648
+ const a = this[h].ccall(
1649
+ "wasm_sapi_handle_request",
1650
+ E,
1651
+ [],
1652
+ []
1653
+ );
1654
+ return a instanceof Promise ? a.then(i, o) : i(a);
1604
1655
  });
1605
1656
  } catch (i) {
1606
- for (const l in this)
1607
- typeof this[l] == "function" && (this[l] = () => {
1657
+ for (const c in this)
1658
+ typeof this[c] == "function" && (this[c] = () => {
1608
1659
  throw new Error(
1609
1660
  "PHP runtime has crashed – see the earlier error for details."
1610
1661
  );
1611
1662
  });
1612
- this.functionsMaybeMissingFromAsyncify = wt();
1613
- const o = i, a = "betterMessage" in o ? o.betterMessage : o.message, c = new Error(a);
1614
- throw c.cause = o, c;
1663
+ this.functionsMaybeMissingFromAsyncify = dt();
1664
+ const o = i, a = "betterMessage" in o ? o.betterMessage : o.message, l = new Error(a);
1665
+ throw l.cause = o, l;
1615
1666
  } finally {
1616
- this.#r?.removeEventListener("error", r);
1667
+ this.#s?.removeEventListener("error", r), this.#r = {};
1617
1668
  }
1618
- const { headers: s, httpStatusCode: n } = this.#i();
1619
- return new S(
1669
+ const { headers: s, httpStatusCode: n } = this.#n();
1670
+ return new _(
1620
1671
  n,
1621
1672
  s,
1622
1673
  this.readFileAsBuffer("/tmp/stdout"),
@@ -1675,56 +1726,56 @@ class w {
1675
1726
  }
1676
1727
  }
1677
1728
  }
1678
- g([
1729
+ w([
1679
1730
  m('Could not create directory "{path}"')
1680
- ], w.prototype, "mkdir", 1);
1681
- g([
1731
+ ], g.prototype, "mkdir", 1);
1732
+ w([
1682
1733
  m('Could not create directory "{path}"')
1683
- ], w.prototype, "mkdirTree", 1);
1684
- g([
1734
+ ], g.prototype, "mkdirTree", 1);
1735
+ w([
1685
1736
  m('Could not read "{path}"')
1686
- ], w.prototype, "readFileAsText", 1);
1687
- g([
1737
+ ], g.prototype, "readFileAsText", 1);
1738
+ w([
1688
1739
  m('Could not read "{path}"')
1689
- ], w.prototype, "readFileAsBuffer", 1);
1690
- g([
1740
+ ], g.prototype, "readFileAsBuffer", 1);
1741
+ w([
1691
1742
  m('Could not write to "{path}"')
1692
- ], w.prototype, "writeFile", 1);
1693
- g([
1743
+ ], g.prototype, "writeFile", 1);
1744
+ w([
1694
1745
  m('Could not unlink "{path}"')
1695
- ], w.prototype, "unlink", 1);
1696
- g([
1746
+ ], g.prototype, "unlink", 1);
1747
+ w([
1697
1748
  m('Could not move "{path}"')
1698
- ], w.prototype, "mv", 1);
1699
- g([
1749
+ ], g.prototype, "mv", 1);
1750
+ w([
1700
1751
  m('Could not remove directory "{path}"')
1701
- ], w.prototype, "rmdir", 1);
1702
- g([
1752
+ ], g.prototype, "rmdir", 1);
1753
+ w([
1703
1754
  m('Could not list files in "{path}"')
1704
- ], w.prototype, "listFiles", 1);
1705
- g([
1755
+ ], g.prototype, "listFiles", 1);
1756
+ w([
1706
1757
  m('Could not stat "{path}"')
1707
- ], w.prototype, "isDir", 1);
1708
- g([
1758
+ ], g.prototype, "isDir", 1);
1759
+ w([
1709
1760
  m('Could not stat "{path}"')
1710
- ], w.prototype, "fileExists", 1);
1711
- function ge(t) {
1761
+ ], g.prototype, "fileExists", 1);
1762
+ function ye(t) {
1712
1763
  const e = {};
1713
1764
  for (const r in t)
1714
1765
  e[r.toLowerCase()] = t[r];
1715
1766
  return e;
1716
1767
  }
1717
- const St = [
1768
+ const Ct = [
1718
1769
  "vfs",
1719
1770
  "literal",
1720
1771
  "wordpress.org/themes",
1721
1772
  "wordpress.org/plugins",
1722
1773
  "url"
1723
1774
  ];
1724
- function Rt(t) {
1725
- return t && typeof t == "object" && typeof t.resource == "string" && St.includes(t.resource);
1775
+ function Ft(t) {
1776
+ return t && typeof t == "object" && typeof t.resource == "string" && Ct.includes(t.resource);
1726
1777
  }
1727
- class b {
1778
+ class $ {
1728
1779
  /**
1729
1780
  * Creates a new Resource based on the given file reference
1730
1781
  *
@@ -1736,24 +1787,24 @@ class b {
1736
1787
  let n;
1737
1788
  switch (e.resource) {
1738
1789
  case "vfs":
1739
- n = new xt(e, s);
1790
+ n = new kt(e, s);
1740
1791
  break;
1741
1792
  case "literal":
1742
- n = new Tt(e, s);
1793
+ n = new Ot(e, s);
1743
1794
  break;
1744
1795
  case "wordpress.org/themes":
1745
- n = new Ft(e, s);
1796
+ n = new Ut(e, s);
1746
1797
  break;
1747
1798
  case "wordpress.org/plugins":
1748
- n = new Ot(e, s);
1799
+ n = new Ht(e, s);
1749
1800
  break;
1750
1801
  case "url":
1751
- n = new kt(e, s);
1802
+ n = new Lt(e, s);
1752
1803
  break;
1753
1804
  default:
1754
1805
  throw new Error(`Invalid resource: ${e}`);
1755
1806
  }
1756
- return n = new At(n), r && (n = new Lt(n, r)), n;
1807
+ return n = new It(n), r && (n = new Nt(n, r)), n;
1757
1808
  }
1758
1809
  setPlayground(e) {
1759
1810
  this.playground = e;
@@ -1763,7 +1814,7 @@ class b {
1763
1814
  return !1;
1764
1815
  }
1765
1816
  }
1766
- class xt extends b {
1817
+ class kt extends $ {
1767
1818
  /**
1768
1819
  * Creates a new instance of `VFSResource`.
1769
1820
  * @param playground The playground client.
@@ -1785,7 +1836,7 @@ class xt extends b {
1785
1836
  return this.resource.path;
1786
1837
  }
1787
1838
  }
1788
- class Tt extends b {
1839
+ class Ot extends $ {
1789
1840
  /**
1790
1841
  * Creates a new instance of `LiteralResource`.
1791
1842
  * @param resource The literal reference.
@@ -1803,7 +1854,7 @@ class Tt extends b {
1803
1854
  return this.resource.name;
1804
1855
  }
1805
1856
  }
1806
- class q extends b {
1857
+ class z extends $ {
1807
1858
  /**
1808
1859
  * Creates a new instance of `FetchResource`.
1809
1860
  * @param progress The progress tracker.
@@ -1816,9 +1867,9 @@ class q extends b {
1816
1867
  this.progress?.setCaption(this.caption);
1817
1868
  const e = this.getURL();
1818
1869
  let r = await fetch(e);
1819
- if (r = await nt(
1870
+ if (r = await ct(
1820
1871
  r,
1821
- this.progress?.loadingListener ?? Ct
1872
+ this.progress?.loadingListener ?? At
1822
1873
  ), r.status !== 200)
1823
1874
  throw new Error(`Could not download "${e}"`);
1824
1875
  return new File([await r.blob()], this.name);
@@ -1843,9 +1894,9 @@ class q extends b {
1843
1894
  return !0;
1844
1895
  }
1845
1896
  }
1846
- const Ct = () => {
1897
+ const At = () => {
1847
1898
  };
1848
- class kt extends q {
1899
+ class Lt extends z {
1849
1900
  /**
1850
1901
  * Creates a new instance of `UrlResource`.
1851
1902
  * @param resource The URL reference.
@@ -1864,10 +1915,10 @@ class kt extends q {
1864
1915
  }
1865
1916
  }
1866
1917
  let j = "https://playground.wordpress.net/plugin-proxy";
1867
- function sr(t) {
1918
+ function ar(t) {
1868
1919
  j = t;
1869
1920
  }
1870
- class Ft extends q {
1921
+ class Ut extends z {
1871
1922
  constructor(e, r) {
1872
1923
  super(r), this.resource = e;
1873
1924
  }
@@ -1875,11 +1926,11 @@ class Ft extends q {
1875
1926
  return L(this.resource.slug);
1876
1927
  }
1877
1928
  getURL() {
1878
- const e = we(this.resource.slug);
1929
+ const e = Pe(this.resource.slug);
1879
1930
  return `${j}?theme=` + e;
1880
1931
  }
1881
1932
  }
1882
- class Ot extends q {
1933
+ class Ht extends z {
1883
1934
  constructor(e, r) {
1884
1935
  super(r), this.resource = e;
1885
1936
  }
@@ -1889,14 +1940,14 @@ class Ot extends q {
1889
1940
  }
1890
1941
  /** @inheritDoc */
1891
1942
  getURL() {
1892
- const e = we(this.resource.slug);
1943
+ const e = Pe(this.resource.slug);
1893
1944
  return `${j}?plugin=` + e;
1894
1945
  }
1895
1946
  }
1896
- function we(t) {
1947
+ function Pe(t) {
1897
1948
  return !t || t.endsWith(".zip") ? t : t + ".latest-stable.zip";
1898
1949
  }
1899
- class ye extends b {
1950
+ class be extends $ {
1900
1951
  constructor(e) {
1901
1952
  super(), this.resource = e;
1902
1953
  }
@@ -1925,13 +1976,13 @@ class ye extends b {
1925
1976
  return this.resource.isAsync;
1926
1977
  }
1927
1978
  }
1928
- class At extends ye {
1979
+ class It extends be {
1929
1980
  /** @inheritDoc */
1930
1981
  async resolve() {
1931
1982
  return this.promise || (this.promise = super.resolve()), this.promise;
1932
1983
  }
1933
1984
  }
1934
- class Lt extends ye {
1985
+ class Nt extends be {
1935
1986
  constructor(e, r) {
1936
1987
  super(e), this.semaphore = r;
1937
1988
  }
@@ -1940,18 +1991,18 @@ class Lt extends ye {
1940
1991
  return this.isAsync ? this.semaphore.run(() => super.resolve()) : super.resolve();
1941
1992
  }
1942
1993
  }
1943
- const Ut = ["6.2", "6.1", "6.0", "5.9"];
1944
- function Ht(t, {
1994
+ const Wt = ["6.2", "6.1", "6.0", "5.9"];
1995
+ function Mt(t, {
1945
1996
  progress: e = new U(),
1946
- semaphore: r = new de({ concurrency: 3 }),
1997
+ semaphore: r = new fe({ concurrency: 3 }),
1947
1998
  onStepCompleted: s = () => {
1948
1999
  }
1949
2000
  } = {}) {
1950
- const n = (t.steps || []).filter(It), i = n.reduce(
1951
- (a, c) => a + (c.progress?.weight || 1),
2001
+ const n = (t.steps || []).filter(Dt), i = n.reduce(
2002
+ (a, l) => a + (l.progress?.weight || 1),
1952
2003
  0
1953
2004
  ), o = n.map(
1954
- (a) => Nt(a, {
2005
+ (a) => qt(a, {
1955
2006
  semaphore: r,
1956
2007
  rootProgressTracker: e,
1957
2008
  totalProgressWeight: i
@@ -1959,25 +2010,25 @@ function Ht(t, {
1959
2010
  );
1960
2011
  return {
1961
2012
  versions: {
1962
- php: ie(
2013
+ php: ae(
1963
2014
  t.preferredVersions?.php,
1964
- D,
1965
- it
2015
+ q,
2016
+ yt
1966
2017
  ),
1967
- wp: ie(
2018
+ wp: ae(
1968
2019
  t.preferredVersions?.wp,
1969
- Ut,
2020
+ Wt,
1970
2021
  "6.2"
1971
2022
  )
1972
2023
  },
1973
2024
  run: async (a) => {
1974
2025
  try {
1975
- for (const { resources: c } of o)
1976
- for (const l of c)
1977
- l.setPlayground(a), l.isAsync && l.resolve();
1978
- for (const { run: c, step: l } of o) {
1979
- const u = await c(a);
1980
- s(u, l);
2026
+ for (const { resources: l } of o)
2027
+ for (const c of l)
2028
+ c.setPlayground(a), c.isAsync && c.resolve();
2029
+ for (const { run: l, step: c } of o) {
2030
+ const u = await l(a);
2031
+ s(u, c);
1981
2032
  }
1982
2033
  try {
1983
2034
  await a.goTo(
@@ -1991,13 +2042,13 @@ function Ht(t, {
1991
2042
  }
1992
2043
  };
1993
2044
  }
1994
- function ie(t, e, r) {
2045
+ function ae(t, e, r) {
1995
2046
  return t && e.includes(t) ? t : r;
1996
2047
  }
1997
- function It(t) {
2048
+ function Dt(t) {
1998
2049
  return !!(typeof t == "object" && t);
1999
2050
  }
2000
- function Nt(t, {
2051
+ function qt(t, {
2001
2052
  semaphore: e,
2002
2053
  rootProgressTracker: r,
2003
2054
  totalProgressWeight: s
@@ -2007,15 +2058,15 @@ function Nt(t, {
2007
2058
  ), i = {};
2008
2059
  for (const u of Object.keys(t)) {
2009
2060
  let d = t[u];
2010
- Rt(d) && (d = b.create(d, {
2061
+ Ft(d) && (d = $.create(d, {
2011
2062
  semaphore: e
2012
2063
  })), i[u] = d;
2013
2064
  }
2014
2065
  const o = async (u) => {
2015
2066
  try {
2016
- return n.fillSlowly(), await rt[t.step](
2067
+ return n.fillSlowly(), await ot[t.step](
2017
2068
  u,
2018
- await Mt(i),
2069
+ await zt(i),
2019
2070
  {
2020
2071
  tracker: n,
2021
2072
  initialCaption: t.progress?.caption
@@ -2024,30 +2075,30 @@ function Nt(t, {
2024
2075
  } finally {
2025
2076
  n.finish();
2026
2077
  }
2027
- }, a = oe(i), c = oe(i).filter(
2078
+ }, a = ce(i), l = ce(i).filter(
2028
2079
  (u) => u.isAsync
2029
- ), l = 1 / (c.length + 1);
2030
- for (const u of c)
2031
- u.progress = n.stage(l);
2080
+ ), c = 1 / (l.length + 1);
2081
+ for (const u of l)
2082
+ u.progress = n.stage(c);
2032
2083
  return { run: o, step: t, resources: a };
2033
2084
  }
2034
- function oe(t) {
2085
+ function ce(t) {
2035
2086
  const e = [];
2036
2087
  for (const r in t) {
2037
2088
  const s = t[r];
2038
- s instanceof b && e.push(s);
2089
+ s instanceof $ && e.push(s);
2039
2090
  }
2040
2091
  return e;
2041
2092
  }
2042
- async function Mt(t) {
2093
+ async function zt(t) {
2043
2094
  const e = {};
2044
2095
  for (const r in t) {
2045
2096
  const s = t[r];
2046
- s instanceof b ? e[r] = await s.resolve() : e[r] = s;
2097
+ s instanceof $ ? e[r] = await s.resolve() : e[r] = s;
2047
2098
  }
2048
2099
  return e;
2049
2100
  }
2050
- async function Wt(t, e) {
2101
+ async function jt(t, e) {
2051
2102
  await t.run(e);
2052
2103
  }
2053
2104
  /**
@@ -2055,8 +2106,8 @@ async function Wt(t, e) {
2055
2106
  * Copyright 2019 Google LLC
2056
2107
  * SPDX-License-Identifier: Apache-2.0
2057
2108
  */
2058
- const Pe = Symbol("Comlink.proxy"), Dt = Symbol("Comlink.endpoint"), zt = Symbol("Comlink.releaseProxy"), I = Symbol("Comlink.finalizer"), C = Symbol("Comlink.thrown"), be = (t) => typeof t == "object" && t !== null || typeof t == "function", qt = {
2059
- canHandle: (t) => be(t) && t[Pe],
2109
+ const _e = Symbol("Comlink.proxy"), Bt = Symbol("Comlink.endpoint"), Vt = Symbol("Comlink.releaseProxy"), I = Symbol("Comlink.finalizer"), T = Symbol("Comlink.thrown"), $e = (t) => typeof t == "object" && t !== null || typeof t == "function", Gt = {
2110
+ canHandle: (t) => $e(t) && t[_e],
2060
2111
  serialize(t) {
2061
2112
  const { port1: e, port2: r } = new MessageChannel();
2062
2113
  return B(t, e), [r, [r]];
@@ -2064,8 +2115,8 @@ const Pe = Symbol("Comlink.proxy"), Dt = Symbol("Comlink.endpoint"), zt = Symbol
2064
2115
  deserialize(t) {
2065
2116
  return t.start(), V(t);
2066
2117
  }
2067
- }, jt = {
2068
- canHandle: (t) => be(t) && C in t,
2118
+ }, Jt = {
2119
+ canHandle: (t) => $e(t) && T in t,
2069
2120
  serialize({ value: t }) {
2070
2121
  let e;
2071
2122
  return t instanceof Error ? e = {
@@ -2081,10 +2132,10 @@ const Pe = Symbol("Comlink.proxy"), Dt = Symbol("Comlink.endpoint"), zt = Symbol
2081
2132
  throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
2082
2133
  }
2083
2134
  }, R = /* @__PURE__ */ new Map([
2084
- ["proxy", qt],
2085
- ["throw", jt]
2135
+ ["proxy", Gt],
2136
+ ["throw", Jt]
2086
2137
  ]);
2087
- function Bt(t, e) {
2138
+ function Yt(t, e) {
2088
2139
  for (const r of t)
2089
2140
  if (e === r || r === "*" || r instanceof RegExp && r.test(e))
2090
2141
  return !0;
@@ -2094,160 +2145,160 @@ function B(t, e = globalThis, r = ["*"]) {
2094
2145
  e.addEventListener("message", function s(n) {
2095
2146
  if (!n || !n.data)
2096
2147
  return;
2097
- if (!Bt(r, n.origin)) {
2148
+ if (!Yt(r, n.origin)) {
2098
2149
  console.warn(`Invalid origin '${n.origin}' for comlink proxy`);
2099
2150
  return;
2100
2151
  }
2101
- const { id: i, type: o, path: a } = Object.assign({ path: [] }, n.data), c = (n.data.argumentList || []).map(P);
2102
- let l;
2152
+ const { id: i, type: o, path: a } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(b);
2153
+ let c;
2103
2154
  try {
2104
2155
  const u = a.slice(0, -1).reduce((p, y) => p[y], t), d = a.reduce((p, y) => p[y], t);
2105
2156
  switch (o) {
2106
2157
  case "GET":
2107
- l = d;
2158
+ c = d;
2108
2159
  break;
2109
2160
  case "SET":
2110
- u[a.slice(-1)[0]] = P(n.data.value), l = !0;
2161
+ u[a.slice(-1)[0]] = b(n.data.value), c = !0;
2111
2162
  break;
2112
2163
  case "APPLY":
2113
- l = d.apply(u, c);
2164
+ c = d.apply(u, l);
2114
2165
  break;
2115
2166
  case "CONSTRUCT":
2116
2167
  {
2117
- const p = new d(...c);
2118
- l = ve(p);
2168
+ const p = new d(...l);
2169
+ c = Re(p);
2119
2170
  }
2120
2171
  break;
2121
2172
  case "ENDPOINT":
2122
2173
  {
2123
2174
  const { port1: p, port2: y } = new MessageChannel();
2124
- B(t, y), l = Kt(p, [p]);
2175
+ B(t, y), c = er(p, [p]);
2125
2176
  }
2126
2177
  break;
2127
2178
  case "RELEASE":
2128
- l = void 0;
2179
+ c = void 0;
2129
2180
  break;
2130
2181
  default:
2131
2182
  return;
2132
2183
  }
2133
2184
  } catch (u) {
2134
- l = { value: u, [C]: 0 };
2185
+ c = { value: u, [T]: 0 };
2135
2186
  }
2136
- Promise.resolve(l).catch((u) => ({ value: u, [C]: 0 })).then((u) => {
2187
+ Promise.resolve(c).catch((u) => ({ value: u, [T]: 0 })).then((u) => {
2137
2188
  const [d, p] = A(u);
2138
- e.postMessage(Object.assign(Object.assign({}, d), { id: i }), p), o === "RELEASE" && (e.removeEventListener("message", s), _e(e), I in t && typeof t[I] == "function" && t[I]());
2189
+ e.postMessage(Object.assign(Object.assign({}, d), { id: i }), p), o === "RELEASE" && (e.removeEventListener("message", s), Ee(e), I in t && typeof t[I] == "function" && t[I]());
2139
2190
  }).catch((u) => {
2140
2191
  const [d, p] = A({
2141
2192
  value: new TypeError("Unserializable return value"),
2142
- [C]: 0
2193
+ [T]: 0
2143
2194
  });
2144
2195
  e.postMessage(Object.assign(Object.assign({}, d), { id: i }), p);
2145
2196
  });
2146
2197
  }), e.start && e.start();
2147
2198
  }
2148
- function Vt(t) {
2199
+ function Kt(t) {
2149
2200
  return t.constructor.name === "MessagePort";
2150
2201
  }
2151
- function _e(t) {
2152
- Vt(t) && t.close();
2202
+ function Ee(t) {
2203
+ Kt(t) && t.close();
2153
2204
  }
2154
2205
  function V(t, e) {
2155
- return M(t, [], e);
2206
+ return W(t, [], e);
2156
2207
  }
2157
- function T(t) {
2208
+ function x(t) {
2158
2209
  if (t)
2159
2210
  throw new Error("Proxy has been released and is not useable");
2160
2211
  }
2161
- function $e(t) {
2162
- return $(t, {
2212
+ function ve(t) {
2213
+ return v(t, {
2163
2214
  type: "RELEASE"
2164
2215
  }).then(() => {
2165
- _e(t);
2216
+ Ee(t);
2166
2217
  });
2167
2218
  }
2168
- const F = /* @__PURE__ */ new WeakMap(), O = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
2169
- const e = (F.get(t) || 0) - 1;
2170
- F.set(t, e), e === 0 && $e(t);
2219
+ const k = /* @__PURE__ */ new WeakMap(), O = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
2220
+ const e = (k.get(t) || 0) - 1;
2221
+ k.set(t, e), e === 0 && ve(t);
2171
2222
  });
2172
- function Gt(t, e) {
2173
- const r = (F.get(e) || 0) + 1;
2174
- F.set(e, r), O && O.register(t, e, t);
2223
+ function Qt(t, e) {
2224
+ const r = (k.get(e) || 0) + 1;
2225
+ k.set(e, r), O && O.register(t, e, t);
2175
2226
  }
2176
- function Jt(t) {
2227
+ function Xt(t) {
2177
2228
  O && O.unregister(t);
2178
2229
  }
2179
- function M(t, e = [], r = function() {
2230
+ function W(t, e = [], r = function() {
2180
2231
  }) {
2181
2232
  let s = !1;
2182
2233
  const n = new Proxy(r, {
2183
2234
  get(i, o) {
2184
- if (T(s), o === zt)
2235
+ if (x(s), o === Vt)
2185
2236
  return () => {
2186
- Jt(n), $e(t), s = !0;
2237
+ Xt(n), ve(t), s = !0;
2187
2238
  };
2188
2239
  if (o === "then") {
2189
2240
  if (e.length === 0)
2190
2241
  return { then: () => n };
2191
- const a = $(t, {
2242
+ const a = v(t, {
2192
2243
  type: "GET",
2193
- path: e.map((c) => c.toString())
2194
- }).then(P);
2244
+ path: e.map((l) => l.toString())
2245
+ }).then(b);
2195
2246
  return a.then.bind(a);
2196
2247
  }
2197
- return M(t, [...e, o]);
2248
+ return W(t, [...e, o]);
2198
2249
  },
2199
2250
  set(i, o, a) {
2200
- T(s);
2201
- const [c, l] = A(a);
2202
- return $(t, {
2251
+ x(s);
2252
+ const [l, c] = A(a);
2253
+ return v(t, {
2203
2254
  type: "SET",
2204
2255
  path: [...e, o].map((u) => u.toString()),
2205
- value: c
2206
- }, l).then(P);
2256
+ value: l
2257
+ }, c).then(b);
2207
2258
  },
2208
2259
  apply(i, o, a) {
2209
- T(s);
2210
- const c = e[e.length - 1];
2211
- if (c === Dt)
2212
- return $(t, {
2260
+ x(s);
2261
+ const l = e[e.length - 1];
2262
+ if (l === Bt)
2263
+ return v(t, {
2213
2264
  type: "ENDPOINT"
2214
- }).then(P);
2215
- if (c === "bind")
2216
- return M(t, e.slice(0, -1));
2217
- const [l, u] = ae(a);
2218
- return $(t, {
2265
+ }).then(b);
2266
+ if (l === "bind")
2267
+ return W(t, e.slice(0, -1));
2268
+ const [c, u] = le(a);
2269
+ return v(t, {
2219
2270
  type: "APPLY",
2220
2271
  path: e.map((d) => d.toString()),
2221
- argumentList: l
2222
- }, u).then(P);
2272
+ argumentList: c
2273
+ }, u).then(b);
2223
2274
  },
2224
2275
  construct(i, o) {
2225
- T(s);
2226
- const [a, c] = ae(o);
2227
- return $(t, {
2276
+ x(s);
2277
+ const [a, l] = le(o);
2278
+ return v(t, {
2228
2279
  type: "CONSTRUCT",
2229
- path: e.map((l) => l.toString()),
2280
+ path: e.map((c) => c.toString()),
2230
2281
  argumentList: a
2231
- }, c).then(P);
2282
+ }, l).then(b);
2232
2283
  }
2233
2284
  });
2234
- return Gt(n, t), n;
2285
+ return Qt(n, t), n;
2235
2286
  }
2236
- function Yt(t) {
2287
+ function Zt(t) {
2237
2288
  return Array.prototype.concat.apply([], t);
2238
2289
  }
2239
- function ae(t) {
2290
+ function le(t) {
2240
2291
  const e = t.map(A);
2241
- return [e.map((r) => r[0]), Yt(e.map((r) => r[1]))];
2292
+ return [e.map((r) => r[0]), Zt(e.map((r) => r[1]))];
2242
2293
  }
2243
- const Ee = /* @__PURE__ */ new WeakMap();
2244
- function Kt(t, e) {
2245
- return Ee.set(t, e), t;
2294
+ const Se = /* @__PURE__ */ new WeakMap();
2295
+ function er(t, e) {
2296
+ return Se.set(t, e), t;
2246
2297
  }
2247
- function ve(t) {
2248
- return Object.assign(t, { [Pe]: !0 });
2298
+ function Re(t) {
2299
+ return Object.assign(t, { [_e]: !0 });
2249
2300
  }
2250
- function Qt(t, e = globalThis, r = "*") {
2301
+ function tr(t, e = globalThis, r = "*") {
2251
2302
  return {
2252
2303
  postMessage: (s, n) => t.postMessage(s, r, n),
2253
2304
  addEventListener: e.addEventListener.bind(e),
@@ -2272,10 +2323,10 @@ function A(t) {
2272
2323
  type: "RAW",
2273
2324
  value: t
2274
2325
  },
2275
- Ee.get(t) || []
2326
+ Se.get(t) || []
2276
2327
  ];
2277
2328
  }
2278
- function P(t) {
2329
+ function b(t) {
2279
2330
  switch (t.type) {
2280
2331
  case "HANDLER":
2281
2332
  return R.get(t.name).deserialize(t.value);
@@ -2283,27 +2334,27 @@ function P(t) {
2283
2334
  return t.value;
2284
2335
  }
2285
2336
  }
2286
- function $(t, e, r) {
2337
+ function v(t, e, r) {
2287
2338
  return new Promise((s) => {
2288
- const n = Xt();
2339
+ const n = rr();
2289
2340
  t.addEventListener("message", function i(o) {
2290
2341
  !o.data || !o.data.id || o.data.id !== n || (t.removeEventListener("message", i), s(o.data));
2291
2342
  }), t.start && t.start(), t.postMessage(Object.assign({ id: n }, e), r);
2292
2343
  });
2293
2344
  }
2294
- function Xt() {
2345
+ function rr() {
2295
2346
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
2296
2347
  }
2297
- function Se(t) {
2298
- Zt();
2299
- const e = t instanceof Worker ? t : Qt(t), r = V(e), s = Re(r);
2348
+ function xe(t) {
2349
+ sr();
2350
+ const e = t instanceof Worker ? t : tr(t), r = V(e), s = Te(r);
2300
2351
  return new Proxy(s, {
2301
2352
  get: (n, i) => i === "isConnected" ? () => r.isConnected() : r[i]
2302
2353
  });
2303
2354
  }
2304
- let ce = !1;
2305
- function Zt() {
2306
- ce || (ce = !0, R.set("EVENT", {
2355
+ let ue = !1;
2356
+ function sr() {
2357
+ ue || (ue = !0, R.set("EVENT", {
2307
2358
  canHandle: (t) => t instanceof CustomEvent,
2308
2359
  serialize: (t) => [
2309
2360
  {
@@ -2328,24 +2379,24 @@ function Zt() {
2328
2379
  return [t.toRawData(), []];
2329
2380
  },
2330
2381
  deserialize(t) {
2331
- return S.fromRawData(t);
2382
+ return _.fromRawData(t);
2332
2383
  }
2333
2384
  }));
2334
2385
  }
2335
- function Re(t) {
2386
+ function Te(t) {
2336
2387
  return new Proxy(t, {
2337
2388
  get(e, r) {
2338
2389
  switch (typeof e[r]) {
2339
2390
  case "function":
2340
2391
  return (...s) => e[r](...s);
2341
2392
  case "object":
2342
- return e[r] === null ? e[r] : Re(e[r]);
2393
+ return e[r] === null ? e[r] : Te(e[r]);
2343
2394
  case "undefined":
2344
2395
  case "number":
2345
2396
  case "string":
2346
2397
  return e[r];
2347
2398
  default:
2348
- return ve(e[r]);
2399
+ return Re(e[r]);
2349
2400
  }
2350
2401
  }
2351
2402
  });
@@ -2353,7 +2404,7 @@ function Re(t) {
2353
2404
  (function() {
2354
2405
  return typeof navigator < "u" && navigator?.userAgent?.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
2355
2406
  })();
2356
- async function er({
2407
+ async function nr({
2357
2408
  iframe: t,
2358
2409
  blueprint: e,
2359
2410
  remoteUrl: r,
@@ -2361,94 +2412,96 @@ async function er({
2361
2412
  disableProgressBar: n,
2362
2413
  onBlueprintStepCompleted: i
2363
2414
  }) {
2364
- if (tr(r), r = ue(r, {
2415
+ if (ir(r), r = de(r, {
2365
2416
  progressbar: !n
2366
2417
  }), s.setCaption("Preparing WordPress"), !e)
2367
- return le(t, r, s);
2368
- const o = Ht(e, {
2418
+ return he(t, r, s);
2419
+ const o = Mt(e, {
2369
2420
  progress: s.stage(0.5),
2370
2421
  onStepCompleted: i
2371
- }), a = await le(
2422
+ }), a = await he(
2372
2423
  t,
2373
- ue(r, {
2424
+ de(r, {
2374
2425
  php: o.versions.php,
2375
2426
  wp: o.versions.wp
2376
2427
  }),
2377
2428
  s
2378
2429
  );
2379
- return await Wt(o, a), s.finish(), a;
2430
+ return await jt(o, a), s.finish(), a;
2380
2431
  }
2381
- async function le(t, e, r) {
2432
+ async function he(t, e, r) {
2382
2433
  await new Promise((i) => {
2383
2434
  t.src = e, t.addEventListener("load", i, !1);
2384
2435
  });
2385
- const s = Se(
2436
+ const s = xe(
2386
2437
  t.contentWindow
2387
2438
  );
2388
2439
  await s.isConnected(), r.pipe(s);
2389
2440
  const n = r.stage();
2390
2441
  return await s.onDownloadProgress(n.loadingListener), await s.isReady(), n.finish(), s;
2391
2442
  }
2392
- const k = "https://playground.wordpress.net";
2393
- function tr(t) {
2394
- const e = new URL(t, k);
2395
- if ((e.origin === k || e.hostname === "localhost") && e.pathname !== "/remote.html")
2443
+ const C = "https://playground.wordpress.net";
2444
+ function ir(t) {
2445
+ const e = new URL(t, C);
2446
+ if ((e.origin === C || e.hostname === "localhost") && e.pathname !== "/remote.html")
2396
2447
  throw new Error(
2397
- `Invalid remote URL: ${e}. Expected origin to be ${k}/remote.html.`
2448
+ `Invalid remote URL: ${e}. Expected origin to be ${C}/remote.html.`
2398
2449
  );
2399
2450
  }
2400
- function ue(t, e) {
2401
- const r = new URL(t, k), s = new URLSearchParams(r.search);
2451
+ function de(t, e) {
2452
+ const r = new URL(t, C), s = new URLSearchParams(r.search);
2402
2453
  for (const [n, i] of Object.entries(e))
2403
2454
  i != null && i !== !1 && s.set(n, i.toString());
2404
2455
  return r.search = s.toString(), r.toString();
2405
2456
  }
2406
- async function nr(t, e) {
2457
+ async function cr(t, e) {
2407
2458
  if (console.warn(
2408
2459
  "`connectPlayground` is deprecated and will be removed. Use `startPlayground` instead."
2409
2460
  ), e?.loadRemote)
2410
- return er({
2461
+ return nr({
2411
2462
  iframe: t,
2412
2463
  remoteUrl: e.loadRemote
2413
2464
  });
2414
- const r = Se(
2465
+ const r = xe(
2415
2466
  t.contentWindow
2416
2467
  );
2417
2468
  return await r.isConnected(), r;
2418
2469
  }
2419
2470
  export {
2420
- it as LatestSupportedPHPVersion,
2421
- D as SupportedPHPVersions,
2422
- rr as SupportedPHPVersionsList,
2471
+ yt as LatestSupportedPHPVersion,
2472
+ q as SupportedPHPVersions,
2473
+ or as SupportedPHPVersionsList,
2423
2474
  ke as activatePlugin,
2424
- Fe as applyWordPressPatches,
2425
- Ht as compileBlueprint,
2426
- nr as connectPlayground,
2427
- Ie as cp,
2428
- qe as defineSiteUrl,
2429
- he as defineWpConfigConsts,
2430
- Ge as importFile,
2431
- Ke as installPlugin,
2432
- Qe as installTheme,
2433
- Xe as login,
2434
- Me as mkdir,
2435
- Ne as mv,
2436
- v as phpVar,
2437
- W as phpVars,
2438
- Ve as replaceSite,
2439
- He as request,
2440
- We as rm,
2441
- De as rmdir,
2442
- Wt as runBlueprintSteps,
2443
- Ae as runPHP,
2444
- Le as runPHPWithOptions,
2445
- Ze as runWpInstallationWizard,
2446
- Ue as setPhpIniEntry,
2447
- sr as setPluginProxyURL,
2448
- et as setSiteOptions,
2449
- er as startPlaygroundWeb,
2450
- pe as unzip,
2451
- tt as updateUserMeta,
2452
- ze as writeFile,
2453
- Be as zipEntireSite
2475
+ Oe as activateTheme,
2476
+ Le as applyWordPressPatches,
2477
+ Mt as compileBlueprint,
2478
+ cr as connectPlayground,
2479
+ Me as cp,
2480
+ Ve as defineSiteUrl,
2481
+ it as defineVirtualWpConfigConsts,
2482
+ pe as defineWpConfigConsts,
2483
+ Ke as importFile,
2484
+ Ze as installPlugin,
2485
+ et as installTheme,
2486
+ tt as login,
2487
+ qe as mkdir,
2488
+ De as mv,
2489
+ S as phpVar,
2490
+ M as phpVars,
2491
+ Ye as replaceSite,
2492
+ We as request,
2493
+ ze as rm,
2494
+ je as rmdir,
2495
+ jt as runBlueprintSteps,
2496
+ He as runPHP,
2497
+ Ie as runPHPWithOptions,
2498
+ rt as runWpInstallationWizard,
2499
+ Ne as setPhpIniEntry,
2500
+ ar as setPluginProxyURL,
2501
+ st as setSiteOptions,
2502
+ nr as startPlaygroundWeb,
2503
+ me as unzip,
2504
+ nt as updateUserMeta,
2505
+ Be as writeFile,
2506
+ Je as zipEntireSite
2454
2507
  };