@wp-playground/cli 3.0.21 → 3.0.22

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,5 +1,5 @@
1
1
  import { logger as g, LogSeverity as N, errorLogPath as z } from "@php-wasm/logger";
2
- import { PHPResponse as O, consumeAPI as R, SupportedPHPVersions as me, printDebugDetails as he, exposeAPI as ge, exposeSyncAPI as we } from "@php-wasm/universal";
2
+ import { PHPResponse as _, consumeAPI as F, SupportedPHPVersions as me, printDebugDetails as he, exposeAPI as ge, exposeSyncAPI as we } from "@php-wasm/universal";
3
3
  import { resolveRemoteBlueprint as ye, resolveRuntimeConfiguration as X, compileBlueprintV1 as be, isBlueprintBundle as ve, runBlueprintV1Steps as Pe } from "@wp-playground/blueprints";
4
4
  import { zipDirectory as Se, RecommendedPHPVersion as ee } from "@wp-playground/common";
5
5
  import p, { mkdirSync as J } from "fs";
@@ -19,35 +19,35 @@ import { startBridge as Ae } from "@php-wasm/xdebug-bridge";
19
19
  import { dir as Ue, setGracefulCleanup as Ne } from "tmp-promise";
20
20
  import Ve from "ps-man";
21
21
  import { XMLParser as oe, XMLBuilder as re } from "fast-xml-parser";
22
- import v from "jsonc-parser";
23
- async function Oe(e) {
24
- const o = Ie(), 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);
22
+ import P from "jsonc-parser";
23
+ async function _e(e) {
24
+ const o = Ie(), t = await new Promise((n, a) => {
25
+ const r = o.listen(e.port, () => {
26
+ const l = r.address();
27
+ l === null || typeof l == "string" ? a(new Error("Server address is not available")) : n(r);
28
28
  });
29
29
  });
30
- o.use("/", async (n, r) => {
31
- let a;
30
+ o.use("/", async (n, a) => {
31
+ let r;
32
32
  try {
33
- a = await e.handleRequest({
33
+ r = await e.handleRequest({
34
34
  url: n.url,
35
35
  headers: He(n),
36
36
  method: n.method,
37
- body: await _e(n)
37
+ body: await Oe(n)
38
38
  });
39
39
  } catch (l) {
40
- g.error(l), a = O.forHttpCode(500);
40
+ g.error(l), r = _.forHttpCode(500);
41
41
  }
42
- r.statusCode = a.httpStatusCode;
43
- for (const l in a.headers)
44
- r.setHeader(l, a.headers[l]);
45
- r.end(a.bytes);
42
+ a.statusCode = r.httpStatusCode;
43
+ for (const l in r.headers)
44
+ a.setHeader(l, r.headers[l]);
45
+ a.end(r.bytes);
46
46
  });
47
47
  const s = t.address().port;
48
48
  return await e.onBind(t, s);
49
49
  }
50
- const _e = 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);
@@ -126,7 +126,7 @@ async function Xe({
126
126
  `Blueprint file at ${t} is not a valid JSON file`
127
127
  );
128
128
  }
129
- const r = m.dirname(t), a = new je(r);
129
+ const a = m.dirname(t), r = new je(a);
130
130
  return new Be([
131
131
  new Me({
132
132
  "blueprint.json": n
@@ -143,7 +143,7 @@ async function Xe({
143
143
 
144
144
  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.`
145
145
  );
146
- return a.read(l);
146
+ return r.read(l);
147
147
  }
148
148
  }
149
149
  ]);
@@ -162,7 +162,7 @@ class Je {
162
162
  return "v2";
163
163
  }
164
164
  async bootAndSetUpInitialPlayground(o, t, i) {
165
- const s = R(o);
165
+ const s = F(o);
166
166
  await s.useFileLockManager(t);
167
167
  const n = {
168
168
  ...this.args,
@@ -188,9 +188,9 @@ class Je {
188
188
  firstProcessId: i,
189
189
  nativeInternalDirPath: s
190
190
  }) {
191
- const n = R(o.phpPort);
191
+ const n = F(o.phpPort);
192
192
  await n.useFileLockManager(t);
193
- const r = {
193
+ const a = {
194
194
  ...this.args,
195
195
  phpVersion: this.phpVersion,
196
196
  siteUrl: this.siteUrl,
@@ -202,7 +202,7 @@ class Je {
202
202
  mountsBeforeWpInstall: this.args["mount-before-install"] || [],
203
203
  mountsAfterWpInstall: this.args.mount || []
204
204
  };
205
- return await n.bootWorker(r), n;
205
+ return await n.bootWorker(a), n;
206
206
  }
207
207
  writeProgressUpdate(o, t, i) {
208
208
  t !== this.lastProgressMessage && (this.lastProgressMessage = t, o.isTTY ? (o.cursorTo(0), o.write(t), o.clearLine(1), i && o.write(`
@@ -210,7 +210,7 @@ class Je {
210
210
  `));
211
211
  }
212
212
  }
213
- const _ = m.join(te.homedir(), ".wordpress-playground");
213
+ const O = m.join(te.homedir(), ".wordpress-playground");
214
214
  async function Ze(e) {
215
215
  return await ne(
216
216
  "https://github.com/WordPress/sqlite-database-integration/archive/refs/heads/develop.zip",
@@ -219,20 +219,20 @@ async function Ze(e) {
219
219
  );
220
220
  }
221
221
  async function ne(e, o, t) {
222
- const i = m.join(_, o);
223
- return T.existsSync(i) || (T.ensureDirSync(_), await Ye(e, i, t)), ie(i);
222
+ const i = m.join(O, o);
223
+ return T.existsSync(i) || (T.ensureDirSync(O), await Ye(e, i, t)), ie(i);
224
224
  }
225
225
  async function Ye(e, o, t) {
226
- const s = (await t.monitorFetch(fetch(e))).body.getReader(), n = `${o}.partial`, r = T.createWriteStream(n);
226
+ const s = (await t.monitorFetch(fetch(e))).body.getReader(), n = `${o}.partial`, a = T.createWriteStream(n);
227
227
  for (; ; ) {
228
- const { done: a, value: l } = await s.read();
229
- if (l && r.write(l), a)
228
+ const { done: r, value: l } = await s.read();
229
+ if (l && a.write(l), r)
230
230
  break;
231
231
  }
232
- r.close(), r.closed || await new Promise((a, l) => {
233
- r.on("finish", () => {
234
- T.renameSync(n, o), a(null);
235
- }), r.on("error", (d) => {
232
+ a.close(), a.closed || await new Promise((r, l) => {
233
+ a.on("finish", () => {
234
+ T.renameSync(n, o), r(null);
235
+ }), a.on("error", (d) => {
236
236
  T.removeSync(n), l(d);
237
237
  });
238
238
  });
@@ -248,34 +248,34 @@ class Ge {
248
248
  return "v1";
249
249
  }
250
250
  async bootAndSetUpInitialPlayground(o, t, i) {
251
- let s, n, r;
252
- const a = new Fe();
251
+ let s, n, a;
252
+ const r = new Fe();
253
253
  if (this.args.wordpressInstallMode === "download-and-install") {
254
- let k = !1;
255
- a.addEventListener("progress", (j) => {
256
- if (k)
254
+ let I = !1;
255
+ r.addEventListener("progress", (j) => {
256
+ if (I)
257
257
  return;
258
258
  const { loaded: x, total: f } = j.detail, B = Math.floor(
259
259
  Math.min(100, 100 * x / f)
260
260
  );
261
- k = B === 100, this.writeProgressUpdate(
261
+ I = B === 100, this.writeProgressUpdate(
262
262
  process.stdout,
263
263
  `Downloading WordPress ${B}%...`,
264
- k
264
+ I
265
265
  );
266
- }), s = await De(this.args.wp), r = m.join(
267
- _,
266
+ }), s = await De(this.args.wp), a = m.join(
267
+ O,
268
268
  `prebuilt-wp-content-for-wp-${s.version}.zip`
269
- ), n = p.existsSync(r) ? ie(r) : await ne(
269
+ ), n = p.existsSync(a) ? ie(a) : await ne(
270
270
  s.releaseUrl,
271
271
  `${s.version}.zip`,
272
- a
272
+ r
273
273
  ), g.log(
274
274
  `Resolved WordPress release URL: ${s?.releaseUrl}`
275
275
  );
276
276
  }
277
277
  g.log("Fetching SQLite integration plugin...");
278
- const l = this.args.skipSqliteSetup ? void 0 : await Ze(a), d = this.args.followSymlinks === !0, c = this.args.experimentalTrace === !0, u = this.args["mount-before-install"] || [], h = this.args.mount || [], b = R(o);
278
+ const l = this.args.skipSqliteSetup ? void 0 : await Ze(r), d = this.args.followSymlinks === !0, c = this.args.experimentalTrace === !0, u = this.args["mount-before-install"] || [], h = this.args.mount || [], b = F(o);
279
279
  await b.isConnected(), g.log("Booting WordPress...");
280
280
  const S = await X(
281
281
  this.getEffectiveBlueprint()
@@ -300,8 +300,8 @@ class Ge {
300
300
  // TODO: Consider supporting Xdebug for the initial worker via a dedicated flag.
301
301
  withXdebug: !1,
302
302
  nativeInternalDirPath: i
303
- }), r && !this.args["mount-before-install"] && !p.existsSync(r) && (g.log("Caching preinstalled WordPress for the next boot..."), p.writeFileSync(
304
- r,
303
+ }), a && !this.args["mount-before-install"] && !p.existsSync(a) && (g.log("Caching preinstalled WordPress for the next boot..."), p.writeFileSync(
304
+ a,
305
305
  await Se(b, "/wordpress")
306
306
  ), g.log("Cached!")), b;
307
307
  }
@@ -311,15 +311,15 @@ class Ge {
311
311
  firstProcessId: i,
312
312
  nativeInternalDirPath: s
313
313
  }) {
314
- const n = R(
314
+ const n = F(
315
315
  o.phpPort
316
316
  );
317
317
  await n.isConnected();
318
- const r = await X(
318
+ const a = await X(
319
319
  this.getEffectiveBlueprint()
320
320
  );
321
321
  return await n.useFileLockManager(t), await n.bootWorker({
322
- phpVersion: r.phpVersion,
322
+ phpVersion: a.phpVersion,
323
323
  siteUrl: this.siteUrl,
324
324
  mountsBeforeWpInstall: this.args["mount-before-install"] || [],
325
325
  mountsAfterWpInstall: this.args.mount || [],
@@ -337,13 +337,13 @@ class Ge {
337
337
  async compileInputBlueprint(o) {
338
338
  const t = this.getEffectiveBlueprint(), i = new We();
339
339
  let s = "", n = !1;
340
- return i.addEventListener("progress", (r) => {
340
+ return i.addEventListener("progress", (a) => {
341
341
  if (n)
342
342
  return;
343
- n = r.detail.progress === 100;
344
- const a = Math.floor(r.detail.progress);
345
- s = r.detail.caption || s || "Running the Blueprint";
346
- const l = `${s.trim()} – ${a}%`;
343
+ n = a.detail.progress === 100;
344
+ const r = Math.floor(a.detail.progress);
345
+ s = a.detail.caption || s || "Running the Blueprint";
346
+ const l = `${s.trim()} – ${r}%`;
347
347
  this.writeProgressUpdate(
348
348
  process.stdout,
349
349
  l,
@@ -393,14 +393,14 @@ async function Qe(e, o, t) {
393
393
  o,
394
394
  t
395
395
  )).map(
396
- (n) => new Promise((r) => {
397
- p.rm(n, { recursive: !0 }, (a) => {
398
- a ? g.warn(
396
+ (n) => new Promise((a) => {
397
+ p.rm(n, { recursive: !0 }, (r) => {
398
+ r ? g.warn(
399
399
  `Failed to delete stale Playground temp dir: ${n}`,
400
- a
400
+ r
401
401
  ) : g.info(
402
402
  `Deleted stale Playground temp dir: ${n}`
403
- ), r();
403
+ ), a();
404
404
  });
405
405
  })
406
406
  );
@@ -431,14 +431,14 @@ async function tt(e, o, t) {
431
431
  );
432
432
  if (!n)
433
433
  return !1;
434
- const r = {
434
+ const a = {
435
435
  executableName: n[1],
436
436
  pid: n[2]
437
437
  };
438
- if (await ot(r.pid, r.executableName))
438
+ if (await ot(a.pid, a.executableName))
439
439
  return !1;
440
- const a = Date.now() - o;
441
- return p.statSync(t).mtime.getTime() < a;
440
+ const r = Date.now() - o;
441
+ return p.statSync(t).mtime.getTime() < r;
442
442
  }
443
443
  async function ot(e, o) {
444
444
  const [t] = await new Promise(
@@ -450,8 +450,8 @@ async function ot(e, o) {
450
450
  // Remove path from executable name in the results.
451
451
  clean: !0
452
452
  },
453
- (n, r) => {
454
- n ? s(n) : i(r);
453
+ (n, a) => {
454
+ n ? s(n) : i(a);
455
455
  }
456
456
  );
457
457
  }
@@ -500,14 +500,14 @@ const E = {
500
500
  suppressBooleanAttributes: !E.allowBooleanAttributes,
501
501
  format: !0,
502
502
  indentBy: " "
503
- }, F = {
503
+ }, W = {
504
504
  allowEmptyContent: !0,
505
505
  allowTrailingComma: !0
506
506
  };
507
507
  function st(e, o) {
508
- const { name: t, host: i, port: s, mappings: n, ideKey: r } = o, a = new oe(E), l = (() => {
508
+ const { name: t, host: i, port: s, mappings: n, ideKey: a } = o, r = new oe(E), l = (() => {
509
509
  try {
510
- return a.parse(e, !0);
510
+ return r.parse(e, !0);
511
511
  } catch {
512
512
  throw new Error("PhpStorm configuration file is not valid XML.");
513
513
  }
@@ -587,14 +587,14 @@ function st(e, o) {
587
587
  factoryName: "PHP Remote Debug",
588
588
  filter_connections: "FILTER",
589
589
  server_name: t,
590
- session_id: r
590
+ session_id: a
591
591
  }
592
592
  };
593
593
  S.component === void 0 && (S.component = []), S.component.push(f);
594
594
  }
595
595
  const x = new re(se).build(l);
596
596
  try {
597
- a.parse(x, !0);
597
+ r.parse(x, !0);
598
598
  } catch {
599
599
  throw new Error(
600
600
  "The resulting PhpStorm configuration file is not valid XML."
@@ -604,18 +604,18 @@ function st(e, o) {
604
604
  }
605
605
  function at(e, o) {
606
606
  const { name: t, mappings: i } = o, s = [];
607
- let n = e, r = v.parseTree(n, s, F);
608
- if (r === void 0 || s.length)
607
+ let n = e, a = P.parseTree(n, s, W);
608
+ if (a === void 0 || s.length)
609
609
  throw new Error("VS Code configuration file is not valid JSON.");
610
- let a = v.findNodeAtLocation(r, ["configurations"]);
611
- if (a === void 0 || a.children === void 0) {
612
- const d = v.modify(n, ["configurations"], [], {});
613
- n = v.applyEdits(n, d), r = v.parseTree(n, [], F), a = v.findNodeAtLocation(r, [
610
+ let r = P.findNodeAtLocation(a, ["configurations"]);
611
+ if (r === void 0 || r.children === void 0) {
612
+ const d = P.modify(n, ["configurations"], [], {});
613
+ n = P.applyEdits(n, d), a = P.parseTree(n, [], W), r = P.findNodeAtLocation(a, [
614
614
  "configurations"
615
615
  ]);
616
616
  }
617
- const l = a?.children?.findIndex(
618
- (d) => v.findNodeAtLocation(d, ["name"])?.value === t
617
+ const l = r?.children?.findIndex(
618
+ (d) => P.findNodeAtLocation(d, ["name"])?.value === t
619
619
  );
620
620
  if (l === void 0 || l < 0) {
621
621
  const d = {
@@ -626,7 +626,7 @@ function at(e, o) {
626
626
  pathMappings: i.reduce((h, b) => (h[b.vfsPath] = `\${workspaceFolder}/${le(
627
627
  m.relative(o.workspaceDir, b.hostPath)
628
628
  )}`, h), {})
629
- }, c = a?.children?.length || 0, u = v.modify(
629
+ }, c = r?.children?.length || 0, u = P.modify(
630
630
  n,
631
631
  ["configurations", c],
632
632
  d,
@@ -650,9 +650,9 @@ async function lt({
650
650
  port: i,
651
651
  cwd: s,
652
652
  mounts: n,
653
- ideKey: r = "PLAYGROUNDCLI"
653
+ ideKey: a = "PLAYGROUNDCLI"
654
654
  }) {
655
- const a = it(s, n), l = [];
655
+ const r = it(s, n), l = [];
656
656
  if (o.includes("phpstorm")) {
657
657
  const d = ".idea/workspace.xml", c = m.join(
658
658
  s,
@@ -677,8 +677,8 @@ async function lt({
677
677
  host: t,
678
678
  port: i,
679
679
  projectDir: s,
680
- mappings: a,
681
- ideKey: r
680
+ mappings: r,
681
+ ideKey: a
682
682
  });
683
683
  p.writeFileSync(c, h);
684
684
  }
@@ -706,7 +706,7 @@ async function lt({
706
706
  const u = p.readFileSync(c, "utf-8"), h = at(u, {
707
707
  name: e,
708
708
  workspaceDir: s,
709
- mappings: a
709
+ mappings: r
710
710
  });
711
711
  h !== u && (p.writeFileSync(c, h), l.push(d));
712
712
  }
@@ -716,7 +716,7 @@ async function lt({
716
716
  async function ct(e, o) {
717
717
  const t = m.join(o, ".idea/workspace.xml");
718
718
  if (p.existsSync(t)) {
719
- const s = p.readFileSync(t, "utf8"), n = new oe(E), r = (() => {
719
+ const s = p.readFileSync(t, "utf8"), n = new oe(E), a = (() => {
720
720
  try {
721
721
  return n.parse(s, !0);
722
722
  } catch {
@@ -724,7 +724,7 @@ async function ct(e, o) {
724
724
  "PhpStorm configuration file is not valid XML."
725
725
  );
726
726
  }
727
- })(), d = r.find(
727
+ })(), d = a.find(
728
728
  (u) => !!u?.project
729
729
  )?.project?.find(
730
730
  (u) => !!u?.component && u?.[":@"]?.name === "PhpServers"
@@ -735,7 +735,7 @@ async function ct(e, o) {
735
735
  );
736
736
  if (c !== void 0 && c >= 0) {
737
737
  d.servers.splice(c, 1);
738
- const h = new re(se).build(r);
738
+ const h = new re(se).build(a);
739
739
  try {
740
740
  n.parse(h, !0);
741
741
  } catch {
@@ -753,16 +753,16 @@ async function ct(e, o) {
753
753
  }
754
754
  const i = m.join(o, ".vscode/launch.json");
755
755
  if (p.existsSync(i)) {
756
- const s = [], n = p.readFileSync(i, "utf-8"), r = v.parseTree(n, s, F);
757
- if (r === void 0 || s.length)
756
+ const s = [], n = p.readFileSync(i, "utf-8"), a = P.parseTree(n, s, W);
757
+ if (a === void 0 || s.length)
758
758
  throw new Error("VS Code configuration file is not valid JSON.");
759
- const l = v.findNodeAtLocation(r, [
759
+ const l = P.findNodeAtLocation(a, [
760
760
  "configurations"
761
761
  ])?.children?.findIndex(
762
- (d) => v.findNodeAtLocation(d, ["name"])?.value === e
762
+ (d) => P.findNodeAtLocation(d, ["name"])?.value === e
763
763
  );
764
764
  if (l !== void 0 && l >= 0) {
765
- const d = v.modify(
765
+ const d = P.modify(
766
766
  n,
767
767
  ["configurations", l],
768
768
  void 0,
@@ -782,20 +782,20 @@ async function ct(e, o) {
782
782
  }
783
783
  }
784
784
  function ae(e, o) {
785
- const t = [], i = v.applyEdits(e, o);
786
- if (t.length = 0, v.parseTree(i, t, F), t.length) {
787
- const s = t.map((r) => ({
788
- message: v.printParseErrorCode(r.error),
789
- offset: r.offset,
790
- length: r.length,
785
+ const t = [], i = P.applyEdits(e, o);
786
+ if (t.length = 0, P.parseTree(i, t, W), t.length) {
787
+ const s = t.map((a) => ({
788
+ message: P.printParseErrorCode(a.error),
789
+ offset: a.offset,
790
+ length: a.length,
791
791
  fragment: i.slice(
792
- Math.max(0, r.offset - 20),
793
- Math.min(i.length, r.offset + r.length + 10)
792
+ Math.max(0, a.offset - 20),
793
+ Math.min(i.length, a.offset + a.length + 10)
794
794
  )
795
795
  })).map(
796
- (r) => `${r.message} at ${r.offset}:${r.length} (${r.fragment})`
796
+ (a) => `${a.message} at ${a.offset}:${a.length} (${a.fragment})`
797
797
  ), n = o.map(
798
- (r) => `At ${r.offset}:${r.length} - (${r.content})`
798
+ (a) => `At ${a.offset}:${a.length} - (${a.content})`
799
799
  );
800
800
  throw new Error(
801
801
  `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.
@@ -819,9 +819,9 @@ const H = {
819
819
  Normal: { name: "normal", severity: N.Info },
820
820
  Debug: { name: "debug", severity: N.Debug }
821
821
  };
822
- async function At() {
822
+ async function At(e) {
823
823
  try {
824
- const e = $e(process.argv.slice(2)).usage("Usage: wp-playground <command> [options]").positional("command", {
824
+ const o = $e(e).usage("Usage: wp-playground <command> [options]").positional("command", {
825
825
  describe: "Command to run",
826
826
  choices: ["server", "run-blueprint", "build-snapshot"],
827
827
  demandOption: !0
@@ -982,21 +982,27 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
982
982
  );
983
983
  }
984
984
  if (r["auto-mount"]) {
985
- let a = !1;
985
+ let l = !1;
986
986
  try {
987
- a = p.statSync(r["auto-mount"]).isDirectory();
987
+ l = p.statSync(r["auto-mount"]).isDirectory();
988
988
  } catch {
989
- a = !1;
989
+ l = !1;
990
990
  }
991
- if (!a)
991
+ if (!l)
992
992
  throw new Error(
993
993
  `The specified --auto-mount path is not a directory: '${r["auto-mount"]}'.`
994
994
  );
995
995
  }
996
- if (r["experimental-multi-worker"] !== void 0 && r["experimental-multi-worker"] <= 1)
997
- throw new Error(
998
- "The --experimental-multi-worker flag must be a positive integer greater than 1."
999
- );
996
+ if (r["experimental-multi-worker"] !== void 0) {
997
+ if (r._[0] !== "server")
998
+ throw new Error(
999
+ "The --experimental-multi-worker flag is only supported when running the server command."
1000
+ );
1001
+ if (r["experimental-multi-worker"] <= 1)
1002
+ throw new Error(
1003
+ "The --experimental-multi-worker flag must be a positive integer greater than 1."
1004
+ );
1005
+ }
1000
1006
  if (r["experimental-blueprints-v2-runner"] === !0) {
1001
1007
  if (r.mode !== void 0) {
1002
1008
  if (r["wordpress-install-mode"] !== void 0)
@@ -1013,47 +1019,47 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
1013
1019
  );
1014
1020
  } else
1015
1021
  r["wordpress-install-mode"] === "do-not-attempt-installing" ? r.mode = "apply-to-existing-site" : r.mode = "create-new-site";
1016
- const a = r.allow || [];
1017
- r.followSymlinks === !0 && a.push("follow-symlinks"), r["blueprint-may-read-adjacent-files"] === !0 && a.push("read-local-fs"), r.allow = a;
1022
+ const l = r.allow || [];
1023
+ r.followSymlinks === !0 && l.push("follow-symlinks"), r["blueprint-may-read-adjacent-files"] === !0 && l.push("read-local-fs"), r.allow = l;
1018
1024
  } else if (r.mode !== void 0)
1019
1025
  throw new Error(
1020
1026
  "The --mode option requires the --experimentalBlueprintsV2Runner flag."
1021
1027
  );
1022
1028
  return !0;
1023
1029
  });
1024
- e.wrap(e.terminalWidth());
1025
- const o = await e.argv, t = o._[0];
1026
- ["run-blueprint", "server", "build-snapshot"].includes(t) || (e.showHelp(), process.exit(1));
1027
- const i = {
1028
- ...o,
1029
- command: t,
1030
- mount: [...o.mount || [], ...o["mount-dir"] || []],
1030
+ o.wrap(o.terminalWidth());
1031
+ const t = await o.argv, i = t._[0];
1032
+ ["run-blueprint", "server", "build-snapshot"].includes(i) || (o.showHelp(), process.exit(1));
1033
+ const s = {
1034
+ ...t,
1035
+ command: i,
1036
+ mount: [...t.mount || [], ...t["mount-dir"] || []],
1031
1037
  "mount-before-install": [
1032
- ...o["mount-before-install"] || [],
1033
- ...o["mount-dir-before-install"] || []
1038
+ ...t["mount-before-install"] || [],
1039
+ ...t["mount-dir-before-install"] || []
1034
1040
  ]
1035
- }, s = await pt(i);
1036
- s === void 0 && process.exit(0);
1037
- const n = /* @__PURE__ */ (() => {
1041
+ }, n = await pt(s);
1042
+ n === void 0 && process.exit(0);
1043
+ const a = /* @__PURE__ */ (() => {
1038
1044
  let r;
1039
1045
  return async () => {
1040
- r !== void 0 && (r = s[Symbol.asyncDispose]()), await r, process.exit(0);
1046
+ r !== void 0 && (r = n[Symbol.asyncDispose]()), await r, process.exit(0);
1041
1047
  };
1042
1048
  })();
1043
- process.on("SIGINT", n), process.on("SIGTERM", n);
1044
- } catch (e) {
1045
- if (!(e instanceof Error))
1046
- throw e;
1049
+ process.on("SIGINT", a), process.on("SIGTERM", a);
1050
+ } catch (o) {
1051
+ if (!(o instanceof Error))
1052
+ throw o;
1047
1053
  if (process.argv.includes("--debug"))
1048
- he(e);
1054
+ he(o);
1049
1055
  else {
1050
- const t = [];
1051
- let i = e;
1056
+ const i = [];
1057
+ let s = o;
1052
1058
  do
1053
- t.push(i.message), i = i.cause;
1054
- while (i instanceof Error);
1059
+ i.push(s.message), s = s.cause;
1060
+ while (s instanceof Error);
1055
1061
  console.error(
1056
- "\x1B[1m" + t.join(" caused by: ") + "\x1B[0m"
1062
+ "\x1B[1m" + i.join(" caused by: ") + "\x1B[0m"
1057
1063
  );
1058
1064
  }
1059
1065
  process.exit(1);
@@ -1062,7 +1068,7 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
1062
1068
  const M = (e) => process.stdout.isTTY ? "\x1B[1m" + e + "\x1B[0m" : e, dt = (e) => process.stdout.isTTY ? `\x1B[2m${e}\x1B[0m` : e, V = (e) => process.stdout.isTTY ? `\x1B[3m${e}\x1B[0m` : e, K = (e) => process.stdout.isTTY ? `\x1B[33m${e}\x1B[0m` : e;
1063
1069
  async function pt(e) {
1064
1070
  let o, t;
1065
- const i = [];
1071
+ const i = /* @__PURE__ */ new Map();
1066
1072
  if (e.autoMount !== void 0 && (e.autoMount === "" && (e = { ...e, autoMount: process.cwd() }), e = ke(e)), e.wordpressInstallMode === void 0 && (e.wordpressInstallMode = "download-and-install"), e.quiet && (e.verbosity = "quiet", delete e.quiet), e.debug ? e.verbosity = "debug" : e.verbosity === "debug" && (e.debug = !0), e.verbosity) {
1067
1073
  const l = Object.values(H).find(
1068
1074
  (d) => d.name === e.verbosity
@@ -1077,11 +1083,15 @@ async function pt(e) {
1077
1083
  "The fs-ext package is not installed. Internal file locking will not be integrated with host OS file locking."
1078
1084
  );
1079
1085
  }), n = new Ee(s);
1080
- let r = !1, a = !0;
1081
- return g.log("Starting a PHP server..."), Oe({
1086
+ let a = !1, r = !0;
1087
+ return g.log("Starting a PHP server..."), _e({
1082
1088
  port: e.port,
1083
1089
  onBind: async (l, d) => {
1084
- const c = "127.0.0.1", u = `http://${c}:${d}`, h = e["site-url"] || u, b = e.experimentalMultiWorker ?? 1, S = b + 1, k = Math.floor(
1090
+ const c = "127.0.0.1", u = `http://${c}:${d}`, h = e["site-url"] || u, b = e.command === "server" ? e.experimentalMultiWorker ?? 1 : 1, S = e.command === "server" ? (
1091
+ // Account for the initial worker
1092
+ // which is discarded by the server after setup.
1093
+ b + 1
1094
+ ) : b, I = Math.floor(
1085
1095
  Number.MAX_SAFE_INTEGER / S
1086
1096
  ), j = "-playground-cli-site-", x = await Ke(
1087
1097
  j
@@ -1112,7 +1122,7 @@ async function pt(e) {
1112
1122
  ...e.mount || []
1113
1123
  ],
1114
1124
  ideKey: y?.ideKey
1115
- }), P = e.experimentalUnsafeIdeIntegration, I = P.includes("vscode"), C = P.includes("phpstorm");
1125
+ }), v = e.experimentalUnsafeIdeIntegration, k = v.includes("vscode"), C = v.includes("phpstorm");
1116
1126
  console.log(""), console.log(M("Xdebug configured successfully")), console.log(
1117
1127
  K("Updated IDE config: ") + $.join(" ")
1118
1128
  ), console.log(
@@ -1121,7 +1131,7 @@ async function pt(e) {
1121
1131
  " – you can set breakpoints and preview Playground's VFS structure in there."
1122
1132
  )
1123
1133
  )
1124
- ), console.log(""), I && (console.log(M("VS Code / Cursor instructions:")), console.log(
1134
+ ), console.log(""), k && (console.log(M("VS Code / Cursor instructions:")), console.log(
1125
1135
  " 1. Ensure you have installed an IDE extension for PHP Debugging"
1126
1136
  ), console.log(
1127
1137
  ` (The ${M("PHP Debug")} extension by ${M(
@@ -1158,8 +1168,8 @@ async function pt(e) {
1158
1168
  de,
1159
1169
  ce
1160
1170
  );
1161
- const W = m.join(x.path, "internal");
1162
- J(W);
1171
+ const D = m.join(x.path, "internal");
1172
+ J(D);
1163
1173
  const pe = [
1164
1174
  "wordpress",
1165
1175
  // Note: These dirs are from Emscripten's "default dirs" list:
@@ -1172,15 +1182,15 @@ async function pt(e) {
1172
1182
  "home"
1173
1183
  ];
1174
1184
  for (const w of pe) {
1175
- const y = (P) => P.vfsPath === `/${w}`;
1185
+ const y = (v) => v.vfsPath === `/${w}`;
1176
1186
  if (!(e["mount-before-install"]?.some(y) || e.mount?.some(y))) {
1177
- const P = m.join(
1187
+ const v = m.join(
1178
1188
  x.path,
1179
1189
  w
1180
1190
  );
1181
- J(P), e["mount-before-install"] === void 0 && (e["mount-before-install"] = []), e["mount-before-install"].unshift({
1191
+ J(v), e["mount-before-install"] === void 0 && (e["mount-before-install"] = []), e["mount-before-install"].unshift({
1182
1192
  vfsPath: `/${w}`,
1183
- hostPath: P
1193
+ hostPath: v
1184
1194
  });
1185
1195
  }
1186
1196
  }
@@ -1197,26 +1207,28 @@ async function pt(e) {
1197
1207
  let L;
1198
1208
  e["experimental-blueprints-v2-runner"] ? L = new Je(e, {
1199
1209
  siteUrl: h,
1200
- processIdSpaceLength: k
1210
+ processIdSpaceLength: I
1201
1211
  }) : (L = new Ge(e, {
1202
1212
  siteUrl: h,
1203
- processIdSpaceLength: k
1213
+ processIdSpaceLength: I
1204
1214
  }), typeof e.blueprint == "string" && (e.blueprint = await Xe({
1205
1215
  sourceString: e.blueprint,
1206
1216
  blueprintMayReadAdjacentFiles: e["blueprint-may-read-adjacent-files"] === !0
1207
1217
  })));
1208
- let D = !1;
1209
- const A = async function() {
1210
- D || (D = !0, await Promise.all(
1211
- i.map(async ({ playground: y, worker: $ }) => {
1212
- await y.dispose(), await $.terminate();
1213
- })
1218
+ let A = !1;
1219
+ const R = async function() {
1220
+ A || (A = !0, await Promise.all(
1221
+ [...i].map(
1222
+ async ([y, $]) => {
1223
+ await $.dispose(), await y.terminate();
1224
+ }
1225
+ )
1214
1226
  ), l && await new Promise((y) => l.close(y)), await x.cleanup());
1215
1227
  }, ue = ut(
1216
1228
  S,
1217
1229
  L.getWorkerType(),
1218
1230
  ({ exitCode: w, workerIndex: y }) => {
1219
- D || w === 0 && g.error(
1231
+ A || w === 0 && g.error(
1220
1232
  `Worker ${y} exited with code ${w}
1221
1233
  `
1222
1234
  );
@@ -1228,45 +1240,48 @@ async function pt(e) {
1228
1240
  n
1229
1241
  );
1230
1242
  {
1231
- const P = w.shift(), I = await L.bootAndSetUpInitialPlayground(
1232
- P.phpPort,
1243
+ const v = w.shift(), k = await L.bootAndSetUpInitialPlayground(
1244
+ v.phpPort,
1233
1245
  y,
1234
- W
1246
+ D
1235
1247
  );
1236
- if (await I.isReady(), r = !0, g.log("Booted!"), o = new qe(I), !e["experimental-blueprints-v2-runner"]) {
1248
+ if (i.set(
1249
+ v.worker,
1250
+ k
1251
+ ), await k.isReady(), a = !0, g.log("Booted!"), o = new qe(k), !e["experimental-blueprints-v2-runner"]) {
1237
1252
  const C = await L.compileInputBlueprint(
1238
1253
  e["additional-blueprint-steps"] || []
1239
1254
  );
1240
1255
  C && (g.log("Running the Blueprint..."), await Pe(
1241
1256
  C,
1242
- I
1257
+ k
1243
1258
  ), g.log("Finished running the blueprint"));
1244
1259
  }
1245
1260
  if (e.command === "build-snapshot") {
1246
- await mt(t, e.outfile), g.log(`WordPress exported to ${e.outfile}`), await A();
1261
+ await mt(t, e.outfile), g.log(`WordPress exported to ${e.outfile}`), await R();
1247
1262
  return;
1248
1263
  } else if (e.command === "run-blueprint") {
1249
- g.log("Blueprint executed"), await A();
1264
+ g.log("Blueprint executed"), await R();
1250
1265
  return;
1251
1266
  }
1252
- await o.removeWorker(I), await I.dispose(), await P.worker.terminate();
1267
+ await o.removeWorker(k), await k.dispose(), await v.worker.terminate(), i.delete(v.worker);
1253
1268
  }
1254
1269
  g.log("Preparing workers...");
1255
- const $ = k;
1270
+ const $ = I;
1256
1271
  return [t] = await Promise.all(
1257
- w.map(async (P, I) => {
1258
- const C = $ + I * k, fe = await Q(
1272
+ w.map(async (v, k) => {
1273
+ const C = $ + k * I, fe = await Q(
1259
1274
  n
1260
1275
  ), U = await L.bootPlayground({
1261
- worker: P,
1276
+ worker: v,
1262
1277
  fileLockManagerPort: fe,
1263
1278
  firstProcessId: C,
1264
- nativeInternalDirPath: W
1279
+ nativeInternalDirPath: D
1265
1280
  });
1266
- return i.push({
1267
- playground: U,
1268
- worker: P.worker
1269
- }), o.addWorker(U), U;
1281
+ return i.set(
1282
+ v.worker,
1283
+ U
1284
+ ), o.addWorker(U), U;
1270
1285
  })
1271
1286
  ), g.log(
1272
1287
  `WordPress is running on ${u} with ${b} worker(s)`
@@ -1277,24 +1292,24 @@ async function pt(e) {
1277
1292
  playground: t,
1278
1293
  server: l,
1279
1294
  serverUrl: u,
1280
- [Symbol.asyncDispose]: A,
1295
+ [Symbol.asyncDispose]: R,
1281
1296
  workerThreadCount: b
1282
1297
  };
1283
1298
  } catch (w) {
1284
1299
  if (!e.debug)
1285
1300
  throw w;
1286
1301
  let y = "";
1287
- throw await t?.fileExists(z) && (y = await t.readFileAsText(z)), new Error(y, { cause: w });
1302
+ throw await t?.fileExists(z) && (y = await t.readFileAsText(z)), await R(), new Error(y, { cause: w });
1288
1303
  }
1289
1304
  },
1290
1305
  async handleRequest(l) {
1291
- if (!r)
1292
- return O.forHttpCode(
1306
+ if (!a)
1307
+ return _.forHttpCode(
1293
1308
  502,
1294
1309
  "WordPress is not ready yet"
1295
1310
  );
1296
- if (a) {
1297
- a = !1;
1311
+ if (r) {
1312
+ r = !1;
1298
1313
  const d = {
1299
1314
  "Content-Type": ["text/plain"],
1300
1315
  "Content-Length": ["0"],
@@ -1304,7 +1319,7 @@ async function pt(e) {
1304
1319
  "playground_auto_login_already_happened"
1305
1320
  ) && (d["Set-Cookie"] = [
1306
1321
  "playground_auto_login_already_happened=1; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Path=/"
1307
- ]), new O(302, d, new Uint8Array());
1322
+ ]), new _(302, d, new Uint8Array());
1308
1323
  }
1309
1324
  return await o.handleRequest(l);
1310
1325
  }
@@ -1313,24 +1328,24 @@ async function pt(e) {
1313
1328
  async function ut(e, o, t) {
1314
1329
  const i = [];
1315
1330
  for (let s = 0; s < e; s++) {
1316
- const n = await ft(o), r = (a) => {
1331
+ const n = await ft(o), a = (r) => {
1317
1332
  t({
1318
- exitCode: a,
1333
+ exitCode: r,
1319
1334
  workerIndex: s
1320
1335
  });
1321
1336
  };
1322
1337
  i.push(
1323
1338
  new Promise(
1324
- (a, l) => {
1339
+ (r, l) => {
1325
1340
  n.once("message", function(d) {
1326
- d.command === "worker-script-initialized" && a({ worker: n, phpPort: d.phpPort });
1341
+ d.command === "worker-script-initialized" && r({ worker: n, phpPort: d.phpPort });
1327
1342
  }), n.once("error", function(d) {
1328
1343
  console.error(d);
1329
1344
  const c = new Error(
1330
1345
  `Worker failed to load worker. ${d.message ? `Original error: ${d.message}` : ""}`
1331
1346
  );
1332
1347
  l(c);
1333
- }), n.once("exit", r);
1348
+ }), n.once("exit", a);
1334
1349
  }
1335
1350
  )
1336
1351
  );
@@ -1373,4 +1388,4 @@ export {
1373
1388
  At as p,
1374
1389
  pt as r
1375
1390
  };
1376
- //# sourceMappingURL=run-cli-g3_uJkf5.js.map
1391
+ //# sourceMappingURL=run-cli-LDWC8vQD.js.map