@wp-playground/client 0.1.38 → 0.1.40

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,4 +1,4 @@
1
- function T(t) {
1
+ function x(t) {
2
2
  return new DOMParser().parseFromString(t.text, "text/html");
3
3
  }
4
4
  function L(t) {
@@ -6,14 +6,15 @@ function L(t) {
6
6
  return e.charAt(0).toUpperCase() + e.slice(1).toLowerCase();
7
7
  }
8
8
  async function E(t, e, r) {
9
- await t.writeFile(e, r(await t.readFileAsText(e)));
9
+ let s = "";
10
+ await t.fileExists(e) && (s = await t.readFileAsText(e)), await t.writeFile(e, r(s));
10
11
  }
11
- async function be(t) {
12
+ async function Ce(t) {
12
13
  return new Uint8Array(await t.arrayBuffer());
13
14
  }
14
- const _e = async (t, { plugin: e }, r) => {
15
+ const ke = async (t, { plugin: e }, r) => {
15
16
  r?.tracker.setCaption(`Activating ${e}`);
16
- const i = T(
17
+ const i = x(
17
18
  await t.request({
18
19
  url: "/wp-admin/plugins.php"
19
20
  })
@@ -23,15 +24,15 @@ const _e = async (t, { plugin: e }, r) => {
23
24
  await t.request({
24
25
  url: "/wp-admin/" + i
25
26
  });
26
- }, $e = async (t, e) => {
27
- const r = new Se(
27
+ }, Fe = async (t, e) => {
28
+ const r = new Oe(
28
29
  t,
29
30
  e.siteUrl,
30
31
  e.wordpressPath || "/wordpress"
31
32
  );
32
33
  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();
33
34
  };
34
- class Se {
35
+ class Oe {
35
36
  constructor(e, r, s) {
36
37
  this.php = e, this.scopedSiteUrl = r, this.wordpressPath = s;
37
38
  }
@@ -82,39 +83,51 @@ class Se {
82
83
  );
83
84
  }
84
85
  }
85
- const ve = async (t, { code: e }) => await t.run({ code: e }), Ee = async (t, { options: e }) => await t.run(e), Re = async (t, { key: e, value: r }) => {
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 }) => {
86
87
  await t.setPhpIniEntry(e, r);
87
- }, Te = async (t, { request: e }) => await t.request(e), xe = async (t, { fromPath: e, toPath: r }) => {
88
+ }, He = async (t, { request: e }) => await t.request(e), Ie = async (t, { fromPath: e, toPath: r }) => {
88
89
  await t.writeFile(
89
90
  r,
90
91
  await t.readFileAsBuffer(e)
91
92
  );
92
- }, Ce = async (t, { fromPath: e, toPath: r }) => {
93
+ }, Ne = async (t, { fromPath: e, toPath: r }) => {
93
94
  await t.mv(e, r);
94
- }, Fe = async (t, { path: e }) => {
95
+ }, Me = async (t, { path: e }) => {
95
96
  await t.mkdir(e);
96
- }, ke = async (t, { path: e }) => {
97
+ }, We = async (t, { path: e }) => {
97
98
  await t.unlink(e);
98
- }, Oe = async (t, { path: e }) => {
99
+ }, De = async (t, { path: e }) => {
99
100
  await t.rmdir(e);
100
- }, Ue = async (t, { path: e, data: r }) => {
101
- r instanceof File && (r = await be(r)), await t.writeFile(e, r);
102
- }, Le = async (t, { siteUrl: 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 }) => {
103
104
  const r = await t.documentRoot;
104
105
  await E(
106
+ t,
107
+ `${r}/playground-consts.json`,
108
+ (s) => JSON.stringify({
109
+ ...JSON.parse(s || "{}"),
110
+ ...e
111
+ })
112
+ ), await E(
105
113
  t,
106
114
  `${r}/wp-config.php`,
107
- (s) => `<?php
108
- if ( ! defined( 'WP_HOME' ) ) {
109
- define('WP_HOME', "${e}");
110
- }
111
- if ( ! defined( 'WP_SITEURL' ) ) {
112
- define('WP_SITEURL', "${e}");
113
- }
114
- ?>${s}`
115
+ (s) => s.includes("playground-consts.json") ? s : `<?php
116
+ $consts = json_decode(file_get_contents('./playground-consts.json'), true);
117
+ foreach ($consts as $const => $value) {
118
+ if (!defined($const)) {
119
+ define($const, $value);
120
+ }
121
+ }
122
+ ?>${s}`
115
123
  );
116
- };
117
- class se {
124
+ }, qe = async (t, { siteUrl: e }) => await he(t, {
125
+ consts: {
126
+ WP_HOME: e,
127
+ WP_SITEURL: e
128
+ }
129
+ });
130
+ class de {
118
131
  constructor({ concurrency: e }) {
119
132
  this._running = 0, this.concurrency = e, this.queue = [];
120
133
  }
@@ -139,29 +152,29 @@ class se {
139
152
  }
140
153
  }
141
154
  }
142
- const Ae = Symbol("literal");
143
- function S(t) {
155
+ const je = Symbol("literal");
156
+ function v(t) {
144
157
  if (typeof t == "string")
145
158
  return t.startsWith("$") ? t : JSON.stringify(t);
146
159
  if (typeof t == "number")
147
160
  return t.toString();
148
161
  if (Array.isArray(t))
149
- return `array(${t.map(S).join(", ")})`;
162
+ return `array(${t.map(v).join(", ")})`;
150
163
  if (t === null)
151
164
  return "null";
152
165
  if (typeof t == "object")
153
- return Ae in t ? t.toString() : `array(${Object.entries(t).map(([r, s]) => `${JSON.stringify(r)} => ${S(s)}`).join(", ")})`;
166
+ return je in t ? t.toString() : `array(${Object.entries(t).map(([r, s]) => `${JSON.stringify(r)} => ${v(s)}`).join(", ")})`;
154
167
  if (typeof t == "function")
155
168
  return t();
156
169
  throw new Error(`Unsupported value: ${t}`);
157
170
  }
158
- function D(t) {
171
+ function W(t) {
159
172
  const e = {};
160
173
  for (const r in t)
161
- e[r] = S(t[r]);
174
+ e[r] = v(t[r]);
162
175
  return e;
163
176
  }
164
- const B = `<?php
177
+ const G = `<?php
165
178
 
166
179
  function zipDir($dir, $output, $additionalFiles = array())
167
180
  {
@@ -224,28 +237,28 @@ function delTree($dir)
224
237
  return rmdir($dir);
225
238
  }
226
239
  `;
227
- async function He(t) {
228
- const e = "wordpress-playground.zip", r = `/${e}`, s = D({
240
+ async function Be(t) {
241
+ const e = "wordpress-playground.zip", r = `/${e}`, s = W({
229
242
  zipPath: r,
230
243
  documentRoot: await t.documentRoot
231
244
  });
232
- await ie(
245
+ await fe(
233
246
  t,
234
247
  `zipDir(${s.documentRoot}, ${s.zipPath});`
235
248
  );
236
249
  const n = await t.readFileAsBuffer(r);
237
250
  return t.unlink(r), new File([n], e);
238
251
  }
239
- const Ie = async (t, { fullSiteZip: e }) => {
252
+ const Ve = async (t, { fullSiteZip: e }) => {
240
253
  const r = "/import.zip";
241
254
  await t.writeFile(
242
255
  r,
243
256
  new Uint8Array(await e.arrayBuffer())
244
257
  );
245
258
  const s = await t.absoluteUrl, n = await t.documentRoot;
246
- await t.rmdir(n), await ne(t, { zipPath: r, extractToPath: "/" });
247
- const i = D({ absoluteUrl: s });
248
- await ze(
259
+ await t.rmdir(n), await pe(t, { zipPath: r, extractToPath: "/" });
260
+ const i = W({ absoluteUrl: s });
261
+ await Ye(
249
262
  t,
250
263
  `${n}/wp-config.php`,
251
264
  (o) => `<?php
@@ -255,35 +268,35 @@ const Ie = async (t, { fullSiteZip: e }) => {
255
268
  }
256
269
  ?>${o}`
257
270
  );
258
- }, ne = async (t, { zipPath: e, extractToPath: r }) => {
259
- const s = D({
271
+ }, pe = async (t, { zipPath: e, extractToPath: r }) => {
272
+ const s = W({
260
273
  zipPath: e,
261
274
  extractToPath: r
262
275
  });
263
- await ie(
276
+ await fe(
264
277
  t,
265
278
  `unzip(${s.zipPath}, ${s.extractToPath});`
266
279
  );
267
- }, Ne = async (t, { file: e }) => {
280
+ }, Ge = async (t, { file: e }) => {
268
281
  const r = await t.request({
269
282
  url: "/wp-admin/admin.php?import=wordpress"
270
- }), s = V(r).getElementById("import-upload-form")?.getAttribute("action"), n = await t.request({
283
+ }), s = J(r).getElementById("import-upload-form")?.getAttribute("action"), n = await t.request({
271
284
  url: `/wp-admin/${s}`,
272
285
  method: "POST",
273
286
  files: { import: e }
274
- }), i = V(n).querySelector(
287
+ }), i = J(n).querySelector(
275
288
  "#wpbody-content form"
276
289
  );
277
290
  if (!i)
278
291
  throw console.log(n.text), new Error(
279
292
  "Could not find an importer form in response. See the response text above for details."
280
293
  );
281
- const o = De(i);
294
+ const o = Je(i);
282
295
  o.fetch_attachments = "1";
283
296
  for (const a in o)
284
297
  if (a.startsWith("user_map[")) {
285
- const l = "user_new[" + a.slice(9, -1) + "]";
286
- o[l] = "1";
298
+ const c = "user_new[" + a.slice(9, -1) + "]";
299
+ o[c] = "1";
287
300
  }
288
301
  await t.request({
289
302
  url: i.action,
@@ -291,45 +304,45 @@ const Ie = async (t, { fullSiteZip: e }) => {
291
304
  formData: o
292
305
  });
293
306
  };
294
- function V(t) {
307
+ function J(t) {
295
308
  return new DOMParser().parseFromString(t.text, "text/html");
296
309
  }
297
- function De(t) {
310
+ function Je(t) {
298
311
  return Object.fromEntries(new FormData(t).entries());
299
312
  }
300
- async function ze(t, e, r) {
313
+ async function Ye(t, e, r) {
301
314
  await t.writeFile(
302
315
  e,
303
316
  r(await t.readFileAsText(e))
304
317
  );
305
318
  }
306
- async function ie(t, e) {
319
+ async function fe(t, e) {
307
320
  const r = await t.run({
308
- code: B + e
321
+ code: G + e
309
322
  });
310
323
  if (r.exitCode !== 0)
311
- throw console.log(B + e), console.log(e + ""), console.log(r.errors), r.errors;
324
+ throw console.log(G + e), console.log(e + ""), console.log(r.errors), r.errors;
312
325
  return r;
313
326
  }
314
- const qe = async (t, { pluginZipFile: e, options: r = {} }, s) => {
327
+ const Ke = async (t, { pluginZipFile: e, options: r = {} }, s) => {
315
328
  s?.tracker.setCaption(
316
329
  `Installing the ${L(e?.name)} plugin`
317
330
  );
318
331
  try {
319
332
  const n = "activate" in r ? r.activate : !0, i = await t.request({
320
333
  url: "/wp-admin/plugin-install.php?tab=upload"
321
- }), o = T(i), a = new FormData(
334
+ }), o = x(i), a = new FormData(
322
335
  o.querySelector(".wp-upload-form")
323
- ), { pluginzip: l, ...c } = Object.fromEntries(
336
+ ), { pluginzip: c, ...l } = Object.fromEntries(
324
337
  a.entries()
325
338
  ), u = await t.request({
326
339
  url: "/wp-admin/update.php?action=upload-plugin",
327
340
  method: "POST",
328
- formData: c,
341
+ formData: l,
329
342
  files: { pluginzip: e }
330
343
  });
331
344
  if (n) {
332
- const p = T(u).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value, y = new URL(
345
+ const p = x(u).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value, y = new URL(
333
346
  p,
334
347
  await t.pathToInternalUrl("/wp-admin/")
335
348
  ).toString();
@@ -339,14 +352,14 @@ const qe = async (t, { pluginZipFile: e, options: r = {} }, s) => {
339
352
  }
340
353
  await t.isDir(
341
354
  "/wordpress/wp-content/plugins/gutenberg"
342
- ) && !await t.fileExists("/wordpress/.gutenberg-patched") && (await t.writeFile("/wordpress/.gutenberg-patched", "1"), await G(
355
+ ) && !await t.fileExists("/wordpress/.gutenberg-patched") && (await t.writeFile("/wordpress/.gutenberg-patched", "1"), await Y(
343
356
  t,
344
357
  "/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.js",
345
358
  (d) => d.replace(
346
359
  /srcDoc:("[^"]+"|[^,]+)/g,
347
360
  'src:"/wp-includes/empty.html"'
348
361
  )
349
- ), await G(
362
+ ), await Y(
350
363
  t,
351
364
  "/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.min.js",
352
365
  (d) => d.replace(
@@ -360,31 +373,31 @@ const qe = async (t, { pluginZipFile: e, options: r = {} }, s) => {
360
373
  ), console.error(n);
361
374
  }
362
375
  };
363
- async function G(t, e, r) {
376
+ async function Y(t, e, r) {
364
377
  return await t.writeFile(
365
378
  e,
366
379
  r(await t.readFileAsText(e))
367
380
  );
368
381
  }
369
- const We = async (t, { themeZipFile: e, options: r = {} }, s) => {
382
+ const Qe = async (t, { themeZipFile: e, options: r = {} }, s) => {
370
383
  s?.tracker.setCaption(
371
384
  `Installing the ${L(e.name)} theme`
372
385
  );
373
386
  try {
374
387
  const n = "activate" in r ? r.activate : !0, i = await t.request({
375
388
  url: "/wp-admin/theme-install.php"
376
- }), o = T(i), a = new FormData(
389
+ }), o = x(i), a = new FormData(
377
390
  o.querySelector(".wp-upload-form")
378
- ), { themezip: l, ...c } = Object.fromEntries(
391
+ ), { themezip: c, ...l } = Object.fromEntries(
379
392
  a.entries()
380
393
  ), u = await t.request({
381
394
  url: "/wp-admin/update.php?action=upload-theme",
382
395
  method: "POST",
383
- formData: c,
396
+ formData: l,
384
397
  files: { themezip: e }
385
398
  });
386
399
  if (n) {
387
- const d = T(u), p = d.querySelector(
400
+ const d = x(u), p = d.querySelector(
388
401
  "#wpbody-content > .wrap"
389
402
  );
390
403
  if (p?.textContent?.includes(
@@ -400,12 +413,12 @@ const We = async (t, { themeZipFile: e, options: r = {} }, s) => {
400
413
  console.error('The "activate" button was not found.');
401
414
  return;
402
415
  }
403
- const ye = y.attributes.getNamedItem("href").value, Pe = new URL(
404
- ye,
416
+ const xe = y.attributes.getNamedItem("href").value, Te = new URL(
417
+ xe,
405
418
  await t.pathToInternalUrl("/wp-admin/")
406
419
  ).toString();
407
420
  await t.request({
408
- url: Pe
421
+ url: Te
409
422
  });
410
423
  }
411
424
  } catch (n) {
@@ -413,7 +426,7 @@ const We = async (t, { themeZipFile: e, options: r = {} }, s) => {
413
426
  `Proceeding without the ${e.name} theme. Could not install it in wp-admin. The original error was: ${n}`
414
427
  ), console.error(n);
415
428
  }
416
- }, Me = async (t, { username: e = "admin", password: r = "password" } = {}, s) => {
429
+ }, Xe = async (t, { username: e = "admin", password: r = "password" } = {}, s) => {
417
430
  s?.tracker.setCaption(s?.initialCaption || "Logging in"), await t.request({
418
431
  url: "/wp-login.php"
419
432
  }), await t.request({
@@ -425,7 +438,7 @@ const We = async (t, { themeZipFile: e, options: r = {} }, s) => {
425
438
  rememberme: "forever"
426
439
  }
427
440
  });
428
- }, je = async (t, { options: e }) => {
441
+ }, Ze = async (t, { options: e }) => {
429
442
  await t.request({
430
443
  url: "/wp-admin/install.php?step=2",
431
444
  method: "POST",
@@ -442,10 +455,10 @@ const We = async (t, { themeZipFile: e, options: r = {} }, s) => {
442
455
  admin_email: "admin@localhost.com"
443
456
  }
444
457
  });
445
- }, Be = async (t, { options: e }) => {
458
+ }, et = async (t, { options: e }) => {
446
459
  const r = `<?php
447
460
  include 'wordpress/wp-load.php';
448
- $site_options = ${S(e)};
461
+ $site_options = ${v(e)};
449
462
  foreach($site_options as $name => $value) {
450
463
  update_option($name, $value);
451
464
  }
@@ -453,52 +466,53 @@ const We = async (t, { themeZipFile: e, options: r = {} }, s) => {
453
466
  `, s = await t.run({
454
467
  code: r
455
468
  });
456
- return oe(s), { code: r, result: s };
457
- }, Ve = async (t, { meta: e, userId: r }) => {
469
+ return me(s), { code: r, result: s };
470
+ }, tt = async (t, { meta: e, userId: r }) => {
458
471
  const s = `<?php
459
472
  include 'wordpress/wp-load.php';
460
- $meta = ${S(e)};
473
+ $meta = ${v(e)};
461
474
  foreach($meta as $name => $value) {
462
- update_user_meta(${S(r)}, $name, $value);
475
+ update_user_meta(${v(r)}, $name, $value);
463
476
  }
464
477
  echo "Success";
465
478
  `, n = await t.run({
466
479
  code: s
467
480
  });
468
- return oe(n), { code: s, result: n };
481
+ return me(n), { code: s, result: n };
469
482
  };
470
- async function oe(t) {
483
+ async function me(t) {
471
484
  if (t.text !== "Success")
472
485
  throw console.log(t), new Error(`Failed to run code: ${t.text} ${t.errors}`);
473
486
  }
474
- const Ge = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
487
+ const rt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
475
488
  __proto__: null,
476
- activatePlugin: _e,
477
- applyWordPressPatches: $e,
478
- cp: xe,
479
- defineSiteUrl: Le,
480
- importFile: Ne,
481
- installPlugin: qe,
482
- installTheme: We,
483
- login: Me,
484
- mkdir: Fe,
485
- mv: Ce,
486
- replaceSite: Ie,
487
- request: Te,
488
- rm: ke,
489
- rmdir: Oe,
490
- runPHP: ve,
491
- runPHPWithOptions: Ee,
492
- runWpInstallationWizard: je,
493
- setPhpIniEntry: Re,
494
- setSiteOptions: Be,
495
- unzip: ne,
496
- updateUserMeta: Ve,
497
- writeFile: Ue,
498
- zipEntireSite: He
499
- }, Symbol.toStringTag, { value: "Module" })), Je = 5 * 1024 * 1024;
500
- function Ke(t, e) {
501
- const r = t.headers.get("content-length") || "", s = parseInt(r, 10) || Je;
489
+ 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;
502
516
  function n(i, o) {
503
517
  e(
504
518
  new CustomEvent("progress", {
@@ -520,14 +534,14 @@ function Ke(t, e) {
520
534
  let a = 0;
521
535
  for (; ; )
522
536
  try {
523
- const { done: l, value: c } = await o.read();
524
- if (c && (a += c.byteLength), l) {
537
+ const { done: c, value: l } = await o.read();
538
+ if (l && (a += l.byteLength), c) {
525
539
  n(a, a), i.close();
526
540
  break;
527
541
  } else
528
- n(a, s), i.enqueue(c);
529
- } catch (l) {
530
- console.error({ e: l }), i.error(l);
542
+ n(a, s), i.enqueue(l);
543
+ } catch (c) {
544
+ console.error({ e: c }), i.error(c);
531
545
  break;
532
546
  }
533
547
  }
@@ -540,7 +554,7 @@ function Ke(t, e) {
540
554
  );
541
555
  }
542
556
  const H = 1e-5;
543
- class A extends EventTarget {
557
+ class U extends EventTarget {
544
558
  constructor({
545
559
  weight: e = 1,
546
560
  caption: r = "",
@@ -589,7 +603,7 @@ class A extends EventTarget {
589
603
  `Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`
590
604
  );
591
605
  this._selfWeight -= e;
592
- const s = new A({
606
+ const s = new U({
593
607
  caption: r,
594
608
  weight: e,
595
609
  fillTime: this._fillTime
@@ -706,12 +720,12 @@ class A extends EventTarget {
706
720
  this.dispatchEvent(new CustomEvent("done"));
707
721
  }
708
722
  }
709
- class v {
723
+ class S {
710
724
  constructor(e, r, s, n = "", i = 0) {
711
725
  this.httpStatusCode = e, this.headers = r, this.bytes = s, this.exitCode = i, this.errors = n;
712
726
  }
713
727
  static fromRawData(e) {
714
- return new v(
728
+ return new S(
715
729
  e.httpStatusCode,
716
730
  e.headers,
717
731
  e.bytes,
@@ -741,7 +755,7 @@ class v {
741
755
  return new TextDecoder().decode(this.bytes);
742
756
  }
743
757
  }
744
- const z = [
758
+ const D = [
745
759
  "8.2",
746
760
  "8.1",
747
761
  "8.0",
@@ -751,8 +765,8 @@ const z = [
751
765
  "7.1",
752
766
  "7.0",
753
767
  "5.6"
754
- ], Ye = z[0], Nt = z;
755
- class Qe {
768
+ ], it = D[0], rr = D;
769
+ class ot {
756
770
  #e;
757
771
  #t;
758
772
  /**
@@ -785,10 +799,10 @@ class Qe {
785
799
  ...e,
786
800
  headers: {
787
801
  ...e.headers,
788
- cookie: this.#s()
802
+ cookie: this.#n()
789
803
  }
790
804
  });
791
- if (s.headers["set-cookie"] && this.#n(s.headers["set-cookie"]), this.#t.handleRedirects && s.headers.location && r < this.#t.maxRedirects) {
805
+ if (s.headers["set-cookie"] && this.#r(s.headers["set-cookie"]), this.#t.handleRedirects && s.headers.location && r < this.#t.maxRedirects) {
792
806
  const n = new URL(
793
807
  s.headers.location[0],
794
808
  this.requestHandler.absoluteUrl
@@ -820,7 +834,7 @@ class Qe {
820
834
  get documentRoot() {
821
835
  return this.requestHandler.documentRoot;
822
836
  }
823
- #n(e) {
837
+ #r(e) {
824
838
  for (const r of e)
825
839
  try {
826
840
  if (!r.includes("="))
@@ -831,30 +845,30 @@ class Qe {
831
845
  console.error(s);
832
846
  }
833
847
  }
834
- #s() {
848
+ #n() {
835
849
  const e = [];
836
850
  for (const r in this.#e)
837
851
  e.push(`${r}=${this.#e[r]}`);
838
852
  return e.join("; ");
839
853
  }
840
854
  }
841
- const Xe = "http://example.com";
842
- function J(t) {
855
+ const at = "http://example.com";
856
+ function K(t) {
843
857
  return t.toString().substring(t.origin.length);
844
858
  }
845
- function K(t, e) {
859
+ function Q(t, e) {
846
860
  return !e || !t.startsWith(e) ? t : t.substring(e.length);
847
861
  }
848
- function Ze(t, e) {
862
+ function ct(t, e) {
849
863
  return !e || t.startsWith(e) ? t : e + t;
850
864
  }
851
- class et {
865
+ class lt {
852
866
  #e;
853
867
  #t;
868
+ #r;
854
869
  #n;
855
- #s;
856
870
  #i;
857
- #r;
871
+ #s;
858
872
  #o;
859
873
  #a;
860
874
  #c;
@@ -863,7 +877,7 @@ class et {
863
877
  * @param config - Request Handler configuration.
864
878
  */
865
879
  constructor(e, r = {}) {
866
- this.#a = new se({ concurrency: 1 });
880
+ this.#a = new de({ concurrency: 1 });
867
881
  const {
868
882
  documentRoot: s = "/www/",
869
883
  absoluteUrl: n = typeof location == "object" ? location?.href : "",
@@ -871,15 +885,15 @@ class et {
871
885
  } = r;
872
886
  this.php = e, this.#e = s, this.#c = i;
873
887
  const o = new URL(n);
874
- this.#n = o.hostname, this.#s = o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80, this.#t = (o.protocol || "").replace(":", "");
875
- const a = this.#s !== 443 && this.#s !== 80;
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;
876
890
  this.#i = [
877
- this.#n,
878
- a ? `:${this.#s}` : ""
879
- ].join(""), this.#r = o.pathname.replace(/\/+$/, ""), this.#o = [
891
+ this.#r,
892
+ a ? `:${this.#n}` : ""
893
+ ].join(""), this.#s = o.pathname.replace(/\/+$/, ""), this.#o = [
880
894
  `${this.#t}://`,
881
895
  this.#i,
882
- this.#r
896
+ this.#s
883
897
  ].join("");
884
898
  }
885
899
  /** @inheritDoc */
@@ -889,7 +903,7 @@ class et {
889
903
  /** @inheritDoc */
890
904
  internalUrlToPath(e) {
891
905
  const r = new URL(e);
892
- return r.pathname.startsWith(this.#r) && (r.pathname = r.pathname.slice(this.#r.length)), J(r);
906
+ return r.pathname.startsWith(this.#s) && (r.pathname = r.pathname.slice(this.#s.length)), K(r);
893
907
  }
894
908
  get isRequestRunning() {
895
909
  return this.#a.running > 0;
@@ -906,10 +920,10 @@ class et {
906
920
  async request(e) {
907
921
  const r = e.url.startsWith("http://") || e.url.startsWith("https://"), s = new URL(
908
922
  e.url,
909
- r ? void 0 : Xe
910
- ), n = K(
923
+ r ? void 0 : at
924
+ ), n = Q(
911
925
  s.pathname,
912
- this.#r
926
+ this.#s
913
927
  );
914
928
  return this.#c(n) ? this.#l(n) : await this.#u(e, s);
915
929
  }
@@ -922,20 +936,20 @@ class et {
922
936
  #l(e) {
923
937
  const r = `${this.#e}${e}`;
924
938
  if (!this.php.fileExists(r))
925
- return new v(
939
+ return new S(
926
940
  404,
927
941
  {},
928
942
  new TextEncoder().encode("404 File not found")
929
943
  );
930
944
  const s = this.php.readFileAsBuffer(r);
931
- return new v(
945
+ return new S(
932
946
  200,
933
947
  {
934
948
  "content-length": [`${s.byteLength}`],
935
949
  // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
936
950
  // The code below won't return the correct mime-type if the extension
937
951
  // was tampered with.
938
- "content-type": [rt(r)],
952
+ "content-type": [ht(r)],
939
953
  "accept-ranges": ["bytes"],
940
954
  "cache-control": ["public, max-age=0"]
941
955
  },
@@ -959,20 +973,20 @@ class et {
959
973
  let n = "GET";
960
974
  const i = {
961
975
  host: this.#i,
962
- ...ae(e.headers || {})
976
+ ...ge(e.headers || {})
963
977
  }, o = [];
964
978
  if (e.files && Object.keys(e.files).length) {
965
979
  n = "POST";
966
- for (const l in e.files) {
967
- const c = e.files[l];
980
+ for (const c in e.files) {
981
+ const l = e.files[c];
968
982
  o.push({
969
- key: l,
970
- name: c.name,
971
- type: c.type,
972
- data: new Uint8Array(await c.arrayBuffer())
983
+ key: c,
984
+ name: l.name,
985
+ type: l.type,
986
+ data: new Uint8Array(await l.arrayBuffer())
973
987
  });
974
988
  }
975
- i["content-type"]?.startsWith("multipart/form-data") && (e.formData = tt(
989
+ i["content-type"]?.startsWith("multipart/form-data") && (e.formData = ut(
976
990
  e.body || ""
977
991
  ), i["content-type"] = "application/x-www-form-urlencoded", delete e.body);
978
992
  }
@@ -980,9 +994,9 @@ class et {
980
994
  return e.formData !== void 0 ? (n = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
981
995
  e.formData
982
996
  ).toString()) : a = e.body, await this.php.run({
983
- relativeUri: Ze(
984
- J(r),
985
- this.#r
997
+ relativeUri: ct(
998
+ K(r),
999
+ this.#s
986
1000
  ),
987
1001
  protocol: this.#t,
988
1002
  method: e.method || n,
@@ -1004,13 +1018,13 @@ class et {
1004
1018
  * @returns The resolved filesystem path.
1005
1019
  */
1006
1020
  #h(e) {
1007
- let r = K(e, this.#r);
1021
+ let r = Q(e, this.#s);
1008
1022
  r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
1009
1023
  const s = `${this.#e}${r}`;
1010
1024
  return this.php.fileExists(s) ? s : `${this.#e}/index.php`;
1011
1025
  }
1012
1026
  }
1013
- function tt(t) {
1027
+ function ut(t) {
1014
1028
  const e = {}, r = t.match(/--(.*)\r\n/);
1015
1029
  if (!r)
1016
1030
  return e;
@@ -1018,14 +1032,14 @@ function tt(t) {
1018
1032
  return n.shift(), n.pop(), n.forEach((i) => {
1019
1033
  const o = i.indexOf(`\r
1020
1034
  \r
1021
- `), a = i.substring(0, o).trim(), l = i.substring(o + 4).trim(), c = a.match(/name="([^"]+)"/);
1022
- if (c) {
1023
- const u = c[1];
1024
- e[u] = l;
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;
1025
1039
  }
1026
1040
  }), e;
1027
1041
  }
1028
- function rt(t) {
1042
+ function ht(t) {
1029
1043
  switch (t.split(".").pop()) {
1030
1044
  case "css":
1031
1045
  return "text/css";
@@ -1065,7 +1079,7 @@ function rt(t) {
1065
1079
  return "application-octet-stream";
1066
1080
  }
1067
1081
  }
1068
- const Y = {
1082
+ const X = {
1069
1083
  0: "No error occurred. System call completed successfully.",
1070
1084
  1: "Argument list too long.",
1071
1085
  2: "Permission denied.",
@@ -1151,10 +1165,10 @@ function m(t = "") {
1151
1165
  try {
1152
1166
  return i.apply(this, o);
1153
1167
  } catch (a) {
1154
- const l = typeof a == "object" ? a?.errno : null;
1155
- if (l in Y) {
1156
- const c = Y[l], u = typeof o[0] == "string" ? o[0] : null, d = u !== null ? t.replaceAll("{path}", u) : t;
1157
- throw new Error(`${d}: ${c}`, {
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}`, {
1158
1172
  cause: a
1159
1173
  });
1160
1174
  }
@@ -1163,20 +1177,165 @@ function m(t = "") {
1163
1177
  };
1164
1178
  };
1165
1179
  }
1166
- const st = [];
1167
- function nt(t) {
1168
- return st[t];
1180
+ const dt = [];
1181
+ function pt(t) {
1182
+ return dt[t];
1169
1183
  }
1170
1184
  (function() {
1171
- return typeof window < "u" && !{}.TEST ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
1185
+ return typeof process < "u" && process.release?.name === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
1172
1186
  })();
1173
- var it = Object.defineProperty, ot = Object.getOwnPropertyDescriptor, w = (t, e, r, s) => {
1174
- for (var n = s > 1 ? void 0 : s ? ot(e, r) : e, i = t.length - 1, o; i >= 0; i--)
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--)
1175
1334
  (o = t[i]) && (n = (s ? o(e, r, n) : o(n)) || n);
1176
- return s && n && it(e, r, n), n;
1335
+ return s && n && Et(e, r, n), n;
1177
1336
  };
1178
1337
  const f = "string", _ = "number", h = Symbol("__private__dont__use");
1179
- class g {
1338
+ class w {
1180
1339
  /**
1181
1340
  * Initializes a PHP runtime.
1182
1341
  *
@@ -1185,12 +1344,13 @@ class g {
1185
1344
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
1186
1345
  */
1187
1346
  constructor(e, r) {
1188
- this.#e = [], this.#t = !1, e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new Qe(
1189
- new et(this, 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)
1190
1349
  ));
1191
1350
  }
1192
1351
  #e;
1193
1352
  #t;
1353
+ #r;
1194
1354
  /** @inheritDoc */
1195
1355
  get absoluteUrl() {
1196
1356
  return this.requestHandler.requestHandler.absoluteUrl;
@@ -1212,10 +1372,10 @@ class g {
1212
1372
  initializeRuntime(e) {
1213
1373
  if (this[h])
1214
1374
  throw new Error("PHP runtime already initialized.");
1215
- const r = nt(e);
1375
+ const r = pt(e);
1216
1376
  if (!r)
1217
1377
  throw new Error("Invalid PHP runtime id.");
1218
- this[h] = r;
1378
+ this[h] = r, this.#r = gt(r);
1219
1379
  }
1220
1380
  /** @inheritDoc */
1221
1381
  setPhpIniPath(e) {
@@ -1246,15 +1406,15 @@ class g {
1246
1406
  }
1247
1407
  /** @inheritDoc */
1248
1408
  async run(e) {
1249
- this.#t || (this.#n(), this.#t = !0), this.#l(e.scriptPath || ""), this.#i(e.relativeUri || ""), this.#o(e.method || "GET");
1409
+ this.#t || (this.#n(), this.#t = !0), this.#u(e.scriptPath || ""), this.#s(e.relativeUri || ""), this.#a(e.method || "GET");
1250
1410
  const { host: r, ...s } = {
1251
1411
  host: "example.com:443",
1252
- ...ae(e.headers || {})
1412
+ ...ge(e.headers || {})
1253
1413
  };
1254
- if (this.#r(r, e.protocol || "http"), this.#a(s), e.body && this.#c(e.body), e.fileInfos)
1414
+ if (this.#o(r, e.protocol || "http"), this.#c(s), e.body && this.#l(e.body), e.fileInfos)
1255
1415
  for (const n of e.fileInfos)
1256
- this.#u(n);
1257
- return e.code && this.#h(" ?>" + e.code), await this.#d();
1416
+ this.#h(n);
1417
+ return e.code && this.#d(" ?>" + e.code), await this.#p();
1258
1418
  }
1259
1419
  #n() {
1260
1420
  if (this.#e.length > 0) {
@@ -1271,7 +1431,7 @@ class g {
1271
1431
  }
1272
1432
  this[h].ccall("php_wasm_init", null, [], []);
1273
1433
  }
1274
- #s() {
1434
+ #i() {
1275
1435
  const e = "/tmp/headers.json";
1276
1436
  if (!this.fileExists(e))
1277
1437
  throw new Error(
@@ -1289,7 +1449,7 @@ class g {
1289
1449
  httpStatusCode: r.status
1290
1450
  };
1291
1451
  }
1292
- #i(e) {
1452
+ #s(e) {
1293
1453
  if (this[h].ccall(
1294
1454
  "wasm_set_request_uri",
1295
1455
  null,
@@ -1305,7 +1465,7 @@ class g {
1305
1465
  );
1306
1466
  }
1307
1467
  }
1308
- #r(e, r) {
1468
+ #o(e, r) {
1309
1469
  this[h].ccall(
1310
1470
  "wasm_set_request_host",
1311
1471
  null,
@@ -1324,7 +1484,7 @@ class g {
1324
1484
  [s]
1325
1485
  ), (r === "https" || !r && s === 443) && this.addServerGlobalEntry("HTTPS", "on");
1326
1486
  }
1327
- #o(e) {
1487
+ #a(e) {
1328
1488
  this[h].ccall(
1329
1489
  "wasm_set_request_method",
1330
1490
  null,
@@ -1332,7 +1492,7 @@ class g {
1332
1492
  [e]
1333
1493
  );
1334
1494
  }
1335
- #a(e) {
1495
+ #c(e) {
1336
1496
  e.cookie && this[h].ccall(
1337
1497
  "wasm_set_cookies",
1338
1498
  null,
@@ -1355,7 +1515,7 @@ class g {
1355
1515
  e[r]
1356
1516
  );
1357
1517
  }
1358
- #c(e) {
1518
+ #l(e) {
1359
1519
  this[h].ccall(
1360
1520
  "wasm_set_request_body",
1361
1521
  null,
@@ -1365,10 +1525,10 @@ class g {
1365
1525
  "wasm_set_content_length",
1366
1526
  null,
1367
1527
  [_],
1368
- [e.length]
1528
+ [new TextEncoder().encode(e).length]
1369
1529
  );
1370
1530
  }
1371
- #l(e) {
1531
+ #u(e) {
1372
1532
  this[h].ccall(
1373
1533
  "wasm_set_path_translated",
1374
1534
  null,
@@ -1393,7 +1553,7 @@ class g {
1393
1553
  *
1394
1554
  * @param fileInfo - File details
1395
1555
  */
1396
- #u(e) {
1556
+ #h(e) {
1397
1557
  const { key: r, name: s, type: n, data: i } = e, o = `/tmp/${Math.random().toFixed(20)}`;
1398
1558
  this.writeFile(o, i);
1399
1559
  const a = 0;
@@ -1404,7 +1564,7 @@ class g {
1404
1564
  [r, s, n, o, a, i.byteLength]
1405
1565
  );
1406
1566
  }
1407
- #h(e) {
1567
+ #d(e) {
1408
1568
  this[h].ccall(
1409
1569
  "wasm_set_php_code",
1410
1570
  null,
@@ -1412,16 +1572,53 @@ class g {
1412
1572
  [e]
1413
1573
  );
1414
1574
  }
1415
- async #d() {
1416
- const e = await await this[h].ccall(
1417
- "wasm_sapi_handle_request",
1418
- _,
1419
- [],
1420
- []
1421
- ), { headers: r, httpStatusCode: s } = this.#s();
1422
- return new v(
1575
+ async #p() {
1576
+ let e, r;
1577
+ try {
1578
+ e = await new Promise(async (i, o) => {
1579
+ r = (a) => {
1580
+ const c = new Error("Rethrown");
1581
+ c.cause = a.error, c.betterMessage = a.message, o(c);
1582
+ }, this.#r?.addEventListener(
1583
+ "error",
1584
+ r
1585
+ );
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
+ }
1604
+ });
1605
+ } catch (i) {
1606
+ for (const l in this)
1607
+ typeof this[l] == "function" && (this[l] = () => {
1608
+ throw new Error(
1609
+ "PHP runtime has crashed – see the earlier error for details."
1610
+ );
1611
+ });
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;
1615
+ } finally {
1616
+ this.#r?.removeEventListener("error", r);
1617
+ }
1618
+ const { headers: s, httpStatusCode: n } = this.#i();
1619
+ return new S(
1620
+ n,
1423
1621
  s,
1424
- r,
1425
1622
  this.readFileAsBuffer("/tmp/stdout"),
1426
1623
  this.readFileAsText("/tmp/stderr"),
1427
1624
  e
@@ -1478,54 +1675,54 @@ class g {
1478
1675
  }
1479
1676
  }
1480
1677
  }
1481
- w([
1678
+ g([
1482
1679
  m('Could not create directory "{path}"')
1483
- ], g.prototype, "mkdir", 1);
1484
- w([
1680
+ ], w.prototype, "mkdir", 1);
1681
+ g([
1485
1682
  m('Could not create directory "{path}"')
1486
- ], g.prototype, "mkdirTree", 1);
1487
- w([
1683
+ ], w.prototype, "mkdirTree", 1);
1684
+ g([
1488
1685
  m('Could not read "{path}"')
1489
- ], g.prototype, "readFileAsText", 1);
1490
- w([
1686
+ ], w.prototype, "readFileAsText", 1);
1687
+ g([
1491
1688
  m('Could not read "{path}"')
1492
- ], g.prototype, "readFileAsBuffer", 1);
1493
- w([
1689
+ ], w.prototype, "readFileAsBuffer", 1);
1690
+ g([
1494
1691
  m('Could not write to "{path}"')
1495
- ], g.prototype, "writeFile", 1);
1496
- w([
1692
+ ], w.prototype, "writeFile", 1);
1693
+ g([
1497
1694
  m('Could not unlink "{path}"')
1498
- ], g.prototype, "unlink", 1);
1499
- w([
1695
+ ], w.prototype, "unlink", 1);
1696
+ g([
1500
1697
  m('Could not move "{path}"')
1501
- ], g.prototype, "mv", 1);
1502
- w([
1698
+ ], w.prototype, "mv", 1);
1699
+ g([
1503
1700
  m('Could not remove directory "{path}"')
1504
- ], g.prototype, "rmdir", 1);
1505
- w([
1701
+ ], w.prototype, "rmdir", 1);
1702
+ g([
1506
1703
  m('Could not list files in "{path}"')
1507
- ], g.prototype, "listFiles", 1);
1508
- w([
1704
+ ], w.prototype, "listFiles", 1);
1705
+ g([
1509
1706
  m('Could not stat "{path}"')
1510
- ], g.prototype, "isDir", 1);
1511
- w([
1707
+ ], w.prototype, "isDir", 1);
1708
+ g([
1512
1709
  m('Could not stat "{path}"')
1513
- ], g.prototype, "fileExists", 1);
1514
- function ae(t) {
1710
+ ], w.prototype, "fileExists", 1);
1711
+ function ge(t) {
1515
1712
  const e = {};
1516
1713
  for (const r in t)
1517
1714
  e[r.toLowerCase()] = t[r];
1518
1715
  return e;
1519
1716
  }
1520
- const at = [
1717
+ const St = [
1521
1718
  "vfs",
1522
1719
  "literal",
1523
1720
  "wordpress.org/themes",
1524
1721
  "wordpress.org/plugins",
1525
1722
  "url"
1526
1723
  ];
1527
- function ct(t) {
1528
- return t && typeof t == "object" && typeof t.resource == "string" && at.includes(t.resource);
1724
+ function Rt(t) {
1725
+ return t && typeof t == "object" && typeof t.resource == "string" && St.includes(t.resource);
1529
1726
  }
1530
1727
  class b {
1531
1728
  /**
@@ -1539,24 +1736,24 @@ class b {
1539
1736
  let n;
1540
1737
  switch (e.resource) {
1541
1738
  case "vfs":
1542
- n = new lt(e, s);
1739
+ n = new xt(e, s);
1543
1740
  break;
1544
1741
  case "literal":
1545
- n = new ut(e, s);
1742
+ n = new Tt(e, s);
1546
1743
  break;
1547
1744
  case "wordpress.org/themes":
1548
- n = new pt(e, s);
1745
+ n = new Ft(e, s);
1549
1746
  break;
1550
1747
  case "wordpress.org/plugins":
1551
- n = new ft(e, s);
1748
+ n = new Ot(e, s);
1552
1749
  break;
1553
1750
  case "url":
1554
- n = new dt(e, s);
1751
+ n = new kt(e, s);
1555
1752
  break;
1556
1753
  default:
1557
1754
  throw new Error(`Invalid resource: ${e}`);
1558
1755
  }
1559
- return n = new mt(n), r && (n = new wt(n, r)), n;
1756
+ return n = new At(n), r && (n = new Lt(n, r)), n;
1560
1757
  }
1561
1758
  setPlayground(e) {
1562
1759
  this.playground = e;
@@ -1566,7 +1763,7 @@ class b {
1566
1763
  return !1;
1567
1764
  }
1568
1765
  }
1569
- class lt extends b {
1766
+ class xt extends b {
1570
1767
  /**
1571
1768
  * Creates a new instance of `VFSResource`.
1572
1769
  * @param playground The playground client.
@@ -1588,7 +1785,7 @@ class lt extends b {
1588
1785
  return this.resource.path;
1589
1786
  }
1590
1787
  }
1591
- class ut extends b {
1788
+ class Tt extends b {
1592
1789
  /**
1593
1790
  * Creates a new instance of `LiteralResource`.
1594
1791
  * @param resource The literal reference.
@@ -1619,9 +1816,9 @@ class q extends b {
1619
1816
  this.progress?.setCaption(this.caption);
1620
1817
  const e = this.getURL();
1621
1818
  let r = await fetch(e);
1622
- if (r = await Ke(
1819
+ if (r = await nt(
1623
1820
  r,
1624
- this.progress?.loadingListener ?? ht
1821
+ this.progress?.loadingListener ?? Ct
1625
1822
  ), r.status !== 200)
1626
1823
  throw new Error(`Could not download "${e}"`);
1627
1824
  return new File([await r.blob()], this.name);
@@ -1635,16 +1832,20 @@ class q extends b {
1635
1832
  }
1636
1833
  /** @inheritDoc */
1637
1834
  get name() {
1638
- return this.getURL();
1835
+ try {
1836
+ return new URL(this.getURL(), "http://example.com").pathname.split("/").pop();
1837
+ } catch {
1838
+ return this.getURL();
1839
+ }
1639
1840
  }
1640
1841
  /** @inheritDoc */
1641
1842
  get isAsync() {
1642
1843
  return !0;
1643
1844
  }
1644
1845
  }
1645
- const ht = () => {
1846
+ const Ct = () => {
1646
1847
  };
1647
- class dt extends q {
1848
+ class kt extends q {
1648
1849
  /**
1649
1850
  * Creates a new instance of `UrlResource`.
1650
1851
  * @param resource The URL reference.
@@ -1662,11 +1863,11 @@ class dt extends q {
1662
1863
  return this.resource.caption ?? super.caption;
1663
1864
  }
1664
1865
  }
1665
- let W = "https://playground.wordpress.net/plugin-proxy";
1666
- function Dt(t) {
1667
- W = t;
1866
+ let j = "https://playground.wordpress.net/plugin-proxy";
1867
+ function sr(t) {
1868
+ j = t;
1668
1869
  }
1669
- class pt extends q {
1870
+ class Ft extends q {
1670
1871
  constructor(e, r) {
1671
1872
  super(r), this.resource = e;
1672
1873
  }
@@ -1674,11 +1875,11 @@ class pt extends q {
1674
1875
  return L(this.resource.slug);
1675
1876
  }
1676
1877
  getURL() {
1677
- const e = ce(this.resource.slug);
1678
- return `${W}?theme=` + e;
1878
+ const e = we(this.resource.slug);
1879
+ return `${j}?theme=` + e;
1679
1880
  }
1680
1881
  }
1681
- class ft extends q {
1882
+ class Ot extends q {
1682
1883
  constructor(e, r) {
1683
1884
  super(r), this.resource = e;
1684
1885
  }
@@ -1688,14 +1889,14 @@ class ft extends q {
1688
1889
  }
1689
1890
  /** @inheritDoc */
1690
1891
  getURL() {
1691
- const e = ce(this.resource.slug);
1692
- return `${W}?plugin=` + e;
1892
+ const e = we(this.resource.slug);
1893
+ return `${j}?plugin=` + e;
1693
1894
  }
1694
1895
  }
1695
- function ce(t) {
1896
+ function we(t) {
1696
1897
  return !t || t.endsWith(".zip") ? t : t + ".latest-stable.zip";
1697
1898
  }
1698
- class le extends b {
1899
+ class ye extends b {
1699
1900
  constructor(e) {
1700
1901
  super(), this.resource = e;
1701
1902
  }
@@ -1724,13 +1925,13 @@ class le extends b {
1724
1925
  return this.resource.isAsync;
1725
1926
  }
1726
1927
  }
1727
- class mt extends le {
1928
+ class At extends ye {
1728
1929
  /** @inheritDoc */
1729
1930
  async resolve() {
1730
1931
  return this.promise || (this.promise = super.resolve()), this.promise;
1731
1932
  }
1732
1933
  }
1733
- class wt extends le {
1934
+ class Lt extends ye {
1734
1935
  constructor(e, r) {
1735
1936
  super(e), this.semaphore = r;
1736
1937
  }
@@ -1739,18 +1940,18 @@ class wt extends le {
1739
1940
  return this.isAsync ? this.semaphore.run(() => super.resolve()) : super.resolve();
1740
1941
  }
1741
1942
  }
1742
- const gt = ["6.2", "6.1", "6.0", "5.9"];
1743
- function yt(t, {
1744
- progress: e = new A(),
1745
- semaphore: r = new se({ concurrency: 3 }),
1943
+ const Ut = ["6.2", "6.1", "6.0", "5.9"];
1944
+ function Ht(t, {
1945
+ progress: e = new U(),
1946
+ semaphore: r = new de({ concurrency: 3 }),
1746
1947
  onStepCompleted: s = () => {
1747
1948
  }
1748
1949
  } = {}) {
1749
- const n = (t.steps || []).filter(Pt), i = n.reduce(
1750
- (a, l) => a + (l.progress?.weight || 1),
1950
+ const n = (t.steps || []).filter(It), i = n.reduce(
1951
+ (a, c) => a + (c.progress?.weight || 1),
1751
1952
  0
1752
1953
  ), o = n.map(
1753
- (a) => bt(a, {
1954
+ (a) => Nt(a, {
1754
1955
  semaphore: r,
1755
1956
  rootProgressTracker: e,
1756
1957
  totalProgressWeight: i
@@ -1758,25 +1959,25 @@ function yt(t, {
1758
1959
  );
1759
1960
  return {
1760
1961
  versions: {
1761
- php: Q(
1962
+ php: ie(
1762
1963
  t.preferredVersions?.php,
1763
- z,
1764
- Ye
1964
+ D,
1965
+ it
1765
1966
  ),
1766
- wp: Q(
1967
+ wp: ie(
1767
1968
  t.preferredVersions?.wp,
1768
- gt,
1969
+ Ut,
1769
1970
  "6.2"
1770
1971
  )
1771
1972
  },
1772
1973
  run: async (a) => {
1773
1974
  try {
1774
- for (const { resources: l } of o)
1775
- for (const c of l)
1776
- c.setPlayground(a), c.isAsync && c.resolve();
1777
- for (const { run: l, step: c } of o) {
1778
- const u = await l(a);
1779
- s(u, c);
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);
1780
1981
  }
1781
1982
  try {
1782
1983
  await a.goTo(
@@ -1790,13 +1991,13 @@ function yt(t, {
1790
1991
  }
1791
1992
  };
1792
1993
  }
1793
- function Q(t, e, r) {
1994
+ function ie(t, e, r) {
1794
1995
  return t && e.includes(t) ? t : r;
1795
1996
  }
1796
- function Pt(t) {
1997
+ function It(t) {
1797
1998
  return !!(typeof t == "object" && t);
1798
1999
  }
1799
- function bt(t, {
2000
+ function Nt(t, {
1800
2001
  semaphore: e,
1801
2002
  rootProgressTracker: r,
1802
2003
  totalProgressWeight: s
@@ -1806,15 +2007,15 @@ function bt(t, {
1806
2007
  ), i = {};
1807
2008
  for (const u of Object.keys(t)) {
1808
2009
  let d = t[u];
1809
- ct(d) && (d = b.create(d, {
2010
+ Rt(d) && (d = b.create(d, {
1810
2011
  semaphore: e
1811
2012
  })), i[u] = d;
1812
2013
  }
1813
2014
  const o = async (u) => {
1814
2015
  try {
1815
- return n.fillSlowly(), await Ge[t.step](
2016
+ return n.fillSlowly(), await rt[t.step](
1816
2017
  u,
1817
- await _t(i),
2018
+ await Mt(i),
1818
2019
  {
1819
2020
  tracker: n,
1820
2021
  initialCaption: t.progress?.caption
@@ -1823,14 +2024,14 @@ function bt(t, {
1823
2024
  } finally {
1824
2025
  n.finish();
1825
2026
  }
1826
- }, a = X(i), l = X(i).filter(
2027
+ }, a = oe(i), c = oe(i).filter(
1827
2028
  (u) => u.isAsync
1828
- ), c = 1 / (l.length + 1);
1829
- for (const u of l)
1830
- u.progress = n.stage(c);
2029
+ ), l = 1 / (c.length + 1);
2030
+ for (const u of c)
2031
+ u.progress = n.stage(l);
1831
2032
  return { run: o, step: t, resources: a };
1832
2033
  }
1833
- function X(t) {
2034
+ function oe(t) {
1834
2035
  const e = [];
1835
2036
  for (const r in t) {
1836
2037
  const s = t[r];
@@ -1838,7 +2039,7 @@ function X(t) {
1838
2039
  }
1839
2040
  return e;
1840
2041
  }
1841
- async function _t(t) {
2042
+ async function Mt(t) {
1842
2043
  const e = {};
1843
2044
  for (const r in t) {
1844
2045
  const s = t[r];
@@ -1846,7 +2047,7 @@ async function _t(t) {
1846
2047
  }
1847
2048
  return e;
1848
2049
  }
1849
- async function $t(t, e) {
2050
+ async function Wt(t, e) {
1850
2051
  await t.run(e);
1851
2052
  }
1852
2053
  /**
@@ -1854,17 +2055,17 @@ async function $t(t, e) {
1854
2055
  * Copyright 2019 Google LLC
1855
2056
  * SPDX-License-Identifier: Apache-2.0
1856
2057
  */
1857
- const ue = Symbol("Comlink.proxy"), St = Symbol("Comlink.endpoint"), vt = Symbol("Comlink.releaseProxy"), I = Symbol("Comlink.finalizer"), C = Symbol("Comlink.thrown"), he = (t) => typeof t == "object" && t !== null || typeof t == "function", Et = {
1858
- canHandle: (t) => he(t) && t[ue],
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],
1859
2060
  serialize(t) {
1860
2061
  const { port1: e, port2: r } = new MessageChannel();
1861
- return M(t, e), [r, [r]];
2062
+ return B(t, e), [r, [r]];
1862
2063
  },
1863
2064
  deserialize(t) {
1864
- return t.start(), j(t);
2065
+ return t.start(), V(t);
1865
2066
  }
1866
- }, Rt = {
1867
- canHandle: (t) => he(t) && C in t,
2067
+ }, jt = {
2068
+ canHandle: (t) => be(t) && C in t,
1868
2069
  serialize({ value: t }) {
1869
2070
  let e;
1870
2071
  return t instanceof Error ? e = {
@@ -1880,63 +2081,63 @@ const ue = Symbol("Comlink.proxy"), St = Symbol("Comlink.endpoint"), vt = Symbol
1880
2081
  throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
1881
2082
  }
1882
2083
  }, R = /* @__PURE__ */ new Map([
1883
- ["proxy", Et],
1884
- ["throw", Rt]
2084
+ ["proxy", qt],
2085
+ ["throw", jt]
1885
2086
  ]);
1886
- function Tt(t, e) {
2087
+ function Bt(t, e) {
1887
2088
  for (const r of t)
1888
2089
  if (e === r || r === "*" || r instanceof RegExp && r.test(e))
1889
2090
  return !0;
1890
2091
  return !1;
1891
2092
  }
1892
- function M(t, e = globalThis, r = ["*"]) {
2093
+ function B(t, e = globalThis, r = ["*"]) {
1893
2094
  e.addEventListener("message", function s(n) {
1894
2095
  if (!n || !n.data)
1895
2096
  return;
1896
- if (!Tt(r, n.origin)) {
2097
+ if (!Bt(r, n.origin)) {
1897
2098
  console.warn(`Invalid origin '${n.origin}' for comlink proxy`);
1898
2099
  return;
1899
2100
  }
1900
- const { id: i, type: o, path: a } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(P);
1901
- let c;
2101
+ const { id: i, type: o, path: a } = Object.assign({ path: [] }, n.data), c = (n.data.argumentList || []).map(P);
2102
+ let l;
1902
2103
  try {
1903
2104
  const u = a.slice(0, -1).reduce((p, y) => p[y], t), d = a.reduce((p, y) => p[y], t);
1904
2105
  switch (o) {
1905
2106
  case "GET":
1906
- c = d;
2107
+ l = d;
1907
2108
  break;
1908
2109
  case "SET":
1909
- u[a.slice(-1)[0]] = P(n.data.value), c = !0;
2110
+ u[a.slice(-1)[0]] = P(n.data.value), l = !0;
1910
2111
  break;
1911
2112
  case "APPLY":
1912
- c = d.apply(u, l);
2113
+ l = d.apply(u, c);
1913
2114
  break;
1914
2115
  case "CONSTRUCT":
1915
2116
  {
1916
- const p = new d(...l);
1917
- c = me(p);
2117
+ const p = new d(...c);
2118
+ l = ve(p);
1918
2119
  }
1919
2120
  break;
1920
2121
  case "ENDPOINT":
1921
2122
  {
1922
2123
  const { port1: p, port2: y } = new MessageChannel();
1923
- M(t, y), c = Ot(p, [p]);
2124
+ B(t, y), l = Kt(p, [p]);
1924
2125
  }
1925
2126
  break;
1926
2127
  case "RELEASE":
1927
- c = void 0;
2128
+ l = void 0;
1928
2129
  break;
1929
2130
  default:
1930
2131
  return;
1931
2132
  }
1932
2133
  } catch (u) {
1933
- c = { value: u, [C]: 0 };
2134
+ l = { value: u, [C]: 0 };
1934
2135
  }
1935
- Promise.resolve(c).catch((u) => ({ value: u, [C]: 0 })).then((u) => {
1936
- const [d, p] = U(u);
1937
- e.postMessage(Object.assign(Object.assign({}, d), { id: i }), p), o === "RELEASE" && (e.removeEventListener("message", s), de(e), I in t && typeof t[I] == "function" && t[I]());
2136
+ Promise.resolve(l).catch((u) => ({ value: u, [C]: 0 })).then((u) => {
2137
+ 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]());
1938
2139
  }).catch((u) => {
1939
- const [d, p] = U({
2140
+ const [d, p] = A({
1940
2141
  value: new TypeError("Unserializable return value"),
1941
2142
  [C]: 0
1942
2143
  });
@@ -1944,116 +2145,116 @@ function M(t, e = globalThis, r = ["*"]) {
1944
2145
  });
1945
2146
  }), e.start && e.start();
1946
2147
  }
1947
- function xt(t) {
2148
+ function Vt(t) {
1948
2149
  return t.constructor.name === "MessagePort";
1949
2150
  }
1950
- function de(t) {
1951
- xt(t) && t.close();
2151
+ function _e(t) {
2152
+ Vt(t) && t.close();
1952
2153
  }
1953
- function j(t, e) {
1954
- return N(t, [], e);
2154
+ function V(t, e) {
2155
+ return M(t, [], e);
1955
2156
  }
1956
- function x(t) {
2157
+ function T(t) {
1957
2158
  if (t)
1958
2159
  throw new Error("Proxy has been released and is not useable");
1959
2160
  }
1960
- function pe(t) {
2161
+ function $e(t) {
1961
2162
  return $(t, {
1962
2163
  type: "RELEASE"
1963
2164
  }).then(() => {
1964
- de(t);
2165
+ _e(t);
1965
2166
  });
1966
2167
  }
1967
- const k = /* @__PURE__ */ new WeakMap(), O = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
1968
- const e = (k.get(t) || 0) - 1;
1969
- k.set(t, e), e === 0 && pe(t);
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);
1970
2171
  });
1971
- function Ct(t, e) {
1972
- const r = (k.get(e) || 0) + 1;
1973
- k.set(e, r), O && O.register(t, e, t);
2172
+ function Gt(t, e) {
2173
+ const r = (F.get(e) || 0) + 1;
2174
+ F.set(e, r), O && O.register(t, e, t);
1974
2175
  }
1975
- function Ft(t) {
2176
+ function Jt(t) {
1976
2177
  O && O.unregister(t);
1977
2178
  }
1978
- function N(t, e = [], r = function() {
2179
+ function M(t, e = [], r = function() {
1979
2180
  }) {
1980
2181
  let s = !1;
1981
2182
  const n = new Proxy(r, {
1982
2183
  get(i, o) {
1983
- if (x(s), o === vt)
2184
+ if (T(s), o === zt)
1984
2185
  return () => {
1985
- Ft(n), pe(t), s = !0;
2186
+ Jt(n), $e(t), s = !0;
1986
2187
  };
1987
2188
  if (o === "then") {
1988
2189
  if (e.length === 0)
1989
2190
  return { then: () => n };
1990
2191
  const a = $(t, {
1991
2192
  type: "GET",
1992
- path: e.map((l) => l.toString())
2193
+ path: e.map((c) => c.toString())
1993
2194
  }).then(P);
1994
2195
  return a.then.bind(a);
1995
2196
  }
1996
- return N(t, [...e, o]);
2197
+ return M(t, [...e, o]);
1997
2198
  },
1998
2199
  set(i, o, a) {
1999
- x(s);
2000
- const [l, c] = U(a);
2200
+ T(s);
2201
+ const [c, l] = A(a);
2001
2202
  return $(t, {
2002
2203
  type: "SET",
2003
2204
  path: [...e, o].map((u) => u.toString()),
2004
- value: l
2005
- }, c).then(P);
2205
+ value: c
2206
+ }, l).then(P);
2006
2207
  },
2007
2208
  apply(i, o, a) {
2008
- x(s);
2009
- const l = e[e.length - 1];
2010
- if (l === St)
2209
+ T(s);
2210
+ const c = e[e.length - 1];
2211
+ if (c === Dt)
2011
2212
  return $(t, {
2012
2213
  type: "ENDPOINT"
2013
2214
  }).then(P);
2014
- if (l === "bind")
2015
- return N(t, e.slice(0, -1));
2016
- const [c, u] = Z(a);
2215
+ if (c === "bind")
2216
+ return M(t, e.slice(0, -1));
2217
+ const [l, u] = ae(a);
2017
2218
  return $(t, {
2018
2219
  type: "APPLY",
2019
2220
  path: e.map((d) => d.toString()),
2020
- argumentList: c
2221
+ argumentList: l
2021
2222
  }, u).then(P);
2022
2223
  },
2023
2224
  construct(i, o) {
2024
- x(s);
2025
- const [a, l] = Z(o);
2225
+ T(s);
2226
+ const [a, c] = ae(o);
2026
2227
  return $(t, {
2027
2228
  type: "CONSTRUCT",
2028
- path: e.map((c) => c.toString()),
2229
+ path: e.map((l) => l.toString()),
2029
2230
  argumentList: a
2030
- }, l).then(P);
2231
+ }, c).then(P);
2031
2232
  }
2032
2233
  });
2033
- return Ct(n, t), n;
2234
+ return Gt(n, t), n;
2034
2235
  }
2035
- function kt(t) {
2236
+ function Yt(t) {
2036
2237
  return Array.prototype.concat.apply([], t);
2037
2238
  }
2038
- function Z(t) {
2039
- const e = t.map(U);
2040
- return [e.map((r) => r[0]), kt(e.map((r) => r[1]))];
2239
+ function ae(t) {
2240
+ const e = t.map(A);
2241
+ return [e.map((r) => r[0]), Yt(e.map((r) => r[1]))];
2041
2242
  }
2042
- const fe = /* @__PURE__ */ new WeakMap();
2043
- function Ot(t, e) {
2044
- return fe.set(t, e), t;
2243
+ const Ee = /* @__PURE__ */ new WeakMap();
2244
+ function Kt(t, e) {
2245
+ return Ee.set(t, e), t;
2045
2246
  }
2046
- function me(t) {
2047
- return Object.assign(t, { [ue]: !0 });
2247
+ function ve(t) {
2248
+ return Object.assign(t, { [Pe]: !0 });
2048
2249
  }
2049
- function Ut(t, e = globalThis, r = "*") {
2250
+ function Qt(t, e = globalThis, r = "*") {
2050
2251
  return {
2051
2252
  postMessage: (s, n) => t.postMessage(s, r, n),
2052
2253
  addEventListener: e.addEventListener.bind(e),
2053
2254
  removeEventListener: e.removeEventListener.bind(e)
2054
2255
  };
2055
2256
  }
2056
- function U(t) {
2257
+ function A(t) {
2057
2258
  for (const [e, r] of R)
2058
2259
  if (r.canHandle(t)) {
2059
2260
  const [s, n] = r.serialize(t);
@@ -2071,7 +2272,7 @@ function U(t) {
2071
2272
  type: "RAW",
2072
2273
  value: t
2073
2274
  },
2074
- fe.get(t) || []
2275
+ Ee.get(t) || []
2075
2276
  ];
2076
2277
  }
2077
2278
  function P(t) {
@@ -2084,25 +2285,25 @@ function P(t) {
2084
2285
  }
2085
2286
  function $(t, e, r) {
2086
2287
  return new Promise((s) => {
2087
- const n = Lt();
2288
+ const n = Xt();
2088
2289
  t.addEventListener("message", function i(o) {
2089
2290
  !o.data || !o.data.id || o.data.id !== n || (t.removeEventListener("message", i), s(o.data));
2090
2291
  }), t.start && t.start(), t.postMessage(Object.assign({ id: n }, e), r);
2091
2292
  });
2092
2293
  }
2093
- function Lt() {
2294
+ function Xt() {
2094
2295
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
2095
2296
  }
2096
- function we(t) {
2097
- At();
2098
- const e = t instanceof Worker ? t : Ut(t), r = j(e), s = ge(r);
2297
+ function Se(t) {
2298
+ Zt();
2299
+ const e = t instanceof Worker ? t : Qt(t), r = V(e), s = Re(r);
2099
2300
  return new Proxy(s, {
2100
2301
  get: (n, i) => i === "isConnected" ? () => r.isConnected() : r[i]
2101
2302
  });
2102
2303
  }
2103
- let ee = !1;
2104
- function At() {
2105
- ee || (ee = !0, R.set("EVENT", {
2304
+ let ce = !1;
2305
+ function Zt() {
2306
+ ce || (ce = !0, R.set("EVENT", {
2106
2307
  canHandle: (t) => t instanceof CustomEvent,
2107
2308
  serialize: (t) => [
2108
2309
  {
@@ -2116,10 +2317,10 @@ function At() {
2116
2317
  serialize(t) {
2117
2318
  console.debug("[Comlink][Performance] Proxying a function");
2118
2319
  const { port1: e, port2: r } = new MessageChannel();
2119
- return M(t, e), [r, [r]];
2320
+ return B(t, e), [r, [r]];
2120
2321
  },
2121
2322
  deserialize(t) {
2122
- return t.start(), j(t);
2323
+ return t.start(), V(t);
2123
2324
  }
2124
2325
  }), R.set("PHPResponse", {
2125
2326
  canHandle: (t) => typeof t == "object" && t !== null && "headers" in t && "bytes" in t && "errors" in t && "exitCode" in t && "httpStatusCode" in t,
@@ -2127,24 +2328,24 @@ function At() {
2127
2328
  return [t.toRawData(), []];
2128
2329
  },
2129
2330
  deserialize(t) {
2130
- return v.fromRawData(t);
2331
+ return S.fromRawData(t);
2131
2332
  }
2132
2333
  }));
2133
2334
  }
2134
- function ge(t) {
2335
+ function Re(t) {
2135
2336
  return new Proxy(t, {
2136
2337
  get(e, r) {
2137
2338
  switch (typeof e[r]) {
2138
2339
  case "function":
2139
2340
  return (...s) => e[r](...s);
2140
2341
  case "object":
2141
- return e[r] === null ? e[r] : ge(e[r]);
2342
+ return e[r] === null ? e[r] : Re(e[r]);
2142
2343
  case "undefined":
2143
2344
  case "number":
2144
2345
  case "string":
2145
2346
  return e[r];
2146
2347
  default:
2147
- return me(e[r]);
2348
+ return ve(e[r]);
2148
2349
  }
2149
2350
  }
2150
2351
  });
@@ -2152,101 +2353,102 @@ function ge(t) {
2152
2353
  (function() {
2153
2354
  return typeof navigator < "u" && navigator?.userAgent?.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
2154
2355
  })();
2155
- async function Ht({
2356
+ async function er({
2156
2357
  iframe: t,
2157
2358
  blueprint: e,
2158
2359
  remoteUrl: r,
2159
- progressTracker: s = new A(),
2360
+ progressTracker: s = new U(),
2160
2361
  disableProgressBar: n,
2161
2362
  onBlueprintStepCompleted: i
2162
2363
  }) {
2163
- if (It(r), r = re(r, {
2364
+ if (tr(r), r = ue(r, {
2164
2365
  progressbar: !n
2165
2366
  }), s.setCaption("Preparing WordPress"), !e)
2166
- return te(t, r, s);
2167
- const o = yt(e, {
2367
+ return le(t, r, s);
2368
+ const o = Ht(e, {
2168
2369
  progress: s.stage(0.5),
2169
2370
  onStepCompleted: i
2170
- }), a = await te(
2371
+ }), a = await le(
2171
2372
  t,
2172
- re(r, {
2373
+ ue(r, {
2173
2374
  php: o.versions.php,
2174
2375
  wp: o.versions.wp
2175
2376
  }),
2176
2377
  s
2177
2378
  );
2178
- return await $t(o, a), s.finish(), a;
2379
+ return await Wt(o, a), s.finish(), a;
2179
2380
  }
2180
- async function te(t, e, r) {
2381
+ async function le(t, e, r) {
2181
2382
  await new Promise((i) => {
2182
2383
  t.src = e, t.addEventListener("load", i, !1);
2183
2384
  });
2184
- const s = we(
2385
+ const s = Se(
2185
2386
  t.contentWindow
2186
2387
  );
2187
2388
  await s.isConnected(), r.pipe(s);
2188
2389
  const n = r.stage();
2189
2390
  return await s.onDownloadProgress(n.loadingListener), await s.isReady(), n.finish(), s;
2190
2391
  }
2191
- const F = "https://playground.wordpress.net";
2192
- function It(t) {
2193
- const e = new URL(t, F);
2194
- if ((e.origin === F || e.hostname === "localhost") && e.pathname !== "/remote.html")
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")
2195
2396
  throw new Error(
2196
- `Invalid remote URL: ${e}. Expected origin to be ${F}/remote.html.`
2397
+ `Invalid remote URL: ${e}. Expected origin to be ${k}/remote.html.`
2197
2398
  );
2198
2399
  }
2199
- function re(t, e) {
2200
- const r = new URL(t, F), s = new URLSearchParams(r.search);
2400
+ function ue(t, e) {
2401
+ const r = new URL(t, k), s = new URLSearchParams(r.search);
2201
2402
  for (const [n, i] of Object.entries(e))
2202
2403
  i != null && i !== !1 && s.set(n, i.toString());
2203
2404
  return r.search = s.toString(), r.toString();
2204
2405
  }
2205
- async function zt(t, e) {
2406
+ async function nr(t, e) {
2206
2407
  if (console.warn(
2207
2408
  "`connectPlayground` is deprecated and will be removed. Use `startPlayground` instead."
2208
2409
  ), e?.loadRemote)
2209
- return Ht({
2410
+ return er({
2210
2411
  iframe: t,
2211
2412
  remoteUrl: e.loadRemote
2212
2413
  });
2213
- const r = we(
2414
+ const r = Se(
2214
2415
  t.contentWindow
2215
2416
  );
2216
2417
  return await r.isConnected(), r;
2217
2418
  }
2218
2419
  export {
2219
- Ye as LatestSupportedPHPVersion,
2220
- z as SupportedPHPVersions,
2221
- Nt as SupportedPHPVersionsList,
2222
- _e as activatePlugin,
2223
- $e as applyWordPressPatches,
2224
- yt as compileBlueprint,
2225
- zt as connectPlayground,
2226
- xe as cp,
2227
- Le as defineSiteUrl,
2228
- Ne as importFile,
2229
- qe as installPlugin,
2230
- We as installTheme,
2231
- Me as login,
2232
- Fe as mkdir,
2233
- Ce as mv,
2234
- S as phpVar,
2235
- D as phpVars,
2236
- Ie as replaceSite,
2237
- Te as request,
2238
- ke as rm,
2239
- Oe as rmdir,
2240
- $t as runBlueprintSteps,
2241
- ve as runPHP,
2242
- Ee as runPHPWithOptions,
2243
- je as runWpInstallationWizard,
2244
- Re as setPhpIniEntry,
2245
- Dt as setPluginProxyURL,
2246
- Be as setSiteOptions,
2247
- Ht as startPlaygroundWeb,
2248
- ne as unzip,
2249
- Ve as updateUserMeta,
2250
- Ue as writeFile,
2251
- He as zipEntireSite
2420
+ it as LatestSupportedPHPVersion,
2421
+ D as SupportedPHPVersions,
2422
+ rr as SupportedPHPVersionsList,
2423
+ 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
2252
2454
  };