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