@wp-playground/cli 3.1.1 → 3.1.3

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.
@@ -1,86 +1,69 @@
1
- import { logger as g, LogSeverity as L, errorLogPath as Q } from "@php-wasm/logger";
2
- import { PHPResponse as H, consumeAPI as ne, SupportedPHPVersions as X, printDebugDetails as be, HttpCookieStore as ge, FileLockManagerInMemory as Pe, createObjectPoolProxy as ve, exposeAPI as xe, exposeSyncAPI as Se } from "@php-wasm/universal";
3
- import { resolveRemoteBlueprint as Ie, resolveRuntimeConfiguration as Z, compileBlueprintV1 as ae, isBlueprintBundle as $e, runBlueprintV1Steps as J } from "@wp-playground/blueprints";
4
- import { zipDirectory as Te, RecommendedPHPVersion as C } from "@wp-playground/common";
5
- import c, { existsSync as j, rmdirSync as Ee, mkdirSync as N, readdirSync as ke } from "fs";
6
- import { MessageChannel as le, Worker as K } from "worker_threads";
7
- import { createNodeFsMountHandler as Me } from "@php-wasm/node";
8
- import u, { basename as A, join as de } from "path";
9
- import Be from "express";
10
- import V, { cpus as Ae } from "os";
11
- import Ce from "yargs";
12
- import { NodeJsFilesystem as De, OverlayFilesystem as Re, InMemoryFilesystem as We, ZipFilesystem as Le } from "@wp-playground/storage";
13
- import { EmscriptenDownloadMonitor as Ue, ProgressTracker as Fe } from "@php-wasm/progress";
14
- import { resolveWordPressRelease as _e } from "@wp-playground/wordpress";
15
- import I from "fs-extra";
16
- import { createRequire as He } from "module";
17
- import { startBridge as Ne } from "@php-wasm/xdebug-bridge";
18
- import { exec as Oe } from "child_process";
19
- import { dir as je, setGracefulCleanup as Ve } from "tmp-promise";
20
- import Ye from "ps-man";
21
- import { removeTempDirSymlink as qe, createTempDirSymlink as ze, clearXdebugIDEConfig as Ge, addXdebugIDEConfig as Qe } from "@php-wasm/cli-util";
22
- import { createHash as Xe } from "crypto";
23
- import { PHPMYADMIN_INSTALL_PATH as ee, getPhpMyAdminInstallSteps as Ze, PHPMYADMIN_ENTRY_PATH as Je } from "@wp-playground/tools";
24
- import { jspi as te } from "wasm-feature-detect";
25
- const Ke = 2 ** 31 - 1;
26
- class et {
27
- constructor(t = 1, r = Ke) {
28
- this.claimed = /* @__PURE__ */ new Set(), this.initialId = t, this.maxId = r, this.nextId = t;
29
- }
30
- claim() {
31
- const t = this.maxId - this.initialId + 1;
32
- for (let r = 0; r < t; r++)
33
- if (this.claimed.has(this.nextId))
34
- this.nextId++, this.nextId > this.maxId && (this.nextId = this.initialId);
35
- else
36
- return this.claimed.add(this.nextId), this.nextId;
37
- throw new Error(
38
- `Unable to find free process ID after ${t} tries.`
39
- );
40
- }
41
- release(t) {
42
- return this.claimed.has(t) ? (this.claimed.delete(t), !0) : !1;
43
- }
44
- }
45
- function U(e) {
1
+ import { logger as P, LogSeverity as F, errorLogPath as Z } from "@php-wasm/logger";
2
+ import { consumeAPI as ue, ProcessIdAllocator as xe, SupportedPHPVersions as R, printDebugDetails as $e, HttpCookieStore as Ee, FileLockManagerInMemory as Te, StreamedPHPResponse as J, createObjectPoolProxy as Ie, exposeAPI as ke, PHPResponse as Me, exposeSyncAPI as Be } from "@php-wasm/universal";
3
+ import { resolveRemoteBlueprint as Ae, resolveRuntimeConfiguration as K, compileBlueprintV1 as de, isBlueprintBundle as Ce, runBlueprintV1Steps as ee } from "@wp-playground/blueprints";
4
+ import { zipDirectory as De, RecommendedPHPVersion as M } from "@wp-playground/common";
5
+ import c, { existsSync as Y, rmdirSync as Re, mkdirSync as j, readdirSync as We } from "fs";
6
+ import { MessageChannel as pe, Worker as te } from "worker_threads";
7
+ import { createNodeFsMountHandler as Le } from "@php-wasm/node";
8
+ import d, { basename as D, join as ce } from "path";
9
+ import { exec as me } from "child_process";
10
+ import { promisify as Ue } from "util";
11
+ import fe from "express";
12
+ import { Readable as He } from "stream";
13
+ import { pipeline as Fe } from "stream/promises";
14
+ import Ne from "yargs";
15
+ import { NodeJsFilesystem as Oe, OverlayFilesystem as _e, InMemoryFilesystem as je, ZipFilesystem as Ve } from "@wp-playground/storage";
16
+ import { EmscriptenDownloadMonitor as Ye, ProgressTracker as qe } from "@php-wasm/progress";
17
+ import { resolveWordPressRelease as ze } from "@wp-playground/wordpress";
18
+ import $ from "fs-extra";
19
+ import { createRequire as Ge } from "module";
20
+ import q from "os";
21
+ import { startBridge as Qe } from "@php-wasm/xdebug-bridge";
22
+ import { dir as Xe, setGracefulCleanup as Ze } from "tmp-promise";
23
+ import Je from "ps-man";
24
+ import { removeTempDirSymlink as Ke, createTempDirSymlink as oe, makeXdebugConfig as et, clearXdebugIDEConfig as tt, addXdebugIDEConfig as ot } from "@php-wasm/cli-util";
25
+ import { createHash as rt } from "crypto";
26
+ import { PHPMYADMIN_INSTALL_PATH as re, getPhpMyAdminInstallSteps as st, PHPMYADMIN_ENTRY_PATH as it } from "@wp-playground/tools";
27
+ import { jspi as se } from "wasm-feature-detect";
28
+ function N(e) {
46
29
  const t = [];
47
- for (const r of e) {
48
- const o = r.split(":");
49
- if (o.length !== 2)
50
- throw new Error(`Invalid mount format: ${r}.
30
+ for (const o of e) {
31
+ const r = o.split(":");
32
+ if (r.length !== 2)
33
+ throw new Error(`Invalid mount format: ${o}.
51
34
  Expected format: /host/path:/vfs/path.
52
35
  If your path contains a colon, e.g. C:\\myplugin, use the --mount-dir option instead.
53
36
  Example: --mount-dir C:\\my-plugin /wordpress/wp-content/plugins/my-plugin`);
54
- const [s, i] = o;
55
- if (!j(s))
37
+ const [s, i] = r;
38
+ if (!Y(s))
56
39
  throw new Error(`Host path does not exist: ${s}`);
57
40
  t.push({ hostPath: s, vfsPath: i });
58
41
  }
59
42
  return t;
60
43
  }
61
- function re(e) {
44
+ function ie(e) {
62
45
  if (e.length % 2 !== 0)
63
46
  throw new Error("Invalid mount format. Expected: /host/path /vfs/path");
64
47
  const t = [];
65
- for (let r = 0; r < e.length; r += 2) {
66
- const o = e[r], s = e[r + 1];
67
- if (!j(o))
68
- throw new Error(`Host path does not exist: ${o}`);
48
+ for (let o = 0; o < e.length; o += 2) {
49
+ const r = e[o], s = e[o + 1];
50
+ if (!Y(r))
51
+ throw new Error(`Host path does not exist: ${r}`);
69
52
  t.push({
70
- hostPath: u.resolve(process.cwd(), o),
53
+ hostPath: d.resolve(process.cwd(), r),
71
54
  vfsPath: s
72
55
  });
73
56
  }
74
57
  return t;
75
58
  }
76
- async function nr(e, t) {
77
- for (const r of t)
59
+ async function yo(e, t) {
60
+ for (const o of t)
78
61
  await e.mount(
79
- r.vfsPath,
80
- Me(r.hostPath)
62
+ o.vfsPath,
63
+ Le(o.hostPath)
81
64
  );
82
65
  }
83
- const oe = {
66
+ const ne = {
84
67
  step: "runPHP",
85
68
  code: {
86
69
  filename: "activate-theme.php",
@@ -99,30 +82,30 @@ const oe = {
99
82
  `
100
83
  }
101
84
  };
102
- function ue(e) {
103
- const t = e.autoMount, r = [...e.mount || []], o = [...e["mount-before-install"] || []], s = {
85
+ function he(e) {
86
+ const t = e.autoMount, o = [...e.mount || []], r = [...e["mount-before-install"] || []], s = {
104
87
  ...e,
105
- mount: r,
106
- "mount-before-install": o,
88
+ mount: o,
89
+ "mount-before-install": r,
107
90
  "additional-blueprint-steps": [
108
91
  ...e["additional-blueprint-steps"] || []
109
92
  ]
110
93
  };
111
- if (st(t)) {
112
- const a = `/wordpress/wp-content/plugins/${A(t)}`;
113
- r.push({
94
+ if (ut(t)) {
95
+ const n = `/wordpress/wp-content/plugins/${D(t)}`;
96
+ o.push({
114
97
  hostPath: t,
115
- vfsPath: a,
98
+ vfsPath: n,
116
99
  autoMounted: !0
117
100
  }), s["additional-blueprint-steps"].push({
118
101
  step: "activatePlugin",
119
- pluginPath: `/wordpress/wp-content/plugins/${A(t)}`
102
+ pluginPath: `/wordpress/wp-content/plugins/${D(t)}`
120
103
  });
121
- } else if (ot(t)) {
122
- const i = A(t), a = `/wordpress/wp-content/themes/${i}`;
123
- r.push({
104
+ } else if (lt(t)) {
105
+ const i = D(t), n = `/wordpress/wp-content/themes/${i}`;
106
+ o.push({
124
107
  hostPath: t,
125
- vfsPath: a,
108
+ vfsPath: n,
126
109
  autoMounted: !0
127
110
  }), s["additional-blueprint-steps"].push(
128
111
  e["experimental-blueprints-v2-runner"] ? {
@@ -133,194 +116,224 @@ function ue(e) {
133
116
  themeFolderName: i
134
117
  }
135
118
  );
136
- } else if (rt(t)) {
119
+ } else if (at(t)) {
137
120
  const i = c.readdirSync(t);
138
- for (const a of i)
139
- a !== "index.php" && r.push({
140
- hostPath: `${t}/${a}`,
141
- vfsPath: `/wordpress/wp-content/${a}`,
121
+ for (const n of i)
122
+ n !== "index.php" && o.push({
123
+ hostPath: `${t}/${n}`,
124
+ vfsPath: `/wordpress/wp-content/${n}`,
142
125
  autoMounted: !0
143
126
  });
144
- s["additional-blueprint-steps"].push(oe);
145
- } else tt(t) && (o.push({
127
+ s["additional-blueprint-steps"].push(ne);
128
+ } else nt(t) && (r.push({
146
129
  hostPath: t,
147
130
  vfsPath: "/wordpress",
148
131
  autoMounted: !0
149
- }), s.mode = "apply-to-existing-site", s["additional-blueprint-steps"].push(oe), s.wordpressInstallMode || (s.wordpressInstallMode = "install-from-existing-files-if-needed"));
132
+ }), s.mode = "apply-to-existing-site", s["additional-blueprint-steps"].push(ne), s.wordpressInstallMode || (s.wordpressInstallMode = "install-from-existing-files-if-needed"));
150
133
  return s;
151
134
  }
152
- function tt(e) {
135
+ function nt(e) {
153
136
  const t = c.readdirSync(e);
154
137
  return t.includes("wp-admin") && t.includes("wp-includes") && t.includes("wp-content");
155
138
  }
156
- function rt(e) {
139
+ function at(e) {
157
140
  const t = c.readdirSync(e);
158
141
  return t.includes("themes") || t.includes("plugins") || t.includes("mu-plugins") || t.includes("uploads");
159
142
  }
160
- function ot(e) {
143
+ function lt(e) {
161
144
  if (!c.readdirSync(e).includes("style.css"))
162
145
  return !1;
163
- const r = c.readFileSync(de(e, "style.css"), "utf8");
164
- return !!/^(?:[ \t]*<\?php)?[ \t/*#@]*Theme Name:(.*)$/im.exec(r);
146
+ const o = c.readFileSync(ce(e, "style.css"), "utf8");
147
+ return !!/^(?:[ \t]*<\?php)?[ \t/*#@]*Theme Name:(.*)$/im.exec(o);
165
148
  }
166
- function st(e) {
167
- const t = c.readdirSync(e), r = /^(?:[ \t]*<\?php)?[ \t/*#@]*Plugin Name:(.*)$/im;
149
+ function ut(e) {
150
+ const t = c.readdirSync(e), o = /^(?:[ \t]*<\?php)?[ \t/*#@]*Plugin Name:(.*)$/im;
168
151
  return !!t.filter((s) => s.endsWith(".php")).find((s) => {
169
- const i = c.readFileSync(de(e, s), "utf8");
170
- return !!r.exec(i);
152
+ const i = c.readFileSync(ce(e, s), "utf8");
153
+ return !!o.exec(i);
171
154
  });
172
155
  }
173
- function it(e) {
156
+ function dt(e) {
174
157
  if (e.length % 2 !== 0)
175
158
  throw new Error(
176
159
  "Invalid constant definition format. Expected pairs of NAME value"
177
160
  );
178
161
  const t = {};
179
- for (let r = 0; r < e.length; r += 2) {
180
- const o = e[r], s = e[r + 1];
181
- if (!o || !o.trim())
162
+ for (let o = 0; o < e.length; o += 2) {
163
+ const r = e[o], s = e[o + 1];
164
+ if (!r || !r.trim())
182
165
  throw new Error("Constant name cannot be empty");
183
- t[o.trim()] = s;
166
+ t[r.trim()] = s;
184
167
  }
185
168
  return t;
186
169
  }
187
- function nt(e) {
170
+ function pt(e) {
188
171
  if (e.length % 2 !== 0)
189
172
  throw new Error(
190
173
  "Invalid boolean constant definition format. Expected pairs of NAME value"
191
174
  );
192
175
  const t = {};
193
- for (let r = 0; r < e.length; r += 2) {
194
- const o = e[r], s = e[r + 1].trim().toLowerCase();
195
- if (!o || !o.trim())
176
+ for (let o = 0; o < e.length; o += 2) {
177
+ const r = e[o], s = e[o + 1].trim().toLowerCase();
178
+ if (!r || !r.trim())
196
179
  throw new Error("Constant name cannot be empty");
197
180
  if (s === "true" || s === "1")
198
- t[o.trim()] = !0;
181
+ t[r.trim()] = !0;
199
182
  else if (s === "false" || s === "0")
200
- t[o.trim()] = !1;
183
+ t[r.trim()] = !1;
201
184
  else
202
185
  throw new Error(
203
- `Invalid boolean value for constant "${o}": "${s}". Must be "true", "false", "1", or "0".`
186
+ `Invalid boolean value for constant "${r}": "${s}". Must be "true", "false", "1", or "0".`
204
187
  );
205
188
  }
206
189
  return t;
207
190
  }
208
- function at(e) {
191
+ function ct(e) {
209
192
  if (e.length % 2 !== 0)
210
193
  throw new Error(
211
194
  "Invalid number constant definition format. Expected pairs of NAME value"
212
195
  );
213
196
  const t = {};
214
- for (let r = 0; r < e.length; r += 2) {
215
- const o = e[r], s = e[r + 1].trim();
216
- if (!o || !o.trim())
197
+ for (let o = 0; o < e.length; o += 2) {
198
+ const r = e[o], s = e[o + 1].trim();
199
+ if (!r || !r.trim())
217
200
  throw new Error("Constant name cannot be empty");
218
201
  const i = Number(s);
219
202
  if (isNaN(i))
220
203
  throw new Error(
221
- `Invalid number value for constant "${o}": "${s}". Must be a valid number.`
204
+ `Invalid number value for constant "${r}": "${s}". Must be a valid number.`
222
205
  );
223
- t[o.trim()] = i;
206
+ t[r.trim()] = i;
224
207
  }
225
208
  return t;
226
209
  }
227
- function lt(e = {}, t = {}, r = {}) {
228
- const o = {}, s = /* @__PURE__ */ new Set(), i = (a, l) => {
229
- for (const d in a) {
230
- if (s.has(d))
210
+ function mt(e = {}, t = {}, o = {}) {
211
+ const r = {}, s = /* @__PURE__ */ new Set(), i = (n, l) => {
212
+ for (const u in n) {
213
+ if (s.has(u))
231
214
  throw new Error(
232
- `Constant "${d}" is defined multiple times across different --define-${l} flags`
215
+ `Constant "${u}" is defined multiple times across different --define-${l} flags`
233
216
  );
234
- s.add(d), o[d] = a[d];
217
+ s.add(u), r[u] = n[u];
235
218
  }
236
219
  };
237
- return i(e, "string"), i(t, "bool"), i(r, "number"), o;
220
+ return i(e, "string"), i(t, "bool"), i(o, "number"), r;
238
221
  }
239
- function pe(e) {
240
- return lt(
222
+ function we(e) {
223
+ return mt(
241
224
  e.define,
242
225
  e["define-bool"],
243
226
  e["define-number"]
244
227
  );
245
228
  }
246
- async function dt(e) {
247
- const t = Be(), r = await new Promise((i, a) => {
248
- const l = t.listen(e.port, () => {
249
- const d = l.address();
250
- d === null || typeof d == "string" ? a(new Error("Server address is not available")) : i(l);
251
- });
229
+ const ft = Ue(me);
230
+ function ht(e) {
231
+ return new Promise((t) => {
232
+ if (e === 0) return t(!1);
233
+ const o = fe().listen(e);
234
+ o.once("listening", () => o.close(() => t(!1))), o.once(
235
+ "error",
236
+ (r) => t(r.code === "EADDRINUSE")
237
+ );
252
238
  });
253
- t.use("/", async (i, a) => {
254
- let l;
239
+ }
240
+ async function wt(e) {
241
+ const t = fe(), o = await new Promise((n, l) => {
242
+ const u = t.listen(e.port, () => {
243
+ const w = u.address();
244
+ w === null || typeof w == "string" ? l(new Error("Server address is not available")) : n(u);
245
+ }).once("error", l);
246
+ });
247
+ t.use("/", async (n, l) => {
255
248
  try {
256
- l = await e.handleRequest({
257
- url: i.url,
258
- headers: pt(i),
259
- method: i.method,
260
- body: await ut(i)
261
- });
262
- } catch (d) {
263
- g.error(d), l = H.forHttpCode(500);
249
+ const u = {
250
+ url: n.url,
251
+ headers: Pt(n),
252
+ method: n.method,
253
+ body: await bt(n)
254
+ }, w = await e.handleRequest(u);
255
+ await yt(w, l);
256
+ } catch (u) {
257
+ P.error(u), l.headersSent || (l.statusCode = 500, l.end("Internal Server Error"));
264
258
  }
265
- a.statusCode = l.httpStatusCode;
266
- for (const d in l.headers)
267
- a.setHeader(d, l.headers[d]);
268
- a.end(l.bytes);
269
259
  });
270
- const s = r.address().port;
271
- return await e.onBind(r, s);
260
+ const s = o.address().port, i = process.env.CODESPACE_NAME;
261
+ return i && gt(s, i), await e.onBind(o, s);
262
+ }
263
+ async function yt(e, t) {
264
+ const [o, r] = await Promise.all([
265
+ e.headers,
266
+ e.httpStatusCode
267
+ ]);
268
+ t.statusCode = r;
269
+ for (const i in o)
270
+ t.setHeader(i, o[i]);
271
+ const s = He.fromWeb(e.stdout);
272
+ await Fe(s, t);
272
273
  }
273
- const ut = async (e) => await new Promise((t) => {
274
- const r = [];
275
- e.on("data", (o) => {
276
- r.push(o);
274
+ const bt = async (e) => await new Promise((t) => {
275
+ const o = [];
276
+ e.on("data", (r) => {
277
+ o.push(r);
277
278
  }), e.on("end", () => {
278
- t(new Uint8Array(Buffer.concat(r)));
279
+ t(new Uint8Array(Buffer.concat(o)));
279
280
  });
280
- }), pt = (e) => {
281
+ });
282
+ async function gt(e, t) {
283
+ P.log(`Publishing port ${e}...`);
284
+ const o = `gh codespace ports visibility ${e}:public -c ${t}`;
285
+ for (let r = 0; r < 10; r++)
286
+ try {
287
+ await ft(o);
288
+ return;
289
+ } catch {
290
+ await new Promise((s) => setTimeout(s, 2e3));
291
+ }
292
+ }
293
+ const Pt = (e) => {
281
294
  const t = {};
282
295
  if (e.rawHeaders && e.rawHeaders.length)
283
- for (let r = 0; r < e.rawHeaders.length; r += 2)
284
- t[e.rawHeaders[r].toLowerCase()] = e.rawHeaders[r + 1];
296
+ for (let o = 0; o < e.rawHeaders.length; o += 2)
297
+ t[e.rawHeaders[o].toLowerCase()] = e.rawHeaders[o + 1];
285
298
  return t;
286
299
  };
287
- function ct(e) {
300
+ function vt(e) {
288
301
  return /^latest$|^trunk$|^nightly$|^(?:(\d+)\.(\d+)(?:\.(\d+))?)((?:-beta(?:\d+)?)|(?:-RC(?:\d+)?))?$/.test(e);
289
302
  }
290
- async function mt({
303
+ async function St({
291
304
  sourceString: e,
292
305
  blueprintMayReadAdjacentFiles: t
293
306
  }) {
294
307
  if (!e)
295
308
  return;
296
309
  if (e.startsWith("http://") || e.startsWith("https://"))
297
- return await Ie(e);
298
- let r = u.resolve(process.cwd(), e);
299
- if (!c.existsSync(r))
300
- throw new Error(`Blueprint file does not exist: ${r}`);
301
- const o = c.statSync(r);
302
- if (o.isDirectory() && (r = u.join(r, "blueprint.json")), !o.isFile() && o.isSymbolicLink())
310
+ return await Ae(e);
311
+ let o = d.resolve(process.cwd(), e);
312
+ if (!c.existsSync(o))
313
+ throw new Error(`Blueprint file does not exist: ${o}`);
314
+ const r = c.statSync(o);
315
+ if (r.isDirectory() && (o = d.join(o, "blueprint.json")), !r.isFile() && r.isSymbolicLink())
303
316
  throw new Error(
304
- `Blueprint path is neither a file nor a directory: ${r}`
317
+ `Blueprint path is neither a file nor a directory: ${o}`
305
318
  );
306
- const s = u.extname(r);
319
+ const s = d.extname(o);
307
320
  switch (s) {
308
321
  case ".zip":
309
- return Le.fromArrayBuffer(
310
- c.readFileSync(r).buffer
322
+ return Ve.fromArrayBuffer(
323
+ c.readFileSync(o).buffer
311
324
  );
312
325
  case ".json": {
313
- const i = c.readFileSync(r, "utf-8");
326
+ const i = c.readFileSync(o, "utf-8");
314
327
  try {
315
328
  JSON.parse(i);
316
329
  } catch {
317
330
  throw new Error(
318
- `Blueprint file at ${r} is not a valid JSON file`
331
+ `Blueprint file at ${o} is not a valid JSON file`
319
332
  );
320
333
  }
321
- const a = u.dirname(r), l = new De(a);
322
- return new Re([
323
- new We({
334
+ const n = d.dirname(o), l = new Oe(n);
335
+ return new _e([
336
+ new je({
324
337
  "blueprint.json": i
325
338
  }),
326
339
  /**
@@ -328,14 +341,14 @@ async function mt({
328
341
  * unless the user explicitly allowed it.
329
342
  */
330
343
  {
331
- read(d) {
344
+ read(u) {
332
345
  if (!t)
333
346
  throw new Error(
334
- `Error: Blueprint contained tried to read a local file at path "${d}" (via a resource of type "bundled"). Playground restricts access to local resources by default as a security measure.
347
+ `Error: Blueprint contained tried to read a local file at path "${u}" (via a resource of type "bundled"). Playground restricts access to local resources by default as a security measure.
335
348
 
336
349
  You can allow this Blueprint to read files from the same parent directory by explicitly adding the --blueprint-may-read-adjacent-files option to your command.`
337
350
  );
338
- return l.read(d);
351
+ return l.read(u);
339
352
  }
340
353
  }
341
354
  ]);
@@ -346,29 +359,29 @@ You can allow this Blueprint to read files from the same parent directory by exp
346
359
  );
347
360
  }
348
361
  }
349
- class ht {
350
- constructor(t, r) {
351
- this.args = t, this.siteUrl = r.siteUrl, this.phpVersion = t.php, this.cliOutput = r.cliOutput;
362
+ class xt {
363
+ constructor(t, o) {
364
+ this.args = t, this.siteUrl = o.siteUrl, this.phpVersion = t.php, this.cliOutput = o.cliOutput;
352
365
  }
353
366
  getWorkerType() {
354
367
  return "v2";
355
368
  }
356
- async bootWordPress(t, r) {
357
- const o = {
369
+ async bootWordPress(t, o) {
370
+ const r = {
358
371
  command: this.args.command,
359
372
  siteUrl: this.siteUrl,
360
373
  blueprint: this.args.blueprint,
361
- workerPostInstallMountsPort: r
374
+ workerPostInstallMountsPort: o
362
375
  };
363
- return await t.bootWordPress(o, r), t;
376
+ return await t.bootWordPress(r, o), t;
364
377
  }
365
378
  async bootRequestHandler({
366
379
  worker: t,
367
- fileLockManagerPort: r,
368
- nativeInternalDirPath: o
380
+ fileLockManagerPort: o,
381
+ nativeInternalDirPath: r
369
382
  }) {
370
- const s = ne(t.phpPort);
371
- await s.useFileLockManager(r);
383
+ const s = ue(t.phpPort);
384
+ await s.useFileLockManager(o);
372
385
  const i = {
373
386
  ...this.args,
374
387
  phpVersion: this.phpVersion,
@@ -379,106 +392,106 @@ class ht {
379
392
  withRedis: this.args.redis,
380
393
  withMemcached: this.args.memcached,
381
394
  withXdebug: !!this.args.xdebug,
382
- nativeInternalDirPath: o,
395
+ nativeInternalDirPath: r,
383
396
  mountsBeforeWpInstall: this.args["mount-before-install"] || [],
384
397
  mountsAfterWpInstall: this.args.mount || [],
385
- constants: pe(this.args)
398
+ constants: we(this.args)
386
399
  };
387
400
  return await s.bootWorker(i), s;
388
401
  }
389
402
  }
390
- const O = u.join(V.homedir(), ".wordpress-playground");
391
- async function ft() {
403
+ const V = d.join(q.homedir(), ".wordpress-playground");
404
+ async function $t() {
392
405
  const e = typeof __dirname < "u" ? __dirname : import.meta.dirname;
393
- let t = u.join(e, "sqlite-database-integration.zip");
394
- if (!I.existsSync(t)) {
395
- const r = He(import.meta.url), o = u.dirname(
396
- r.resolve("@wp-playground/wordpress-builds/package.json")
406
+ let t = d.join(e, "sqlite-database-integration.zip");
407
+ if (!$.existsSync(t)) {
408
+ const o = Ge(import.meta.url), r = d.dirname(
409
+ o.resolve("@wp-playground/wordpress-builds/package.json")
397
410
  );
398
- t = u.join(
399
- o,
411
+ t = d.join(
412
+ r,
400
413
  "src",
401
414
  "sqlite-database-integration",
402
415
  "sqlite-database-integration-trunk.zip"
403
416
  );
404
417
  }
405
- return new File([await I.readFile(t)], u.basename(t));
418
+ return new File([await $.readFile(t)], d.basename(t));
406
419
  }
407
- async function wt(e, t, r) {
408
- const o = u.join(O, t);
409
- return I.existsSync(o) || (I.ensureDirSync(O), await yt(e, o, r)), ce(o);
420
+ async function Et(e, t, o) {
421
+ const r = d.join(V, t);
422
+ return $.existsSync(r) || ($.ensureDirSync(V), await Tt(e, r, o)), ye(r);
410
423
  }
411
- async function yt(e, t, r) {
412
- const s = (await r.monitorFetch(fetch(e))).body.getReader(), i = `${t}.partial`, a = I.createWriteStream(i);
424
+ async function Tt(e, t, o) {
425
+ const s = (await o.monitorFetch(fetch(e))).body.getReader(), i = `${t}.partial`, n = $.createWriteStream(i);
413
426
  for (; ; ) {
414
- const { done: l, value: d } = await s.read();
415
- if (d && a.write(d), l)
427
+ const { done: l, value: u } = await s.read();
428
+ if (u && n.write(u), l)
416
429
  break;
417
430
  }
418
- a.close(), a.closed || await new Promise((l, d) => {
419
- a.on("finish", () => {
420
- I.renameSync(i, t), l(null);
421
- }), a.on("error", (S) => {
422
- I.removeSync(i), d(S);
431
+ n.close(), n.closed || await new Promise((l, u) => {
432
+ n.on("finish", () => {
433
+ $.renameSync(i, t), l(null);
434
+ }), n.on("error", (w) => {
435
+ $.removeSync(i), u(w);
423
436
  });
424
437
  });
425
438
  }
426
- function ce(e, t) {
427
- return new File([I.readFileSync(e)], A(e));
439
+ function ye(e, t) {
440
+ return new File([$.readFileSync(e)], D(e));
428
441
  }
429
- class bt {
430
- constructor(t, r) {
431
- this.args = t, this.siteUrl = r.siteUrl, this.cliOutput = r.cliOutput;
442
+ class It {
443
+ constructor(t, o) {
444
+ this.args = t, this.siteUrl = o.siteUrl, this.cliOutput = o.cliOutput;
432
445
  }
433
446
  getWorkerType() {
434
447
  return "v1";
435
448
  }
436
- async bootWordPress(t, r) {
437
- let o, s, i;
438
- const a = new Ue();
449
+ async bootWordPress(t, o) {
450
+ let r, s, i;
451
+ const n = new Ye();
439
452
  if (this.args.wordpressInstallMode === "download-and-install") {
440
- let S = !1;
441
- a.addEventListener("progress", (x) => {
442
- if (S)
453
+ let w = !1;
454
+ n.addEventListener("progress", (S) => {
455
+ if (w)
443
456
  return;
444
- const { loaded: p, total: n } = x.detail, f = Math.floor(
445
- Math.min(100, 100 * p / n)
457
+ const { loaded: p, total: a } = S.detail, m = Math.floor(
458
+ Math.min(100, 100 * p / a)
446
459
  );
447
- S = f === 100, this.cliOutput.updateProgress(
460
+ w = m === 100, this.cliOutput.updateProgress(
448
461
  "Downloading WordPress",
449
- f
462
+ m
450
463
  );
451
- }), o = await _e(this.args.wp), i = u.join(
452
- O,
453
- `prebuilt-wp-content-for-wp-${o.version}.zip`
454
- ), s = c.existsSync(i) ? ce(i) : await wt(
455
- o.releaseUrl,
456
- `${o.version}.zip`,
457
- a
458
- ), g.debug(
459
- `Resolved WordPress release URL: ${o?.releaseUrl}`
464
+ }), r = await ze(this.args.wp), i = d.join(
465
+ V,
466
+ `prebuilt-wp-content-for-wp-${r.version}.zip`
467
+ ), s = c.existsSync(i) ? ye(i) : await Et(
468
+ r.releaseUrl,
469
+ `${r.version}.zip`,
470
+ n
471
+ ), P.debug(
472
+ `Resolved WordPress release URL: ${r?.releaseUrl}`
460
473
  );
461
474
  }
462
475
  let l;
463
- this.args.skipSqliteSetup ? (g.debug("Skipping SQLite integration plugin setup..."), l = void 0) : (this.cliOutput.updateProgress("Preparing SQLite database"), l = await ft()), this.cliOutput.updateProgress("Booting WordPress");
464
- const d = await Z(
476
+ this.args.skipSqliteSetup ? (P.debug("Skipping SQLite integration plugin setup..."), l = void 0) : (this.cliOutput.updateProgress("Preparing SQLite database"), l = await $t()), this.cliOutput.updateProgress("Booting WordPress");
477
+ const u = await K(
465
478
  this.getEffectiveBlueprint()
466
479
  );
467
480
  return await t.bootWordPress(
468
481
  {
469
- wpVersion: d.wpVersion,
482
+ wpVersion: u.wpVersion,
470
483
  siteUrl: this.siteUrl,
471
484
  wordpressInstallMode: this.args.wordpressInstallMode || "download-and-install",
472
485
  wordPressZip: s && await s.arrayBuffer(),
473
486
  sqliteIntegrationPluginZip: await l?.arrayBuffer(),
474
- constants: pe(this.args)
487
+ constants: we(this.args)
475
488
  },
476
- r
489
+ o
477
490
  ), i && !this.args["mount-before-install"] && !c.existsSync(i) && (this.cliOutput.updateProgress("Caching WordPress for next boot"), c.writeFileSync(
478
491
  i,
479
492
  // Comlink proxy is not assignable to UniversalPHP but
480
493
  // proxies all method calls transparently at runtime.
481
- await Te(
494
+ await De(
482
495
  t,
483
496
  "/wordpress"
484
497
  )
@@ -486,17 +499,17 @@ class bt {
486
499
  }
487
500
  async bootRequestHandler({
488
501
  worker: t,
489
- fileLockManagerPort: r,
490
- nativeInternalDirPath: o
502
+ fileLockManagerPort: o,
503
+ nativeInternalDirPath: r
491
504
  }) {
492
- const s = ne(
505
+ const s = ue(
493
506
  t.phpPort
494
507
  );
495
508
  await s.isConnected();
496
- const i = await Z(
509
+ const i = await K(
497
510
  this.getEffectiveBlueprint()
498
511
  );
499
- return await s.useFileLockManager(r), await s.bootRequestHandler({
512
+ return await s.useFileLockManager(o), await s.bootRequestHandler({
500
513
  phpVersion: i.phpVersion,
501
514
  siteUrl: this.siteUrl,
502
515
  mountsBeforeWpInstall: this.args["mount-before-install"] || [],
@@ -508,40 +521,40 @@ class bt {
508
521
  withRedis: this.args.redis,
509
522
  withMemcached: this.args.memcached,
510
523
  withXdebug: !!this.args.xdebug,
511
- nativeInternalDirPath: o,
524
+ nativeInternalDirPath: r,
512
525
  pathAliases: this.args.pathAliases
513
526
  }), await s.isReady(), s;
514
527
  }
515
528
  async compileInputBlueprint(t) {
516
- const r = this.getEffectiveBlueprint(), o = new Fe();
529
+ const o = this.getEffectiveBlueprint(), r = new qe();
517
530
  let s = "", i = !1;
518
- return o.addEventListener("progress", (a) => {
531
+ return r.addEventListener("progress", (n) => {
519
532
  if (i)
520
533
  return;
521
- i = a.detail.progress === 100;
522
- const l = Math.floor(a.detail.progress);
523
- s = a.detail.caption || s || "Running Blueprint", this.cliOutput.updateProgress(s.trim(), l);
524
- }), await ae(r, {
525
- progress: o,
534
+ i = n.detail.progress === 100;
535
+ const l = Math.floor(n.detail.progress);
536
+ s = n.detail.caption || s || "Running Blueprint", this.cliOutput.updateProgress(s.trim(), l);
537
+ }), await de(o, {
538
+ progress: r,
526
539
  additionalSteps: t
527
540
  });
528
541
  }
529
542
  getEffectiveBlueprint() {
530
543
  const t = this.args.blueprint;
531
- return $e(t) ? t : {
544
+ return Ce(t) ? t : {
532
545
  login: this.args.login,
533
546
  ...t || {},
534
547
  preferredVersions: {
535
- php: this.args.php ?? t?.preferredVersions?.php ?? C,
548
+ php: this.args.php ?? t?.preferredVersions?.php ?? M,
536
549
  wp: this.args.wp ?? t?.preferredVersions?.wp ?? "latest",
537
550
  ...t?.preferredVersions || {}
538
551
  }
539
552
  };
540
553
  }
541
554
  }
542
- async function gt(e, t = !0) {
543
- const o = `${u.basename(process.argv0)}${e}${process.pid}-`, s = await je({
544
- prefix: o,
555
+ async function kt(e, t = !0) {
556
+ const r = `${d.basename(process.argv0)}${e}${process.pid}-`, s = await Xe({
557
+ prefix: r,
545
558
  /*
546
559
  * Allow recursive cleanup on process exit.
547
560
  *
@@ -552,45 +565,45 @@ async function gt(e, t = !0) {
552
565
  */
553
566
  unsafeCleanup: !0
554
567
  });
555
- return t && Ve(), s;
568
+ return t && Ze(), s;
556
569
  }
557
- async function Pt(e, t, r) {
558
- const s = (await vt(
570
+ async function Mt(e, t, o) {
571
+ const s = (await Bt(
559
572
  e,
560
573
  t,
561
- r
574
+ o
562
575
  )).map(
563
- (i) => new Promise((a) => {
576
+ (i) => new Promise((n) => {
564
577
  c.rm(i, { recursive: !0 }, (l) => {
565
- l ? g.warn(
578
+ l ? P.warn(
566
579
  `Failed to delete stale Playground temp dir: ${i}`,
567
580
  l
568
- ) : g.info(
581
+ ) : P.info(
569
582
  `Deleted stale Playground temp dir: ${i}`
570
- ), a();
583
+ ), n();
571
584
  });
572
585
  })
573
586
  );
574
587
  await Promise.all(s);
575
588
  }
576
- async function vt(e, t, r) {
589
+ async function Bt(e, t, o) {
577
590
  try {
578
- const o = c.readdirSync(r).map((i) => u.join(r, i)), s = [];
579
- for (const i of o)
580
- await xt(
591
+ const r = c.readdirSync(o).map((i) => d.join(o, i)), s = [];
592
+ for (const i of r)
593
+ await At(
581
594
  e,
582
595
  t,
583
596
  i
584
597
  ) && s.push(i);
585
598
  return s;
586
- } catch (o) {
587
- return g.warn(`Failed to find stale Playground temp dirs: ${o}`), [];
599
+ } catch (r) {
600
+ return P.warn(`Failed to find stale Playground temp dirs: ${r}`), [];
588
601
  }
589
602
  }
590
- async function xt(e, t, r) {
591
- if (!c.lstatSync(r).isDirectory())
603
+ async function At(e, t, o) {
604
+ if (!c.lstatSync(o).isDirectory())
592
605
  return !1;
593
- const s = u.basename(r);
606
+ const s = d.basename(o);
594
607
  if (!s.includes(e))
595
608
  return !1;
596
609
  const i = s.match(
@@ -598,37 +611,37 @@ async function xt(e, t, r) {
598
611
  );
599
612
  if (!i)
600
613
  return !1;
601
- const a = {
614
+ const n = {
602
615
  executableName: i[1],
603
616
  pid: i[2]
604
617
  };
605
- if (await St(a.pid, a.executableName))
618
+ if (await Ct(n.pid, n.executableName))
606
619
  return !1;
607
620
  const l = Date.now() - t;
608
- return c.statSync(r).mtime.getTime() < l;
621
+ return c.statSync(o).mtime.getTime() < l;
609
622
  }
610
- async function St(e, t) {
611
- const [r] = await new Promise(
612
- (o, s) => {
613
- Ye.list(
623
+ async function Ct(e, t) {
624
+ const [o] = await new Promise(
625
+ (r, s) => {
626
+ Je.list(
614
627
  {
615
628
  pid: e,
616
629
  name: t,
617
630
  // Remove path from executable name in the results.
618
631
  clean: !0
619
632
  },
620
- (i, a) => {
621
- i ? s(i) : o(a);
633
+ (i, n) => {
634
+ i ? s(i) : r(n);
622
635
  }
623
636
  );
624
637
  }
625
638
  );
626
- return !!r && r.pid === e && r.command === t;
639
+ return !!o && o.pid === e && o.command === t;
627
640
  }
628
- function It(e) {
641
+ function Dt(e) {
629
642
  return process.env.CI === "true" || process.env.CI === "1" || process.env.GITHUB_ACTIONS === "true" || process.env.GITHUB_ACTIONS === "1" || (process.env.TERM || "").toLowerCase() === "dumb" ? !1 : e ? !!e.isTTY : process.stdout.isTTY;
630
643
  }
631
- class $t {
644
+ class Rt {
632
645
  constructor(t) {
633
646
  this.lastProgressLine = "", this.progressActive = !1, this.verbosity = t.verbosity, this.writeStream = t.writeStream || process.stdout;
634
647
  }
@@ -642,7 +655,7 @@ class $t {
642
655
  * This prevents progress spam in logs - users only see the final outcome.
643
656
  */
644
657
  get shouldRender() {
645
- return It(this.writeStream);
658
+ return Dt(this.writeStream);
646
659
  }
647
660
  get isQuiet() {
648
661
  return this.verbosity === "quiet";
@@ -689,19 +702,19 @@ ${t}
689
702
  */
690
703
  printConfig(t) {
691
704
  if (this.isQuiet) return;
692
- const r = [];
693
- r.push(
705
+ const o = [];
706
+ o.push(
694
707
  `${this.dim("PHP")} ${this.cyan(t.phpVersion)} ${this.dim("WordPress")} ${this.cyan(t.wpVersion)}`
695
708
  );
696
- const o = [];
697
- if (t.intl && o.push("intl"), t.redis && o.push("redis"), t.memcached && o.push("memcached"), t.xdebug && o.push(this.yellow("xdebug")), o.length > 0 && r.push(`${this.dim("Extensions")} ${o.join(", ")}`), t.mounts.length > 0)
709
+ const r = [];
710
+ if (t.intl && r.push("intl"), t.redis && r.push("redis"), t.memcached && r.push("memcached"), t.xdebug && r.push(this.yellow("xdebug")), r.length > 0 && o.push(`${this.dim("Extensions")} ${r.join(", ")}`), t.mounts.length > 0)
698
711
  for (const s of t.mounts) {
699
712
  const i = s.autoMounted ? ` ${this.dim("(auto-mount)")}` : "";
700
- r.push(
713
+ o.push(
701
714
  `${this.dim("Mount")} ${s.hostPath} ${this.dim("→")} ${s.vfsPath}${i}`
702
715
  );
703
716
  }
704
- t.blueprint && r.push(`${this.dim("Blueprint")} ${t.blueprint}`), this.writeStream.write(r.join(`
717
+ t.blueprint && o.push(`${this.dim("Blueprint")} ${t.blueprint}`), this.writeStream.write(o.join(`
705
718
  `) + `
706
719
 
707
720
  `);
@@ -722,11 +735,11 @@ ${t}
722
735
  * Identical messages are skipped to prevent flickering. When piped,
723
736
  * this method does nothing (early return via shouldRender check).
724
737
  */
725
- updateProgress(t, r) {
738
+ updateProgress(t, o) {
726
739
  if (this.isQuiet || !this.shouldRender) return;
727
740
  this.progressActive || (this.progressActive = !0);
728
- let o = `${t}`;
729
- r !== void 0 && (o = `${t} ${this.dim(`${r}%`)}`), o !== this.lastProgressLine && (this.lastProgressLine = o, this.isTTY ? (this.writeStream.cursorTo(0), this.writeStream.write(o), this.writeStream.clearLine(1)) : this.writeStream.write(`${o}
741
+ let r = `${t}`;
742
+ o !== void 0 && (r = `${t} ${this.dim(`${o}%`)}`), r !== this.lastProgressLine && (this.lastProgressLine = r, this.isTTY ? (this.writeStream.cursorTo(0), this.writeStream.write(r), this.writeStream.clearLine(1)) : this.writeStream.write(`${r}
730
743
  `));
731
744
  }
732
745
  /**
@@ -766,12 +779,12 @@ ${t}
766
779
  * Note: The exact wording "WordPress is running on" is checked by
767
780
  * CI tests, so changes to this string will break test assertions.
768
781
  */
769
- printReady(t, r) {
782
+ printReady(t, o) {
770
783
  if (this.isQuiet) return;
771
- const o = r === 1 ? "worker" : "workers";
784
+ const r = o === 1 ? "worker" : "workers";
772
785
  this.writeStream.write(
773
786
  `
774
- ${this.green("Ready!")} WordPress is running on ${this.bold(t)} ${this.dim(`(${r} ${o})`)}
787
+ ${this.green("Ready!")} WordPress is running on ${this.bold(t)} ${this.dim(`(${o} ${r})`)}
775
788
 
776
789
  `
777
790
  );
@@ -791,12 +804,12 @@ ${this.green("Ready!")} WordPress is running on ${this.bold(t)} ${this.dim(`(${r
791
804
  );
792
805
  }
793
806
  }
794
- const me = {
795
- Quiet: { name: "quiet", severity: L.Fatal },
796
- Normal: { name: "normal", severity: L.Info },
797
- Debug: { name: "debug", severity: L.Debug }
798
- }, Tt = 10;
799
- async function ar(e) {
807
+ const be = {
808
+ Quiet: { name: "quiet", severity: F.Fatal },
809
+ Normal: { name: "normal", severity: F.Info },
810
+ Debug: { name: "debug", severity: F.Debug }
811
+ };
812
+ async function bo(e) {
800
813
  try {
801
814
  const t = {
802
815
  "site-url": {
@@ -806,8 +819,8 @@ async function ar(e) {
806
819
  php: {
807
820
  describe: "PHP version to use.",
808
821
  type: "string",
809
- default: C,
810
- choices: X
822
+ default: M,
823
+ choices: R
811
824
  },
812
825
  wp: {
813
826
  describe: "WordPress version to use.",
@@ -819,21 +832,21 @@ async function ar(e) {
819
832
  type: "string",
820
833
  nargs: 2,
821
834
  array: !0,
822
- coerce: it
835
+ coerce: dt
823
836
  },
824
837
  "define-bool": {
825
838
  describe: 'Define PHP boolean constants (can be used multiple times). Format: NAME value. Value must be "true", "false", "1", or "0". Examples: --define-bool WP_DEBUG true --define-bool MY_FEATURE false',
826
839
  type: "string",
827
840
  nargs: 2,
828
841
  array: !0,
829
- coerce: nt
842
+ coerce: pt
830
843
  },
831
844
  "define-number": {
832
845
  describe: "Define PHP number constants (can be used multiple times). Format: NAME value. Examples: --define-number LIMIT 100 --define-number RATE 45.67",
833
846
  type: "string",
834
847
  nargs: 2,
835
848
  array: !0,
836
- coerce: at
849
+ coerce: ct
837
850
  },
838
851
  // @TODO: Support read-only mounts, e.g. via WORKERFS, a custom
839
852
  // ReadOnlyNODEFS, or by copying the files into MEMFS
@@ -841,27 +854,27 @@ async function ar(e) {
841
854
  describe: "Mount a directory to the PHP runtime (can be used multiple times). Format: /host/path:/vfs/path",
842
855
  type: "array",
843
856
  string: !0,
844
- coerce: U
857
+ coerce: N
845
858
  },
846
859
  "mount-before-install": {
847
860
  describe: "Mount a directory to the PHP runtime before WordPress installation (can be used multiple times). Format: /host/path:/vfs/path",
848
861
  type: "array",
849
862
  string: !0,
850
- coerce: U
863
+ coerce: N
851
864
  },
852
865
  "mount-dir": {
853
866
  describe: 'Mount a directory to the PHP runtime (can be used multiple times). Format: "/host/path" "/vfs/path"',
854
867
  type: "array",
855
868
  nargs: 2,
856
869
  array: !0,
857
- coerce: re
870
+ coerce: ie
858
871
  },
859
872
  "mount-dir-before-install": {
860
873
  describe: 'Mount a directory before WordPress installation (can be used multiple times). Format: "/host/path" "/vfs/path"',
861
874
  type: "string",
862
875
  nargs: 2,
863
876
  array: !0,
864
- coerce: re
877
+ coerce: ie
865
878
  },
866
879
  login: {
867
880
  describe: "Should log the user in",
@@ -908,8 +921,8 @@ async function ar(e) {
908
921
  verbosity: {
909
922
  describe: "Output logs and progress messages.",
910
923
  type: "string",
911
- choices: Object.values(me).map(
912
- (n) => n.name
924
+ choices: Object.values(be).map(
925
+ (a) => a.name
913
926
  ),
914
927
  default: "normal"
915
928
  },
@@ -969,7 +982,7 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
969
982
  // supported IDEs and, if needed, will create the relevant
970
983
  // config file for each.
971
984
  choices: ["", "vscode", "phpstorm"],
972
- coerce: (n) => n === "" ? ["vscode", "phpstorm"] : [n]
985
+ coerce: (a) => a === "" ? ["vscode", "phpstorm"] : [a]
973
986
  },
974
987
  "experimental-blueprints-v2-runner": {
975
988
  describe: "Use the experimental Blueprint V2 runner.",
@@ -988,13 +1001,12 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
988
1001
  phpmyadmin: {
989
1002
  describe: "Install phpMyAdmin for database management. The phpMyAdmin URL will be printed after boot. Optionally specify a custom URL path (default: /phpmyadmin).",
990
1003
  type: "string",
991
- coerce: (n) => n === "" ? "/phpmyadmin" : n
1004
+ coerce: (a) => a === "" ? "/phpmyadmin" : a
992
1005
  }
993
- }, r = {
1006
+ }, o = {
994
1007
  port: {
995
- describe: "Port to listen on when serving.",
996
- type: "number",
997
- default: 9400
1008
+ describe: "Port to listen on when serving. Defaults to 9400 when available.",
1009
+ type: "number"
998
1010
  },
999
1011
  "experimental-multi-worker": {
1000
1012
  deprecated: "This option is not needed. Multiple workers are always used.",
@@ -1005,7 +1017,7 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
1005
1017
  describe: "Enable experimental browser development tools.",
1006
1018
  type: "boolean"
1007
1019
  }
1008
- }, o = {
1020
+ }, r = {
1009
1021
  path: {
1010
1022
  describe: "Path to the project directory. Playground will auto-detect if this is a plugin, theme, wp-content, or WordPress directory.",
1011
1023
  type: "string",
@@ -1014,8 +1026,8 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
1014
1026
  php: {
1015
1027
  describe: "PHP version to use.",
1016
1028
  type: "string",
1017
- default: C,
1018
- choices: X
1029
+ default: M,
1030
+ choices: R
1019
1031
  },
1020
1032
  wp: {
1021
1033
  describe: "WordPress version to use.",
@@ -1023,9 +1035,8 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
1023
1035
  default: "latest"
1024
1036
  },
1025
1037
  port: {
1026
- describe: "Port to listen on.",
1027
- type: "number",
1028
- default: 9400
1038
+ describe: "Port to listen on. Defaults to 9400 when available.",
1039
+ type: "number"
1029
1040
  },
1030
1041
  blueprint: {
1031
1042
  describe: "Path to a Blueprint JSON file to execute on startup.",
@@ -1061,7 +1072,7 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
1061
1072
  describe: "Mount a directory to the PHP runtime (can be used multiple times). Format: /host/path:/vfs/path. Use this for additional mounts beyond auto-detection.",
1062
1073
  type: "array",
1063
1074
  string: !0,
1064
- coerce: U
1075
+ coerce: N
1065
1076
  },
1066
1077
  reset: {
1067
1078
  describe: "Deletes the stored site directory and starts a new site from scratch.",
@@ -1085,10 +1096,10 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
1085
1096
  type: "string",
1086
1097
  default: "wordpress.zip"
1087
1098
  }
1088
- }, i = Ce(e).usage("Usage: wp-playground <command> [options]").command(
1099
+ }, i = Ne(e).usage("Usage: wp-playground <command> [options]").command(
1089
1100
  "start",
1090
1101
  "Start a local WordPress server with automatic project detection (recommended)",
1091
- (n) => n.usage(
1102
+ (a) => a.usage(
1092
1103
  `Usage: wp-playground start [options]
1093
1104
 
1094
1105
  The easiest way to run WordPress locally. Automatically detects
@@ -1101,142 +1112,142 @@ Examples:
1101
1112
  wp-playground start --wp=6.7 --php=8.3 # Use specific versions
1102
1113
  wp-playground start --skip-browser # Skip opening browser
1103
1114
  wp-playground start --no-auto-mount # Disable auto-detection`
1104
- ).options(o)
1115
+ ).options(r)
1105
1116
  ).command(
1106
1117
  "server",
1107
1118
  "Start a local WordPress server (advanced, low-level)",
1108
- (n) => n.options({
1119
+ (a) => a.options({
1109
1120
  ...t,
1110
- ...r
1121
+ ...o
1111
1122
  })
1112
1123
  ).command(
1113
1124
  "run-blueprint",
1114
1125
  "Execute a Blueprint without starting a server",
1115
- (n) => n.options({ ...t })
1126
+ (a) => a.options({ ...t })
1116
1127
  ).command(
1117
1128
  "build-snapshot",
1118
1129
  "Build a ZIP snapshot of a WordPress site based on a Blueprint",
1119
- (n) => n.options({
1130
+ (a) => a.options({
1120
1131
  ...t,
1121
1132
  ...s
1122
1133
  })
1123
1134
  ).demandCommand(1, "Please specify a command").strictCommands().conflicts(
1124
1135
  "experimental-unsafe-ide-integration",
1125
1136
  "experimental-devtools"
1126
- ).showHelpOnFail(!1).fail((n, f, y) => {
1127
- if (f)
1128
- throw f;
1129
- n && n.includes("Please specify a command") && (y.showHelp(), console.error(`
1130
- ` + n), process.exit(1)), console.error(n), process.exit(1);
1131
- }).strictOptions().check(async (n) => {
1132
- if (n["skip-wordpress-install"] === !0 && (n["wordpress-install-mode"] = "do-not-attempt-installing", n.wordpressInstallMode = "do-not-attempt-installing"), n.wp !== void 0 && typeof n.wp == "string" && !ct(n.wp))
1137
+ ).showHelpOnFail(!1).fail((a, m, y) => {
1138
+ if (m)
1139
+ throw m;
1140
+ a && a.includes("Please specify a command") && (y.showHelp(), console.error(`
1141
+ ` + a), process.exit(1)), console.error(a), process.exit(1);
1142
+ }).strictOptions().check(async (a) => {
1143
+ if (a["skip-wordpress-install"] === !0 && (a["wordpress-install-mode"] = "do-not-attempt-installing", a.wordpressInstallMode = "do-not-attempt-installing"), a.wp !== void 0 && typeof a.wp == "string" && !vt(a.wp))
1133
1144
  try {
1134
- new URL(n.wp);
1145
+ new URL(a.wp);
1135
1146
  } catch {
1136
1147
  throw new Error(
1137
1148
  'Unrecognized WordPress version. Please use "latest", a URL, or a numeric version such as "6.2", "6.0.1", "6.2-beta1", or "6.2-RC1"'
1138
1149
  );
1139
1150
  }
1140
- const f = n["site-url"];
1141
- if (typeof f == "string" && f.trim() !== "")
1151
+ const m = a["site-url"];
1152
+ if (typeof m == "string" && m.trim() !== "")
1142
1153
  try {
1143
- new URL(f);
1154
+ new URL(m);
1144
1155
  } catch {
1145
1156
  throw new Error(
1146
- `Invalid site-url "${f}". Please provide a valid URL (e.g., http://localhost:8080 or https://example.com)`
1157
+ `Invalid site-url "${m}". Please provide a valid URL (e.g., http://localhost:8080 or https://example.com)`
1147
1158
  );
1148
1159
  }
1149
- if (n["auto-mount"]) {
1160
+ if (a["auto-mount"]) {
1150
1161
  let y = !1;
1151
1162
  try {
1152
1163
  y = c.statSync(
1153
- n["auto-mount"]
1164
+ a["auto-mount"]
1154
1165
  ).isDirectory();
1155
1166
  } catch {
1156
1167
  y = !1;
1157
1168
  }
1158
1169
  if (!y)
1159
1170
  throw new Error(
1160
- `The specified --auto-mount path is not a directory: '${n["auto-mount"]}'.`
1171
+ `The specified --auto-mount path is not a directory: '${a["auto-mount"]}'.`
1161
1172
  );
1162
1173
  }
1163
- if (n["experimental-blueprints-v2-runner"] === !0)
1174
+ if (a["experimental-blueprints-v2-runner"] === !0)
1164
1175
  throw new Error(
1165
1176
  "Blueprints v2 are temporarily disabled while we rework their runtime implementation."
1166
1177
  );
1167
- if (n.mode !== void 0)
1178
+ if (a.mode !== void 0)
1168
1179
  throw new Error(
1169
1180
  "The --mode option requires the --experimentalBlueprintsV2Runner flag."
1170
1181
  );
1171
1182
  return !0;
1172
1183
  });
1173
1184
  i.wrap(i.terminalWidth());
1174
- const a = await i.argv, l = a._[0];
1185
+ const n = await i.argv, l = n._[0];
1175
1186
  ["start", "run-blueprint", "server", "build-snapshot"].includes(
1176
1187
  l
1177
1188
  ) || (i.showHelp(), process.exit(1));
1178
- const d = a.define || {};
1179
- !("WP_DEBUG" in d) && !("WP_DEBUG_LOG" in d) && !("WP_DEBUG_DISPLAY" in d) && (d.WP_DEBUG = "true", d.WP_DEBUG_LOG = "true", d.WP_DEBUG_DISPLAY = "true");
1180
- const S = {
1181
- ...a,
1182
- define: d,
1189
+ const u = n.define || {};
1190
+ !("WP_DEBUG" in u) && !("WP_DEBUG_LOG" in u) && !("WP_DEBUG_DISPLAY" in u) && (u.WP_DEBUG = "true", u.WP_DEBUG_LOG = "true", u.WP_DEBUG_DISPLAY = "true");
1191
+ const w = {
1192
+ ...n,
1193
+ define: u,
1183
1194
  command: l,
1184
1195
  mount: [
1185
- ...a.mount || [],
1186
- ...a["mount-dir"] || []
1196
+ ...n.mount || [],
1197
+ ...n["mount-dir"] || []
1187
1198
  ],
1188
1199
  "mount-before-install": [
1189
- ...a["mount-before-install"] || [],
1190
- ...a["mount-dir-before-install"] || []
1200
+ ...n["mount-before-install"] || [],
1201
+ ...n["mount-dir-before-install"] || []
1191
1202
  ]
1192
- }, x = await Mt(S);
1193
- x === void 0 && process.exit(0);
1203
+ }, S = await Lt(w);
1204
+ S === void 0 && process.exit(0);
1194
1205
  const p = /* @__PURE__ */ (() => {
1195
- let n;
1206
+ let a;
1196
1207
  return async () => {
1197
- n === void 0 && (n = x[Symbol.asyncDispose]()), await n, process.exit(0);
1208
+ a === void 0 && (a = S[Symbol.asyncDispose]()), await a, process.exit(0);
1198
1209
  };
1199
1210
  })();
1200
1211
  return process.on("SIGINT", p), process.on("SIGTERM", p), {
1201
1212
  [Symbol.asyncDispose]: async () => {
1202
- process.off("SIGINT", p), process.off("SIGTERM", p), await x[Symbol.asyncDispose]();
1213
+ process.off("SIGINT", p), process.off("SIGTERM", p), await S[Symbol.asyncDispose]();
1203
1214
  },
1204
- [he]: { cliServer: x }
1215
+ [ge]: { cliServer: S }
1205
1216
  };
1206
1217
  } catch (t) {
1207
1218
  if (console.error(t), !(t instanceof Error))
1208
1219
  throw t;
1209
1220
  if (process.argv.includes("--debug"))
1210
- be(t);
1221
+ $e(t);
1211
1222
  else {
1212
- const o = [];
1223
+ const r = [];
1213
1224
  let s = t;
1214
1225
  do
1215
- o.push(s.message), s = s.cause;
1226
+ r.push(s.message), s = s.cause;
1216
1227
  while (s instanceof Error);
1217
1228
  console.error(
1218
- "\x1B[1m" + o.join(" caused by: ") + "\x1B[0m"
1229
+ "\x1B[1m" + r.join(" caused by: ") + "\x1B[0m"
1219
1230
  );
1220
1231
  }
1221
1232
  process.exit(1);
1222
1233
  }
1223
1234
  }
1224
- function se(e, t) {
1235
+ function ae(e, t) {
1225
1236
  return e.find(
1226
- (r) => r.vfsPath.replace(/\/$/, "") === t.replace(/\/$/, "")
1237
+ (o) => o.vfsPath.replace(/\/$/, "") === t.replace(/\/$/, "")
1227
1238
  );
1228
1239
  }
1229
- const he = Symbol("playground-cli-testing"), k = (e) => process.stdout.isTTY ? "\x1B[1m" + e + "\x1B[0m" : e, Et = (e) => process.stdout.isTTY ? "\x1B[31m" + e + "\x1B[0m" : e, kt = (e) => process.stdout.isTTY ? `\x1B[2m${e}\x1B[0m` : e, F = (e) => process.stdout.isTTY ? `\x1B[3m${e}\x1B[0m` : e, ie = (e) => process.stdout.isTTY ? `\x1B[33m${e}\x1B[0m` : e;
1230
- async function Mt(e) {
1240
+ const ge = Symbol("playground-cli-testing"), I = (e) => process.stdout.isTTY ? "\x1B[1m" + e + "\x1B[0m" : e, Wt = (e) => process.stdout.isTTY ? "\x1B[31m" + e + "\x1B[0m" : e, le = (e) => process.stdout.isTTY ? `\x1B[2m${e}\x1B[0m` : e, C = (e) => process.stdout.isTTY ? `\x1B[3m${e}\x1B[0m` : e, O = (e) => process.stdout.isTTY ? `\x1B[33m${e}\x1B[0m` : e;
1241
+ async function Lt(e) {
1231
1242
  let t;
1232
- const r = e.internalCookieStore ? new ge() : void 0, o = [], s = /* @__PURE__ */ new Map();
1233
- if (e.command === "start" && (e = Bt(e)), e.autoMount !== void 0 && (e.autoMount === "" && (e = { ...e, autoMount: process.cwd() }), e = ue(e)), e.wordpressInstallMode === void 0 && (e.wordpressInstallMode = "download-and-install"), e.quiet && (e.verbosity = "quiet", delete e.quiet), e.debug && (e.verbosity = "debug", delete e.debug), e.verbosity) {
1234
- const p = Object.values(me).find(
1235
- (n) => n.name === e.verbosity
1243
+ const o = e.internalCookieStore ? new Ee() : void 0, r = [], s = /* @__PURE__ */ new Map();
1244
+ if (e.command === "start" && (e = Ut(e)), e.autoMount !== void 0 && (e.autoMount === "" && (e = { ...e, autoMount: process.cwd() }), e = he(e)), e.wordpressInstallMode === void 0 && (e.wordpressInstallMode = "download-and-install"), e.quiet && (e.verbosity = "quiet", delete e.quiet), e.debug && (e.verbosity = "debug", delete e.debug), e.verbosity) {
1245
+ const p = Object.values(be).find(
1246
+ (a) => a.name === e.verbosity
1236
1247
  ).severity;
1237
- g.setSeverityFilterLevel(p);
1248
+ P.setSeverityFilterLevel(p);
1238
1249
  }
1239
- if (e.intl || (e.intl = !0), e.redis === void 0 && (e.redis = await te()), e.memcached === void 0 && (e.memcached = await te()), e.phpmyadmin) {
1250
+ if (e.intl || (e.intl = !0), e.redis === void 0 && (e.redis = await se()), e.memcached === void 0 && (e.memcached = await se()), e.phpmyadmin) {
1240
1251
  if (e.phpmyadmin === !0 && (e.phpmyadmin = "/phpmyadmin"), e.skipSqliteSetup)
1241
1252
  throw new Error(
1242
1253
  "--phpmyadmin requires SQLite. Cannot be used with --skip-sqlite-setup."
@@ -1244,17 +1255,17 @@ async function Mt(e) {
1244
1255
  e.pathAliases = [
1245
1256
  {
1246
1257
  urlPrefix: e.phpmyadmin,
1247
- fsPath: ee
1258
+ fsPath: re
1248
1259
  }
1249
1260
  ];
1250
1261
  }
1251
- const i = new $t({
1262
+ const i = new Rt({
1252
1263
  verbosity: e.verbosity || "normal"
1253
1264
  });
1254
1265
  e.command === "server" && (i.printBanner(), i.printConfig({
1255
- phpVersion: e.php || C,
1266
+ phpVersion: e.php || M,
1256
1267
  wpVersion: e.wp || "latest",
1257
- port: e.port || 9400,
1268
+ port: e.port ?? 9400,
1258
1269
  xdebug: !!e.xdebug,
1259
1270
  intl: !!e.intl,
1260
1271
  redis: !!e.redis,
@@ -1265,92 +1276,130 @@ async function Mt(e) {
1265
1276
  ],
1266
1277
  blueprint: typeof e.blueprint == "string" ? e.blueprint : void 0
1267
1278
  }));
1268
- const a = e.command === "server" ? e.port ?? 9400 : 0, l = new Pe();
1269
- let d = !1, S = !0;
1270
- const x = await dt({
1271
- port: a,
1272
- onBind: async (p, n) => {
1273
- const f = "127.0.0.1", y = `http://${f}:${n}`, D = e["site-url"] || y, R = Math.max(
1274
- Ae().length - 1,
1275
- Tt
1276
- ), Y = "-playground-cli-site-", T = await gt(Y);
1277
- g.debug(`Native temp dir for VFS root: ${T.path}`);
1278
- const M = "WP Playground CLI - Listen for Xdebug", q = ".playground-xdebug-root", z = u.join(process.cwd(), q);
1279
- if (await qe(z), e.xdebug && e.experimentalUnsafeIdeIntegration) {
1280
- await ze(
1281
- T.path,
1282
- z,
1283
- process.platform
1284
- );
1285
- const m = {
1286
- hostPath: u.join(".", u.sep, q),
1279
+ const n = e.command === "server" ? e.port ?? 9400 : 0, l = new Te();
1280
+ let u = !1, w = !0;
1281
+ const S = await wt({
1282
+ port: e.port ? e.port : await ht(n) ? 0 : n,
1283
+ onBind: async (p, a) => {
1284
+ const m = "127.0.0.1", y = `http://${m}:${a}`, W = e["site-url"] || y, L = 6, z = "-playground-cli-site-", E = await kt(z);
1285
+ P.debug(`Native temp dir for VFS root: ${E.path}`);
1286
+ const B = "WP Playground CLI - Listen for Xdebug", G = ".playground-xdebug-root", U = d.join(process.cwd(), G);
1287
+ if (await Ke(U), e.xdebug) {
1288
+ const f = {
1289
+ hostPath: d.join(".", d.sep, G),
1287
1290
  vfsPath: "/"
1288
1291
  };
1289
- try {
1290
- await Ge(M, process.cwd());
1291
- const w = typeof e.xdebug == "object" ? e.xdebug : void 0, h = await Qe({
1292
- name: M,
1293
- host: f,
1294
- port: n,
1295
- ides: e.experimentalUnsafeIdeIntegration,
1292
+ if (R.indexOf(
1293
+ e.php || M
1294
+ ) <= R.indexOf("8.5"))
1295
+ await oe(
1296
+ E.path,
1297
+ U,
1298
+ process.platform
1299
+ ), e.xdebug = et({
1296
1300
  cwd: process.cwd(),
1297
1301
  mounts: [
1298
- m,
1302
+ f,
1299
1303
  ...e["mount-before-install"] || [],
1300
1304
  ...e.mount || []
1301
1305
  ],
1302
- ideKey: w?.ideKey
1303
- }), b = e.experimentalUnsafeIdeIntegration, P = b.includes("vscode"), v = b.includes("phpstorm"), $ = Object.values(h);
1304
- console.log(""), $.length > 0 ? (console.log(k("Xdebug configured successfully")), console.log(
1305
- ie("Updated IDE config: ") + $.join(" ")
1306
- ), console.log(
1307
- ie("Playground source root: ") + ".playground-xdebug-root" + F(
1308
- kt(
1306
+ pathSkippings: [
1307
+ "/dev/",
1308
+ "/home/",
1309
+ "/internal/",
1310
+ "/request/",
1311
+ "/proc/"
1312
+ ]
1313
+ }), console.log(I("Xdebug configured successfully")), console.log(
1314
+ O("Playground source root: ") + ".playground-xdebug-root" + C(
1315
+ le(
1309
1316
  " – you can set breakpoints and preview Playground's VFS structure in there."
1310
1317
  )
1311
1318
  )
1312
- )) : (console.log(k("Xdebug configuration failed.")), console.log(
1313
- "No IDE-specific project settings directory was found in the current working directory."
1314
- )), console.log(""), P && h.vscode && (console.log(k("VS Code / Cursor instructions:")), console.log(
1315
- " 1. Ensure you have installed an IDE extension for PHP Debugging"
1316
- ), console.log(
1317
- ` (The ${k("PHP Debug")} extension by ${k(
1318
- "Xdebug"
1319
- )} has been a solid option)`
1320
- ), console.log(
1321
- " 2. Open the Run and Debug panel on the left sidebar"
1322
- ), console.log(
1323
- ` 3. Select "${F(
1324
- M
1325
- )}" from the dropdown`
1326
- ), console.log(' 3. Click "start debugging"'), console.log(
1327
- " 5. Set a breakpoint. For example, in .playground-xdebug-root/wordpress/index.php"
1328
- ), console.log(
1329
- " 6. Visit Playground in your browser to hit the breakpoint"
1330
- ), v && console.log("")), v && h.phpstorm && (console.log(k("PhpStorm instructions:")), console.log(
1331
- ` 1. Choose "${F(
1332
- M
1333
- )}" debug configuration in the toolbar`
1334
- ), console.log(" 2. Click the debug button (bug icon)`"), console.log(
1335
- " 3. Set a breakpoint. For example, in .playground-xdebug-root/wordpress/index.php"
1336
- ), console.log(
1337
- " 4. Visit Playground in your browser to hit the breakpoint"
1338
- )), console.log("");
1339
- } catch (w) {
1340
- throw new Error("Could not configure Xdebug", {
1341
- cause: w
1342
- });
1319
+ );
1320
+ else if (e.experimentalUnsafeIdeIntegration) {
1321
+ await oe(
1322
+ E.path,
1323
+ U,
1324
+ process.platform
1325
+ );
1326
+ try {
1327
+ await tt(
1328
+ B,
1329
+ process.cwd()
1330
+ );
1331
+ const h = typeof e.xdebug == "object" ? e.xdebug : {}, b = await ot({
1332
+ name: B,
1333
+ host: m,
1334
+ port: a,
1335
+ ides: e.experimentalUnsafeIdeIntegration,
1336
+ cwd: process.cwd(),
1337
+ mounts: [
1338
+ f,
1339
+ ...e["mount-before-install"] || [],
1340
+ ...e.mount || []
1341
+ ],
1342
+ ideKey: h.ideKey || "WPPLAYGROUNDCLI"
1343
+ }), v = e.experimentalUnsafeIdeIntegration, x = v.includes("vscode"), T = v.includes("phpstorm"), X = Object.values(b);
1344
+ console.log(""), X.length > 0 ? (console.log(
1345
+ I("Xdebug configured successfully")
1346
+ ), console.log(
1347
+ O("Updated IDE config: ") + X.join(" ")
1348
+ ), console.log(
1349
+ O("Playground source root: ") + ".playground-xdebug-root" + C(
1350
+ le(
1351
+ " – you can set breakpoints and preview Playground's VFS structure in there."
1352
+ )
1353
+ )
1354
+ )) : (console.log(
1355
+ I("Xdebug configuration failed.")
1356
+ ), console.log(
1357
+ "No IDE-specific project settings directory was found in the current working directory."
1358
+ )), console.log(""), x && b.vscode && (console.log(
1359
+ I("VS Code / Cursor instructions:")
1360
+ ), console.log(
1361
+ " 1. Ensure you have installed an IDE extension for PHP Debugging"
1362
+ ), console.log(
1363
+ ` (The ${I("PHP Debug")} extension by ${I(
1364
+ "Xdebug"
1365
+ )} has been a solid option)`
1366
+ ), console.log(
1367
+ " 2. Open the Run and Debug panel on the left sidebar"
1368
+ ), console.log(
1369
+ ` 3. Select "${C(
1370
+ B
1371
+ )}" from the dropdown`
1372
+ ), console.log(' 3. Click "start debugging"'), console.log(
1373
+ " 5. Set a breakpoint. For example, in .playground-xdebug-root/wordpress/index.php"
1374
+ ), console.log(
1375
+ " 6. Visit Playground in your browser to hit the breakpoint"
1376
+ ), T && console.log("")), T && b.phpstorm && (console.log(I("PhpStorm instructions:")), console.log(
1377
+ ` 1. Choose "${C(
1378
+ B
1379
+ )}" debug configuration in the toolbar`
1380
+ ), console.log(
1381
+ " 2. Click the debug button (bug icon)`"
1382
+ ), console.log(
1383
+ " 3. Set a breakpoint. For example, in .playground-xdebug-root/wordpress/index.php"
1384
+ ), console.log(
1385
+ " 4. Visit Playground in your browser to hit the breakpoint"
1386
+ )), console.log("");
1387
+ } catch (h) {
1388
+ throw new Error("Could not configure Xdebug", {
1389
+ cause: h
1390
+ });
1391
+ }
1343
1392
  }
1344
1393
  }
1345
- const fe = u.dirname(T.path), we = 2 * 24 * 60 * 60 * 1e3;
1346
- Pt(
1347
- Y,
1348
- we,
1349
- fe
1394
+ const Pe = d.dirname(E.path), ve = 2 * 24 * 60 * 60 * 1e3;
1395
+ Mt(
1396
+ z,
1397
+ ve,
1398
+ Pe
1350
1399
  );
1351
- const G = u.join(T.path, "internal");
1352
- N(G);
1353
- const ye = [
1400
+ const Q = d.join(E.path, "internal");
1401
+ j(Q);
1402
+ const Se = [
1354
1403
  "wordpress",
1355
1404
  "tools",
1356
1405
  // Note: These dirs are from Emscripten's "default dirs" list:
@@ -1362,91 +1411,91 @@ async function Mt(e) {
1362
1411
  "tmp",
1363
1412
  "home"
1364
1413
  ];
1365
- for (const m of ye) {
1366
- const w = (b) => b.vfsPath === `/${m}`;
1367
- if (!(e["mount-before-install"]?.some(w) || e.mount?.some(w))) {
1368
- const b = u.join(
1369
- T.path,
1370
- m
1414
+ for (const f of Se) {
1415
+ const g = (b) => b.vfsPath === `/${f}`;
1416
+ if (!(e["mount-before-install"]?.some(g) || e.mount?.some(g))) {
1417
+ const b = d.join(
1418
+ E.path,
1419
+ f
1371
1420
  );
1372
- N(b), e["mount-before-install"] === void 0 && (e["mount-before-install"] = []), e["mount-before-install"].unshift({
1373
- vfsPath: `/${m}`,
1421
+ j(b), e["mount-before-install"] === void 0 && (e["mount-before-install"] = []), e["mount-before-install"].unshift({
1422
+ vfsPath: `/${f}`,
1374
1423
  hostPath: b
1375
1424
  });
1376
1425
  }
1377
1426
  }
1378
1427
  if (e["mount-before-install"])
1379
- for (const m of e["mount-before-install"])
1380
- g.debug(
1381
- `Mount before WP install: ${m.vfsPath} -> ${m.hostPath}`
1428
+ for (const f of e["mount-before-install"])
1429
+ P.debug(
1430
+ `Mount before WP install: ${f.vfsPath} -> ${f.hostPath}`
1382
1431
  );
1383
1432
  if (e.mount)
1384
- for (const m of e.mount)
1385
- g.debug(
1386
- `Mount after WP install: ${m.vfsPath} -> ${m.hostPath}`
1433
+ for (const f of e.mount)
1434
+ P.debug(
1435
+ `Mount after WP install: ${f.vfsPath} -> ${f.hostPath}`
1387
1436
  );
1388
- let E;
1389
- e["experimental-blueprints-v2-runner"] ? E = new ht(e, {
1390
- siteUrl: D,
1437
+ let k;
1438
+ e["experimental-blueprints-v2-runner"] ? k = new xt(e, {
1439
+ siteUrl: W,
1391
1440
  cliOutput: i
1392
- }) : (E = new bt(e, {
1393
- siteUrl: D,
1441
+ }) : (k = new It(e, {
1442
+ siteUrl: W,
1394
1443
  cliOutput: i
1395
- }), typeof e.blueprint == "string" && (e.blueprint = await mt({
1444
+ }), typeof e.blueprint == "string" && (e.blueprint = await St({
1396
1445
  sourceString: e.blueprint,
1397
1446
  blueprintMayReadAdjacentFiles: e["blueprint-may-read-adjacent-files"] === !0
1398
1447
  })));
1399
- let W = !1;
1400
- const B = async function() {
1401
- W || (W = !0, await Promise.all(
1402
- o.map(async (w) => {
1403
- await s.get(w)?.dispose(), await w.worker.terminate();
1448
+ let H = !1;
1449
+ const A = async function() {
1450
+ H || (H = !0, await Promise.all(
1451
+ r.map(async (g) => {
1452
+ await s.get(g)?.dispose(), await g.worker.terminate();
1404
1453
  })
1405
- ), p && await new Promise((w) => {
1406
- p.close(w), p.closeAllConnections();
1407
- }), await T.cleanup());
1454
+ ), p && await new Promise((g) => {
1455
+ p.close(g), p.closeAllConnections();
1456
+ }), await E.cleanup());
1408
1457
  };
1409
1458
  try {
1410
- const m = [], w = E.getWorkerType();
1411
- for (let h = 0; h < R; h++) {
1412
- const b = At(w, {
1413
- onExit: (P) => {
1414
- W || P === 0 && g.error(
1415
- `Worker ${h} exited with code ${P}
1459
+ const f = [], g = k.getWorkerType();
1460
+ for (let h = 0; h < L; h++) {
1461
+ const b = Ht(g, {
1462
+ onExit: (v) => {
1463
+ H || v === 0 && P.error(
1464
+ `Worker ${h} exited with code ${v}
1416
1465
  `
1417
1466
  );
1418
1467
  }
1419
1468
  }).then(
1420
- async (P) => {
1421
- o.push(P);
1422
- const v = await Ct(l), $ = await E.bootRequestHandler({
1423
- worker: P,
1424
- fileLockManagerPort: v,
1425
- nativeInternalDirPath: G
1469
+ async (v) => {
1470
+ r.push(v);
1471
+ const x = await Ft(l), T = await k.bootRequestHandler({
1472
+ worker: v,
1473
+ fileLockManagerPort: x,
1474
+ nativeInternalDirPath: Q
1426
1475
  });
1427
1476
  return s.set(
1428
- P,
1429
- $
1430
- ), [P, $];
1477
+ v,
1478
+ T
1479
+ ), [v, T];
1431
1480
  }
1432
1481
  );
1433
- m.push(b), h === 0 && await b;
1482
+ f.push(b), h === 0 && await b;
1434
1483
  }
1435
- await Promise.all(m), t = ve(
1436
- o.map(
1484
+ await Promise.all(f), t = Ie(
1485
+ r.map(
1437
1486
  (h) => s.get(h)
1438
1487
  )
1439
1488
  );
1440
1489
  {
1441
- const h = new le(), b = h.port1, P = h.port2;
1442
- if (await xe(
1490
+ const h = new pe(), b = h.port1, v = h.port2;
1491
+ if (await ke(
1443
1492
  {
1444
1493
  applyPostInstallMountsToAllWorkers: async () => {
1445
1494
  await Promise.all(
1446
1495
  Array.from(
1447
1496
  s.values()
1448
1497
  ).map(
1449
- (v) => v.mountAfterWordPressInstall(
1498
+ (x) => x.mountAfterWordPressInstall(
1450
1499
  e.mount || []
1451
1500
  )
1452
1501
  )
@@ -1455,80 +1504,82 @@ async function Mt(e) {
1455
1504
  },
1456
1505
  void 0,
1457
1506
  b
1458
- ), await E.bootWordPress(
1507
+ ), await k.bootWordPress(
1459
1508
  t,
1460
- P
1461
- ), b.close(), d = !0, !e["experimental-blueprints-v2-runner"]) {
1462
- const v = await E.compileInputBlueprint(
1509
+ v
1510
+ ), b.close(), u = !0, !e["experimental-blueprints-v2-runner"]) {
1511
+ const x = await k.compileInputBlueprint(
1463
1512
  e["additional-blueprint-steps"] || []
1464
1513
  );
1465
- v && await J(
1466
- v,
1514
+ x && await ee(
1515
+ x,
1467
1516
  t
1468
1517
  );
1469
1518
  }
1470
1519
  if (e.phpmyadmin && !await t.fileExists(
1471
- `${ee}/index.php`
1520
+ `${re}/index.php`
1472
1521
  )) {
1473
- const v = await Ze(), $ = await ae({ steps: v });
1474
- await J($, t);
1522
+ const x = await st(), T = await de({ steps: x });
1523
+ await ee(T, t);
1475
1524
  }
1476
1525
  if (e.command === "build-snapshot") {
1477
- await Rt(t, e.outfile), i.printStatus(`Exported to ${e.outfile}`), await B();
1526
+ await Ot(t, e.outfile), i.printStatus(`Exported to ${e.outfile}`), await A();
1478
1527
  return;
1479
1528
  } else if (e.command === "run-blueprint") {
1480
- i.finishProgress("Done"), await B();
1529
+ i.finishProgress("Done"), await A();
1481
1530
  return;
1482
1531
  }
1483
1532
  }
1484
- if (i.finishProgress(), i.printReady(y, R), e.phpmyadmin) {
1485
- const h = u.join(
1533
+ if (i.finishProgress(), i.printReady(y, L), e.phpmyadmin) {
1534
+ const h = d.join(
1486
1535
  e.phpmyadmin,
1487
- Je
1536
+ it
1488
1537
  );
1489
1538
  i.printPhpMyAdminUrl(
1490
1539
  new URL(h, y).toString()
1491
1540
  );
1492
1541
  }
1493
- return e.xdebug && e.experimentalDevtools && (await Ne({
1542
+ return e.xdebug && e.experimentalDevtools && (await Qe({
1494
1543
  phpInstance: t,
1495
1544
  phpRoot: "/wordpress"
1496
1545
  })).start(), {
1497
1546
  playground: t,
1498
1547
  server: p,
1499
1548
  serverUrl: y,
1500
- [Symbol.asyncDispose]: B,
1501
- [he]: {
1502
- workerThreadCount: R
1549
+ [Symbol.asyncDispose]: A,
1550
+ [ge]: {
1551
+ workerThreadCount: L
1503
1552
  }
1504
1553
  };
1505
- } catch (m) {
1554
+ } catch (f) {
1506
1555
  if (e.verbosity !== "debug")
1507
- throw m;
1508
- let w = "";
1509
- throw await t?.fileExists(Q) && (w = await t.readFileAsText(Q)), await B(), new Error(w, { cause: m });
1556
+ throw f;
1557
+ let g = "";
1558
+ throw await t?.fileExists(Z) && (g = await t.readFileAsText(Z)), await A(), new Error(g, { cause: f });
1510
1559
  }
1511
1560
  },
1512
1561
  async handleRequest(p) {
1513
- if (!d)
1514
- return H.forHttpCode(
1562
+ if (!u)
1563
+ return J.forHttpCode(
1515
1564
  502,
1516
1565
  "WordPress is not ready yet"
1517
1566
  );
1518
- if (S) {
1519
- S = !1;
1520
- const f = {
1567
+ if (w) {
1568
+ w = !1;
1569
+ const m = {
1521
1570
  "Content-Type": ["text/plain"],
1522
1571
  "Content-Length": ["0"],
1523
1572
  Location: [p.url]
1524
1573
  };
1525
1574
  return p.headers?.cookie?.includes(
1526
1575
  "playground_auto_login_already_happened"
1527
- ) && (f["Set-Cookie"] = [
1576
+ ) && (m["Set-Cookie"] = [
1528
1577
  "playground_auto_login_already_happened=1; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Path=/"
1529
- ]), new H(302, f, new Uint8Array());
1578
+ ]), J.fromPHPResponse(
1579
+ new Me(302, m, new Uint8Array())
1580
+ );
1530
1581
  }
1531
- r && (p = {
1582
+ o && (p = {
1532
1583
  ...p,
1533
1584
  headers: {
1534
1585
  ...p.headers,
@@ -1537,27 +1588,31 @@ async function Mt(e) {
1537
1588
  // header with the cookies from our store. This avoids
1538
1589
  // getting into a strange state where both browser and
1539
1590
  // server are managing cookies.
1540
- cookie: r.getCookieRequestHeader()
1591
+ cookie: o.getCookieRequestHeader()
1541
1592
  }
1542
1593
  });
1543
- const n = await t.request(p);
1544
- return r && (r.rememberCookiesFromResponseHeaders(
1545
- n.headers
1546
- ), delete n.headers["set-cookie"]), n;
1594
+ const a = await t.requestStreamed(p);
1595
+ if (o) {
1596
+ const m = await a.headers;
1597
+ o.rememberCookiesFromResponseHeaders(m), delete m["set-cookie"];
1598
+ }
1599
+ return a;
1547
1600
  }
1601
+ }).catch((p) => {
1602
+ i.printError(p.message), process.exit(1);
1548
1603
  });
1549
- return x && e.command === "start" && !e.skipBrowser && Dt(x.serverUrl), x;
1604
+ return S && e.command === "start" && !e.skipBrowser && Nt(S.serverUrl), S;
1550
1605
  }
1551
- function Bt(e) {
1606
+ function Ut(e) {
1552
1607
  let t = { ...e, command: "server" };
1553
- e.noAutoMount || (t.autoMount = u.resolve(process.cwd(), t.path ?? ""), t = ue(t), delete t.autoMount);
1554
- const r = se(
1608
+ e.noAutoMount || (t.autoMount = d.resolve(process.cwd(), t.path ?? ""), t = he(t), delete t.autoMount);
1609
+ const o = ae(
1555
1610
  t["mount-before-install"] || [],
1556
1611
  "/wordpress"
1557
- ) || se(t.mount || [], "/wordpress");
1558
- if (r)
1559
- console.log("Site files stored at:", r?.hostPath), e.reset && (console.log(""), console.log(
1560
- Et(
1612
+ ) || ae(t.mount || [], "/wordpress");
1613
+ if (o)
1614
+ console.log("Site files stored at:", o?.hostPath), e.reset && (console.log(""), console.log(
1615
+ Wt(
1561
1616
  "This site is not managed by Playground CLI and cannot be reset."
1562
1617
  )
1563
1618
  ), console.log(
@@ -1566,15 +1621,15 @@ function Bt(e) {
1566
1621
  "You may still remove the site's directory manually if you wish."
1567
1622
  ), process.exit(1));
1568
1623
  else {
1569
- const o = t.autoMount || process.cwd(), s = Xe("sha256").update(o).digest("hex"), i = V.homedir(), a = u.join(
1624
+ const r = t.autoMount || process.cwd(), s = rt("sha256").update(r).digest("hex"), i = q.homedir(), n = d.join(
1570
1625
  i,
1571
1626
  ".wordpress-playground/sites",
1572
1627
  s
1573
1628
  );
1574
- console.log("Site files stored at:", a), j(a) && e.reset && (console.log("Resetting site..."), Ee(a, { recursive: !0 })), N(a, { recursive: !0 }), t["mount-before-install"] = [
1629
+ console.log("Site files stored at:", n), Y(n) && e.reset && (console.log("Resetting site..."), Re(n, { recursive: !0 })), j(n, { recursive: !0 }), t["mount-before-install"] = [
1575
1630
  ...t["mount-before-install"] || [],
1576
- { vfsPath: "/wordpress", hostPath: a }
1577
- ], t.wordpressInstallMode = ke(a).length === 0 ? (
1631
+ { vfsPath: "/wordpress", hostPath: n }
1632
+ ], t.wordpressInstallMode = We(n).length === 0 ? (
1578
1633
  // Only download WordPress on the first run when the site directory is still
1579
1634
  // empty.
1580
1635
  "download-and-install"
@@ -1585,55 +1640,55 @@ function Bt(e) {
1585
1640
  }
1586
1641
  return t;
1587
1642
  }
1588
- const _ = new et();
1589
- function At(e, { onExit: t } = {}) {
1590
- let r;
1591
- return e === "v1" ? r = new K(new URL("./worker-thread-v1.js", import.meta.url)) : r = new K(new URL("./worker-thread-v2.js", import.meta.url)), new Promise((o, s) => {
1643
+ const _ = new xe();
1644
+ function Ht(e, { onExit: t } = {}) {
1645
+ let o;
1646
+ return e === "v1" ? o = new te(new URL("./worker-thread-v1.js", import.meta.url)) : o = new te(new URL("./worker-thread-v2.js", import.meta.url)), new Promise((r, s) => {
1592
1647
  const i = _.claim();
1593
- r.once("message", function(l) {
1594
- l.command === "worker-script-initialized" && o({
1648
+ o.once("message", function(l) {
1649
+ l.command === "worker-script-initialized" && r({
1595
1650
  processId: i,
1596
- worker: r,
1651
+ worker: o,
1597
1652
  phpPort: l.phpPort
1598
1653
  });
1599
- }), r.once("error", function(l) {
1654
+ }), o.once("error", function(l) {
1600
1655
  _.release(i), console.error(l);
1601
- const d = new Error(
1656
+ const u = new Error(
1602
1657
  `Worker failed to load worker. ${l.message ? `Original error: ${l.message}` : ""}`
1603
1658
  );
1604
- s(d);
1659
+ s(u);
1605
1660
  });
1606
- let a = !1;
1607
- r.once("spawn", () => {
1608
- a = !0;
1609
- }), r.once("exit", (l) => {
1610
- _.release(i), a || s(new Error(`Worker exited before spawning: ${l}`)), t?.(l);
1661
+ let n = !1;
1662
+ o.once("spawn", () => {
1663
+ n = !0;
1664
+ }), o.once("exit", (l) => {
1665
+ _.release(i), n || s(new Error(`Worker exited before spawning: ${l}`)), t?.(l);
1611
1666
  });
1612
1667
  });
1613
1668
  }
1614
- async function Ct(e) {
1615
- const { port1: t, port2: r } = new le();
1616
- return await Se(e, t), r;
1669
+ async function Ft(e) {
1670
+ const { port1: t, port2: o } = new pe();
1671
+ return await Be(e, t), o;
1617
1672
  }
1618
- function Dt(e) {
1619
- const t = V.platform();
1620
- let r;
1673
+ function Nt(e) {
1674
+ const t = q.platform();
1675
+ let o;
1621
1676
  switch (t) {
1622
1677
  case "darwin":
1623
- r = `open "${e}"`;
1678
+ o = `open "${e}"`;
1624
1679
  break;
1625
1680
  case "win32":
1626
- r = `start "" "${e}"`;
1681
+ o = `start "" "${e}"`;
1627
1682
  break;
1628
1683
  default:
1629
- r = `xdg-open "${e}"`;
1684
+ o = `xdg-open "${e}"`;
1630
1685
  break;
1631
1686
  }
1632
- Oe(r, (o) => {
1633
- o && g.debug(`Could not open browser: ${o.message}`);
1687
+ me(o, (r) => {
1688
+ r && P.debug(`Could not open browser: ${r.message}`);
1634
1689
  });
1635
1690
  }
1636
- async function Rt(e, t) {
1691
+ async function Ot(e, t) {
1637
1692
  await e.run({
1638
1693
  code: `<?php
1639
1694
  $zip = new ZipArchive();
@@ -1654,17 +1709,17 @@ async function Rt(e, t) {
1654
1709
 
1655
1710
  `
1656
1711
  });
1657
- const r = await e.readFileAsBuffer("/tmp/build.zip");
1658
- c.writeFileSync(t, r);
1712
+ const o = await e.readFileAsBuffer("/tmp/build.zip");
1713
+ c.writeFileSync(t, o);
1659
1714
  }
1660
1715
  export {
1661
- me as L,
1662
- nr as a,
1663
- It as b,
1664
- he as i,
1665
- pe as m,
1666
- ar as p,
1667
- Mt as r,
1668
- At as s
1716
+ be as L,
1717
+ yo as a,
1718
+ Dt as b,
1719
+ ge as i,
1720
+ we as m,
1721
+ bo as p,
1722
+ Lt as r,
1723
+ Ht as s
1669
1724
  };
1670
- //# sourceMappingURL=run-cli-FHDubnX7.js.map
1725
+ //# sourceMappingURL=run-cli-Cv4FHhj_.js.map