@wp-playground/cli 3.0.12 → 3.0.14

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,8 +1,8 @@
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";
1
+ import { logger as p, LogSeverity as I, errorLogPath as A } from "@php-wasm/logger";
2
+ import { PHPResponse as E, 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
- import d, { mkdirSync as D } from "fs";
5
+ import c, { mkdirSync as D } from "fs";
6
6
  import { Worker as H, MessageChannel as ne } from "worker_threads";
7
7
  import { p as V, a as ae, e as le } from "./mounts-D1_eXSTw.js";
8
8
  import pe from "express";
@@ -10,7 +10,7 @@ import { FileLockManagerForNode as ue } from "@php-wasm/node";
10
10
  import q, { cpus as de } from "os";
11
11
  import { jspi as ce } from "wasm-feature-detect";
12
12
  import fe from "yargs";
13
- import c, { basename as he } from "path";
13
+ import f, { basename as he } from "path";
14
14
  import { NodeJsFilesystem as me, OverlayFilesystem as we, InMemoryFilesystem as ye, ZipFilesystem as be } from "@wp-playground/storage";
15
15
  import { EmscriptenDownloadMonitor as ge, ProgressTracker as Pe } from "@php-wasm/progress";
16
16
  import { resolveWordPressRelease as ve } from "@wp-playground/wordpress";
@@ -30,12 +30,12 @@ async function Le(e) {
30
30
  try {
31
31
  l = await e.handleRequest({
32
32
  url: i.url,
33
- headers: Be(i),
33
+ headers: $e(i),
34
34
  method: i.method,
35
35
  body: await Re(i)
36
36
  });
37
37
  } catch (a) {
38
- p.error(a), l = $.forHttpCode(500);
38
+ p.error(a), l = E.forHttpCode(500);
39
39
  }
40
40
  n.statusCode = l.httpStatusCode;
41
41
  for (const a in l.headers)
@@ -52,14 +52,14 @@ const Re = async (e) => await new Promise((r) => {
52
52
  }), e.on("end", () => {
53
53
  r(new Uint8Array(Buffer.concat(t)));
54
54
  });
55
- }), Be = (e) => {
55
+ }), $e = (e) => {
56
56
  const r = {};
57
57
  if (e.rawHeaders && e.rawHeaders.length)
58
58
  for (let t = 0; t < e.rawHeaders.length; t += 2)
59
59
  r[e.rawHeaders[t].toLowerCase()] = e.rawHeaders[t + 1];
60
60
  return r;
61
61
  };
62
- class Ie {
62
+ class Be {
63
63
  constructor(r) {
64
64
  this.workerLoads = [], this.addWorker(r);
65
65
  }
@@ -84,7 +84,7 @@ class Ie {
84
84
  function Me(e) {
85
85
  return /^latest$|^trunk$|^nightly$|^(?:(\d+)\.(\d+)(?:\.(\d+))?)((?:-beta(?:\d+)?)|(?:-RC(?:\d+)?))?$/.test(e);
86
86
  }
87
- async function Ee({
87
+ async function Ie({
88
88
  sourceString: e,
89
89
  blueprintMayReadAdjacentFiles: r
90
90
  }) {
@@ -92,22 +92,22 @@ async function Ee({
92
92
  return;
93
93
  if (e.startsWith("http://") || e.startsWith("https://"))
94
94
  return await ee(e);
95
- let t = c.resolve(process.cwd(), e);
96
- if (!d.existsSync(t))
95
+ let t = f.resolve(process.cwd(), e);
96
+ if (!c.existsSync(t))
97
97
  throw new Error(`Blueprint file does not exist: ${t}`);
98
- const s = d.statSync(t);
99
- if (s.isDirectory() && (t = c.join(t, "blueprint.json")), !s.isFile() && s.isSymbolicLink())
98
+ const s = c.statSync(t);
99
+ if (s.isDirectory() && (t = f.join(t, "blueprint.json")), !s.isFile() && s.isSymbolicLink())
100
100
  throw new Error(
101
101
  `Blueprint path is neither a file nor a directory: ${t}`
102
102
  );
103
- const o = c.extname(t);
103
+ const o = f.extname(t);
104
104
  switch (o) {
105
105
  case ".zip":
106
106
  return be.fromArrayBuffer(
107
- d.readFileSync(t).buffer
107
+ c.readFileSync(t).buffer
108
108
  );
109
109
  case ".json": {
110
- const i = d.readFileSync(t, "utf-8");
110
+ const i = c.readFileSync(t, "utf-8");
111
111
  try {
112
112
  JSON.parse(i);
113
113
  } catch {
@@ -115,7 +115,7 @@ async function Ee({
115
115
  `Blueprint file at ${t} is not a valid JSON file`
116
116
  );
117
117
  }
118
- const n = c.dirname(t), l = new me(n);
118
+ const n = f.dirname(t), l = new me(n);
119
119
  return new we([
120
120
  new ye({
121
121
  "blueprint.json": i
@@ -143,7 +143,7 @@ You can allow this Blueprint to read files from the same parent directory by exp
143
143
  );
144
144
  }
145
145
  }
146
- class $e {
146
+ class Ee {
147
147
  constructor(r, t) {
148
148
  this.lastProgressMessage = "", this.args = r, this.siteUrl = t.siteUrl, this.processIdSpaceLength = t.processIdSpaceLength, this.phpVersion = r.php;
149
149
  }
@@ -192,7 +192,7 @@ class $e {
192
192
  `));
193
193
  }
194
194
  }
195
- const T = c.join(q.homedir(), ".wordpress-playground");
195
+ const T = f.join(q.homedir(), ".wordpress-playground");
196
196
  async function Te(e) {
197
197
  return await z(
198
198
  "https://github.com/WordPress/sqlite-database-integration/archive/refs/heads/develop.zip",
@@ -201,7 +201,7 @@ async function Te(e) {
201
201
  );
202
202
  }
203
203
  async function z(e, r, t) {
204
- const s = c.join(T, r);
204
+ const s = f.join(T, r);
205
205
  return S.existsSync(s) || (S.ensureDirSync(T), await Fe(e, s, t)), O(s);
206
206
  }
207
207
  async function Fe(e, r, t) {
@@ -214,8 +214,8 @@ async function Fe(e, r, t) {
214
214
  n.close(), n.closed || await new Promise((l, a) => {
215
215
  n.on("finish", () => {
216
216
  S.renameSync(i, r), l(null);
217
- }), n.on("error", (u) => {
218
- S.removeSync(i), a(u);
217
+ }), n.on("error", (d) => {
218
+ S.removeSync(i), a(d);
219
219
  });
220
220
  });
221
221
  }
@@ -233,32 +233,32 @@ class Ce {
233
233
  let o;
234
234
  const i = new ge();
235
235
  if (!this.args.skipWordPressSetup) {
236
- let b = !1;
237
- i.addEventListener("progress", (B) => {
238
- if (b)
236
+ let y = !1;
237
+ i.addEventListener("progress", ($) => {
238
+ if (y)
239
239
  return;
240
- const { loaded: C, total: I } = B.detail, P = Math.floor(
241
- Math.min(100, 100 * C / I)
240
+ const { loaded: C, total: B } = $.detail, P = Math.floor(
241
+ Math.min(100, 100 * C / B)
242
242
  );
243
- b = P === 100, this.writeProgressUpdate(
243
+ y = P === 100, this.writeProgressUpdate(
244
244
  process.stdout,
245
245
  `Downloading WordPress ${P}%...`,
246
- b
246
+ y
247
247
  );
248
248
  }), o = await ve(this.args.wp), p.log(
249
249
  `Resolved WordPress release URL: ${o?.releaseUrl}`
250
250
  );
251
251
  }
252
- const n = o && c.join(
252
+ const n = o && f.join(
253
253
  T,
254
254
  `prebuilt-wp-content-for-wp-${o.version}.zip`
255
- ), l = o ? d.existsSync(n) ? O(n) : await z(
255
+ ), l = o ? c.existsSync(n) ? O(n) : await z(
256
256
  o.releaseUrl,
257
257
  `${o.version}.zip`,
258
258
  i
259
259
  ) : void 0;
260
260
  p.log("Fetching SQLite integration plugin...");
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);
261
+ const a = this.args.skipSqliteSetup ? void 0 : await Te(i), d = this.args.followSymlinks === !0, b = this.args.experimentalTrace === !0, W = this.args["mount-before-install"] || [], g = this.args.mount || [], m = R(r);
262
262
  await m.isConnected(), p.log("Booting WordPress...");
263
263
  const x = await te(
264
264
  this.getEffectiveBlueprint()
@@ -273,12 +273,12 @@ class Ce {
273
273
  sqliteIntegrationPluginZip: await a?.arrayBuffer(),
274
274
  firstProcessId: 0,
275
275
  processIdSpaceLength: this.processIdSpaceLength,
276
- followSymlinks: u,
277
- trace: y,
276
+ followSymlinks: d,
277
+ trace: b,
278
278
  internalCookieStore: this.args.internalCookieStore,
279
279
  withXdebug: this.args.xdebug,
280
280
  nativeInternalDirPath: s
281
- }), o && !this.args["mount-before-install"] && !d.existsSync(n) && (p.log("Caching preinstalled WordPress for the next boot..."), d.writeFileSync(
281
+ }), o && !this.args["mount-before-install"] && !c.existsSync(n) && (p.log("Caching preinstalled WordPress for the next boot..."), c.writeFileSync(
282
282
  n,
283
283
  await se(m, "/wordpress")
284
284
  ), p.log("Cached!")), m;
@@ -347,7 +347,7 @@ class Ce {
347
347
  }
348
348
  }
349
349
  async function Ue(e, r = !0) {
350
- const s = `${c.basename(process.argv0)}${e}${process.pid}-`, o = (await Se({
350
+ const s = `${f.basename(process.argv0)}${e}${process.pid}-`, o = (await Se({
351
351
  prefix: s,
352
352
  /*
353
353
  * Allow recursive cleanup on process exit.
@@ -368,7 +368,7 @@ async function Ae(e, r, t) {
368
368
  t
369
369
  )).map(
370
370
  (i) => new Promise((n) => {
371
- d.rm(i, { recursive: !0 }, (l) => {
371
+ c.rm(i, { recursive: !0 }, (l) => {
372
372
  l ? p.warn(
373
373
  `Failed to delete stale Playground temp dir: ${i}`,
374
374
  l
@@ -382,7 +382,7 @@ async function Ae(e, r, t) {
382
382
  }
383
383
  async function De(e, r, t) {
384
384
  try {
385
- const s = d.readdirSync(t).map((i) => c.join(t, i)), o = [];
385
+ const s = c.readdirSync(t).map((i) => f.join(t, i)), o = [];
386
386
  for (const i of s)
387
387
  await He(
388
388
  e,
@@ -395,9 +395,9 @@ async function De(e, r, t) {
395
395
  }
396
396
  }
397
397
  async function He(e, r, t) {
398
- if (!d.lstatSync(t).isDirectory())
398
+ if (!c.lstatSync(t).isDirectory())
399
399
  return !1;
400
- const o = c.basename(t);
400
+ const o = f.basename(t);
401
401
  if (!o.includes(e))
402
402
  return !1;
403
403
  const i = o.match(
@@ -412,7 +412,7 @@ async function He(e, r, t) {
412
412
  if (await Ve(n.pid, n.executableName))
413
413
  return !1;
414
414
  const l = Date.now() - r;
415
- return d.statSync(t).mtime.getTime() < l;
415
+ return c.statSync(t).mtime.getTime() < l;
416
416
  }
417
417
  async function Ve(e, r) {
418
418
  const [t] = await new Promise(
@@ -433,9 +433,9 @@ async function Ve(e, r) {
433
433
  return !!t && t.pid === e && t.command === r;
434
434
  }
435
435
  const F = {
436
- Quiet: { name: "quiet", severity: E.Fatal },
437
- Normal: { name: "normal", severity: E.Info },
438
- Debug: { name: "debug", severity: E.Debug }
436
+ Quiet: { name: "quiet", severity: I.Fatal },
437
+ Normal: { name: "normal", severity: I.Info },
438
+ Debug: { name: "debug", severity: I.Debug }
439
439
  };
440
440
  async function dt() {
441
441
  try {
@@ -582,7 +582,7 @@ Warning: Following symlinks will expose files outside mounted directories to Pla
582
582
  if (o["auto-mount"]) {
583
583
  let i = !1;
584
584
  try {
585
- i = d.statSync(o["auto-mount"]).isDirectory();
585
+ i = c.statSync(o["auto-mount"]).isDirectory();
586
586
  } catch {
587
587
  i = !1;
588
588
  }
@@ -655,7 +655,7 @@ async function je(e) {
655
655
  const s = [];
656
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) {
657
657
  const a = Object.values(F).find(
658
- (u) => u.name === e.verbosity
658
+ (d) => d.name === e.verbosity
659
659
  ).severity;
660
660
  p.setSeverityFilterLevel(a);
661
661
  }
@@ -670,18 +670,20 @@ async function je(e) {
670
670
  let n = !1, l = !0;
671
671
  return p.log("Starting a PHP server..."), Le({
672
672
  port: e.port,
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(
673
+ onBind: async (a, d) => {
674
+ const b = `http://127.0.0.1:${d}`, W = e["site-url"] || b, g = e.experimentalMultiWorker ?? 1, m = Math.floor(
675
675
  Number.MAX_SAFE_INTEGER / g
676
- ), x = "-playground-cli-site-", b = await Ue(
676
+ ), x = "-playground-cli-site-", y = await Ue(
677
677
  x
678
- ), B = c.dirname(b), I = 2 * 24 * 60 * 60 * 1e3;
678
+ );
679
+ p.debug(`Native temp dir for VFS root: ${y}`);
680
+ const $ = f.dirname(y), B = 2 * 24 * 60 * 60 * 1e3;
679
681
  Ae(
680
682
  x,
681
- I,
682
- B
683
+ B,
684
+ $
683
685
  );
684
- const P = c.join(b, "internal");
686
+ const P = f.join(y, "internal");
685
687
  D(P);
686
688
  const N = [
687
689
  "wordpress",
@@ -694,53 +696,63 @@ async function je(e) {
694
696
  "tmp",
695
697
  "home"
696
698
  ];
697
- for (const f of N) {
698
- const w = (h) => h.vfsPath === `/${f}`;
699
+ for (const u of N) {
700
+ const w = (h) => h.vfsPath === `/${u}`;
699
701
  if (!(e["mount-before-install"]?.some(w) || e.mount?.some(w))) {
700
- const h = c.join(
701
- b,
702
- f
702
+ const h = f.join(
703
+ y,
704
+ u
703
705
  );
704
706
  D(h), e["mount-before-install"] === void 0 && (e["mount-before-install"] = []), e["mount-before-install"].unshift({
705
- vfsPath: `/${f}`,
707
+ vfsPath: `/${u}`,
706
708
  hostPath: h
707
709
  });
708
710
  }
709
711
  }
712
+ if (e["mount-before-install"])
713
+ for (const u of e["mount-before-install"])
714
+ p.debug(
715
+ `Mount before WP install: ${u.vfsPath} -> ${u.hostPath}`
716
+ );
717
+ if (e.mount)
718
+ for (const u of e.mount)
719
+ p.debug(
720
+ `Mount after WP install: ${u.vfsPath} -> ${u.hostPath}`
721
+ );
710
722
  let v;
711
- e["experimental-blueprints-v2-runner"] ? v = new $e(e, {
723
+ e["experimental-blueprints-v2-runner"] ? v = new Ee(e, {
712
724
  siteUrl: W,
713
725
  processIdSpaceLength: m
714
726
  }) : (v = new Ce(e, {
715
727
  siteUrl: W,
716
728
  processIdSpaceLength: m
717
- }), typeof e.blueprint == "string" && (e.blueprint = await Ee({
729
+ }), typeof e.blueprint == "string" && (e.blueprint = await Ie({
718
730
  sourceString: e.blueprint,
719
731
  blueprintMayReadAdjacentFiles: e["blueprint-may-read-adjacent-files"] === !0
720
732
  })));
721
733
  const Z = _e(
722
734
  g,
723
735
  v.getWorkerType(),
724
- ({ exitCode: f, isMain: w, workerIndex: L }) => {
725
- f !== 0 && (p.error(
726
- `Worker ${L} exited with code ${f}
736
+ ({ exitCode: u, isMain: w, workerIndex: L }) => {
737
+ u !== 0 && (p.error(
738
+ `Worker ${L} exited with code ${u}
727
739
  `
728
740
  ), w && e.exitOnPrimaryWorkerCrash && process.exit(1));
729
741
  }
730
742
  );
731
743
  p.log(`Setting up WordPress ${e.wp}`);
732
744
  try {
733
- const [f, ...w] = await Z, L = await j(
745
+ const [u, ...w] = await Z, L = await j(
734
746
  i
735
747
  );
736
748
  if (t = await v.bootPrimaryWorker(
737
- f.phpPort,
749
+ u.phpPort,
738
750
  L,
739
751
  P
740
752
  ), s.push({
741
753
  playground: t,
742
- worker: f.worker
743
- }), await t.isReady(), n = !0, p.log("Booted!"), r = new Ie(t), !e["experimental-blueprints-v2-runner"]) {
754
+ worker: u.worker
755
+ }), await t.isReady(), n = !0, p.log("Booted!"), r = new Be(t), !e["experimental-blueprints-v2-runner"]) {
744
756
  const h = await v.compileInputBlueprint(
745
757
  e["additional-blueprint-steps"] || []
746
758
  );
@@ -768,14 +780,14 @@ async function je(e) {
768
780
  );
769
781
  }
770
782
  return p.log(
771
- `WordPress is running on ${y} with ${g} worker(s)`
783
+ `WordPress is running on ${b} with ${g} worker(s)`
772
784
  ), e.experimentalDevtools && e.xdebug && (await ke({
773
785
  phpInstance: t,
774
786
  phpRoot: "/wordpress"
775
787
  })).start(), {
776
788
  playground: t,
777
789
  server: a,
778
- serverUrl: y,
790
+ serverUrl: b,
779
791
  [Symbol.asyncDispose]: async function() {
780
792
  await Promise.all(
781
793
  s.map(
@@ -787,31 +799,31 @@ async function je(e) {
787
799
  },
788
800
  workerThreadCount: g
789
801
  };
790
- } catch (f) {
802
+ } catch (u) {
791
803
  if (!e.debug)
792
- throw f;
804
+ throw u;
793
805
  let w = "";
794
- throw await t?.fileExists(A) && (w = await t.readFileAsText(A)), new Error(w, { cause: f });
806
+ throw await t?.fileExists(A) && (w = await t.readFileAsText(A)), new Error(w, { cause: u });
795
807
  }
796
808
  },
797
809
  async handleRequest(a) {
798
810
  if (!n)
799
- return $.forHttpCode(
811
+ return E.forHttpCode(
800
812
  502,
801
813
  "WordPress is not ready yet"
802
814
  );
803
815
  if (l) {
804
816
  l = !1;
805
- const u = {
817
+ const d = {
806
818
  "Content-Type": ["text/plain"],
807
819
  "Content-Length": ["0"],
808
820
  Location: [a.url]
809
821
  };
810
822
  return a.headers?.cookie?.includes(
811
823
  "playground_auto_login_already_happened"
812
- ) && (u["Set-Cookie"] = [
824
+ ) && (d["Set-Cookie"] = [
813
825
  "playground_auto_login_already_happened=1; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Path=/"
814
- ]), new $(302, u, new Uint8Array());
826
+ ]), new E(302, d, new Uint8Array());
815
827
  }
816
828
  return await r.handleRequest(a);
817
829
  }
@@ -830,14 +842,14 @@ async function _e(e, r, t) {
830
842
  s.push(
831
843
  new Promise(
832
844
  (l, a) => {
833
- i.once("message", function(u) {
834
- u.command === "worker-script-initialized" && l({ worker: i, phpPort: u.phpPort });
835
- }), i.once("error", function(u) {
836
- console.error(u);
837
- const y = new Error(
838
- `Worker failed to load worker. ${u.message ? `Original error: ${u.message}` : ""}`
845
+ i.once("message", function(d) {
846
+ d.command === "worker-script-initialized" && l({ worker: i, phpPort: d.phpPort });
847
+ }), i.once("error", function(d) {
848
+ console.error(d);
849
+ const b = new Error(
850
+ `Worker failed to load worker. ${d.message ? `Original error: ${d.message}` : ""}`
839
851
  );
840
- a(y);
852
+ a(b);
841
853
  }), i.once("exit", n);
842
854
  }
843
855
  )
@@ -874,11 +886,11 @@ async function ze(e, r) {
874
886
  `
875
887
  });
876
888
  const t = await e.readFileAsBuffer("/tmp/build.zip");
877
- d.writeFileSync(r, t);
889
+ c.writeFileSync(r, t);
878
890
  }
879
891
  export {
880
892
  F as L,
881
893
  dt as p,
882
894
  je as r
883
895
  };
884
- //# sourceMappingURL=run-cli-BRWTcRHa.js.map
896
+ //# sourceMappingURL=run-cli-C0WqHEVM.js.map