@wp-playground/cli 3.0.54 → 3.1.0

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,59 +1,58 @@
1
- import { logger as M, errorLogPath as S } from "@php-wasm/logger";
2
- import { createNodeFsMountHandler as R, loadNodeRuntime as F } from "@php-wasm/node";
3
- import { EmscriptenDownloadMonitor as B } from "@php-wasm/progress";
4
- import { exposeAPI as _, PHPWorker as L, consumeAPI as I, consumeAPISync as q, sandboxedSpawnHandlerFactory as x, PHPResponse as E, PHPExecutionFailureError as C } from "@php-wasm/universal";
5
- import { sprintf as N } from "@php-wasm/util";
1
+ import { logger as T, errorLogPath as H } from "@php-wasm/logger";
2
+ import { createNodeFsMountHandler as W, loadNodeRuntime as M, bindUserSpace as $ } from "@php-wasm/node";
3
+ import { EmscriptenDownloadMonitor as I } from "@php-wasm/progress";
4
+ import { exposeAPI as v, PHPWorker as A, consumeAPISync as S, setPhpIniEntries as L, writeFiles as B, sandboxedSpawnHandlerFactory as C, PHPResponse as E, PHPExecutionFailureError as F, consumeAPI as g, releaseApiProxy as U } from "@php-wasm/universal";
5
+ import { joinPaths as q, sprintf as D } from "@php-wasm/util";
6
6
  import { runBlueprintV2 as O } from "@wp-playground/blueprints";
7
- import { bootRequestHandler as j } from "@wp-playground/wordpress";
8
- import { existsSync as V } from "fs";
9
- import W from "path";
10
- import { rootCertificates as D } from "tls";
11
- import { MessageChannel as U, parentPort as Y } from "worker_threads";
12
- import { jspi as z } from "wasm-feature-detect";
13
- import { s as K, b as G } from "./run-cli-Cxpf7CoX.js";
14
- async function m(s, e) {
15
- for (const r of e)
7
+ import { setupPlatformLevelMuPlugins as j, preloadPhpInfoRoute as V, bootRequestHandler as N } from "@wp-playground/wordpress";
8
+ import { existsSync as G } from "fs";
9
+ import m from "path";
10
+ import { rootCertificates as Y } from "tls";
11
+ import { MessageChannel as z, parentPort as K } from "worker_threads";
12
+ import { s as J, b as Q } from "./run-cli-BzYAH0YF.js";
13
+ async function b(s, e) {
14
+ for (const t of e)
16
15
  try {
17
- s.mkdir(r.vfsPath), await s.mount(
18
- r.vfsPath,
19
- R(r.hostPath)
16
+ s.mkdir(t.vfsPath), await s.mount(
17
+ t.vfsPath,
18
+ W(t.hostPath)
20
19
  );
21
20
  } catch {
22
- i.stderr(
23
- `\x1B[31m\x1B[1mError mounting path ${r.hostPath} at ${r.vfsPath}\x1B[0m
21
+ a.stderr(
22
+ `\x1B[31m\x1B[1mError mounting path ${t.hostPath} at ${t.vfsPath}\x1B[0m
24
23
  `
25
24
  ), process.exit(1);
26
25
  }
27
26
  }
28
- function J(s, e, ...r) {
27
+ function X(s, e, ...t) {
29
28
  console.log(
30
29
  performance.now().toFixed(6).padStart(15, "0"),
31
30
  s.toString().padStart(16, "0"),
32
- N(e, ...r)
31
+ D(e, ...t)
33
32
  );
34
33
  }
35
34
  Object.defineProperty(process.stdout, "isTTY", { value: !0 });
36
35
  Object.defineProperty(process.stderr, "isTTY", { value: !0 });
37
- const i = {
36
+ const a = {
38
37
  lastWriteWasProgress: !1,
39
38
  progress(s) {
40
- G(process.stdout) && (process.stdout.isTTY ? (i.lastWriteWasProgress || process.stdout.write(`
41
- `), process.stdout.write("\r\x1B[K" + s), i.lastWriteWasProgress = !0) : console.log(s));
39
+ Q(process.stdout) && (process.stdout.isTTY ? (a.lastWriteWasProgress || process.stdout.write(`
40
+ `), process.stdout.write("\r\x1B[K" + s), a.lastWriteWasProgress = !0) : console.log(s));
42
41
  },
43
42
  stdout(s) {
44
43
  process.stdout.write(`
45
44
 
46
45
 
47
- `), i.lastWriteWasProgress && (i.lastWriteWasProgress = !1), process.stdout.write(s);
46
+ `), a.lastWriteWasProgress && (a.lastWriteWasProgress = !1), process.stdout.write(s);
48
47
  },
49
48
  stderr(s) {
50
49
  process.stdout.write(`
51
50
 
52
51
 
53
- `), i.lastWriteWasProgress && (i.lastWriteWasProgress = !1), process.stderr.write(s);
52
+ `), a.lastWriteWasProgress && (a.lastWriteWasProgress = !1), process.stderr.write(s);
54
53
  }
55
54
  };
56
- class Q extends L {
55
+ class Z extends A {
57
56
  constructor(e) {
58
57
  super(void 0, e), this.booted = !1, this.blueprintTargetResolved = !1, this.phpInstancesThatNeedMountsAfterTargetResolved = /* @__PURE__ */ new Set();
59
58
  }
@@ -67,76 +66,67 @@ class Q extends L {
67
66
  * @see phpwasm-emscripten-library-file-locking-for-node.js
68
67
  */
69
68
  async useFileLockManager(e) {
70
- await z() ? this.fileLockManager = I(e) : this.fileLockManager = await q(e);
69
+ this.fileLockManager = await S(e);
71
70
  }
72
- async bootAndSetUpInitialWorker(e) {
73
- const r = {
74
- ...e.constants || {}
75
- }, c = {
76
- ...e,
77
- createFiles: {
78
- "/internal/shared/ca-bundle.crt": D.join(`
71
+ async bootWordPress(e, t) {
72
+ const o = await this.__internal_getRequestHandler().getPrimaryPhp();
73
+ if (o.defineConstant("WP_DEBUG", "true"), o.defineConstant("WP_DEBUG_LOG", "true"), o.defineConstant("WP_DEBUG_DISPLAY", "false"), o.defineConstant("WP_HOME", e.siteUrl), o.defineConstant("WP_SITEURL", e.siteUrl), await L(o, {
74
+ "openssl.cafile": "/internal/shared/ca-bundle.crt",
75
+ allow_url_fopen: "1",
76
+ disable_functions: ""
77
+ }), await j(o), await B(o, "/", {
78
+ "/internal/shared/ca-bundle.crt": Y.join(`
79
79
  `)
80
- },
81
- constants: r,
82
- phpIniEntries: {
83
- "openssl.cafile": "/internal/shared/ca-bundle.crt"
84
- },
85
- onPHPInstanceCreated: async (o) => {
86
- await m(o, e.mountsBeforeWpInstall || []), this.blueprintTargetResolved ? await m(o, e.mountsAfterWpInstall || []) : (this.phpInstancesThatNeedMountsAfterTargetResolved.add(o), o.addEventListener("runtime.beforeExit", () => {
87
- this.phpInstancesThatNeedMountsAfterTargetResolved.delete(
88
- o
89
- );
90
- }));
91
- },
92
- spawnHandler: () => x(
93
- () => T(e, this.fileLockManager)
94
- )
95
- };
96
- await this.bootRequestHandler(c);
97
- const p = this.__internal_getPHP();
98
- if (e.mode === "mount-only") {
99
- await m(p, e.mountsAfterWpInstall || []);
80
+ }), await V(
81
+ o,
82
+ q(new URL(e.siteUrl).pathname, "phpinfo.php")
83
+ ), e.mode === "mount-only") {
84
+ await this.applyPostInstallMountsToAllWorkers(
85
+ t
86
+ );
100
87
  return;
101
88
  }
102
- await this.runBlueprintV2({
103
- ...e,
104
- mountsAfterWpInstall: e.mountsAfterWpInstall || []
105
- });
89
+ await this.runBlueprintV2(
90
+ {
91
+ // TODO: Do we really want to create a new object or can we pass args directly?
92
+ ...e
93
+ },
94
+ t
95
+ );
106
96
  }
107
97
  async bootWorker(e) {
108
98
  await this.bootRequestHandler({
109
99
  ...e,
110
- onPHPInstanceCreated: async (r) => {
111
- await m(r, e.mountsBeforeWpInstall || []), await m(r, e.mountsAfterWpInstall || []), r.isDir("/wordpress/wp-content") || r.mkdir("/wordpress/wp-content"), r.isDir("/wordpress/wp-content/database") || r.mkdir("/wordpress/wp-content/database"), r.isFile("/wordpress/wp-content/database/.htaccess") || r.writeFile(
100
+ onPHPInstanceCreated: async (t) => {
101
+ await b(t, e.mountsBeforeWpInstall || []), await b(t, e.mountsAfterWpInstall || []), t.isDir("/wordpress/wp-content") || t.mkdir("/wordpress/wp-content"), t.isDir("/wordpress/wp-content/database") || t.mkdir("/wordpress/wp-content/database"), t.isFile("/wordpress/wp-content/database/.htaccess") || t.writeFile(
112
102
  "/wordpress/wp-content/database/.htaccess",
113
103
  "deny from all"
114
- ), r.isFile("/wordpress/wp-content/database/index.php") || r.writeFile(
104
+ ), t.isFile("/wordpress/wp-content/database/index.php") || t.writeFile(
115
105
  "/wordpress/wp-content/database/index.php",
116
106
  "deny from all"
117
107
  );
118
108
  },
119
- spawnHandler: () => x(
120
- () => T(e, this.fileLockManager)
109
+ spawnHandler: () => C(
110
+ () => ee(e, this.fileLockManager)
121
111
  )
122
112
  });
123
113
  }
124
- async runBlueprintV2(e) {
125
- const r = this.__internal_getRequestHandler(), { php: c, reap: p } = await r.instanceManager.acquirePHPInstance(), o = this.__internal_getPHP();
126
- let u = () => {
114
+ async runBlueprintV2(e, t) {
115
+ const o = this.__internal_getRequestHandler(), { php: u, reap: h } = await o.instanceManager.acquirePHPInstance(), w = this.__internal_getPHP();
116
+ let f = () => {
127
117
  };
128
118
  if (typeof e.blueprint == "string") {
129
- const n = W.resolve(process.cwd(), e.blueprint);
130
- V(n) && (o.mkdir("/internal/shared/cwd"), u = await o.mount(
119
+ const n = m.resolve(process.cwd(), e.blueprint);
120
+ G(n) && (w.mkdir("/internal/shared/cwd"), f = await w.mount(
131
121
  "/internal/shared/cwd",
132
- R(W.dirname(n))
133
- ), e.blueprint = W.join(
122
+ W(m.dirname(n))
123
+ ), e.blueprint = m.join(
134
124
  "/internal/shared/cwd",
135
- W.basename(e.blueprint)
125
+ m.basename(e.blueprint)
136
126
  ));
137
127
  }
138
128
  try {
139
- const l = [
129
+ const i = [
140
130
  "mode",
141
131
  "db-engine",
142
132
  "db-host",
@@ -146,47 +136,40 @@ class Q extends L {
146
136
  "db-path",
147
137
  "truncate-new-site-directory",
148
138
  "allow"
149
- ].filter((t) => t in e).map((t) => `--${t}=${e[t]}`);
150
- l.push(`--site-url=${e.siteUrl}`);
151
- const d = await O({
152
- php: c,
139
+ ].filter((r) => r in e).map((r) => `--${r}=${e[r]}`);
140
+ i.push(`--site-url=${e.siteUrl}`);
141
+ const l = await O({
142
+ php: u,
153
143
  blueprint: e.blueprint,
154
144
  blueprintOverrides: {
155
145
  additionalSteps: e["additional-blueprint-steps"],
156
146
  wordpressVersion: e.wp
157
147
  },
158
- cliArgs: l,
159
- onMessage: async (t) => {
160
- switch (t.type) {
148
+ cliArgs: i,
149
+ onMessage: async (r) => {
150
+ switch (r.type) {
161
151
  case "blueprint.target_resolved": {
162
- if (!this.blueprintTargetResolved) {
163
- this.blueprintTargetResolved = !0;
164
- for (const a of this.phpInstancesThatNeedMountsAfterTargetResolved)
165
- this.phpInstancesThatNeedMountsAfterTargetResolved.delete(
166
- a
167
- ), await m(
168
- a,
169
- e.mountsAfterWpInstall || []
170
- );
171
- }
152
+ this.blueprintTargetResolved || (this.blueprintTargetResolved = !0, await this.applyPostInstallMountsToAllWorkers(
153
+ t
154
+ ));
172
155
  break;
173
156
  }
174
157
  case "blueprint.progress": {
175
- const a = `${t.caption.trim()} – ${t.progress.toFixed(
158
+ const p = `${r.caption.trim()} – ${r.progress.toFixed(
176
159
  2
177
160
  )}%`;
178
- i.progress(a);
161
+ a.progress(p);
179
162
  break;
180
163
  }
181
164
  case "blueprint.error": {
182
- const a = "\x1B[31m", w = "\x1B[1m", f = "\x1B[0m";
183
- e.verbosity === "debug" && t.details ? i.stderr(
184
- `${a}${w}Fatal error:${f} Uncaught ${t.details.exception}: ${t.details.message}
185
- at ${t.details.file}:${t.details.line}
186
- ` + (t.details.trace ? t.details.trace + `
165
+ const p = "\x1B[31m", c = "\x1B[1m", d = "\x1B[0m";
166
+ e.verbosity === "debug" && r.details ? a.stderr(
167
+ `${p}${c}Fatal error:${d} Uncaught ${r.details.exception}: ${r.details.message}
168
+ at ${r.details.file}:${r.details.line}
169
+ ` + (r.details.trace ? r.details.trace + `
187
170
  ` : "")
188
- ) : i.stderr(
189
- `${a}${w}Error:${f} ${t.message}
171
+ ) : a.stderr(
172
+ `${p}${c}Error:${d} ${r.message}
190
173
  `
191
174
  );
192
175
  break;
@@ -194,169 +177,173 @@ class Q extends L {
194
177
  }
195
178
  }
196
179
  });
197
- if (e.verbosity === "debug" && (d.stdout.pipeTo(
180
+ if (e.verbosity === "debug" && (l.stdout.pipeTo(
198
181
  new WritableStream({
199
- write(t) {
200
- process.stdout.write(t);
182
+ write(r) {
183
+ process.stdout.write(r);
201
184
  }
202
185
  })
203
- ), d.stderr.pipeTo(
186
+ ), l.stderr.pipeTo(
204
187
  new WritableStream({
205
- write(t) {
206
- process.stderr.write(t);
188
+ write(r) {
189
+ process.stderr.write(r);
207
190
  }
208
191
  })
209
- )), await d.finished, await d.exitCode !== 0) {
210
- const t = await E.fromStreamedResponse(d);
211
- throw new C(
212
- `PHP.run() failed with exit code ${t.exitCode}. ${t.errors} ${t.text}`,
213
- t,
192
+ )), await l.finished, await l.exitCode !== 0) {
193
+ const r = await E.fromStreamedResponse(l);
194
+ throw new F(
195
+ `PHP.run() failed with exit code ${r.exitCode}. ${r.errors} ${r.text}`,
196
+ r,
214
197
  "request"
215
198
  );
216
199
  }
217
200
  } catch (n) {
218
- let l = "";
201
+ let i = "";
219
202
  try {
220
- l = c.readFileAsText(S);
203
+ i = u.readFileAsText(H);
221
204
  } catch {
222
205
  }
223
- throw n.phpLogs = l, n;
206
+ throw n.phpLogs = i, n;
224
207
  } finally {
225
- p(), u();
208
+ h(), f();
226
209
  }
227
210
  }
228
211
  async bootRequestHandler({
229
212
  siteUrl: e,
230
- allow: r,
231
- phpVersion: c,
232
- createFiles: p,
233
- constants: o,
234
- phpIniEntries: u,
235
- firstProcessId: n,
236
- processIdSpaceLength: l,
237
- trace: d,
238
- nativeInternalDirPath: t,
239
- withIntl: a,
240
- withRedis: w,
241
- withMemcached: f,
242
- withXdebug: k,
243
- pathAliases: b,
244
- onPHPInstanceCreated: h,
245
- spawnHandler: v
213
+ allow: t,
214
+ phpVersion: o,
215
+ processId: u,
216
+ createFiles: h,
217
+ constants: w,
218
+ phpIniEntries: f,
219
+ trace: n,
220
+ nativeInternalDirPath: i,
221
+ withIntl: l,
222
+ withRedis: r,
223
+ withMemcached: p,
224
+ withXdebug: c,
225
+ pathAliases: d,
226
+ onPHPInstanceCreated: k,
227
+ spawnHandler: x
246
228
  }) {
247
229
  if (this.booted)
248
230
  throw new Error("Playground already booted");
249
231
  this.booted = !0;
250
- let y = n;
251
- const H = n + l - 1;
252
232
  try {
253
- const P = await j({
233
+ const P = await N({
254
234
  siteUrl: e,
255
- createPhpRuntime: async () => {
256
- const $ = y;
257
- return y < H ? y++ : y = n, await F(c, {
258
- emscriptenOptions: {
259
- fileLockManager: this.fileLockManager,
260
- processId: $,
261
- trace: d ? J : void 0,
262
- ENV: {
263
- DOCROOT: "/wordpress"
264
- },
265
- phpWasmInitOptions: { nativeInternalDirPath: t }
235
+ createPhpRuntime: async () => await M(o, {
236
+ fileLockManager: this.fileLockManager,
237
+ emscriptenOptions: {
238
+ processId: u,
239
+ trace: n ? X : void 0,
240
+ ENV: {
241
+ DOCROOT: "/wordpress"
266
242
  },
267
- followSymlinks: r?.includes("follow-symlinks"),
268
- withIntl: a,
269
- withRedis: w,
270
- withMemcached: f,
271
- withXdebug: k
272
- });
273
- },
243
+ nativeInternalDirPath: i,
244
+ bindUserSpace: (R) => $(
245
+ {
246
+ fileLockManager: this.fileLockManager
247
+ },
248
+ R
249
+ )
250
+ },
251
+ followSymlinks: t?.includes("follow-symlinks"),
252
+ withIntl: l,
253
+ withRedis: r,
254
+ withMemcached: p,
255
+ withXdebug: c
256
+ }),
274
257
  maxPhpInstances: 1,
275
- onPHPInstanceCreated: h,
258
+ onPHPInstanceCreated: k,
276
259
  sapiName: "cli",
277
- createFiles: p,
278
- constants: o,
279
- phpIniEntries: u,
280
- pathAliases: b,
260
+ createFiles: h,
261
+ constants: w,
262
+ phpIniEntries: f,
263
+ pathAliases: d,
281
264
  cookieStore: !1,
282
- spawnHandler: v
265
+ spawnHandler: x
283
266
  });
284
267
  this.__internal_setRequestHandler(P);
285
- const A = await P.getPrimaryPhp();
286
- await this.setPrimaryPHP(A), X();
268
+ const _ = await P.getPrimaryPhp();
269
+ await this.setPrimaryPHP(_), te();
287
270
  } catch (P) {
288
- throw Z(P), P;
271
+ throw re(P), P;
289
272
  }
290
273
  }
274
+ async mountAfterWordPressInstall(e) {
275
+ await b(this.__internal_getPHP(), e);
276
+ }
277
+ async applyPostInstallMountsToAllWorkers(e) {
278
+ const t = g(e);
279
+ await t(), t[U]();
280
+ }
291
281
  // Provide a named disposal method that can be invoked via comlink.
292
282
  async dispose() {
293
283
  await this[Symbol.asyncDispose]();
294
284
  }
295
285
  }
296
- async function T({
286
+ async function ee({
297
287
  siteUrl: s,
298
288
  allow: e,
299
- phpVersion: r,
300
- createFiles: c,
301
- constants: p,
302
- phpIniEntries: o,
303
- firstProcessId: u,
304
- processIdSpaceLength: n,
305
- trace: l,
306
- nativeInternalDirPath: d,
307
- withXdebug: t,
308
- pathAliases: a,
309
- mountsBeforeWpInstall: w,
310
- mountsAfterWpInstall: f
311
- }, k) {
312
- const b = await K("v2"), h = I(
313
- b.phpPort
289
+ phpVersion: t,
290
+ createFiles: o,
291
+ constants: u,
292
+ phpIniEntries: h,
293
+ trace: w,
294
+ nativeInternalDirPath: f,
295
+ withXdebug: n,
296
+ pathAliases: i,
297
+ mountsBeforeWpInstall: l,
298
+ mountsAfterWpInstall: r
299
+ }, p) {
300
+ const c = await J("v2"), d = g(
301
+ c.phpPort
314
302
  );
315
- return h.useFileLockManager(k), await h.bootWorker({
303
+ return d.useFileLockManager(p), await d.bootWorker({
316
304
  siteUrl: s,
317
305
  allow: e,
318
- phpVersion: r,
319
- createFiles: c,
320
- constants: p,
321
- phpIniEntries: o,
322
- firstProcessId: u,
323
- processIdSpaceLength: n,
324
- trace: l,
325
- nativeInternalDirPath: d,
326
- withXdebug: t,
327
- pathAliases: a,
328
- mountsBeforeWpInstall: w,
329
- mountsAfterWpInstall: f
306
+ phpVersion: t,
307
+ createFiles: o,
308
+ constants: u,
309
+ phpIniEntries: h,
310
+ processId: c.processId,
311
+ trace: w,
312
+ nativeInternalDirPath: f,
313
+ withXdebug: n,
314
+ pathAliases: i,
315
+ mountsBeforeWpInstall: l,
316
+ mountsAfterWpInstall: r
330
317
  }), {
331
- php: h,
318
+ php: d,
332
319
  reap: () => {
333
320
  try {
334
- h.dispose();
321
+ d.dispose();
335
322
  } catch {
336
323
  }
337
324
  try {
338
- b.worker.terminate();
325
+ c.worker.terminate();
339
326
  } catch {
340
327
  }
341
328
  }
342
329
  };
343
330
  }
344
331
  process.on("unhandledRejection", (s) => {
345
- M.error("Unhandled rejection:", s);
332
+ T.error("Unhandled rejection:", s);
346
333
  });
347
- const g = new U(), [X, Z] = _(
348
- new Q(new B()),
334
+ const y = new z(), [te, re] = v(
335
+ new Z(new I()),
349
336
  void 0,
350
- g.port1
337
+ y.port1
351
338
  );
352
- Y?.postMessage(
339
+ K?.postMessage(
353
340
  {
354
341
  command: "worker-script-initialized",
355
- phpPort: g.port2
342
+ phpPort: y.port2
356
343
  },
357
- [g.port2]
344
+ [y.port2]
358
345
  );
359
346
  export {
360
- Q as PlaygroundCliBlueprintV2Worker
347
+ Z as PlaygroundCliBlueprintV2Worker
361
348
  };
362
349
  //# sourceMappingURL=worker-thread-v2.js.map