@wp-playground/cli 1.2.1 → 1.2.3
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 +3 -0
- package/blueprints.phar +0 -0
- package/cli.cjs +1 -1
- package/cli.js +1 -1
- package/index.cjs +1 -1
- package/index.js +1 -1
- package/mounts-B-Qdcyyt.js +124 -0
- package/mounts-B-Qdcyyt.js.map +1 -0
- package/mounts-D7bhhGq3.cjs +15 -0
- package/mounts-D7bhhGq3.cjs.map +1 -0
- package/{mount.d.ts → mounts.d.ts} +10 -1
- package/package.json +11 -12
- package/run-cli-B5BfXxxJ.cjs +24 -0
- package/run-cli-B5BfXxxJ.cjs.map +1 -0
- package/run-cli-W9VNXESj.js +586 -0
- package/run-cli-W9VNXESj.js.map +1 -0
- package/run-cli.d.ts +4 -1
- package/v2.d.ts +45 -0
- package/worker-thread-CYvRK9UX.js +130 -0
- package/worker-thread-CYvRK9UX.js.map +1 -0
- package/worker-thread.cjs +2 -2
- package/worker-thread.cjs.map +1 -1
- package/worker-thread.d.ts +26 -3
- package/worker-thread.js +71 -51
- package/worker-thread.js.map +1 -1
- package/cli-auto-mount.d.ts +0 -19
- package/run-cli-CbJy_CRO.js +0 -8436
- package/run-cli-CbJy_CRO.js.map +0 -1
- package/run-cli-Dff9jZvG.cjs +0 -43
- package/run-cli-Dff9jZvG.cjs.map +0 -1
- package/worker-thread-BQ8BezvJ.js +0 -152
- package/worker-thread-BQ8BezvJ.js.map +0 -1
package/README.md
CHANGED
|
@@ -95,6 +95,9 @@ The `server` command supports the following optional arguments:
|
|
|
95
95
|
- `--skip-sqlite-setup`: Do not set up the SQLite database integration.
|
|
96
96
|
- `--quiet`: Do not output logs and progress messages.
|
|
97
97
|
- `--debug`: Print the PHP error log if an error occurs during boot.
|
|
98
|
+
- `--follow-symlinks`: Allow Playground to follow symlinks by automatically mounting symlinked directories and files encountered in mounted directories. ⚠️ Warning: Following symlinks will expose files outside mounted directories to Playground and could be a security risk.
|
|
99
|
+
- `--experimental-multi-worker`: Enables experimental multi-worker support. It needs JSPI and a /wordpress directory on a real filesystem. You can pass a positive number to use a specific number of workers, otherwise, it defaults to the number of CPUs minus one.
|
|
100
|
+
- `--internal-cookie-store`: Enables Playground's internal cookie handling. When active, Playground uses an HttpCookieStore to manage and persist cookies across requests. If disabled, cookies are handled externally, like by a browser in Node.js.
|
|
98
101
|
|
|
99
102
|
## Need some help with the CLI?
|
|
100
103
|
|
package/blueprints.phar
ADDED
|
Binary file
|
package/cli.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const s=require("./run-cli-
|
|
1
|
+
"use strict";const s=require("./run-cli-B5BfXxxJ.cjs");s.parseOptionsAndRunCLI().catch(()=>{process.exit(1)});
|
|
2
2
|
//# sourceMappingURL=cli.cjs.map
|
package/cli.js
CHANGED
package/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./run-cli-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./run-cli-B5BfXxxJ.cjs");exports.parseOptionsAndRunCLI=n.parseOptionsAndRunCLI;exports.runCLI=n.runCLI;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/index.js
CHANGED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { createNodeFsMountHandler as l } from "@php-wasm/node";
|
|
2
|
+
import r, { existsSync as c } from "fs";
|
|
3
|
+
import m, { basename as p, join as h } from "path";
|
|
4
|
+
function v(e) {
|
|
5
|
+
const t = [];
|
|
6
|
+
for (const n of e) {
|
|
7
|
+
const o = n.split(":");
|
|
8
|
+
if (o.length !== 2)
|
|
9
|
+
throw new Error(`Invalid mount format: ${n}.
|
|
10
|
+
Expected format: /host/path:/vfs/path.
|
|
11
|
+
If your path contains a colon, e.g. C:\\myplugin, use the --mount-dir option instead.
|
|
12
|
+
Example: --mount-dir C:\\my-plugin /wordpress/wp-content/plugins/my-plugin`);
|
|
13
|
+
const [s, i] = o;
|
|
14
|
+
if (!c(s))
|
|
15
|
+
throw new Error(`Host path does not exist: ${s}`);
|
|
16
|
+
t.push({ hostPath: s, vfsPath: i });
|
|
17
|
+
}
|
|
18
|
+
return t;
|
|
19
|
+
}
|
|
20
|
+
function x(e) {
|
|
21
|
+
if (e.length % 2 !== 0)
|
|
22
|
+
throw new Error("Invalid mount format. Expected: /host/path /vfs/path");
|
|
23
|
+
const t = [];
|
|
24
|
+
for (let n = 0; n < e.length; n += 2) {
|
|
25
|
+
const o = e[n], s = e[n + 1];
|
|
26
|
+
if (!c(o))
|
|
27
|
+
throw new Error(`Host path does not exist: ${o}`);
|
|
28
|
+
t.push({
|
|
29
|
+
hostPath: m.resolve(process.cwd(), o),
|
|
30
|
+
vfsPath: s
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return t;
|
|
34
|
+
}
|
|
35
|
+
async function N(e, t) {
|
|
36
|
+
for (const n of t)
|
|
37
|
+
await e.mount(
|
|
38
|
+
n.vfsPath,
|
|
39
|
+
l(n.hostPath)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
const u = {
|
|
43
|
+
step: "runPHP",
|
|
44
|
+
code: {
|
|
45
|
+
filename: "activate-theme.php",
|
|
46
|
+
content: `<?php
|
|
47
|
+
require_once getenv('DOCROOT') . '/wp-load.php';
|
|
48
|
+
$theme = wp_get_theme();
|
|
49
|
+
if (!$theme->exists()) {
|
|
50
|
+
$themes = wp_get_themes();
|
|
51
|
+
if (count($themes) > 0) {
|
|
52
|
+
$themeName = array_keys($themes)[0];
|
|
53
|
+
switch_theme($themeName);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
function E(e) {
|
|
60
|
+
const t = process.cwd(), n = [...e.mount || []], o = [...e["mount-before-install"] || []], s = {
|
|
61
|
+
...e,
|
|
62
|
+
mount: n,
|
|
63
|
+
"mount-before-install": o,
|
|
64
|
+
"additional-blueprint-steps": [
|
|
65
|
+
...e["additional-blueprint-steps"] || []
|
|
66
|
+
]
|
|
67
|
+
};
|
|
68
|
+
if (g(t)) {
|
|
69
|
+
const i = p(t);
|
|
70
|
+
n.push({
|
|
71
|
+
hostPath: t,
|
|
72
|
+
vfsPath: `/wordpress/wp-content/plugins/${i}`
|
|
73
|
+
}), s["additional-blueprint-steps"].push({
|
|
74
|
+
step: "activatePlugin",
|
|
75
|
+
pluginPath: `/wordpress/wp-content/plugins/${p(t)}`
|
|
76
|
+
});
|
|
77
|
+
} else if (w(t)) {
|
|
78
|
+
const i = p(t);
|
|
79
|
+
n.push({
|
|
80
|
+
hostPath: t,
|
|
81
|
+
vfsPath: `/wordpress/wp-content/themes/${i}`
|
|
82
|
+
}), s["additional-blueprint-steps"].push({
|
|
83
|
+
step: "activateTheme",
|
|
84
|
+
themeDirectoryName: i
|
|
85
|
+
});
|
|
86
|
+
} else if (f(t)) {
|
|
87
|
+
const i = r.readdirSync(t);
|
|
88
|
+
for (const a of i)
|
|
89
|
+
a !== "index.php" && n.push({
|
|
90
|
+
hostPath: `${t}/${a}`,
|
|
91
|
+
vfsPath: `/wordpress/wp-content/${a}`
|
|
92
|
+
});
|
|
93
|
+
s["additional-blueprint-steps"].push(u);
|
|
94
|
+
} else d(t) ? (o.push({ hostPath: t, vfsPath: "/wordpress" }), s["additional-blueprint-steps"].push(u)) : n.push({ hostPath: t, vfsPath: "/wordpress" });
|
|
95
|
+
return s;
|
|
96
|
+
}
|
|
97
|
+
function d(e) {
|
|
98
|
+
const t = r.readdirSync(e);
|
|
99
|
+
return t.includes("wp-admin") && t.includes("wp-includes") && t.includes("wp-content");
|
|
100
|
+
}
|
|
101
|
+
function f(e) {
|
|
102
|
+
const t = r.readdirSync(e);
|
|
103
|
+
return t.includes("themes") || t.includes("plugins") || t.includes("mu-plugins") || t.includes("uploads");
|
|
104
|
+
}
|
|
105
|
+
function w(e) {
|
|
106
|
+
if (!r.readdirSync(e).includes("style.css"))
|
|
107
|
+
return !1;
|
|
108
|
+
const n = r.readFileSync(h(e, "style.css"), "utf8");
|
|
109
|
+
return !!/^(?:[ \t]*<\?php)?[ \t/*#@]*Theme Name:(.*)$/im.exec(n);
|
|
110
|
+
}
|
|
111
|
+
function g(e) {
|
|
112
|
+
const t = r.readdirSync(e), n = /^(?:[ \t]*<\?php)?[ \t/*#@]*Plugin Name:(.*)$/im;
|
|
113
|
+
return !!t.filter((s) => s.endsWith(".php")).find((s) => {
|
|
114
|
+
const i = r.readFileSync(h(e, s), "utf8");
|
|
115
|
+
return !!n.exec(i);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
x as a,
|
|
120
|
+
E as e,
|
|
121
|
+
N as m,
|
|
122
|
+
v as p
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=mounts-B-Qdcyyt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mounts-B-Qdcyyt.js","sources":["../../../../packages/playground/cli/src/mounts.ts"],"sourcesContent":["import { createNodeFsMountHandler } from '@php-wasm/node';\nimport type { PHP } from '@php-wasm/universal';\nimport fs, { existsSync } from 'fs';\nimport path, { basename, join } from 'path';\nimport type { RunCLIArgs } from './run-cli';\n\nexport interface Mount {\n\thostPath: string;\n\tvfsPath: string;\n}\n\n/**\n * Parse an array of mount argument strings where the host path and VFS path\n * are separated by a colon.\n *\n * Example:\n * parseMountWithDelimiterArguments( [ '/host/path:/vfs/path', '/host/path:/vfs/path' ] )\n * // returns:\n * [\n * { hostPath: '/host/path', vfsPath: '/vfs/path' },\n * { hostPath: '/host/path', vfsPath: '/vfs/path' }\n * ]\n *\n * @param mounts - An array of mount argument strings separated by a colon.\n * @returns An array of Mount objects.\n */\nexport function parseMountWithDelimiterArguments(mounts: string[]): Mount[] {\n\tconst parsedMounts = [];\n\tfor (const mount of mounts) {\n\t\tconst mountParts = mount.split(':');\n\t\tif (mountParts.length !== 2) {\n\t\t\tthrow new Error(`Invalid mount format: ${mount}.\n\t\t\t\tExpected format: /host/path:/vfs/path.\n\t\t\t\tIf your path contains a colon, e.g. C:\\\\myplugin, use the --mount-dir option instead.\n\t\t\t\tExample: --mount-dir C:\\\\my-plugin /wordpress/wp-content/plugins/my-plugin`);\n\t\t}\n\t\tconst [hostPath, vfsPath] = mountParts;\n\t\tif (!existsSync(hostPath)) {\n\t\t\tthrow new Error(`Host path does not exist: ${hostPath}`);\n\t\t}\n\t\tparsedMounts.push({ hostPath, vfsPath });\n\t}\n\treturn parsedMounts;\n}\n\n/**\n * Parse an array of mount argument strings where each odd array element is a host path\n * and each even element is the VFS path.\n * e.g. [ '/host/path', '/vfs/path', '/host/path2', '/vfs/path2' ]\n *\n * The result will be an array of Mount objects for each host path the\n * following element is it's VFS path.\n * e.g. [\n * { hostPath: '/host/path', vfsPath: '/vfs/path' },\n * { hostPath: '/host/path2', vfsPath: '/vfs/path2' }\n * ]\n *\n * @param mounts - An array of paths\n * @returns An array of Mount objects.\n */\nexport function parseMountDirArguments(mounts: string[]): Mount[] {\n\tif (mounts.length % 2 !== 0) {\n\t\tthrow new Error('Invalid mount format. Expected: /host/path /vfs/path');\n\t}\n\n\tconst parsedMounts = [];\n\tfor (let i = 0; i < mounts.length; i += 2) {\n\t\tconst source = mounts[i];\n\t\tconst vfsPath = mounts[i + 1];\n\t\tif (!existsSync(source)) {\n\t\t\tthrow new Error(`Host path does not exist: ${source}`);\n\t\t}\n\t\tparsedMounts.push({\n\t\t\thostPath: path.resolve(process.cwd(), source),\n\t\t\tvfsPath,\n\t\t});\n\t}\n\treturn parsedMounts;\n}\n\nexport async function mountResources(php: PHP, mounts: Mount[]) {\n\tfor (const mount of mounts) {\n\t\tawait php.mount(\n\t\t\tmount.vfsPath,\n\t\t\tcreateNodeFsMountHandler(mount.hostPath)\n\t\t);\n\t}\n}\n\nconst ACTIVATE_FIRST_THEME_STEP = {\n\tstep: 'runPHP',\n\tcode: {\n\t\tfilename: 'activate-theme.php',\n\t\tcontent: `<?php\n\t\t\trequire_once getenv('DOCROOT') . '/wp-load.php';\n\t\t\t$theme = wp_get_theme();\n\t\t\tif (!$theme->exists()) {\n\t\t\t\t$themes = wp_get_themes();\n\t\t\t\tif (count($themes) > 0) {\n\t\t\t\t\t$themeName = array_keys($themes)[0];\n\t\t\t\t\tswitch_theme($themeName);\n\t\t\t\t}\n\t\t\t}\n\t\t`,\n\t},\n};\n\n/**\n * Auto-mounts resolution logic:\n */\nexport function expandAutoMounts(args: RunCLIArgs): RunCLIArgs {\n\tconst path = process.cwd();\n\n\tconst mount = [...(args.mount || [])];\n\tconst mountBeforeInstall = [...(args['mount-before-install'] || [])];\n\n\tconst newArgs = {\n\t\t...args,\n\t\tmount,\n\t\t'mount-before-install': mountBeforeInstall,\n\t\t'additional-blueprint-steps': [\n\t\t\t...((args as any)['additional-blueprint-steps'] || []),\n\t\t],\n\t};\n\n\tif (isPluginFilename(path)) {\n\t\tconst pluginName = basename(path);\n\t\tmount.push({\n\t\t\thostPath: path,\n\t\t\tvfsPath: `/wordpress/wp-content/plugins/${pluginName}`,\n\t\t});\n\t\tnewArgs['additional-blueprint-steps'].push({\n\t\t\tstep: 'activatePlugin',\n\t\t\tpluginPath: `/wordpress/wp-content/plugins/${basename(path)}`,\n\t\t});\n\t} else if (isThemeDirectory(path)) {\n\t\tconst themeName = basename(path);\n\t\tmount.push({\n\t\t\thostPath: path,\n\t\t\tvfsPath: `/wordpress/wp-content/themes/${themeName}`,\n\t\t});\n\t\tnewArgs['additional-blueprint-steps'].push({\n\t\t\tstep: 'activateTheme',\n\t\t\tthemeDirectoryName: themeName,\n\t\t});\n\t} else if (containsWpContentDirectories(path)) {\n\t\t/**\n\t\t * Mount each wp-content file and directory individually.\n\t\t */\n\t\tconst files = fs.readdirSync(path);\n\t\tfor (const file of files) {\n\t\t\t/**\n\t\t\t * WordPress already ships with the wp-content/index.php file\n\t\t\t * and Playground does not support overriding existing VFS files\n\t\t\t * with mounts.\n\t\t\t */\n\t\t\tif (file === 'index.php') {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tmount.push({\n\t\t\t\thostPath: `${path}/${file}`,\n\t\t\t\tvfsPath: `/wordpress/wp-content/${file}`,\n\t\t\t});\n\t\t}\n\t\tnewArgs['additional-blueprint-steps'].push(ACTIVATE_FIRST_THEME_STEP);\n\t} else if (containsFullWordPressInstallation(path)) {\n\t\tmountBeforeInstall.push({ hostPath: path, vfsPath: '/wordpress' });\n\t\t// @TODO: Uncomment when merging Blueprints v2 support\n\t\t// newArgs.mode = 'apply-to-existing-site';\n\t\tnewArgs['additional-blueprint-steps'].push(ACTIVATE_FIRST_THEME_STEP);\n\t} else {\n\t\t/**\n\t\t * By default, mount the current working directory as the Playground root.\n\t\t * This allows users to run and PHP or HTML files using the Playground CLI.\n\t\t */\n\t\tmount.push({ hostPath: path, vfsPath: '/wordpress' });\n\t\t// @TODO: Uncomment when merging Blueprints v2 support\n\t\t// newArgs.mode = 'mount-only';\n\t}\n\n\treturn newArgs as RunCLIArgs;\n}\n\nexport function containsFullWordPressInstallation(path: string): boolean {\n\tconst files = fs.readdirSync(path);\n\treturn (\n\t\tfiles.includes('wp-admin') &&\n\t\tfiles.includes('wp-includes') &&\n\t\tfiles.includes('wp-content')\n\t);\n}\n\nexport function containsWpContentDirectories(path: string): boolean {\n\tconst files = fs.readdirSync(path);\n\treturn (\n\t\tfiles.includes('themes') ||\n\t\tfiles.includes('plugins') ||\n\t\tfiles.includes('mu-plugins') ||\n\t\tfiles.includes('uploads')\n\t);\n}\n\nexport function isThemeDirectory(path: string): boolean {\n\tconst files = fs.readdirSync(path);\n\tif (!files.includes('style.css')) {\n\t\treturn false;\n\t}\n\tconst styleCssContent = fs.readFileSync(join(path, 'style.css'), 'utf8');\n\tconst themeNameRegex = /^(?:[ \\t]*<\\?php)?[ \\t/*#@]*Theme Name:(.*)$/im;\n\treturn !!themeNameRegex.exec(styleCssContent);\n}\n\nexport function isPluginFilename(path: string): boolean {\n\tconst files = fs.readdirSync(path);\n\tconst pluginNameRegex = /^(?:[ \\t]*<\\?php)?[ \\t/*#@]*Plugin Name:(.*)$/im;\n\tconst pluginNameMatch = files\n\t\t.filter((file) => file.endsWith('.php'))\n\t\t.find((file) => {\n\t\t\tconst fileContent = fs.readFileSync(join(path, file), 'utf8');\n\t\t\treturn !!pluginNameRegex.exec(fileContent);\n\t\t});\n\treturn !!pluginNameMatch;\n}\n"],"names":["parseMountWithDelimiterArguments","mounts","parsedMounts","mount","mountParts","hostPath","vfsPath","existsSync","parseMountDirArguments","i","source","path","mountResources","php","createNodeFsMountHandler","ACTIVATE_FIRST_THEME_STEP","expandAutoMounts","args","mountBeforeInstall","newArgs","isPluginFilename","pluginName","basename","isThemeDirectory","themeName","containsWpContentDirectories","files","fs","file","containsFullWordPressInstallation","styleCssContent","join","pluginNameRegex","fileContent"],"mappings":";;;AA0BO,SAASA,EAAiCC,GAA2B;AAC3E,QAAMC,IAAe,CAAC;AACtB,aAAWC,KAASF,GAAQ;AACrB,UAAAG,IAAaD,EAAM,MAAM,GAAG;AAC9B,QAAAC,EAAW,WAAW;AACnB,YAAA,IAAI,MAAM,yBAAyBD,CAAK;AAAA;AAAA;AAAA,+EAG8B;AAEvE,UAAA,CAACE,GAAUC,CAAO,IAAIF;AACxB,QAAA,CAACG,EAAWF,CAAQ;AACvB,YAAM,IAAI,MAAM,6BAA6BA,CAAQ,EAAE;AAExD,IAAAH,EAAa,KAAK,EAAE,UAAAG,GAAU,SAAAC,EAAA,CAAS;AAAA,EAAA;AAEjC,SAAAJ;AACR;AAiBO,SAASM,EAAuBP,GAA2B;AAC7D,MAAAA,EAAO,SAAS,MAAM;AACnB,UAAA,IAAI,MAAM,sDAAsD;AAGvE,QAAMC,IAAe,CAAC;AACtB,WAASO,IAAI,GAAGA,IAAIR,EAAO,QAAQQ,KAAK,GAAG;AACpC,UAAAC,IAAST,EAAOQ,C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AW,GAAG,MAAM;AAEvE,SAAO,CAAC,CADe,iDACC,KAAKmB,CAAe;AAC7C;AAEO,SAASV,EAAiBT,GAAuB;AACjD,QAAAe,IAAQC,EAAG,YAAYhB,CAAI,GAC3BqB,IAAkB;AAOxB,SAAO,CAAC,CANgBN,EACtB,OAAO,CAACE,MAASA,EAAK,SAAS,MAAM,CAAC,EACtC,KAAK,CAACA,MAAS;AACf,UAAMK,IAAcN,EAAG,aAAaI,EAAKpB,GAAMiB,CAAI,GAAG,MAAM;AAC5D,WAAO,CAAC,CAACI,EAAgB,KAAKC,CAAW;AAAA,EAAA,CACzC;AAEH;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";const p=require("@php-wasm/node"),r=require("fs"),a=require("path");function h(t){const e=[];for(const n of t){const o=n.split(":");if(o.length!==2)throw new Error(`Invalid mount format: ${n}.
|
|
2
|
+
Expected format: /host/path:/vfs/path.
|
|
3
|
+
If your path contains a colon, e.g. C:\\myplugin, use the --mount-dir option instead.
|
|
4
|
+
Example: --mount-dir C:\\my-plugin /wordpress/wp-content/plugins/my-plugin`);const[s,i]=o;if(!r.existsSync(s))throw new Error(`Host path does not exist: ${s}`);e.push({hostPath:s,vfsPath:i})}return e}function l(t){if(t.length%2!==0)throw new Error("Invalid mount format. Expected: /host/path /vfs/path");const e=[];for(let n=0;n<t.length;n+=2){const o=t[n],s=t[n+1];if(!r.existsSync(o))throw new Error(`Host path does not exist: ${o}`);e.push({hostPath:a.resolve(process.cwd(),o),vfsPath:s})}return e}async function d(t,e){for(const n of e)await t.mount(n.vfsPath,p.createNodeFsMountHandler(n.hostPath))}const c={step:"runPHP",code:{filename:"activate-theme.php",content:`<?php
|
|
5
|
+
require_once getenv('DOCROOT') . '/wp-load.php';
|
|
6
|
+
$theme = wp_get_theme();
|
|
7
|
+
if (!$theme->exists()) {
|
|
8
|
+
$themes = wp_get_themes();
|
|
9
|
+
if (count($themes) > 0) {
|
|
10
|
+
$themeName = array_keys($themes)[0];
|
|
11
|
+
switch_theme($themeName);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`}};function m(t){const e=process.cwd(),n=[...t.mount||[]],o=[...t["mount-before-install"]||[]],s={...t,mount:n,"mount-before-install":o,"additional-blueprint-steps":[...t["additional-blueprint-steps"]||[]]};if(P(e)){const i=a.basename(e);n.push({hostPath:e,vfsPath:`/wordpress/wp-content/plugins/${i}`}),s["additional-blueprint-steps"].push({step:"activatePlugin",pluginPath:`/wordpress/wp-content/plugins/${a.basename(e)}`})}else if(g(e)){const i=a.basename(e);n.push({hostPath:e,vfsPath:`/wordpress/wp-content/themes/${i}`}),s["additional-blueprint-steps"].push({step:"activateTheme",themeDirectoryName:i})}else if(w(e)){const i=r.readdirSync(e);for(const u of i)u!=="index.php"&&n.push({hostPath:`${e}/${u}`,vfsPath:`/wordpress/wp-content/${u}`});s["additional-blueprint-steps"].push(c)}else f(e)?(o.push({hostPath:e,vfsPath:"/wordpress"}),s["additional-blueprint-steps"].push(c)):n.push({hostPath:e,vfsPath:"/wordpress"});return s}function f(t){const e=r.readdirSync(t);return e.includes("wp-admin")&&e.includes("wp-includes")&&e.includes("wp-content")}function w(t){const e=r.readdirSync(t);return e.includes("themes")||e.includes("plugins")||e.includes("mu-plugins")||e.includes("uploads")}function g(t){if(!r.readdirSync(t).includes("style.css"))return!1;const n=r.readFileSync(a.join(t,"style.css"),"utf8");return!!/^(?:[ \t]*<\?php)?[ \t/*#@]*Theme Name:(.*)$/im.exec(n)}function P(t){const e=r.readdirSync(t),n=/^(?:[ \t]*<\?php)?[ \t/*#@]*Plugin Name:(.*)$/im;return!!e.filter(s=>s.endsWith(".php")).find(s=>{const i=r.readFileSync(a.join(t,s),"utf8");return!!n.exec(i)})}exports.expandAutoMounts=m;exports.mountResources=d;exports.parseMountDirArguments=l;exports.parseMountWithDelimiterArguments=h;
|
|
15
|
+
//# sourceMappingURL=mounts-D7bhhGq3.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mounts-D7bhhGq3.cjs","sources":["../../../../packages/playground/cli/src/mounts.ts"],"sourcesContent":["import { createNodeFsMountHandler } from '@php-wasm/node';\nimport type { PHP } from '@php-wasm/universal';\nimport fs, { existsSync } from 'fs';\nimport path, { basename, join } from 'path';\nimport type { RunCLIArgs } from './run-cli';\n\nexport interface Mount {\n\thostPath: string;\n\tvfsPath: string;\n}\n\n/**\n * Parse an array of mount argument strings where the host path and VFS path\n * are separated by a colon.\n *\n * Example:\n * parseMountWithDelimiterArguments( [ '/host/path:/vfs/path', '/host/path:/vfs/path' ] )\n * // returns:\n * [\n * { hostPath: '/host/path', vfsPath: '/vfs/path' },\n * { hostPath: '/host/path', vfsPath: '/vfs/path' }\n * ]\n *\n * @param mounts - An array of mount argument strings separated by a colon.\n * @returns An array of Mount objects.\n */\nexport function parseMountWithDelimiterArguments(mounts: string[]): Mount[] {\n\tconst parsedMounts = [];\n\tfor (const mount of mounts) {\n\t\tconst mountParts = mount.split(':');\n\t\tif (mountParts.length !== 2) {\n\t\t\tthrow new Error(`Invalid mount format: ${mount}.\n\t\t\t\tExpected format: /host/path:/vfs/path.\n\t\t\t\tIf your path contains a colon, e.g. C:\\\\myplugin, use the --mount-dir option instead.\n\t\t\t\tExample: --mount-dir C:\\\\my-plugin /wordpress/wp-content/plugins/my-plugin`);\n\t\t}\n\t\tconst [hostPath, vfsPath] = mountParts;\n\t\tif (!existsSync(hostPath)) {\n\t\t\tthrow new Error(`Host path does not exist: ${hostPath}`);\n\t\t}\n\t\tparsedMounts.push({ hostPath, vfsPath });\n\t}\n\treturn parsedMounts;\n}\n\n/**\n * Parse an array of mount argument strings where each odd array element is a host path\n * and each even element is the VFS path.\n * e.g. [ '/host/path', '/vfs/path', '/host/path2', '/vfs/path2' ]\n *\n * The result will be an array of Mount objects for each host path the\n * following element is it's VFS path.\n * e.g. [\n * { hostPath: '/host/path', vfsPath: '/vfs/path' },\n * { hostPath: '/host/path2', vfsPath: '/vfs/path2' }\n * ]\n *\n * @param mounts - An array of paths\n * @returns An array of Mount objects.\n */\nexport function parseMountDirArguments(mounts: string[]): Mount[] {\n\tif (mounts.length % 2 !== 0) {\n\t\tthrow new Error('Invalid mount format. Expected: /host/path /vfs/path');\n\t}\n\n\tconst parsedMounts = [];\n\tfor (let i = 0; i < mounts.length; i += 2) {\n\t\tconst source = mounts[i];\n\t\tconst vfsPath = mounts[i + 1];\n\t\tif (!existsSync(source)) {\n\t\t\tthrow new Error(`Host path does not exist: ${source}`);\n\t\t}\n\t\tparsedMounts.push({\n\t\t\thostPath: path.resolve(process.cwd(), source),\n\t\t\tvfsPath,\n\t\t});\n\t}\n\treturn parsedMounts;\n}\n\nexport async function mountResources(php: PHP, mounts: Mount[]) {\n\tfor (const mount of mounts) {\n\t\tawait php.mount(\n\t\t\tmount.vfsPath,\n\t\t\tcreateNodeFsMountHandler(mount.hostPath)\n\t\t);\n\t}\n}\n\nconst ACTIVATE_FIRST_THEME_STEP = {\n\tstep: 'runPHP',\n\tcode: {\n\t\tfilename: 'activate-theme.php',\n\t\tcontent: `<?php\n\t\t\trequire_once getenv('DOCROOT') . '/wp-load.php';\n\t\t\t$theme = wp_get_theme();\n\t\t\tif (!$theme->exists()) {\n\t\t\t\t$themes = wp_get_themes();\n\t\t\t\tif (count($themes) > 0) {\n\t\t\t\t\t$themeName = array_keys($themes)[0];\n\t\t\t\t\tswitch_theme($themeName);\n\t\t\t\t}\n\t\t\t}\n\t\t`,\n\t},\n};\n\n/**\n * Auto-mounts resolution logic:\n */\nexport function expandAutoMounts(args: RunCLIArgs): RunCLIArgs {\n\tconst path = process.cwd();\n\n\tconst mount = [...(args.mount || [])];\n\tconst mountBeforeInstall = [...(args['mount-before-install'] || [])];\n\n\tconst newArgs = {\n\t\t...args,\n\t\tmount,\n\t\t'mount-before-install': mountBeforeInstall,\n\t\t'additional-blueprint-steps': [\n\t\t\t...((args as any)['additional-blueprint-steps'] || []),\n\t\t],\n\t};\n\n\tif (isPluginFilename(path)) {\n\t\tconst pluginName = basename(path);\n\t\tmount.push({\n\t\t\thostPath: path,\n\t\t\tvfsPath: `/wordpress/wp-content/plugins/${pluginName}`,\n\t\t});\n\t\tnewArgs['additional-blueprint-steps'].push({\n\t\t\tstep: 'activatePlugin',\n\t\t\tpluginPath: `/wordpress/wp-content/plugins/${basename(path)}`,\n\t\t});\n\t} else if (isThemeDirectory(path)) {\n\t\tconst themeName = basename(path);\n\t\tmount.push({\n\t\t\thostPath: path,\n\t\t\tvfsPath: `/wordpress/wp-content/themes/${themeName}`,\n\t\t});\n\t\tnewArgs['additional-blueprint-steps'].push({\n\t\t\tstep: 'activateTheme',\n\t\t\tthemeDirectoryName: themeName,\n\t\t});\n\t} else if (containsWpContentDirectories(path)) {\n\t\t/**\n\t\t * Mount each wp-content file and directory individually.\n\t\t */\n\t\tconst files = fs.readdirSync(path);\n\t\tfor (const file of files) {\n\t\t\t/**\n\t\t\t * WordPress already ships with the wp-content/index.php file\n\t\t\t * and Playground does not support overriding existing VFS files\n\t\t\t * with mounts.\n\t\t\t */\n\t\t\tif (file === 'index.php') {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tmount.push({\n\t\t\t\thostPath: `${path}/${file}`,\n\t\t\t\tvfsPath: `/wordpress/wp-content/${file}`,\n\t\t\t});\n\t\t}\n\t\tnewArgs['additional-blueprint-steps'].push(ACTIVATE_FIRST_THEME_STEP);\n\t} else if (containsFullWordPressInstallation(path)) {\n\t\tmountBeforeInstall.push({ hostPath: path, vfsPath: '/wordpress' });\n\t\t// @TODO: Uncomment when merging Blueprints v2 support\n\t\t// newArgs.mode = 'apply-to-existing-site';\n\t\tnewArgs['additional-blueprint-steps'].push(ACTIVATE_FIRST_THEME_STEP);\n\t} else {\n\t\t/**\n\t\t * By default, mount the current working directory as the Playground root.\n\t\t * This allows users to run and PHP or HTML files using the Playground CLI.\n\t\t */\n\t\tmount.push({ hostPath: path, vfsPath: '/wordpress' });\n\t\t// @TODO: Uncomment when merging Blueprints v2 support\n\t\t// newArgs.mode = 'mount-only';\n\t}\n\n\treturn newArgs as RunCLIArgs;\n}\n\nexport function containsFullWordPressInstallation(path: string): boolean {\n\tconst files = fs.readdirSync(path);\n\treturn (\n\t\tfiles.includes('wp-admin') &&\n\t\tfiles.includes('wp-includes') &&\n\t\tfiles.includes('wp-content')\n\t);\n}\n\nexport function containsWpContentDirectories(path: string): boolean {\n\tconst files = fs.readdirSync(path);\n\treturn (\n\t\tfiles.includes('themes') ||\n\t\tfiles.includes('plugins') ||\n\t\tfiles.includes('mu-plugins') ||\n\t\tfiles.includes('uploads')\n\t);\n}\n\nexport function isThemeDirectory(path: string): boolean {\n\tconst files = fs.readdirSync(path);\n\tif (!files.includes('style.css')) {\n\t\treturn false;\n\t}\n\tconst styleCssContent = fs.readFileSync(join(path, 'style.css'), 'utf8');\n\tconst themeNameRegex = /^(?:[ \\t]*<\\?php)?[ \\t/*#@]*Theme Name:(.*)$/im;\n\treturn !!themeNameRegex.exec(styleCssContent);\n}\n\nexport function isPluginFilename(path: string): boolean {\n\tconst files = fs.readdirSync(path);\n\tconst pluginNameRegex = /^(?:[ \\t]*<\\?php)?[ \\t/*#@]*Plugin Name:(.*)$/im;\n\tconst pluginNameMatch = files\n\t\t.filter((file) => file.endsWith('.php'))\n\t\t.find((file) => {\n\t\t\tconst fileContent = fs.readFileSync(join(path, file), 'utf8');\n\t\t\treturn !!pluginNameRegex.exec(fileContent);\n\t\t});\n\treturn !!pluginNameMatch;\n}\n"],"names":["parseMountWithDelimiterArguments","mounts","parsedMounts","mount","mountParts","hostPath","vfsPath","existsSync","parseMountDirArguments","i","source","path","mountResources","php","createNodeFsMountHandler","ACTIVATE_FIRST_THEME_STEP","expandAutoMounts","args","mountBeforeInstall","newArgs","isPluginFilename","pluginName","basename","isThemeDirectory","themeName","containsWpContentDirectories","files","fs","file","containsFullWordPressInstallation","styleCssContent","join","pluginNameRegex","fileContent"],"mappings":"iFA0BO,SAASA,EAAiCC,EAA2B,CAC3E,M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M,SAAS,YAAY,CAE7B,CAEO,SAASD,EAA6Bd,EAAuB,CAC7D,MAAAe,EAAQC,EAAG,YAAYhB,CAAI,EACjC,OACCe,EAAM,SAAS,QAAQ,GACvBA,EAAM,SAAS,SAAS,GACxBA,EAAM,SAAS,YAAY,GAC3BA,EAAM,SAAS,SAAS,CAE1B,CAEO,SAASH,EAAiBZ,EAAuB,CAEvD,GAAI,CADUgB,EAAG,YAAYhB,CAAI,EACtB,SAAS,WAAW,EACvB,MAAA,GAER,MAAMmB,EAAkBH,EAAG,aAAaI,OAAKpB,EAAM,WAAW,EAAG,MAAM,EAEvE,MAAO,CAAC,CADe,iDACC,KAAKmB,CAAe,CAC7C,CAEO,SAASV,EAAiBT,EAAuB,CACjD,MAAAe,EAAQC,EAAG,YAAYhB,CAAI,EAC3BqB,EAAkB,kDAOxB,MAAO,CAAC,CANgBN,EACtB,OAAQE,GAASA,EAAK,SAAS,MAAM,CAAC,EACtC,KAAMA,GAAS,CACf,MAAMK,EAAcN,EAAG,aAAaI,OAAKpB,EAAMiB,CAAI,EAAG,MAAM,EAC5D,MAAO,CAAC,CAACI,EAAgB,KAAKC,CAAW,CAAA,CACzC,CAEH"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PHP } from '@php-wasm/universal';
|
|
2
|
+
import type { RunCLIArgs } from './run-cli';
|
|
2
3
|
export interface Mount {
|
|
3
4
|
hostPath: string;
|
|
4
5
|
vfsPath: string;
|
|
@@ -35,4 +36,12 @@ export declare function parseMountWithDelimiterArguments(mounts: string[]): Moun
|
|
|
35
36
|
* @returns An array of Mount objects.
|
|
36
37
|
*/
|
|
37
38
|
export declare function parseMountDirArguments(mounts: string[]): Mount[];
|
|
38
|
-
export declare function mountResources(php: PHP, mounts: Mount[]): void
|
|
39
|
+
export declare function mountResources(php: PHP, mounts: Mount[]): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Auto-mounts resolution logic:
|
|
42
|
+
*/
|
|
43
|
+
export declare function expandAutoMounts(args: RunCLIArgs): RunCLIArgs;
|
|
44
|
+
export declare function containsFullWordPressInstallation(path: string): boolean;
|
|
45
|
+
export declare function containsWpContentDirectories(path: string): boolean;
|
|
46
|
+
export declare function isThemeDirectory(path: string): boolean;
|
|
47
|
+
export declare function isPluginFilename(path: string): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-playground/cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "WordPress Playground CLI",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,13 +32,12 @@
|
|
|
32
32
|
"module": "./index.js",
|
|
33
33
|
"types": "index.d.ts",
|
|
34
34
|
"bin": "wp-playground.js",
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "a6624a5390d899d164f887dc915a0ba1dbc31c83",
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@zip.js/zip.js": "2.7.57",
|
|
38
38
|
"ajv": "8.12.0",
|
|
39
39
|
"async-lock": "1.4.1",
|
|
40
40
|
"clean-git-ref": "2.0.1",
|
|
41
|
-
"comlink": "^4.4.2",
|
|
42
41
|
"crc-32": "1.2.2",
|
|
43
42
|
"diff3": "0.0.4",
|
|
44
43
|
"express": "4.21.2",
|
|
@@ -56,15 +55,15 @@
|
|
|
56
55
|
"wasm-feature-detect": "1.8.0",
|
|
57
56
|
"ws": "8.18.1",
|
|
58
57
|
"yargs": "17.7.2",
|
|
59
|
-
"@
|
|
60
|
-
"@php-wasm/
|
|
61
|
-
"@php-wasm/
|
|
62
|
-
"@php-wasm/
|
|
63
|
-
"@
|
|
64
|
-
"@wp-playground/
|
|
65
|
-
"@wp-playground/common": "1.2.
|
|
66
|
-
"@wp-playground/wordpress": "1.2.
|
|
67
|
-
"@php-wasm/util": "1.2.
|
|
58
|
+
"@php-wasm/progress": "1.2.3",
|
|
59
|
+
"@php-wasm/universal": "1.2.3",
|
|
60
|
+
"@php-wasm/node": "1.2.3",
|
|
61
|
+
"@php-wasm/logger": "1.2.3",
|
|
62
|
+
"@wp-playground/storage": "1.2.3",
|
|
63
|
+
"@wp-playground/blueprints": "1.2.3",
|
|
64
|
+
"@wp-playground/common": "1.2.3",
|
|
65
|
+
"@wp-playground/wordpress": "1.2.3",
|
|
66
|
+
"@php-wasm/util": "1.2.3"
|
|
68
67
|
},
|
|
69
68
|
"overrides": {
|
|
70
69
|
"rollup": "^4.34.6",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";var ie=Object.create;var _=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var le=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var ue=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of ae(r))!ce.call(e,o)&&o!==t&&_(e,o,{get:()=>r[o],enumerable:!(i=se(r,o))||i.enumerable});return e};var de=(e,r,t)=>(t=e!=null?ie(le(e)):{},ue(r||!e||!e.__esModule?_(t,"default",{value:e,enumerable:!0}):t,e));const a=require("@php-wasm/logger"),N=require("@php-wasm/progress"),v=require("@php-wasm/universal"),$=require("@wp-playground/blueprints"),L=require("@wp-playground/common"),g=require("fs"),b=require("path"),X=require("worker_threads"),pe=require("@wp-playground/wordpress"),E=require("./mounts-D7bhhGq3.cjs"),R=require("fs-extra"),J=require("os"),fe=require("express"),we=require("@php-wasm/node"),he=require("wasm-feature-detect"),me=require("yargs"),M=require("@wp-playground/storage");var H=typeof document<"u"?document.currentScript:null;const z=b.join(J.homedir(),".wordpress-playground");async function ye(e){return await Y("https://github.com/WordPress/sqlite-database-integration/archive/refs/heads/develop.zip","sqlite.zip",e)}async function Y(e,r,t){const i=b.join(z,r);return R.existsSync(i)||(R.ensureDirSync(z),await ge(e,i,t)),Q(i)}async function ge(e,r,t){const o=(await t.monitorFetch(fetch(e))).body.getReader(),n=`${r}.partial`,l=R.createWriteStream(n);for(;;){const{done:u,value:d}=await o.read();if(d&&l.write(d),u)break}l.close(),l.closed||await new Promise((u,d)=>{l.on("finish",()=>{R.renameSync(n,r),u(null)}),l.on("error",A=>{R.removeSync(n),d(A)})})}function Q(e,r){return new File([R.readFileSync(e)],b.basename(e))}async function be(e){const r=fe(),t=await new Promise((n,l)=>{const u=r.listen(e.port,()=>{const d=u.address();d===null||typeof d=="string"?l(new Error("Server address is not available")):n(u)})});r.use("/",async(n,l)=>{const u=await e.handleRequest({url:n.url,headers:ke(n),method:n.method,body:await Pe(n)});l.statusCode=u.httpStatusCode;for(const d in u.headers)l.setHeader(d,u.headers[d]);l.end(u.bytes)});const o=t.address().port;return await e.onBind(t,o)}const Pe=async e=>await new Promise(r=>{const t=[];e.on("data",i=>{t.push(i)}),e.on("end",()=>{r(new Uint8Array(Buffer.concat(t)))})}),ke=e=>{const r={};if(e.rawHeaders&&e.rawHeaders.length)for(let t=0;t<e.rawHeaders.length;t+=2)r[e.rawHeaders[t].toLowerCase()]=e.rawHeaders[t+1];return r},ve=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/worker-thread-CYvRK9UX.js").href:new URL("worker-thread-CYvRK9UX.js",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href);class Re{constructor(r){this.workerLoads=[],this.addWorker(r)}addWorker(r){this.workerLoads.push({worker:r,activeRequests:new Set})}async handleRequest(r){let t=this.workerLoads[0];for(let o=1;o<this.workerLoads.length;o++){const n=this.workerLoads[o];n.activeRequests.size<t.activeRequests.size&&(t=n)}const i=t.worker.request(r);return t.activeRequests.add(i),i.url=r.url,i.finally(()=>{t.activeRequests.delete(i)})}}function We(e){return/^latest$|^trunk$|^nightly$|^(?:(\d+)\.(\d+)(?:\.(\d+))?)((?:-beta(?:\d+)?)|(?:-RC(?:\d+)?))?$/.test(e)}class K extends Error{constructor(r,t){super(r,{...t,cause:{isReportableInCLI:!0}}),this.isReportableInCLI=!0,this.isReportableInCLI=!0}static getReportableCause(r){let t=0;const i=15,o=[r];for(;o.length>0&&t<i;){const n=o.pop();if(n instanceof Error){if(n.isReportableInCLI)return n;Array.isArray(n.cause)?o.push(...n.cause):o.push(n.cause),t++,t>=i&&a.logger.warn("Recursion limit exceeded while checking if error is reportable")}}return null}}async function Se({sourceString:e,blueprintMayReadAdjacentFiles:r}){if(!e)return;if(e.startsWith("http://")||e.startsWith("https://"))return await $.resolveRemoteBlueprint(e);let t=b.resolve(process.cwd(),e);if(!g.existsSync(t))throw new Error(`Blueprint file does not exist: ${t}`);const i=g.statSync(t);if(i.isDirectory()&&(t=b.join(t,"blueprint.json")),!i.isFile()&&i.isSymbolicLink())throw new Error(`Blueprint path is neither a file nor a directory: ${t}`);const o=b.extname(t);switch(o){case".zip":return M.ZipFilesystem.fromArrayBuffer(g.readFileSync(t).buffer);case".json":{const n=g.readFileSync(t,"utf-8");try{JSON.parse(n)}catch{throw new Error(`Blueprint file at ${t} is not a valid JSON file`)}const l=b.dirname(t),u=new M.NodeJsFilesystem(l);return new M.OverlayFilesystem([new M.InMemoryFilesystem({"blueprint.json":n}),{read(d){if(!r)throw new K(`Error: Blueprint contained tried to read a local file at path "${d}" (via a resource of type "bundled"). Playground restricts access to local resources by default as a security measure.
|
|
2
|
+
|
|
3
|
+
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.`);return u.read(d)}}])}default:throw new Error(`Unsupported blueprint file extension: ${o}. Only .zip and .json files are supported.`)}}async function xe(){const e=me(process.argv.slice(2)).usage("Usage: wp-playground <command> [options]").positional("command",{describe:"Command to run",choices:["server","run-blueprint","build-snapshot"],demandOption:!0}).option("outfile",{describe:"When building, write to this output file.",type:"string",default:"wordpress.zip"}).option("port",{describe:"Port to listen on when serving.",type:"number",default:9400}).option("php",{describe:"PHP version to use.",type:"string",default:L.RecommendedPHPVersion,choices:v.SupportedPHPVersions}).option("wp",{describe:"WordPress version to use.",type:"string",default:"latest"}).option("mount",{describe:"Mount a directory to the PHP runtime (can be used multiple times). Format: /host/path:/vfs/path",type:"array",string:!0,coerce:E.parseMountWithDelimiterArguments}).option("mount-before-install",{describe:"Mount a directory to the PHP runtime before WordPress installation (can be used multiple times). Format: /host/path:/vfs/path",type:"array",string:!0,coerce:E.parseMountWithDelimiterArguments}).option("mount-dir",{describe:'Mount a directory to the PHP runtime (can be used multiple times). Format: "/host/path" "/vfs/path"',type:"array",nargs:2,array:!0}).option("mount-dir-before-install",{describe:'Mount a directory before WordPress installation (can be used multiple times). Format: "/host/path" "/vfs/path"',type:"string",nargs:2,array:!0,coerce:E.parseMountDirArguments}).option("login",{describe:"Should log the user in",type:"boolean",default:!1}).option("blueprint",{describe:"Blueprint to execute.",type:"string"}).option("blueprint-may-read-adjacent-files",{describe:'Consent flag: Allow "bundled" resources in a local blueprint to read files in the same directory as the blueprint file.',type:"boolean",default:!1}).option("skip-wordpress-setup",{describe:"Do not download, unzip, and install WordPress. Useful for mounting a pre-configured WordPress directory at /wordpress.",type:"boolean",default:!1}).option("skip-sqlite-setup",{describe:"Skip the SQLite integration plugin setup to allow the WordPress site to use MySQL.",type:"boolean",default:!1}).option("quiet",{describe:"Do not output logs and progress messages.",type:"boolean",default:!1}).option("debug",{describe:"Print PHP error log content if an error occurs during Playground boot.",type:"boolean",default:!1}).option("auto-mount",{describe:"Automatically mount the current working directory. You can mount a WordPress directory, a plugin directory, a theme directory, a wp-content directory, or any directory containing PHP and HTML files.",type:"boolean",default:!1}).option("follow-symlinks",{describe:`Allow Playground to follow symlinks by automatically mounting symlinked directories and files encountered in mounted directories.
|
|
4
|
+
Warning: Following symlinks will expose files outside mounted directories to Playground and could be a security risk.`,type:"boolean",default:!1}).option("experimentalTrace",{describe:"Print detailed messages about system behavior to the console. Useful for troubleshooting.",type:"boolean",default:!1,hidden:!0}).option("internal-cookie-store",{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).",type:"boolean",default:!1}).option("xdebug",{describe:"Enable Xdebug.",type:"boolean",default:!1}).option("experimentalMultiWorker",{describe:"Enable experimental multi-worker support which requires JSPI and a /wordpress directory backed by a real filesystem. Pass a positive number to specify the number of workers to use. Otherwise, default to the number of CPUs minus 1.",type:"number",coerce:o=>o??J.cpus().length-1}).showHelpOnFail(!1).check(async o=>{if(o.wp!==void 0&&!We(o.wp))try{new URL(o.wp)}catch{throw new Error('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"')}if(o.experimentalMultiWorker!==void 0){if(o.experimentalMultiWorker<=1)throw new Error("The --experimentalMultiWorker flag must be a positive integer greater than 1.");const n=l=>l.vfsPath==="/wordpress";if(!o.mount?.some(n)&&!o["mount-before-install"]?.some(n))throw new Error("Please mount a real filesystem directory as the /wordpress directory before using the --experimentalMultiWorker flag.")}return!0});e.wrap(e.terminalWidth());const r=await e.argv,t=r._[0];["run-blueprint","server","build-snapshot"].includes(t)||(e.showHelp(),process.exit(1));const i={...r,command:t,blueprint:await Se({sourceString:r.blueprint,blueprintMayReadAdjacentFiles:r.blueprintMayReadAdjacentFiles}),mount:[...r.mount||[],...r["mount-dir"]||[]],"mount-before-install":[...r["mount-before-install"]||[],...r["mount-dir-before-install"]||[]]};try{return G(i)}catch(o){const n=K.getReportableCause(o);if(n)console.log(""),console.log(n.message),process.exit(1);else throw o}}async function G(e){let r,t;const i=[];e.autoMount&&(e=E.expandAutoMounts(e));async function o(s){await t.run({code:`<?php
|
|
5
|
+
$zip = new ZipArchive();
|
|
6
|
+
if(false === $zip->open('/tmp/build.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
|
|
7
|
+
throw new Exception('Failed to create ZIP');
|
|
8
|
+
}
|
|
9
|
+
$files = new RecursiveIteratorIterator(
|
|
10
|
+
new RecursiveDirectoryIterator('/wordpress')
|
|
11
|
+
);
|
|
12
|
+
foreach ($files as $file) {
|
|
13
|
+
echo $file . PHP_EOL;
|
|
14
|
+
if (!$file->isFile()) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
$zip->addFile($file->getPathname(), $file->getPathname());
|
|
18
|
+
}
|
|
19
|
+
$zip->close();
|
|
20
|
+
|
|
21
|
+
`});const c=await t.readFileAsBuffer("/tmp/build.zip");g.writeFileSync(s,c)}async function n(s){const c=$.isBlueprintBundle(e.blueprint)?e.blueprint:{login:e.login,...e.blueprint,preferredVersions:{php:e.php??e?.blueprint?.preferredVersions?.php??L.RecommendedPHPVersion,wp:e.wp??e?.blueprint?.preferredVersions?.wp??"latest",...e.blueprint?.preferredVersions||{}}},f=new N.ProgressTracker;let h="",w=!1;return f.addEventListener("progress",p=>{if(w)return;w=p.detail.progress===100;const S=Math.floor(p.detail.progress);h=p.detail.caption||h||"Running the Blueprint";const P=`${h.trim()} – ${S}%`;e.quiet||u(process.stdout,P,w)}),await $.compileBlueprint(c,{progress:f,additionalSteps:s})}let l="";function u(s,c,f){c!==l&&(l=c,s.isTTY?(s.cursorTo(0),s.write(c),s.clearLine(1),f&&s.write(`
|
|
22
|
+
`)):s.write(`${c}
|
|
23
|
+
`))}async function d(s){const c=new X.Worker(s);return new Promise((f,h)=>{c.once("message",function(w){w.command==="worker-script-initialized"&&f({worker:c,phpPort:w.phpPort})}),c.once("error",function(w){console.error(w);const p=new Error(`Worker failed to load at ${s}. ${w.message?`Original error: ${w.message}`:""}`);p.filename=s,h(p)})})}function A(s){const c=new URL(ve,typeof document>"u"?require("url").pathToFileURL(__filename).href:H&&H.tagName.toUpperCase()==="SCRIPT"&&H.src||new URL("run-cli-B5BfXxxJ.cjs",document.baseURI).href),f=[];for(let h=0;h<s;h++)f.push(d(c));return Promise.all(f)}e.quiet&&(a.logger.handlers=[]);const W=await n(e["additional-blueprint-steps"]||[]),ee=await import("fs-ext").then(s=>s.flockSync).catch(()=>{a.logger.warn("The fs-ext package is not installed. Internal file locking will not be integrated with host OS file locking.")}),U=new we.FileLockManagerForNode(ee);async function T(){const{port1:s,port2:c}=new X.MessageChannel;return await he.jspi()?v.exposeAPI(U,null,s):await v.exposeSyncAPI(U,s),c}let j=!1;return a.logger.log("Starting a PHP server..."),be({port:e.port,onBind:async(s,c)=>{const f=`http://127.0.0.1:${c}`,h=e.experimentalMultiWorker??1,w=A(h);a.logger.log(`Setting up WordPress ${e.wp}`);let p;const S=new N.EmscriptenDownloadMonitor;if(!e.skipWordPressSetup){let m=!1;S.addEventListener("progress",k=>{if(m)return;const{loaded:C,total:B}=k.detail,F=Math.floor(Math.min(100,100*C/B));m=F===100,e.quiet||u(process.stdout,`Downloading WordPress ${F}%...`,m)}),p=await pe.resolveWordPressRelease(e.wp),a.logger.log(`Resolved WordPress release URL: ${p?.releaseUrl}`)}const P=p&&b.join(z,`prebuilt-wp-content-for-wp-${p.version}.zip`),D=p?g.existsSync(P)?Q(P):await Y(p.releaseUrl,`${p.version}.zip`,S):void 0;a.logger.log("Fetching SQLite integration plugin...");const te=e.skipSqliteSetup?void 0:await ye(S),O=e.followSymlinks===!0,Z=e.experimentalTrace===!0;try{const m=e["mount-before-install"]||[],k=e.mount||[],[C,...B]=await w;t=v.consumeAPI(C.phpPort),i.push({playground:t,worker:C.worker}),await t.isConnected();const F=await T();a.logger.log("Booting WordPress...");const I=Math.floor(Number.MAX_SAFE_INTEGER/h);if(await t.useFileLockManager(F),await t.boot({phpVersion:W.versions.php,wpVersion:W.versions.wp,absoluteUrl:f,mountsBeforeWpInstall:m,mountsAfterWpInstall:k,wordPressZip:D&&await D.arrayBuffer(),sqliteIntegrationPluginZip:await te.arrayBuffer(),firstProcessId:0,processIdSpaceLength:I,followSymlinks:O,trace:Z,internalCookieStore:e.internalCookieStore,withXdebug:e.xdebug}),p&&!e["mount-before-install"]&&!g.existsSync(P)&&(a.logger.log("Caching preinstalled WordPress for the next boot..."),g.writeFileSync(P,await L.zipDirectory(t,"/wordpress")),a.logger.log("Cached!")),r=new Re(t),await t.isReady(),j=!0,a.logger.log("Booted!"),W&&(a.logger.log("Running the Blueprint..."),await $.runBlueprintSteps(W,t),a.logger.log("Finished running the blueprint")),e.command==="build-snapshot"?(await o(e.outfile),a.logger.log(`WordPress exported to ${e.outfile}`),process.exit(0)):e.command==="run-blueprint"&&(a.logger.log("Blueprint executed"),process.exit(0)),e.experimentalMultiWorker&&e.experimentalMultiWorker>1){a.logger.log("Preparing additional workers...");const V=await L.zipDirectory(t,"/internal"),x=I;await Promise.all(B.map(async(q,re)=>{const y=v.consumeAPI(q.phpPort);i.push({playground:y,worker:q.worker}),await y.isConnected();const oe=x+re*I,ne=await T();await y.useFileLockManager(ne),await y.boot({phpVersion:W.versions.php,absoluteUrl:f,mountsBeforeWpInstall:m,mountsAfterWpInstall:k,wordPressZip:void 0,sqliteIntegrationPluginZip:void 0,dataSqlPath:"/wordpress/wp-content/database/.ht.sqlite",firstProcessId:oe,processIdSpaceLength:I,followSymlinks:O,trace:Z,internalCookieStore:e.internalCookieStore,withXdebug:e.xdebug}),await y.isReady(),await y.writeFile("/tmp/internal.zip",V),await L.unzipFile(y,"/tmp/internal.zip","/internal"),await y.unlink("/tmp/internal.zip"),r.addWorker(y)})),a.logger.log("Ready!")}return a.logger.log(`WordPress is running on ${f}`),{playground:t,server:s,[Symbol.asyncDispose]:async function(){await Promise.all(i.map(async({playground:x,worker:q})=>{await x.dispose(),await q.terminate()})),await new Promise(x=>s.close(x))}}}catch(m){if(!e.debug)throw m;const k=await t.readFileAsText(a.errorLogPath);throw new Error(k,{cause:m})}},async handleRequest(s){return j?await r.handleRequest(s):v.PHPResponse.forHttpCode(502,"WordPress is not ready yet")}})}exports.parseOptionsAndRunCLI=xe;exports.runCLI=G;
|
|
24
|
+
//# sourceMappingURL=run-cli-B5BfXxxJ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-cli-B5BfXxxJ.cjs","sources":["../../../../packages/playground/cli/src/download.ts","../../../../packages/playground/cli/src/server.ts","../../../../packages/playground/cli/src/load-balancer.ts","../../../../packages/playground/cli/src/is-valid-wordpress-slug.ts","../../../../packages/playground/cli/src/reportable-error.ts","../../../../packages/playground/cli/src/resolve-blueprint.ts","../../../../packages/playground/cli/src/run-cli.ts"],"sourcesContent":["import type { EmscriptenDownloadMonitor } from '@php-wasm/progress';\nimport fs from 'fs-extra';\nimport os from 'os';\nimport path, { basename } from 'path';\n\nexport const CACHE_FOLDER = path.join(os.homedir(), '.wordpress-playground');\n\nexport async function fetchSqliteIntegration(\n\tmonitor: EmscriptenDownloadMonitor\n) {\n\tconst sqliteZip = await cachedDownload(\n\t\t'https://github.com/WordPress/sqlite-database-integration/archive/refs/heads/develop.zip',\n\t\t'sqlite.zip',\n\t\tmonitor\n\t);\n\treturn sqliteZip;\n}\n\n// @TODO: Support HTTP cache, invalidate the local file if the remote file has\n// changed\nexport async function cachedDownload(\n\tremoteUrl: string,\n\tcacheKey: string,\n\tmonitor: EmscriptenDownloadMonitor\n) {\n\tconst artifactPath = path.join(CACHE_FOLDER, cacheKey);\n\tif (!fs.existsSync(artifactPath)) {\n\t\tfs.ensureDirSync(CACHE_FOLDER);\n\t\tawait downloadTo(remoteUrl, artifactPath, monitor);\n\t}\n\treturn readAsFile(artifactPath);\n}\n\nasync function downloadTo(\n\tremoteUrl: string,\n\tlocalPath: string,\n\tmonitor: EmscriptenDownloadMonitor\n) {\n\tconst response = await monitor.monitorFetch(fetch(remoteUrl));\n\tconst reader = response.body!.getReader();\n\tconst tmpPath = `${localPath}.partial`;\n\tconst writer = fs.createWriteStream(tmpPath);\n\twhile (true) {\n\t\tconst { done, value } = await reader.read();\n\t\tif (value) {\n\t\t\twriter.write(value);\n\t\t}\n\t\tif (done) {\n\t\t\tbreak;\n\t\t}\n\t}\n\twriter.close();\n\tif (!writer.closed) {\n\t\tawait new Promise((resolve, reject) => {\n\t\t\twriter.on('finish', () => {\n\t\t\t\tfs.renameSync(tmpPath, localPath);\n\t\t\t\tresolve(null);\n\t\t\t});\n\t\t\twriter.on('error', (err: any) => {\n\t\t\t\tfs.removeSync(tmpPath);\n\t\t\t\treject(err);\n\t\t\t});\n\t\t});\n\t}\n}\n\nexport function readAsFile(path: string, fileName?: string): File {\n\treturn new File([fs.readFileSync(path)], fileName ?? basename(path));\n}\n","import type { PHPRequest, PHPResponse } from '@php-wasm/universal';\nimport type { Request } from 'express';\nimport express from 'express';\nimport type { IncomingMessage, Server, ServerResponse } from 'http';\nimport type { AddressInfo } from 'net';\nimport type { RunCLIServer } from './run-cli';\n\nexport interface ServerOptions {\n\tport: number;\n\tonBind: (server: Server, port: number) => Promise<RunCLIServer>;\n\thandleRequest: (request: PHPRequest) => Promise<PHPResponse>;\n}\n\nexport async function startServer(\n\toptions: ServerOptions\n): Promise<RunCLIServer> {\n\tconst app = express();\n\n\tconst server = await new Promise<\n\t\tServer<typeof IncomingMessage, typeof ServerResponse>\n\t>((resolve, reject) => {\n\t\tconst server = app.listen(options.port, () => {\n\t\t\tconst address = server.address();\n\t\t\tif (address === null || typeof address === 'string') {\n\t\t\t\treject(new Error('Server address is not available'));\n\t\t\t} else {\n\t\t\t\tresolve(server);\n\t\t\t}\n\t\t});\n\t});\n\n\tapp.use('/', async (req, res) => {\n\t\tconst phpResponse = await options.handleRequest({\n\t\t\turl: req.url,\n\t\t\theaders: parseHeaders(req),\n\t\t\tmethod: req.method as any,\n\t\t\tbody: await bufferRequestBody(req),\n\t\t});\n\n\t\tres.statusCode = phpResponse.httpStatusCode;\n\t\tfor (const key in phpResponse.headers) {\n\t\t\tres.setHeader(key, phpResponse.headers[key]);\n\t\t}\n\t\tres.end(phpResponse.bytes);\n\t});\n\n\tconst address = server.address();\n\tconst port = (address! as AddressInfo).port;\n\treturn await options.onBind(server, port);\n}\n\nconst bufferRequestBody = async (req: Request): Promise<Uint8Array> =>\n\tawait new Promise((resolve) => {\n\t\tconst body: Uint8Array[] = [];\n\t\treq.on('data', (chunk) => {\n\t\t\tbody.push(chunk);\n\t\t});\n\t\treq.on('end', () => {\n\t\t\tresolve(new Uint8Array(Buffer.concat(body)));\n\t\t});\n\t});\n\nconst parseHeaders = (req: Request): Record<string, string> => {\n\tconst requestHeaders: Record<string, string> = {};\n\tif (req.rawHeaders && req.rawHeaders.length) {\n\t\tfor (let i = 0; i < req.rawHeaders.length; i += 2) {\n\t\t\trequestHeaders[req.rawHeaders[i].toLowerCase()] =\n\t\t\t\treq.rawHeaders[i + 1];\n\t\t}\n\t}\n\treturn requestHeaders;\n};\n","import type { PHPRequest, PHPResponse, RemoteAPI } from '@php-wasm/universal';\nimport type { PlaygroundCliWorker } from './worker-thread';\n\n// TODO: Let's merge worker management into PHPProcessManager\n// when we can have multiple workers in both CLI and web.\n// ¡ATTENTION!:Please don't expand upon this as an independent abstraction.\n\n// TODO: Could we just spawn a worker using the factory function to PHPProcessManager?\ntype WorkerLoad = {\n\tworker: RemoteAPI<PlaygroundCliWorker>;\n\tactiveRequests: Set<Promise<PHPResponse>>;\n};\nexport class LoadBalancer {\n\tworkerLoads: WorkerLoad[] = [];\n\n\tconstructor(\n\t\t// NOTE: We require a worker to start so that a load balancer\n\t\t// may not exist without being able to service requests.\n\t\t// Playground CLI initialization, as of 2025-06-11, requires that\n\t\t// an initial worker is booted alone and initialized via Blueprint\n\t\t// before additional workers are created based on the initialized worker.\n\t\tinitialWorker: RemoteAPI<PlaygroundCliWorker>\n\t) {\n\t\tthis.addWorker(initialWorker);\n\t}\n\n\taddWorker(worker: RemoteAPI<PlaygroundCliWorker>) {\n\t\tthis.workerLoads.push({\n\t\t\tworker,\n\t\t\tactiveRequests: new Set(),\n\t\t});\n\t}\n\n\tasync handleRequest(request: PHPRequest) {\n\t\tlet smallestWorkerLoad = this.workerLoads[0];\n\n\t\t// TODO: Is there any way for us to track CPU load so we could avoid\n\t\t// picking a worker that is under heavy load despite few requests?\n\t\t// Possibly this: https://nodejs.org/api/worker_threads.html#workerperformance\n\t\t// Though we probably don't need to worry about it.\n\t\tfor (let i = 1; i < this.workerLoads.length; i++) {\n\t\t\tconst workerLoad = this.workerLoads[i];\n\t\t\tif (\n\t\t\t\tworkerLoad.activeRequests.size <\n\t\t\t\tsmallestWorkerLoad.activeRequests.size\n\t\t\t) {\n\t\t\t\tsmallestWorkerLoad = workerLoad;\n\t\t\t}\n\t\t}\n\n\t\t// TODO: Add trace facility to Playground CLI to observe internals like request routing.\n\n\t\tconst promiseForResponse = smallestWorkerLoad.worker.request(request);\n\t\tsmallestWorkerLoad.activeRequests.add(promiseForResponse);\n\n\t\t// Add URL to promise for use while debugging\n\t\t(promiseForResponse as any).url = request.url;\n\n\t\treturn promiseForResponse.finally(() => {\n\t\t\tsmallestWorkerLoad.activeRequests.delete(promiseForResponse);\n\t\t});\n\t}\n}\n","/**\n * Checks if the given version string is a valid WordPress version.\n *\n * The Regex is based on the releases on https://wordpress.org/download/releases/#betas\n * The version string can be one of the following formats:\n * - \"latest\"\n * - \"trunk\"\n * - \"nightly\"\n * - \"x.y\" (x and y are integers) e.g. \"6.2\"\n * - \"x.y.z\" (x, y and z are integers) e.g. \"6.2.1\"\n * - \"x.y.z-betaN\" (N is an integer) e.g. \"6.2.1-beta1\"\n * - \"x.y.z-RCN\" (N is an integer) e.g. \"6.2-RC1\"\n *\n * @param version The version string to check.\n * @returns A boolean value indicating whether the version string is a valid WordPress version.\n */\nexport function isValidWordPressSlug(version: string): boolean {\n\tconst versionPattern =\n\t\t/^latest$|^trunk$|^nightly$|^(?:(\\d+)\\.(\\d+)(?:\\.(\\d+))?)((?:-beta(?:\\d+)?)|(?:-RC(?:\\d+)?))?$/;\n\treturn versionPattern.test(version);\n}\n","/**\n * Specialized error class for CLI errors that should be reported to the user\n * as text messages. Any error of this type thrown in the CLI call stack will\n * be printed as a regular text, not a stack trace, and will cause the process\n * to exit with a non-zero exit code.\n */\nimport { logger } from '@php-wasm/logger';\n\nexport class ReportableError extends Error {\n\tpublic isReportableInCLI = true;\n\n\tconstructor(message: string, options?: ErrorOptions) {\n\t\tsuper(message, {\n\t\t\t...options,\n\t\t\tcause: {\n\t\t\t\tisReportableInCLI: true,\n\t\t\t},\n\t\t});\n\t\tthis.isReportableInCLI = true;\n\t}\n\n\tstatic getReportableCause(error: unknown): Error | null {\n\t\tlet iterations = 0;\n\t\tconst maxIterations = 15;\n\n\t\tconst errorStack = [error];\n\t\twhile (errorStack.length > 0 && iterations < maxIterations) {\n\t\t\tconst subError = errorStack.pop();\n\t\t\tif (!(subError instanceof Error)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ((subError as any).isReportableInCLI) {\n\t\t\t\treturn subError;\n\t\t\t}\n\t\t\tif (Array.isArray(subError.cause)) {\n\t\t\t\terrorStack.push(...subError.cause);\n\t\t\t} else {\n\t\t\t\terrorStack.push(subError.cause);\n\t\t\t}\n\t\t\titerations++;\n\t\t\tif (iterations >= maxIterations) {\n\t\t\t\tlogger.warn(\n\t\t\t\t\t'Recursion limit exceeded while checking if error is reportable'\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n}\n","import fs from 'fs';\nimport path from 'path';\nimport {\n\tZipFilesystem,\n\tNodeJsFilesystem,\n\tOverlayFilesystem,\n\tInMemoryFilesystem,\n} from '@wp-playground/storage';\nimport { resolveRemoteBlueprint } from '@wp-playground/blueprints';\nimport { ReportableError } from './reportable-error';\n\ntype ResolveBlueprintOptions = {\n\tsourceString: string | undefined;\n\tblueprintMayReadAdjacentFiles: boolean;\n};\n\n/**\n * Resolves a blueprint from a URL or a local path.\n *\n * @TODO: Extract the common Blueprint resolution logic between CLI and\n * the website into a single, isomorphic resolveBlueprint() function.\n * Still retain the CLI-specific bits in the CLI package.\n *\n * @param sourceString - The source string to resolve the blueprint from.\n * @param blueprintMayReadAdjacentFiles - Whether the blueprint may read adjacent files.\n * @returns The resolved blueprint.\n */\nexport async function resolveBlueprint({\n\tsourceString,\n\tblueprintMayReadAdjacentFiles,\n}: ResolveBlueprintOptions) {\n\tif (!sourceString) {\n\t\treturn undefined;\n\t}\n\n\tif (\n\t\tsourceString.startsWith('http://') ||\n\t\tsourceString.startsWith('https://')\n\t) {\n\t\treturn await resolveRemoteBlueprint(sourceString);\n\t}\n\n\t// If the sourceString does not refer to a remote blueprint, try to\n\t// resolve it from a local filesystem.\n\n\tlet blueprintPath = path.resolve(process.cwd(), sourceString);\n\tif (!fs.existsSync(blueprintPath)) {\n\t\tthrow new Error(`Blueprint file does not exist: ${blueprintPath}`);\n\t}\n\n\tconst stat = fs.statSync(blueprintPath);\n\tif (stat.isDirectory()) {\n\t\tblueprintPath = path.join(blueprintPath, 'blueprint.json');\n\t}\n\n\tif (!stat.isFile() && stat.isSymbolicLink()) {\n\t\tthrow new Error(\n\t\t\t`Blueprint path is neither a file nor a directory: ${blueprintPath}`\n\t\t);\n\t}\n\n\tconst extension = path.extname(blueprintPath);\n\tswitch (extension) {\n\t\tcase '.zip':\n\t\t\treturn ZipFilesystem.fromArrayBuffer(\n\t\t\t\tfs.readFileSync(blueprintPath).buffer as ArrayBuffer\n\t\t\t);\n\t\tcase '.json': {\n\t\t\tconst blueprintText = fs.readFileSync(blueprintPath, 'utf-8');\n\t\t\ttry {\n\t\t\t\tJSON.parse(blueprintText);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Blueprint file at ${blueprintPath} is not a valid JSON file`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst contextPath = path.dirname(blueprintPath);\n\t\t\tconst nodeJsFilesystem = new NodeJsFilesystem(contextPath);\n\t\t\treturn new OverlayFilesystem([\n\t\t\t\tnew InMemoryFilesystem({\n\t\t\t\t\t'blueprint.json': blueprintText,\n\t\t\t\t}),\n\t\t\t\t/**\n\t\t\t\t * Wrap the NodeJS filesystem to prevent access to local files\n\t\t\t\t * unless the user explicitly allowed it.\n\t\t\t\t */\n\t\t\t\t{\n\t\t\t\t\tread(path) {\n\t\t\t\t\t\tif (!blueprintMayReadAdjacentFiles) {\n\t\t\t\t\t\t\tthrow new ReportableError(\n\t\t\t\t\t\t\t\t`Error: Blueprint contained tried to read a local file at path \"${path}\" (via a resource of type \"bundled\"). ` +\n\t\t\t\t\t\t\t\t\t`Playground restricts access to local resources by default as a security measure. \\n\\n` +\n\t\t\t\t\t\t\t\t\t`You can allow this Blueprint to read files from the same parent directory by explicitly adding the ` +\n\t\t\t\t\t\t\t\t\t`--blueprint-may-read-adjacent-files option to your command.`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn nodeJsFilesystem.read(path);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t]);\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(\n\t\t\t\t`Unsupported blueprint file extension: ${extension}. Only .zip and .json files are supported.`\n\t\t\t);\n\t}\n}\n","import { errorLogPath, logger } from '@php-wasm/logger';\nimport { EmscriptenDownloadMonitor, ProgressTracker } from '@php-wasm/progress';\nimport type {\n\tPHPRequest,\n\tRemoteAPI,\n\tSupportedPHPVersion,\n} from '@php-wasm/universal';\nimport {\n\tPHPResponse,\n\tconsumeAPI,\n\texposeAPI,\n\texposeSyncAPI,\n} from '@php-wasm/universal';\nimport type {\n\tBlueprintBundle,\n\tBlueprintDeclaration,\n} from '@wp-playground/blueprints';\nimport {\n\tcompileBlueprint,\n\tisBlueprintBundle,\n\trunBlueprintSteps,\n} from '@wp-playground/blueprints';\nimport {\n\tRecommendedPHPVersion,\n\tunzipFile,\n\tzipDirectory,\n} from '@wp-playground/common';\nimport fs from 'fs';\nimport type { Server } from 'http';\nimport path from 'path';\nimport { Worker, MessageChannel } from 'worker_threads';\n// @ts-ignore\nimport { resolveWordPressRelease } from '@wp-playground/wordpress';\nimport {\n\texpandAutoMounts,\n\tparseMountDirArguments,\n\tparseMountWithDelimiterArguments,\n} from './mounts';\nimport {\n\tCACHE_FOLDER,\n\tcachedDownload,\n\tfetchSqliteIntegration,\n\treadAsFile,\n} from './download';\nimport { startServer } from './server';\nimport type { Mount, PlaygroundCliWorker } from './worker-thread';\n// @ts-ignore\nimport importedWorkerUrlString from './worker-thread?worker&url';\n// @ts-ignore\nimport { FileLockManagerForNode } from '@php-wasm/node';\nimport { LoadBalancer } from './load-balancer';\n/* eslint-disable no-console */\nimport { SupportedPHPVersions } from '@php-wasm/universal';\nimport { cpus } from 'os';\nimport { jspi } from 'wasm-feature-detect';\nimport type { MessagePort as NodeMessagePort } from 'worker_threads';\nimport yargs from 'yargs';\nimport { isValidWordPressSlug } from './is-valid-wordpress-slug';\nimport { ReportableError } from './reportable-error';\nimport { resolveBlueprint } from './resolve-blueprint';\n\nexport async function parseOptionsAndRunCLI() {\n\t/**\n\t * @TODO This looks similar to Query API args https://wordpress.github.io/wordpress-playground/developers/apis/query-api/\n\t * Perhaps the two could be handled by the same code?\n\t */\n\tconst yargsObject = yargs(process.argv.slice(2))\n\t\t.usage('Usage: wp-playground <command> [options]')\n\t\t.positional('command', {\n\t\t\tdescribe: 'Command to run',\n\t\t\tchoices: ['server', 'run-blueprint', 'build-snapshot'] as const,\n\t\t\tdemandOption: true,\n\t\t})\n\t\t.option('outfile', {\n\t\t\tdescribe: 'When building, write to this output file.',\n\t\t\ttype: 'string',\n\t\t\tdefault: 'wordpress.zip',\n\t\t})\n\t\t.option('port', {\n\t\t\tdescribe: 'Port to listen on when serving.',\n\t\t\ttype: 'number',\n\t\t\tdefault: 9400,\n\t\t})\n\t\t.option('php', {\n\t\t\tdescribe: 'PHP version to use.',\n\t\t\ttype: 'string',\n\t\t\tdefault: RecommendedPHPVersion,\n\t\t\tchoices: SupportedPHPVersions,\n\t\t})\n\t\t.option('wp', {\n\t\t\tdescribe: 'WordPress version to use.',\n\t\t\ttype: 'string',\n\t\t\tdefault: 'latest',\n\t\t})\n\t\t// @TODO: Support read-only mounts, e.g. via WORKERFS, a custom\n\t\t// ReadOnlyNODEFS, or by copying the files into MEMFS\n\t\t.option('mount', {\n\t\t\tdescribe:\n\t\t\t\t'Mount a directory to the PHP runtime (can be used multiple times). Format: /host/path:/vfs/path',\n\t\t\ttype: 'array',\n\t\t\tstring: true,\n\t\t\tcoerce: parseMountWithDelimiterArguments,\n\t\t})\n\t\t.option('mount-before-install', {\n\t\t\tdescribe:\n\t\t\t\t'Mount a directory to the PHP runtime before WordPress installation (can be used multiple times). Format: /host/path:/vfs/path',\n\t\t\ttype: 'array',\n\t\t\tstring: true,\n\t\t\tcoerce: parseMountWithDelimiterArguments,\n\t\t})\n\t\t.option('mount-dir', {\n\t\t\tdescribe:\n\t\t\t\t'Mount a directory to the PHP runtime (can be used multiple times). Format: \"/host/path\" \"/vfs/path\"',\n\t\t\ttype: 'array',\n\t\t\tnargs: 2,\n\t\t\tarray: true,\n\t\t\t// coerce: parseMountDirArguments,\n\t\t})\n\t\t.option('mount-dir-before-install', {\n\t\t\tdescribe:\n\t\t\t\t'Mount a directory before WordPress installation (can be used multiple times). Format: \"/host/path\" \"/vfs/path\"',\n\t\t\ttype: 'string',\n\t\t\tnargs: 2,\n\t\t\tarray: true,\n\t\t\tcoerce: parseMountDirArguments,\n\t\t})\n\t\t.option('login', {\n\t\t\tdescribe: 'Should log the user in',\n\t\t\ttype: 'boolean',\n\t\t\tdefault: false,\n\t\t})\n\t\t.option('blueprint', {\n\t\t\tdescribe: 'Blueprint to execute.',\n\t\t\ttype: 'string',\n\t\t})\n\t\t.option('blueprint-may-read-adjacent-files', {\n\t\t\tdescribe:\n\t\t\t\t'Consent flag: Allow \"bundled\" resources in a local blueprint to read files in the same directory as the blueprint file.',\n\t\t\ttype: 'boolean',\n\t\t\tdefault: false,\n\t\t})\n\t\t.option('skip-wordpress-setup', {\n\t\t\tdescribe:\n\t\t\t\t'Do not download, unzip, and install WordPress. Useful for mounting a pre-configured WordPress directory at /wordpress.',\n\t\t\ttype: 'boolean',\n\t\t\tdefault: false,\n\t\t})\n\t\t.option('skip-sqlite-setup', {\n\t\t\tdescribe:\n\t\t\t\t'Skip the SQLite integration plugin setup to allow the WordPress site to use MySQL.',\n\t\t\ttype: 'boolean',\n\t\t\tdefault: false,\n\t\t})\n\t\t.option('quiet', {\n\t\t\tdescribe: 'Do not output logs and progress messages.',\n\t\t\ttype: 'boolean',\n\t\t\tdefault: false,\n\t\t})\n\t\t.option('debug', {\n\t\t\tdescribe:\n\t\t\t\t'Print PHP error log content if an error occurs during Playground boot.',\n\t\t\ttype: 'boolean',\n\t\t\tdefault: false,\n\t\t})\n\t\t.option('auto-mount', {\n\t\t\tdescribe: `Automatically mount the current working directory. You can mount a WordPress directory, a plugin directory, a theme directory, a wp-content directory, or any directory containing PHP and HTML files.`,\n\t\t\ttype: 'boolean',\n\t\t\tdefault: false,\n\t\t})\n\t\t.option('follow-symlinks', {\n\t\t\tdescribe:\n\t\t\t\t'Allow Playground to follow symlinks by automatically mounting symlinked directories and files encountered in mounted directories. \\nWarning: Following symlinks will expose files outside mounted directories to Playground and could be a security risk.',\n\t\t\ttype: 'boolean',\n\t\t\tdefault: false,\n\t\t})\n\t\t.option('experimentalTrace', {\n\t\t\tdescribe:\n\t\t\t\t'Print detailed messages about system behavior to the console. Useful for troubleshooting.',\n\t\t\ttype: 'boolean',\n\t\t\tdefault: false,\n\t\t\t// Hide this option because we want to replace with a more general log-level flag.\n\t\t\thidden: true,\n\t\t})\n\t\t.option('internal-cookie-store', {\n\t\t\tdescribe:\n\t\t\t\t'Enable internal cookie handling. When enabled, Playground will manage cookies internally using ' +\n\t\t\t\t'an HttpCookieStore that persists cookies across requests. When disabled, cookies are handled ' +\n\t\t\t\t'externally (e.g., by a browser in Node.js environments).',\n\t\t\ttype: 'boolean',\n\t\t\tdefault: false,\n\t\t})\n\t\t.option('xdebug', {\n\t\t\tdescribe: 'Enable Xdebug.',\n\t\t\ttype: 'boolean',\n\t\t\tdefault: false,\n\t\t})\n\t\t// TODO: Should we make this a hidden flag?\n\t\t.option('experimentalMultiWorker', {\n\t\t\tdescribe:\n\t\t\t\t'Enable experimental multi-worker support which requires JSPI ' +\n\t\t\t\t'and a /wordpress directory backed by a real filesystem. ' +\n\t\t\t\t'Pass a positive number to specify the number of workers to use. ' +\n\t\t\t\t'Otherwise, default to the number of CPUs minus 1.',\n\t\t\ttype: 'number',\n\t\t\tcoerce: (value?: number) => value ?? cpus().length - 1,\n\t\t})\n\t\t.showHelpOnFail(false)\n\t\t.check(async (args) => {\n\t\t\tif (args.wp !== undefined && !isValidWordPressSlug(args.wp)) {\n\t\t\t\ttry {\n\t\t\t\t\t// Check if is valid URL\n\t\t\t\t\tnew URL(args.wp);\n\t\t\t\t} catch {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'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\"'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (args.experimentalMultiWorker !== undefined) {\n\t\t\t\tif (args.experimentalMultiWorker <= 1) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'The --experimentalMultiWorker flag must be a positive integer greater than 1.'\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst isMountingWordPressDir = (mount: Mount) =>\n\t\t\t\t\tmount.vfsPath === '/wordpress';\n\t\t\t\tif (\n\t\t\t\t\t!args.mount?.some(isMountingWordPressDir) &&\n\t\t\t\t\t!(args['mount-before-install'] as any)?.some(\n\t\t\t\t\t\tisMountingWordPressDir\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'Please mount a real filesystem directory as the /wordpress directory before using the --experimentalMultiWorker flag.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\n\tyargsObject.wrap(yargsObject.terminalWidth());\n\tconst args = await yargsObject.argv;\n\n\tconst command = args._[0] as string;\n\n\tif (!['run-blueprint', 'server', 'build-snapshot'].includes(command)) {\n\t\tyargsObject.showHelp();\n\t\tprocess.exit(1);\n\t}\n\n\tconst cliArgs = {\n\t\t...args,\n\t\tcommand,\n\t\tblueprint: await resolveBlueprint({\n\t\t\tsourceString: args.blueprint,\n\t\t\tblueprintMayReadAdjacentFiles: args.blueprintMayReadAdjacentFiles,\n\t\t}),\n\t\tmount: [...(args.mount || []), ...(args['mount-dir'] || [])],\n\t\t'mount-before-install': [\n\t\t\t...(args['mount-before-install'] || []),\n\t\t\t...(args['mount-dir-before-install'] || []),\n\t\t],\n\t} as RunCLIArgs;\n\n\ttry {\n\t\treturn runCLI(cliArgs);\n\t} catch (e) {\n\t\tconst reportableCause = ReportableError.getReportableCause(e);\n\t\tif (reportableCause) {\n\t\t\tconsole.log('');\n\t\t\tconsole.log(reportableCause.message);\n\t\t\tprocess.exit(1);\n\t\t} else {\n\t\t\tthrow e;\n\t\t}\n\t}\n}\n\nexport interface RunCLIArgs {\n\tblueprint?: BlueprintDeclaration | BlueprintBundle;\n\tcommand: 'server' | 'run-blueprint' | 'build-snapshot';\n\tdebug?: boolean;\n\tlogin?: boolean;\n\tmount?: Mount[];\n\t'mount-before-install'?: Mount[];\n\toutfile?: string;\n\tphp?: SupportedPHPVersion;\n\tport?: number;\n\tquiet?: boolean;\n\tskipWordPressSetup?: boolean;\n\tskipSqliteSetup?: boolean;\n\twp?: string;\n\tautoMount?: boolean;\n\tfollowSymlinks?: boolean;\n\texperimentalMultiWorker?: number;\n\texperimentalTrace?: boolean;\n\tinternalCookieStore?: boolean;\n\t'additional-blueprint-steps'?: any[];\n\txdebug?: boolean;\n}\n\nexport interface RunCLIServer extends AsyncDisposable {\n\tplayground: RemoteAPI<PlaygroundCliWorker>;\n\tserver: Server;\n\t[Symbol.asyncDispose](): Promise<void>;\n}\n\nexport async function runCLI(args: RunCLIArgs): Promise<RunCLIServer> {\n\tlet loadBalancer: LoadBalancer;\n\tlet playground: RemoteAPI<PlaygroundCliWorker>;\n\n\tconst playgroundsToCleanUp: {\n\t\tplayground: RemoteAPI<PlaygroundCliWorker>;\n\t\tworker: Worker;\n\t}[] = [];\n\n\t/**\n\t * Expand auto-mounts to include the necessary mounts and steps\n\t * when running in auto-mount mode.\n\t */\n\tif (args.autoMount) {\n\t\targs = expandAutoMounts(args);\n\t}\n\n\t/**\n\t * TODO: This exact feature will be provided in the PHP Blueprints library.\n\t * Let's use it when it ships. Let's also use it in the web Playground\n\t * app.\n\t */\n\tasync function zipSite(outfile: string) {\n\t\tawait playground.run({\n\t\t\tcode: `<?php\n\t\t\t$zip = new ZipArchive();\n\t\t\tif(false === $zip->open('/tmp/build.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE)) {\n\t\t\t\tthrow new Exception('Failed to create ZIP');\n\t\t\t}\n\t\t\t$files = new RecursiveIteratorIterator(\n\t\t\t\tnew RecursiveDirectoryIterator('/wordpress')\n\t\t\t);\n\t\t\tforeach ($files as $file) {\n\t\t\t\techo $file . PHP_EOL;\n\t\t\t\tif (!$file->isFile()) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t$zip->addFile($file->getPathname(), $file->getPathname());\n\t\t\t}\n\t\t\t$zip->close();\n\n\t\t`,\n\t\t});\n\t\tconst zip = await playground.readFileAsBuffer('/tmp/build.zip');\n\t\tfs.writeFileSync(outfile, zip);\n\t}\n\n\tasync function compileInputBlueprint(additionalBlueprintSteps: any[]) {\n\t\t/**\n\t\t * @TODO This looks similar to the resolveBlueprint() call in the website package:\n\t\t * \t https://github.com/WordPress/wordpress-playground/blob/ce586059e5885d185376184fdd2f52335cca32b0/packages/playground/website/src/main.tsx#L41\n\t\t *\n\t\t * \t\t Also the Blueprint Builder tool does something similar.\n\t\t * Perhaps all these cases could be handled by the same function?\n\t\t */\n\t\tconst blueprint: BlueprintDeclaration | BlueprintBundle =\n\t\t\tisBlueprintBundle(args.blueprint)\n\t\t\t\t? args.blueprint\n\t\t\t\t: {\n\t\t\t\t\t\tlogin: args.login,\n\t\t\t\t\t\t...args.blueprint,\n\t\t\t\t\t\tpreferredVersions: {\n\t\t\t\t\t\t\tphp:\n\t\t\t\t\t\t\t\targs.php ??\n\t\t\t\t\t\t\t\targs?.blueprint?.preferredVersions?.php ??\n\t\t\t\t\t\t\t\tRecommendedPHPVersion,\n\t\t\t\t\t\t\twp:\n\t\t\t\t\t\t\t\targs.wp ??\n\t\t\t\t\t\t\t\targs?.blueprint?.preferredVersions?.wp ??\n\t\t\t\t\t\t\t\t'latest',\n\t\t\t\t\t\t\t...(args.blueprint?.preferredVersions || {}),\n\t\t\t\t\t\t},\n\t\t\t\t };\n\n\t\tconst tracker = new ProgressTracker();\n\t\tlet lastCaption = '';\n\t\tlet progressReached100 = false;\n\t\ttracker.addEventListener('progress', (e: any) => {\n\t\t\tif (progressReached100) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tprogressReached100 = e.detail.progress === 100;\n\n\t\t\t// Use floor() so we don't report 100% until truly there.\n\t\t\tconst progressInteger = Math.floor(e.detail.progress);\n\t\t\tlastCaption =\n\t\t\t\te.detail.caption || lastCaption || 'Running the Blueprint';\n\t\t\tconst message = `${lastCaption.trim()} – ${progressInteger}%`;\n\t\t\tif (!args.quiet) {\n\t\t\t\twriteProgressUpdate(\n\t\t\t\t\tprocess.stdout,\n\t\t\t\t\tmessage,\n\t\t\t\t\tprogressReached100\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t\treturn await compileBlueprint(blueprint as BlueprintDeclaration, {\n\t\t\tprogress: tracker,\n\t\t\tadditionalSteps: additionalBlueprintSteps,\n\t\t});\n\t}\n\n\tlet lastProgressMessage = '';\n\tfunction writeProgressUpdate(\n\t\twriteStream: NodeJS.WriteStream,\n\t\tmessage: string,\n\t\tfinalUpdate: boolean\n\t) {\n\t\tif (message === lastProgressMessage) {\n\t\t\t// Avoid repeating the same message\n\t\t\treturn;\n\t\t}\n\t\tlastProgressMessage = message;\n\n\t\tif (writeStream.isTTY) {\n\t\t\t// Overwrite previous progress updates in-place for a quieter UX.\n\t\t\twriteStream.cursorTo(0);\n\t\t\twriteStream.write(message);\n\t\t\twriteStream.clearLine(1);\n\n\t\t\tif (finalUpdate) {\n\t\t\t\twriteStream.write('\\n');\n\t\t\t}\n\t\t} else {\n\t\t\t// Fall back to writing one line per progress update\n\t\t\twriteStream.write(`${message}\\n`);\n\t\t}\n\t}\n\n\t/**\n\t * Spawns a new Worker Thread.\n\t *\n\t * @param workerUrl The absolute URL of the worker script.\n\t * @returns The spawned Worker Thread.\n\t */\n\tasync function spawnPHPWorkerThread(workerUrl: URL) {\n\t\tconst worker = new Worker(workerUrl);\n\n\t\treturn new Promise<{ worker: Worker; phpPort: NodeMessagePort }>(\n\t\t\t(resolve, reject) => {\n\t\t\t\tworker.once('message', function (message: any) {\n\t\t\t\t\t// Let the worker confirm it has initialized.\n\t\t\t\t\t// We could use the 'online' event to detect start of JS execution,\n\t\t\t\t\t// but that would miss initialization errors.\n\t\t\t\t\tif (message.command === 'worker-script-initialized') {\n\t\t\t\t\t\tresolve({ worker, phpPort: message.phpPort });\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tworker.once('error', function (e: Error) {\n\t\t\t\t\tconsole.error(e);\n\t\t\t\t\tconst error = new Error(\n\t\t\t\t\t\t`Worker failed to load at ${workerUrl}. ${\n\t\t\t\t\t\t\te.message ? `Original error: ${e.message}` : ''\n\t\t\t\t\t\t}`\n\t\t\t\t\t);\n\t\t\t\t\t(error as any).filename = workerUrl;\n\t\t\t\t\treject(error);\n\t\t\t\t});\n\t\t\t}\n\t\t);\n\t}\n\n\tfunction spawnWorkerThreads(\n\t\tcount: number\n\t): Promise<{ worker: Worker; phpPort: NodeMessagePort }[]> {\n\t\tconst moduleWorkerUrl = new URL(\n\t\t\timportedWorkerUrlString,\n\t\t\timport.meta.url\n\t\t);\n\n\t\tconst promises = [];\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tpromises.push(spawnPHPWorkerThread(moduleWorkerUrl));\n\t\t}\n\t\treturn Promise.all(promises);\n\t}\n\n\tif (args.quiet) {\n\t\t// @ts-ignore\n\t\tlogger.handlers = [];\n\t}\n\n\tconst compiledBlueprint = await compileInputBlueprint(\n\t\targs['additional-blueprint-steps'] || []\n\t);\n\n\t// Declare file lock manager outside scope of startServer\n\t// so we can look at it when debugging request handling.\n\tconst nativeFlockSync = await import('fs-ext')\n\t\t.then((m) => m.flockSync)\n\t\t.catch(() => {\n\t\t\tlogger.warn(\n\t\t\t\t'The fs-ext package is not installed. ' +\n\t\t\t\t\t'Internal file locking will not be integrated with ' +\n\t\t\t\t\t'host OS file locking.'\n\t\t\t);\n\t\t\treturn undefined;\n\t\t});\n\tconst fileLockManager = new FileLockManagerForNode(nativeFlockSync);\n\n\t/**\n\t * Expose the file lock manager API on a MessagePort and return it.\n\t *\n\t * @see comlink-sync.ts\n\t * @see phpwasm-emscripten-library-file-locking-for-node.js\n\t */\n\tasync function exposeFileLockManager() {\n\t\tconst { port1, port2 } = new MessageChannel();\n\t\tif (await jspi()) {\n\t\t\t/**\n\t\t\t * When JSPI is available, the worker thread expects an asynchronous API.\n\t\t\t *\n\t\t\t * @see worker-thread.ts\n\t\t\t * @see comlink-sync.ts\n\t\t\t * @see phpwasm-emscripten-library-file-locking-for-node.js\n\t\t\t */\n\t\t\texposeAPI(fileLockManager, null, port1);\n\t\t} else {\n\t\t\t/**\n\t\t\t * When JSPI is not available, the worker thread expects a synchronous API.\n\t\t\t *\n\t\t\t * @see worker-thread.ts\n\t\t\t * @see comlink-sync.ts\n\t\t\t * @see phpwasm-emscripten-library-file-locking-for-node.js\n\t\t\t */\n\t\t\tawait exposeSyncAPI(fileLockManager, port1);\n\t\t}\n\t\treturn port2;\n\t}\n\n\tlet wordPressReady = false;\n\n\tlogger.log('Starting a PHP server...');\n\n\treturn startServer({\n\t\tport: args['port'] as number,\n\t\tonBind: async (server: Server, port: number): Promise<RunCLIServer> => {\n\t\t\tconst absoluteUrl = `http://127.0.0.1:${port}`;\n\n\t\t\t// Kick off worker threads now to save time later.\n\t\t\t// There is no need to wait for other async processes to complete.\n\t\t\tconst totalWorkerCount = args.experimentalMultiWorker ?? 1;\n\t\t\tconst promisedWorkers = spawnWorkerThreads(totalWorkerCount);\n\n\t\t\tlogger.log(`Setting up WordPress ${args.wp}`);\n\t\t\tlet wpDetails: any = undefined;\n\t\t\t// @TODO: Rename to FetchProgressMonitor. There's nothing Emscripten\n\t\t\t// about that class anymore.\n\t\t\tconst monitor = new EmscriptenDownloadMonitor();\n\t\t\tif (!args.skipWordPressSetup) {\n\t\t\t\tlet progressReached100 = false;\n\t\t\t\tmonitor.addEventListener('progress', ((\n\t\t\t\t\te: CustomEvent<ProgressEvent & { finished: boolean }>\n\t\t\t\t) => {\n\t\t\t\t\tif (progressReached100) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t// @TODO Every progress bar will want percentages. The\n\t\t\t\t\t// download monitor should just provide that.\n\t\t\t\t\tconst { loaded, total } = e.detail;\n\t\t\t\t\t// Use floor() so we don't report 100% until truly there.\n\t\t\t\t\tconst percentProgress = Math.floor(\n\t\t\t\t\t\tMath.min(100, (100 * loaded) / total)\n\t\t\t\t\t);\n\t\t\t\t\tprogressReached100 = percentProgress === 100;\n\n\t\t\t\t\tif (!args.quiet) {\n\t\t\t\t\t\twriteProgressUpdate(\n\t\t\t\t\t\t\tprocess.stdout,\n\t\t\t\t\t\t\t`Downloading WordPress ${percentProgress}%...`,\n\t\t\t\t\t\t\tprogressReached100\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}) as any);\n\n\t\t\t\twpDetails = await resolveWordPressRelease(args.wp);\n\t\t\t\tlogger.log(\n\t\t\t\t\t`Resolved WordPress release URL: ${wpDetails?.releaseUrl}`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst preinstalledWpContentPath =\n\t\t\t\twpDetails &&\n\t\t\t\tpath.join(\n\t\t\t\t\tCACHE_FOLDER,\n\t\t\t\t\t`prebuilt-wp-content-for-wp-${wpDetails.version}.zip`\n\t\t\t\t);\n\t\t\tconst wordPressZip = !wpDetails\n\t\t\t\t? undefined\n\t\t\t\t: fs.existsSync(preinstalledWpContentPath)\n\t\t\t\t? readAsFile(preinstalledWpContentPath)\n\t\t\t\t: await cachedDownload(\n\t\t\t\t\t\twpDetails.releaseUrl,\n\t\t\t\t\t\t`${wpDetails.version}.zip`,\n\t\t\t\t\t\tmonitor\n\t\t\t\t );\n\n\t\t\tlogger.log(`Fetching SQLite integration plugin...`);\n\t\t\tconst sqliteIntegrationPluginZip = args.skipSqliteSetup\n\t\t\t\t? undefined\n\t\t\t\t: await fetchSqliteIntegration(monitor);\n\n\t\t\tconst followSymlinks = args.followSymlinks === true;\n\t\t\tconst trace = args.experimentalTrace === true;\n\t\t\ttry {\n\t\t\t\tconst mountsBeforeWpInstall =\n\t\t\t\t\targs['mount-before-install'] || [];\n\t\t\t\tconst mountsAfterWpInstall = args.mount || [];\n\n\t\t\t\tconst [initialWorker, ...additionalWorkers] =\n\t\t\t\t\tawait promisedWorkers;\n\n\t\t\t\tplayground = consumeAPI<PlaygroundCliWorker>(\n\t\t\t\t\tinitialWorker.phpPort\n\t\t\t\t);\n\t\t\t\tplaygroundsToCleanUp.push({\n\t\t\t\t\tplayground,\n\t\t\t\t\tworker: initialWorker.worker,\n\t\t\t\t});\n\n\t\t\t\t// Comlink communication proxy\n\t\t\t\tawait playground.isConnected();\n\n\t\t\t\tconst fileLockManagerPort = await exposeFileLockManager();\n\n\t\t\t\tlogger.log(`Booting WordPress...`);\n\n\t\t\t\t// Each additional worker needs a separate process ID space\n\t\t\t\t// for file locking to work properly because locks are associated\n\t\t\t\t// with individual processes. To accommodate this, we split the safe\n\t\t\t\t// integers into a range for each worker.\n\t\t\t\tconst processIdSpaceLength = Math.floor(\n\t\t\t\t\tNumber.MAX_SAFE_INTEGER / totalWorkerCount\n\t\t\t\t);\n\n\t\t\t\tawait playground.useFileLockManager(fileLockManagerPort);\n\t\t\t\tawait playground.boot({\n\t\t\t\t\tphpVersion: compiledBlueprint.versions.php,\n\t\t\t\t\twpVersion: compiledBlueprint.versions.wp,\n\t\t\t\t\tabsoluteUrl,\n\t\t\t\t\tmountsBeforeWpInstall,\n\t\t\t\t\tmountsAfterWpInstall,\n\t\t\t\t\twordPressZip:\n\t\t\t\t\t\twordPressZip && (await wordPressZip!.arrayBuffer()),\n\t\t\t\t\tsqliteIntegrationPluginZip:\n\t\t\t\t\t\tawait sqliteIntegrationPluginZip!.arrayBuffer(),\n\t\t\t\t\tfirstProcessId: 0,\n\t\t\t\t\tprocessIdSpaceLength,\n\t\t\t\t\tfollowSymlinks,\n\t\t\t\t\ttrace,\n\t\t\t\t\tinternalCookieStore: args.internalCookieStore,\n\t\t\t\t\twithXdebug: args.xdebug,\n\t\t\t\t});\n\n\t\t\t\tif (\n\t\t\t\t\twpDetails &&\n\t\t\t\t\t!args['mount-before-install'] &&\n\t\t\t\t\t!fs.existsSync(preinstalledWpContentPath)\n\t\t\t\t) {\n\t\t\t\t\tlogger.log(\n\t\t\t\t\t\t`Caching preinstalled WordPress for the next boot...`\n\t\t\t\t\t);\n\t\t\t\t\tfs.writeFileSync(\n\t\t\t\t\t\tpreinstalledWpContentPath,\n\t\t\t\t\t\tawait zipDirectory(playground, '/wordpress')\n\t\t\t\t\t);\n\t\t\t\t\tlogger.log(`Cached!`);\n\t\t\t\t}\n\n\t\t\t\tloadBalancer = new LoadBalancer(playground);\n\n\t\t\t\tawait playground.isReady();\n\t\t\t\twordPressReady = true;\n\t\t\t\tlogger.log(`Booted!`);\n\n\t\t\t\tif (compiledBlueprint) {\n\t\t\t\t\tlogger.log(`Running the Blueprint...`);\n\t\t\t\t\tawait runBlueprintSteps(compiledBlueprint, playground);\n\t\t\t\t\tlogger.log(`Finished running the blueprint`);\n\t\t\t\t}\n\n\t\t\t\tif (args.command === 'build-snapshot') {\n\t\t\t\t\tawait zipSite(args.outfile as string);\n\t\t\t\t\tlogger.log(`WordPress exported to ${args.outfile}`);\n\t\t\t\t\tprocess.exit(0);\n\t\t\t\t} else if (args.command === 'run-blueprint') {\n\t\t\t\t\tlogger.log(`Blueprint executed`);\n\t\t\t\t\tprocess.exit(0);\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\targs.experimentalMultiWorker &&\n\t\t\t\t\targs.experimentalMultiWorker > 1\n\t\t\t\t) {\n\t\t\t\t\tlogger.log(`Preparing additional workers...`);\n\n\t\t\t\t\t// Save /internal directory from initial worker so we can replicate it\n\t\t\t\t\t// in each additional worker.\n\t\t\t\t\tconst internalZip = await zipDirectory(\n\t\t\t\t\t\tplayground,\n\t\t\t\t\t\t'/internal'\n\t\t\t\t\t);\n\n\t\t\t\t\t// Boot additional workers\n\t\t\t\t\tconst initialWorkerProcessIdSpace = processIdSpaceLength;\n\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\tadditionalWorkers.map(async (worker, index) => {\n\t\t\t\t\t\t\tconst additionalPlayground =\n\t\t\t\t\t\t\t\tconsumeAPI<PlaygroundCliWorker>(worker.phpPort);\n\t\t\t\t\t\t\tplaygroundsToCleanUp.push({\n\t\t\t\t\t\t\t\tplayground: additionalPlayground,\n\t\t\t\t\t\t\t\tworker: worker.worker,\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tawait additionalPlayground.isConnected();\n\n\t\t\t\t\t\t\tconst firstProcessId =\n\t\t\t\t\t\t\t\tinitialWorkerProcessIdSpace +\n\t\t\t\t\t\t\t\tindex * processIdSpaceLength;\n\n\t\t\t\t\t\t\tconst fileLockManagerPort =\n\t\t\t\t\t\t\t\tawait exposeFileLockManager();\n\t\t\t\t\t\t\tawait additionalPlayground.useFileLockManager(\n\t\t\t\t\t\t\t\tfileLockManagerPort\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tawait additionalPlayground.boot({\n\t\t\t\t\t\t\t\tphpVersion: compiledBlueprint.versions.php,\n\t\t\t\t\t\t\t\tabsoluteUrl,\n\t\t\t\t\t\t\t\tmountsBeforeWpInstall,\n\t\t\t\t\t\t\t\tmountsAfterWpInstall,\n\t\t\t\t\t\t\t\t// Skip WordPress zip because we share the /wordpress directory\n\t\t\t\t\t\t\t\t// populated by the initial worker.\n\t\t\t\t\t\t\t\twordPressZip: undefined,\n\t\t\t\t\t\t\t\t// Skip SQLite integration plugin for now because we\n\t\t\t\t\t\t\t\t// will copy it from primary's `/internal` directory.\n\t\t\t\t\t\t\t\tsqliteIntegrationPluginZip: undefined,\n\t\t\t\t\t\t\t\tdataSqlPath:\n\t\t\t\t\t\t\t\t\t'/wordpress/wp-content/database/.ht.sqlite',\n\t\t\t\t\t\t\t\tfirstProcessId,\n\t\t\t\t\t\t\t\tprocessIdSpaceLength,\n\t\t\t\t\t\t\t\tfollowSymlinks,\n\t\t\t\t\t\t\t\ttrace,\n\t\t\t\t\t\t\t\tinternalCookieStore: args.internalCookieStore,\n\t\t\t\t\t\t\t\twithXdebug: args.xdebug,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tawait additionalPlayground.isReady();\n\n\t\t\t\t\t\t\t// Replicate the Blueprint-initialized /internal directory\n\t\t\t\t\t\t\tawait additionalPlayground.writeFile(\n\t\t\t\t\t\t\t\t'/tmp/internal.zip',\n\t\t\t\t\t\t\t\tinternalZip\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tawait unzipFile(\n\t\t\t\t\t\t\t\tadditionalPlayground,\n\t\t\t\t\t\t\t\t'/tmp/internal.zip',\n\t\t\t\t\t\t\t\t'/internal'\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tawait additionalPlayground.unlink(\n\t\t\t\t\t\t\t\t'/tmp/internal.zip'\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tloadBalancer.addWorker(additionalPlayground);\n\t\t\t\t\t\t})\n\t\t\t\t\t);\n\n\t\t\t\t\tlogger.log(`Ready!`);\n\t\t\t\t}\n\n\t\t\t\tlogger.log(`WordPress is running on ${absoluteUrl}`);\n\n\t\t\t\treturn {\n\t\t\t\t\tplayground,\n\t\t\t\t\tserver,\n\t\t\t\t\t[Symbol.asyncDispose]: async function disposeCLI() {\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\tplaygroundsToCleanUp.map(\n\t\t\t\t\t\t\t\tasync ({ playground, worker }) => {\n\t\t\t\t\t\t\t\t\tawait playground.dispose();\n\t\t\t\t\t\t\t\t\tawait worker.terminate();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t\tawait new Promise((resolve) => server.close(resolve));\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tif (!args.debug) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tconst phpLogs = await playground.readFileAsText(errorLogPath);\n\t\t\t\tthrow new Error(phpLogs, { cause: error });\n\t\t\t}\n\t\t},\n\t\tasync handleRequest(request: PHPRequest) {\n\t\t\tif (!wordPressReady) {\n\t\t\t\treturn PHPResponse.forHttpCode(\n\t\t\t\t\t502,\n\t\t\t\t\t'WordPress is not ready yet'\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn await loadBalancer.handleRequest(request);\n\t\t},\n\t});\n}\n"],"names":["CACHE_FOLDER","path","os","fetchSqliteIntegration","monitor","cachedDownload","remoteUrl","cacheKey","artifactPath","fs","downloadTo","readAsFile","localPath","reader","tmpPath","writer","done","value","resolve","reject","err","fileName","basename","startServer","options","app","express","server","address","req","res","phpResponse","parseHeaders","bufferRequestBody","key","port","body","chunk","requestHeaders","i","LoadBalancer","initialWorker","worker","request","smallestWorkerLoad","workerLoad","promiseForResponse","isValidWordPressSlug","version","ReportableError","message","error","iterations","maxIterations","errorStack","subError","logger","resolveBlueprint","sourceString","blueprintMayReadAdjacentFiles","resolveRemoteBlueprint","blueprintPath","stat","extension","ZipFilesystem","blueprintText","contextPath","nodeJsFilesystem","NodeJsFilesystem","OverlayFilesystem","InMemoryFilesystem","parseOptionsAndRunCLI","yargsObject","yargs","RecommendedPHPVersion","SupportedPHPVersions","parseMountWithDelimiterArguments","parseMountDirArguments","cpus","args","isMountingWordPressDir","mount","command","cliArgs","runCLI","e","reportableCause","loadBalancer","playground","playgroundsToCleanUp","expandAutoMounts","zipSite","outfile","zip","compileInputBlueprint","additionalBlueprintSteps","blueprint","isBlueprintBundle","tracker","ProgressTracker","lastCaption","progressReached100","progressInteger","writeProgressUpdate","compileBlueprint","lastProgressMessage","writeStream","finalUpdate","spawnPHPWorkerThread","workerUrl","Worker","spawnWorkerThreads","count","moduleWorkerUrl","importedWorkerUrlString","_documentCurrentScript","promises","compiledBlueprint","nativeFlockSync","m","fileLockManager","FileLockManagerForNode","exposeFileLockManager","port1","port2","MessageChannel","jspi","exposeAPI","exposeSyncAPI","wordPressReady","absoluteUrl","totalWorkerCount","promisedWorkers","wpDetails","EmscriptenDownloadMonitor","loaded","total","percentProgress","resolveWordPressRelease","preinstalledWpContentPath","wordPressZip","sqliteIntegrationPluginZip","followSymlinks","trace","mountsBeforeWpInstall","mountsAfterWpInstall","additionalWorkers","consumeAPI","fileLockManagerPort","processIdSpaceLength","zipDirectory","runBlueprintSteps","internalZip","initialWorkerProcessIdSpace","index","additionalPlayground","firstProcessId","unzipFile","phpLogs","errorLogPath","PHPResponse"],"mappings":"qgCAKO,MAAMA,EAAeC,EAAK,KAAKC,EAAG,QAAA,EAAW,uBAAuB,EAE3E,eAAsBC,GACrBC,EACC,CAMM,OALW,MAAMC,EACvB,0FACA,aACAD,CACD,CAED,CAIsB,eAAAC,EACrBC,EACAC,EACAH,EACC,CACD,MAAMI,EAAeP,EAAK,KAAKD,EAAcO,CAAQ,EACrD,OAAKE,EAAG,WAAWD,CAAY,IAC9BC,EAAG,cAAcT,CAAY,EACvB,MAAAU,GAAWJ,EAAWE,EAAcJ,CAAO,GAE3CO,EAAWH,CAAY,CAC/B,CAEA,eAAeE,GACdJ,EACAM,EACAR,EACC,CAEK,MAAAS,GADW,MAAMT,EAAQ,aAAa,MAAME,CAAS,CAAC,GACpC,KAAM,UAAU,EAClCQ,EAAU,GAAGF,CAAS,WACtBG,EAASN,EAAG,kBAAkBK,CAAO,EAC3C,OAAa,CAC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