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