-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
… them in wp-content/mu-plugins) (#1366) This PR moves the Playground mu-plugins from `/wordpress/wp-content/mu-plugins`, where they may interfere with the user-provided files and pollute the git repository, to `/internal/mu-plugins`, where they're invisible to the Playground consumer and don't show up in exports or OPFS mounts. Closes #1318 ## Changes made Technically, this PR uses the `auto_prepend_file` PHP options to pre-load the following script: ```php <?php foreach (glob('/internal/preload/*.php') as $file) { require_once $file; } ``` From here, preloading files is as simple as creating them in `/internal/preload`. This PR ships a few such preloaded files: * `consts.php`, that enables predefining PHP constants without affecting `wp-config.php`. * `env.php`, that preloads mu-plugins from `/internal/mu-plugins` using [the method described by](#1318 (comment)) @brandonpayton. * `phpinfo.php`, that just calls `phpinfo();` when the request URL is `/phpinfo.php` – this prevents creating an actual `phpinfo.php` file in the document root. This involves a slight change in the path resolution logic which will have to change even more soon to solve #1365. From there, the SQLite integration plugin and the Playground mu-plugins are placed in `/internal/mu-plugins` and do not affect the WordPress file structure. This PR also reduces code duplication by moving some parts of the WordPress setup to the `@wp-playground/wordpress` package where they can be imported by both the web and the CLI versions of Playground. We'll only see more of these moving forward. ## Follow-up work * Define clear use-cases and behaviors related to the location of Playground-provided files. E.g. Full site export, where we want to keep the SQLite integration plugin, or a GitHub repo, where we only want to keep track of our changes in wp-content. * Use `@wp-playground/cli` to build and setup WordPress in `packages/playground/wordpress-builds/build/Dockerfile` * Playground web: do not ship the SQLite integration plugin in the pre-built `wp-content` directory. Source it from the `/internal/mu-plugins` directory same way as in the CLI build. * Do not create the drop-in plugin `wp-content/db.php` * Do not install the WordPress importer plugin in `wp-content/plugins` * Figure out how to avoid touching `wp-config.php` – defining PHP constants may require rewriting it and it might be desirable to keep those changes on export ## Testing instructions * Confirm the tests pass * In the browser – export Playground as zip, import it, also refresh the page and import again, confirm it all worked.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { BasePHP } from './base-php'; | ||
|
||
/** | ||
* Proxy specific paths to the parent's MEMFS instance. | ||
* This is useful for sharing the WordPress installation | ||
* between the parent and child processes. | ||
*/ | ||
export function proxyFileSystem( | ||
sourceOfTruth: BasePHP, | ||
replica: BasePHP, | ||
paths: string[] | ||
) { | ||
// We can't just import the symbol from the library because | ||
// Playground CLI is built as ESM and php-wasm-node is built as | ||
// CJS and the imported symbols will different in the production build. | ||
const __private__symbol = Object.getOwnPropertySymbols(sourceOfTruth)[0]; | ||
for (const path of paths) { | ||
if (!replica.fileExists(path)) { | ||
replica.mkdir(path); | ||
} | ||
if (!sourceOfTruth.fileExists(path)) { | ||
sourceOfTruth.mkdir(path); | ||
} | ||
// @ts-ignore | ||
replica[__private__symbol].FS.mount( | ||
// @ts-ignore | ||
replica[__private__symbol].PROXYFS, | ||
{ | ||
root: path, | ||
// @ts-ignore | ||
fs: sourceOfTruth[__private__symbol].FS, | ||
}, | ||
path | ||
); | ||
} | ||
} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.