@wp-playground/cli 2.0.11 → 2.0.13
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.
- package/README.md +2 -1
- package/blueprints-v1/blueprints-v1-handler.d.ts +1 -1
- package/cli.cjs +1 -1
- package/cli.js +1 -1
- package/index.cjs +1 -1
- package/index.js +4 -3
- package/mounts-BJFrPHGW.cjs +16 -0
- package/mounts-BJFrPHGW.cjs.map +1 -0
- package/{mounts-ClzM-OKS.js → mounts-D1_eXSTw.js} +17 -12
- package/mounts-D1_eXSTw.js.map +1 -0
- package/package.json +12 -12
- package/run-cli-DXE7WaVM.cjs +27 -0
- package/run-cli-DXE7WaVM.cjs.map +1 -0
- package/run-cli-ob90MazJ.js +772 -0
- package/run-cli-ob90MazJ.js.map +1 -0
- package/run-cli.d.ts +27 -1
- package/worker-thread-v1-BTJIbQLy.js.map +1 -1
- package/worker-thread-v1.cjs +1 -1
- package/worker-thread-v1.js +1 -1
- package/mounts-ClzM-OKS.js.map +0 -1
- package/mounts-qNNxXLf_.cjs +0 -16
- package/mounts-qNNxXLf_.cjs.map +0 -1
- package/run-cli-DyGaDiU2.cjs +0 -27
- package/run-cli-DyGaDiU2.cjs.map +0 -1
- package/run-cli-FboNWUuJ.js +0 -703
- package/run-cli-FboNWUuJ.js.map +0 -1
package/run-cli-FboNWUuJ.js
DELETED
|
@@ -1,703 +0,0 @@
|
|
|
1
|
-
import { logger as p, errorLogPath as R } from "@php-wasm/logger";
|
|
2
|
-
import { consumeAPI as L, SupportedPHPVersions as q, printDebugDetails as j, PHPResponse as U, exposeAPI as D, exposeSyncAPI as O } from "@php-wasm/universal";
|
|
3
|
-
import { resolveRemoteBlueprint as Z, isBlueprintBundle as _, compileBlueprint as N, runBlueprintSteps as J } from "@wp-playground/blueprints";
|
|
4
|
-
import { zipDirectory as E, RecommendedPHPVersion as A, unzipFile as Y } from "@wp-playground/common";
|
|
5
|
-
import y from "fs";
|
|
6
|
-
import { Worker as Q, MessageChannel as X } from "worker_threads";
|
|
7
|
-
import { p as M, a as G, e as K } from "./mounts-ClzM-OKS.js";
|
|
8
|
-
import ee from "express";
|
|
9
|
-
import { FileLockManagerForNode as te } from "@php-wasm/node";
|
|
10
|
-
import re, { cpus as oe } from "os";
|
|
11
|
-
import { jspi as se } from "wasm-feature-detect";
|
|
12
|
-
import ie from "yargs";
|
|
13
|
-
import m, { basename as ne } from "path";
|
|
14
|
-
import { NodeJsFilesystem as ae, OverlayFilesystem as le, InMemoryFilesystem as pe, ZipFilesystem as de } from "@wp-playground/storage";
|
|
15
|
-
import { EmscriptenDownloadMonitor as ce, ProgressTracker as ue } from "@php-wasm/progress";
|
|
16
|
-
import { resolveWordPressRelease as he } from "@wp-playground/wordpress";
|
|
17
|
-
import k from "fs-extra";
|
|
18
|
-
import { startBridge as fe } from "@php-wasm/xdebug-bridge";
|
|
19
|
-
async function me(t) {
|
|
20
|
-
const r = ee(), e = await new Promise((i, n) => {
|
|
21
|
-
const l = r.listen(t.port, () => {
|
|
22
|
-
const a = l.address();
|
|
23
|
-
a === null || typeof a == "string" ? n(new Error("Server address is not available")) : i(l);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
r.use("/", async (i, n) => {
|
|
27
|
-
const l = await t.handleRequest({
|
|
28
|
-
url: i.url,
|
|
29
|
-
headers: ge(i),
|
|
30
|
-
method: i.method,
|
|
31
|
-
body: await we(i)
|
|
32
|
-
});
|
|
33
|
-
n.statusCode = l.httpStatusCode;
|
|
34
|
-
for (const a in l.headers)
|
|
35
|
-
n.setHeader(a, l.headers[a]);
|
|
36
|
-
n.end(l.bytes);
|
|
37
|
-
});
|
|
38
|
-
const s = e.address().port;
|
|
39
|
-
return await t.onBind(e, s);
|
|
40
|
-
}
|
|
41
|
-
const we = async (t) => await new Promise((r) => {
|
|
42
|
-
const e = [];
|
|
43
|
-
t.on("data", (o) => {
|
|
44
|
-
e.push(o);
|
|
45
|
-
}), t.on("end", () => {
|
|
46
|
-
r(new Uint8Array(Buffer.concat(e)));
|
|
47
|
-
});
|
|
48
|
-
}), ge = (t) => {
|
|
49
|
-
const r = {};
|
|
50
|
-
if (t.rawHeaders && t.rawHeaders.length)
|
|
51
|
-
for (let e = 0; e < t.rawHeaders.length; e += 2)
|
|
52
|
-
r[t.rawHeaders[e].toLowerCase()] = t.rawHeaders[e + 1];
|
|
53
|
-
return r;
|
|
54
|
-
};
|
|
55
|
-
class ye {
|
|
56
|
-
constructor(r) {
|
|
57
|
-
this.workerLoads = [], this.addWorker(r);
|
|
58
|
-
}
|
|
59
|
-
addWorker(r) {
|
|
60
|
-
this.workerLoads.push({
|
|
61
|
-
worker: r,
|
|
62
|
-
activeRequests: /* @__PURE__ */ new Set()
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
async handleRequest(r) {
|
|
66
|
-
let e = this.workerLoads[0];
|
|
67
|
-
for (let s = 1; s < this.workerLoads.length; s++) {
|
|
68
|
-
const i = this.workerLoads[s];
|
|
69
|
-
i.activeRequests.size < e.activeRequests.size && (e = i);
|
|
70
|
-
}
|
|
71
|
-
const o = e.worker.request(r);
|
|
72
|
-
return e.activeRequests.add(o), o.url = r.url, o.finally(() => {
|
|
73
|
-
e.activeRequests.delete(o);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function be(t) {
|
|
78
|
-
return /^latest$|^trunk$|^nightly$|^(?:(\d+)\.(\d+)(?:\.(\d+))?)((?:-beta(?:\d+)?)|(?:-RC(?:\d+)?))?$/.test(t);
|
|
79
|
-
}
|
|
80
|
-
async function Pe({
|
|
81
|
-
sourceString: t,
|
|
82
|
-
blueprintMayReadAdjacentFiles: r
|
|
83
|
-
}) {
|
|
84
|
-
if (!t)
|
|
85
|
-
return;
|
|
86
|
-
if (t.startsWith("http://") || t.startsWith("https://"))
|
|
87
|
-
return await Z(t);
|
|
88
|
-
let e = m.resolve(process.cwd(), t);
|
|
89
|
-
if (!y.existsSync(e))
|
|
90
|
-
throw new Error(`Blueprint file does not exist: ${e}`);
|
|
91
|
-
const o = y.statSync(e);
|
|
92
|
-
if (o.isDirectory() && (e = m.join(e, "blueprint.json")), !o.isFile() && o.isSymbolicLink())
|
|
93
|
-
throw new Error(
|
|
94
|
-
`Blueprint path is neither a file nor a directory: ${e}`
|
|
95
|
-
);
|
|
96
|
-
const s = m.extname(e);
|
|
97
|
-
switch (s) {
|
|
98
|
-
case ".zip":
|
|
99
|
-
return de.fromArrayBuffer(
|
|
100
|
-
y.readFileSync(e).buffer
|
|
101
|
-
);
|
|
102
|
-
case ".json": {
|
|
103
|
-
const i = y.readFileSync(e, "utf-8");
|
|
104
|
-
try {
|
|
105
|
-
JSON.parse(i);
|
|
106
|
-
} catch {
|
|
107
|
-
throw new Error(
|
|
108
|
-
`Blueprint file at ${e} is not a valid JSON file`
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
const n = m.dirname(e), l = new ae(n);
|
|
112
|
-
return new le([
|
|
113
|
-
new pe({
|
|
114
|
-
"blueprint.json": i
|
|
115
|
-
}),
|
|
116
|
-
/**
|
|
117
|
-
* Wrap the NodeJS filesystem to prevent access to local files
|
|
118
|
-
* unless the user explicitly allowed it.
|
|
119
|
-
*/
|
|
120
|
-
{
|
|
121
|
-
read(a) {
|
|
122
|
-
if (!r)
|
|
123
|
-
throw new Error(
|
|
124
|
-
`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.
|
|
125
|
-
|
|
126
|
-
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.`
|
|
127
|
-
);
|
|
128
|
-
return l.read(a);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
]);
|
|
132
|
-
}
|
|
133
|
-
default:
|
|
134
|
-
throw new Error(
|
|
135
|
-
`Unsupported blueprint file extension: ${s}. Only .zip and .json files are supported.`
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const I = "" + new URL("worker-thread-v2-Pfv6UYF4.js", import.meta.url).href;
|
|
140
|
-
class ke {
|
|
141
|
-
constructor(r, e) {
|
|
142
|
-
this.lastProgressMessage = "", this.args = r, this.siteUrl = e.siteUrl, this.processIdSpaceLength = e.processIdSpaceLength, this.phpVersion = r.php;
|
|
143
|
-
}
|
|
144
|
-
getWorkerUrl() {
|
|
145
|
-
return process.env.VITEST && I.startsWith("/src/") ? m.join(
|
|
146
|
-
import.meta.dirname,
|
|
147
|
-
"..",
|
|
148
|
-
"..",
|
|
149
|
-
I
|
|
150
|
-
) : I;
|
|
151
|
-
}
|
|
152
|
-
async bootPrimaryWorker(r, e) {
|
|
153
|
-
const o = L(r);
|
|
154
|
-
await o.useFileLockManager(e);
|
|
155
|
-
const s = {
|
|
156
|
-
...this.args,
|
|
157
|
-
php: this.phpVersion,
|
|
158
|
-
siteUrl: this.siteUrl,
|
|
159
|
-
firstProcessId: 1,
|
|
160
|
-
processIdSpaceLength: this.processIdSpaceLength,
|
|
161
|
-
trace: this.args.debug || !1,
|
|
162
|
-
blueprint: this.args.blueprint
|
|
163
|
-
};
|
|
164
|
-
return await o.bootAsPrimaryWorker(s), o;
|
|
165
|
-
}
|
|
166
|
-
async bootSecondaryWorker({
|
|
167
|
-
worker: r,
|
|
168
|
-
fileLockManagerPort: e,
|
|
169
|
-
firstProcessId: o
|
|
170
|
-
}) {
|
|
171
|
-
const s = L(r.phpPort);
|
|
172
|
-
await s.useFileLockManager(e);
|
|
173
|
-
const i = {
|
|
174
|
-
...this.args,
|
|
175
|
-
php: this.phpVersion,
|
|
176
|
-
siteUrl: this.siteUrl,
|
|
177
|
-
firstProcessId: o,
|
|
178
|
-
processIdSpaceLength: this.processIdSpaceLength,
|
|
179
|
-
trace: this.args.debug || !1,
|
|
180
|
-
blueprint: this.args.blueprint
|
|
181
|
-
};
|
|
182
|
-
return await s.bootAsSecondaryWorker(i), s;
|
|
183
|
-
}
|
|
184
|
-
writeProgressUpdate(r, e, o) {
|
|
185
|
-
e !== this.lastProgressMessage && (this.lastProgressMessage = e, r.isTTY ? (r.cursorTo(0), r.write(e), r.clearLine(1), o && r.write(`
|
|
186
|
-
`)) : r.write(`${e}
|
|
187
|
-
`));
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
const B = m.join(re.homedir(), ".wordpress-playground");
|
|
191
|
-
async function ve(t) {
|
|
192
|
-
return await C(
|
|
193
|
-
"https://github.com/WordPress/sqlite-database-integration/archive/refs/heads/develop.zip",
|
|
194
|
-
"sqlite.zip",
|
|
195
|
-
t
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
async function C(t, r, e) {
|
|
199
|
-
const o = m.join(B, r);
|
|
200
|
-
return k.existsSync(o) || (k.ensureDirSync(B), await We(t, o, e)), T(o);
|
|
201
|
-
}
|
|
202
|
-
async function We(t, r, e) {
|
|
203
|
-
const s = (await e.monitorFetch(fetch(t))).body.getReader(), i = `${r}.partial`, n = k.createWriteStream(i);
|
|
204
|
-
for (; ; ) {
|
|
205
|
-
const { done: l, value: a } = await s.read();
|
|
206
|
-
if (a && n.write(a), l)
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
n.close(), n.closed || await new Promise((l, a) => {
|
|
210
|
-
n.on("finish", () => {
|
|
211
|
-
k.renameSync(i, r), l(null);
|
|
212
|
-
}), n.on("error", (c) => {
|
|
213
|
-
k.removeSync(i), a(c);
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
function T(t, r) {
|
|
218
|
-
return new File([k.readFileSync(t)], ne(t));
|
|
219
|
-
}
|
|
220
|
-
const F = "" + new URL("worker-thread-v1-BTJIbQLy.js", import.meta.url).href;
|
|
221
|
-
class xe {
|
|
222
|
-
constructor(r, e) {
|
|
223
|
-
this.lastProgressMessage = "", this.args = r, this.siteUrl = e.siteUrl, this.processIdSpaceLength = e.processIdSpaceLength;
|
|
224
|
-
}
|
|
225
|
-
getWorkerUrl() {
|
|
226
|
-
return process.env.VITEST && F.startsWith("/src/") ? m.join(
|
|
227
|
-
import.meta.dirname,
|
|
228
|
-
"..",
|
|
229
|
-
"..",
|
|
230
|
-
F
|
|
231
|
-
) : F;
|
|
232
|
-
}
|
|
233
|
-
async bootPrimaryWorker(r, e) {
|
|
234
|
-
const o = await this.compileInputBlueprint(
|
|
235
|
-
this.args["additional-blueprint-steps"] || []
|
|
236
|
-
);
|
|
237
|
-
this.phpVersion = o.versions.php;
|
|
238
|
-
let s;
|
|
239
|
-
const i = new ce();
|
|
240
|
-
if (!this.args.skipWordPressSetup) {
|
|
241
|
-
let v = !1;
|
|
242
|
-
i.addEventListener("progress", (h) => {
|
|
243
|
-
if (v)
|
|
244
|
-
return;
|
|
245
|
-
const { loaded: g, total: W } = h.detail, f = Math.floor(
|
|
246
|
-
Math.min(100, 100 * g / W)
|
|
247
|
-
);
|
|
248
|
-
v = f === 100, this.args.quiet || this.writeProgressUpdate(
|
|
249
|
-
process.stdout,
|
|
250
|
-
`Downloading WordPress ${f}%...`,
|
|
251
|
-
v
|
|
252
|
-
);
|
|
253
|
-
}), s = await he(this.args.wp), p.log(
|
|
254
|
-
`Resolved WordPress release URL: ${s?.releaseUrl}`
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
const n = s && m.join(
|
|
258
|
-
B,
|
|
259
|
-
`prebuilt-wp-content-for-wp-${s.version}.zip`
|
|
260
|
-
), l = s ? y.existsSync(n) ? T(n) : await C(
|
|
261
|
-
s.releaseUrl,
|
|
262
|
-
`${s.version}.zip`,
|
|
263
|
-
i
|
|
264
|
-
) : void 0;
|
|
265
|
-
p.log("Fetching SQLite integration plugin...");
|
|
266
|
-
const a = this.args.skipSqliteSetup ? void 0 : await ve(i), c = this.args.followSymlinks === !0, d = this.args.experimentalTrace === !0, w = this.args["mount-before-install"] || [], P = this.args.mount || [], u = L(r);
|
|
267
|
-
return await u.isConnected(), p.log("Booting WordPress..."), await u.useFileLockManager(e), await u.bootAsPrimaryWorker({
|
|
268
|
-
phpVersion: this.phpVersion,
|
|
269
|
-
wpVersion: o.versions.wp,
|
|
270
|
-
absoluteUrl: this.siteUrl,
|
|
271
|
-
mountsBeforeWpInstall: w,
|
|
272
|
-
mountsAfterWpInstall: P,
|
|
273
|
-
wordPressZip: l && await l.arrayBuffer(),
|
|
274
|
-
sqliteIntegrationPluginZip: await a?.arrayBuffer(),
|
|
275
|
-
firstProcessId: 0,
|
|
276
|
-
processIdSpaceLength: this.processIdSpaceLength,
|
|
277
|
-
followSymlinks: c,
|
|
278
|
-
trace: d,
|
|
279
|
-
internalCookieStore: this.args.internalCookieStore,
|
|
280
|
-
withXdebug: this.args.xdebug
|
|
281
|
-
}), s && !this.args["mount-before-install"] && !y.existsSync(n) && (p.log("Caching preinstalled WordPress for the next boot..."), y.writeFileSync(
|
|
282
|
-
n,
|
|
283
|
-
await E(u, "/wordpress")
|
|
284
|
-
), p.log("Cached!")), u;
|
|
285
|
-
}
|
|
286
|
-
async bootSecondaryWorker({
|
|
287
|
-
worker: r,
|
|
288
|
-
fileLockManagerPort: e,
|
|
289
|
-
firstProcessId: o
|
|
290
|
-
}) {
|
|
291
|
-
const s = L(
|
|
292
|
-
r.phpPort
|
|
293
|
-
);
|
|
294
|
-
return await s.isConnected(), await s.useFileLockManager(e), await s.bootAsSecondaryWorker({
|
|
295
|
-
phpVersion: this.phpVersion,
|
|
296
|
-
absoluteUrl: this.siteUrl,
|
|
297
|
-
mountsBeforeWpInstall: this.args["mount-before-install"] || [],
|
|
298
|
-
mountsAfterWpInstall: this.args.mount || [],
|
|
299
|
-
// Skip WordPress zip because we share the /wordpress directory
|
|
300
|
-
// populated by the initial worker.
|
|
301
|
-
wordPressZip: void 0,
|
|
302
|
-
// Skip SQLite integration plugin for now because we
|
|
303
|
-
// will copy it from primary's `/internal` directory.
|
|
304
|
-
sqliteIntegrationPluginZip: void 0,
|
|
305
|
-
dataSqlPath: "/wordpress/wp-content/database/.ht.sqlite",
|
|
306
|
-
firstProcessId: o,
|
|
307
|
-
processIdSpaceLength: this.processIdSpaceLength,
|
|
308
|
-
followSymlinks: this.args.followSymlinks === !0,
|
|
309
|
-
trace: this.args.experimentalTrace === !0,
|
|
310
|
-
// @TODO: Move this to the request handler or else every worker
|
|
311
|
-
// will have a separate cookie store.
|
|
312
|
-
internalCookieStore: this.args.internalCookieStore,
|
|
313
|
-
withXdebug: this.args.xdebug
|
|
314
|
-
}), await s.isReady(), s;
|
|
315
|
-
}
|
|
316
|
-
async compileInputBlueprint(r) {
|
|
317
|
-
const e = this.args, o = e.blueprint, s = _(o) ? o : {
|
|
318
|
-
login: e.login,
|
|
319
|
-
...o || {},
|
|
320
|
-
preferredVersions: {
|
|
321
|
-
php: e.php ?? o?.preferredVersions?.php ?? A,
|
|
322
|
-
wp: e.wp ?? o?.preferredVersions?.wp ?? "latest",
|
|
323
|
-
...o?.preferredVersions || {}
|
|
324
|
-
}
|
|
325
|
-
}, i = new ue();
|
|
326
|
-
let n = "", l = !1;
|
|
327
|
-
return i.addEventListener("progress", (a) => {
|
|
328
|
-
if (l)
|
|
329
|
-
return;
|
|
330
|
-
l = a.detail.progress === 100;
|
|
331
|
-
const c = Math.floor(a.detail.progress);
|
|
332
|
-
n = a.detail.caption || n || "Running the Blueprint";
|
|
333
|
-
const d = `${n.trim()} – ${c}%`;
|
|
334
|
-
e.quiet || this.writeProgressUpdate(
|
|
335
|
-
process.stdout,
|
|
336
|
-
d,
|
|
337
|
-
l
|
|
338
|
-
);
|
|
339
|
-
}), await N(s, {
|
|
340
|
-
progress: i,
|
|
341
|
-
additionalSteps: r
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
writeProgressUpdate(r, e, o) {
|
|
345
|
-
e !== this.lastProgressMessage && (this.lastProgressMessage = e, r.isTTY ? (r.cursorTo(0), r.write(e), r.clearLine(1), o && r.write(`
|
|
346
|
-
`)) : r.write(`${e}
|
|
347
|
-
`));
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
async function _e() {
|
|
351
|
-
try {
|
|
352
|
-
const t = ie(process.argv.slice(2)).usage("Usage: wp-playground <command> [options]").positional("command", {
|
|
353
|
-
describe: "Command to run",
|
|
354
|
-
choices: ["server", "run-blueprint", "build-snapshot"],
|
|
355
|
-
demandOption: !0
|
|
356
|
-
}).option("outfile", {
|
|
357
|
-
describe: "When building, write to this output file.",
|
|
358
|
-
type: "string",
|
|
359
|
-
default: "wordpress.zip"
|
|
360
|
-
}).option("port", {
|
|
361
|
-
describe: "Port to listen on when serving.",
|
|
362
|
-
type: "number",
|
|
363
|
-
default: 9400
|
|
364
|
-
}).option("php", {
|
|
365
|
-
describe: "PHP version to use.",
|
|
366
|
-
type: "string",
|
|
367
|
-
default: A,
|
|
368
|
-
choices: q
|
|
369
|
-
}).option("wp", {
|
|
370
|
-
describe: "WordPress version to use.",
|
|
371
|
-
type: "string",
|
|
372
|
-
default: "latest"
|
|
373
|
-
}).option("mount", {
|
|
374
|
-
describe: "Mount a directory to the PHP runtime (can be used multiple times). Format: /host/path:/vfs/path",
|
|
375
|
-
type: "array",
|
|
376
|
-
string: !0,
|
|
377
|
-
coerce: M
|
|
378
|
-
}).option("mount-before-install", {
|
|
379
|
-
describe: "Mount a directory to the PHP runtime before WordPress installation (can be used multiple times). Format: /host/path:/vfs/path",
|
|
380
|
-
type: "array",
|
|
381
|
-
string: !0,
|
|
382
|
-
coerce: M
|
|
383
|
-
}).option("mount-dir", {
|
|
384
|
-
describe: 'Mount a directory to the PHP runtime (can be used multiple times). Format: "/host/path" "/vfs/path"',
|
|
385
|
-
type: "array",
|
|
386
|
-
nargs: 2,
|
|
387
|
-
array: !0
|
|
388
|
-
// coerce: parseMountDirArguments,
|
|
389
|
-
}).option("mount-dir-before-install", {
|
|
390
|
-
describe: 'Mount a directory before WordPress installation (can be used multiple times). Format: "/host/path" "/vfs/path"',
|
|
391
|
-
type: "string",
|
|
392
|
-
nargs: 2,
|
|
393
|
-
array: !0,
|
|
394
|
-
coerce: G
|
|
395
|
-
}).option("login", {
|
|
396
|
-
describe: "Should log the user in",
|
|
397
|
-
type: "boolean",
|
|
398
|
-
default: !1
|
|
399
|
-
}).option("blueprint", {
|
|
400
|
-
describe: "Blueprint to execute.",
|
|
401
|
-
type: "string"
|
|
402
|
-
}).option("blueprint-may-read-adjacent-files", {
|
|
403
|
-
describe: 'Consent flag: Allow "bundled" resources in a local blueprint to read files in the same directory as the blueprint file.',
|
|
404
|
-
type: "boolean",
|
|
405
|
-
default: !1
|
|
406
|
-
}).option("skip-wordpress-setup", {
|
|
407
|
-
describe: "Do not download, unzip, and install WordPress. Useful for mounting a pre-configured WordPress directory at /wordpress.",
|
|
408
|
-
type: "boolean",
|
|
409
|
-
default: !1
|
|
410
|
-
}).option("skip-sqlite-setup", {
|
|
411
|
-
describe: "Skip the SQLite integration plugin setup to allow the WordPress site to use MySQL.",
|
|
412
|
-
type: "boolean",
|
|
413
|
-
default: !1
|
|
414
|
-
}).option("quiet", {
|
|
415
|
-
describe: "Do not output logs and progress messages.",
|
|
416
|
-
type: "boolean",
|
|
417
|
-
default: !1
|
|
418
|
-
}).option("debug", {
|
|
419
|
-
describe: "Print PHP error log content if an error occurs during Playground boot.",
|
|
420
|
-
type: "boolean",
|
|
421
|
-
default: !1
|
|
422
|
-
}).option("auto-mount", {
|
|
423
|
-
describe: "Automatically mount the current working directory. You can mount a WordPress directory, a plugin directory, a theme directory, a wp-content directory, or any directory containing PHP and HTML files.",
|
|
424
|
-
type: "boolean",
|
|
425
|
-
default: !1
|
|
426
|
-
}).option("follow-symlinks", {
|
|
427
|
-
describe: `Allow Playground to follow symlinks by automatically mounting symlinked directories and files encountered in mounted directories.
|
|
428
|
-
Warning: Following symlinks will expose files outside mounted directories to Playground and could be a security risk.`,
|
|
429
|
-
type: "boolean",
|
|
430
|
-
default: !1
|
|
431
|
-
}).option("experimental-trace", {
|
|
432
|
-
describe: "Print detailed messages about system behavior to the console. Useful for troubleshooting.",
|
|
433
|
-
type: "boolean",
|
|
434
|
-
default: !1,
|
|
435
|
-
// Hide this option because we want to replace with a more general log-level flag.
|
|
436
|
-
hidden: !0
|
|
437
|
-
}).option("internal-cookie-store", {
|
|
438
|
-
describe: "Enable internal cookie handling. When enabled, Playground will manage cookies internally using an HttpCookieStore that persists cookies across requests. When disabled, cookies are handled externally (e.g., by a browser in Node.js environments).",
|
|
439
|
-
type: "boolean",
|
|
440
|
-
default: !1
|
|
441
|
-
}).option("xdebug", {
|
|
442
|
-
describe: "Enable Xdebug.",
|
|
443
|
-
type: "boolean",
|
|
444
|
-
default: !1
|
|
445
|
-
}).option("experimental-devtools", {
|
|
446
|
-
describe: "Enable experimental browser development tools.",
|
|
447
|
-
type: "boolean",
|
|
448
|
-
default: !1
|
|
449
|
-
}).option("experimental-multi-worker", {
|
|
450
|
-
describe: "Enable experimental multi-worker support which requires JSPI and 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.",
|
|
451
|
-
type: "number",
|
|
452
|
-
coerce: (s) => s ?? oe().length - 1
|
|
453
|
-
}).option("experimental-blueprints-v2-runner", {
|
|
454
|
-
describe: "Use the experimental Blueprint V2 runner.",
|
|
455
|
-
type: "boolean",
|
|
456
|
-
default: !1,
|
|
457
|
-
// Remove the "hidden" flag once Blueprint V2 is fully supported
|
|
458
|
-
hidden: !0
|
|
459
|
-
}).showHelpOnFail(!1).strictOptions().check(async (s) => {
|
|
460
|
-
if (s.wp !== void 0 && !be(s.wp))
|
|
461
|
-
try {
|
|
462
|
-
new URL(s.wp);
|
|
463
|
-
} catch {
|
|
464
|
-
throw new Error(
|
|
465
|
-
'Unrecognized WordPress version. Please use "latest", a URL, or a numeric version such as "6.2", "6.0.1", "6.2-beta1", or "6.2-RC1"'
|
|
466
|
-
);
|
|
467
|
-
}
|
|
468
|
-
if (s["experimental-multi-worker"] !== void 0) {
|
|
469
|
-
if (s["experimental-multi-worker"] <= 1)
|
|
470
|
-
throw new Error(
|
|
471
|
-
"The --experimentalMultiWorker flag must be a positive integer greater than 1."
|
|
472
|
-
);
|
|
473
|
-
const i = (n) => n.vfsPath === "/wordpress";
|
|
474
|
-
if (!s.mount?.some(i) && !s["mount-before-install"]?.some(
|
|
475
|
-
i
|
|
476
|
-
))
|
|
477
|
-
throw new Error(
|
|
478
|
-
"Please mount a real filesystem directory as the /wordpress directory before using the --experimentalMultiWorker flag. For example: --mount-dir-before-install ./empty-dir /wordpress"
|
|
479
|
-
);
|
|
480
|
-
}
|
|
481
|
-
return !0;
|
|
482
|
-
});
|
|
483
|
-
t.wrap(t.terminalWidth());
|
|
484
|
-
const r = await t.argv, e = r._[0];
|
|
485
|
-
["run-blueprint", "server", "build-snapshot"].includes(e) || (t.showHelp(), process.exit(1));
|
|
486
|
-
const o = {
|
|
487
|
-
...r,
|
|
488
|
-
command: e,
|
|
489
|
-
mount: [...r.mount || [], ...r["mount-dir"] || []],
|
|
490
|
-
"mount-before-install": [
|
|
491
|
-
...r["mount-before-install"] || [],
|
|
492
|
-
...r["mount-dir-before-install"] || []
|
|
493
|
-
]
|
|
494
|
-
};
|
|
495
|
-
await Se(o);
|
|
496
|
-
} catch (t) {
|
|
497
|
-
if (!(t instanceof Error))
|
|
498
|
-
throw t;
|
|
499
|
-
if (process.argv.includes("--debug"))
|
|
500
|
-
j(t);
|
|
501
|
-
else {
|
|
502
|
-
const e = [];
|
|
503
|
-
let o = t;
|
|
504
|
-
do
|
|
505
|
-
e.push(o.message), o = o.cause;
|
|
506
|
-
while (o instanceof Error);
|
|
507
|
-
console.error(
|
|
508
|
-
"\x1B[1m" + e.join(" caused by ") + "\x1B[0m"
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
process.exit(1);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
async function Se(t) {
|
|
515
|
-
let r, e;
|
|
516
|
-
const o = [];
|
|
517
|
-
t.autoMount && (t = K(t)), t.quiet && (p.handlers = []);
|
|
518
|
-
const s = await import("fs-ext").then((a) => a.flockSync).catch(() => {
|
|
519
|
-
p.warn(
|
|
520
|
-
"The fs-ext package is not installed. Internal file locking will not be integrated with host OS file locking."
|
|
521
|
-
);
|
|
522
|
-
}), i = new te(s);
|
|
523
|
-
let n = !1, l = !0;
|
|
524
|
-
return p.log("Starting a PHP server..."), me({
|
|
525
|
-
port: t.port,
|
|
526
|
-
onBind: async (a, c) => {
|
|
527
|
-
const d = `http://127.0.0.1:${c}`, w = t.experimentalMultiWorker ?? 1, P = Math.floor(
|
|
528
|
-
Number.MAX_SAFE_INTEGER / w
|
|
529
|
-
);
|
|
530
|
-
let u;
|
|
531
|
-
t["experimental-blueprints-v2-runner"] ? u = new ke(t, {
|
|
532
|
-
siteUrl: d,
|
|
533
|
-
processIdSpaceLength: P
|
|
534
|
-
}) : (u = new xe(t, {
|
|
535
|
-
siteUrl: d,
|
|
536
|
-
processIdSpaceLength: P
|
|
537
|
-
}), typeof t.blueprint == "string" && (t.blueprint = await Pe({
|
|
538
|
-
sourceString: t.blueprint,
|
|
539
|
-
blueprintMayReadAdjacentFiles: t["blueprint-may-read-adjacent-files"] === !0
|
|
540
|
-
})));
|
|
541
|
-
const v = Le(
|
|
542
|
-
u.getWorkerUrl(),
|
|
543
|
-
w,
|
|
544
|
-
({ exitCode: h, isMain: g, workerIndex: W }) => {
|
|
545
|
-
h !== 0 && (p.error(
|
|
546
|
-
`Worker ${W} exited with code ${h}
|
|
547
|
-
`
|
|
548
|
-
), g && t.exitOnPrimaryWorkerCrash && process.exit(1));
|
|
549
|
-
}
|
|
550
|
-
);
|
|
551
|
-
p.log(`Setting up WordPress ${t.wp}`);
|
|
552
|
-
try {
|
|
553
|
-
const [h, ...g] = await v, W = await $(
|
|
554
|
-
i
|
|
555
|
-
);
|
|
556
|
-
if (e = await u.bootPrimaryWorker(
|
|
557
|
-
h.phpPort,
|
|
558
|
-
W
|
|
559
|
-
), o.push({
|
|
560
|
-
playground: e,
|
|
561
|
-
worker: h.worker
|
|
562
|
-
}), await e.isReady(), n = !0, p.log("Booted!"), r = new ye(e), !t["experimental-blueprints-v2-runner"]) {
|
|
563
|
-
const f = await u.compileInputBlueprint(
|
|
564
|
-
t["additional-blueprint-steps"] || []
|
|
565
|
-
);
|
|
566
|
-
f && (p.log("Running the Blueprint..."), await J(f, e), p.log("Finished running the blueprint"));
|
|
567
|
-
}
|
|
568
|
-
if (t.command === "build-snapshot" ? (await Ie(e, t.outfile), p.log(`WordPress exported to ${t.outfile}`), process.exit(0)) : t.command === "run-blueprint" && (p.log("Blueprint executed"), process.exit(0)), t.experimentalMultiWorker && t.experimentalMultiWorker > 1) {
|
|
569
|
-
p.log("Preparing additional workers...");
|
|
570
|
-
const f = await E(
|
|
571
|
-
e,
|
|
572
|
-
"/internal"
|
|
573
|
-
), b = P;
|
|
574
|
-
await Promise.all(
|
|
575
|
-
g.map(async (S, H) => {
|
|
576
|
-
const z = b + H * P, V = await $(i), x = await u.bootSecondaryWorker({
|
|
577
|
-
worker: S,
|
|
578
|
-
fileLockManagerPort: V,
|
|
579
|
-
firstProcessId: z
|
|
580
|
-
});
|
|
581
|
-
o.push({
|
|
582
|
-
playground: x,
|
|
583
|
-
worker: S.worker
|
|
584
|
-
}), await x.writeFile(
|
|
585
|
-
"/tmp/internal.zip",
|
|
586
|
-
f
|
|
587
|
-
), await Y(
|
|
588
|
-
x,
|
|
589
|
-
"/tmp/internal.zip",
|
|
590
|
-
"/internal"
|
|
591
|
-
), await x.unlink(
|
|
592
|
-
"/tmp/internal.zip"
|
|
593
|
-
), r.addWorker(x);
|
|
594
|
-
})
|
|
595
|
-
), p.log("Ready!");
|
|
596
|
-
}
|
|
597
|
-
return p.log(`WordPress is running on ${d}`), t.experimentalDevtools && t.xdebug && (await fe({
|
|
598
|
-
getPHPFile: async (b) => await e.readFileAsText(b)
|
|
599
|
-
})).start(), {
|
|
600
|
-
playground: e,
|
|
601
|
-
server: a,
|
|
602
|
-
[Symbol.asyncDispose]: async function() {
|
|
603
|
-
await Promise.all(
|
|
604
|
-
o.map(
|
|
605
|
-
async ({ playground: b, worker: S }) => {
|
|
606
|
-
await b.dispose(), await S.terminate();
|
|
607
|
-
}
|
|
608
|
-
)
|
|
609
|
-
), await new Promise((b) => a.close(b));
|
|
610
|
-
},
|
|
611
|
-
workerThreadCount: w
|
|
612
|
-
};
|
|
613
|
-
} catch (h) {
|
|
614
|
-
if (!t.debug)
|
|
615
|
-
throw h;
|
|
616
|
-
let g = "";
|
|
617
|
-
throw await e?.fileExists(R) && (g = await e.readFileAsText(R)), new Error(g, { cause: h });
|
|
618
|
-
}
|
|
619
|
-
},
|
|
620
|
-
async handleRequest(a) {
|
|
621
|
-
if (!n)
|
|
622
|
-
return U.forHttpCode(
|
|
623
|
-
502,
|
|
624
|
-
"WordPress is not ready yet"
|
|
625
|
-
);
|
|
626
|
-
if (l) {
|
|
627
|
-
l = !1;
|
|
628
|
-
const c = {
|
|
629
|
-
"Content-Type": ["text/plain"],
|
|
630
|
-
"Content-Length": ["0"],
|
|
631
|
-
Location: ["/"]
|
|
632
|
-
};
|
|
633
|
-
return a.headers?.cookie?.includes(
|
|
634
|
-
"playground_auto_login_already_happened"
|
|
635
|
-
) && (c["Set-Cookie"] = [
|
|
636
|
-
"playground_auto_login_already_happened=1; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Path=/"
|
|
637
|
-
]), new U(302, c, new Uint8Array());
|
|
638
|
-
}
|
|
639
|
-
return await r.handleRequest(a);
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
function Le(t, r, e) {
|
|
644
|
-
const o = new URL(t, import.meta.url), s = [];
|
|
645
|
-
for (let i = 0; i < r; i++) {
|
|
646
|
-
const n = new Q(o), l = (a) => {
|
|
647
|
-
e({
|
|
648
|
-
exitCode: a,
|
|
649
|
-
isMain: i === 0,
|
|
650
|
-
workerIndex: i
|
|
651
|
-
});
|
|
652
|
-
};
|
|
653
|
-
s.push(
|
|
654
|
-
new Promise(
|
|
655
|
-
(a, c) => {
|
|
656
|
-
n.once("message", function(d) {
|
|
657
|
-
d.command === "worker-script-initialized" && a({ worker: n, phpPort: d.phpPort });
|
|
658
|
-
}), n.once("error", function(d) {
|
|
659
|
-
console.error(d);
|
|
660
|
-
const w = new Error(
|
|
661
|
-
`Worker failed to load at ${o}. ${d.message ? `Original error: ${d.message}` : ""}`
|
|
662
|
-
);
|
|
663
|
-
w.filename = o, c(w);
|
|
664
|
-
}), n.once("exit", l);
|
|
665
|
-
}
|
|
666
|
-
)
|
|
667
|
-
);
|
|
668
|
-
}
|
|
669
|
-
return Promise.all(s);
|
|
670
|
-
}
|
|
671
|
-
async function $(t) {
|
|
672
|
-
const { port1: r, port2: e } = new X();
|
|
673
|
-
return await se() ? D(t, null, r) : await O(t, r), e;
|
|
674
|
-
}
|
|
675
|
-
async function Ie(t, r) {
|
|
676
|
-
await t.run({
|
|
677
|
-
code: `<?php
|
|
678
|
-
$zip = new ZipArchive();
|
|
679
|
-
if(false === $zip->open('/tmp/build.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
|
|
680
|
-
throw new Exception('Failed to create ZIP');
|
|
681
|
-
}
|
|
682
|
-
$files = new RecursiveIteratorIterator(
|
|
683
|
-
new RecursiveDirectoryIterator('/wordpress')
|
|
684
|
-
);
|
|
685
|
-
foreach ($files as $file) {
|
|
686
|
-
echo $file . PHP_EOL;
|
|
687
|
-
if (!$file->isFile()) {
|
|
688
|
-
continue;
|
|
689
|
-
}
|
|
690
|
-
$zip->addFile($file->getPathname(), $file->getPathname());
|
|
691
|
-
}
|
|
692
|
-
$zip->close();
|
|
693
|
-
|
|
694
|
-
`
|
|
695
|
-
});
|
|
696
|
-
const e = await t.readFileAsBuffer("/tmp/build.zip");
|
|
697
|
-
y.writeFileSync(r, e);
|
|
698
|
-
}
|
|
699
|
-
export {
|
|
700
|
-
_e as p,
|
|
701
|
-
Se as r
|
|
702
|
-
};
|
|
703
|
-
//# sourceMappingURL=run-cli-FboNWUuJ.js.map
|