-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wp-now: Treat wp-content
in a subdirectory as 'wp-content' mode
#51
Conversation
php.mount(projectPath, `${documentRoot}/wp-content`); | ||
} else { | ||
php.mount(projectPath, documentRoot); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sejas Any ideas why the Learn wp-content
directory isn't being mounted correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it turns out, it was following the first part of the conditional because there were some hidden directories (#32):
The hidden directories existed because I previously ran wp-now start
in the directory.
When I remove the hidden directories, I see this crash:
Error: Could not mount /Users/danielbachhuber/projects/wordpress-learn: Device or resource busy.
at _NodePHP.descriptor.value (/Users/danielbachhuber/projects/playground-tools/node_modules/@php-wasm/node/index.cjs:67405:17)
at runWpContentMode (file:///Users/danielbachhuber/projects/playground-tools/dist/packages/wp-now/main.js:590:9)
at async file:///Users/danielbachhuber/projects/playground-tools/dist/packages/wp-now/main.js:535:9
at async applyToInstances (file:///Users/danielbachhuber/projects/playground-tools/dist/packages/wp-now/main.js:481:5)
at async startWPNow (file:///Users/danielbachhuber/projects/playground-tools/dist/packages/wp-now/main.js:532:3)
at async startServer (file:///Users/danielbachhuber/projects/playground-tools/dist/packages/wp-now/main.js:780:42)
at async Object.handler (file:///Users/danielbachhuber/projects/playground-tools/dist/packages/wp-now/main.js:925:25) {
However, if wp-now
creates hidden directories each time it starts, we'll revert to the first behavior after it starts...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With more reflection, I kinda think this particular scenario would be better solved by #19
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sejas Any ideas why the Learn
wp-content
directory isn't being mounted correctly?
@danielbachhuber , I debugged the code andphp.mount(projectPath, documentRoot);
is trying to mount twice the same destinationdocumentRoot
. This directory was already mounted with the WordPress latest files.
A simple suggestion would be mounting the wp-content
folders.
- php.mount(projectPath, documentRoot);
+ php.mount(`${projectPath}/wp-content`, `${documentRoot}/wp-content`);
But this approach would be "similar" as running wp-now directly from inside the wp-content
folder.
A more elaborated approach would be mounting each subfolder/file independently resulting on a "merge" between core and the plugin, maybe even recursively if we want that themes
folder contains twentytwentythree.
This is what I see with the simple approach:
Themes:
Plugins:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already pushed the simple fix: 1b2260f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mapping folders is a more general fix, let's go for it. 👍
Restructures the repository as monorepo and separates the PHP implementation from the WordPress-specific bits. The new packages: * **php-wasm** – low-level WASM PHP primitives * A configurable PHP build pipeline for different targets (web, node.js, standalone) * A low-level `PHP` JavaScript class with `eval` for executing PHP code and FS utils like `writeFile` for runtime managing the * A `PHPServer` JavaScript class for dispatching HTTP requests – both to run the PHP files AND to download static files * A `PHPBrowser` JavaScript class to consume the above using an iframe * **php-wasm-browser** – a high-level layer to efficiently run `php-wasm` in the browser * `service-worker` utilities to redirect the browser traffic to `PHPServer` * `worker-thread` utilities to offload the `PHPServer` to a separate process. Three backends are available: Iframe, Webworker, SharedWorker. * A messaging layer and setup helpers to connect the above. * Server utilities to serve the correct headers for the `wasm` files via `.htaccess`. * **wordpress-wasm** – WordPress-specific WASM PHP bindings for web and node.js * The required WordPress-specific setup like constants and filters * `wp.data` bundling pipeline for the web configurable to bundle custom code * WordPress API to ease common tasks like login, install a plugin, start a block editor with specific settings and content * A `fetch`-based transport for HTTP requests * An example app demonstrating WordPress in the browser. Let's eventually extract it into a separate package or at least a directory. Other, general notes: * Pre-built binaries are shipped in the global `build` directory – it would be nice to either move them to their specific packages, or remove them from the repo completely and download them from somewhere on the initial build. * `esbuild` is used to build each packages and then the entire app. * Gulp is used for orchestration. Perhaps https://nx.dev/ would make a good replacement in the future. * There is no package publishing process yet. Perhaps Lerna would make a good one? Solves WordPress#51 and WordPress#16
See #39 (comment)
Related #26
What?
Treats a repository structure like https://github.com/WordPress/Learn as 'wp-content' mode:
Specifically, in the Learn repository, the
wp-content
directory is a subdirectory of the repository, and containsplugins
andthemes
directories.Why?
How?
isWpContentDirectory()
to first look in the immediate directory forplugins
orthemes
, and then also look in awp-content
subdirectory (if one exists) forplugins
orthemes
too.runWpContentMode()
to handle both variations of directory structures.Testing Instructions
nx preview wp-now start --path=/path/to/learn-repository
nx preview wp-now start
against a few other modes and verify it works as expected.