@wp-playground/cli 3.0.22 → 3.0.30
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 +80 -45
- package/blueprints-v1/worker-thread-v1.d.ts +6 -6
- package/blueprints-v2/worker-thread-v2.d.ts +10 -5
- package/cli.cjs +1 -1
- package/cli.js +1 -1
- package/index.cjs +1 -1
- package/index.js +6 -4
- package/is-valid-wordpress-slug.d.ts +1 -1
- package/mounts.d.ts +1 -4
- package/package.json +16 -14
- package/resolve-blueprint.d.ts +1 -1
- package/run-cli-D8BNUM1f.cjs +42 -0
- package/run-cli-D8BNUM1f.cjs.map +1 -0
- package/run-cli-pLJHMn5d.js +1234 -0
- package/run-cli-pLJHMn5d.js.map +1 -0
- package/run-cli.d.ts +22 -2
- package/utils/progress.d.ts +3 -0
- package/worker-thread-v1.cjs +2 -2
- package/worker-thread-v1.cjs.map +1 -1
- package/worker-thread-v1.js +123 -117
- package/worker-thread-v1.js.map +1 -1
- package/worker-thread-v2.cjs +12 -8
- package/worker-thread-v2.cjs.map +1 -1
- package/worker-thread-v2.js +150 -79
- package/worker-thread-v2.js.map +1 -1
- package/mounts-ChxECdbN.js +0 -131
- package/mounts-ChxECdbN.js.map +0 -1
- package/mounts-R4uHe-O-.cjs +0 -16
- package/mounts-R4uHe-O-.cjs.map +0 -1
- package/run-cli-BIOpeo2v.cjs +0 -46
- package/run-cli-BIOpeo2v.cjs.map +0 -1
- package/run-cli-LDWC8vQD.js +0 -1391
- package/run-cli-LDWC8vQD.js.map +0 -1
- package/xdebug-path-mappings.d.ts +0 -92
|
@@ -0,0 +1,1234 @@
|
|
|
1
|
+
import { logger as u, LogSeverity as V, errorLogPath as Z } from "@php-wasm/logger";
|
|
2
|
+
import { PHPResponse as _, consumeAPI as D, SupportedPHPVersions as he, printDebugDetails as me, exposeAPI as we, exposeSyncAPI as ge } from "@php-wasm/universal";
|
|
3
|
+
import { resolveRemoteBlueprint as ye, resolveRuntimeConfiguration as Y, compileBlueprintV1 as be, isBlueprintBundle as Pe, runBlueprintV1Steps as ve } from "@wp-playground/blueprints";
|
|
4
|
+
import { zipDirectory as ke, RecommendedPHPVersion as re } from "@wp-playground/common";
|
|
5
|
+
import p, { existsSync as se, mkdirSync as G } from "fs";
|
|
6
|
+
import { Worker as Q, MessageChannel as xe } from "worker_threads";
|
|
7
|
+
import { createNodeFsMountHandler as Se, FileLockManagerForNode as Ie } from "@php-wasm/node";
|
|
8
|
+
import w, { basename as R, join as ne } from "path";
|
|
9
|
+
import Te from "express";
|
|
10
|
+
import ie, { cpus as $e } from "os";
|
|
11
|
+
import { jspi as Ee } from "wasm-feature-detect";
|
|
12
|
+
import Ce from "yargs";
|
|
13
|
+
import { NodeJsFilesystem as We, OverlayFilesystem as Be, InMemoryFilesystem as Le, ZipFilesystem as Me } from "@wp-playground/storage";
|
|
14
|
+
import { EmscriptenDownloadMonitor as Re, ProgressTracker as De } from "@php-wasm/progress";
|
|
15
|
+
import { resolveWordPressRelease as Fe } from "@wp-playground/wordpress";
|
|
16
|
+
import C from "fs-extra";
|
|
17
|
+
import { startBridge as Ue } from "@php-wasm/xdebug-bridge";
|
|
18
|
+
import { dir as Ae, setGracefulCleanup as He } from "tmp-promise";
|
|
19
|
+
import Ve from "ps-man";
|
|
20
|
+
import { removeTempDirSymlink as Ne, createTempDirSymlink as _e, clearXdebugIDEConfig as Oe, addXdebugIDEConfig as je } from "@php-wasm/cli-util";
|
|
21
|
+
function J(e) {
|
|
22
|
+
const t = [];
|
|
23
|
+
for (const o of e) {
|
|
24
|
+
const n = o.split(":");
|
|
25
|
+
if (n.length !== 2)
|
|
26
|
+
throw new Error(`Invalid mount format: ${o}.
|
|
27
|
+
Expected format: /host/path:/vfs/path.
|
|
28
|
+
If your path contains a colon, e.g. C:\\myplugin, use the --mount-dir option instead.
|
|
29
|
+
Example: --mount-dir C:\\my-plugin /wordpress/wp-content/plugins/my-plugin`);
|
|
30
|
+
const [r, s] = n;
|
|
31
|
+
if (!se(r))
|
|
32
|
+
throw new Error(`Host path does not exist: ${r}`);
|
|
33
|
+
t.push({ hostPath: r, vfsPath: s });
|
|
34
|
+
}
|
|
35
|
+
return t;
|
|
36
|
+
}
|
|
37
|
+
function K(e) {
|
|
38
|
+
if (e.length % 2 !== 0)
|
|
39
|
+
throw new Error("Invalid mount format. Expected: /host/path /vfs/path");
|
|
40
|
+
const t = [];
|
|
41
|
+
for (let o = 0; o < e.length; o += 2) {
|
|
42
|
+
const n = e[o], r = e[o + 1];
|
|
43
|
+
if (!se(n))
|
|
44
|
+
throw new Error(`Host path does not exist: ${n}`);
|
|
45
|
+
t.push({
|
|
46
|
+
hostPath: w.resolve(process.cwd(), n),
|
|
47
|
+
vfsPath: r
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return t;
|
|
51
|
+
}
|
|
52
|
+
async function At(e, t) {
|
|
53
|
+
for (const o of t)
|
|
54
|
+
await e.mount(
|
|
55
|
+
o.vfsPath,
|
|
56
|
+
Se(o.hostPath)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
const ee = {
|
|
60
|
+
step: "runPHP",
|
|
61
|
+
code: {
|
|
62
|
+
filename: "activate-theme.php",
|
|
63
|
+
// @TODO: Remove DOCROOT check after moving totally to Blueprints v2.
|
|
64
|
+
content: `<?php
|
|
65
|
+
$docroot = getenv('DOCROOT') ? getenv('DOCROOT') : '/wordpress';
|
|
66
|
+
require_once "$docroot/wp-load.php";
|
|
67
|
+
$theme = wp_get_theme();
|
|
68
|
+
if (!$theme->exists()) {
|
|
69
|
+
$themes = wp_get_themes();
|
|
70
|
+
if (count($themes) > 0) {
|
|
71
|
+
$themeName = array_keys($themes)[0];
|
|
72
|
+
switch_theme($themeName);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
`
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
function qe(e) {
|
|
79
|
+
const t = e.autoMount, o = [...e.mount || []], n = [...e["mount-before-install"] || []], r = {
|
|
80
|
+
...e,
|
|
81
|
+
mount: o,
|
|
82
|
+
"mount-before-install": n,
|
|
83
|
+
"additional-blueprint-steps": [
|
|
84
|
+
...e["additional-blueprint-steps"] || []
|
|
85
|
+
]
|
|
86
|
+
};
|
|
87
|
+
if (Ye(t)) {
|
|
88
|
+
const s = R(t);
|
|
89
|
+
o.push({
|
|
90
|
+
hostPath: t,
|
|
91
|
+
vfsPath: `/wordpress/wp-content/plugins/${s}`
|
|
92
|
+
}), r["additional-blueprint-steps"].push({
|
|
93
|
+
step: "activatePlugin",
|
|
94
|
+
pluginPath: `/wordpress/wp-content/plugins/${R(t)}`
|
|
95
|
+
});
|
|
96
|
+
} else if (Ze(t)) {
|
|
97
|
+
const s = R(t);
|
|
98
|
+
o.push({
|
|
99
|
+
hostPath: t,
|
|
100
|
+
vfsPath: `/wordpress/wp-content/themes/${s}`
|
|
101
|
+
}), r["additional-blueprint-steps"].push(
|
|
102
|
+
e["experimental-blueprints-v2-runner"] ? {
|
|
103
|
+
step: "activateTheme",
|
|
104
|
+
themeDirectoryName: s
|
|
105
|
+
} : {
|
|
106
|
+
step: "activateTheme",
|
|
107
|
+
themeFolderName: s
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
} else if (Xe(t)) {
|
|
111
|
+
const s = p.readdirSync(t);
|
|
112
|
+
for (const a of s)
|
|
113
|
+
a !== "index.php" && o.push({
|
|
114
|
+
hostPath: `${t}/${a}`,
|
|
115
|
+
vfsPath: `/wordpress/wp-content/${a}`
|
|
116
|
+
});
|
|
117
|
+
r["additional-blueprint-steps"].push(ee);
|
|
118
|
+
} else ze(t) ? (n.push({ hostPath: t, vfsPath: "/wordpress" }), r.mode = "apply-to-existing-site", r["additional-blueprint-steps"].push(ee), r.wordpressInstallMode || (r.wordpressInstallMode = "install-from-existing-files-if-needed")) : (o.push({ hostPath: t, vfsPath: "/wordpress" }), r.mode = "mount-only");
|
|
119
|
+
return r;
|
|
120
|
+
}
|
|
121
|
+
function ze(e) {
|
|
122
|
+
const t = p.readdirSync(e);
|
|
123
|
+
return t.includes("wp-admin") && t.includes("wp-includes") && t.includes("wp-content");
|
|
124
|
+
}
|
|
125
|
+
function Xe(e) {
|
|
126
|
+
const t = p.readdirSync(e);
|
|
127
|
+
return t.includes("themes") || t.includes("plugins") || t.includes("mu-plugins") || t.includes("uploads");
|
|
128
|
+
}
|
|
129
|
+
function Ze(e) {
|
|
130
|
+
if (!p.readdirSync(e).includes("style.css"))
|
|
131
|
+
return !1;
|
|
132
|
+
const o = p.readFileSync(ne(e, "style.css"), "utf8");
|
|
133
|
+
return !!/^(?:[ \t]*<\?php)?[ \t/*#@]*Theme Name:(.*)$/im.exec(o);
|
|
134
|
+
}
|
|
135
|
+
function Ye(e) {
|
|
136
|
+
const t = p.readdirSync(e), o = /^(?:[ \t]*<\?php)?[ \t/*#@]*Plugin Name:(.*)$/im;
|
|
137
|
+
return !!t.filter((r) => r.endsWith(".php")).find((r) => {
|
|
138
|
+
const s = p.readFileSync(ne(e, r), "utf8");
|
|
139
|
+
return !!o.exec(s);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
async function Ge(e) {
|
|
143
|
+
const t = Te(), o = await new Promise((s, a) => {
|
|
144
|
+
const l = t.listen(e.port, () => {
|
|
145
|
+
const d = l.address();
|
|
146
|
+
d === null || typeof d == "string" ? a(new Error("Server address is not available")) : s(l);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
t.use("/", async (s, a) => {
|
|
150
|
+
let l;
|
|
151
|
+
try {
|
|
152
|
+
l = await e.handleRequest({
|
|
153
|
+
url: s.url,
|
|
154
|
+
headers: Je(s),
|
|
155
|
+
method: s.method,
|
|
156
|
+
body: await Qe(s)
|
|
157
|
+
});
|
|
158
|
+
} catch (d) {
|
|
159
|
+
u.error(d), l = _.forHttpCode(500);
|
|
160
|
+
}
|
|
161
|
+
a.statusCode = l.httpStatusCode;
|
|
162
|
+
for (const d in l.headers)
|
|
163
|
+
a.setHeader(d, l.headers[d]);
|
|
164
|
+
a.end(l.bytes);
|
|
165
|
+
});
|
|
166
|
+
const r = o.address().port;
|
|
167
|
+
return await e.onBind(o, r);
|
|
168
|
+
}
|
|
169
|
+
const Qe = async (e) => await new Promise((t) => {
|
|
170
|
+
const o = [];
|
|
171
|
+
e.on("data", (n) => {
|
|
172
|
+
o.push(n);
|
|
173
|
+
}), e.on("end", () => {
|
|
174
|
+
t(new Uint8Array(Buffer.concat(o)));
|
|
175
|
+
});
|
|
176
|
+
}), Je = (e) => {
|
|
177
|
+
const t = {};
|
|
178
|
+
if (e.rawHeaders && e.rawHeaders.length)
|
|
179
|
+
for (let o = 0; o < e.rawHeaders.length; o += 2)
|
|
180
|
+
t[e.rawHeaders[o].toLowerCase()] = e.rawHeaders[o + 1];
|
|
181
|
+
return t;
|
|
182
|
+
};
|
|
183
|
+
class Ke {
|
|
184
|
+
constructor(t) {
|
|
185
|
+
this.workerLoads = [], this.addWorker(t);
|
|
186
|
+
}
|
|
187
|
+
addWorker(t) {
|
|
188
|
+
this.workerLoads.push({
|
|
189
|
+
worker: t,
|
|
190
|
+
activeRequests: /* @__PURE__ */ new Set()
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
async removeWorker(t) {
|
|
194
|
+
const o = this.workerLoads.findIndex(
|
|
195
|
+
(r) => r.worker === t
|
|
196
|
+
);
|
|
197
|
+
if (o === -1)
|
|
198
|
+
return;
|
|
199
|
+
const [n] = this.workerLoads.splice(o, 1);
|
|
200
|
+
await Promise.allSettled(n.activeRequests);
|
|
201
|
+
}
|
|
202
|
+
async handleRequest(t) {
|
|
203
|
+
let o = this.workerLoads[0];
|
|
204
|
+
for (let r = 1; r < this.workerLoads.length; r++) {
|
|
205
|
+
const s = this.workerLoads[r];
|
|
206
|
+
s.activeRequests.size < o.activeRequests.size && (o = s);
|
|
207
|
+
}
|
|
208
|
+
const n = o.worker.request(t);
|
|
209
|
+
return o.activeRequests.add(n), n.url = t.url, n.finally(() => {
|
|
210
|
+
o.activeRequests.delete(n);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function et(e) {
|
|
215
|
+
return /^latest$|^trunk$|^nightly$|^(?:(\d+)\.(\d+)(?:\.(\d+))?)((?:-beta(?:\d+)?)|(?:-RC(?:\d+)?))?$/.test(e);
|
|
216
|
+
}
|
|
217
|
+
async function tt({
|
|
218
|
+
sourceString: e,
|
|
219
|
+
blueprintMayReadAdjacentFiles: t
|
|
220
|
+
}) {
|
|
221
|
+
if (!e)
|
|
222
|
+
return;
|
|
223
|
+
if (e.startsWith("http://") || e.startsWith("https://"))
|
|
224
|
+
return await ye(e);
|
|
225
|
+
let o = w.resolve(process.cwd(), e);
|
|
226
|
+
if (!p.existsSync(o))
|
|
227
|
+
throw new Error(`Blueprint file does not exist: ${o}`);
|
|
228
|
+
const n = p.statSync(o);
|
|
229
|
+
if (n.isDirectory() && (o = w.join(o, "blueprint.json")), !n.isFile() && n.isSymbolicLink())
|
|
230
|
+
throw new Error(
|
|
231
|
+
`Blueprint path is neither a file nor a directory: ${o}`
|
|
232
|
+
);
|
|
233
|
+
const r = w.extname(o);
|
|
234
|
+
switch (r) {
|
|
235
|
+
case ".zip":
|
|
236
|
+
return Me.fromArrayBuffer(
|
|
237
|
+
p.readFileSync(o).buffer
|
|
238
|
+
);
|
|
239
|
+
case ".json": {
|
|
240
|
+
const s = p.readFileSync(o, "utf-8");
|
|
241
|
+
try {
|
|
242
|
+
JSON.parse(s);
|
|
243
|
+
} catch {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`Blueprint file at ${o} is not a valid JSON file`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
const a = w.dirname(o), l = new We(a);
|
|
249
|
+
return new Be([
|
|
250
|
+
new Le({
|
|
251
|
+
"blueprint.json": s
|
|
252
|
+
}),
|
|
253
|
+
/**
|
|
254
|
+
* Wrap the NodeJS filesystem to prevent access to local files
|
|
255
|
+
* unless the user explicitly allowed it.
|
|
256
|
+
*/
|
|
257
|
+
{
|
|
258
|
+
read(d) {
|
|
259
|
+
if (!t)
|
|
260
|
+
throw new Error(
|
|
261
|
+
`Error: Blueprint contained tried to read a local file at path "${d}" (via a resource of type "bundled"). Playground restricts access to local resources by default as a security measure.
|
|
262
|
+
|
|
263
|
+
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.`
|
|
264
|
+
);
|
|
265
|
+
return l.read(d);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
]);
|
|
269
|
+
}
|
|
270
|
+
default:
|
|
271
|
+
throw new Error(
|
|
272
|
+
`Unsupported blueprint file extension: ${r}. Only .zip and .json files are supported.`
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function ae(e) {
|
|
277
|
+
return process.env.CI === "true" || process.env.CI === "1" || process.env.GITHUB_ACTIONS === "true" || process.env.GITHUB_ACTIONS === "1" || (process.env.TERM || "").toLowerCase() === "dumb" ? !1 : e ? !!e.isTTY : process.stdout.isTTY;
|
|
278
|
+
}
|
|
279
|
+
class ot {
|
|
280
|
+
constructor(t, o) {
|
|
281
|
+
this.lastProgressMessage = "", this.args = t, this.siteUrl = o.siteUrl, this.processIdSpaceLength = o.processIdSpaceLength, this.phpVersion = t.php;
|
|
282
|
+
}
|
|
283
|
+
getWorkerType() {
|
|
284
|
+
return "v2";
|
|
285
|
+
}
|
|
286
|
+
async bootAndSetUpInitialPlayground(t, o, n) {
|
|
287
|
+
const r = D(t);
|
|
288
|
+
await r.useFileLockManager(o);
|
|
289
|
+
const s = {
|
|
290
|
+
...this.args,
|
|
291
|
+
phpVersion: this.phpVersion,
|
|
292
|
+
siteUrl: this.siteUrl,
|
|
293
|
+
firstProcessId: 1,
|
|
294
|
+
processIdSpaceLength: this.processIdSpaceLength,
|
|
295
|
+
trace: this.args.debug || !1,
|
|
296
|
+
blueprint: this.args.blueprint,
|
|
297
|
+
withIntl: this.args.intl,
|
|
298
|
+
// We do not enable Xdebug by default for the initial worker
|
|
299
|
+
// because we do not imagine users expect to hit breakpoints
|
|
300
|
+
// until Playground has fully booted.
|
|
301
|
+
// TODO: Consider supporting Xdebug for the initial worker via a dedicated flag.
|
|
302
|
+
withXdebug: !1,
|
|
303
|
+
xdebug: void 0,
|
|
304
|
+
nativeInternalDirPath: n,
|
|
305
|
+
mountsBeforeWpInstall: this.args["mount-before-install"] || [],
|
|
306
|
+
mountsAfterWpInstall: this.args.mount || []
|
|
307
|
+
};
|
|
308
|
+
return await r.bootAndSetUpInitialWorker(s), r;
|
|
309
|
+
}
|
|
310
|
+
async bootPlayground({
|
|
311
|
+
worker: t,
|
|
312
|
+
fileLockManagerPort: o,
|
|
313
|
+
firstProcessId: n,
|
|
314
|
+
nativeInternalDirPath: r
|
|
315
|
+
}) {
|
|
316
|
+
const s = D(t.phpPort);
|
|
317
|
+
await s.useFileLockManager(o);
|
|
318
|
+
const a = {
|
|
319
|
+
...this.args,
|
|
320
|
+
phpVersion: this.phpVersion,
|
|
321
|
+
siteUrl: this.siteUrl,
|
|
322
|
+
firstProcessId: n,
|
|
323
|
+
processIdSpaceLength: this.processIdSpaceLength,
|
|
324
|
+
trace: this.args.debug || !1,
|
|
325
|
+
withIntl: this.args.intl,
|
|
326
|
+
withXdebug: !!this.args.xdebug,
|
|
327
|
+
nativeInternalDirPath: r,
|
|
328
|
+
mountsBeforeWpInstall: this.args["mount-before-install"] || [],
|
|
329
|
+
mountsAfterWpInstall: this.args.mount || []
|
|
330
|
+
};
|
|
331
|
+
return await s.bootWorker(a), s;
|
|
332
|
+
}
|
|
333
|
+
writeProgressUpdate(t, o, n) {
|
|
334
|
+
ae(t) && o !== this.lastProgressMessage && (this.lastProgressMessage = o, t.isTTY ? (t.cursorTo(0), t.write(o), t.clearLine(1), n && t.write(`
|
|
335
|
+
`)) : t.write(`${o}
|
|
336
|
+
`));
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
const O = w.join(ie.homedir(), ".wordpress-playground");
|
|
340
|
+
async function rt(e) {
|
|
341
|
+
return await le(
|
|
342
|
+
"https://github.com/WordPress/sqlite-database-integration/archive/refs/heads/develop.zip",
|
|
343
|
+
"sqlite.zip",
|
|
344
|
+
e
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
async function le(e, t, o) {
|
|
348
|
+
const n = w.join(O, t);
|
|
349
|
+
return C.existsSync(n) || (C.ensureDirSync(O), await st(e, n, o)), de(n);
|
|
350
|
+
}
|
|
351
|
+
async function st(e, t, o) {
|
|
352
|
+
const r = (await o.monitorFetch(fetch(e))).body.getReader(), s = `${t}.partial`, a = C.createWriteStream(s);
|
|
353
|
+
for (; ; ) {
|
|
354
|
+
const { done: l, value: d } = await r.read();
|
|
355
|
+
if (d && a.write(d), l)
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
a.close(), a.closed || await new Promise((l, d) => {
|
|
359
|
+
a.on("finish", () => {
|
|
360
|
+
C.renameSync(s, t), l(null);
|
|
361
|
+
}), a.on("error", (f) => {
|
|
362
|
+
C.removeSync(s), d(f);
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
function de(e, t) {
|
|
367
|
+
return new File([C.readFileSync(e)], R(e));
|
|
368
|
+
}
|
|
369
|
+
class nt {
|
|
370
|
+
constructor(t, o) {
|
|
371
|
+
this.lastProgressMessage = "", this.args = t, this.siteUrl = o.siteUrl, this.processIdSpaceLength = o.processIdSpaceLength;
|
|
372
|
+
}
|
|
373
|
+
getWorkerType() {
|
|
374
|
+
return "v1";
|
|
375
|
+
}
|
|
376
|
+
async bootAndSetUpInitialPlayground(t, o, n) {
|
|
377
|
+
let r, s, a;
|
|
378
|
+
const l = new Re();
|
|
379
|
+
if (this.args.wordpressInstallMode === "download-and-install") {
|
|
380
|
+
let I = !1;
|
|
381
|
+
l.addEventListener("progress", (q) => {
|
|
382
|
+
if (I)
|
|
383
|
+
return;
|
|
384
|
+
const { loaded: F, total: x } = q.detail, W = Math.floor(
|
|
385
|
+
Math.min(100, 100 * F / x)
|
|
386
|
+
);
|
|
387
|
+
I = W === 100, this.writeProgressUpdate(
|
|
388
|
+
process.stdout,
|
|
389
|
+
`Downloading WordPress ${W}%...`,
|
|
390
|
+
I
|
|
391
|
+
);
|
|
392
|
+
}), r = await Fe(this.args.wp), a = w.join(
|
|
393
|
+
O,
|
|
394
|
+
`prebuilt-wp-content-for-wp-${r.version}.zip`
|
|
395
|
+
), s = p.existsSync(a) ? de(a) : await le(
|
|
396
|
+
r.releaseUrl,
|
|
397
|
+
`${r.version}.zip`,
|
|
398
|
+
l
|
|
399
|
+
), u.log(
|
|
400
|
+
`Resolved WordPress release URL: ${r?.releaseUrl}`
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
let d;
|
|
404
|
+
this.args.skipSqliteSetup ? (u.log("Skipping SQLite integration plugin setup..."), d = void 0) : (u.log("Fetching SQLite integration plugin..."), d = await rt(l));
|
|
405
|
+
const f = this.args.followSymlinks === !0, i = this.args.experimentalTrace === !0, y = this.args["mount-before-install"] || [], g = this.args.mount || [], P = D(t);
|
|
406
|
+
await P.isConnected(), u.log("Booting WordPress...");
|
|
407
|
+
const k = await Y(
|
|
408
|
+
this.getEffectiveBlueprint()
|
|
409
|
+
);
|
|
410
|
+
return await P.useFileLockManager(o), await P.bootAndSetUpInitialWorker({
|
|
411
|
+
phpVersion: k.phpVersion,
|
|
412
|
+
wpVersion: k.wpVersion,
|
|
413
|
+
siteUrl: this.siteUrl,
|
|
414
|
+
mountsBeforeWpInstall: y,
|
|
415
|
+
mountsAfterWpInstall: g,
|
|
416
|
+
wordpressInstallMode: this.args.wordpressInstallMode || "download-and-install",
|
|
417
|
+
wordPressZip: s && await s.arrayBuffer(),
|
|
418
|
+
sqliteIntegrationPluginZip: await d?.arrayBuffer(),
|
|
419
|
+
firstProcessId: 0,
|
|
420
|
+
processIdSpaceLength: this.processIdSpaceLength,
|
|
421
|
+
followSymlinks: f,
|
|
422
|
+
trace: i,
|
|
423
|
+
internalCookieStore: this.args.internalCookieStore,
|
|
424
|
+
withIntl: this.args.intl,
|
|
425
|
+
// We do not enable Xdebug by default for the initial worker
|
|
426
|
+
// because we do not imagine users expect to hit breakpoints
|
|
427
|
+
// until Playground has fully booted.
|
|
428
|
+
// TODO: Consider supporting Xdebug for the initial worker via a dedicated flag.
|
|
429
|
+
withXdebug: !1,
|
|
430
|
+
nativeInternalDirPath: n
|
|
431
|
+
}), a && !this.args["mount-before-install"] && !p.existsSync(a) && (u.log("Caching preinstalled WordPress for the next boot..."), p.writeFileSync(
|
|
432
|
+
a,
|
|
433
|
+
await ke(P, "/wordpress")
|
|
434
|
+
), u.log("Cached!")), P;
|
|
435
|
+
}
|
|
436
|
+
async bootPlayground({
|
|
437
|
+
worker: t,
|
|
438
|
+
fileLockManagerPort: o,
|
|
439
|
+
firstProcessId: n,
|
|
440
|
+
nativeInternalDirPath: r
|
|
441
|
+
}) {
|
|
442
|
+
const s = D(
|
|
443
|
+
t.phpPort
|
|
444
|
+
);
|
|
445
|
+
await s.isConnected();
|
|
446
|
+
const a = await Y(
|
|
447
|
+
this.getEffectiveBlueprint()
|
|
448
|
+
);
|
|
449
|
+
return await s.useFileLockManager(o), await s.bootWorker({
|
|
450
|
+
phpVersion: a.phpVersion,
|
|
451
|
+
siteUrl: this.siteUrl,
|
|
452
|
+
mountsBeforeWpInstall: this.args["mount-before-install"] || [],
|
|
453
|
+
mountsAfterWpInstall: this.args.mount || [],
|
|
454
|
+
firstProcessId: n,
|
|
455
|
+
processIdSpaceLength: this.processIdSpaceLength,
|
|
456
|
+
followSymlinks: this.args.followSymlinks === !0,
|
|
457
|
+
trace: this.args.experimentalTrace === !0,
|
|
458
|
+
// @TODO: Move this to the request handler or else every worker
|
|
459
|
+
// will have a separate cookie store.
|
|
460
|
+
internalCookieStore: this.args.internalCookieStore,
|
|
461
|
+
withIntl: this.args.intl,
|
|
462
|
+
withXdebug: !!this.args.xdebug,
|
|
463
|
+
nativeInternalDirPath: r
|
|
464
|
+
}), await s.isReady(), s;
|
|
465
|
+
}
|
|
466
|
+
async compileInputBlueprint(t) {
|
|
467
|
+
const o = this.getEffectiveBlueprint(), n = new De();
|
|
468
|
+
let r = "", s = !1;
|
|
469
|
+
return n.addEventListener("progress", (a) => {
|
|
470
|
+
if (s)
|
|
471
|
+
return;
|
|
472
|
+
s = a.detail.progress === 100;
|
|
473
|
+
const l = Math.floor(a.detail.progress);
|
|
474
|
+
r = a.detail.caption || r || "Running the Blueprint";
|
|
475
|
+
const d = `${r.trim()} – ${l}%`;
|
|
476
|
+
this.writeProgressUpdate(
|
|
477
|
+
process.stdout,
|
|
478
|
+
d,
|
|
479
|
+
s
|
|
480
|
+
);
|
|
481
|
+
}), await be(o, {
|
|
482
|
+
progress: n,
|
|
483
|
+
additionalSteps: t
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
getEffectiveBlueprint() {
|
|
487
|
+
const t = this.args.blueprint;
|
|
488
|
+
return Pe(t) ? t : {
|
|
489
|
+
login: this.args.login,
|
|
490
|
+
...t || {},
|
|
491
|
+
preferredVersions: {
|
|
492
|
+
php: this.args.php ?? t?.preferredVersions?.php ?? re,
|
|
493
|
+
wp: this.args.wp ?? t?.preferredVersions?.wp ?? "latest",
|
|
494
|
+
...t?.preferredVersions || {}
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
writeProgressUpdate(t, o, n) {
|
|
499
|
+
this.args.verbosity !== j.Quiet.name && ae(t) && o !== this.lastProgressMessage && (this.lastProgressMessage = o, t.isTTY ? (t.cursorTo(0), t.write(o), t.clearLine(1), n && t.write(`
|
|
500
|
+
`)) : t.write(`${o}
|
|
501
|
+
`));
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
async function it(e, t = !0) {
|
|
505
|
+
const n = `${w.basename(process.argv0)}${e}${process.pid}-`, r = await Ae({
|
|
506
|
+
prefix: n,
|
|
507
|
+
/*
|
|
508
|
+
* Allow recursive cleanup on process exit.
|
|
509
|
+
*
|
|
510
|
+
* NOTE: I worried about whether this cleanup would follow symlinks
|
|
511
|
+
* and delete target files instead of unlinking the symlink,
|
|
512
|
+
* but this feature uses rimraf under the hood which respects symlinks:
|
|
513
|
+
* https://github.com/raszi/node-tmp/blob/3d2fe387f3f91b13830b9182faa02c3231ea8258/lib/tmp.js#L318
|
|
514
|
+
*/
|
|
515
|
+
unsafeCleanup: !0
|
|
516
|
+
});
|
|
517
|
+
return t && He(), r;
|
|
518
|
+
}
|
|
519
|
+
async function at(e, t, o) {
|
|
520
|
+
const r = (await lt(
|
|
521
|
+
e,
|
|
522
|
+
t,
|
|
523
|
+
o
|
|
524
|
+
)).map(
|
|
525
|
+
(s) => new Promise((a) => {
|
|
526
|
+
p.rm(s, { recursive: !0 }, (l) => {
|
|
527
|
+
l ? u.warn(
|
|
528
|
+
`Failed to delete stale Playground temp dir: ${s}`,
|
|
529
|
+
l
|
|
530
|
+
) : u.info(
|
|
531
|
+
`Deleted stale Playground temp dir: ${s}`
|
|
532
|
+
), a();
|
|
533
|
+
});
|
|
534
|
+
})
|
|
535
|
+
);
|
|
536
|
+
await Promise.all(r);
|
|
537
|
+
}
|
|
538
|
+
async function lt(e, t, o) {
|
|
539
|
+
try {
|
|
540
|
+
const n = p.readdirSync(o).map((s) => w.join(o, s)), r = [];
|
|
541
|
+
for (const s of n)
|
|
542
|
+
await dt(
|
|
543
|
+
e,
|
|
544
|
+
t,
|
|
545
|
+
s
|
|
546
|
+
) && r.push(s);
|
|
547
|
+
return r;
|
|
548
|
+
} catch (n) {
|
|
549
|
+
return u.warn(`Failed to find stale Playground temp dirs: ${n}`), [];
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
async function dt(e, t, o) {
|
|
553
|
+
if (!p.lstatSync(o).isDirectory())
|
|
554
|
+
return !1;
|
|
555
|
+
const r = w.basename(o);
|
|
556
|
+
if (!r.includes(e))
|
|
557
|
+
return !1;
|
|
558
|
+
const s = r.match(
|
|
559
|
+
new RegExp(`^(.+)${e}(\\d+)-`)
|
|
560
|
+
);
|
|
561
|
+
if (!s)
|
|
562
|
+
return !1;
|
|
563
|
+
const a = {
|
|
564
|
+
executableName: s[1],
|
|
565
|
+
pid: s[2]
|
|
566
|
+
};
|
|
567
|
+
if (await ut(a.pid, a.executableName))
|
|
568
|
+
return !1;
|
|
569
|
+
const l = Date.now() - t;
|
|
570
|
+
return p.statSync(o).mtime.getTime() < l;
|
|
571
|
+
}
|
|
572
|
+
async function ut(e, t) {
|
|
573
|
+
const [o] = await new Promise(
|
|
574
|
+
(n, r) => {
|
|
575
|
+
Ve.list(
|
|
576
|
+
{
|
|
577
|
+
pid: e,
|
|
578
|
+
name: t,
|
|
579
|
+
// Remove path from executable name in the results.
|
|
580
|
+
clean: !0
|
|
581
|
+
},
|
|
582
|
+
(s, a) => {
|
|
583
|
+
s ? r(s) : n(a);
|
|
584
|
+
}
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
);
|
|
588
|
+
return !!o && o.pid === e && o.command === t;
|
|
589
|
+
}
|
|
590
|
+
const j = {
|
|
591
|
+
Quiet: { name: "quiet", severity: V.Fatal },
|
|
592
|
+
Normal: { name: "normal", severity: V.Info },
|
|
593
|
+
Debug: { name: "debug", severity: V.Debug }
|
|
594
|
+
};
|
|
595
|
+
async function Ht(e) {
|
|
596
|
+
try {
|
|
597
|
+
const t = {
|
|
598
|
+
"site-url": {
|
|
599
|
+
describe: "Site URL to use for WordPress. Defaults to http://127.0.0.1:{port}",
|
|
600
|
+
type: "string"
|
|
601
|
+
},
|
|
602
|
+
php: {
|
|
603
|
+
describe: "PHP version to use.",
|
|
604
|
+
type: "string",
|
|
605
|
+
default: re,
|
|
606
|
+
choices: he
|
|
607
|
+
},
|
|
608
|
+
wp: {
|
|
609
|
+
describe: "WordPress version to use.",
|
|
610
|
+
type: "string",
|
|
611
|
+
default: "latest"
|
|
612
|
+
},
|
|
613
|
+
// @TODO: Support read-only mounts, e.g. via WORKERFS, a custom
|
|
614
|
+
// ReadOnlyNODEFS, or by copying the files into MEMFS
|
|
615
|
+
mount: {
|
|
616
|
+
describe: "Mount a directory to the PHP runtime (can be used multiple times). Format: /host/path:/vfs/path",
|
|
617
|
+
type: "array",
|
|
618
|
+
string: !0,
|
|
619
|
+
coerce: J
|
|
620
|
+
},
|
|
621
|
+
"mount-before-install": {
|
|
622
|
+
describe: "Mount a directory to the PHP runtime before WordPress installation (can be used multiple times). Format: /host/path:/vfs/path",
|
|
623
|
+
type: "array",
|
|
624
|
+
string: !0,
|
|
625
|
+
coerce: J
|
|
626
|
+
},
|
|
627
|
+
"mount-dir": {
|
|
628
|
+
describe: 'Mount a directory to the PHP runtime (can be used multiple times). Format: "/host/path" "/vfs/path"',
|
|
629
|
+
type: "array",
|
|
630
|
+
nargs: 2,
|
|
631
|
+
array: !0,
|
|
632
|
+
coerce: K
|
|
633
|
+
},
|
|
634
|
+
"mount-dir-before-install": {
|
|
635
|
+
describe: 'Mount a directory before WordPress installation (can be used multiple times). Format: "/host/path" "/vfs/path"',
|
|
636
|
+
type: "string",
|
|
637
|
+
nargs: 2,
|
|
638
|
+
array: !0,
|
|
639
|
+
coerce: K
|
|
640
|
+
},
|
|
641
|
+
login: {
|
|
642
|
+
describe: "Should log the user in",
|
|
643
|
+
type: "boolean",
|
|
644
|
+
default: !1
|
|
645
|
+
},
|
|
646
|
+
blueprint: {
|
|
647
|
+
describe: "Blueprint to execute.",
|
|
648
|
+
type: "string"
|
|
649
|
+
},
|
|
650
|
+
"blueprint-may-read-adjacent-files": {
|
|
651
|
+
describe: 'Consent flag: Allow "bundled" resources in a local blueprint to read files in the same directory as the blueprint file.',
|
|
652
|
+
type: "boolean",
|
|
653
|
+
default: !1
|
|
654
|
+
},
|
|
655
|
+
"wordpress-install-mode": {
|
|
656
|
+
describe: "Control how Playground prepares WordPress before booting.",
|
|
657
|
+
type: "string",
|
|
658
|
+
default: "download-and-install",
|
|
659
|
+
choices: [
|
|
660
|
+
"download-and-install",
|
|
661
|
+
"install-from-existing-files",
|
|
662
|
+
"install-from-existing-files-if-needed",
|
|
663
|
+
"do-not-attempt-installing"
|
|
664
|
+
]
|
|
665
|
+
},
|
|
666
|
+
"skip-wordpress-install": {
|
|
667
|
+
describe: "[Deprecated] Use --wordpress-install-mode instead.",
|
|
668
|
+
type: "boolean",
|
|
669
|
+
hidden: !0
|
|
670
|
+
},
|
|
671
|
+
"skip-sqlite-setup": {
|
|
672
|
+
describe: "Skip the SQLite integration plugin setup to allow the WordPress site to use MySQL.",
|
|
673
|
+
type: "boolean",
|
|
674
|
+
default: !1
|
|
675
|
+
},
|
|
676
|
+
// Hidden - Deprecated in favor of verbosity
|
|
677
|
+
quiet: {
|
|
678
|
+
describe: "Do not output logs and progress messages.",
|
|
679
|
+
type: "boolean",
|
|
680
|
+
default: !1,
|
|
681
|
+
hidden: !0
|
|
682
|
+
},
|
|
683
|
+
verbosity: {
|
|
684
|
+
describe: "Output logs and progress messages.",
|
|
685
|
+
type: "string",
|
|
686
|
+
choices: Object.values(j).map(
|
|
687
|
+
(i) => i.name
|
|
688
|
+
),
|
|
689
|
+
default: "normal"
|
|
690
|
+
},
|
|
691
|
+
debug: {
|
|
692
|
+
describe: "Print PHP error log content if an error occurs during Playground boot.",
|
|
693
|
+
type: "boolean",
|
|
694
|
+
default: !1
|
|
695
|
+
},
|
|
696
|
+
"auto-mount": {
|
|
697
|
+
describe: "Automatically mount the specified directory. If no path is provided, 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.",
|
|
698
|
+
type: "string"
|
|
699
|
+
},
|
|
700
|
+
"follow-symlinks": {
|
|
701
|
+
describe: `Allow Playground to follow symlinks by automatically mounting symlinked directories and files encountered in mounted directories.
|
|
702
|
+
Warning: Following symlinks will expose files outside mounted directories to Playground and could be a security risk.`,
|
|
703
|
+
type: "boolean",
|
|
704
|
+
default: !1
|
|
705
|
+
},
|
|
706
|
+
"experimental-trace": {
|
|
707
|
+
describe: "Print detailed messages about system behavior to the console. Useful for troubleshooting.",
|
|
708
|
+
type: "boolean",
|
|
709
|
+
default: !1,
|
|
710
|
+
// Hide this option because we want to replace with a more general log-level flag.
|
|
711
|
+
hidden: !0
|
|
712
|
+
},
|
|
713
|
+
"internal-cookie-store": {
|
|
714
|
+
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).",
|
|
715
|
+
type: "boolean",
|
|
716
|
+
default: !1
|
|
717
|
+
},
|
|
718
|
+
intl: {
|
|
719
|
+
describe: "Enable Intl.",
|
|
720
|
+
type: "boolean",
|
|
721
|
+
default: !0
|
|
722
|
+
},
|
|
723
|
+
xdebug: {
|
|
724
|
+
describe: "Enable Xdebug.",
|
|
725
|
+
type: "boolean",
|
|
726
|
+
default: !1
|
|
727
|
+
},
|
|
728
|
+
"experimental-unsafe-ide-integration": {
|
|
729
|
+
describe: "Enable experimental IDE development tools. This option edits IDE config files to set Xdebug path mappings and web server details. CAUTION: If there are bugs, this feature may break your IDE config files. Please consider backing up your IDE configs before using this feature.",
|
|
730
|
+
type: "string",
|
|
731
|
+
// The empty value means the option is enabled for all
|
|
732
|
+
// supported IDEs and, if needed, will create the relevant
|
|
733
|
+
// config file for each.
|
|
734
|
+
choices: ["", "vscode", "phpstorm"],
|
|
735
|
+
coerce: (i) => i === "" ? ["vscode", "phpstorm"] : [i]
|
|
736
|
+
},
|
|
737
|
+
"experimental-blueprints-v2-runner": {
|
|
738
|
+
describe: "Use the experimental Blueprint V2 runner.",
|
|
739
|
+
type: "boolean",
|
|
740
|
+
default: !1,
|
|
741
|
+
// Remove the "hidden" flag once Blueprint V2 is fully supported
|
|
742
|
+
hidden: !0
|
|
743
|
+
},
|
|
744
|
+
mode: {
|
|
745
|
+
describe: "Blueprints v2 runner mode to use. This option is required when using the --experimental-blueprints-v2-runner flag with a blueprint.",
|
|
746
|
+
type: "string",
|
|
747
|
+
choices: ["create-new-site", "apply-to-existing-site"],
|
|
748
|
+
// Remove the "hidden" flag once Blueprint V2 is fully supported
|
|
749
|
+
hidden: !0
|
|
750
|
+
}
|
|
751
|
+
}, o = {
|
|
752
|
+
port: {
|
|
753
|
+
describe: "Port to listen on when serving.",
|
|
754
|
+
type: "number",
|
|
755
|
+
default: 9400
|
|
756
|
+
},
|
|
757
|
+
"experimental-multi-worker": {
|
|
758
|
+
describe: "Enable experimental multi-worker support which requires 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.",
|
|
759
|
+
type: "number",
|
|
760
|
+
coerce: (i) => i ?? $e().length - 1
|
|
761
|
+
},
|
|
762
|
+
"experimental-devtools": {
|
|
763
|
+
describe: "Enable experimental browser development tools.",
|
|
764
|
+
type: "boolean"
|
|
765
|
+
}
|
|
766
|
+
}, n = {
|
|
767
|
+
outfile: {
|
|
768
|
+
describe: "When building, write to this output file.",
|
|
769
|
+
type: "string",
|
|
770
|
+
default: "wordpress.zip"
|
|
771
|
+
}
|
|
772
|
+
}, r = Ce(e).usage("Usage: wp-playground <command> [options]").command(
|
|
773
|
+
"server",
|
|
774
|
+
"Start a local WordPress server",
|
|
775
|
+
(i) => i.options({
|
|
776
|
+
...t,
|
|
777
|
+
...o
|
|
778
|
+
})
|
|
779
|
+
).command(
|
|
780
|
+
"run-blueprint",
|
|
781
|
+
"Execute a Blueprint without starting a server",
|
|
782
|
+
(i) => i.options({ ...t })
|
|
783
|
+
).command(
|
|
784
|
+
"build-snapshot",
|
|
785
|
+
"Build a ZIP snapshot of a WordPress site based on a Blueprint",
|
|
786
|
+
(i) => i.options({
|
|
787
|
+
...t,
|
|
788
|
+
...n
|
|
789
|
+
})
|
|
790
|
+
).demandCommand(1, "Please specify a command").strictCommands().conflicts(
|
|
791
|
+
"experimental-unsafe-ide-integration",
|
|
792
|
+
"experimental-devtools"
|
|
793
|
+
).showHelpOnFail(!1).fail((i, y, g) => {
|
|
794
|
+
if (y)
|
|
795
|
+
throw y;
|
|
796
|
+
i && i.includes("Please specify a command") && (g.showHelp(), console.error(`
|
|
797
|
+
` + i), process.exit(1)), console.error(i), process.exit(1);
|
|
798
|
+
}).strictOptions().check(async (i) => {
|
|
799
|
+
if (i["skip-wordpress-install"] === !0 && (i["wordpress-install-mode"] = "do-not-attempt-installing", i.wordpressInstallMode = "do-not-attempt-installing"), i.wp !== void 0 && typeof i.wp == "string" && !et(i.wp))
|
|
800
|
+
try {
|
|
801
|
+
new URL(i.wp);
|
|
802
|
+
} catch {
|
|
803
|
+
throw new Error(
|
|
804
|
+
'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"'
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
const y = i["site-url"];
|
|
808
|
+
if (typeof y == "string" && y.trim() !== "")
|
|
809
|
+
try {
|
|
810
|
+
new URL(y);
|
|
811
|
+
} catch {
|
|
812
|
+
throw new Error(
|
|
813
|
+
`Invalid site-url "${y}". Please provide a valid URL (e.g., http://localhost:8080 or https://example.com)`
|
|
814
|
+
);
|
|
815
|
+
}
|
|
816
|
+
if (i["auto-mount"]) {
|
|
817
|
+
let g = !1;
|
|
818
|
+
try {
|
|
819
|
+
g = p.statSync(
|
|
820
|
+
i["auto-mount"]
|
|
821
|
+
).isDirectory();
|
|
822
|
+
} catch {
|
|
823
|
+
g = !1;
|
|
824
|
+
}
|
|
825
|
+
if (!g)
|
|
826
|
+
throw new Error(
|
|
827
|
+
`The specified --auto-mount path is not a directory: '${i["auto-mount"]}'.`
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
if (i["experimental-multi-worker"] !== void 0) {
|
|
831
|
+
if (i._[0] !== "server")
|
|
832
|
+
throw new Error(
|
|
833
|
+
"The --experimental-multi-worker flag is only supported when running the server command."
|
|
834
|
+
);
|
|
835
|
+
if (i["experimental-multi-worker"] !== void 0 && typeof i["experimental-multi-worker"] == "number" && i["experimental-multi-worker"] <= 1)
|
|
836
|
+
throw new Error(
|
|
837
|
+
"The --experimental-multi-worker flag must be a positive integer greater than 1."
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
if (i["experimental-blueprints-v2-runner"] === !0) {
|
|
841
|
+
if (i.mode !== void 0) {
|
|
842
|
+
if (i["wordpress-install-mode"] !== void 0)
|
|
843
|
+
throw new Error(
|
|
844
|
+
"The --wordpress-install-mode option cannot be used with the --mode option. Use one or the other."
|
|
845
|
+
);
|
|
846
|
+
if ("skip-sqlite-setup" in i)
|
|
847
|
+
throw new Error(
|
|
848
|
+
"The --skipSqliteSetup option is not supported in Blueprint V2 mode."
|
|
849
|
+
);
|
|
850
|
+
if (i["auto-mount"] !== void 0)
|
|
851
|
+
throw new Error(
|
|
852
|
+
"The --mode option cannot be used with --auto-mount because --auto-mount automatically sets the mode."
|
|
853
|
+
);
|
|
854
|
+
} else
|
|
855
|
+
i["wordpress-install-mode"] === "do-not-attempt-installing" ? i.mode = "apply-to-existing-site" : i.mode = "create-new-site";
|
|
856
|
+
const g = i.allow || [];
|
|
857
|
+
i.followSymlinks === !0 && g.push("follow-symlinks"), i["blueprint-may-read-adjacent-files"] === !0 && g.push("read-local-fs"), i.allow = g;
|
|
858
|
+
} else if (i.mode !== void 0)
|
|
859
|
+
throw new Error(
|
|
860
|
+
"The --mode option requires the --experimentalBlueprintsV2Runner flag."
|
|
861
|
+
);
|
|
862
|
+
return !0;
|
|
863
|
+
});
|
|
864
|
+
r.wrap(r.terminalWidth());
|
|
865
|
+
const s = await r.argv, a = s._[0];
|
|
866
|
+
["run-blueprint", "server", "build-snapshot"].includes(a) || (r.showHelp(), process.exit(1));
|
|
867
|
+
const l = {
|
|
868
|
+
...s,
|
|
869
|
+
command: a,
|
|
870
|
+
mount: [
|
|
871
|
+
...s.mount || [],
|
|
872
|
+
...s["mount-dir"] || []
|
|
873
|
+
],
|
|
874
|
+
"mount-before-install": [
|
|
875
|
+
...s["mount-before-install"] || [],
|
|
876
|
+
...s["mount-dir-before-install"] || []
|
|
877
|
+
]
|
|
878
|
+
}, d = await ft(l);
|
|
879
|
+
d === void 0 && process.exit(0);
|
|
880
|
+
const f = /* @__PURE__ */ (() => {
|
|
881
|
+
let i;
|
|
882
|
+
return async () => {
|
|
883
|
+
i !== void 0 && (i = d[Symbol.asyncDispose]()), await i, process.exit(0);
|
|
884
|
+
};
|
|
885
|
+
})();
|
|
886
|
+
process.on("SIGINT", f), process.on("SIGTERM", f);
|
|
887
|
+
} catch (t) {
|
|
888
|
+
if (!(t instanceof Error))
|
|
889
|
+
throw t;
|
|
890
|
+
if (process.argv.includes("--debug"))
|
|
891
|
+
me(t);
|
|
892
|
+
else {
|
|
893
|
+
const n = [];
|
|
894
|
+
let r = t;
|
|
895
|
+
do
|
|
896
|
+
n.push(r.message), r = r.cause;
|
|
897
|
+
while (r instanceof Error);
|
|
898
|
+
console.error(
|
|
899
|
+
"\x1B[1m" + n.join(" caused by: ") + "\x1B[0m"
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
process.exit(1);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
const ct = Symbol("playground-cli-testing"), E = (e) => process.stdout.isTTY ? "\x1B[1m" + e + "\x1B[0m" : e, pt = (e) => process.stdout.isTTY ? `\x1B[2m${e}\x1B[0m` : e, N = (e) => process.stdout.isTTY ? `\x1B[3m${e}\x1B[0m` : e, te = (e) => process.stdout.isTTY ? `\x1B[33m${e}\x1B[0m` : e;
|
|
906
|
+
async function ft(e) {
|
|
907
|
+
let t, o;
|
|
908
|
+
const n = /* @__PURE__ */ new Map();
|
|
909
|
+
if (e.autoMount !== void 0 && (e.autoMount === "" && (e = { ...e, autoMount: process.cwd() }), e = qe(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) {
|
|
910
|
+
const f = Object.values(j).find(
|
|
911
|
+
(i) => i.name === e.verbosity
|
|
912
|
+
).severity;
|
|
913
|
+
u.setSeverityFilterLevel(f);
|
|
914
|
+
}
|
|
915
|
+
e.intl || (e.intl = !0);
|
|
916
|
+
const r = e.command === "server" ? e.port ?? 9400 : 0, s = ie.platform() === "win32" ? (
|
|
917
|
+
// @TODO: Enable fs-ext here when it works with Windows.
|
|
918
|
+
void 0
|
|
919
|
+
) : await import("fs-ext").then((f) => f.flockSync).catch(() => {
|
|
920
|
+
u.warn(
|
|
921
|
+
"The fs-ext package is not installed. Internal file locking will not be integrated with host OS file locking."
|
|
922
|
+
);
|
|
923
|
+
}), a = new Ie(s);
|
|
924
|
+
let l = !1, d = !0;
|
|
925
|
+
return u.log("Starting a PHP server..."), Ge({
|
|
926
|
+
port: r,
|
|
927
|
+
onBind: async (f, i) => {
|
|
928
|
+
const y = "127.0.0.1", g = `http://${y}:${i}`, P = e["site-url"] || g, k = e.command === "server" ? e.experimentalMultiWorker ?? 1 : 1, I = e.command === "server" ? (
|
|
929
|
+
// Account for the initial worker which is discarded by the server after setup.
|
|
930
|
+
k + 1
|
|
931
|
+
) : k, F = 2 ** 31 - 1, x = Math.floor(
|
|
932
|
+
F / I
|
|
933
|
+
), W = "-playground-cli-site-", T = await it(W);
|
|
934
|
+
u.debug(`Native temp dir for VFS root: ${T.path}`);
|
|
935
|
+
const B = "WP Playground CLI - Listen for Xdebug", z = ".playground-xdebug-root", X = w.join(process.cwd(), z);
|
|
936
|
+
if (await Ne(X), e.xdebug && e.experimentalUnsafeIdeIntegration) {
|
|
937
|
+
await _e(
|
|
938
|
+
T.path,
|
|
939
|
+
X,
|
|
940
|
+
process.platform
|
|
941
|
+
);
|
|
942
|
+
const c = {
|
|
943
|
+
hostPath: w.join(".", w.sep, z),
|
|
944
|
+
vfsPath: "/"
|
|
945
|
+
};
|
|
946
|
+
try {
|
|
947
|
+
await Oe(B, process.cwd());
|
|
948
|
+
const m = typeof e.xdebug == "object" ? e.xdebug : void 0, v = await je({
|
|
949
|
+
name: B,
|
|
950
|
+
host: y,
|
|
951
|
+
port: i,
|
|
952
|
+
ides: e.experimentalUnsafeIdeIntegration,
|
|
953
|
+
cwd: process.cwd(),
|
|
954
|
+
mounts: [
|
|
955
|
+
c,
|
|
956
|
+
...e["mount-before-install"] || [],
|
|
957
|
+
...e.mount || []
|
|
958
|
+
],
|
|
959
|
+
ideKey: m?.ideKey
|
|
960
|
+
}), h = e.experimentalUnsafeIdeIntegration, b = h.includes("vscode"), S = h.includes("phpstorm"), M = Object.values(v);
|
|
961
|
+
console.log(""), M.length > 0 ? (console.log(E("Xdebug configured successfully")), console.log(
|
|
962
|
+
te("Updated IDE config: ") + M.join(" ")
|
|
963
|
+
), console.log(
|
|
964
|
+
te("Playground source root: ") + ".playground-xdebug-root" + N(
|
|
965
|
+
pt(
|
|
966
|
+
" – you can set breakpoints and preview Playground's VFS structure in there."
|
|
967
|
+
)
|
|
968
|
+
)
|
|
969
|
+
)) : (console.log(E("Xdebug configuration failed.")), console.log(
|
|
970
|
+
"No IDE-specific project settings directory was found in the current working directory."
|
|
971
|
+
)), console.log(""), b && v.vscode && (console.log(E("VS Code / Cursor instructions:")), console.log(
|
|
972
|
+
" 1. Ensure you have installed an IDE extension for PHP Debugging"
|
|
973
|
+
), console.log(
|
|
974
|
+
` (The ${E("PHP Debug")} extension by ${E(
|
|
975
|
+
"Xdebug"
|
|
976
|
+
)} has been a solid option)`
|
|
977
|
+
), console.log(
|
|
978
|
+
" 2. Open the Run and Debug panel on the left sidebar"
|
|
979
|
+
), console.log(
|
|
980
|
+
` 3. Select "${N(
|
|
981
|
+
B
|
|
982
|
+
)}" from the dropdown`
|
|
983
|
+
), console.log(' 3. Click "start debugging"'), console.log(
|
|
984
|
+
" 5. Set a breakpoint. For example, in .playground-xdebug-root/wordpress/index.php"
|
|
985
|
+
), console.log(
|
|
986
|
+
" 6. Visit Playground in your browser to hit the breakpoint"
|
|
987
|
+
), S && console.log("")), S && v.phpstorm && (console.log(E("PhpStorm instructions:")), console.log(
|
|
988
|
+
` 1. Choose "${N(
|
|
989
|
+
B
|
|
990
|
+
)}" debug configuration in the toolbar`
|
|
991
|
+
), console.log(" 2. Click the debug button (bug icon)`"), console.log(
|
|
992
|
+
" 3. Set a breakpoint. For example, in .playground-xdebug-root/wordpress/index.php"
|
|
993
|
+
), console.log(
|
|
994
|
+
" 4. Visit Playground in your browser to hit the breakpoint"
|
|
995
|
+
)), console.log("");
|
|
996
|
+
} catch (m) {
|
|
997
|
+
throw new Error("Could not configure Xdebug", {
|
|
998
|
+
cause: m
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
const ue = w.dirname(T.path), ce = 2 * 24 * 60 * 60 * 1e3;
|
|
1003
|
+
at(
|
|
1004
|
+
W,
|
|
1005
|
+
ce,
|
|
1006
|
+
ue
|
|
1007
|
+
);
|
|
1008
|
+
const U = w.join(T.path, "internal");
|
|
1009
|
+
G(U);
|
|
1010
|
+
const pe = [
|
|
1011
|
+
"wordpress",
|
|
1012
|
+
// Note: These dirs are from Emscripten's "default dirs" list:
|
|
1013
|
+
// https://github.com/emscripten-core/emscripten/blob/f431ec220e472e1f8d3db6b52fe23fb377facf30/src/lib/libfs.js#L1400-L1402
|
|
1014
|
+
//
|
|
1015
|
+
// Any Playground process with multiple workers may assume
|
|
1016
|
+
// these are part of a shared filesystem, so let's recognize
|
|
1017
|
+
// them explicitly here.
|
|
1018
|
+
"tmp",
|
|
1019
|
+
"home"
|
|
1020
|
+
];
|
|
1021
|
+
for (const c of pe) {
|
|
1022
|
+
const m = (h) => h.vfsPath === `/${c}`;
|
|
1023
|
+
if (!(e["mount-before-install"]?.some(m) || e.mount?.some(m))) {
|
|
1024
|
+
const h = w.join(
|
|
1025
|
+
T.path,
|
|
1026
|
+
c
|
|
1027
|
+
);
|
|
1028
|
+
G(h), e["mount-before-install"] === void 0 && (e["mount-before-install"] = []), e["mount-before-install"].unshift({
|
|
1029
|
+
vfsPath: `/${c}`,
|
|
1030
|
+
hostPath: h
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
if (e["mount-before-install"])
|
|
1035
|
+
for (const c of e["mount-before-install"])
|
|
1036
|
+
u.debug(
|
|
1037
|
+
`Mount before WP install: ${c.vfsPath} -> ${c.hostPath}`
|
|
1038
|
+
);
|
|
1039
|
+
if (e.mount)
|
|
1040
|
+
for (const c of e.mount)
|
|
1041
|
+
u.debug(
|
|
1042
|
+
`Mount after WP install: ${c.vfsPath} -> ${c.hostPath}`
|
|
1043
|
+
);
|
|
1044
|
+
let $;
|
|
1045
|
+
e["experimental-blueprints-v2-runner"] ? $ = new ot(e, {
|
|
1046
|
+
siteUrl: P,
|
|
1047
|
+
processIdSpaceLength: x
|
|
1048
|
+
}) : ($ = new nt(e, {
|
|
1049
|
+
siteUrl: P,
|
|
1050
|
+
processIdSpaceLength: x
|
|
1051
|
+
}), typeof e.blueprint == "string" && (e.blueprint = await tt({
|
|
1052
|
+
sourceString: e.blueprint,
|
|
1053
|
+
blueprintMayReadAdjacentFiles: e["blueprint-may-read-adjacent-files"] === !0
|
|
1054
|
+
})));
|
|
1055
|
+
let A = !1;
|
|
1056
|
+
const L = async function() {
|
|
1057
|
+
A || (A = !0, await Promise.all(
|
|
1058
|
+
[...n].map(
|
|
1059
|
+
async ([m, v]) => {
|
|
1060
|
+
await v.dispose(), await m.terminate();
|
|
1061
|
+
}
|
|
1062
|
+
)
|
|
1063
|
+
), f && await new Promise((m) => f.close(m)), await T.cleanup());
|
|
1064
|
+
}, fe = ht(
|
|
1065
|
+
I,
|
|
1066
|
+
$.getWorkerType(),
|
|
1067
|
+
({ exitCode: c, workerIndex: m }) => {
|
|
1068
|
+
A || c === 0 && u.error(
|
|
1069
|
+
`Worker ${m} exited with code ${c}
|
|
1070
|
+
`
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
);
|
|
1074
|
+
u.log("Starting up workers");
|
|
1075
|
+
try {
|
|
1076
|
+
const c = await fe, m = await oe(a);
|
|
1077
|
+
{
|
|
1078
|
+
const h = c.shift(), b = await $.bootAndSetUpInitialPlayground(
|
|
1079
|
+
h.phpPort,
|
|
1080
|
+
m,
|
|
1081
|
+
U
|
|
1082
|
+
);
|
|
1083
|
+
if (n.set(
|
|
1084
|
+
h.worker,
|
|
1085
|
+
b
|
|
1086
|
+
), await b.isReady(), l = !0, u.log("Booted!"), t = new Ke(b), !e["experimental-blueprints-v2-runner"]) {
|
|
1087
|
+
const S = await $.compileInputBlueprint(
|
|
1088
|
+
e["additional-blueprint-steps"] || []
|
|
1089
|
+
);
|
|
1090
|
+
S && (u.log("Running the Blueprint..."), await ve(
|
|
1091
|
+
S,
|
|
1092
|
+
b
|
|
1093
|
+
), u.log("Finished running the blueprint"));
|
|
1094
|
+
}
|
|
1095
|
+
if (e.command === "build-snapshot") {
|
|
1096
|
+
await wt(o, e.outfile), u.log(`WordPress exported to ${e.outfile}`), await L();
|
|
1097
|
+
return;
|
|
1098
|
+
} else if (e.command === "run-blueprint") {
|
|
1099
|
+
u.log("Blueprint executed"), await L();
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
await t.removeWorker(b), await b.dispose(), await h.worker.terminate(), n.delete(h.worker);
|
|
1103
|
+
}
|
|
1104
|
+
u.log("Preparing workers...");
|
|
1105
|
+
const v = x;
|
|
1106
|
+
return [o] = await Promise.all(
|
|
1107
|
+
c.map(async (h, b) => {
|
|
1108
|
+
const S = v + b * x, M = await oe(a), H = await $.bootPlayground({
|
|
1109
|
+
worker: h,
|
|
1110
|
+
fileLockManagerPort: M,
|
|
1111
|
+
firstProcessId: S,
|
|
1112
|
+
nativeInternalDirPath: U
|
|
1113
|
+
});
|
|
1114
|
+
return n.set(
|
|
1115
|
+
h.worker,
|
|
1116
|
+
H
|
|
1117
|
+
), t.addWorker(H), H;
|
|
1118
|
+
})
|
|
1119
|
+
), u.log(
|
|
1120
|
+
`WordPress is running on ${g} with ${k} worker(s)`
|
|
1121
|
+
), e.xdebug && e.experimentalDevtools && (await Ue({
|
|
1122
|
+
phpInstance: o,
|
|
1123
|
+
phpRoot: "/wordpress"
|
|
1124
|
+
})).start(), {
|
|
1125
|
+
playground: o,
|
|
1126
|
+
server: f,
|
|
1127
|
+
serverUrl: g,
|
|
1128
|
+
[Symbol.asyncDispose]: L,
|
|
1129
|
+
[ct]: {
|
|
1130
|
+
workerThreadCount: k,
|
|
1131
|
+
getWorkerNumberFromProcessId: (h) => Math.floor(h / x)
|
|
1132
|
+
}
|
|
1133
|
+
};
|
|
1134
|
+
} catch (c) {
|
|
1135
|
+
if (!e.debug)
|
|
1136
|
+
throw c;
|
|
1137
|
+
let m = "";
|
|
1138
|
+
throw await o?.fileExists(Z) && (m = await o.readFileAsText(Z)), await L(), new Error(m, { cause: c });
|
|
1139
|
+
}
|
|
1140
|
+
},
|
|
1141
|
+
async handleRequest(f) {
|
|
1142
|
+
if (!l)
|
|
1143
|
+
return _.forHttpCode(
|
|
1144
|
+
502,
|
|
1145
|
+
"WordPress is not ready yet"
|
|
1146
|
+
);
|
|
1147
|
+
if (d) {
|
|
1148
|
+
d = !1;
|
|
1149
|
+
const i = {
|
|
1150
|
+
"Content-Type": ["text/plain"],
|
|
1151
|
+
"Content-Length": ["0"],
|
|
1152
|
+
Location: [f.url]
|
|
1153
|
+
};
|
|
1154
|
+
return f.headers?.cookie?.includes(
|
|
1155
|
+
"playground_auto_login_already_happened"
|
|
1156
|
+
) && (i["Set-Cookie"] = [
|
|
1157
|
+
"playground_auto_login_already_happened=1; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Path=/"
|
|
1158
|
+
]), new _(302, i, new Uint8Array());
|
|
1159
|
+
}
|
|
1160
|
+
return await t.handleRequest(f);
|
|
1161
|
+
}
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
async function ht(e, t, o) {
|
|
1165
|
+
const n = [];
|
|
1166
|
+
for (let r = 0; r < e; r++) {
|
|
1167
|
+
const a = mt(t, { onExit: (l) => {
|
|
1168
|
+
o({
|
|
1169
|
+
exitCode: l,
|
|
1170
|
+
workerIndex: r
|
|
1171
|
+
});
|
|
1172
|
+
} });
|
|
1173
|
+
n.push(a);
|
|
1174
|
+
}
|
|
1175
|
+
return Promise.all(n);
|
|
1176
|
+
}
|
|
1177
|
+
function mt(e, { onExit: t } = {}) {
|
|
1178
|
+
let o;
|
|
1179
|
+
return e === "v1" ? o = new Q(new URL("./worker-thread-v1.js", import.meta.url)) : o = new Q(new URL("./worker-thread-v2.js", import.meta.url)), new Promise((n, r) => {
|
|
1180
|
+
o.once("message", function(a) {
|
|
1181
|
+
a.command === "worker-script-initialized" && n({ worker: o, phpPort: a.phpPort });
|
|
1182
|
+
}), o.once("error", function(a) {
|
|
1183
|
+
console.error(a);
|
|
1184
|
+
const l = new Error(
|
|
1185
|
+
`Worker failed to load worker. ${a.message ? `Original error: ${a.message}` : ""}`
|
|
1186
|
+
);
|
|
1187
|
+
r(l);
|
|
1188
|
+
});
|
|
1189
|
+
let s = !1;
|
|
1190
|
+
o.once("spawn", () => {
|
|
1191
|
+
s = !0;
|
|
1192
|
+
}), o.once("exit", (a) => {
|
|
1193
|
+
s || r(new Error(`Worker exited before spawning: ${a}`)), t?.(a);
|
|
1194
|
+
});
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
async function oe(e) {
|
|
1198
|
+
const { port1: t, port2: o } = new xe();
|
|
1199
|
+
return await Ee() ? we(e, null, t) : await ge(e, t), o;
|
|
1200
|
+
}
|
|
1201
|
+
async function wt(e, t) {
|
|
1202
|
+
await e.run({
|
|
1203
|
+
code: `<?php
|
|
1204
|
+
$zip = new ZipArchive();
|
|
1205
|
+
if(false === $zip->open('/tmp/build.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
|
|
1206
|
+
throw new Exception('Failed to create ZIP');
|
|
1207
|
+
}
|
|
1208
|
+
$files = new RecursiveIteratorIterator(
|
|
1209
|
+
new RecursiveDirectoryIterator('/wordpress')
|
|
1210
|
+
);
|
|
1211
|
+
foreach ($files as $file) {
|
|
1212
|
+
echo $file . PHP_EOL;
|
|
1213
|
+
if (!$file->isFile()) {
|
|
1214
|
+
continue;
|
|
1215
|
+
}
|
|
1216
|
+
$zip->addFile($file->getPathname(), $file->getPathname());
|
|
1217
|
+
}
|
|
1218
|
+
$zip->close();
|
|
1219
|
+
|
|
1220
|
+
`
|
|
1221
|
+
});
|
|
1222
|
+
const o = await e.readFileAsBuffer("/tmp/build.zip");
|
|
1223
|
+
p.writeFileSync(t, o);
|
|
1224
|
+
}
|
|
1225
|
+
export {
|
|
1226
|
+
j as L,
|
|
1227
|
+
ae as a,
|
|
1228
|
+
ct as i,
|
|
1229
|
+
At as m,
|
|
1230
|
+
Ht as p,
|
|
1231
|
+
ft as r,
|
|
1232
|
+
mt as s
|
|
1233
|
+
};
|
|
1234
|
+
//# sourceMappingURL=run-cli-pLJHMn5d.js.map
|