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