@wp-playground/blueprints 0.1.42 → 0.1.45

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,20 +1,20 @@
1
- function _(r) {
1
+ function b(r) {
2
2
  return new DOMParser().parseFromString(r.text, "text/html");
3
3
  }
4
4
  function E(r) {
5
5
  const e = r.split(".").shift().replace("-", " ");
6
6
  return e.charAt(0).toUpperCase() + e.slice(1).toLowerCase();
7
7
  }
8
- async function P(r, e, t) {
8
+ async function g(r, e, t) {
9
9
  let s = "";
10
10
  await r.fileExists(e) && (s = await r.readFileAsText(e)), await r.writeFile(e, t(s));
11
11
  }
12
- async function ne(r) {
12
+ async function oe(r) {
13
13
  return new Uint8Array(await r.arrayBuffer());
14
14
  }
15
- const ie = async (r, { plugin: e }, t) => {
15
+ const O = "/vfs-blueprints", A = "/vfs-blueprints/wp-config-consts.php", ae = async (r, { plugin: e }, t) => {
16
16
  t?.tracker.setCaption(`Activating ${e}`);
17
- const i = _(
17
+ const i = b(
18
18
  await r.request({
19
19
  url: "/wp-admin/plugins.php"
20
20
  })
@@ -24,20 +24,20 @@ const ie = async (r, { plugin: e }, t) => {
24
24
  await r.request({
25
25
  url: "/wp-admin/" + i
26
26
  });
27
- }, oe = async (r, e) => {
28
- const t = new ae(
27
+ }, ce = async (r, e) => {
28
+ const t = new le(
29
29
  r,
30
30
  e.siteUrl,
31
31
  e.wordpressPath || "/wordpress"
32
32
  );
33
33
  e.patchSqlitePlugin !== !1 && await t.patchSqlitePlugin(), e.addPhpInfo !== !1 && await t.addPhpInfo(), e.patchSiteUrl !== !1 && await t.patchSiteUrl(), e.disableSiteHealth !== !1 && await t.disableSiteHealth(), e.disableWpNewBlogNotification !== !1 && await t.disableWpNewBlogNotification();
34
34
  };
35
- class ae {
35
+ class le {
36
36
  constructor(e, t, s) {
37
37
  this.php = e, this.scopedSiteUrl = t, this.wordpressPath = s;
38
38
  }
39
39
  async patchSqlitePlugin() {
40
- await P(
40
+ await g(
41
41
  this.php,
42
42
  `${this.wordpressPath}/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php`,
43
43
  (e) => e.replace(
@@ -53,7 +53,7 @@ class ae {
53
53
  );
54
54
  }
55
55
  async patchSiteUrl() {
56
- await P(
56
+ await g(
57
57
  this.php,
58
58
  `${this.wordpressPath}/wp-config.php`,
59
59
  (e) => `<?php
@@ -65,7 +65,7 @@ class ae {
65
65
  );
66
66
  }
67
67
  async disableSiteHealth() {
68
- await P(
68
+ await g(
69
69
  this.php,
70
70
  `${this.wordpressPath}/wp-includes/default-filters.php`,
71
71
  (e) => e.replace(
@@ -75,7 +75,7 @@ class ae {
75
75
  );
76
76
  }
77
77
  async disableWpNewBlogNotification() {
78
- await P(
78
+ await g(
79
79
  this.php,
80
80
  `${this.wordpressPath}/wp-config.php`,
81
81
  // The original version of this function crashes WASM PHP, let's define an empty one instead.
@@ -83,33 +83,33 @@ class ae {
83
83
  );
84
84
  }
85
85
  }
86
- const ce = async (r, { code: e }) => await r.run({ code: e }), le = async (r, { options: e }) => await r.run(e), ue = async (r, { key: e, value: t }) => {
86
+ const ue = async (r, { code: e }) => await r.run({ code: e }), he = async (r, { options: e }) => await r.run(e), pe = async (r, { key: e, value: t }) => {
87
87
  await r.setPhpIniEntry(e, t);
88
- }, he = async (r, { request: e }) => await r.request(e), pe = async (r, { fromPath: e, toPath: t }) => {
88
+ }, de = async (r, { request: e }) => await r.request(e), fe = async (r, { fromPath: e, toPath: t }) => {
89
89
  await r.writeFile(
90
90
  t,
91
91
  await r.readFileAsBuffer(e)
92
92
  );
93
- }, de = async (r, { fromPath: e, toPath: t }) => {
93
+ }, me = async (r, { fromPath: e, toPath: t }) => {
94
94
  await r.mv(e, t);
95
- }, fe = async (r, { path: e }) => {
95
+ }, we = async (r, { path: e }) => {
96
96
  await r.mkdir(e);
97
- }, me = async (r, { path: e }) => {
97
+ }, ge = async (r, { path: e }) => {
98
98
  await r.unlink(e);
99
- }, we = async (r, { path: e }) => {
99
+ }, ye = async (r, { path: e }) => {
100
100
  await r.rmdir(e);
101
- }, ge = async (r, { path: e, data: t }) => {
102
- t instanceof File && (t = await ne(t)), await r.writeFile(e, t);
103
- }, V = async (r, { consts: e }) => {
101
+ }, Pe = async (r, { path: e, data: t }) => {
102
+ t instanceof File && (t = await oe(t)), await r.writeFile(e, t);
103
+ }, K = async (r, { consts: e }) => {
104
104
  const t = await r.documentRoot;
105
- await P(
105
+ await g(
106
106
  r,
107
107
  `${t}/playground-consts.json`,
108
108
  (s) => JSON.stringify({
109
109
  ...JSON.parse(s || "{}"),
110
110
  ...e
111
111
  })
112
- ), await P(
112
+ ), await g(
113
113
  r,
114
114
  `${t}/wp-config.php`,
115
115
  (s) => s.includes("playground-consts.json") ? s : `<?php
@@ -121,13 +121,13 @@ const ce = async (r, { code: e }) => await r.run({ code: e }), le = async (r, {
121
121
  }
122
122
  ?>${s}`
123
123
  );
124
- }, ye = async (r, { siteUrl: e }) => await V(r, {
124
+ }, _e = async (r, { siteUrl: e }) => await K(r, {
125
125
  consts: {
126
126
  WP_HOME: e,
127
127
  WP_SITEURL: e
128
128
  }
129
129
  });
130
- class J {
130
+ class Y {
131
131
  constructor({ concurrency: e }) {
132
132
  this._running = 0, this.concurrency = e, this.queue = [];
133
133
  }
@@ -152,18 +152,18 @@ class J {
152
152
  }
153
153
  }
154
154
  }
155
- const Pe = Symbol("literal");
156
- function b(r) {
155
+ const be = Symbol("literal");
156
+ function _(r) {
157
157
  if (typeof r == "string")
158
158
  return r.startsWith("$") ? r : JSON.stringify(r);
159
159
  if (typeof r == "number")
160
160
  return r.toString();
161
161
  if (Array.isArray(r))
162
- return `array(${r.map(b).join(", ")})`;
162
+ return `array(${r.map(_).join(", ")})`;
163
163
  if (r === null)
164
164
  return "null";
165
165
  if (typeof r == "object")
166
- return Pe in r ? r.toString() : `array(${Object.entries(r).map(([t, s]) => `${JSON.stringify(t)} => ${b(s)}`).join(", ")})`;
166
+ return be in r ? r.toString() : `array(${Object.entries(r).map(([t, s]) => `${JSON.stringify(t)} => ${_(s)}`).join(", ")})`;
167
167
  if (typeof r == "function")
168
168
  return r();
169
169
  throw new Error(`Unsupported value: ${r}`);
@@ -171,10 +171,10 @@ function b(r) {
171
171
  function x(r) {
172
172
  const e = {};
173
173
  for (const t in r)
174
- e[t] = b(r[t]);
174
+ e[t] = _(r[t]);
175
175
  return e;
176
176
  }
177
- const A = `<?php
177
+ const I = `<?php
178
178
 
179
179
  function zipDir($dir, $output, $additionalFiles = array())
180
180
  {
@@ -237,28 +237,28 @@ function delTree($dir)
237
237
  return rmdir($dir);
238
238
  }
239
239
  `;
240
- async function be(r) {
240
+ async function $e(r) {
241
241
  const e = "wordpress-playground.zip", t = `/${e}`, s = x({
242
242
  zipPath: t,
243
243
  documentRoot: await r.documentRoot
244
244
  });
245
- await Y(
245
+ await Q(
246
246
  r,
247
247
  `zipDir(${s.documentRoot}, ${s.zipPath});`
248
248
  );
249
249
  const n = await r.readFileAsBuffer(t);
250
250
  return r.unlink(t), new File([n], e);
251
251
  }
252
- const _e = async (r, { fullSiteZip: e }) => {
252
+ const ve = async (r, { fullSiteZip: e }) => {
253
253
  const t = "/import.zip";
254
254
  await r.writeFile(
255
255
  t,
256
256
  new Uint8Array(await e.arrayBuffer())
257
257
  );
258
258
  const s = await r.absoluteUrl, n = await r.documentRoot;
259
- await r.rmdir(n), await K(r, { zipPath: t, extractToPath: "/" });
259
+ await r.rmdir(n), await Z(r, { zipPath: t, extractToPath: "/" });
260
260
  const i = x({ absoluteUrl: s });
261
- await Se(
261
+ await Re(
262
262
  r,
263
263
  `${n}/wp-config.php`,
264
264
  (o) => `<?php
@@ -268,30 +268,30 @@ const _e = async (r, { fullSiteZip: e }) => {
268
268
  }
269
269
  ?>${o}`
270
270
  );
271
- }, K = async (r, { zipPath: e, extractToPath: t }) => {
271
+ }, Z = async (r, { zipPath: e, extractToPath: t }) => {
272
272
  const s = x({
273
273
  zipPath: e,
274
274
  extractToPath: t
275
275
  });
276
- await Y(
276
+ await Q(
277
277
  r,
278
278
  `unzip(${s.zipPath}, ${s.extractToPath});`
279
279
  );
280
- }, $e = async (r, { file: e }) => {
280
+ }, Se = async (r, { file: e }) => {
281
281
  const t = await r.request({
282
282
  url: "/wp-admin/admin.php?import=wordpress"
283
- }), s = O(t).getElementById("import-upload-form")?.getAttribute("action"), n = await r.request({
283
+ }), s = L(t).getElementById("import-upload-form")?.getAttribute("action"), n = await r.request({
284
284
  url: `/wp-admin/${s}`,
285
285
  method: "POST",
286
286
  files: { import: e }
287
- }), i = O(n).querySelector(
287
+ }), i = L(n).querySelector(
288
288
  "#wpbody-content form"
289
289
  );
290
290
  if (!i)
291
291
  throw console.log(n.text), new Error(
292
292
  "Could not find an importer form in response. See the response text above for details."
293
293
  );
294
- const o = ve(i);
294
+ const o = Ee(i);
295
295
  o.fetch_attachments = "1";
296
296
  for (const a in o)
297
297
  if (a.startsWith("user_map[")) {
@@ -304,34 +304,34 @@ const _e = async (r, { fullSiteZip: e }) => {
304
304
  formData: o
305
305
  });
306
306
  };
307
- function O(r) {
307
+ function L(r) {
308
308
  return new DOMParser().parseFromString(r.text, "text/html");
309
309
  }
310
- function ve(r) {
310
+ function Ee(r) {
311
311
  return Object.fromEntries(new FormData(r).entries());
312
312
  }
313
- async function Se(r, e, t) {
313
+ async function Re(r, e, t) {
314
314
  await r.writeFile(
315
315
  e,
316
316
  t(await r.readFileAsText(e))
317
317
  );
318
318
  }
319
- async function Y(r, e) {
319
+ async function Q(r, e) {
320
320
  const t = await r.run({
321
- code: A + e
321
+ code: I + e
322
322
  });
323
323
  if (t.exitCode !== 0)
324
- throw console.log(A + e), console.log(e + ""), console.log(t.errors), t.errors;
324
+ throw console.log(I + e), console.log(e + ""), console.log(t.errors), t.errors;
325
325
  return t;
326
326
  }
327
- const Ee = async (r, { pluginZipFile: e, options: t = {} }, s) => {
327
+ const Te = async (r, { pluginZipFile: e, options: t = {} }, s) => {
328
328
  s?.tracker.setCaption(
329
329
  `Installing the ${E(e?.name)} plugin`
330
330
  );
331
331
  try {
332
332
  const n = "activate" in t ? t.activate : !0, i = await r.request({
333
333
  url: "/wp-admin/plugin-install.php?tab=upload"
334
- }), o = _(i), a = new FormData(
334
+ }), o = b(i), a = new FormData(
335
335
  o.querySelector(".wp-upload-form")
336
336
  ), { pluginzip: c, ...u } = Object.fromEntries(
337
337
  a.entries()
@@ -342,7 +342,7 @@ const Ee = async (r, { pluginZipFile: e, options: t = {} }, s) => {
342
342
  files: { pluginzip: e }
343
343
  });
344
344
  if (n) {
345
- const v = _(h).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value, S = new URL(
345
+ const v = b(h).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value, S = new URL(
346
346
  v,
347
347
  await r.pathToInternalUrl("/wp-admin/")
348
348
  ).toString();
@@ -352,14 +352,14 @@ const Ee = async (r, { pluginZipFile: e, options: t = {} }, s) => {
352
352
  }
353
353
  await r.isDir(
354
354
  "/wordpress/wp-content/plugins/gutenberg"
355
- ) && !await r.fileExists("/wordpress/.gutenberg-patched") && (await r.writeFile("/wordpress/.gutenberg-patched", "1"), await L(
355
+ ) && !await r.fileExists("/wordpress/.gutenberg-patched") && (await r.writeFile("/wordpress/.gutenberg-patched", "1"), await H(
356
356
  r,
357
357
  "/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.js",
358
358
  (d) => d.replace(
359
359
  /srcDoc:("[^"]+"|[^,]+)/g,
360
360
  'src:"/wp-includes/empty.html"'
361
361
  )
362
- ), await L(
362
+ ), await H(
363
363
  r,
364
364
  "/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.min.js",
365
365
  (d) => d.replace(
@@ -373,20 +373,20 @@ const Ee = async (r, { pluginZipFile: e, options: t = {} }, s) => {
373
373
  ), console.error(n);
374
374
  }
375
375
  };
376
- async function L(r, e, t) {
376
+ async function H(r, e, t) {
377
377
  return await r.writeFile(
378
378
  e,
379
379
  t(await r.readFileAsText(e))
380
380
  );
381
381
  }
382
- const Re = async (r, { themeZipFile: e, options: t = {} }, s) => {
382
+ const xe = async (r, { themeZipFile: e, options: t = {} }, s) => {
383
383
  s?.tracker.setCaption(
384
384
  `Installing the ${E(e.name)} theme`
385
385
  );
386
386
  try {
387
387
  const n = "activate" in t ? t.activate : !0, i = await r.request({
388
388
  url: "/wp-admin/theme-install.php"
389
- }), o = _(i), a = new FormData(
389
+ }), o = b(i), a = new FormData(
390
390
  o.querySelector(".wp-upload-form")
391
391
  ), { themezip: c, ...u } = Object.fromEntries(
392
392
  a.entries()
@@ -397,7 +397,7 @@ const Re = async (r, { themeZipFile: e, options: t = {} }, s) => {
397
397
  files: { themezip: e }
398
398
  });
399
399
  if (n) {
400
- const d = _(h), v = d.querySelector(
400
+ const d = b(h), v = d.querySelector(
401
401
  "#wpbody-content > .wrap"
402
402
  );
403
403
  if (v?.textContent?.includes(
@@ -413,12 +413,12 @@ const Re = async (r, { themeZipFile: e, options: t = {} }, s) => {
413
413
  console.error('The "activate" button was not found.');
414
414
  return;
415
415
  }
416
- const re = S.attributes.getNamedItem("href").value, se = new URL(
417
- re,
416
+ const ne = S.attributes.getNamedItem("href").value, ie = new URL(
417
+ ne,
418
418
  await r.pathToInternalUrl("/wp-admin/")
419
419
  ).toString();
420
420
  await r.request({
421
- url: se
421
+ url: ie
422
422
  });
423
423
  }
424
424
  } catch (n) {
@@ -426,7 +426,7 @@ const Re = async (r, { themeZipFile: e, options: t = {} }, s) => {
426
426
  `Proceeding without the ${e.name} theme. Could not install it in wp-admin. The original error was: ${n}`
427
427
  ), console.error(n);
428
428
  }
429
- }, Te = async (r, { username: e = "admin", password: t = "password" } = {}, s) => {
429
+ }, Fe = async (r, { username: e = "admin", password: t = "password" } = {}, s) => {
430
430
  s?.tracker.setCaption(s?.initialCaption || "Logging in"), await r.request({
431
431
  url: "/wp-login.php"
432
432
  }), await r.request({
@@ -438,7 +438,7 @@ const Re = async (r, { themeZipFile: e, options: t = {} }, s) => {
438
438
  rememberme: "forever"
439
439
  }
440
440
  });
441
- }, xe = async (r, { options: e }) => {
441
+ }, ke = async (r, { options: e }) => {
442
442
  await r.request({
443
443
  url: "/wp-admin/install.php?step=2",
444
444
  method: "POST",
@@ -455,10 +455,10 @@ const Re = async (r, { themeZipFile: e, options: t = {} }, s) => {
455
455
  admin_email: "admin@localhost.com"
456
456
  }
457
457
  });
458
- }, Fe = async (r, { options: e }) => {
458
+ }, Ce = async (r, { options: e }) => {
459
459
  const t = `<?php
460
460
  include 'wordpress/wp-load.php';
461
- $site_options = ${b(e)};
461
+ $site_options = ${_(e)};
462
462
  foreach($site_options as $name => $value) {
463
463
  update_option($name, $value);
464
464
  }
@@ -466,53 +466,72 @@ const Re = async (r, { themeZipFile: e, options: t = {} }, s) => {
466
466
  `, s = await r.run({
467
467
  code: t
468
468
  });
469
- return Z(s), { code: t, result: s };
470
- }, ke = async (r, { meta: e, userId: t }) => {
469
+ return X(s), { code: t, result: s };
470
+ }, Ue = async (r, { meta: e, userId: t }) => {
471
471
  const s = `<?php
472
472
  include 'wordpress/wp-load.php';
473
- $meta = ${b(e)};
473
+ $meta = ${_(e)};
474
474
  foreach($meta as $name => $value) {
475
- update_user_meta(${b(t)}, $name, $value);
475
+ update_user_meta(${_(t)}, $name, $value);
476
476
  }
477
477
  echo "Success";
478
478
  `, n = await r.run({
479
479
  code: s
480
480
  });
481
- return Z(n), { code: s, result: n };
481
+ return X(n), { code: s, result: n };
482
482
  };
483
- async function Z(r) {
483
+ async function X(r) {
484
484
  if (r.text !== "Success")
485
485
  throw console.log(r), new Error(`Failed to run code: ${r.text} ${r.errors}`);
486
486
  }
487
- const Ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
487
+ const Oe = async (r, { consts: e }) => {
488
+ r.mkdir(O);
489
+ const t = `${O}/playground-consts.json`;
490
+ return await g(
491
+ r,
492
+ t,
493
+ (s) => JSON.stringify({
494
+ ...JSON.parse(s || "{}"),
495
+ ...e
496
+ })
497
+ ), await g(r, A, (s) => s.includes("playground-consts.json") ? s : `<?php
498
+ $consts = json_decode(file_get_contents('${t}'), true);
499
+ foreach ($consts as $const => $value) {
500
+ if (!defined($const)) {
501
+ define($const, $value);
502
+ }
503
+ }
504
+ ?>${s}`), A;
505
+ }, Ae = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
488
506
  __proto__: null,
489
- activatePlugin: ie,
490
- applyWordPressPatches: oe,
491
- cp: pe,
492
- defineSiteUrl: ye,
493
- defineWpConfigConsts: V,
494
- importFile: $e,
495
- installPlugin: Ee,
496
- installTheme: Re,
497
- login: Te,
498
- mkdir: fe,
499
- mv: de,
500
- replaceSite: _e,
501
- request: he,
502
- rm: me,
503
- rmdir: we,
504
- runPHP: ce,
505
- runPHPWithOptions: le,
506
- runWpInstallationWizard: xe,
507
- setPhpIniEntry: ue,
508
- setSiteOptions: Fe,
509
- unzip: K,
510
- updateUserMeta: ke,
511
- writeFile: ge,
512
- zipEntireSite: be
513
- }, Symbol.toStringTag, { value: "Module" })), Ue = 5 * 1024 * 1024;
514
- function Ae(r, e) {
515
- const t = r.headers.get("content-length") || "", s = parseInt(t, 10) || Ue;
507
+ activatePlugin: ae,
508
+ applyWordPressPatches: ce,
509
+ cp: fe,
510
+ defineSiteUrl: _e,
511
+ defineVirtualWpConfigConsts: Oe,
512
+ defineWpConfigConsts: K,
513
+ importFile: Se,
514
+ installPlugin: Te,
515
+ installTheme: xe,
516
+ login: Fe,
517
+ mkdir: we,
518
+ mv: me,
519
+ replaceSite: ve,
520
+ request: de,
521
+ rm: ge,
522
+ rmdir: ye,
523
+ runPHP: ue,
524
+ runPHPWithOptions: he,
525
+ runWpInstallationWizard: ke,
526
+ setPhpIniEntry: pe,
527
+ setSiteOptions: Ce,
528
+ unzip: Z,
529
+ updateUserMeta: Ue,
530
+ writeFile: Pe,
531
+ zipEntireSite: $e
532
+ }, Symbol.toStringTag, { value: "Module" })), Ie = 5 * 1024 * 1024;
533
+ function Le(r, e) {
534
+ const t = r.headers.get("content-length") || "", s = parseInt(t, 10) || Ie;
516
535
  function n(i, o) {
517
536
  e(
518
537
  new CustomEvent("progress", {
@@ -720,6 +739,151 @@ class F extends EventTarget {
720
739
  this.dispatchEvent(new CustomEvent("done"));
721
740
  }
722
741
  }
742
+ const N = Symbol("error"), q = Symbol("message");
743
+ class k extends Event {
744
+ /**
745
+ * Create a new `ErrorEvent`.
746
+ *
747
+ * @param type The name of the event
748
+ * @param options A dictionary object that allows for setting
749
+ * attributes via object members of the same name.
750
+ */
751
+ constructor(e, t = {}) {
752
+ super(e), this[N] = t.error === void 0 ? null : t.error, this[q] = t.message === void 0 ? "" : t.message;
753
+ }
754
+ get error() {
755
+ return this[N];
756
+ }
757
+ get message() {
758
+ return this[q];
759
+ }
760
+ }
761
+ Object.defineProperty(k.prototype, "error", { enumerable: !0 });
762
+ Object.defineProperty(k.prototype, "message", { enumerable: !0 });
763
+ const He = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : k;
764
+ class Ne extends EventTarget {
765
+ constructor() {
766
+ super(...arguments), this.listenersCount = 0;
767
+ }
768
+ addEventListener(e, t) {
769
+ ++this.listenersCount, super.addEventListener(e, t);
770
+ }
771
+ removeEventListener(e, t) {
772
+ --this.listenersCount, super.removeEventListener(e, t);
773
+ }
774
+ hasListeners() {
775
+ return this.listenersCount > 0;
776
+ }
777
+ }
778
+ function qe(r) {
779
+ r.asm = {
780
+ ...r.asm
781
+ };
782
+ const e = new Ne();
783
+ for (const t in r.asm)
784
+ if (typeof r.asm[t] == "function") {
785
+ const s = r.asm[t];
786
+ r.asm[t] = function(...n) {
787
+ try {
788
+ return s(...n);
789
+ } catch (i) {
790
+ if (!(i instanceof Error))
791
+ throw i;
792
+ if ("exitCode" in i && i?.exitCode === 0)
793
+ return;
794
+ const o = We(
795
+ i,
796
+ r.lastAsyncifyStackSource?.stack
797
+ );
798
+ if (r.lastAsyncifyStackSource && (i.cause = r.lastAsyncifyStackSource), !e.hasListeners())
799
+ throw ze(o), i;
800
+ e.dispatchEvent(
801
+ new He("error", {
802
+ error: i,
803
+ message: o
804
+ })
805
+ );
806
+ }
807
+ };
808
+ }
809
+ return e;
810
+ }
811
+ let T = [];
812
+ function De() {
813
+ return T;
814
+ }
815
+ function We(r, e) {
816
+ if (r.message === "unreachable") {
817
+ let t = Me;
818
+ e || (t += `
819
+
820
+ This stack trace is lacking. For a better one initialize
821
+ the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
822
+
823
+ `), T = Be(
824
+ e || r.stack || ""
825
+ );
826
+ for (const s of T)
827
+ t += ` * ${s}
828
+ `;
829
+ return t;
830
+ }
831
+ return r.message;
832
+ }
833
+ const Me = `
834
+ "unreachable" WASM instruction executed.
835
+
836
+ The typical reason is a PHP function missing from the ASYNCIFY_ONLY
837
+ list when building PHP.wasm.
838
+
839
+ You will need to file a new issue in the WordPress Playground repository
840
+ and paste this error message there:
841
+
842
+ https://github.com/WordPress/wordpress-playground/issues/new
843
+
844
+ If you're a core developer, the typical fix is to:
845
+
846
+ * Isolate a minimal reproduction of the error
847
+ * Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository
848
+ * Run 'npm run fix-asyncify'
849
+ * Commit the changes, push to the repo, release updated NPM packages
850
+
851
+ Below is a list of all the PHP functions found in the stack trace to
852
+ help with the minimal reproduction. If they're all already listed in
853
+ the Dockerfile, you'll need to trigger this error again with long stack
854
+ traces enabled. In node.js, you can do it using the --stack-trace-limit=100
855
+ CLI option:
856
+
857
+ `, D = "\x1B[41m", je = "\x1B[1m", W = "\x1B[0m", M = "\x1B[K";
858
+ let j = !1;
859
+ function ze(r) {
860
+ if (!j) {
861
+ j = !0, console.log(`${D}
862
+ ${M}
863
+ ${je} WASM ERROR${W}${D}`);
864
+ for (const e of r.split(`
865
+ `))
866
+ console.log(`${M} ${e} `);
867
+ console.log(`${W}`);
868
+ }
869
+ }
870
+ function Be(r) {
871
+ try {
872
+ const e = r.split(`
873
+ `).slice(1).map((t) => {
874
+ const s = t.trim().substring(3).split(" ");
875
+ return {
876
+ fn: s.length >= 2 ? s[0] : "<unknown>",
877
+ isWasm: t.includes("wasm://")
878
+ };
879
+ }).filter(
880
+ ({ fn: t, isWasm: s }) => s && !t.startsWith("dynCall_") && !t.startsWith("invoke_")
881
+ ).map(({ fn: t }) => t);
882
+ return Array.from(new Set(e));
883
+ } catch {
884
+ return [];
885
+ }
886
+ }
723
887
  class $ {
724
888
  constructor(e, t, s, n = "", i = 0) {
725
889
  this.httpStatusCode = e, this.headers = t, this.bytes = s, this.exitCode = i, this.errors = n;
@@ -755,7 +919,7 @@ class $ {
755
919
  return new TextDecoder().decode(this.bytes);
756
920
  }
757
921
  }
758
- const Q = [
922
+ const ee = [
759
923
  "8.2",
760
924
  "8.1",
761
925
  "8.0",
@@ -765,8 +929,8 @@ const Q = [
765
929
  "7.1",
766
930
  "7.0",
767
931
  "5.6"
768
- ], Oe = Q[0];
769
- class Le {
932
+ ], Ge = ee[0];
933
+ class Ve {
770
934
  #e;
771
935
  #t;
772
936
  /**
@@ -799,10 +963,10 @@ class Le {
799
963
  ...e,
800
964
  headers: {
801
965
  ...e.headers,
802
- cookie: this.#n()
966
+ cookie: this.#r()
803
967
  }
804
968
  });
805
- if (s.headers["set-cookie"] && this.#r(s.headers["set-cookie"]), this.#t.handleRedirects && s.headers.location && t < this.#t.maxRedirects) {
969
+ if (s.headers["set-cookie"] && this.#s(s.headers["set-cookie"]), this.#t.handleRedirects && s.headers.location && t < this.#t.maxRedirects) {
806
970
  const n = new URL(
807
971
  s.headers.location[0],
808
972
  this.requestHandler.absoluteUrl
@@ -834,7 +998,7 @@ class Le {
834
998
  get documentRoot() {
835
999
  return this.requestHandler.documentRoot;
836
1000
  }
837
- #r(e) {
1001
+ #s(e) {
838
1002
  for (const t of e)
839
1003
  try {
840
1004
  if (!t.includes("="))
@@ -845,30 +1009,30 @@ class Le {
845
1009
  console.error(s);
846
1010
  }
847
1011
  }
848
- #n() {
1012
+ #r() {
849
1013
  const e = [];
850
1014
  for (const t in this.#e)
851
1015
  e.push(`${t}=${this.#e[t]}`);
852
1016
  return e.join("; ");
853
1017
  }
854
1018
  }
855
- const Ie = "http://example.com";
856
- function I(r) {
1019
+ const Je = "http://example.com";
1020
+ function z(r) {
857
1021
  return r.toString().substring(r.origin.length);
858
1022
  }
859
- function H(r, e) {
1023
+ function B(r, e) {
860
1024
  return !e || !r.startsWith(e) ? r : r.substring(e.length);
861
1025
  }
862
- function He(r, e) {
1026
+ function Ke(r, e) {
863
1027
  return !e || r.startsWith(e) ? r : e + r;
864
1028
  }
865
- class Ne {
1029
+ class Ye {
866
1030
  #e;
867
1031
  #t;
1032
+ #s;
868
1033
  #r;
869
- #n;
870
1034
  #i;
871
- #s;
1035
+ #n;
872
1036
  #o;
873
1037
  #a;
874
1038
  #c;
@@ -877,7 +1041,7 @@ class Ne {
877
1041
  * @param config - Request Handler configuration.
878
1042
  */
879
1043
  constructor(e, t = {}) {
880
- this.#a = new J({ concurrency: 1 });
1044
+ this.#a = new Y({ concurrency: 1 });
881
1045
  const {
882
1046
  documentRoot: s = "/www/",
883
1047
  absoluteUrl: n = typeof location == "object" ? location?.href : "",
@@ -885,15 +1049,15 @@ class Ne {
885
1049
  } = t;
886
1050
  this.php = e, this.#e = s, this.#c = i;
887
1051
  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;
1052
+ this.#s = o.hostname, this.#r = o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80, this.#t = (o.protocol || "").replace(":", "");
1053
+ const a = this.#r !== 443 && this.#r !== 80;
890
1054
  this.#i = [
891
- this.#r,
892
- a ? `:${this.#n}` : ""
893
- ].join(""), this.#s = o.pathname.replace(/\/+$/, ""), this.#o = [
1055
+ this.#s,
1056
+ a ? `:${this.#r}` : ""
1057
+ ].join(""), this.#n = o.pathname.replace(/\/+$/, ""), this.#o = [
894
1058
  `${this.#t}://`,
895
1059
  this.#i,
896
- this.#s
1060
+ this.#n
897
1061
  ].join("");
898
1062
  }
899
1063
  /** @inheritDoc */
@@ -903,7 +1067,7 @@ class Ne {
903
1067
  /** @inheritDoc */
904
1068
  internalUrlToPath(e) {
905
1069
  const t = new URL(e);
906
- return t.pathname.startsWith(this.#s) && (t.pathname = t.pathname.slice(this.#s.length)), I(t);
1070
+ return t.pathname.startsWith(this.#n) && (t.pathname = t.pathname.slice(this.#n.length)), z(t);
907
1071
  }
908
1072
  get isRequestRunning() {
909
1073
  return this.#a.running > 0;
@@ -920,10 +1084,10 @@ class Ne {
920
1084
  async request(e) {
921
1085
  const t = e.url.startsWith("http://") || e.url.startsWith("https://"), s = new URL(
922
1086
  e.url,
923
- t ? void 0 : Ie
924
- ), n = H(
1087
+ t ? void 0 : Je
1088
+ ), n = B(
925
1089
  s.pathname,
926
- this.#s
1090
+ this.#n
927
1091
  );
928
1092
  return this.#c(n) ? this.#l(n) : await this.#u(e, s);
929
1093
  }
@@ -949,7 +1113,7 @@ class Ne {
949
1113
  // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
950
1114
  // The code below won't return the correct mime-type if the extension
951
1115
  // was tampered with.
952
- "content-type": [De(t)],
1116
+ "content-type": [Qe(t)],
953
1117
  "accept-ranges": ["bytes"],
954
1118
  "cache-control": ["public, max-age=0"]
955
1119
  },
@@ -973,7 +1137,7 @@ class Ne {
973
1137
  let n = "GET";
974
1138
  const i = {
975
1139
  host: this.#i,
976
- ...X(e.headers || {})
1140
+ ...te(e.headers || {})
977
1141
  }, o = [];
978
1142
  if (e.files && Object.keys(e.files).length) {
979
1143
  n = "POST";
@@ -986,7 +1150,7 @@ class Ne {
986
1150
  data: new Uint8Array(await u.arrayBuffer())
987
1151
  });
988
1152
  }
989
- i["content-type"]?.startsWith("multipart/form-data") && (e.formData = qe(
1153
+ i["content-type"]?.startsWith("multipart/form-data") && (e.formData = Ze(
990
1154
  e.body || ""
991
1155
  ), i["content-type"] = "application/x-www-form-urlencoded", delete e.body);
992
1156
  }
@@ -994,9 +1158,9 @@ class Ne {
994
1158
  return e.formData !== void 0 ? (n = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
995
1159
  e.formData
996
1160
  ).toString()) : a = e.body, await this.php.run({
997
- relativeUri: He(
998
- I(t),
999
- this.#s
1161
+ relativeUri: Ke(
1162
+ z(t),
1163
+ this.#n
1000
1164
  ),
1001
1165
  protocol: this.#t,
1002
1166
  method: e.method || n,
@@ -1018,13 +1182,13 @@ class Ne {
1018
1182
  * @returns The resolved filesystem path.
1019
1183
  */
1020
1184
  #h(e) {
1021
- let t = H(e, this.#s);
1185
+ let t = B(e, this.#n);
1022
1186
  t.includes(".php") ? t = t.split(".php")[0] + ".php" : (t.endsWith("/") || (t += "/"), t.endsWith("index.php") || (t += "index.php"));
1023
1187
  const s = `${this.#e}${t}`;
1024
1188
  return this.php.fileExists(s) ? s : `${this.#e}/index.php`;
1025
1189
  }
1026
1190
  }
1027
- function qe(r) {
1191
+ function Ze(r) {
1028
1192
  const e = {}, t = r.match(/--(.*)\r\n/);
1029
1193
  if (!t)
1030
1194
  return e;
@@ -1039,7 +1203,7 @@ function qe(r) {
1039
1203
  }
1040
1204
  }), e;
1041
1205
  }
1042
- function De(r) {
1206
+ function Qe(r) {
1043
1207
  switch (r.split(".").pop()) {
1044
1208
  case "css":
1045
1209
  return "text/css";
@@ -1079,7 +1243,7 @@ function De(r) {
1079
1243
  return "application-octet-stream";
1080
1244
  }
1081
1245
  }
1082
- const N = {
1246
+ const G = {
1083
1247
  0: "No error occurred. System call completed successfully.",
1084
1248
  1: "Argument list too long.",
1085
1249
  2: "Permission denied.",
@@ -1166,8 +1330,8 @@ function f(r = "") {
1166
1330
  return i.apply(this, o);
1167
1331
  } catch (a) {
1168
1332
  const c = typeof a == "object" ? a?.errno : null;
1169
- if (c in N) {
1170
- const u = N[c], h = typeof o[0] == "string" ? o[0] : null, d = h !== null ? r.replaceAll("{path}", h) : r;
1333
+ if (c in G) {
1334
+ const u = G[c], h = typeof o[0] == "string" ? o[0] : null, d = h !== null ? r.replaceAll("{path}", h) : r;
1171
1335
  throw new Error(`${d}: ${u}`, {
1172
1336
  cause: a
1173
1337
  });
@@ -1177,164 +1341,19 @@ function f(r = "") {
1177
1341
  };
1178
1342
  };
1179
1343
  }
1180
- const We = [];
1181
- function Me(r) {
1182
- return We[r];
1344
+ const Xe = [];
1345
+ function et(r) {
1346
+ return Xe[r];
1183
1347
  }
1184
1348
  (function() {
1185
1349
  return typeof process < "u" && process.release?.name === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
1186
1350
  })();
1187
- const q = Symbol("error"), D = Symbol("message");
1188
- class k 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, t = {}) {
1197
- super(e), this[q] = t.error === void 0 ? null : t.error, this[D] = t.message === void 0 ? "" : t.message;
1198
- }
1199
- get error() {
1200
- return this[q];
1201
- }
1202
- get message() {
1203
- return this[D];
1204
- }
1205
- }
1206
- Object.defineProperty(k.prototype, "error", { enumerable: !0 });
1207
- Object.defineProperty(k.prototype, "message", { enumerable: !0 });
1208
- const ze = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : k;
1209
- class Be extends EventTarget {
1210
- constructor() {
1211
- super(...arguments), this.listenersCount = 0;
1212
- }
1213
- addEventListener(e, t) {
1214
- ++this.listenersCount, super.addEventListener(e, t);
1215
- }
1216
- removeEventListener(e, t) {
1217
- --this.listenersCount, super.removeEventListener(e, t);
1218
- }
1219
- hasListeners() {
1220
- return this.listenersCount > 0;
1221
- }
1222
- }
1223
- function je(r) {
1224
- r.asm = {
1225
- ...r.asm
1226
- };
1227
- const e = new Be();
1228
- for (const t in r.asm)
1229
- if (typeof r.asm[t] == "function") {
1230
- const s = r.asm[t];
1231
- r.asm[t] = 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 = Ve(
1240
- i,
1241
- r.lastAsyncifyStackSource?.stack
1242
- );
1243
- if (r.lastAsyncifyStackSource && (i.cause = r.lastAsyncifyStackSource), !e.hasListeners())
1244
- throw Ye(o), i;
1245
- e.dispatchEvent(
1246
- new ze("error", {
1247
- error: i,
1248
- message: o
1249
- })
1250
- );
1251
- }
1252
- };
1253
- }
1254
- return e;
1255
- }
1256
- let T = [];
1257
- function Ge() {
1258
- return T;
1259
- }
1260
- function Ve(r, e) {
1261
- if (r.message === "unreachable") {
1262
- let t = Je;
1263
- e || (t += `
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
- `), T = Ze(
1269
- e || r.stack || ""
1270
- );
1271
- for (const s of T)
1272
- t += ` * ${s}
1273
- `;
1274
- return t;
1275
- }
1276
- return r.message;
1277
- }
1278
- const Je = `
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
- `, W = "\x1B[41m", Ke = "\x1B[1m", M = "\x1B[0m", z = "\x1B[K";
1303
- let B = !1;
1304
- function Ye(r) {
1305
- if (!B) {
1306
- B = !0, console.log(`${W}
1307
- ${z}
1308
- ${Ke} WASM ERROR${M}${W}`);
1309
- for (const e of r.split(`
1310
- `))
1311
- console.log(`${z} ${e} `);
1312
- console.log(`${M}`);
1313
- }
1314
- }
1315
- function Ze(r) {
1316
- try {
1317
- const e = r.split(`
1318
- `).slice(1).map((t) => {
1319
- const s = t.trim().substring(3).split(" ");
1320
- return {
1321
- fn: s.length >= 2 ? s[0] : "<unknown>",
1322
- isWasm: t.includes("wasm://")
1323
- };
1324
- }).filter(
1325
- ({ fn: t, isWasm: s }) => s && !t.startsWith("dynCall_") && !t.startsWith("invoke_")
1326
- ).map(({ fn: t }) => t);
1327
- return Array.from(new Set(e));
1328
- } catch {
1329
- return [];
1330
- }
1331
- }
1332
- var Qe = Object.defineProperty, Xe = Object.getOwnPropertyDescriptor, m = (r, e, t, s) => {
1333
- for (var n = s > 1 ? void 0 : s ? Xe(e, t) : e, i = r.length - 1, o; i >= 0; i--)
1351
+ var tt = Object.defineProperty, rt = Object.getOwnPropertyDescriptor, m = (r, e, t, s) => {
1352
+ for (var n = s > 1 ? void 0 : s ? rt(e, t) : e, i = r.length - 1, o; i >= 0; i--)
1334
1353
  (o = r[i]) && (n = (s ? o(e, t, n) : o(n)) || n);
1335
- return s && n && Qe(e, t, n), n;
1354
+ return s && n && tt(e, t, n), n;
1336
1355
  };
1337
- const p = "string", y = "number", l = Symbol("__private__dont__use");
1356
+ const p = "string", P = "number", l = Symbol("__private__dont__use");
1338
1357
  class w {
1339
1358
  /**
1340
1359
  * Initializes a PHP runtime.
@@ -1344,12 +1363,13 @@ class w {
1344
1363
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
1345
1364
  */
1346
1365
  constructor(e, t) {
1347
- this.#e = [], this.#t = !1, this.#r = null, e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new Le(
1348
- new Ne(this, t)
1366
+ this.#e = [], this.#t = !1, this.#s = null, this.#r = {}, e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new Ve(
1367
+ new Ye(this, t)
1349
1368
  ));
1350
1369
  }
1351
1370
  #e;
1352
1371
  #t;
1372
+ #s;
1353
1373
  #r;
1354
1374
  /** @inheritDoc */
1355
1375
  get absoluteUrl() {
@@ -1372,10 +1392,10 @@ class w {
1372
1392
  initializeRuntime(e) {
1373
1393
  if (this[l])
1374
1394
  throw new Error("PHP runtime already initialized.");
1375
- const t = Me(e);
1395
+ const t = et(e);
1376
1396
  if (!t)
1377
1397
  throw new Error("Invalid PHP runtime id.");
1378
- this[l] = t, this.#r = je(t);
1398
+ this[l] = t, this.#s = qe(t);
1379
1399
  }
1380
1400
  /** @inheritDoc */
1381
1401
  setPhpIniPath(e) {
@@ -1406,17 +1426,17 @@ class w {
1406
1426
  }
1407
1427
  /** @inheritDoc */
1408
1428
  async run(e) {
1409
- this.#t || (this.#n(), this.#t = !0), this.#u(e.scriptPath || ""), this.#s(e.relativeUri || ""), this.#a(e.method || "GET");
1429
+ this.#t || (this.#i(), this.#t = !0), this.#h(e.scriptPath || ""), this.#o(e.relativeUri || ""), this.#c(e.method || "GET");
1410
1430
  const { host: t, ...s } = {
1411
1431
  host: "example.com:443",
1412
- ...X(e.headers || {})
1432
+ ...te(e.headers || {})
1413
1433
  };
1414
- if (this.#o(t, e.protocol || "http"), this.#c(s), e.body && this.#l(e.body), e.fileInfos)
1434
+ if (this.#a(t, e.protocol || "http"), this.#l(s), e.body && this.#u(e.body), e.fileInfos)
1415
1435
  for (const n of e.fileInfos)
1416
- this.#h(n);
1417
- return e.code && this.#p(" ?>" + e.code), await this.#d();
1436
+ this.#d(n);
1437
+ return e.code && this.#f(" ?>" + e.code), this.#p(), await this.#m();
1418
1438
  }
1419
- #n() {
1439
+ #i() {
1420
1440
  if (this.#e.length > 0) {
1421
1441
  const e = this.#e.map(([t, s]) => `${t}=${s}`).join(`
1422
1442
  `) + `
@@ -1431,7 +1451,7 @@ class w {
1431
1451
  }
1432
1452
  this[l].ccall("php_wasm_init", null, [], []);
1433
1453
  }
1434
- #i() {
1454
+ #n() {
1435
1455
  const e = "/tmp/headers.json";
1436
1456
  if (!this.fileExists(e))
1437
1457
  throw new Error(
@@ -1449,7 +1469,7 @@ class w {
1449
1469
  httpStatusCode: t.status
1450
1470
  };
1451
1471
  }
1452
- #s(e) {
1472
+ #o(e) {
1453
1473
  if (this[l].ccall(
1454
1474
  "wasm_set_request_uri",
1455
1475
  null,
@@ -1465,7 +1485,7 @@ class w {
1465
1485
  );
1466
1486
  }
1467
1487
  }
1468
- #o(e, t) {
1488
+ #a(e, t) {
1469
1489
  this[l].ccall(
1470
1490
  "wasm_set_request_host",
1471
1491
  null,
@@ -1480,11 +1500,11 @@ class w {
1480
1500
  (!s || isNaN(s) || s === 80) && (s = t === "https" ? 443 : 80), this[l].ccall(
1481
1501
  "wasm_set_request_port",
1482
1502
  null,
1483
- [y],
1503
+ [P],
1484
1504
  [s]
1485
1505
  ), (t === "https" || !t && s === 443) && this.addServerGlobalEntry("HTTPS", "on");
1486
1506
  }
1487
- #a(e) {
1507
+ #c(e) {
1488
1508
  this[l].ccall(
1489
1509
  "wasm_set_request_method",
1490
1510
  null,
@@ -1492,7 +1512,7 @@ class w {
1492
1512
  [e]
1493
1513
  );
1494
1514
  }
1495
- #c(e) {
1515
+ #l(e) {
1496
1516
  e.cookie && this[l].ccall(
1497
1517
  "wasm_set_cookies",
1498
1518
  null,
@@ -1506,7 +1526,7 @@ class w {
1506
1526
  ), e["content-length"] && this[l].ccall(
1507
1527
  "wasm_set_content_length",
1508
1528
  null,
1509
- [y],
1529
+ [P],
1510
1530
  [parseInt(e["content-length"], 10)]
1511
1531
  );
1512
1532
  for (const t in e)
@@ -1515,7 +1535,7 @@ class w {
1515
1535
  e[t]
1516
1536
  );
1517
1537
  }
1518
- #l(e) {
1538
+ #u(e) {
1519
1539
  this[l].ccall(
1520
1540
  "wasm_set_request_body",
1521
1541
  null,
@@ -1524,11 +1544,11 @@ class w {
1524
1544
  ), this[l].ccall(
1525
1545
  "wasm_set_content_length",
1526
1546
  null,
1527
- [y],
1547
+ [P],
1528
1548
  [new TextEncoder().encode(e).length]
1529
1549
  );
1530
1550
  }
1531
- #u(e) {
1551
+ #h(e) {
1532
1552
  this[l].ccall(
1533
1553
  "wasm_set_path_translated",
1534
1554
  null,
@@ -1537,12 +1557,16 @@ class w {
1537
1557
  );
1538
1558
  }
1539
1559
  addServerGlobalEntry(e, t) {
1540
- this[l].ccall(
1541
- "wasm_add_SERVER_entry",
1542
- null,
1543
- [p, p],
1544
- [e, t]
1545
- );
1560
+ this.#r[e] = t;
1561
+ }
1562
+ #p() {
1563
+ for (const e in this.#r)
1564
+ this[l].ccall(
1565
+ "wasm_add_SERVER_entry",
1566
+ null,
1567
+ [p, p],
1568
+ [e, this.#r[e]]
1569
+ );
1546
1570
  }
1547
1571
  /**
1548
1572
  * Adds file information to $_FILES superglobal in PHP.
@@ -1553,18 +1577,18 @@ class w {
1553
1577
  *
1554
1578
  * @param fileInfo - File details
1555
1579
  */
1556
- #h(e) {
1580
+ #d(e) {
1557
1581
  const { key: t, name: s, type: n, data: i } = e, o = `/tmp/${Math.random().toFixed(20)}`;
1558
1582
  this.writeFile(o, i);
1559
1583
  const a = 0;
1560
1584
  this[l].ccall(
1561
1585
  "wasm_add_uploaded_file",
1562
1586
  null,
1563
- [p, p, p, p, y, y],
1587
+ [p, p, p, p, P, P],
1564
1588
  [t, s, n, o, a, i.byteLength]
1565
1589
  );
1566
1590
  }
1567
- #p(e) {
1591
+ #f(e) {
1568
1592
  this[l].ccall(
1569
1593
  "wasm_set_php_code",
1570
1594
  null,
@@ -1572,14 +1596,14 @@ class w {
1572
1596
  [e]
1573
1597
  );
1574
1598
  }
1575
- async #d() {
1599
+ async #m() {
1576
1600
  let e, t;
1577
1601
  try {
1578
1602
  e = await new Promise(async (i, o) => {
1579
1603
  t = (a) => {
1580
1604
  const c = new Error("Rethrown");
1581
1605
  c.cause = a.error, c.betterMessage = a.message, o(c);
1582
- }, this.#r?.addEventListener(
1606
+ }, this.#s?.addEventListener(
1583
1607
  "error",
1584
1608
  t
1585
1609
  );
@@ -1593,7 +1617,7 @@ class w {
1593
1617
  */
1594
1618
  await await this[l].ccall(
1595
1619
  "wasm_sapi_handle_request",
1596
- y,
1620
+ P,
1597
1621
  [],
1598
1622
  []
1599
1623
  )
@@ -1609,13 +1633,13 @@ class w {
1609
1633
  "PHP runtime has crashed – see the earlier error for details."
1610
1634
  );
1611
1635
  });
1612
- this.functionsMaybeMissingFromAsyncify = Ge();
1636
+ this.functionsMaybeMissingFromAsyncify = De();
1613
1637
  const o = i, a = "betterMessage" in o ? o.betterMessage : o.message, c = new Error(a);
1614
1638
  throw c.cause = o, c;
1615
1639
  } finally {
1616
- this.#r?.removeEventListener("error", t);
1640
+ this.#s?.removeEventListener("error", t), this.#r = {};
1617
1641
  }
1618
- const { headers: s, httpStatusCode: n } = this.#i();
1642
+ const { headers: s, httpStatusCode: n } = this.#n();
1619
1643
  return new $(
1620
1644
  n,
1621
1645
  s,
@@ -1708,23 +1732,23 @@ m([
1708
1732
  m([
1709
1733
  f('Could not stat "{path}"')
1710
1734
  ], w.prototype, "fileExists", 1);
1711
- function X(r) {
1735
+ function te(r) {
1712
1736
  const e = {};
1713
1737
  for (const t in r)
1714
1738
  e[t.toLowerCase()] = r[t];
1715
1739
  return e;
1716
1740
  }
1717
- const et = [
1741
+ const st = [
1718
1742
  "vfs",
1719
1743
  "literal",
1720
1744
  "wordpress.org/themes",
1721
1745
  "wordpress.org/plugins",
1722
1746
  "url"
1723
1747
  ];
1724
- function tt(r) {
1725
- return r && typeof r == "object" && typeof r.resource == "string" && et.includes(r.resource);
1748
+ function nt(r) {
1749
+ return r && typeof r == "object" && typeof r.resource == "string" && st.includes(r.resource);
1726
1750
  }
1727
- class g {
1751
+ class y {
1728
1752
  /**
1729
1753
  * Creates a new Resource based on the given file reference
1730
1754
  *
@@ -1736,24 +1760,24 @@ class g {
1736
1760
  let n;
1737
1761
  switch (e.resource) {
1738
1762
  case "vfs":
1739
- n = new rt(e, s);
1763
+ n = new it(e, s);
1740
1764
  break;
1741
1765
  case "literal":
1742
- n = new st(e, s);
1766
+ n = new ot(e, s);
1743
1767
  break;
1744
1768
  case "wordpress.org/themes":
1745
- n = new ot(e, s);
1769
+ n = new lt(e, s);
1746
1770
  break;
1747
1771
  case "wordpress.org/plugins":
1748
- n = new at(e, s);
1772
+ n = new ut(e, s);
1749
1773
  break;
1750
1774
  case "url":
1751
- n = new it(e, s);
1775
+ n = new ct(e, s);
1752
1776
  break;
1753
1777
  default:
1754
1778
  throw new Error(`Invalid resource: ${e}`);
1755
1779
  }
1756
- return n = new ct(n), t && (n = new lt(n, t)), n;
1780
+ return n = new ht(n), t && (n = new pt(n, t)), n;
1757
1781
  }
1758
1782
  setPlayground(e) {
1759
1783
  this.playground = e;
@@ -1763,7 +1787,7 @@ class g {
1763
1787
  return !1;
1764
1788
  }
1765
1789
  }
1766
- class rt extends g {
1790
+ class it extends y {
1767
1791
  /**
1768
1792
  * Creates a new instance of `VFSResource`.
1769
1793
  * @param playground The playground client.
@@ -1785,7 +1809,7 @@ class rt extends g {
1785
1809
  return this.resource.path;
1786
1810
  }
1787
1811
  }
1788
- class st extends g {
1812
+ class ot extends y {
1789
1813
  /**
1790
1814
  * Creates a new instance of `LiteralResource`.
1791
1815
  * @param resource The literal reference.
@@ -1803,7 +1827,7 @@ class st extends g {
1803
1827
  return this.resource.name;
1804
1828
  }
1805
1829
  }
1806
- class C extends g {
1830
+ class C extends y {
1807
1831
  /**
1808
1832
  * Creates a new instance of `FetchResource`.
1809
1833
  * @param progress The progress tracker.
@@ -1816,9 +1840,9 @@ class C extends g {
1816
1840
  this.progress?.setCaption(this.caption);
1817
1841
  const e = this.getURL();
1818
1842
  let t = await fetch(e);
1819
- if (t = await Ae(
1843
+ if (t = await Le(
1820
1844
  t,
1821
- this.progress?.loadingListener ?? nt
1845
+ this.progress?.loadingListener ?? at
1822
1846
  ), t.status !== 200)
1823
1847
  throw new Error(`Could not download "${e}"`);
1824
1848
  return new File([await t.blob()], this.name);
@@ -1843,9 +1867,9 @@ class C extends g {
1843
1867
  return !0;
1844
1868
  }
1845
1869
  }
1846
- const nt = () => {
1870
+ const at = () => {
1847
1871
  };
1848
- class it extends C {
1872
+ class ct extends C {
1849
1873
  /**
1850
1874
  * Creates a new instance of `UrlResource`.
1851
1875
  * @param resource The URL reference.
@@ -1864,10 +1888,10 @@ class it extends C {
1864
1888
  }
1865
1889
  }
1866
1890
  let U = "https://playground.wordpress.net/plugin-proxy";
1867
- function ft(r) {
1891
+ function gt(r) {
1868
1892
  U = r;
1869
1893
  }
1870
- class ot extends C {
1894
+ class lt extends C {
1871
1895
  constructor(e, t) {
1872
1896
  super(t), this.resource = e;
1873
1897
  }
@@ -1875,11 +1899,11 @@ class ot extends C {
1875
1899
  return E(this.resource.slug);
1876
1900
  }
1877
1901
  getURL() {
1878
- const e = ee(this.resource.slug);
1902
+ const e = re(this.resource.slug);
1879
1903
  return `${U}?theme=` + e;
1880
1904
  }
1881
1905
  }
1882
- class at extends C {
1906
+ class ut extends C {
1883
1907
  constructor(e, t) {
1884
1908
  super(t), this.resource = e;
1885
1909
  }
@@ -1889,14 +1913,14 @@ class at extends C {
1889
1913
  }
1890
1914
  /** @inheritDoc */
1891
1915
  getURL() {
1892
- const e = ee(this.resource.slug);
1916
+ const e = re(this.resource.slug);
1893
1917
  return `${U}?plugin=` + e;
1894
1918
  }
1895
1919
  }
1896
- function ee(r) {
1920
+ function re(r) {
1897
1921
  return !r || r.endsWith(".zip") ? r : r + ".latest-stable.zip";
1898
1922
  }
1899
- class te extends g {
1923
+ class se extends y {
1900
1924
  constructor(e) {
1901
1925
  super(), this.resource = e;
1902
1926
  }
@@ -1925,13 +1949,13 @@ class te extends g {
1925
1949
  return this.resource.isAsync;
1926
1950
  }
1927
1951
  }
1928
- class ct extends te {
1952
+ class ht extends se {
1929
1953
  /** @inheritDoc */
1930
1954
  async resolve() {
1931
1955
  return this.promise || (this.promise = super.resolve()), this.promise;
1932
1956
  }
1933
1957
  }
1934
- class lt extends te {
1958
+ class pt extends se {
1935
1959
  constructor(e, t) {
1936
1960
  super(e), this.semaphore = t;
1937
1961
  }
@@ -1940,18 +1964,18 @@ class lt extends te {
1940
1964
  return this.isAsync ? this.semaphore.run(() => super.resolve()) : super.resolve();
1941
1965
  }
1942
1966
  }
1943
- const ut = ["6.2", "6.1", "6.0", "5.9"];
1944
- function mt(r, {
1967
+ const dt = ["6.2", "6.1", "6.0", "5.9"];
1968
+ function yt(r, {
1945
1969
  progress: e = new F(),
1946
- semaphore: t = new J({ concurrency: 3 }),
1970
+ semaphore: t = new Y({ concurrency: 3 }),
1947
1971
  onStepCompleted: s = () => {
1948
1972
  }
1949
1973
  } = {}) {
1950
- const n = (r.steps || []).filter(ht), i = n.reduce(
1974
+ const n = (r.steps || []).filter(ft), i = n.reduce(
1951
1975
  (a, c) => a + (c.progress?.weight || 1),
1952
1976
  0
1953
1977
  ), o = n.map(
1954
- (a) => pt(a, {
1978
+ (a) => mt(a, {
1955
1979
  semaphore: t,
1956
1980
  rootProgressTracker: e,
1957
1981
  totalProgressWeight: i
@@ -1959,14 +1983,14 @@ function mt(r, {
1959
1983
  );
1960
1984
  return {
1961
1985
  versions: {
1962
- php: j(
1986
+ php: V(
1963
1987
  r.preferredVersions?.php,
1964
- Q,
1965
- Oe
1988
+ ee,
1989
+ Ge
1966
1990
  ),
1967
- wp: j(
1991
+ wp: V(
1968
1992
  r.preferredVersions?.wp,
1969
- ut,
1993
+ dt,
1970
1994
  "6.2"
1971
1995
  )
1972
1996
  },
@@ -1991,13 +2015,13 @@ function mt(r, {
1991
2015
  }
1992
2016
  };
1993
2017
  }
1994
- function j(r, e, t) {
2018
+ function V(r, e, t) {
1995
2019
  return r && e.includes(r) ? r : t;
1996
2020
  }
1997
- function ht(r) {
2021
+ function ft(r) {
1998
2022
  return !!(typeof r == "object" && r);
1999
2023
  }
2000
- function pt(r, {
2024
+ function mt(r, {
2001
2025
  semaphore: e,
2002
2026
  rootProgressTracker: t,
2003
2027
  totalProgressWeight: s
@@ -2007,15 +2031,15 @@ function pt(r, {
2007
2031
  ), i = {};
2008
2032
  for (const h of Object.keys(r)) {
2009
2033
  let d = r[h];
2010
- tt(d) && (d = g.create(d, {
2034
+ nt(d) && (d = y.create(d, {
2011
2035
  semaphore: e
2012
2036
  })), i[h] = d;
2013
2037
  }
2014
2038
  const o = async (h) => {
2015
2039
  try {
2016
- return n.fillSlowly(), await Ce[r.step](
2040
+ return n.fillSlowly(), await Ae[r.step](
2017
2041
  h,
2018
- await dt(i),
2042
+ await wt(i),
2019
2043
  {
2020
2044
  tracker: n,
2021
2045
  initialCaption: r.progress?.caption
@@ -2024,58 +2048,59 @@ function pt(r, {
2024
2048
  } finally {
2025
2049
  n.finish();
2026
2050
  }
2027
- }, a = G(i), c = G(i).filter(
2051
+ }, a = J(i), c = J(i).filter(
2028
2052
  (h) => h.isAsync
2029
2053
  ), u = 1 / (c.length + 1);
2030
2054
  for (const h of c)
2031
2055
  h.progress = n.stage(u);
2032
2056
  return { run: o, step: r, resources: a };
2033
2057
  }
2034
- function G(r) {
2058
+ function J(r) {
2035
2059
  const e = [];
2036
2060
  for (const t in r) {
2037
2061
  const s = r[t];
2038
- s instanceof g && e.push(s);
2062
+ s instanceof y && e.push(s);
2039
2063
  }
2040
2064
  return e;
2041
2065
  }
2042
- async function dt(r) {
2066
+ async function wt(r) {
2043
2067
  const e = {};
2044
2068
  for (const t in r) {
2045
2069
  const s = r[t];
2046
- s instanceof g ? e[t] = await s.resolve() : e[t] = s;
2070
+ s instanceof y ? e[t] = await s.resolve() : e[t] = s;
2047
2071
  }
2048
2072
  return e;
2049
2073
  }
2050
- async function wt(r, e) {
2074
+ async function Pt(r, e) {
2051
2075
  await r.run(e);
2052
2076
  }
2053
2077
  export {
2054
- ie as activatePlugin,
2055
- oe as applyWordPressPatches,
2056
- mt as compileBlueprint,
2057
- pe as cp,
2058
- ye as defineSiteUrl,
2059
- V as defineWpConfigConsts,
2060
- $e as importFile,
2061
- Ee as installPlugin,
2062
- Re as installTheme,
2063
- Te as login,
2064
- fe as mkdir,
2065
- de as mv,
2066
- _e as replaceSite,
2067
- he as request,
2068
- me as rm,
2069
- we as rmdir,
2070
- wt as runBlueprintSteps,
2071
- ce as runPHP,
2072
- le as runPHPWithOptions,
2073
- xe as runWpInstallationWizard,
2074
- ue as setPhpIniEntry,
2075
- ft as setPluginProxyURL,
2076
- Fe as setSiteOptions,
2077
- K as unzip,
2078
- ke as updateUserMeta,
2079
- ge as writeFile,
2080
- be as zipEntireSite
2078
+ ae as activatePlugin,
2079
+ ce as applyWordPressPatches,
2080
+ yt as compileBlueprint,
2081
+ fe as cp,
2082
+ _e as defineSiteUrl,
2083
+ Oe as defineVirtualWpConfigConsts,
2084
+ K as defineWpConfigConsts,
2085
+ Se as importFile,
2086
+ Te as installPlugin,
2087
+ xe as installTheme,
2088
+ Fe as login,
2089
+ we as mkdir,
2090
+ me as mv,
2091
+ ve as replaceSite,
2092
+ de as request,
2093
+ ge as rm,
2094
+ ye as rmdir,
2095
+ Pt as runBlueprintSteps,
2096
+ ue as runPHP,
2097
+ he as runPHPWithOptions,
2098
+ ke as runWpInstallationWizard,
2099
+ pe as setPhpIniEntry,
2100
+ gt as setPluginProxyURL,
2101
+ Ce as setSiteOptions,
2102
+ Z as unzip,
2103
+ Ue as updateUserMeta,
2104
+ Pe as writeFile,
2105
+ $e as zipEntireSite
2081
2106
  };