@wp-playground/blueprints 0.1.56 → 0.1.58

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,61 +1,80 @@
1
- const ie = async (r, { pluginPath: e }, t) => {
2
- t?.tracker.setCaption(`Activating ${e}`);
3
- const s = [
4
- `${r.documentRoot}/wp-load.php`,
5
- `${r.documentRoot}/wp-admin/includes/plugin.php`
1
+ const J = async (s, { pluginPath: e, pluginName: t }, r) => {
2
+ r?.tracker.setCaption(`Activating ${t || e}`);
3
+ const i = [
4
+ `${await s.documentRoot}/wp-load.php`,
5
+ `${await s.documentRoot}/wp-admin/includes/plugin.php`
6
6
  ];
7
- if (!s.every(
8
- (i) => r.fileExists(i)
7
+ if (!i.every(
8
+ (a) => s.fileExists(a)
9
9
  ))
10
10
  throw new Error(
11
- `Required WordPress files do not exist: ${s.join(", ")}`
11
+ `Required WordPress files do not exist: ${i.join(", ")}`
12
12
  );
13
- await r.run({
13
+ if ((await s.run({
14
14
  code: `<?php
15
- ${s.map((i) => `require_once( '${i}' );`).join(`
15
+ ${i.map((a) => `require_once( '${a}' );`).join(`
16
16
  `)}
17
- activate_plugin('${e}');
18
- `
19
- });
20
- }, oe = async (r, { themeFolderName: e }, t) => {
17
+ $plugin_path = '${e}';
18
+ if (!is_dir($plugin_path)) {
19
+ activate_plugin($plugin_path);
20
+ return;
21
+ }
22
+ // Find plugin entry file
23
+ foreach ( ( glob( $plugin_path . '/*.php' ) ?: array() ) as $file ) {
24
+ $info = get_plugin_data( $file, false, false );
25
+ if ( ! empty( $info['Name'] ) ) {
26
+ activate_plugin( $file );
27
+ return;
28
+ }
29
+ }
30
+ echo 'NO_ENTRY_FILE';
31
+ `
32
+ })).text.endsWith("NO_ENTRY_FILE"))
33
+ throw new Error("Could not find plugin entry file.");
34
+ }, K = async (s, { themeFolderName: e }, t) => {
21
35
  t?.tracker.setCaption(`Activating ${e}`);
22
- const s = `${r.documentRoot}/wp-load.php`;
23
- if (!r.fileExists(s))
36
+ const r = `${await s.documentRoot}/wp-load.php`;
37
+ if (!s.fileExists(r))
24
38
  throw new Error(
25
- `Required WordPress file does not exist: ${s}`
39
+ `Required WordPress file does not exist: ${r}`
26
40
  );
27
- await r.run({
41
+ await s.run({
28
42
  code: `<?php
29
- require_once( '${s}' );
43
+ require_once( '${r}' );
30
44
  switch_theme( '${e}' );
31
45
  `
32
46
  });
33
47
  };
34
- function S(r) {
35
- return new DOMParser().parseFromString(r.text, "text/html");
36
- }
37
- function E(r) {
38
- const e = r.split(".").shift().replace("-", " ");
48
+ function b(s) {
49
+ const e = s.split(".").shift().replace(/-/g, " ");
39
50
  return e.charAt(0).toUpperCase() + e.slice(1).toLowerCase();
40
51
  }
41
- async function P(r, e, t) {
42
- let s = "";
43
- await r.fileExists(e) && (s = await r.readFileAsText(e)), await r.writeFile(e, t(s));
52
+ async function P(s, e, t) {
53
+ let r = "";
54
+ await s.fileExists(e) && (r = await s.readFileAsText(e)), await s.writeFile(e, t(r));
44
55
  }
45
- async function ae(r) {
46
- return new Uint8Array(await r.arrayBuffer());
56
+ async function ae(s) {
57
+ return new Uint8Array(await s.arrayBuffer());
47
58
  }
48
- const ce = async (r, e) => {
49
- const t = new le(
50
- r,
59
+ class ce extends File {
60
+ constructor(e, t) {
61
+ super(e, t), this.buffers = e;
62
+ }
63
+ async arrayBuffer() {
64
+ return this.buffers[0];
65
+ }
66
+ }
67
+ const R = File.prototype.arrayBuffer instanceof Function ? File : ce, le = async (s, e) => {
68
+ const t = new he(
69
+ s,
51
70
  e.siteUrl,
52
71
  e.wordpressPath || "/wordpress"
53
72
  );
54
73
  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();
55
74
  };
56
- class le {
57
- constructor(e, t, s) {
58
- this.php = e, this.scopedSiteUrl = t, this.wordpressPath = s;
75
+ class he {
76
+ constructor(e, t, r) {
77
+ this.php = e, this.scopedSiteUrl = t, this.wordpressPath = r;
59
78
  }
60
79
  async patchSqlitePlugin() {
61
80
  await P(
@@ -104,47 +123,47 @@ class le {
104
123
  );
105
124
  }
106
125
  }
107
- 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 }) => {
108
- await r.setPhpIniEntry(e, t);
109
- }, de = async (r, { request: e }) => await r.request(e), fe = async (r, { fromPath: e, toPath: t }) => {
110
- await r.writeFile(
126
+ const ue = async (s, { code: e }) => await s.run({ code: e }), pe = async (s, { options: e }) => await s.run(e), de = async (s, { key: e, value: t }) => {
127
+ await s.setPhpIniEntry(e, t);
128
+ }, fe = async (s, { request: e }) => await s.request(e), me = async (s, { fromPath: e, toPath: t }) => {
129
+ await s.writeFile(
111
130
  t,
112
- await r.readFileAsBuffer(e)
131
+ await s.readFileAsBuffer(e)
113
132
  );
114
- }, me = async (r, { fromPath: e, toPath: t }) => {
115
- await r.mv(e, t);
116
- }, we = async (r, { path: e }) => {
117
- await r.mkdir(e);
118
- }, ge = async (r, { path: e }) => {
119
- await r.unlink(e);
120
- }, ye = async (r, { path: e }) => {
121
- await r.rmdir(e);
122
- }, Pe = async (r, { path: e, data: t }) => {
123
- t instanceof File && (t = await ae(t)), await r.writeFile(e, t);
124
- }, A = "/vfs-blueprints", J = async (r, { consts: e, virtualize: t = !1 }) => {
125
- const s = await r.documentRoot, n = t ? A : s, i = `${n}/playground-consts.json`, o = `${n}/wp-config.php`;
126
- return t && (r.mkdir(A), r.setPhpIniEntry("auto_prepend_file", o)), await P(
127
- r,
128
- i,
133
+ }, we = async (s, { fromPath: e, toPath: t }) => {
134
+ await s.mv(e, t);
135
+ }, ge = async (s, { path: e }) => {
136
+ await s.mkdir(e);
137
+ }, ye = async (s, { path: e }) => {
138
+ await s.unlink(e);
139
+ }, Pe = async (s, { path: e }) => {
140
+ await s.rmdir(e);
141
+ }, Z = async (s, { path: e, data: t }) => {
142
+ t instanceof File && (t = await ae(t)), await s.writeFile(e, t);
143
+ }, O = "/vfs-blueprints", Q = async (s, { consts: e, virtualize: t = !1 }) => {
144
+ const r = await s.documentRoot, i = t ? O : r, n = `${i}/playground-consts.json`, o = `${i}/wp-config.php`;
145
+ return t && (s.mkdir(O), s.setPhpIniEntry("auto_prepend_file", o)), await P(
146
+ s,
147
+ n,
129
148
  (a) => JSON.stringify({
130
149
  ...JSON.parse(a || "{}"),
131
150
  ...e
132
151
  })
133
- ), await P(r, o, (a) => a.includes("playground-consts.json") ? a : `<?php
134
- $consts = json_decode(file_get_contents('${i}'), true);
152
+ ), await P(s, o, (a) => a.includes("playground-consts.json") ? a : `<?php
153
+ $consts = json_decode(file_get_contents('${n}'), true);
135
154
  foreach ($consts as $const => $value) {
136
155
  if (!defined($const)) {
137
156
  define($const, $value);
138
157
  }
139
158
  }
140
159
  ?>${a}`), o;
141
- }, _e = async (r, { siteUrl: e }) => await J(r, {
160
+ }, _e = async (s, { siteUrl: e }) => await Q(s, {
142
161
  consts: {
143
162
  WP_HOME: e,
144
163
  WP_SITEURL: e
145
164
  }
146
165
  });
147
- class Y {
166
+ class X {
148
167
  constructor({ concurrency: e }) {
149
168
  this._running = 0, this.concurrency = e, this.queue = [];
150
169
  }
@@ -169,29 +188,29 @@ class Y {
169
188
  }
170
189
  }
171
190
  }
172
- const be = Symbol("literal");
173
- function b(r) {
174
- if (typeof r == "string")
175
- return r.startsWith("$") ? r : JSON.stringify(r);
176
- if (typeof r == "number")
177
- return r.toString();
178
- if (Array.isArray(r))
179
- return `array(${r.map(b).join(", ")})`;
180
- if (r === null)
191
+ const $e = Symbol("literal");
192
+ function $(s) {
193
+ if (typeof s == "string")
194
+ return s.startsWith("$") ? s : JSON.stringify(s);
195
+ if (typeof s == "number")
196
+ return s.toString();
197
+ if (Array.isArray(s))
198
+ return `array(${s.map($).join(", ")})`;
199
+ if (s === null)
181
200
  return "null";
182
- if (typeof r == "object")
183
- return be in r ? r.toString() : `array(${Object.entries(r).map(([t, s]) => `${JSON.stringify(t)} => ${b(s)}`).join(", ")})`;
184
- if (typeof r == "function")
185
- return r();
186
- throw new Error(`Unsupported value: ${r}`);
201
+ if (typeof s == "object")
202
+ return $e in s ? s.toString() : `array(${Object.entries(s).map(([t, r]) => `${JSON.stringify(t)} => ${$(r)}`).join(", ")})`;
203
+ if (typeof s == "function")
204
+ return s();
205
+ throw new Error(`Unsupported value: ${s}`);
187
206
  }
188
- function T(r) {
207
+ function x(s) {
189
208
  const e = {};
190
- for (const t in r)
191
- e[t] = b(r[t]);
209
+ for (const t in s)
210
+ e[t] = $(s[t]);
192
211
  return e;
193
212
  }
194
- const O = `<?php
213
+ const N = `<?php
195
214
 
196
215
  function zipDir($dir, $output, $additionalFiles = array())
197
216
  {
@@ -254,199 +273,190 @@ function delTree($dir)
254
273
  return rmdir($dir);
255
274
  }
256
275
  `;
257
- async function $e(r) {
258
- const e = "wordpress-playground.zip", t = `/${e}`, s = T({
276
+ async function be(s) {
277
+ const e = "wordpress-playground.zip", t = `/${e}`, r = x({
259
278
  zipPath: t,
260
- documentRoot: await r.documentRoot
279
+ documentRoot: await s.documentRoot
261
280
  });
262
- await Z(
263
- r,
264
- `zipDir(${s.documentRoot}, ${s.zipPath});`
281
+ await ee(
282
+ s,
283
+ `zipDir(${r.documentRoot}, ${r.zipPath});`
265
284
  );
266
- const n = await r.readFileAsBuffer(t);
267
- return r.unlink(t), new File([n], e);
285
+ const i = await s.readFileAsBuffer(t);
286
+ return s.unlink(t), new File([i], e);
268
287
  }
269
- const ve = async (r, { fullSiteZip: e }) => {
288
+ const ve = async (s, { fullSiteZip: e }) => {
270
289
  const t = "/import.zip";
271
- await r.writeFile(
290
+ await s.writeFile(
272
291
  t,
273
292
  new Uint8Array(await e.arrayBuffer())
274
293
  );
275
- const s = await r.absoluteUrl, n = await r.documentRoot;
276
- await r.rmdir(n), await K(r, { zipPath: t, extractToPath: "/" });
277
- const i = T({ absoluteUrl: s });
294
+ const r = await s.absoluteUrl, i = await s.documentRoot;
295
+ await s.rmdir(i), await F(s, { zipPath: t, extractToPath: "/" });
296
+ const n = x({ absoluteUrl: r });
278
297
  await Re(
279
- r,
280
- `${n}/wp-config.php`,
298
+ s,
299
+ `${i}/wp-config.php`,
281
300
  (o) => `<?php
282
301
  if(!defined('WP_HOME')) {
283
- define('WP_HOME', ${i.absoluteUrl});
284
- define('WP_SITEURL', ${i.absoluteUrl});
302
+ define('WP_HOME', ${n.absoluteUrl});
303
+ define('WP_SITEURL', ${n.absoluteUrl});
285
304
  }
286
305
  ?>${o}`
287
306
  );
288
- }, K = async (r, { zipPath: e, extractToPath: t }) => {
289
- const s = T({
307
+ }, F = async (s, { zipPath: e, extractToPath: t }) => {
308
+ const r = x({
290
309
  zipPath: e,
291
310
  extractToPath: t
292
311
  });
293
- await Z(
294
- r,
295
- `unzip(${s.zipPath}, ${s.extractToPath});`
312
+ await ee(
313
+ s,
314
+ `unzip(${r.zipPath}, ${r.extractToPath});`
296
315
  );
297
- }, Se = async (r, { file: e }) => {
298
- const t = await r.request({
316
+ }, Ee = async (s, { file: e }) => {
317
+ const t = await s.request({
299
318
  url: "/wp-admin/admin.php?import=wordpress"
300
- }), s = I(t).getElementById("import-upload-form")?.getAttribute("action"), n = await r.request({
301
- url: `/wp-admin/${s}`,
319
+ }), r = L(t).getElementById("import-upload-form")?.getAttribute("action"), i = await s.request({
320
+ url: `/wp-admin/${r}`,
302
321
  method: "POST",
303
322
  files: { import: e }
304
- }), i = I(n).querySelector(
323
+ }), n = L(i).querySelector(
305
324
  "#wpbody-content form"
306
325
  );
307
- if (!i)
308
- throw console.log(n.text), new Error(
326
+ if (!n)
327
+ throw console.log(i.text), new Error(
309
328
  "Could not find an importer form in response. See the response text above for details."
310
329
  );
311
- const o = Ee(i);
330
+ const o = Se(n);
312
331
  o.fetch_attachments = "1";
313
332
  for (const a in o)
314
333
  if (a.startsWith("user_map[")) {
315
- const c = "user_new[" + a.slice(9, -1) + "]";
316
- o[c] = "1";
334
+ const l = "user_new[" + a.slice(9, -1) + "]";
335
+ o[l] = "1";
317
336
  }
318
- await r.request({
319
- url: i.action,
337
+ await s.request({
338
+ url: n.action,
320
339
  method: "POST",
321
340
  formData: o
322
341
  });
323
342
  };
324
- function I(r) {
325
- return new DOMParser().parseFromString(r.text, "text/html");
343
+ function L(s) {
344
+ return new DOMParser().parseFromString(s.text, "text/html");
326
345
  }
327
- function Ee(r) {
328
- return Object.fromEntries(new FormData(r).entries());
346
+ function Se(s) {
347
+ return Object.fromEntries(new FormData(s).entries());
329
348
  }
330
- async function Re(r, e, t) {
331
- await r.writeFile(
349
+ async function Re(s, e, t) {
350
+ await s.writeFile(
332
351
  e,
333
- t(await r.readFileAsText(e))
352
+ t(await s.readFileAsText(e))
334
353
  );
335
354
  }
336
- async function Z(r, e) {
337
- const t = await r.run({
338
- code: O + e
355
+ async function ee(s, e) {
356
+ const t = await s.run({
357
+ code: N + e
339
358
  });
340
359
  if (t.exitCode !== 0)
341
- throw console.log(O + e), console.log(e + ""), console.log(t.errors), t.errors;
360
+ throw console.log(N + e), console.log(e + ""), console.log(t.errors), t.errors;
342
361
  return t;
343
362
  }
344
- const xe = async (r, { pluginZipFile: e, options: t = {} }, s) => {
345
- s?.tracker.setCaption(
346
- `Installing the ${E(e?.name)} plugin`
347
- );
363
+ async function te(s, { targetPath: e, zipFile: t }) {
364
+ const r = t.name, i = r.replace(/\.zip$/, ""), n = `/tmp/assets/${i}`, o = `/tmp/${r}`, a = () => s.rmdir(n, {
365
+ recursive: !0
366
+ });
367
+ await s.fileExists(n) && await a(), await Z(s, {
368
+ path: o,
369
+ data: t
370
+ });
371
+ const l = () => Promise.all([a, () => s.unlink(o)]);
348
372
  try {
349
- const n = "activate" in t ? t.activate : !0, i = await r.request({
350
- url: "/wp-admin/plugin-install.php?tab=upload"
351
- }), o = S(i), a = new FormData(
352
- o.querySelector(".wp-upload-form")
353
- ), { pluginzip: c, ...l } = Object.fromEntries(
354
- a.entries()
355
- ), h = await r.request({
356
- url: "/wp-admin/update.php?action=upload-plugin",
357
- method: "POST",
358
- formData: l,
359
- files: { pluginzip: e }
373
+ await F(s, {
374
+ zipPath: o,
375
+ extractToPath: n
360
376
  });
361
- if (n) {
362
- const $ = S(h).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value, v = new URL(
363
- $,
364
- await r.pathToInternalUrl("/wp-admin/")
365
- ).toString();
366
- await r.request({
367
- url: v
368
- });
369
- }
370
- await r.isDir(
371
- "/wordpress/wp-content/plugins/gutenberg"
372
- ) && !await r.fileExists("/wordpress/.gutenberg-patched") && (await r.writeFile("/wordpress/.gutenberg-patched", "1"), await L(
373
- r,
374
- "/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.js",
375
- (d) => d.replace(
376
- /srcDoc:("[^"]+"|[^,]+)/g,
377
- 'src:"/wp-includes/empty.html"'
378
- )
379
- ), await L(
380
- r,
381
- "/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.min.js",
382
- (d) => d.replace(
383
- /srcDoc:("[^"]+"|[^,]+)/g,
384
- 'src:"/wp-includes/empty.html"'
385
- )
386
- ));
387
- } catch (n) {
377
+ const c = await s.listFiles(n, {
378
+ prependPath: !0
379
+ }), u = c.length === 1 && await s.isDir(c[0]);
380
+ let d, v = "";
381
+ u ? (v = c[0], d = c[0].split("/").pop()) : (v = n, d = i);
382
+ const U = `${e}/${d}`;
383
+ return await s.mv(v, U), await l(), {
384
+ assetFolderPath: U,
385
+ assetFolderName: d
386
+ };
387
+ } catch (c) {
388
+ throw await l(), c;
389
+ }
390
+ }
391
+ const xe = async (s, { pluginZipFile: e, options: t = {} }, r) => {
392
+ const i = e.name.split("/").pop() || "plugin.zip", n = b(i);
393
+ r?.tracker.setCaption(`Installing the ${n} plugin`);
394
+ try {
395
+ const { assetFolderPath: o } = await te(s, {
396
+ zipFile: e,
397
+ targetPath: `${await s.documentRoot}/wp-content/plugins`
398
+ });
399
+ ("activate" in t ? t.activate : !0) && await J(
400
+ s,
401
+ {
402
+ pluginPath: o,
403
+ pluginName: n
404
+ },
405
+ r
406
+ ), await Fe(s);
407
+ } catch (o) {
388
408
  console.error(
389
- `Proceeding without the ${e.name} theme. Could not install it in wp-admin. The original error was: ${n}`
390
- ), console.error(n);
409
+ `Proceeding without the ${n} plugin. Could not install it in wp-admin. The original error was: ${o}`
410
+ ), console.error(o);
391
411
  }
392
412
  };
393
- async function L(r, e, t) {
394
- return await r.writeFile(
413
+ async function Fe(s) {
414
+ await s.isDir("/wordpress/wp-content/plugins/gutenberg") && !await s.fileExists("/wordpress/.gutenberg-patched") && (await s.writeFile("/wordpress/.gutenberg-patched", "1"), await H(
415
+ s,
416
+ "/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.js",
417
+ (e) => e.replace(
418
+ /srcDoc:("[^"]+"|[^,]+)/g,
419
+ 'src:"/wp-includes/empty.html"'
420
+ )
421
+ ), await H(
422
+ s,
423
+ "/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.min.js",
424
+ (e) => e.replace(
425
+ /srcDoc:("[^"]+"|[^,]+)/g,
426
+ 'src:"/wp-includes/empty.html"'
427
+ )
428
+ ));
429
+ }
430
+ async function H(s, e, t) {
431
+ return await s.writeFile(
395
432
  e,
396
- t(await r.readFileAsText(e))
433
+ t(await s.readFileAsText(e))
397
434
  );
398
435
  }
399
- const Te = async (r, { themeZipFile: e, options: t = {} }, s) => {
400
- s?.tracker.setCaption(
401
- `Installing the ${E(e.name)} theme`
402
- );
436
+ const Te = async (s, { themeZipFile: e, options: t = {} }, r) => {
437
+ const i = b(e.name);
438
+ r?.tracker.setCaption(`Installing the ${i} theme`);
403
439
  try {
404
- const n = "activate" in t ? t.activate : !0, i = await r.request({
405
- url: "/wp-admin/theme-install.php"
406
- }), o = S(i), a = new FormData(
407
- o.querySelector(".wp-upload-form")
408
- ), { themezip: c, ...l } = Object.fromEntries(
409
- a.entries()
410
- ), h = await r.request({
411
- url: "/wp-admin/update.php?action=upload-theme",
412
- method: "POST",
413
- formData: l,
414
- files: { themezip: e }
440
+ const { assetFolderName: n } = await te(s, {
441
+ zipFile: e,
442
+ targetPath: `${await s.documentRoot}/wp-content/themes`
415
443
  });
416
- if (n) {
417
- const d = S(h), $ = d.querySelector(
418
- "#wpbody-content > .wrap"
419
- );
420
- if ($?.textContent?.includes(
421
- "Theme installation failed."
422
- )) {
423
- console.error($?.textContent);
424
- return;
425
- }
426
- const v = d.querySelector(
427
- "#wpbody-content .activatelink, .update-from-upload-actions .button.button-primary"
428
- );
429
- if (!v) {
430
- console.error('The "activate" button was not found.');
431
- return;
432
- }
433
- const se = v.attributes.getNamedItem("href").value, ne = new URL(
434
- se,
435
- await r.pathToInternalUrl("/wp-admin/")
436
- ).toString();
437
- await r.request({
438
- url: ne
439
- });
440
- }
444
+ ("activate" in t ? t.activate : !0) && await K(
445
+ s,
446
+ {
447
+ themeFolderName: n
448
+ },
449
+ r
450
+ );
441
451
  } catch (n) {
442
452
  console.error(
443
- `Proceeding without the ${e.name} theme. Could not install it in wp-admin. The original error was: ${n}`
453
+ `Proceeding without the ${i} theme. Could not install it in wp-admin. The original error was: ${n}`
444
454
  ), console.error(n);
445
455
  }
446
- }, Fe = async (r, { username: e = "admin", password: t = "password" } = {}, s) => {
447
- s?.tracker.setCaption(s?.initialCaption || "Logging in"), await r.request({
456
+ }, ke = async (s, { username: e = "admin", password: t = "password" } = {}, r) => {
457
+ r?.tracker.setCaption(r?.initialCaption || "Logging in"), await s.request({
448
458
  url: "/wp-login.php"
449
- }), await r.request({
459
+ }), await s.request({
450
460
  url: "/wp-login.php",
451
461
  method: "POST",
452
462
  formData: {
@@ -455,8 +465,8 @@ const Te = async (r, { themeZipFile: e, options: t = {} }, s) => {
455
465
  rememberme: "forever"
456
466
  }
457
467
  });
458
- }, ke = async (r, { options: e }) => {
459
- await r.request({
468
+ }, Ce = async (s, { options: e }) => {
469
+ await s.request({
460
470
  url: "/wp-admin/install.php?step=2",
461
471
  method: "POST",
462
472
  formData: {
@@ -472,70 +482,70 @@ const Te = async (r, { themeZipFile: e, options: t = {} }, s) => {
472
482
  admin_email: "admin@localhost.com"
473
483
  }
474
484
  });
475
- }, Ce = async (r, { options: e }) => {
485
+ }, Ae = async (s, { options: e }) => {
476
486
  const t = `<?php
477
487
  include 'wordpress/wp-load.php';
478
- $site_options = ${b(e)};
488
+ $site_options = ${$(e)};
479
489
  foreach($site_options as $name => $value) {
480
490
  update_option($name, $value);
481
491
  }
482
492
  echo "Success";
483
- `, s = await r.run({
493
+ `, r = await s.run({
484
494
  code: t
485
495
  });
486
- return Q(s), { code: t, result: s };
487
- }, Ue = async (r, { meta: e, userId: t }) => {
488
- const s = `<?php
496
+ return se(r), { code: t, result: r };
497
+ }, Ue = async (s, { meta: e, userId: t }) => {
498
+ const r = `<?php
489
499
  include 'wordpress/wp-load.php';
490
- $meta = ${b(e)};
500
+ $meta = ${$(e)};
491
501
  foreach($meta as $name => $value) {
492
- update_user_meta(${b(t)}, $name, $value);
502
+ update_user_meta(${$(t)}, $name, $value);
493
503
  }
494
504
  echo "Success";
495
- `, n = await r.run({
496
- code: s
505
+ `, i = await s.run({
506
+ code: r
497
507
  });
498
- return Q(n), { code: s, result: n };
508
+ return se(i), { code: r, result: i };
499
509
  };
500
- async function Q(r) {
501
- if (r.text !== "Success")
502
- throw console.log(r), new Error(`Failed to run code: ${r.text} ${r.errors}`);
510
+ async function se(s) {
511
+ if (s.text !== "Success")
512
+ throw console.log(s), new Error(`Failed to run code: ${s.text} ${s.errors}`);
503
513
  }
504
- const Ae = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
514
+ const Oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
505
515
  __proto__: null,
506
- activatePlugin: ie,
507
- activateTheme: oe,
508
- applyWordPressPatches: ce,
509
- cp: fe,
516
+ activatePlugin: J,
517
+ activateTheme: K,
518
+ applyWordPressPatches: le,
519
+ cp: me,
510
520
  defineSiteUrl: _e,
511
- defineWpConfigConsts: J,
512
- importFile: Se,
521
+ defineWpConfigConsts: Q,
522
+ importFile: Ee,
513
523
  installPlugin: xe,
514
524
  installTheme: Te,
515
- login: Fe,
516
- mkdir: we,
517
- mv: me,
525
+ login: ke,
526
+ mkdir: ge,
527
+ mv: we,
518
528
  replaceSite: ve,
519
- request: de,
520
- rm: ge,
521
- rmdir: ye,
529
+ request: fe,
530
+ rm: ye,
531
+ rmdir: Pe,
522
532
  runPHP: ue,
523
- runPHPWithOptions: he,
524
- runWpInstallationWizard: ke,
525
- setPhpIniEntry: pe,
526
- setSiteOptions: Ce,
527
- unzip: K,
533
+ runPHPWithOptions: pe,
534
+ runWpInstallationWizard: Ce,
535
+ setPhpIniEntry: de,
536
+ setSiteOptions: Ae,
537
+ unzip: F,
528
538
  updateUserMeta: Ue,
529
- writeFile: Pe,
530
- zipEntireSite: $e
531
- }, Symbol.toStringTag, { value: "Module" })), Oe = 5 * 1024 * 1024;
532
- function Ie(r, e) {
533
- const t = r.headers.get("content-length") || "", s = parseInt(t, 10) || Oe;
534
- function n(i, o) {
539
+ writeFile: Z,
540
+ zipEntireSite: be
541
+ }, Symbol.toStringTag, { value: "Module" })), Ne = 5 * 1024 * 1024;
542
+ function Le(s, e) {
543
+ const t = s.headers.get("content-length") || "", r = parseInt(t, 10) || Ne;
544
+ function i(n, o) {
535
545
  e(
536
546
  new CustomEvent("progress", {
537
547
  detail: {
538
- loaded: i,
548
+ loaded: n,
539
549
  total: o
540
550
  }
541
551
  })
@@ -543,42 +553,42 @@ function Ie(r, e) {
543
553
  }
544
554
  return new Response(
545
555
  new ReadableStream({
546
- async start(i) {
547
- if (!r.body) {
548
- i.close();
556
+ async start(n) {
557
+ if (!s.body) {
558
+ n.close();
549
559
  return;
550
560
  }
551
- const o = r.body.getReader();
561
+ const o = s.body.getReader();
552
562
  let a = 0;
553
563
  for (; ; )
554
564
  try {
555
- const { done: c, value: l } = await o.read();
556
- if (l && (a += l.byteLength), c) {
557
- n(a, a), i.close();
565
+ const { done: l, value: c } = await o.read();
566
+ if (c && (a += c.byteLength), l) {
567
+ i(a, a), n.close();
558
568
  break;
559
569
  } else
560
- n(a, s), i.enqueue(l);
561
- } catch (c) {
562
- console.error({ e: c }), i.error(c);
570
+ i(a, r), n.enqueue(c);
571
+ } catch (l) {
572
+ console.error({ e: l }), n.error(l);
563
573
  break;
564
574
  }
565
575
  }
566
576
  }),
567
577
  {
568
- status: r.status,
569
- statusText: r.statusText,
570
- headers: r.headers
578
+ status: s.status,
579
+ statusText: s.statusText,
580
+ headers: s.headers
571
581
  }
572
582
  );
573
583
  }
574
- const R = 1e-5;
575
- class F extends EventTarget {
584
+ const E = 1e-5;
585
+ class T extends EventTarget {
576
586
  constructor({
577
587
  weight: e = 1,
578
588
  caption: t = "",
579
- fillTime: s = 4
589
+ fillTime: r = 4
580
590
  } = {}) {
581
- super(), this._selfWeight = 1, this._selfDone = !1, this._selfProgress = 0, this._selfCaption = "", this._isFilling = !1, this._subTrackers = [], this._weight = e, this._selfCaption = t, this._fillTime = s;
591
+ super(), this._selfWeight = 1, this._selfDone = !1, this._selfProgress = 0, this._selfCaption = "", this._isFilling = !1, this._subTrackers = [], this._weight = e, this._selfCaption = t, this._fillTime = r;
582
592
  }
583
593
  /**
584
594
  * Creates a new sub-tracker with a specific weight.
@@ -616,19 +626,19 @@ class F extends EventTarget {
616
626
  * ```
617
627
  */
618
628
  stage(e, t = "") {
619
- if (e || (e = this._selfWeight), this._selfWeight - e < -R)
629
+ if (e || (e = this._selfWeight), this._selfWeight - e < -E)
620
630
  throw new Error(
621
631
  `Cannot add a stage with weight ${e} as the total weight of registered stages would exceed 1.`
622
632
  );
623
633
  this._selfWeight -= e;
624
- const s = new F({
634
+ const r = new T({
625
635
  caption: t,
626
636
  weight: e,
627
637
  fillTime: this._fillTime
628
638
  });
629
- return this._subTrackers.push(s), s.addEventListener("progress", () => this.notifyProgress()), s.addEventListener("done", () => {
639
+ return this._subTrackers.push(r), r.addEventListener("progress", () => this.notifyProgress()), r.addEventListener("done", () => {
630
640
  this.done && this.notifyDone();
631
- }), s;
641
+ }), r;
632
642
  }
633
643
  /**
634
644
  * Fills the progress bar slowly over time, simulating progress.
@@ -652,13 +662,13 @@ class F extends EventTarget {
652
662
  if (this._isFilling)
653
663
  return;
654
664
  this._isFilling = !0;
655
- const t = 100, s = this._fillTime / t;
665
+ const t = 100, r = this._fillTime / t;
656
666
  this._fillInterval = setInterval(() => {
657
667
  this.set(this._selfProgress + 1), e && this._selfProgress >= 99 && clearInterval(this._fillInterval);
658
- }, s);
668
+ }, r);
659
669
  }
660
670
  set(e) {
661
- this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + R >= 100 && this.finish();
671
+ this._selfProgress = Math.min(e, 100), this.notifyProgress(), this._selfProgress + E >= 100 && this.finish();
662
672
  }
663
673
  finish() {
664
674
  this._fillInterval && clearInterval(this._fillInterval), this._selfDone = !0, this._selfProgress = 100, this._isFilling = !1, this._fillInterval = void 0, this.notifyProgress(), this.notifyDone();
@@ -676,13 +686,13 @@ class F extends EventTarget {
676
686
  this._selfCaption = e, this.notifyProgress();
677
687
  }
678
688
  get done() {
679
- return this.progress + R >= 100;
689
+ return this.progress + E >= 100;
680
690
  }
681
691
  get progress() {
682
692
  if (this._selfDone)
683
693
  return 100;
684
694
  const e = this._subTrackers.reduce(
685
- (t, s) => t + s.progress * s.weight,
695
+ (t, r) => t + r.progress * r.weight,
686
696
  this._selfProgress * this._selfWeight
687
697
  );
688
698
  return Math.round(e * 1e4) / 1e4;
@@ -738,7 +748,7 @@ class F extends EventTarget {
738
748
  this.dispatchEvent(new CustomEvent("done"));
739
749
  }
740
750
  }
741
- const H = Symbol("error"), q = Symbol("message");
751
+ const I = Symbol("error"), W = Symbol("message");
742
752
  class k extends Event {
743
753
  /**
744
754
  * Create a new `ErrorEvent`.
@@ -748,19 +758,19 @@ class k extends Event {
748
758
  * attributes via object members of the same name.
749
759
  */
750
760
  constructor(e, t = {}) {
751
- super(e), this[H] = t.error === void 0 ? null : t.error, this[q] = t.message === void 0 ? "" : t.message;
761
+ super(e), this[I] = t.error === void 0 ? null : t.error, this[W] = t.message === void 0 ? "" : t.message;
752
762
  }
753
763
  get error() {
754
- return this[H];
764
+ return this[I];
755
765
  }
756
766
  get message() {
757
- return this[q];
767
+ return this[W];
758
768
  }
759
769
  }
760
770
  Object.defineProperty(k.prototype, "error", { enumerable: !0 });
761
771
  Object.defineProperty(k.prototype, "message", { enumerable: !0 });
762
- const Le = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : k;
763
- class He extends EventTarget {
772
+ const He = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : k;
773
+ class Ie extends EventTarget {
764
774
  constructor() {
765
775
  super(...arguments), this.listenersCount = 0;
766
776
  }
@@ -774,31 +784,31 @@ class He extends EventTarget {
774
784
  return this.listenersCount > 0;
775
785
  }
776
786
  }
777
- function qe(r) {
778
- r.asm = {
779
- ...r.asm
787
+ function We(s) {
788
+ s.asm = {
789
+ ...s.asm
780
790
  };
781
- const e = new He();
782
- for (const t in r.asm)
783
- if (typeof r.asm[t] == "function") {
784
- const s = r.asm[t];
785
- r.asm[t] = function(...n) {
791
+ const e = new Ie();
792
+ for (const t in s.asm)
793
+ if (typeof s.asm[t] == "function") {
794
+ const r = s.asm[t];
795
+ s.asm[t] = function(...i) {
786
796
  try {
787
- return s(...n);
788
- } catch (i) {
789
- if (!(i instanceof Error))
790
- throw i;
791
- if ("exitCode" in i && i?.exitCode === 0)
797
+ return r(...i);
798
+ } catch (n) {
799
+ if (!(n instanceof Error))
800
+ throw n;
801
+ if ("exitCode" in n && n?.exitCode === 0)
792
802
  return;
793
- const o = Ne(
794
- i,
795
- r.lastAsyncifyStackSource?.stack
803
+ const o = ze(
804
+ n,
805
+ s.lastAsyncifyStackSource?.stack
796
806
  );
797
- if (r.lastAsyncifyStackSource && (i.cause = r.lastAsyncifyStackSource), !e.hasListeners())
798
- throw je(o), i;
807
+ if (s.lastAsyncifyStackSource && (n.cause = s.lastAsyncifyStackSource), !e.hasListeners())
808
+ throw Be(o), n;
799
809
  e.dispatchEvent(
800
- new Le("error", {
801
- error: i,
810
+ new He("error", {
811
+ error: n,
802
812
  message: o
803
813
  })
804
814
  );
@@ -807,29 +817,29 @@ function qe(r) {
807
817
  }
808
818
  return e;
809
819
  }
810
- let x = [];
811
- function De() {
812
- return x;
820
+ let S = [];
821
+ function qe() {
822
+ return S;
813
823
  }
814
- function Ne(r, e) {
815
- if (r.message === "unreachable") {
816
- let t = We;
824
+ function ze(s, e) {
825
+ if (s.message === "unreachable") {
826
+ let t = De;
817
827
  e || (t += `
818
828
 
819
829
  This stack trace is lacking. For a better one initialize
820
830
  the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
821
831
 
822
- `), x = ze(
823
- e || r.stack || ""
832
+ `), S = je(
833
+ e || s.stack || ""
824
834
  );
825
- for (const s of x)
826
- t += ` * ${s}
835
+ for (const r of S)
836
+ t += ` * ${r}
827
837
  `;
828
838
  return t;
829
839
  }
830
- return r.message;
840
+ return s.message;
831
841
  }
832
- const We = `
842
+ const De = `
833
843
  "unreachable" WASM instruction executed.
834
844
 
835
845
  The typical reason is a PHP function missing from the ASYNCIFY_ONLY
@@ -853,30 +863,30 @@ the Dockerfile, you'll need to trigger this error again with long stack
853
863
  traces enabled. In node.js, you can do it using the --stack-trace-limit=100
854
864
  CLI option:
855
865
 
856
- `, D = "\x1B[41m", Me = "\x1B[1m", N = "\x1B[0m", W = "\x1B[K";
866
+ `, q = "\x1B[41m", Me = "\x1B[1m", z = "\x1B[0m", D = "\x1B[K";
857
867
  let M = !1;
858
- function je(r) {
868
+ function Be(s) {
859
869
  if (!M) {
860
- M = !0, console.log(`${D}
861
- ${W}
862
- ${Me} WASM ERROR${N}${D}`);
863
- for (const e of r.split(`
870
+ M = !0, console.log(`${q}
871
+ ${D}
872
+ ${Me} WASM ERROR${z}${q}`);
873
+ for (const e of s.split(`
864
874
  `))
865
- console.log(`${W} ${e} `);
866
- console.log(`${N}`);
875
+ console.log(`${D} ${e} `);
876
+ console.log(`${z}`);
867
877
  }
868
878
  }
869
- function ze(r) {
879
+ function je(s) {
870
880
  try {
871
- const e = r.split(`
881
+ const e = s.split(`
872
882
  `).slice(1).map((t) => {
873
- const s = t.trim().substring(3).split(" ");
883
+ const r = t.trim().substring(3).split(" ");
874
884
  return {
875
- fn: s.length >= 2 ? s[0] : "<unknown>",
885
+ fn: r.length >= 2 ? r[0] : "<unknown>",
876
886
  isWasm: t.includes("wasm://")
877
887
  };
878
888
  }).filter(
879
- ({ fn: t, isWasm: s }) => s && !t.startsWith("dynCall_") && !t.startsWith("invoke_")
889
+ ({ fn: t, isWasm: r }) => r && !t.startsWith("dynCall_") && !t.startsWith("invoke_")
880
890
  ).map(({ fn: t }) => t);
881
891
  return Array.from(new Set(e));
882
892
  } catch {
@@ -884,8 +894,8 @@ function ze(r) {
884
894
  }
885
895
  }
886
896
  class _ {
887
- constructor(e, t, s, n = "", i = 0) {
888
- this.httpStatusCode = e, this.headers = t, this.bytes = s, this.exitCode = i, this.errors = n;
897
+ constructor(e, t, r, i = "", n = 0) {
898
+ this.httpStatusCode = e, this.headers = t, this.bytes = r, this.exitCode = n, this.errors = i;
889
899
  }
890
900
  static fromRawData(e) {
891
901
  return new _(
@@ -918,7 +928,7 @@ class _ {
918
928
  return new TextDecoder().decode(this.bytes);
919
929
  }
920
930
  }
921
- const X = [
931
+ const re = [
922
932
  "8.2",
923
933
  "8.1",
924
934
  "8.0",
@@ -928,8 +938,8 @@ const X = [
928
938
  "7.1",
929
939
  "7.0",
930
940
  "5.6"
931
- ], Be = X[0];
932
- class Ge {
941
+ ], Ge = re[0];
942
+ class Ve {
933
943
  #e;
934
944
  #t;
935
945
  /**
@@ -958,28 +968,28 @@ class Ge {
958
968
  * @returns PHPRequestHandler response.
959
969
  */
960
970
  async request(e, t = 0) {
961
- const s = await this.requestHandler.request({
971
+ const r = await this.requestHandler.request({
962
972
  ...e,
963
973
  headers: {
964
974
  ...e.headers,
965
- cookie: this.#r()
975
+ cookie: this.#s()
966
976
  }
967
977
  });
968
- if (s.headers["set-cookie"] && this.#s(s.headers["set-cookie"]), this.#t.handleRedirects && s.headers.location && t < this.#t.maxRedirects) {
969
- const n = new URL(
970
- s.headers.location[0],
978
+ if (r.headers["set-cookie"] && this.#r(r.headers["set-cookie"]), this.#t.handleRedirects && r.headers.location && t < this.#t.maxRedirects) {
979
+ const i = new URL(
980
+ r.headers.location[0],
971
981
  this.requestHandler.absoluteUrl
972
982
  );
973
983
  return this.request(
974
984
  {
975
- url: n.toString(),
985
+ url: i.toString(),
976
986
  method: "GET",
977
987
  headers: {}
978
988
  },
979
989
  t + 1
980
990
  );
981
991
  }
982
- return s;
992
+ return r;
983
993
  }
984
994
  /** @inheritDoc */
985
995
  pathToInternalUrl(e) {
@@ -997,41 +1007,41 @@ class Ge {
997
1007
  get documentRoot() {
998
1008
  return this.requestHandler.documentRoot;
999
1009
  }
1000
- #s(e) {
1010
+ #r(e) {
1001
1011
  for (const t of e)
1002
1012
  try {
1003
1013
  if (!t.includes("="))
1004
1014
  continue;
1005
- const s = t.indexOf("="), n = t.substring(0, s), i = t.substring(s + 1).split(";")[0];
1006
- this.#e[n] = i;
1007
- } catch (s) {
1008
- console.error(s);
1015
+ const r = t.indexOf("="), i = t.substring(0, r), n = t.substring(r + 1).split(";")[0];
1016
+ this.#e[i] = n;
1017
+ } catch (r) {
1018
+ console.error(r);
1009
1019
  }
1010
1020
  }
1011
- #r() {
1021
+ #s() {
1012
1022
  const e = [];
1013
1023
  for (const t in this.#e)
1014
1024
  e.push(`${t}=${this.#e[t]}`);
1015
1025
  return e.join("; ");
1016
1026
  }
1017
1027
  }
1018
- const Ve = "http://example.com";
1019
- function j(r) {
1020
- return r.toString().substring(r.origin.length);
1028
+ const Ye = "http://example.com";
1029
+ function B(s) {
1030
+ return s.toString().substring(s.origin.length);
1021
1031
  }
1022
- function z(r, e) {
1023
- return !e || !r.startsWith(e) ? r : r.substring(e.length);
1032
+ function j(s, e) {
1033
+ return !e || !s.startsWith(e) ? s : s.substring(e.length);
1024
1034
  }
1025
- function Je(r, e) {
1026
- return !e || r.startsWith(e) ? r : e + r;
1035
+ function Je(s, e) {
1036
+ return !e || s.startsWith(e) ? s : e + s;
1027
1037
  }
1028
- class Ye {
1038
+ class Ke {
1029
1039
  #e;
1030
1040
  #t;
1031
- #s;
1032
1041
  #r;
1033
- #i;
1042
+ #s;
1034
1043
  #n;
1044
+ #i;
1035
1045
  #o;
1036
1046
  #a;
1037
1047
  #c;
@@ -1040,23 +1050,23 @@ class Ye {
1040
1050
  * @param config - Request Handler configuration.
1041
1051
  */
1042
1052
  constructor(e, t = {}) {
1043
- this.#a = new Y({ concurrency: 1 });
1053
+ this.#a = new X({ concurrency: 1 });
1044
1054
  const {
1045
- documentRoot: s = "/www/",
1046
- absoluteUrl: n = typeof location == "object" ? location?.href : "",
1047
- isStaticFilePath: i = () => !1
1055
+ documentRoot: r = "/www/",
1056
+ absoluteUrl: i = typeof location == "object" ? location?.href : "",
1057
+ isStaticFilePath: n = () => !1
1048
1058
  } = t;
1049
- this.php = e, this.#e = s, this.#c = i;
1050
- const o = new URL(n);
1051
- this.#s = o.hostname, this.#r = o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80, this.#t = (o.protocol || "").replace(":", "");
1052
- const a = this.#r !== 443 && this.#r !== 80;
1053
- this.#i = [
1054
- this.#s,
1055
- a ? `:${this.#r}` : ""
1056
- ].join(""), this.#n = o.pathname.replace(/\/+$/, ""), this.#o = [
1059
+ this.php = e, this.#e = r, this.#c = n;
1060
+ const o = new URL(i);
1061
+ this.#r = o.hostname, this.#s = o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80, this.#t = (o.protocol || "").replace(":", "");
1062
+ const a = this.#s !== 443 && this.#s !== 80;
1063
+ this.#n = [
1064
+ this.#r,
1065
+ a ? `:${this.#s}` : ""
1066
+ ].join(""), this.#i = o.pathname.replace(/\/+$/, ""), this.#o = [
1057
1067
  `${this.#t}://`,
1058
- this.#i,
1059
- this.#n
1068
+ this.#n,
1069
+ this.#i
1060
1070
  ].join("");
1061
1071
  }
1062
1072
  /** @inheritDoc */
@@ -1066,7 +1076,7 @@ class Ye {
1066
1076
  /** @inheritDoc */
1067
1077
  internalUrlToPath(e) {
1068
1078
  const t = new URL(e);
1069
- return t.pathname.startsWith(this.#n) && (t.pathname = t.pathname.slice(this.#n.length)), j(t);
1079
+ return t.pathname.startsWith(this.#i) && (t.pathname = t.pathname.slice(this.#i.length)), B(t);
1070
1080
  }
1071
1081
  get isRequestRunning() {
1072
1082
  return this.#a.running > 0;
@@ -1081,14 +1091,14 @@ class Ye {
1081
1091
  }
1082
1092
  /** @inheritDoc */
1083
1093
  async request(e) {
1084
- const t = e.url.startsWith("http://") || e.url.startsWith("https://"), s = new URL(
1094
+ const t = e.url.startsWith("http://") || e.url.startsWith("https://"), r = new URL(
1085
1095
  e.url,
1086
- t ? void 0 : Ve
1087
- ), n = z(
1088
- s.pathname,
1089
- this.#n
1096
+ t ? void 0 : Ye
1097
+ ), i = j(
1098
+ r.pathname,
1099
+ this.#i
1090
1100
  );
1091
- return this.#c(n) ? this.#l(n) : await this.#u(e, s);
1101
+ return this.#c(i) ? this.#l(i) : await this.#h(e, r);
1092
1102
  }
1093
1103
  /**
1094
1104
  * Serves a static file from the PHP filesystem.
@@ -1104,19 +1114,19 @@ class Ye {
1104
1114
  {},
1105
1115
  new TextEncoder().encode("404 File not found")
1106
1116
  );
1107
- const s = this.php.readFileAsBuffer(t);
1117
+ const r = this.php.readFileAsBuffer(t);
1108
1118
  return new _(
1109
1119
  200,
1110
1120
  {
1111
- "content-length": [`${s.byteLength}`],
1121
+ "content-length": [`${r.byteLength}`],
1112
1122
  // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
1113
1123
  // The code below won't return the correct mime-type if the extension
1114
1124
  // was tampered with.
1115
- "content-type": [Ze(t)],
1125
+ "content-type": [Qe(t)],
1116
1126
  "accept-ranges": ["bytes"],
1117
1127
  "cache-control": ["public, max-age=0"]
1118
1128
  },
1119
- s
1129
+ r
1120
1130
  );
1121
1131
  }
1122
1132
  /**
@@ -1126,40 +1136,40 @@ class Ye {
1126
1136
  * @param request - The request.
1127
1137
  * @returns The response.
1128
1138
  */
1129
- async #u(e, t) {
1130
- const s = await this.#a.acquire();
1139
+ async #h(e, t) {
1140
+ const r = await this.#a.acquire();
1131
1141
  try {
1132
1142
  this.php.addServerGlobalEntry("DOCUMENT_ROOT", this.#e), this.php.addServerGlobalEntry(
1133
1143
  "HTTPS",
1134
1144
  this.#o.startsWith("https://") ? "on" : ""
1135
1145
  );
1136
- let n = "GET";
1137
- const i = {
1138
- host: this.#i,
1139
- ...ee(e.headers || {})
1146
+ let i = "GET";
1147
+ const n = {
1148
+ host: this.#n,
1149
+ ...ie(e.headers || {})
1140
1150
  }, o = [];
1141
1151
  if (e.files && Object.keys(e.files).length) {
1142
- n = "POST";
1143
- for (const l in e.files) {
1144
- const h = e.files[l];
1152
+ i = "POST";
1153
+ for (const c in e.files) {
1154
+ const u = e.files[c];
1145
1155
  o.push({
1146
- key: l,
1147
- name: h.name,
1148
- type: h.type,
1149
- data: new Uint8Array(await h.arrayBuffer())
1156
+ key: c,
1157
+ name: u.name,
1158
+ type: u.type,
1159
+ data: new Uint8Array(await u.arrayBuffer())
1150
1160
  });
1151
1161
  }
1152
- i["content-type"]?.startsWith("multipart/form-data") && (e.formData = Ke(
1162
+ n["content-type"]?.startsWith("multipart/form-data") && (e.formData = Ze(
1153
1163
  e.body || ""
1154
- ), i["content-type"] = "application/x-www-form-urlencoded", delete e.body);
1164
+ ), n["content-type"] = "application/x-www-form-urlencoded", delete e.body);
1155
1165
  }
1156
1166
  let a;
1157
- e.formData !== void 0 ? (n = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
1167
+ e.formData !== void 0 ? (i = "POST", n["content-type"] = n["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
1158
1168
  e.formData
1159
1169
  ).toString()) : a = e.body;
1160
- let c;
1170
+ let l;
1161
1171
  try {
1162
- c = this.#h(t.pathname);
1172
+ l = this.#u(t.pathname);
1163
1173
  } catch {
1164
1174
  return new _(
1165
1175
  404,
@@ -1169,18 +1179,18 @@ class Ye {
1169
1179
  }
1170
1180
  return await this.php.run({
1171
1181
  relativeUri: Je(
1172
- j(t),
1173
- this.#n
1182
+ B(t),
1183
+ this.#i
1174
1184
  ),
1175
1185
  protocol: this.#t,
1176
- method: e.method || n,
1186
+ method: e.method || i,
1177
1187
  body: a,
1178
1188
  fileInfos: o,
1179
- scriptPath: c,
1180
- headers: i
1189
+ scriptPath: l,
1190
+ headers: n
1181
1191
  });
1182
1192
  } finally {
1183
- s();
1193
+ r();
1184
1194
  }
1185
1195
  }
1186
1196
  /**
@@ -1192,34 +1202,34 @@ class Ye {
1192
1202
  * @throws {Error} If the requested path doesn't exist.
1193
1203
  * @returns The resolved filesystem path.
1194
1204
  */
1195
- #h(e) {
1196
- let t = z(e, this.#n);
1205
+ #u(e) {
1206
+ let t = j(e, this.#i);
1197
1207
  t.includes(".php") ? t = t.split(".php")[0] + ".php" : (t.endsWith("/") || (t += "/"), t.endsWith("index.php") || (t += "index.php"));
1198
- const s = `${this.#e}${t}`;
1199
- if (this.php.fileExists(s))
1200
- return s;
1208
+ const r = `${this.#e}${t}`;
1209
+ if (this.php.fileExists(r))
1210
+ return r;
1201
1211
  if (!this.php.fileExists(`${this.#e}/index.php`))
1202
- throw new Error(`File not found: ${s}`);
1212
+ throw new Error(`File not found: ${r}`);
1203
1213
  return `${this.#e}/index.php`;
1204
1214
  }
1205
1215
  }
1206
- function Ke(r) {
1207
- const e = {}, t = r.match(/--(.*)\r\n/);
1216
+ function Ze(s) {
1217
+ const e = {}, t = s.match(/--(.*)\r\n/);
1208
1218
  if (!t)
1209
1219
  return e;
1210
- const s = t[1], n = r.split(`--${s}`);
1211
- return n.shift(), n.pop(), n.forEach((i) => {
1212
- const o = i.indexOf(`\r
1220
+ const r = t[1], i = s.split(`--${r}`);
1221
+ return i.shift(), i.pop(), i.forEach((n) => {
1222
+ const o = n.indexOf(`\r
1213
1223
  \r
1214
- `), a = i.substring(0, o).trim(), c = i.substring(o + 4).trim(), l = a.match(/name="([^"]+)"/);
1215
- if (l) {
1216
- const h = l[1];
1217
- e[h] = c;
1224
+ `), a = n.substring(0, o).trim(), l = n.substring(o + 4).trim(), c = a.match(/name="([^"]+)"/);
1225
+ if (c) {
1226
+ const u = c[1];
1227
+ e[u] = l;
1218
1228
  }
1219
1229
  }), e;
1220
1230
  }
1221
- function Ze(r) {
1222
- switch (r.split(".").pop()) {
1231
+ function Qe(s) {
1232
+ switch (s.split(".").pop()) {
1223
1233
  case "css":
1224
1234
  return "text/css";
1225
1235
  case "js":
@@ -1258,7 +1268,7 @@ function Ze(r) {
1258
1268
  return "application-octet-stream";
1259
1269
  }
1260
1270
  }
1261
- const B = {
1271
+ const G = {
1262
1272
  0: "No error occurred. System call completed successfully.",
1263
1273
  1: "Argument list too long.",
1264
1274
  2: "Permission denied.",
@@ -1337,17 +1347,17 @@ const B = {
1337
1347
  75: "Cross-device link.",
1338
1348
  76: "Extension: Capabilities insufficient."
1339
1349
  };
1340
- function f(r = "") {
1341
- return function(t, s, n) {
1342
- const i = n.value;
1343
- n.value = function(...o) {
1350
+ function f(s = "") {
1351
+ return function(t, r, i) {
1352
+ const n = i.value;
1353
+ i.value = function(...o) {
1344
1354
  try {
1345
- return i.apply(this, o);
1355
+ return n.apply(this, o);
1346
1356
  } catch (a) {
1347
- const c = typeof a == "object" ? a?.errno : null;
1348
- if (c in B) {
1349
- const l = B[c], h = typeof o[0] == "string" ? o[0] : null, d = h !== null ? r.replaceAll("{path}", h) : r;
1350
- throw new Error(`${d}: ${l}`, {
1357
+ const l = typeof a == "object" ? a?.errno : null;
1358
+ if (l in G) {
1359
+ const c = G[l], u = typeof o[0] == "string" ? o[0] : null, d = u !== null ? s.replaceAll("{path}", u) : s;
1360
+ throw new Error(`${d}: ${c}`, {
1351
1361
  cause: a
1352
1362
  });
1353
1363
  }
@@ -1356,19 +1366,19 @@ function f(r = "") {
1356
1366
  };
1357
1367
  };
1358
1368
  }
1359
- const Qe = [];
1360
- function Xe(r) {
1361
- return Qe[r];
1369
+ const Xe = [];
1370
+ function et(s) {
1371
+ return Xe[s];
1362
1372
  }
1363
1373
  (function() {
1364
1374
  return typeof process < "u" && process.release?.name === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
1365
1375
  })();
1366
- var et = Object.defineProperty, tt = Object.getOwnPropertyDescriptor, m = (r, e, t, s) => {
1367
- for (var n = s > 1 ? void 0 : s ? tt(e, t) : e, i = r.length - 1, o; i >= 0; i--)
1368
- (o = r[i]) && (n = (s ? o(e, t, n) : o(n)) || n);
1369
- return s && n && et(e, t, n), n;
1376
+ var tt = Object.defineProperty, st = Object.getOwnPropertyDescriptor, m = (s, e, t, r) => {
1377
+ for (var i = r > 1 ? void 0 : r ? st(e, t) : e, n = s.length - 1, o; n >= 0; n--)
1378
+ (o = s[n]) && (i = (r ? o(e, t, i) : o(i)) || i);
1379
+ return r && i && tt(e, t, i), i;
1370
1380
  };
1371
- const p = "string", y = "number", u = Symbol("__private__dont__use");
1381
+ const p = "string", y = "number", h = Symbol("__private__dont__use");
1372
1382
  class w {
1373
1383
  /**
1374
1384
  * Initializes a PHP runtime.
@@ -1378,14 +1388,14 @@ class w {
1378
1388
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
1379
1389
  */
1380
1390
  constructor(e, t) {
1381
- this.#e = [], this.#t = !1, this.#s = null, this.#r = {}, e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new Ge(
1382
- new Ye(this, t)
1391
+ this.#e = [], this.#t = !1, this.#r = null, this.#s = {}, e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new Ve(
1392
+ new Ke(this, t)
1383
1393
  ));
1384
1394
  }
1385
1395
  #e;
1386
1396
  #t;
1387
- #s;
1388
1397
  #r;
1398
+ #s;
1389
1399
  /** @inheritDoc */
1390
1400
  get absoluteUrl() {
1391
1401
  return this.requestHandler.requestHandler.absoluteUrl;
@@ -1405,18 +1415,18 @@ class w {
1405
1415
  );
1406
1416
  }
1407
1417
  initializeRuntime(e) {
1408
- if (this[u])
1418
+ if (this[h])
1409
1419
  throw new Error("PHP runtime already initialized.");
1410
- const t = Xe(e);
1420
+ const t = et(e);
1411
1421
  if (!t)
1412
1422
  throw new Error("Invalid PHP runtime id.");
1413
- this[u] = t, this.#s = qe(t);
1423
+ this[h] = t, this.#r = We(t);
1414
1424
  }
1415
1425
  /** @inheritDoc */
1416
1426
  setPhpIniPath(e) {
1417
1427
  if (this.#t)
1418
1428
  throw new Error("Cannot set PHP ini path after calling run().");
1419
- this[u].ccall(
1429
+ this[h].ccall(
1420
1430
  "wasm_set_phpini_path",
1421
1431
  null,
1422
1432
  ["string"],
@@ -1431,7 +1441,7 @@ class w {
1431
1441
  }
1432
1442
  /** @inheritDoc */
1433
1443
  chdir(e) {
1434
- this[u].FS.chdir(e);
1444
+ this[h].FS.chdir(e);
1435
1445
  }
1436
1446
  /** @inheritDoc */
1437
1447
  async request(e, t) {
@@ -1441,58 +1451,58 @@ class w {
1441
1451
  }
1442
1452
  /** @inheritDoc */
1443
1453
  async run(e) {
1444
- this.#t || (this.#i(), this.#t = !0), this.#h(e.scriptPath || ""), this.#o(e.relativeUri || ""), this.#c(e.method || "GET");
1445
- const { host: t, ...s } = {
1454
+ this.#t || (this.#n(), this.#t = !0), this.#u(e.scriptPath || ""), this.#o(e.relativeUri || ""), this.#c(e.method || "GET");
1455
+ const { host: t, ...r } = {
1446
1456
  host: "example.com:443",
1447
- ...ee(e.headers || {})
1457
+ ...ie(e.headers || {})
1448
1458
  };
1449
- if (this.#a(t, e.protocol || "http"), this.#l(s), e.body && this.#u(e.body), e.fileInfos)
1450
- for (const n of e.fileInfos)
1451
- this.#d(n);
1459
+ if (this.#a(t, e.protocol || "http"), this.#l(r), e.body && this.#h(e.body), e.fileInfos)
1460
+ for (const i of e.fileInfos)
1461
+ this.#d(i);
1452
1462
  return e.code && this.#f(" ?>" + e.code), this.#p(), await this.#m();
1453
1463
  }
1454
- #i() {
1464
+ #n() {
1455
1465
  if (this.#e.length > 0) {
1456
- const e = this.#e.map(([t, s]) => `${t}=${s}`).join(`
1466
+ const e = this.#e.map(([t, r]) => `${t}=${r}`).join(`
1457
1467
  `) + `
1458
1468
 
1459
1469
  `;
1460
- this[u].ccall(
1470
+ this[h].ccall(
1461
1471
  "wasm_set_phpini_entries",
1462
1472
  null,
1463
1473
  [p],
1464
1474
  [e]
1465
1475
  );
1466
1476
  }
1467
- this[u].ccall("php_wasm_init", null, [], []);
1477
+ this[h].ccall("php_wasm_init", null, [], []);
1468
1478
  }
1469
- #n() {
1479
+ #i() {
1470
1480
  const e = "/tmp/headers.json";
1471
1481
  if (!this.fileExists(e))
1472
1482
  throw new Error(
1473
1483
  "SAPI Error: Could not find response headers file."
1474
1484
  );
1475
- const t = JSON.parse(this.readFileAsText(e)), s = {};
1476
- for (const n of t.headers) {
1477
- if (!n.includes(": "))
1485
+ const t = JSON.parse(this.readFileAsText(e)), r = {};
1486
+ for (const i of t.headers) {
1487
+ if (!i.includes(": "))
1478
1488
  continue;
1479
- const i = n.indexOf(": "), o = n.substring(0, i).toLowerCase(), a = n.substring(i + 2);
1480
- o in s || (s[o] = []), s[o].push(a);
1489
+ const n = i.indexOf(": "), o = i.substring(0, n).toLowerCase(), a = i.substring(n + 2);
1490
+ o in r || (r[o] = []), r[o].push(a);
1481
1491
  }
1482
1492
  return {
1483
- headers: s,
1493
+ headers: r,
1484
1494
  httpStatusCode: t.status
1485
1495
  };
1486
1496
  }
1487
1497
  #o(e) {
1488
- if (this[u].ccall(
1498
+ if (this[h].ccall(
1489
1499
  "wasm_set_request_uri",
1490
1500
  null,
1491
1501
  [p],
1492
1502
  [e]
1493
1503
  ), e.includes("?")) {
1494
1504
  const t = e.substring(e.indexOf("?") + 1);
1495
- this[u].ccall(
1505
+ this[h].ccall(
1496
1506
  "wasm_set_query_string",
1497
1507
  null,
1498
1508
  [p],
@@ -1501,26 +1511,26 @@ class w {
1501
1511
  }
1502
1512
  }
1503
1513
  #a(e, t) {
1504
- this[u].ccall(
1514
+ this[h].ccall(
1505
1515
  "wasm_set_request_host",
1506
1516
  null,
1507
1517
  [p],
1508
1518
  [e]
1509
1519
  );
1510
- let s;
1520
+ let r;
1511
1521
  try {
1512
- s = parseInt(new URL(e).port, 10);
1522
+ r = parseInt(new URL(e).port, 10);
1513
1523
  } catch {
1514
1524
  }
1515
- (!s || isNaN(s) || s === 80) && (s = t === "https" ? 443 : 80), this[u].ccall(
1525
+ (!r || isNaN(r) || r === 80) && (r = t === "https" ? 443 : 80), this[h].ccall(
1516
1526
  "wasm_set_request_port",
1517
1527
  null,
1518
1528
  [y],
1519
- [s]
1520
- ), (t === "https" || !t && s === 443) && this.addServerGlobalEntry("HTTPS", "on");
1529
+ [r]
1530
+ ), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
1521
1531
  }
1522
1532
  #c(e) {
1523
- this[u].ccall(
1533
+ this[h].ccall(
1524
1534
  "wasm_set_request_method",
1525
1535
  null,
1526
1536
  [p],
@@ -1528,43 +1538,45 @@ class w {
1528
1538
  );
1529
1539
  }
1530
1540
  #l(e) {
1531
- e.cookie && this[u].ccall(
1541
+ e.cookie && this[h].ccall(
1532
1542
  "wasm_set_cookies",
1533
1543
  null,
1534
1544
  [p],
1535
1545
  [e.cookie]
1536
- ), e["content-type"] && this[u].ccall(
1546
+ ), e["content-type"] && this[h].ccall(
1537
1547
  "wasm_set_content_type",
1538
1548
  null,
1539
1549
  [p],
1540
1550
  [e["content-type"]]
1541
- ), e["content-length"] && this[u].ccall(
1551
+ ), e["content-length"] && this[h].ccall(
1542
1552
  "wasm_set_content_length",
1543
1553
  null,
1544
1554
  [y],
1545
1555
  [parseInt(e["content-length"], 10)]
1546
1556
  );
1547
- for (const t in e)
1548
- this.addServerGlobalEntry(
1549
- `HTTP_${t.toUpperCase().replace(/-/g, "_")}`,
1557
+ for (const t in e) {
1558
+ let r = "HTTP_";
1559
+ ["content-type", "content-length"].includes(t.toLowerCase()) && (r = ""), this.addServerGlobalEntry(
1560
+ `${r}${t.toUpperCase().replace(/-/g, "_")}`,
1550
1561
  e[t]
1551
1562
  );
1563
+ }
1552
1564
  }
1553
- #u(e) {
1554
- this[u].ccall(
1565
+ #h(e) {
1566
+ this[h].ccall(
1555
1567
  "wasm_set_request_body",
1556
1568
  null,
1557
1569
  [p],
1558
1570
  [e]
1559
- ), this[u].ccall(
1571
+ ), this[h].ccall(
1560
1572
  "wasm_set_content_length",
1561
1573
  null,
1562
1574
  [y],
1563
1575
  [new TextEncoder().encode(e).length]
1564
1576
  );
1565
1577
  }
1566
- #h(e) {
1567
- this[u].ccall(
1578
+ #u(e) {
1579
+ this[h].ccall(
1568
1580
  "wasm_set_path_translated",
1569
1581
  null,
1570
1582
  [p],
@@ -1572,15 +1584,15 @@ class w {
1572
1584
  );
1573
1585
  }
1574
1586
  addServerGlobalEntry(e, t) {
1575
- this.#r[e] = t;
1587
+ this.#s[e] = t;
1576
1588
  }
1577
1589
  #p() {
1578
- for (const e in this.#r)
1579
- this[u].ccall(
1590
+ for (const e in this.#s)
1591
+ this[h].ccall(
1580
1592
  "wasm_add_SERVER_entry",
1581
1593
  null,
1582
1594
  [p, p],
1583
- [e, this.#r[e]]
1595
+ [e, this.#s[e]]
1584
1596
  );
1585
1597
  }
1586
1598
  /**
@@ -1593,18 +1605,18 @@ class w {
1593
1605
  * @param fileInfo - File details
1594
1606
  */
1595
1607
  #d(e) {
1596
- const { key: t, name: s, type: n, data: i } = e, o = `/tmp/${Math.random().toFixed(20)}`;
1597
- this.writeFile(o, i);
1608
+ const { key: t, name: r, type: i, data: n } = e, o = `/tmp/${Math.random().toFixed(20)}`;
1609
+ this.writeFile(o, n);
1598
1610
  const a = 0;
1599
- this[u].ccall(
1611
+ this[h].ccall(
1600
1612
  "wasm_add_uploaded_file",
1601
1613
  null,
1602
1614
  [p, p, p, p, y, y],
1603
- [t, s, n, o, a, i.byteLength]
1615
+ [t, r, i, o, a, n.byteLength]
1604
1616
  );
1605
1617
  }
1606
1618
  #f(e) {
1607
- this[u].ccall(
1619
+ this[h].ccall(
1608
1620
  "wasm_set_php_code",
1609
1621
  null,
1610
1622
  [p],
@@ -1614,46 +1626,46 @@ class w {
1614
1626
  async #m() {
1615
1627
  let e, t;
1616
1628
  try {
1617
- e = await new Promise((i, o) => {
1618
- t = (c) => {
1619
- const l = new Error("Rethrown");
1620
- l.cause = c.error, l.betterMessage = c.message, o(l);
1621
- }, this.#s?.addEventListener(
1629
+ e = await new Promise((n, o) => {
1630
+ t = (l) => {
1631
+ const c = new Error("Rethrown");
1632
+ c.cause = l.error, c.betterMessage = l.message, o(c);
1633
+ }, this.#r?.addEventListener(
1622
1634
  "error",
1623
1635
  t
1624
1636
  );
1625
- const a = this[u].ccall(
1637
+ const a = this[h].ccall(
1626
1638
  "wasm_sapi_handle_request",
1627
1639
  y,
1628
1640
  [],
1629
1641
  []
1630
1642
  );
1631
- return a instanceof Promise ? a.then(i, o) : i(a);
1643
+ return a instanceof Promise ? a.then(n, o) : n(a);
1632
1644
  });
1633
- } catch (i) {
1634
- for (const l in this)
1635
- typeof this[l] == "function" && (this[l] = () => {
1645
+ } catch (n) {
1646
+ for (const c in this)
1647
+ typeof this[c] == "function" && (this[c] = () => {
1636
1648
  throw new Error(
1637
1649
  "PHP runtime has crashed – see the earlier error for details."
1638
1650
  );
1639
1651
  });
1640
- this.functionsMaybeMissingFromAsyncify = De();
1641
- const o = i, a = "betterMessage" in o ? o.betterMessage : o.message, c = new Error(a);
1642
- throw c.cause = o, c;
1652
+ this.functionsMaybeMissingFromAsyncify = qe();
1653
+ const o = n, a = "betterMessage" in o ? o.betterMessage : o.message, l = new Error(a);
1654
+ throw l.cause = o, l;
1643
1655
  } finally {
1644
- this.#s?.removeEventListener("error", t), this.#r = {};
1656
+ this.#r?.removeEventListener("error", t), this.#s = {};
1645
1657
  }
1646
- const { headers: s, httpStatusCode: n } = this.#n();
1658
+ const { headers: r, httpStatusCode: i } = this.#i();
1647
1659
  return new _(
1648
- n,
1649
- s,
1660
+ i,
1661
+ r,
1650
1662
  this.readFileAsBuffer("/tmp/stdout"),
1651
1663
  this.readFileAsText("/tmp/stderr"),
1652
1664
  e
1653
1665
  );
1654
1666
  }
1655
1667
  mkdir(e) {
1656
- this[u].FS.mkdirTree(e);
1668
+ this[h].FS.mkdirTree(e);
1657
1669
  }
1658
1670
  mkdirTree(e) {
1659
1671
  this.mkdir(e);
@@ -1662,42 +1674,47 @@ class w {
1662
1674
  return new TextDecoder().decode(this.readFileAsBuffer(e));
1663
1675
  }
1664
1676
  readFileAsBuffer(e) {
1665
- return this[u].FS.readFile(e);
1677
+ return this[h].FS.readFile(e);
1666
1678
  }
1667
1679
  writeFile(e, t) {
1668
- this[u].FS.writeFile(e, t);
1680
+ this[h].FS.writeFile(e, t);
1669
1681
  }
1670
1682
  unlink(e) {
1671
- this[u].FS.unlink(e);
1683
+ this[h].FS.unlink(e);
1672
1684
  }
1673
1685
  mv(e, t) {
1674
- this[u].FS.rename(e, t);
1686
+ this[h].FS.rename(e, t);
1675
1687
  }
1676
1688
  rmdir(e, t = { recursive: !0 }) {
1677
- t?.recursive && this.listFiles(e).forEach((s) => {
1678
- const n = `${e}/${s}`;
1679
- this.isDir(n) ? this.rmdir(n, t) : this.unlink(n);
1680
- }), this[u].FS.rmdir(e);
1689
+ t?.recursive && this.listFiles(e).forEach((r) => {
1690
+ const i = `${e}/${r}`;
1691
+ this.isDir(i) ? this.rmdir(i, t) : this.unlink(i);
1692
+ }), this[h].FS.rmdir(e);
1681
1693
  }
1682
- listFiles(e) {
1694
+ listFiles(e, t = { prependPath: !1 }) {
1683
1695
  if (!this.fileExists(e))
1684
1696
  return [];
1685
1697
  try {
1686
- return this[u].FS.readdir(e).filter(
1687
- (t) => t !== "." && t !== ".."
1698
+ const r = this[h].FS.readdir(e).filter(
1699
+ (i) => i !== "." && i !== ".."
1688
1700
  );
1689
- } catch (t) {
1690
- return console.error(t, { path: e }), [];
1701
+ if (t.prependPath) {
1702
+ const i = e.replace(/\/$/, "");
1703
+ return r.map((n) => `${i}/${n}`);
1704
+ }
1705
+ return r;
1706
+ } catch (r) {
1707
+ return console.error(r, { path: e }), [];
1691
1708
  }
1692
1709
  }
1693
1710
  isDir(e) {
1694
- return this.fileExists(e) ? this[u].FS.isDir(
1695
- this[u].FS.lookupPath(e).node.mode
1711
+ return this.fileExists(e) ? this[h].FS.isDir(
1712
+ this[h].FS.lookupPath(e).node.mode
1696
1713
  ) : !1;
1697
1714
  }
1698
1715
  fileExists(e) {
1699
1716
  try {
1700
- return this[u].FS.lookupPath(e), !0;
1717
+ return this[h].FS.lookupPath(e), !0;
1701
1718
  } catch {
1702
1719
  return !1;
1703
1720
  }
@@ -1736,10 +1753,10 @@ m([
1736
1753
  m([
1737
1754
  f('Could not stat "{path}"')
1738
1755
  ], w.prototype, "fileExists", 1);
1739
- function ee(r) {
1756
+ function ie(s) {
1740
1757
  const e = {};
1741
- for (const t in r)
1742
- e[t.toLowerCase()] = r[t];
1758
+ for (const t in s)
1759
+ e[t.toLowerCase()] = s[t];
1743
1760
  return e;
1744
1761
  }
1745
1762
  const rt = [
@@ -1749,8 +1766,8 @@ const rt = [
1749
1766
  "wordpress.org/plugins",
1750
1767
  "url"
1751
1768
  ];
1752
- function st(r) {
1753
- return r && typeof r == "object" && typeof r.resource == "string" && rt.includes(r.resource);
1769
+ function it(s) {
1770
+ return s && typeof s == "object" && typeof s.resource == "string" && rt.includes(s.resource);
1754
1771
  }
1755
1772
  class g {
1756
1773
  /**
@@ -1760,28 +1777,28 @@ class g {
1760
1777
  * @param options Additional options for the Resource
1761
1778
  * @returns A new Resource instance
1762
1779
  */
1763
- static create(e, { semaphore: t, progress: s }) {
1764
- let n;
1780
+ static create(e, { semaphore: t, progress: r }) {
1781
+ let i;
1765
1782
  switch (e.resource) {
1766
1783
  case "vfs":
1767
- n = new nt(e, s);
1784
+ i = new nt(e, r);
1768
1785
  break;
1769
1786
  case "literal":
1770
- n = new it(e, s);
1787
+ i = new ot(e, r);
1771
1788
  break;
1772
1789
  case "wordpress.org/themes":
1773
- n = new ct(e, s);
1790
+ i = new lt(e, r);
1774
1791
  break;
1775
1792
  case "wordpress.org/plugins":
1776
- n = new lt(e, s);
1793
+ i = new ht(e, r);
1777
1794
  break;
1778
1795
  case "url":
1779
- n = new at(e, s);
1796
+ i = new ct(e, r);
1780
1797
  break;
1781
1798
  default:
1782
1799
  throw new Error(`Invalid resource: ${e}`);
1783
1800
  }
1784
- return n = new ut(n), t && (n = new ht(n, t)), n;
1801
+ return i = new ut(i), t && (i = new pt(i, t)), i;
1785
1802
  }
1786
1803
  setPlayground(e) {
1787
1804
  this.playground = e;
@@ -1806,14 +1823,14 @@ class nt extends g {
1806
1823
  const e = await this.playground.readFileAsBuffer(
1807
1824
  this.resource.path
1808
1825
  );
1809
- return this.progress?.set(100), new File([e], this.name);
1826
+ return this.progress?.set(100), new R([e], this.name);
1810
1827
  }
1811
1828
  /** @inheritDoc */
1812
1829
  get name() {
1813
- return this.resource.path;
1830
+ return this.resource.path.split("/").pop() || "";
1814
1831
  }
1815
1832
  }
1816
- class it extends g {
1833
+ class ot extends g {
1817
1834
  /**
1818
1835
  * Creates a new instance of `LiteralResource`.
1819
1836
  * @param resource The literal reference.
@@ -1824,7 +1841,7 @@ class it extends g {
1824
1841
  }
1825
1842
  /** @inheritDoc */
1826
1843
  async resolve() {
1827
- return this.progress?.set(100), new File([this.resource.contents], this.resource.name);
1844
+ return this.progress?.set(100), new R([this.resource.contents], this.resource.name);
1828
1845
  }
1829
1846
  /** @inheritDoc */
1830
1847
  get name() {
@@ -1844,12 +1861,12 @@ class C extends g {
1844
1861
  this.progress?.setCaption(this.caption);
1845
1862
  const e = this.getURL();
1846
1863
  let t = await fetch(e);
1847
- if (t = await Ie(
1864
+ if (t = await Le(
1848
1865
  t,
1849
- this.progress?.loadingListener ?? ot
1866
+ this.progress?.loadingListener ?? at
1850
1867
  ), t.status !== 200)
1851
1868
  throw new Error(`Could not download "${e}"`);
1852
- return new File([await t.blob()], this.name);
1869
+ return new R([await t.blob()], this.name);
1853
1870
  }
1854
1871
  /**
1855
1872
  * Gets the caption for the progress tracker.
@@ -1871,9 +1888,9 @@ class C extends g {
1871
1888
  return !0;
1872
1889
  }
1873
1890
  }
1874
- const ot = () => {
1891
+ const at = () => {
1875
1892
  };
1876
- class at extends C {
1893
+ class ct extends C {
1877
1894
  /**
1878
1895
  * Creates a new instance of `UrlResource`.
1879
1896
  * @param resource The URL reference.
@@ -1891,40 +1908,40 @@ class at extends C {
1891
1908
  return this.resource.caption ?? super.caption;
1892
1909
  }
1893
1910
  }
1894
- let U = "https://playground.wordpress.net/plugin-proxy";
1895
- function wt(r) {
1896
- U = r;
1911
+ let A = "https://playground.wordpress.net/plugin-proxy";
1912
+ function gt(s) {
1913
+ A = s;
1897
1914
  }
1898
- class ct extends C {
1915
+ class lt extends C {
1899
1916
  constructor(e, t) {
1900
1917
  super(t), this.resource = e;
1901
1918
  }
1902
1919
  get name() {
1903
- return E(this.resource.slug);
1920
+ return b(this.resource.slug);
1904
1921
  }
1905
1922
  getURL() {
1906
- const e = te(this.resource.slug);
1907
- return `${U}?theme=` + e;
1923
+ const e = ne(this.resource.slug);
1924
+ return `${A}?theme=` + e;
1908
1925
  }
1909
1926
  }
1910
- class lt extends C {
1927
+ class ht extends C {
1911
1928
  constructor(e, t) {
1912
1929
  super(t), this.resource = e;
1913
1930
  }
1914
1931
  /** @inheritDoc */
1915
1932
  get name() {
1916
- return E(this.resource.slug);
1933
+ return b(this.resource.slug);
1917
1934
  }
1918
1935
  /** @inheritDoc */
1919
1936
  getURL() {
1920
- const e = te(this.resource.slug);
1921
- return `${U}?plugin=` + e;
1937
+ const e = ne(this.resource.slug);
1938
+ return `${A}?plugin=` + e;
1922
1939
  }
1923
1940
  }
1924
- function te(r) {
1925
- return !r || r.endsWith(".zip") ? r : r + ".latest-stable.zip";
1941
+ function ne(s) {
1942
+ return !s || s.endsWith(".zip") ? s : s + ".latest-stable.zip";
1926
1943
  }
1927
- class re extends g {
1944
+ class oe extends g {
1928
1945
  constructor(e) {
1929
1946
  super(), this.resource = e;
1930
1947
  }
@@ -1953,13 +1970,13 @@ class re extends g {
1953
1970
  return this.resource.isAsync;
1954
1971
  }
1955
1972
  }
1956
- class ut extends re {
1973
+ class ut extends oe {
1957
1974
  /** @inheritDoc */
1958
1975
  async resolve() {
1959
1976
  return this.promise || (this.promise = super.resolve()), this.promise;
1960
1977
  }
1961
1978
  }
1962
- class ht extends re {
1979
+ class pt extends oe {
1963
1980
  constructor(e, t) {
1964
1981
  super(e), this.semaphore = t;
1965
1982
  }
@@ -1968,48 +1985,48 @@ class ht extends re {
1968
1985
  return this.isAsync ? this.semaphore.run(() => super.resolve()) : super.resolve();
1969
1986
  }
1970
1987
  }
1971
- const pt = ["6.2", "6.1", "6.0", "5.9"];
1972
- function gt(r, {
1973
- progress: e = new F(),
1974
- semaphore: t = new Y({ concurrency: 3 }),
1975
- onStepCompleted: s = () => {
1988
+ const dt = ["6.2", "6.1", "6.0", "5.9"];
1989
+ function yt(s, {
1990
+ progress: e = new T(),
1991
+ semaphore: t = new X({ concurrency: 3 }),
1992
+ onStepCompleted: r = () => {
1976
1993
  }
1977
1994
  } = {}) {
1978
- const n = (r.steps || []).filter(dt), i = n.reduce(
1979
- (a, c) => a + (c.progress?.weight || 1),
1995
+ const i = (s.steps || []).filter(ft), n = i.reduce(
1996
+ (a, l) => a + (l.progress?.weight || 1),
1980
1997
  0
1981
- ), o = n.map(
1982
- (a) => ft(a, {
1998
+ ), o = i.map(
1999
+ (a) => mt(a, {
1983
2000
  semaphore: t,
1984
2001
  rootProgressTracker: e,
1985
- totalProgressWeight: i
2002
+ totalProgressWeight: n
1986
2003
  })
1987
2004
  );
1988
2005
  return {
1989
2006
  versions: {
1990
- php: G(
1991
- r.preferredVersions?.php,
1992
- X,
1993
- Be
2007
+ php: V(
2008
+ s.preferredVersions?.php,
2009
+ re,
2010
+ Ge
1994
2011
  ),
1995
- wp: G(
1996
- r.preferredVersions?.wp,
1997
- pt,
2012
+ wp: V(
2013
+ s.preferredVersions?.wp,
2014
+ dt,
1998
2015
  "6.2"
1999
2016
  )
2000
2017
  },
2001
2018
  run: async (a) => {
2002
2019
  try {
2003
- for (const { resources: c } of o)
2004
- for (const l of c)
2005
- l.setPlayground(a), l.isAsync && l.resolve();
2006
- for (const { run: c, step: l } of o) {
2007
- const h = await c(a);
2008
- s(h, l);
2020
+ for (const { resources: l } of o)
2021
+ for (const c of l)
2022
+ c.setPlayground(a), c.isAsync && c.resolve();
2023
+ for (const { run: l, step: c } of o) {
2024
+ const u = await l(a);
2025
+ r(u, c);
2009
2026
  }
2010
2027
  try {
2011
2028
  await a.goTo(
2012
- r.landingPage || "/"
2029
+ s.landingPage || "/"
2013
2030
  );
2014
2031
  } catch {
2015
2032
  }
@@ -2019,92 +2036,92 @@ function gt(r, {
2019
2036
  }
2020
2037
  };
2021
2038
  }
2022
- function G(r, e, t) {
2023
- return r && e.includes(r) ? r : t;
2039
+ function V(s, e, t) {
2040
+ return s && e.includes(s) ? s : t;
2024
2041
  }
2025
- function dt(r) {
2026
- return !!(typeof r == "object" && r);
2042
+ function ft(s) {
2043
+ return !!(typeof s == "object" && s);
2027
2044
  }
2028
- function ft(r, {
2045
+ function mt(s, {
2029
2046
  semaphore: e,
2030
2047
  rootProgressTracker: t,
2031
- totalProgressWeight: s
2048
+ totalProgressWeight: r
2032
2049
  }) {
2033
- const n = t.stage(
2034
- (r.progress?.weight || 1) / s
2035
- ), i = {};
2036
- for (const h of Object.keys(r)) {
2037
- let d = r[h];
2038
- st(d) && (d = g.create(d, {
2050
+ const i = t.stage(
2051
+ (s.progress?.weight || 1) / r
2052
+ ), n = {};
2053
+ for (const u of Object.keys(s)) {
2054
+ let d = s[u];
2055
+ it(d) && (d = g.create(d, {
2039
2056
  semaphore: e
2040
- })), i[h] = d;
2057
+ })), n[u] = d;
2041
2058
  }
2042
- const o = async (h) => {
2059
+ const o = async (u) => {
2043
2060
  try {
2044
- return n.fillSlowly(), await Ae[r.step](
2045
- h,
2046
- await mt(i),
2061
+ return i.fillSlowly(), await Oe[s.step](
2062
+ u,
2063
+ await wt(n),
2047
2064
  {
2048
- tracker: n,
2049
- initialCaption: r.progress?.caption
2065
+ tracker: i,
2066
+ initialCaption: s.progress?.caption
2050
2067
  }
2051
2068
  );
2052
2069
  } finally {
2053
- n.finish();
2070
+ i.finish();
2054
2071
  }
2055
- }, a = V(i), c = V(i).filter(
2056
- (h) => h.isAsync
2057
- ), l = 1 / (c.length + 1);
2058
- for (const h of c)
2059
- h.progress = n.stage(l);
2060
- return { run: o, step: r, resources: a };
2072
+ }, a = Y(n), l = Y(n).filter(
2073
+ (u) => u.isAsync
2074
+ ), c = 1 / (l.length + 1);
2075
+ for (const u of l)
2076
+ u.progress = i.stage(c);
2077
+ return { run: o, step: s, resources: a };
2061
2078
  }
2062
- function V(r) {
2079
+ function Y(s) {
2063
2080
  const e = [];
2064
- for (const t in r) {
2065
- const s = r[t];
2066
- s instanceof g && e.push(s);
2081
+ for (const t in s) {
2082
+ const r = s[t];
2083
+ r instanceof g && e.push(r);
2067
2084
  }
2068
2085
  return e;
2069
2086
  }
2070
- async function mt(r) {
2087
+ async function wt(s) {
2071
2088
  const e = {};
2072
- for (const t in r) {
2073
- const s = r[t];
2074
- s instanceof g ? e[t] = await s.resolve() : e[t] = s;
2089
+ for (const t in s) {
2090
+ const r = s[t];
2091
+ r instanceof g ? e[t] = await r.resolve() : e[t] = r;
2075
2092
  }
2076
2093
  return e;
2077
2094
  }
2078
- async function yt(r, e) {
2079
- await r.run(e);
2095
+ async function Pt(s, e) {
2096
+ await s.run(e);
2080
2097
  }
2081
2098
  export {
2082
- ie as activatePlugin,
2083
- oe as activateTheme,
2084
- ce as applyWordPressPatches,
2085
- gt as compileBlueprint,
2086
- fe as cp,
2099
+ J as activatePlugin,
2100
+ K as activateTheme,
2101
+ le as applyWordPressPatches,
2102
+ yt as compileBlueprint,
2103
+ me as cp,
2087
2104
  _e as defineSiteUrl,
2088
- J as defineWpConfigConsts,
2089
- Se as importFile,
2105
+ Q as defineWpConfigConsts,
2106
+ Ee as importFile,
2090
2107
  xe as installPlugin,
2091
2108
  Te as installTheme,
2092
- Fe as login,
2093
- we as mkdir,
2094
- me as mv,
2109
+ ke as login,
2110
+ ge as mkdir,
2111
+ we as mv,
2095
2112
  ve as replaceSite,
2096
- de as request,
2097
- ge as rm,
2098
- ye as rmdir,
2099
- yt as runBlueprintSteps,
2113
+ fe as request,
2114
+ ye as rm,
2115
+ Pe as rmdir,
2116
+ Pt as runBlueprintSteps,
2100
2117
  ue as runPHP,
2101
- he as runPHPWithOptions,
2102
- ke as runWpInstallationWizard,
2103
- pe as setPhpIniEntry,
2104
- wt as setPluginProxyURL,
2105
- Ce as setSiteOptions,
2106
- K as unzip,
2118
+ pe as runPHPWithOptions,
2119
+ Ce as runWpInstallationWizard,
2120
+ de as setPhpIniEntry,
2121
+ gt as setPluginProxyURL,
2122
+ Ae as setSiteOptions,
2123
+ F as unzip,
2107
2124
  Ue as updateUserMeta,
2108
- Pe as writeFile,
2109
- $e as zipEntireSite
2125
+ Z as writeFile,
2126
+ be as zipEntireSite
2110
2127
  };