@wp-playground/cli 3.0.6 → 3.0.12

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
- import { logger as p, LogSeverity as E, errorLogPath as U } from "@php-wasm/logger";
2
- import { consumeAPI as R, SupportedPHPVersions as X, printDebugDetails as Y, PHPResponse as C, exposeAPI as G, exposeSyncAPI as K } from "@php-wasm/universal";
1
+ import { logger as p, LogSeverity as E, errorLogPath as A } from "@php-wasm/logger";
2
+ import { PHPResponse as $, consumeAPI as R, SupportedPHPVersions as X, printDebugDetails as Y, exposeAPI as G, exposeSyncAPI as K } from "@php-wasm/universal";
3
3
  import { resolveRemoteBlueprint as ee, resolveRuntimeConfiguration as te, compileBlueprintV1 as re, isBlueprintBundle as oe, runBlueprintV1Steps as ie } from "@wp-playground/blueprints";
4
4
  import { zipDirectory as se, RecommendedPHPVersion as _ } from "@wp-playground/common";
5
5
  import d, { mkdirSync as D } from "fs";
@@ -11,8 +11,8 @@ import q, { cpus as de } from "os";
11
11
  import { jspi as ce } from "wasm-feature-detect";
12
12
  import fe from "yargs";
13
13
  import c, { basename as he } from "path";
14
- import { NodeJsFilesystem as me, OverlayFilesystem as we, InMemoryFilesystem as ye, ZipFilesystem as ge } from "@wp-playground/storage";
15
- import { EmscriptenDownloadMonitor as be, ProgressTracker as Pe } from "@php-wasm/progress";
14
+ import { NodeJsFilesystem as me, OverlayFilesystem as we, InMemoryFilesystem as ye, ZipFilesystem as be } from "@wp-playground/storage";
15
+ import { EmscriptenDownloadMonitor as ge, ProgressTracker as Pe } from "@php-wasm/progress";
16
16
  import { resolveWordPressRelease as ve } from "@wp-playground/wordpress";
17
17
  import S from "fs-extra";
18
18
  import { startBridge as ke } from "@php-wasm/xdebug-bridge";
@@ -20,22 +20,27 @@ import { dir as Se, setGracefulCleanup as xe } from "tmp-promise";
20
20
  import We from "ps-man";
21
21
  async function Le(e) {
22
22
  const r = pe(), t = await new Promise((i, n) => {
23
- const a = r.listen(e.port, () => {
24
- const l = a.address();
25
- l === null || typeof l == "string" ? n(new Error("Server address is not available")) : i(a);
23
+ const l = r.listen(e.port, () => {
24
+ const a = l.address();
25
+ a === null || typeof a == "string" ? n(new Error("Server address is not available")) : i(l);
26
26
  });
27
27
  });
28
28
  r.use("/", async (i, n) => {
29
- const a = await e.handleRequest({
30
- url: i.url,
31
- headers: Be(i),
32
- method: i.method,
33
- body: await Re(i)
34
- });
35
- n.statusCode = a.httpStatusCode;
36
- for (const l in a.headers)
37
- n.setHeader(l, a.headers[l]);
38
- n.end(a.bytes);
29
+ let l;
30
+ try {
31
+ l = await e.handleRequest({
32
+ url: i.url,
33
+ headers: Be(i),
34
+ method: i.method,
35
+ body: await Re(i)
36
+ });
37
+ } catch (a) {
38
+ p.error(a), l = $.forHttpCode(500);
39
+ }
40
+ n.statusCode = l.httpStatusCode;
41
+ for (const a in l.headers)
42
+ n.setHeader(a, l.headers[a]);
43
+ n.end(l.bytes);
39
44
  });
40
45
  const o = t.address().port;
41
46
  return await e.onBind(t, o);
@@ -98,7 +103,7 @@ async function Ee({
98
103
  const o = c.extname(t);
99
104
  switch (o) {
100
105
  case ".zip":
101
- return ge.fromArrayBuffer(
106
+ return be.fromArrayBuffer(
102
107
  d.readFileSync(t).buffer
103
108
  );
104
109
  case ".json": {
@@ -110,7 +115,7 @@ async function Ee({
110
115
  `Blueprint file at ${t} is not a valid JSON file`
111
116
  );
112
117
  }
113
- const n = c.dirname(t), a = new me(n);
118
+ const n = c.dirname(t), l = new me(n);
114
119
  return new we([
115
120
  new ye({
116
121
  "blueprint.json": i
@@ -120,14 +125,14 @@ async function Ee({
120
125
  * unless the user explicitly allowed it.
121
126
  */
122
127
  {
123
- read(l) {
128
+ read(a) {
124
129
  if (!r)
125
130
  throw new Error(
126
- `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.
131
+ `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.
127
132
 
128
133
  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.`
129
134
  );
130
- return a.read(l);
135
+ return l.read(a);
131
136
  }
132
137
  }
133
138
  ]);
@@ -187,7 +192,7 @@ class $e {
187
192
  `));
188
193
  }
189
194
  }
190
- const $ = c.join(q.homedir(), ".wordpress-playground");
195
+ const T = c.join(q.homedir(), ".wordpress-playground");
191
196
  async function Te(e) {
192
197
  return await z(
193
198
  "https://github.com/WordPress/sqlite-database-integration/archive/refs/heads/develop.zip",
@@ -196,28 +201,28 @@ async function Te(e) {
196
201
  );
197
202
  }
198
203
  async function z(e, r, t) {
199
- const s = c.join($, r);
200
- return S.existsSync(s) || (S.ensureDirSync($), await Fe(e, s, t)), O(s);
204
+ const s = c.join(T, r);
205
+ return S.existsSync(s) || (S.ensureDirSync(T), await Fe(e, s, t)), O(s);
201
206
  }
202
207
  async function Fe(e, r, t) {
203
208
  const o = (await t.monitorFetch(fetch(e))).body.getReader(), i = `${r}.partial`, n = S.createWriteStream(i);
204
209
  for (; ; ) {
205
- const { done: a, value: l } = await o.read();
206
- if (l && n.write(l), a)
210
+ const { done: l, value: a } = await o.read();
211
+ if (a && n.write(a), l)
207
212
  break;
208
213
  }
209
- n.close(), n.closed || await new Promise((a, l) => {
214
+ n.close(), n.closed || await new Promise((l, a) => {
210
215
  n.on("finish", () => {
211
- S.renameSync(i, r), a(null);
216
+ S.renameSync(i, r), l(null);
212
217
  }), n.on("error", (u) => {
213
- S.removeSync(i), l(u);
218
+ S.removeSync(i), a(u);
214
219
  });
215
220
  });
216
221
  }
217
222
  function O(e, r) {
218
223
  return new File([S.readFileSync(e)], he(e));
219
224
  }
220
- class Ae {
225
+ class Ce {
221
226
  constructor(r, t) {
222
227
  this.lastProgressMessage = "", this.args = r, this.siteUrl = t.siteUrl, this.processIdSpaceLength = t.processIdSpaceLength;
223
228
  }
@@ -226,34 +231,34 @@ class Ae {
226
231
  }
227
232
  async bootPrimaryWorker(r, t, s) {
228
233
  let o;
229
- const i = new be();
234
+ const i = new ge();
230
235
  if (!this.args.skipWordPressSetup) {
231
- let g = !1;
236
+ let b = !1;
232
237
  i.addEventListener("progress", (B) => {
233
- if (g)
238
+ if (b)
234
239
  return;
235
- const { loaded: F, total: I } = B.detail, v = Math.floor(
236
- Math.min(100, 100 * F / I)
240
+ const { loaded: C, total: I } = B.detail, P = Math.floor(
241
+ Math.min(100, 100 * C / I)
237
242
  );
238
- g = v === 100, this.writeProgressUpdate(
243
+ b = P === 100, this.writeProgressUpdate(
239
244
  process.stdout,
240
- `Downloading WordPress ${v}%...`,
241
- g
245
+ `Downloading WordPress ${P}%...`,
246
+ b
242
247
  );
243
248
  }), o = await ve(this.args.wp), p.log(
244
249
  `Resolved WordPress release URL: ${o?.releaseUrl}`
245
250
  );
246
251
  }
247
252
  const n = o && c.join(
248
- $,
253
+ T,
249
254
  `prebuilt-wp-content-for-wp-${o.version}.zip`
250
- ), a = o ? d.existsSync(n) ? O(n) : await z(
255
+ ), l = o ? d.existsSync(n) ? O(n) : await z(
251
256
  o.releaseUrl,
252
257
  `${o.version}.zip`,
253
258
  i
254
259
  ) : void 0;
255
260
  p.log("Fetching SQLite integration plugin...");
256
- const l = this.args.skipSqliteSetup ? void 0 : await Te(i), u = this.args.followSymlinks === !0, b = this.args.experimentalTrace === !0, W = this.args["mount-before-install"] || [], P = this.args.mount || [], m = R(r);
261
+ const a = this.args.skipSqliteSetup ? void 0 : await Te(i), u = this.args.followSymlinks === !0, y = this.args.experimentalTrace === !0, W = this.args["mount-before-install"] || [], g = this.args.mount || [], m = R(r);
257
262
  await m.isConnected(), p.log("Booting WordPress...");
258
263
  const x = await te(
259
264
  this.getEffectiveBlueprint()
@@ -263,13 +268,13 @@ class Ae {
263
268
  wpVersion: x.wpVersion,
264
269
  siteUrl: this.siteUrl,
265
270
  mountsBeforeWpInstall: W,
266
- mountsAfterWpInstall: P,
267
- wordPressZip: a && await a.arrayBuffer(),
268
- sqliteIntegrationPluginZip: await l?.arrayBuffer(),
271
+ mountsAfterWpInstall: g,
272
+ wordPressZip: l && await l.arrayBuffer(),
273
+ sqliteIntegrationPluginZip: await a?.arrayBuffer(),
269
274
  firstProcessId: 0,
270
275
  processIdSpaceLength: this.processIdSpaceLength,
271
276
  followSymlinks: u,
272
- trace: b,
277
+ trace: y,
273
278
  internalCookieStore: this.args.internalCookieStore,
274
279
  withXdebug: this.args.xdebug,
275
280
  nativeInternalDirPath: s
@@ -310,12 +315,12 @@ class Ae {
310
315
  if (i)
311
316
  return;
312
317
  i = n.detail.progress === 100;
313
- const a = Math.floor(n.detail.progress);
318
+ const l = Math.floor(n.detail.progress);
314
319
  o = n.detail.caption || o || "Running the Blueprint";
315
- const l = `${o.trim()} – ${a}%`;
320
+ const a = `${o.trim()} – ${l}%`;
316
321
  this.writeProgressUpdate(
317
322
  process.stdout,
318
- l,
323
+ a,
319
324
  i
320
325
  );
321
326
  }), await re(t, {
@@ -336,7 +341,7 @@ class Ae {
336
341
  };
337
342
  }
338
343
  writeProgressUpdate(r, t, s) {
339
- this.args.verbosity !== T.Quiet.name && t !== this.lastProgressMessage && (this.lastProgressMessage = t, r.isTTY ? (r.cursorTo(0), r.write(t), r.clearLine(1), s && r.write(`
344
+ this.args.verbosity !== F.Quiet.name && t !== this.lastProgressMessage && (this.lastProgressMessage = t, r.isTTY ? (r.cursorTo(0), r.write(t), r.clearLine(1), s && r.write(`
340
345
  `)) : r.write(`${t}
341
346
  `));
342
347
  }
@@ -356,17 +361,17 @@ async function Ue(e, r = !0) {
356
361
  })).path;
357
362
  return r && xe(), o;
358
363
  }
359
- async function Ce(e, r, t) {
364
+ async function Ae(e, r, t) {
360
365
  const o = (await De(
361
366
  e,
362
367
  r,
363
368
  t
364
369
  )).map(
365
370
  (i) => new Promise((n) => {
366
- d.rm(i, { recursive: !0 }, (a) => {
367
- a ? p.warn(
371
+ d.rm(i, { recursive: !0 }, (l) => {
372
+ l ? p.warn(
368
373
  `Failed to delete stale Playground temp dir: ${i}`,
369
- a
374
+ l
370
375
  ) : p.info(
371
376
  `Deleted stale Playground temp dir: ${i}`
372
377
  ), n();
@@ -406,8 +411,8 @@ async function He(e, r, t) {
406
411
  };
407
412
  if (await Ve(n.pid, n.executableName))
408
413
  return !1;
409
- const a = Date.now() - r;
410
- return d.statSync(t).mtime.getTime() < a;
414
+ const l = Date.now() - r;
415
+ return d.statSync(t).mtime.getTime() < l;
411
416
  }
412
417
  async function Ve(e, r) {
413
418
  const [t] = await new Promise(
@@ -427,7 +432,7 @@ async function Ve(e, r) {
427
432
  );
428
433
  return !!t && t.pid === e && t.command === r;
429
434
  }
430
- const T = {
435
+ const F = {
431
436
  Quiet: { name: "quiet", severity: E.Fatal },
432
437
  Normal: { name: "normal", severity: E.Info },
433
438
  Debug: { name: "debug", severity: E.Debug }
@@ -507,7 +512,7 @@ async function dt() {
507
512
  }).option("verbosity", {
508
513
  describe: "Output logs and progress messages.",
509
514
  type: "string",
510
- choices: Object.values(T).map(
515
+ choices: Object.values(F).map(
511
516
  (o) => o.name
512
517
  ),
513
518
  default: "normal"
@@ -649,35 +654,35 @@ async function je(e) {
649
654
  let r, t;
650
655
  const s = [];
651
656
  if (e.autoMount !== void 0 && (e.autoMount === "" && (e = { ...e, autoMount: process.cwd() }), e = le(e)), e.quiet && (e.verbosity = "quiet", delete e.quiet), e.debug ? e.verbosity = "debug" : e.verbosity === "debug" && (e.debug = !0), e.verbosity) {
652
- const l = Object.values(T).find(
657
+ const a = Object.values(F).find(
653
658
  (u) => u.name === e.verbosity
654
659
  ).severity;
655
- p.setSeverityFilterLevel(l);
660
+ p.setSeverityFilterLevel(a);
656
661
  }
657
662
  const o = q.platform() === "win32" ? (
658
663
  // @TODO: Enable fs-ext here when it works with Windows.
659
664
  void 0
660
- ) : await import("fs-ext").then((l) => l.flockSync).catch(() => {
665
+ ) : await import("fs-ext").then((a) => a.flockSync).catch(() => {
661
666
  p.warn(
662
667
  "The fs-ext package is not installed. Internal file locking will not be integrated with host OS file locking."
663
668
  );
664
669
  }), i = new ue(o);
665
- let n = !1, a = !0;
670
+ let n = !1, l = !0;
666
671
  return p.log("Starting a PHP server..."), Le({
667
672
  port: e.port,
668
- onBind: async (l, u) => {
669
- const b = `http://127.0.0.1:${u}`, W = e["site-url"] || b, P = e.experimentalMultiWorker ?? 1, m = Math.floor(
670
- Number.MAX_SAFE_INTEGER / P
671
- ), x = "-playground-cli-site-", g = await Ue(
673
+ onBind: async (a, u) => {
674
+ const y = `http://127.0.0.1:${u}`, W = e["site-url"] || y, g = e.experimentalMultiWorker ?? 1, m = Math.floor(
675
+ Number.MAX_SAFE_INTEGER / g
676
+ ), x = "-playground-cli-site-", b = await Ue(
672
677
  x
673
- ), B = c.dirname(g), I = 2 * 24 * 60 * 60 * 1e3;
674
- Ce(
678
+ ), B = c.dirname(b), I = 2 * 24 * 60 * 60 * 1e3;
679
+ Ae(
675
680
  x,
676
681
  I,
677
682
  B
678
683
  );
679
- const v = c.join(g, "internal");
680
- D(v);
684
+ const P = c.join(b, "internal");
685
+ D(P);
681
686
  const N = [
682
687
  "wordpress",
683
688
  // Note: These dirs are from Emscripten's "default dirs" list:
@@ -693,7 +698,7 @@ async function je(e) {
693
698
  const w = (h) => h.vfsPath === `/${f}`;
694
699
  if (!(e["mount-before-install"]?.some(w) || e.mount?.some(w))) {
695
700
  const h = c.join(
696
- g,
701
+ b,
697
702
  f
698
703
  );
699
704
  D(h), e["mount-before-install"] === void 0 && (e["mount-before-install"] = []), e["mount-before-install"].unshift({
@@ -702,11 +707,11 @@ async function je(e) {
702
707
  });
703
708
  }
704
709
  }
705
- let k;
706
- e["experimental-blueprints-v2-runner"] ? k = new $e(e, {
710
+ let v;
711
+ e["experimental-blueprints-v2-runner"] ? v = new $e(e, {
707
712
  siteUrl: W,
708
713
  processIdSpaceLength: m
709
- }) : (k = new Ae(e, {
714
+ }) : (v = new Ce(e, {
710
715
  siteUrl: W,
711
716
  processIdSpaceLength: m
712
717
  }), typeof e.blueprint == "string" && (e.blueprint = await Ee({
@@ -714,8 +719,8 @@ async function je(e) {
714
719
  blueprintMayReadAdjacentFiles: e["blueprint-may-read-adjacent-files"] === !0
715
720
  })));
716
721
  const Z = _e(
717
- P,
718
- k.getWorkerType(),
722
+ g,
723
+ v.getWorkerType(),
719
724
  ({ exitCode: f, isMain: w, workerIndex: L }) => {
720
725
  f !== 0 && (p.error(
721
726
  `Worker ${L} exited with code ${f}
@@ -728,15 +733,15 @@ async function je(e) {
728
733
  const [f, ...w] = await Z, L = await j(
729
734
  i
730
735
  );
731
- if (t = await k.bootPrimaryWorker(
736
+ if (t = await v.bootPrimaryWorker(
732
737
  f.phpPort,
733
738
  L,
734
- v
739
+ P
735
740
  ), s.push({
736
741
  playground: t,
737
742
  worker: f.worker
738
743
  }), await t.isReady(), n = !0, p.log("Booted!"), r = new Ie(t), !e["experimental-blueprints-v2-runner"]) {
739
- const h = await k.compileInputBlueprint(
744
+ const h = await v.compileInputBlueprint(
740
745
  e["additional-blueprint-steps"] || []
741
746
  );
742
747
  h && (p.log("Running the Blueprint..."), await ie(
@@ -748,89 +753,91 @@ async function je(e) {
748
753
  p.log("Preparing additional workers...");
749
754
  const h = m;
750
755
  await Promise.all(
751
- w.map(async (y, M) => {
752
- const J = h + M * m, Q = await j(i), A = await k.bootSecondaryWorker({
753
- worker: y,
756
+ w.map(async (k, M) => {
757
+ const J = h + M * m, Q = await j(i), U = await v.bootSecondaryWorker({
758
+ worker: k,
754
759
  fileLockManagerPort: Q,
755
760
  firstProcessId: J,
756
- nativeInternalDirPath: v
761
+ nativeInternalDirPath: P
757
762
  });
758
763
  s.push({
759
- playground: A,
760
- worker: y.worker
761
- }), r.addWorker(A);
764
+ playground: U,
765
+ worker: k.worker
766
+ }), r.addWorker(U);
762
767
  })
763
768
  );
764
769
  }
765
770
  return p.log(
766
- `WordPress is running on ${b} with ${P} worker(s)`
771
+ `WordPress is running on ${y} with ${g} worker(s)`
767
772
  ), e.experimentalDevtools && e.xdebug && (await ke({
768
- getPHPFile: async (y) => await t.readFileAsText(y)
773
+ phpInstance: t,
774
+ phpRoot: "/wordpress"
769
775
  })).start(), {
770
776
  playground: t,
771
- server: l,
777
+ server: a,
778
+ serverUrl: y,
772
779
  [Symbol.asyncDispose]: async function() {
773
780
  await Promise.all(
774
781
  s.map(
775
- async ({ playground: y, worker: M }) => {
776
- await y.dispose(), await M.terminate();
782
+ async ({ playground: k, worker: M }) => {
783
+ await k.dispose(), await M.terminate();
777
784
  }
778
785
  )
779
- ), await new Promise((y) => l.close(y));
786
+ ), await new Promise((k) => a.close(k));
780
787
  },
781
- workerThreadCount: P
788
+ workerThreadCount: g
782
789
  };
783
790
  } catch (f) {
784
791
  if (!e.debug)
785
792
  throw f;
786
793
  let w = "";
787
- throw await t?.fileExists(U) && (w = await t.readFileAsText(U)), new Error(w, { cause: f });
794
+ throw await t?.fileExists(A) && (w = await t.readFileAsText(A)), new Error(w, { cause: f });
788
795
  }
789
796
  },
790
- async handleRequest(l) {
797
+ async handleRequest(a) {
791
798
  if (!n)
792
- return C.forHttpCode(
799
+ return $.forHttpCode(
793
800
  502,
794
801
  "WordPress is not ready yet"
795
802
  );
796
- if (a) {
797
- a = !1;
803
+ if (l) {
804
+ l = !1;
798
805
  const u = {
799
806
  "Content-Type": ["text/plain"],
800
807
  "Content-Length": ["0"],
801
- Location: ["/"]
808
+ Location: [a.url]
802
809
  };
803
- return l.headers?.cookie?.includes(
810
+ return a.headers?.cookie?.includes(
804
811
  "playground_auto_login_already_happened"
805
812
  ) && (u["Set-Cookie"] = [
806
813
  "playground_auto_login_already_happened=1; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Path=/"
807
- ]), new C(302, u, new Uint8Array());
814
+ ]), new $(302, u, new Uint8Array());
808
815
  }
809
- return await r.handleRequest(l);
816
+ return await r.handleRequest(a);
810
817
  }
811
818
  });
812
819
  }
813
820
  async function _e(e, r, t) {
814
821
  const s = [];
815
822
  for (let o = 0; o < e; o++) {
816
- const i = await qe(r), n = (a) => {
823
+ const i = await qe(r), n = (l) => {
817
824
  t({
818
- exitCode: a,
825
+ exitCode: l,
819
826
  isMain: o === 0,
820
827
  workerIndex: o
821
828
  });
822
829
  };
823
830
  s.push(
824
831
  new Promise(
825
- (a, l) => {
832
+ (l, a) => {
826
833
  i.once("message", function(u) {
827
- u.command === "worker-script-initialized" && a({ worker: i, phpPort: u.phpPort });
834
+ u.command === "worker-script-initialized" && l({ worker: i, phpPort: u.phpPort });
828
835
  }), i.once("error", function(u) {
829
836
  console.error(u);
830
- const b = new Error(
837
+ const y = new Error(
831
838
  `Worker failed to load worker. ${u.message ? `Original error: ${u.message}` : ""}`
832
839
  );
833
- l(b);
840
+ a(y);
834
841
  }), i.once("exit", n);
835
842
  }
836
843
  )
@@ -870,8 +877,8 @@ async function ze(e, r) {
870
877
  d.writeFileSync(r, t);
871
878
  }
872
879
  export {
873
- T as L,
880
+ F as L,
874
881
  dt as p,
875
882
  je as r
876
883
  };
877
- //# sourceMappingURL=run-cli-Md2TQOSk.js.map
884
+ //# sourceMappingURL=run-cli-BRWTcRHa.js.map