@wp-playground/cli 3.0.16 → 3.0.17

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,67 +1,67 @@
1
- import { logger as m, LogSeverity as M, errorLogPath as _ } from "@php-wasm/logger";
2
- import { PHPResponse as U, consumeAPI as j, SupportedPHPVersions as ce, printDebugDetails as pe, exposeAPI as ue, exposeSyncAPI as de } from "@php-wasm/universal";
3
- import { resolveRemoteBlueprint as fe, resolveRuntimeConfiguration as me, compileBlueprintV1 as he, isBlueprintBundle as ge, runBlueprintV1Steps as ye } from "@wp-playground/blueprints";
4
- import { zipDirectory as we, RecommendedPHPVersion as Z } from "@wp-playground/common";
5
- import u, { mkdirSync as H } from "fs";
6
- import { Worker as q, MessageChannel as be } from "worker_threads";
7
- import { p as z, a as ve, e as Pe } from "./mounts-D1_eXSTw.js";
8
- import Se from "express";
9
- import { FileLockManagerForNode as ke } from "@php-wasm/node";
10
- import Y, { cpus as xe } from "os";
11
- import { jspi as Ee } from "wasm-feature-detect";
12
- import Ie from "yargs";
13
- import g, { basename as Ce } from "path";
14
- import { NodeJsFilesystem as Le, OverlayFilesystem as We, InMemoryFilesystem as $e, ZipFilesystem as Te } from "@wp-playground/storage";
15
- import { EmscriptenDownloadMonitor as Be, ProgressTracker as je } from "@php-wasm/progress";
16
- import { resolveWordPressRelease as Fe } from "@wp-playground/wordpress";
17
- import T from "fs-extra";
18
- import { startBridge as Re } from "@php-wasm/xdebug-bridge";
19
- import { dir as Me, setGracefulCleanup as De } from "tmp-promise";
20
- import Ae from "ps-man";
21
- import { XMLParser as K, XMLBuilder as Q } from "fast-xml-parser";
22
- import v from "jsonc-parser";
23
- async function Ue(e) {
24
- const o = Se(), t = await new Promise((n, s) => {
25
- const l = o.listen(e.port, () => {
26
- const a = l.address();
27
- a === null || typeof a == "string" ? s(new Error("Server address is not available")) : n(l);
1
+ import { logger as h, LogSeverity as A, errorLogPath as q } from "@php-wasm/logger";
2
+ import { PHPResponse as V, consumeAPI as j, SupportedPHPVersions as ue, printDebugDetails as de, exposeAPI as fe, exposeSyncAPI as me } from "@php-wasm/universal";
3
+ import { resolveRemoteBlueprint as he, resolveRuntimeConfiguration as ge, compileBlueprintV1 as ye, isBlueprintBundle as we, runBlueprintV1Steps as be } from "@wp-playground/blueprints";
4
+ import { zipDirectory as ve, RecommendedPHPVersion as G } from "@wp-playground/common";
5
+ import u, { mkdirSync as z } from "fs";
6
+ import { Worker as X, MessageChannel as Pe } from "worker_threads";
7
+ import { p as J, a as Se, e as ke } from "./mounts-D1_eXSTw.js";
8
+ import xe from "express";
9
+ import { FileLockManagerForNode as Ee } from "@php-wasm/node";
10
+ import K, { cpus as Ie } from "os";
11
+ import { jspi as Ce } from "wasm-feature-detect";
12
+ import Le from "yargs";
13
+ import g, { basename as $e } from "path";
14
+ import { NodeJsFilesystem as We, OverlayFilesystem as Te, InMemoryFilesystem as Be, ZipFilesystem as je } from "@wp-playground/storage";
15
+ import { EmscriptenDownloadMonitor as Re, ProgressTracker as Fe } from "@php-wasm/progress";
16
+ import { resolveWordPressRelease as Me } from "@wp-playground/wordpress";
17
+ import $ from "fs-extra";
18
+ import { startBridge as De } from "@php-wasm/xdebug-bridge";
19
+ import { dir as Ae, setGracefulCleanup as Ue } from "tmp-promise";
20
+ import Ne from "ps-man";
21
+ import { XMLParser as Q, XMLBuilder as ee } from "fast-xml-parser";
22
+ import P from "jsonc-parser";
23
+ async function Ve(e) {
24
+ const o = xe(), t = await new Promise((n, r) => {
25
+ const a = o.listen(e.port, () => {
26
+ const l = a.address();
27
+ l === null || typeof l == "string" ? r(new Error("Server address is not available")) : n(a);
28
28
  });
29
29
  });
30
- o.use("/", async (n, s) => {
31
- let l;
30
+ o.use("/", async (n, r) => {
31
+ let a;
32
32
  try {
33
- l = await e.handleRequest({
33
+ a = await e.handleRequest({
34
34
  url: n.url,
35
- headers: Ve(n),
35
+ headers: _e(n),
36
36
  method: n.method,
37
- body: await Ne(n)
37
+ body: await Oe(n)
38
38
  });
39
- } catch (a) {
40
- m.error(a), l = U.forHttpCode(500);
39
+ } catch (l) {
40
+ h.error(l), a = V.forHttpCode(500);
41
41
  }
42
- s.statusCode = l.httpStatusCode;
43
- for (const a in l.headers)
44
- s.setHeader(a, l.headers[a]);
45
- s.end(l.bytes);
42
+ r.statusCode = a.httpStatusCode;
43
+ for (const l in a.headers)
44
+ r.setHeader(l, a.headers[l]);
45
+ r.end(a.bytes);
46
46
  });
47
- const r = t.address().port;
48
- return await e.onBind(t, r);
47
+ const s = t.address().port;
48
+ return await e.onBind(t, s);
49
49
  }
50
- const Ne = async (e) => await new Promise((o) => {
50
+ const Oe = async (e) => await new Promise((o) => {
51
51
  const t = [];
52
52
  e.on("data", (i) => {
53
53
  t.push(i);
54
54
  }), e.on("end", () => {
55
55
  o(new Uint8Array(Buffer.concat(t)));
56
56
  });
57
- }), Ve = (e) => {
57
+ }), _e = (e) => {
58
58
  const o = {};
59
59
  if (e.rawHeaders && e.rawHeaders.length)
60
60
  for (let t = 0; t < e.rawHeaders.length; t += 2)
61
61
  o[e.rawHeaders[t].toLowerCase()] = e.rawHeaders[t + 1];
62
62
  return o;
63
63
  };
64
- class Oe {
64
+ class He {
65
65
  constructor(o) {
66
66
  this.workerLoads = [], this.addWorker(o);
67
67
  }
@@ -73,8 +73,8 @@ class Oe {
73
73
  }
74
74
  async handleRequest(o) {
75
75
  let t = this.workerLoads[0];
76
- for (let r = 1; r < this.workerLoads.length; r++) {
77
- const n = this.workerLoads[r];
76
+ for (let s = 1; s < this.workerLoads.length; s++) {
77
+ const n = this.workerLoads[s];
78
78
  n.activeRequests.size < t.activeRequests.size && (t = n);
79
79
  }
80
80
  const i = t.worker.request(o);
@@ -83,17 +83,17 @@ class Oe {
83
83
  });
84
84
  }
85
85
  }
86
- function _e(e) {
86
+ function qe(e) {
87
87
  return /^latest$|^trunk$|^nightly$|^(?:(\d+)\.(\d+)(?:\.(\d+))?)((?:-beta(?:\d+)?)|(?:-RC(?:\d+)?))?$/.test(e);
88
88
  }
89
- async function He({
89
+ async function ze({
90
90
  sourceString: e,
91
91
  blueprintMayReadAdjacentFiles: o
92
92
  }) {
93
93
  if (!e)
94
94
  return;
95
95
  if (e.startsWith("http://") || e.startsWith("https://"))
96
- return await fe(e);
96
+ return await he(e);
97
97
  let t = g.resolve(process.cwd(), e);
98
98
  if (!u.existsSync(t))
99
99
  throw new Error(`Blueprint file does not exist: ${t}`);
@@ -102,10 +102,10 @@ async function He({
102
102
  throw new Error(
103
103
  `Blueprint path is neither a file nor a directory: ${t}`
104
104
  );
105
- const r = g.extname(t);
106
- switch (r) {
105
+ const s = g.extname(t);
106
+ switch (s) {
107
107
  case ".zip":
108
- return Te.fromArrayBuffer(
108
+ return je.fromArrayBuffer(
109
109
  u.readFileSync(t).buffer
110
110
  );
111
111
  case ".json": {
@@ -117,9 +117,9 @@ async function He({
117
117
  `Blueprint file at ${t} is not a valid JSON file`
118
118
  );
119
119
  }
120
- const s = g.dirname(t), l = new Le(s);
121
- return new We([
122
- new $e({
120
+ const r = g.dirname(t), a = new We(r);
121
+ return new Te([
122
+ new Be({
123
123
  "blueprint.json": n
124
124
  }),
125
125
  /**
@@ -127,25 +127,25 @@ async function He({
127
127
  * unless the user explicitly allowed it.
128
128
  */
129
129
  {
130
- read(a) {
130
+ read(l) {
131
131
  if (!o)
132
132
  throw new Error(
133
- `Error: Blueprint contained tried to read a local file at path "${a}" (via a resource of type "bundled"). Playground restricts access to local resources by default as a security measure.
133
+ `Error: Blueprint contained tried to read a local file at path "${l}" (via a resource of type "bundled"). Playground restricts access to local resources by default as a security measure.
134
134
 
135
135
  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.`
136
136
  );
137
- return l.read(a);
137
+ return a.read(l);
138
138
  }
139
139
  }
140
140
  ]);
141
141
  }
142
142
  default:
143
143
  throw new Error(
144
- `Unsupported blueprint file extension: ${r}. Only .zip and .json files are supported.`
144
+ `Unsupported blueprint file extension: ${s}. Only .zip and .json files are supported.`
145
145
  );
146
146
  }
147
147
  }
148
- class qe {
148
+ class Xe {
149
149
  constructor(o, t) {
150
150
  this.lastProgressMessage = "", this.args = o, this.siteUrl = t.siteUrl, this.processIdSpaceLength = t.processIdSpaceLength, this.phpVersion = o.php;
151
151
  }
@@ -153,8 +153,8 @@ class qe {
153
153
  return "v2";
154
154
  }
155
155
  async bootPrimaryWorker(o, t, i) {
156
- const r = j(o);
157
- await r.useFileLockManager(t);
156
+ const s = j(o);
157
+ await s.useFileLockManager(t);
158
158
  const n = {
159
159
  ...this.args,
160
160
  phpVersion: this.phpVersion,
@@ -167,17 +167,17 @@ class qe {
167
167
  xdebug: typeof this.args.xdebug == "object" ? this.args.xdebug : void 0,
168
168
  nativeInternalDirPath: i
169
169
  };
170
- return await r.bootAsPrimaryWorker(n), r;
170
+ return await s.bootAsPrimaryWorker(n), s;
171
171
  }
172
172
  async bootSecondaryWorker({
173
173
  worker: o,
174
174
  fileLockManagerPort: t,
175
175
  firstProcessId: i,
176
- nativeInternalDirPath: r
176
+ nativeInternalDirPath: s
177
177
  }) {
178
178
  const n = j(o.phpPort);
179
179
  await n.useFileLockManager(t);
180
- const s = {
180
+ const r = {
181
181
  ...this.args,
182
182
  phpVersion: this.phpVersion,
183
183
  siteUrl: this.siteUrl,
@@ -185,11 +185,11 @@ class qe {
185
185
  processIdSpaceLength: this.processIdSpaceLength,
186
186
  trace: this.args.debug || !1,
187
187
  withXdebug: !!this.args.xdebug,
188
- nativeInternalDirPath: r,
188
+ nativeInternalDirPath: s,
189
189
  mountsBeforeWpInstall: this.args["mount-before-install"] || [],
190
190
  mountsAfterWpInstall: this.args.mount || []
191
191
  };
192
- return await n.bootAsSecondaryWorker(s), n;
192
+ return await n.bootAsSecondaryWorker(r), n;
193
193
  }
194
194
  writeProgressUpdate(o, t, i) {
195
195
  t !== this.lastProgressMessage && (this.lastProgressMessage = t, o.isTTY ? (o.cursorTo(0), o.write(t), o.clearLine(1), i && o.write(`
@@ -197,37 +197,37 @@ class qe {
197
197
  `));
198
198
  }
199
199
  }
200
- const N = g.join(Y.homedir(), ".wordpress-playground");
201
- async function ze(e) {
202
- return await G(
200
+ const O = g.join(K.homedir(), ".wordpress-playground");
201
+ async function Je(e) {
202
+ return await te(
203
203
  "https://github.com/WordPress/sqlite-database-integration/archive/refs/heads/develop.zip",
204
204
  "sqlite.zip",
205
205
  e
206
206
  );
207
207
  }
208
- async function G(e, o, t) {
209
- const i = g.join(N, o);
210
- return T.existsSync(i) || (T.ensureDirSync(N), await Xe(e, i, t)), ee(i);
208
+ async function te(e, o, t) {
209
+ const i = g.join(O, o);
210
+ return $.existsSync(i) || ($.ensureDirSync(O), await Ze(e, i, t)), oe(i);
211
211
  }
212
- async function Xe(e, o, t) {
213
- const r = (await t.monitorFetch(fetch(e))).body.getReader(), n = `${o}.partial`, s = T.createWriteStream(n);
212
+ async function Ze(e, o, t) {
213
+ const s = (await t.monitorFetch(fetch(e))).body.getReader(), n = `${o}.partial`, r = $.createWriteStream(n);
214
214
  for (; ; ) {
215
- const { done: l, value: a } = await r.read();
216
- if (a && s.write(a), l)
215
+ const { done: a, value: l } = await s.read();
216
+ if (l && r.write(l), a)
217
217
  break;
218
218
  }
219
- s.close(), s.closed || await new Promise((l, a) => {
220
- s.on("finish", () => {
221
- T.renameSync(n, o), l(null);
222
- }), s.on("error", (p) => {
223
- T.removeSync(n), a(p);
219
+ r.close(), r.closed || await new Promise((a, l) => {
220
+ r.on("finish", () => {
221
+ $.renameSync(n, o), a(null);
222
+ }), r.on("error", (p) => {
223
+ $.removeSync(n), l(p);
224
224
  });
225
225
  });
226
226
  }
227
- function ee(e, o) {
228
- return new File([T.readFileSync(e)], Ce(e));
227
+ function oe(e, o) {
228
+ return new File([$.readFileSync(e)], $e(e));
229
229
  }
230
- class Je {
230
+ class Ye {
231
231
  constructor(o, t) {
232
232
  this.lastProgressMessage = "", this.args = o, this.siteUrl = t.siteUrl, this.processIdSpaceLength = t.processIdSpaceLength;
233
233
  }
@@ -235,47 +235,47 @@ class Je {
235
235
  return "v1";
236
236
  }
237
237
  async bootPrimaryWorker(o, t, i) {
238
- let r;
239
- const n = new Be();
238
+ let s;
239
+ const n = new Re();
240
240
  if (!this.args.skipWordPressSetup) {
241
- let C = !1;
242
- n.addEventListener("progress", (x) => {
243
- if (C)
241
+ let I = !1;
242
+ n.addEventListener("progress", (k) => {
243
+ if (I)
244
244
  return;
245
- const { loaded: k, total: f } = x.detail, B = Math.floor(
246
- Math.min(100, 100 * k / f)
245
+ const { loaded: x, total: f } = k.detail, W = Math.floor(
246
+ Math.min(100, 100 * x / f)
247
247
  );
248
- C = B === 100, this.writeProgressUpdate(
248
+ I = W === 100, this.writeProgressUpdate(
249
249
  process.stdout,
250
- `Downloading WordPress ${B}%...`,
251
- C
250
+ `Downloading WordPress ${W}%...`,
251
+ I
252
252
  );
253
- }), r = await Fe(this.args.wp), m.log(
254
- `Resolved WordPress release URL: ${r?.releaseUrl}`
253
+ }), s = await Me(this.args.wp), h.log(
254
+ `Resolved WordPress release URL: ${s?.releaseUrl}`
255
255
  );
256
256
  }
257
- const s = r && g.join(
258
- N,
259
- `prebuilt-wp-content-for-wp-${r.version}.zip`
260
- ), l = r ? u.existsSync(s) ? ee(s) : await G(
261
- r.releaseUrl,
262
- `${r.version}.zip`,
257
+ const r = s && g.join(
258
+ O,
259
+ `prebuilt-wp-content-for-wp-${s.version}.zip`
260
+ ), a = s ? u.existsSync(r) ? oe(r) : await te(
261
+ s.releaseUrl,
262
+ `${s.version}.zip`,
263
263
  n
264
264
  ) : void 0;
265
- m.log("Fetching SQLite integration plugin...");
266
- const a = this.args.skipSqliteSetup ? void 0 : await ze(n), p = this.args.followSymlinks === !0, c = this.args.experimentalTrace === !0, d = this.args["mount-before-install"] || [], h = this.args.mount || [], w = j(o);
267
- await w.isConnected(), m.log("Booting WordPress...");
268
- const b = await me(
265
+ h.log("Fetching SQLite integration plugin...");
266
+ const l = this.args.skipSqliteSetup ? void 0 : await Je(n), p = this.args.followSymlinks === !0, c = this.args.experimentalTrace === !0, d = this.args["mount-before-install"] || [], m = this.args.mount || [], b = j(o);
267
+ await b.isConnected(), h.log("Booting WordPress...");
268
+ const v = await ge(
269
269
  this.getEffectiveBlueprint()
270
270
  );
271
- return await w.useFileLockManager(t), await w.bootAsPrimaryWorker({
272
- phpVersion: b.phpVersion,
273
- wpVersion: b.wpVersion,
271
+ return await b.useFileLockManager(t), await b.bootAsPrimaryWorker({
272
+ phpVersion: v.phpVersion,
273
+ wpVersion: v.wpVersion,
274
274
  siteUrl: this.siteUrl,
275
275
  mountsBeforeWpInstall: d,
276
- mountsAfterWpInstall: h,
277
- wordPressZip: l && await l.arrayBuffer(),
278
- sqliteIntegrationPluginZip: await a?.arrayBuffer(),
276
+ mountsAfterWpInstall: m,
277
+ wordPressZip: a && await a.arrayBuffer(),
278
+ sqliteIntegrationPluginZip: await l?.arrayBuffer(),
279
279
  firstProcessId: 0,
280
280
  processIdSpaceLength: this.processIdSpaceLength,
281
281
  followSymlinks: p,
@@ -283,16 +283,16 @@ class Je {
283
283
  internalCookieStore: this.args.internalCookieStore,
284
284
  withXdebug: !!this.args.xdebug,
285
285
  nativeInternalDirPath: i
286
- }), r && !this.args["mount-before-install"] && !u.existsSync(s) && (m.log("Caching preinstalled WordPress for the next boot..."), u.writeFileSync(
287
- s,
288
- await we(w, "/wordpress")
289
- ), m.log("Cached!")), w;
286
+ }), s && !this.args["mount-before-install"] && !u.existsSync(r) && (h.log("Caching preinstalled WordPress for the next boot..."), u.writeFileSync(
287
+ r,
288
+ await ve(b, "/wordpress")
289
+ ), h.log("Cached!")), b;
290
290
  }
291
291
  async bootSecondaryWorker({
292
292
  worker: o,
293
293
  fileLockManagerPort: t,
294
294
  firstProcessId: i,
295
- nativeInternalDirPath: r
295
+ nativeInternalDirPath: s
296
296
  }) {
297
297
  const n = j(
298
298
  o.phpPort
@@ -310,49 +310,49 @@ class Je {
310
310
  // will have a separate cookie store.
311
311
  internalCookieStore: this.args.internalCookieStore,
312
312
  withXdebug: !!this.args.xdebug,
313
- nativeInternalDirPath: r
313
+ nativeInternalDirPath: s
314
314
  }), await n.isReady(), n;
315
315
  }
316
316
  async compileInputBlueprint(o) {
317
- const t = this.getEffectiveBlueprint(), i = new je();
318
- let r = "", n = !1;
319
- return i.addEventListener("progress", (s) => {
317
+ const t = this.getEffectiveBlueprint(), i = new Fe();
318
+ let s = "", n = !1;
319
+ return i.addEventListener("progress", (r) => {
320
320
  if (n)
321
321
  return;
322
- n = s.detail.progress === 100;
323
- const l = Math.floor(s.detail.progress);
324
- r = s.detail.caption || r || "Running the Blueprint";
325
- const a = `${r.trim()} – ${l}%`;
322
+ n = r.detail.progress === 100;
323
+ const a = Math.floor(r.detail.progress);
324
+ s = r.detail.caption || s || "Running the Blueprint";
325
+ const l = `${s.trim()} – ${a}%`;
326
326
  this.writeProgressUpdate(
327
327
  process.stdout,
328
- a,
328
+ l,
329
329
  n
330
330
  );
331
- }), await he(t, {
331
+ }), await ye(t, {
332
332
  progress: i,
333
333
  additionalSteps: o
334
334
  });
335
335
  }
336
336
  getEffectiveBlueprint() {
337
337
  const o = this.args.blueprint;
338
- return ge(o) ? o : {
338
+ return we(o) ? o : {
339
339
  login: this.args.login,
340
340
  ...o || {},
341
341
  preferredVersions: {
342
- php: this.args.php ?? o?.preferredVersions?.php ?? Z,
342
+ php: this.args.php ?? o?.preferredVersions?.php ?? G,
343
343
  wp: this.args.wp ?? o?.preferredVersions?.wp ?? "latest",
344
344
  ...o?.preferredVersions || {}
345
345
  }
346
346
  };
347
347
  }
348
348
  writeProgressUpdate(o, t, i) {
349
- this.args.verbosity !== V.Quiet.name && t !== this.lastProgressMessage && (this.lastProgressMessage = t, o.isTTY ? (o.cursorTo(0), o.write(t), o.clearLine(1), i && o.write(`
349
+ this.args.verbosity !== _.Quiet.name && t !== this.lastProgressMessage && (this.lastProgressMessage = t, o.isTTY ? (o.cursorTo(0), o.write(t), o.clearLine(1), i && o.write(`
350
350
  `)) : o.write(`${t}
351
351
  `));
352
352
  }
353
353
  }
354
- async function Ze(e, o = !0) {
355
- const i = `${g.basename(process.argv0)}${e}${process.pid}-`, r = (await Me({
354
+ async function Ge(e, o = !0) {
355
+ const i = `${g.basename(process.argv0)}${e}${process.pid}-`, s = await Ae({
356
356
  prefix: i,
357
357
  /*
358
358
  * Allow recursive cleanup on process exit.
@@ -363,81 +363,81 @@ async function Ze(e, o = !0) {
363
363
  * https://github.com/raszi/node-tmp/blob/3d2fe387f3f91b13830b9182faa02c3231ea8258/lib/tmp.js#L318
364
364
  */
365
365
  unsafeCleanup: !0
366
- })).path;
367
- return o && De(), r;
366
+ });
367
+ return o && Ue(), s;
368
368
  }
369
- async function Ye(e, o, t) {
370
- const r = (await Ke(
369
+ async function Ke(e, o, t) {
370
+ const s = (await Qe(
371
371
  e,
372
372
  o,
373
373
  t
374
374
  )).map(
375
- (n) => new Promise((s) => {
376
- u.rm(n, { recursive: !0 }, (l) => {
377
- l ? m.warn(
375
+ (n) => new Promise((r) => {
376
+ u.rm(n, { recursive: !0 }, (a) => {
377
+ a ? h.warn(
378
378
  `Failed to delete stale Playground temp dir: ${n}`,
379
- l
380
- ) : m.info(
379
+ a
380
+ ) : h.info(
381
381
  `Deleted stale Playground temp dir: ${n}`
382
- ), s();
382
+ ), r();
383
383
  });
384
384
  })
385
385
  );
386
- await Promise.all(r);
386
+ await Promise.all(s);
387
387
  }
388
- async function Ke(e, o, t) {
388
+ async function Qe(e, o, t) {
389
389
  try {
390
- const i = u.readdirSync(t).map((n) => g.join(t, n)), r = [];
390
+ const i = u.readdirSync(t).map((n) => g.join(t, n)), s = [];
391
391
  for (const n of i)
392
- await Qe(
392
+ await et(
393
393
  e,
394
394
  o,
395
395
  n
396
- ) && r.push(n);
397
- return r;
396
+ ) && s.push(n);
397
+ return s;
398
398
  } catch (i) {
399
- return m.warn(`Failed to find stale Playground temp dirs: ${i}`), [];
399
+ return h.warn(`Failed to find stale Playground temp dirs: ${i}`), [];
400
400
  }
401
401
  }
402
- async function Qe(e, o, t) {
402
+ async function et(e, o, t) {
403
403
  if (!u.lstatSync(t).isDirectory())
404
404
  return !1;
405
- const r = g.basename(t);
406
- if (!r.includes(e))
405
+ const s = g.basename(t);
406
+ if (!s.includes(e))
407
407
  return !1;
408
- const n = r.match(
408
+ const n = s.match(
409
409
  new RegExp(`^(.+)${e}(\\d+)-`)
410
410
  );
411
411
  if (!n)
412
412
  return !1;
413
- const s = {
413
+ const r = {
414
414
  executableName: n[1],
415
415
  pid: n[2]
416
416
  };
417
- if (await Ge(s.pid, s.executableName))
417
+ if (await tt(r.pid, r.executableName))
418
418
  return !1;
419
- const l = Date.now() - o;
420
- return u.statSync(t).mtime.getTime() < l;
419
+ const a = Date.now() - o;
420
+ return u.statSync(t).mtime.getTime() < a;
421
421
  }
422
- async function Ge(e, o) {
422
+ async function tt(e, o) {
423
423
  const [t] = await new Promise(
424
- (i, r) => {
425
- Ae.list(
424
+ (i, s) => {
425
+ Ne.list(
426
426
  {
427
427
  pid: e,
428
428
  name: o,
429
429
  // Remove path from executable name in the results.
430
430
  clean: !0
431
431
  },
432
- (n, s) => {
433
- n ? r(n) : i(s);
432
+ (n, r) => {
433
+ n ? s(n) : i(r);
434
434
  }
435
435
  );
436
436
  }
437
437
  );
438
438
  return !!t && t.pid === e && t.command === o;
439
439
  }
440
- async function et(e, o, t) {
440
+ async function ot(e, o, t) {
441
441
  const i = t === "win32" ? (
442
442
  // On Windows, creating a 'dir' symlink can require elevated permissions.
443
443
  // In this case, let's make junction points because they function like
@@ -446,23 +446,23 @@ async function et(e, o, t) {
446
446
  ) : "dir";
447
447
  u.symlinkSync(e, o, i);
448
448
  }
449
- async function tt(e) {
449
+ async function rt(e) {
450
450
  try {
451
451
  u.lstatSync(e).isSymbolicLink() && u.unlinkSync(e);
452
452
  } catch {
453
453
  }
454
454
  }
455
- function ot(e, o) {
455
+ function nt(e, o) {
456
456
  return o.filter((t) => {
457
- const i = g.resolve(t.hostPath), r = g.join(e, g.sep);
457
+ const i = g.resolve(t.hostPath), s = g.join(e, g.sep);
458
458
  return (
459
459
  // If auto-mounting from the current directory,
460
460
  // the entire project directory can be mapped.
461
- i === e || i.startsWith(r)
461
+ i === e || i.startsWith(s)
462
462
  );
463
463
  });
464
464
  }
465
- const I = {
465
+ const E = {
466
466
  ignoreAttributes: !1,
467
467
  attributeNamePrefix: "",
468
468
  preserveOrder: !0,
@@ -470,23 +470,23 @@ const I = {
470
470
  commentPropName: "__xmlComment",
471
471
  allowBooleanAttributes: !0,
472
472
  trimValues: !0
473
- }, te = {
474
- ignoreAttributes: I.ignoreAttributes,
475
- attributeNamePrefix: I.attributeNamePrefix,
476
- preserveOrder: I.preserveOrder,
477
- cdataPropName: I.cdataPropName,
478
- commentPropName: I.commentPropName,
479
- suppressBooleanAttributes: !I.allowBooleanAttributes,
473
+ }, re = {
474
+ ignoreAttributes: E.ignoreAttributes,
475
+ attributeNamePrefix: E.attributeNamePrefix,
476
+ preserveOrder: E.preserveOrder,
477
+ cdataPropName: E.cdataPropName,
478
+ commentPropName: E.commentPropName,
479
+ suppressBooleanAttributes: !E.allowBooleanAttributes,
480
480
  format: !0,
481
481
  indentBy: " "
482
- }, F = {
482
+ }, R = {
483
483
  allowEmptyContent: !0,
484
484
  allowTrailingComma: !0
485
485
  };
486
- function rt(e, o) {
487
- const { name: t, host: i, port: r, mappings: n, ideKey: s } = o, l = new K(I), a = (() => {
486
+ function it(e, o) {
487
+ const { name: t, host: i, port: s, mappings: n, ideKey: r } = o, a = new Q(E), l = (() => {
488
488
  try {
489
- return l.parse(e, !0);
489
+ return a.parse(e, !0);
490
490
  } catch {
491
491
  throw new Error("PhpStorm configuration file is not valid XML.");
492
492
  }
@@ -510,11 +510,11 @@ function rt(e, o) {
510
510
  // NOTE: PhpStorm quirk: Xdebug only works when the full URL (including port)
511
511
  // is provided in `host`. The separate `port` field is ignored or misinterpreted,
512
512
  // so we rely solely on host: "host:port".
513
- host: `${i}:${r}`,
513
+ host: `${i}:${s}`,
514
514
  use_path_mappings: "true"
515
515
  }
516
516
  };
517
- let c = a?.find((f) => !!f?.project);
517
+ let c = l?.find((f) => !!f?.project);
518
518
  if (c) {
519
519
  const f = c[":@"]?.version;
520
520
  if (f === void 0)
@@ -529,7 +529,7 @@ function rt(e, o) {
529
529
  c === void 0 && (c = {
530
530
  project: [],
531
531
  ":@": { version: "4" }
532
- }, a.push(c));
532
+ }, l.push(c));
533
533
  let d = c.project?.find(
534
534
  (f) => !!f?.component && f?.[":@"]?.name === "PhpServers"
535
535
  );
@@ -537,21 +537,21 @@ function rt(e, o) {
537
537
  component: [],
538
538
  ":@": { name: "PhpServers" }
539
539
  }, c.project === void 0 && (c.project = []), c.project.push(d));
540
- let h = d.component?.find(
540
+ let m = d.component?.find(
541
541
  (f) => !!f?.servers
542
542
  );
543
- h === void 0 && (h = { servers: [] }, d.component === void 0 && (d.component = []), d.component.push(h));
544
- const w = h.servers?.findIndex(
543
+ m === void 0 && (m = { servers: [] }, d.component === void 0 && (d.component = []), d.component.push(m));
544
+ const b = m.servers?.findIndex(
545
545
  (f) => !!f?.server && f?.[":@"]?.name === t
546
546
  );
547
- (w === void 0 || w < 0) && (h.servers === void 0 && (h.servers = []), h.servers.push(p));
548
- let b = c.project?.find(
547
+ (b === void 0 || b < 0) && (m.servers === void 0 && (m.servers = []), m.servers.push(p));
548
+ let v = c.project?.find(
549
549
  (f) => !!f?.component && f?.[":@"]?.name === "RunManager"
550
550
  );
551
- if (b === void 0 && (b = {
551
+ if (v === void 0 && (v = {
552
552
  component: [],
553
553
  ":@": { name: "RunManager" }
554
- }, c.project === void 0 && (c.project = []), c.project.push(b)), (b.component?.findIndex(
554
+ }, c.project === void 0 && (c.project = []), c.project.push(v)), (v.component?.findIndex(
555
555
  (f) => !!f?.configuration && f?.[":@"]?.name === t
556
556
  ) ?? -1) < 0) {
557
557
  const f = {
@@ -567,47 +567,47 @@ function rt(e, o) {
567
567
  factoryName: "PHP Remote Debug",
568
568
  filter_connections: "FILTER",
569
569
  server_name: t,
570
- session_id: s
570
+ session_id: r
571
571
  }
572
572
  };
573
- b.component === void 0 && (b.component = []), b.component.push(f);
573
+ v.component === void 0 && (v.component = []), v.component.push(f);
574
574
  }
575
- const k = new Q(te).build(a);
575
+ const x = new ee(re).build(l);
576
576
  try {
577
- l.parse(k, !0);
577
+ a.parse(x, !0);
578
578
  } catch {
579
579
  throw new Error(
580
580
  "The resulting PhpStorm configuration file is not valid XML."
581
581
  );
582
582
  }
583
- return k;
583
+ return x;
584
584
  }
585
- function nt(e, o) {
586
- const { name: t, mappings: i } = o, r = [];
587
- let n = e, s = v.parseTree(n, r, F);
588
- if (s === void 0 || r.length)
585
+ function st(e, o) {
586
+ const { name: t, mappings: i } = o, s = [];
587
+ let n = e, r = P.parseTree(n, s, R);
588
+ if (r === void 0 || s.length)
589
589
  throw new Error("VS Code configuration file is not valid JSON.");
590
- let l = v.findNodeAtLocation(s, ["configurations"]);
591
- if (l === void 0 || l.children === void 0) {
592
- const p = v.modify(n, ["configurations"], [], {});
593
- n = v.applyEdits(n, p), s = v.parseTree(n, [], F), l = v.findNodeAtLocation(s, [
590
+ let a = P.findNodeAtLocation(r, ["configurations"]);
591
+ if (a === void 0 || a.children === void 0) {
592
+ const p = P.modify(n, ["configurations"], [], {});
593
+ n = P.applyEdits(n, p), r = P.parseTree(n, [], R), a = P.findNodeAtLocation(r, [
594
594
  "configurations"
595
595
  ]);
596
596
  }
597
- const a = l?.children?.findIndex(
598
- (p) => v.findNodeAtLocation(p, ["name"])?.value === t
597
+ const l = a?.children?.findIndex(
598
+ (p) => P.findNodeAtLocation(p, ["name"])?.value === t
599
599
  );
600
- if (a === void 0 || a < 0) {
600
+ if (l === void 0 || l < 0) {
601
601
  const p = {
602
602
  name: t,
603
603
  type: "php",
604
604
  request: "launch",
605
605
  port: 9003,
606
- pathMappings: i.reduce((h, w) => (h[w.vfsPath] = `\${workspaceFolder}/${w.hostPath.replace(
606
+ pathMappings: i.reduce((m, b) => (m[b.vfsPath] = `\${workspaceFolder}/${b.hostPath.replace(
607
607
  /^\.\/?/,
608
608
  ""
609
- )}`, h), {})
610
- }, c = l?.children?.length || 0, d = v.modify(
609
+ )}`, m), {})
610
+ }, c = a?.children?.length || 0, d = P.modify(
611
611
  n,
612
612
  ["configurations", c],
613
613
  p,
@@ -620,23 +620,23 @@ function nt(e, o) {
620
620
  }
621
621
  }
622
622
  );
623
- n = oe(n, d);
623
+ n = ne(n, d);
624
624
  }
625
625
  return n;
626
626
  }
627
- async function it({
627
+ async function at({
628
628
  name: e,
629
629
  ides: o,
630
630
  host: t,
631
631
  port: i,
632
- cwd: r,
632
+ cwd: s,
633
633
  mounts: n,
634
- ideKey: s = "PLAYGROUNDCLI"
634
+ ideKey: r = "PLAYGROUNDCLI"
635
635
  }) {
636
- const l = ot(r, n), a = [];
636
+ const a = nt(s, n), l = [];
637
637
  if (o.includes("phpstorm")) {
638
638
  const p = ".idea/workspace.xml", c = g.join(
639
- r,
639
+ s,
640
640
  p
641
641
  );
642
642
  if (!u.existsSync(c)) {
@@ -653,20 +653,20 @@ async function it({
653
653
  );
654
654
  }
655
655
  if (u.existsSync(c)) {
656
- const d = u.readFileSync(c, "utf8"), h = rt(d, {
656
+ const d = u.readFileSync(c, "utf8"), m = it(d, {
657
657
  name: e,
658
658
  host: t,
659
659
  port: i,
660
- mappings: l,
661
- ideKey: s
660
+ mappings: a,
661
+ ideKey: r
662
662
  });
663
- u.writeFileSync(c, h);
663
+ u.writeFileSync(c, m);
664
664
  }
665
- a.push(p);
665
+ l.push(p);
666
666
  }
667
667
  if (o.includes("vscode")) {
668
668
  const p = ".vscode/launch.json", c = g.join(
669
- r,
669
+ s,
670
670
  p
671
671
  );
672
672
  if (!u.existsSync(c)) {
@@ -683,27 +683,27 @@ async function it({
683
683
  );
684
684
  }
685
685
  if (u.existsSync(c)) {
686
- const d = u.readFileSync(c, "utf-8"), h = nt(d, {
686
+ const d = u.readFileSync(c, "utf-8"), m = st(d, {
687
687
  name: e,
688
- mappings: l
688
+ mappings: a
689
689
  });
690
- h !== d && (u.writeFileSync(c, h), a.push(p));
690
+ m !== d && (u.writeFileSync(c, m), l.push(p));
691
691
  }
692
692
  }
693
- return a;
693
+ return l;
694
694
  }
695
- async function st(e, o) {
695
+ async function lt(e, o) {
696
696
  const t = g.join(o, ".idea/workspace.xml");
697
697
  if (u.existsSync(t)) {
698
- const r = u.readFileSync(t, "utf8"), n = new K(I), s = (() => {
698
+ const s = u.readFileSync(t, "utf8"), n = new Q(E), r = (() => {
699
699
  try {
700
- return n.parse(r, !0);
700
+ return n.parse(s, !0);
701
701
  } catch {
702
702
  throw new Error(
703
703
  "PhpStorm configuration file is not valid XML."
704
704
  );
705
705
  }
706
- })(), p = s.find(
706
+ })(), p = r.find(
707
707
  (d) => !!d?.project
708
708
  )?.project?.find(
709
709
  (d) => !!d?.component && d?.[":@"]?.name === "PhpServers"
@@ -714,36 +714,36 @@ async function st(e, o) {
714
714
  );
715
715
  if (c !== void 0 && c >= 0) {
716
716
  p.servers.splice(c, 1);
717
- const h = new Q(te).build(s);
717
+ const m = new ee(re).build(r);
718
718
  try {
719
- n.parse(h, !0);
719
+ n.parse(m, !0);
720
720
  } catch {
721
721
  throw new Error(
722
722
  "The resulting PhpStorm configuration file is not valid XML."
723
723
  );
724
724
  }
725
- h === `<?xml version="1.0" encoding="UTF-8"?>
725
+ m === `<?xml version="1.0" encoding="UTF-8"?>
726
726
  <project version="4">
727
727
  <component name="PhpServers">
728
728
  <servers></servers>
729
729
  </component>
730
- </project>` ? u.unlinkSync(t) : u.writeFileSync(t, h);
730
+ </project>` ? u.unlinkSync(t) : u.writeFileSync(t, m);
731
731
  }
732
732
  }
733
733
  const i = g.join(o, ".vscode/launch.json");
734
734
  if (u.existsSync(i)) {
735
- const r = [], n = u.readFileSync(i, "utf-8"), s = v.parseTree(n, r, F);
736
- if (s === void 0 || r.length)
735
+ const s = [], n = u.readFileSync(i, "utf-8"), r = P.parseTree(n, s, R);
736
+ if (r === void 0 || s.length)
737
737
  throw new Error("VS Code configuration file is not valid JSON.");
738
- const a = v.findNodeAtLocation(s, [
738
+ const l = P.findNodeAtLocation(r, [
739
739
  "configurations"
740
740
  ])?.children?.findIndex(
741
- (p) => v.findNodeAtLocation(p, ["name"])?.value === e
741
+ (p) => P.findNodeAtLocation(p, ["name"])?.value === e
742
742
  );
743
- if (a !== void 0 && a >= 0) {
744
- const p = v.modify(
743
+ if (l !== void 0 && l >= 0) {
744
+ const p = P.modify(
745
745
  n,
746
- ["configurations", a],
746
+ ["configurations", l],
747
747
  void 0,
748
748
  {
749
749
  formattingOptions: {
@@ -753,28 +753,28 @@ async function st(e, o) {
753
753
  `
754
754
  }
755
755
  }
756
- ), c = oe(n, p);
756
+ ), c = ne(n, p);
757
757
  c === `{
758
758
  "configurations": []
759
759
  }` ? u.unlinkSync(i) : u.writeFileSync(i, c);
760
760
  }
761
761
  }
762
762
  }
763
- function oe(e, o) {
764
- const t = [], i = v.applyEdits(e, o);
765
- if (t.length = 0, v.parseTree(i, t, F), t.length) {
766
- const r = t.map((s) => ({
767
- message: v.printParseErrorCode(s.error),
768
- offset: s.offset,
769
- length: s.length,
763
+ function ne(e, o) {
764
+ const t = [], i = P.applyEdits(e, o);
765
+ if (t.length = 0, P.parseTree(i, t, R), t.length) {
766
+ const s = t.map((r) => ({
767
+ message: P.printParseErrorCode(r.error),
768
+ offset: r.offset,
769
+ length: r.length,
770
770
  fragment: i.slice(
771
- Math.max(0, s.offset - 20),
772
- Math.min(i.length, s.offset + s.length + 10)
771
+ Math.max(0, r.offset - 20),
772
+ Math.min(i.length, r.offset + r.length + 10)
773
773
  )
774
774
  })).map(
775
- (s) => `${s.message} at ${s.offset}:${s.length} (${s.fragment})`
775
+ (r) => `${r.message} at ${r.offset}:${r.length} (${r.fragment})`
776
776
  ), n = o.map(
777
- (s) => `At ${s.offset}:${s.length} - (${s.content})`
777
+ (r) => `At ${r.offset}:${r.length} - (${r.content})`
778
778
  );
779
779
  throw new Error(
780
780
  `VS Code configuration file (.vscode/launch.json) is not valid a JSONC after Playground CLI modifications. This is likely a Playground CLI bug. Please report it at https://github.com/WordPress/wordpress-playground/issues and include the contents of your ".vscode/launch.json" file.
@@ -784,20 +784,20 @@ function oe(e, o) {
784
784
  `
785
785
  )}
786
786
 
787
- The errors are: ${r.join(`
787
+ The errors are: ${s.join(`
788
788
  `)}`
789
789
  );
790
790
  }
791
791
  return i;
792
792
  }
793
- const V = {
794
- Quiet: { name: "quiet", severity: M.Fatal },
795
- Normal: { name: "normal", severity: M.Info },
796
- Debug: { name: "debug", severity: M.Debug }
793
+ const _ = {
794
+ Quiet: { name: "quiet", severity: A.Fatal },
795
+ Normal: { name: "normal", severity: A.Info },
796
+ Debug: { name: "debug", severity: A.Debug }
797
797
  };
798
- async function Rt() {
798
+ async function Dt() {
799
799
  try {
800
- const e = Ie(process.argv.slice(2)).usage("Usage: wp-playground <command> [options]").positional("command", {
800
+ const e = Le(process.argv.slice(2)).usage("Usage: wp-playground <command> [options]").positional("command", {
801
801
  describe: "Command to run",
802
802
  choices: ["server", "run-blueprint", "build-snapshot"],
803
803
  demandOption: !0
@@ -815,8 +815,8 @@ async function Rt() {
815
815
  }).option("php", {
816
816
  describe: "PHP version to use.",
817
817
  type: "string",
818
- default: Z,
819
- choices: ce
818
+ default: G,
819
+ choices: ue
820
820
  }).option("wp", {
821
821
  describe: "WordPress version to use.",
822
822
  type: "string",
@@ -825,12 +825,12 @@ async function Rt() {
825
825
  describe: "Mount a directory to the PHP runtime (can be used multiple times). Format: /host/path:/vfs/path",
826
826
  type: "array",
827
827
  string: !0,
828
- coerce: z
828
+ coerce: J
829
829
  }).option("mount-before-install", {
830
830
  describe: "Mount a directory to the PHP runtime before WordPress installation (can be used multiple times). Format: /host/path:/vfs/path",
831
831
  type: "array",
832
832
  string: !0,
833
- coerce: z
833
+ coerce: J
834
834
  }).option("mount-dir", {
835
835
  describe: 'Mount a directory to the PHP runtime (can be used multiple times). Format: "/host/path" "/vfs/path"',
836
836
  type: "array",
@@ -842,7 +842,7 @@ async function Rt() {
842
842
  type: "string",
843
843
  nargs: 2,
844
844
  array: !0,
845
- coerce: ve
845
+ coerce: Se
846
846
  }).option("login", {
847
847
  describe: "Should log the user in",
848
848
  type: "boolean",
@@ -870,7 +870,7 @@ async function Rt() {
870
870
  }).option("verbosity", {
871
871
  describe: "Output logs and progress messages.",
872
872
  type: "string",
873
- choices: Object.values(V).map(
873
+ choices: Object.values(_).map(
874
874
  (r) => r.name
875
875
  ),
876
876
  default: "normal"
@@ -917,7 +917,7 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
917
917
  ).option("experimental-multi-worker", {
918
918
  describe: "Enable experimental multi-worker support which requires a /wordpress directory backed by a real filesystem. Pass a positive number to specify the number of workers to use. Otherwise, default to the number of CPUs minus 1.",
919
919
  type: "number",
920
- coerce: (r) => r ?? xe().length - 1
920
+ coerce: (r) => r ?? Ie().length - 1
921
921
  }).option("experimental-blueprints-v2-runner", {
922
922
  describe: "Use the experimental Blueprint V2 runner.",
923
923
  type: "boolean",
@@ -931,7 +931,7 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
931
931
  // Remove the "hidden" flag once Blueprint V2 is fully supported
932
932
  hidden: !0
933
933
  }).showHelpOnFail(!1).strictOptions().check(async (r) => {
934
- if ((r["skip-wordpress-setup"] || r.skipWordpressSetup) && (r.skipWordPressSetup = !0), r.wp !== void 0 && !_e(r.wp))
934
+ if ((r["skip-wordpress-setup"] || r.skipWordpressSetup) && (r.skipWordPressSetup = !0), r.wp !== void 0 && !qe(r.wp))
935
935
  try {
936
936
  new URL(r.wp);
937
937
  } catch {
@@ -948,13 +948,13 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
948
948
  );
949
949
  }
950
950
  if (r["auto-mount"]) {
951
- let n = !1;
951
+ let a = !1;
952
952
  try {
953
- n = u.statSync(r["auto-mount"]).isDirectory();
953
+ a = u.statSync(r["auto-mount"]).isDirectory();
954
954
  } catch {
955
- n = !1;
955
+ a = !1;
956
956
  }
957
- if (!n)
957
+ if (!a)
958
958
  throw new Error(
959
959
  `The specified --auto-mount path is not a directory: '${r["auto-mount"]}'.`
960
960
  );
@@ -979,8 +979,8 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
979
979
  );
980
980
  } else
981
981
  r["skip-wordpress-setup"] === !0 ? r.mode = "apply-to-existing-site" : r.mode = "create-new-site";
982
- const n = r.allow || [];
983
- r.followSymlinks === !0 && n.push("follow-symlinks"), r["blueprint-may-read-adjacent-files"] === !0 && n.push("read-local-fs"), r.allow = n;
982
+ const a = r.allow || [];
983
+ r.followSymlinks === !0 && a.push("follow-symlinks"), r["blueprint-may-read-adjacent-files"] === !0 && a.push("read-local-fs"), r.allow = a;
984
984
  } else if (r.mode !== void 0)
985
985
  throw new Error(
986
986
  "The --mode option requires the --experimentalBlueprintsV2Runner flag."
@@ -998,13 +998,20 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
998
998
  ...o["mount-before-install"] || [],
999
999
  ...o["mount-dir-before-install"] || []
1000
1000
  ]
1001
- };
1002
- await lt(i);
1001
+ }, s = await pt(i);
1002
+ s === void 0 && process.exit(0);
1003
+ const n = /* @__PURE__ */ (() => {
1004
+ let r;
1005
+ return async () => {
1006
+ r !== void 0 && (r = s[Symbol.asyncDispose]()), await r, process.exit(0);
1007
+ };
1008
+ })();
1009
+ process.on("SIGINT", n), process.on("SIGTERM", n);
1003
1010
  } catch (e) {
1004
1011
  if (!(e instanceof Error))
1005
1012
  throw e;
1006
1013
  if (process.argv.includes("--debug"))
1007
- pe(e);
1014
+ de(e);
1008
1015
  else {
1009
1016
  const t = [];
1010
1017
  let i = e;
@@ -1018,39 +1025,39 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
1018
1025
  process.exit(1);
1019
1026
  }
1020
1027
  }
1021
- const D = (e) => process.stdout.isTTY ? "\x1B[1m" + e + "\x1B[0m" : e, at = (e) => process.stdout.isTTY ? `\x1B[2m${e}\x1B[0m` : e, A = (e) => process.stdout.isTTY ? `\x1B[3m${e}\x1B[0m` : e, X = (e) => process.stdout.isTTY ? `\x1B[33m${e}\x1B[0m` : e;
1022
- async function lt(e) {
1028
+ const U = (e) => process.stdout.isTTY ? "\x1B[1m" + e + "\x1B[0m" : e, ct = (e) => process.stdout.isTTY ? `\x1B[2m${e}\x1B[0m` : e, N = (e) => process.stdout.isTTY ? `\x1B[3m${e}\x1B[0m` : e, Z = (e) => process.stdout.isTTY ? `\x1B[33m${e}\x1B[0m` : e;
1029
+ async function pt(e) {
1023
1030
  let o, t;
1024
1031
  const i = [];
1025
- if (e.autoMount !== void 0 && (e.autoMount === "" && (e = { ...e, autoMount: process.cwd() }), e = Pe(e)), e.quiet && (e.verbosity = "quiet", delete e.quiet), e.debug ? e.verbosity = "debug" : e.verbosity === "debug" && (e.debug = !0), e.verbosity) {
1026
- const a = Object.values(V).find(
1032
+ if (e.autoMount !== void 0 && (e.autoMount === "" && (e = { ...e, autoMount: process.cwd() }), e = ke(e)), e.quiet && (e.verbosity = "quiet", delete e.quiet), e.debug ? e.verbosity = "debug" : e.verbosity === "debug" && (e.debug = !0), e.verbosity) {
1033
+ const l = Object.values(_).find(
1027
1034
  (p) => p.name === e.verbosity
1028
1035
  ).severity;
1029
- m.setSeverityFilterLevel(a);
1036
+ h.setSeverityFilterLevel(l);
1030
1037
  }
1031
- const r = Y.platform() === "win32" ? (
1038
+ const s = K.platform() === "win32" ? (
1032
1039
  // @TODO: Enable fs-ext here when it works with Windows.
1033
1040
  void 0
1034
- ) : await import("fs-ext").then((a) => a.flockSync).catch(() => {
1035
- m.warn(
1041
+ ) : await import("fs-ext").then((l) => l.flockSync).catch(() => {
1042
+ h.warn(
1036
1043
  "The fs-ext package is not installed. Internal file locking will not be integrated with host OS file locking."
1037
1044
  );
1038
- }), n = new ke(r);
1039
- let s = !1, l = !0;
1040
- return m.log("Starting a PHP server..."), Ue({
1045
+ }), n = new Ee(s);
1046
+ let r = !1, a = !0;
1047
+ return h.log("Starting a PHP server..."), Ve({
1041
1048
  port: e.port,
1042
- onBind: async (a, p) => {
1043
- const c = "127.0.0.1", d = `http://${c}:${p}`, h = e["site-url"] || d, w = e.experimentalMultiWorker ?? 1, b = Math.floor(
1044
- Number.MAX_SAFE_INTEGER / w
1045
- ), C = "-playground-cli-site-", x = await Ze(
1046
- C
1049
+ onBind: async (l, p) => {
1050
+ const c = "127.0.0.1", d = `http://${c}:${p}`, m = e["site-url"] || d, b = e.experimentalMultiWorker ?? 1, v = Math.floor(
1051
+ Number.MAX_SAFE_INTEGER / b
1052
+ ), I = "-playground-cli-site-", k = await Ge(
1053
+ I
1047
1054
  );
1048
- m.debug(`Native temp dir for VFS root: ${x}`);
1049
- const k = "WP Playground CLI - Listen for Xdebug", f = ".playground-xdebug-root", B = g.join(process.cwd(), f);
1050
- if (await tt(B), e.xdebug && e.experimentalUnsafeIdeIntegration) {
1051
- await et(
1052
- x,
1053
- B,
1055
+ h.debug(`Native temp dir for VFS root: ${k.path}`);
1056
+ const x = "WP Playground CLI - Listen for Xdebug", f = ".playground-xdebug-root", W = g.join(process.cwd(), f);
1057
+ if (await rt(W), e.xdebug && e.experimentalUnsafeIdeIntegration) {
1058
+ await ot(
1059
+ k.path,
1060
+ W,
1054
1061
  process.platform
1055
1062
  );
1056
1063
  const y = {
@@ -1058,9 +1065,9 @@ async function lt(e) {
1058
1065
  vfsPath: "/"
1059
1066
  };
1060
1067
  try {
1061
- await st(k, process.cwd());
1062
- const S = typeof e.xdebug == "object" ? e.xdebug : void 0, W = await it({
1063
- name: k,
1068
+ await lt(x, process.cwd());
1069
+ const w = typeof e.xdebug == "object" ? e.xdebug : void 0, L = await at({
1070
+ name: x,
1064
1071
  host: c,
1065
1072
  port: p,
1066
1073
  ides: e.experimentalUnsafeIdeIntegration,
@@ -1070,51 +1077,50 @@ async function lt(e) {
1070
1077
  ...e["mount-before-install"] || [],
1071
1078
  ...e.mount || []
1072
1079
  ],
1073
- ideKey: S?.ideKey
1074
- }), P = e.experimentalUnsafeIdeIntegration, E = P.includes("vscode"), $ = P.includes("phpstorm");
1075
- console.log(""), console.log(D("Xdebug configured successfully")), console.log(
1076
- X("Updated IDE config: ") + W.join(" ")
1080
+ ideKey: w?.ideKey
1081
+ }), S = e.experimentalUnsafeIdeIntegration, T = S.includes("vscode"), B = S.includes("phpstorm");
1082
+ console.log(""), console.log(U("Xdebug configured successfully")), console.log(
1083
+ Z("Updated IDE config: ") + L.join(" ")
1077
1084
  ), console.log(
1078
- X("Playground source root: ") + ".playground-xdebug-root" + A(
1079
- at(
1085
+ Z("Playground source root: ") + ".playground-xdebug-root" + N(
1086
+ ct(
1080
1087
  " – you can set breakpoints and preview Playground's VFS structure in there."
1081
1088
  )
1082
1089
  )
1083
- ), console.log(""), E && (console.log(D("VS Code / Cursor instructions:")), console.log(
1090
+ ), console.log(""), T && (console.log(U("VS Code / Cursor instructions:")), console.log(
1084
1091
  " 1. Open the Run and Debug panel on the left sidebar"
1085
1092
  ), console.log(
1086
- ` 2. Select "${A(
1087
- k
1093
+ ` 2. Select "${N(
1094
+ x
1088
1095
  )}" from the dropdown`
1089
1096
  ), console.log(' 3. Click "start debugging"'), console.log(
1090
1097
  " 4. Set a breakpoint. For example, in .playground-xdebug-root/wordpress/index.php"
1091
1098
  ), console.log(
1092
1099
  " 5. Visit Playground in your browser to hit the breakpoint"
1093
- ), $ && console.log("")), $ && (console.log(D("PhpStorm instructions:")), console.log(
1094
- ` 1. Choose "${A(
1095
- k
1100
+ ), B && console.log("")), B && (console.log(U("PhpStorm instructions:")), console.log(
1101
+ ` 1. Choose "${N(
1102
+ x
1096
1103
  )}" debug configuration in the toolbar`
1097
1104
  ), console.log(" 2. Click the debug button (bug icon)`"), console.log(
1098
1105
  " 3. Set a breakpoint. For example, in .playground-xdebug-root/wordpress/index.php"
1099
1106
  ), console.log(
1100
1107
  " 4. Visit Playground in your browser to hit the breakpoint"
1101
1108
  )), console.log("");
1102
- } catch (S) {
1103
- m.error(
1104
- "Could not configure Xdebug:",
1105
- S?.message
1106
- ), process.exit(1);
1109
+ } catch (w) {
1110
+ throw new Error("Could not configure Xdebug", {
1111
+ cause: w
1112
+ });
1107
1113
  }
1108
1114
  }
1109
- const re = g.dirname(x), ne = 2 * 24 * 60 * 60 * 1e3;
1110
- Ye(
1111
- C,
1112
- ne,
1113
- re
1115
+ const ie = g.dirname(k.path), se = 2 * 24 * 60 * 60 * 1e3;
1116
+ Ke(
1117
+ I,
1118
+ se,
1119
+ ie
1114
1120
  );
1115
- const R = g.join(x, "internal");
1116
- H(R);
1117
- const ie = [
1121
+ const F = g.join(k.path, "internal");
1122
+ z(F);
1123
+ const ae = [
1118
1124
  "wordpress",
1119
1125
  // Note: These dirs are from Emscripten's "default dirs" list:
1120
1126
  // https://github.com/emscripten-core/emscripten/blob/f431ec220e472e1f8d3db6b52fe23fb377facf30/src/lib/libfs.js#L1400-L1402
@@ -1125,175 +1131,180 @@ async function lt(e) {
1125
1131
  "tmp",
1126
1132
  "home"
1127
1133
  ];
1128
- for (const y of ie) {
1129
- const S = (P) => P.vfsPath === `/${y}`;
1130
- if (!(e["mount-before-install"]?.some(S) || e.mount?.some(S))) {
1131
- const P = g.join(
1132
- x,
1134
+ for (const y of ae) {
1135
+ const w = (S) => S.vfsPath === `/${y}`;
1136
+ if (!(e["mount-before-install"]?.some(w) || e.mount?.some(w))) {
1137
+ const S = g.join(
1138
+ k.path,
1133
1139
  y
1134
1140
  );
1135
- H(P), e["mount-before-install"] === void 0 && (e["mount-before-install"] = []), e["mount-before-install"].unshift({
1141
+ z(S), e["mount-before-install"] === void 0 && (e["mount-before-install"] = []), e["mount-before-install"].unshift({
1136
1142
  vfsPath: `/${y}`,
1137
- hostPath: P
1143
+ hostPath: S
1138
1144
  });
1139
1145
  }
1140
1146
  }
1141
1147
  if (e["mount-before-install"])
1142
1148
  for (const y of e["mount-before-install"])
1143
- m.debug(
1149
+ h.debug(
1144
1150
  `Mount before WP install: ${y.vfsPath} -> ${y.hostPath}`
1145
1151
  );
1146
1152
  if (e.mount)
1147
1153
  for (const y of e.mount)
1148
- m.debug(
1154
+ h.debug(
1149
1155
  `Mount after WP install: ${y.vfsPath} -> ${y.hostPath}`
1150
1156
  );
1151
- let L;
1152
- e["experimental-blueprints-v2-runner"] ? L = new qe(e, {
1153
- siteUrl: h,
1154
- processIdSpaceLength: b
1155
- }) : (L = new Je(e, {
1156
- siteUrl: h,
1157
- processIdSpaceLength: b
1158
- }), typeof e.blueprint == "string" && (e.blueprint = await He({
1157
+ let C;
1158
+ e["experimental-blueprints-v2-runner"] ? C = new Xe(e, {
1159
+ siteUrl: m,
1160
+ processIdSpaceLength: v
1161
+ }) : (C = new Ye(e, {
1162
+ siteUrl: m,
1163
+ processIdSpaceLength: v
1164
+ }), typeof e.blueprint == "string" && (e.blueprint = await ze({
1159
1165
  sourceString: e.blueprint,
1160
1166
  blueprintMayReadAdjacentFiles: e["blueprint-may-read-adjacent-files"] === !0
1161
1167
  })));
1162
- const se = ct(
1163
- w,
1164
- L.getWorkerType(),
1165
- ({ exitCode: y, isMain: S, workerIndex: W }) => {
1166
- y !== 0 && (m.error(
1167
- `Worker ${W} exited with code ${y}
1168
+ let M = !1;
1169
+ const D = async function() {
1170
+ M || (M = !0, await Promise.all(
1171
+ i.map(async ({ playground: w, worker: L }) => {
1172
+ await w.dispose(), await L.terminate();
1173
+ })
1174
+ ), l && await new Promise((w) => l.close(w)), await k.cleanup());
1175
+ }, le = ut(
1176
+ b,
1177
+ C.getWorkerType(),
1178
+ ({ exitCode: y, workerIndex: w }) => {
1179
+ M || y === 0 && h.error(
1180
+ `Worker ${w} exited with code ${y}
1168
1181
  `
1169
- ), S && e.exitOnPrimaryWorkerCrash && process.exit(1));
1182
+ );
1170
1183
  }
1171
1184
  );
1172
- m.log(`Setting up WordPress ${e.wp}`);
1185
+ h.log(`Setting up WordPress ${e.wp}`);
1173
1186
  try {
1174
- const [y, ...S] = await se, W = await J(
1187
+ const [y, ...w] = await le, L = await Y(
1175
1188
  n
1176
1189
  );
1177
- if (t = await L.bootPrimaryWorker(
1190
+ if (t = await C.bootPrimaryWorker(
1178
1191
  y.phpPort,
1179
- W,
1180
- R
1192
+ L,
1193
+ F
1181
1194
  ), i.push({
1182
1195
  playground: t,
1183
1196
  worker: y.worker
1184
- }), await t.isReady(), s = !0, m.log("Booted!"), o = new Oe(t), !e["experimental-blueprints-v2-runner"]) {
1185
- const P = await L.compileInputBlueprint(
1197
+ }), await t.isReady(), r = !0, h.log("Booted!"), o = new He(t), !e["experimental-blueprints-v2-runner"]) {
1198
+ const S = await C.compileInputBlueprint(
1186
1199
  e["additional-blueprint-steps"] || []
1187
1200
  );
1188
- P && (m.log("Running the Blueprint..."), await ye(
1189
- P,
1201
+ S && (h.log("Running the Blueprint..."), await be(
1202
+ S,
1190
1203
  t
1191
- ), m.log("Finished running the blueprint"));
1204
+ ), h.log("Finished running the blueprint"));
1192
1205
  }
1193
- if (e.command === "build-snapshot" ? (await ut(t, e.outfile), m.log(`WordPress exported to ${e.outfile}`), process.exit(0)) : e.command === "run-blueprint" && (m.log("Blueprint executed"), process.exit(0)), e.experimentalMultiWorker && e.experimentalMultiWorker > 1) {
1194
- m.log("Preparing additional workers...");
1195
- const P = b;
1206
+ if (e.command === "build-snapshot") {
1207
+ await ft(t, e.outfile), h.log(`WordPress exported to ${e.outfile}`), await D();
1208
+ return;
1209
+ } else if (e.command === "run-blueprint") {
1210
+ h.log("Blueprint executed"), await D();
1211
+ return;
1212
+ }
1213
+ if (e.experimentalMultiWorker && e.experimentalMultiWorker > 1) {
1214
+ h.log("Preparing additional workers...");
1215
+ const S = v;
1196
1216
  await Promise.all(
1197
- S.map(async (E, $) => {
1198
- const ae = P + $ * b, le = await J(n), O = await L.bootSecondaryWorker({
1199
- worker: E,
1200
- fileLockManagerPort: le,
1201
- firstProcessId: ae,
1202
- nativeInternalDirPath: R
1217
+ w.map(async (T, B) => {
1218
+ const ce = S + B * v, pe = await Y(n), H = await C.bootSecondaryWorker({
1219
+ worker: T,
1220
+ fileLockManagerPort: pe,
1221
+ firstProcessId: ce,
1222
+ nativeInternalDirPath: F
1203
1223
  });
1204
1224
  i.push({
1205
- playground: O,
1206
- worker: E.worker
1207
- }), o.addWorker(O);
1225
+ playground: H,
1226
+ worker: T.worker
1227
+ }), o.addWorker(H);
1208
1228
  })
1209
1229
  );
1210
1230
  }
1211
- return m.log(
1212
- `WordPress is running on ${d} with ${w} worker(s)`
1213
- ), e.xdebug && e.experimentalDevtools && (await Re({
1231
+ return h.log(
1232
+ `WordPress is running on ${d} with ${b} worker(s)`
1233
+ ), e.xdebug && e.experimentalDevtools && (await De({
1214
1234
  phpInstance: t,
1215
1235
  phpRoot: "/wordpress"
1216
1236
  })).start(), {
1217
1237
  playground: t,
1218
- server: a,
1238
+ server: l,
1219
1239
  serverUrl: d,
1220
- [Symbol.asyncDispose]: async function() {
1221
- await Promise.all(
1222
- i.map(
1223
- async ({ playground: E, worker: $ }) => {
1224
- await E.dispose(), await $.terminate();
1225
- }
1226
- )
1227
- ), await new Promise((E) => a.close(E));
1228
- },
1229
- workerThreadCount: w
1240
+ [Symbol.asyncDispose]: D,
1241
+ workerThreadCount: b
1230
1242
  };
1231
1243
  } catch (y) {
1232
1244
  if (!e.debug)
1233
1245
  throw y;
1234
- let S = "";
1235
- throw await t?.fileExists(_) && (S = await t.readFileAsText(_)), new Error(S, { cause: y });
1246
+ let w = "";
1247
+ throw await t?.fileExists(q) && (w = await t.readFileAsText(q)), new Error(w, { cause: y });
1236
1248
  }
1237
1249
  },
1238
- async handleRequest(a) {
1239
- if (!s)
1240
- return U.forHttpCode(
1250
+ async handleRequest(l) {
1251
+ if (!r)
1252
+ return V.forHttpCode(
1241
1253
  502,
1242
1254
  "WordPress is not ready yet"
1243
1255
  );
1244
- if (l) {
1245
- l = !1;
1256
+ if (a) {
1257
+ a = !1;
1246
1258
  const p = {
1247
1259
  "Content-Type": ["text/plain"],
1248
1260
  "Content-Length": ["0"],
1249
- Location: [a.url]
1261
+ Location: [l.url]
1250
1262
  };
1251
- return a.headers?.cookie?.includes(
1263
+ return l.headers?.cookie?.includes(
1252
1264
  "playground_auto_login_already_happened"
1253
1265
  ) && (p["Set-Cookie"] = [
1254
1266
  "playground_auto_login_already_happened=1; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Path=/"
1255
- ]), new U(302, p, new Uint8Array());
1267
+ ]), new V(302, p, new Uint8Array());
1256
1268
  }
1257
- return await o.handleRequest(a);
1269
+ return await o.handleRequest(l);
1258
1270
  }
1259
1271
  });
1260
1272
  }
1261
- async function ct(e, o, t) {
1273
+ async function ut(e, o, t) {
1262
1274
  const i = [];
1263
- for (let r = 0; r < e; r++) {
1264
- const n = await pt(o), s = (l) => {
1275
+ for (let s = 0; s < e; s++) {
1276
+ const n = await dt(o), r = (a) => {
1265
1277
  t({
1266
- exitCode: l,
1267
- isMain: r === 0,
1268
- workerIndex: r
1278
+ exitCode: a,
1279
+ workerIndex: s
1269
1280
  });
1270
1281
  };
1271
1282
  i.push(
1272
1283
  new Promise(
1273
- (l, a) => {
1284
+ (a, l) => {
1274
1285
  n.once("message", function(p) {
1275
- p.command === "worker-script-initialized" && l({ worker: n, phpPort: p.phpPort });
1286
+ p.command === "worker-script-initialized" && a({ worker: n, phpPort: p.phpPort });
1276
1287
  }), n.once("error", function(p) {
1277
1288
  console.error(p);
1278
1289
  const c = new Error(
1279
1290
  `Worker failed to load worker. ${p.message ? `Original error: ${p.message}` : ""}`
1280
1291
  );
1281
- a(c);
1282
- }), n.once("exit", s);
1292
+ l(c);
1293
+ }), n.once("exit", r);
1283
1294
  }
1284
1295
  )
1285
1296
  );
1286
1297
  }
1287
1298
  return Promise.all(i);
1288
1299
  }
1289
- async function pt(e) {
1290
- return e === "v1" ? new q(new URL("./worker-thread-v1.js", import.meta.url)) : new q(new URL("./worker-thread-v2.js", import.meta.url));
1300
+ async function dt(e) {
1301
+ return e === "v1" ? new X(new URL("./worker-thread-v1.js", import.meta.url)) : new X(new URL("./worker-thread-v2.js", import.meta.url));
1291
1302
  }
1292
- async function J(e) {
1293
- const { port1: o, port2: t } = new be();
1294
- return await Ee() ? ue(e, null, o) : await de(e, o), t;
1303
+ async function Y(e) {
1304
+ const { port1: o, port2: t } = new Pe();
1305
+ return await Ce() ? fe(e, null, o) : await me(e, o), t;
1295
1306
  }
1296
- async function ut(e, o) {
1307
+ async function ft(e, o) {
1297
1308
  await e.run({
1298
1309
  code: `<?php
1299
1310
  $zip = new ZipArchive();
@@ -1318,8 +1329,8 @@ async function ut(e, o) {
1318
1329
  u.writeFileSync(o, t);
1319
1330
  }
1320
1331
  export {
1321
- V as L,
1322
- Rt as p,
1323
- lt as r
1332
+ _ as L,
1333
+ Dt as p,
1334
+ pt as r
1324
1335
  };
1325
- //# sourceMappingURL=run-cli-B59N7dQd.js.map
1336
+ //# sourceMappingURL=run-cli-BBfr5tmj.js.map